blob: 816fc406135b3f95bfb3beaf1ddd031821fbc9a4 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart67073c62021-03-01 09:18:21 -08004 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
James Smarta93ff372010-10-22 11:06:08 -040025#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/pci.h>
28#include <linux/kthread.h>
29#include <linux/interrupt.h>
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +010030#include <linux/lockdep.h>
James Smarte3ba04c2019-12-18 15:58:02 -080031#include <linux/utsname.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
James Smarta0f2d3e2017-02-12 13:52:31 -080037#include <scsi/fc/fc_fs.h>
38
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040044#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050052
53/* AlpaArray for assignment of scsid for scan-down and bind_method */
54static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
68};
69
James Smart2e0fef82007-06-17 19:56:36 -050070static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010071static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040072static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040073static int lpfc_fcf_inuse(struct lpfc_hba *);
James Smart7f048392020-09-11 13:01:47 -070074static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
Gaurav Srivastava20397172021-06-08 10:05:54 +053075static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
Gaurav Srivastava0c4792c2021-06-08 10:05:55 +053076static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
dea31012005-04-17 16:05:31 -050077
James Smart07aaefd2021-01-04 10:02:29 -080078static int
79lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
80{
81 if (ndlp->nlp_fc4_type ||
James Smartfe83e3b2021-05-14 12:55:54 -070082 ndlp->nlp_type & NLP_FABRIC)
James Smart07aaefd2021-01-04 10:02:29 -080083 return 1;
84 return 0;
85}
James Smartc6adba12020-11-15 11:26:34 -080086/* The source of a terminate rport I/O is either a dev_loss_tmo
87 * event or a call to fc_remove_host. While the rport should be
88 * valid during these downcalls, the transport can call twice
89 * in a single event. This routine provides somoe protection
90 * as the NDLP isn't really free, just released to the pool.
91 */
92static int
93lpfc_rport_invalid(struct fc_rport *rport)
94{
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
James Smartc6adba12020-11-15 11:26:34 -080097
98 if (!rport) {
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
100 return -EINVAL;
101 }
102
103 rdata = rport->dd_data;
104 if (!rdata) {
James Smartf1156122021-04-11 18:31:24 -0700105 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
James Smartc6adba12020-11-15 11:26:34 -0800106 __func__, rport, rport->scsi_target_id);
107 return -EINVAL;
108 }
109
110 ndlp = rdata->pnode;
111 if (!rdata->pnode) {
James Smartf1156122021-04-11 18:31:24 -0700112 pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n",
James Smartc6adba12020-11-15 11:26:34 -0800113 __func__, rport, rport->scsi_target_id);
114 return -EINVAL;
115 }
116
James Smartc6adba12020-11-15 11:26:34 -0800117 if (!ndlp->vport) {
James Smartf1156122021-04-11 18:31:24 -0700118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
James Smartc6adba12020-11-15 11:26:34 -0800119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
121 return -EINVAL;
122 }
123 return 0;
124}
125
James Smartc01f3202006-08-18 17:47:08 -0400126void
127lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -0500128{
James Smartc01f3202006-08-18 17:47:08 -0400129 struct lpfc_rport_data *rdata;
James Smartc6adba12020-11-15 11:26:34 -0800130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
132
133 if (lpfc_rport_invalid(rport))
134 return;
dea31012005-04-17 16:05:31 -0500135
James Smartc01f3202006-08-18 17:47:08 -0400136 rdata = rport->dd_data;
137 ndlp = rdata->pnode;
James Smartc6adba12020-11-15 11:26:34 -0800138 vport = ndlp->vport;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
James Smart858c9f62007-06-17 19:56:39 -0500142
James Smart078c68b2021-04-11 18:31:12 -0700143 if (ndlp->nlp_sid != NLP_NO_SID)
144 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -0400145}
146
147/*
148 * This function will be called when dev_loss_tmo fire.
149 */
150void
151lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
152{
James Smartc6adba12020-11-15 11:26:34 -0800153 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500155 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500156 struct lpfc_work_evt *evtp;
James Smart894bb172019-08-14 16:56:52 -0700157 unsigned long iflags;
James Smartc01f3202006-08-18 17:47:08 -0400158
James Smartc6adba12020-11-15 11:26:34 -0800159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
James Smart307e3382020-11-15 11:26:30 -0800160 if (!ndlp)
James Smartc01f3202006-08-18 17:47:08 -0400161 return;
James Smartc01f3202006-08-18 17:47:08 -0400162
James Smart858c9f62007-06-17 19:56:39 -0500163 vport = ndlp->vport;
164 phba = vport->phba;
165
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
169
James Smart34f5ad82012-08-03 12:35:03 -0400170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smartf1156122021-04-11 18:31:24 -0700171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
James Smartc6adba12020-11-15 11:26:34 -0800172 "load_flag x%x refcnt %d\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref));
James Smart34f5ad82012-08-03 12:35:03 -0400175
James Smartc6adba12020-11-15 11:26:34 -0800176 /* Don't schedule a worker thread event if the vport is going down.
177 * The teardown process cleans up the node via lpfc_drop_node.
James Smarta8adb832007-10-27 13:37:53 -0400178 */
179 if (vport->load_flag & FC_UNLOADING) {
James Smartc6adba12020-11-15 11:26:34 -0800180 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
James Smarta8adb832007-10-27 13:37:53 -0400181 ndlp->rport = NULL;
James Smartc6adba12020-11-15 11:26:34 -0800182
183 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
184
185 /* Remove the node reference from remote_port_add now.
186 * The driver will not call remote_port_delete.
187 */
188 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -0400189 return;
190 }
191
192 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
193 return;
194
James Smart466e8402015-05-21 13:55:28 -0400195 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
Dick Kennedy372c1872020-06-30 14:50:00 -0700196 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
197 "6789 rport name %llx != node port name %llx",
198 rport->port_name,
199 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400200
James Smart858c9f62007-06-17 19:56:39 -0500201 evtp = &ndlp->dev_loss_evt;
202
James Smart466e8402015-05-21 13:55:28 -0400203 if (!list_empty(&evtp->evt_listp)) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700204 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartc6adba12020-11-15 11:26:34 -0800205 "6790 rport name %llx dev_loss_evt pending\n",
Dick Kennedy372c1872020-06-30 14:50:00 -0700206 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500207 return;
James Smart466e8402015-05-21 13:55:28 -0400208 }
James Smart858c9f62007-06-17 19:56:39 -0500209
James Smartc6adba12020-11-15 11:26:34 -0800210 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400211 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
James Smartaf984c82021-10-20 14:14:16 -0700212
213 /* If there is a PLOGI in progress, and we are in a
214 * NLP_NPR_2B_DISC state, don't turn off the flag.
215 */
216 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
217 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart52edb2c2020-11-15 11:26:35 -0800218
James Smartc6adba12020-11-15 11:26:34 -0800219 /*
James Smart52edb2c2020-11-15 11:26:35 -0800220 * The backend does not expect any more calls associated with this
221 * rport. Remove the association between rport and ndlp.
James Smartc6adba12020-11-15 11:26:34 -0800222 */
James Smart52edb2c2020-11-15 11:26:35 -0800223 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
James Smartc6adba12020-11-15 11:26:34 -0800224 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
225 ndlp->rport = NULL;
226 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smarta62a4352013-04-17 20:18:19 -0400227
James Smartfa4066b2008-01-11 01:53:27 -0500228 /* We need to hold the node by incrementing the reference
229 * count until this queued work is done
230 */
James Smart4430f7f2020-11-15 11:26:31 -0800231 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400232
James Smart894bb172019-08-14 16:56:52 -0700233 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5e9d9b82008-06-14 22:52:53 -0400234 if (evtp->evt_arg1) {
235 evtp->evt = LPFC_EVT_DEV_LOSS;
236 list_add_tail(&evtp->evt_listp, &phba->work_list);
237 lpfc_worker_wake_up(phba);
238 }
James Smart894bb172019-08-14 16:56:52 -0700239 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500240
James Smart858c9f62007-06-17 19:56:39 -0500241 return;
242}
243
James Smarta93ff372010-10-22 11:06:08 -0400244/**
Gaurav Srivastava20397172021-06-08 10:05:54 +0530245 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
246 * @vport: Pointer to vport context object.
247 *
248 * This function checks for idle VMID entries related to a particular vport. If
249 * found unused/idle, free them accordingly.
250 **/
251static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
252{
253 u16 keep;
254 u32 difftime = 0, r, bucket;
255 u64 *lta;
256 int cpu;
257 struct lpfc_vmid *vmp;
258
259 write_lock(&vport->vmid_lock);
260
261 if (!vport->cur_vmid_cnt)
262 goto out;
263
264 /* iterate through the table */
265 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
266 keep = 0;
267 if (vmp->flag & LPFC_VMID_REGISTERED) {
268 /* check if the particular VMID is in use */
269 /* for all available per cpu variable */
270 for_each_possible_cpu(cpu) {
271 /* if last access time is less than timeout */
272 lta = per_cpu_ptr(vmp->last_io_time, cpu);
273 if (!lta)
274 continue;
275 difftime = (jiffies) - (*lta);
276 if ((vport->vmid_inactivity_timeout *
277 JIFFIES_PER_HR) > difftime) {
278 keep = 1;
279 break;
280 }
281 }
282
283 /* if none of the cpus have been used by the vm, */
284 /* remove the entry if already registered */
285 if (!keep) {
286 /* mark the entry for deregistration */
287 vmp->flag = LPFC_VMID_DE_REGISTER;
288 write_unlock(&vport->vmid_lock);
289 if (vport->vmid_priority_tagging)
290 r = lpfc_vmid_uvem(vport, vmp, false);
291 else
292 r = lpfc_vmid_cmd(vport,
293 SLI_CTAS_DAPP_IDENT,
294 vmp);
295
296 /* decrement number of active vms and mark */
297 /* entry in slot as free */
298 write_lock(&vport->vmid_lock);
299 if (!r) {
300 struct lpfc_vmid *ht = vmp;
301
302 vport->cur_vmid_cnt--;
303 ht->flag = LPFC_VMID_SLOT_FREE;
304 free_percpu(ht->last_io_time);
305 ht->last_io_time = NULL;
306 hash_del(&ht->hnode);
307 }
308 }
309 }
310 }
311 out:
312 write_unlock(&vport->vmid_lock);
313}
314
315/**
316 * lpfc_check_inactive_vmid - VMID inactivity checker
317 * @phba: Pointer to hba context object.
318 *
319 * This function is called from the worker thread to determine if an entry in
320 * the VMID table can be released since there was no I/O activity seen from that
321 * particular VM for the specified time. When this happens, the entry in the
322 * table is released and also the resources on the switch cleared.
323 **/
324
325static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
326{
327 struct lpfc_vport *vport;
328 struct lpfc_vport **vports;
329 int i;
330
331 vports = lpfc_create_vport_work_array(phba);
332 if (!vports)
333 return;
334
335 for (i = 0; i <= phba->max_vports; i++) {
336 if ((!vports[i]) && (i == 0))
337 vport = phba->pport;
338 else
339 vport = vports[i];
340 if (!vport)
341 break;
342
343 lpfc_check_inactive_vmid_one(vport);
344 }
345 lpfc_destroy_vport_work_array(phba, vports);
346}
347
348/**
James Smartaf984c82021-10-20 14:14:16 -0700349 * lpfc_check_nlp_post_devloss - Check to restore ndlp refcnt after devloss
350 * @vport: Pointer to vport object.
351 * @ndlp: Pointer to remote node object.
352 *
353 * If NLP_IN_RECOV_POST_DEV_LOSS flag was set due to outstanding recovery of
354 * node during dev_loss_tmo processing, then this function restores the nlp_put
355 * kref decrement from lpfc_dev_loss_tmo_handler.
356 **/
357void
358lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
359 struct lpfc_nodelist *ndlp)
360{
361 unsigned long iflags;
362
363 spin_lock_irqsave(&ndlp->lock, iflags);
364 if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
365 ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
366 spin_unlock_irqrestore(&ndlp->lock, iflags);
367 lpfc_nlp_get(ndlp);
368 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
369 "8438 Devloss timeout reversed on DID x%x "
370 "refcnt %d ndlp %p flag x%x "
371 "port_state = x%x\n",
372 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
373 ndlp->nlp_flag, vport->port_state);
374 spin_lock_irqsave(&ndlp->lock, iflags);
375 }
376 spin_unlock_irqrestore(&ndlp->lock, iflags);
377}
378
379/**
James Smarta93ff372010-10-22 11:06:08 -0400380 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
381 * @ndlp: Pointer to remote node object.
382 *
383 * This function is called from the worker thread when devloss timeout timer
384 * expires. For SLI4 host, this routine shall return 1 when at lease one
385 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
386 * routine shall return 0 when there is no remote node is still in use of FCF
387 * when devloss timeout happened to this @ndlp.
388 **/
389static int
James Smart858c9f62007-06-17 19:56:39 -0500390lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
391{
James Smart858c9f62007-06-17 19:56:39 -0500392 struct lpfc_vport *vport;
393 struct lpfc_hba *phba;
394 uint8_t *name;
395 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400396 int fcf_inuse = 0;
James Smartaf984c82021-10-20 14:14:16 -0700397 bool recovering = false;
398 struct fc_vport *fc_vport = NULL;
James Smart894bb172019-08-14 16:56:52 -0700399 unsigned long iflags;
James Smart858c9f62007-06-17 19:56:39 -0500400
James Smart858c9f62007-06-17 19:56:39 -0500401 vport = ndlp->vport;
James Smartc6adba12020-11-15 11:26:34 -0800402 name = (uint8_t *)&ndlp->nlp_portname;
403 phba = vport->phba;
James Smart466e8402015-05-21 13:55:28 -0400404
James Smartc6adba12020-11-15 11:26:34 -0800405 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400406 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
James Smartc6adba12020-11-15 11:26:34 -0800407 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500408
James Smarta93ff372010-10-22 11:06:08 -0400409 if (phba->sli_rev == LPFC_SLI_REV4)
410 fcf_inuse = lpfc_fcf_inuse(phba);
411
James Smart858c9f62007-06-17 19:56:39 -0500412 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smartc6adba12020-11-15 11:26:34 -0800413 "rport devlosstmo:did:x%x type:x%x id:x%x",
414 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
James Smart858c9f62007-06-17 19:56:39 -0500415
James Smart34f5ad82012-08-03 12:35:03 -0400416 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart52edb2c2020-11-15 11:26:35 -0800417 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
James Smartc6adba12020-11-15 11:26:34 -0800418 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
James Smart52edb2c2020-11-15 11:26:35 -0800419 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
James Smarta8adb832007-10-27 13:37:53 -0400420
James Smart52edb2c2020-11-15 11:26:35 -0800421 /* If the driver is recovering the rport, ignore devloss. */
James Smartd7c255b2008-08-24 21:50:00 -0400422 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
423 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
424 "0284 Devloss timeout Ignored on "
425 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
426 "NPort x%x\n",
427 *name, *(name+1), *(name+2), *(name+3),
428 *(name+4), *(name+5), *(name+6), *(name+7),
429 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400430 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400431 }
James Smart858c9f62007-06-17 19:56:39 -0500432
James Smart52edb2c2020-11-15 11:26:35 -0800433 /* Fabric nodes are done. */
434 if (ndlp->nlp_type & NLP_FABRIC) {
James Smartaf984c82021-10-20 14:14:16 -0700435 spin_lock_irqsave(&ndlp->lock, iflags);
436 /* In massive vport configuration settings, it's possible
437 * dev_loss_tmo fired during node recovery. So, check if
438 * fabric nodes are in discovery states outstanding.
439 */
440 switch (ndlp->nlp_DID) {
441 case Fabric_DID:
442 fc_vport = vport->fc_vport;
443 if (fc_vport &&
444 fc_vport->vport_state == FC_VPORT_INITIALIZING)
445 recovering = true;
446 break;
447 case Fabric_Cntl_DID:
448 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
449 recovering = true;
450 break;
451 case FDMI_DID:
452 fallthrough;
453 case NameServer_DID:
454 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
455 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
456 recovering = true;
457 break;
458 }
459 spin_unlock_irqrestore(&ndlp->lock, iflags);
460
461 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
462 * the following lpfc_nlp_put is necessary after fabric node is
463 * recovered.
464 */
465 if (recovering) {
466 lpfc_printf_vlog(vport, KERN_INFO,
467 LOG_DISCOVERY | LOG_NODE,
468 "8436 Devloss timeout marked on "
469 "DID x%x refcnt %d ndlp %p "
470 "flag x%x port_state = x%x\n",
471 ndlp->nlp_DID, kref_read(&ndlp->kref),
472 ndlp, ndlp->nlp_flag,
473 vport->port_state);
474 spin_lock_irqsave(&ndlp->lock, iflags);
475 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
476 spin_unlock_irqrestore(&ndlp->lock, iflags);
477 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
478 /* Fabric node fully recovered before this dev_loss_tmo
479 * queue work is processed. Thus, ignore the
480 * dev_loss_tmo event.
481 */
482 lpfc_printf_vlog(vport, KERN_INFO,
483 LOG_DISCOVERY | LOG_NODE,
484 "8437 Devloss timeout ignored on "
485 "DID x%x refcnt %d ndlp %p "
486 "flag x%x port_state = x%x\n",
487 ndlp->nlp_DID, kref_read(&ndlp->kref),
488 ndlp, ndlp->nlp_flag,
489 vport->port_state);
490 return fcf_inuse;
491 }
492
James Smart52edb2c2020-11-15 11:26:35 -0800493 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400494 return fcf_inuse;
James Smart52edb2c2020-11-15 11:26:35 -0800495 }
James Smart82085712007-04-25 09:52:41 -0400496
dea31012005-04-17 16:05:31 -0500497 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400498 warn_on = 1;
James Smart078c68b2021-04-11 18:31:12 -0700499 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500500 }
James Smartc01f3202006-08-18 17:47:08 -0400501
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400502 if (warn_on) {
Dick Kennedy372c1872020-06-30 14:50:00 -0700503 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400504 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400505 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
506 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400507 *name, *(name+1), *(name+2), *(name+3),
508 *(name+4), *(name+5), *(name+6), *(name+7),
509 ndlp->nlp_DID, ndlp->nlp_flag,
510 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400511 } else {
Dick Kennedy372c1872020-06-30 14:50:00 -0700512 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400513 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400514 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
515 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400516 *name, *(name+1), *(name+2), *(name+3),
517 *(name+4), *(name+5), *(name+6), *(name+7),
518 ndlp->nlp_DID, ndlp->nlp_flag,
519 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400520 }
521
James Smartaf984c82021-10-20 14:14:16 -0700522 /* If we are devloss, but we are in the process of rediscovering the
523 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
524 */
525 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
526 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
527 return fcf_inuse;
528 }
529
James Smart52edb2c2020-11-15 11:26:35 -0800530 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
James Smart2e0fef82007-06-17 19:56:36 -0500531 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400532
James Smarta93ff372010-10-22 11:06:08 -0400533 return fcf_inuse;
534}
535
Gaurav Srivastava0c4792c2021-06-08 10:05:55 +0530536static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
537{
538 struct lpfc_vport *vport;
539 struct lpfc_vport **vports;
540 int i;
541
542 vports = lpfc_create_vport_work_array(phba);
543 if (!vports)
544 return;
545
546 for (i = 0; i <= phba->max_vports; i++) {
547 if ((!vports[i]) && (i == 0))
548 vport = phba->pport;
549 else
550 vport = vports[i];
551 if (!vport)
552 break;
553
554 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
555 if (!lpfc_issue_els_qfpa(vport))
556 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
557 }
558 }
559 lpfc_destroy_vport_work_array(phba, vports);
560}
561
James Smarta93ff372010-10-22 11:06:08 -0400562/**
563 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
564 * @phba: Pointer to hba context object.
565 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
566 * @nlp_did: remote node identifer with devloss timeout.
567 *
568 * This function is called from the worker thread after invoking devloss
569 * timeout handler and releasing the reference count for the ndlp with
570 * which the devloss timeout was handled for SLI4 host. For the devloss
571 * timeout of the last remote node which had been in use of FCF, when this
572 * routine is invoked, it shall be guaranteed that none of the remote are
573 * in-use of FCF. When devloss timeout to the last remote using the FCF,
574 * if the FIP engine is neither in FCF table scan process nor roundrobin
575 * failover process, the in-use FCF shall be unregistered. If the FIP
576 * engine is in FCF discovery process, the devloss timeout state shall
577 * be set for either the FCF table scan process or roundrobin failover
578 * process to unregister the in-use FCF.
579 **/
580static void
581lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
582 uint32_t nlp_did)
583{
584 /* If devloss timeout happened to a remote node when FCF had no
585 * longer been in-use, do nothing.
586 */
587 if (!fcf_inuse)
588 return;
589
590 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
591 spin_lock_irq(&phba->hbalock);
592 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
593 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
594 spin_unlock_irq(&phba->hbalock);
595 return;
596 }
597 phba->hba_flag |= HBA_DEVLOSS_TMO;
598 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
599 "2847 Last remote node (x%x) using "
600 "FCF devloss tmo\n", nlp_did);
601 }
602 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
603 spin_unlock_irq(&phba->hbalock);
604 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
605 "2868 Devloss tmo to FCF rediscovery "
606 "in progress\n");
607 return;
608 }
609 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
610 spin_unlock_irq(&phba->hbalock);
611 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
612 "2869 Devloss tmo to idle FIP engine, "
613 "unreg in-use FCF and rescan.\n");
614 /* Unregister in-use FCF and rescan */
615 lpfc_unregister_fcf_rescan(phba);
616 return;
617 }
618 spin_unlock_irq(&phba->hbalock);
619 if (phba->hba_flag & FCF_TS_INPROG)
620 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
621 "2870 FCF table scan in progress\n");
622 if (phba->hba_flag & FCF_RR_INPROG)
623 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
624 "2871 FLOGI roundrobin FCF failover "
625 "in progress\n");
626 }
James Smart6fb120a2009-05-22 14:52:59 -0400627 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500628}
James Smartc01f3202006-08-18 17:47:08 -0400629
James Smartea2151b2008-09-07 11:52:10 -0400630/**
James Smart3621a712009-04-06 18:47:14 -0400631 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400632 * @phba: Pointer to hba context object.
633 *
634 * This function is called from the functions which need to post
635 * events from interrupt context. This function allocates data
636 * structure required for posting event. It also keeps track of
637 * number of events pending and prevent event storm when there are
638 * too many events.
639 **/
640struct lpfc_fast_path_event *
641lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
642 struct lpfc_fast_path_event *ret;
643
644 /* If there are lot of fast event do not exhaust memory due to this */
645 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
646 return NULL;
647
648 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
649 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400650 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400651 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400652 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
653 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
654 }
James Smartea2151b2008-09-07 11:52:10 -0400655 return ret;
656}
657
658/**
James Smart3621a712009-04-06 18:47:14 -0400659 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400660 * @phba: Pointer to hba context object.
661 * @evt: Event object which need to be freed.
662 *
663 * This function frees the data structure required for posting
664 * events.
665 **/
666void
667lpfc_free_fast_evt(struct lpfc_hba *phba,
668 struct lpfc_fast_path_event *evt) {
669
670 atomic_dec(&phba->fast_event_count);
671 kfree(evt);
672}
673
674/**
James Smart3621a712009-04-06 18:47:14 -0400675 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400676 * @phba: Pointer to hba context object.
677 * @evtp: Event data structure.
678 *
679 * This function is called from worker thread, when the interrupt
680 * context need to post an event. This function posts the event
681 * to fc transport netlink interface.
682 **/
683static void
684lpfc_send_fastpath_evt(struct lpfc_hba *phba,
685 struct lpfc_work_evt *evtp)
686{
687 unsigned long evt_category, evt_sub_category;
688 struct lpfc_fast_path_event *fast_evt_data;
689 char *evt_data;
690 uint32_t evt_data_size;
691 struct Scsi_Host *shost;
692
693 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
694 work_evt);
695
696 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
697 evt_sub_category = (unsigned long) fast_evt_data->un.
698 fabric_evt.subcategory;
699 shost = lpfc_shost_from_vport(fast_evt_data->vport);
700 if (evt_category == FC_REG_FABRIC_EVENT) {
701 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
702 evt_data = (char *) &fast_evt_data->un.read_check_error;
703 evt_data_size = sizeof(fast_evt_data->un.
704 read_check_error);
705 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500706 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400707 evt_data = (char *) &fast_evt_data->un.fabric_evt;
708 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
709 } else {
710 lpfc_free_fast_evt(phba, fast_evt_data);
711 return;
712 }
713 } else if (evt_category == FC_REG_SCSI_EVENT) {
714 switch (evt_sub_category) {
715 case LPFC_EVENT_QFULL:
716 case LPFC_EVENT_DEVBSY:
717 evt_data = (char *) &fast_evt_data->un.scsi_evt;
718 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
719 break;
720 case LPFC_EVENT_CHECK_COND:
721 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
722 evt_data_size = sizeof(fast_evt_data->un.
723 check_cond_evt);
724 break;
725 case LPFC_EVENT_VARQUEDEPTH:
726 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
727 evt_data_size = sizeof(fast_evt_data->un.
728 queue_depth_evt);
729 break;
730 default:
731 lpfc_free_fast_evt(phba, fast_evt_data);
732 return;
733 }
734 } else {
735 lpfc_free_fast_evt(phba, fast_evt_data);
736 return;
737 }
738
James Smart895427b2017-02-12 13:52:30 -0800739 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
740 fc_host_post_vendor_event(shost,
741 fc_get_event_number(),
742 evt_data_size,
743 evt_data,
744 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400745
746 lpfc_free_fast_evt(phba, fast_evt_data);
747 return;
748}
749
dea31012005-04-17 16:05:31 -0500750static void
James Smart2e0fef82007-06-17 19:56:36 -0500751lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500752{
753 struct lpfc_work_evt *evtp = NULL;
754 struct lpfc_nodelist *ndlp;
755 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400756 int fcf_inuse;
757 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500758
James Smart2e0fef82007-06-17 19:56:36 -0500759 spin_lock_irq(&phba->hbalock);
760 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500761 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
762 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500763 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500764 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500765 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500766 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500767 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500768 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500769 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500770 /* decrement the node reference count held
771 * for this queued work
772 */
773 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500774 break;
James Smart858c9f62007-06-17 19:56:39 -0500775 case LPFC_EVT_DEV_LOSS:
776 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400777 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500778 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500779 /* decrement the node reference count held for
780 * this queued work
781 */
James Smarta93ff372010-10-22 11:06:08 -0400782 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500783 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400784 if (phba->sli_rev == LPFC_SLI_REV4)
785 lpfc_sli4_post_dev_loss_tmo_handler(phba,
786 fcf_inuse,
787 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500788 break;
James Smarte7dab162020-10-20 13:27:12 -0700789 case LPFC_EVT_RECOVER_PORT:
790 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
791 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
792 free_evt = 0;
793 /* decrement the node reference count held for
794 * this queued work
795 */
796 lpfc_nlp_put(ndlp);
797 break;
dea31012005-04-17 16:05:31 -0500798 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500799 if (phba->link_state < LPFC_LINK_DOWN)
800 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500801 else
James Smart2e0fef82007-06-17 19:56:36 -0500802 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500803 complete((struct completion *)(evtp->evt_arg2));
804 break;
James Smart46fa3112007-04-25 09:51:45 -0400805 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500806 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400807 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400808 *(int *)(evtp->evt_arg1) = 0;
809 complete((struct completion *)(evtp->evt_arg2));
810 break;
811 case LPFC_EVT_OFFLINE:
812 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500813 lpfc_sli_brdrestart(phba);
814 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400815 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
816 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500817 complete((struct completion *)(evtp->evt_arg2));
818 break;
819 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400820 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500821 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500822 lpfc_sli_brdreset(phba);
823 lpfc_hba_down_post(phba);
824 *(int *)(evtp->evt_arg1) =
825 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400826 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500827 complete((struct completion *)(evtp->evt_arg2));
828 break;
829 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400830 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500831 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500832 = (phba->pport->stopped)
833 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400834 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500835 complete((struct completion *)(evtp->evt_arg2));
836 break;
James Smartea2151b2008-09-07 11:52:10 -0400837 case LPFC_EVT_FASTPATH_MGMT_EVT:
838 lpfc_send_fastpath_evt(phba, evtp);
839 free_evt = 0;
840 break;
James Smart78730cf2010-04-06 15:06:30 -0400841 case LPFC_EVT_RESET_HBA:
842 if (!(phba->pport->load_flag & FC_UNLOADING))
843 lpfc_reset_hba(phba);
844 break;
dea31012005-04-17 16:05:31 -0500845 }
846 if (free_evt)
847 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500848 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500849 }
James Smart2e0fef82007-06-17 19:56:36 -0500850 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500851
852}
853
James Smart311464e2007-08-02 11:10:37 -0400854static void
James Smart2e0fef82007-06-17 19:56:36 -0500855lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500856{
857 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500858 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400859 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400860 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400861 int i;
dea31012005-04-17 16:05:31 -0500862
James Smart2e0fef82007-06-17 19:56:36 -0500863 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500864 ha_copy = phba->work_ha;
865 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500866 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500867
James Smartda0436e2009-05-22 14:51:39 -0400868 /* First, try to post the next mailbox command to SLI4 device */
869 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
870 lpfc_sli4_post_async_mbox(phba);
871
James Smart7dd2e2a2021-12-03 16:26:40 -0800872 if (ha_copy & HA_ERATT) {
James Smart93996272008-08-24 21:50:30 -0400873 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500874 lpfc_handle_eratt(phba);
875
James Smart7dd2e2a2021-12-03 16:26:40 -0800876 if (phba->fw_dump_cmpl) {
877 complete(phba->fw_dump_cmpl);
878 phba->fw_dump_cmpl = NULL;
879 }
880 }
881
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500882 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500883 lpfc_sli_handle_mb_event(phba);
884
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500885 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500886 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400887
Gaurav Srivastava0c4792c2021-06-08 10:05:55 +0530888 /* Handle VMID Events */
889 if (lpfc_is_vmid_enabled(phba)) {
890 if (phba->pport->work_port_events &
891 WORKER_CHECK_VMID_ISSUE_QFPA) {
892 lpfc_check_vmid_qfpa_issue(phba);
893 phba->pport->work_port_events &=
894 ~WORKER_CHECK_VMID_ISSUE_QFPA;
895 }
896 if (phba->pport->work_port_events &
897 WORKER_CHECK_INACTIVE_VMID) {
898 lpfc_check_inactive_vmid(phba);
899 phba->pport->work_port_events &=
900 ~WORKER_CHECK_INACTIVE_VMID;
901 }
902 }
903
James Smartda0436e2009-05-22 14:51:39 -0400904 /* Process SLI4 events */
905 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500906 if (phba->hba_flag & HBA_RRQ_ACTIVE)
907 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400908 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
909 lpfc_sli4_els_xri_abort_event_proc(phba);
910 if (phba->hba_flag & ASYNC_EVENT)
911 lpfc_sli4_async_event_proc(phba);
912 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
913 spin_lock_irq(&phba->hbalock);
914 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
915 spin_unlock_irq(&phba->hbalock);
916 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
917 }
James Smartecfd03c2010-02-12 14:41:27 -0500918 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
919 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400920 }
921
James Smart549e55c2007-08-02 11:09:51 -0400922 vports = lpfc_create_vport_work_array(phba);
923 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400924 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400925 /*
926 * We could have no vports in array if unloading, so if
927 * this happens then just use the pport
928 */
929 if (vports[i] == NULL && i == 0)
930 vport = phba->pport;
931 else
932 vport = vports[i];
933 if (vport == NULL)
934 break;
James Smart58da1ff2008-04-07 10:15:56 -0400935 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400936 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400937 vport->work_port_events &= ~work_port_events;
938 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400939 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400940 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400941 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400942 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400943 if (work_port_events & WORKER_HB_TMO)
944 lpfc_hb_timeout_handler(phba);
945 if (work_port_events & WORKER_MBOX_TMO)
946 lpfc_mbox_timeout_handler(phba);
947 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
948 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400949 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
950 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500951 if (work_port_events & WORKER_DELAYED_DISC_TMO)
952 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500953 }
James Smart09372822008-01-11 01:52:54 -0500954 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500955
James Smart895427b2017-02-12 13:52:30 -0800956 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500957 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
958 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700959 if (pring && (status & HA_RXMASK ||
960 pring->flag & LPFC_DEFERRED_RING_EVENT ||
961 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400962 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500963 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800964 /* Preserve legacy behavior. */
965 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
966 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500967 } else {
James Smart15498dc2019-09-21 20:58:59 -0700968 /* Driver could have abort request completed in queue
969 * when link goes down. Allow for this transition.
970 */
971 if (phba->link_state >= LPFC_LINK_DOWN ||
James Smartae9e28f2017-05-15 15:20:51 -0700972 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500973 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
974 lpfc_sli_handle_slow_ring_event(phba, pring,
975 (status &
976 HA_RXMASK));
977 }
James Smart858c9f62007-06-17 19:56:39 -0500978 }
James Smartdc19e3b2018-05-24 21:08:57 -0700979 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400980 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500981 /*
982 * Turn on Ring interrupts
983 */
James Smart3772a992009-05-22 14:50:54 -0400984 if (phba->sli_rev <= LPFC_SLI_REV3) {
985 spin_lock_irq(&phba->hbalock);
986 control = readl(phba->HCregaddr);
987 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
988 lpfc_debugfs_slow_ring_trc(phba,
989 "WRK Enable ring: cntl:x%x hacopy:x%x",
990 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400991
James Smart3772a992009-05-22 14:50:54 -0400992 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
993 writel(control, phba->HCregaddr);
994 readl(phba->HCregaddr); /* flush */
995 } else {
996 lpfc_debugfs_slow_ring_trc(phba,
997 "WRK Ring ok: cntl:x%x hacopy:x%x",
998 control, ha_copy, 0);
999 }
1000 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001001 }
1002 }
James Smart2e0fef82007-06-17 19:56:36 -05001003 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -05001004}
1005
dea31012005-04-17 16:05:31 -05001006int
1007lpfc_do_work(void *p)
1008{
1009 struct lpfc_hba *phba = p;
1010 int rc;
dea31012005-04-17 16:05:31 -05001011
Dongsheng Yang8698a742014-03-11 18:09:12 +08001012 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -04001013 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -04001014 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -05001015
James Smart3a55b532008-12-04 22:38:54 -05001016 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -04001017 /* wait and check worker queue activities */
1018 rc = wait_event_interruptible(phba->work_waitq,
1019 (test_and_clear_bit(LPFC_DATA_READY,
1020 &phba->data_flags)
1021 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -05001022 /* Signal wakeup shall terminate the worker thread */
1023 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001024 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart3a55b532008-12-04 22:38:54 -05001025 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -05001026 break;
James Smart3a55b532008-12-04 22:38:54 -05001027 }
dea31012005-04-17 16:05:31 -05001028
James Smart5e9d9b82008-06-14 22:52:53 -04001029 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -05001030 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -05001031 }
James Smart3a55b532008-12-04 22:38:54 -05001032 phba->worker_thread = NULL;
1033 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1034 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -05001035 return 0;
1036}
1037
1038/*
1039 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001040 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -05001041 * embedding it in the IOCB.
1042 */
1043int
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -05001045 uint32_t evt)
1046{
1047 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -05001048 unsigned long flags;
dea31012005-04-17 16:05:31 -05001049
1050 /*
1051 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1052 * be queued to worker thread for processing
1053 */
James Smart92d7f7b2007-06-17 19:56:38 -05001054 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -05001055 if (!evtp)
1056 return 0;
1057
1058 evtp->evt_arg1 = arg1;
1059 evtp->evt_arg2 = arg2;
1060 evtp->evt = evt;
1061
James Smarted957682007-06-17 19:56:37 -05001062 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -04001063 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -05001064 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001065
James Smart5e9d9b82008-06-14 22:52:53 -04001066 lpfc_worker_wake_up(phba);
1067
dea31012005-04-17 16:05:31 -05001068 return 1;
1069}
1070
James Smart92d7f7b2007-06-17 19:56:38 -05001071void
1072lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1073{
James Smart09372822008-01-11 01:52:54 -05001074 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001075 struct lpfc_hba *phba = vport->phba;
1076 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05001077
1078 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart88f77022021-09-10 16:31:49 -07001079 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
1080 /* It's possible the FLOGI to the fabric node never
1081 * successfully completed and never registered with the
1082 * transport. In this case there is no way to clean up
1083 * the node.
1084 */
1085 if (ndlp->nlp_DID == Fabric_DID) {
1086 if (ndlp->nlp_prev_state ==
1087 NLP_STE_UNUSED_NODE &&
1088 !ndlp->fc4_xpt_flags)
1089 lpfc_nlp_put(ndlp);
1090 }
James Smart92d7f7b2007-06-17 19:56:38 -05001091 continue;
James Smart88f77022021-09-10 16:31:49 -07001092 }
James Smartb3f2e672020-11-15 11:26:37 -08001093
James Smart98c9ea52007-10-27 13:37:33 -04001094 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
James Smartb3f2e672020-11-15 11:26:37 -08001095 ((vport->port_type == LPFC_NPIV_PORT) &&
1096 ((ndlp->nlp_DID == NameServer_DID) ||
James Smartfe83e3b2021-05-14 12:55:54 -07001097 (ndlp->nlp_DID == FDMI_DID) ||
1098 (ndlp->nlp_DID == Fabric_Cntl_DID))))
James Smart92d7f7b2007-06-17 19:56:38 -05001099 lpfc_unreg_rpi(vport, ndlp);
1100
1101 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -04001102 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1103 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -05001104 continue;
James Smart4c2805a2020-03-31 09:50:10 -07001105
1106 /* Notify transport of connectivity loss to trigger cleanup. */
1107 if (phba->nvmet_support &&
1108 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1109 lpfc_nvmet_invalidate_host(phba, ndlp);
1110
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001111 lpfc_disc_state_machine(vport, ndlp, NULL,
1112 remove
1113 ? NLP_EVT_DEVICE_RM
1114 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -05001115 }
1116 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -04001117 if (phba->sli_rev == LPFC_SLI_REV4)
1118 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001119 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05001120 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001121 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05001122 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001123 }
1124}
1125
James Smart87af33f2007-10-27 13:37:43 -04001126void
James Smart98c9ea52007-10-27 13:37:33 -04001127lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05001128{
James Smart695a8142010-01-26 23:08:03 -05001129 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1130
James Smart45ed1192009-10-02 15:17:02 -04001131 /* Cleanup any outstanding received buffers */
1132 lpfc_cleanup_rcv_buffers(vport);
1133
James Smart92d7f7b2007-06-17 19:56:38 -05001134 /* Cleanup any outstanding RSCN activity */
1135 lpfc_els_flush_rscn(vport);
1136
1137 /* Cleanup any outstanding ELS commands */
1138 lpfc_els_flush_cmd(vport);
1139
1140 lpfc_cleanup_rpis(vport, 0);
1141
James Smart92d7f7b2007-06-17 19:56:38 -05001142 /* Turn off discovery timer if its running */
1143 lpfc_can_disctmo(vport);
1144}
1145
James Smart3772a992009-05-22 14:50:54 -04001146void
James Smart98c9ea52007-10-27 13:37:33 -04001147lpfc_linkdown_port(struct lpfc_vport *vport)
1148{
1149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1150
James Smartf6e84792019-01-28 11:14:38 -08001151 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001152 fc_host_post_event(shost, fc_get_event_number(),
1153 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -04001154
1155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1156 "Link Down: state:x%x rtry:x%x flg:x%x",
1157 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1158
1159 lpfc_port_link_failure(vport);
1160
James Smart92494142011-02-16 12:39:44 -05001161 /* Stop delayed Nport discovery */
1162 spin_lock_irq(shost->host_lock);
1163 vport->fc_flag &= ~FC_DISC_DELAYED;
1164 spin_unlock_irq(shost->host_lock);
1165 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -04001166}
1167
dea31012005-04-17 16:05:31 -05001168int
James Smart685f0bf2007-04-25 09:53:08 -04001169lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001170{
James Smart2e0fef82007-06-17 19:56:36 -05001171 struct lpfc_vport *vport = phba->pport;
1172 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -04001173 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -04001174 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -04001175 int i;
dea31012005-04-17 16:05:31 -05001176
James Smart19193ff2019-03-12 16:30:25 -07001177 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -05001178 return 0;
James Smart19193ff2019-03-12 16:30:25 -07001179
James Smartaacc20e2009-12-21 17:02:51 -05001180 /* Block all SCSI stack I/Os */
1181 lpfc_scsi_dev_block(phba);
1182
James Smart0a9e9682018-11-29 16:09:36 -08001183 phba->defer_flogi_acc_flag = false;
1184
James Smart2e0fef82007-06-17 19:56:36 -05001185 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001186 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -05001187 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -05001188 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -05001189 phba->link_state = LPFC_LINK_DOWN;
James Smart2977a092018-12-13 15:17:52 -08001190 if (phba->sli4_hba.conf_trunk) {
1191 phba->trunk_link.link0.state = 0;
1192 phba->trunk_link.link1.state = 0;
1193 phba->trunk_link.link2.state = 0;
1194 phba->trunk_link.link3.state = 0;
James Smart845d0322019-08-14 16:57:01 -07001195 phba->sli4_hba.link_state.logical_speed =
1196 LPFC_LINK_SPEED_UNKNOWN;
James Smart2977a092018-12-13 15:17:52 -08001197 }
James Smart72100cc2010-02-12 14:43:01 -05001198 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001199 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -05001200 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001201 }
James Smart549e55c2007-08-02 11:09:51 -04001202 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -08001203 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -04001204 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -04001205 /* Issue a LINK DOWN event to all nodes */
1206 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -08001207
1208 vports[i]->fc_myDID = 0;
1209
James Smartf6e84792019-01-28 11:14:38 -08001210 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1211 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08001212 if (phba->nvmet_support)
1213 lpfc_nvmet_update_targetport(phba);
1214 else
James Smart8c258642017-02-12 13:52:36 -08001215 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -08001216 }
James Smart549e55c2007-08-02 11:09:51 -04001217 }
James Smart895427b2017-02-12 13:52:30 -08001218 }
James Smart09372822008-01-11 01:52:54 -05001219 lpfc_destroy_vport_work_array(phba, vports);
James Smartc95a3b42019-03-12 16:30:07 -07001220
1221 /* Clean up any SLI3 firmware default rpi's */
1222 if (phba->sli_rev > LPFC_SLI_REV3)
1223 goto skip_unreg_did;
1224
James Smart2e0fef82007-06-17 19:56:36 -05001225 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1226 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -04001227 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -05001228 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -05001229 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04001230 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001231 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001232 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001233 }
1234 }
1235
James Smartc95a3b42019-03-12 16:30:07 -07001236 skip_unreg_did:
dea31012005-04-17 16:05:31 -05001237 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -05001238 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -05001239 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1240 if (mb) {
dea31012005-04-17 16:05:31 -05001241 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -05001242 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05001243 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04001244 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05001245 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05001246 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001247 }
1248 }
James Smart2e0fef82007-06-17 19:56:36 -05001249 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001250 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -07001251 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001252 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001253 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001254 return 0;
dea31012005-04-17 16:05:31 -05001255}
1256
James Smart92d7f7b2007-06-17 19:56:38 -05001257static void
1258lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001259{
James Smart92d7f7b2007-06-17 19:56:38 -05001260 struct lpfc_nodelist *ndlp;
1261
1262 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -08001263 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smart307e3382020-11-15 11:26:30 -08001264
James Smart92d7f7b2007-06-17 19:56:38 -05001265 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1266 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05001267 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -05001268 /* On Linkup its safe to clean up the ndlp
1269 * from Fabric connections.
1270 */
James Smart92d7f7b2007-06-17 19:56:38 -05001271 if (ndlp->nlp_DID != Fabric_DID)
1272 lpfc_unreg_rpi(vport, ndlp);
1273 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1274 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -05001275 /* Fail outstanding IO now since device is
1276 * marked for PLOGI.
1277 */
James Smart92d7f7b2007-06-17 19:56:38 -05001278 lpfc_unreg_rpi(vport, ndlp);
1279 }
1280 }
1281}
1282
1283static void
1284lpfc_linkup_port(struct lpfc_vport *vport)
1285{
1286 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001287 struct lpfc_hba *phba = vport->phba;
1288
1289 if ((vport->load_flag & FC_UNLOADING) != 0)
1290 return;
1291
James Smart858c9f62007-06-17 19:56:39 -05001292 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1293 "Link Up: top:x%x speed:x%x flg:x%x",
1294 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1295
James Smart92d7f7b2007-06-17 19:56:38 -05001296 /* If NPIV is not enabled, only bring the physical port up */
1297 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1298 (vport != phba->pport))
1299 return;
dea31012005-04-17 16:05:31 -05001300
James Smartf6e84792019-01-28 11:14:38 -08001301 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001302 fc_host_post_event(shost, fc_get_event_number(),
1303 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001304
James Smart2e0fef82007-06-17 19:56:36 -05001305 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001306 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1307 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1308 vport->fc_flag |= FC_NDISC_ACTIVE;
1309 vport->fc_ns_retry = 0;
1310 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001311
James Smartb3f2e672020-11-15 11:26:37 -08001312 lpfc_linkup_cleanup_nodes(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001313}
1314
1315static int
1316lpfc_linkup(struct lpfc_hba *phba)
1317{
James Smart549e55c2007-08-02 11:09:51 -04001318 struct lpfc_vport **vports;
1319 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001320 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001321
1322 phba->link_state = LPFC_LINK_UP;
1323
1324 /* Unblock fabric iocbs if they are blocked */
1325 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1326 del_timer_sync(&phba->fabric_block_timer);
1327
James Smart549e55c2007-08-02 11:09:51 -04001328 vports = lpfc_create_vport_work_array(phba);
1329 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001330 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001331 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001332 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001333
James Smartd496b9a2018-10-23 13:41:08 -07001334 /* Clear the pport flogi counter in case the link down was
1335 * absorbed without an ACQE. No lock here - in worker thread
1336 * and discovery is synchronized.
1337 */
1338 spin_lock_irq(shost->host_lock);
1339 phba->pport->rcv_flogi_cnt = 0;
1340 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001341
1342 /* reinitialize initial FLOGI flag */
1343 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1344 phba->defer_flogi_acc_flag = false;
1345
dea31012005-04-17 16:05:31 -05001346 return 0;
1347}
1348
1349/*
1350 * This routine handles processing a CLEAR_LA mailbox
1351 * command upon completion. It is setup in the LPFC_MBOXQ
1352 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001353 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001354 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001355static void
James Smart2e0fef82007-06-17 19:56:36 -05001356lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001357{
James Smart2e0fef82007-06-17 19:56:36 -05001358 struct lpfc_vport *vport = pmb->vport;
1359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1360 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001361 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001362 uint32_t control;
1363
dea31012005-04-17 16:05:31 -05001364 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001365 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1366 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001367
1368 /* Check for error */
1369 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001370 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07001371 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001372 "0320 CLEAR_LA mbxStatus error x%x hba "
1373 "state x%x\n",
1374 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001375 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001376 goto out;
1377 }
1378
James Smart92d7f7b2007-06-17 19:56:38 -05001379 if (vport->port_type == LPFC_PHYSICAL_PORT)
1380 phba->link_state = LPFC_HBA_READY;
1381
1382 spin_lock_irq(&phba->hbalock);
1383 psli->sli_flag |= LPFC_PROCESS_LA;
1384 control = readl(phba->HCregaddr);
1385 control |= HC_LAINT_ENA;
1386 writel(control, phba->HCregaddr);
1387 readl(phba->HCregaddr); /* flush */
1388 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001389 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001390 return;
dea31012005-04-17 16:05:31 -05001391
dea31012005-04-17 16:05:31 -05001392out:
1393 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001394 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1395 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001396 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001397
James Smart2e0fef82007-06-17 19:56:36 -05001398 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001399 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001400 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001401
James Smart2e0fef82007-06-17 19:56:36 -05001402 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001403
1404 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001405
1406 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001407 psli->sli_flag |= LPFC_PROCESS_LA;
1408 control = readl(phba->HCregaddr);
1409 control |= HC_LAINT_ENA;
1410 writel(control, phba->HCregaddr);
1411 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001412 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001413
1414 return;
1415}
1416
James Smartd6de08c2015-12-16 18:11:53 -05001417void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001418lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001419{
James Smart2e0fef82007-06-17 19:56:36 -05001420 struct lpfc_vport *vport = pmb->vport;
James Smart7f048392020-09-11 13:01:47 -07001421 LPFC_MBOXQ_t *sparam_mb;
1422 struct lpfc_dmabuf *sparam_mp;
Dan Carpenter0be31092021-01-25 11:44:34 +03001423 u16 status = pmb->u.mb.mbxStatus;
James Smart7f048392020-09-11 13:01:47 -07001424 int rc;
dea31012005-04-17 16:05:31 -05001425
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001426 mempool_free(pmb, phba->mbox_mem_pool);
1427
Dan Carpenter0be31092021-01-25 11:44:34 +03001428 if (status)
1429 goto out;
1430
James Smart1b511972011-12-13 13:23:09 -05001431 /* don't perform discovery for SLI4 loopback diagnostic test */
1432 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1433 !(phba->hba_flag & HBA_FCOE_MODE) &&
1434 (phba->link_flag & LS_LOOPBACK_MODE))
1435 return;
1436
James Smart76a95d72010-11-20 23:11:48 -05001437 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001438 vport->fc_flag & FC_PUBLIC_LOOP &&
1439 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001440 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001441 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001442 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1443 */
James Smart2e0fef82007-06-17 19:56:36 -05001444 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001445 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001446 }
dea31012005-04-17 16:05:31 -05001447
James Smart2e0fef82007-06-17 19:56:36 -05001448 /* Start discovery by sending a FLOGI. port_state is identically
James Smart7f048392020-09-11 13:01:47 -07001449 * LPFC_FLOGI while waiting for FLOGI cmpl.
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001450 */
James Smart835214f2020-01-27 16:23:03 -08001451 if (vport->port_state != LPFC_FLOGI) {
James Smart7f048392020-09-11 13:01:47 -07001452 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1453 * bb-credit recovery is in place.
1454 */
1455 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1456 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1457 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1458 GFP_KERNEL);
1459 if (!sparam_mb)
1460 goto sparam_out;
1461
1462 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1463 if (rc) {
1464 mempool_free(sparam_mb, phba->mbox_mem_pool);
1465 goto sparam_out;
1466 }
1467 sparam_mb->vport = vport;
1468 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1469 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1470 if (rc == MBX_NOT_FINISHED) {
1471 sparam_mp = (struct lpfc_dmabuf *)
1472 sparam_mb->ctx_buf;
1473 lpfc_mbuf_free(phba, sparam_mp->virt,
1474 sparam_mp->phys);
1475 kfree(sparam_mp);
1476 sparam_mb->ctx_buf = NULL;
1477 mempool_free(sparam_mb, phba->mbox_mem_pool);
1478 goto sparam_out;
1479 }
1480
1481 phba->hba_flag |= HBA_DEFER_FLOGI;
1482 } else {
James Smart835214f2020-01-27 16:23:03 -08001483 lpfc_initial_flogi(vport);
James Smart7f048392020-09-11 13:01:47 -07001484 }
James Smart835214f2020-01-27 16:23:03 -08001485 } else {
1486 if (vport->fc_flag & FC_PT2PT)
1487 lpfc_disc_start(vport);
1488 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001489 return;
dea31012005-04-17 16:05:31 -05001490
1491out:
Dick Kennedy372c1872020-06-30 14:50:00 -07001492 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
Dan Carpenter0be31092021-01-25 11:44:34 +03001493 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1494 status, vport->port_state);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001495
Dan Carpenter0be31092021-01-25 11:44:34 +03001496sparam_out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001497 lpfc_linkdown(phba);
1498
Dick Kennedy372c1872020-06-30 14:50:00 -07001499 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001500 "0200 CONFIG_LINK bad hba state x%x\n",
1501 vport->port_state);
dea31012005-04-17 16:05:31 -05001502
James Smart92d7f7b2007-06-17 19:56:38 -05001503 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001504 return;
1505}
1506
James Smart7d791df2011-07-22 18:37:52 -04001507/**
1508 * lpfc_sli4_clear_fcf_rr_bmask
Lee Jonese415f2a2020-07-23 13:24:08 +01001509 * @phba: pointer to the struct lpfc_hba for this port.
James Smart7d791df2011-07-22 18:37:52 -04001510 * This fucnction resets the round robin bit mask and clears the
1511 * fcf priority list. The list deletions are done while holding the
1512 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1513 * from the lpfc_fcf_pri record.
1514 **/
1515void
1516lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1517{
1518 struct lpfc_fcf_pri *fcf_pri;
1519 struct lpfc_fcf_pri *next_fcf_pri;
1520 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1521 spin_lock_irq(&phba->hbalock);
1522 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1523 &phba->fcf.fcf_pri_list, list) {
1524 list_del_init(&fcf_pri->list);
1525 fcf_pri->fcf_rec.flag = 0;
1526 }
1527 spin_unlock_irq(&phba->hbalock);
1528}
dea31012005-04-17 16:05:31 -05001529static void
James Smart6fb120a2009-05-22 14:52:59 -04001530lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1531{
1532 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001533
1534 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07001535 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1536 "2017 REG_FCFI mbxStatus error x%x "
1537 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1538 vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001539 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001540 }
1541
1542 /* Start FCoE discovery by sending a FLOGI. */
1543 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1544 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001545 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001546 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001547 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001548
James Smart32b97932009-07-19 10:01:21 -04001549 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001550 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1551 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001552 goto fail_out;
1553
1554 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001555 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001556 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001557 phba->hba_flag &= ~FCF_TS_INPROG;
1558 if (vport->port_state != LPFC_FLOGI) {
1559 phba->hba_flag |= FCF_RR_INPROG;
1560 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001561 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001562 goto out;
1563 }
1564 spin_unlock_irq(&phba->hbalock);
1565 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001566
James Smarta93ff372010-10-22 11:06:08 -04001567fail_out:
1568 spin_lock_irq(&phba->hbalock);
1569 phba->hba_flag &= ~FCF_RR_INPROG;
1570 spin_unlock_irq(&phba->hbalock);
1571out:
James Smart6fb120a2009-05-22 14:52:59 -04001572 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001573}
1574
1575/**
1576 * lpfc_fab_name_match - Check if the fcf fabric name match.
1577 * @fab_name: pointer to fabric name.
1578 * @new_fcf_record: pointer to fcf record.
1579 *
1580 * This routine compare the fcf record's fabric name with provided
1581 * fabric name. If the fabric name are identical this function
1582 * returns 1 else return 0.
1583 **/
1584static uint32_t
1585lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1586{
James Smartecfd03c2010-02-12 14:41:27 -05001587 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001588 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001589 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1590 return 0;
1591 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1592 return 0;
1593 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1594 return 0;
1595 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1596 return 0;
1597 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1598 return 0;
1599 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1600 return 0;
1601 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1602 return 0;
1603 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001604}
1605
1606/**
James Smart8fa38512009-07-19 10:01:03 -04001607 * lpfc_sw_name_match - Check if the fcf switch name match.
Lee Jonese415f2a2020-07-23 13:24:08 +01001608 * @sw_name: pointer to switch name.
James Smart8fa38512009-07-19 10:01:03 -04001609 * @new_fcf_record: pointer to fcf record.
1610 *
1611 * This routine compare the fcf record's switch name with provided
1612 * switch name. If the switch name are identical this function
1613 * returns 1 else return 0.
1614 **/
1615static uint32_t
1616lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1617{
James Smartecfd03c2010-02-12 14:41:27 -05001618 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001619 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001620 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1621 return 0;
1622 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1623 return 0;
1624 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1625 return 0;
1626 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1627 return 0;
1628 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1629 return 0;
1630 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1631 return 0;
1632 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1633 return 0;
1634 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001635}
1636
1637/**
James Smart6fb120a2009-05-22 14:52:59 -04001638 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001639 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001640 * @new_fcf_record: pointer to fcf record.
1641 *
1642 * This routine compare the fcf record's mac address with HBA's
1643 * FCF mac address. If the mac addresses are identical this function
1644 * returns 1 else return 0.
1645 **/
1646static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001647lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001648{
James Smartecfd03c2010-02-12 14:41:27 -05001649 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001650 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001651 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1652 return 0;
1653 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1654 return 0;
1655 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1656 return 0;
1657 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1658 return 0;
1659 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1660 return 0;
1661 return 1;
1662}
1663
1664static bool
1665lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1666{
1667 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001668}
1669
1670/**
James Smart7d791df2011-07-22 18:37:52 -04001671 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1672 * @phba: pointer to lpfc hba data structure.
1673 * @fcf_index: Index for the lpfc_fcf_record.
1674 * @new_fcf_record: pointer to hba fcf record.
1675 *
1676 * This routine updates the driver FCF priority record from the new HBA FCF
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001677 * record. The hbalock is asserted held in the code path calling this
1678 * routine.
James Smart7d791df2011-07-22 18:37:52 -04001679 **/
1680static void
1681__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1682 struct fcf_record *new_fcf_record
1683 )
1684{
1685 struct lpfc_fcf_pri *fcf_pri;
1686
1687 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1688 fcf_pri->fcf_rec.fcf_index = fcf_index;
1689 /* FCF record priority */
1690 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1691
1692}
1693
1694/**
James Smart6fb120a2009-05-22 14:52:59 -04001695 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
Lee Jonese415f2a2020-07-23 13:24:08 +01001696 * @fcf_rec: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001697 * @new_fcf_record: pointer to fcf record.
1698 *
1699 * This routine copies the FCF information from the FCF
1700 * record to lpfc_hba data structure.
1701 **/
1702static void
James Smartecfd03c2010-02-12 14:41:27 -05001703lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1704 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001705{
James Smartecfd03c2010-02-12 14:41:27 -05001706 /* Fabric name */
1707 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001708 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001709 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001710 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001711 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001712 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001713 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001714 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001715 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001716 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001717 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001718 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001719 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001720 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001721 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001722 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001723 /* Mac address */
1724 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1725 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1726 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1727 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1728 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1729 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1730 /* FCF record index */
1731 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1732 /* FCF record priority */
1733 fcf_rec->priority = new_fcf_record->fip_priority;
1734 /* Switch name */
1735 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001736 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001737 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001738 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001739 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001740 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001741 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001742 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001743 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001744 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001745 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001746 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001747 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001748 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001749 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001750 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001751}
1752
1753/**
Lee Jones3884ce12021-03-03 14:46:28 +00001754 * __lpfc_update_fcf_record - Update driver fcf record
James Smartecfd03c2010-02-12 14:41:27 -05001755 * @phba: pointer to lpfc hba data structure.
1756 * @fcf_rec: pointer to driver fcf record.
1757 * @new_fcf_record: pointer to hba fcf record.
1758 * @addr_mode: address mode to be set to the driver fcf record.
1759 * @vlan_id: vlan tag to be set to the driver fcf record.
1760 * @flag: flag bits to be set to the driver fcf record.
1761 *
1762 * This routine updates the driver FCF record from the new HBA FCF record
1763 * together with the address mode, vlan_id, and other informations. This
Dick Kennedy88acb4d2020-05-01 14:43:07 -07001764 * routine is called with the hbalock held.
James Smartecfd03c2010-02-12 14:41:27 -05001765 **/
1766static void
1767__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1768 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1769 uint16_t vlan_id, uint32_t flag)
1770{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001771 lockdep_assert_held(&phba->hbalock);
1772
James Smartecfd03c2010-02-12 14:41:27 -05001773 /* Copy the fields from the HBA's FCF record */
1774 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1775 /* Update other fields of driver FCF record */
1776 fcf_rec->addr_mode = addr_mode;
1777 fcf_rec->vlan_id = vlan_id;
1778 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001779 __lpfc_update_fcf_record_pri(phba,
1780 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1781 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001782}
1783
1784/**
James Smart6fb120a2009-05-22 14:52:59 -04001785 * lpfc_register_fcf - Register the FCF with hba.
1786 * @phba: pointer to lpfc hba data structure.
1787 *
1788 * This routine issues a register fcfi mailbox command to register
1789 * the fcf with HBA.
1790 **/
1791static void
1792lpfc_register_fcf(struct lpfc_hba *phba)
1793{
1794 LPFC_MBOXQ_t *fcf_mbxq;
1795 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001796
James Smartd439d282010-09-29 11:18:45 -04001797 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001798 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001799 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001800 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001801 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001802 return;
1803 }
1804
1805 /* The FCF is already registered, start discovery */
1806 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001807 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001808 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001809 if (phba->pport->port_state != LPFC_FLOGI &&
1810 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001811 phba->hba_flag |= FCF_RR_INPROG;
1812 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001813 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001814 return;
1815 }
1816 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001817 return;
1818 }
James Smartd439d282010-09-29 11:18:45 -04001819 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001820
James Smarta93ff372010-10-22 11:06:08 -04001821 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001822 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001823 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001824 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001825 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001826 return;
James Smart4d9ab992009-10-02 15:16:39 -04001827 }
James Smart6fb120a2009-05-22 14:52:59 -04001828
1829 lpfc_reg_fcfi(phba, fcf_mbxq);
1830 fcf_mbxq->vport = phba->pport;
1831 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1832 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001833 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001834 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001835 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001836 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001837 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001838 }
James Smart6fb120a2009-05-22 14:52:59 -04001839
1840 return;
1841}
1842
1843/**
1844 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1845 * @phba: pointer to lpfc hba data structure.
1846 * @new_fcf_record: pointer to fcf record.
1847 * @boot_flag: Indicates if this record used by boot bios.
1848 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001849 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001850 *
1851 * This routine compare the fcf record with connect list obtained from the
1852 * config region to decide if this FCF can be used for SAN discovery. It returns
1853 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1854 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1855 * is used by boot bios and addr_mode will indicate the addressing mode to be
1856 * used for this FCF when the function returns.
1857 * If the FCF record need to be used with a particular vlan id, the vlan is
1858 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001859 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001860 **/
1861static int
1862lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1863 struct fcf_record *new_fcf_record,
1864 uint32_t *boot_flag, uint32_t *addr_mode,
1865 uint16_t *vlan_id)
1866{
1867 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001868 int i, j, fcf_vlan_id = 0;
1869
1870 /* Find the lowest VLAN id in the FCF record */
1871 for (i = 0; i < 512; i++) {
1872 if (new_fcf_record->vlan_bitmap[i]) {
1873 fcf_vlan_id = i * 8;
1874 j = 0;
1875 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1876 j++;
1877 fcf_vlan_id++;
1878 }
1879 break;
1880 }
1881 }
James Smart6fb120a2009-05-22 14:52:59 -04001882
James Smart26979ce2012-09-29 11:31:55 -04001883 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001884 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001885 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1886 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001887 return 0;
1888
James Smart45ed1192009-10-02 15:17:02 -04001889 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001890 *boot_flag = 0;
1891 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1892 new_fcf_record);
1893 if (phba->valid_vlan)
1894 *vlan_id = phba->vlan_id;
1895 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001896 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001897 return 1;
1898 }
1899
1900 /*
1901 * If there are no FCF connection table entry, driver connect to all
1902 * FCFs.
1903 */
1904 if (list_empty(&phba->fcf_conn_rec_list)) {
1905 *boot_flag = 0;
1906 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1907 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001908
1909 /*
1910 * When there are no FCF connect entries, use driver's default
1911 * addressing mode - FPMA.
1912 */
1913 if (*addr_mode & LPFC_FCF_FPMA)
1914 *addr_mode = LPFC_FCF_FPMA;
1915
James Smart4d9ab992009-10-02 15:16:39 -04001916 /* If FCF record report a vlan id use that vlan id */
1917 if (fcf_vlan_id)
1918 *vlan_id = fcf_vlan_id;
1919 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001920 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001921 return 1;
1922 }
1923
James Smartecfd03c2010-02-12 14:41:27 -05001924 list_for_each_entry(conn_entry,
1925 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001926 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1927 continue;
1928
1929 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1930 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001931 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001932 continue;
James Smart8fa38512009-07-19 10:01:03 -04001933 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1934 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1935 new_fcf_record))
1936 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001937 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1938 /*
1939 * If the vlan bit map does not have the bit set for the
1940 * vlan id to be used, then it is not a match.
1941 */
1942 if (!(new_fcf_record->vlan_bitmap
1943 [conn_entry->conn_rec.vlan_tag / 8] &
1944 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1945 continue;
1946 }
1947
1948 /*
James Smart0c287582009-06-10 17:22:56 -04001949 * If connection record does not support any addressing mode,
1950 * skip the FCF record.
1951 */
1952 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1953 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1954 continue;
1955
1956 /*
James Smart6fb120a2009-05-22 14:52:59 -04001957 * Check if the connection record specifies a required
1958 * addressing mode.
1959 */
1960 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1961 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1962
1963 /*
1964 * If SPMA required but FCF not support this continue.
1965 */
1966 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1967 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1968 new_fcf_record) & LPFC_FCF_SPMA))
1969 continue;
1970
1971 /*
1972 * If FPMA required but FCF not support this continue.
1973 */
1974 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1975 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1976 new_fcf_record) & LPFC_FCF_FPMA))
1977 continue;
1978 }
1979
1980 /*
1981 * This fcf record matches filtering criteria.
1982 */
1983 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1984 *boot_flag = 1;
1985 else
1986 *boot_flag = 0;
1987
James Smart0c287582009-06-10 17:22:56 -04001988 /*
1989 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001990 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001991 * by FCF, allow fabric to pick the addressing mode.
1992 */
James Smart6fb120a2009-05-22 14:52:59 -04001993 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1994 new_fcf_record);
1995 /*
1996 * If the user specified a required address mode, assign that
1997 * address mode
1998 */
1999 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2000 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
2001 *addr_mode = (conn_entry->conn_rec.flags &
2002 FCFCNCT_AM_SPMA) ?
2003 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
2004 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002005 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04002006 * addr mode only if FCF support the addr_mode.
2007 */
2008 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2009 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2010 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2011 (*addr_mode & LPFC_FCF_SPMA))
2012 *addr_mode = LPFC_FCF_SPMA;
2013 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2014 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2015 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2016 (*addr_mode & LPFC_FCF_FPMA))
2017 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04002018
James Smart4d9ab992009-10-02 15:16:39 -04002019 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04002020 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2021 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04002022 /*
2023 * If no vlan id is specified in connect list, use the vlan id
2024 * in the FCF record
2025 */
2026 else if (fcf_vlan_id)
2027 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04002028 else
James Smartdbb6b3a2010-06-08 18:31:37 -04002029 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04002030
2031 return 1;
2032 }
2033
2034 return 0;
2035}
2036
2037/**
James Smart32b97932009-07-19 10:01:21 -04002038 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2039 * @phba: pointer to lpfc hba data structure.
2040 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2041 *
2042 * This function check if there is any fcoe event pending while driver
2043 * scan FCF entries. If there is any pending event, it will restart the
2044 * FCF saning and return 1 else return 0.
2045 */
2046int
2047lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2048{
James Smart32b97932009-07-19 10:01:21 -04002049 /*
2050 * If the Link is up and no FCoE events while in the
2051 * FCF discovery, no need to restart FCF discovery.
2052 */
2053 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04002054 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04002055 return 0;
2056
James Smart0c9ab6f2010-02-26 14:15:57 -05002057 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2058 "2768 Pending link or FCF event during current "
2059 "handling of the previous event: link_state:x%x, "
2060 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2061 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2062 phba->fcoe_eventtag);
2063
James Smart32b97932009-07-19 10:01:21 -04002064 spin_lock_irq(&phba->hbalock);
2065 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2066 spin_unlock_irq(&phba->hbalock);
2067
James Smart0c9ab6f2010-02-26 14:15:57 -05002068 if (phba->link_state >= LPFC_LINK_UP) {
2069 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2070 "2780 Restart FCF table scan due to "
2071 "pending FCF event:evt_tag_at_scan:x%x, "
2072 "evt_tag_current:x%x\n",
2073 phba->fcoe_eventtag_at_fcf_scan,
2074 phba->fcoe_eventtag);
2075 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2076 } else {
James Smart4d9ab992009-10-02 15:16:39 -04002077 /*
James Smarta93ff372010-10-22 11:06:08 -04002078 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04002079 * flag
2080 */
James Smartdbb6b3a2010-06-08 18:31:37 -04002081 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2082 "2833 Stop FCF discovery process due to link "
2083 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05002084 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002085 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05002086 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05002087 spin_unlock_irq(&phba->hbalock);
2088 }
James Smart32b97932009-07-19 10:01:21 -04002089
James Smart0c9ab6f2010-02-26 14:15:57 -05002090 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04002091 if (unreg_fcf) {
2092 spin_lock_irq(&phba->hbalock);
2093 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2094 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05002095 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04002096 }
James Smart32b97932009-07-19 10:01:21 -04002097 return 1;
2098}
2099
2100/**
James Smart999d8132010-03-15 11:24:56 -04002101 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2102 * @phba: pointer to lpfc hba data structure.
2103 * @fcf_cnt: number of eligible fcf record seen so far.
2104 *
2105 * This function makes an running random selection decision on FCF record to
2106 * use through a sequence of @fcf_cnt eligible FCF records with equal
2107 * probability. To perform integer manunipulation of random numbers with
2108 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07002109 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04002110 *
2111 * Returns true when outcome is for the newly read FCF record should be
2112 * chosen; otherwise, return false when outcome is for keeping the previously
2113 * chosen FCF record.
2114 **/
2115static bool
2116lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2117{
2118 uint32_t rand_num;
2119
2120 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07002121 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04002122
2123 /* Decision with probability 1/fcf_cnt */
2124 if ((fcf_cnt * rand_num) < 0xFFFF)
2125 return true;
2126 else
2127 return false;
2128}
2129
2130/**
James Smart3804dc82010-07-14 15:31:37 -04002131 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04002132 * @phba: pointer to lpfc hba data structure.
2133 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05002134 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04002135 *
James Smart0c9ab6f2010-02-26 14:15:57 -05002136 * This routine parses the non-embedded fcf mailbox command by performing the
2137 * necessarily error checking, non-embedded read FCF record mailbox command
2138 * SGE parsing, and endianness swapping.
2139 *
2140 * Returns the pointer to the new FCF record in the non-embedded mailbox
2141 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04002142 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002143static struct fcf_record *
2144lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2145 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04002146{
2147 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04002148 struct lpfc_mbx_sge sge;
2149 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04002150 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04002151 union lpfc_sli4_cfg_shdr *shdr;
2152 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04002153
James Smart6fb120a2009-05-22 14:52:59 -04002154 /* Get the first SGE entry from the non-embedded DMA memory. This
2155 * routine only uses a single SGE.
2156 */
2157 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04002158 if (unlikely(!mboxq->sge_array)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002159 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04002160 "2524 Failed to get the non-embedded SGE "
2161 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05002162 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04002163 }
2164 virt_addr = mboxq->sge_array->addr[0];
2165
2166 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05002167 lpfc_sli_pcimem_bcopy(shdr, shdr,
2168 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04002169 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04002170 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05002171 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04002172 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04002173 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2174 if_type == LPFC_SLI_INTF_IF_TYPE_2)
Dick Kennedy372c1872020-06-30 14:50:00 -07002175 lpfc_printf_log(phba, KERN_ERR,
2176 LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05002177 "2726 READ_FCF_RECORD Indicates empty "
2178 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05002179 else
Dick Kennedy372c1872020-06-30 14:50:00 -07002180 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartdef9c7a2009-12-21 17:02:28 -05002181 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05002182 "with status x%x add_status x%x, "
2183 "mbx\n", shdr_status, shdr_add_status);
2184 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04002185 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002186
2187 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04002188 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2189 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2190 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05002191 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04002192 new_fcf_record = (struct fcf_record *)(virt_addr +
2193 sizeof(struct lpfc_mbx_read_fcf_tbl));
2194 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04002195 offsetof(struct fcf_record, vlan_bitmap));
2196 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2197 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04002198
James Smart0c9ab6f2010-02-26 14:15:57 -05002199 return new_fcf_record;
2200}
2201
2202/**
2203 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2204 * @phba: pointer to lpfc hba data structure.
2205 * @fcf_record: pointer to the fcf record.
2206 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2207 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2208 *
2209 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2210 * enabled.
2211 **/
2212static void
2213lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2214 struct fcf_record *fcf_record,
2215 uint16_t vlan_id,
2216 uint16_t next_fcf_index)
2217{
2218 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2219 "2764 READ_FCF_RECORD:\n"
2220 "\tFCF_Index : x%x\n"
2221 "\tFCF_Avail : x%x\n"
2222 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04002223 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05002224 "\tFIP_Priority : x%x\n"
2225 "\tMAC_Provider : x%x\n"
2226 "\tLowest VLANID : x%x\n"
2227 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2228 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2229 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2230 "\tNext_FCF_Index: x%x\n",
2231 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2232 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2233 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04002234 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05002235 fcf_record->fip_priority,
2236 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2237 vlan_id,
2238 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2239 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2240 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2241 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2242 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2243 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2244 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2245 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2246 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2247 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2248 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2249 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2250 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2251 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2252 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2253 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2254 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2255 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2256 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2257 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2258 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2259 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2260 next_fcf_index);
2261}
2262
2263/**
Lee Jonese415f2a2020-07-23 13:24:08 +01002264 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
James Smartdbb6b3a2010-06-08 18:31:37 -04002265 * @phba: pointer to lpfc hba data structure.
2266 * @fcf_rec: pointer to an existing FCF record.
2267 * @new_fcf_record: pointer to a new FCF record.
2268 * @new_vlan_id: vlan id from the new FCF record.
2269 *
2270 * This function performs matching test of a new FCF record against an existing
2271 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2272 * will not be used as part of the FCF record matching criteria.
2273 *
2274 * Returns true if all the fields matching, otherwise returns false.
2275 */
2276static bool
2277lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2278 struct lpfc_fcf_rec *fcf_rec,
2279 struct fcf_record *new_fcf_record,
2280 uint16_t new_vlan_id)
2281{
2282 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2283 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2284 return false;
2285 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2286 return false;
2287 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2288 return false;
2289 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2290 return false;
James Smart7d791df2011-07-22 18:37:52 -04002291 if (fcf_rec->priority != new_fcf_record->fip_priority)
2292 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04002293 return true;
2294}
2295
2296/**
James Smarta93ff372010-10-22 11:06:08 -04002297 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2298 * @vport: Pointer to vport object.
2299 * @fcf_index: index to next fcf.
2300 *
2301 * This function processing the roundrobin fcf failover to next fcf index.
2302 * When this function is invoked, there will be a current fcf registered
2303 * for flogi.
2304 * Return: 0 for continue retrying flogi on currently registered fcf;
2305 * 1 for stop flogi on currently registered fcf;
2306 */
2307int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2308{
2309 struct lpfc_hba *phba = vport->phba;
2310 int rc;
2311
2312 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2313 spin_lock_irq(&phba->hbalock);
2314 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2315 spin_unlock_irq(&phba->hbalock);
2316 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2317 "2872 Devloss tmo with no eligible "
2318 "FCF, unregister in-use FCF (x%x) "
2319 "and rescan FCF table\n",
2320 phba->fcf.current_rec.fcf_indx);
2321 lpfc_unregister_fcf_rescan(phba);
2322 goto stop_flogi_current_fcf;
2323 }
2324 /* Mark the end to FLOGI roundrobin failover */
2325 phba->hba_flag &= ~FCF_RR_INPROG;
2326 /* Allow action to new fcf asynchronous event */
2327 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2328 spin_unlock_irq(&phba->hbalock);
2329 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2330 "2865 No FCF available, stop roundrobin FCF "
2331 "failover and change port state:x%x/x%x\n",
2332 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2333 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002334
2335 if (!phba->fcf.fcf_redisc_attempted) {
2336 lpfc_unregister_fcf(phba);
2337
2338 rc = lpfc_sli4_redisc_fcf_table(phba);
2339 if (!rc) {
2340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2341 "3195 Rediscover FCF table\n");
2342 phba->fcf.fcf_redisc_attempted = 1;
2343 lpfc_sli4_clear_fcf_rr_bmask(phba);
2344 } else {
2345 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2346 "3196 Rediscover FCF table "
2347 "failed. Status:x%x\n", rc);
2348 }
2349 } else {
2350 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2351 "3197 Already rediscover FCF table "
2352 "attempted. No more retry\n");
2353 }
James Smarta93ff372010-10-22 11:06:08 -04002354 goto stop_flogi_current_fcf;
2355 } else {
2356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2357 "2794 Try FLOGI roundrobin FCF failover to "
2358 "(x%x)\n", fcf_index);
2359 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2360 if (rc)
2361 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2362 "2761 FLOGI roundrobin FCF failover "
2363 "failed (rc:x%x) to read FCF (x%x)\n",
2364 rc, phba->fcf.current_rec.fcf_indx);
2365 else
2366 goto stop_flogi_current_fcf;
2367 }
2368 return 0;
2369
2370stop_flogi_current_fcf:
2371 lpfc_can_disctmo(vport);
2372 return 1;
2373}
2374
2375/**
James Smart7d791df2011-07-22 18:37:52 -04002376 * lpfc_sli4_fcf_pri_list_del
2377 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002378 * @fcf_index: the index of the fcf record to delete
James Smart7d791df2011-07-22 18:37:52 -04002379 * This routine checks the on list flag of the fcf_index to be deleted.
2380 * If it is one the list then it is removed from the list, and the flag
2381 * is cleared. This routine grab the hbalock before removing the fcf
2382 * record from the list.
2383 **/
2384static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2385 uint16_t fcf_index)
2386{
2387 struct lpfc_fcf_pri *new_fcf_pri;
2388
2389 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2390 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2391 "3058 deleting idx x%x pri x%x flg x%x\n",
2392 fcf_index, new_fcf_pri->fcf_rec.priority,
2393 new_fcf_pri->fcf_rec.flag);
2394 spin_lock_irq(&phba->hbalock);
2395 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2396 if (phba->fcf.current_rec.priority ==
2397 new_fcf_pri->fcf_rec.priority)
2398 phba->fcf.eligible_fcf_cnt--;
2399 list_del_init(&new_fcf_pri->list);
2400 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2401 }
2402 spin_unlock_irq(&phba->hbalock);
2403}
2404
2405/**
2406 * lpfc_sli4_set_fcf_flogi_fail
2407 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002408 * @fcf_index: the index of the fcf record to update
James Smart7d791df2011-07-22 18:37:52 -04002409 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2410 * flag so the the round robin slection for the particular priority level
2411 * will try a different fcf record that does not have this bit set.
2412 * If the fcf record is re-read for any reason this flag is cleared brfore
2413 * adding it to the priority list.
2414 **/
2415void
2416lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2417{
2418 struct lpfc_fcf_pri *new_fcf_pri;
2419 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2420 spin_lock_irq(&phba->hbalock);
2421 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2422 spin_unlock_irq(&phba->hbalock);
2423}
2424
2425/**
2426 * lpfc_sli4_fcf_pri_list_add
2427 * @phba: pointer to lpfc hba data structure.
Lee Jonese415f2a2020-07-23 13:24:08 +01002428 * @fcf_index: the index of the fcf record to add
2429 * @new_fcf_record: pointer to a new FCF record.
James Smart7d791df2011-07-22 18:37:52 -04002430 * This routine checks the priority of the fcf_index to be added.
2431 * If it is a lower priority than the current head of the fcf_pri list
2432 * then it is added to the list in the right order.
2433 * If it is the same priority as the current head of the list then it
2434 * is added to the head of the list and its bit in the rr_bmask is set.
2435 * If the fcf_index to be added is of a higher priority than the current
2436 * head of the list then the rr_bmask is cleared, its bit is set in the
2437 * rr_bmask and it is added to the head of the list.
2438 * returns:
2439 * 0=success 1=failure
2440 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002441static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2442 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002443 struct fcf_record *new_fcf_record)
2444{
2445 uint16_t current_fcf_pri;
2446 uint16_t last_index;
2447 struct lpfc_fcf_pri *fcf_pri;
2448 struct lpfc_fcf_pri *next_fcf_pri;
2449 struct lpfc_fcf_pri *new_fcf_pri;
2450 int ret;
2451
2452 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2453 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2454 "3059 adding idx x%x pri x%x flg x%x\n",
2455 fcf_index, new_fcf_record->fip_priority,
2456 new_fcf_pri->fcf_rec.flag);
2457 spin_lock_irq(&phba->hbalock);
2458 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2459 list_del_init(&new_fcf_pri->list);
2460 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2461 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2462 if (list_empty(&phba->fcf.fcf_pri_list)) {
2463 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2464 ret = lpfc_sli4_fcf_rr_index_set(phba,
2465 new_fcf_pri->fcf_rec.fcf_index);
2466 goto out;
2467 }
2468
2469 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2470 LPFC_SLI4_FCF_TBL_INDX_MAX);
2471 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2472 ret = 0; /* Empty rr list */
2473 goto out;
2474 }
2475 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2476 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2477 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2478 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2479 memset(phba->fcf.fcf_rr_bmask, 0,
2480 sizeof(*phba->fcf.fcf_rr_bmask));
2481 /* fcfs_at_this_priority_level = 1; */
2482 phba->fcf.eligible_fcf_cnt = 1;
2483 } else
2484 /* fcfs_at_this_priority_level++; */
2485 phba->fcf.eligible_fcf_cnt++;
2486 ret = lpfc_sli4_fcf_rr_index_set(phba,
2487 new_fcf_pri->fcf_rec.fcf_index);
2488 goto out;
2489 }
2490
2491 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2492 &phba->fcf.fcf_pri_list, list) {
2493 if (new_fcf_pri->fcf_rec.priority <=
2494 fcf_pri->fcf_rec.priority) {
2495 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2496 list_add(&new_fcf_pri->list,
2497 &phba->fcf.fcf_pri_list);
2498 else
2499 list_add(&new_fcf_pri->list,
2500 &((struct lpfc_fcf_pri *)
2501 fcf_pri->list.prev)->list);
2502 ret = 0;
2503 goto out;
2504 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2505 || new_fcf_pri->fcf_rec.priority <
2506 next_fcf_pri->fcf_rec.priority) {
2507 list_add(&new_fcf_pri->list, &fcf_pri->list);
2508 ret = 0;
2509 goto out;
2510 }
2511 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2512 continue;
2513
2514 }
2515 ret = 1;
2516out:
2517 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2518 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2519 spin_unlock_irq(&phba->hbalock);
2520 return ret;
2521}
2522
2523/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002524 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2525 * @phba: pointer to lpfc hba data structure.
2526 * @mboxq: pointer to mailbox object.
2527 *
2528 * This function iterates through all the fcf records available in
2529 * HBA and chooses the optimal FCF record for discovery. After finding
2530 * the FCF for discovery it registers the FCF record and kicks start
2531 * discovery.
2532 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2533 * use an FCF record which matches fabric name and mac address of the
2534 * currently used FCF record.
2535 * If the driver supports only one FCF, it will try to use the FCF record
2536 * used by BOOT_BIOS.
2537 */
2538void
2539lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2540{
2541 struct fcf_record *new_fcf_record;
2542 uint32_t boot_flag, addr_mode;
2543 uint16_t fcf_index, next_fcf_index;
2544 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002545 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002546 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002547 int rc;
2548
2549 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002550 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002551 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2552 return;
2553 }
2554
2555 /* Parse the FCF record from the non-embedded mailbox command */
2556 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2557 &next_fcf_index);
2558 if (!new_fcf_record) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002559 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart0c9ab6f2010-02-26 14:15:57 -05002560 "2765 Mailbox command READ_FCF_RECORD "
2561 "failed to retrieve a FCF record.\n");
2562 /* Let next new FCF event trigger fast failover */
2563 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002564 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002565 spin_unlock_irq(&phba->hbalock);
2566 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2567 return;
2568 }
2569
2570 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002571 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2572 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002573
2574 /* Log the FCF record information if turned on */
2575 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2576 next_fcf_index);
2577
James Smart6fb120a2009-05-22 14:52:59 -04002578 /*
2579 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002580 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002581 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002582 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002583 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002584 lpfc_sli4_fcf_pri_list_del(phba,
2585 bf_get(lpfc_fcf_record_fcf_index,
2586 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002587 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002588 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002589 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002590 bf_get(lpfc_fcf_record_fcf_index,
2591 new_fcf_record),
2592 bf_get(lpfc_fcf_record_fcf_avail,
2593 new_fcf_record),
2594 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002595 new_fcf_record),
2596 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002597 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002598 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2599 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2600 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002601 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2602 phba->fcf.current_rec.fcf_indx) {
Dick Kennedy372c1872020-06-30 14:50:00 -07002603 lpfc_printf_log(phba, KERN_ERR,
2604 LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002605 "2862 FCF (x%x) matches property "
2606 "of in-use FCF (x%x)\n",
2607 bf_get(lpfc_fcf_record_fcf_index,
2608 new_fcf_record),
2609 phba->fcf.current_rec.fcf_indx);
2610 goto read_next_fcf;
2611 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002612 /*
2613 * In case the current in-use FCF record becomes
2614 * invalid/unavailable during FCF discovery that
2615 * was not triggered by fast FCF failover process,
2616 * treat it as fast FCF failover.
2617 */
2618 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2619 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2620 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2621 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002622 "(x%x), enter FCF failover "
2623 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002624 phba->fcf.current_rec.fcf_indx);
2625 spin_lock_irq(&phba->hbalock);
2626 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2627 spin_unlock_irq(&phba->hbalock);
2628 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2629 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2630 LPFC_FCOE_FCF_GET_FIRST);
2631 return;
2632 }
2633 }
James Smart6fb120a2009-05-22 14:52:59 -04002634 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002635 } else {
2636 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002637 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2638 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002639 if (rc)
2640 goto read_next_fcf;
2641 }
2642
James Smart6fb120a2009-05-22 14:52:59 -04002643 /*
2644 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002645 * FCF record for the discovery. The condition that a rescan
2646 * matches the in-use FCF record: fabric name, switch name, mac
2647 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002648 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002649 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002650 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002651 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2652 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002653 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002654 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2655 phba->fcf.current_rec.fcf_indx) {
2656 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2657 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2658 /* Stop FCF redisc wait timer */
2659 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2660 phba);
2661 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2662 /* Fast failover, mark completed */
2663 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2664 spin_unlock_irq(&phba->hbalock);
2665 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2666 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002667 "FCF (x%x), port_state:x%x, "
2668 "fc_flag:x%x\n",
2669 phba->fcf.current_rec.fcf_indx,
2670 phba->pport->port_state,
2671 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002672 goto out;
2673 } else
Dick Kennedy372c1872020-06-30 14:50:00 -07002674 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart5ac6b302010-10-22 11:05:36 -04002675 "2863 New FCF (x%x) matches "
2676 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002677 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002678 new_fcf_record),
2679 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002680 }
James Smartecfd03c2010-02-12 14:41:27 -05002681 /*
2682 * Read next FCF record from HBA searching for the matching
2683 * with in-use record only if not during the fast failover
2684 * period. In case of fast failover period, it shall try to
2685 * determine whether the FCF record just read should be the
2686 * next candidate.
2687 */
2688 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002689 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002690 goto read_next_fcf;
2691 }
James Smart6fb120a2009-05-22 14:52:59 -04002692 }
James Smartecfd03c2010-02-12 14:41:27 -05002693 /*
2694 * Update on failover FCF record only if it's in FCF fast-failover
2695 * period; otherwise, update on current FCF record.
2696 */
James Smartfc2b9892010-02-26 14:15:29 -05002697 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2698 fcf_rec = &phba->fcf.failover_rec;
2699 else
James Smartecfd03c2010-02-12 14:41:27 -05002700 fcf_rec = &phba->fcf.current_rec;
2701
James Smart6fb120a2009-05-22 14:52:59 -04002702 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2703 /*
James Smartecfd03c2010-02-12 14:41:27 -05002704 * If the driver FCF record does not have boot flag
2705 * set and new hba fcf record has boot flag set, use
2706 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002707 */
James Smartecfd03c2010-02-12 14:41:27 -05002708 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2709 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002710 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2711 "2837 Update current FCF record "
2712 "(x%x) with new FCF record (x%x)\n",
2713 fcf_rec->fcf_indx,
2714 bf_get(lpfc_fcf_record_fcf_index,
2715 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002716 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2717 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002718 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002719 goto read_next_fcf;
2720 }
2721 /*
James Smartecfd03c2010-02-12 14:41:27 -05002722 * If the driver FCF record has boot flag set and the
2723 * new hba FCF record does not have boot flag, read
2724 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002725 */
James Smartecfd03c2010-02-12 14:41:27 -05002726 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002727 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002728 goto read_next_fcf;
2729 }
2730 /*
James Smartecfd03c2010-02-12 14:41:27 -05002731 * If the new hba FCF record has lower priority value
2732 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002733 */
James Smartfc2b9892010-02-26 14:15:29 -05002734 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002735 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002736 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2737 "2838 Update current FCF record "
2738 "(x%x) with new FCF record (x%x)\n",
2739 fcf_rec->fcf_indx,
2740 bf_get(lpfc_fcf_record_fcf_index,
2741 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002742 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2743 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002744 /* Reset running random FCF selection count */
2745 phba->fcf.eligible_fcf_cnt = 1;
2746 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2747 /* Update running random FCF selection count */
2748 phba->fcf.eligible_fcf_cnt++;
2749 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2750 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002751 if (select_new_fcf) {
2752 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2753 "2839 Update current FCF record "
2754 "(x%x) with new FCF record (x%x)\n",
2755 fcf_rec->fcf_indx,
2756 bf_get(lpfc_fcf_record_fcf_index,
2757 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002758 /* Choose the new FCF by random selection */
2759 __lpfc_update_fcf_record(phba, fcf_rec,
2760 new_fcf_record,
2761 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002762 }
James Smart6fb120a2009-05-22 14:52:59 -04002763 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002764 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002765 goto read_next_fcf;
2766 }
2767 /*
James Smartecfd03c2010-02-12 14:41:27 -05002768 * This is the first suitable FCF record, choose this record for
2769 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002770 */
James Smartecfd03c2010-02-12 14:41:27 -05002771 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002772 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002773 "2840 Update initial FCF candidate "
2774 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002775 bf_get(lpfc_fcf_record_fcf_index,
2776 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002777 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2778 addr_mode, vlan_id, (boot_flag ?
2779 BOOT_ENABLE : 0));
2780 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002781 /* Setup initial running random FCF selection count */
2782 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002783 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002784 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002785 goto read_next_fcf;
2786
2787read_next_fcf:
2788 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002789 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2790 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2791 /*
2792 * Case of FCF fast failover scan
2793 */
2794
2795 /*
2796 * It has not found any suitable FCF record, cancel
2797 * FCF scan inprogress, and do nothing
2798 */
2799 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002800 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002801 "2782 No suitable FCF found: "
2802 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002803 phba->fcoe_eventtag_at_fcf_scan,
2804 bf_get(lpfc_fcf_record_fcf_index,
2805 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002806 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002807 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2808 phba->hba_flag &= ~FCF_TS_INPROG;
2809 spin_unlock_irq(&phba->hbalock);
2810 /* Unregister in-use FCF and rescan */
2811 lpfc_printf_log(phba, KERN_INFO,
2812 LOG_FIP,
2813 "2864 On devloss tmo "
2814 "unreg in-use FCF and "
2815 "rescan FCF table\n");
2816 lpfc_unregister_fcf_rescan(phba);
2817 return;
2818 }
2819 /*
2820 * Let next new FCF event trigger fast failover
2821 */
2822 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002823 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002824 return;
2825 }
2826 /*
2827 * It has found a suitable FCF record that is not
2828 * the same as in-use FCF record, unregister the
2829 * in-use FCF record, replace the in-use FCF record
2830 * with the new FCF record, mark FCF fast failover
2831 * completed, and then start register the new FCF
2832 * record.
2833 */
2834
James Smart0c9ab6f2010-02-26 14:15:57 -05002835 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002836 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002837
2838 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002839 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002840 "2842 Replace in-use FCF (x%x) "
2841 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002842 phba->fcf.current_rec.fcf_indx,
2843 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002844 memcpy(&phba->fcf.current_rec,
2845 &phba->fcf.failover_rec,
2846 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002847 /*
2848 * Mark the fast FCF failover rediscovery completed
2849 * and the start of the first round of the roundrobin
2850 * FCF failover.
2851 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002852 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002853 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002854 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002855 /* Register to the new FCF record */
2856 lpfc_register_fcf(phba);
2857 } else {
2858 /*
2859 * In case of transaction period to fast FCF failover,
2860 * do nothing when search to the end of the FCF table.
2861 */
2862 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2863 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2864 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002865
James Smart7d791df2011-07-22 18:37:52 -04002866 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2867 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002868 /*
2869 * In case the current in-use FCF record no
2870 * longer existed during FCF discovery that
2871 * was not triggered by fast FCF failover
2872 * process, treat it as fast FCF failover.
2873 */
2874 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2875 "2841 In-use FCF record (x%x) "
2876 "not reported, entering fast "
2877 "FCF failover mode scanning.\n",
2878 phba->fcf.current_rec.fcf_indx);
2879 spin_lock_irq(&phba->hbalock);
2880 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2881 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002882 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2883 LPFC_FCOE_FCF_GET_FIRST);
2884 return;
2885 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002886 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002887 lpfc_register_fcf(phba);
2888 }
2889 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002890 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002891 return;
2892
2893out:
2894 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2895 lpfc_register_fcf(phba);
2896
2897 return;
2898}
2899
2900/**
James Smarta93ff372010-10-22 11:06:08 -04002901 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002902 * @phba: pointer to lpfc hba data structure.
2903 * @mboxq: pointer to mailbox object.
2904 *
James Smarta93ff372010-10-22 11:06:08 -04002905 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002906 * read FCF record mailbox command from the eligible FCF record bmask for
2907 * performing the failover. If the FCF read back is not valid/available, it
2908 * fails through to retrying FLOGI to the currently registered FCF again.
2909 * Otherwise, if the FCF read back is valid and available, it will set the
2910 * newly read FCF record to the failover FCF record, unregister currently
2911 * registered FCF record, copy the failover FCF record to the current
2912 * FCF record, and then register the current FCF record before proceeding
2913 * to trying FLOGI on the new failover FCF.
2914 */
2915void
2916lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2917{
2918 struct fcf_record *new_fcf_record;
2919 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002920 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002921 uint16_t current_fcf_index;
2922 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002923 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002924
James Smarta93ff372010-10-22 11:06:08 -04002925 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002926 if (phba->link_state < LPFC_LINK_UP) {
2927 spin_lock_irq(&phba->hbalock);
2928 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002929 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002930 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002931 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002932 }
2933
2934 /* Parse the FCF record from the non-embedded mailbox command */
2935 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2936 &next_fcf_index);
2937 if (!new_fcf_record) {
2938 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2939 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002940 "failed to retrieve a FCF record. "
2941 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2942 phba->fcf.fcf_flag);
2943 lpfc_unregister_fcf_rescan(phba);
2944 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002945 }
2946
2947 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002948 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2949 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002950
2951 /* Log the FCF record information if turned on */
2952 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2953 next_fcf_index);
2954
James Smarta93ff372010-10-22 11:06:08 -04002955 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2956 if (!rc) {
2957 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2958 "2848 Remove ineligible FCF (x%x) from "
2959 "from roundrobin bmask\n", fcf_index);
2960 /* Clear roundrobin bmask bit for ineligible FCF */
2961 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2962 /* Perform next round of roundrobin FCF failover */
2963 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2964 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2965 if (rc)
2966 goto out;
2967 goto error_out;
2968 }
2969
2970 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2971 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2972 "2760 Perform FLOGI roundrobin FCF failover: "
2973 "FCF (x%x) back to FCF (x%x)\n",
2974 phba->fcf.current_rec.fcf_indx, fcf_index);
2975 /* Wait 500 ms before retrying FLOGI to current FCF */
2976 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002977 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002978 goto out;
2979 }
2980
James Smart0c9ab6f2010-02-26 14:15:57 -05002981 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002982 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002983 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2984 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002985 spin_lock_irq(&phba->hbalock);
2986 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2987 new_fcf_record, addr_mode, vlan_id,
2988 (boot_flag ? BOOT_ENABLE : 0));
2989 spin_unlock_irq(&phba->hbalock);
2990
2991 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2992
2993 /* Unregister the current in-use FCF record */
2994 lpfc_unregister_fcf(phba);
2995
2996 /* Replace in-use record with the new record */
2997 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2998 sizeof(struct lpfc_fcf_rec));
2999
3000 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04003001 "2783 Perform FLOGI roundrobin FCF failover: FCF "
3002 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05003003
James Smarta93ff372010-10-22 11:06:08 -04003004error_out:
3005 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05003006out:
3007 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05003008}
3009
3010/**
3011 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3012 * @phba: pointer to lpfc hba data structure.
3013 * @mboxq: pointer to mailbox object.
3014 *
3015 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04003016 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05003017 * failover when a new FCF event happened. If the FCF read back is
3018 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04003019 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05003020 */
3021void
3022lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3023{
3024 struct fcf_record *new_fcf_record;
3025 uint32_t boot_flag, addr_mode;
3026 uint16_t fcf_index, next_fcf_index;
3027 uint16_t vlan_id;
3028 int rc;
3029
3030 /* If link state is not up, no need to proceed */
3031 if (phba->link_state < LPFC_LINK_UP)
3032 goto out;
3033
3034 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04003035 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05003036 goto out;
3037
3038 /* Parse the FCF record from the non-embedded mailbox command */
3039 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3040 &next_fcf_index);
3041 if (!new_fcf_record) {
3042 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3043 "2767 Mailbox command READ_FCF_RECORD "
3044 "failed to retrieve a FCF record.\n");
3045 goto out;
3046 }
3047
3048 /* Check the connection list for eligibility */
3049 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3050 &addr_mode, &vlan_id);
3051
3052 /* Log the FCF record information if turned on */
3053 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3054 next_fcf_index);
3055
3056 if (!rc)
3057 goto out;
3058
3059 /* Update the eligible FCF record index bmask */
3060 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04003061
3062 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05003063
3064out:
3065 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3066}
3067
3068/**
James Smart76a95d72010-11-20 23:11:48 -05003069 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3070 * @phba: pointer to lpfc hba data structure.
3071 * @mboxq: pointer to mailbox data structure.
3072 *
3073 * This function handles completion of init vfi mailbox command.
3074 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04003075static void
James Smart76a95d72010-11-20 23:11:48 -05003076lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3077{
3078 struct lpfc_vport *vport = mboxq->vport;
3079
James Smartdf9e1b52011-12-13 13:22:17 -05003080 /*
3081 * VFI not supported on interface type 0, just do the flogi
3082 * Also continue if the VFI is in use - just use the same one.
3083 */
3084 if (mboxq->u.mb.mbxStatus &&
3085 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3086 LPFC_SLI_INTF_IF_TYPE_0) &&
3087 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003088 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3089 "2891 Init VFI mailbox failed 0x%x\n",
3090 mboxq->u.mb.mbxStatus);
James Smart76a95d72010-11-20 23:11:48 -05003091 mempool_free(mboxq, phba->mbox_mem_pool);
3092 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3093 return;
3094 }
James Smart73d91e52011-10-10 21:32:10 -04003095
James Smart76a95d72010-11-20 23:11:48 -05003096 lpfc_initial_flogi(vport);
3097 mempool_free(mboxq, phba->mbox_mem_pool);
3098 return;
3099}
3100
3101/**
3102 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3103 * @vport: pointer to lpfc_vport data structure.
3104 *
3105 * This function issue a init_vfi mailbox command to initialize the VFI and
3106 * VPI for the physical port.
3107 */
3108void
3109lpfc_issue_init_vfi(struct lpfc_vport *vport)
3110{
3111 LPFC_MBOXQ_t *mboxq;
3112 int rc;
3113 struct lpfc_hba *phba = vport->phba;
3114
3115 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3116 if (!mboxq) {
3117 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003118 LOG_TRACE_EVENT, "2892 Failed to allocate "
James Smart76a95d72010-11-20 23:11:48 -05003119 "init_vfi mailbox\n");
3120 return;
3121 }
3122 lpfc_init_vfi(mboxq, vport);
3123 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3124 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3125 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003126 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3127 "2893 Failed to issue init_vfi mailbox\n");
James Smart76a95d72010-11-20 23:11:48 -05003128 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3129 }
3130}
3131
3132/**
James Smart1c6834a2009-07-19 10:01:26 -04003133 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3134 * @phba: pointer to lpfc hba data structure.
3135 * @mboxq: pointer to mailbox data structure.
3136 *
3137 * This function handles completion of init vpi mailbox command.
3138 */
James Smart695a8142010-01-26 23:08:03 -05003139void
James Smart1c6834a2009-07-19 10:01:26 -04003140lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3141{
3142 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05003143 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05003144 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3145
James Smart1c6834a2009-07-19 10:01:26 -04003146 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003147 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3148 "2609 Init VPI mailbox failed 0x%x\n",
3149 mboxq->u.mb.mbxStatus);
James Smart1c6834a2009-07-19 10:01:26 -04003150 mempool_free(mboxq, phba->mbox_mem_pool);
3151 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3152 return;
3153 }
James Smart72100cc2010-02-12 14:43:01 -05003154 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04003155 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003156 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04003157
James Smart695a8142010-01-26 23:08:03 -05003158 /* If this port is physical port or FDISC is done, do reg_vpi */
3159 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3160 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3161 if (!ndlp)
3162 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003163 LOG_TRACE_EVENT,
James Smart695a8142010-01-26 23:08:03 -05003164 "2731 Cannot find fabric "
3165 "controller node\n");
3166 else
3167 lpfc_register_new_vport(phba, vport, ndlp);
3168 mempool_free(mboxq, phba->mbox_mem_pool);
3169 return;
3170 }
3171
James Smart1c6834a2009-07-19 10:01:26 -04003172 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3173 lpfc_initial_fdisc(vport);
3174 else {
3175 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
Dick Kennedy372c1872020-06-30 14:50:00 -07003176 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart6a9c52c2009-10-02 15:16:51 -04003177 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04003178 }
James Smart695a8142010-01-26 23:08:03 -05003179 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003180 return;
3181}
3182
3183/**
James Smartecfd03c2010-02-12 14:41:27 -05003184 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3185 * @vport: pointer to lpfc_vport data structure.
3186 *
3187 * This function issue a init_vpi mailbox command to initialize
3188 * VPI for the vport.
3189 */
3190void
3191lpfc_issue_init_vpi(struct lpfc_vport *vport)
3192{
3193 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04003194 int rc, vpi;
3195
3196 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3197 vpi = lpfc_alloc_vpi(vport->phba);
3198 if (!vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003199 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart16a3a202013-04-17 20:14:38 -04003200 "3303 Failed to obtain vport vpi\n");
3201 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3202 return;
3203 }
3204 vport->vpi = vpi;
3205 }
James Smartecfd03c2010-02-12 14:41:27 -05003206
3207 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3208 if (!mboxq) {
3209 lpfc_printf_vlog(vport, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003210 LOG_TRACE_EVENT, "2607 Failed to allocate "
James Smartecfd03c2010-02-12 14:41:27 -05003211 "init_vpi mailbox\n");
3212 return;
3213 }
3214 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3215 mboxq->vport = vport;
3216 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3217 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3218 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003219 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3220 "2608 Failed to issue init_vpi mailbox\n");
James Smartecfd03c2010-02-12 14:41:27 -05003221 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3222 }
3223}
3224
3225/**
James Smart6fb120a2009-05-22 14:52:59 -04003226 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3227 * @phba: pointer to lpfc hba data structure.
3228 *
3229 * This function loops through the list of vports on the @phba and issues an
3230 * FDISC if possible.
3231 */
3232void
3233lpfc_start_fdiscs(struct lpfc_hba *phba)
3234{
3235 struct lpfc_vport **vports;
3236 int i;
3237
3238 vports = lpfc_create_vport_work_array(phba);
3239 if (vports != NULL) {
3240 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3241 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3242 continue;
3243 /* There are no vpi for this vport */
3244 if (vports[i]->vpi > phba->max_vpi) {
3245 lpfc_vport_set_state(vports[i],
3246 FC_VPORT_FAILED);
3247 continue;
3248 }
James Smart76a95d72010-11-20 23:11:48 -05003249 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04003250 lpfc_vport_set_state(vports[i],
3251 FC_VPORT_LINKDOWN);
3252 continue;
3253 }
James Smart1c6834a2009-07-19 10:01:26 -04003254 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05003255 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04003256 continue;
3257 }
James Smart6fb120a2009-05-22 14:52:59 -04003258 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3259 lpfc_initial_fdisc(vports[i]);
3260 else {
3261 lpfc_vport_set_state(vports[i],
3262 FC_VPORT_NO_FABRIC_SUPP);
3263 lpfc_printf_vlog(vports[i], KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003264 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04003265 "0259 No NPIV "
3266 "Fabric support\n");
3267 }
3268 }
3269 }
3270 lpfc_destroy_vport_work_array(phba, vports);
3271}
3272
3273void
3274lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3275{
James Smart3e1f0712018-11-29 16:09:29 -08003276 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04003277 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05003278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04003279
James Smartf5eca9b2012-03-01 22:37:54 -05003280 /*
3281 * VFI not supported for interface type 0, so ignore any mailbox
3282 * error (except VFI in use) and continue with the discovery.
3283 */
3284 if (mboxq->u.mb.mbxStatus &&
3285 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3286 LPFC_SLI_INTF_IF_TYPE_0) &&
3287 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003288 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3289 "2018 REG_VFI mbxStatus error x%x "
3290 "HBA state x%x\n",
3291 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05003292 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04003293 /* FLOGI failed, use loop map to make discovery list */
3294 lpfc_disc_list_loopmap(vport);
3295 /* Start discovery */
3296 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05003297 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003298 }
3299 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05003300 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04003301 }
James Smartae05ebe2013-03-01 16:35:38 -05003302
James Smarte74c03c2013-04-17 20:15:19 -04003303 /* If the VFI is already registered, there is nothing else to do
3304 * Unless this was a VFI update and we are in PT2PT mode, then
3305 * we should drop through to set the port state to ready.
3306 */
James Smartae05ebe2013-03-01 16:35:38 -05003307 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04003308 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3309 vport->fc_flag & FC_PT2PT))
3310 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05003311
James Smartc8685952009-11-18 15:39:16 -05003312 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05003313 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003314 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003315 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003316 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003317 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003318 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003319
James Smart1b511972011-12-13 13:23:09 -05003320 /* In case SLI4 FC loopback test, we are ready */
3321 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3322 (phba->link_flag & LS_LOOPBACK_MODE)) {
3323 phba->link_state = LPFC_HBA_READY;
3324 goto out_free_mem;
3325 }
3326
James Smarte74c03c2013-04-17 20:15:19 -04003327 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3328 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3329 "alpacnt:%d LinkState:%x topology:%x\n",
3330 vport->port_state, vport->fc_flag, vport->fc_myDID,
3331 vport->phba->alpa_map[0],
3332 phba->link_state, phba->fc_topology);
3333
James Smart6fb120a2009-05-22 14:52:59 -04003334 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003335 /*
3336 * For private loop or for NPort pt2pt,
3337 * just start discovery and we are done.
3338 */
3339 if ((vport->fc_flag & FC_PT2PT) ||
3340 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3341 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3342
James Smart76a95d72010-11-20 23:11:48 -05003343 /* Use loop map to make discovery list */
3344 lpfc_disc_list_loopmap(vport);
3345 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003346 if (vport->fc_flag & FC_PT2PT)
3347 vport->port_state = LPFC_VPORT_READY;
3348 else
3349 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003350 } else {
3351 lpfc_start_fdiscs(phba);
3352 lpfc_do_scr_ns_plogi(phba, vport);
3353 }
James Smart6fb120a2009-05-22 14:52:59 -04003354 }
3355
James Smart1b511972011-12-13 13:23:09 -05003356out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003357 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003358 if (dmabuf) {
3359 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3360 kfree(dmabuf);
3361 }
James Smart6fb120a2009-05-22 14:52:59 -04003362 return;
3363}
3364
3365static void
James Smart2e0fef82007-06-17 19:56:36 -05003366lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003367{
James Smart6fb120a2009-05-22 14:52:59 -04003368 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003369 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003370 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003372 struct serv_parm *sp = &vport->fc_sparam;
3373 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003374
3375 /* Check for error */
3376 if (mb->mbxStatus) {
3377 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
Dick Kennedy372c1872020-06-30 14:50:00 -07003378 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003379 "0319 READ_SPARAM mbxStatus error x%x "
3380 "hba state x%x>\n",
3381 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003382 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003383 goto out;
3384 }
3385
James Smart2e0fef82007-06-17 19:56:36 -05003386 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003387 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003388
3389 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3390 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3391 ed_tov = (ed_tov + 999999) / 1000000;
3392
3393 phba->fc_edtov = ed_tov;
3394 phba->fc_ratov = (2 * ed_tov) / 1000;
3395 if (phba->fc_ratov < FF_DEF_RATOV) {
3396 /* RA_TOV should be atleast 10sec for initial flogi */
3397 phba->fc_ratov = FF_DEF_RATOV;
3398 }
3399
James Smart05580562011-05-24 11:40:48 -04003400 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003401 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003402 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3403 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3404 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3405 }
3406
dea31012005-04-17 16:05:31 -05003407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3408 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003409 mempool_free(pmb, phba->mbox_mem_pool);
James Smart835214f2020-01-27 16:23:03 -08003410
3411 /* Check if sending the FLOGI is being deferred to after we get
3412 * up to date CSPs from MBX_READ_SPARAM.
3413 */
3414 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3415 lpfc_initial_flogi(vport);
3416 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3417 }
dea31012005-04-17 16:05:31 -05003418 return;
3419
3420out:
James Smart3e1f0712018-11-29 16:09:29 -08003421 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003422 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3423 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003424 lpfc_issue_clear_la(phba, vport);
3425 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003426 return;
3427}
3428
3429static void
James Smart76a95d72010-11-20 23:11:48 -05003430lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003431{
James Smart92d7f7b2007-06-17 19:56:38 -05003432 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003433 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003434 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003435 int i;
James Smart14691152006-12-02 13:34:28 -05003436 struct lpfc_dmabuf *mp;
3437 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003438 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003439 uint32_t fc_flags = 0;
James Smart894bb172019-08-14 16:56:52 -07003440 unsigned long iflags;
James Smart14691152006-12-02 13:34:28 -05003441
James Smart894bb172019-08-14 16:56:52 -07003442 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta085e872015-12-16 18:12:02 -05003443 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3444
3445 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3446 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3447 case LPFC_LINK_SPEED_1GHZ:
3448 case LPFC_LINK_SPEED_2GHZ:
3449 case LPFC_LINK_SPEED_4GHZ:
3450 case LPFC_LINK_SPEED_8GHZ:
3451 case LPFC_LINK_SPEED_10GHZ:
3452 case LPFC_LINK_SPEED_16GHZ:
3453 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003454 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003455 case LPFC_LINK_SPEED_128GHZ:
James Smartbfc47782021-07-22 15:17:19 -07003456 case LPFC_LINK_SPEED_256GHZ:
James Smarta085e872015-12-16 18:12:02 -05003457 break;
3458 default:
3459 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3460 break;
3461 }
dea31012005-04-17 16:05:31 -05003462 }
3463
James Smarte74c03c2013-04-17 20:15:19 -04003464 if (phba->fc_topology &&
3465 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3466 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3467 "3314 Toplogy changed was 0x%x is 0x%x\n",
3468 phba->fc_topology,
3469 bf_get(lpfc_mbx_read_top_topology, la));
3470 phba->fc_topology_changed = 1;
3471 }
3472
James Smart76a95d72010-11-20 23:11:48 -05003473 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart8aaa7bc2020-10-20 13:27:17 -07003474 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
dea31012005-04-17 16:05:31 -05003475
James Smartdf9e1b52011-12-13 13:22:17 -05003476 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003477 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003478 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003479
James Smart6a9c52c2009-10-02 15:16:51 -04003480 /* if npiv is enabled and this adapter supports npiv log
3481 * a message that npiv is not supported in this topology
3482 */
3483 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003484 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3485 "1309 Link Up Event npiv not supported in loop "
3486 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003487 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003488 if (bf_get(lpfc_mbx_read_top_il, la))
3489 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003490
James Smart76a95d72010-11-20 23:11:48 -05003491 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3492 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003493
3494 if (i == 0) {
3495 phba->alpa_map[0] = 0;
3496 } else {
James Smarte8b62012007-08-02 11:10:09 -04003497 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003498 int numalpa, j, k;
3499 union {
3500 uint8_t pamap[16];
3501 struct {
3502 uint32_t wd1;
3503 uint32_t wd2;
3504 uint32_t wd3;
3505 uint32_t wd4;
3506 } pa;
3507 } un;
3508 numalpa = phba->alpa_map[0];
3509 j = 0;
3510 while (j < numalpa) {
3511 memset(un.pamap, 0, 16);
3512 for (k = 1; j < numalpa; k++) {
3513 un.pamap[k - 1] =
3514 phba->alpa_map[j + 1];
3515 j++;
3516 if (k == 16)
3517 break;
3518 }
3519 /* Link Up Event ALPA map */
3520 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003521 KERN_WARNING,
3522 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003523 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003524 "ALPA map Data: x%x "
3525 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003526 un.pa.wd1, un.pa.wd2,
3527 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003528 }
3529 }
3530 }
3531 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003532 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003533 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003534 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003535 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3536 }
James Smart2e0fef82007-06-17 19:56:36 -05003537 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003538 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003539 }
James Smart894bb172019-08-14 16:56:52 -07003540 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003541
James Smart38c20672013-03-01 16:37:44 -05003542 if (fc_flags) {
James Smart894bb172019-08-14 16:56:52 -07003543 spin_lock_irqsave(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003544 vport->fc_flag |= fc_flags;
James Smart894bb172019-08-14 16:56:52 -07003545 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003546 }
3547
dea31012005-04-17 16:05:31 -05003548 lpfc_linkup(phba);
James Smart835214f2020-01-27 16:23:03 -08003549 sparam_mbox = NULL;
3550
James Smart9f1177a2010-02-26 14:12:57 -05003551 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3552 if (!sparam_mbox)
3553 goto out;
3554
3555 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3556 if (rc) {
3557 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3558 goto out;
3559 }
3560 sparam_mbox->vport = vport;
3561 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3562 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3563 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003564 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003565 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3566 kfree(mp);
3567 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3568 goto out;
dea31012005-04-17 16:05:31 -05003569 }
3570
James Smart7f048392020-09-11 13:01:47 -07003571 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3572 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3573 if (!cfglink_mbox)
3574 goto out;
3575 vport->port_state = LPFC_LOCAL_CFG_LINK;
3576 lpfc_config_link(phba, cfglink_mbox);
3577 cfglink_mbox->vport = vport;
3578 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3579 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3580 if (rc == MBX_NOT_FINISHED) {
3581 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3582 goto out;
3583 }
3584 } else {
James Smart32b97932009-07-19 10:01:21 -04003585 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003586 /*
3587 * Add the driver's default FCF record at FCF index 0 now. This
3588 * is phase 1 implementation that support FCF index 0 and driver
3589 * defaults.
3590 */
James Smart45ed1192009-10-02 15:17:02 -04003591 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003592 fcf_record = kzalloc(sizeof(struct fcf_record),
3593 GFP_KERNEL);
3594 if (unlikely(!fcf_record)) {
3595 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003596 LOG_TRACE_EVENT,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003597 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003598 "fcf record\n");
3599 rc = -ENODEV;
3600 goto out;
3601 }
3602
3603 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3604 LPFC_FCOE_FCF_DEF_INDEX);
3605 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3606 if (unlikely(rc)) {
3607 lpfc_printf_log(phba, KERN_ERR,
Dick Kennedy372c1872020-06-30 14:50:00 -07003608 LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04003609 "2013 Could not manually add FCF "
3610 "record 0, status %d\n", rc);
3611 rc = -ENODEV;
3612 kfree(fcf_record);
3613 goto out;
3614 }
3615 kfree(fcf_record);
3616 }
3617 /*
3618 * The driver is expected to do FIP/FCF. Call the port
3619 * and get the FCF Table.
3620 */
James Smart894bb172019-08-14 16:56:52 -07003621 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta93ff372010-10-22 11:06:08 -04003622 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart894bb172019-08-14 16:56:52 -07003623 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart32b97932009-07-19 10:01:21 -04003624 return;
3625 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003626 /* This is the initial FCF discovery scan */
3627 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003628 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003629 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3630 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003631 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3632 LPFC_FCOE_FCF_GET_FIRST);
3633 if (rc) {
James Smart894bb172019-08-14 16:56:52 -07003634 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003635 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003636 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6fb120a2009-05-22 14:52:59 -04003637 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003638 }
James Smart38b92ef2010-08-04 16:11:39 -04003639 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003640 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003641 }
James Smart6fb120a2009-05-22 14:52:59 -04003642
James Smarte3ba04c2019-12-18 15:58:02 -08003643 /* Prepare for LINK up registrations */
3644 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3645 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3646 init_utsname()->nodename);
James Smart6fb120a2009-05-22 14:52:59 -04003647 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003648out:
3649 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
Dick Kennedy372c1872020-06-30 14:50:00 -07003650 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart32350662019-08-14 16:57:06 -07003651 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04003652 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003653 lpfc_issue_clear_la(phba, vport);
3654 return;
dea31012005-04-17 16:05:31 -05003655}
3656
3657static void
James Smart84774a42008-08-24 21:50:06 -04003658lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003659{
dea31012005-04-17 16:05:31 -05003660 uint32_t control;
3661 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003662 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003663 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003664 if (phba->sli_rev <= LPFC_SLI_REV3) {
3665 control = readl(phba->HCregaddr);
3666 control |= HC_LAINT_ENA;
3667 writel(control, phba->HCregaddr);
3668 readl(phba->HCregaddr); /* flush */
3669 }
James Smart2e0fef82007-06-17 19:56:36 -05003670 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003671}
3672
James Smart84774a42008-08-24 21:50:06 -04003673static void
3674lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3675{
3676 lpfc_linkdown(phba);
3677 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003678 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003679 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3680}
3681
3682
dea31012005-04-17 16:05:31 -05003683/*
James Smart76a95d72010-11-20 23:11:48 -05003684 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003685 * command upon completion. It is setup in the LPFC_MBOXQ
3686 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003687 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003688 */
3689void
James Smart76a95d72010-11-20 23:11:48 -05003690lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003691{
James Smart2e0fef82007-06-17 19:56:36 -05003692 struct lpfc_vport *vport = pmb->vport;
3693 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003694 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003695 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003696 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003697 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003698 uint8_t attn_type;
James Smart894bb172019-08-14 16:56:52 -07003699 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003700
James Smart0d2b6b82008-06-14 22:52:47 -04003701 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003702 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003703 if (pring)
3704 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003705
dea31012005-04-17 16:05:31 -05003706 /* Check for error */
3707 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003708 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003709 "1307 READ_LA mbox error x%x state x%x\n",
3710 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003711 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003712 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003713 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003714 }
3715
James Smart76a95d72010-11-20 23:11:48 -05003716 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003717 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003718
3719 memcpy(&phba->alpa_map[0], mp->virt, 128);
3720
James Smart894bb172019-08-14 16:56:52 -07003721 spin_lock_irqsave(shost->host_lock, iflags);
James Smart76a95d72010-11-20 23:11:48 -05003722 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003723 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003724 else
James Smart2e0fef82007-06-17 19:56:36 -05003725 vport->fc_flag &= ~FC_BYPASSED_MODE;
James Smart894bb172019-08-14 16:56:52 -07003726 spin_unlock_irqrestore(shost->host_lock, iflags);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003727
James Smartbe0c0082013-03-01 16:38:14 -05003728 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003729 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003730 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003731 if (phba->fc_eventTag != 0)
3732 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003733 }
dea31012005-04-17 16:05:31 -05003734
3735 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003736 if (phba->sli_rev < LPFC_SLI_REV4) {
James Smart894bb172019-08-14 16:56:52 -07003737 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003738 if (bf_get(lpfc_mbx_read_top_mm, la))
3739 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3740 else
3741 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart894bb172019-08-14 16:56:52 -07003742 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003743 }
dea31012005-04-17 16:05:31 -05003744
James Smart4d9ab992009-10-02 15:16:39 -04003745 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003746 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003747 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003748 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003749 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003750 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003751 "1306 Link Up Event in loop back mode "
3752 "x%x received Data: x%x x%x x%x x%x\n",
3753 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003754 bf_get(lpfc_mbx_read_top_alpa_granted,
3755 la),
3756 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003757 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003758 } else {
3759 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003760 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003761 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003762 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003763 bf_get(lpfc_mbx_read_top_alpa_granted,
3764 la),
3765 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003766 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003767 bf_get(lpfc_mbx_read_top_mm, la),
3768 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003769 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003770 }
James Smart92d7f7b2007-06-17 19:56:38 -05003771 lpfc_mbx_process_link_up(phba, la);
James Smart02243832021-08-16 09:28:54 -07003772
3773 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3774 lpfc_cmf_signal_init(phba);
3775
James Smartaeb3c812017-04-21 16:05:02 -07003776 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3777 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003778 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003779 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003780 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3781 "1308 Link Down Event in loop back mode "
3782 "x%x received "
3783 "Data: x%x x%x x%x\n",
3784 la->eventTag, phba->fc_eventTag,
3785 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003786 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3787 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smartb9da8142019-11-04 16:57:04 -08003788 "1313 Link Down Unexpected FA WWPN Event x%x "
3789 "received Data: x%x x%x x%x x%x x%x\n",
James Smartaeb3c812017-04-21 16:05:02 -07003790 la->eventTag, phba->fc_eventTag,
3791 phba->pport->port_state, vport->fc_flag,
3792 bf_get(lpfc_mbx_read_top_mm, la),
3793 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003794 else
James Smart3163f722008-02-08 18:50:25 -05003795 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003796 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003797 "Data: x%x x%x x%x x%x x%x\n",
3798 la->eventTag, phba->fc_eventTag,
3799 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003800 bf_get(lpfc_mbx_read_top_mm, la),
3801 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003802 lpfc_mbx_issue_link_down(phba);
3803 }
James Smartaeb3c812017-04-21 16:05:02 -07003804 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3805 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003806 if (phba->link_state != LPFC_LINK_DOWN) {
3807 phba->fc_stat.LinkDown++;
3808 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3809 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003810 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003811 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003812 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003813 lpfc_mbx_issue_link_down(phba);
3814 } else
3815 lpfc_enable_la(phba);
3816
3817 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3818 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3819 "Data: x%x x%x x%x\n",
3820 la->eventTag, phba->fc_eventTag,
3821 phba->pport->port_state, vport->fc_flag);
3822 /*
3823 * The cmnd that triggered this will be waiting for this
3824 * signal.
3825 */
3826 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3827 if (phba->wait_4_mlo_maint_flg) {
3828 phba->wait_4_mlo_maint_flg = 0;
3829 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003830 }
James Smart84774a42008-08-24 21:50:06 -04003831 }
3832
James Smartbe0c0082013-03-01 16:38:14 -05003833 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3834 bf_get(lpfc_mbx_read_top_fa, la)) {
3835 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003836 lpfc_issue_clear_la(phba, vport);
3837 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003838 "1311 fa %d\n",
3839 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003840 }
3841
James Smart76a95d72010-11-20 23:11:48 -05003842lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003843 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3844 kfree(mp);
3845 mempool_free(pmb, phba->mbox_mem_pool);
3846 return;
3847}
3848
3849/*
3850 * This routine handles processing a REG_LOGIN mailbox
3851 * command upon completion. It is setup in the LPFC_MBOXQ
3852 * as the completion routine when the command is
3853 * handed off to the SLI layer.
3854 */
3855void
James Smart2e0fef82007-06-17 19:56:36 -05003856lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003857{
James Smart2e0fef82007-06-17 19:56:36 -05003858 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003859 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3860 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
dea31012005-04-17 16:05:31 -05003861
James Smart3e1f0712018-11-29 16:09:29 -08003862 pmb->ctx_buf = NULL;
3863 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003864
James Smart52edb2c2020-11-15 11:26:35 -08003865 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08003866 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04003867 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003868 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08003869 ndlp);
James Smartffc95492010-06-07 15:23:17 -04003870 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3871 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3872
James Smart40426292010-12-15 17:58:10 -05003873 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3874 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003875 /* We rcvd a rscn after issuing this
3876 * mbox reg login, we may have cycled
3877 * back through the state and be
3878 * back at reg login state so this
3879 * mbox needs to be ignored becase
3880 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003881 * process.
James Smartffc95492010-06-07 15:23:17 -04003882 */
James Smartc6adba12020-11-15 11:26:34 -08003883 spin_lock_irq(&ndlp->lock);
James Smartffc95492010-06-07 15:23:17 -04003884 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
James Smartc6adba12020-11-15 11:26:34 -08003885 spin_unlock_irq(&ndlp->lock);
James Smart895427b2017-02-12 13:52:30 -08003886
3887 /*
3888 * We cannot leave the RPI registered because
3889 * if we go thru discovery again for this ndlp
3890 * a subsequent REG_RPI will fail.
3891 */
3892 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3893 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003894 }
3895
3896 /* Call state machine */
3897 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003898
dea31012005-04-17 16:05:31 -05003899 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3900 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003901 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003902 /* decrement the node reference count held for this callback
3903 * function.
3904 */
James Smart329f9bc2007-04-25 09:53:01 -04003905 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003906
3907 return;
3908}
3909
James Smart92d7f7b2007-06-17 19:56:38 -05003910static void
3911lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3912{
James Smart04c68492009-05-22 14:52:52 -04003913 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003914 struct lpfc_vport *vport = pmb->vport;
3915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3916
3917 switch (mb->mbxStatus) {
3918 case 0x0011:
3919 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003920 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3921 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3922 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003923 break;
James Smart78730cf2010-04-06 15:06:30 -04003924 /* If VPI is busy, reset the HBA */
3925 case 0x9700:
Dick Kennedy372c1872020-06-30 14:50:00 -07003926 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart78730cf2010-04-06 15:06:30 -04003927 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3928 vport->vpi, mb->mbxStatus);
3929 if (!(phba->pport->load_flag & FC_UNLOADING))
3930 lpfc_workq_post_event(phba, NULL, NULL,
3931 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003932 }
James Smart72100cc2010-02-12 14:43:01 -05003933 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003934 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003935 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003936 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003937 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003938 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003939 /*
3940 * This shost reference might have been taken at the beginning of
3941 * lpfc_vport_delete()
3942 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003943 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003944 scsi_host_put(shost);
3945}
3946
James Smartd7c255b2008-08-24 21:50:00 -04003947int
James Smart92d7f7b2007-06-17 19:56:38 -05003948lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3949{
3950 struct lpfc_hba *phba = vport->phba;
3951 LPFC_MBOXQ_t *mbox;
3952 int rc;
3953
3954 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3955 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003956 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003957
3958 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3959 mbox->vport = vport;
3960 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003961 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003962 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07003963 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003964 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003965 mempool_free(mbox, phba->mbox_mem_pool);
James Smartd7c255b2008-08-24 21:50:00 -04003966 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003967 }
James Smartd7c255b2008-08-24 21:50:00 -04003968 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003969}
3970
3971static void
3972lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3973{
3974 struct lpfc_vport *vport = pmb->vport;
3975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003976 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003977
3978 switch (mb->mbxStatus) {
3979 case 0x0011:
3980 case 0x9601:
3981 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003982 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3983 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3984 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003985 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3986 spin_lock_irq(shost->host_lock);
3987 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3988 spin_unlock_irq(shost->host_lock);
3989 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003990
James Smartf6e84792019-01-28 11:14:38 -08003991 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3992 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003993 if (phba->nvmet_support)
3994 lpfc_nvmet_update_targetport(phba);
3995 else
James Smart8c258642017-02-12 13:52:36 -08003996 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003997 }
James Smart92d7f7b2007-06-17 19:56:38 -05003998 goto out;
3999 }
James Smart92d7f7b2007-06-17 19:56:38 -05004000
James Smart72100cc2010-02-12 14:43:01 -05004001 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05004002 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05004003 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05004004 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004005 vport->num_disc_nodes = 0;
4006 /* go thru NPR list and issue ELS PLOGIs */
4007 if (vport->fc_npr_cnt)
4008 lpfc_els_disc_plogi(vport);
4009
4010 if (!vport->num_disc_nodes) {
4011 spin_lock_irq(shost->host_lock);
4012 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4013 spin_unlock_irq(shost->host_lock);
4014 lpfc_can_disctmo(vport);
4015 }
4016 vport->port_state = LPFC_VPORT_READY;
4017
4018out:
4019 mempool_free(pmb, phba->mbox_mem_pool);
4020 return;
4021}
4022
James Smart21e9a0a2009-05-22 14:53:21 -04004023/**
4024 * lpfc_create_static_vport - Read HBA config region to create static vports.
4025 * @phba: pointer to lpfc hba data structure.
4026 *
4027 * This routine issue a DUMP mailbox command for config region 22 to get
4028 * the list of static vports to be created. The function create vports
4029 * based on the information returned from the HBA.
4030 **/
4031void
4032lpfc_create_static_vport(struct lpfc_hba *phba)
4033{
4034 LPFC_MBOXQ_t *pmb = NULL;
4035 MAILBOX_t *mb;
4036 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04004037 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04004038 struct fc_vport_identifiers vport_id;
4039 struct fc_vport *new_fc_vport;
4040 struct Scsi_Host *shost;
4041 struct lpfc_vport *vport;
4042 uint16_t offset = 0;
4043 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04004044 struct lpfc_dmabuf *mp;
4045 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04004046
4047 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4048 if (!pmb) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004049 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004050 "0542 lpfc_create_static_vport failed to"
4051 " allocate mailbox memory\n");
4052 return;
4053 }
James Smartcdcc2342012-08-14 14:26:35 -04004054 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04004055 mb = &pmb->u.mb;
4056
4057 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4058 if (!vport_info) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004059 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004060 "0543 lpfc_create_static_vport failed to"
4061 " allocate vport_info\n");
4062 mempool_free(pmb, phba->mbox_mem_pool);
4063 return;
4064 }
4065
4066 vport_buff = (uint8_t *) vport_info;
4067 do {
James Smartcdcc2342012-08-14 14:26:35 -04004068 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08004069 if (pmb->ctx_buf) {
4070 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04004071 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4072 kfree(mp);
4073 }
James Smart1c6834a2009-07-19 10:01:26 -04004074 if (lpfc_dump_static_vport(phba, pmb, offset))
4075 goto out;
4076
James Smart21e9a0a2009-05-22 14:53:21 -04004077 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04004078 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4079 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04004080
James Smartcdcc2342012-08-14 14:26:35 -04004081 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04004082 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4083 "0544 lpfc_create_static_vport failed to"
4084 " issue dump mailbox command ret 0x%x "
4085 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04004086 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04004087 goto out;
4088 }
4089
James Smart1c6834a2009-07-19 10:01:26 -04004090 if (phba->sli_rev == LPFC_SLI_REV4) {
4091 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08004092 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04004093 if (byte_count > sizeof(struct static_vport_info) -
4094 offset)
4095 byte_count = sizeof(struct static_vport_info)
4096 - offset;
4097 memcpy(vport_buff + offset, mp->virt, byte_count);
4098 offset += byte_count;
4099 } else {
4100 if (mb->un.varDmp.word_cnt >
4101 sizeof(struct static_vport_info) - offset)
4102 mb->un.varDmp.word_cnt =
4103 sizeof(struct static_vport_info)
4104 - offset;
4105 byte_count = mb->un.varDmp.word_cnt;
4106 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4107 vport_buff + offset,
4108 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04004109
James Smart1c6834a2009-07-19 10:01:26 -04004110 offset += byte_count;
4111 }
James Smart21e9a0a2009-05-22 14:53:21 -04004112
James Smart1c6834a2009-07-19 10:01:26 -04004113 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04004114 offset < sizeof(struct static_vport_info));
4115
4116
4117 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4118 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4119 != VPORT_INFO_REV)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004120 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4121 "0545 lpfc_create_static_vport bad"
4122 " information header 0x%x 0x%x\n",
4123 le32_to_cpu(vport_info->signature),
4124 le32_to_cpu(vport_info->rev) &
4125 VPORT_INFO_REV_MASK);
James Smart21e9a0a2009-05-22 14:53:21 -04004126
4127 goto out;
4128 }
4129
4130 shost = lpfc_shost_from_vport(phba->pport);
4131
4132 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4133 memset(&vport_id, 0, sizeof(vport_id));
4134 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4135 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4136 if (!vport_id.port_name || !vport_id.node_name)
4137 continue;
4138
4139 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4140 vport_id.vport_type = FC_PORTTYPE_NPIV;
4141 vport_id.disable = false;
4142 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4143
4144 if (!new_fc_vport) {
4145 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4146 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04004147 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04004148 continue;
4149 }
4150
4151 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4152 vport->vport_flag |= STATIC_VPORT;
4153 }
4154
4155out:
James Smart21e9a0a2009-05-22 14:53:21 -04004156 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04004157 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08004158 if (pmb->ctx_buf) {
4159 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04004160 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4161 kfree(mp);
4162 }
James Smart21e9a0a2009-05-22 14:53:21 -04004163 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04004164 }
James Smart21e9a0a2009-05-22 14:53:21 -04004165
4166 return;
4167}
4168
dea31012005-04-17 16:05:31 -05004169/*
4170 * This routine handles processing a Fabric REG_LOGIN mailbox
4171 * command upon completion. It is setup in the LPFC_MBOXQ
4172 * as the completion routine when the command is
4173 * handed off to the SLI layer.
4174 */
4175void
James Smart2e0fef82007-06-17 19:56:36 -05004176lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004177{
James Smart92d7f7b2007-06-17 19:56:38 -05004178 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04004179 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004180 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05004181 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05004182 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05004183
James Smart3e1f0712018-11-29 16:09:29 -08004184 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4185 pmb->ctx_ndlp = NULL;
4186 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04004187
dea31012005-04-17 16:05:31 -05004188 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004189 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004190 "0258 Register Fabric login error: 0x%x\n",
4191 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05004192 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4193 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04004194 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004195
James Smart76a95d72010-11-20 23:11:48 -05004196 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004197 /* FLOGI failed, use loop map to make discovery list */
4198 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004199
James Smart92d7f7b2007-06-17 19:56:38 -05004200 /* Start discovery */
4201 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05004202 /* Decrement the reference count to ndlp after the
4203 * reference to the ndlp are done.
4204 */
4205 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004206 return;
4207 }
4208
4209 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05004210 /* Decrement the reference count to ndlp after the reference
4211 * to the ndlp are done.
4212 */
4213 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004214 return;
4215 }
4216
James Smart6d368e52011-05-24 11:44:12 -04004217 if (phba->sli_rev < LPFC_SLI_REV4)
4218 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004219 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004220 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004221 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004222
James Smart2e0fef82007-06-17 19:56:36 -05004223 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04004224 /* when physical port receive logo donot start
4225 * vport discovery */
4226 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4227 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05004228 else {
4229 shost = lpfc_shost_from_vport(vport);
4230 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04004231 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05004232 spin_unlock_irq(shost->host_lock);
4233 }
James Smart92d7f7b2007-06-17 19:56:38 -05004234 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05004235 }
4236
4237 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4238 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04004239 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05004240
4241 /* Drop the reference count from the mbox at the end after
4242 * all the current reference to the ndlp have been done.
4243 */
4244 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004245 return;
4246}
4247
James Smarta0f2d3e2017-02-12 13:52:31 -08004248 /*
4249 * This routine will issue a GID_FT for each FC4 Type supported
4250 * by the driver. ALL GID_FTs must complete before discovery is started.
4251 */
4252int
4253lpfc_issue_gidft(struct lpfc_vport *vport)
4254{
James Smarta0f2d3e2017-02-12 13:52:31 -08004255 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08004256 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4257 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004258 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4259 /* Cannot issue NameServer FCP Query, so finish up
4260 * discovery
4261 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004262 lpfc_printf_vlog(vport, KERN_ERR,
4263 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08004264 "0604 %s FC TYPE %x %s\n",
4265 "Failed to issue GID_FT to ",
4266 FC_TYPE_FCP,
4267 "Finishing discovery.");
4268 return 0;
4269 }
4270 vport->gidft_inp++;
4271 }
4272
James Smartf6e84792019-01-28 11:14:38 -08004273 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4274 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004275 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4276 /* Cannot issue NameServer NVME Query, so finish up
4277 * discovery
4278 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004279 lpfc_printf_vlog(vport, KERN_ERR,
4280 LOG_TRACE_EVENT,
James Smarta0f2d3e2017-02-12 13:52:31 -08004281 "0605 %s FC_TYPE %x %s %d\n",
4282 "Failed to issue GID_FT to ",
4283 FC_TYPE_NVME,
4284 "Finishing discovery: gidftinp ",
4285 vport->gidft_inp);
4286 if (vport->gidft_inp == 0)
4287 return 0;
4288 } else
4289 vport->gidft_inp++;
4290 }
4291 return vport->gidft_inp;
4292}
4293
James Smart7ea92eb2018-10-23 13:41:10 -07004294/**
4295 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4296 * @vport: The virtual port for which this call is being executed.
4297 *
4298 * This routine will issue a GID_PT to get a list of all N_Ports
4299 *
4300 * Return value :
4301 * 0 - Failure to issue a GID_PT
4302 * 1 - GID_PT issued
4303 **/
4304int
4305lpfc_issue_gidpt(struct lpfc_vport *vport)
4306{
4307 /* Good status, issue CT Request to NameServer */
4308 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4309 /* Cannot issue NameServer FCP Query, so finish up
4310 * discovery
4311 */
Dick Kennedy372c1872020-06-30 14:50:00 -07004312 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart7ea92eb2018-10-23 13:41:10 -07004313 "0606 %s Port TYPE %x %s\n",
4314 "Failed to issue GID_PT to ",
4315 GID_PT_N_PORT,
4316 "Finishing discovery.");
4317 return 0;
4318 }
4319 vport->gidft_inp++;
4320 return 1;
4321}
4322
dea31012005-04-17 16:05:31 -05004323/*
4324 * This routine handles processing a NameServer REG_LOGIN mailbox
4325 * command upon completion. It is setup in the LPFC_MBOXQ
4326 * as the completion routine when the command is
4327 * handed off to the SLI layer.
4328 */
4329void
James Smart2e0fef82007-06-17 19:56:36 -05004330lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004331{
James Smart21e9a0a2009-05-22 14:53:21 -04004332 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004333 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4334 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004335 struct lpfc_vport *vport = pmb->vport;
James Smart9064aeb2021-08-16 09:28:50 -07004336 int rc;
dea31012005-04-17 16:05:31 -05004337
James Smart3e1f0712018-11-29 16:09:29 -08004338 pmb->ctx_buf = NULL;
4339 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004340 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004341
dea31012005-04-17 16:05:31 -05004342 if (mb->mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07004343 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smart21e9a0a2009-05-22 14:53:21 -04004344 "0260 Register NameServer error: 0x%x\n",
4345 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004346
4347out:
James Smartfa4066b2008-01-11 01:53:27 -05004348 /* decrement the node reference count held for this
4349 * callback function.
4350 */
James Smart329f9bc2007-04-25 09:53:01 -04004351 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004352 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4353 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004354 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004355
James Smart52edb2c2020-11-15 11:26:35 -08004356 /* If the node is not registered with the scsi or nvme
4357 * transport, remove the fabric node. The failed reg_login
4358 * is terminal.
4359 */
4360 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4361 spin_lock_irq(&ndlp->lock);
4362 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4363 spin_unlock_irq(&ndlp->lock);
4364 lpfc_nlp_not_used(ndlp);
4365 }
dea31012005-04-17 16:05:31 -05004366
James Smart76a95d72010-11-20 23:11:48 -05004367 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004368 /*
4369 * RegLogin failed, use loop map to make discovery
4370 * list
4371 */
4372 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004373
James Smart92d7f7b2007-06-17 19:56:38 -05004374 /* Start discovery */
4375 lpfc_disc_start(vport);
4376 return;
4377 }
4378 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004379 return;
4380 }
4381
James Smart6d368e52011-05-24 11:44:12 -04004382 if (phba->sli_rev < LPFC_SLI_REV4)
4383 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004384 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004385 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004386 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07004387 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08004388 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004389 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004390 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08004391 ndlp);
dea31012005-04-17 16:05:31 -05004392
James Smart2e0fef82007-06-17 19:56:36 -05004393 if (vport->port_state < LPFC_VPORT_READY) {
4394 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004395 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4396 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4397 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4398 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004399
James Smartf6e84792019-01-28 11:14:38 -08004400 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4401 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004402 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4403
James Smartf6e84792019-01-28 11:14:38 -08004404 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4405 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08004406 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4407 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004408
4409 /* Issue SCR just before NameServer GID_FT Query */
James Smartdf3fe762020-02-10 09:31:55 -08004410 lpfc_issue_els_scr(vport, 0);
4411
James Smart9064aeb2021-08-16 09:28:50 -07004412 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4413 * with initial FW values provided the congestion mode is
4414 * not off. Note that signals may or may not be supported
4415 * by the adapter but FPIN is provided by default for 1
4416 * or both missing signals support.
4417 */
4418 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4419 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4420 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4421 rc = lpfc_issue_els_edc(vport, 0);
4422 lpfc_printf_log(phba, KERN_INFO,
4423 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4424 "4220 EDC issue error x%x, Data: x%x\n",
4425 rc, phba->cgn_init_reg_signal);
4426 } else {
James Smart8aaa7bc2020-10-20 13:27:17 -07004427 lpfc_issue_els_rdf(vport, 0);
James Smart9064aeb2021-08-16 09:28:50 -07004428 }
dea31012005-04-17 16:05:31 -05004429 }
4430
James Smart2e0fef82007-06-17 19:56:36 -05004431 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004432 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004433 goto out;
dea31012005-04-17 16:05:31 -05004434
James Smarta0f2d3e2017-02-12 13:52:31 -08004435 /*
4436 * At this point in time we may need to wait for multiple
4437 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4438 *
4439 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004440 * callback function.
4441 */
James Smart329f9bc2007-04-25 09:53:01 -04004442 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4444 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004445 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004446
4447 return;
4448}
4449
James Smartfe83e3b2021-05-14 12:55:54 -07004450/*
4451 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4452 * command upon completion. It is setup in the LPFC_MBOXQ
4453 * as the completion routine when the command is handed off to the SLI layer.
4454 */
4455void
4456lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4457{
4458 struct lpfc_vport *vport = pmb->vport;
4459 MAILBOX_t *mb = &pmb->u.mb;
4460 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4461 struct lpfc_nodelist *ndlp;
4462
4463 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4464 pmb->ctx_ndlp = NULL;
4465 pmb->ctx_buf = NULL;
4466
4467 if (mb->mbxStatus) {
4468 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4469 "0933 %s: Register FC login error: 0x%x\n",
4470 __func__, mb->mbxStatus);
4471 goto out;
4472 }
4473
James Smartaf984c82021-10-20 14:14:16 -07004474 lpfc_check_nlp_post_devloss(vport, ndlp);
4475
James Smartfe83e3b2021-05-14 12:55:54 -07004476 if (phba->sli_rev < LPFC_SLI_REV4)
4477 ndlp->nlp_rpi = mb->un.varWords[0];
4478
4479 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4480 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4481 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4482 ndlp->nlp_state);
4483
4484 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
James Smart79b20be2021-10-20 14:14:13 -07004485 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smartfe83e3b2021-05-14 12:55:54 -07004486 ndlp->nlp_type |= NLP_FABRIC;
4487 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4488
4489 out:
4490 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4491 kfree(mp);
4492 mempool_free(pmb, phba->mbox_mem_pool);
4493
4494 /* Drop the reference count from the mbox at the end after
4495 * all the current reference to the ndlp have been done.
4496 */
4497 lpfc_nlp_put(ndlp);
4498}
4499
dea31012005-04-17 16:05:31 -05004500static void
James Smart2e0fef82007-06-17 19:56:36 -05004501lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004502{
James Smart2e0fef82007-06-17 19:56:36 -05004503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4504 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004505 struct lpfc_rport_data *rdata;
4506 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004507 struct lpfc_hba *phba = vport->phba;
James Smartc6adba12020-11-15 11:26:34 -08004508 unsigned long flags;
dea31012005-04-17 16:05:31 -05004509
James Smartf6e84792019-01-28 11:14:38 -08004510 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004511 return;
4512
dea31012005-04-17 16:05:31 -05004513 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004514 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4515 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004516 rport_ids.port_id = ndlp->nlp_DID;
4517 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004518
James Smart858c9f62007-06-17 19:56:39 -05004519
4520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smartc6adba12020-11-15 11:26:34 -08004521 "rport add: did:x%x flg:x%x type x%x",
4522 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
James Smart858c9f62007-06-17 19:56:39 -05004523
James Smart9589b0622011-04-16 11:03:17 -04004524 /* Don't add the remote port if unloading. */
4525 if (vport->load_flag & FC_UNLOADING)
4526 return;
4527
James Smartc6adba12020-11-15 11:26:34 -08004528 /*
4529 * Disassociate any older association between this ndlp and rport
4530 */
4531 if (ndlp->rport) {
4532 rdata = ndlp->rport->dd_data;
4533 rdata->pnode = NULL;
4534 }
4535
James Smart2e0fef82007-06-17 19:56:36 -05004536 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart95f0ef82020-11-15 11:26:32 -08004537 if (!rport) {
dea31012005-04-17 16:05:31 -05004538 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4539 "Warning: fc_remote_port_add failed\n");
4540 return;
4541 }
4542
James Smartc6adba12020-11-15 11:26:34 -08004543 /* Successful port add. Complete initializing node data */
dea31012005-04-17 16:05:31 -05004544 rport->maxframe_size = ndlp->nlp_maxframe;
4545 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004546 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004547 rdata->pnode = lpfc_nlp_get(ndlp);
James Smart4430f7f2020-11-15 11:26:31 -08004548 if (!rdata->pnode) {
4549 dev_warn(&phba->pcidev->dev,
4550 "Warning - node ref failed. Unreg rport\n");
4551 fc_remote_port_delete(rport);
4552 ndlp->rport = NULL;
4553 return;
4554 }
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004555
James Smartc6adba12020-11-15 11:26:34 -08004556 spin_lock_irqsave(&ndlp->lock, flags);
4557 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4558 spin_unlock_irqrestore(&ndlp->lock, flags);
4559
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004560 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004561 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004562 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004563 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4564 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4565 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4566 if (ndlp->nlp_type & NLP_NVME_TARGET)
4567 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4568 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4569 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004570
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004571 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4572 fc_remote_port_rolechg(rport, rport_ids.roles);
4573
James Smart34f5ad82012-08-03 12:35:03 -04004574 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart982fc392021-09-10 16:31:47 -07004575 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4576 __func__, rport, rport->port_id, rport->roles,
4577 kref_read(&ndlp->kref));
James Smart34f5ad82012-08-03 12:35:03 -04004578
James Smart071fbd3d2006-04-15 11:53:20 -04004579 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004580 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004581 ndlp->nlp_sid = rport->scsi_target_id;
4582 }
James Smart95f0ef82020-11-15 11:26:32 -08004583
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004584 return;
4585}
4586
4587static void
James Smart2e0fef82007-06-17 19:56:36 -05004588lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004589{
4590 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004591 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004592
James Smartf6e84792019-01-28 11:14:38 -08004593 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004594 return;
James Smartc01f3202006-08-18 17:47:08 -04004595
James Smart2ea259e2017-02-12 13:52:27 -08004596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004597 "rport delete: did:x%x flg:x%x type x%x",
4598 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4599
James Smart2ea259e2017-02-12 13:52:27 -08004600 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smartc6adba12020-11-15 11:26:34 -08004601 "3184 rport unregister x%06x, rport x%px "
James Smart982fc392021-09-10 16:31:47 -07004602 "xptflg x%x refcnt %d\n",
4603 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4604 kref_read(&ndlp->kref));
James Smart34f5ad82012-08-03 12:35:03 -04004605
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004606 fc_remote_port_delete(rport);
James Smartc6adba12020-11-15 11:26:34 -08004607 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004608}
4609
James Smartde0c5b32007-04-25 09:52:27 -04004610static void
James Smart2e0fef82007-06-17 19:56:36 -05004611lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004612{
James Smart2e0fef82007-06-17 19:56:36 -05004613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -07004614 unsigned long iflags;
James Smart2e0fef82007-06-17 19:56:36 -05004615
James Smart894bb172019-08-14 16:56:52 -07004616 spin_lock_irqsave(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004617 switch (state) {
4618 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004619 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004620 break;
4621 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004622 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004623 break;
4624 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004625 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004626 break;
4627 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004628 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004629 break;
4630 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004631 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004632 break;
4633 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004634 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004635 break;
4636 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004637 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004638 break;
4639 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004640 if (vport->fc_npr_cnt == 0 && count == -1)
4641 vport->fc_npr_cnt = 0;
4642 else
4643 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004644 break;
4645 }
James Smart894bb172019-08-14 16:56:52 -07004646 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004647}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004648
James Smart06145682021-07-07 11:43:46 -07004649/* Register a node with backend if not already done */
4650void
4651lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4652{
James Smart06145682021-07-07 11:43:46 -07004653 unsigned long iflags;
4654
James Smartaf984c82021-10-20 14:14:16 -07004655 lpfc_check_nlp_post_devloss(vport, ndlp);
4656
James Smart06145682021-07-07 11:43:46 -07004657 spin_lock_irqsave(&ndlp->lock, iflags);
4658 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4659 /* Already registered with backend, trigger rescan */
4660 spin_unlock_irqrestore(&ndlp->lock, iflags);
4661
4662 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4663 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4664 lpfc_nvme_rescan_port(vport, ndlp);
4665 }
4666 return;
4667 }
4668
4669 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4670 spin_unlock_irqrestore(&ndlp->lock, iflags);
4671
4672 if (lpfc_valid_xpt_node(ndlp)) {
4673 vport->phba->nport_event_cnt++;
4674 /*
4675 * Tell the fc transport about the port, if we haven't
4676 * already. If we have, and it's a scsi entity, be
4677 */
4678 lpfc_register_remote_port(vport, ndlp);
4679 }
4680
4681 /* We are done if we do not have any NVME remote node */
4682 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4683 return;
4684
4685 /* Notify the NVME transport of this new rport. */
4686 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4687 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4688 if (vport->phba->nvmet_support == 0) {
4689 /* Register this rport with the transport.
4690 * Only NVME Target Rports are registered with
4691 * the transport.
4692 */
4693 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4694 vport->phba->nport_event_cnt++;
4695 lpfc_nvme_register_port(vport, ndlp);
4696 }
4697 } else {
4698 /* Just take an NDLP ref count since the
4699 * target does not register rports.
4700 */
4701 lpfc_nlp_get(ndlp);
4702 }
4703 }
4704}
4705
4706/* Unregister a node with backend if not already done */
4707void
4708lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4709{
4710 unsigned long iflags;
4711
4712 spin_lock_irqsave(&ndlp->lock, iflags);
4713 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4714 spin_unlock_irqrestore(&ndlp->lock, iflags);
4715 return;
4716 }
4717
4718 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4719 spin_unlock_irqrestore(&ndlp->lock, iflags);
4720
4721 if (ndlp->rport &&
4722 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4723 vport->phba->nport_event_cnt++;
4724 lpfc_unregister_remote_port(ndlp);
4725 }
4726
4727 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4728 vport->phba->nport_event_cnt++;
4729 if (vport->phba->nvmet_support == 0) {
4730 /* Start devloss if target. */
4731 if (ndlp->nlp_type & NLP_NVME_TARGET)
4732 lpfc_nvme_unregister_port(vport, ndlp);
4733 } else {
4734 /* NVMET has no upcall. */
4735 lpfc_nlp_put(ndlp);
4736 }
4737 }
4738
4739}
4740
4741/*
4742 * Adisc state change handling
4743 */
4744static void
4745lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4746 int new_state)
4747{
4748 switch (new_state) {
4749 /*
4750 * Any state to ADISC_ISSUE
4751 * Do nothing, adisc cmpl handling will trigger state changes
4752 */
4753 case NLP_STE_ADISC_ISSUE:
4754 break;
4755
4756 /*
4757 * ADISC_ISSUE to mapped states
4758 * Trigger a registration with backend, it will be nop if
4759 * already registered
4760 */
4761 case NLP_STE_UNMAPPED_NODE:
4762 ndlp->nlp_type |= NLP_FC_NODE;
4763 fallthrough;
4764 case NLP_STE_MAPPED_NODE:
4765 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4766 lpfc_nlp_reg_node(vport, ndlp);
4767 break;
4768
4769 /*
4770 * ADISC_ISSUE to non-mapped states
4771 * We are moving from ADISC_ISSUE to a non-mapped state because
4772 * ADISC failed, we would have skipped unregistering with
4773 * backend, attempt it now
4774 */
4775 case NLP_STE_NPR_NODE:
4776 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4777 fallthrough;
4778 default:
4779 lpfc_nlp_unreg_node(vport, ndlp);
4780 break;
4781 }
4782
4783}
4784
James Smartde0c5b32007-04-25 09:52:27 -04004785static void
James Smart2e0fef82007-06-17 19:56:36 -05004786lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004787 int old_state, int new_state)
4788{
James Smart06145682021-07-07 11:43:46 -07004789 /* Trap ADISC changes here */
4790 if (new_state == NLP_STE_ADISC_ISSUE ||
4791 old_state == NLP_STE_ADISC_ISSUE) {
4792 lpfc_handle_adisc_state(vport, ndlp, new_state);
4793 return;
4794 }
4795
James Smartde0c5b32007-04-25 09:52:27 -04004796 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004797 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4798 ndlp->nlp_type |= NLP_FC_NODE;
4799 }
4800 if (new_state == NLP_STE_MAPPED_NODE)
4801 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4802 if (new_state == NLP_STE_NPR_NODE)
4803 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004804
James Smart06145682021-07-07 11:43:46 -07004805 /* Reg/Unreg for FCP and NVME Transport interface */
James Smarta0f2d3e2017-02-12 13:52:31 -08004806 if ((old_state == NLP_STE_MAPPED_NODE ||
4807 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart3a874482021-09-10 16:31:50 -07004808 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl
4809 * if linkup. In linkdown do unreg_node
4810 */
4811 if (!(ndlp->nlp_flag & NLP_NPR_ADISC) ||
4812 !lpfc_is_link_up(vport->phba))
James Smart06145682021-07-07 11:43:46 -07004813 lpfc_nlp_unreg_node(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004814 }
dea31012005-04-17 16:05:31 -05004815
James Smartde0c5b32007-04-25 09:52:27 -04004816 if (new_state == NLP_STE_MAPPED_NODE ||
James Smart06145682021-07-07 11:43:46 -07004817 new_state == NLP_STE_UNMAPPED_NODE)
4818 lpfc_nlp_reg_node(vport, ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004819
James Smartea2151b2008-09-07 11:52:10 -04004820 if ((new_state == NLP_STE_MAPPED_NODE) &&
4821 (vport->stat_data_enabled)) {
4822 /*
4823 * A new target is discovered, if there is no buffer for
4824 * statistical data collection allocate buffer.
4825 */
4826 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4827 sizeof(struct lpfc_scsicmd_bkt),
4828 GFP_KERNEL);
4829
4830 if (!ndlp->lat_data)
Dick Kennedy372c1872020-06-30 14:50:00 -07004831 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smartea2151b2008-09-07 11:52:10 -04004832 "0286 lpfc_nlp_state_cleanup failed to "
4833 "allocate statistical data buffer DID "
4834 "0x%x\n", ndlp->nlp_DID);
4835 }
James Smart858c9f62007-06-17 19:56:39 -05004836 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004837 * If the node just added to Mapped list was an FCP target,
4838 * but the remote port registration failed or assigned a target
4839 * id outside the presentable range - move the node to the
4840 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004841 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004842 if ((new_state == NLP_STE_MAPPED_NODE) &&
4843 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004844 (!ndlp->rport ||
4845 ndlp->rport->scsi_target_id == -1 ||
4846 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smartc6adba12020-11-15 11:26:34 -08004847 spin_lock_irq(&ndlp->lock);
James Smartde0c5b32007-04-25 09:52:27 -04004848 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smartc6adba12020-11-15 11:26:34 -08004849 spin_unlock_irq(&ndlp->lock);
James Smart2e0fef82007-06-17 19:56:36 -05004850 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004851 }
James Smartde0c5b32007-04-25 09:52:27 -04004852}
4853
James Smart685f0bf2007-04-25 09:53:08 -04004854static char *
4855lpfc_nlp_state_name(char *buffer, size_t size, int state)
4856{
4857 static char *states[] = {
4858 [NLP_STE_UNUSED_NODE] = "UNUSED",
4859 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4860 [NLP_STE_ADISC_ISSUE] = "ADISC",
4861 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4862 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004863 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004864 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4865 [NLP_STE_MAPPED_NODE] = "MAPPED",
4866 [NLP_STE_NPR_NODE] = "NPR",
4867 };
4868
James Smart311464e2007-08-02 11:10:37 -04004869 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004870 strlcpy(buffer, states[state], size);
4871 else
4872 snprintf(buffer, size, "unknown (%d)", state);
4873 return buffer;
4874}
4875
James Smartde0c5b32007-04-25 09:52:27 -04004876void
James Smart2e0fef82007-06-17 19:56:36 -05004877lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4878 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004879{
James Smart2e0fef82007-06-17 19:56:36 -05004880 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004881 int old_state = ndlp->nlp_state;
James Smart307e3382020-11-15 11:26:30 -08004882 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
James Smart685f0bf2007-04-25 09:53:08 -04004883 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004884
James Smarte8b62012007-08-02 11:10:09 -04004885 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4886 "0904 NPort state transition x%06x, %s -> %s\n",
4887 ndlp->nlp_DID,
4888 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4889 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004890
4891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4892 "node statechg did:x%x old:%d ste:%d",
4893 ndlp->nlp_DID, old_state, state);
4894
James Smart307e3382020-11-15 11:26:30 -08004895 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4896 state != NLP_STE_UNUSED_NODE) {
4897 ndlp->nlp_flag &= ~NLP_DROPPED;
4898 lpfc_nlp_get(ndlp);
4899 }
4900
James Smartde0c5b32007-04-25 09:52:27 -04004901 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004902 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004903 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004904 if (old_state == NLP_STE_UNMAPPED_NODE) {
4905 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4906 ndlp->nlp_type &= ~NLP_FC_NODE;
4907 }
4908
James Smart685f0bf2007-04-25 09:53:08 -04004909 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004910 spin_lock_irq(shost->host_lock);
4911 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4912 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004913 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004914 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004915
4916 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004917 lpfc_nlp_counters(vport, state, 1);
4918 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004919}
4920
4921void
James Smarte47c9092008-02-08 18:49:26 -05004922lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4923{
4924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4925
4926 if (list_empty(&ndlp->nlp_listp)) {
4927 spin_lock_irq(shost->host_lock);
4928 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4929 spin_unlock_irq(shost->host_lock);
4930 }
4931}
4932
4933void
James Smart2e0fef82007-06-17 19:56:36 -05004934lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004935{
James Smart2e0fef82007-06-17 19:56:36 -05004936 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4937
James Smart0d2b6b82008-06-14 22:52:47 -04004938 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004939 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004940 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4941 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004942 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004943 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004944 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004945 NLP_STE_UNUSED_NODE);
4946}
4947
James Smart109f6ed2008-12-04 22:39:08 -05004948/**
James Smart3621a712009-04-06 18:47:14 -04004949 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004950 * @vport: Pointer to Virtual Port object.
4951 * @ndlp: Pointer to FC node object.
4952 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004953 *
4954 * This function is always called when node object need to be initialized.
4955 * It initializes all the fields of the node object. Although the reference
4956 * to phba from @ndlp can be obtained indirectly through it's reference to
4957 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4958 * to the life-span of the @ndlp might go beyond the existence of @vport as
4959 * the final release of ndlp is determined by its reference count. And, the
4960 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004961 **/
4962static inline void
4963lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4964 uint32_t did)
4965{
4966 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4967 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004968 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smarte7dab162020-10-20 13:27:12 -07004969 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4970
James Smart109f6ed2008-12-04 22:39:08 -05004971 ndlp->nlp_DID = did;
4972 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004973 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004974 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004975 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004976 kref_init(&ndlp->kref);
James Smart109f6ed2008-12-04 22:39:08 -05004977 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004978 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004979 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004980}
James Smarte47c9092008-02-08 18:49:26 -05004981
James Smartde0c5b32007-04-25 09:52:27 -04004982void
James Smart2e0fef82007-06-17 19:56:36 -05004983lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004984{
James Smart87af33f2007-10-27 13:37:43 -04004985 /*
James Smartfa4066b2008-01-11 01:53:27 -05004986 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004987 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004988 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4989 * until ALL other outstanding threads have completed. We check
4990 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004991 */
James Smartfa4066b2008-01-11 01:53:27 -05004992 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4993 return;
James Smart51ef4c22007-08-02 11:10:31 -04004994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart307e3382020-11-15 11:26:30 -08004995 ndlp->nlp_flag |= NLP_DROPPED;
James Smartbe6bb942015-04-07 15:07:22 -04004996 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004997 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004998 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004999 }
James Smart02902172015-05-21 13:55:17 -04005000
5001 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04005002 return;
dea31012005-04-17 16:05:31 -05005003}
5004
5005/*
5006 * Start / ReStart rescue timer for Discovery / RSCN handling
5007 */
5008void
James Smart2e0fef82007-06-17 19:56:36 -05005009lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005010{
James Smart2e0fef82007-06-17 19:56:36 -05005011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5012 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005013 uint32_t tmo;
5014
James Smart2e0fef82007-06-17 19:56:36 -05005015 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005016 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005017 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
5018 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02005019 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005020 * FC spec states we need 3 * ratov for CT requests
5021 */
5022 tmo = ((phba->fc_ratov * 3) + 3);
5023 }
dea31012005-04-17 16:05:31 -05005024
James Smart858c9f62007-06-17 19:56:39 -05005025
5026 if (!timer_pending(&vport->fc_disctmo)) {
5027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5028 "set disc timer: tmo:x%x state:x%x flg:x%x",
5029 tmo, vport->port_state, vport->fc_flag);
5030 }
5031
James Smart256ec0d2013-04-17 20:14:58 -04005032 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05005033 spin_lock_irq(shost->host_lock);
5034 vport->fc_flag |= FC_DISC_TMO;
5035 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005036
5037 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005038 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5039 "0247 Start Discovery Timer state x%x "
5040 "Data: x%x x%lx x%x x%x\n",
5041 vport->port_state, tmo,
5042 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5043 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005044
5045 return;
5046}
5047
5048/*
5049 * Cancel rescue timer for Discovery / RSCN handling
5050 */
5051int
James Smart2e0fef82007-06-17 19:56:36 -05005052lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005053{
James Smart2e0fef82007-06-17 19:56:36 -05005054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005055 unsigned long iflags;
5056
James Smart858c9f62007-06-17 19:56:39 -05005057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5058 "can disc timer: state:x%x rtry:x%x flg:x%x",
5059 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5060
dea31012005-04-17 16:05:31 -05005061 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05005062 if (vport->fc_flag & FC_DISC_TMO) {
5063 spin_lock_irqsave(shost->host_lock, iflags);
5064 vport->fc_flag &= ~FC_DISC_TMO;
5065 spin_unlock_irqrestore(shost->host_lock, iflags);
5066 del_timer_sync(&vport->fc_disctmo);
5067 spin_lock_irqsave(&vport->work_port_lock, iflags);
5068 vport->work_port_events &= ~WORKER_DISC_TMO;
5069 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05005070 }
5071
5072 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5074 "0248 Cancel Discovery Timer state x%x "
5075 "Data: x%x x%x x%x\n",
5076 vport->port_state, vport->fc_flag,
5077 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005078 return 0;
dea31012005-04-17 16:05:31 -05005079}
5080
5081/*
5082 * Check specified ring for outstanding IOCB on the SLI queue
5083 * Return true if iocb matches the specified nport
5084 */
5085int
James Smart2e0fef82007-06-17 19:56:36 -05005086lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5087 struct lpfc_sli_ring *pring,
5088 struct lpfc_iocbq *iocb,
5089 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005090{
James Smart2e0fef82007-06-17 19:56:36 -05005091 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05005092 struct lpfc_vport *vport = ndlp->vport;
5093
5094 if (iocb->vport != vport)
5095 return 0;
5096
dea31012005-04-17 16:05:31 -05005097 if (pring->ringno == LPFC_ELS_RING) {
5098 switch (icmd->ulpCommand) {
5099 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04005100 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005101 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05005102 fallthrough;
dea31012005-04-17 16:05:31 -05005103 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04005104 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
5105 return 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05005106 fallthrough;
dea31012005-04-17 16:05:31 -05005107 case CMD_XMIT_ELS_RSP64_CX:
5108 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005109 return 1;
dea31012005-04-17 16:05:31 -05005110 }
James Smart895427b2017-02-12 13:52:30 -08005111 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05005112 /* Skip match check if waiting to relogin to FCP target */
5113 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05005114 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005115 return 0;
dea31012005-04-17 16:05:31 -05005116 }
5117 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005118 return 1;
dea31012005-04-17 16:05:31 -05005119 }
dea31012005-04-17 16:05:31 -05005120 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005121 return 0;
dea31012005-04-17 16:05:31 -05005122}
5123
James Smart895427b2017-02-12 13:52:30 -08005124static void
5125__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5126 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5127 struct list_head *dequeue_list)
5128{
5129 struct lpfc_iocbq *iocb, *next_iocb;
5130
5131 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5132 /* Check to see if iocb matches the nport */
5133 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5134 /* match, dequeue */
5135 list_move_tail(&iocb->list, dequeue_list);
5136 }
5137}
5138
5139static void
5140lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5141 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5142{
5143 struct lpfc_sli *psli = &phba->sli;
5144 uint32_t i;
5145
5146 spin_lock_irq(&phba->hbalock);
5147 for (i = 0; i < psli->num_rings; i++)
5148 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5149 dequeue_list);
5150 spin_unlock_irq(&phba->hbalock);
5151}
5152
5153static void
5154lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5155 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5156{
5157 struct lpfc_sli_ring *pring;
5158 struct lpfc_queue *qp = NULL;
5159
5160 spin_lock_irq(&phba->hbalock);
5161 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5162 pring = qp->pring;
5163 if (!pring)
5164 continue;
James Smart2ade92a2017-03-04 09:30:38 -08005165 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08005166 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08005167 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08005168 }
5169 spin_unlock_irq(&phba->hbalock);
5170}
5171
dea31012005-04-17 16:05:31 -05005172/*
5173 * Free resources / clean up outstanding I/Os
5174 * associated with nlp_rpi in the LPFC_NODELIST entry.
5175 */
5176static int
James Smart2e0fef82007-06-17 19:56:36 -05005177lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005178{
James Smart2534ba72007-04-25 09:52:20 -04005179 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005180
James Smart92d7f7b2007-06-17 19:56:38 -05005181 lpfc_fabric_abort_nport(ndlp);
5182
dea31012005-04-17 16:05:31 -05005183 /*
5184 * Everything that matches on txcmplq will be returned
5185 * by firmware with a no rpi error.
5186 */
James Smart40426292010-12-15 17:58:10 -05005187 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08005188 if (phba->sli_rev != LPFC_SLI_REV4)
5189 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5190 else
5191 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05005192 }
James Smart2534ba72007-04-25 09:52:20 -04005193
James Smarta257bf92009-04-06 18:48:10 -04005194 /* Cancel all the IOCBs from the completions list */
5195 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5196 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005197
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005198 return 0;
dea31012005-04-17 16:05:31 -05005199}
5200
James Smart086a3452012-08-14 14:25:21 -04005201/**
5202 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5203 * @phba: Pointer to HBA context object.
5204 * @pmb: Pointer to mailbox object.
5205 *
5206 * This function will issue an ELS LOGO command after completing
5207 * the UNREG_RPI.
5208 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04005209static void
James Smart086a3452012-08-14 14:25:21 -04005210lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5211{
5212 struct lpfc_vport *vport = pmb->vport;
5213 struct lpfc_nodelist *ndlp;
5214
James Smart3e1f0712018-11-29 16:09:29 -08005215 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04005216 if (!ndlp)
5217 return;
5218 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04005219 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08005220
5221 /* Check to see if there are any deferred events to process */
5222 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5223 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5224 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5225 "1434 UNREG cmpl deferred logo x%x "
James Smart32350662019-08-14 16:57:06 -07005226 "on NPort x%x Data: x%x x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08005227 ndlp->nlp_rpi, ndlp->nlp_DID,
5228 ndlp->nlp_defer_did, ndlp);
5229
5230 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5231 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5232 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08005233 } else {
James Smart01131e72021-05-14 12:55:49 -07005234 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
James Smart4f1a2fe2019-08-14 16:56:32 -07005235 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5236 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
James Smart01131e72021-05-14 12:55:49 -07005237 spin_lock_irq(&ndlp->lock);
James Smart4f1a2fe2019-08-14 16:56:32 -07005238 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
James Smart0f154222019-09-21 20:58:52 -07005239 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smart01131e72021-05-14 12:55:49 -07005240 spin_unlock_irq(&ndlp->lock);
James Smart4f1a2fe2019-08-14 16:56:32 -07005241 }
James Smart01131e72021-05-14 12:55:49 -07005242 spin_lock_irq(&ndlp->lock);
James Smart00292e02018-12-13 15:17:55 -08005243 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smart01131e72021-05-14 12:55:49 -07005244 spin_unlock_irq(&ndlp->lock);
James Smartdea16bd2018-11-29 16:09:30 -08005245 }
James Smart086a3452012-08-14 14:25:21 -04005246}
5247
dea31012005-04-17 16:05:31 -05005248/*
James Smart97acd002019-09-21 20:58:51 -07005249 * Sets the mailbox completion handler to be used for the
5250 * unreg_rpi command. The handler varies based on the state of
5251 * the port and what will be happening to the rpi next.
5252 */
5253static void
5254lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5255 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5256{
5257 unsigned long iflags;
5258
James Smarta70e63e2020-11-15 11:26:38 -08005259 /* Driver always gets a reference on the mailbox job
5260 * in support of async jobs.
5261 */
5262 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5263 if (!mbox->ctx_ndlp)
5264 return;
5265
James Smart97acd002019-09-21 20:58:51 -07005266 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
James Smart97acd002019-09-21 20:58:51 -07005267 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5268
5269 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5270 (!(vport->load_flag & FC_UNLOADING)) &&
5271 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5272 LPFC_SLI_INTF_IF_TYPE_2) &&
5273 (kref_read(&ndlp->kref) > 0)) {
James Smart97acd002019-09-21 20:58:51 -07005274 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5275 } else {
5276 if (vport->load_flag & FC_UNLOADING) {
5277 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartc6adba12020-11-15 11:26:34 -08005278 spin_lock_irqsave(&ndlp->lock, iflags);
James Smart97acd002019-09-21 20:58:51 -07005279 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smartc6adba12020-11-15 11:26:34 -08005280 spin_unlock_irqrestore(&ndlp->lock, iflags);
James Smart97acd002019-09-21 20:58:51 -07005281 }
James Smart97acd002019-09-21 20:58:51 -07005282 }
James Smart97acd002019-09-21 20:58:51 -07005283 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5284 }
5285}
5286
5287/*
dea31012005-04-17 16:05:31 -05005288 * Free rpi associated with LPFC_NODELIST entry.
5289 * This routine is called from lpfc_freenode(), when we are removing
5290 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5291 * LOGO that completes successfully, and we are waiting to PLOGI back
5292 * to the remote NPort. In addition, it is called after we receive
5293 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5294 * we are waiting to PLOGI back to the remote NPort.
5295 */
5296int
James Smart2e0fef82007-06-17 19:56:36 -05005297lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005298{
James Smart2e0fef82007-06-17 19:56:36 -05005299 struct lpfc_hba *phba = vport->phba;
5300 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04005301 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04005302 uint16_t rpi;
dea31012005-04-17 16:05:31 -05005303
James Smartf454a9a2013-09-06 12:20:07 -04005304 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5305 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5306 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
James Smart0f154222019-09-21 20:58:52 -07005307 lpfc_printf_vlog(vport, KERN_INFO,
5308 LOG_NODE | LOG_DISCOVERY,
James Smartf454a9a2013-09-06 12:20:07 -04005309 "3366 RPI x%x needs to be "
5310 "unregistered nlp_flag x%x "
5311 "did x%x\n",
5312 ndlp->nlp_rpi, ndlp->nlp_flag,
5313 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08005314
5315 /* If there is already an UNREG in progress for this ndlp,
5316 * no need to queue up another one.
5317 */
5318 if (ndlp->nlp_flag & NLP_UNREG_INP) {
James Smart0f154222019-09-21 20:58:52 -07005319 lpfc_printf_vlog(vport, KERN_INFO,
5320 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08005321 "1436 unreg_rpi SKIP UNREG x%x on "
5322 "NPort x%x deferred x%x flg x%x "
James Smart32350662019-08-14 16:57:06 -07005323 "Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08005324 ndlp->nlp_rpi, ndlp->nlp_DID,
5325 ndlp->nlp_defer_did,
5326 ndlp->nlp_flag, ndlp);
5327 goto out;
5328 }
5329
James Smart2e0fef82007-06-17 19:56:36 -05005330 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5331 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005332 /* SLI4 ports require the physical rpi value. */
5333 rpi = ndlp->nlp_rpi;
5334 if (phba->sli_rev == LPFC_SLI_REV4)
5335 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04005336
James Smart6d368e52011-05-24 11:44:12 -04005337 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05005338 mbox->vport = vport;
James Smart97acd002019-09-21 20:58:51 -07005339 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
James Smarta70e63e2020-11-15 11:26:38 -08005340 if (!mbox->ctx_ndlp) {
5341 mempool_free(mbox, phba->mbox_mem_pool);
5342 return 1;
5343 }
5344
James Smart97acd002019-09-21 20:58:51 -07005345 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5346 /*
5347 * accept PLOGIs after unreg_rpi_cmpl
5348 */
5349 acc_plogi = 0;
James Smartdea16bd2018-11-29 16:09:30 -08005350 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5351 Fabric_DID_MASK) &&
5352 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5353 ndlp->nlp_flag |= NLP_UNREG_INP;
5354
James Smart0f154222019-09-21 20:58:52 -07005355 lpfc_printf_vlog(vport, KERN_INFO,
5356 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08005357 "1433 unreg_rpi UNREG x%x on "
James Smart32350662019-08-14 16:57:06 -07005358 "NPort x%x deferred flg x%x "
5359 "Data:x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08005360 ndlp->nlp_rpi, ndlp->nlp_DID,
5361 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04005362
James Smart0b727fe2007-10-27 13:37:25 -04005363 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04005364 if (rc == MBX_NOT_FINISHED) {
James Smart25ac2c972021-09-10 16:31:54 -07005365 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smart2e0fef82007-06-17 19:56:36 -05005366 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04005367 acc_plogi = 1;
5368 }
James Smarte7dab162020-10-20 13:27:12 -07005369 } else {
5370 lpfc_printf_vlog(vport, KERN_INFO,
5371 LOG_NODE | LOG_DISCOVERY,
5372 "1444 Failed to allocate mempool "
5373 "unreg_rpi UNREG x%x, "
5374 "DID x%x, flag x%x, "
5375 "ndlp x%px\n",
5376 ndlp->nlp_rpi, ndlp->nlp_DID,
5377 ndlp->nlp_flag, ndlp);
5378
5379 /* Because mempool_alloc failed, we
5380 * will issue a LOGO here and keep the rpi alive if
5381 * not unloading.
5382 */
5383 if (!(vport->load_flag & FC_UNLOADING)) {
5384 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5385 lpfc_issue_els_logo(vport, ndlp, 0);
5386 ndlp->nlp_prev_state = ndlp->nlp_state;
5387 lpfc_nlp_set_state(vport, ndlp,
5388 NLP_STE_NPR_NODE);
5389 }
5390
5391 return 1;
dea31012005-04-17 16:05:31 -05005392 }
dea31012005-04-17 16:05:31 -05005393 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08005394out:
James Smart40426292010-12-15 17:58:10 -05005395 if (phba->sli_rev != LPFC_SLI_REV4)
5396 ndlp->nlp_rpi = 0;
5397 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04005398 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04005399 if (acc_plogi)
5400 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05005401 return 1;
5402 }
James Smart7c5e5182015-05-22 10:42:43 -04005403 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05005404 return 0;
5405}
5406
James Smartecfd03c2010-02-12 14:41:27 -05005407/**
5408 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5409 * @phba: pointer to lpfc hba data structure.
5410 *
5411 * This routine is invoked to unregister all the currently registered RPIs
5412 * to the HBA.
5413 **/
5414void
5415lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5416{
5417 struct lpfc_vport **vports;
5418 struct lpfc_nodelist *ndlp;
5419 struct Scsi_Host *shost;
5420 int i;
5421
5422 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05005423 if (!vports) {
Dick Kennedy372c1872020-06-30 14:50:00 -07005424 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5425 "2884 Vport array allocation failed \n");
James Smart63e801c2010-11-20 23:14:19 -05005426 return;
5427 }
James Smartecfd03c2010-02-12 14:41:27 -05005428 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5429 shost = lpfc_shost_from_vport(vports[i]);
5430 spin_lock_irq(shost->host_lock);
5431 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05005432 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005433 /* The mempool_alloc might sleep */
5434 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05005435 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05005436 spin_lock_irq(shost->host_lock);
5437 }
James Smartecfd03c2010-02-12 14:41:27 -05005438 }
5439 spin_unlock_irq(shost->host_lock);
5440 }
5441 lpfc_destroy_vport_work_array(phba, vports);
5442}
5443
James Smart92d7f7b2007-06-17 19:56:38 -05005444void
5445lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5446{
5447 struct lpfc_hba *phba = vport->phba;
5448 LPFC_MBOXQ_t *mbox;
5449 int rc;
5450
James Smart5af5eee2010-10-22 11:06:38 -04005451 if (phba->sli_rev == LPFC_SLI_REV4) {
5452 lpfc_sli4_unreg_all_rpis(vport);
5453 return;
5454 }
5455
James Smart92d7f7b2007-06-17 19:56:38 -05005456 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5457 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005458 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5459 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005460 mbox->vport = vport;
5461 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005462 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005463 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005464 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005465 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04005466
5467 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005468 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5469 "1836 Could not issue "
5470 "unreg_login(all_rpis) status %d\n",
5471 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005472 }
5473}
5474
5475void
5476lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5477{
5478 struct lpfc_hba *phba = vport->phba;
5479 LPFC_MBOXQ_t *mbox;
5480 int rc;
5481
James Smartc95a3b42019-03-12 16:30:07 -07005482 /* Unreg DID is an SLI3 operation. */
5483 if (phba->sli_rev > LPFC_SLI_REV3)
5484 return;
5485
James Smart92d7f7b2007-06-17 19:56:38 -05005486 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5487 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005488 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5489 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005490 mbox->vport = vport;
5491 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005492 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005493 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005494 if (rc != MBX_TIMEOUT)
5495 mempool_free(mbox, phba->mbox_mem_pool);
5496
5497 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
Dick Kennedy372c1872020-06-30 14:50:00 -07005498 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04005499 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005500 "unreg_did (default rpis) status %d\n",
5501 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005502 }
5503}
5504
dea31012005-04-17 16:05:31 -05005505/*
5506 * Free resources associated with LPFC_NODELIST entry
5507 * so it can be freed.
5508 */
5509static int
James Smart2e0fef82007-06-17 19:56:36 -05005510lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005511{
James Smart2e0fef82007-06-17 19:56:36 -05005512 struct lpfc_hba *phba = vport->phba;
5513 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005514 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05005515
5516 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005517 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5518 "0900 Cleanup node for NPort x%x "
5519 "Data: x%x x%x x%x\n",
5520 ndlp->nlp_DID, ndlp->nlp_flag,
5521 ndlp->nlp_state, ndlp->nlp_rpi);
James Smart307e3382020-11-15 11:26:30 -08005522 lpfc_dequeue_node(vport, ndlp);
James Smart086a3452012-08-14 14:25:21 -04005523
5524 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5525
dea31012005-04-17 16:05:31 -05005526 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5527 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005528 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005529 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005530 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5531 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005532 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5533 }
5534 }
James Smart33ccf8d2006-08-17 11:57:58 -04005535
James Smart2e0fef82007-06-17 19:56:36 -05005536 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005537 /* Cleanup REG_LOGIN completions which are not yet processed */
5538 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5539 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005540 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005541 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005542 continue;
5543
James Smart3e1f0712018-11-29 16:09:29 -08005544 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005545 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5546 }
5547
dea31012005-04-17 16:05:31 -05005548 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005549 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005550 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005551 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5552 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005553 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005554 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005555 kfree(mp);
5556 }
5557 list_del(&mb->list);
5558 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005559 /* We shall not invoke the lpfc_nlp_put to decrement
5560 * the ndlp reference count as we are in the process
5561 * of lpfc_nlp_release.
5562 */
dea31012005-04-17 16:05:31 -05005563 }
5564 }
James Smart2e0fef82007-06-17 19:56:36 -05005565 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005566
James Smarte47c9092008-02-08 18:49:26 -05005567 lpfc_els_abort(phba, ndlp);
5568
James Smartc6adba12020-11-15 11:26:34 -08005569 spin_lock_irq(&ndlp->lock);
James Smartc01f3202006-08-18 17:47:08 -04005570 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smartc6adba12020-11-15 11:26:34 -08005571 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005572
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005573 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005574 del_timer_sync(&ndlp->nlp_delayfunc);
5575
James Smart0d2b6b82008-06-14 22:52:47 -04005576 list_del_init(&ndlp->els_retry_evt.evt_listp);
5577 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smarte7dab162020-10-20 13:27:12 -07005578 list_del_init(&ndlp->recovery_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005579 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart01131e72021-05-14 12:55:49 -07005580
James Smart4f1a2fe2019-08-14 16:56:32 -07005581 if (phba->sli_rev == LPFC_SLI_REV4)
5582 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smart01131e72021-05-14 12:55:49 -07005583
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005584 return 0;
dea31012005-04-17 16:05:31 -05005585}
5586
dea31012005-04-17 16:05:31 -05005587static int
James Smart2e0fef82007-06-17 19:56:36 -05005588lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5589 uint32_t did)
dea31012005-04-17 16:05:31 -05005590{
James Smart2e0fef82007-06-17 19:56:36 -05005591 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005592
5593 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005594 return 0;
dea31012005-04-17 16:05:31 -05005595
dea31012005-04-17 16:05:31 -05005596 /* First check for Direct match */
5597 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005598 return 1;
dea31012005-04-17 16:05:31 -05005599
5600 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005601 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005602 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005603 return 0;
dea31012005-04-17 16:05:31 -05005604 }
5605
5606 matchdid.un.word = did;
5607 ndlpdid.un.word = ndlp->nlp_DID;
5608 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5609 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5610 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005611 /* This code is supposed to match the ID
5612 * for a private loop device that is
5613 * connect to fl_port. But we need to
5614 * check that the port did not just go
5615 * from pt2pt to fabric or we could end
5616 * up matching ndlp->nlp_DID 000001 to
5617 * fabric DID 0x20101
5618 */
dea31012005-04-17 16:05:31 -05005619 if ((ndlpdid.un.b.domain == 0) &&
5620 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005621 if (ndlpdid.un.b.id &&
5622 vport->phba->fc_topology ==
5623 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005624 return 1;
dea31012005-04-17 16:05:31 -05005625 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005626 return 0;
dea31012005-04-17 16:05:31 -05005627 }
5628
5629 matchdid.un.word = ndlp->nlp_DID;
5630 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5631 (mydid.un.b.area == ndlpdid.un.b.area)) {
5632 if ((matchdid.un.b.domain == 0) &&
5633 (matchdid.un.b.area == 0)) {
5634 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005635 return 1;
dea31012005-04-17 16:05:31 -05005636 }
5637 }
5638 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005639 return 0;
dea31012005-04-17 16:05:31 -05005640}
5641
James Smart685f0bf2007-04-25 09:53:08 -04005642/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005643static struct lpfc_nodelist *
5644__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005645{
James Smart2fb9bd82006-12-02 13:33:57 -05005646 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005647 uint32_t data1;
5648
James Smart2e0fef82007-06-17 19:56:36 -05005649 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5650 if (lpfc_matchdid(vport, ndlp, did)) {
James Smartb95b2112019-08-14 16:56:47 -07005651 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5652 ((uint32_t)ndlp->nlp_xri << 16) |
James Smart307e3382020-11-15 11:26:30 -08005653 ((uint32_t)ndlp->nlp_type << 8)
5654 );
James Smarte8b62012007-08-02 11:10:09 -04005655 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5656 "0929 FIND node DID "
James Smartb95b2112019-08-14 16:56:47 -07005657 "Data: x%px x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005658 ndlp, ndlp->nlp_DID,
James Smartb95b2112019-08-14 16:56:47 -07005659 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
James Smartcff261f2013-12-17 20:29:47 -05005660 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005661 return ndlp;
dea31012005-04-17 16:05:31 -05005662 }
5663 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005664
dea31012005-04-17 16:05:31 -05005665 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005666 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5667 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005668 return NULL;
5669}
5670
5671struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005672lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005673{
James Smart2e0fef82007-06-17 19:56:36 -05005674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005675 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005676 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005677
James Smartfedd3b72011-02-16 12:39:24 -05005678 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005679 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005680 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005681 return ndlp;
5682}
5683
5684struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005685lpfc_findnode_mapped(struct lpfc_vport *vport)
5686{
5687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5688 struct lpfc_nodelist *ndlp;
5689 uint32_t data1;
5690 unsigned long iflags;
5691
5692 spin_lock_irqsave(shost->host_lock, iflags);
5693
5694 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5695 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5696 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5697 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5698 ((uint32_t)ndlp->nlp_xri << 16) |
5699 ((uint32_t)ndlp->nlp_type << 8) |
5700 ((uint32_t)ndlp->nlp_rpi & 0xff));
5701 spin_unlock_irqrestore(shost->host_lock, iflags);
5702 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5703 "2025 FIND node DID "
James Smart32350662019-08-14 16:57:06 -07005704 "Data: x%px x%x x%x x%x x%px\n",
James Smartf60cb932019-05-14 14:58:05 -07005705 ndlp, ndlp->nlp_DID,
5706 ndlp->nlp_flag, data1,
5707 ndlp->active_rrqs_xri_bitmap);
5708 return ndlp;
5709 }
5710 }
5711 spin_unlock_irqrestore(shost->host_lock, iflags);
5712
5713 /* FIND node did <did> NOT FOUND */
5714 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5715 "2026 FIND mapped did NOT FOUND.\n");
5716 return NULL;
5717}
5718
5719struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005720lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5721{
James Smart2e0fef82007-06-17 19:56:36 -05005722 struct lpfc_nodelist *ndlp;
5723
5724 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005725 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005726 if (vport->phba->nvmet_support)
5727 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005728 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5729 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005730 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005731 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005732 if (!ndlp)
5733 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005734 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb4b34172019-10-18 14:18:31 -07005735
5736 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5737 "6453 Setup New Node 2B_DISC x%x "
5738 "Data:x%x x%x x%x\n",
5739 ndlp->nlp_DID, ndlp->nlp_flag,
5740 ndlp->nlp_state, vport->fc_flag);
5741
James Smartc6adba12020-11-15 11:26:34 -08005742 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005743 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005744 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005745 return ndlp;
5746 }
James Smarte47c9092008-02-08 18:49:26 -05005747
James Smart1c5b12f2017-04-21 16:05:03 -07005748 /* The NVME Target does not want to actively manage an rport.
5749 * The goal is to allow the target to reset its state and clear
5750 * pending IO in preparation for the initiator to recover.
5751 */
James Smart58da1ff2008-04-07 10:15:56 -04005752 if ((vport->fc_flag & FC_RSCN_MODE) &&
5753 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005754 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005755
5756 /* Since this node is marked for discovery,
5757 * delay timeout is not needed.
5758 */
5759 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5760
James Smartb4b34172019-10-18 14:18:31 -07005761 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5762 "6455 Setup RSCN Node 2B_DISC x%x "
5763 "Data:x%x x%x x%x\n",
5764 ndlp->nlp_DID, ndlp->nlp_flag,
5765 ndlp->nlp_state, vport->fc_flag);
5766
James Smart1c5b12f2017-04-21 16:05:03 -07005767 /* NVME Target mode waits until rport is known to be
5768 * impacted by the RSCN before it transitions. No
5769 * active management - just go to NPR provided the
5770 * node had a valid login.
5771 */
5772 if (vport->phba->nvmet_support)
5773 return ndlp;
5774
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005775 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005776 * we don't need to try to discover it again.
5777 */
James Smart3f97aed2019-09-21 20:58:55 -07005778 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5779 !(ndlp->nlp_type &
5780 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
James Smart87af33f2007-10-27 13:37:43 -04005781 return NULL;
5782
James Smart3f97aed2019-09-21 20:58:55 -07005783 ndlp->nlp_prev_state = ndlp->nlp_state;
5784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5785
James Smartc6adba12020-11-15 11:26:34 -08005786 spin_lock_irq(&ndlp->lock);
James Smarta257bf92009-04-06 18:48:10 -04005787 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005788 spin_unlock_irq(&ndlp->lock);
James Smartb4b34172019-10-18 14:18:31 -07005789 } else {
5790 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5791 "6456 Skip Setup RSCN Node x%x "
5792 "Data:x%x x%x x%x\n",
5793 ndlp->nlp_DID, ndlp->nlp_flag,
5794 ndlp->nlp_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05005795 ndlp = NULL;
James Smartb4b34172019-10-18 14:18:31 -07005796 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005797 } else {
James Smartb4b34172019-10-18 14:18:31 -07005798 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5799 "6457 Setup Active Node 2B_DISC x%x "
5800 "Data:x%x x%x x%x\n",
5801 ndlp->nlp_DID, ndlp->nlp_flag,
5802 ndlp->nlp_state, vport->fc_flag);
5803
James Smart1c5b12f2017-04-21 16:05:03 -07005804 /* If the initiator received a PLOGI from this NPort or if the
5805 * initiator is already in the process of discovery on it,
5806 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005807 */
James Smart685f0bf2007-04-25 09:53:08 -04005808 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005809 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005810 (!vport->phba->nvmet_support &&
5811 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005812 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005813
James Smart8c258642017-02-12 13:52:36 -08005814 if (vport->phba->nvmet_support)
5815 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005816
5817 /* Moving to NPR state clears unsolicited flags and
5818 * allows for rediscovery
5819 */
5820 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5821
James Smartc6adba12020-11-15 11:26:34 -08005822 spin_lock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005823 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smartc6adba12020-11-15 11:26:34 -08005824 spin_unlock_irq(&ndlp->lock);
dea31012005-04-17 16:05:31 -05005825 }
5826 return ndlp;
5827}
5828
5829/* Build a list of nodes to discover based on the loopmap */
5830void
James Smart2e0fef82007-06-17 19:56:36 -05005831lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005832{
James Smart2e0fef82007-06-17 19:56:36 -05005833 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005834 int j;
5835 uint32_t alpa, index;
5836
James Smart2e0fef82007-06-17 19:56:36 -05005837 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005838 return;
James Smart2e0fef82007-06-17 19:56:36 -05005839
James Smart76a95d72010-11-20 23:11:48 -05005840 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005841 return;
dea31012005-04-17 16:05:31 -05005842
5843 /* Check for loop map present or not */
5844 if (phba->alpa_map[0]) {
5845 for (j = 1; j <= phba->alpa_map[0]; j++) {
5846 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005847 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005848 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005849 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005850 }
5851 } else {
5852 /* No alpamap, so try all alpa's */
5853 for (j = 0; j < FC_MAXLOOP; j++) {
5854 /* If cfg_scan_down is set, start from highest
5855 * ALPA (0xef) to lowest (0x1).
5856 */
James Smart3de2a652007-08-02 11:09:59 -04005857 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005858 index = j;
5859 else
5860 index = FC_MAXLOOP - j - 1;
5861 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005862 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005863 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005864 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005865 }
5866 }
5867 return;
5868}
5869
James Smart895427b2017-02-12 13:52:30 -08005870/* SLI3 only */
dea31012005-04-17 16:05:31 -05005871void
James Smart2e0fef82007-06-17 19:56:36 -05005872lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005873{
dea31012005-04-17 16:05:31 -05005874 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005875 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005876 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5877 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005878 int rc;
5879
James Smart92d7f7b2007-06-17 19:56:38 -05005880 /*
5881 * if it's not a physical port or if we already send
5882 * clear_la then don't send it.
5883 */
5884 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005885 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5886 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005887 return;
5888
James Smart2e0fef82007-06-17 19:56:36 -05005889 /* Link up discovery */
5890 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5891 phba->link_state = LPFC_CLEAR_LA;
5892 lpfc_clear_la(phba, mbox);
5893 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5894 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005895 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005896 if (rc == MBX_NOT_FINISHED) {
5897 mempool_free(mbox, phba->mbox_mem_pool);
5898 lpfc_disc_flush_list(vport);
5899 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5900 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005901 phba->link_state = LPFC_HBA_ERROR;
5902 }
5903 }
5904}
5905
5906/* Reg_vpi to tell firmware to resume normal operations */
5907void
5908lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5909{
5910 LPFC_MBOXQ_t *regvpimbox;
5911
5912 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5913 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005914 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005915 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5916 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005917 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005918 == MBX_NOT_FINISHED) {
5919 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005920 }
5921 }
5922}
5923
5924/* Start Link up / RSCN discovery on NPR nodes */
5925void
5926lpfc_disc_start(struct lpfc_vport *vport)
5927{
5928 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5929 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005930 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005931 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005932
James Smarte74c03c2013-04-17 20:15:19 -04005933 if (!lpfc_is_link_up(phba)) {
5934 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5935 "3315 Link is not up %x\n",
5936 phba->link_state);
dea31012005-04-17 16:05:31 -05005937 return;
James Smarte74c03c2013-04-17 20:15:19 -04005938 }
James Smart2e0fef82007-06-17 19:56:36 -05005939
5940 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005941 clear_la_pending = 1;
5942 else
5943 clear_la_pending = 0;
5944
James Smart2e0fef82007-06-17 19:56:36 -05005945 if (vport->port_state < LPFC_VPORT_READY)
5946 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005947
James Smart2e0fef82007-06-17 19:56:36 -05005948 lpfc_set_disctmo(vport);
5949
James Smart2e0fef82007-06-17 19:56:36 -05005950 vport->fc_prevDID = vport->fc_myDID;
5951 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005952
5953 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005954 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07005955 "0202 Start Discovery port state x%x "
5956 "flg x%x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04005957 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
James Smartb4b34172019-10-18 14:18:31 -07005958 vport->fc_adisc_cnt, vport->fc_npr_cnt);
dea31012005-04-17 16:05:31 -05005959
5960 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005961 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005962
5963 if (num_sent)
5964 return;
5965
James Smart6fa139f2013-04-17 20:20:00 -04005966 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005967 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005968 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005969 !(vport->fc_flag & FC_RSCN_MODE) &&
5970 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005971 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005972 lpfc_issue_reg_vpi(phba, vport);
5973 return;
5974 }
James Smart2e0fef82007-06-17 19:56:36 -05005975
James Smart92d7f7b2007-06-17 19:56:38 -05005976 /*
5977 * For SLI2, we need to set port_state to READY and continue
5978 * discovery.
5979 */
5980 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5981 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005982 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005983
5984 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005985 vport->num_disc_nodes = 0;
5986 /* go thru NPR nodes and issue ELS PLOGIs */
5987 if (vport->fc_npr_cnt)
5988 lpfc_els_disc_plogi(vport);
5989
5990 if (!vport->num_disc_nodes) {
5991 spin_lock_irq(shost->host_lock);
5992 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5993 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005994 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005995 }
5996 }
James Smart92d7f7b2007-06-17 19:56:38 -05005997 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005998 } else {
5999 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05006000 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05006001
6002 if (num_sent)
6003 return;
6004
James Smart2e0fef82007-06-17 19:56:36 -05006005 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05006006 /* Check to see if more RSCNs came in while we
6007 * were processing this one.
6008 */
James Smart2e0fef82007-06-17 19:56:36 -05006009 if ((vport->fc_rscn_id_cnt == 0) &&
6010 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
6011 spin_lock_irq(shost->host_lock);
6012 vport->fc_flag &= ~FC_RSCN_MODE;
6013 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006014 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006015 } else
James Smart2e0fef82007-06-17 19:56:36 -05006016 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006017 }
6018 }
6019 return;
6020}
6021
6022/*
6023 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
6024 * ring the match the sppecified nodelist.
6025 */
6026static void
James Smart2e0fef82007-06-17 19:56:36 -05006027lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006028{
James Smart2534ba72007-04-25 09:52:20 -04006029 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05006030 IOCB_t *icmd;
6031 struct lpfc_iocbq *iocb, *next_iocb;
6032 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05006033
James Smart895427b2017-02-12 13:52:30 -08006034 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07006035 if (unlikely(!pring))
6036 return;
dea31012005-04-17 16:05:31 -05006037
6038 /* Error matching iocb on txq or txcmplq
6039 * First check the txq.
6040 */
James Smart2e0fef82007-06-17 19:56:36 -05006041 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006042 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6043 if (iocb->context1 != ndlp) {
6044 continue;
6045 }
6046 icmd = &iocb->iocb;
6047 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
6048 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
6049
James Smart2534ba72007-04-25 09:52:20 -04006050 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05006051 }
6052 }
6053
6054 /* Next check the txcmplq */
6055 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6056 if (iocb->context1 != ndlp) {
6057 continue;
6058 }
6059 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05006060 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
6061 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smartdb7531d2020-11-15 11:26:44 -08006062 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
dea31012005-04-17 16:05:31 -05006063 }
6064 }
James Smart2e0fef82007-06-17 19:56:36 -05006065 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006066
James Smarta22d73b2021-01-04 10:02:38 -08006067 /* Make sure HBA is alive */
6068 lpfc_issue_hb_tmo(phba);
6069
James Smarta257bf92009-04-06 18:48:10 -04006070 /* Cancel all the IOCBs from the completions list */
6071 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6072 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05006073}
6074
Adrian Bunka6ababd2007-11-05 18:07:33 +01006075static void
James Smart2e0fef82007-06-17 19:56:36 -05006076lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006077{
6078 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006079 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006080
James Smart2e0fef82007-06-17 19:56:36 -05006081 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6082 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04006083 nlp_listp) {
6084 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6085 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6086 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04006087 }
dea31012005-04-17 16:05:31 -05006088 }
6089 }
dea31012005-04-17 16:05:31 -05006090}
6091
James Smart92d7f7b2007-06-17 19:56:38 -05006092void
6093lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6094{
6095 lpfc_els_flush_rscn(vport);
6096 lpfc_els_flush_cmd(vport);
6097 lpfc_disc_flush_list(vport);
6098}
6099
dea31012005-04-17 16:05:31 -05006100/*****************************************************************************/
6101/*
6102 * NAME: lpfc_disc_timeout
6103 *
6104 * FUNCTION: Fibre Channel driver discovery timeout routine.
6105 *
6106 * EXECUTION ENVIRONMENT: interrupt only
6107 *
6108 * CALLED FROM:
6109 * Timer function
6110 *
6111 * RETURNS:
6112 * none
6113 */
6114/*****************************************************************************/
6115void
Kees Cookf22eb4d2017-09-06 20:24:26 -07006116lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05006117{
Kees Cookf22eb4d2017-09-06 20:24:26 -07006118 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05006119 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006120 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006121 unsigned long flags = 0;
6122
6123 if (unlikely(!phba))
6124 return;
6125
James Smart5e9d9b82008-06-14 22:52:53 -04006126 spin_lock_irqsave(&vport->work_port_lock, flags);
6127 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6128 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006129 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006130 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05006131
James Smart5e9d9b82008-06-14 22:52:53 -04006132 if (!tmo_posted)
6133 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006134 return;
6135}
6136
6137static void
James Smart2e0fef82007-06-17 19:56:36 -05006138lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006139{
James Smart2e0fef82007-06-17 19:56:36 -05006140 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6141 struct lpfc_hba *phba = vport->phba;
6142 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006143 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05006144 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05006145 int rc, clrlaerr = 0;
6146
James Smart2e0fef82007-06-17 19:56:36 -05006147 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05006148 return;
6149
James Smart2e0fef82007-06-17 19:56:36 -05006150 spin_lock_irq(shost->host_lock);
6151 vport->fc_flag &= ~FC_DISC_TMO;
6152 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006153
James Smart858c9f62007-06-17 19:56:39 -05006154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6155 "disc timeout: state:x%x rtry:x%x flg:x%x",
6156 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6157
James Smart2e0fef82007-06-17 19:56:36 -05006158 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05006159
6160 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08006161 /*
6162 * port_state is identically LPFC_LOCAL_CFG_LINK while
6163 * waiting for FAN timeout
6164 */
James Smarte8b62012007-08-02 11:10:09 -04006165 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6166 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08006167
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006168 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05006169 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04006170 nlp_listp) {
6171 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6172 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006173 if (ndlp->nlp_type & NLP_FABRIC) {
6174 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05006175 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006176
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006177 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006178 /* Fail outstanding IO now since device
6179 * is marked for PLOGI.
6180 */
James Smart2e0fef82007-06-17 19:56:36 -05006181 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006182 }
6183 }
James Smart92d7f7b2007-06-17 19:56:38 -05006184 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05006185 if (phba->sli_rev <= LPFC_SLI_REV3)
6186 lpfc_initial_flogi(vport);
6187 else
6188 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05006189 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006190 }
dea31012005-04-17 16:05:31 -05006191 break;
6192
James Smart92d7f7b2007-06-17 19:56:38 -05006193 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05006194 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05006195 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05006196 /* Initial FLOGI timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07006197 lpfc_printf_vlog(vport, KERN_ERR,
6198 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006199 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04006200 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05006201
6202 /* Assume no Fabric and go on with discovery.
6203 * Check for outstanding ELS FLOGI to abort.
6204 */
6205
6206 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05006207 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05006208
6209 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05006210 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05006211 break;
6212
6213 case LPFC_FABRIC_CFG_LINK:
6214 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6215 NameServer login */
Dick Kennedy372c1872020-06-30 14:50:00 -07006216 lpfc_printf_vlog(vport, KERN_ERR,
6217 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006218 "0223 Timeout while waiting for "
6219 "NameServer login\n");
dea31012005-04-17 16:05:31 -05006220 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05006221 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart307e3382020-11-15 11:26:30 -08006222 if (ndlp)
James Smart87af33f2007-10-27 13:37:43 -04006223 lpfc_els_abort(phba, ndlp);
6224
6225 /* ReStart discovery */
6226 goto restart_disc;
dea31012005-04-17 16:05:31 -05006227
6228 case LPFC_NS_QRY:
6229 /* Check for wait for NameServer Rsp timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07006230 lpfc_printf_vlog(vport, KERN_ERR,
6231 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006232 "0224 NameServer Query timeout "
6233 "Data: x%x x%x\n",
6234 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05006235
James Smart92d7f7b2007-06-17 19:56:38 -05006236 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6237 /* Try it one more time */
6238 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08006239 vport->gidft_inp = 0;
6240 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006241 if (rc == 0)
6242 break;
dea31012005-04-17 16:05:31 -05006243 }
James Smart92d7f7b2007-06-17 19:56:38 -05006244 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05006245
James Smart87af33f2007-10-27 13:37:43 -04006246restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05006247 /*
6248 * Discovery is over.
6249 * set port_state to PORT_READY if SLI2.
6250 * cmpl_reg_vpi will set port_state to READY for SLI3.
6251 */
James Smart3772a992009-05-22 14:50:54 -04006252 if (phba->sli_rev < LPFC_SLI_REV4) {
6253 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6254 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04006255 else {
James Smart3772a992009-05-22 14:50:54 -04006256 lpfc_issue_clear_la(phba, vport);
6257 vport->port_state = LPFC_VPORT_READY;
6258 }
dea31012005-04-17 16:05:31 -05006259 }
6260
6261 /* Setup and issue mailbox INITIALIZE LINK command */
6262 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6263 if (!initlinkmbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006264 lpfc_printf_vlog(vport, KERN_ERR,
6265 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006266 "0206 Device Discovery "
6267 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05006268 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05006269 break;
6270 }
6271
6272 lpfc_linkdown(phba);
6273 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6274 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04006275 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05006276 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05006277 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04006278 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04006279 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05006280 if (rc == MBX_NOT_FINISHED)
6281 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6282
6283 break;
6284
6285 case LPFC_DISC_AUTH:
6286 /* Node Authentication timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07006287 lpfc_printf_vlog(vport, KERN_ERR,
6288 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006289 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05006290 lpfc_disc_flush_list(vport);
6291
James Smart92d7f7b2007-06-17 19:56:38 -05006292 /*
6293 * set port_state to PORT_READY if SLI2.
6294 * cmpl_reg_vpi will set port_state to READY for SLI3.
6295 */
James Smart3772a992009-05-22 14:50:54 -04006296 if (phba->sli_rev < LPFC_SLI_REV4) {
6297 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6298 lpfc_issue_reg_vpi(phba, vport);
6299 else { /* NPIV Not enabled */
6300 lpfc_issue_clear_la(phba, vport);
6301 vport->port_state = LPFC_VPORT_READY;
6302 }
dea31012005-04-17 16:05:31 -05006303 }
6304 break;
6305
James Smart2e0fef82007-06-17 19:56:36 -05006306 case LPFC_VPORT_READY:
6307 if (vport->fc_flag & FC_RSCN_MODE) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006308 lpfc_printf_vlog(vport, KERN_ERR,
6309 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006310 "0231 RSCN timeout Data: x%x "
6311 "x%x\n",
6312 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05006313
6314 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05006315 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05006316
James Smart2e0fef82007-06-17 19:56:36 -05006317 lpfc_els_flush_rscn(vport);
6318 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05006319 }
6320 break;
James Smart2e0fef82007-06-17 19:56:36 -05006321
James Smart92d7f7b2007-06-17 19:56:38 -05006322 default:
Dick Kennedy372c1872020-06-30 14:50:00 -07006323 lpfc_printf_vlog(vport, KERN_ERR,
6324 LOG_TRACE_EVENT,
James Smartd7c255b2008-08-24 21:50:00 -04006325 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04006326 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05006327 break;
6328 }
6329
6330 switch (phba->link_state) {
6331 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05006332 /* CLEAR LA timeout */
Dick Kennedy372c1872020-06-30 14:50:00 -07006333 lpfc_printf_vlog(vport, KERN_ERR,
6334 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006335 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05006336 clrlaerr = 1;
6337 break;
6338
James Smart09372822008-01-11 01:52:54 -05006339 case LPFC_LINK_UP:
6340 lpfc_issue_clear_la(phba, vport);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05006341 fallthrough;
James Smart2e0fef82007-06-17 19:56:36 -05006342 case LPFC_LINK_UNKNOWN:
6343 case LPFC_WARM_START:
6344 case LPFC_INIT_START:
6345 case LPFC_INIT_MBX_CMDS:
6346 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05006347 case LPFC_HBA_ERROR:
Dick Kennedy372c1872020-06-30 14:50:00 -07006348 lpfc_printf_vlog(vport, KERN_ERR,
6349 LOG_TRACE_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04006350 "0230 Unexpected timeout, hba link "
6351 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05006352 clrlaerr = 1;
6353 break;
James Smart92d7f7b2007-06-17 19:56:38 -05006354
6355 case LPFC_HBA_READY:
6356 break;
dea31012005-04-17 16:05:31 -05006357 }
6358
6359 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05006360 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08006361 if (phba->sli_rev != LPFC_SLI_REV4) {
6362 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6363 ~LPFC_STOP_IOCB_EVENT;
6364 psli->sli3_ring[LPFC_FCP_RING].flag &=
6365 ~LPFC_STOP_IOCB_EVENT;
6366 }
James Smart2e0fef82007-06-17 19:56:36 -05006367 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05006368 }
dea31012005-04-17 16:05:31 -05006369 return;
6370}
6371
dea31012005-04-17 16:05:31 -05006372/*
6373 * This routine handles processing a NameServer REG_LOGIN mailbox
6374 * command upon completion. It is setup in the LPFC_MBOXQ
6375 * as the completion routine when the command is
6376 * handed off to the SLI layer.
6377 */
6378void
James Smart2e0fef82007-06-17 19:56:36 -05006379lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05006380{
James Smart04c68492009-05-22 14:52:52 -04006381 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006382 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6383 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006384 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05006385
James Smart3e1f0712018-11-29 16:09:29 -08006386 pmb->ctx_buf = NULL;
6387 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05006388
James Smart6d368e52011-05-24 11:44:12 -04006389 if (phba->sli_rev < LPFC_SLI_REV4)
6390 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05006391 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05006392 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05006393 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07006394 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart307e3382020-11-15 11:26:30 -08006395 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04006396 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006397 kref_read(&ndlp->kref),
James Smart307e3382020-11-15 11:26:30 -08006398 ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006399 /*
6400 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05006401 * 0xfffffa (FDMI well known port).
6402 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6403 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05006404 */
James Smarta314dec2021-04-11 18:31:20 -07006405 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6406 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
James Smart4258e982015-12-16 18:11:58 -05006407 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smarta314dec2021-04-11 18:31:20 -07006408 } else {
James Smart4258e982015-12-16 18:11:58 -05006409 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
James Smarta314dec2021-04-11 18:31:20 -07006410 }
James Smart4258e982015-12-16 18:11:58 -05006411
dea31012005-04-17 16:05:31 -05006412
James Smartfa4066b2008-01-11 01:53:27 -05006413 /* decrement the node reference count held for this callback
6414 * function.
6415 */
James Smart329f9bc2007-04-25 09:53:01 -04006416 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006417 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6418 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04006419 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006420
6421 return;
6422}
6423
James Smart685f0bf2007-04-25 09:53:08 -04006424static int
6425lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6426{
6427 uint16_t *rpi = param;
6428
6429 return ndlp->nlp_rpi == *rpi;
6430}
6431
6432static int
6433lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6434{
6435 return memcmp(&ndlp->nlp_portname, param,
6436 sizeof(ndlp->nlp_portname)) == 0;
6437}
6438
Adrian Bunka6ababd2007-11-05 18:07:33 +01006439static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006440__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006441{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006442 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006443
James Smart2e0fef82007-06-17 19:56:36 -05006444 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006445 if (filter(ndlp, param)) {
6446 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006447 "3185 FIND node filter %ps DID "
James Smart32350662019-08-14 16:57:06 -07006448 "ndlp x%px did x%x flg x%x st x%x "
James Smart49382502017-11-20 16:00:38 -08006449 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006450 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006451 ndlp->nlp_flag, ndlp->nlp_state,
6452 ndlp->nlp_xri, ndlp->nlp_type,
6453 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006454 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006455 }
James Smart685f0bf2007-04-25 09:53:08 -04006456 }
James Smart34f5ad82012-08-03 12:35:03 -04006457 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006458 "3186 FIND node filter %ps NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006459 return NULL;
dea31012005-04-17 16:05:31 -05006460}
6461
James Smart685f0bf2007-04-25 09:53:08 -04006462/*
6463 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006464 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006465 */
6466struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006467__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006468{
James Smart2e0fef82007-06-17 19:56:36 -05006469 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006470}
6471
James Smart488d1462006-03-07 15:02:37 -05006472/*
James Smart685f0bf2007-04-25 09:53:08 -04006473 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006474 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006475 */
6476struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006477lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006478{
James Smart2e0fef82007-06-17 19:56:36 -05006479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006480 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006481
James Smart2e0fef82007-06-17 19:56:36 -05006482 spin_lock_irq(shost->host_lock);
6483 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6484 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006485 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006486}
6487
James Smartcb69f7d2011-12-13 13:21:57 -05006488/*
6489 * This routine looks up the ndlp lists for the given RPI. If the rpi
6490 * is found, the routine returns the node element list pointer else
6491 * return NULL.
6492 */
6493struct lpfc_nodelist *
6494lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6495{
6496 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6497 struct lpfc_nodelist *ndlp;
Fuqian Huang78d4b132019-08-12 16:31:34 +08006498 unsigned long flags;
James Smartcb69f7d2011-12-13 13:21:57 -05006499
Fuqian Huang78d4b132019-08-12 16:31:34 +08006500 spin_lock_irqsave(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006501 ndlp = __lpfc_findnode_rpi(vport, rpi);
Fuqian Huang78d4b132019-08-12 16:31:34 +08006502 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006503 return ndlp;
6504}
6505
6506/**
6507 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6508 * @phba: pointer to lpfc hba data structure.
6509 * @vpi: the physical host virtual N_Port identifier.
6510 *
6511 * This routine finds a vport on a HBA (referred by @phba) through a
6512 * @vpi. The function walks the HBA's vport list and returns the address
6513 * of the vport with the matching @vpi.
6514 *
6515 * Return code
6516 * NULL - No vport with the matching @vpi found
6517 * Otherwise - Address to the vport with the matching @vpi.
6518 **/
6519struct lpfc_vport *
6520lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6521{
6522 struct lpfc_vport *vport;
6523 unsigned long flags;
6524 int i = 0;
6525
6526 /* The physical ports are always vpi 0 - translate is unnecessary. */
6527 if (vpi > 0) {
6528 /*
6529 * Translate the physical vpi to the logical vpi. The
6530 * vport stores the logical vpi.
6531 */
James Smart58c36e82021-03-01 09:18:01 -08006532 for (i = 0; i <= phba->max_vpi; i++) {
James Smartcb69f7d2011-12-13 13:21:57 -05006533 if (vpi == phba->vpi_ids[i])
6534 break;
6535 }
6536
James Smart58c36e82021-03-01 09:18:01 -08006537 if (i > phba->max_vpi) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006538 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6539 "2936 Could not find Vport mapped "
6540 "to vpi %d\n", vpi);
James Smartcb69f7d2011-12-13 13:21:57 -05006541 return NULL;
6542 }
6543 }
6544
James Smart523128e2018-09-10 10:30:46 -07006545 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006546 list_for_each_entry(vport, &phba->port_list, listentry) {
6547 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006548 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006549 return vport;
6550 }
6551 }
James Smart523128e2018-09-10 10:30:46 -07006552 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006553 return NULL;
6554}
6555
James Smart9d3d3402017-04-21 16:05:00 -07006556struct lpfc_nodelist *
6557lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006558{
James Smart9d3d3402017-04-21 16:05:00 -07006559 struct lpfc_nodelist *ndlp;
6560 int rpi = LPFC_RPI_ALLOC_ERROR;
6561
6562 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6563 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6564 if (rpi == LPFC_RPI_ALLOC_ERROR)
6565 return NULL;
6566 }
6567
6568 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6569 if (!ndlp) {
6570 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6571 lpfc_sli4_free_rpi(vport->phba, rpi);
6572 return NULL;
6573 }
6574
dea31012005-04-17 16:05:31 -05006575 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006576
James Smartc6adba12020-11-15 11:26:34 -08006577 spin_lock_init(&ndlp->lock);
6578
James Smart109f6ed2008-12-04 22:39:08 -05006579 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006580 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006581 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006582 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07006583 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6584 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
James Smart307e3382020-11-15 11:26:30 -08006585 "flg:x%x refcnt:%d\n",
James Smart0f154222019-09-21 20:58:52 -07006586 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
James Smart307e3382020-11-15 11:26:30 -08006587 ndlp->nlp_flag, kref_read(&ndlp->kref));
James Smartbe6bb942015-04-07 15:07:22 -04006588
James Smartcff261f2013-12-17 20:29:47 -05006589 ndlp->active_rrqs_xri_bitmap =
6590 mempool_alloc(vport->phba->active_rrq_pool,
6591 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006592 if (ndlp->active_rrqs_xri_bitmap)
6593 memset(ndlp->active_rrqs_xri_bitmap, 0,
6594 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006595 }
6596
James Smart725dd392013-10-10 12:23:30 -04006597
James Smart858c9f62007-06-17 19:56:39 -05006598
6599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6600 "node init: did:x%x",
6601 ndlp->nlp_DID, 0, 0);
6602
James Smart9d3d3402017-04-21 16:05:00 -07006603 return ndlp;
dea31012005-04-17 16:05:31 -05006604}
James Smart329f9bc2007-04-25 09:53:01 -04006605
James Smart98c9ea52007-10-27 13:37:33 -04006606/* This routine releases all resources associated with a specifc NPort's ndlp
6607 * and mempool_free's the nodelist.
6608 */
James Smart311464e2007-08-02 11:10:37 -04006609static void
James Smart329f9bc2007-04-25 09:53:01 -04006610lpfc_nlp_release(struct kref *kref)
6611{
6612 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6613 kref);
James Smartc6adba12020-11-15 11:26:34 -08006614 struct lpfc_vport *vport = ndlp->vport;
James Smart858c9f62007-06-17 19:56:39 -05006615
6616 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6617 "node release: did:x%x flg:x%x type:x%x",
6618 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6619
James Smartc6adba12020-11-15 11:26:34 -08006620 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smartf1156122021-04-11 18:31:24 -07006621 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
James Smartc6adba12020-11-15 11:26:34 -08006622 __func__, ndlp, ndlp->nlp_DID,
6623 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006624
6625 /* remove ndlp from action. */
James Smartc6adba12020-11-15 11:26:34 -08006626 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6627 lpfc_cleanup_node(vport, ndlp);
6628
James Smart01131e72021-05-14 12:55:49 -07006629 /* Not all ELS transactions have registered the RPI with the port.
6630 * In these cases the rpi usage is temporary and the node is
6631 * released when the WQE is completed. Catch this case to free the
6632 * RPI to the pool. Because this node is in the release path, a lock
6633 * is unnecessary. All references are gone and the node has been
6634 * dequeued.
6635 */
6636 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6637 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6638 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6639 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6640 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6641 }
6642 }
6643
6644 /* The node is not freed back to memory, it is released to a pool so
6645 * the node fields need to be cleaned up.
James Smartc6adba12020-11-15 11:26:34 -08006646 */
6647 ndlp->vport = NULL;
6648 ndlp->nlp_state = NLP_STE_FREED_NODE;
6649 ndlp->nlp_flag = 0;
6650 ndlp->fc4_xpt_flags = 0;
James Smarte47c9092008-02-08 18:49:26 -05006651
James Smarte47c9092008-02-08 18:49:26 -05006652 /* free ndlp memory for final ndlp release */
James Smart307e3382020-11-15 11:26:30 -08006653 kfree(ndlp->lat_data);
6654 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6655 mempool_free(ndlp->active_rrqs_xri_bitmap,
6656 ndlp->phba->active_rrq_pool);
6657 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04006658}
6659
James Smart98c9ea52007-10-27 13:37:33 -04006660/* This routine bumps the reference count for a ndlp structure to ensure
6661 * that one discovery thread won't free a ndlp while another discovery thread
6662 * is using it.
6663 */
James Smart329f9bc2007-04-25 09:53:01 -04006664struct lpfc_nodelist *
6665lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6666{
James Smarte47c9092008-02-08 18:49:26 -05006667 unsigned long flags;
6668
James Smart98c9ea52007-10-27 13:37:33 -04006669 if (ndlp) {
6670 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6671 "node get: did:x%x flg:x%x refcnt:x%x",
6672 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006673 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006674
James Smarte47c9092008-02-08 18:49:26 -05006675 /* The check of ndlp usage to prevent incrementing the
6676 * ndlp reference count that is in the process of being
6677 * released.
6678 */
James Smartc6adba12020-11-15 11:26:34 -08006679 spin_lock_irqsave(&ndlp->lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006680 if (!kref_get_unless_zero(&ndlp->kref)) {
James Smartc6adba12020-11-15 11:26:34 -08006681 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smarte47c9092008-02-08 18:49:26 -05006682 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart307e3382020-11-15 11:26:30 -08006683 "0276 %s: ndlp:x%px refcnt:%d\n",
6684 __func__, (void *)ndlp, kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006685 return NULL;
James Smart307e3382020-11-15 11:26:30 -08006686 }
James Smartc6adba12020-11-15 11:26:34 -08006687 spin_unlock_irqrestore(&ndlp->lock, flags);
James Smart307e3382020-11-15 11:26:30 -08006688 } else {
6689 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006690 }
James Smart307e3382020-11-15 11:26:30 -08006691
James Smart329f9bc2007-04-25 09:53:01 -04006692 return ndlp;
6693}
6694
James Smart98c9ea52007-10-27 13:37:33 -04006695/* This routine decrements the reference count for a ndlp structure. If the
James Smart307e3382020-11-15 11:26:30 -08006696 * count goes to 0, this indicates the associated nodelist should be freed.
James Smart98c9ea52007-10-27 13:37:33 -04006697 */
James Smart329f9bc2007-04-25 09:53:01 -04006698int
6699lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6700{
James Smart307e3382020-11-15 11:26:30 -08006701 if (ndlp) {
6702 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6703 "node put: did:x%x flg:x%x refcnt:x%x",
6704 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006705 kref_read(&ndlp->kref));
James Smart307e3382020-11-15 11:26:30 -08006706 } else {
6707 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
James Smart98c9ea52007-10-27 13:37:33 -04006708 }
James Smart307e3382020-11-15 11:26:30 -08006709
6710 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
James Smart329f9bc2007-04-25 09:53:01 -04006711}
James Smart98c9ea52007-10-27 13:37:33 -04006712
6713/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006714 * by any other discovery thread. This routine returns 1 if the
6715 * ndlp has been freed. A return value of 0 indicates the ndlp is
6716 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006717 */
6718int
6719lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6720{
6721 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6722 "node not used: did:x%x flg:x%x refcnt:x%x",
6723 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006724 kref_read(&ndlp->kref));
James Smart01131e72021-05-14 12:55:49 -07006725
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006726 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006727 if (lpfc_nlp_put(ndlp))
6728 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006729 return 0;
6730}
James Smart6fb120a2009-05-22 14:52:59 -04006731
6732/**
6733 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6734 * @phba: Pointer to hba context object.
6735 *
6736 * This function iterate through all FC nodes associated
6737 * will all vports to check if there is any node with
6738 * fc_rports associated with it. If there is an fc_rport
6739 * associated with the node, then the node is either in
6740 * discovered state or its devloss_timer is pending.
6741 */
6742static int
6743lpfc_fcf_inuse(struct lpfc_hba *phba)
6744{
6745 struct lpfc_vport **vports;
6746 int i, ret = 0;
6747 struct lpfc_nodelist *ndlp;
6748 struct Scsi_Host *shost;
6749
6750 vports = lpfc_create_vport_work_array(phba);
6751
James Smart63e801c2010-11-20 23:14:19 -05006752 /* If driver cannot allocate memory, indicate fcf is in use */
6753 if (!vports)
6754 return 1;
6755
James Smart6fb120a2009-05-22 14:52:59 -04006756 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6757 shost = lpfc_shost_from_vport(vports[i]);
6758 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006759 /*
6760 * IF the CVL_RCVD bit is not set then we have sent the
6761 * flogi.
6762 * If dev_loss fires while we are waiting we do not want to
6763 * unreg the fcf.
6764 */
6765 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6766 spin_unlock_irq(shost->host_lock);
6767 ret = 1;
6768 goto out;
6769 }
James Smart6fb120a2009-05-22 14:52:59 -04006770 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart307e3382020-11-15 11:26:30 -08006771 if (ndlp->rport &&
James Smart6fb120a2009-05-22 14:52:59 -04006772 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6773 ret = 1;
6774 spin_unlock_irq(shost->host_lock);
6775 goto out;
James Smart80c17842012-03-01 22:35:45 -05006776 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6777 ret = 1;
James Smart0f154222019-09-21 20:58:52 -07006778 lpfc_printf_log(phba, KERN_INFO,
6779 LOG_NODE | LOG_DISCOVERY,
James Smart80c17842012-03-01 22:35:45 -05006780 "2624 RPI %x DID %x flag %x "
6781 "still logged in\n",
6782 ndlp->nlp_rpi, ndlp->nlp_DID,
6783 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006784 }
6785 }
6786 spin_unlock_irq(shost->host_lock);
6787 }
6788out:
6789 lpfc_destroy_vport_work_array(phba, vports);
6790 return ret;
6791}
6792
6793/**
6794 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6795 * @phba: Pointer to hba context object.
6796 * @mboxq: Pointer to mailbox object.
6797 *
6798 * This function frees memory associated with the mailbox command.
6799 */
James Smart1b511972011-12-13 13:23:09 -05006800void
James Smart6fb120a2009-05-22 14:52:59 -04006801lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6802{
6803 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006804 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006805
6806 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006807 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6808 "2555 UNREG_VFI mbxStatus error x%x "
6809 "HBA state x%x\n",
6810 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006811 }
James Smart38b92ef2010-08-04 16:11:39 -04006812 spin_lock_irq(shost->host_lock);
6813 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6814 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006815 mempool_free(mboxq, phba->mbox_mem_pool);
6816 return;
6817}
6818
6819/**
6820 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6821 * @phba: Pointer to hba context object.
6822 * @mboxq: Pointer to mailbox object.
6823 *
6824 * This function frees memory associated with the mailbox command.
6825 */
6826static void
6827lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6828{
6829 struct lpfc_vport *vport = mboxq->vport;
6830
6831 if (mboxq->u.mb.mbxStatus) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006832 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6833 "2550 UNREG_FCFI mbxStatus error x%x "
6834 "HBA state x%x\n",
6835 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04006836 }
6837 mempool_free(mboxq, phba->mbox_mem_pool);
6838 return;
6839}
6840
6841/**
James Smartecfd03c2010-02-12 14:41:27 -05006842 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006843 * @phba: Pointer to hba context object.
6844 *
James Smartecfd03c2010-02-12 14:41:27 -05006845 * This function prepare the HBA for unregistering the currently registered
6846 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6847 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006848 */
James Smartecfd03c2010-02-12 14:41:27 -05006849int
6850lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006851{
James Smart6fb120a2009-05-22 14:52:59 -04006852 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006853 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006854 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006855 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006856
James Smartecfd03c2010-02-12 14:41:27 -05006857 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006858 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006859 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006860
James Smart4d9ab992009-10-02 15:16:39 -04006861 /* At this point, all discovery is aborted */
6862 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006863
6864 /* Unregister VPIs */
6865 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006866 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006867 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006868 /* Stop FLOGI/FDISC retries */
6869 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6870 if (ndlp)
6871 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006872 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006873 if (phba->sli_rev == LPFC_SLI_REV4)
6874 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006875 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006876 shost = lpfc_shost_from_vport(vports[i]);
6877 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006878 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006879 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006880 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006881 }
6882 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006883 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6884 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6885 if (ndlp)
6886 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6887 lpfc_cleanup_pending_mbox(phba->pport);
6888 if (phba->sli_rev == LPFC_SLI_REV4)
6889 lpfc_sli4_unreg_all_rpis(phba->pport);
6890 lpfc_mbx_unreg_vpi(phba->pport);
6891 shost = lpfc_shost_from_vport(phba->pport);
6892 spin_lock_irq(shost->host_lock);
6893 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6894 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6895 spin_unlock_irq(shost->host_lock);
6896 }
James Smart6fb120a2009-05-22 14:52:59 -04006897
James Smart695a8142010-01-26 23:08:03 -05006898 /* Cleanup any outstanding ELS commands */
6899 lpfc_els_flush_all_cmd(phba);
6900
James Smart1b511972011-12-13 13:23:09 -05006901 /* Unregister the physical port VFI */
6902 rc = lpfc_issue_unreg_vfi(phba->pport);
6903 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006904}
6905
6906/**
6907 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6908 * @phba: Pointer to hba context object.
6909 *
6910 * This function issues synchronous unregister FCF mailbox command to HBA to
6911 * unregister the currently registered FCF record. The driver does not reset
6912 * the driver FCF usage state flags.
6913 *
6914 * Return 0 if successfully issued, none-zero otherwise.
6915 */
6916int
6917lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6918{
6919 LPFC_MBOXQ_t *mbox;
6920 int rc;
6921
James Smart6fb120a2009-05-22 14:52:59 -04006922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6923 if (!mbox) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006924 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006925 "2551 UNREG_FCFI mbox allocation failed"
6926 "HBA state x%x\n", phba->pport->port_state);
6927 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006928 }
James Smart6fb120a2009-05-22 14:52:59 -04006929 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6930 mbox->vport = phba->pport;
6931 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6932 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6933
6934 if (rc == MBX_NOT_FINISHED) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006935 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006936 "2552 Unregister FCFI command failed rc x%x "
6937 "HBA state x%x\n",
6938 rc, phba->pport->port_state);
6939 return -EINVAL;
6940 }
6941 return 0;
6942}
6943
6944/**
6945 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6946 * @phba: Pointer to hba context object.
6947 *
6948 * This function unregisters the currently reigstered FCF. This function
6949 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6950 */
6951void
6952lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6953{
6954 int rc;
6955
6956 /* Preparation for unregistering fcf */
6957 rc = lpfc_unregister_fcf_prep(phba);
6958 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07006959 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006960 "2748 Failed to prepare for unregistering "
6961 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006962 return;
6963 }
6964
James Smartecfd03c2010-02-12 14:41:27 -05006965 /* Now, unregister FCF record and reset HBA FCF state */
6966 rc = lpfc_sli4_unregister_fcf(phba);
6967 if (rc)
6968 return;
6969 /* Reset HBA FCF states after successful unregister FCF */
6970 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006971 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006972
6973 /*
6974 * If driver is not unloading, check if there is any other
6975 * FCF record that can be used for discovery.
6976 */
6977 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006978 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006979 return;
6980
James Smart0c9ab6f2010-02-26 14:15:57 -05006981 /* This is considered as the initial FCF discovery scan */
6982 spin_lock_irq(&phba->hbalock);
6983 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6984 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006985
6986 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006987 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006988
James Smart0c9ab6f2010-02-26 14:15:57 -05006989 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006990
James Smart0c9ab6f2010-02-26 14:15:57 -05006991 if (rc) {
6992 spin_lock_irq(&phba->hbalock);
6993 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6994 spin_unlock_irq(&phba->hbalock);
Dick Kennedy372c1872020-06-30 14:50:00 -07006995 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05006996 "2553 lpfc_unregister_unused_fcf failed "
6997 "to read FCF record HBA state x%x\n",
6998 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006999 }
James Smartecfd03c2010-02-12 14:41:27 -05007000}
7001
7002/**
7003 * lpfc_unregister_fcf - Unregister the currently registered fcf record
7004 * @phba: Pointer to hba context object.
7005 *
7006 * This function just unregisters the currently reigstered FCF. It does not
7007 * try to find another FCF for discovery.
7008 */
7009void
7010lpfc_unregister_fcf(struct lpfc_hba *phba)
7011{
7012 int rc;
7013
7014 /* Preparation for unregistering fcf */
7015 rc = lpfc_unregister_fcf_prep(phba);
7016 if (rc) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007017 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smartecfd03c2010-02-12 14:41:27 -05007018 "2749 Failed to prepare for unregistering "
7019 "HBA's FCF record: rc=%d\n", rc);
7020 return;
7021 }
7022
7023 /* Now, unregister FCF record and reset HBA FCF state */
7024 rc = lpfc_sli4_unregister_fcf(phba);
7025 if (rc)
7026 return;
7027 /* Set proper HBA FCF states after successful unregister FCF */
7028 spin_lock_irq(&phba->hbalock);
7029 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7030 spin_unlock_irq(&phba->hbalock);
7031}
7032
7033/**
7034 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7035 * @phba: Pointer to hba context object.
7036 *
7037 * This function check if there are any connected remote port for the FCF and
7038 * if all the devices are disconnected, this function unregister FCFI.
7039 * This function also tries to use another FCF for discovery.
7040 */
7041void
7042lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7043{
7044 /*
James Smart3804dc82010-07-14 15:31:37 -04007045 * If HBA is not running in FIP mode, if HBA does not support
7046 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7047 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05007048 */
7049 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05007050 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05007051 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04007052 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04007053 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04007054 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05007055 spin_unlock_irq(&phba->hbalock);
7056 return;
7057 }
7058 spin_unlock_irq(&phba->hbalock);
7059
7060 if (lpfc_fcf_inuse(phba))
7061 return;
7062
7063 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007064}
7065
7066/**
7067 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7068 * @phba: Pointer to hba context object.
7069 * @buff: Buffer containing the FCF connection table as in the config
7070 * region.
7071 * This function create driver data structure for the FCF connection
7072 * record table read from config region 23.
7073 */
7074static void
7075lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7076 uint8_t *buff)
7077{
7078 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7079 struct lpfc_fcf_conn_hdr *conn_hdr;
7080 struct lpfc_fcf_conn_rec *conn_rec;
7081 uint32_t record_count;
7082 int i;
7083
7084 /* Free the current connect table */
7085 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04007086 &phba->fcf_conn_rec_list, list) {
7087 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007088 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04007089 }
James Smart6fb120a2009-05-22 14:52:59 -04007090
7091 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7092 record_count = conn_hdr->length * sizeof(uint32_t)/
7093 sizeof(struct lpfc_fcf_conn_rec);
7094
7095 conn_rec = (struct lpfc_fcf_conn_rec *)
7096 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7097
7098 for (i = 0; i < record_count; i++) {
7099 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7100 continue;
7101 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7102 GFP_KERNEL);
7103 if (!conn_entry) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007104 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7105 "2566 Failed to allocate connection"
7106 " table entry\n");
James Smart6fb120a2009-05-22 14:52:59 -04007107 return;
7108 }
7109
7110 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7111 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04007112 list_add_tail(&conn_entry->list,
7113 &phba->fcf_conn_rec_list);
7114 }
James Smartdf0d0852013-05-31 17:05:08 -04007115
7116 if (!list_empty(&phba->fcf_conn_rec_list)) {
7117 i = 0;
7118 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7119 list) {
7120 conn_rec = &conn_entry->conn_rec;
7121 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7122 "3345 FCF connection list rec[%02d]: "
7123 "flags:x%04x, vtag:x%04x, "
7124 "fabric_name:x%02x:%02x:%02x:%02x:"
7125 "%02x:%02x:%02x:%02x, "
7126 "switch_name:x%02x:%02x:%02x:%02x:"
7127 "%02x:%02x:%02x:%02x\n", i++,
7128 conn_rec->flags, conn_rec->vlan_tag,
7129 conn_rec->fabric_name[0],
7130 conn_rec->fabric_name[1],
7131 conn_rec->fabric_name[2],
7132 conn_rec->fabric_name[3],
7133 conn_rec->fabric_name[4],
7134 conn_rec->fabric_name[5],
7135 conn_rec->fabric_name[6],
7136 conn_rec->fabric_name[7],
7137 conn_rec->switch_name[0],
7138 conn_rec->switch_name[1],
7139 conn_rec->switch_name[2],
7140 conn_rec->switch_name[3],
7141 conn_rec->switch_name[4],
7142 conn_rec->switch_name[5],
7143 conn_rec->switch_name[6],
7144 conn_rec->switch_name[7]);
7145 }
7146 }
James Smart6fb120a2009-05-22 14:52:59 -04007147}
7148
7149/**
7150 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7151 * @phba: Pointer to hba context object.
7152 * @buff: Buffer containing the FCoE parameter data structure.
7153 *
7154 * This function update driver data structure with config
7155 * parameters read from config region 23.
7156 */
7157static void
7158lpfc_read_fcoe_param(struct lpfc_hba *phba,
7159 uint8_t *buff)
7160{
7161 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7162 struct lpfc_fcoe_params *fcoe_param;
7163
7164 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7165 buff;
7166 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04007167 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04007168
7169 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7170 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7171 return;
7172
James Smart6fb120a2009-05-22 14:52:59 -04007173 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7174 phba->valid_vlan = 1;
7175 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7176 0xFFF;
7177 }
7178
7179 phba->fc_map[0] = fcoe_param->fc_map[0];
7180 phba->fc_map[1] = fcoe_param->fc_map[1];
7181 phba->fc_map[2] = fcoe_param->fc_map[2];
7182 return;
7183}
7184
7185/**
7186 * lpfc_get_rec_conf23 - Get a record type in config region data.
7187 * @buff: Buffer containing config region 23 data.
7188 * @size: Size of the data buffer.
7189 * @rec_type: Record type to be searched.
7190 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007191 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04007192 * of the record specified by record_type. If record found, this
7193 * function return pointer to the record else return NULL.
7194 */
7195static uint8_t *
7196lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7197{
7198 uint32_t offset = 0, rec_length;
7199
7200 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7201 (size < sizeof(uint32_t)))
7202 return NULL;
7203
7204 rec_length = buff[offset + 1];
7205
7206 /*
7207 * One TLV record has one word header and number of data words
7208 * specified in the rec_length field of the record header.
7209 */
7210 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7211 <= size) {
7212 if (buff[offset] == rec_type)
7213 return &buff[offset];
7214
7215 if (buff[offset] == LPFC_REGION23_LAST_REC)
7216 return NULL;
7217
7218 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7219 rec_length = buff[offset + 1];
7220 }
7221 return NULL;
7222}
7223
7224/**
7225 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7226 * @phba: Pointer to lpfc_hba data structure.
7227 * @buff: Buffer containing config region 23 data.
7228 * @size: Size of the data buffer.
7229 *
Stefan Weileef35c22010-08-06 21:11:15 +02007230 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04007231 * populate driver data structure with the parameters.
7232 */
7233void
7234lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7235 uint8_t *buff,
7236 uint32_t size)
7237{
James Smarteb016562014-09-03 12:58:06 -04007238 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04007239 uint8_t *rec_ptr;
7240
7241 /*
7242 * If data size is less than 2 words signature and version cannot be
7243 * verified.
7244 */
7245 if (size < 2*sizeof(uint32_t))
7246 return;
7247
7248 /* Check the region signature first */
7249 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007250 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
James Smart6fb120a2009-05-22 14:52:59 -04007251 "2567 Config region 23 has bad signature\n");
7252 return;
7253 }
7254
7255 offset += 4;
7256
7257 /* Check the data structure version */
7258 if (buff[offset] != LPFC_REGION23_VERSION) {
Dick Kennedy372c1872020-06-30 14:50:00 -07007259 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7260 "2568 Config region 23 has bad version\n");
James Smart6fb120a2009-05-22 14:52:59 -04007261 return;
7262 }
7263 offset += 4;
7264
James Smart6fb120a2009-05-22 14:52:59 -04007265 /* Read FCoE param record */
7266 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7267 size - offset, FCOE_PARAM_TYPE);
7268 if (rec_ptr)
7269 lpfc_read_fcoe_param(phba, rec_ptr);
7270
7271 /* Read FCF connection table */
7272 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7273 size - offset, FCOE_CONN_TBL_TYPE);
7274 if (rec_ptr)
7275 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
7276
7277}