blob: 9d387fbf65a3b5376e663d47c9b1d60d06692b33 [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 Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 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 Smartc01f3202006-08-18 17:47:08 -040076void
77lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050078{
James Smartc01f3202006-08-18 17:47:08 -040079 struct lpfc_rport_data *rdata;
80 struct lpfc_nodelist * ndlp;
81 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050082
James Smartc01f3202006-08-18 17:47:08 -040083 rdata = rport->dd_data;
84 ndlp = rdata->pnode;
85
James Smart307e3382020-11-15 11:26:30 -080086 if (!ndlp) {
James Smartc01f3202006-08-18 17:47:08 -040087 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
88 printk(KERN_ERR "Cannot find remote node"
89 " to terminate I/O Data x%x\n",
90 rport->port_id);
dea31012005-04-17 16:05:31 -050091 return;
92 }
93
James Smarta257bf92009-04-06 18:48:10 -040094 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050095
James Smart858c9f62007-06-17 19:56:39 -050096 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
97 "rport terminate: sid:x%x did:x%x flg:x%x",
98 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
99
James Smartc01f3202006-08-18 17:47:08 -0400100 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -0400101 lpfc_sli_abort_iocb(ndlp->vport,
James Smart895427b2017-02-12 13:52:30 -0800102 &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400103 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -0400104 }
James Smartc01f3202006-08-18 17:47:08 -0400105}
106
107/*
108 * This function will be called when dev_loss_tmo fire.
109 */
110void
111lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
112{
113 struct lpfc_rport_data *rdata;
114 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500115 struct lpfc_vport *vport;
James Smart466e8402015-05-21 13:55:28 -0400116 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500117 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500118 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400119 int put_node;
120 int put_rport;
James Smart894bb172019-08-14 16:56:52 -0700121 unsigned long iflags;
James Smartc01f3202006-08-18 17:47:08 -0400122
123 rdata = rport->dd_data;
124 ndlp = rdata->pnode;
James Smart307e3382020-11-15 11:26:30 -0800125 if (!ndlp)
James Smartc01f3202006-08-18 17:47:08 -0400126 return;
James Smartc01f3202006-08-18 17:47:08 -0400127
James Smart858c9f62007-06-17 19:56:39 -0500128 vport = ndlp->vport;
129 phba = vport->phba;
130
131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
132 "rport devlosscb: sid:x%x did:x%x flg:x%x",
133 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
134
James Smart34f5ad82012-08-03 12:35:03 -0400135 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -0700136 "3181 dev_loss_callbk x%06x, rport x%px flg x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -0400137 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
138
James Smarta8adb832007-10-27 13:37:53 -0400139 /* Don't defer this if we are in the process of deleting the vport
140 * or unloading the driver. The unload will cleanup the node
141 * appropriately we just need to cleanup the ndlp rport info here.
142 */
143 if (vport->load_flag & FC_UNLOADING) {
144 put_node = rdata->pnode != NULL;
145 put_rport = ndlp->rport != NULL;
146 rdata->pnode = NULL;
147 ndlp->rport = NULL;
148 if (put_node)
149 lpfc_nlp_put(ndlp);
150 if (put_rport)
151 put_device(&rport->dev);
152 return;
153 }
154
155 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
156 return;
157
James Smart466e8402015-05-21 13:55:28 -0400158 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
Dick Kennedy372c1872020-06-30 14:50:00 -0700159 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
160 "6789 rport name %llx != node port name %llx",
161 rport->port_name,
162 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400163
James Smart858c9f62007-06-17 19:56:39 -0500164 evtp = &ndlp->dev_loss_evt;
165
James Smart466e8402015-05-21 13:55:28 -0400166 if (!list_empty(&evtp->evt_listp)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700167 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
168 "6790 rport name %llx dev_loss_evt pending",
169 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500170 return;
James Smart466e8402015-05-21 13:55:28 -0400171 }
James Smart858c9f62007-06-17 19:56:39 -0500172
James Smart466e8402015-05-21 13:55:28 -0400173 shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -0700174 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400175 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700176 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smarta62a4352013-04-17 20:18:19 -0400177
James Smartfa4066b2008-01-11 01:53:27 -0500178 /* We need to hold the node by incrementing the reference
179 * count until this queued work is done
180 */
James Smart4430f7f2020-11-15 11:26:31 -0800181 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400182
James Smart894bb172019-08-14 16:56:52 -0700183 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5e9d9b82008-06-14 22:52:53 -0400184 if (evtp->evt_arg1) {
185 evtp->evt = LPFC_EVT_DEV_LOSS;
186 list_add_tail(&evtp->evt_listp, &phba->work_list);
187 lpfc_worker_wake_up(phba);
188 }
James Smart894bb172019-08-14 16:56:52 -0700189 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500190
James Smart858c9f62007-06-17 19:56:39 -0500191 return;
192}
193
James Smarta93ff372010-10-22 11:06:08 -0400194/**
195 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
196 * @ndlp: Pointer to remote node object.
197 *
198 * This function is called from the worker thread when devloss timeout timer
199 * expires. For SLI4 host, this routine shall return 1 when at lease one
200 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
201 * routine shall return 0 when there is no remote node is still in use of FCF
202 * when devloss timeout happened to this @ndlp.
203 **/
204static int
James Smart858c9f62007-06-17 19:56:39 -0500205lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
206{
207 struct lpfc_rport_data *rdata;
208 struct fc_rport *rport;
209 struct lpfc_vport *vport;
210 struct lpfc_hba *phba;
James Smart466e8402015-05-21 13:55:28 -0400211 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500212 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400213 int put_node;
James Smart858c9f62007-06-17 19:56:39 -0500214 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400215 int fcf_inuse = 0;
James Smart894bb172019-08-14 16:56:52 -0700216 unsigned long iflags;
James Smart858c9f62007-06-17 19:56:39 -0500217
218 rport = ndlp->rport;
James Smart858c9f62007-06-17 19:56:39 -0500219 vport = ndlp->vport;
James Smart466e8402015-05-21 13:55:28 -0400220 shost = lpfc_shost_from_vport(vport);
221
James Smart894bb172019-08-14 16:56:52 -0700222 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400223 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700224 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400225
226 if (!rport)
227 return fcf_inuse;
228
229 name = (uint8_t *) &ndlp->nlp_portname;
James Smart858c9f62007-06-17 19:56:39 -0500230 phba = vport->phba;
231
James Smarta93ff372010-10-22 11:06:08 -0400232 if (phba->sli_rev == LPFC_SLI_REV4)
233 fcf_inuse = lpfc_fcf_inuse(phba);
234
James Smart858c9f62007-06-17 19:56:39 -0500235 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
236 "rport devlosstmo:did:x%x type:x%x id:x%x",
237 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
238
James Smart34f5ad82012-08-03 12:35:03 -0400239 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -0700240 "3182 dev_loss_tmo_handler x%06x, rport x%px flg x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -0400241 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
242
James Smart466e8402015-05-21 13:55:28 -0400243 /*
244 * lpfc_nlp_remove if reached with dangling rport drops the
245 * reference. To make sure that does not happen clear rport
246 * pointer in ndlp before lpfc_nlp_put.
247 */
248 rdata = rport->dd_data;
249
James Smarta8adb832007-10-27 13:37:53 -0400250 /* Don't defer this if we are in the process of deleting the vport
251 * or unloading the driver. The unload will cleanup the node
252 * appropriately we just need to cleanup the ndlp rport info here.
253 */
254 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500255 if (ndlp->nlp_sid != NLP_NO_SID) {
256 /* flush the target */
257 lpfc_sli_abort_iocb(vport,
James Smart895427b2017-02-12 13:52:30 -0800258 &phba->sli.sli3_ring[LPFC_FCP_RING],
259 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smart09372822008-01-11 01:52:54 -0500260 }
James Smarta8adb832007-10-27 13:37:53 -0400261 put_node = rdata->pnode != NULL;
James Smarta8adb832007-10-27 13:37:53 -0400262 rdata->pnode = NULL;
263 ndlp->rport = NULL;
264 if (put_node)
265 lpfc_nlp_put(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400266 put_device(&rport->dev);
267
James Smarta93ff372010-10-22 11:06:08 -0400268 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400269 }
270
James Smartd7c255b2008-08-24 21:50:00 -0400271 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
272 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
273 "0284 Devloss timeout Ignored on "
274 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
275 "NPort x%x\n",
276 *name, *(name+1), *(name+2), *(name+3),
277 *(name+4), *(name+5), *(name+6), *(name+7),
278 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400279 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400280 }
James Smart858c9f62007-06-17 19:56:39 -0500281
James Smart466e8402015-05-21 13:55:28 -0400282 put_node = rdata->pnode != NULL;
283 rdata->pnode = NULL;
284 ndlp->rport = NULL;
285 if (put_node)
286 lpfc_nlp_put(ndlp);
287 put_device(&rport->dev);
288
289 if (ndlp->nlp_type & NLP_FABRIC)
James Smarta93ff372010-10-22 11:06:08 -0400290 return fcf_inuse;
James Smart82085712007-04-25 09:52:41 -0400291
dea31012005-04-17 16:05:31 -0500292 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400293 warn_on = 1;
James Smart895427b2017-02-12 13:52:30 -0800294 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400295 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500296 }
James Smartc01f3202006-08-18 17:47:08 -0400297
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400298 if (warn_on) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700299 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400300 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400301 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
302 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400303 *name, *(name+1), *(name+2), *(name+3),
304 *(name+4), *(name+5), *(name+6), *(name+7),
305 ndlp->nlp_DID, ndlp->nlp_flag,
306 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400307 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -0700308 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400309 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400310 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
311 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400312 *name, *(name+1), *(name+2), *(name+3),
313 *(name+4), *(name+5), *(name+6), *(name+7),
314 ndlp->nlp_DID, ndlp->nlp_flag,
315 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400316 }
317
James Smart2ade92a2017-03-04 09:30:38 -0800318 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400319 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400320 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400321 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
322 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500323 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400324
James Smarta93ff372010-10-22 11:06:08 -0400325 return fcf_inuse;
326}
327
328/**
329 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
330 * @phba: Pointer to hba context object.
331 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
332 * @nlp_did: remote node identifer with devloss timeout.
333 *
334 * This function is called from the worker thread after invoking devloss
335 * timeout handler and releasing the reference count for the ndlp with
336 * which the devloss timeout was handled for SLI4 host. For the devloss
337 * timeout of the last remote node which had been in use of FCF, when this
338 * routine is invoked, it shall be guaranteed that none of the remote are
339 * in-use of FCF. When devloss timeout to the last remote using the FCF,
340 * if the FIP engine is neither in FCF table scan process nor roundrobin
341 * failover process, the in-use FCF shall be unregistered. If the FIP
342 * engine is in FCF discovery process, the devloss timeout state shall
343 * be set for either the FCF table scan process or roundrobin failover
344 * process to unregister the in-use FCF.
345 **/
346static void
347lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
348 uint32_t nlp_did)
349{
350 /* If devloss timeout happened to a remote node when FCF had no
351 * longer been in-use, do nothing.
352 */
353 if (!fcf_inuse)
354 return;
355
356 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
357 spin_lock_irq(&phba->hbalock);
358 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
359 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
360 spin_unlock_irq(&phba->hbalock);
361 return;
362 }
363 phba->hba_flag |= HBA_DEVLOSS_TMO;
364 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
365 "2847 Last remote node (x%x) using "
366 "FCF devloss tmo\n", nlp_did);
367 }
368 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
369 spin_unlock_irq(&phba->hbalock);
370 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
371 "2868 Devloss tmo to FCF rediscovery "
372 "in progress\n");
373 return;
374 }
375 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
376 spin_unlock_irq(&phba->hbalock);
377 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
378 "2869 Devloss tmo to idle FIP engine, "
379 "unreg in-use FCF and rescan.\n");
380 /* Unregister in-use FCF and rescan */
381 lpfc_unregister_fcf_rescan(phba);
382 return;
383 }
384 spin_unlock_irq(&phba->hbalock);
385 if (phba->hba_flag & FCF_TS_INPROG)
386 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
387 "2870 FCF table scan in progress\n");
388 if (phba->hba_flag & FCF_RR_INPROG)
389 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
390 "2871 FLOGI roundrobin FCF failover "
391 "in progress\n");
392 }
James Smart6fb120a2009-05-22 14:52:59 -0400393 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500394}
James Smartc01f3202006-08-18 17:47:08 -0400395
James Smartea2151b2008-09-07 11:52:10 -0400396/**
James Smart3621a712009-04-06 18:47:14 -0400397 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400398 * @phba: Pointer to hba context object.
399 *
400 * This function is called from the functions which need to post
401 * events from interrupt context. This function allocates data
402 * structure required for posting event. It also keeps track of
403 * number of events pending and prevent event storm when there are
404 * too many events.
405 **/
406struct lpfc_fast_path_event *
407lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
408 struct lpfc_fast_path_event *ret;
409
410 /* If there are lot of fast event do not exhaust memory due to this */
411 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
412 return NULL;
413
414 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
415 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400416 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400417 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400418 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
419 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
420 }
James Smartea2151b2008-09-07 11:52:10 -0400421 return ret;
422}
423
424/**
James Smart3621a712009-04-06 18:47:14 -0400425 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400426 * @phba: Pointer to hba context object.
427 * @evt: Event object which need to be freed.
428 *
429 * This function frees the data structure required for posting
430 * events.
431 **/
432void
433lpfc_free_fast_evt(struct lpfc_hba *phba,
434 struct lpfc_fast_path_event *evt) {
435
436 atomic_dec(&phba->fast_event_count);
437 kfree(evt);
438}
439
440/**
James Smart3621a712009-04-06 18:47:14 -0400441 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400442 * @phba: Pointer to hba context object.
443 * @evtp: Event data structure.
444 *
445 * This function is called from worker thread, when the interrupt
446 * context need to post an event. This function posts the event
447 * to fc transport netlink interface.
448 **/
449static void
450lpfc_send_fastpath_evt(struct lpfc_hba *phba,
451 struct lpfc_work_evt *evtp)
452{
453 unsigned long evt_category, evt_sub_category;
454 struct lpfc_fast_path_event *fast_evt_data;
455 char *evt_data;
456 uint32_t evt_data_size;
457 struct Scsi_Host *shost;
458
459 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
460 work_evt);
461
462 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
463 evt_sub_category = (unsigned long) fast_evt_data->un.
464 fabric_evt.subcategory;
465 shost = lpfc_shost_from_vport(fast_evt_data->vport);
466 if (evt_category == FC_REG_FABRIC_EVENT) {
467 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
468 evt_data = (char *) &fast_evt_data->un.read_check_error;
469 evt_data_size = sizeof(fast_evt_data->un.
470 read_check_error);
471 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500472 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400473 evt_data = (char *) &fast_evt_data->un.fabric_evt;
474 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
475 } else {
476 lpfc_free_fast_evt(phba, fast_evt_data);
477 return;
478 }
479 } else if (evt_category == FC_REG_SCSI_EVENT) {
480 switch (evt_sub_category) {
481 case LPFC_EVENT_QFULL:
482 case LPFC_EVENT_DEVBSY:
483 evt_data = (char *) &fast_evt_data->un.scsi_evt;
484 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
485 break;
486 case LPFC_EVENT_CHECK_COND:
487 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
488 evt_data_size = sizeof(fast_evt_data->un.
489 check_cond_evt);
490 break;
491 case LPFC_EVENT_VARQUEDEPTH:
492 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
493 evt_data_size = sizeof(fast_evt_data->un.
494 queue_depth_evt);
495 break;
496 default:
497 lpfc_free_fast_evt(phba, fast_evt_data);
498 return;
499 }
500 } else {
501 lpfc_free_fast_evt(phba, fast_evt_data);
502 return;
503 }
504
James Smart895427b2017-02-12 13:52:30 -0800505 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
506 fc_host_post_vendor_event(shost,
507 fc_get_event_number(),
508 evt_data_size,
509 evt_data,
510 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400511
512 lpfc_free_fast_evt(phba, fast_evt_data);
513 return;
514}
515
dea31012005-04-17 16:05:31 -0500516static void
James Smart2e0fef82007-06-17 19:56:36 -0500517lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500518{
519 struct lpfc_work_evt *evtp = NULL;
520 struct lpfc_nodelist *ndlp;
521 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400522 int fcf_inuse;
523 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500524
James Smart2e0fef82007-06-17 19:56:36 -0500525 spin_lock_irq(&phba->hbalock);
526 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500527 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
528 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500529 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500530 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500531 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500532 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500533 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500534 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500535 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500536 /* decrement the node reference count held
537 * for this queued work
538 */
539 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500540 break;
James Smart858c9f62007-06-17 19:56:39 -0500541 case LPFC_EVT_DEV_LOSS:
542 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400543 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500544 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500545 /* decrement the node reference count held for
546 * this queued work
547 */
James Smarta93ff372010-10-22 11:06:08 -0400548 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500549 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400550 if (phba->sli_rev == LPFC_SLI_REV4)
551 lpfc_sli4_post_dev_loss_tmo_handler(phba,
552 fcf_inuse,
553 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500554 break;
James Smarte7dab162020-10-20 13:27:12 -0700555 case LPFC_EVT_RECOVER_PORT:
556 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
557 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
558 free_evt = 0;
559 /* decrement the node reference count held for
560 * this queued work
561 */
562 lpfc_nlp_put(ndlp);
563 break;
dea31012005-04-17 16:05:31 -0500564 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500565 if (phba->link_state < LPFC_LINK_DOWN)
566 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500567 else
James Smart2e0fef82007-06-17 19:56:36 -0500568 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500569 complete((struct completion *)(evtp->evt_arg2));
570 break;
James Smart46fa3112007-04-25 09:51:45 -0400571 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500572 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400573 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400574 *(int *)(evtp->evt_arg1) = 0;
575 complete((struct completion *)(evtp->evt_arg2));
576 break;
577 case LPFC_EVT_OFFLINE:
578 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500579 lpfc_sli_brdrestart(phba);
580 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400581 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
582 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500583 complete((struct completion *)(evtp->evt_arg2));
584 break;
585 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400586 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500587 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500588 lpfc_sli_brdreset(phba);
589 lpfc_hba_down_post(phba);
590 *(int *)(evtp->evt_arg1) =
591 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400592 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500593 complete((struct completion *)(evtp->evt_arg2));
594 break;
595 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400596 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500597 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500598 = (phba->pport->stopped)
599 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400600 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500601 complete((struct completion *)(evtp->evt_arg2));
602 break;
James Smartea2151b2008-09-07 11:52:10 -0400603 case LPFC_EVT_FASTPATH_MGMT_EVT:
604 lpfc_send_fastpath_evt(phba, evtp);
605 free_evt = 0;
606 break;
James Smart78730cf2010-04-06 15:06:30 -0400607 case LPFC_EVT_RESET_HBA:
608 if (!(phba->pport->load_flag & FC_UNLOADING))
609 lpfc_reset_hba(phba);
610 break;
dea31012005-04-17 16:05:31 -0500611 }
612 if (free_evt)
613 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500614 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500615 }
James Smart2e0fef82007-06-17 19:56:36 -0500616 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500617
618}
619
James Smart311464e2007-08-02 11:10:37 -0400620static void
James Smart2e0fef82007-06-17 19:56:36 -0500621lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500622{
623 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500624 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400625 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400626 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400627 int i;
dea31012005-04-17 16:05:31 -0500628
James Smart2e0fef82007-06-17 19:56:36 -0500629 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500630 ha_copy = phba->work_ha;
631 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500632 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500633
James Smartda0436e2009-05-22 14:51:39 -0400634 /* First, try to post the next mailbox command to SLI4 device */
635 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
636 lpfc_sli4_post_async_mbox(phba);
637
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500638 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400639 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500640 lpfc_handle_eratt(phba);
641
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500642 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500643 lpfc_sli_handle_mb_event(phba);
644
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500645 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500646 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400647
James Smartda0436e2009-05-22 14:51:39 -0400648 /* Process SLI4 events */
649 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500650 if (phba->hba_flag & HBA_RRQ_ACTIVE)
651 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400652 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
653 lpfc_sli4_els_xri_abort_event_proc(phba);
654 if (phba->hba_flag & ASYNC_EVENT)
655 lpfc_sli4_async_event_proc(phba);
656 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
657 spin_lock_irq(&phba->hbalock);
658 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
659 spin_unlock_irq(&phba->hbalock);
660 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
661 }
James Smartecfd03c2010-02-12 14:41:27 -0500662 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
663 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400664 }
665
James Smart549e55c2007-08-02 11:09:51 -0400666 vports = lpfc_create_vport_work_array(phba);
667 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400668 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400669 /*
670 * We could have no vports in array if unloading, so if
671 * this happens then just use the pport
672 */
673 if (vports[i] == NULL && i == 0)
674 vport = phba->pport;
675 else
676 vport = vports[i];
677 if (vport == NULL)
678 break;
James Smart58da1ff2008-04-07 10:15:56 -0400679 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400680 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400681 vport->work_port_events &= ~work_port_events;
682 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400683 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400684 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400685 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400686 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400687 if (work_port_events & WORKER_HB_TMO)
688 lpfc_hb_timeout_handler(phba);
689 if (work_port_events & WORKER_MBOX_TMO)
690 lpfc_mbox_timeout_handler(phba);
691 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
692 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400693 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
694 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500695 if (work_port_events & WORKER_DELAYED_DISC_TMO)
696 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500697 }
James Smart09372822008-01-11 01:52:54 -0500698 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500699
James Smart895427b2017-02-12 13:52:30 -0800700 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500701 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
702 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700703 if (pring && (status & HA_RXMASK ||
704 pring->flag & LPFC_DEFERRED_RING_EVENT ||
705 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400706 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500707 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800708 /* Preserve legacy behavior. */
709 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
710 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500711 } else {
James Smart15498dc2019-09-21 20:58:59 -0700712 /* Driver could have abort request completed in queue
713 * when link goes down. Allow for this transition.
714 */
715 if (phba->link_state >= LPFC_LINK_DOWN ||
James Smartae9e28f2017-05-15 15:20:51 -0700716 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500717 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
718 lpfc_sli_handle_slow_ring_event(phba, pring,
719 (status &
720 HA_RXMASK));
721 }
James Smart858c9f62007-06-17 19:56:39 -0500722 }
James Smartdc19e3b2018-05-24 21:08:57 -0700723 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400724 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500725 /*
726 * Turn on Ring interrupts
727 */
James Smart3772a992009-05-22 14:50:54 -0400728 if (phba->sli_rev <= LPFC_SLI_REV3) {
729 spin_lock_irq(&phba->hbalock);
730 control = readl(phba->HCregaddr);
731 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
732 lpfc_debugfs_slow_ring_trc(phba,
733 "WRK Enable ring: cntl:x%x hacopy:x%x",
734 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400735
James Smart3772a992009-05-22 14:50:54 -0400736 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
737 writel(control, phba->HCregaddr);
738 readl(phba->HCregaddr); /* flush */
739 } else {
740 lpfc_debugfs_slow_ring_trc(phba,
741 "WRK Ring ok: cntl:x%x hacopy:x%x",
742 control, ha_copy, 0);
743 }
744 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500745 }
746 }
James Smart2e0fef82007-06-17 19:56:36 -0500747 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500748}
749
dea31012005-04-17 16:05:31 -0500750int
751lpfc_do_work(void *p)
752{
753 struct lpfc_hba *phba = p;
754 int rc;
dea31012005-04-17 16:05:31 -0500755
Dongsheng Yang8698a742014-03-11 18:09:12 +0800756 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400757 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400758 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500759
James Smart3a55b532008-12-04 22:38:54 -0500760 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400761 /* wait and check worker queue activities */
762 rc = wait_event_interruptible(phba->work_waitq,
763 (test_and_clear_bit(LPFC_DATA_READY,
764 &phba->data_flags)
765 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500766 /* Signal wakeup shall terminate the worker thread */
767 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700768 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3a55b532008-12-04 22:38:54 -0500769 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500770 break;
James Smart3a55b532008-12-04 22:38:54 -0500771 }
dea31012005-04-17 16:05:31 -0500772
James Smart5e9d9b82008-06-14 22:52:53 -0400773 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500774 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500775 }
James Smart3a55b532008-12-04 22:38:54 -0500776 phba->worker_thread = NULL;
777 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
778 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500779 return 0;
780}
781
782/*
783 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300784 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500785 * embedding it in the IOCB.
786 */
787int
James Smart2e0fef82007-06-17 19:56:36 -0500788lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500789 uint32_t evt)
790{
791 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500792 unsigned long flags;
dea31012005-04-17 16:05:31 -0500793
794 /*
795 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
796 * be queued to worker thread for processing
797 */
James Smart92d7f7b2007-06-17 19:56:38 -0500798 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500799 if (!evtp)
800 return 0;
801
802 evtp->evt_arg1 = arg1;
803 evtp->evt_arg2 = arg2;
804 evtp->evt = evt;
805
James Smarted957682007-06-17 19:56:37 -0500806 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400807 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500808 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500809
James Smart5e9d9b82008-06-14 22:52:53 -0400810 lpfc_worker_wake_up(phba);
811
dea31012005-04-17 16:05:31 -0500812 return 1;
813}
814
James Smart92d7f7b2007-06-17 19:56:38 -0500815void
816lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
817{
James Smart09372822008-01-11 01:52:54 -0500818 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500819 struct lpfc_hba *phba = vport->phba;
820 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500821
822 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -0800823
James Smart92d7f7b2007-06-17 19:56:38 -0500824 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
825 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400826 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
827 ((vport->port_type == LPFC_NPIV_PORT) &&
828 (ndlp->nlp_DID == NameServer_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 Smart92d7f7b2007-06-17 19:56:38 -05001042 if (vport->fc_flag & FC_LBIT)
1043 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001044
James Smart92d7f7b2007-06-17 19:56:38 -05001045}
1046
1047static int
1048lpfc_linkup(struct lpfc_hba *phba)
1049{
James Smart549e55c2007-08-02 11:09:51 -04001050 struct lpfc_vport **vports;
1051 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001052 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001053
1054 phba->link_state = LPFC_LINK_UP;
1055
1056 /* Unblock fabric iocbs if they are blocked */
1057 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1058 del_timer_sync(&phba->fabric_block_timer);
1059
James Smart549e55c2007-08-02 11:09:51 -04001060 vports = lpfc_create_vport_work_array(phba);
1061 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001062 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001063 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001064 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001065
James Smartd496b9a2018-10-23 13:41:08 -07001066 /* Clear the pport flogi counter in case the link down was
1067 * absorbed without an ACQE. No lock here - in worker thread
1068 * and discovery is synchronized.
1069 */
1070 spin_lock_irq(shost->host_lock);
1071 phba->pport->rcv_flogi_cnt = 0;
1072 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001073
1074 /* reinitialize initial FLOGI flag */
1075 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1076 phba->defer_flogi_acc_flag = false;
1077
dea31012005-04-17 16:05:31 -05001078 return 0;
1079}
1080
1081/*
1082 * This routine handles processing a CLEAR_LA mailbox
1083 * command upon completion. It is setup in the LPFC_MBOXQ
1084 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001085 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001086 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001087static void
James Smart2e0fef82007-06-17 19:56:36 -05001088lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001089{
James Smart2e0fef82007-06-17 19:56:36 -05001090 struct lpfc_vport *vport = pmb->vport;
1091 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1092 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001093 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001094 uint32_t control;
1095
dea31012005-04-17 16:05:31 -05001096 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001097 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1098 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001099
1100 /* Check for error */
1101 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001102 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07001103 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001104 "0320 CLEAR_LA mbxStatus error x%x hba "
1105 "state x%x\n",
1106 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001107 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001108 goto out;
1109 }
1110
James Smart92d7f7b2007-06-17 19:56:38 -05001111 if (vport->port_type == LPFC_PHYSICAL_PORT)
1112 phba->link_state = LPFC_HBA_READY;
1113
1114 spin_lock_irq(&phba->hbalock);
1115 psli->sli_flag |= LPFC_PROCESS_LA;
1116 control = readl(phba->HCregaddr);
1117 control |= HC_LAINT_ENA;
1118 writel(control, phba->HCregaddr);
1119 readl(phba->HCregaddr); /* flush */
1120 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001121 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001122 return;
dea31012005-04-17 16:05:31 -05001123
dea31012005-04-17 16:05:31 -05001124out:
1125 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001126 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1127 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001128 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001129
James Smart2e0fef82007-06-17 19:56:36 -05001130 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001131 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001132 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001133
James Smart2e0fef82007-06-17 19:56:36 -05001134 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001135
1136 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001137
1138 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001139 psli->sli_flag |= LPFC_PROCESS_LA;
1140 control = readl(phba->HCregaddr);
1141 control |= HC_LAINT_ENA;
1142 writel(control, phba->HCregaddr);
1143 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001144 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001145
1146 return;
1147}
1148
James Smartd6de08c2015-12-16 18:11:53 -05001149void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001150lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001151{
James Smart2e0fef82007-06-17 19:56:36 -05001152 struct lpfc_vport *vport = pmb->vport;
James Smart7f048392020-09-11 13:01:47 -07001153 LPFC_MBOXQ_t *sparam_mb;
1154 struct lpfc_dmabuf *sparam_mp;
1155 int rc;
dea31012005-04-17 16:05:31 -05001156
James Smart04c68492009-05-22 14:52:52 -04001157 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001158 goto out;
dea31012005-04-17 16:05:31 -05001159
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001160 mempool_free(pmb, phba->mbox_mem_pool);
1161
James Smart1b511972011-12-13 13:23:09 -05001162 /* don't perform discovery for SLI4 loopback diagnostic test */
1163 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1164 !(phba->hba_flag & HBA_FCOE_MODE) &&
1165 (phba->link_flag & LS_LOOPBACK_MODE))
1166 return;
1167
James Smart76a95d72010-11-20 23:11:48 -05001168 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001169 vport->fc_flag & FC_PUBLIC_LOOP &&
1170 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001171 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001172 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001173 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1174 */
James Smart2e0fef82007-06-17 19:56:36 -05001175 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001176 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001177 }
dea31012005-04-17 16:05:31 -05001178
James Smart2e0fef82007-06-17 19:56:36 -05001179 /* Start discovery by sending a FLOGI. port_state is identically
James Smart7f048392020-09-11 13:01:47 -07001180 * LPFC_FLOGI while waiting for FLOGI cmpl.
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001181 */
James Smart835214f2020-01-27 16:23:03 -08001182 if (vport->port_state != LPFC_FLOGI) {
James Smart7f048392020-09-11 13:01:47 -07001183 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1184 * bb-credit recovery is in place.
1185 */
1186 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1187 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1188 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1189 GFP_KERNEL);
1190 if (!sparam_mb)
1191 goto sparam_out;
1192
1193 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1194 if (rc) {
1195 mempool_free(sparam_mb, phba->mbox_mem_pool);
1196 goto sparam_out;
1197 }
1198 sparam_mb->vport = vport;
1199 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1200 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1201 if (rc == MBX_NOT_FINISHED) {
1202 sparam_mp = (struct lpfc_dmabuf *)
1203 sparam_mb->ctx_buf;
1204 lpfc_mbuf_free(phba, sparam_mp->virt,
1205 sparam_mp->phys);
1206 kfree(sparam_mp);
1207 sparam_mb->ctx_buf = NULL;
1208 mempool_free(sparam_mb, phba->mbox_mem_pool);
1209 goto sparam_out;
1210 }
1211
1212 phba->hba_flag |= HBA_DEFER_FLOGI;
1213 } else {
James Smart835214f2020-01-27 16:23:03 -08001214 lpfc_initial_flogi(vport);
James Smart7f048392020-09-11 13:01:47 -07001215 }
James Smart835214f2020-01-27 16:23:03 -08001216 } else {
1217 if (vport->fc_flag & FC_PT2PT)
1218 lpfc_disc_start(vport);
1219 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001220 return;
dea31012005-04-17 16:05:31 -05001221
1222out:
Dick Kennedy372c1872020-06-30 14:50:00 -07001223 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001224 "0306 CONFIG_LINK mbxStatus error x%x "
1225 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001226 pmb->u.mb.mbxStatus, vport->port_state);
James Smart7f048392020-09-11 13:01:47 -07001227sparam_out:
James Smart92d7f7b2007-06-17 19:56:38 -05001228 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001229
1230 lpfc_linkdown(phba);
1231
Dick Kennedy372c1872020-06-30 14:50:00 -07001232 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001233 "0200 CONFIG_LINK bad hba state x%x\n",
1234 vport->port_state);
dea31012005-04-17 16:05:31 -05001235
James Smart92d7f7b2007-06-17 19:56:38 -05001236 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001237 return;
1238}
1239
James Smart7d791df2011-07-22 18:37:52 -04001240/**
1241 * lpfc_sli4_clear_fcf_rr_bmask
Lee Jonese415f2a2020-07-23 13:24:08 +01001242 * @phba: pointer to the struct lpfc_hba for this port.
James Smart7d791df2011-07-22 18:37:52 -04001243 * This fucnction resets the round robin bit mask and clears the
1244 * fcf priority list. The list deletions are done while holding the
1245 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1246 * from the lpfc_fcf_pri record.
1247 **/
1248void
1249lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1250{
1251 struct lpfc_fcf_pri *fcf_pri;
1252 struct lpfc_fcf_pri *next_fcf_pri;
1253 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1254 spin_lock_irq(&phba->hbalock);
1255 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1256 &phba->fcf.fcf_pri_list, list) {
1257 list_del_init(&fcf_pri->list);
1258 fcf_pri->fcf_rec.flag = 0;
1259 }
1260 spin_unlock_irq(&phba->hbalock);
1261}
dea31012005-04-17 16:05:31 -05001262static void
James Smart6fb120a2009-05-22 14:52:59 -04001263lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1264{
1265 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001266
1267 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001268 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1269 "2017 REG_FCFI mbxStatus error x%x "
1270 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1271 vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001272 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001273 }
1274
1275 /* Start FCoE discovery by sending a FLOGI. */
1276 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1277 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001278 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001279 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001280 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001281
James Smart32b97932009-07-19 10:01:21 -04001282 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001283 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1284 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001285 goto fail_out;
1286
1287 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001288 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001289 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001290 phba->hba_flag &= ~FCF_TS_INPROG;
1291 if (vport->port_state != LPFC_FLOGI) {
1292 phba->hba_flag |= FCF_RR_INPROG;
1293 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001294 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001295 goto out;
1296 }
1297 spin_unlock_irq(&phba->hbalock);
1298 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001299
James Smarta93ff372010-10-22 11:06:08 -04001300fail_out:
1301 spin_lock_irq(&phba->hbalock);
1302 phba->hba_flag &= ~FCF_RR_INPROG;
1303 spin_unlock_irq(&phba->hbalock);
1304out:
James Smart6fb120a2009-05-22 14:52:59 -04001305 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001306}
1307
1308/**
1309 * lpfc_fab_name_match - Check if the fcf fabric name match.
1310 * @fab_name: pointer to fabric name.
1311 * @new_fcf_record: pointer to fcf record.
1312 *
1313 * This routine compare the fcf record's fabric name with provided
1314 * fabric name. If the fabric name are identical this function
1315 * returns 1 else return 0.
1316 **/
1317static uint32_t
1318lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1319{
James Smartecfd03c2010-02-12 14:41:27 -05001320 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001321 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001322 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1323 return 0;
1324 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1325 return 0;
1326 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1327 return 0;
1328 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1329 return 0;
1330 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1331 return 0;
1332 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1333 return 0;
1334 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1335 return 0;
1336 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001337}
1338
1339/**
James Smart8fa38512009-07-19 10:01:03 -04001340 * lpfc_sw_name_match - Check if the fcf switch name match.
Lee Jonese415f2a2020-07-23 13:24:08 +01001341 * @sw_name: pointer to switch name.
James Smart8fa38512009-07-19 10:01:03 -04001342 * @new_fcf_record: pointer to fcf record.
1343 *
1344 * This routine compare the fcf record's switch name with provided
1345 * switch name. If the switch name are identical this function
1346 * returns 1 else return 0.
1347 **/
1348static uint32_t
1349lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1350{
James Smartecfd03c2010-02-12 14:41:27 -05001351 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001352 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001353 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1354 return 0;
1355 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1356 return 0;
1357 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1358 return 0;
1359 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1360 return 0;
1361 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1362 return 0;
1363 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1364 return 0;
1365 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1366 return 0;
1367 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001368}
1369
1370/**
James Smart6fb120a2009-05-22 14:52:59 -04001371 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001372 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001373 * @new_fcf_record: pointer to fcf record.
1374 *
1375 * This routine compare the fcf record's mac address with HBA's
1376 * FCF mac address. If the mac addresses are identical this function
1377 * returns 1 else return 0.
1378 **/
1379static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001380lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001381{
James Smartecfd03c2010-02-12 14:41:27 -05001382 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001383 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001384 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1385 return 0;
1386 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1387 return 0;
1388 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1389 return 0;
1390 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1391 return 0;
1392 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1393 return 0;
1394 return 1;
1395}
1396
1397static bool
1398lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1399{
1400 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001401}
1402
1403/**
James Smart7d791df2011-07-22 18:37:52 -04001404 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1405 * @phba: pointer to lpfc hba data structure.
1406 * @fcf_index: Index for the lpfc_fcf_record.
1407 * @new_fcf_record: pointer to hba fcf record.
1408 *
1409 * This routine updates the driver FCF priority record from the new HBA FCF
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001410 * record. The hbalock is asserted held in the code path calling this
1411 * routine.
James Smart7d791df2011-07-22 18:37:52 -04001412 **/
1413static void
1414__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1415 struct fcf_record *new_fcf_record
1416 )
1417{
1418 struct lpfc_fcf_pri *fcf_pri;
1419
1420 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1421 fcf_pri->fcf_rec.fcf_index = fcf_index;
1422 /* FCF record priority */
1423 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1424
1425}
1426
1427/**
James Smart6fb120a2009-05-22 14:52:59 -04001428 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
Lee Jonese415f2a2020-07-23 13:24:08 +01001429 * @fcf_rec: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001430 * @new_fcf_record: pointer to fcf record.
1431 *
1432 * This routine copies the FCF information from the FCF
1433 * record to lpfc_hba data structure.
1434 **/
1435static void
James Smartecfd03c2010-02-12 14:41:27 -05001436lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1437 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001438{
James Smartecfd03c2010-02-12 14:41:27 -05001439 /* Fabric name */
1440 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001441 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001442 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001443 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001444 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001445 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001446 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001447 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001448 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001449 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001450 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001451 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001452 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001453 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001454 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001455 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001456 /* Mac address */
1457 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1458 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1459 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1460 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1461 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1462 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1463 /* FCF record index */
1464 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1465 /* FCF record priority */
1466 fcf_rec->priority = new_fcf_record->fip_priority;
1467 /* Switch name */
1468 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001469 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001470 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001471 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001472 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001473 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001474 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001475 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001476 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001477 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001478 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001479 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001480 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001481 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001482 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001483 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001484}
1485
1486/**
James Smartecfd03c2010-02-12 14:41:27 -05001487 * lpfc_update_fcf_record - Update driver fcf record
1488 * @phba: pointer to lpfc hba data structure.
1489 * @fcf_rec: pointer to driver fcf record.
1490 * @new_fcf_record: pointer to hba fcf record.
1491 * @addr_mode: address mode to be set to the driver fcf record.
1492 * @vlan_id: vlan tag to be set to the driver fcf record.
1493 * @flag: flag bits to be set to the driver fcf record.
1494 *
1495 * This routine updates the driver FCF record from the new HBA FCF record
1496 * together with the address mode, vlan_id, and other informations. This
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001497 * routine is called with the hbalock held.
James Smartecfd03c2010-02-12 14:41:27 -05001498 **/
1499static void
1500__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1501 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1502 uint16_t vlan_id, uint32_t flag)
1503{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001504 lockdep_assert_held(&phba->hbalock);
1505
James Smartecfd03c2010-02-12 14:41:27 -05001506 /* Copy the fields from the HBA's FCF record */
1507 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1508 /* Update other fields of driver FCF record */
1509 fcf_rec->addr_mode = addr_mode;
1510 fcf_rec->vlan_id = vlan_id;
1511 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001512 __lpfc_update_fcf_record_pri(phba,
1513 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1514 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001515}
1516
1517/**
James Smart6fb120a2009-05-22 14:52:59 -04001518 * lpfc_register_fcf - Register the FCF with hba.
1519 * @phba: pointer to lpfc hba data structure.
1520 *
1521 * This routine issues a register fcfi mailbox command to register
1522 * the fcf with HBA.
1523 **/
1524static void
1525lpfc_register_fcf(struct lpfc_hba *phba)
1526{
1527 LPFC_MBOXQ_t *fcf_mbxq;
1528 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001529
James Smartd439d282010-09-29 11:18:45 -04001530 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001531 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001532 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001533 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001534 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001535 return;
1536 }
1537
1538 /* The FCF is already registered, start discovery */
1539 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001540 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001541 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001542 if (phba->pport->port_state != LPFC_FLOGI &&
1543 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001544 phba->hba_flag |= FCF_RR_INPROG;
1545 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001546 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001547 return;
1548 }
1549 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001550 return;
1551 }
James Smartd439d282010-09-29 11:18:45 -04001552 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001553
James Smarta93ff372010-10-22 11:06:08 -04001554 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001555 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001556 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001557 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001558 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001559 return;
James Smart4d9ab992009-10-02 15:16:39 -04001560 }
James Smart6fb120a2009-05-22 14:52:59 -04001561
1562 lpfc_reg_fcfi(phba, fcf_mbxq);
1563 fcf_mbxq->vport = phba->pport;
1564 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1565 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001566 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001567 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001568 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001569 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001570 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001571 }
James Smart6fb120a2009-05-22 14:52:59 -04001572
1573 return;
1574}
1575
1576/**
1577 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1578 * @phba: pointer to lpfc hba data structure.
1579 * @new_fcf_record: pointer to fcf record.
1580 * @boot_flag: Indicates if this record used by boot bios.
1581 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001582 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001583 *
1584 * This routine compare the fcf record with connect list obtained from the
1585 * config region to decide if this FCF can be used for SAN discovery. It returns
1586 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1587 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1588 * is used by boot bios and addr_mode will indicate the addressing mode to be
1589 * used for this FCF when the function returns.
1590 * If the FCF record need to be used with a particular vlan id, the vlan is
1591 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001592 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001593 **/
1594static int
1595lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1596 struct fcf_record *new_fcf_record,
1597 uint32_t *boot_flag, uint32_t *addr_mode,
1598 uint16_t *vlan_id)
1599{
1600 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001601 int i, j, fcf_vlan_id = 0;
1602
1603 /* Find the lowest VLAN id in the FCF record */
1604 for (i = 0; i < 512; i++) {
1605 if (new_fcf_record->vlan_bitmap[i]) {
1606 fcf_vlan_id = i * 8;
1607 j = 0;
1608 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1609 j++;
1610 fcf_vlan_id++;
1611 }
1612 break;
1613 }
1614 }
James Smart6fb120a2009-05-22 14:52:59 -04001615
James Smart26979ce2012-09-29 11:31:55 -04001616 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001617 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001618 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1619 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001620 return 0;
1621
James Smart45ed1192009-10-02 15:17:02 -04001622 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001623 *boot_flag = 0;
1624 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1625 new_fcf_record);
1626 if (phba->valid_vlan)
1627 *vlan_id = phba->vlan_id;
1628 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001629 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001630 return 1;
1631 }
1632
1633 /*
1634 * If there are no FCF connection table entry, driver connect to all
1635 * FCFs.
1636 */
1637 if (list_empty(&phba->fcf_conn_rec_list)) {
1638 *boot_flag = 0;
1639 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1640 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001641
1642 /*
1643 * When there are no FCF connect entries, use driver's default
1644 * addressing mode - FPMA.
1645 */
1646 if (*addr_mode & LPFC_FCF_FPMA)
1647 *addr_mode = LPFC_FCF_FPMA;
1648
James Smart4d9ab992009-10-02 15:16:39 -04001649 /* If FCF record report a vlan id use that vlan id */
1650 if (fcf_vlan_id)
1651 *vlan_id = fcf_vlan_id;
1652 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001653 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001654 return 1;
1655 }
1656
James Smartecfd03c2010-02-12 14:41:27 -05001657 list_for_each_entry(conn_entry,
1658 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001659 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1660 continue;
1661
1662 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1663 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001664 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001665 continue;
James Smart8fa38512009-07-19 10:01:03 -04001666 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1667 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1668 new_fcf_record))
1669 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001670 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1671 /*
1672 * If the vlan bit map does not have the bit set for the
1673 * vlan id to be used, then it is not a match.
1674 */
1675 if (!(new_fcf_record->vlan_bitmap
1676 [conn_entry->conn_rec.vlan_tag / 8] &
1677 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1678 continue;
1679 }
1680
1681 /*
James Smart0c287582009-06-10 17:22:56 -04001682 * If connection record does not support any addressing mode,
1683 * skip the FCF record.
1684 */
1685 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1686 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1687 continue;
1688
1689 /*
James Smart6fb120a2009-05-22 14:52:59 -04001690 * Check if the connection record specifies a required
1691 * addressing mode.
1692 */
1693 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1694 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1695
1696 /*
1697 * If SPMA required but FCF not support this continue.
1698 */
1699 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1700 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1701 new_fcf_record) & LPFC_FCF_SPMA))
1702 continue;
1703
1704 /*
1705 * If FPMA required but FCF not support this continue.
1706 */
1707 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1708 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1709 new_fcf_record) & LPFC_FCF_FPMA))
1710 continue;
1711 }
1712
1713 /*
1714 * This fcf record matches filtering criteria.
1715 */
1716 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1717 *boot_flag = 1;
1718 else
1719 *boot_flag = 0;
1720
James Smart0c287582009-06-10 17:22:56 -04001721 /*
1722 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001723 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001724 * by FCF, allow fabric to pick the addressing mode.
1725 */
James Smart6fb120a2009-05-22 14:52:59 -04001726 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1727 new_fcf_record);
1728 /*
1729 * If the user specified a required address mode, assign that
1730 * address mode
1731 */
1732 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1733 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1734 *addr_mode = (conn_entry->conn_rec.flags &
1735 FCFCNCT_AM_SPMA) ?
1736 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1737 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001738 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001739 * addr mode only if FCF support the addr_mode.
1740 */
1741 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1742 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1743 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1744 (*addr_mode & LPFC_FCF_SPMA))
1745 *addr_mode = LPFC_FCF_SPMA;
1746 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1747 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1748 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1749 (*addr_mode & LPFC_FCF_FPMA))
1750 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001751
James Smart4d9ab992009-10-02 15:16:39 -04001752 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001753 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1754 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001755 /*
1756 * If no vlan id is specified in connect list, use the vlan id
1757 * in the FCF record
1758 */
1759 else if (fcf_vlan_id)
1760 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001761 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001762 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001763
1764 return 1;
1765 }
1766
1767 return 0;
1768}
1769
1770/**
James Smart32b97932009-07-19 10:01:21 -04001771 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1772 * @phba: pointer to lpfc hba data structure.
1773 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1774 *
1775 * This function check if there is any fcoe event pending while driver
1776 * scan FCF entries. If there is any pending event, it will restart the
1777 * FCF saning and return 1 else return 0.
1778 */
1779int
1780lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1781{
James Smart32b97932009-07-19 10:01:21 -04001782 /*
1783 * If the Link is up and no FCoE events while in the
1784 * FCF discovery, no need to restart FCF discovery.
1785 */
1786 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001787 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001788 return 0;
1789
James Smart0c9ab6f2010-02-26 14:15:57 -05001790 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1791 "2768 Pending link or FCF event during current "
1792 "handling of the previous event: link_state:x%x, "
1793 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1794 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1795 phba->fcoe_eventtag);
1796
James Smart32b97932009-07-19 10:01:21 -04001797 spin_lock_irq(&phba->hbalock);
1798 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1799 spin_unlock_irq(&phba->hbalock);
1800
James Smart0c9ab6f2010-02-26 14:15:57 -05001801 if (phba->link_state >= LPFC_LINK_UP) {
1802 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1803 "2780 Restart FCF table scan due to "
1804 "pending FCF event:evt_tag_at_scan:x%x, "
1805 "evt_tag_current:x%x\n",
1806 phba->fcoe_eventtag_at_fcf_scan,
1807 phba->fcoe_eventtag);
1808 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1809 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001810 /*
James Smarta93ff372010-10-22 11:06:08 -04001811 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001812 * flag
1813 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001814 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1815 "2833 Stop FCF discovery process due to link "
1816 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001817 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001818 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001819 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001820 spin_unlock_irq(&phba->hbalock);
1821 }
James Smart32b97932009-07-19 10:01:21 -04001822
James Smart0c9ab6f2010-02-26 14:15:57 -05001823 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001824 if (unreg_fcf) {
1825 spin_lock_irq(&phba->hbalock);
1826 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1827 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001828 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001829 }
James Smart32b97932009-07-19 10:01:21 -04001830 return 1;
1831}
1832
1833/**
James Smart999d8132010-03-15 11:24:56 -04001834 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1835 * @phba: pointer to lpfc hba data structure.
1836 * @fcf_cnt: number of eligible fcf record seen so far.
1837 *
1838 * This function makes an running random selection decision on FCF record to
1839 * use through a sequence of @fcf_cnt eligible FCF records with equal
1840 * probability. To perform integer manunipulation of random numbers with
1841 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001842 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001843 *
1844 * Returns true when outcome is for the newly read FCF record should be
1845 * chosen; otherwise, return false when outcome is for keeping the previously
1846 * chosen FCF record.
1847 **/
1848static bool
1849lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1850{
1851 uint32_t rand_num;
1852
1853 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001854 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001855
1856 /* Decision with probability 1/fcf_cnt */
1857 if ((fcf_cnt * rand_num) < 0xFFFF)
1858 return true;
1859 else
1860 return false;
1861}
1862
1863/**
James Smart3804dc82010-07-14 15:31:37 -04001864 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001865 * @phba: pointer to lpfc hba data structure.
1866 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001867 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001868 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001869 * This routine parses the non-embedded fcf mailbox command by performing the
1870 * necessarily error checking, non-embedded read FCF record mailbox command
1871 * SGE parsing, and endianness swapping.
1872 *
1873 * Returns the pointer to the new FCF record in the non-embedded mailbox
1874 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001875 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001876static struct fcf_record *
1877lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1878 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001879{
1880 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001881 struct lpfc_mbx_sge sge;
1882 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001883 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001884 union lpfc_sli4_cfg_shdr *shdr;
1885 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001886
James Smart6fb120a2009-05-22 14:52:59 -04001887 /* Get the first SGE entry from the non-embedded DMA memory. This
1888 * routine only uses a single SGE.
1889 */
1890 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001891 if (unlikely(!mboxq->sge_array)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001892 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04001893 "2524 Failed to get the non-embedded SGE "
1894 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001895 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001896 }
1897 virt_addr = mboxq->sge_array->addr[0];
1898
1899 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001900 lpfc_sli_pcimem_bcopy(shdr, shdr,
1901 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001902 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001903 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001904 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001905 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001906 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1907 if_type == LPFC_SLI_INTF_IF_TYPE_2)
Dick Kennedy372c1872020-06-30 14:50:00 -07001908 lpfc_printf_log(phba, KERN_ERR,
1909 LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05001910 "2726 READ_FCF_RECORD Indicates empty "
1911 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001912 else
Dick Kennedy372c1872020-06-30 14:50:00 -07001913 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05001914 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001915 "with status x%x add_status x%x, "
1916 "mbx\n", shdr_status, shdr_add_status);
1917 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001918 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001919
1920 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001921 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1922 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1923 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001924 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001925 new_fcf_record = (struct fcf_record *)(virt_addr +
1926 sizeof(struct lpfc_mbx_read_fcf_tbl));
1927 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001928 offsetof(struct fcf_record, vlan_bitmap));
1929 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1930 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001931
James Smart0c9ab6f2010-02-26 14:15:57 -05001932 return new_fcf_record;
1933}
1934
1935/**
1936 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1937 * @phba: pointer to lpfc hba data structure.
1938 * @fcf_record: pointer to the fcf record.
1939 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1940 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1941 *
1942 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1943 * enabled.
1944 **/
1945static void
1946lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1947 struct fcf_record *fcf_record,
1948 uint16_t vlan_id,
1949 uint16_t next_fcf_index)
1950{
1951 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1952 "2764 READ_FCF_RECORD:\n"
1953 "\tFCF_Index : x%x\n"
1954 "\tFCF_Avail : x%x\n"
1955 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001956 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001957 "\tFIP_Priority : x%x\n"
1958 "\tMAC_Provider : x%x\n"
1959 "\tLowest VLANID : x%x\n"
1960 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1961 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1962 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1963 "\tNext_FCF_Index: x%x\n",
1964 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1965 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1966 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001967 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001968 fcf_record->fip_priority,
1969 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1970 vlan_id,
1971 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1972 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1973 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1974 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1975 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1976 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1977 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1978 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1979 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1980 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1981 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1982 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1983 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1984 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1985 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1986 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1987 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1988 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1989 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1990 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1991 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1992 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1993 next_fcf_index);
1994}
1995
1996/**
Lee Jonese415f2a2020-07-23 13:24:08 +01001997 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
James Smartdbb6b3a2010-06-08 18:31:37 -04001998 * @phba: pointer to lpfc hba data structure.
1999 * @fcf_rec: pointer to an existing FCF record.
2000 * @new_fcf_record: pointer to a new FCF record.
2001 * @new_vlan_id: vlan id from the new FCF record.
2002 *
2003 * This function performs matching test of a new FCF record against an existing
2004 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2005 * will not be used as part of the FCF record matching criteria.
2006 *
2007 * Returns true if all the fields matching, otherwise returns false.
2008 */
2009static bool
2010lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2011 struct lpfc_fcf_rec *fcf_rec,
2012 struct fcf_record *new_fcf_record,
2013 uint16_t new_vlan_id)
2014{
2015 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2016 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2017 return false;
2018 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2019 return false;
2020 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2021 return false;
2022 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2023 return false;
James Smart7d791df2011-07-22 18:37:52 -04002024 if (fcf_rec->priority != new_fcf_record->fip_priority)
2025 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04002026 return true;
2027}
2028
2029/**
James Smarta93ff372010-10-22 11:06:08 -04002030 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2031 * @vport: Pointer to vport object.
2032 * @fcf_index: index to next fcf.
2033 *
2034 * This function processing the roundrobin fcf failover to next fcf index.
2035 * When this function is invoked, there will be a current fcf registered
2036 * for flogi.
2037 * Return: 0 for continue retrying flogi on currently registered fcf;
2038 * 1 for stop flogi on currently registered fcf;
2039 */
2040int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2041{
2042 struct lpfc_hba *phba = vport->phba;
2043 int rc;
2044
2045 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2046 spin_lock_irq(&phba->hbalock);
2047 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2048 spin_unlock_irq(&phba->hbalock);
2049 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2050 "2872 Devloss tmo with no eligible "
2051 "FCF, unregister in-use FCF (x%x) "
2052 "and rescan FCF table\n",
2053 phba->fcf.current_rec.fcf_indx);
2054 lpfc_unregister_fcf_rescan(phba);
2055 goto stop_flogi_current_fcf;
2056 }
2057 /* Mark the end to FLOGI roundrobin failover */
2058 phba->hba_flag &= ~FCF_RR_INPROG;
2059 /* Allow action to new fcf asynchronous event */
2060 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2061 spin_unlock_irq(&phba->hbalock);
2062 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2063 "2865 No FCF available, stop roundrobin FCF "
2064 "failover and change port state:x%x/x%x\n",
2065 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2066 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002067
2068 if (!phba->fcf.fcf_redisc_attempted) {
2069 lpfc_unregister_fcf(phba);
2070
2071 rc = lpfc_sli4_redisc_fcf_table(phba);
2072 if (!rc) {
2073 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2074 "3195 Rediscover FCF table\n");
2075 phba->fcf.fcf_redisc_attempted = 1;
2076 lpfc_sli4_clear_fcf_rr_bmask(phba);
2077 } else {
2078 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2079 "3196 Rediscover FCF table "
2080 "failed. Status:x%x\n", rc);
2081 }
2082 } else {
2083 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2084 "3197 Already rediscover FCF table "
2085 "attempted. No more retry\n");
2086 }
James Smarta93ff372010-10-22 11:06:08 -04002087 goto stop_flogi_current_fcf;
2088 } else {
2089 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2090 "2794 Try FLOGI roundrobin FCF failover to "
2091 "(x%x)\n", fcf_index);
2092 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2093 if (rc)
2094 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2095 "2761 FLOGI roundrobin FCF failover "
2096 "failed (rc:x%x) to read FCF (x%x)\n",
2097 rc, phba->fcf.current_rec.fcf_indx);
2098 else
2099 goto stop_flogi_current_fcf;
2100 }
2101 return 0;
2102
2103stop_flogi_current_fcf:
2104 lpfc_can_disctmo(vport);
2105 return 1;
2106}
2107
2108/**
James Smart7d791df2011-07-22 18:37:52 -04002109 * lpfc_sli4_fcf_pri_list_del
2110 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002111 * @fcf_index: the index of the fcf record to delete
James Smart7d791df2011-07-22 18:37:52 -04002112 * This routine checks the on list flag of the fcf_index to be deleted.
2113 * If it is one the list then it is removed from the list, and the flag
2114 * is cleared. This routine grab the hbalock before removing the fcf
2115 * record from the list.
2116 **/
2117static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2118 uint16_t fcf_index)
2119{
2120 struct lpfc_fcf_pri *new_fcf_pri;
2121
2122 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2123 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2124 "3058 deleting idx x%x pri x%x flg x%x\n",
2125 fcf_index, new_fcf_pri->fcf_rec.priority,
2126 new_fcf_pri->fcf_rec.flag);
2127 spin_lock_irq(&phba->hbalock);
2128 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2129 if (phba->fcf.current_rec.priority ==
2130 new_fcf_pri->fcf_rec.priority)
2131 phba->fcf.eligible_fcf_cnt--;
2132 list_del_init(&new_fcf_pri->list);
2133 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2134 }
2135 spin_unlock_irq(&phba->hbalock);
2136}
2137
2138/**
2139 * lpfc_sli4_set_fcf_flogi_fail
2140 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002141 * @fcf_index: the index of the fcf record to update
James Smart7d791df2011-07-22 18:37:52 -04002142 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2143 * flag so the the round robin slection for the particular priority level
2144 * will try a different fcf record that does not have this bit set.
2145 * If the fcf record is re-read for any reason this flag is cleared brfore
2146 * adding it to the priority list.
2147 **/
2148void
2149lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2150{
2151 struct lpfc_fcf_pri *new_fcf_pri;
2152 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2153 spin_lock_irq(&phba->hbalock);
2154 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2155 spin_unlock_irq(&phba->hbalock);
2156}
2157
2158/**
2159 * lpfc_sli4_fcf_pri_list_add
2160 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002161 * @fcf_index: the index of the fcf record to add
2162 * @new_fcf_record: pointer to a new FCF record.
James Smart7d791df2011-07-22 18:37:52 -04002163 * This routine checks the priority of the fcf_index to be added.
2164 * If it is a lower priority than the current head of the fcf_pri list
2165 * then it is added to the list in the right order.
2166 * If it is the same priority as the current head of the list then it
2167 * is added to the head of the list and its bit in the rr_bmask is set.
2168 * If the fcf_index to be added is of a higher priority than the current
2169 * head of the list then the rr_bmask is cleared, its bit is set in the
2170 * rr_bmask and it is added to the head of the list.
2171 * returns:
2172 * 0=success 1=failure
2173 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002174static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2175 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002176 struct fcf_record *new_fcf_record)
2177{
2178 uint16_t current_fcf_pri;
2179 uint16_t last_index;
2180 struct lpfc_fcf_pri *fcf_pri;
2181 struct lpfc_fcf_pri *next_fcf_pri;
2182 struct lpfc_fcf_pri *new_fcf_pri;
2183 int ret;
2184
2185 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2186 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2187 "3059 adding idx x%x pri x%x flg x%x\n",
2188 fcf_index, new_fcf_record->fip_priority,
2189 new_fcf_pri->fcf_rec.flag);
2190 spin_lock_irq(&phba->hbalock);
2191 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2192 list_del_init(&new_fcf_pri->list);
2193 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2194 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2195 if (list_empty(&phba->fcf.fcf_pri_list)) {
2196 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2197 ret = lpfc_sli4_fcf_rr_index_set(phba,
2198 new_fcf_pri->fcf_rec.fcf_index);
2199 goto out;
2200 }
2201
2202 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2203 LPFC_SLI4_FCF_TBL_INDX_MAX);
2204 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2205 ret = 0; /* Empty rr list */
2206 goto out;
2207 }
2208 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2209 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2210 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2211 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2212 memset(phba->fcf.fcf_rr_bmask, 0,
2213 sizeof(*phba->fcf.fcf_rr_bmask));
2214 /* fcfs_at_this_priority_level = 1; */
2215 phba->fcf.eligible_fcf_cnt = 1;
2216 } else
2217 /* fcfs_at_this_priority_level++; */
2218 phba->fcf.eligible_fcf_cnt++;
2219 ret = lpfc_sli4_fcf_rr_index_set(phba,
2220 new_fcf_pri->fcf_rec.fcf_index);
2221 goto out;
2222 }
2223
2224 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2225 &phba->fcf.fcf_pri_list, list) {
2226 if (new_fcf_pri->fcf_rec.priority <=
2227 fcf_pri->fcf_rec.priority) {
2228 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2229 list_add(&new_fcf_pri->list,
2230 &phba->fcf.fcf_pri_list);
2231 else
2232 list_add(&new_fcf_pri->list,
2233 &((struct lpfc_fcf_pri *)
2234 fcf_pri->list.prev)->list);
2235 ret = 0;
2236 goto out;
2237 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2238 || new_fcf_pri->fcf_rec.priority <
2239 next_fcf_pri->fcf_rec.priority) {
2240 list_add(&new_fcf_pri->list, &fcf_pri->list);
2241 ret = 0;
2242 goto out;
2243 }
2244 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2245 continue;
2246
2247 }
2248 ret = 1;
2249out:
2250 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2251 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2252 spin_unlock_irq(&phba->hbalock);
2253 return ret;
2254}
2255
2256/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002257 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2258 * @phba: pointer to lpfc hba data structure.
2259 * @mboxq: pointer to mailbox object.
2260 *
2261 * This function iterates through all the fcf records available in
2262 * HBA and chooses the optimal FCF record for discovery. After finding
2263 * the FCF for discovery it registers the FCF record and kicks start
2264 * discovery.
2265 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2266 * use an FCF record which matches fabric name and mac address of the
2267 * currently used FCF record.
2268 * If the driver supports only one FCF, it will try to use the FCF record
2269 * used by BOOT_BIOS.
2270 */
2271void
2272lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2273{
2274 struct fcf_record *new_fcf_record;
2275 uint32_t boot_flag, addr_mode;
2276 uint16_t fcf_index, next_fcf_index;
2277 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002278 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002279 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002280 int rc;
2281
2282 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002283 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002284 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2285 return;
2286 }
2287
2288 /* Parse the FCF record from the non-embedded mailbox command */
2289 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2290 &next_fcf_index);
2291 if (!new_fcf_record) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002292 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05002293 "2765 Mailbox command READ_FCF_RECORD "
2294 "failed to retrieve a FCF record.\n");
2295 /* Let next new FCF event trigger fast failover */
2296 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002297 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002298 spin_unlock_irq(&phba->hbalock);
2299 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2300 return;
2301 }
2302
2303 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002304 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2305 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002306
2307 /* Log the FCF record information if turned on */
2308 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2309 next_fcf_index);
2310
James Smart6fb120a2009-05-22 14:52:59 -04002311 /*
2312 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002313 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002314 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002315 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002316 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002317 lpfc_sli4_fcf_pri_list_del(phba,
2318 bf_get(lpfc_fcf_record_fcf_index,
2319 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002320 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002321 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002322 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002323 bf_get(lpfc_fcf_record_fcf_index,
2324 new_fcf_record),
2325 bf_get(lpfc_fcf_record_fcf_avail,
2326 new_fcf_record),
2327 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002328 new_fcf_record),
2329 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002330 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002331 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2332 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2333 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002334 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2335 phba->fcf.current_rec.fcf_indx) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002336 lpfc_printf_log(phba, KERN_ERR,
2337 LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002338 "2862 FCF (x%x) matches property "
2339 "of in-use FCF (x%x)\n",
2340 bf_get(lpfc_fcf_record_fcf_index,
2341 new_fcf_record),
2342 phba->fcf.current_rec.fcf_indx);
2343 goto read_next_fcf;
2344 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002345 /*
2346 * In case the current in-use FCF record becomes
2347 * invalid/unavailable during FCF discovery that
2348 * was not triggered by fast FCF failover process,
2349 * treat it as fast FCF failover.
2350 */
2351 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2352 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2353 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2354 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002355 "(x%x), enter FCF failover "
2356 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002357 phba->fcf.current_rec.fcf_indx);
2358 spin_lock_irq(&phba->hbalock);
2359 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2360 spin_unlock_irq(&phba->hbalock);
2361 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2362 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2363 LPFC_FCOE_FCF_GET_FIRST);
2364 return;
2365 }
2366 }
James Smart6fb120a2009-05-22 14:52:59 -04002367 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002368 } else {
2369 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002370 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2371 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002372 if (rc)
2373 goto read_next_fcf;
2374 }
2375
James Smart6fb120a2009-05-22 14:52:59 -04002376 /*
2377 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002378 * FCF record for the discovery. The condition that a rescan
2379 * matches the in-use FCF record: fabric name, switch name, mac
2380 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002381 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002382 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002383 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002384 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2385 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002386 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002387 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2388 phba->fcf.current_rec.fcf_indx) {
2389 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2390 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2391 /* Stop FCF redisc wait timer */
2392 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2393 phba);
2394 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2395 /* Fast failover, mark completed */
2396 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2397 spin_unlock_irq(&phba->hbalock);
2398 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2399 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002400 "FCF (x%x), port_state:x%x, "
2401 "fc_flag:x%x\n",
2402 phba->fcf.current_rec.fcf_indx,
2403 phba->pport->port_state,
2404 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002405 goto out;
2406 } else
Dick Kennedy372c1872020-06-30 14:50:00 -07002407 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002408 "2863 New FCF (x%x) matches "
2409 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002410 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002411 new_fcf_record),
2412 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002413 }
James Smartecfd03c2010-02-12 14:41:27 -05002414 /*
2415 * Read next FCF record from HBA searching for the matching
2416 * with in-use record only if not during the fast failover
2417 * period. In case of fast failover period, it shall try to
2418 * determine whether the FCF record just read should be the
2419 * next candidate.
2420 */
2421 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002422 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002423 goto read_next_fcf;
2424 }
James Smart6fb120a2009-05-22 14:52:59 -04002425 }
James Smartecfd03c2010-02-12 14:41:27 -05002426 /*
2427 * Update on failover FCF record only if it's in FCF fast-failover
2428 * period; otherwise, update on current FCF record.
2429 */
James Smartfc2b9892010-02-26 14:15:29 -05002430 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2431 fcf_rec = &phba->fcf.failover_rec;
2432 else
James Smartecfd03c2010-02-12 14:41:27 -05002433 fcf_rec = &phba->fcf.current_rec;
2434
James Smart6fb120a2009-05-22 14:52:59 -04002435 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2436 /*
James Smartecfd03c2010-02-12 14:41:27 -05002437 * If the driver FCF record does not have boot flag
2438 * set and new hba fcf record has boot flag set, use
2439 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002440 */
James Smartecfd03c2010-02-12 14:41:27 -05002441 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2442 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002443 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2444 "2837 Update current FCF record "
2445 "(x%x) with new FCF record (x%x)\n",
2446 fcf_rec->fcf_indx,
2447 bf_get(lpfc_fcf_record_fcf_index,
2448 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002449 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2450 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002451 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002452 goto read_next_fcf;
2453 }
2454 /*
James Smartecfd03c2010-02-12 14:41:27 -05002455 * If the driver FCF record has boot flag set and the
2456 * new hba FCF record does not have boot flag, read
2457 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002458 */
James Smartecfd03c2010-02-12 14:41:27 -05002459 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002460 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002461 goto read_next_fcf;
2462 }
2463 /*
James Smartecfd03c2010-02-12 14:41:27 -05002464 * If the new hba FCF record has lower priority value
2465 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002466 */
James Smartfc2b9892010-02-26 14:15:29 -05002467 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002468 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002469 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2470 "2838 Update current FCF record "
2471 "(x%x) with new FCF record (x%x)\n",
2472 fcf_rec->fcf_indx,
2473 bf_get(lpfc_fcf_record_fcf_index,
2474 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002475 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2476 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002477 /* Reset running random FCF selection count */
2478 phba->fcf.eligible_fcf_cnt = 1;
2479 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2480 /* Update running random FCF selection count */
2481 phba->fcf.eligible_fcf_cnt++;
2482 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2483 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002484 if (select_new_fcf) {
2485 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2486 "2839 Update current FCF record "
2487 "(x%x) with new FCF record (x%x)\n",
2488 fcf_rec->fcf_indx,
2489 bf_get(lpfc_fcf_record_fcf_index,
2490 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002491 /* Choose the new FCF by random selection */
2492 __lpfc_update_fcf_record(phba, fcf_rec,
2493 new_fcf_record,
2494 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002495 }
James Smart6fb120a2009-05-22 14:52:59 -04002496 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002497 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002498 goto read_next_fcf;
2499 }
2500 /*
James Smartecfd03c2010-02-12 14:41:27 -05002501 * This is the first suitable FCF record, choose this record for
2502 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002503 */
James Smartecfd03c2010-02-12 14:41:27 -05002504 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002505 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002506 "2840 Update initial FCF candidate "
2507 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002508 bf_get(lpfc_fcf_record_fcf_index,
2509 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002510 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2511 addr_mode, vlan_id, (boot_flag ?
2512 BOOT_ENABLE : 0));
2513 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002514 /* Setup initial running random FCF selection count */
2515 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002516 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002517 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002518 goto read_next_fcf;
2519
2520read_next_fcf:
2521 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002522 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2523 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2524 /*
2525 * Case of FCF fast failover scan
2526 */
2527
2528 /*
2529 * It has not found any suitable FCF record, cancel
2530 * FCF scan inprogress, and do nothing
2531 */
2532 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002533 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002534 "2782 No suitable FCF found: "
2535 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002536 phba->fcoe_eventtag_at_fcf_scan,
2537 bf_get(lpfc_fcf_record_fcf_index,
2538 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002539 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002540 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2541 phba->hba_flag &= ~FCF_TS_INPROG;
2542 spin_unlock_irq(&phba->hbalock);
2543 /* Unregister in-use FCF and rescan */
2544 lpfc_printf_log(phba, KERN_INFO,
2545 LOG_FIP,
2546 "2864 On devloss tmo "
2547 "unreg in-use FCF and "
2548 "rescan FCF table\n");
2549 lpfc_unregister_fcf_rescan(phba);
2550 return;
2551 }
2552 /*
2553 * Let next new FCF event trigger fast failover
2554 */
2555 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002556 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002557 return;
2558 }
2559 /*
2560 * It has found a suitable FCF record that is not
2561 * the same as in-use FCF record, unregister the
2562 * in-use FCF record, replace the in-use FCF record
2563 * with the new FCF record, mark FCF fast failover
2564 * completed, and then start register the new FCF
2565 * record.
2566 */
2567
James Smart0c9ab6f2010-02-26 14:15:57 -05002568 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002569 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002570
2571 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002572 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002573 "2842 Replace in-use FCF (x%x) "
2574 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002575 phba->fcf.current_rec.fcf_indx,
2576 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002577 memcpy(&phba->fcf.current_rec,
2578 &phba->fcf.failover_rec,
2579 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002580 /*
2581 * Mark the fast FCF failover rediscovery completed
2582 * and the start of the first round of the roundrobin
2583 * FCF failover.
2584 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002585 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002586 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002587 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002588 /* Register to the new FCF record */
2589 lpfc_register_fcf(phba);
2590 } else {
2591 /*
2592 * In case of transaction period to fast FCF failover,
2593 * do nothing when search to the end of the FCF table.
2594 */
2595 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2596 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2597 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002598
James Smart7d791df2011-07-22 18:37:52 -04002599 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2600 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002601 /*
2602 * In case the current in-use FCF record no
2603 * longer existed during FCF discovery that
2604 * was not triggered by fast FCF failover
2605 * process, treat it as fast FCF failover.
2606 */
2607 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2608 "2841 In-use FCF record (x%x) "
2609 "not reported, entering fast "
2610 "FCF failover mode scanning.\n",
2611 phba->fcf.current_rec.fcf_indx);
2612 spin_lock_irq(&phba->hbalock);
2613 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2614 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002615 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2616 LPFC_FCOE_FCF_GET_FIRST);
2617 return;
2618 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002619 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002620 lpfc_register_fcf(phba);
2621 }
2622 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002623 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002624 return;
2625
2626out:
2627 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2628 lpfc_register_fcf(phba);
2629
2630 return;
2631}
2632
2633/**
James Smarta93ff372010-10-22 11:06:08 -04002634 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002635 * @phba: pointer to lpfc hba data structure.
2636 * @mboxq: pointer to mailbox object.
2637 *
James Smarta93ff372010-10-22 11:06:08 -04002638 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002639 * read FCF record mailbox command from the eligible FCF record bmask for
2640 * performing the failover. If the FCF read back is not valid/available, it
2641 * fails through to retrying FLOGI to the currently registered FCF again.
2642 * Otherwise, if the FCF read back is valid and available, it will set the
2643 * newly read FCF record to the failover FCF record, unregister currently
2644 * registered FCF record, copy the failover FCF record to the current
2645 * FCF record, and then register the current FCF record before proceeding
2646 * to trying FLOGI on the new failover FCF.
2647 */
2648void
2649lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2650{
2651 struct fcf_record *new_fcf_record;
2652 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002653 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002654 uint16_t current_fcf_index;
2655 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002656 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002657
James Smarta93ff372010-10-22 11:06:08 -04002658 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002659 if (phba->link_state < LPFC_LINK_UP) {
2660 spin_lock_irq(&phba->hbalock);
2661 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002662 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002663 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002664 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002665 }
2666
2667 /* Parse the FCF record from the non-embedded mailbox command */
2668 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2669 &next_fcf_index);
2670 if (!new_fcf_record) {
2671 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2672 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002673 "failed to retrieve a FCF record. "
2674 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2675 phba->fcf.fcf_flag);
2676 lpfc_unregister_fcf_rescan(phba);
2677 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002678 }
2679
2680 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002681 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2682 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002683
2684 /* Log the FCF record information if turned on */
2685 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2686 next_fcf_index);
2687
James Smarta93ff372010-10-22 11:06:08 -04002688 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2689 if (!rc) {
2690 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2691 "2848 Remove ineligible FCF (x%x) from "
2692 "from roundrobin bmask\n", fcf_index);
2693 /* Clear roundrobin bmask bit for ineligible FCF */
2694 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2695 /* Perform next round of roundrobin FCF failover */
2696 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2697 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2698 if (rc)
2699 goto out;
2700 goto error_out;
2701 }
2702
2703 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2704 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2705 "2760 Perform FLOGI roundrobin FCF failover: "
2706 "FCF (x%x) back to FCF (x%x)\n",
2707 phba->fcf.current_rec.fcf_indx, fcf_index);
2708 /* Wait 500 ms before retrying FLOGI to current FCF */
2709 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002710 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002711 goto out;
2712 }
2713
James Smart0c9ab6f2010-02-26 14:15:57 -05002714 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002715 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002716 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2717 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002718 spin_lock_irq(&phba->hbalock);
2719 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2720 new_fcf_record, addr_mode, vlan_id,
2721 (boot_flag ? BOOT_ENABLE : 0));
2722 spin_unlock_irq(&phba->hbalock);
2723
2724 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2725
2726 /* Unregister the current in-use FCF record */
2727 lpfc_unregister_fcf(phba);
2728
2729 /* Replace in-use record with the new record */
2730 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2731 sizeof(struct lpfc_fcf_rec));
2732
2733 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002734 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2735 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002736
James Smarta93ff372010-10-22 11:06:08 -04002737error_out:
2738 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002739out:
2740 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002741}
2742
2743/**
2744 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2745 * @phba: pointer to lpfc hba data structure.
2746 * @mboxq: pointer to mailbox object.
2747 *
2748 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002749 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002750 * failover when a new FCF event happened. If the FCF read back is
2751 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002752 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002753 */
2754void
2755lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2756{
2757 struct fcf_record *new_fcf_record;
2758 uint32_t boot_flag, addr_mode;
2759 uint16_t fcf_index, next_fcf_index;
2760 uint16_t vlan_id;
2761 int rc;
2762
2763 /* If link state is not up, no need to proceed */
2764 if (phba->link_state < LPFC_LINK_UP)
2765 goto out;
2766
2767 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002768 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002769 goto out;
2770
2771 /* Parse the FCF record from the non-embedded mailbox command */
2772 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2773 &next_fcf_index);
2774 if (!new_fcf_record) {
2775 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2776 "2767 Mailbox command READ_FCF_RECORD "
2777 "failed to retrieve a FCF record.\n");
2778 goto out;
2779 }
2780
2781 /* Check the connection list for eligibility */
2782 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2783 &addr_mode, &vlan_id);
2784
2785 /* Log the FCF record information if turned on */
2786 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2787 next_fcf_index);
2788
2789 if (!rc)
2790 goto out;
2791
2792 /* Update the eligible FCF record index bmask */
2793 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002794
2795 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002796
2797out:
2798 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2799}
2800
2801/**
James Smart76a95d72010-11-20 23:11:48 -05002802 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2803 * @phba: pointer to lpfc hba data structure.
2804 * @mboxq: pointer to mailbox data structure.
2805 *
2806 * This function handles completion of init vfi mailbox command.
2807 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002808static void
James Smart76a95d72010-11-20 23:11:48 -05002809lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2810{
2811 struct lpfc_vport *vport = mboxq->vport;
2812
James Smartdf9e1b52011-12-13 13:22:17 -05002813 /*
2814 * VFI not supported on interface type 0, just do the flogi
2815 * Also continue if the VFI is in use - just use the same one.
2816 */
2817 if (mboxq->u.mb.mbxStatus &&
2818 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2819 LPFC_SLI_INTF_IF_TYPE_0) &&
2820 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002821 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2822 "2891 Init VFI mailbox failed 0x%x\n",
2823 mboxq->u.mb.mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -05002824 mempool_free(mboxq, phba->mbox_mem_pool);
2825 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2826 return;
2827 }
James Smart73d91e52011-10-10 21:32:10 -04002828
James Smart76a95d72010-11-20 23:11:48 -05002829 lpfc_initial_flogi(vport);
2830 mempool_free(mboxq, phba->mbox_mem_pool);
2831 return;
2832}
2833
2834/**
2835 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2836 * @vport: pointer to lpfc_vport data structure.
2837 *
2838 * This function issue a init_vfi mailbox command to initialize the VFI and
2839 * VPI for the physical port.
2840 */
2841void
2842lpfc_issue_init_vfi(struct lpfc_vport *vport)
2843{
2844 LPFC_MBOXQ_t *mboxq;
2845 int rc;
2846 struct lpfc_hba *phba = vport->phba;
2847
2848 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2849 if (!mboxq) {
2850 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002851 LOG_TRACE_EVENT, "2892 Failed to allocate "
James Smart76a95d72010-11-20 23:11:48 -05002852 "init_vfi mailbox\n");
2853 return;
2854 }
2855 lpfc_init_vfi(mboxq, vport);
2856 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2857 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2858 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002859 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2860 "2893 Failed to issue init_vfi mailbox\n");
James Smart76a95d72010-11-20 23:11:48 -05002861 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2862 }
2863}
2864
2865/**
James Smart1c6834a2009-07-19 10:01:26 -04002866 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2867 * @phba: pointer to lpfc hba data structure.
2868 * @mboxq: pointer to mailbox data structure.
2869 *
2870 * This function handles completion of init vpi mailbox command.
2871 */
James Smart695a8142010-01-26 23:08:03 -05002872void
James Smart1c6834a2009-07-19 10:01:26 -04002873lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2874{
2875 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002876 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002877 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2878
James Smart1c6834a2009-07-19 10:01:26 -04002879 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002880 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2881 "2609 Init VPI mailbox failed 0x%x\n",
2882 mboxq->u.mb.mbxStatus);
James Smart1c6834a2009-07-19 10:01:26 -04002883 mempool_free(mboxq, phba->mbox_mem_pool);
2884 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2885 return;
2886 }
James Smart72100cc2010-02-12 14:43:01 -05002887 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002888 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002889 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002890
James Smart695a8142010-01-26 23:08:03 -05002891 /* If this port is physical port or FDISC is done, do reg_vpi */
2892 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2893 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2894 if (!ndlp)
2895 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002896 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -05002897 "2731 Cannot find fabric "
2898 "controller node\n");
2899 else
2900 lpfc_register_new_vport(phba, vport, ndlp);
2901 mempool_free(mboxq, phba->mbox_mem_pool);
2902 return;
2903 }
2904
James Smart1c6834a2009-07-19 10:01:26 -04002905 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2906 lpfc_initial_fdisc(vport);
2907 else {
2908 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
Dick Kennedy372c1872020-06-30 14:50:00 -07002909 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6a9c52c2009-10-02 15:16:51 -04002910 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002911 }
James Smart695a8142010-01-26 23:08:03 -05002912 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002913 return;
2914}
2915
2916/**
James Smartecfd03c2010-02-12 14:41:27 -05002917 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2918 * @vport: pointer to lpfc_vport data structure.
2919 *
2920 * This function issue a init_vpi mailbox command to initialize
2921 * VPI for the vport.
2922 */
2923void
2924lpfc_issue_init_vpi(struct lpfc_vport *vport)
2925{
2926 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002927 int rc, vpi;
2928
2929 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2930 vpi = lpfc_alloc_vpi(vport->phba);
2931 if (!vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002932 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart16a3a202013-04-17 20:14:38 -04002933 "3303 Failed to obtain vport vpi\n");
2934 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2935 return;
2936 }
2937 vport->vpi = vpi;
2938 }
James Smartecfd03c2010-02-12 14:41:27 -05002939
2940 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2941 if (!mboxq) {
2942 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002943 LOG_TRACE_EVENT, "2607 Failed to allocate "
James Smartecfd03c2010-02-12 14:41:27 -05002944 "init_vpi mailbox\n");
2945 return;
2946 }
2947 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2948 mboxq->vport = vport;
2949 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2950 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2951 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002952 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2953 "2608 Failed to issue init_vpi mailbox\n");
James Smartecfd03c2010-02-12 14:41:27 -05002954 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2955 }
2956}
2957
2958/**
James Smart6fb120a2009-05-22 14:52:59 -04002959 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2960 * @phba: pointer to lpfc hba data structure.
2961 *
2962 * This function loops through the list of vports on the @phba and issues an
2963 * FDISC if possible.
2964 */
2965void
2966lpfc_start_fdiscs(struct lpfc_hba *phba)
2967{
2968 struct lpfc_vport **vports;
2969 int i;
2970
2971 vports = lpfc_create_vport_work_array(phba);
2972 if (vports != NULL) {
2973 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2974 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2975 continue;
2976 /* There are no vpi for this vport */
2977 if (vports[i]->vpi > phba->max_vpi) {
2978 lpfc_vport_set_state(vports[i],
2979 FC_VPORT_FAILED);
2980 continue;
2981 }
James Smart76a95d72010-11-20 23:11:48 -05002982 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002983 lpfc_vport_set_state(vports[i],
2984 FC_VPORT_LINKDOWN);
2985 continue;
2986 }
James Smart1c6834a2009-07-19 10:01:26 -04002987 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002988 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002989 continue;
2990 }
James Smart6fb120a2009-05-22 14:52:59 -04002991 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2992 lpfc_initial_fdisc(vports[i]);
2993 else {
2994 lpfc_vport_set_state(vports[i],
2995 FC_VPORT_NO_FABRIC_SUPP);
2996 lpfc_printf_vlog(vports[i], KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07002997 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04002998 "0259 No NPIV "
2999 "Fabric support\n");
3000 }
3001 }
3002 }
3003 lpfc_destroy_vport_work_array(phba, vports);
3004}
3005
3006void
3007lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3008{
James Smart3e1f0712018-11-29 16:09:29 -08003009 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04003010 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05003011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04003012
James Smartf5eca9b2012-03-01 22:37:54 -05003013 /*
3014 * VFI not supported for interface type 0, so ignore any mailbox
3015 * error (except VFI in use) and continue with the discovery.
3016 */
3017 if (mboxq->u.mb.mbxStatus &&
3018 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3019 LPFC_SLI_INTF_IF_TYPE_0) &&
3020 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003021 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3022 "2018 REG_VFI mbxStatus error x%x "
3023 "HBA state x%x\n",
3024 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05003025 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04003026 /* FLOGI failed, use loop map to make discovery list */
3027 lpfc_disc_list_loopmap(vport);
3028 /* Start discovery */
3029 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05003030 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003031 }
3032 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05003033 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003034 }
James Smartae05ebe2013-03-01 16:35:38 -05003035
James Smarte74c03c2013-04-17 20:15:19 -04003036 /* If the VFI is already registered, there is nothing else to do
3037 * Unless this was a VFI update and we are in PT2PT mode, then
3038 * we should drop through to set the port state to ready.
3039 */
James Smartae05ebe2013-03-01 16:35:38 -05003040 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04003041 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3042 vport->fc_flag & FC_PT2PT))
3043 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05003044
James Smartc8685952009-11-18 15:39:16 -05003045 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05003046 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003047 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003048 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003049 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003050 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003051 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003052
James Smart1b511972011-12-13 13:23:09 -05003053 /* In case SLI4 FC loopback test, we are ready */
3054 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3055 (phba->link_flag & LS_LOOPBACK_MODE)) {
3056 phba->link_state = LPFC_HBA_READY;
3057 goto out_free_mem;
3058 }
3059
James Smarte74c03c2013-04-17 20:15:19 -04003060 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3061 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3062 "alpacnt:%d LinkState:%x topology:%x\n",
3063 vport->port_state, vport->fc_flag, vport->fc_myDID,
3064 vport->phba->alpa_map[0],
3065 phba->link_state, phba->fc_topology);
3066
James Smart6fb120a2009-05-22 14:52:59 -04003067 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003068 /*
3069 * For private loop or for NPort pt2pt,
3070 * just start discovery and we are done.
3071 */
3072 if ((vport->fc_flag & FC_PT2PT) ||
3073 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3074 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3075
James Smart76a95d72010-11-20 23:11:48 -05003076 /* Use loop map to make discovery list */
3077 lpfc_disc_list_loopmap(vport);
3078 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003079 if (vport->fc_flag & FC_PT2PT)
3080 vport->port_state = LPFC_VPORT_READY;
3081 else
3082 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003083 } else {
3084 lpfc_start_fdiscs(phba);
3085 lpfc_do_scr_ns_plogi(phba, vport);
3086 }
James Smart6fb120a2009-05-22 14:52:59 -04003087 }
3088
James Smart1b511972011-12-13 13:23:09 -05003089out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003090 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003091 if (dmabuf) {
3092 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3093 kfree(dmabuf);
3094 }
James Smart6fb120a2009-05-22 14:52:59 -04003095 return;
3096}
3097
3098static void
James Smart2e0fef82007-06-17 19:56:36 -05003099lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003100{
James Smart6fb120a2009-05-22 14:52:59 -04003101 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003102 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003103 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003104 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003105 struct serv_parm *sp = &vport->fc_sparam;
3106 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003107
3108 /* Check for error */
3109 if (mb->mbxStatus) {
3110 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07003111 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003112 "0319 READ_SPARAM mbxStatus error x%x "
3113 "hba state x%x>\n",
3114 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003115 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003116 goto out;
3117 }
3118
James Smart2e0fef82007-06-17 19:56:36 -05003119 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003120 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003121
3122 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3123 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3124 ed_tov = (ed_tov + 999999) / 1000000;
3125
3126 phba->fc_edtov = ed_tov;
3127 phba->fc_ratov = (2 * ed_tov) / 1000;
3128 if (phba->fc_ratov < FF_DEF_RATOV) {
3129 /* RA_TOV should be atleast 10sec for initial flogi */
3130 phba->fc_ratov = FF_DEF_RATOV;
3131 }
3132
James Smart05580562011-05-24 11:40:48 -04003133 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003134 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003135 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3136 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3137 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3138 }
3139
dea31012005-04-17 16:05:31 -05003140 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3141 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003142 mempool_free(pmb, phba->mbox_mem_pool);
James Smart835214f2020-01-27 16:23:03 -08003143
3144 /* Check if sending the FLOGI is being deferred to after we get
3145 * up to date CSPs from MBX_READ_SPARAM.
3146 */
3147 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3148 lpfc_initial_flogi(vport);
3149 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3150 }
dea31012005-04-17 16:05:31 -05003151 return;
3152
3153out:
James Smart3e1f0712018-11-29 16:09:29 -08003154 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003155 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3156 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003157 lpfc_issue_clear_la(phba, vport);
3158 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003159 return;
3160}
3161
3162static void
James Smart76a95d72010-11-20 23:11:48 -05003163lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003164{
James Smart92d7f7b2007-06-17 19:56:38 -05003165 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003166 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003167 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003168 int i;
James Smart14691152006-12-02 13:34:28 -05003169 struct lpfc_dmabuf *mp;
3170 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003171 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003172 uint32_t fc_flags = 0;
James Smart894bb172019-08-14 16:56:52 -07003173 unsigned long iflags;
James Smart14691152006-12-02 13:34:28 -05003174
James Smart894bb172019-08-14 16:56:52 -07003175 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta085e872015-12-16 18:12:02 -05003176 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3177
3178 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3179 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3180 case LPFC_LINK_SPEED_1GHZ:
3181 case LPFC_LINK_SPEED_2GHZ:
3182 case LPFC_LINK_SPEED_4GHZ:
3183 case LPFC_LINK_SPEED_8GHZ:
3184 case LPFC_LINK_SPEED_10GHZ:
3185 case LPFC_LINK_SPEED_16GHZ:
3186 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003187 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003188 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003189 break;
3190 default:
3191 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3192 break;
3193 }
dea31012005-04-17 16:05:31 -05003194 }
3195
James Smarte74c03c2013-04-17 20:15:19 -04003196 if (phba->fc_topology &&
3197 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3198 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3199 "3314 Toplogy changed was 0x%x is 0x%x\n",
3200 phba->fc_topology,
3201 bf_get(lpfc_mbx_read_top_topology, la));
3202 phba->fc_topology_changed = 1;
3203 }
3204
James Smart76a95d72010-11-20 23:11:48 -05003205 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart8aaa7bc2020-10-20 13:27:17 -07003206 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
dea31012005-04-17 16:05:31 -05003207
James Smartdf9e1b52011-12-13 13:22:17 -05003208 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003209 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003210 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003211
James Smart6a9c52c2009-10-02 15:16:51 -04003212 /* if npiv is enabled and this adapter supports npiv log
3213 * a message that npiv is not supported in this topology
3214 */
3215 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003216 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3217 "1309 Link Up Event npiv not supported in loop "
3218 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003219 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003220 if (bf_get(lpfc_mbx_read_top_il, la))
3221 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003222
James Smart76a95d72010-11-20 23:11:48 -05003223 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3224 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003225
3226 if (i == 0) {
3227 phba->alpa_map[0] = 0;
3228 } else {
James Smarte8b62012007-08-02 11:10:09 -04003229 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003230 int numalpa, j, k;
3231 union {
3232 uint8_t pamap[16];
3233 struct {
3234 uint32_t wd1;
3235 uint32_t wd2;
3236 uint32_t wd3;
3237 uint32_t wd4;
3238 } pa;
3239 } un;
3240 numalpa = phba->alpa_map[0];
3241 j = 0;
3242 while (j < numalpa) {
3243 memset(un.pamap, 0, 16);
3244 for (k = 1; j < numalpa; k++) {
3245 un.pamap[k - 1] =
3246 phba->alpa_map[j + 1];
3247 j++;
3248 if (k == 16)
3249 break;
3250 }
3251 /* Link Up Event ALPA map */
3252 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003253 KERN_WARNING,
3254 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003255 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003256 "ALPA map Data: x%x "
3257 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003258 un.pa.wd1, un.pa.wd2,
3259 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003260 }
3261 }
3262 }
3263 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003264 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003265 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003266 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003267 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3268 }
James Smart2e0fef82007-06-17 19:56:36 -05003269 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003270 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003271 }
James Smart894bb172019-08-14 16:56:52 -07003272 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003273
James Smart38c20672013-03-01 16:37:44 -05003274 if (fc_flags) {
James Smart894bb172019-08-14 16:56:52 -07003275 spin_lock_irqsave(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003276 vport->fc_flag |= fc_flags;
James Smart894bb172019-08-14 16:56:52 -07003277 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003278 }
3279
dea31012005-04-17 16:05:31 -05003280 lpfc_linkup(phba);
James Smart835214f2020-01-27 16:23:03 -08003281 sparam_mbox = NULL;
3282
James Smart9f1177a2010-02-26 14:12:57 -05003283 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3284 if (!sparam_mbox)
3285 goto out;
3286
3287 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3288 if (rc) {
3289 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3290 goto out;
3291 }
3292 sparam_mbox->vport = vport;
3293 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3294 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3295 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003296 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003297 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3298 kfree(mp);
3299 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3300 goto out;
dea31012005-04-17 16:05:31 -05003301 }
3302
James Smart7f048392020-09-11 13:01:47 -07003303 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3304 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3305 if (!cfglink_mbox)
3306 goto out;
3307 vport->port_state = LPFC_LOCAL_CFG_LINK;
3308 lpfc_config_link(phba, cfglink_mbox);
3309 cfglink_mbox->vport = vport;
3310 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3311 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3312 if (rc == MBX_NOT_FINISHED) {
3313 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3314 goto out;
3315 }
3316 } else {
James Smart32b97932009-07-19 10:01:21 -04003317 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003318 /*
3319 * Add the driver's default FCF record at FCF index 0 now. This
3320 * is phase 1 implementation that support FCF index 0 and driver
3321 * defaults.
3322 */
James Smart45ed1192009-10-02 15:17:02 -04003323 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003324 fcf_record = kzalloc(sizeof(struct fcf_record),
3325 GFP_KERNEL);
3326 if (unlikely(!fcf_record)) {
3327 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003328 LOG_TRACE_EVENT,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003329 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003330 "fcf record\n");
3331 rc = -ENODEV;
3332 goto out;
3333 }
3334
3335 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3336 LPFC_FCOE_FCF_DEF_INDEX);
3337 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3338 if (unlikely(rc)) {
3339 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003340 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04003341 "2013 Could not manually add FCF "
3342 "record 0, status %d\n", rc);
3343 rc = -ENODEV;
3344 kfree(fcf_record);
3345 goto out;
3346 }
3347 kfree(fcf_record);
3348 }
3349 /*
3350 * The driver is expected to do FIP/FCF. Call the port
3351 * and get the FCF Table.
3352 */
James Smart894bb172019-08-14 16:56:52 -07003353 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta93ff372010-10-22 11:06:08 -04003354 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart894bb172019-08-14 16:56:52 -07003355 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart32b97932009-07-19 10:01:21 -04003356 return;
3357 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003358 /* This is the initial FCF discovery scan */
3359 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003360 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003361 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3362 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003363 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3364 LPFC_FCOE_FCF_GET_FIRST);
3365 if (rc) {
James Smart894bb172019-08-14 16:56:52 -07003366 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003367 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003368 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6fb120a2009-05-22 14:52:59 -04003369 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003370 }
James Smart38b92ef2010-08-04 16:11:39 -04003371 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003372 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003373 }
James Smart6fb120a2009-05-22 14:52:59 -04003374
James Smarte3ba04c2019-12-18 15:58:02 -08003375 /* Prepare for LINK up registrations */
3376 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3377 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3378 init_utsname()->nodename);
James Smart6fb120a2009-05-22 14:52:59 -04003379 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003380out:
3381 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07003382 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart32350662019-08-14 16:57:06 -07003383 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04003384 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003385 lpfc_issue_clear_la(phba, vport);
3386 return;
dea31012005-04-17 16:05:31 -05003387}
3388
3389static void
James Smart84774a42008-08-24 21:50:06 -04003390lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003391{
dea31012005-04-17 16:05:31 -05003392 uint32_t control;
3393 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003394 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003395 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003396 if (phba->sli_rev <= LPFC_SLI_REV3) {
3397 control = readl(phba->HCregaddr);
3398 control |= HC_LAINT_ENA;
3399 writel(control, phba->HCregaddr);
3400 readl(phba->HCregaddr); /* flush */
3401 }
James Smart2e0fef82007-06-17 19:56:36 -05003402 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003403}
3404
James Smart84774a42008-08-24 21:50:06 -04003405static void
3406lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3407{
3408 lpfc_linkdown(phba);
3409 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003410 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003411 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3412}
3413
3414
dea31012005-04-17 16:05:31 -05003415/*
James Smart76a95d72010-11-20 23:11:48 -05003416 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003417 * command upon completion. It is setup in the LPFC_MBOXQ
3418 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003419 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003420 */
3421void
James Smart76a95d72010-11-20 23:11:48 -05003422lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003423{
James Smart2e0fef82007-06-17 19:56:36 -05003424 struct lpfc_vport *vport = pmb->vport;
3425 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003426 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003427 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003428 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003429 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003430 uint8_t attn_type;
James Smart894bb172019-08-14 16:56:52 -07003431 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003432
James Smart0d2b6b82008-06-14 22:52:47 -04003433 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003434 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003435 if (pring)
3436 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003437
dea31012005-04-17 16:05:31 -05003438 /* Check for error */
3439 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003440 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003441 "1307 READ_LA mbox error x%x state x%x\n",
3442 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003443 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003444 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003445 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003446 }
3447
James Smart76a95d72010-11-20 23:11:48 -05003448 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003449 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003450
3451 memcpy(&phba->alpa_map[0], mp->virt, 128);
3452
James Smart894bb172019-08-14 16:56:52 -07003453 spin_lock_irqsave(shost->host_lock, iflags);
James Smart76a95d72010-11-20 23:11:48 -05003454 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003455 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003456 else
James Smart2e0fef82007-06-17 19:56:36 -05003457 vport->fc_flag &= ~FC_BYPASSED_MODE;
James Smart894bb172019-08-14 16:56:52 -07003458 spin_unlock_irqrestore(shost->host_lock, iflags);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003459
James Smartbe0c0082013-03-01 16:38:14 -05003460 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003461 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003462 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003463 if (phba->fc_eventTag != 0)
3464 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003465 }
dea31012005-04-17 16:05:31 -05003466
3467 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003468 if (phba->sli_rev < LPFC_SLI_REV4) {
James Smart894bb172019-08-14 16:56:52 -07003469 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003470 if (bf_get(lpfc_mbx_read_top_mm, la))
3471 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3472 else
3473 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart894bb172019-08-14 16:56:52 -07003474 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003475 }
dea31012005-04-17 16:05:31 -05003476
James Smart4d9ab992009-10-02 15:16:39 -04003477 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003478 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003479 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003480 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003481 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003482 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003483 "1306 Link Up Event in loop back mode "
3484 "x%x received Data: x%x x%x x%x x%x\n",
3485 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003486 bf_get(lpfc_mbx_read_top_alpa_granted,
3487 la),
3488 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003489 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003490 } else {
3491 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003492 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003493 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003494 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003495 bf_get(lpfc_mbx_read_top_alpa_granted,
3496 la),
3497 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003498 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003499 bf_get(lpfc_mbx_read_top_mm, la),
3500 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003501 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003502 }
James Smart92d7f7b2007-06-17 19:56:38 -05003503 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003504 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3505 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003506 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003507 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003508 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3509 "1308 Link Down Event in loop back mode "
3510 "x%x received "
3511 "Data: x%x x%x x%x\n",
3512 la->eventTag, phba->fc_eventTag,
3513 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003514 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3515 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smartb9da8142019-11-04 16:57:04 -08003516 "1313 Link Down Unexpected FA WWPN Event x%x "
3517 "received Data: x%x x%x x%x x%x x%x\n",
James Smartaeb3c812017-04-21 16:05:02 -07003518 la->eventTag, phba->fc_eventTag,
3519 phba->pport->port_state, vport->fc_flag,
3520 bf_get(lpfc_mbx_read_top_mm, la),
3521 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003522 else
James Smart3163f722008-02-08 18:50:25 -05003523 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003524 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003525 "Data: x%x x%x x%x x%x x%x\n",
3526 la->eventTag, phba->fc_eventTag,
3527 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003528 bf_get(lpfc_mbx_read_top_mm, la),
3529 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003530 lpfc_mbx_issue_link_down(phba);
3531 }
James Smartaeb3c812017-04-21 16:05:02 -07003532 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3533 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003534 if (phba->link_state != LPFC_LINK_DOWN) {
3535 phba->fc_stat.LinkDown++;
3536 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3537 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003538 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003539 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003540 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003541 lpfc_mbx_issue_link_down(phba);
3542 } else
3543 lpfc_enable_la(phba);
3544
3545 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3546 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3547 "Data: x%x x%x x%x\n",
3548 la->eventTag, phba->fc_eventTag,
3549 phba->pport->port_state, vport->fc_flag);
3550 /*
3551 * The cmnd that triggered this will be waiting for this
3552 * signal.
3553 */
3554 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3555 if (phba->wait_4_mlo_maint_flg) {
3556 phba->wait_4_mlo_maint_flg = 0;
3557 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003558 }
James Smart84774a42008-08-24 21:50:06 -04003559 }
3560
James Smartbe0c0082013-03-01 16:38:14 -05003561 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3562 bf_get(lpfc_mbx_read_top_fa, la)) {
3563 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003564 lpfc_issue_clear_la(phba, vport);
3565 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003566 "1311 fa %d\n",
3567 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003568 }
3569
James Smart76a95d72010-11-20 23:11:48 -05003570lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003571 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3572 kfree(mp);
3573 mempool_free(pmb, phba->mbox_mem_pool);
3574 return;
3575}
3576
3577/*
3578 * This routine handles processing a REG_LOGIN mailbox
3579 * command upon completion. It is setup in the LPFC_MBOXQ
3580 * as the completion routine when the command is
3581 * handed off to the SLI layer.
3582 */
3583void
James Smart2e0fef82007-06-17 19:56:36 -05003584lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003585{
James Smart2e0fef82007-06-17 19:56:36 -05003586 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003587 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3588 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smartffc95492010-06-07 15:23:17 -04003589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003590
James Smart3e1f0712018-11-29 16:09:29 -08003591 pmb->ctx_buf = NULL;
3592 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003593
James Smartbe6bb942015-04-07 15:07:22 -04003594 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
James Smart307e3382020-11-15 11:26:30 -08003595 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04003596 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003597 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08003598 ndlp);
James Smartffc95492010-06-07 15:23:17 -04003599 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3600 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3601
James Smart40426292010-12-15 17:58:10 -05003602 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3603 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003604 /* We rcvd a rscn after issuing this
3605 * mbox reg login, we may have cycled
3606 * back through the state and be
3607 * back at reg login state so this
3608 * mbox needs to be ignored becase
3609 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003610 * process.
James Smartffc95492010-06-07 15:23:17 -04003611 */
3612 spin_lock_irq(shost->host_lock);
3613 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3614 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003615
3616 /*
3617 * We cannot leave the RPI registered because
3618 * if we go thru discovery again for this ndlp
3619 * a subsequent REG_RPI will fail.
3620 */
3621 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3622 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003623 }
3624
3625 /* Call state machine */
3626 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003627
dea31012005-04-17 16:05:31 -05003628 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3629 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003630 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003631 /* decrement the node reference count held for this callback
3632 * function.
3633 */
James Smart329f9bc2007-04-25 09:53:01 -04003634 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003635
3636 return;
3637}
3638
James Smart92d7f7b2007-06-17 19:56:38 -05003639static void
3640lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3641{
James Smart04c68492009-05-22 14:52:52 -04003642 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003643 struct lpfc_vport *vport = pmb->vport;
3644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3645
3646 switch (mb->mbxStatus) {
3647 case 0x0011:
3648 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003649 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3650 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3651 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003652 break;
James Smart78730cf2010-04-06 15:06:30 -04003653 /* If VPI is busy, reset the HBA */
3654 case 0x9700:
Dick Kennedy372c1872020-06-30 14:50:00 -07003655 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart78730cf2010-04-06 15:06:30 -04003656 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3657 vport->vpi, mb->mbxStatus);
3658 if (!(phba->pport->load_flag & FC_UNLOADING))
3659 lpfc_workq_post_event(phba, NULL, NULL,
3660 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003661 }
James Smart72100cc2010-02-12 14:43:01 -05003662 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003663 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003664 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003665 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003666 vport->unreg_vpi_cmpl = VPORT_OK;
3667 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003668 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003669 /*
3670 * This shost reference might have been taken at the beginning of
3671 * lpfc_vport_delete()
3672 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003673 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003674 scsi_host_put(shost);
3675}
3676
James Smartd7c255b2008-08-24 21:50:00 -04003677int
James Smart92d7f7b2007-06-17 19:56:38 -05003678lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3679{
3680 struct lpfc_hba *phba = vport->phba;
3681 LPFC_MBOXQ_t *mbox;
3682 int rc;
3683
3684 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3685 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003686 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003687
3688 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3689 mbox->vport = vport;
3690 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003691 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003692 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003693 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003694 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003695 mempool_free(mbox, phba->mbox_mem_pool);
3696 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003697 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003698 }
James Smartd7c255b2008-08-24 21:50:00 -04003699 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003700}
3701
3702static void
3703lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3704{
3705 struct lpfc_vport *vport = pmb->vport;
3706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003707 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003708
3709 switch (mb->mbxStatus) {
3710 case 0x0011:
3711 case 0x9601:
3712 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003713 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3714 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3715 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003716 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3717 spin_lock_irq(shost->host_lock);
3718 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3719 spin_unlock_irq(shost->host_lock);
3720 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003721
James Smartf6e84792019-01-28 11:14:38 -08003722 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3723 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003724 if (phba->nvmet_support)
3725 lpfc_nvmet_update_targetport(phba);
3726 else
James Smart8c258642017-02-12 13:52:36 -08003727 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003728 }
James Smart92d7f7b2007-06-17 19:56:38 -05003729 goto out;
3730 }
James Smart92d7f7b2007-06-17 19:56:38 -05003731
James Smart72100cc2010-02-12 14:43:01 -05003732 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003733 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003734 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003735 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003736 vport->num_disc_nodes = 0;
3737 /* go thru NPR list and issue ELS PLOGIs */
3738 if (vport->fc_npr_cnt)
3739 lpfc_els_disc_plogi(vport);
3740
3741 if (!vport->num_disc_nodes) {
3742 spin_lock_irq(shost->host_lock);
3743 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3744 spin_unlock_irq(shost->host_lock);
3745 lpfc_can_disctmo(vport);
3746 }
3747 vport->port_state = LPFC_VPORT_READY;
3748
3749out:
3750 mempool_free(pmb, phba->mbox_mem_pool);
3751 return;
3752}
3753
James Smart21e9a0a2009-05-22 14:53:21 -04003754/**
3755 * lpfc_create_static_vport - Read HBA config region to create static vports.
3756 * @phba: pointer to lpfc hba data structure.
3757 *
3758 * This routine issue a DUMP mailbox command for config region 22 to get
3759 * the list of static vports to be created. The function create vports
3760 * based on the information returned from the HBA.
3761 **/
3762void
3763lpfc_create_static_vport(struct lpfc_hba *phba)
3764{
3765 LPFC_MBOXQ_t *pmb = NULL;
3766 MAILBOX_t *mb;
3767 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003768 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003769 struct fc_vport_identifiers vport_id;
3770 struct fc_vport *new_fc_vport;
3771 struct Scsi_Host *shost;
3772 struct lpfc_vport *vport;
3773 uint16_t offset = 0;
3774 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003775 struct lpfc_dmabuf *mp;
3776 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003777
3778 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3779 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003780 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003781 "0542 lpfc_create_static_vport failed to"
3782 " allocate mailbox memory\n");
3783 return;
3784 }
James Smartcdcc2342012-08-14 14:26:35 -04003785 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003786 mb = &pmb->u.mb;
3787
3788 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3789 if (!vport_info) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003790 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003791 "0543 lpfc_create_static_vport failed to"
3792 " allocate vport_info\n");
3793 mempool_free(pmb, phba->mbox_mem_pool);
3794 return;
3795 }
3796
3797 vport_buff = (uint8_t *) vport_info;
3798 do {
James Smartcdcc2342012-08-14 14:26:35 -04003799 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003800 if (pmb->ctx_buf) {
3801 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003802 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3803 kfree(mp);
3804 }
James Smart1c6834a2009-07-19 10:01:26 -04003805 if (lpfc_dump_static_vport(phba, pmb, offset))
3806 goto out;
3807
James Smart21e9a0a2009-05-22 14:53:21 -04003808 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003809 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3810 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003811
James Smartcdcc2342012-08-14 14:26:35 -04003812 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003813 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3814 "0544 lpfc_create_static_vport failed to"
3815 " issue dump mailbox command ret 0x%x "
3816 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003817 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003818 goto out;
3819 }
3820
James Smart1c6834a2009-07-19 10:01:26 -04003821 if (phba->sli_rev == LPFC_SLI_REV4) {
3822 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003823 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003824 if (byte_count > sizeof(struct static_vport_info) -
3825 offset)
3826 byte_count = sizeof(struct static_vport_info)
3827 - offset;
3828 memcpy(vport_buff + offset, mp->virt, byte_count);
3829 offset += byte_count;
3830 } else {
3831 if (mb->un.varDmp.word_cnt >
3832 sizeof(struct static_vport_info) - offset)
3833 mb->un.varDmp.word_cnt =
3834 sizeof(struct static_vport_info)
3835 - offset;
3836 byte_count = mb->un.varDmp.word_cnt;
3837 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3838 vport_buff + offset,
3839 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003840
James Smart1c6834a2009-07-19 10:01:26 -04003841 offset += byte_count;
3842 }
James Smart21e9a0a2009-05-22 14:53:21 -04003843
James Smart1c6834a2009-07-19 10:01:26 -04003844 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003845 offset < sizeof(struct static_vport_info));
3846
3847
3848 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3849 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3850 != VPORT_INFO_REV)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003851 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3852 "0545 lpfc_create_static_vport bad"
3853 " information header 0x%x 0x%x\n",
3854 le32_to_cpu(vport_info->signature),
3855 le32_to_cpu(vport_info->rev) &
3856 VPORT_INFO_REV_MASK);
James Smart21e9a0a2009-05-22 14:53:21 -04003857
3858 goto out;
3859 }
3860
3861 shost = lpfc_shost_from_vport(phba->pport);
3862
3863 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3864 memset(&vport_id, 0, sizeof(vport_id));
3865 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3866 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3867 if (!vport_id.port_name || !vport_id.node_name)
3868 continue;
3869
3870 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3871 vport_id.vport_type = FC_PORTTYPE_NPIV;
3872 vport_id.disable = false;
3873 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3874
3875 if (!new_fc_vport) {
3876 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3877 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003878 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003879 continue;
3880 }
3881
3882 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3883 vport->vport_flag |= STATIC_VPORT;
3884 }
3885
3886out:
James Smart21e9a0a2009-05-22 14:53:21 -04003887 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003888 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003889 if (pmb->ctx_buf) {
3890 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003891 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3892 kfree(mp);
3893 }
James Smart21e9a0a2009-05-22 14:53:21 -04003894 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003895 }
James Smart21e9a0a2009-05-22 14:53:21 -04003896
3897 return;
3898}
3899
dea31012005-04-17 16:05:31 -05003900/*
3901 * This routine handles processing a Fabric REG_LOGIN mailbox
3902 * command upon completion. It is setup in the LPFC_MBOXQ
3903 * as the completion routine when the command is
3904 * handed off to the SLI layer.
3905 */
3906void
James Smart2e0fef82007-06-17 19:56:36 -05003907lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003908{
James Smart92d7f7b2007-06-17 19:56:38 -05003909 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003910 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003911 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003912 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003913 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003914
James Smart3e1f0712018-11-29 16:09:29 -08003915 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3916 pmb->ctx_ndlp = NULL;
3917 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003918
dea31012005-04-17 16:05:31 -05003919 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003920 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04003921 "0258 Register Fabric login error: 0x%x\n",
3922 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003923 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3924 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003925 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003926
James Smart76a95d72010-11-20 23:11:48 -05003927 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003928 /* FLOGI failed, use loop map to make discovery list */
3929 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003930
James Smart92d7f7b2007-06-17 19:56:38 -05003931 /* Start discovery */
3932 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003933 /* Decrement the reference count to ndlp after the
3934 * reference to the ndlp are done.
3935 */
3936 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003937 return;
3938 }
3939
3940 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003941 /* Decrement the reference count to ndlp after the reference
3942 * to the ndlp are done.
3943 */
3944 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003945 return;
3946 }
3947
James Smart6d368e52011-05-24 11:44:12 -04003948 if (phba->sli_rev < LPFC_SLI_REV4)
3949 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003950 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003951 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003952 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003953
James Smart2e0fef82007-06-17 19:56:36 -05003954 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003955 /* when physical port receive logo donot start
3956 * vport discovery */
3957 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3958 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003959 else {
3960 shost = lpfc_shost_from_vport(vport);
3961 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003962 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003963 spin_unlock_irq(shost->host_lock);
3964 }
James Smart92d7f7b2007-06-17 19:56:38 -05003965 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003966 }
3967
3968 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3969 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003970 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003971
3972 /* Drop the reference count from the mbox at the end after
3973 * all the current reference to the ndlp have been done.
3974 */
3975 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003976 return;
3977}
3978
James Smarta0f2d3e2017-02-12 13:52:31 -08003979 /*
3980 * This routine will issue a GID_FT for each FC4 Type supported
3981 * by the driver. ALL GID_FTs must complete before discovery is started.
3982 */
3983int
3984lpfc_issue_gidft(struct lpfc_vport *vport)
3985{
James Smarta0f2d3e2017-02-12 13:52:31 -08003986 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08003987 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3988 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003989 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3990 /* Cannot issue NameServer FCP Query, so finish up
3991 * discovery
3992 */
Dick Kennedy372c1872020-06-30 14:50:00 -07003993 lpfc_printf_vlog(vport, KERN_ERR,
3994 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08003995 "0604 %s FC TYPE %x %s\n",
3996 "Failed to issue GID_FT to ",
3997 FC_TYPE_FCP,
3998 "Finishing discovery.");
3999 return 0;
4000 }
4001 vport->gidft_inp++;
4002 }
4003
James Smartf6e84792019-01-28 11:14:38 -08004004 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4005 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004006 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4007 /* Cannot issue NameServer NVME Query, so finish up
4008 * discovery
4009 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004010 lpfc_printf_vlog(vport, KERN_ERR,
4011 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08004012 "0605 %s FC_TYPE %x %s %d\n",
4013 "Failed to issue GID_FT to ",
4014 FC_TYPE_NVME,
4015 "Finishing discovery: gidftinp ",
4016 vport->gidft_inp);
4017 if (vport->gidft_inp == 0)
4018 return 0;
4019 } else
4020 vport->gidft_inp++;
4021 }
4022 return vport->gidft_inp;
4023}
4024
James Smart7ea92eb2018-10-23 13:41:10 -07004025/**
4026 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4027 * @vport: The virtual port for which this call is being executed.
4028 *
4029 * This routine will issue a GID_PT to get a list of all N_Ports
4030 *
4031 * Return value :
4032 * 0 - Failure to issue a GID_PT
4033 * 1 - GID_PT issued
4034 **/
4035int
4036lpfc_issue_gidpt(struct lpfc_vport *vport)
4037{
4038 /* Good status, issue CT Request to NameServer */
4039 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4040 /* Cannot issue NameServer FCP Query, so finish up
4041 * discovery
4042 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004043 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart7ea92eb2018-10-23 13:41:10 -07004044 "0606 %s Port TYPE %x %s\n",
4045 "Failed to issue GID_PT to ",
4046 GID_PT_N_PORT,
4047 "Finishing discovery.");
4048 return 0;
4049 }
4050 vport->gidft_inp++;
4051 return 1;
4052}
4053
dea31012005-04-17 16:05:31 -05004054/*
4055 * This routine handles processing a NameServer REG_LOGIN mailbox
4056 * command upon completion. It is setup in the LPFC_MBOXQ
4057 * as the completion routine when the command is
4058 * handed off to the SLI layer.
4059 */
4060void
James Smart2e0fef82007-06-17 19:56:36 -05004061lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004062{
James Smart21e9a0a2009-05-22 14:53:21 -04004063 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004064 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4065 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004066 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004067
James Smart3e1f0712018-11-29 16:09:29 -08004068 pmb->ctx_buf = NULL;
4069 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004070 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004071
dea31012005-04-17 16:05:31 -05004072 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004073 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004074 "0260 Register NameServer error: 0x%x\n",
4075 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004076
4077out:
James Smartfa4066b2008-01-11 01:53:27 -05004078 /* decrement the node reference count held for this
4079 * callback function.
4080 */
James Smart329f9bc2007-04-25 09:53:01 -04004081 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004082 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4083 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004084 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004085
4086 /* If no other thread is using the ndlp, free it */
4087 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05004088
James Smart76a95d72010-11-20 23:11:48 -05004089 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004090 /*
4091 * RegLogin failed, use loop map to make discovery
4092 * list
4093 */
4094 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004095
James Smart92d7f7b2007-06-17 19:56:38 -05004096 /* Start discovery */
4097 lpfc_disc_start(vport);
4098 return;
4099 }
4100 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004101 return;
4102 }
4103
James Smart6d368e52011-05-24 11:44:12 -04004104 if (phba->sli_rev < LPFC_SLI_REV4)
4105 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004106 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004107 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004108 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07004109 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08004110 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004111 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004112 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08004113 ndlp);
dea31012005-04-17 16:05:31 -05004114
James Smart2e0fef82007-06-17 19:56:36 -05004115 if (vport->port_state < LPFC_VPORT_READY) {
4116 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004117 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4118 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4119 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4120 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004121
James Smartf6e84792019-01-28 11:14:38 -08004122 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4123 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004124 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4125
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_NVME))
James Smart01649562017-02-12 13:52:32 -08004128 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4129 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004130
4131 /* Issue SCR just before NameServer GID_FT Query */
James Smartdf3fe762020-02-10 09:31:55 -08004132 lpfc_issue_els_scr(vport, 0);
4133
James Smart8aaa7bc2020-10-20 13:27:17 -07004134 if (!phba->cfg_enable_mi ||
4135 phba->sli4_hba.pc_sli4_params.mi_ver < LPFC_MIB3_SUPPORT)
4136 lpfc_issue_els_rdf(vport, 0);
dea31012005-04-17 16:05:31 -05004137 }
4138
James Smart2e0fef82007-06-17 19:56:36 -05004139 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004140 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004141 goto out;
dea31012005-04-17 16:05:31 -05004142
James Smarta0f2d3e2017-02-12 13:52:31 -08004143 /*
4144 * At this point in time we may need to wait for multiple
4145 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4146 *
4147 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004148 * callback function.
4149 */
James Smart329f9bc2007-04-25 09:53:01 -04004150 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004151 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4152 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004153 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004154
4155 return;
4156}
4157
4158static void
James Smart2e0fef82007-06-17 19:56:36 -05004159lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004160{
James Smart2e0fef82007-06-17 19:56:36 -05004161 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4162 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004163 struct lpfc_rport_data *rdata;
4164 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004165 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004166
James Smartf6e84792019-01-28 11:14:38 -08004167 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004168 return;
4169
dea31012005-04-17 16:05:31 -05004170 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004171 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4172 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004173 rport_ids.port_id = ndlp->nlp_DID;
4174 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004175
James Smart329f9bc2007-04-25 09:53:01 -04004176 /*
4177 * We leave our node pointer in rport->dd_data when we unregister a
4178 * FCP target port. But fc_remote_port_add zeros the space to which
4179 * rport->dd_data points. So, if we're reusing a previously
4180 * registered port, drop the reference that we took the last time we
4181 * registered the port.
4182 */
James Smart466e8402015-05-21 13:55:28 -04004183 rport = ndlp->rport;
4184 if (rport) {
4185 rdata = rport->dd_data;
4186 /* break the link before dropping the ref */
4187 ndlp->rport = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08004188 if (rdata) {
4189 if (rdata->pnode == ndlp)
4190 lpfc_nlp_put(ndlp);
4191 rdata->pnode = NULL;
4192 }
James Smart466e8402015-05-21 13:55:28 -04004193 /* drop reference for earlier registeration */
4194 put_device(&rport->dev);
4195 }
James Smart858c9f62007-06-17 19:56:39 -05004196
4197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4198 "rport add: did:x%x flg:x%x type x%x",
4199 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4200
James Smart9589b0622011-04-16 11:03:17 -04004201 /* Don't add the remote port if unloading. */
4202 if (vport->load_flag & FC_UNLOADING)
4203 return;
4204
James Smart2e0fef82007-06-17 19:56:36 -05004205 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004206 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004207 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4208 "Warning: fc_remote_port_add failed\n");
4209 return;
4210 }
4211
4212 /* initialize static port data */
4213 rport->maxframe_size = ndlp->nlp_maxframe;
4214 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004215 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004216 rdata->pnode = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08004217 if (!rdata->pnode) {
4218 dev_warn(&phba->pcidev->dev,
4219 "Warning - node ref failed. Unreg rport\n");
4220 fc_remote_port_delete(rport);
4221 ndlp->rport = NULL;
4222 return;
4223 }
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004224
4225 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004226 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004227 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004228 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4229 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4230 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4231 if (ndlp->nlp_type & NLP_NVME_TARGET)
4232 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4233 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4234 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004235
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004236 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4237 fc_remote_port_rolechg(rport, rport_ids.roles);
4238
James Smart34f5ad82012-08-03 12:35:03 -04004239 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004240 "3183 rport register x%06x, rport x%px role x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04004241 ndlp->nlp_DID, rport, rport_ids.roles);
4242
James Smart071fbd3d2006-04-15 11:53:20 -04004243 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004244 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004245 ndlp->nlp_sid = rport->scsi_target_id;
4246 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004247 return;
4248}
4249
4250static void
James Smart2e0fef82007-06-17 19:56:36 -05004251lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004252{
4253 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004254 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004255
James Smartf6e84792019-01-28 11:14:38 -08004256 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004257 return;
James Smartc01f3202006-08-18 17:47:08 -04004258
James Smart2ea259e2017-02-12 13:52:27 -08004259 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004260 "rport delete: did:x%x flg:x%x type x%x",
4261 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4262
James Smart2ea259e2017-02-12 13:52:27 -08004263 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004264 "3184 rport unregister x%06x, rport x%px\n",
James Smart34f5ad82012-08-03 12:35:03 -04004265 ndlp->nlp_DID, rport);
4266
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004267 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004268
4269 return;
4270}
4271
James Smartde0c5b32007-04-25 09:52:27 -04004272static void
James Smart2e0fef82007-06-17 19:56:36 -05004273lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004274{
James Smart2e0fef82007-06-17 19:56:36 -05004275 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -07004276 unsigned long iflags;
James Smart2e0fef82007-06-17 19:56:36 -05004277
James Smart894bb172019-08-14 16:56:52 -07004278 spin_lock_irqsave(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004279 switch (state) {
4280 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004281 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004282 break;
4283 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004284 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004285 break;
4286 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004287 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004288 break;
4289 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004290 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004291 break;
4292 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004293 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004294 break;
4295 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004296 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004297 break;
4298 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004299 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004300 break;
4301 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004302 if (vport->fc_npr_cnt == 0 && count == -1)
4303 vport->fc_npr_cnt = 0;
4304 else
4305 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004306 break;
4307 }
James Smart894bb172019-08-14 16:56:52 -07004308 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004309}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004310
James Smartde0c5b32007-04-25 09:52:27 -04004311static void
James Smart2e0fef82007-06-17 19:56:36 -05004312lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004313 int old_state, int new_state)
4314{
James Smart2e0fef82007-06-17 19:56:36 -05004315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4316
James Smartde0c5b32007-04-25 09:52:27 -04004317 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004318 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4319 ndlp->nlp_type |= NLP_FC_NODE;
4320 }
4321 if (new_state == NLP_STE_MAPPED_NODE)
4322 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4323 if (new_state == NLP_STE_NPR_NODE)
4324 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004325
James Smarta0f2d3e2017-02-12 13:52:31 -08004326 /* FCP and NVME Transport interface */
4327 if ((old_state == NLP_STE_MAPPED_NODE ||
4328 old_state == NLP_STE_UNMAPPED_NODE)) {
4329 if (ndlp->rport) {
4330 vport->phba->nport_event_cnt++;
4331 lpfc_unregister_remote_port(ndlp);
4332 }
4333
James Smart1c5b12f2017-04-21 16:05:03 -07004334 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004335 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004336 if (vport->phba->nvmet_support == 0) {
4337 /* Start devloss if target. */
4338 if (ndlp->nlp_type & NLP_NVME_TARGET)
4339 lpfc_nvme_unregister_port(vport, ndlp);
4340 } else {
James Smart6599e122017-06-01 21:07:00 -07004341 /* NVMET has no upcall. */
4342 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004343 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004344 }
James Smartde0c5b32007-04-25 09:52:27 -04004345 }
dea31012005-04-17 16:05:31 -05004346
James Smarta0f2d3e2017-02-12 13:52:31 -08004347 /* FCP and NVME Transport interfaces */
4348
James Smartde0c5b32007-04-25 09:52:27 -04004349 if (new_state == NLP_STE_MAPPED_NODE ||
4350 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart01a8aed2018-09-10 10:30:41 -07004351 if (ndlp->nlp_fc4_type ||
James Smart92721c32017-06-01 21:06:59 -07004352 ndlp->nlp_DID == Fabric_DID ||
4353 ndlp->nlp_DID == NameServer_DID ||
4354 ndlp->nlp_DID == FDMI_DID) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004355 vport->phba->nport_event_cnt++;
4356 /*
4357 * Tell the fc transport about the port, if we haven't
4358 * already. If we have, and it's a scsi entity, be
4359 */
4360 lpfc_register_remote_port(vport, ndlp);
4361 }
4362 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004363 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4364 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004365 if (vport->phba->nvmet_support == 0) {
4366 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004367 * Only NVME Target Rports are registered with
4368 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004369 */
James Smart3b5bde692017-11-20 16:00:39 -08004370 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4371 vport->phba->nport_event_cnt++;
4372 lpfc_nvme_register_port(vport, ndlp);
4373 }
James Smart8c258642017-02-12 13:52:36 -08004374 } else {
4375 /* Just take an NDLP ref count since the
4376 * target does not register rports.
4377 */
4378 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004379 }
4380 }
James Smartde0c5b32007-04-25 09:52:27 -04004381 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004382
James Smartea2151b2008-09-07 11:52:10 -04004383 if ((new_state == NLP_STE_MAPPED_NODE) &&
4384 (vport->stat_data_enabled)) {
4385 /*
4386 * A new target is discovered, if there is no buffer for
4387 * statistical data collection allocate buffer.
4388 */
4389 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4390 sizeof(struct lpfc_scsicmd_bkt),
4391 GFP_KERNEL);
4392
4393 if (!ndlp->lat_data)
Dick Kennedy372c1872020-06-30 14:50:00 -07004394 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartea2151b2008-09-07 11:52:10 -04004395 "0286 lpfc_nlp_state_cleanup failed to "
4396 "allocate statistical data buffer DID "
4397 "0x%x\n", ndlp->nlp_DID);
4398 }
James Smart858c9f62007-06-17 19:56:39 -05004399 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004400 * If the node just added to Mapped list was an FCP target,
4401 * but the remote port registration failed or assigned a target
4402 * id outside the presentable range - move the node to the
4403 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004404 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004405 if ((new_state == NLP_STE_MAPPED_NODE) &&
4406 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004407 (!ndlp->rport ||
4408 ndlp->rport->scsi_target_id == -1 ||
4409 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004410 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004411 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004412 spin_unlock_irq(shost->host_lock);
4413 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004414 }
James Smartde0c5b32007-04-25 09:52:27 -04004415}
4416
James Smart685f0bf2007-04-25 09:53:08 -04004417static char *
4418lpfc_nlp_state_name(char *buffer, size_t size, int state)
4419{
4420 static char *states[] = {
4421 [NLP_STE_UNUSED_NODE] = "UNUSED",
4422 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4423 [NLP_STE_ADISC_ISSUE] = "ADISC",
4424 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4425 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004426 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004427 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4428 [NLP_STE_MAPPED_NODE] = "MAPPED",
4429 [NLP_STE_NPR_NODE] = "NPR",
4430 };
4431
James Smart311464e2007-08-02 11:10:37 -04004432 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004433 strlcpy(buffer, states[state], size);
4434 else
4435 snprintf(buffer, size, "unknown (%d)", state);
4436 return buffer;
4437}
4438
James Smartde0c5b32007-04-25 09:52:27 -04004439void
James Smart2e0fef82007-06-17 19:56:36 -05004440lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4441 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004442{
James Smart2e0fef82007-06-17 19:56:36 -05004443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004444 int old_state = ndlp->nlp_state;
James Smart307e3382020-11-15 11:26:30 -08004445 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
James Smart685f0bf2007-04-25 09:53:08 -04004446 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004447
James Smarte8b62012007-08-02 11:10:09 -04004448 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4449 "0904 NPort state transition x%06x, %s -> %s\n",
4450 ndlp->nlp_DID,
4451 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4452 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004453
4454 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4455 "node statechg did:x%x old:%d ste:%d",
4456 ndlp->nlp_DID, old_state, state);
4457
James Smart307e3382020-11-15 11:26:30 -08004458 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4459 state != NLP_STE_UNUSED_NODE) {
4460 ndlp->nlp_flag &= ~NLP_DROPPED;
4461 lpfc_nlp_get(ndlp);
4462 }
4463
James Smartde0c5b32007-04-25 09:52:27 -04004464 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004465 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004466 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004467 if (old_state == NLP_STE_UNMAPPED_NODE) {
4468 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4469 ndlp->nlp_type &= ~NLP_FC_NODE;
4470 }
4471
James Smart685f0bf2007-04-25 09:53:08 -04004472 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004473 spin_lock_irq(shost->host_lock);
4474 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4475 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004476 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004477 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004478
4479 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004480 lpfc_nlp_counters(vport, state, 1);
4481 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004482}
4483
4484void
James Smarte47c9092008-02-08 18:49:26 -05004485lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4486{
4487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4488
4489 if (list_empty(&ndlp->nlp_listp)) {
4490 spin_lock_irq(shost->host_lock);
4491 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4492 spin_unlock_irq(shost->host_lock);
4493 }
4494}
4495
4496void
James Smart2e0fef82007-06-17 19:56:36 -05004497lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004498{
James Smart2e0fef82007-06-17 19:56:36 -05004499 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4500
James Smart0d2b6b82008-06-14 22:52:47 -04004501 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004502 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004503 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4504 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004505 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004506 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004507 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004508 NLP_STE_UNUSED_NODE);
4509}
4510
James Smart109f6ed2008-12-04 22:39:08 -05004511/**
James Smart3621a712009-04-06 18:47:14 -04004512 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004513 * @vport: Pointer to Virtual Port object.
4514 * @ndlp: Pointer to FC node object.
4515 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004516 *
4517 * This function is always called when node object need to be initialized.
4518 * It initializes all the fields of the node object. Although the reference
4519 * to phba from @ndlp can be obtained indirectly through it's reference to
4520 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4521 * to the life-span of the @ndlp might go beyond the existence of @vport as
4522 * the final release of ndlp is determined by its reference count. And, the
4523 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004524 **/
4525static inline void
4526lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4527 uint32_t did)
4528{
4529 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4530 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004531 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smarte7dab162020-10-20 13:27:12 -07004532 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4533
James Smart109f6ed2008-12-04 22:39:08 -05004534 ndlp->nlp_DID = did;
4535 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004536 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004537 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004538 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004539 kref_init(&ndlp->kref);
James Smart109f6ed2008-12-04 22:39:08 -05004540 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004541 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004542 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004543}
James Smarte47c9092008-02-08 18:49:26 -05004544
James Smartde0c5b32007-04-25 09:52:27 -04004545void
James Smart2e0fef82007-06-17 19:56:36 -05004546lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004547{
James Smart87af33f2007-10-27 13:37:43 -04004548 /*
James Smartfa4066b2008-01-11 01:53:27 -05004549 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004550 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004551 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4552 * until ALL other outstanding threads have completed. We check
4553 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004554 */
James Smartfa4066b2008-01-11 01:53:27 -05004555 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4556 return;
James Smart51ef4c22007-08-02 11:10:31 -04004557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart307e3382020-11-15 11:26:30 -08004558 ndlp->nlp_flag |= NLP_DROPPED;
James Smartbe6bb942015-04-07 15:07:22 -04004559 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004560 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004561 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004562 }
James Smart02902172015-05-21 13:55:17 -04004563
4564 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004565 return;
dea31012005-04-17 16:05:31 -05004566}
4567
4568/*
4569 * Start / ReStart rescue timer for Discovery / RSCN handling
4570 */
4571void
James Smart2e0fef82007-06-17 19:56:36 -05004572lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004573{
James Smart2e0fef82007-06-17 19:56:36 -05004574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004576 uint32_t tmo;
4577
James Smart2e0fef82007-06-17 19:56:36 -05004578 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004579 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004580 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4581 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004582 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004583 * FC spec states we need 3 * ratov for CT requests
4584 */
4585 tmo = ((phba->fc_ratov * 3) + 3);
4586 }
dea31012005-04-17 16:05:31 -05004587
James Smart858c9f62007-06-17 19:56:39 -05004588
4589 if (!timer_pending(&vport->fc_disctmo)) {
4590 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4591 "set disc timer: tmo:x%x state:x%x flg:x%x",
4592 tmo, vport->port_state, vport->fc_flag);
4593 }
4594
James Smart256ec0d2013-04-17 20:14:58 -04004595 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004596 spin_lock_irq(shost->host_lock);
4597 vport->fc_flag |= FC_DISC_TMO;
4598 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004599
4600 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004601 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4602 "0247 Start Discovery Timer state x%x "
4603 "Data: x%x x%lx x%x x%x\n",
4604 vport->port_state, tmo,
4605 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4606 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004607
4608 return;
4609}
4610
4611/*
4612 * Cancel rescue timer for Discovery / RSCN handling
4613 */
4614int
James Smart2e0fef82007-06-17 19:56:36 -05004615lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004616{
James Smart2e0fef82007-06-17 19:56:36 -05004617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004618 unsigned long iflags;
4619
James Smart858c9f62007-06-17 19:56:39 -05004620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4621 "can disc timer: state:x%x rtry:x%x flg:x%x",
4622 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4623
dea31012005-04-17 16:05:31 -05004624 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004625 if (vport->fc_flag & FC_DISC_TMO) {
4626 spin_lock_irqsave(shost->host_lock, iflags);
4627 vport->fc_flag &= ~FC_DISC_TMO;
4628 spin_unlock_irqrestore(shost->host_lock, iflags);
4629 del_timer_sync(&vport->fc_disctmo);
4630 spin_lock_irqsave(&vport->work_port_lock, iflags);
4631 vport->work_port_events &= ~WORKER_DISC_TMO;
4632 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004633 }
4634
4635 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004636 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4637 "0248 Cancel Discovery Timer state x%x "
4638 "Data: x%x x%x x%x\n",
4639 vport->port_state, vport->fc_flag,
4640 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004641 return 0;
dea31012005-04-17 16:05:31 -05004642}
4643
4644/*
4645 * Check specified ring for outstanding IOCB on the SLI queue
4646 * Return true if iocb matches the specified nport
4647 */
4648int
James Smart2e0fef82007-06-17 19:56:36 -05004649lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4650 struct lpfc_sli_ring *pring,
4651 struct lpfc_iocbq *iocb,
4652 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004653{
James Smart2e0fef82007-06-17 19:56:36 -05004654 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004655 struct lpfc_vport *vport = ndlp->vport;
4656
4657 if (iocb->vport != vport)
4658 return 0;
4659
dea31012005-04-17 16:05:31 -05004660 if (pring->ringno == LPFC_ELS_RING) {
4661 switch (icmd->ulpCommand) {
4662 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004663 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004664 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004665 fallthrough;
dea31012005-04-17 16:05:31 -05004666 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004667 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4668 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05004669 fallthrough;
dea31012005-04-17 16:05:31 -05004670 case CMD_XMIT_ELS_RSP64_CX:
4671 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004672 return 1;
dea31012005-04-17 16:05:31 -05004673 }
James Smart895427b2017-02-12 13:52:30 -08004674 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004675 /* Skip match check if waiting to relogin to FCP target */
4676 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004677 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004678 return 0;
dea31012005-04-17 16:05:31 -05004679 }
4680 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004681 return 1;
dea31012005-04-17 16:05:31 -05004682 }
dea31012005-04-17 16:05:31 -05004683 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004684 return 0;
dea31012005-04-17 16:05:31 -05004685}
4686
James Smart895427b2017-02-12 13:52:30 -08004687static void
4688__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4689 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4690 struct list_head *dequeue_list)
4691{
4692 struct lpfc_iocbq *iocb, *next_iocb;
4693
4694 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4695 /* Check to see if iocb matches the nport */
4696 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4697 /* match, dequeue */
4698 list_move_tail(&iocb->list, dequeue_list);
4699 }
4700}
4701
4702static void
4703lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4704 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4705{
4706 struct lpfc_sli *psli = &phba->sli;
4707 uint32_t i;
4708
4709 spin_lock_irq(&phba->hbalock);
4710 for (i = 0; i < psli->num_rings; i++)
4711 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4712 dequeue_list);
4713 spin_unlock_irq(&phba->hbalock);
4714}
4715
4716static void
4717lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4718 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4719{
4720 struct lpfc_sli_ring *pring;
4721 struct lpfc_queue *qp = NULL;
4722
4723 spin_lock_irq(&phba->hbalock);
4724 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4725 pring = qp->pring;
4726 if (!pring)
4727 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004728 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004729 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004730 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004731 }
4732 spin_unlock_irq(&phba->hbalock);
4733}
4734
dea31012005-04-17 16:05:31 -05004735/*
4736 * Free resources / clean up outstanding I/Os
4737 * associated with nlp_rpi in the LPFC_NODELIST entry.
4738 */
4739static int
James Smart2e0fef82007-06-17 19:56:36 -05004740lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004741{
James Smart2534ba72007-04-25 09:52:20 -04004742 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004743
James Smart92d7f7b2007-06-17 19:56:38 -05004744 lpfc_fabric_abort_nport(ndlp);
4745
dea31012005-04-17 16:05:31 -05004746 /*
4747 * Everything that matches on txcmplq will be returned
4748 * by firmware with a no rpi error.
4749 */
James Smart40426292010-12-15 17:58:10 -05004750 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004751 if (phba->sli_rev != LPFC_SLI_REV4)
4752 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4753 else
4754 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004755 }
James Smart2534ba72007-04-25 09:52:20 -04004756
James Smarta257bf92009-04-06 18:48:10 -04004757 /* Cancel all the IOCBs from the completions list */
4758 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4759 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004760
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004761 return 0;
dea31012005-04-17 16:05:31 -05004762}
4763
James Smart086a3452012-08-14 14:25:21 -04004764/**
4765 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4766 * @phba: Pointer to HBA context object.
4767 * @pmb: Pointer to mailbox object.
4768 *
4769 * This function will issue an ELS LOGO command after completing
4770 * the UNREG_RPI.
4771 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004772static void
James Smart086a3452012-08-14 14:25:21 -04004773lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4774{
4775 struct lpfc_vport *vport = pmb->vport;
4776 struct lpfc_nodelist *ndlp;
4777
James Smart3e1f0712018-11-29 16:09:29 -08004778 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004779 if (!ndlp)
4780 return;
4781 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004782 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004783
4784 /* Check to see if there are any deferred events to process */
4785 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4786 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4787 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4788 "1434 UNREG cmpl deferred logo x%x "
James Smart32350662019-08-14 16:57:06 -07004789 "on NPort x%x Data: x%x x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004790 ndlp->nlp_rpi, ndlp->nlp_DID,
4791 ndlp->nlp_defer_did, ndlp);
4792
4793 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4794 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4795 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08004796 } else {
James Smart4f1a2fe2019-08-14 16:56:32 -07004797 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4798 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4799 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
James Smart0f154222019-09-21 20:58:52 -07004800 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smart4f1a2fe2019-08-14 16:56:32 -07004801 }
James Smart00292e02018-12-13 15:17:55 -08004802 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smartdea16bd2018-11-29 16:09:30 -08004803 }
James Smart086a3452012-08-14 14:25:21 -04004804}
4805
dea31012005-04-17 16:05:31 -05004806/*
James Smart97acd002019-09-21 20:58:51 -07004807 * Sets the mailbox completion handler to be used for the
4808 * unreg_rpi command. The handler varies based on the state of
4809 * the port and what will be happening to the rpi next.
4810 */
4811static void
4812lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4813 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4814{
4815 unsigned long iflags;
4816
4817 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4818 mbox->ctx_ndlp = ndlp;
4819 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4820
4821 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4822 (!(vport->load_flag & FC_UNLOADING)) &&
4823 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4824 LPFC_SLI_INTF_IF_TYPE_2) &&
4825 (kref_read(&ndlp->kref) > 0)) {
4826 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4827 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4828 } else {
4829 if (vport->load_flag & FC_UNLOADING) {
4830 if (phba->sli_rev == LPFC_SLI_REV4) {
4831 spin_lock_irqsave(&vport->phba->ndlp_lock,
4832 iflags);
4833 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4834 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
4835 iflags);
4836 }
4837 lpfc_nlp_get(ndlp);
4838 }
4839 mbox->ctx_ndlp = ndlp;
4840 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4841 }
4842}
4843
4844/*
dea31012005-04-17 16:05:31 -05004845 * Free rpi associated with LPFC_NODELIST entry.
4846 * This routine is called from lpfc_freenode(), when we are removing
4847 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4848 * LOGO that completes successfully, and we are waiting to PLOGI back
4849 * to the remote NPort. In addition, it is called after we receive
4850 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4851 * we are waiting to PLOGI back to the remote NPort.
4852 */
4853int
James Smart2e0fef82007-06-17 19:56:36 -05004854lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004855{
James Smart2e0fef82007-06-17 19:56:36 -05004856 struct lpfc_hba *phba = vport->phba;
4857 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004858 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004859 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004860
James Smartf454a9a2013-09-06 12:20:07 -04004861 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4862 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4863 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
James Smart0f154222019-09-21 20:58:52 -07004864 lpfc_printf_vlog(vport, KERN_INFO,
4865 LOG_NODE | LOG_DISCOVERY,
James Smartf454a9a2013-09-06 12:20:07 -04004866 "3366 RPI x%x needs to be "
4867 "unregistered nlp_flag x%x "
4868 "did x%x\n",
4869 ndlp->nlp_rpi, ndlp->nlp_flag,
4870 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004871
4872 /* If there is already an UNREG in progress for this ndlp,
4873 * no need to queue up another one.
4874 */
4875 if (ndlp->nlp_flag & NLP_UNREG_INP) {
James Smart0f154222019-09-21 20:58:52 -07004876 lpfc_printf_vlog(vport, KERN_INFO,
4877 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004878 "1436 unreg_rpi SKIP UNREG x%x on "
4879 "NPort x%x deferred x%x flg x%x "
James Smart32350662019-08-14 16:57:06 -07004880 "Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004881 ndlp->nlp_rpi, ndlp->nlp_DID,
4882 ndlp->nlp_defer_did,
4883 ndlp->nlp_flag, ndlp);
4884 goto out;
4885 }
4886
James Smart2e0fef82007-06-17 19:56:36 -05004887 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4888 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004889 /* SLI4 ports require the physical rpi value. */
4890 rpi = ndlp->nlp_rpi;
4891 if (phba->sli_rev == LPFC_SLI_REV4)
4892 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004893
James Smart6d368e52011-05-24 11:44:12 -04004894 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004895 mbox->vport = vport;
James Smart97acd002019-09-21 20:58:51 -07004896 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
4897 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4898 /*
4899 * accept PLOGIs after unreg_rpi_cmpl
4900 */
4901 acc_plogi = 0;
James Smartdea16bd2018-11-29 16:09:30 -08004902 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4903 Fabric_DID_MASK) &&
4904 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4905 ndlp->nlp_flag |= NLP_UNREG_INP;
4906
James Smart0f154222019-09-21 20:58:52 -07004907 lpfc_printf_vlog(vport, KERN_INFO,
4908 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004909 "1433 unreg_rpi UNREG x%x on "
James Smart32350662019-08-14 16:57:06 -07004910 "NPort x%x deferred flg x%x "
4911 "Data:x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004912 ndlp->nlp_rpi, ndlp->nlp_DID,
4913 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004914
James Smart0b727fe2007-10-27 13:37:25 -04004915 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004916 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004917 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004918 acc_plogi = 1;
4919 }
James Smarte7dab162020-10-20 13:27:12 -07004920 } else {
4921 lpfc_printf_vlog(vport, KERN_INFO,
4922 LOG_NODE | LOG_DISCOVERY,
4923 "1444 Failed to allocate mempool "
4924 "unreg_rpi UNREG x%x, "
4925 "DID x%x, flag x%x, "
4926 "ndlp x%px\n",
4927 ndlp->nlp_rpi, ndlp->nlp_DID,
4928 ndlp->nlp_flag, ndlp);
4929
4930 /* Because mempool_alloc failed, we
4931 * will issue a LOGO here and keep the rpi alive if
4932 * not unloading.
4933 */
4934 if (!(vport->load_flag & FC_UNLOADING)) {
4935 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4936 lpfc_issue_els_logo(vport, ndlp, 0);
4937 ndlp->nlp_prev_state = ndlp->nlp_state;
4938 lpfc_nlp_set_state(vport, ndlp,
4939 NLP_STE_NPR_NODE);
4940 }
4941
4942 return 1;
dea31012005-04-17 16:05:31 -05004943 }
dea31012005-04-17 16:05:31 -05004944 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004945out:
James Smart40426292010-12-15 17:58:10 -05004946 if (phba->sli_rev != LPFC_SLI_REV4)
4947 ndlp->nlp_rpi = 0;
4948 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004949 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004950 if (acc_plogi)
4951 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004952 return 1;
4953 }
James Smart7c5e5182015-05-22 10:42:43 -04004954 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004955 return 0;
4956}
4957
James Smartecfd03c2010-02-12 14:41:27 -05004958/**
4959 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4960 * @phba: pointer to lpfc hba data structure.
4961 *
4962 * This routine is invoked to unregister all the currently registered RPIs
4963 * to the HBA.
4964 **/
4965void
4966lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4967{
4968 struct lpfc_vport **vports;
4969 struct lpfc_nodelist *ndlp;
4970 struct Scsi_Host *shost;
4971 int i;
4972
4973 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004974 if (!vports) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004975 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4976 "2884 Vport array allocation failed \n");
James Smart63e801c2010-11-20 23:14:19 -05004977 return;
4978 }
James Smartecfd03c2010-02-12 14:41:27 -05004979 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4980 shost = lpfc_shost_from_vport(vports[i]);
4981 spin_lock_irq(shost->host_lock);
4982 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004983 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004984 /* The mempool_alloc might sleep */
4985 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004986 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004987 spin_lock_irq(shost->host_lock);
4988 }
James Smartecfd03c2010-02-12 14:41:27 -05004989 }
4990 spin_unlock_irq(shost->host_lock);
4991 }
4992 lpfc_destroy_vport_work_array(phba, vports);
4993}
4994
James Smart92d7f7b2007-06-17 19:56:38 -05004995void
4996lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4997{
4998 struct lpfc_hba *phba = vport->phba;
4999 LPFC_MBOXQ_t *mbox;
5000 int rc;
5001
James Smart5af5eee2010-10-22 11:06:38 -04005002 if (phba->sli_rev == LPFC_SLI_REV4) {
5003 lpfc_sli4_unreg_all_rpis(vport);
5004 return;
5005 }
5006
James Smart92d7f7b2007-06-17 19:56:38 -05005007 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5008 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005009 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5010 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005011 mbox->vport = vport;
5012 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005013 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005014 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005015 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005016 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04005017
5018 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005019 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5020 "1836 Could not issue "
5021 "unreg_login(all_rpis) status %d\n",
5022 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005023 }
5024}
5025
5026void
5027lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5028{
5029 struct lpfc_hba *phba = vport->phba;
5030 LPFC_MBOXQ_t *mbox;
5031 int rc;
5032
James Smartc95a3b42019-03-12 16:30:07 -07005033 /* Unreg DID is an SLI3 operation. */
5034 if (phba->sli_rev > LPFC_SLI_REV3)
5035 return;
5036
James Smart92d7f7b2007-06-17 19:56:38 -05005037 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5038 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005039 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5040 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005041 mbox->vport = vport;
5042 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005043 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005044 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005045 if (rc != MBX_TIMEOUT)
5046 mempool_free(mbox, phba->mbox_mem_pool);
5047
5048 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005049 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005050 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005051 "unreg_did (default rpis) status %d\n",
5052 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005053 }
5054}
5055
dea31012005-04-17 16:05:31 -05005056/*
5057 * Free resources associated with LPFC_NODELIST entry
5058 * so it can be freed.
5059 */
5060static int
James Smart2e0fef82007-06-17 19:56:36 -05005061lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005062{
James Smart2e0fef82007-06-17 19:56:36 -05005063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5064 struct lpfc_hba *phba = vport->phba;
5065 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005066 struct lpfc_dmabuf *mp;
James Smart97acd002019-09-21 20:58:51 -07005067 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005068
5069 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005070 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5071 "0900 Cleanup node for NPort x%x "
5072 "Data: x%x x%x x%x\n",
5073 ndlp->nlp_DID, ndlp->nlp_flag,
5074 ndlp->nlp_state, ndlp->nlp_rpi);
James Smart307e3382020-11-15 11:26:30 -08005075 lpfc_dequeue_node(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -04005076
5077 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5078
dea31012005-04-17 16:05:31 -05005079 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5080 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005081 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005082 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005083 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5084 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005085 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5086 }
5087 }
James Smart33ccf8d2006-08-17 11:57:58 -04005088
James Smart2e0fef82007-06-17 19:56:36 -05005089 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005090 /* Cleanup REG_LOGIN completions which are not yet processed */
5091 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5092 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005093 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005094 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005095 continue;
5096
James Smart3e1f0712018-11-29 16:09:29 -08005097 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005098 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5099 }
5100
dea31012005-04-17 16:05:31 -05005101 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005102 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005103 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005104 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5105 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005106 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005107 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005108 kfree(mp);
5109 }
5110 list_del(&mb->list);
5111 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005112 /* We shall not invoke the lpfc_nlp_put to decrement
5113 * the ndlp reference count as we are in the process
5114 * of lpfc_nlp_release.
5115 */
dea31012005-04-17 16:05:31 -05005116 }
5117 }
James Smart2e0fef82007-06-17 19:56:36 -05005118 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005119
James Smarte47c9092008-02-08 18:49:26 -05005120 lpfc_els_abort(phba, ndlp);
5121
James Smart2e0fef82007-06-17 19:56:36 -05005122 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04005123 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05005124 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005125
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005126 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005127 del_timer_sync(&ndlp->nlp_delayfunc);
5128
James Smart0d2b6b82008-06-14 22:52:47 -04005129 list_del_init(&ndlp->els_retry_evt.evt_listp);
5130 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smarte7dab162020-10-20 13:27:12 -07005131 list_del_init(&ndlp->recovery_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005132 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart4f1a2fe2019-08-14 16:56:32 -07005133 if (phba->sli_rev == LPFC_SLI_REV4)
5134 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smart97acd002019-09-21 20:58:51 -07005135 if (!lpfc_unreg_rpi(vport, ndlp)) {
5136 /* Clean up unregistered and non freed rpis */
5137 if ((ndlp->nlp_flag & NLP_RELEASE_RPI) &&
5138 !(ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)) {
5139 lpfc_sli4_free_rpi(vport->phba,
5140 ndlp->nlp_rpi);
5141 spin_lock_irqsave(&vport->phba->ndlp_lock,
5142 iflags);
5143 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5144 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5145 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
5146 iflags);
5147 }
5148 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005149 return 0;
dea31012005-04-17 16:05:31 -05005150}
5151
5152/*
5153 * Check to see if we can free the nlp back to the freelist.
5154 * If we are in the middle of using the nlp in the discovery state
5155 * machine, defer the free till we reach the end of the state machine.
5156 */
James Smart329f9bc2007-04-25 09:53:01 -04005157static void
James Smart2e0fef82007-06-17 19:56:36 -05005158lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005159{
James Smarta8adb832007-10-27 13:37:53 -04005160 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04005161 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04005162 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04005163 LPFC_MBOXQ_t *mbox;
5164 int rc;
dea31012005-04-17 16:05:31 -05005165
James Smart0d2b6b82008-06-14 22:52:47 -04005166 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08005167 if (!(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
Dick Kennedye8bcf0a2017-09-29 17:34:32 -07005168 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5169 phba->sli_rev != LPFC_SLI_REV4) {
James Smarta8adb832007-10-27 13:37:53 -04005170 /* For this case we need to cleanup the default rpi
5171 * allocated by the firmware.
5172 */
James Smart0f154222019-09-21 20:58:52 -07005173 lpfc_printf_vlog(vport, KERN_INFO,
5174 LOG_NODE | LOG_DISCOVERY,
5175 "0005 Cleanup Default rpi:x%x DID:x%x flg:x%x "
James Smart307e3382020-11-15 11:26:30 -08005176 "ref %d ndlp x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04005177 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005178 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08005179 ndlp);
James Smarta8adb832007-10-27 13:37:53 -04005180 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5181 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04005182 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05005183 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04005184 if (rc) {
5185 mempool_free(mbox, phba->mbox_mem_pool);
5186 }
5187 else {
5188 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5189 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5190 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08005191 mbox->ctx_ndlp = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04005192 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5193 if (rc == MBX_NOT_FINISHED) {
5194 mempool_free(mbox, phba->mbox_mem_pool);
5195 }
5196 }
5197 }
5198 }
James Smart2e0fef82007-06-17 19:56:36 -05005199 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04005200
James Smart2e0fef82007-06-17 19:56:36 -05005201 /*
James Smart466e8402015-05-21 13:55:28 -04005202 * ndlp->rport must be set to NULL before it reaches here
5203 * i.e. break rport/node link before doing lpfc_nlp_put for
5204 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05005205 */
James Smart92d7f7b2007-06-17 19:56:38 -05005206 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04005207 /*
5208 * extra lpfc_nlp_put dropped the reference of ndlp
5209 * for registered rport so need to cleanup rport
5210 */
5211 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07005212 "0940 removed node x%px DID x%x "
James Smart0f154222019-09-21 20:58:52 -07005213 "rpi %d rport not null x%px\n",
5214 ndlp, ndlp->nlp_DID, ndlp->nlp_rpi,
5215 ndlp->rport);
James Smart466e8402015-05-21 13:55:28 -04005216 rport = ndlp->rport;
5217 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04005218 rdata->pnode = NULL;
5219 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04005220 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05005221 }
dea31012005-04-17 16:05:31 -05005222}
5223
5224static int
James Smart2e0fef82007-06-17 19:56:36 -05005225lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5226 uint32_t did)
dea31012005-04-17 16:05:31 -05005227{
James Smart2e0fef82007-06-17 19:56:36 -05005228 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005229
5230 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005231 return 0;
dea31012005-04-17 16:05:31 -05005232
dea31012005-04-17 16:05:31 -05005233 /* First check for Direct match */
5234 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005235 return 1;
dea31012005-04-17 16:05:31 -05005236
5237 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005238 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005239 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005240 return 0;
dea31012005-04-17 16:05:31 -05005241 }
5242
5243 matchdid.un.word = did;
5244 ndlpdid.un.word = ndlp->nlp_DID;
5245 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5246 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5247 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005248 /* This code is supposed to match the ID
5249 * for a private loop device that is
5250 * connect to fl_port. But we need to
5251 * check that the port did not just go
5252 * from pt2pt to fabric or we could end
5253 * up matching ndlp->nlp_DID 000001 to
5254 * fabric DID 0x20101
5255 */
dea31012005-04-17 16:05:31 -05005256 if ((ndlpdid.un.b.domain == 0) &&
5257 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005258 if (ndlpdid.un.b.id &&
5259 vport->phba->fc_topology ==
5260 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005261 return 1;
dea31012005-04-17 16:05:31 -05005262 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005263 return 0;
dea31012005-04-17 16:05:31 -05005264 }
5265
5266 matchdid.un.word = ndlp->nlp_DID;
5267 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5268 (mydid.un.b.area == ndlpdid.un.b.area)) {
5269 if ((matchdid.un.b.domain == 0) &&
5270 (matchdid.un.b.area == 0)) {
5271 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005272 return 1;
dea31012005-04-17 16:05:31 -05005273 }
5274 }
5275 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005276 return 0;
dea31012005-04-17 16:05:31 -05005277}
5278
James Smart685f0bf2007-04-25 09:53:08 -04005279/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005280static struct lpfc_nodelist *
5281__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005282{
James Smart2fb9bd82006-12-02 13:33:57 -05005283 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005284 uint32_t data1;
5285
James Smart2e0fef82007-06-17 19:56:36 -05005286 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5287 if (lpfc_matchdid(vport, ndlp, did)) {
James Smartb95b2112019-08-14 16:56:47 -07005288 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5289 ((uint32_t)ndlp->nlp_xri << 16) |
James Smart307e3382020-11-15 11:26:30 -08005290 ((uint32_t)ndlp->nlp_type << 8)
5291 );
James Smarte8b62012007-08-02 11:10:09 -04005292 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5293 "0929 FIND node DID "
James Smartb95b2112019-08-14 16:56:47 -07005294 "Data: x%px x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005295 ndlp, ndlp->nlp_DID,
James Smartb95b2112019-08-14 16:56:47 -07005296 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
James Smartcff261f2013-12-17 20:29:47 -05005297 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005298 return ndlp;
dea31012005-04-17 16:05:31 -05005299 }
5300 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005301
dea31012005-04-17 16:05:31 -05005302 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005303 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5304 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005305 return NULL;
5306}
5307
5308struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005309lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005310{
James Smart2e0fef82007-06-17 19:56:36 -05005311 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005312 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005313 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005314
James Smartfedd3b72011-02-16 12:39:24 -05005315 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005316 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005317 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005318 return ndlp;
5319}
5320
5321struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005322lpfc_findnode_mapped(struct lpfc_vport *vport)
5323{
5324 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5325 struct lpfc_nodelist *ndlp;
5326 uint32_t data1;
5327 unsigned long iflags;
5328
5329 spin_lock_irqsave(shost->host_lock, iflags);
5330
5331 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5332 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5333 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5334 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5335 ((uint32_t)ndlp->nlp_xri << 16) |
5336 ((uint32_t)ndlp->nlp_type << 8) |
5337 ((uint32_t)ndlp->nlp_rpi & 0xff));
5338 spin_unlock_irqrestore(shost->host_lock, iflags);
5339 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5340 "2025 FIND node DID "
James Smart32350662019-08-14 16:57:06 -07005341 "Data: x%px x%x x%x x%x x%px\n",
James Smartf60cb932019-05-14 14:58:05 -07005342 ndlp, ndlp->nlp_DID,
5343 ndlp->nlp_flag, data1,
5344 ndlp->active_rrqs_xri_bitmap);
5345 return ndlp;
5346 }
5347 }
5348 spin_unlock_irqrestore(shost->host_lock, iflags);
5349
5350 /* FIND node did <did> NOT FOUND */
5351 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5352 "2026 FIND mapped did NOT FOUND.\n");
5353 return NULL;
5354}
5355
5356struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005357lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5358{
5359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5360 struct lpfc_nodelist *ndlp;
5361
5362 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005363 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005364 if (vport->phba->nvmet_support)
5365 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005366 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5367 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005368 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005369 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005370 if (!ndlp)
5371 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb4b34172019-10-18 14:18:31 -07005373
5374 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5375 "6453 Setup New Node 2B_DISC x%x "
5376 "Data:x%x x%x x%x\n",
5377 ndlp->nlp_DID, ndlp->nlp_flag,
5378 ndlp->nlp_state, vport->fc_flag);
5379
James Smart2e0fef82007-06-17 19:56:36 -05005380 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005381 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005382 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005383 return ndlp;
5384 }
James Smarte47c9092008-02-08 18:49:26 -05005385
James Smart1c5b12f2017-04-21 16:05:03 -07005386 /* The NVME Target does not want to actively manage an rport.
5387 * The goal is to allow the target to reset its state and clear
5388 * pending IO in preparation for the initiator to recover.
5389 */
James Smart58da1ff2008-04-07 10:15:56 -04005390 if ((vport->fc_flag & FC_RSCN_MODE) &&
5391 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005392 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005393
5394 /* Since this node is marked for discovery,
5395 * delay timeout is not needed.
5396 */
5397 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5398
James Smartb4b34172019-10-18 14:18:31 -07005399 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5400 "6455 Setup RSCN Node 2B_DISC x%x "
5401 "Data:x%x x%x x%x\n",
5402 ndlp->nlp_DID, ndlp->nlp_flag,
5403 ndlp->nlp_state, vport->fc_flag);
5404
James Smart1c5b12f2017-04-21 16:05:03 -07005405 /* NVME Target mode waits until rport is known to be
5406 * impacted by the RSCN before it transitions. No
5407 * active management - just go to NPR provided the
5408 * node had a valid login.
5409 */
5410 if (vport->phba->nvmet_support)
5411 return ndlp;
5412
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005413 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005414 * we don't need to try to discover it again.
5415 */
James Smart3f97aed2019-09-21 20:58:55 -07005416 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5417 !(ndlp->nlp_type &
5418 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
James Smart87af33f2007-10-27 13:37:43 -04005419 return NULL;
5420
James Smart3f97aed2019-09-21 20:58:55 -07005421 ndlp->nlp_prev_state = ndlp->nlp_state;
5422 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5423
James Smarta257bf92009-04-06 18:48:10 -04005424 spin_lock_irq(shost->host_lock);
5425 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5426 spin_unlock_irq(shost->host_lock);
James Smartb4b34172019-10-18 14:18:31 -07005427 } else {
5428 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5429 "6456 Skip Setup RSCN Node x%x "
5430 "Data:x%x x%x x%x\n",
5431 ndlp->nlp_DID, ndlp->nlp_flag,
5432 ndlp->nlp_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05005433 ndlp = NULL;
James Smartb4b34172019-10-18 14:18:31 -07005434 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005435 } else {
James Smartb4b34172019-10-18 14:18:31 -07005436 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5437 "6457 Setup Active Node 2B_DISC x%x "
5438 "Data:x%x x%x x%x\n",
5439 ndlp->nlp_DID, ndlp->nlp_flag,
5440 ndlp->nlp_state, vport->fc_flag);
5441
James Smart1c5b12f2017-04-21 16:05:03 -07005442 /* If the initiator received a PLOGI from this NPort or if the
5443 * initiator is already in the process of discovery on it,
5444 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005445 */
James Smart685f0bf2007-04-25 09:53:08 -04005446 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005447 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005448 (!vport->phba->nvmet_support &&
5449 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005450 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005451
James Smart8c258642017-02-12 13:52:36 -08005452 if (vport->phba->nvmet_support)
5453 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005454
5455 /* Moving to NPR state clears unsolicited flags and
5456 * allows for rediscovery
5457 */
5458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5459
James Smart2e0fef82007-06-17 19:56:36 -05005460 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005461 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005462 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005463 }
5464 return ndlp;
5465}
5466
5467/* Build a list of nodes to discover based on the loopmap */
5468void
James Smart2e0fef82007-06-17 19:56:36 -05005469lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005470{
James Smart2e0fef82007-06-17 19:56:36 -05005471 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005472 int j;
5473 uint32_t alpa, index;
5474
James Smart2e0fef82007-06-17 19:56:36 -05005475 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005476 return;
James Smart2e0fef82007-06-17 19:56:36 -05005477
James Smart76a95d72010-11-20 23:11:48 -05005478 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005479 return;
dea31012005-04-17 16:05:31 -05005480
5481 /* Check for loop map present or not */
5482 if (phba->alpa_map[0]) {
5483 for (j = 1; j <= phba->alpa_map[0]; j++) {
5484 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005485 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005486 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005487 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005488 }
5489 } else {
5490 /* No alpamap, so try all alpa's */
5491 for (j = 0; j < FC_MAXLOOP; j++) {
5492 /* If cfg_scan_down is set, start from highest
5493 * ALPA (0xef) to lowest (0x1).
5494 */
James Smart3de2a652007-08-02 11:09:59 -04005495 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005496 index = j;
5497 else
5498 index = FC_MAXLOOP - j - 1;
5499 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005500 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005501 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005502 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005503 }
5504 }
5505 return;
5506}
5507
James Smart895427b2017-02-12 13:52:30 -08005508/* SLI3 only */
dea31012005-04-17 16:05:31 -05005509void
James Smart2e0fef82007-06-17 19:56:36 -05005510lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005511{
dea31012005-04-17 16:05:31 -05005512 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005513 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005514 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5515 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005516 int rc;
5517
James Smart92d7f7b2007-06-17 19:56:38 -05005518 /*
5519 * if it's not a physical port or if we already send
5520 * clear_la then don't send it.
5521 */
5522 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005523 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5524 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005525 return;
5526
James Smart2e0fef82007-06-17 19:56:36 -05005527 /* Link up discovery */
5528 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5529 phba->link_state = LPFC_CLEAR_LA;
5530 lpfc_clear_la(phba, mbox);
5531 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5532 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005533 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005534 if (rc == MBX_NOT_FINISHED) {
5535 mempool_free(mbox, phba->mbox_mem_pool);
5536 lpfc_disc_flush_list(vport);
5537 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5538 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005539 phba->link_state = LPFC_HBA_ERROR;
5540 }
5541 }
5542}
5543
5544/* Reg_vpi to tell firmware to resume normal operations */
5545void
5546lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5547{
5548 LPFC_MBOXQ_t *regvpimbox;
5549
5550 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5551 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005552 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005553 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5554 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005555 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005556 == MBX_NOT_FINISHED) {
5557 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005558 }
5559 }
5560}
5561
5562/* Start Link up / RSCN discovery on NPR nodes */
5563void
5564lpfc_disc_start(struct lpfc_vport *vport)
5565{
5566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5567 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005568 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005569 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005570
James Smarte74c03c2013-04-17 20:15:19 -04005571 if (!lpfc_is_link_up(phba)) {
5572 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5573 "3315 Link is not up %x\n",
5574 phba->link_state);
dea31012005-04-17 16:05:31 -05005575 return;
James Smarte74c03c2013-04-17 20:15:19 -04005576 }
James Smart2e0fef82007-06-17 19:56:36 -05005577
5578 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005579 clear_la_pending = 1;
5580 else
5581 clear_la_pending = 0;
5582
James Smart2e0fef82007-06-17 19:56:36 -05005583 if (vport->port_state < LPFC_VPORT_READY)
5584 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005585
James Smart2e0fef82007-06-17 19:56:36 -05005586 lpfc_set_disctmo(vport);
5587
James Smart2e0fef82007-06-17 19:56:36 -05005588 vport->fc_prevDID = vport->fc_myDID;
5589 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005590
5591 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005592 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07005593 "0202 Start Discovery port state x%x "
5594 "flg x%x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04005595 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
James Smartb4b34172019-10-18 14:18:31 -07005596 vport->fc_adisc_cnt, vport->fc_npr_cnt);
dea31012005-04-17 16:05:31 -05005597
5598 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005599 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005600
5601 if (num_sent)
5602 return;
5603
James Smart6fa139f2013-04-17 20:20:00 -04005604 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005605 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005606 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005607 !(vport->fc_flag & FC_RSCN_MODE) &&
5608 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005609 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005610 lpfc_issue_reg_vpi(phba, vport);
5611 return;
5612 }
James Smart2e0fef82007-06-17 19:56:36 -05005613
James Smart92d7f7b2007-06-17 19:56:38 -05005614 /*
5615 * For SLI2, we need to set port_state to READY and continue
5616 * discovery.
5617 */
5618 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5619 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005620 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005621
5622 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005623 vport->num_disc_nodes = 0;
5624 /* go thru NPR nodes and issue ELS PLOGIs */
5625 if (vport->fc_npr_cnt)
5626 lpfc_els_disc_plogi(vport);
5627
5628 if (!vport->num_disc_nodes) {
5629 spin_lock_irq(shost->host_lock);
5630 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5631 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005632 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005633 }
5634 }
James Smart92d7f7b2007-06-17 19:56:38 -05005635 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005636 } else {
5637 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005638 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005639
5640 if (num_sent)
5641 return;
5642
James Smart2e0fef82007-06-17 19:56:36 -05005643 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005644 /* Check to see if more RSCNs came in while we
5645 * were processing this one.
5646 */
James Smart2e0fef82007-06-17 19:56:36 -05005647 if ((vport->fc_rscn_id_cnt == 0) &&
5648 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5649 spin_lock_irq(shost->host_lock);
5650 vport->fc_flag &= ~FC_RSCN_MODE;
5651 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005652 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005653 } else
James Smart2e0fef82007-06-17 19:56:36 -05005654 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005655 }
5656 }
5657 return;
5658}
5659
5660/*
5661 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5662 * ring the match the sppecified nodelist.
5663 */
5664static void
James Smart2e0fef82007-06-17 19:56:36 -05005665lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005666{
James Smart2534ba72007-04-25 09:52:20 -04005667 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005668 IOCB_t *icmd;
5669 struct lpfc_iocbq *iocb, *next_iocb;
5670 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005671
James Smart895427b2017-02-12 13:52:30 -08005672 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005673 if (unlikely(!pring))
5674 return;
dea31012005-04-17 16:05:31 -05005675
5676 /* Error matching iocb on txq or txcmplq
5677 * First check the txq.
5678 */
James Smart2e0fef82007-06-17 19:56:36 -05005679 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005680 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5681 if (iocb->context1 != ndlp) {
5682 continue;
5683 }
5684 icmd = &iocb->iocb;
5685 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5686 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5687
James Smart2534ba72007-04-25 09:52:20 -04005688 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005689 }
5690 }
5691
5692 /* Next check the txcmplq */
5693 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5694 if (iocb->context1 != ndlp) {
5695 continue;
5696 }
5697 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005698 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5699 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005700 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005701 }
5702 }
James Smart2e0fef82007-06-17 19:56:36 -05005703 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005704
James Smarta257bf92009-04-06 18:48:10 -04005705 /* Cancel all the IOCBs from the completions list */
5706 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5707 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005708}
5709
Adrian Bunka6ababd2007-11-05 18:07:33 +01005710static void
James Smart2e0fef82007-06-17 19:56:36 -05005711lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005712{
5713 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005714 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005715
James Smart2e0fef82007-06-17 19:56:36 -05005716 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5717 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005718 nlp_listp) {
5719 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5720 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5721 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005722 }
dea31012005-04-17 16:05:31 -05005723 }
5724 }
dea31012005-04-17 16:05:31 -05005725}
5726
James Smart92d7f7b2007-06-17 19:56:38 -05005727void
5728lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5729{
5730 lpfc_els_flush_rscn(vport);
5731 lpfc_els_flush_cmd(vport);
5732 lpfc_disc_flush_list(vport);
5733}
5734
dea31012005-04-17 16:05:31 -05005735/*****************************************************************************/
5736/*
5737 * NAME: lpfc_disc_timeout
5738 *
5739 * FUNCTION: Fibre Channel driver discovery timeout routine.
5740 *
5741 * EXECUTION ENVIRONMENT: interrupt only
5742 *
5743 * CALLED FROM:
5744 * Timer function
5745 *
5746 * RETURNS:
5747 * none
5748 */
5749/*****************************************************************************/
5750void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005751lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005752{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005753 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005754 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005755 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005756 unsigned long flags = 0;
5757
5758 if (unlikely(!phba))
5759 return;
5760
James Smart5e9d9b82008-06-14 22:52:53 -04005761 spin_lock_irqsave(&vport->work_port_lock, flags);
5762 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5763 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005764 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005765 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005766
James Smart5e9d9b82008-06-14 22:52:53 -04005767 if (!tmo_posted)
5768 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005769 return;
5770}
5771
5772static void
James Smart2e0fef82007-06-17 19:56:36 -05005773lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005774{
James Smart2e0fef82007-06-17 19:56:36 -05005775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5776 struct lpfc_hba *phba = vport->phba;
5777 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005778 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005779 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005780 int rc, clrlaerr = 0;
5781
James Smart2e0fef82007-06-17 19:56:36 -05005782 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005783 return;
5784
James Smart2e0fef82007-06-17 19:56:36 -05005785 spin_lock_irq(shost->host_lock);
5786 vport->fc_flag &= ~FC_DISC_TMO;
5787 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005788
James Smart858c9f62007-06-17 19:56:39 -05005789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5790 "disc timeout: state:x%x rtry:x%x flg:x%x",
5791 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5792
James Smart2e0fef82007-06-17 19:56:36 -05005793 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005794
5795 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005796 /*
5797 * port_state is identically LPFC_LOCAL_CFG_LINK while
5798 * waiting for FAN timeout
5799 */
James Smarte8b62012007-08-02 11:10:09 -04005800 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5801 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005802
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005803 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005804 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005805 nlp_listp) {
5806 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5807 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005808 if (ndlp->nlp_type & NLP_FABRIC) {
5809 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005810 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005811
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005812 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005813 /* Fail outstanding IO now since device
5814 * is marked for PLOGI.
5815 */
James Smart2e0fef82007-06-17 19:56:36 -05005816 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005817 }
5818 }
James Smart92d7f7b2007-06-17 19:56:38 -05005819 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005820 if (phba->sli_rev <= LPFC_SLI_REV3)
5821 lpfc_initial_flogi(vport);
5822 else
5823 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005824 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005825 }
dea31012005-04-17 16:05:31 -05005826 break;
5827
James Smart92d7f7b2007-06-17 19:56:38 -05005828 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005829 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005830 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005831 /* Initial FLOGI timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005832 lpfc_printf_vlog(vport, KERN_ERR,
5833 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005834 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005835 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005836
5837 /* Assume no Fabric and go on with discovery.
5838 * Check for outstanding ELS FLOGI to abort.
5839 */
5840
5841 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005842 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005843
5844 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005845 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005846 break;
5847
5848 case LPFC_FABRIC_CFG_LINK:
5849 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5850 NameServer login */
Dick Kennedy372c1872020-06-30 14:50:00 -07005851 lpfc_printf_vlog(vport, KERN_ERR,
5852 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005853 "0223 Timeout while waiting for "
5854 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005855 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005856 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08005857 if (ndlp)
James Smart87af33f2007-10-27 13:37:43 -04005858 lpfc_els_abort(phba, ndlp);
5859
5860 /* ReStart discovery */
5861 goto restart_disc;
dea31012005-04-17 16:05:31 -05005862
5863 case LPFC_NS_QRY:
5864 /* Check for wait for NameServer Rsp timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005865 lpfc_printf_vlog(vport, KERN_ERR,
5866 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005867 "0224 NameServer Query timeout "
5868 "Data: x%x x%x\n",
5869 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005870
James Smart92d7f7b2007-06-17 19:56:38 -05005871 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5872 /* Try it one more time */
5873 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005874 vport->gidft_inp = 0;
5875 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005876 if (rc == 0)
5877 break;
dea31012005-04-17 16:05:31 -05005878 }
James Smart92d7f7b2007-06-17 19:56:38 -05005879 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005880
James Smart87af33f2007-10-27 13:37:43 -04005881restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005882 /*
5883 * Discovery is over.
5884 * set port_state to PORT_READY if SLI2.
5885 * cmpl_reg_vpi will set port_state to READY for SLI3.
5886 */
James Smart3772a992009-05-22 14:50:54 -04005887 if (phba->sli_rev < LPFC_SLI_REV4) {
5888 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5889 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005890 else {
James Smart3772a992009-05-22 14:50:54 -04005891 lpfc_issue_clear_la(phba, vport);
5892 vport->port_state = LPFC_VPORT_READY;
5893 }
dea31012005-04-17 16:05:31 -05005894 }
5895
5896 /* Setup and issue mailbox INITIALIZE LINK command */
5897 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5898 if (!initlinkmbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005899 lpfc_printf_vlog(vport, KERN_ERR,
5900 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005901 "0206 Device Discovery "
5902 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005903 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005904 break;
5905 }
5906
5907 lpfc_linkdown(phba);
5908 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5909 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005910 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005911 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005912 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005913 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005914 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005915 if (rc == MBX_NOT_FINISHED)
5916 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5917
5918 break;
5919
5920 case LPFC_DISC_AUTH:
5921 /* Node Authentication timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005922 lpfc_printf_vlog(vport, KERN_ERR,
5923 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005924 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005925 lpfc_disc_flush_list(vport);
5926
James Smart92d7f7b2007-06-17 19:56:38 -05005927 /*
5928 * set port_state to PORT_READY if SLI2.
5929 * cmpl_reg_vpi will set port_state to READY for SLI3.
5930 */
James Smart3772a992009-05-22 14:50:54 -04005931 if (phba->sli_rev < LPFC_SLI_REV4) {
5932 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5933 lpfc_issue_reg_vpi(phba, vport);
5934 else { /* NPIV Not enabled */
5935 lpfc_issue_clear_la(phba, vport);
5936 vport->port_state = LPFC_VPORT_READY;
5937 }
dea31012005-04-17 16:05:31 -05005938 }
5939 break;
5940
James Smart2e0fef82007-06-17 19:56:36 -05005941 case LPFC_VPORT_READY:
5942 if (vport->fc_flag & FC_RSCN_MODE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005943 lpfc_printf_vlog(vport, KERN_ERR,
5944 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005945 "0231 RSCN timeout Data: x%x "
5946 "x%x\n",
5947 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005948
5949 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005950 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005951
James Smart2e0fef82007-06-17 19:56:36 -05005952 lpfc_els_flush_rscn(vport);
5953 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005954 }
5955 break;
James Smart2e0fef82007-06-17 19:56:36 -05005956
James Smart92d7f7b2007-06-17 19:56:38 -05005957 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07005958 lpfc_printf_vlog(vport, KERN_ERR,
5959 LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04005960 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005961 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005962 break;
5963 }
5964
5965 switch (phba->link_state) {
5966 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005967 /* CLEAR LA timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07005968 lpfc_printf_vlog(vport, KERN_ERR,
5969 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005970 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005971 clrlaerr = 1;
5972 break;
5973
James Smart09372822008-01-11 01:52:54 -05005974 case LPFC_LINK_UP:
5975 lpfc_issue_clear_la(phba, vport);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05005976 fallthrough;
James Smart2e0fef82007-06-17 19:56:36 -05005977 case LPFC_LINK_UNKNOWN:
5978 case LPFC_WARM_START:
5979 case LPFC_INIT_START:
5980 case LPFC_INIT_MBX_CMDS:
5981 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005982 case LPFC_HBA_ERROR:
Dick Kennedy372c1872020-06-30 14:50:00 -07005983 lpfc_printf_vlog(vport, KERN_ERR,
5984 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005985 "0230 Unexpected timeout, hba link "
5986 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005987 clrlaerr = 1;
5988 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005989
5990 case LPFC_HBA_READY:
5991 break;
dea31012005-04-17 16:05:31 -05005992 }
5993
5994 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005995 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005996 if (phba->sli_rev != LPFC_SLI_REV4) {
5997 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5998 ~LPFC_STOP_IOCB_EVENT;
5999 psli->sli3_ring[LPFC_FCP_RING].flag &=
6000 ~LPFC_STOP_IOCB_EVENT;
6001 }
James Smart2e0fef82007-06-17 19:56:36 -05006002 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05006003 }
dea31012005-04-17 16:05:31 -05006004 return;
6005}
6006
dea31012005-04-17 16:05:31 -05006007/*
6008 * This routine handles processing a NameServer REG_LOGIN mailbox
6009 * command upon completion. It is setup in the LPFC_MBOXQ
6010 * as the completion routine when the command is
6011 * handed off to the SLI layer.
6012 */
6013void
James Smart2e0fef82007-06-17 19:56:36 -05006014lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05006015{
James Smart04c68492009-05-22 14:52:52 -04006016 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006017 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6018 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006019 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05006020
James Smart3e1f0712018-11-29 16:09:29 -08006021 pmb->ctx_buf = NULL;
6022 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05006023
James Smart6d368e52011-05-24 11:44:12 -04006024 if (phba->sli_rev < LPFC_SLI_REV4)
6025 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05006026 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05006027 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05006028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07006029 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08006030 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04006031 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006032 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08006033 ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006034 /*
6035 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05006036 * 0xfffffa (FDMI well known port).
6037 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6038 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05006039 */
James Smart4258e982015-12-16 18:11:58 -05006040 if (vport->port_type == LPFC_PHYSICAL_PORT)
6041 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04006042 else
James Smart4258e982015-12-16 18:11:58 -05006043 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6044
dea31012005-04-17 16:05:31 -05006045
James Smartfa4066b2008-01-11 01:53:27 -05006046 /* decrement the node reference count held for this callback
6047 * function.
6048 */
James Smart329f9bc2007-04-25 09:53:01 -04006049 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006050 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6051 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04006052 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006053
6054 return;
6055}
6056
James Smart685f0bf2007-04-25 09:53:08 -04006057static int
6058lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6059{
6060 uint16_t *rpi = param;
6061
6062 return ndlp->nlp_rpi == *rpi;
6063}
6064
6065static int
6066lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6067{
6068 return memcmp(&ndlp->nlp_portname, param,
6069 sizeof(ndlp->nlp_portname)) == 0;
6070}
6071
Adrian Bunka6ababd2007-11-05 18:07:33 +01006072static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006073__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006074{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006075 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006076
James Smart2e0fef82007-06-17 19:56:36 -05006077 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006078 if (filter(ndlp, param)) {
6079 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006080 "3185 FIND node filter %ps DID "
James Smart32350662019-08-14 16:57:06 -07006081 "ndlp x%px did x%x flg x%x st x%x "
James Smart49382502017-11-20 16:00:38 -08006082 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006083 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006084 ndlp->nlp_flag, ndlp->nlp_state,
6085 ndlp->nlp_xri, ndlp->nlp_type,
6086 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006087 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006088 }
James Smart685f0bf2007-04-25 09:53:08 -04006089 }
James Smart34f5ad82012-08-03 12:35:03 -04006090 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006091 "3186 FIND node filter %ps NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006092 return NULL;
dea31012005-04-17 16:05:31 -05006093}
6094
James Smart685f0bf2007-04-25 09:53:08 -04006095/*
6096 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006097 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006098 */
6099struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006100__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006101{
James Smart2e0fef82007-06-17 19:56:36 -05006102 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006103}
6104
James Smart488d1462006-03-07 15:02:37 -05006105/*
James Smart685f0bf2007-04-25 09:53:08 -04006106 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006107 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006108 */
6109struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006110lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006111{
James Smart2e0fef82007-06-17 19:56:36 -05006112 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006113 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006114
James Smart2e0fef82007-06-17 19:56:36 -05006115 spin_lock_irq(shost->host_lock);
6116 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6117 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006118 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006119}
6120
James Smartcb69f7d2011-12-13 13:21:57 -05006121/*
6122 * This routine looks up the ndlp lists for the given RPI. If the rpi
6123 * is found, the routine returns the node element list pointer else
6124 * return NULL.
6125 */
6126struct lpfc_nodelist *
6127lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6128{
6129 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6130 struct lpfc_nodelist *ndlp;
Fuqian Huang78d4b132019-08-12 16:31:34 +08006131 unsigned long flags;
James Smartcb69f7d2011-12-13 13:21:57 -05006132
Fuqian Huang78d4b132019-08-12 16:31:34 +08006133 spin_lock_irqsave(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006134 ndlp = __lpfc_findnode_rpi(vport, rpi);
Fuqian Huang78d4b132019-08-12 16:31:34 +08006135 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006136 return ndlp;
6137}
6138
6139/**
6140 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6141 * @phba: pointer to lpfc hba data structure.
6142 * @vpi: the physical host virtual N_Port identifier.
6143 *
6144 * This routine finds a vport on a HBA (referred by @phba) through a
6145 * @vpi. The function walks the HBA's vport list and returns the address
6146 * of the vport with the matching @vpi.
6147 *
6148 * Return code
6149 * NULL - No vport with the matching @vpi found
6150 * Otherwise - Address to the vport with the matching @vpi.
6151 **/
6152struct lpfc_vport *
6153lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6154{
6155 struct lpfc_vport *vport;
6156 unsigned long flags;
6157 int i = 0;
6158
6159 /* The physical ports are always vpi 0 - translate is unnecessary. */
6160 if (vpi > 0) {
6161 /*
6162 * Translate the physical vpi to the logical vpi. The
6163 * vport stores the logical vpi.
6164 */
6165 for (i = 0; i < phba->max_vpi; i++) {
6166 if (vpi == phba->vpi_ids[i])
6167 break;
6168 }
6169
6170 if (i >= phba->max_vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006171 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6172 "2936 Could not find Vport mapped "
6173 "to vpi %d\n", vpi);
James Smartcb69f7d2011-12-13 13:21:57 -05006174 return NULL;
6175 }
6176 }
6177
James Smart523128e2018-09-10 10:30:46 -07006178 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006179 list_for_each_entry(vport, &phba->port_list, listentry) {
6180 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006181 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006182 return vport;
6183 }
6184 }
James Smart523128e2018-09-10 10:30:46 -07006185 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006186 return NULL;
6187}
6188
James Smart9d3d3402017-04-21 16:05:00 -07006189struct lpfc_nodelist *
6190lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006191{
James Smart9d3d3402017-04-21 16:05:00 -07006192 struct lpfc_nodelist *ndlp;
6193 int rpi = LPFC_RPI_ALLOC_ERROR;
6194
6195 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6196 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6197 if (rpi == LPFC_RPI_ALLOC_ERROR)
6198 return NULL;
6199 }
6200
6201 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6202 if (!ndlp) {
6203 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6204 lpfc_sli4_free_rpi(vport->phba, rpi);
6205 return NULL;
6206 }
6207
dea31012005-04-17 16:05:31 -05006208 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006209
6210 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006211 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006212 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006213 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07006214 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6215 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
James Smart307e3382020-11-15 11:26:30 -08006216 "flg:x%x refcnt:%d\n",
James Smart0f154222019-09-21 20:58:52 -07006217 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
James Smart307e3382020-11-15 11:26:30 -08006218 ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smartbe6bb942015-04-07 15:07:22 -04006219
James Smartcff261f2013-12-17 20:29:47 -05006220 ndlp->active_rrqs_xri_bitmap =
6221 mempool_alloc(vport->phba->active_rrq_pool,
6222 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006223 if (ndlp->active_rrqs_xri_bitmap)
6224 memset(ndlp->active_rrqs_xri_bitmap, 0,
6225 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006226 }
6227
James Smart725dd392013-10-10 12:23:30 -04006228
James Smart858c9f62007-06-17 19:56:39 -05006229
6230 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6231 "node init: did:x%x",
6232 ndlp->nlp_DID, 0, 0);
6233
James Smart9d3d3402017-04-21 16:05:00 -07006234 return ndlp;
dea31012005-04-17 16:05:31 -05006235}
James Smart329f9bc2007-04-25 09:53:01 -04006236
James Smart98c9ea52007-10-27 13:37:33 -04006237/* This routine releases all resources associated with a specifc NPort's ndlp
6238 * and mempool_free's the nodelist.
6239 */
James Smart311464e2007-08-02 11:10:37 -04006240static void
James Smart329f9bc2007-04-25 09:53:01 -04006241lpfc_nlp_release(struct kref *kref)
6242{
6243 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6244 kref);
James Smart858c9f62007-06-17 19:56:39 -05006245
6246 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6247 "node release: did:x%x flg:x%x type:x%x",
6248 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6249
James Smarte47c9092008-02-08 18:49:26 -05006250 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart307e3382020-11-15 11:26:30 -08006251 "0279 %s: ndlp:x%px did %x refcnt:%d rpi:%x\n",
6252 __func__, (void *)ndlp, ndlp->nlp_DID,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006253 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006254
6255 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05006256 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05006257
James Smarte47c9092008-02-08 18:49:26 -05006258 /* free ndlp memory for final ndlp release */
James Smart307e3382020-11-15 11:26:30 -08006259 kfree(ndlp->lat_data);
6260 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6261 mempool_free(ndlp->active_rrqs_xri_bitmap,
6262 ndlp->phba->active_rrq_pool);
6263 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04006264}
6265
James Smart98c9ea52007-10-27 13:37:33 -04006266/* This routine bumps the reference count for a ndlp structure to ensure
6267 * that one discovery thread won't free a ndlp while another discovery thread
6268 * is using it.
6269 */
James Smart329f9bc2007-04-25 09:53:01 -04006270struct lpfc_nodelist *
6271lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6272{
James Smarte47c9092008-02-08 18:49:26 -05006273 struct lpfc_hba *phba;
6274 unsigned long flags;
6275
James Smart98c9ea52007-10-27 13:37:33 -04006276 if (ndlp) {
6277 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6278 "node get: did:x%x flg:x%x refcnt:x%x",
6279 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006280 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006281
James Smarte47c9092008-02-08 18:49:26 -05006282 /* The check of ndlp usage to prevent incrementing the
6283 * ndlp reference count that is in the process of being
6284 * released.
6285 */
James Smarta257bf92009-04-06 18:48:10 -04006286 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006287 spin_lock_irqsave(&phba->ndlp_lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006288 if (!kref_get_unless_zero(&ndlp->kref)) {
James Smarte47c9092008-02-08 18:49:26 -05006289 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6290 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart307e3382020-11-15 11:26:30 -08006291 "0276 %s: ndlp:x%px refcnt:%d\n",
6292 __func__, (void *)ndlp, kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006293 return NULL;
James Smart307e3382020-11-15 11:26:30 -08006294 }
James Smarte47c9092008-02-08 18:49:26 -05006295 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006296 } else {
6297 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006298 }
James Smart307e3382020-11-15 11:26:30 -08006299
James Smart329f9bc2007-04-25 09:53:01 -04006300 return ndlp;
6301}
6302
James Smart98c9ea52007-10-27 13:37:33 -04006303/* This routine decrements the reference count for a ndlp structure. If the
James Smart307e3382020-11-15 11:26:30 -08006304 * count goes to 0, this indicates the associated nodelist should be freed.
James Smart98c9ea52007-10-27 13:37:33 -04006305 */
James Smart329f9bc2007-04-25 09:53:01 -04006306int
6307lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6308{
James Smart307e3382020-11-15 11:26:30 -08006309 if (ndlp) {
6310 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6311 "node put: did:x%x flg:x%x refcnt:x%x",
6312 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006313 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006314 } else {
6315 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006316 }
James Smart307e3382020-11-15 11:26:30 -08006317
6318 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
James Smart329f9bc2007-04-25 09:53:01 -04006319}
James Smart98c9ea52007-10-27 13:37:33 -04006320
6321/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006322 * by any other discovery thread. This routine returns 1 if the
6323 * ndlp has been freed. A return value of 0 indicates the ndlp is
6324 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006325 */
6326int
6327lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6328{
6329 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6330 "node not used: did:x%x flg:x%x refcnt:x%x",
6331 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006332 kref_read(&ndlp->kref));
6333 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006334 if (lpfc_nlp_put(ndlp))
6335 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006336 return 0;
6337}
James Smart6fb120a2009-05-22 14:52:59 -04006338
6339/**
6340 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6341 * @phba: Pointer to hba context object.
6342 *
6343 * This function iterate through all FC nodes associated
6344 * will all vports to check if there is any node with
6345 * fc_rports associated with it. If there is an fc_rport
6346 * associated with the node, then the node is either in
6347 * discovered state or its devloss_timer is pending.
6348 */
6349static int
6350lpfc_fcf_inuse(struct lpfc_hba *phba)
6351{
6352 struct lpfc_vport **vports;
6353 int i, ret = 0;
6354 struct lpfc_nodelist *ndlp;
6355 struct Scsi_Host *shost;
6356
6357 vports = lpfc_create_vport_work_array(phba);
6358
James Smart63e801c2010-11-20 23:14:19 -05006359 /* If driver cannot allocate memory, indicate fcf is in use */
6360 if (!vports)
6361 return 1;
6362
James Smart6fb120a2009-05-22 14:52:59 -04006363 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6364 shost = lpfc_shost_from_vport(vports[i]);
6365 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006366 /*
6367 * IF the CVL_RCVD bit is not set then we have sent the
6368 * flogi.
6369 * If dev_loss fires while we are waiting we do not want to
6370 * unreg the fcf.
6371 */
6372 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6373 spin_unlock_irq(shost->host_lock);
6374 ret = 1;
6375 goto out;
6376 }
James Smart6fb120a2009-05-22 14:52:59 -04006377 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08006378 if (ndlp->rport &&
James Smart6fb120a2009-05-22 14:52:59 -04006379 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6380 ret = 1;
6381 spin_unlock_irq(shost->host_lock);
6382 goto out;
James Smart80c17842012-03-01 22:35:45 -05006383 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6384 ret = 1;
James Smart0f154222019-09-21 20:58:52 -07006385 lpfc_printf_log(phba, KERN_INFO,
6386 LOG_NODE | LOG_DISCOVERY,
James Smart80c17842012-03-01 22:35:45 -05006387 "2624 RPI %x DID %x flag %x "
6388 "still logged in\n",
6389 ndlp->nlp_rpi, ndlp->nlp_DID,
6390 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006391 }
6392 }
6393 spin_unlock_irq(shost->host_lock);
6394 }
6395out:
6396 lpfc_destroy_vport_work_array(phba, vports);
6397 return ret;
6398}
6399
6400/**
6401 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6402 * @phba: Pointer to hba context object.
6403 * @mboxq: Pointer to mailbox object.
6404 *
6405 * This function frees memory associated with the mailbox command.
6406 */
James Smart1b511972011-12-13 13:23:09 -05006407void
James Smart6fb120a2009-05-22 14:52:59 -04006408lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6409{
6410 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006412
6413 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006414 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6415 "2555 UNREG_VFI mbxStatus error x%x "
6416 "HBA state x%x\n",
6417 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006418 }
James Smart38b92ef2010-08-04 16:11:39 -04006419 spin_lock_irq(shost->host_lock);
6420 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6421 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006422 mempool_free(mboxq, phba->mbox_mem_pool);
6423 return;
6424}
6425
6426/**
6427 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6428 * @phba: Pointer to hba context object.
6429 * @mboxq: Pointer to mailbox object.
6430 *
6431 * This function frees memory associated with the mailbox command.
6432 */
6433static void
6434lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6435{
6436 struct lpfc_vport *vport = mboxq->vport;
6437
6438 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006439 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6440 "2550 UNREG_FCFI mbxStatus error x%x "
6441 "HBA state x%x\n",
6442 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006443 }
6444 mempool_free(mboxq, phba->mbox_mem_pool);
6445 return;
6446}
6447
6448/**
James Smartecfd03c2010-02-12 14:41:27 -05006449 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006450 * @phba: Pointer to hba context object.
6451 *
James Smartecfd03c2010-02-12 14:41:27 -05006452 * This function prepare the HBA for unregistering the currently registered
6453 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6454 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006455 */
James Smartecfd03c2010-02-12 14:41:27 -05006456int
6457lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006458{
James Smart6fb120a2009-05-22 14:52:59 -04006459 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006460 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006461 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006462 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006463
James Smartecfd03c2010-02-12 14:41:27 -05006464 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006465 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006466 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006467
James Smart4d9ab992009-10-02 15:16:39 -04006468 /* At this point, all discovery is aborted */
6469 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006470
6471 /* Unregister VPIs */
6472 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006473 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006474 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006475 /* Stop FLOGI/FDISC retries */
6476 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6477 if (ndlp)
6478 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006479 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006480 if (phba->sli_rev == LPFC_SLI_REV4)
6481 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006482 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006483 shost = lpfc_shost_from_vport(vports[i]);
6484 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006485 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006486 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006487 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006488 }
6489 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006490 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6491 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6492 if (ndlp)
6493 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6494 lpfc_cleanup_pending_mbox(phba->pport);
6495 if (phba->sli_rev == LPFC_SLI_REV4)
6496 lpfc_sli4_unreg_all_rpis(phba->pport);
6497 lpfc_mbx_unreg_vpi(phba->pport);
6498 shost = lpfc_shost_from_vport(phba->pport);
6499 spin_lock_irq(shost->host_lock);
6500 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6501 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6502 spin_unlock_irq(shost->host_lock);
6503 }
James Smart6fb120a2009-05-22 14:52:59 -04006504
James Smart695a8142010-01-26 23:08:03 -05006505 /* Cleanup any outstanding ELS commands */
6506 lpfc_els_flush_all_cmd(phba);
6507
James Smart1b511972011-12-13 13:23:09 -05006508 /* Unregister the physical port VFI */
6509 rc = lpfc_issue_unreg_vfi(phba->pport);
6510 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006511}
6512
6513/**
6514 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6515 * @phba: Pointer to hba context object.
6516 *
6517 * This function issues synchronous unregister FCF mailbox command to HBA to
6518 * unregister the currently registered FCF record. The driver does not reset
6519 * the driver FCF usage state flags.
6520 *
6521 * Return 0 if successfully issued, none-zero otherwise.
6522 */
6523int
6524lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6525{
6526 LPFC_MBOXQ_t *mbox;
6527 int rc;
6528
James Smart6fb120a2009-05-22 14:52:59 -04006529 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6530 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006531 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006532 "2551 UNREG_FCFI mbox allocation failed"
6533 "HBA state x%x\n", phba->pport->port_state);
6534 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006535 }
James Smart6fb120a2009-05-22 14:52:59 -04006536 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6537 mbox->vport = phba->pport;
6538 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6539 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6540
6541 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006542 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006543 "2552 Unregister FCFI command failed rc x%x "
6544 "HBA state x%x\n",
6545 rc, phba->pport->port_state);
6546 return -EINVAL;
6547 }
6548 return 0;
6549}
6550
6551/**
6552 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6553 * @phba: Pointer to hba context object.
6554 *
6555 * This function unregisters the currently reigstered FCF. This function
6556 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6557 */
6558void
6559lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6560{
6561 int rc;
6562
6563 /* Preparation for unregistering fcf */
6564 rc = lpfc_unregister_fcf_prep(phba);
6565 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006566 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006567 "2748 Failed to prepare for unregistering "
6568 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006569 return;
6570 }
6571
James Smartecfd03c2010-02-12 14:41:27 -05006572 /* Now, unregister FCF record and reset HBA FCF state */
6573 rc = lpfc_sli4_unregister_fcf(phba);
6574 if (rc)
6575 return;
6576 /* Reset HBA FCF states after successful unregister FCF */
6577 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006578 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006579
6580 /*
6581 * If driver is not unloading, check if there is any other
6582 * FCF record that can be used for discovery.
6583 */
6584 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006585 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006586 return;
6587
James Smart0c9ab6f2010-02-26 14:15:57 -05006588 /* This is considered as the initial FCF discovery scan */
6589 spin_lock_irq(&phba->hbalock);
6590 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6591 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006592
6593 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006594 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006595
James Smart0c9ab6f2010-02-26 14:15:57 -05006596 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006597
James Smart0c9ab6f2010-02-26 14:15:57 -05006598 if (rc) {
6599 spin_lock_irq(&phba->hbalock);
6600 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6601 spin_unlock_irq(&phba->hbalock);
Dick Kennedy372c1872020-06-30 14:50:00 -07006602 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006603 "2553 lpfc_unregister_unused_fcf failed "
6604 "to read FCF record HBA state x%x\n",
6605 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006606 }
James Smartecfd03c2010-02-12 14:41:27 -05006607}
6608
6609/**
6610 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6611 * @phba: Pointer to hba context object.
6612 *
6613 * This function just unregisters the currently reigstered FCF. It does not
6614 * try to find another FCF for discovery.
6615 */
6616void
6617lpfc_unregister_fcf(struct lpfc_hba *phba)
6618{
6619 int rc;
6620
6621 /* Preparation for unregistering fcf */
6622 rc = lpfc_unregister_fcf_prep(phba);
6623 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006624 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006625 "2749 Failed to prepare for unregistering "
6626 "HBA's FCF record: rc=%d\n", rc);
6627 return;
6628 }
6629
6630 /* Now, unregister FCF record and reset HBA FCF state */
6631 rc = lpfc_sli4_unregister_fcf(phba);
6632 if (rc)
6633 return;
6634 /* Set proper HBA FCF states after successful unregister FCF */
6635 spin_lock_irq(&phba->hbalock);
6636 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6637 spin_unlock_irq(&phba->hbalock);
6638}
6639
6640/**
6641 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6642 * @phba: Pointer to hba context object.
6643 *
6644 * This function check if there are any connected remote port for the FCF and
6645 * if all the devices are disconnected, this function unregister FCFI.
6646 * This function also tries to use another FCF for discovery.
6647 */
6648void
6649lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6650{
6651 /*
James Smart3804dc82010-07-14 15:31:37 -04006652 * If HBA is not running in FIP mode, if HBA does not support
6653 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6654 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006655 */
6656 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006657 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006658 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006659 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006660 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006661 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006662 spin_unlock_irq(&phba->hbalock);
6663 return;
6664 }
6665 spin_unlock_irq(&phba->hbalock);
6666
6667 if (lpfc_fcf_inuse(phba))
6668 return;
6669
6670 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006671}
6672
6673/**
6674 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6675 * @phba: Pointer to hba context object.
6676 * @buff: Buffer containing the FCF connection table as in the config
6677 * region.
6678 * This function create driver data structure for the FCF connection
6679 * record table read from config region 23.
6680 */
6681static void
6682lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6683 uint8_t *buff)
6684{
6685 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6686 struct lpfc_fcf_conn_hdr *conn_hdr;
6687 struct lpfc_fcf_conn_rec *conn_rec;
6688 uint32_t record_count;
6689 int i;
6690
6691 /* Free the current connect table */
6692 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006693 &phba->fcf_conn_rec_list, list) {
6694 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006695 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006696 }
James Smart6fb120a2009-05-22 14:52:59 -04006697
6698 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6699 record_count = conn_hdr->length * sizeof(uint32_t)/
6700 sizeof(struct lpfc_fcf_conn_rec);
6701
6702 conn_rec = (struct lpfc_fcf_conn_rec *)
6703 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6704
6705 for (i = 0; i < record_count; i++) {
6706 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6707 continue;
6708 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6709 GFP_KERNEL);
6710 if (!conn_entry) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006711 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6712 "2566 Failed to allocate connection"
6713 " table entry\n");
James Smart6fb120a2009-05-22 14:52:59 -04006714 return;
6715 }
6716
6717 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6718 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006719 list_add_tail(&conn_entry->list,
6720 &phba->fcf_conn_rec_list);
6721 }
James Smartdf0d0852013-05-31 17:05:08 -04006722
6723 if (!list_empty(&phba->fcf_conn_rec_list)) {
6724 i = 0;
6725 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6726 list) {
6727 conn_rec = &conn_entry->conn_rec;
6728 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6729 "3345 FCF connection list rec[%02d]: "
6730 "flags:x%04x, vtag:x%04x, "
6731 "fabric_name:x%02x:%02x:%02x:%02x:"
6732 "%02x:%02x:%02x:%02x, "
6733 "switch_name:x%02x:%02x:%02x:%02x:"
6734 "%02x:%02x:%02x:%02x\n", i++,
6735 conn_rec->flags, conn_rec->vlan_tag,
6736 conn_rec->fabric_name[0],
6737 conn_rec->fabric_name[1],
6738 conn_rec->fabric_name[2],
6739 conn_rec->fabric_name[3],
6740 conn_rec->fabric_name[4],
6741 conn_rec->fabric_name[5],
6742 conn_rec->fabric_name[6],
6743 conn_rec->fabric_name[7],
6744 conn_rec->switch_name[0],
6745 conn_rec->switch_name[1],
6746 conn_rec->switch_name[2],
6747 conn_rec->switch_name[3],
6748 conn_rec->switch_name[4],
6749 conn_rec->switch_name[5],
6750 conn_rec->switch_name[6],
6751 conn_rec->switch_name[7]);
6752 }
6753 }
James Smart6fb120a2009-05-22 14:52:59 -04006754}
6755
6756/**
6757 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6758 * @phba: Pointer to hba context object.
6759 * @buff: Buffer containing the FCoE parameter data structure.
6760 *
6761 * This function update driver data structure with config
6762 * parameters read from config region 23.
6763 */
6764static void
6765lpfc_read_fcoe_param(struct lpfc_hba *phba,
6766 uint8_t *buff)
6767{
6768 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6769 struct lpfc_fcoe_params *fcoe_param;
6770
6771 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6772 buff;
6773 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006774 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006775
6776 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6777 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6778 return;
6779
James Smart6fb120a2009-05-22 14:52:59 -04006780 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6781 phba->valid_vlan = 1;
6782 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6783 0xFFF;
6784 }
6785
6786 phba->fc_map[0] = fcoe_param->fc_map[0];
6787 phba->fc_map[1] = fcoe_param->fc_map[1];
6788 phba->fc_map[2] = fcoe_param->fc_map[2];
6789 return;
6790}
6791
6792/**
6793 * lpfc_get_rec_conf23 - Get a record type in config region data.
6794 * @buff: Buffer containing config region 23 data.
6795 * @size: Size of the data buffer.
6796 * @rec_type: Record type to be searched.
6797 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006798 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006799 * of the record specified by record_type. If record found, this
6800 * function return pointer to the record else return NULL.
6801 */
6802static uint8_t *
6803lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6804{
6805 uint32_t offset = 0, rec_length;
6806
6807 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6808 (size < sizeof(uint32_t)))
6809 return NULL;
6810
6811 rec_length = buff[offset + 1];
6812
6813 /*
6814 * One TLV record has one word header and number of data words
6815 * specified in the rec_length field of the record header.
6816 */
6817 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6818 <= size) {
6819 if (buff[offset] == rec_type)
6820 return &buff[offset];
6821
6822 if (buff[offset] == LPFC_REGION23_LAST_REC)
6823 return NULL;
6824
6825 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6826 rec_length = buff[offset + 1];
6827 }
6828 return NULL;
6829}
6830
6831/**
6832 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6833 * @phba: Pointer to lpfc_hba data structure.
6834 * @buff: Buffer containing config region 23 data.
6835 * @size: Size of the data buffer.
6836 *
Stefan Weileef35c22010-08-06 21:11:15 +02006837 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006838 * populate driver data structure with the parameters.
6839 */
6840void
6841lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6842 uint8_t *buff,
6843 uint32_t size)
6844{
James Smarteb016562014-09-03 12:58:06 -04006845 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006846 uint8_t *rec_ptr;
6847
6848 /*
6849 * If data size is less than 2 words signature and version cannot be
6850 * verified.
6851 */
6852 if (size < 2*sizeof(uint32_t))
6853 return;
6854
6855 /* Check the region signature first */
6856 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006857 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04006858 "2567 Config region 23 has bad signature\n");
6859 return;
6860 }
6861
6862 offset += 4;
6863
6864 /* Check the data structure version */
6865 if (buff[offset] != LPFC_REGION23_VERSION) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006866 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6867 "2568 Config region 23 has bad version\n");
James Smart6fb120a2009-05-22 14:52:59 -04006868 return;
6869 }
6870 offset += 4;
6871
James Smart6fb120a2009-05-22 14:52:59 -04006872 /* Read FCoE param record */
6873 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6874 size - offset, FCOE_PARAM_TYPE);
6875 if (rec_ptr)
6876 lpfc_read_fcoe_param(phba, rec_ptr);
6877
6878 /* Read FCF connection table */
6879 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6880 size - offset, FCOE_CONN_TBL_TYPE);
6881 if (rec_ptr)
6882 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6883
6884}