blob: f5952f8cd4b56290504a53776b3ad8e524954386 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart145e5a82020-01-27 16:23:12 -08004 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
James Smarta93ff372010-10-22 11:06:08 -040025#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/pci.h>
28#include <linux/kthread.h>
29#include <linux/interrupt.h>
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +010030#include <linux/lockdep.h>
James Smarte3ba04c2019-12-18 15:58:02 -080031#include <linux/utsname.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_transport_fc.h>
James Smarta0f2d3e2017-02-12 13:52:31 -080037#include <scsi/fc/fc_fs.h>
38
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040041#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050042#include "lpfc_disc.h"
43#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040044#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080046#include "lpfc_scsi.h"
47#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc_logmsg.h"
49#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050050#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050051#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050052
53/* AlpaArray for assignment of scsid for scan-down and bind_method */
54static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
68};
69
James Smart2e0fef82007-06-17 19:56:36 -050070static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010071static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040072static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040073static int lpfc_fcf_inuse(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050074
James Smartc01f3202006-08-18 17:47:08 -040075void
76lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050077{
James Smartc01f3202006-08-18 17:47:08 -040078 struct lpfc_rport_data *rdata;
79 struct lpfc_nodelist * ndlp;
80 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050081
James Smartc01f3202006-08-18 17:47:08 -040082 rdata = rport->dd_data;
83 ndlp = rdata->pnode;
84
James Smart58da1ff2008-04-07 10:15:56 -040085 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040086 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
87 printk(KERN_ERR "Cannot find remote node"
88 " to terminate I/O Data x%x\n",
89 rport->port_id);
dea31012005-04-17 16:05:31 -050090 return;
91 }
92
James Smarta257bf92009-04-06 18:48:10 -040093 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050094
James Smart858c9f62007-06-17 19:56:39 -050095 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
96 "rport terminate: sid:x%x did:x%x flg:x%x",
97 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
98
James Smartc01f3202006-08-18 17:47:08 -040099 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -0400100 lpfc_sli_abort_iocb(ndlp->vport,
James Smart895427b2017-02-12 13:52:30 -0800101 &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400102 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -0400103 }
James Smartc01f3202006-08-18 17:47:08 -0400104}
105
106/*
107 * This function will be called when dev_loss_tmo fire.
108 */
109void
110lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
111{
112 struct lpfc_rport_data *rdata;
113 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500114 struct lpfc_vport *vport;
James Smart466e8402015-05-21 13:55:28 -0400115 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500116 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500117 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400118 int put_node;
119 int put_rport;
James Smart894bb172019-08-14 16:56:52 -0700120 unsigned long iflags;
James Smartc01f3202006-08-18 17:47:08 -0400121
122 rdata = rport->dd_data;
123 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400124 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400125 return;
James Smartc01f3202006-08-18 17:47:08 -0400126
James Smart858c9f62007-06-17 19:56:39 -0500127 vport = ndlp->vport;
128 phba = vport->phba;
129
130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
131 "rport devlosscb: sid:x%x did:x%x flg:x%x",
132 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
133
James Smart34f5ad82012-08-03 12:35:03 -0400134 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -0700135 "3181 dev_loss_callbk x%06x, rport x%px flg x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -0400136 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
137
James Smarta8adb832007-10-27 13:37:53 -0400138 /* Don't defer this if we are in the process of deleting the vport
139 * or unloading the driver. The unload will cleanup the node
140 * appropriately we just need to cleanup the ndlp rport info here.
141 */
142 if (vport->load_flag & FC_UNLOADING) {
143 put_node = rdata->pnode != NULL;
144 put_rport = ndlp->rport != NULL;
145 rdata->pnode = NULL;
146 ndlp->rport = NULL;
147 if (put_node)
148 lpfc_nlp_put(ndlp);
149 if (put_rport)
150 put_device(&rport->dev);
151 return;
152 }
153
154 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
155 return;
156
James Smart466e8402015-05-21 13:55:28 -0400157 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
158 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
159 "6789 rport name %llx != node port name %llx",
160 rport->port_name,
161 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400162
James Smart858c9f62007-06-17 19:56:39 -0500163 evtp = &ndlp->dev_loss_evt;
164
James Smart466e8402015-05-21 13:55:28 -0400165 if (!list_empty(&evtp->evt_listp)) {
166 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
167 "6790 rport name %llx dev_loss_evt pending",
168 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500169 return;
James Smart466e8402015-05-21 13:55:28 -0400170 }
James Smart858c9f62007-06-17 19:56:39 -0500171
James Smart466e8402015-05-21 13:55:28 -0400172 shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -0700173 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400174 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700175 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smarta62a4352013-04-17 20:18:19 -0400176
James Smartfa4066b2008-01-11 01:53:27 -0500177 /* We need to hold the node by incrementing the reference
178 * count until this queued work is done
179 */
James Smart466e8402015-05-21 13:55:28 -0400180 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
181
James Smart894bb172019-08-14 16:56:52 -0700182 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5e9d9b82008-06-14 22:52:53 -0400183 if (evtp->evt_arg1) {
184 evtp->evt = LPFC_EVT_DEV_LOSS;
185 list_add_tail(&evtp->evt_listp, &phba->work_list);
186 lpfc_worker_wake_up(phba);
187 }
James Smart894bb172019-08-14 16:56:52 -0700188 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500189
James Smart858c9f62007-06-17 19:56:39 -0500190 return;
191}
192
James Smarta93ff372010-10-22 11:06:08 -0400193/**
194 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
195 * @ndlp: Pointer to remote node object.
196 *
197 * This function is called from the worker thread when devloss timeout timer
198 * expires. For SLI4 host, this routine shall return 1 when at lease one
199 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
200 * routine shall return 0 when there is no remote node is still in use of FCF
201 * when devloss timeout happened to this @ndlp.
202 **/
203static int
James Smart858c9f62007-06-17 19:56:39 -0500204lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
205{
206 struct lpfc_rport_data *rdata;
207 struct fc_rport *rport;
208 struct lpfc_vport *vport;
209 struct lpfc_hba *phba;
James Smart466e8402015-05-21 13:55:28 -0400210 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500211 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400212 int put_node;
James Smart858c9f62007-06-17 19:56:39 -0500213 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400214 int fcf_inuse = 0;
James Smart894bb172019-08-14 16:56:52 -0700215 unsigned long iflags;
James Smart858c9f62007-06-17 19:56:39 -0500216
217 rport = ndlp->rport;
James Smart858c9f62007-06-17 19:56:39 -0500218 vport = ndlp->vport;
James Smart466e8402015-05-21 13:55:28 -0400219 shost = lpfc_shost_from_vport(vport);
220
James Smart894bb172019-08-14 16:56:52 -0700221 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400222 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700223 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400224
225 if (!rport)
226 return fcf_inuse;
227
228 name = (uint8_t *) &ndlp->nlp_portname;
James Smart858c9f62007-06-17 19:56:39 -0500229 phba = vport->phba;
230
James Smarta93ff372010-10-22 11:06:08 -0400231 if (phba->sli_rev == LPFC_SLI_REV4)
232 fcf_inuse = lpfc_fcf_inuse(phba);
233
James Smart858c9f62007-06-17 19:56:39 -0500234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
235 "rport devlosstmo:did:x%x type:x%x id:x%x",
236 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
237
James Smart34f5ad82012-08-03 12:35:03 -0400238 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -0700239 "3182 dev_loss_tmo_handler x%06x, rport x%px flg x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -0400240 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
241
James Smart466e8402015-05-21 13:55:28 -0400242 /*
243 * lpfc_nlp_remove if reached with dangling rport drops the
244 * reference. To make sure that does not happen clear rport
245 * pointer in ndlp before lpfc_nlp_put.
246 */
247 rdata = rport->dd_data;
248
James Smarta8adb832007-10-27 13:37:53 -0400249 /* Don't defer this if we are in the process of deleting the vport
250 * or unloading the driver. The unload will cleanup the node
251 * appropriately we just need to cleanup the ndlp rport info here.
252 */
253 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500254 if (ndlp->nlp_sid != NLP_NO_SID) {
255 /* flush the target */
256 lpfc_sli_abort_iocb(vport,
James Smart895427b2017-02-12 13:52:30 -0800257 &phba->sli.sli3_ring[LPFC_FCP_RING],
258 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smart09372822008-01-11 01:52:54 -0500259 }
James Smarta8adb832007-10-27 13:37:53 -0400260 put_node = rdata->pnode != NULL;
James Smarta8adb832007-10-27 13:37:53 -0400261 rdata->pnode = NULL;
262 ndlp->rport = NULL;
263 if (put_node)
264 lpfc_nlp_put(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400265 put_device(&rport->dev);
266
James Smarta93ff372010-10-22 11:06:08 -0400267 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400268 }
269
James Smartd7c255b2008-08-24 21:50:00 -0400270 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
271 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
272 "0284 Devloss timeout Ignored on "
273 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
274 "NPort x%x\n",
275 *name, *(name+1), *(name+2), *(name+3),
276 *(name+4), *(name+5), *(name+6), *(name+7),
277 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400278 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400279 }
James Smart858c9f62007-06-17 19:56:39 -0500280
James Smart466e8402015-05-21 13:55:28 -0400281 put_node = rdata->pnode != NULL;
282 rdata->pnode = NULL;
283 ndlp->rport = NULL;
284 if (put_node)
285 lpfc_nlp_put(ndlp);
286 put_device(&rport->dev);
287
288 if (ndlp->nlp_type & NLP_FABRIC)
James Smarta93ff372010-10-22 11:06:08 -0400289 return fcf_inuse;
James Smart82085712007-04-25 09:52:41 -0400290
dea31012005-04-17 16:05:31 -0500291 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400292 warn_on = 1;
James Smart895427b2017-02-12 13:52:30 -0800293 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400294 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500295 }
James Smartc01f3202006-08-18 17:47:08 -0400296
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400297 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400298 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
299 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400300 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
301 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400302 *name, *(name+1), *(name+2), *(name+3),
303 *(name+4), *(name+5), *(name+6), *(name+7),
304 ndlp->nlp_DID, ndlp->nlp_flag,
305 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400306 } else {
James Smarte8b62012007-08-02 11:10:09 -0400307 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
308 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400309 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
310 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400311 *name, *(name+1), *(name+2), *(name+3),
312 *(name+4), *(name+5), *(name+6), *(name+7),
313 ndlp->nlp_DID, ndlp->nlp_flag,
314 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400315 }
316
James Smart2ade92a2017-03-04 09:30:38 -0800317 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400318 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400319 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400320 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
321 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500322 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400323
James Smarta93ff372010-10-22 11:06:08 -0400324 return fcf_inuse;
325}
326
327/**
328 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
329 * @phba: Pointer to hba context object.
330 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
331 * @nlp_did: remote node identifer with devloss timeout.
332 *
333 * This function is called from the worker thread after invoking devloss
334 * timeout handler and releasing the reference count for the ndlp with
335 * which the devloss timeout was handled for SLI4 host. For the devloss
336 * timeout of the last remote node which had been in use of FCF, when this
337 * routine is invoked, it shall be guaranteed that none of the remote are
338 * in-use of FCF. When devloss timeout to the last remote using the FCF,
339 * if the FIP engine is neither in FCF table scan process nor roundrobin
340 * failover process, the in-use FCF shall be unregistered. If the FIP
341 * engine is in FCF discovery process, the devloss timeout state shall
342 * be set for either the FCF table scan process or roundrobin failover
343 * process to unregister the in-use FCF.
344 **/
345static void
346lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
347 uint32_t nlp_did)
348{
349 /* If devloss timeout happened to a remote node when FCF had no
350 * longer been in-use, do nothing.
351 */
352 if (!fcf_inuse)
353 return;
354
355 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
356 spin_lock_irq(&phba->hbalock);
357 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
358 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
359 spin_unlock_irq(&phba->hbalock);
360 return;
361 }
362 phba->hba_flag |= HBA_DEVLOSS_TMO;
363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
364 "2847 Last remote node (x%x) using "
365 "FCF devloss tmo\n", nlp_did);
366 }
367 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
368 spin_unlock_irq(&phba->hbalock);
369 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
370 "2868 Devloss tmo to FCF rediscovery "
371 "in progress\n");
372 return;
373 }
374 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
375 spin_unlock_irq(&phba->hbalock);
376 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
377 "2869 Devloss tmo to idle FIP engine, "
378 "unreg in-use FCF and rescan.\n");
379 /* Unregister in-use FCF and rescan */
380 lpfc_unregister_fcf_rescan(phba);
381 return;
382 }
383 spin_unlock_irq(&phba->hbalock);
384 if (phba->hba_flag & FCF_TS_INPROG)
385 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
386 "2870 FCF table scan in progress\n");
387 if (phba->hba_flag & FCF_RR_INPROG)
388 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
389 "2871 FLOGI roundrobin FCF failover "
390 "in progress\n");
391 }
James Smart6fb120a2009-05-22 14:52:59 -0400392 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500393}
James Smartc01f3202006-08-18 17:47:08 -0400394
James Smartea2151b2008-09-07 11:52:10 -0400395/**
James Smart3621a712009-04-06 18:47:14 -0400396 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400397 * @phba: Pointer to hba context object.
398 *
399 * This function is called from the functions which need to post
400 * events from interrupt context. This function allocates data
401 * structure required for posting event. It also keeps track of
402 * number of events pending and prevent event storm when there are
403 * too many events.
404 **/
405struct lpfc_fast_path_event *
406lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
407 struct lpfc_fast_path_event *ret;
408
409 /* If there are lot of fast event do not exhaust memory due to this */
410 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
411 return NULL;
412
413 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
414 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400415 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400416 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400417 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
418 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
419 }
James Smartea2151b2008-09-07 11:52:10 -0400420 return ret;
421}
422
423/**
James Smart3621a712009-04-06 18:47:14 -0400424 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400425 * @phba: Pointer to hba context object.
426 * @evt: Event object which need to be freed.
427 *
428 * This function frees the data structure required for posting
429 * events.
430 **/
431void
432lpfc_free_fast_evt(struct lpfc_hba *phba,
433 struct lpfc_fast_path_event *evt) {
434
435 atomic_dec(&phba->fast_event_count);
436 kfree(evt);
437}
438
439/**
James Smart3621a712009-04-06 18:47:14 -0400440 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400441 * @phba: Pointer to hba context object.
442 * @evtp: Event data structure.
443 *
444 * This function is called from worker thread, when the interrupt
445 * context need to post an event. This function posts the event
446 * to fc transport netlink interface.
447 **/
448static void
449lpfc_send_fastpath_evt(struct lpfc_hba *phba,
450 struct lpfc_work_evt *evtp)
451{
452 unsigned long evt_category, evt_sub_category;
453 struct lpfc_fast_path_event *fast_evt_data;
454 char *evt_data;
455 uint32_t evt_data_size;
456 struct Scsi_Host *shost;
457
458 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
459 work_evt);
460
461 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
462 evt_sub_category = (unsigned long) fast_evt_data->un.
463 fabric_evt.subcategory;
464 shost = lpfc_shost_from_vport(fast_evt_data->vport);
465 if (evt_category == FC_REG_FABRIC_EVENT) {
466 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
467 evt_data = (char *) &fast_evt_data->un.read_check_error;
468 evt_data_size = sizeof(fast_evt_data->un.
469 read_check_error);
470 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500471 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400472 evt_data = (char *) &fast_evt_data->un.fabric_evt;
473 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
474 } else {
475 lpfc_free_fast_evt(phba, fast_evt_data);
476 return;
477 }
478 } else if (evt_category == FC_REG_SCSI_EVENT) {
479 switch (evt_sub_category) {
480 case LPFC_EVENT_QFULL:
481 case LPFC_EVENT_DEVBSY:
482 evt_data = (char *) &fast_evt_data->un.scsi_evt;
483 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
484 break;
485 case LPFC_EVENT_CHECK_COND:
486 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
487 evt_data_size = sizeof(fast_evt_data->un.
488 check_cond_evt);
489 break;
490 case LPFC_EVENT_VARQUEDEPTH:
491 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
492 evt_data_size = sizeof(fast_evt_data->un.
493 queue_depth_evt);
494 break;
495 default:
496 lpfc_free_fast_evt(phba, fast_evt_data);
497 return;
498 }
499 } else {
500 lpfc_free_fast_evt(phba, fast_evt_data);
501 return;
502 }
503
James Smart895427b2017-02-12 13:52:30 -0800504 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
505 fc_host_post_vendor_event(shost,
506 fc_get_event_number(),
507 evt_data_size,
508 evt_data,
509 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400510
511 lpfc_free_fast_evt(phba, fast_evt_data);
512 return;
513}
514
dea31012005-04-17 16:05:31 -0500515static void
James Smart2e0fef82007-06-17 19:56:36 -0500516lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500517{
518 struct lpfc_work_evt *evtp = NULL;
519 struct lpfc_nodelist *ndlp;
520 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400521 int fcf_inuse;
522 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500523
James Smart2e0fef82007-06-17 19:56:36 -0500524 spin_lock_irq(&phba->hbalock);
525 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500526 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
527 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500528 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500529 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500530 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500531 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500532 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500533 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500534 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500535 /* decrement the node reference count held
536 * for this queued work
537 */
538 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500539 break;
James Smart858c9f62007-06-17 19:56:39 -0500540 case LPFC_EVT_DEV_LOSS:
541 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400542 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500543 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500544 /* decrement the node reference count held for
545 * this queued work
546 */
James Smarta93ff372010-10-22 11:06:08 -0400547 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500548 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400549 if (phba->sli_rev == LPFC_SLI_REV4)
550 lpfc_sli4_post_dev_loss_tmo_handler(phba,
551 fcf_inuse,
552 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500553 break;
dea31012005-04-17 16:05:31 -0500554 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500555 if (phba->link_state < LPFC_LINK_DOWN)
556 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500557 else
James Smart2e0fef82007-06-17 19:56:36 -0500558 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500559 complete((struct completion *)(evtp->evt_arg2));
560 break;
James Smart46fa3112007-04-25 09:51:45 -0400561 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500562 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400563 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400564 *(int *)(evtp->evt_arg1) = 0;
565 complete((struct completion *)(evtp->evt_arg2));
566 break;
567 case LPFC_EVT_OFFLINE:
568 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500569 lpfc_sli_brdrestart(phba);
570 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400571 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
572 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500573 complete((struct completion *)(evtp->evt_arg2));
574 break;
575 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400576 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500577 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500578 lpfc_sli_brdreset(phba);
579 lpfc_hba_down_post(phba);
580 *(int *)(evtp->evt_arg1) =
581 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400582 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500583 complete((struct completion *)(evtp->evt_arg2));
584 break;
585 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400586 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500587 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500588 = (phba->pport->stopped)
589 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400590 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500591 complete((struct completion *)(evtp->evt_arg2));
592 break;
James Smartea2151b2008-09-07 11:52:10 -0400593 case LPFC_EVT_FASTPATH_MGMT_EVT:
594 lpfc_send_fastpath_evt(phba, evtp);
595 free_evt = 0;
596 break;
James Smart78730cf2010-04-06 15:06:30 -0400597 case LPFC_EVT_RESET_HBA:
598 if (!(phba->pport->load_flag & FC_UNLOADING))
599 lpfc_reset_hba(phba);
600 break;
dea31012005-04-17 16:05:31 -0500601 }
602 if (free_evt)
603 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500604 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500605 }
James Smart2e0fef82007-06-17 19:56:36 -0500606 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500607
608}
609
James Smart311464e2007-08-02 11:10:37 -0400610static void
James Smart2e0fef82007-06-17 19:56:36 -0500611lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500612{
613 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500614 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400615 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400616 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400617 int i;
dea31012005-04-17 16:05:31 -0500618
James Smart2e0fef82007-06-17 19:56:36 -0500619 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500620 ha_copy = phba->work_ha;
621 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500622 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500623
James Smartda0436e2009-05-22 14:51:39 -0400624 /* First, try to post the next mailbox command to SLI4 device */
625 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
626 lpfc_sli4_post_async_mbox(phba);
627
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500628 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400629 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500630 lpfc_handle_eratt(phba);
631
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500632 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500633 lpfc_sli_handle_mb_event(phba);
634
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500635 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500636 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400637
James Smartda0436e2009-05-22 14:51:39 -0400638 /* Process SLI4 events */
639 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500640 if (phba->hba_flag & HBA_RRQ_ACTIVE)
641 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400642 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
643 lpfc_sli4_els_xri_abort_event_proc(phba);
644 if (phba->hba_flag & ASYNC_EVENT)
645 lpfc_sli4_async_event_proc(phba);
646 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
647 spin_lock_irq(&phba->hbalock);
648 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
649 spin_unlock_irq(&phba->hbalock);
650 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
651 }
James Smartecfd03c2010-02-12 14:41:27 -0500652 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
653 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400654 }
655
James Smart549e55c2007-08-02 11:09:51 -0400656 vports = lpfc_create_vport_work_array(phba);
657 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400658 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400659 /*
660 * We could have no vports in array if unloading, so if
661 * this happens then just use the pport
662 */
663 if (vports[i] == NULL && i == 0)
664 vport = phba->pport;
665 else
666 vport = vports[i];
667 if (vport == NULL)
668 break;
James Smart58da1ff2008-04-07 10:15:56 -0400669 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400670 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400671 vport->work_port_events &= ~work_port_events;
672 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400673 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400674 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400675 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400676 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400677 if (work_port_events & WORKER_HB_TMO)
678 lpfc_hb_timeout_handler(phba);
679 if (work_port_events & WORKER_MBOX_TMO)
680 lpfc_mbox_timeout_handler(phba);
681 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
682 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400683 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
684 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500685 if (work_port_events & WORKER_DELAYED_DISC_TMO)
686 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500687 }
James Smart09372822008-01-11 01:52:54 -0500688 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500689
James Smart895427b2017-02-12 13:52:30 -0800690 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500691 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
692 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700693 if (pring && (status & HA_RXMASK ||
694 pring->flag & LPFC_DEFERRED_RING_EVENT ||
695 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400696 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500697 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800698 /* Preserve legacy behavior. */
699 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
700 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500701 } else {
James Smart15498dc2019-09-21 20:58:59 -0700702 /* Driver could have abort request completed in queue
703 * when link goes down. Allow for this transition.
704 */
705 if (phba->link_state >= LPFC_LINK_DOWN ||
James Smartae9e28f2017-05-15 15:20:51 -0700706 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500707 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
708 lpfc_sli_handle_slow_ring_event(phba, pring,
709 (status &
710 HA_RXMASK));
711 }
James Smart858c9f62007-06-17 19:56:39 -0500712 }
James Smartdc19e3b2018-05-24 21:08:57 -0700713 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400714 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500715 /*
716 * Turn on Ring interrupts
717 */
James Smart3772a992009-05-22 14:50:54 -0400718 if (phba->sli_rev <= LPFC_SLI_REV3) {
719 spin_lock_irq(&phba->hbalock);
720 control = readl(phba->HCregaddr);
721 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
722 lpfc_debugfs_slow_ring_trc(phba,
723 "WRK Enable ring: cntl:x%x hacopy:x%x",
724 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400725
James Smart3772a992009-05-22 14:50:54 -0400726 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
727 writel(control, phba->HCregaddr);
728 readl(phba->HCregaddr); /* flush */
729 } else {
730 lpfc_debugfs_slow_ring_trc(phba,
731 "WRK Ring ok: cntl:x%x hacopy:x%x",
732 control, ha_copy, 0);
733 }
734 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500735 }
736 }
James Smart2e0fef82007-06-17 19:56:36 -0500737 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500738}
739
dea31012005-04-17 16:05:31 -0500740int
741lpfc_do_work(void *p)
742{
743 struct lpfc_hba *phba = p;
744 int rc;
dea31012005-04-17 16:05:31 -0500745
Dongsheng Yang8698a742014-03-11 18:09:12 +0800746 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400747 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400748 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500749
James Smart3a55b532008-12-04 22:38:54 -0500750 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400751 /* wait and check worker queue activities */
752 rc = wait_event_interruptible(phba->work_waitq,
753 (test_and_clear_bit(LPFC_DATA_READY,
754 &phba->data_flags)
755 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500756 /* Signal wakeup shall terminate the worker thread */
757 if (rc) {
758 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
759 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500760 break;
James Smart3a55b532008-12-04 22:38:54 -0500761 }
dea31012005-04-17 16:05:31 -0500762
James Smart5e9d9b82008-06-14 22:52:53 -0400763 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500764 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500765 }
James Smart3a55b532008-12-04 22:38:54 -0500766 phba->worker_thread = NULL;
767 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
768 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500769 return 0;
770}
771
772/*
773 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300774 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500775 * embedding it in the IOCB.
776 */
777int
James Smart2e0fef82007-06-17 19:56:36 -0500778lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500779 uint32_t evt)
780{
781 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500782 unsigned long flags;
dea31012005-04-17 16:05:31 -0500783
784 /*
785 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
786 * be queued to worker thread for processing
787 */
James Smart92d7f7b2007-06-17 19:56:38 -0500788 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500789 if (!evtp)
790 return 0;
791
792 evtp->evt_arg1 = arg1;
793 evtp->evt_arg2 = arg2;
794 evtp->evt = evt;
795
James Smarted957682007-06-17 19:56:37 -0500796 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400797 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500798 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500799
James Smart5e9d9b82008-06-14 22:52:53 -0400800 lpfc_worker_wake_up(phba);
801
dea31012005-04-17 16:05:31 -0500802 return 1;
803}
804
James Smart92d7f7b2007-06-17 19:56:38 -0500805void
806lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
807{
James Smart09372822008-01-11 01:52:54 -0500808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500809 struct lpfc_hba *phba = vport->phba;
810 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500811
812 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500813 if (!NLP_CHK_NODE_ACT(ndlp))
814 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500815 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
816 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400817 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
818 ((vport->port_type == LPFC_NPIV_PORT) &&
819 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500820 lpfc_unreg_rpi(vport, ndlp);
821
822 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400823 if ((phba->sli_rev < LPFC_SLI_REV4) &&
824 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500825 continue;
James Smart4c2805a2020-03-31 09:50:10 -0700826
827 /* Notify transport of connectivity loss to trigger cleanup. */
828 if (phba->nvmet_support &&
829 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
830 lpfc_nvmet_invalidate_host(phba, ndlp);
831
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -0400832 lpfc_disc_state_machine(vport, ndlp, NULL,
833 remove
834 ? NLP_EVT_DEVICE_RM
835 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -0500836 }
837 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400838 if (phba->sli_rev == LPFC_SLI_REV4)
839 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500840 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500841 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500842 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500843 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500844 }
845}
846
James Smart87af33f2007-10-27 13:37:43 -0400847void
James Smart98c9ea52007-10-27 13:37:33 -0400848lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500849{
James Smart695a8142010-01-26 23:08:03 -0500850 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
851
James Smart45ed1192009-10-02 15:17:02 -0400852 /* Cleanup any outstanding received buffers */
853 lpfc_cleanup_rcv_buffers(vport);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* Cleanup any outstanding RSCN activity */
856 lpfc_els_flush_rscn(vport);
857
858 /* Cleanup any outstanding ELS commands */
859 lpfc_els_flush_cmd(vport);
860
861 lpfc_cleanup_rpis(vport, 0);
862
James Smart92d7f7b2007-06-17 19:56:38 -0500863 /* Turn off discovery timer if its running */
864 lpfc_can_disctmo(vport);
865}
866
James Smart3772a992009-05-22 14:50:54 -0400867void
James Smart98c9ea52007-10-27 13:37:33 -0400868lpfc_linkdown_port(struct lpfc_vport *vport)
869{
870 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
871
James Smartf6e84792019-01-28 11:14:38 -0800872 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -0800873 fc_host_post_event(shost, fc_get_event_number(),
874 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400875
876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
877 "Link Down: state:x%x rtry:x%x flg:x%x",
878 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
879
880 lpfc_port_link_failure(vport);
881
James Smart92494142011-02-16 12:39:44 -0500882 /* Stop delayed Nport discovery */
883 spin_lock_irq(shost->host_lock);
884 vport->fc_flag &= ~FC_DISC_DELAYED;
885 spin_unlock_irq(shost->host_lock);
886 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400887}
888
dea31012005-04-17 16:05:31 -0500889int
James Smart685f0bf2007-04-25 09:53:08 -0400890lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500891{
James Smart2e0fef82007-06-17 19:56:36 -0500892 struct lpfc_vport *vport = phba->pport;
893 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400894 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400895 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400896 int i;
dea31012005-04-17 16:05:31 -0500897
James Smart19193ff2019-03-12 16:30:25 -0700898 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500899 return 0;
James Smart19193ff2019-03-12 16:30:25 -0700900
James Smartaacc20e2009-12-21 17:02:51 -0500901 /* Block all SCSI stack I/Os */
902 lpfc_scsi_dev_block(phba);
903
James Smart0a9e9682018-11-29 16:09:36 -0800904 phba->defer_flogi_acc_flag = false;
905
James Smart2e0fef82007-06-17 19:56:36 -0500906 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500907 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500908 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500909 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500910 phba->link_state = LPFC_LINK_DOWN;
James Smart2977a092018-12-13 15:17:52 -0800911 if (phba->sli4_hba.conf_trunk) {
912 phba->trunk_link.link0.state = 0;
913 phba->trunk_link.link1.state = 0;
914 phba->trunk_link.link2.state = 0;
915 phba->trunk_link.link3.state = 0;
James Smart845d0322019-08-14 16:57:01 -0700916 phba->sli4_hba.link_state.logical_speed =
917 LPFC_LINK_SPEED_UNKNOWN;
James Smart2977a092018-12-13 15:17:52 -0800918 }
James Smart72100cc2010-02-12 14:43:01 -0500919 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500920 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500921 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500922 }
James Smart549e55c2007-08-02 11:09:51 -0400923 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800924 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400925 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400926 /* Issue a LINK DOWN event to all nodes */
927 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800928
929 vports[i]->fc_myDID = 0;
930
James Smartf6e84792019-01-28 11:14:38 -0800931 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
932 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800933 if (phba->nvmet_support)
934 lpfc_nvmet_update_targetport(phba);
935 else
James Smart8c258642017-02-12 13:52:36 -0800936 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800937 }
James Smart549e55c2007-08-02 11:09:51 -0400938 }
James Smart895427b2017-02-12 13:52:30 -0800939 }
James Smart09372822008-01-11 01:52:54 -0500940 lpfc_destroy_vport_work_array(phba, vports);
James Smartc95a3b42019-03-12 16:30:07 -0700941
942 /* Clean up any SLI3 firmware default rpi's */
943 if (phba->sli_rev > LPFC_SLI_REV3)
944 goto skip_unreg_did;
945
James Smart2e0fef82007-06-17 19:56:36 -0500946 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
947 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400948 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500949 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500950 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400951 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500952 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500953 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500954 }
955 }
956
James Smartc95a3b42019-03-12 16:30:07 -0700957 skip_unreg_did:
dea31012005-04-17 16:05:31 -0500958 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500959 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500960 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
961 if (mb) {
dea31012005-04-17 16:05:31 -0500962 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500963 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500964 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400965 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500966 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500967 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500968 }
969 }
James Smart2e0fef82007-06-17 19:56:36 -0500970 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500971 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -0700972 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500973 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500974 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500975 return 0;
dea31012005-04-17 16:05:31 -0500976}
977
James Smart92d7f7b2007-06-17 19:56:38 -0500978static void
979lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500980{
James Smart92d7f7b2007-06-17 19:56:38 -0500981 struct lpfc_nodelist *ndlp;
982
983 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -0800984 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smarte47c9092008-02-08 18:49:26 -0500985 if (!NLP_CHK_NODE_ACT(ndlp))
986 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500987 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
988 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500989 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500990 /* On Linkup its safe to clean up the ndlp
991 * from Fabric connections.
992 */
James Smart92d7f7b2007-06-17 19:56:38 -0500993 if (ndlp->nlp_DID != Fabric_DID)
994 lpfc_unreg_rpi(vport, ndlp);
995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
996 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500997 /* Fail outstanding IO now since device is
998 * marked for PLOGI.
999 */
James Smart92d7f7b2007-06-17 19:56:38 -05001000 lpfc_unreg_rpi(vport, ndlp);
1001 }
1002 }
1003}
1004
1005static void
1006lpfc_linkup_port(struct lpfc_vport *vport)
1007{
1008 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001009 struct lpfc_hba *phba = vport->phba;
1010
1011 if ((vport->load_flag & FC_UNLOADING) != 0)
1012 return;
1013
James Smart858c9f62007-06-17 19:56:39 -05001014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1015 "Link Up: top:x%x speed:x%x flg:x%x",
1016 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1017
James Smart92d7f7b2007-06-17 19:56:38 -05001018 /* If NPIV is not enabled, only bring the physical port up */
1019 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1020 (vport != phba->pport))
1021 return;
dea31012005-04-17 16:05:31 -05001022
James Smartf6e84792019-01-28 11:14:38 -08001023 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001024 fc_host_post_event(shost, fc_get_event_number(),
1025 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001026
James Smart2e0fef82007-06-17 19:56:36 -05001027 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001028 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1029 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1030 vport->fc_flag |= FC_NDISC_ACTIVE;
1031 vport->fc_ns_retry = 0;
1032 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001033
James Smart92d7f7b2007-06-17 19:56:38 -05001034 if (vport->fc_flag & FC_LBIT)
1035 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001036
James Smart92d7f7b2007-06-17 19:56:38 -05001037}
1038
1039static int
1040lpfc_linkup(struct lpfc_hba *phba)
1041{
James Smart549e55c2007-08-02 11:09:51 -04001042 struct lpfc_vport **vports;
1043 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001044 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001045
1046 phba->link_state = LPFC_LINK_UP;
1047
1048 /* Unblock fabric iocbs if they are blocked */
1049 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1050 del_timer_sync(&phba->fabric_block_timer);
1051
James Smart549e55c2007-08-02 11:09:51 -04001052 vports = lpfc_create_vport_work_array(phba);
1053 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001054 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001055 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001056 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001057
James Smartd496b9a2018-10-23 13:41:08 -07001058 /* Clear the pport flogi counter in case the link down was
1059 * absorbed without an ACQE. No lock here - in worker thread
1060 * and discovery is synchronized.
1061 */
1062 spin_lock_irq(shost->host_lock);
1063 phba->pport->rcv_flogi_cnt = 0;
1064 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001065
1066 /* reinitialize initial FLOGI flag */
1067 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1068 phba->defer_flogi_acc_flag = false;
1069
dea31012005-04-17 16:05:31 -05001070 return 0;
1071}
1072
1073/*
1074 * This routine handles processing a CLEAR_LA mailbox
1075 * command upon completion. It is setup in the LPFC_MBOXQ
1076 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001077 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001078 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001079static void
James Smart2e0fef82007-06-17 19:56:36 -05001080lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001081{
James Smart2e0fef82007-06-17 19:56:36 -05001082 struct lpfc_vport *vport = pmb->vport;
1083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1084 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001085 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001086 uint32_t control;
1087
dea31012005-04-17 16:05:31 -05001088 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001089 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1090 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001091
1092 /* Check for error */
1093 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001094 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001095 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1096 "0320 CLEAR_LA mbxStatus error x%x hba "
1097 "state x%x\n",
1098 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001099 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001100 goto out;
1101 }
1102
James Smart92d7f7b2007-06-17 19:56:38 -05001103 if (vport->port_type == LPFC_PHYSICAL_PORT)
1104 phba->link_state = LPFC_HBA_READY;
1105
1106 spin_lock_irq(&phba->hbalock);
1107 psli->sli_flag |= LPFC_PROCESS_LA;
1108 control = readl(phba->HCregaddr);
1109 control |= HC_LAINT_ENA;
1110 writel(control, phba->HCregaddr);
1111 readl(phba->HCregaddr); /* flush */
1112 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001113 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001114 return;
dea31012005-04-17 16:05:31 -05001115
dea31012005-04-17 16:05:31 -05001116out:
1117 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001118 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1119 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001120 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001121
James Smart2e0fef82007-06-17 19:56:36 -05001122 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001123 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001124 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001125
James Smart2e0fef82007-06-17 19:56:36 -05001126 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001127
1128 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001129
1130 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001131 psli->sli_flag |= LPFC_PROCESS_LA;
1132 control = readl(phba->HCregaddr);
1133 control |= HC_LAINT_ENA;
1134 writel(control, phba->HCregaddr);
1135 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001137
1138 return;
1139}
1140
James Smart2e0fef82007-06-17 19:56:36 -05001141
James Smartd6de08c2015-12-16 18:11:53 -05001142void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001143lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001144{
James Smart2e0fef82007-06-17 19:56:36 -05001145 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001146
James Smart04c68492009-05-22 14:52:52 -04001147 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001148 goto out;
dea31012005-04-17 16:05:31 -05001149
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001150 mempool_free(pmb, phba->mbox_mem_pool);
1151
James Smart1b511972011-12-13 13:23:09 -05001152 /* don't perform discovery for SLI4 loopback diagnostic test */
1153 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1154 !(phba->hba_flag & HBA_FCOE_MODE) &&
1155 (phba->link_flag & LS_LOOPBACK_MODE))
1156 return;
1157
James Smart76a95d72010-11-20 23:11:48 -05001158 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001159 vport->fc_flag & FC_PUBLIC_LOOP &&
1160 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001161 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001162 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001163 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1164 */
James Smart2e0fef82007-06-17 19:56:36 -05001165 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001166 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001167 }
dea31012005-04-17 16:05:31 -05001168
James Smart2e0fef82007-06-17 19:56:36 -05001169 /* Start discovery by sending a FLOGI. port_state is identically
James Smart835214f2020-01-27 16:23:03 -08001170 * LPFC_FLOGI while waiting for FLOGI cmpl. Check if sending
1171 * the FLOGI is being deferred till after MBX_READ_SPARAM completes.
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001172 */
James Smart835214f2020-01-27 16:23:03 -08001173 if (vport->port_state != LPFC_FLOGI) {
1174 if (!(phba->hba_flag & HBA_DEFER_FLOGI))
1175 lpfc_initial_flogi(vport);
1176 } else {
1177 if (vport->fc_flag & FC_PT2PT)
1178 lpfc_disc_start(vport);
1179 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001180 return;
dea31012005-04-17 16:05:31 -05001181
1182out:
James Smarte8b62012007-08-02 11:10:09 -04001183 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1184 "0306 CONFIG_LINK mbxStatus error x%x "
1185 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001186 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001187 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001188
1189 lpfc_linkdown(phba);
1190
James Smarte8b62012007-08-02 11:10:09 -04001191 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1192 "0200 CONFIG_LINK bad hba state x%x\n",
1193 vport->port_state);
dea31012005-04-17 16:05:31 -05001194
James Smart92d7f7b2007-06-17 19:56:38 -05001195 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001196 return;
1197}
1198
James Smart7d791df2011-07-22 18:37:52 -04001199/**
1200 * lpfc_sli4_clear_fcf_rr_bmask
1201 * @phba pointer to the struct lpfc_hba for this port.
1202 * This fucnction resets the round robin bit mask and clears the
1203 * fcf priority list. The list deletions are done while holding the
1204 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1205 * from the lpfc_fcf_pri record.
1206 **/
1207void
1208lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1209{
1210 struct lpfc_fcf_pri *fcf_pri;
1211 struct lpfc_fcf_pri *next_fcf_pri;
1212 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1213 spin_lock_irq(&phba->hbalock);
1214 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1215 &phba->fcf.fcf_pri_list, list) {
1216 list_del_init(&fcf_pri->list);
1217 fcf_pri->fcf_rec.flag = 0;
1218 }
1219 spin_unlock_irq(&phba->hbalock);
1220}
dea31012005-04-17 16:05:31 -05001221static void
James Smart6fb120a2009-05-22 14:52:59 -04001222lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1223{
1224 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001225
1226 if (mboxq->u.mb.mbxStatus) {
1227 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1228 "2017 REG_FCFI mbxStatus error x%x "
1229 "HBA state x%x\n",
1230 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001231 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001232 }
1233
1234 /* Start FCoE discovery by sending a FLOGI. */
1235 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1236 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001237 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001238 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001239 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001240
James Smart32b97932009-07-19 10:01:21 -04001241 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001242 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1243 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001244 goto fail_out;
1245
1246 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001247 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001248 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001249 phba->hba_flag &= ~FCF_TS_INPROG;
1250 if (vport->port_state != LPFC_FLOGI) {
1251 phba->hba_flag |= FCF_RR_INPROG;
1252 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001253 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001254 goto out;
1255 }
1256 spin_unlock_irq(&phba->hbalock);
1257 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001258
James Smarta93ff372010-10-22 11:06:08 -04001259fail_out:
1260 spin_lock_irq(&phba->hbalock);
1261 phba->hba_flag &= ~FCF_RR_INPROG;
1262 spin_unlock_irq(&phba->hbalock);
1263out:
James Smart6fb120a2009-05-22 14:52:59 -04001264 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001265}
1266
1267/**
1268 * lpfc_fab_name_match - Check if the fcf fabric name match.
1269 * @fab_name: pointer to fabric name.
1270 * @new_fcf_record: pointer to fcf record.
1271 *
1272 * This routine compare the fcf record's fabric name with provided
1273 * fabric name. If the fabric name are identical this function
1274 * returns 1 else return 0.
1275 **/
1276static uint32_t
1277lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1278{
James Smartecfd03c2010-02-12 14:41:27 -05001279 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001280 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001281 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1282 return 0;
1283 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1284 return 0;
1285 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1286 return 0;
1287 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1288 return 0;
1289 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1290 return 0;
1291 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1292 return 0;
1293 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1294 return 0;
1295 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001296}
1297
1298/**
James Smart8fa38512009-07-19 10:01:03 -04001299 * lpfc_sw_name_match - Check if the fcf switch name match.
1300 * @fab_name: pointer to fabric name.
1301 * @new_fcf_record: pointer to fcf record.
1302 *
1303 * This routine compare the fcf record's switch name with provided
1304 * switch name. If the switch name are identical this function
1305 * returns 1 else return 0.
1306 **/
1307static uint32_t
1308lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1309{
James Smartecfd03c2010-02-12 14:41:27 -05001310 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001311 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001312 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1313 return 0;
1314 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1315 return 0;
1316 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1317 return 0;
1318 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1319 return 0;
1320 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1321 return 0;
1322 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1323 return 0;
1324 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1325 return 0;
1326 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001327}
1328
1329/**
James Smart6fb120a2009-05-22 14:52:59 -04001330 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001331 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001332 * @new_fcf_record: pointer to fcf record.
1333 *
1334 * This routine compare the fcf record's mac address with HBA's
1335 * FCF mac address. If the mac addresses are identical this function
1336 * returns 1 else return 0.
1337 **/
1338static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001339lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001340{
James Smartecfd03c2010-02-12 14:41:27 -05001341 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001342 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001343 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1344 return 0;
1345 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1346 return 0;
1347 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1348 return 0;
1349 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1350 return 0;
1351 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1352 return 0;
1353 return 1;
1354}
1355
1356static bool
1357lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1358{
1359 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001360}
1361
1362/**
James Smart7d791df2011-07-22 18:37:52 -04001363 * lpfc_update_fcf_record - Update driver fcf record
1364 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1365 * @phba: pointer to lpfc hba data structure.
1366 * @fcf_index: Index for the lpfc_fcf_record.
1367 * @new_fcf_record: pointer to hba fcf record.
1368 *
1369 * This routine updates the driver FCF priority record from the new HBA FCF
1370 * record. This routine is called with the host lock held.
1371 **/
1372static void
1373__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1374 struct fcf_record *new_fcf_record
1375 )
1376{
1377 struct lpfc_fcf_pri *fcf_pri;
1378
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001379 lockdep_assert_held(&phba->hbalock);
1380
James Smart7d791df2011-07-22 18:37:52 -04001381 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1382 fcf_pri->fcf_rec.fcf_index = fcf_index;
1383 /* FCF record priority */
1384 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1385
1386}
1387
1388/**
James Smart6fb120a2009-05-22 14:52:59 -04001389 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001390 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001391 * @new_fcf_record: pointer to fcf record.
1392 *
1393 * This routine copies the FCF information from the FCF
1394 * record to lpfc_hba data structure.
1395 **/
1396static void
James Smartecfd03c2010-02-12 14:41:27 -05001397lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1398 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001399{
James Smartecfd03c2010-02-12 14:41:27 -05001400 /* Fabric name */
1401 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001402 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001403 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001404 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001405 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001406 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001407 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001408 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001409 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001410 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001411 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001412 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001413 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001414 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001415 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001416 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001417 /* Mac address */
1418 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1419 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1420 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1421 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1422 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1423 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1424 /* FCF record index */
1425 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1426 /* FCF record priority */
1427 fcf_rec->priority = new_fcf_record->fip_priority;
1428 /* Switch name */
1429 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001430 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001431 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001432 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001433 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001434 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001435 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001436 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001437 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001438 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001439 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001440 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001441 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001442 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001443 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001444 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001445}
1446
1447/**
James Smartecfd03c2010-02-12 14:41:27 -05001448 * lpfc_update_fcf_record - Update driver fcf record
1449 * @phba: pointer to lpfc hba data structure.
1450 * @fcf_rec: pointer to driver fcf record.
1451 * @new_fcf_record: pointer to hba fcf record.
1452 * @addr_mode: address mode to be set to the driver fcf record.
1453 * @vlan_id: vlan tag to be set to the driver fcf record.
1454 * @flag: flag bits to be set to the driver fcf record.
1455 *
1456 * This routine updates the driver FCF record from the new HBA FCF record
1457 * together with the address mode, vlan_id, and other informations. This
1458 * routine is called with the host lock held.
1459 **/
1460static void
1461__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1462 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1463 uint16_t vlan_id, uint32_t flag)
1464{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001465 lockdep_assert_held(&phba->hbalock);
1466
James Smartecfd03c2010-02-12 14:41:27 -05001467 /* Copy the fields from the HBA's FCF record */
1468 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1469 /* Update other fields of driver FCF record */
1470 fcf_rec->addr_mode = addr_mode;
1471 fcf_rec->vlan_id = vlan_id;
1472 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001473 __lpfc_update_fcf_record_pri(phba,
1474 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1475 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001476}
1477
1478/**
James Smart6fb120a2009-05-22 14:52:59 -04001479 * lpfc_register_fcf - Register the FCF with hba.
1480 * @phba: pointer to lpfc hba data structure.
1481 *
1482 * This routine issues a register fcfi mailbox command to register
1483 * the fcf with HBA.
1484 **/
1485static void
1486lpfc_register_fcf(struct lpfc_hba *phba)
1487{
1488 LPFC_MBOXQ_t *fcf_mbxq;
1489 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001490
James Smartd439d282010-09-29 11:18:45 -04001491 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001492 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001493 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001494 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001495 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001496 return;
1497 }
1498
1499 /* The FCF is already registered, start discovery */
1500 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001501 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001502 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001503 if (phba->pport->port_state != LPFC_FLOGI &&
1504 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001505 phba->hba_flag |= FCF_RR_INPROG;
1506 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001507 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001508 return;
1509 }
1510 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001511 return;
1512 }
James Smartd439d282010-09-29 11:18:45 -04001513 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001514
James Smarta93ff372010-10-22 11:06:08 -04001515 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001516 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001517 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001518 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001519 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001520 return;
James Smart4d9ab992009-10-02 15:16:39 -04001521 }
James Smart6fb120a2009-05-22 14:52:59 -04001522
1523 lpfc_reg_fcfi(phba, fcf_mbxq);
1524 fcf_mbxq->vport = phba->pport;
1525 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1526 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001527 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001528 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001529 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001530 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001531 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001532 }
James Smart6fb120a2009-05-22 14:52:59 -04001533
1534 return;
1535}
1536
1537/**
1538 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1539 * @phba: pointer to lpfc hba data structure.
1540 * @new_fcf_record: pointer to fcf record.
1541 * @boot_flag: Indicates if this record used by boot bios.
1542 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001543 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001544 *
1545 * This routine compare the fcf record with connect list obtained from the
1546 * config region to decide if this FCF can be used for SAN discovery. It returns
1547 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1548 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1549 * is used by boot bios and addr_mode will indicate the addressing mode to be
1550 * used for this FCF when the function returns.
1551 * If the FCF record need to be used with a particular vlan id, the vlan is
1552 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001553 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001554 **/
1555static int
1556lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1557 struct fcf_record *new_fcf_record,
1558 uint32_t *boot_flag, uint32_t *addr_mode,
1559 uint16_t *vlan_id)
1560{
1561 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001562 int i, j, fcf_vlan_id = 0;
1563
1564 /* Find the lowest VLAN id in the FCF record */
1565 for (i = 0; i < 512; i++) {
1566 if (new_fcf_record->vlan_bitmap[i]) {
1567 fcf_vlan_id = i * 8;
1568 j = 0;
1569 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1570 j++;
1571 fcf_vlan_id++;
1572 }
1573 break;
1574 }
1575 }
James Smart6fb120a2009-05-22 14:52:59 -04001576
James Smart26979ce2012-09-29 11:31:55 -04001577 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001578 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001579 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1580 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001581 return 0;
1582
James Smart45ed1192009-10-02 15:17:02 -04001583 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001584 *boot_flag = 0;
1585 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1586 new_fcf_record);
1587 if (phba->valid_vlan)
1588 *vlan_id = phba->vlan_id;
1589 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001590 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001591 return 1;
1592 }
1593
1594 /*
1595 * If there are no FCF connection table entry, driver connect to all
1596 * FCFs.
1597 */
1598 if (list_empty(&phba->fcf_conn_rec_list)) {
1599 *boot_flag = 0;
1600 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1601 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001602
1603 /*
1604 * When there are no FCF connect entries, use driver's default
1605 * addressing mode - FPMA.
1606 */
1607 if (*addr_mode & LPFC_FCF_FPMA)
1608 *addr_mode = LPFC_FCF_FPMA;
1609
James Smart4d9ab992009-10-02 15:16:39 -04001610 /* If FCF record report a vlan id use that vlan id */
1611 if (fcf_vlan_id)
1612 *vlan_id = fcf_vlan_id;
1613 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001614 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001615 return 1;
1616 }
1617
James Smartecfd03c2010-02-12 14:41:27 -05001618 list_for_each_entry(conn_entry,
1619 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001620 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1621 continue;
1622
1623 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1624 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001625 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001626 continue;
James Smart8fa38512009-07-19 10:01:03 -04001627 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1628 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1629 new_fcf_record))
1630 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001631 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1632 /*
1633 * If the vlan bit map does not have the bit set for the
1634 * vlan id to be used, then it is not a match.
1635 */
1636 if (!(new_fcf_record->vlan_bitmap
1637 [conn_entry->conn_rec.vlan_tag / 8] &
1638 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1639 continue;
1640 }
1641
1642 /*
James Smart0c287582009-06-10 17:22:56 -04001643 * If connection record does not support any addressing mode,
1644 * skip the FCF record.
1645 */
1646 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1647 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1648 continue;
1649
1650 /*
James Smart6fb120a2009-05-22 14:52:59 -04001651 * Check if the connection record specifies a required
1652 * addressing mode.
1653 */
1654 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1655 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1656
1657 /*
1658 * If SPMA required but FCF not support this continue.
1659 */
1660 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1661 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1662 new_fcf_record) & LPFC_FCF_SPMA))
1663 continue;
1664
1665 /*
1666 * If FPMA required but FCF not support this continue.
1667 */
1668 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1669 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1670 new_fcf_record) & LPFC_FCF_FPMA))
1671 continue;
1672 }
1673
1674 /*
1675 * This fcf record matches filtering criteria.
1676 */
1677 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1678 *boot_flag = 1;
1679 else
1680 *boot_flag = 0;
1681
James Smart0c287582009-06-10 17:22:56 -04001682 /*
1683 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001684 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001685 * by FCF, allow fabric to pick the addressing mode.
1686 */
James Smart6fb120a2009-05-22 14:52:59 -04001687 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1688 new_fcf_record);
1689 /*
1690 * If the user specified a required address mode, assign that
1691 * address mode
1692 */
1693 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1694 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1695 *addr_mode = (conn_entry->conn_rec.flags &
1696 FCFCNCT_AM_SPMA) ?
1697 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1698 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001699 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001700 * addr mode only if FCF support the addr_mode.
1701 */
1702 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1703 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1704 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1705 (*addr_mode & LPFC_FCF_SPMA))
1706 *addr_mode = LPFC_FCF_SPMA;
1707 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1708 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1709 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1710 (*addr_mode & LPFC_FCF_FPMA))
1711 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001712
James Smart4d9ab992009-10-02 15:16:39 -04001713 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001714 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1715 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001716 /*
1717 * If no vlan id is specified in connect list, use the vlan id
1718 * in the FCF record
1719 */
1720 else if (fcf_vlan_id)
1721 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001722 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001723 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001724
1725 return 1;
1726 }
1727
1728 return 0;
1729}
1730
1731/**
James Smart32b97932009-07-19 10:01:21 -04001732 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1733 * @phba: pointer to lpfc hba data structure.
1734 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1735 *
1736 * This function check if there is any fcoe event pending while driver
1737 * scan FCF entries. If there is any pending event, it will restart the
1738 * FCF saning and return 1 else return 0.
1739 */
1740int
1741lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1742{
James Smart32b97932009-07-19 10:01:21 -04001743 /*
1744 * If the Link is up and no FCoE events while in the
1745 * FCF discovery, no need to restart FCF discovery.
1746 */
1747 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001748 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001749 return 0;
1750
James Smart0c9ab6f2010-02-26 14:15:57 -05001751 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1752 "2768 Pending link or FCF event during current "
1753 "handling of the previous event: link_state:x%x, "
1754 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1755 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1756 phba->fcoe_eventtag);
1757
James Smart32b97932009-07-19 10:01:21 -04001758 spin_lock_irq(&phba->hbalock);
1759 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1760 spin_unlock_irq(&phba->hbalock);
1761
James Smart0c9ab6f2010-02-26 14:15:57 -05001762 if (phba->link_state >= LPFC_LINK_UP) {
1763 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1764 "2780 Restart FCF table scan due to "
1765 "pending FCF event:evt_tag_at_scan:x%x, "
1766 "evt_tag_current:x%x\n",
1767 phba->fcoe_eventtag_at_fcf_scan,
1768 phba->fcoe_eventtag);
1769 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1770 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001771 /*
James Smarta93ff372010-10-22 11:06:08 -04001772 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001773 * flag
1774 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001775 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1776 "2833 Stop FCF discovery process due to link "
1777 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001778 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001779 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001780 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001781 spin_unlock_irq(&phba->hbalock);
1782 }
James Smart32b97932009-07-19 10:01:21 -04001783
James Smart0c9ab6f2010-02-26 14:15:57 -05001784 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001785 if (unreg_fcf) {
1786 spin_lock_irq(&phba->hbalock);
1787 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1788 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001789 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001790 }
James Smart32b97932009-07-19 10:01:21 -04001791 return 1;
1792}
1793
1794/**
James Smart999d8132010-03-15 11:24:56 -04001795 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1796 * @phba: pointer to lpfc hba data structure.
1797 * @fcf_cnt: number of eligible fcf record seen so far.
1798 *
1799 * This function makes an running random selection decision on FCF record to
1800 * use through a sequence of @fcf_cnt eligible FCF records with equal
1801 * probability. To perform integer manunipulation of random numbers with
1802 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001803 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001804 *
1805 * Returns true when outcome is for the newly read FCF record should be
1806 * chosen; otherwise, return false when outcome is for keeping the previously
1807 * chosen FCF record.
1808 **/
1809static bool
1810lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1811{
1812 uint32_t rand_num;
1813
1814 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001815 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001816
1817 /* Decision with probability 1/fcf_cnt */
1818 if ((fcf_cnt * rand_num) < 0xFFFF)
1819 return true;
1820 else
1821 return false;
1822}
1823
1824/**
James Smart3804dc82010-07-14 15:31:37 -04001825 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001826 * @phba: pointer to lpfc hba data structure.
1827 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001828 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001829 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001830 * This routine parses the non-embedded fcf mailbox command by performing the
1831 * necessarily error checking, non-embedded read FCF record mailbox command
1832 * SGE parsing, and endianness swapping.
1833 *
1834 * Returns the pointer to the new FCF record in the non-embedded mailbox
1835 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001836 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001837static struct fcf_record *
1838lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1839 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001840{
1841 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001842 struct lpfc_mbx_sge sge;
1843 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001844 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001845 union lpfc_sli4_cfg_shdr *shdr;
1846 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001847
James Smart6fb120a2009-05-22 14:52:59 -04001848 /* Get the first SGE entry from the non-embedded DMA memory. This
1849 * routine only uses a single SGE.
1850 */
1851 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001852 if (unlikely(!mboxq->sge_array)) {
1853 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1854 "2524 Failed to get the non-embedded SGE "
1855 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001856 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001857 }
1858 virt_addr = mboxq->sge_array->addr[0];
1859
1860 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001861 lpfc_sli_pcimem_bcopy(shdr, shdr,
1862 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001863 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001864 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001865 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001866 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001867 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1868 if_type == LPFC_SLI_INTF_IF_TYPE_2)
James Smart0c9ab6f2010-02-26 14:15:57 -05001869 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001870 "2726 READ_FCF_RECORD Indicates empty "
1871 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001872 else
1873 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001874 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001875 "with status x%x add_status x%x, "
1876 "mbx\n", shdr_status, shdr_add_status);
1877 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001878 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001879
1880 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001881 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1882 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1883 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001884 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001885 new_fcf_record = (struct fcf_record *)(virt_addr +
1886 sizeof(struct lpfc_mbx_read_fcf_tbl));
1887 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001888 offsetof(struct fcf_record, vlan_bitmap));
1889 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1890 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001891
James Smart0c9ab6f2010-02-26 14:15:57 -05001892 return new_fcf_record;
1893}
1894
1895/**
1896 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1897 * @phba: pointer to lpfc hba data structure.
1898 * @fcf_record: pointer to the fcf record.
1899 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1900 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1901 *
1902 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1903 * enabled.
1904 **/
1905static void
1906lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1907 struct fcf_record *fcf_record,
1908 uint16_t vlan_id,
1909 uint16_t next_fcf_index)
1910{
1911 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1912 "2764 READ_FCF_RECORD:\n"
1913 "\tFCF_Index : x%x\n"
1914 "\tFCF_Avail : x%x\n"
1915 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001916 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001917 "\tFIP_Priority : x%x\n"
1918 "\tMAC_Provider : x%x\n"
1919 "\tLowest VLANID : x%x\n"
1920 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1921 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1922 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1923 "\tNext_FCF_Index: x%x\n",
1924 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1925 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1926 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001927 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001928 fcf_record->fip_priority,
1929 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1930 vlan_id,
1931 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1932 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1933 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1934 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1935 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1936 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1937 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1938 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1939 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1940 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1941 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1942 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1943 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1944 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1945 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1946 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1947 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1948 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1949 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1950 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1951 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1952 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1953 next_fcf_index);
1954}
1955
1956/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001957 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1958 * @phba: pointer to lpfc hba data structure.
1959 * @fcf_rec: pointer to an existing FCF record.
1960 * @new_fcf_record: pointer to a new FCF record.
1961 * @new_vlan_id: vlan id from the new FCF record.
1962 *
1963 * This function performs matching test of a new FCF record against an existing
1964 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1965 * will not be used as part of the FCF record matching criteria.
1966 *
1967 * Returns true if all the fields matching, otherwise returns false.
1968 */
1969static bool
1970lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1971 struct lpfc_fcf_rec *fcf_rec,
1972 struct fcf_record *new_fcf_record,
1973 uint16_t new_vlan_id)
1974{
1975 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1976 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1977 return false;
1978 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1979 return false;
1980 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1981 return false;
1982 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1983 return false;
James Smart7d791df2011-07-22 18:37:52 -04001984 if (fcf_rec->priority != new_fcf_record->fip_priority)
1985 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001986 return true;
1987}
1988
1989/**
James Smarta93ff372010-10-22 11:06:08 -04001990 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1991 * @vport: Pointer to vport object.
1992 * @fcf_index: index to next fcf.
1993 *
1994 * This function processing the roundrobin fcf failover to next fcf index.
1995 * When this function is invoked, there will be a current fcf registered
1996 * for flogi.
1997 * Return: 0 for continue retrying flogi on currently registered fcf;
1998 * 1 for stop flogi on currently registered fcf;
1999 */
2000int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2001{
2002 struct lpfc_hba *phba = vport->phba;
2003 int rc;
2004
2005 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2006 spin_lock_irq(&phba->hbalock);
2007 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2008 spin_unlock_irq(&phba->hbalock);
2009 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2010 "2872 Devloss tmo with no eligible "
2011 "FCF, unregister in-use FCF (x%x) "
2012 "and rescan FCF table\n",
2013 phba->fcf.current_rec.fcf_indx);
2014 lpfc_unregister_fcf_rescan(phba);
2015 goto stop_flogi_current_fcf;
2016 }
2017 /* Mark the end to FLOGI roundrobin failover */
2018 phba->hba_flag &= ~FCF_RR_INPROG;
2019 /* Allow action to new fcf asynchronous event */
2020 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2021 spin_unlock_irq(&phba->hbalock);
2022 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2023 "2865 No FCF available, stop roundrobin FCF "
2024 "failover and change port state:x%x/x%x\n",
2025 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2026 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002027
2028 if (!phba->fcf.fcf_redisc_attempted) {
2029 lpfc_unregister_fcf(phba);
2030
2031 rc = lpfc_sli4_redisc_fcf_table(phba);
2032 if (!rc) {
2033 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2034 "3195 Rediscover FCF table\n");
2035 phba->fcf.fcf_redisc_attempted = 1;
2036 lpfc_sli4_clear_fcf_rr_bmask(phba);
2037 } else {
2038 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2039 "3196 Rediscover FCF table "
2040 "failed. Status:x%x\n", rc);
2041 }
2042 } else {
2043 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2044 "3197 Already rediscover FCF table "
2045 "attempted. No more retry\n");
2046 }
James Smarta93ff372010-10-22 11:06:08 -04002047 goto stop_flogi_current_fcf;
2048 } else {
2049 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2050 "2794 Try FLOGI roundrobin FCF failover to "
2051 "(x%x)\n", fcf_index);
2052 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2053 if (rc)
2054 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2055 "2761 FLOGI roundrobin FCF failover "
2056 "failed (rc:x%x) to read FCF (x%x)\n",
2057 rc, phba->fcf.current_rec.fcf_indx);
2058 else
2059 goto stop_flogi_current_fcf;
2060 }
2061 return 0;
2062
2063stop_flogi_current_fcf:
2064 lpfc_can_disctmo(vport);
2065 return 1;
2066}
2067
2068/**
James Smart7d791df2011-07-22 18:37:52 -04002069 * lpfc_sli4_fcf_pri_list_del
2070 * @phba: pointer to lpfc hba data structure.
2071 * @fcf_index the index of the fcf record to delete
2072 * This routine checks the on list flag of the fcf_index to be deleted.
2073 * If it is one the list then it is removed from the list, and the flag
2074 * is cleared. This routine grab the hbalock before removing the fcf
2075 * record from the list.
2076 **/
2077static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2078 uint16_t fcf_index)
2079{
2080 struct lpfc_fcf_pri *new_fcf_pri;
2081
2082 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2083 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2084 "3058 deleting idx x%x pri x%x flg x%x\n",
2085 fcf_index, new_fcf_pri->fcf_rec.priority,
2086 new_fcf_pri->fcf_rec.flag);
2087 spin_lock_irq(&phba->hbalock);
2088 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2089 if (phba->fcf.current_rec.priority ==
2090 new_fcf_pri->fcf_rec.priority)
2091 phba->fcf.eligible_fcf_cnt--;
2092 list_del_init(&new_fcf_pri->list);
2093 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2094 }
2095 spin_unlock_irq(&phba->hbalock);
2096}
2097
2098/**
2099 * lpfc_sli4_set_fcf_flogi_fail
2100 * @phba: pointer to lpfc hba data structure.
2101 * @fcf_index the index of the fcf record to update
2102 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2103 * flag so the the round robin slection for the particular priority level
2104 * will try a different fcf record that does not have this bit set.
2105 * If the fcf record is re-read for any reason this flag is cleared brfore
2106 * adding it to the priority list.
2107 **/
2108void
2109lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2110{
2111 struct lpfc_fcf_pri *new_fcf_pri;
2112 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2113 spin_lock_irq(&phba->hbalock);
2114 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2115 spin_unlock_irq(&phba->hbalock);
2116}
2117
2118/**
2119 * lpfc_sli4_fcf_pri_list_add
2120 * @phba: pointer to lpfc hba data structure.
2121 * @fcf_index the index of the fcf record to add
2122 * This routine checks the priority of the fcf_index to be added.
2123 * If it is a lower priority than the current head of the fcf_pri list
2124 * then it is added to the list in the right order.
2125 * If it is the same priority as the current head of the list then it
2126 * is added to the head of the list and its bit in the rr_bmask is set.
2127 * If the fcf_index to be added is of a higher priority than the current
2128 * head of the list then the rr_bmask is cleared, its bit is set in the
2129 * rr_bmask and it is added to the head of the list.
2130 * returns:
2131 * 0=success 1=failure
2132 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002133static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2134 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002135 struct fcf_record *new_fcf_record)
2136{
2137 uint16_t current_fcf_pri;
2138 uint16_t last_index;
2139 struct lpfc_fcf_pri *fcf_pri;
2140 struct lpfc_fcf_pri *next_fcf_pri;
2141 struct lpfc_fcf_pri *new_fcf_pri;
2142 int ret;
2143
2144 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2145 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2146 "3059 adding idx x%x pri x%x flg x%x\n",
2147 fcf_index, new_fcf_record->fip_priority,
2148 new_fcf_pri->fcf_rec.flag);
2149 spin_lock_irq(&phba->hbalock);
2150 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2151 list_del_init(&new_fcf_pri->list);
2152 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2153 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2154 if (list_empty(&phba->fcf.fcf_pri_list)) {
2155 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2156 ret = lpfc_sli4_fcf_rr_index_set(phba,
2157 new_fcf_pri->fcf_rec.fcf_index);
2158 goto out;
2159 }
2160
2161 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2162 LPFC_SLI4_FCF_TBL_INDX_MAX);
2163 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2164 ret = 0; /* Empty rr list */
2165 goto out;
2166 }
2167 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2168 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2169 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2170 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2171 memset(phba->fcf.fcf_rr_bmask, 0,
2172 sizeof(*phba->fcf.fcf_rr_bmask));
2173 /* fcfs_at_this_priority_level = 1; */
2174 phba->fcf.eligible_fcf_cnt = 1;
2175 } else
2176 /* fcfs_at_this_priority_level++; */
2177 phba->fcf.eligible_fcf_cnt++;
2178 ret = lpfc_sli4_fcf_rr_index_set(phba,
2179 new_fcf_pri->fcf_rec.fcf_index);
2180 goto out;
2181 }
2182
2183 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2184 &phba->fcf.fcf_pri_list, list) {
2185 if (new_fcf_pri->fcf_rec.priority <=
2186 fcf_pri->fcf_rec.priority) {
2187 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2188 list_add(&new_fcf_pri->list,
2189 &phba->fcf.fcf_pri_list);
2190 else
2191 list_add(&new_fcf_pri->list,
2192 &((struct lpfc_fcf_pri *)
2193 fcf_pri->list.prev)->list);
2194 ret = 0;
2195 goto out;
2196 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2197 || new_fcf_pri->fcf_rec.priority <
2198 next_fcf_pri->fcf_rec.priority) {
2199 list_add(&new_fcf_pri->list, &fcf_pri->list);
2200 ret = 0;
2201 goto out;
2202 }
2203 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2204 continue;
2205
2206 }
2207 ret = 1;
2208out:
2209 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2210 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2211 spin_unlock_irq(&phba->hbalock);
2212 return ret;
2213}
2214
2215/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002216 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2217 * @phba: pointer to lpfc hba data structure.
2218 * @mboxq: pointer to mailbox object.
2219 *
2220 * This function iterates through all the fcf records available in
2221 * HBA and chooses the optimal FCF record for discovery. After finding
2222 * the FCF for discovery it registers the FCF record and kicks start
2223 * discovery.
2224 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2225 * use an FCF record which matches fabric name and mac address of the
2226 * currently used FCF record.
2227 * If the driver supports only one FCF, it will try to use the FCF record
2228 * used by BOOT_BIOS.
2229 */
2230void
2231lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2232{
2233 struct fcf_record *new_fcf_record;
2234 uint32_t boot_flag, addr_mode;
2235 uint16_t fcf_index, next_fcf_index;
2236 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002237 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002238 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002239 int rc;
2240
2241 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002242 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002243 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2244 return;
2245 }
2246
2247 /* Parse the FCF record from the non-embedded mailbox command */
2248 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2249 &next_fcf_index);
2250 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002251 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002252 "2765 Mailbox command READ_FCF_RECORD "
2253 "failed to retrieve a FCF record.\n");
2254 /* Let next new FCF event trigger fast failover */
2255 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002256 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002257 spin_unlock_irq(&phba->hbalock);
2258 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2259 return;
2260 }
2261
2262 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002263 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2264 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002265
2266 /* Log the FCF record information if turned on */
2267 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2268 next_fcf_index);
2269
James Smart6fb120a2009-05-22 14:52:59 -04002270 /*
2271 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002272 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002273 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002274 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002275 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002276 lpfc_sli4_fcf_pri_list_del(phba,
2277 bf_get(lpfc_fcf_record_fcf_index,
2278 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002279 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002280 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002281 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002282 bf_get(lpfc_fcf_record_fcf_index,
2283 new_fcf_record),
2284 bf_get(lpfc_fcf_record_fcf_avail,
2285 new_fcf_record),
2286 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002287 new_fcf_record),
2288 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002289 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002290 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2291 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2292 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002293 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2294 phba->fcf.current_rec.fcf_indx) {
2295 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2296 "2862 FCF (x%x) matches property "
2297 "of in-use FCF (x%x)\n",
2298 bf_get(lpfc_fcf_record_fcf_index,
2299 new_fcf_record),
2300 phba->fcf.current_rec.fcf_indx);
2301 goto read_next_fcf;
2302 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002303 /*
2304 * In case the current in-use FCF record becomes
2305 * invalid/unavailable during FCF discovery that
2306 * was not triggered by fast FCF failover process,
2307 * treat it as fast FCF failover.
2308 */
2309 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2310 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2311 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2312 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002313 "(x%x), enter FCF failover "
2314 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002315 phba->fcf.current_rec.fcf_indx);
2316 spin_lock_irq(&phba->hbalock);
2317 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2318 spin_unlock_irq(&phba->hbalock);
2319 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2320 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2321 LPFC_FCOE_FCF_GET_FIRST);
2322 return;
2323 }
2324 }
James Smart6fb120a2009-05-22 14:52:59 -04002325 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002326 } else {
2327 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002328 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2329 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002330 if (rc)
2331 goto read_next_fcf;
2332 }
2333
James Smart6fb120a2009-05-22 14:52:59 -04002334 /*
2335 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002336 * FCF record for the discovery. The condition that a rescan
2337 * matches the in-use FCF record: fabric name, switch name, mac
2338 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002339 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002340 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002341 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002342 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2343 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002344 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002345 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2346 phba->fcf.current_rec.fcf_indx) {
2347 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2348 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2349 /* Stop FCF redisc wait timer */
2350 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2351 phba);
2352 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2353 /* Fast failover, mark completed */
2354 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2355 spin_unlock_irq(&phba->hbalock);
2356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2357 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002358 "FCF (x%x), port_state:x%x, "
2359 "fc_flag:x%x\n",
2360 phba->fcf.current_rec.fcf_indx,
2361 phba->pport->port_state,
2362 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002363 goto out;
2364 } else
2365 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2366 "2863 New FCF (x%x) matches "
2367 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002368 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002369 new_fcf_record),
2370 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002371 }
James Smartecfd03c2010-02-12 14:41:27 -05002372 /*
2373 * Read next FCF record from HBA searching for the matching
2374 * with in-use record only if not during the fast failover
2375 * period. In case of fast failover period, it shall try to
2376 * determine whether the FCF record just read should be the
2377 * next candidate.
2378 */
2379 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002380 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002381 goto read_next_fcf;
2382 }
James Smart6fb120a2009-05-22 14:52:59 -04002383 }
James Smartecfd03c2010-02-12 14:41:27 -05002384 /*
2385 * Update on failover FCF record only if it's in FCF fast-failover
2386 * period; otherwise, update on current FCF record.
2387 */
James Smartfc2b9892010-02-26 14:15:29 -05002388 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2389 fcf_rec = &phba->fcf.failover_rec;
2390 else
James Smartecfd03c2010-02-12 14:41:27 -05002391 fcf_rec = &phba->fcf.current_rec;
2392
James Smart6fb120a2009-05-22 14:52:59 -04002393 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2394 /*
James Smartecfd03c2010-02-12 14:41:27 -05002395 * If the driver FCF record does not have boot flag
2396 * set and new hba fcf record has boot flag set, use
2397 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002398 */
James Smartecfd03c2010-02-12 14:41:27 -05002399 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2400 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002401 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2402 "2837 Update current FCF record "
2403 "(x%x) with new FCF record (x%x)\n",
2404 fcf_rec->fcf_indx,
2405 bf_get(lpfc_fcf_record_fcf_index,
2406 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002407 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2408 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002409 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002410 goto read_next_fcf;
2411 }
2412 /*
James Smartecfd03c2010-02-12 14:41:27 -05002413 * If the driver FCF record has boot flag set and the
2414 * new hba FCF record does not have boot flag, read
2415 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002416 */
James Smartecfd03c2010-02-12 14:41:27 -05002417 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002418 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002419 goto read_next_fcf;
2420 }
2421 /*
James Smartecfd03c2010-02-12 14:41:27 -05002422 * If the new hba FCF record has lower priority value
2423 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002424 */
James Smartfc2b9892010-02-26 14:15:29 -05002425 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002426 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002427 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2428 "2838 Update current FCF record "
2429 "(x%x) with new FCF record (x%x)\n",
2430 fcf_rec->fcf_indx,
2431 bf_get(lpfc_fcf_record_fcf_index,
2432 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002433 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2434 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002435 /* Reset running random FCF selection count */
2436 phba->fcf.eligible_fcf_cnt = 1;
2437 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2438 /* Update running random FCF selection count */
2439 phba->fcf.eligible_fcf_cnt++;
2440 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2441 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002442 if (select_new_fcf) {
2443 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2444 "2839 Update current FCF record "
2445 "(x%x) with new FCF record (x%x)\n",
2446 fcf_rec->fcf_indx,
2447 bf_get(lpfc_fcf_record_fcf_index,
2448 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002449 /* Choose the new FCF by random selection */
2450 __lpfc_update_fcf_record(phba, fcf_rec,
2451 new_fcf_record,
2452 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002453 }
James Smart6fb120a2009-05-22 14:52:59 -04002454 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002455 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002456 goto read_next_fcf;
2457 }
2458 /*
James Smartecfd03c2010-02-12 14:41:27 -05002459 * This is the first suitable FCF record, choose this record for
2460 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002461 */
James Smartecfd03c2010-02-12 14:41:27 -05002462 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002463 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002464 "2840 Update initial FCF candidate "
2465 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002466 bf_get(lpfc_fcf_record_fcf_index,
2467 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002468 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2469 addr_mode, vlan_id, (boot_flag ?
2470 BOOT_ENABLE : 0));
2471 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002472 /* Setup initial running random FCF selection count */
2473 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002474 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002475 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002476 goto read_next_fcf;
2477
2478read_next_fcf:
2479 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002480 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2481 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2482 /*
2483 * Case of FCF fast failover scan
2484 */
2485
2486 /*
2487 * It has not found any suitable FCF record, cancel
2488 * FCF scan inprogress, and do nothing
2489 */
2490 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002491 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002492 "2782 No suitable FCF found: "
2493 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002494 phba->fcoe_eventtag_at_fcf_scan,
2495 bf_get(lpfc_fcf_record_fcf_index,
2496 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002497 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002498 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2499 phba->hba_flag &= ~FCF_TS_INPROG;
2500 spin_unlock_irq(&phba->hbalock);
2501 /* Unregister in-use FCF and rescan */
2502 lpfc_printf_log(phba, KERN_INFO,
2503 LOG_FIP,
2504 "2864 On devloss tmo "
2505 "unreg in-use FCF and "
2506 "rescan FCF table\n");
2507 lpfc_unregister_fcf_rescan(phba);
2508 return;
2509 }
2510 /*
2511 * Let next new FCF event trigger fast failover
2512 */
2513 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002514 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002515 return;
2516 }
2517 /*
2518 * It has found a suitable FCF record that is not
2519 * the same as in-use FCF record, unregister the
2520 * in-use FCF record, replace the in-use FCF record
2521 * with the new FCF record, mark FCF fast failover
2522 * completed, and then start register the new FCF
2523 * record.
2524 */
2525
James Smart0c9ab6f2010-02-26 14:15:57 -05002526 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002527 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002528
2529 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002530 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002531 "2842 Replace in-use FCF (x%x) "
2532 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002533 phba->fcf.current_rec.fcf_indx,
2534 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002535 memcpy(&phba->fcf.current_rec,
2536 &phba->fcf.failover_rec,
2537 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002538 /*
2539 * Mark the fast FCF failover rediscovery completed
2540 * and the start of the first round of the roundrobin
2541 * FCF failover.
2542 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002543 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002544 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002545 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002546 /* Register to the new FCF record */
2547 lpfc_register_fcf(phba);
2548 } else {
2549 /*
2550 * In case of transaction period to fast FCF failover,
2551 * do nothing when search to the end of the FCF table.
2552 */
2553 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2554 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2555 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002556
James Smart7d791df2011-07-22 18:37:52 -04002557 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2558 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002559 /*
2560 * In case the current in-use FCF record no
2561 * longer existed during FCF discovery that
2562 * was not triggered by fast FCF failover
2563 * process, treat it as fast FCF failover.
2564 */
2565 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2566 "2841 In-use FCF record (x%x) "
2567 "not reported, entering fast "
2568 "FCF failover mode scanning.\n",
2569 phba->fcf.current_rec.fcf_indx);
2570 spin_lock_irq(&phba->hbalock);
2571 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2572 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002573 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2574 LPFC_FCOE_FCF_GET_FIRST);
2575 return;
2576 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002577 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002578 lpfc_register_fcf(phba);
2579 }
2580 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002581 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002582 return;
2583
2584out:
2585 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2586 lpfc_register_fcf(phba);
2587
2588 return;
2589}
2590
2591/**
James Smarta93ff372010-10-22 11:06:08 -04002592 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002593 * @phba: pointer to lpfc hba data structure.
2594 * @mboxq: pointer to mailbox object.
2595 *
James Smarta93ff372010-10-22 11:06:08 -04002596 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002597 * read FCF record mailbox command from the eligible FCF record bmask for
2598 * performing the failover. If the FCF read back is not valid/available, it
2599 * fails through to retrying FLOGI to the currently registered FCF again.
2600 * Otherwise, if the FCF read back is valid and available, it will set the
2601 * newly read FCF record to the failover FCF record, unregister currently
2602 * registered FCF record, copy the failover FCF record to the current
2603 * FCF record, and then register the current FCF record before proceeding
2604 * to trying FLOGI on the new failover FCF.
2605 */
2606void
2607lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2608{
2609 struct fcf_record *new_fcf_record;
2610 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002611 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002612 uint16_t current_fcf_index;
2613 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002614 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002615
James Smarta93ff372010-10-22 11:06:08 -04002616 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002617 if (phba->link_state < LPFC_LINK_UP) {
2618 spin_lock_irq(&phba->hbalock);
2619 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002620 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002621 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002622 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002623 }
2624
2625 /* Parse the FCF record from the non-embedded mailbox command */
2626 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2627 &next_fcf_index);
2628 if (!new_fcf_record) {
2629 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2630 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002631 "failed to retrieve a FCF record. "
2632 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2633 phba->fcf.fcf_flag);
2634 lpfc_unregister_fcf_rescan(phba);
2635 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002636 }
2637
2638 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002639 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2640 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002641
2642 /* Log the FCF record information if turned on */
2643 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2644 next_fcf_index);
2645
James Smarta93ff372010-10-22 11:06:08 -04002646 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2647 if (!rc) {
2648 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2649 "2848 Remove ineligible FCF (x%x) from "
2650 "from roundrobin bmask\n", fcf_index);
2651 /* Clear roundrobin bmask bit for ineligible FCF */
2652 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2653 /* Perform next round of roundrobin FCF failover */
2654 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2655 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2656 if (rc)
2657 goto out;
2658 goto error_out;
2659 }
2660
2661 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2662 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2663 "2760 Perform FLOGI roundrobin FCF failover: "
2664 "FCF (x%x) back to FCF (x%x)\n",
2665 phba->fcf.current_rec.fcf_indx, fcf_index);
2666 /* Wait 500 ms before retrying FLOGI to current FCF */
2667 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002668 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002669 goto out;
2670 }
2671
James Smart0c9ab6f2010-02-26 14:15:57 -05002672 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002673 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002674 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2675 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002676 spin_lock_irq(&phba->hbalock);
2677 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2678 new_fcf_record, addr_mode, vlan_id,
2679 (boot_flag ? BOOT_ENABLE : 0));
2680 spin_unlock_irq(&phba->hbalock);
2681
2682 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2683
2684 /* Unregister the current in-use FCF record */
2685 lpfc_unregister_fcf(phba);
2686
2687 /* Replace in-use record with the new record */
2688 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2689 sizeof(struct lpfc_fcf_rec));
2690
2691 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002692 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2693 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002694
James Smarta93ff372010-10-22 11:06:08 -04002695error_out:
2696 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002697out:
2698 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002699}
2700
2701/**
2702 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2703 * @phba: pointer to lpfc hba data structure.
2704 * @mboxq: pointer to mailbox object.
2705 *
2706 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002707 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002708 * failover when a new FCF event happened. If the FCF read back is
2709 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002710 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002711 */
2712void
2713lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2714{
2715 struct fcf_record *new_fcf_record;
2716 uint32_t boot_flag, addr_mode;
2717 uint16_t fcf_index, next_fcf_index;
2718 uint16_t vlan_id;
2719 int rc;
2720
2721 /* If link state is not up, no need to proceed */
2722 if (phba->link_state < LPFC_LINK_UP)
2723 goto out;
2724
2725 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002726 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002727 goto out;
2728
2729 /* Parse the FCF record from the non-embedded mailbox command */
2730 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2731 &next_fcf_index);
2732 if (!new_fcf_record) {
2733 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2734 "2767 Mailbox command READ_FCF_RECORD "
2735 "failed to retrieve a FCF record.\n");
2736 goto out;
2737 }
2738
2739 /* Check the connection list for eligibility */
2740 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2741 &addr_mode, &vlan_id);
2742
2743 /* Log the FCF record information if turned on */
2744 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2745 next_fcf_index);
2746
2747 if (!rc)
2748 goto out;
2749
2750 /* Update the eligible FCF record index bmask */
2751 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002752
2753 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002754
2755out:
2756 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2757}
2758
2759/**
James Smart76a95d72010-11-20 23:11:48 -05002760 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2761 * @phba: pointer to lpfc hba data structure.
2762 * @mboxq: pointer to mailbox data structure.
2763 *
2764 * This function handles completion of init vfi mailbox command.
2765 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002766static void
James Smart76a95d72010-11-20 23:11:48 -05002767lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2768{
2769 struct lpfc_vport *vport = mboxq->vport;
2770
James Smartdf9e1b52011-12-13 13:22:17 -05002771 /*
2772 * VFI not supported on interface type 0, just do the flogi
2773 * Also continue if the VFI is in use - just use the same one.
2774 */
2775 if (mboxq->u.mb.mbxStatus &&
2776 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2777 LPFC_SLI_INTF_IF_TYPE_0) &&
2778 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002779 lpfc_printf_vlog(vport, KERN_ERR,
2780 LOG_MBOX,
2781 "2891 Init VFI mailbox failed 0x%x\n",
2782 mboxq->u.mb.mbxStatus);
2783 mempool_free(mboxq, phba->mbox_mem_pool);
2784 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2785 return;
2786 }
James Smart73d91e52011-10-10 21:32:10 -04002787
James Smart76a95d72010-11-20 23:11:48 -05002788 lpfc_initial_flogi(vport);
2789 mempool_free(mboxq, phba->mbox_mem_pool);
2790 return;
2791}
2792
2793/**
2794 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2795 * @vport: pointer to lpfc_vport data structure.
2796 *
2797 * This function issue a init_vfi mailbox command to initialize the VFI and
2798 * VPI for the physical port.
2799 */
2800void
2801lpfc_issue_init_vfi(struct lpfc_vport *vport)
2802{
2803 LPFC_MBOXQ_t *mboxq;
2804 int rc;
2805 struct lpfc_hba *phba = vport->phba;
2806
2807 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2808 if (!mboxq) {
2809 lpfc_printf_vlog(vport, KERN_ERR,
2810 LOG_MBOX, "2892 Failed to allocate "
2811 "init_vfi mailbox\n");
2812 return;
2813 }
2814 lpfc_init_vfi(mboxq, vport);
2815 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2816 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2817 if (rc == MBX_NOT_FINISHED) {
2818 lpfc_printf_vlog(vport, KERN_ERR,
2819 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2820 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2821 }
2822}
2823
2824/**
James Smart1c6834a2009-07-19 10:01:26 -04002825 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2826 * @phba: pointer to lpfc hba data structure.
2827 * @mboxq: pointer to mailbox data structure.
2828 *
2829 * This function handles completion of init vpi mailbox command.
2830 */
James Smart695a8142010-01-26 23:08:03 -05002831void
James Smart1c6834a2009-07-19 10:01:26 -04002832lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2833{
2834 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002835 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2837
James Smart1c6834a2009-07-19 10:01:26 -04002838 if (mboxq->u.mb.mbxStatus) {
2839 lpfc_printf_vlog(vport, KERN_ERR,
2840 LOG_MBOX,
2841 "2609 Init VPI mailbox failed 0x%x\n",
2842 mboxq->u.mb.mbxStatus);
2843 mempool_free(mboxq, phba->mbox_mem_pool);
2844 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2845 return;
2846 }
James Smart72100cc2010-02-12 14:43:01 -05002847 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002848 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002849 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002850
James Smart695a8142010-01-26 23:08:03 -05002851 /* If this port is physical port or FDISC is done, do reg_vpi */
2852 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2853 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2854 if (!ndlp)
2855 lpfc_printf_vlog(vport, KERN_ERR,
2856 LOG_DISCOVERY,
2857 "2731 Cannot find fabric "
2858 "controller node\n");
2859 else
2860 lpfc_register_new_vport(phba, vport, ndlp);
2861 mempool_free(mboxq, phba->mbox_mem_pool);
2862 return;
2863 }
2864
James Smart1c6834a2009-07-19 10:01:26 -04002865 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2866 lpfc_initial_fdisc(vport);
2867 else {
2868 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002869 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2870 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002871 }
James Smart695a8142010-01-26 23:08:03 -05002872 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002873 return;
2874}
2875
2876/**
James Smartecfd03c2010-02-12 14:41:27 -05002877 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2878 * @vport: pointer to lpfc_vport data structure.
2879 *
2880 * This function issue a init_vpi mailbox command to initialize
2881 * VPI for the vport.
2882 */
2883void
2884lpfc_issue_init_vpi(struct lpfc_vport *vport)
2885{
2886 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002887 int rc, vpi;
2888
2889 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2890 vpi = lpfc_alloc_vpi(vport->phba);
2891 if (!vpi) {
2892 lpfc_printf_vlog(vport, KERN_ERR,
2893 LOG_MBOX,
2894 "3303 Failed to obtain vport vpi\n");
2895 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2896 return;
2897 }
2898 vport->vpi = vpi;
2899 }
James Smartecfd03c2010-02-12 14:41:27 -05002900
2901 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2902 if (!mboxq) {
2903 lpfc_printf_vlog(vport, KERN_ERR,
2904 LOG_MBOX, "2607 Failed to allocate "
2905 "init_vpi mailbox\n");
2906 return;
2907 }
2908 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2909 mboxq->vport = vport;
2910 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2911 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2912 if (rc == MBX_NOT_FINISHED) {
2913 lpfc_printf_vlog(vport, KERN_ERR,
2914 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2915 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2916 }
2917}
2918
2919/**
James Smart6fb120a2009-05-22 14:52:59 -04002920 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2921 * @phba: pointer to lpfc hba data structure.
2922 *
2923 * This function loops through the list of vports on the @phba and issues an
2924 * FDISC if possible.
2925 */
2926void
2927lpfc_start_fdiscs(struct lpfc_hba *phba)
2928{
2929 struct lpfc_vport **vports;
2930 int i;
2931
2932 vports = lpfc_create_vport_work_array(phba);
2933 if (vports != NULL) {
2934 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2935 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2936 continue;
2937 /* There are no vpi for this vport */
2938 if (vports[i]->vpi > phba->max_vpi) {
2939 lpfc_vport_set_state(vports[i],
2940 FC_VPORT_FAILED);
2941 continue;
2942 }
James Smart76a95d72010-11-20 23:11:48 -05002943 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002944 lpfc_vport_set_state(vports[i],
2945 FC_VPORT_LINKDOWN);
2946 continue;
2947 }
James Smart1c6834a2009-07-19 10:01:26 -04002948 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002949 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002950 continue;
2951 }
James Smart6fb120a2009-05-22 14:52:59 -04002952 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2953 lpfc_initial_fdisc(vports[i]);
2954 else {
2955 lpfc_vport_set_state(vports[i],
2956 FC_VPORT_NO_FABRIC_SUPP);
2957 lpfc_printf_vlog(vports[i], KERN_ERR,
2958 LOG_ELS,
2959 "0259 No NPIV "
2960 "Fabric support\n");
2961 }
2962 }
2963 }
2964 lpfc_destroy_vport_work_array(phba, vports);
2965}
2966
2967void
2968lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2969{
James Smart3e1f0712018-11-29 16:09:29 -08002970 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04002971 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002973
James Smartf5eca9b2012-03-01 22:37:54 -05002974 /*
2975 * VFI not supported for interface type 0, so ignore any mailbox
2976 * error (except VFI in use) and continue with the discovery.
2977 */
2978 if (mboxq->u.mb.mbxStatus &&
2979 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2980 LPFC_SLI_INTF_IF_TYPE_0) &&
2981 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002982 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2983 "2018 REG_VFI mbxStatus error x%x "
2984 "HBA state x%x\n",
2985 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002986 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002987 /* FLOGI failed, use loop map to make discovery list */
2988 lpfc_disc_list_loopmap(vport);
2989 /* Start discovery */
2990 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002991 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002992 }
2993 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002994 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002995 }
James Smartae05ebe2013-03-01 16:35:38 -05002996
James Smarte74c03c2013-04-17 20:15:19 -04002997 /* If the VFI is already registered, there is nothing else to do
2998 * Unless this was a VFI update and we are in PT2PT mode, then
2999 * we should drop through to set the port state to ready.
3000 */
James Smartae05ebe2013-03-01 16:35:38 -05003001 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04003002 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3003 vport->fc_flag & FC_PT2PT))
3004 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05003005
James Smartc8685952009-11-18 15:39:16 -05003006 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05003007 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003008 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003009 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003010 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003011 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003012 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003013
James Smart1b511972011-12-13 13:23:09 -05003014 /* In case SLI4 FC loopback test, we are ready */
3015 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3016 (phba->link_flag & LS_LOOPBACK_MODE)) {
3017 phba->link_state = LPFC_HBA_READY;
3018 goto out_free_mem;
3019 }
3020
James Smarte74c03c2013-04-17 20:15:19 -04003021 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3022 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3023 "alpacnt:%d LinkState:%x topology:%x\n",
3024 vport->port_state, vport->fc_flag, vport->fc_myDID,
3025 vport->phba->alpa_map[0],
3026 phba->link_state, phba->fc_topology);
3027
James Smart6fb120a2009-05-22 14:52:59 -04003028 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003029 /*
3030 * For private loop or for NPort pt2pt,
3031 * just start discovery and we are done.
3032 */
3033 if ((vport->fc_flag & FC_PT2PT) ||
3034 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3035 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3036
James Smart76a95d72010-11-20 23:11:48 -05003037 /* Use loop map to make discovery list */
3038 lpfc_disc_list_loopmap(vport);
3039 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003040 if (vport->fc_flag & FC_PT2PT)
3041 vport->port_state = LPFC_VPORT_READY;
3042 else
3043 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003044 } else {
3045 lpfc_start_fdiscs(phba);
3046 lpfc_do_scr_ns_plogi(phba, vport);
3047 }
James Smart6fb120a2009-05-22 14:52:59 -04003048 }
3049
James Smart1b511972011-12-13 13:23:09 -05003050out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003051 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003052 if (dmabuf) {
3053 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3054 kfree(dmabuf);
3055 }
James Smart6fb120a2009-05-22 14:52:59 -04003056 return;
3057}
3058
3059static void
James Smart2e0fef82007-06-17 19:56:36 -05003060lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003061{
James Smart6fb120a2009-05-22 14:52:59 -04003062 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003063 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003064 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003065 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003066 struct serv_parm *sp = &vport->fc_sparam;
3067 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003068
3069 /* Check for error */
3070 if (mb->mbxStatus) {
3071 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003072 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3073 "0319 READ_SPARAM mbxStatus error x%x "
3074 "hba state x%x>\n",
3075 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003076 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003077 goto out;
3078 }
3079
James Smart2e0fef82007-06-17 19:56:36 -05003080 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003081 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003082
3083 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3084 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3085 ed_tov = (ed_tov + 999999) / 1000000;
3086
3087 phba->fc_edtov = ed_tov;
3088 phba->fc_ratov = (2 * ed_tov) / 1000;
3089 if (phba->fc_ratov < FF_DEF_RATOV) {
3090 /* RA_TOV should be atleast 10sec for initial flogi */
3091 phba->fc_ratov = FF_DEF_RATOV;
3092 }
3093
James Smart05580562011-05-24 11:40:48 -04003094 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003095 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003096 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3097 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3098 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3099 }
3100
dea31012005-04-17 16:05:31 -05003101 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3102 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003103 mempool_free(pmb, phba->mbox_mem_pool);
James Smart835214f2020-01-27 16:23:03 -08003104
3105 /* Check if sending the FLOGI is being deferred to after we get
3106 * up to date CSPs from MBX_READ_SPARAM.
3107 */
3108 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3109 lpfc_initial_flogi(vport);
3110 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3111 }
dea31012005-04-17 16:05:31 -05003112 return;
3113
3114out:
James Smart3e1f0712018-11-29 16:09:29 -08003115 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003116 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3117 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003118 lpfc_issue_clear_la(phba, vport);
3119 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003120 return;
3121}
3122
3123static void
James Smart76a95d72010-11-20 23:11:48 -05003124lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003125{
James Smart92d7f7b2007-06-17 19:56:38 -05003126 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003127 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003128 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003129 int i;
James Smart14691152006-12-02 13:34:28 -05003130 struct lpfc_dmabuf *mp;
3131 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003132 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003133 uint32_t fc_flags = 0;
James Smart894bb172019-08-14 16:56:52 -07003134 unsigned long iflags;
James Smart14691152006-12-02 13:34:28 -05003135
James Smart894bb172019-08-14 16:56:52 -07003136 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta085e872015-12-16 18:12:02 -05003137 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3138
3139 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3140 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3141 case LPFC_LINK_SPEED_1GHZ:
3142 case LPFC_LINK_SPEED_2GHZ:
3143 case LPFC_LINK_SPEED_4GHZ:
3144 case LPFC_LINK_SPEED_8GHZ:
3145 case LPFC_LINK_SPEED_10GHZ:
3146 case LPFC_LINK_SPEED_16GHZ:
3147 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003148 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003149 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003150 break;
3151 default:
3152 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3153 break;
3154 }
dea31012005-04-17 16:05:31 -05003155 }
3156
James Smarte74c03c2013-04-17 20:15:19 -04003157 if (phba->fc_topology &&
3158 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3159 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3160 "3314 Toplogy changed was 0x%x is 0x%x\n",
3161 phba->fc_topology,
3162 bf_get(lpfc_mbx_read_top_topology, la));
3163 phba->fc_topology_changed = 1;
3164 }
3165
James Smart76a95d72010-11-20 23:11:48 -05003166 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003167 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003168
James Smartdf9e1b52011-12-13 13:22:17 -05003169 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003170 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003171 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003172
James Smart6a9c52c2009-10-02 15:16:51 -04003173 /* if npiv is enabled and this adapter supports npiv log
3174 * a message that npiv is not supported in this topology
3175 */
3176 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003177 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3178 "1309 Link Up Event npiv not supported in loop "
3179 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003180 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003181 if (bf_get(lpfc_mbx_read_top_il, la))
3182 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003183
James Smart76a95d72010-11-20 23:11:48 -05003184 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3185 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003186
3187 if (i == 0) {
3188 phba->alpa_map[0] = 0;
3189 } else {
James Smarte8b62012007-08-02 11:10:09 -04003190 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003191 int numalpa, j, k;
3192 union {
3193 uint8_t pamap[16];
3194 struct {
3195 uint32_t wd1;
3196 uint32_t wd2;
3197 uint32_t wd3;
3198 uint32_t wd4;
3199 } pa;
3200 } un;
3201 numalpa = phba->alpa_map[0];
3202 j = 0;
3203 while (j < numalpa) {
3204 memset(un.pamap, 0, 16);
3205 for (k = 1; j < numalpa; k++) {
3206 un.pamap[k - 1] =
3207 phba->alpa_map[j + 1];
3208 j++;
3209 if (k == 16)
3210 break;
3211 }
3212 /* Link Up Event ALPA map */
3213 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003214 KERN_WARNING,
3215 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003216 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003217 "ALPA map Data: x%x "
3218 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003219 un.pa.wd1, un.pa.wd2,
3220 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003221 }
3222 }
3223 }
3224 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003225 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003226 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003227 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003228 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3229 }
James Smart2e0fef82007-06-17 19:56:36 -05003230 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003231 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003232 }
James Smart894bb172019-08-14 16:56:52 -07003233 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003234
James Smart38c20672013-03-01 16:37:44 -05003235 if (fc_flags) {
James Smart894bb172019-08-14 16:56:52 -07003236 spin_lock_irqsave(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003237 vport->fc_flag |= fc_flags;
James Smart894bb172019-08-14 16:56:52 -07003238 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003239 }
3240
dea31012005-04-17 16:05:31 -05003241 lpfc_linkup(phba);
James Smart835214f2020-01-27 16:23:03 -08003242 sparam_mbox = NULL;
3243
3244 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3245 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3246 if (!cfglink_mbox)
3247 goto out;
3248 vport->port_state = LPFC_LOCAL_CFG_LINK;
3249 lpfc_config_link(phba, cfglink_mbox);
3250 cfglink_mbox->vport = vport;
3251 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3252 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3253 if (rc == MBX_NOT_FINISHED) {
3254 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3255 goto out;
3256 }
3257 }
3258
James Smart9f1177a2010-02-26 14:12:57 -05003259 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3260 if (!sparam_mbox)
3261 goto out;
3262
3263 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3264 if (rc) {
3265 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3266 goto out;
3267 }
3268 sparam_mbox->vport = vport;
3269 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3270 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3271 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003272 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003273 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3274 kfree(mp);
3275 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3276 goto out;
dea31012005-04-17 16:05:31 -05003277 }
3278
James Smart835214f2020-01-27 16:23:03 -08003279 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart32b97932009-07-19 10:01:21 -04003280 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003281 /*
3282 * Add the driver's default FCF record at FCF index 0 now. This
3283 * is phase 1 implementation that support FCF index 0 and driver
3284 * defaults.
3285 */
James Smart45ed1192009-10-02 15:17:02 -04003286 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003287 fcf_record = kzalloc(sizeof(struct fcf_record),
3288 GFP_KERNEL);
3289 if (unlikely(!fcf_record)) {
3290 lpfc_printf_log(phba, KERN_ERR,
3291 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003292 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003293 "fcf record\n");
3294 rc = -ENODEV;
3295 goto out;
3296 }
3297
3298 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3299 LPFC_FCOE_FCF_DEF_INDEX);
3300 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3301 if (unlikely(rc)) {
3302 lpfc_printf_log(phba, KERN_ERR,
3303 LOG_MBOX | LOG_SLI,
3304 "2013 Could not manually add FCF "
3305 "record 0, status %d\n", rc);
3306 rc = -ENODEV;
3307 kfree(fcf_record);
3308 goto out;
3309 }
3310 kfree(fcf_record);
3311 }
3312 /*
3313 * The driver is expected to do FIP/FCF. Call the port
3314 * and get the FCF Table.
3315 */
James Smart894bb172019-08-14 16:56:52 -07003316 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta93ff372010-10-22 11:06:08 -04003317 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart894bb172019-08-14 16:56:52 -07003318 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart32b97932009-07-19 10:01:21 -04003319 return;
3320 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003321 /* This is the initial FCF discovery scan */
3322 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003323 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003324 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3325 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003326 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3327 LPFC_FCOE_FCF_GET_FIRST);
3328 if (rc) {
James Smart894bb172019-08-14 16:56:52 -07003329 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003330 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003331 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6fb120a2009-05-22 14:52:59 -04003332 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003333 }
James Smart38b92ef2010-08-04 16:11:39 -04003334 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003335 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart835214f2020-01-27 16:23:03 -08003336 } else {
3337 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
3338 !(phba->link_flag & LS_LOOPBACK_MODE))
3339 phba->hba_flag |= HBA_DEFER_FLOGI;
dea31012005-04-17 16:05:31 -05003340 }
James Smart6fb120a2009-05-22 14:52:59 -04003341
James Smarte3ba04c2019-12-18 15:58:02 -08003342 /* Prepare for LINK up registrations */
3343 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3344 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3345 init_utsname()->nodename);
James Smart6fb120a2009-05-22 14:52:59 -04003346 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003347out:
3348 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003349 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart32350662019-08-14 16:57:06 -07003350 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04003351 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003352 lpfc_issue_clear_la(phba, vport);
3353 return;
dea31012005-04-17 16:05:31 -05003354}
3355
3356static void
James Smart84774a42008-08-24 21:50:06 -04003357lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003358{
dea31012005-04-17 16:05:31 -05003359 uint32_t control;
3360 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003361 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003362 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003363 if (phba->sli_rev <= LPFC_SLI_REV3) {
3364 control = readl(phba->HCregaddr);
3365 control |= HC_LAINT_ENA;
3366 writel(control, phba->HCregaddr);
3367 readl(phba->HCregaddr); /* flush */
3368 }
James Smart2e0fef82007-06-17 19:56:36 -05003369 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003370}
3371
James Smart84774a42008-08-24 21:50:06 -04003372static void
3373lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3374{
3375 lpfc_linkdown(phba);
3376 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003377 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003378 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3379}
3380
3381
dea31012005-04-17 16:05:31 -05003382/*
James Smart76a95d72010-11-20 23:11:48 -05003383 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003384 * command upon completion. It is setup in the LPFC_MBOXQ
3385 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003386 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003387 */
3388void
James Smart76a95d72010-11-20 23:11:48 -05003389lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003390{
James Smart2e0fef82007-06-17 19:56:36 -05003391 struct lpfc_vport *vport = pmb->vport;
3392 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003393 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003394 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003395 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003396 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003397 uint8_t attn_type;
James Smart894bb172019-08-14 16:56:52 -07003398 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003399
James Smart0d2b6b82008-06-14 22:52:47 -04003400 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003401 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003402 if (pring)
3403 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003404
dea31012005-04-17 16:05:31 -05003405 /* Check for error */
3406 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003407 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003408 "1307 READ_LA mbox error x%x state x%x\n",
3409 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003410 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003411 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003412 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003413 }
3414
James Smart76a95d72010-11-20 23:11:48 -05003415 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003416 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003417
3418 memcpy(&phba->alpa_map[0], mp->virt, 128);
3419
James Smart894bb172019-08-14 16:56:52 -07003420 spin_lock_irqsave(shost->host_lock, iflags);
James Smart76a95d72010-11-20 23:11:48 -05003421 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003422 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003423 else
James Smart2e0fef82007-06-17 19:56:36 -05003424 vport->fc_flag &= ~FC_BYPASSED_MODE;
James Smart894bb172019-08-14 16:56:52 -07003425 spin_unlock_irqrestore(shost->host_lock, iflags);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003426
James Smartbe0c0082013-03-01 16:38:14 -05003427 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003428 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003429 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003430 if (phba->fc_eventTag != 0)
3431 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003432 }
dea31012005-04-17 16:05:31 -05003433
3434 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003435 if (phba->sli_rev < LPFC_SLI_REV4) {
James Smart894bb172019-08-14 16:56:52 -07003436 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003437 if (bf_get(lpfc_mbx_read_top_mm, la))
3438 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3439 else
3440 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart894bb172019-08-14 16:56:52 -07003441 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003442 }
dea31012005-04-17 16:05:31 -05003443
James Smart4d9ab992009-10-02 15:16:39 -04003444 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003445 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003446 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003447 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003448 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003449 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003450 "1306 Link Up Event in loop back mode "
3451 "x%x received Data: x%x x%x x%x x%x\n",
3452 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003453 bf_get(lpfc_mbx_read_top_alpa_granted,
3454 la),
3455 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003456 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003457 } else {
3458 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003459 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003460 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003461 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003462 bf_get(lpfc_mbx_read_top_alpa_granted,
3463 la),
3464 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003465 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003466 bf_get(lpfc_mbx_read_top_mm, la),
3467 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003468 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003469 }
James Smart92d7f7b2007-06-17 19:56:38 -05003470 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003471 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3472 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003473 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003474 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003475 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3476 "1308 Link Down Event in loop back mode "
3477 "x%x received "
3478 "Data: x%x x%x x%x\n",
3479 la->eventTag, phba->fc_eventTag,
3480 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003481 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3482 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smartb9da8142019-11-04 16:57:04 -08003483 "1313 Link Down Unexpected FA WWPN Event x%x "
3484 "received Data: x%x x%x x%x x%x x%x\n",
James Smartaeb3c812017-04-21 16:05:02 -07003485 la->eventTag, phba->fc_eventTag,
3486 phba->pport->port_state, vport->fc_flag,
3487 bf_get(lpfc_mbx_read_top_mm, la),
3488 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003489 else
James Smart3163f722008-02-08 18:50:25 -05003490 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003491 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003492 "Data: x%x x%x x%x x%x x%x\n",
3493 la->eventTag, phba->fc_eventTag,
3494 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003495 bf_get(lpfc_mbx_read_top_mm, la),
3496 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003497 lpfc_mbx_issue_link_down(phba);
3498 }
James Smartaeb3c812017-04-21 16:05:02 -07003499 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3500 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003501 if (phba->link_state != LPFC_LINK_DOWN) {
3502 phba->fc_stat.LinkDown++;
3503 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3504 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003505 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003506 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003507 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003508 lpfc_mbx_issue_link_down(phba);
3509 } else
3510 lpfc_enable_la(phba);
3511
3512 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3513 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3514 "Data: x%x x%x x%x\n",
3515 la->eventTag, phba->fc_eventTag,
3516 phba->pport->port_state, vport->fc_flag);
3517 /*
3518 * The cmnd that triggered this will be waiting for this
3519 * signal.
3520 */
3521 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3522 if (phba->wait_4_mlo_maint_flg) {
3523 phba->wait_4_mlo_maint_flg = 0;
3524 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003525 }
James Smart84774a42008-08-24 21:50:06 -04003526 }
3527
James Smartbe0c0082013-03-01 16:38:14 -05003528 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3529 bf_get(lpfc_mbx_read_top_fa, la)) {
3530 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003531 lpfc_issue_clear_la(phba, vport);
3532 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003533 "1311 fa %d\n",
3534 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003535 }
3536
James Smart76a95d72010-11-20 23:11:48 -05003537lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003538 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3539 kfree(mp);
3540 mempool_free(pmb, phba->mbox_mem_pool);
3541 return;
3542}
3543
3544/*
3545 * This routine handles processing a REG_LOGIN mailbox
3546 * command upon completion. It is setup in the LPFC_MBOXQ
3547 * as the completion routine when the command is
3548 * handed off to the SLI layer.
3549 */
3550void
James Smart2e0fef82007-06-17 19:56:36 -05003551lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003552{
James Smart2e0fef82007-06-17 19:56:36 -05003553 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003554 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3555 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smartffc95492010-06-07 15:23:17 -04003556 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003557
James Smart3e1f0712018-11-29 16:09:29 -08003558 pmb->ctx_buf = NULL;
3559 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003560
James Smartbe6bb942015-04-07 15:07:22 -04003561 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
James Smart32350662019-08-14 16:57:06 -07003562 "0002 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04003563 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003564 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003565 ndlp->nlp_usg_map, ndlp);
James Smartffc95492010-06-07 15:23:17 -04003566 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3567 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3568
James Smart40426292010-12-15 17:58:10 -05003569 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3570 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003571 /* We rcvd a rscn after issuing this
3572 * mbox reg login, we may have cycled
3573 * back through the state and be
3574 * back at reg login state so this
3575 * mbox needs to be ignored becase
3576 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003577 * process.
James Smartffc95492010-06-07 15:23:17 -04003578 */
3579 spin_lock_irq(shost->host_lock);
3580 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3581 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003582
3583 /*
3584 * We cannot leave the RPI registered because
3585 * if we go thru discovery again for this ndlp
3586 * a subsequent REG_RPI will fail.
3587 */
3588 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3589 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003590 }
3591
3592 /* Call state machine */
3593 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003594
dea31012005-04-17 16:05:31 -05003595 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3596 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003597 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003598 /* decrement the node reference count held for this callback
3599 * function.
3600 */
James Smart329f9bc2007-04-25 09:53:01 -04003601 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003602
3603 return;
3604}
3605
James Smart92d7f7b2007-06-17 19:56:38 -05003606static void
3607lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3608{
James Smart04c68492009-05-22 14:52:52 -04003609 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003610 struct lpfc_vport *vport = pmb->vport;
3611 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3612
3613 switch (mb->mbxStatus) {
3614 case 0x0011:
3615 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003616 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3617 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3618 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003619 break;
James Smart78730cf2010-04-06 15:06:30 -04003620 /* If VPI is busy, reset the HBA */
3621 case 0x9700:
3622 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3623 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3624 vport->vpi, mb->mbxStatus);
3625 if (!(phba->pport->load_flag & FC_UNLOADING))
3626 lpfc_workq_post_event(phba, NULL, NULL,
3627 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003628 }
James Smart72100cc2010-02-12 14:43:01 -05003629 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003630 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003631 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003632 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003633 vport->unreg_vpi_cmpl = VPORT_OK;
3634 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003635 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003636 /*
3637 * This shost reference might have been taken at the beginning of
3638 * lpfc_vport_delete()
3639 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003640 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003641 scsi_host_put(shost);
3642}
3643
James Smartd7c255b2008-08-24 21:50:00 -04003644int
James Smart92d7f7b2007-06-17 19:56:38 -05003645lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3646{
3647 struct lpfc_hba *phba = vport->phba;
3648 LPFC_MBOXQ_t *mbox;
3649 int rc;
3650
3651 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3652 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003653 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003654
3655 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3656 mbox->vport = vport;
3657 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003658 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003659 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003660 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3661 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003662 mempool_free(mbox, phba->mbox_mem_pool);
3663 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003664 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003665 }
James Smartd7c255b2008-08-24 21:50:00 -04003666 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003667}
3668
3669static void
3670lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3671{
3672 struct lpfc_vport *vport = pmb->vport;
3673 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003674 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003675
3676 switch (mb->mbxStatus) {
3677 case 0x0011:
3678 case 0x9601:
3679 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003680 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3681 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3682 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003683 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3684 spin_lock_irq(shost->host_lock);
3685 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3686 spin_unlock_irq(shost->host_lock);
3687 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003688
James Smartf6e84792019-01-28 11:14:38 -08003689 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3690 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003691 if (phba->nvmet_support)
3692 lpfc_nvmet_update_targetport(phba);
3693 else
James Smart8c258642017-02-12 13:52:36 -08003694 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003695 }
James Smart92d7f7b2007-06-17 19:56:38 -05003696 goto out;
3697 }
James Smart92d7f7b2007-06-17 19:56:38 -05003698
James Smart72100cc2010-02-12 14:43:01 -05003699 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003700 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003701 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003702 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003703 vport->num_disc_nodes = 0;
3704 /* go thru NPR list and issue ELS PLOGIs */
3705 if (vport->fc_npr_cnt)
3706 lpfc_els_disc_plogi(vport);
3707
3708 if (!vport->num_disc_nodes) {
3709 spin_lock_irq(shost->host_lock);
3710 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3711 spin_unlock_irq(shost->host_lock);
3712 lpfc_can_disctmo(vport);
3713 }
3714 vport->port_state = LPFC_VPORT_READY;
3715
3716out:
3717 mempool_free(pmb, phba->mbox_mem_pool);
3718 return;
3719}
3720
James Smart21e9a0a2009-05-22 14:53:21 -04003721/**
3722 * lpfc_create_static_vport - Read HBA config region to create static vports.
3723 * @phba: pointer to lpfc hba data structure.
3724 *
3725 * This routine issue a DUMP mailbox command for config region 22 to get
3726 * the list of static vports to be created. The function create vports
3727 * based on the information returned from the HBA.
3728 **/
3729void
3730lpfc_create_static_vport(struct lpfc_hba *phba)
3731{
3732 LPFC_MBOXQ_t *pmb = NULL;
3733 MAILBOX_t *mb;
3734 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003735 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003736 struct fc_vport_identifiers vport_id;
3737 struct fc_vport *new_fc_vport;
3738 struct Scsi_Host *shost;
3739 struct lpfc_vport *vport;
3740 uint16_t offset = 0;
3741 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003742 struct lpfc_dmabuf *mp;
3743 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003744
3745 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3746 if (!pmb) {
3747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3748 "0542 lpfc_create_static_vport failed to"
3749 " allocate mailbox memory\n");
3750 return;
3751 }
James Smartcdcc2342012-08-14 14:26:35 -04003752 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003753 mb = &pmb->u.mb;
3754
3755 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3756 if (!vport_info) {
3757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3758 "0543 lpfc_create_static_vport failed to"
3759 " allocate vport_info\n");
3760 mempool_free(pmb, phba->mbox_mem_pool);
3761 return;
3762 }
3763
3764 vport_buff = (uint8_t *) vport_info;
3765 do {
James Smartcdcc2342012-08-14 14:26:35 -04003766 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003767 if (pmb->ctx_buf) {
3768 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003769 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3770 kfree(mp);
3771 }
James Smart1c6834a2009-07-19 10:01:26 -04003772 if (lpfc_dump_static_vport(phba, pmb, offset))
3773 goto out;
3774
James Smart21e9a0a2009-05-22 14:53:21 -04003775 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003776 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3777 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003778
James Smartcdcc2342012-08-14 14:26:35 -04003779 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003780 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3781 "0544 lpfc_create_static_vport failed to"
3782 " issue dump mailbox command ret 0x%x "
3783 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003784 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003785 goto out;
3786 }
3787
James Smart1c6834a2009-07-19 10:01:26 -04003788 if (phba->sli_rev == LPFC_SLI_REV4) {
3789 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003790 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003791 if (byte_count > sizeof(struct static_vport_info) -
3792 offset)
3793 byte_count = sizeof(struct static_vport_info)
3794 - offset;
3795 memcpy(vport_buff + offset, mp->virt, byte_count);
3796 offset += byte_count;
3797 } else {
3798 if (mb->un.varDmp.word_cnt >
3799 sizeof(struct static_vport_info) - offset)
3800 mb->un.varDmp.word_cnt =
3801 sizeof(struct static_vport_info)
3802 - offset;
3803 byte_count = mb->un.varDmp.word_cnt;
3804 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3805 vport_buff + offset,
3806 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003807
James Smart1c6834a2009-07-19 10:01:26 -04003808 offset += byte_count;
3809 }
James Smart21e9a0a2009-05-22 14:53:21 -04003810
James Smart1c6834a2009-07-19 10:01:26 -04003811 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003812 offset < sizeof(struct static_vport_info));
3813
3814
3815 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3816 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3817 != VPORT_INFO_REV)) {
3818 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3819 "0545 lpfc_create_static_vport bad"
3820 " information header 0x%x 0x%x\n",
3821 le32_to_cpu(vport_info->signature),
3822 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3823
3824 goto out;
3825 }
3826
3827 shost = lpfc_shost_from_vport(phba->pport);
3828
3829 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3830 memset(&vport_id, 0, sizeof(vport_id));
3831 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3832 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3833 if (!vport_id.port_name || !vport_id.node_name)
3834 continue;
3835
3836 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3837 vport_id.vport_type = FC_PORTTYPE_NPIV;
3838 vport_id.disable = false;
3839 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3840
3841 if (!new_fc_vport) {
3842 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3843 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003844 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003845 continue;
3846 }
3847
3848 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3849 vport->vport_flag |= STATIC_VPORT;
3850 }
3851
3852out:
James Smart21e9a0a2009-05-22 14:53:21 -04003853 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003854 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003855 if (pmb->ctx_buf) {
3856 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003857 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3858 kfree(mp);
3859 }
James Smart21e9a0a2009-05-22 14:53:21 -04003860 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003861 }
James Smart21e9a0a2009-05-22 14:53:21 -04003862
3863 return;
3864}
3865
dea31012005-04-17 16:05:31 -05003866/*
3867 * This routine handles processing a Fabric REG_LOGIN mailbox
3868 * command upon completion. It is setup in the LPFC_MBOXQ
3869 * as the completion routine when the command is
3870 * handed off to the SLI layer.
3871 */
3872void
James Smart2e0fef82007-06-17 19:56:36 -05003873lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003874{
James Smart92d7f7b2007-06-17 19:56:38 -05003875 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003876 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003877 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003878 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003879 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003880
James Smart3e1f0712018-11-29 16:09:29 -08003881 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3882 pmb->ctx_ndlp = NULL;
3883 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003884
dea31012005-04-17 16:05:31 -05003885 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003886 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3887 "0258 Register Fabric login error: 0x%x\n",
3888 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003889 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3890 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003891 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003892
James Smart76a95d72010-11-20 23:11:48 -05003893 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003894 /* FLOGI failed, use loop map to make discovery list */
3895 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003896
James Smart92d7f7b2007-06-17 19:56:38 -05003897 /* Start discovery */
3898 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003899 /* Decrement the reference count to ndlp after the
3900 * reference to the ndlp are done.
3901 */
3902 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003903 return;
3904 }
3905
3906 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003907 /* Decrement the reference count to ndlp after the reference
3908 * to the ndlp are done.
3909 */
3910 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003911 return;
3912 }
3913
James Smart6d368e52011-05-24 11:44:12 -04003914 if (phba->sli_rev < LPFC_SLI_REV4)
3915 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003916 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003917 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003918 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003919
James Smart2e0fef82007-06-17 19:56:36 -05003920 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003921 /* when physical port receive logo donot start
3922 * vport discovery */
3923 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3924 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003925 else {
3926 shost = lpfc_shost_from_vport(vport);
3927 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003928 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003929 spin_unlock_irq(shost->host_lock);
3930 }
James Smart92d7f7b2007-06-17 19:56:38 -05003931 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003932 }
3933
3934 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3935 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003936 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003937
3938 /* Drop the reference count from the mbox at the end after
3939 * all the current reference to the ndlp have been done.
3940 */
3941 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003942 return;
3943}
3944
James Smarta0f2d3e2017-02-12 13:52:31 -08003945 /*
3946 * This routine will issue a GID_FT for each FC4 Type supported
3947 * by the driver. ALL GID_FTs must complete before discovery is started.
3948 */
3949int
3950lpfc_issue_gidft(struct lpfc_vport *vport)
3951{
James Smarta0f2d3e2017-02-12 13:52:31 -08003952 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08003953 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3954 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003955 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3956 /* Cannot issue NameServer FCP Query, so finish up
3957 * discovery
3958 */
3959 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3960 "0604 %s FC TYPE %x %s\n",
3961 "Failed to issue GID_FT to ",
3962 FC_TYPE_FCP,
3963 "Finishing discovery.");
3964 return 0;
3965 }
3966 vport->gidft_inp++;
3967 }
3968
James Smartf6e84792019-01-28 11:14:38 -08003969 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3970 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003971 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3972 /* Cannot issue NameServer NVME Query, so finish up
3973 * discovery
3974 */
3975 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3976 "0605 %s FC_TYPE %x %s %d\n",
3977 "Failed to issue GID_FT to ",
3978 FC_TYPE_NVME,
3979 "Finishing discovery: gidftinp ",
3980 vport->gidft_inp);
3981 if (vport->gidft_inp == 0)
3982 return 0;
3983 } else
3984 vport->gidft_inp++;
3985 }
3986 return vport->gidft_inp;
3987}
3988
James Smart7ea92eb2018-10-23 13:41:10 -07003989/**
3990 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3991 * @vport: The virtual port for which this call is being executed.
3992 *
3993 * This routine will issue a GID_PT to get a list of all N_Ports
3994 *
3995 * Return value :
3996 * 0 - Failure to issue a GID_PT
3997 * 1 - GID_PT issued
3998 **/
3999int
4000lpfc_issue_gidpt(struct lpfc_vport *vport)
4001{
4002 /* Good status, issue CT Request to NameServer */
4003 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4004 /* Cannot issue NameServer FCP Query, so finish up
4005 * discovery
4006 */
4007 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
4008 "0606 %s Port TYPE %x %s\n",
4009 "Failed to issue GID_PT to ",
4010 GID_PT_N_PORT,
4011 "Finishing discovery.");
4012 return 0;
4013 }
4014 vport->gidft_inp++;
4015 return 1;
4016}
4017
dea31012005-04-17 16:05:31 -05004018/*
4019 * This routine handles processing a NameServer REG_LOGIN mailbox
4020 * command upon completion. It is setup in the LPFC_MBOXQ
4021 * as the completion routine when the command is
4022 * handed off to the SLI layer.
4023 */
4024void
James Smart2e0fef82007-06-17 19:56:36 -05004025lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004026{
James Smart21e9a0a2009-05-22 14:53:21 -04004027 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004028 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4029 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004030 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004031
James Smart3e1f0712018-11-29 16:09:29 -08004032 pmb->ctx_buf = NULL;
4033 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004034 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004035
dea31012005-04-17 16:05:31 -05004036 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04004037 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4038 "0260 Register NameServer error: 0x%x\n",
4039 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004040
4041out:
James Smartfa4066b2008-01-11 01:53:27 -05004042 /* decrement the node reference count held for this
4043 * callback function.
4044 */
James Smart329f9bc2007-04-25 09:53:01 -04004045 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004046 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4047 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004048 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004049
4050 /* If no other thread is using the ndlp, free it */
4051 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05004052
James Smart76a95d72010-11-20 23:11:48 -05004053 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004054 /*
4055 * RegLogin failed, use loop map to make discovery
4056 * list
4057 */
4058 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004059
James Smart92d7f7b2007-06-17 19:56:38 -05004060 /* Start discovery */
4061 lpfc_disc_start(vport);
4062 return;
4063 }
4064 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004065 return;
4066 }
4067
James Smart6d368e52011-05-24 11:44:12 -04004068 if (phba->sli_rev < LPFC_SLI_REV4)
4069 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004070 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004071 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004072 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07004073 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart32350662019-08-14 16:57:06 -07004074 "0003 rpi:%x DID:%x flg:%x %d map%x x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04004075 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004076 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004077 ndlp->nlp_usg_map, ndlp);
dea31012005-04-17 16:05:31 -05004078
James Smart2e0fef82007-06-17 19:56:36 -05004079 if (vport->port_state < LPFC_VPORT_READY) {
4080 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004081 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4082 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4083 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4084 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004085
James Smartf6e84792019-01-28 11:14:38 -08004086 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4087 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004088 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4089
James Smartf6e84792019-01-28 11:14:38 -08004090 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4091 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08004092 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4093 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004094
4095 /* Issue SCR just before NameServer GID_FT Query */
James Smartdf3fe762020-02-10 09:31:55 -08004096 lpfc_issue_els_scr(vport, 0);
4097
4098 lpfc_issue_els_rdf(vport, 0);
dea31012005-04-17 16:05:31 -05004099 }
4100
James Smart2e0fef82007-06-17 19:56:36 -05004101 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004102 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004103 goto out;
dea31012005-04-17 16:05:31 -05004104
James Smarta0f2d3e2017-02-12 13:52:31 -08004105 /*
4106 * At this point in time we may need to wait for multiple
4107 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4108 *
4109 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004110 * callback function.
4111 */
James Smart329f9bc2007-04-25 09:53:01 -04004112 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004113 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4114 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004115 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004116
4117 return;
4118}
4119
4120static void
James Smart2e0fef82007-06-17 19:56:36 -05004121lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004122{
James Smart2e0fef82007-06-17 19:56:36 -05004123 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4124 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004125 struct lpfc_rport_data *rdata;
4126 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004127 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004128
James Smartf6e84792019-01-28 11:14:38 -08004129 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004130 return;
4131
dea31012005-04-17 16:05:31 -05004132 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004133 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4134 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004135 rport_ids.port_id = ndlp->nlp_DID;
4136 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004137
James Smart329f9bc2007-04-25 09:53:01 -04004138 /*
4139 * We leave our node pointer in rport->dd_data when we unregister a
4140 * FCP target port. But fc_remote_port_add zeros the space to which
4141 * rport->dd_data points. So, if we're reusing a previously
4142 * registered port, drop the reference that we took the last time we
4143 * registered the port.
4144 */
James Smart466e8402015-05-21 13:55:28 -04004145 rport = ndlp->rport;
4146 if (rport) {
4147 rdata = rport->dd_data;
4148 /* break the link before dropping the ref */
4149 ndlp->rport = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08004150 if (rdata) {
4151 if (rdata->pnode == ndlp)
4152 lpfc_nlp_put(ndlp);
4153 rdata->pnode = NULL;
4154 }
James Smart466e8402015-05-21 13:55:28 -04004155 /* drop reference for earlier registeration */
4156 put_device(&rport->dev);
4157 }
James Smart858c9f62007-06-17 19:56:39 -05004158
4159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4160 "rport add: did:x%x flg:x%x type x%x",
4161 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4162
James Smart9589b0622011-04-16 11:03:17 -04004163 /* Don't add the remote port if unloading. */
4164 if (vport->load_flag & FC_UNLOADING)
4165 return;
4166
James Smart2e0fef82007-06-17 19:56:36 -05004167 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004168 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004169 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4170 "Warning: fc_remote_port_add failed\n");
4171 return;
4172 }
4173
4174 /* initialize static port data */
4175 rport->maxframe_size = ndlp->nlp_maxframe;
4176 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004177 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004178 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004179
4180 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004181 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004182 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004183 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4184 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4185 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4186 if (ndlp->nlp_type & NLP_NVME_TARGET)
4187 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4188 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4189 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004190
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004191 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4192 fc_remote_port_rolechg(rport, rport_ids.roles);
4193
James Smart34f5ad82012-08-03 12:35:03 -04004194 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004195 "3183 rport register x%06x, rport x%px role x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04004196 ndlp->nlp_DID, rport, rport_ids.roles);
4197
James Smart071fbd3d2006-04-15 11:53:20 -04004198 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004199 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004200 ndlp->nlp_sid = rport->scsi_target_id;
4201 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004202 return;
4203}
4204
4205static void
James Smart2e0fef82007-06-17 19:56:36 -05004206lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004207{
4208 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004209 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004210
James Smartf6e84792019-01-28 11:14:38 -08004211 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004212 return;
James Smartc01f3202006-08-18 17:47:08 -04004213
James Smart2ea259e2017-02-12 13:52:27 -08004214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004215 "rport delete: did:x%x flg:x%x type x%x",
4216 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4217
James Smart2ea259e2017-02-12 13:52:27 -08004218 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004219 "3184 rport unregister x%06x, rport x%px\n",
James Smart34f5ad82012-08-03 12:35:03 -04004220 ndlp->nlp_DID, rport);
4221
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004222 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004223
4224 return;
4225}
4226
James Smartde0c5b32007-04-25 09:52:27 -04004227static void
James Smart2e0fef82007-06-17 19:56:36 -05004228lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004229{
James Smart2e0fef82007-06-17 19:56:36 -05004230 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -07004231 unsigned long iflags;
James Smart2e0fef82007-06-17 19:56:36 -05004232
James Smart894bb172019-08-14 16:56:52 -07004233 spin_lock_irqsave(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004234 switch (state) {
4235 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004236 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004237 break;
4238 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004239 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004240 break;
4241 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004242 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004243 break;
4244 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004245 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004246 break;
4247 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004248 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004249 break;
4250 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004251 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004252 break;
4253 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004254 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004255 break;
4256 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004257 if (vport->fc_npr_cnt == 0 && count == -1)
4258 vport->fc_npr_cnt = 0;
4259 else
4260 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004261 break;
4262 }
James Smart894bb172019-08-14 16:56:52 -07004263 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004264}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004265
James Smartde0c5b32007-04-25 09:52:27 -04004266static void
James Smart2e0fef82007-06-17 19:56:36 -05004267lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004268 int old_state, int new_state)
4269{
James Smart2e0fef82007-06-17 19:56:36 -05004270 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4271
James Smartde0c5b32007-04-25 09:52:27 -04004272 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004273 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4274 ndlp->nlp_type |= NLP_FC_NODE;
4275 }
4276 if (new_state == NLP_STE_MAPPED_NODE)
4277 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4278 if (new_state == NLP_STE_NPR_NODE)
4279 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004280
James Smarta0f2d3e2017-02-12 13:52:31 -08004281 /* FCP and NVME Transport interface */
4282 if ((old_state == NLP_STE_MAPPED_NODE ||
4283 old_state == NLP_STE_UNMAPPED_NODE)) {
4284 if (ndlp->rport) {
4285 vport->phba->nport_event_cnt++;
4286 lpfc_unregister_remote_port(ndlp);
4287 }
4288
James Smart1c5b12f2017-04-21 16:05:03 -07004289 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004290 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004291 if (vport->phba->nvmet_support == 0) {
4292 /* Start devloss if target. */
4293 if (ndlp->nlp_type & NLP_NVME_TARGET)
4294 lpfc_nvme_unregister_port(vport, ndlp);
4295 } else {
James Smart6599e122017-06-01 21:07:00 -07004296 /* NVMET has no upcall. */
4297 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004298 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004299 }
James Smartde0c5b32007-04-25 09:52:27 -04004300 }
dea31012005-04-17 16:05:31 -05004301
James Smarta0f2d3e2017-02-12 13:52:31 -08004302 /* FCP and NVME Transport interfaces */
4303
James Smartde0c5b32007-04-25 09:52:27 -04004304 if (new_state == NLP_STE_MAPPED_NODE ||
4305 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart01a8aed2018-09-10 10:30:41 -07004306 if (ndlp->nlp_fc4_type ||
James Smart92721c32017-06-01 21:06:59 -07004307 ndlp->nlp_DID == Fabric_DID ||
4308 ndlp->nlp_DID == NameServer_DID ||
4309 ndlp->nlp_DID == FDMI_DID) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004310 vport->phba->nport_event_cnt++;
4311 /*
4312 * Tell the fc transport about the port, if we haven't
4313 * already. If we have, and it's a scsi entity, be
4314 */
4315 lpfc_register_remote_port(vport, ndlp);
4316 }
4317 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004318 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4319 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004320 if (vport->phba->nvmet_support == 0) {
4321 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004322 * Only NVME Target Rports are registered with
4323 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004324 */
James Smart3b5bde692017-11-20 16:00:39 -08004325 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4326 vport->phba->nport_event_cnt++;
4327 lpfc_nvme_register_port(vport, ndlp);
4328 }
James Smart8c258642017-02-12 13:52:36 -08004329 } else {
4330 /* Just take an NDLP ref count since the
4331 * target does not register rports.
4332 */
4333 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004334 }
4335 }
James Smartde0c5b32007-04-25 09:52:27 -04004336 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004337
James Smartea2151b2008-09-07 11:52:10 -04004338 if ((new_state == NLP_STE_MAPPED_NODE) &&
4339 (vport->stat_data_enabled)) {
4340 /*
4341 * A new target is discovered, if there is no buffer for
4342 * statistical data collection allocate buffer.
4343 */
4344 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4345 sizeof(struct lpfc_scsicmd_bkt),
4346 GFP_KERNEL);
4347
4348 if (!ndlp->lat_data)
4349 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4350 "0286 lpfc_nlp_state_cleanup failed to "
4351 "allocate statistical data buffer DID "
4352 "0x%x\n", ndlp->nlp_DID);
4353 }
James Smart858c9f62007-06-17 19:56:39 -05004354 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004355 * If the node just added to Mapped list was an FCP target,
4356 * but the remote port registration failed or assigned a target
4357 * id outside the presentable range - move the node to the
4358 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004359 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004360 if ((new_state == NLP_STE_MAPPED_NODE) &&
4361 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004362 (!ndlp->rport ||
4363 ndlp->rport->scsi_target_id == -1 ||
4364 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004365 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004366 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004367 spin_unlock_irq(shost->host_lock);
4368 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004369 }
James Smartde0c5b32007-04-25 09:52:27 -04004370}
4371
James Smart685f0bf2007-04-25 09:53:08 -04004372static char *
4373lpfc_nlp_state_name(char *buffer, size_t size, int state)
4374{
4375 static char *states[] = {
4376 [NLP_STE_UNUSED_NODE] = "UNUSED",
4377 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4378 [NLP_STE_ADISC_ISSUE] = "ADISC",
4379 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4380 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004381 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004382 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4383 [NLP_STE_MAPPED_NODE] = "MAPPED",
4384 [NLP_STE_NPR_NODE] = "NPR",
4385 };
4386
James Smart311464e2007-08-02 11:10:37 -04004387 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004388 strlcpy(buffer, states[state], size);
4389 else
4390 snprintf(buffer, size, "unknown (%d)", state);
4391 return buffer;
4392}
4393
James Smartde0c5b32007-04-25 09:52:27 -04004394void
James Smart2e0fef82007-06-17 19:56:36 -05004395lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4396 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004397{
James Smart2e0fef82007-06-17 19:56:36 -05004398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004399 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004400 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004401
James Smarte8b62012007-08-02 11:10:09 -04004402 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4403 "0904 NPort state transition x%06x, %s -> %s\n",
4404 ndlp->nlp_DID,
4405 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4406 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004407
4408 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4409 "node statechg did:x%x old:%d ste:%d",
4410 ndlp->nlp_DID, old_state, state);
4411
James Smartde0c5b32007-04-25 09:52:27 -04004412 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004413 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004414 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004415 if (old_state == NLP_STE_UNMAPPED_NODE) {
4416 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4417 ndlp->nlp_type &= ~NLP_FC_NODE;
4418 }
4419
James Smart685f0bf2007-04-25 09:53:08 -04004420 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004421 spin_lock_irq(shost->host_lock);
4422 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4423 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004424 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004425 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004426
4427 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004428 lpfc_nlp_counters(vport, state, 1);
4429 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004430}
4431
4432void
James Smarte47c9092008-02-08 18:49:26 -05004433lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4434{
4435 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4436
4437 if (list_empty(&ndlp->nlp_listp)) {
4438 spin_lock_irq(shost->host_lock);
4439 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4440 spin_unlock_irq(shost->host_lock);
4441 }
4442}
4443
4444void
James Smart2e0fef82007-06-17 19:56:36 -05004445lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004446{
James Smart2e0fef82007-06-17 19:56:36 -05004447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4448
James Smart0d2b6b82008-06-14 22:52:47 -04004449 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004450 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004451 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4452 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004453 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004454 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004455 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004456 NLP_STE_UNUSED_NODE);
4457}
4458
Adrian Bunk4d9db012008-02-14 23:24:02 +02004459static void
James Smarte47c9092008-02-08 18:49:26 -05004460lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4461{
James Smart0d2b6b82008-06-14 22:52:47 -04004462 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004463 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4464 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4465 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4466 NLP_STE_UNUSED_NODE);
4467}
James Smart109f6ed2008-12-04 22:39:08 -05004468/**
James Smart3621a712009-04-06 18:47:14 -04004469 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004470 * @vport: Pointer to Virtual Port object.
4471 * @ndlp: Pointer to FC node object.
4472 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004473 *
4474 * This function is always called when node object need to be initialized.
4475 * It initializes all the fields of the node object. Although the reference
4476 * to phba from @ndlp can be obtained indirectly through it's reference to
4477 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4478 * to the life-span of the @ndlp might go beyond the existence of @vport as
4479 * the final release of ndlp is determined by its reference count. And, the
4480 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004481 **/
4482static inline void
4483lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4484 uint32_t did)
4485{
4486 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4487 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004488 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smart109f6ed2008-12-04 22:39:08 -05004489 ndlp->nlp_DID = did;
4490 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004491 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004492 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004493 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004494 kref_init(&ndlp->kref);
4495 NLP_INT_NODE_ACT(ndlp);
4496 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004497 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004498 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004499}
James Smarte47c9092008-02-08 18:49:26 -05004500
4501struct lpfc_nodelist *
4502lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4503 int state)
4504{
4505 struct lpfc_hba *phba = vport->phba;
James Smartdea16bd2018-11-29 16:09:30 -08004506 uint32_t did, flag;
James Smarte47c9092008-02-08 18:49:26 -05004507 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004508 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart9d3d3402017-04-21 16:05:00 -07004509 int rpi = LPFC_RPI_ALLOC_ERROR;
James Smartdea16bd2018-11-29 16:09:30 -08004510 uint32_t defer_did = 0;
James Smarte47c9092008-02-08 18:49:26 -05004511
4512 if (!ndlp)
4513 return NULL;
4514
James Smart9d3d3402017-04-21 16:05:00 -07004515 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb95b2112019-08-14 16:56:47 -07004516 if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)
4517 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4518 else
4519 rpi = ndlp->nlp_rpi;
4520
4521 if (rpi == LPFC_RPI_ALLOC_ERROR) {
4522 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4523 "0359 %s: ndlp:x%px "
4524 "usgmap:x%x refcnt:%d FAILED RPI "
4525 " ALLOC\n",
4526 __func__,
4527 (void *)ndlp, ndlp->nlp_usg_map,
4528 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004529 return NULL;
James Smartb95b2112019-08-14 16:56:47 -07004530 }
James Smart9d3d3402017-04-21 16:05:00 -07004531 }
4532
James Smarte47c9092008-02-08 18:49:26 -05004533 spin_lock_irqsave(&phba->ndlp_lock, flags);
4534 /* The ndlp should not be in memory free mode */
4535 if (NLP_CHK_FREE_REQ(ndlp)) {
4536 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4537 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004538 "0277 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05004539 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07004540 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004541 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004542 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004543 }
4544 /* The ndlp should not already be in active mode */
4545 if (NLP_CHK_NODE_ACT(ndlp)) {
4546 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4547 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07004548 "0278 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05004549 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07004550 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004551 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004552 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004553 }
4554
James Smartdea16bd2018-11-29 16:09:30 -08004555 /* First preserve the orginal DID, xri_bitmap and some flags */
James Smarte47c9092008-02-08 18:49:26 -05004556 did = ndlp->nlp_DID;
James Smartdea16bd2018-11-29 16:09:30 -08004557 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4558 if (flag & NLP_UNREG_INP)
4559 defer_did = ndlp->nlp_defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004560 if (phba->sli_rev == LPFC_SLI_REV4)
4561 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004562
James Smartdea16bd2018-11-29 16:09:30 -08004563 /* Zero ndlp except of ndlp linked list pointer */
James Smarte47c9092008-02-08 18:49:26 -05004564 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4565 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smarte47c9092008-02-08 18:49:26 -05004566
James Smartdea16bd2018-11-29 16:09:30 -08004567 /* Next reinitialize and restore saved objects */
4568 lpfc_initialize_node(vport, ndlp, did);
4569 ndlp->nlp_flag |= flag;
4570 if (flag & NLP_UNREG_INP)
4571 ndlp->nlp_defer_did = defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004572 if (phba->sli_rev == LPFC_SLI_REV4)
4573 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4574
James Smarte47c9092008-02-08 18:49:26 -05004575 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smartbe6bb942015-04-07 15:07:22 -04004576 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07004577 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04004578 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4579 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
James Smart32350662019-08-14 16:57:06 -07004580 "map:%x x%px\n", ndlp->nlp_rpi, ndlp->nlp_DID,
James Smartbe6bb942015-04-07 15:07:22 -04004581 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004582 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004583 ndlp->nlp_usg_map, ndlp);
4584 }
James Smart725dd392013-10-10 12:23:30 -04004585
James Smarte47c9092008-02-08 18:49:26 -05004586
4587 if (state != NLP_STE_UNUSED_NODE)
4588 lpfc_nlp_set_state(vport, ndlp, state);
James Smartb95b2112019-08-14 16:56:47 -07004589 else
4590 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4591 "0013 rpi:%x DID:%x flg:%x refcnt:%d "
4592 "map:%x x%px STATE=UNUSED\n",
4593 ndlp->nlp_rpi, ndlp->nlp_DID,
4594 ndlp->nlp_flag,
4595 kref_read(&ndlp->kref),
4596 ndlp->nlp_usg_map, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004597
4598 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4599 "node enable: did:x%x",
4600 ndlp->nlp_DID, 0, 0);
4601 return ndlp;
James Smart9d3d3402017-04-21 16:05:00 -07004602
4603free_rpi:
James Smart0f154222019-09-21 20:58:52 -07004604 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07004605 lpfc_sli4_free_rpi(vport->phba, rpi);
James Smart0f154222019-09-21 20:58:52 -07004606 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
4607 }
James Smart9d3d3402017-04-21 16:05:00 -07004608 return NULL;
James Smartde0c5b32007-04-25 09:52:27 -04004609}
4610
4611void
James Smart2e0fef82007-06-17 19:56:36 -05004612lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004613{
James Smart87af33f2007-10-27 13:37:43 -04004614 /*
James Smartfa4066b2008-01-11 01:53:27 -05004615 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004616 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004617 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4618 * until ALL other outstanding threads have completed. We check
4619 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004620 */
James Smartfa4066b2008-01-11 01:53:27 -05004621 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4622 return;
James Smart51ef4c22007-08-02 11:10:31 -04004623 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004624 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004625 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004626 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004627 }
James Smart02902172015-05-21 13:55:17 -04004628
4629 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004630 return;
dea31012005-04-17 16:05:31 -05004631}
4632
4633/*
4634 * Start / ReStart rescue timer for Discovery / RSCN handling
4635 */
4636void
James Smart2e0fef82007-06-17 19:56:36 -05004637lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004638{
James Smart2e0fef82007-06-17 19:56:36 -05004639 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4640 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004641 uint32_t tmo;
4642
James Smart2e0fef82007-06-17 19:56:36 -05004643 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004644 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004645 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4646 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004647 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004648 * FC spec states we need 3 * ratov for CT requests
4649 */
4650 tmo = ((phba->fc_ratov * 3) + 3);
4651 }
dea31012005-04-17 16:05:31 -05004652
James Smart858c9f62007-06-17 19:56:39 -05004653
4654 if (!timer_pending(&vport->fc_disctmo)) {
4655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4656 "set disc timer: tmo:x%x state:x%x flg:x%x",
4657 tmo, vport->port_state, vport->fc_flag);
4658 }
4659
James Smart256ec0d2013-04-17 20:14:58 -04004660 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004661 spin_lock_irq(shost->host_lock);
4662 vport->fc_flag |= FC_DISC_TMO;
4663 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004664
4665 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004666 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4667 "0247 Start Discovery Timer state x%x "
4668 "Data: x%x x%lx x%x x%x\n",
4669 vport->port_state, tmo,
4670 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4671 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004672
4673 return;
4674}
4675
4676/*
4677 * Cancel rescue timer for Discovery / RSCN handling
4678 */
4679int
James Smart2e0fef82007-06-17 19:56:36 -05004680lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004681{
James Smart2e0fef82007-06-17 19:56:36 -05004682 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004683 unsigned long iflags;
4684
James Smart858c9f62007-06-17 19:56:39 -05004685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4686 "can disc timer: state:x%x rtry:x%x flg:x%x",
4687 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4688
dea31012005-04-17 16:05:31 -05004689 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004690 if (vport->fc_flag & FC_DISC_TMO) {
4691 spin_lock_irqsave(shost->host_lock, iflags);
4692 vport->fc_flag &= ~FC_DISC_TMO;
4693 spin_unlock_irqrestore(shost->host_lock, iflags);
4694 del_timer_sync(&vport->fc_disctmo);
4695 spin_lock_irqsave(&vport->work_port_lock, iflags);
4696 vport->work_port_events &= ~WORKER_DISC_TMO;
4697 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004698 }
4699
4700 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004701 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4702 "0248 Cancel Discovery Timer state x%x "
4703 "Data: x%x x%x x%x\n",
4704 vport->port_state, vport->fc_flag,
4705 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004706 return 0;
dea31012005-04-17 16:05:31 -05004707}
4708
4709/*
4710 * Check specified ring for outstanding IOCB on the SLI queue
4711 * Return true if iocb matches the specified nport
4712 */
4713int
James Smart2e0fef82007-06-17 19:56:36 -05004714lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4715 struct lpfc_sli_ring *pring,
4716 struct lpfc_iocbq *iocb,
4717 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004718{
James Smart2e0fef82007-06-17 19:56:36 -05004719 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004720 struct lpfc_vport *vport = ndlp->vport;
4721
4722 if (iocb->vport != vport)
4723 return 0;
4724
dea31012005-04-17 16:05:31 -05004725 if (pring->ringno == LPFC_ELS_RING) {
4726 switch (icmd->ulpCommand) {
4727 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004728 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004729 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004730 /* fall through */
dea31012005-04-17 16:05:31 -05004731 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004732 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4733 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004734 /* fall through */
dea31012005-04-17 16:05:31 -05004735 case CMD_XMIT_ELS_RSP64_CX:
4736 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004737 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004738 /* fall through */
dea31012005-04-17 16:05:31 -05004739 }
James Smart895427b2017-02-12 13:52:30 -08004740 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004741 /* Skip match check if waiting to relogin to FCP target */
4742 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004743 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004744 return 0;
dea31012005-04-17 16:05:31 -05004745 }
4746 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004747 return 1;
dea31012005-04-17 16:05:31 -05004748 }
dea31012005-04-17 16:05:31 -05004749 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004750 return 0;
dea31012005-04-17 16:05:31 -05004751}
4752
James Smart895427b2017-02-12 13:52:30 -08004753static void
4754__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4755 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4756 struct list_head *dequeue_list)
4757{
4758 struct lpfc_iocbq *iocb, *next_iocb;
4759
4760 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4761 /* Check to see if iocb matches the nport */
4762 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4763 /* match, dequeue */
4764 list_move_tail(&iocb->list, dequeue_list);
4765 }
4766}
4767
4768static void
4769lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4770 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4771{
4772 struct lpfc_sli *psli = &phba->sli;
4773 uint32_t i;
4774
4775 spin_lock_irq(&phba->hbalock);
4776 for (i = 0; i < psli->num_rings; i++)
4777 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4778 dequeue_list);
4779 spin_unlock_irq(&phba->hbalock);
4780}
4781
4782static void
4783lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4784 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4785{
4786 struct lpfc_sli_ring *pring;
4787 struct lpfc_queue *qp = NULL;
4788
4789 spin_lock_irq(&phba->hbalock);
4790 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4791 pring = qp->pring;
4792 if (!pring)
4793 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004794 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004795 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004796 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004797 }
4798 spin_unlock_irq(&phba->hbalock);
4799}
4800
dea31012005-04-17 16:05:31 -05004801/*
4802 * Free resources / clean up outstanding I/Os
4803 * associated with nlp_rpi in the LPFC_NODELIST entry.
4804 */
4805static int
James Smart2e0fef82007-06-17 19:56:36 -05004806lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004807{
James Smart2534ba72007-04-25 09:52:20 -04004808 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004809
James Smart92d7f7b2007-06-17 19:56:38 -05004810 lpfc_fabric_abort_nport(ndlp);
4811
dea31012005-04-17 16:05:31 -05004812 /*
4813 * Everything that matches on txcmplq will be returned
4814 * by firmware with a no rpi error.
4815 */
James Smart40426292010-12-15 17:58:10 -05004816 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004817 if (phba->sli_rev != LPFC_SLI_REV4)
4818 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4819 else
4820 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004821 }
James Smart2534ba72007-04-25 09:52:20 -04004822
James Smarta257bf92009-04-06 18:48:10 -04004823 /* Cancel all the IOCBs from the completions list */
4824 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4825 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004826
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004827 return 0;
dea31012005-04-17 16:05:31 -05004828}
4829
James Smart086a3452012-08-14 14:25:21 -04004830/**
4831 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4832 * @phba: Pointer to HBA context object.
4833 * @pmb: Pointer to mailbox object.
4834 *
4835 * This function will issue an ELS LOGO command after completing
4836 * the UNREG_RPI.
4837 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004838static void
James Smart086a3452012-08-14 14:25:21 -04004839lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4840{
4841 struct lpfc_vport *vport = pmb->vport;
4842 struct lpfc_nodelist *ndlp;
4843
James Smart3e1f0712018-11-29 16:09:29 -08004844 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004845 if (!ndlp)
4846 return;
4847 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004848 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004849
4850 /* Check to see if there are any deferred events to process */
4851 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4852 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4853 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4854 "1434 UNREG cmpl deferred logo x%x "
James Smart32350662019-08-14 16:57:06 -07004855 "on NPort x%x Data: x%x x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004856 ndlp->nlp_rpi, ndlp->nlp_DID,
4857 ndlp->nlp_defer_did, ndlp);
4858
4859 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4860 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4861 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08004862 } else {
James Smart4f1a2fe2019-08-14 16:56:32 -07004863 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4864 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4865 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
James Smart0f154222019-09-21 20:58:52 -07004866 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
James Smart4f1a2fe2019-08-14 16:56:32 -07004867 }
James Smart00292e02018-12-13 15:17:55 -08004868 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smartdea16bd2018-11-29 16:09:30 -08004869 }
James Smart086a3452012-08-14 14:25:21 -04004870}
4871
dea31012005-04-17 16:05:31 -05004872/*
James Smart97acd002019-09-21 20:58:51 -07004873 * Sets the mailbox completion handler to be used for the
4874 * unreg_rpi command. The handler varies based on the state of
4875 * the port and what will be happening to the rpi next.
4876 */
4877static void
4878lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
4879 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
4880{
4881 unsigned long iflags;
4882
4883 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4884 mbox->ctx_ndlp = ndlp;
4885 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4886
4887 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
4888 (!(vport->load_flag & FC_UNLOADING)) &&
4889 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
4890 LPFC_SLI_INTF_IF_TYPE_2) &&
4891 (kref_read(&ndlp->kref) > 0)) {
4892 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4893 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
4894 } else {
4895 if (vport->load_flag & FC_UNLOADING) {
4896 if (phba->sli_rev == LPFC_SLI_REV4) {
4897 spin_lock_irqsave(&vport->phba->ndlp_lock,
4898 iflags);
4899 ndlp->nlp_flag |= NLP_RELEASE_RPI;
4900 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
4901 iflags);
4902 }
4903 lpfc_nlp_get(ndlp);
4904 }
4905 mbox->ctx_ndlp = ndlp;
4906 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4907 }
4908}
4909
4910/*
dea31012005-04-17 16:05:31 -05004911 * Free rpi associated with LPFC_NODELIST entry.
4912 * This routine is called from lpfc_freenode(), when we are removing
4913 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4914 * LOGO that completes successfully, and we are waiting to PLOGI back
4915 * to the remote NPort. In addition, it is called after we receive
4916 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4917 * we are waiting to PLOGI back to the remote NPort.
4918 */
4919int
James Smart2e0fef82007-06-17 19:56:36 -05004920lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004921{
James Smart2e0fef82007-06-17 19:56:36 -05004922 struct lpfc_hba *phba = vport->phba;
4923 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004924 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004925 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004926
James Smartf454a9a2013-09-06 12:20:07 -04004927 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4928 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4929 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
James Smart0f154222019-09-21 20:58:52 -07004930 lpfc_printf_vlog(vport, KERN_INFO,
4931 LOG_NODE | LOG_DISCOVERY,
James Smartf454a9a2013-09-06 12:20:07 -04004932 "3366 RPI x%x needs to be "
4933 "unregistered nlp_flag x%x "
4934 "did x%x\n",
4935 ndlp->nlp_rpi, ndlp->nlp_flag,
4936 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004937
4938 /* If there is already an UNREG in progress for this ndlp,
4939 * no need to queue up another one.
4940 */
4941 if (ndlp->nlp_flag & NLP_UNREG_INP) {
James Smart0f154222019-09-21 20:58:52 -07004942 lpfc_printf_vlog(vport, KERN_INFO,
4943 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004944 "1436 unreg_rpi SKIP UNREG x%x on "
4945 "NPort x%x deferred x%x flg x%x "
James Smart32350662019-08-14 16:57:06 -07004946 "Data: x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004947 ndlp->nlp_rpi, ndlp->nlp_DID,
4948 ndlp->nlp_defer_did,
4949 ndlp->nlp_flag, ndlp);
4950 goto out;
4951 }
4952
James Smart2e0fef82007-06-17 19:56:36 -05004953 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4954 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004955 /* SLI4 ports require the physical rpi value. */
4956 rpi = ndlp->nlp_rpi;
4957 if (phba->sli_rev == LPFC_SLI_REV4)
4958 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004959
James Smart6d368e52011-05-24 11:44:12 -04004960 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004961 mbox->vport = vport;
James Smart97acd002019-09-21 20:58:51 -07004962 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
4963 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
4964 /*
4965 * accept PLOGIs after unreg_rpi_cmpl
4966 */
4967 acc_plogi = 0;
James Smartdea16bd2018-11-29 16:09:30 -08004968 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4969 Fabric_DID_MASK) &&
4970 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4971 ndlp->nlp_flag |= NLP_UNREG_INP;
4972
James Smart0f154222019-09-21 20:58:52 -07004973 lpfc_printf_vlog(vport, KERN_INFO,
4974 LOG_NODE | LOG_DISCOVERY,
James Smartdea16bd2018-11-29 16:09:30 -08004975 "1433 unreg_rpi UNREG x%x on "
James Smart32350662019-08-14 16:57:06 -07004976 "NPort x%x deferred flg x%x "
4977 "Data:x%px\n",
James Smartdea16bd2018-11-29 16:09:30 -08004978 ndlp->nlp_rpi, ndlp->nlp_DID,
4979 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004980
James Smart0b727fe2007-10-27 13:37:25 -04004981 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004982 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004983 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004984 acc_plogi = 1;
4985 }
dea31012005-04-17 16:05:31 -05004986 }
dea31012005-04-17 16:05:31 -05004987 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004988out:
James Smart40426292010-12-15 17:58:10 -05004989 if (phba->sli_rev != LPFC_SLI_REV4)
4990 ndlp->nlp_rpi = 0;
4991 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004992 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004993 if (acc_plogi)
4994 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004995 return 1;
4996 }
James Smart7c5e5182015-05-22 10:42:43 -04004997 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004998 return 0;
4999}
5000
James Smartecfd03c2010-02-12 14:41:27 -05005001/**
5002 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5003 * @phba: pointer to lpfc hba data structure.
5004 *
5005 * This routine is invoked to unregister all the currently registered RPIs
5006 * to the HBA.
5007 **/
5008void
5009lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5010{
5011 struct lpfc_vport **vports;
5012 struct lpfc_nodelist *ndlp;
5013 struct Scsi_Host *shost;
5014 int i;
5015
5016 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05005017 if (!vports) {
5018 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5019 "2884 Vport array allocation failed \n");
5020 return;
5021 }
James Smartecfd03c2010-02-12 14:41:27 -05005022 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5023 shost = lpfc_shost_from_vport(vports[i]);
5024 spin_lock_irq(shost->host_lock);
5025 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05005026 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05005027 /* The mempool_alloc might sleep */
5028 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05005029 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05005030 spin_lock_irq(shost->host_lock);
5031 }
James Smartecfd03c2010-02-12 14:41:27 -05005032 }
5033 spin_unlock_irq(shost->host_lock);
5034 }
5035 lpfc_destroy_vport_work_array(phba, vports);
5036}
5037
James Smart92d7f7b2007-06-17 19:56:38 -05005038void
5039lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5040{
5041 struct lpfc_hba *phba = vport->phba;
5042 LPFC_MBOXQ_t *mbox;
5043 int rc;
5044
James Smart5af5eee2010-10-22 11:06:38 -04005045 if (phba->sli_rev == LPFC_SLI_REV4) {
5046 lpfc_sli4_unreg_all_rpis(vport);
5047 return;
5048 }
5049
James Smart92d7f7b2007-06-17 19:56:38 -05005050 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5051 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005052 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5053 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005054 mbox->vport = vport;
5055 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005056 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005057 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005058 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005059 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04005060
5061 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5062 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5063 "1836 Could not issue "
5064 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005065 }
5066}
5067
5068void
5069lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5070{
5071 struct lpfc_hba *phba = vport->phba;
5072 LPFC_MBOXQ_t *mbox;
5073 int rc;
5074
James Smartc95a3b42019-03-12 16:30:07 -07005075 /* Unreg DID is an SLI3 operation. */
5076 if (phba->sli_rev > LPFC_SLI_REV3)
5077 return;
5078
James Smart92d7f7b2007-06-17 19:56:38 -05005079 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5080 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005081 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5082 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005083 mbox->vport = vport;
5084 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005085 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005086 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005087 if (rc != MBX_TIMEOUT)
5088 mempool_free(mbox, phba->mbox_mem_pool);
5089
5090 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04005091 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5092 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005093 "unreg_did (default rpis) status %d\n",
5094 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005095 }
5096}
5097
dea31012005-04-17 16:05:31 -05005098/*
5099 * Free resources associated with LPFC_NODELIST entry
5100 * so it can be freed.
5101 */
5102static int
James Smart2e0fef82007-06-17 19:56:36 -05005103lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005104{
James Smart2e0fef82007-06-17 19:56:36 -05005105 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5106 struct lpfc_hba *phba = vport->phba;
5107 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005108 struct lpfc_dmabuf *mp;
James Smart97acd002019-09-21 20:58:51 -07005109 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005110
5111 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005112 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5113 "0900 Cleanup node for NPort x%x "
5114 "Data: x%x x%x x%x\n",
5115 ndlp->nlp_DID, ndlp->nlp_flag,
5116 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005117 if (NLP_CHK_FREE_REQ(ndlp)) {
5118 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07005119 "0280 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05005120 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07005121 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005122 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005123 lpfc_dequeue_node(vport, ndlp);
5124 } else {
5125 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07005126 "0281 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05005127 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07005128 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005129 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005130 lpfc_disable_node(vport, ndlp);
5131 }
dea31012005-04-17 16:05:31 -05005132
James Smart086a3452012-08-14 14:25:21 -04005133
5134 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5135
dea31012005-04-17 16:05:31 -05005136 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5137 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005138 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005139 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005140 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5141 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005142 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5143 }
5144 }
James Smart33ccf8d2006-08-17 11:57:58 -04005145
James Smart2e0fef82007-06-17 19:56:36 -05005146 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005147 /* Cleanup REG_LOGIN completions which are not yet processed */
5148 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5149 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005150 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005151 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005152 continue;
5153
James Smart3e1f0712018-11-29 16:09:29 -08005154 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005155 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5156 }
5157
dea31012005-04-17 16:05:31 -05005158 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005159 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005160 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005161 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5162 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005163 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005164 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005165 kfree(mp);
5166 }
5167 list_del(&mb->list);
5168 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005169 /* We shall not invoke the lpfc_nlp_put to decrement
5170 * the ndlp reference count as we are in the process
5171 * of lpfc_nlp_release.
5172 */
dea31012005-04-17 16:05:31 -05005173 }
5174 }
James Smart2e0fef82007-06-17 19:56:36 -05005175 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005176
James Smarte47c9092008-02-08 18:49:26 -05005177 lpfc_els_abort(phba, ndlp);
5178
James Smart2e0fef82007-06-17 19:56:36 -05005179 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04005180 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05005181 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005182
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005183 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005184 del_timer_sync(&ndlp->nlp_delayfunc);
5185
James Smart0d2b6b82008-06-14 22:52:47 -04005186 list_del_init(&ndlp->els_retry_evt.evt_listp);
5187 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005188 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart4f1a2fe2019-08-14 16:56:32 -07005189 if (phba->sli_rev == LPFC_SLI_REV4)
5190 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smart97acd002019-09-21 20:58:51 -07005191 if (!lpfc_unreg_rpi(vport, ndlp)) {
5192 /* Clean up unregistered and non freed rpis */
5193 if ((ndlp->nlp_flag & NLP_RELEASE_RPI) &&
5194 !(ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)) {
5195 lpfc_sli4_free_rpi(vport->phba,
5196 ndlp->nlp_rpi);
5197 spin_lock_irqsave(&vport->phba->ndlp_lock,
5198 iflags);
5199 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5200 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5201 spin_unlock_irqrestore(&vport->phba->ndlp_lock,
5202 iflags);
5203 }
5204 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005205 return 0;
dea31012005-04-17 16:05:31 -05005206}
5207
5208/*
5209 * Check to see if we can free the nlp back to the freelist.
5210 * If we are in the middle of using the nlp in the discovery state
5211 * machine, defer the free till we reach the end of the state machine.
5212 */
James Smart329f9bc2007-04-25 09:53:01 -04005213static void
James Smart2e0fef82007-06-17 19:56:36 -05005214lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005215{
James Smarta8adb832007-10-27 13:37:53 -04005216 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04005217 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04005218 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04005219 LPFC_MBOXQ_t *mbox;
5220 int rc;
dea31012005-04-17 16:05:31 -05005221
James Smart0d2b6b82008-06-14 22:52:47 -04005222 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04005223 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05005224 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
Dick Kennedye8bcf0a2017-09-29 17:34:32 -07005225 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5226 phba->sli_rev != LPFC_SLI_REV4) {
James Smarta8adb832007-10-27 13:37:53 -04005227 /* For this case we need to cleanup the default rpi
5228 * allocated by the firmware.
5229 */
James Smart0f154222019-09-21 20:58:52 -07005230 lpfc_printf_vlog(vport, KERN_INFO,
5231 LOG_NODE | LOG_DISCOVERY,
5232 "0005 Cleanup Default rpi:x%x DID:x%x flg:x%x "
5233 "ref %d map:x%x ndlp x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04005234 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005235 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005236 ndlp->nlp_usg_map, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04005237 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5238 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04005239 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05005240 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04005241 if (rc) {
5242 mempool_free(mbox, phba->mbox_mem_pool);
5243 }
5244 else {
5245 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5246 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5247 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08005248 mbox->ctx_ndlp = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04005249 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5250 if (rc == MBX_NOT_FINISHED) {
5251 mempool_free(mbox, phba->mbox_mem_pool);
5252 }
5253 }
5254 }
5255 }
James Smart2e0fef82007-06-17 19:56:36 -05005256 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04005257
James Smart2e0fef82007-06-17 19:56:36 -05005258 /*
James Smart466e8402015-05-21 13:55:28 -04005259 * ndlp->rport must be set to NULL before it reaches here
5260 * i.e. break rport/node link before doing lpfc_nlp_put for
5261 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05005262 */
James Smart92d7f7b2007-06-17 19:56:38 -05005263 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04005264 /*
5265 * extra lpfc_nlp_put dropped the reference of ndlp
5266 * for registered rport so need to cleanup rport
5267 */
5268 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07005269 "0940 removed node x%px DID x%x "
James Smart0f154222019-09-21 20:58:52 -07005270 "rpi %d rport not null x%px\n",
5271 ndlp, ndlp->nlp_DID, ndlp->nlp_rpi,
5272 ndlp->rport);
James Smart466e8402015-05-21 13:55:28 -04005273 rport = ndlp->rport;
5274 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04005275 rdata->pnode = NULL;
5276 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04005277 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05005278 }
dea31012005-04-17 16:05:31 -05005279}
5280
5281static int
James Smart2e0fef82007-06-17 19:56:36 -05005282lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5283 uint32_t did)
dea31012005-04-17 16:05:31 -05005284{
James Smart2e0fef82007-06-17 19:56:36 -05005285 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005286
5287 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005288 return 0;
dea31012005-04-17 16:05:31 -05005289
dea31012005-04-17 16:05:31 -05005290 /* First check for Direct match */
5291 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005292 return 1;
dea31012005-04-17 16:05:31 -05005293
5294 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005295 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005296 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005297 return 0;
dea31012005-04-17 16:05:31 -05005298 }
5299
5300 matchdid.un.word = did;
5301 ndlpdid.un.word = ndlp->nlp_DID;
5302 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5303 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5304 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005305 /* This code is supposed to match the ID
5306 * for a private loop device that is
5307 * connect to fl_port. But we need to
5308 * check that the port did not just go
5309 * from pt2pt to fabric or we could end
5310 * up matching ndlp->nlp_DID 000001 to
5311 * fabric DID 0x20101
5312 */
dea31012005-04-17 16:05:31 -05005313 if ((ndlpdid.un.b.domain == 0) &&
5314 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005315 if (ndlpdid.un.b.id &&
5316 vport->phba->fc_topology ==
5317 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005318 return 1;
dea31012005-04-17 16:05:31 -05005319 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005320 return 0;
dea31012005-04-17 16:05:31 -05005321 }
5322
5323 matchdid.un.word = ndlp->nlp_DID;
5324 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5325 (mydid.un.b.area == ndlpdid.un.b.area)) {
5326 if ((matchdid.un.b.domain == 0) &&
5327 (matchdid.un.b.area == 0)) {
5328 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005329 return 1;
dea31012005-04-17 16:05:31 -05005330 }
5331 }
5332 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005333 return 0;
dea31012005-04-17 16:05:31 -05005334}
5335
James Smart685f0bf2007-04-25 09:53:08 -04005336/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005337static struct lpfc_nodelist *
5338__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005339{
James Smart2fb9bd82006-12-02 13:33:57 -05005340 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005341 uint32_t data1;
5342
James Smart2e0fef82007-06-17 19:56:36 -05005343 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5344 if (lpfc_matchdid(vport, ndlp, did)) {
James Smartb95b2112019-08-14 16:56:47 -07005345 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5346 ((uint32_t)ndlp->nlp_xri << 16) |
5347 ((uint32_t)ndlp->nlp_type << 8) |
5348 ((uint32_t)ndlp->nlp_usg_map & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04005349 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5350 "0929 FIND node DID "
James Smartb95b2112019-08-14 16:56:47 -07005351 "Data: x%px x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005352 ndlp, ndlp->nlp_DID,
James Smartb95b2112019-08-14 16:56:47 -07005353 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
James Smartcff261f2013-12-17 20:29:47 -05005354 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005355 return ndlp;
dea31012005-04-17 16:05:31 -05005356 }
5357 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005358
dea31012005-04-17 16:05:31 -05005359 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005360 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5361 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005362 return NULL;
5363}
5364
5365struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005366lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005367{
James Smart2e0fef82007-06-17 19:56:36 -05005368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005369 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005370 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005371
James Smartfedd3b72011-02-16 12:39:24 -05005372 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005373 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005374 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005375 return ndlp;
5376}
5377
5378struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005379lpfc_findnode_mapped(struct lpfc_vport *vport)
5380{
5381 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5382 struct lpfc_nodelist *ndlp;
5383 uint32_t data1;
5384 unsigned long iflags;
5385
5386 spin_lock_irqsave(shost->host_lock, iflags);
5387
5388 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5389 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5390 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5391 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5392 ((uint32_t)ndlp->nlp_xri << 16) |
5393 ((uint32_t)ndlp->nlp_type << 8) |
5394 ((uint32_t)ndlp->nlp_rpi & 0xff));
5395 spin_unlock_irqrestore(shost->host_lock, iflags);
5396 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5397 "2025 FIND node DID "
James Smart32350662019-08-14 16:57:06 -07005398 "Data: x%px x%x x%x x%x x%px\n",
James Smartf60cb932019-05-14 14:58:05 -07005399 ndlp, ndlp->nlp_DID,
5400 ndlp->nlp_flag, data1,
5401 ndlp->active_rrqs_xri_bitmap);
5402 return ndlp;
5403 }
5404 }
5405 spin_unlock_irqrestore(shost->host_lock, iflags);
5406
5407 /* FIND node did <did> NOT FOUND */
5408 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5409 "2026 FIND mapped did NOT FOUND.\n");
5410 return NULL;
5411}
5412
5413struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005414lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5415{
5416 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5417 struct lpfc_nodelist *ndlp;
5418
5419 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005420 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005421 if (vport->phba->nvmet_support)
5422 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005423 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5424 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005425 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005426 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005427 if (!ndlp)
5428 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb4b34172019-10-18 14:18:31 -07005430
5431 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5432 "6453 Setup New Node 2B_DISC x%x "
5433 "Data:x%x x%x x%x\n",
5434 ndlp->nlp_DID, ndlp->nlp_flag,
5435 ndlp->nlp_state, vport->fc_flag);
5436
James Smart2e0fef82007-06-17 19:56:36 -05005437 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005438 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005439 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005440 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005441 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005442 if (vport->phba->nvmet_support)
5443 return NULL;
James Smarte47c9092008-02-08 18:49:26 -05005444 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb95b2112019-08-14 16:56:47 -07005445 if (!ndlp) {
5446 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
5447 "0014 Could not enable ndlp\n");
James Smarte47c9092008-02-08 18:49:26 -05005448 return NULL;
James Smartb95b2112019-08-14 16:56:47 -07005449 }
James Smartb4b34172019-10-18 14:18:31 -07005450 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5451 "6454 Setup Enabled Node 2B_DISC x%x "
5452 "Data:x%x x%x x%x\n",
5453 ndlp->nlp_DID, ndlp->nlp_flag,
5454 ndlp->nlp_state, vport->fc_flag);
5455
James Smarte47c9092008-02-08 18:49:26 -05005456 spin_lock_irq(shost->host_lock);
5457 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5458 spin_unlock_irq(shost->host_lock);
5459 return ndlp;
dea31012005-04-17 16:05:31 -05005460 }
James Smarte47c9092008-02-08 18:49:26 -05005461
James Smart1c5b12f2017-04-21 16:05:03 -07005462 /* The NVME Target does not want to actively manage an rport.
5463 * The goal is to allow the target to reset its state and clear
5464 * pending IO in preparation for the initiator to recover.
5465 */
James Smart58da1ff2008-04-07 10:15:56 -04005466 if ((vport->fc_flag & FC_RSCN_MODE) &&
5467 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005468 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005469
5470 /* Since this node is marked for discovery,
5471 * delay timeout is not needed.
5472 */
5473 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5474
James Smartb4b34172019-10-18 14:18:31 -07005475 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5476 "6455 Setup RSCN Node 2B_DISC x%x "
5477 "Data:x%x x%x x%x\n",
5478 ndlp->nlp_DID, ndlp->nlp_flag,
5479 ndlp->nlp_state, vport->fc_flag);
5480
James Smart1c5b12f2017-04-21 16:05:03 -07005481 /* NVME Target mode waits until rport is known to be
5482 * impacted by the RSCN before it transitions. No
5483 * active management - just go to NPR provided the
5484 * node had a valid login.
5485 */
5486 if (vport->phba->nvmet_support)
5487 return ndlp;
5488
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005489 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005490 * we don't need to try to discover it again.
5491 */
James Smart3f97aed2019-09-21 20:58:55 -07005492 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5493 !(ndlp->nlp_type &
5494 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
James Smart87af33f2007-10-27 13:37:43 -04005495 return NULL;
5496
James Smart3f97aed2019-09-21 20:58:55 -07005497 ndlp->nlp_prev_state = ndlp->nlp_state;
5498 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5499
James Smarta257bf92009-04-06 18:48:10 -04005500 spin_lock_irq(shost->host_lock);
5501 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5502 spin_unlock_irq(shost->host_lock);
James Smartb4b34172019-10-18 14:18:31 -07005503 } else {
5504 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5505 "6456 Skip Setup RSCN Node x%x "
5506 "Data:x%x x%x x%x\n",
5507 ndlp->nlp_DID, ndlp->nlp_flag,
5508 ndlp->nlp_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05005509 ndlp = NULL;
James Smartb4b34172019-10-18 14:18:31 -07005510 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005511 } else {
James Smartb4b34172019-10-18 14:18:31 -07005512 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5513 "6457 Setup Active Node 2B_DISC x%x "
5514 "Data:x%x x%x x%x\n",
5515 ndlp->nlp_DID, ndlp->nlp_flag,
5516 ndlp->nlp_state, vport->fc_flag);
5517
James Smart1c5b12f2017-04-21 16:05:03 -07005518 /* If the initiator received a PLOGI from this NPort or if the
5519 * initiator is already in the process of discovery on it,
5520 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005521 */
James Smart685f0bf2007-04-25 09:53:08 -04005522 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005523 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005524 (!vport->phba->nvmet_support &&
5525 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005526 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005527
James Smart8c258642017-02-12 13:52:36 -08005528 if (vport->phba->nvmet_support)
5529 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005530
5531 /* Moving to NPR state clears unsolicited flags and
5532 * allows for rediscovery
5533 */
5534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5535
James Smart2e0fef82007-06-17 19:56:36 -05005536 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005537 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005538 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005539 }
5540 return ndlp;
5541}
5542
5543/* Build a list of nodes to discover based on the loopmap */
5544void
James Smart2e0fef82007-06-17 19:56:36 -05005545lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005546{
James Smart2e0fef82007-06-17 19:56:36 -05005547 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005548 int j;
5549 uint32_t alpa, index;
5550
James Smart2e0fef82007-06-17 19:56:36 -05005551 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005552 return;
James Smart2e0fef82007-06-17 19:56:36 -05005553
James Smart76a95d72010-11-20 23:11:48 -05005554 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005555 return;
dea31012005-04-17 16:05:31 -05005556
5557 /* Check for loop map present or not */
5558 if (phba->alpa_map[0]) {
5559 for (j = 1; j <= phba->alpa_map[0]; j++) {
5560 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005561 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005562 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005563 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005564 }
5565 } else {
5566 /* No alpamap, so try all alpa's */
5567 for (j = 0; j < FC_MAXLOOP; j++) {
5568 /* If cfg_scan_down is set, start from highest
5569 * ALPA (0xef) to lowest (0x1).
5570 */
James Smart3de2a652007-08-02 11:09:59 -04005571 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005572 index = j;
5573 else
5574 index = FC_MAXLOOP - j - 1;
5575 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005576 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005577 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005578 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005579 }
5580 }
5581 return;
5582}
5583
James Smart895427b2017-02-12 13:52:30 -08005584/* SLI3 only */
dea31012005-04-17 16:05:31 -05005585void
James Smart2e0fef82007-06-17 19:56:36 -05005586lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005587{
dea31012005-04-17 16:05:31 -05005588 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005589 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005590 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5591 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005592 int rc;
5593
James Smart92d7f7b2007-06-17 19:56:38 -05005594 /*
5595 * if it's not a physical port or if we already send
5596 * clear_la then don't send it.
5597 */
5598 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005599 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5600 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005601 return;
5602
James Smart2e0fef82007-06-17 19:56:36 -05005603 /* Link up discovery */
5604 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5605 phba->link_state = LPFC_CLEAR_LA;
5606 lpfc_clear_la(phba, mbox);
5607 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5608 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005609 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005610 if (rc == MBX_NOT_FINISHED) {
5611 mempool_free(mbox, phba->mbox_mem_pool);
5612 lpfc_disc_flush_list(vport);
5613 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5614 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005615 phba->link_state = LPFC_HBA_ERROR;
5616 }
5617 }
5618}
5619
5620/* Reg_vpi to tell firmware to resume normal operations */
5621void
5622lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5623{
5624 LPFC_MBOXQ_t *regvpimbox;
5625
5626 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5627 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005628 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005629 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5630 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005631 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005632 == MBX_NOT_FINISHED) {
5633 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005634 }
5635 }
5636}
5637
5638/* Start Link up / RSCN discovery on NPR nodes */
5639void
5640lpfc_disc_start(struct lpfc_vport *vport)
5641{
5642 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5643 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005644 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005645 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005646
James Smarte74c03c2013-04-17 20:15:19 -04005647 if (!lpfc_is_link_up(phba)) {
5648 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5649 "3315 Link is not up %x\n",
5650 phba->link_state);
dea31012005-04-17 16:05:31 -05005651 return;
James Smarte74c03c2013-04-17 20:15:19 -04005652 }
James Smart2e0fef82007-06-17 19:56:36 -05005653
5654 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005655 clear_la_pending = 1;
5656 else
5657 clear_la_pending = 0;
5658
James Smart2e0fef82007-06-17 19:56:36 -05005659 if (vport->port_state < LPFC_VPORT_READY)
5660 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005661
James Smart2e0fef82007-06-17 19:56:36 -05005662 lpfc_set_disctmo(vport);
5663
James Smart2e0fef82007-06-17 19:56:36 -05005664 vport->fc_prevDID = vport->fc_myDID;
5665 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005666
5667 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005668 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartb4b34172019-10-18 14:18:31 -07005669 "0202 Start Discovery port state x%x "
5670 "flg x%x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04005671 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
James Smartb4b34172019-10-18 14:18:31 -07005672 vport->fc_adisc_cnt, vport->fc_npr_cnt);
dea31012005-04-17 16:05:31 -05005673
5674 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005675 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005676
5677 if (num_sent)
5678 return;
5679
James Smart6fa139f2013-04-17 20:20:00 -04005680 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005681 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005682 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005683 !(vport->fc_flag & FC_RSCN_MODE) &&
5684 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005685 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005686 lpfc_issue_reg_vpi(phba, vport);
5687 return;
5688 }
James Smart2e0fef82007-06-17 19:56:36 -05005689
James Smart92d7f7b2007-06-17 19:56:38 -05005690 /*
5691 * For SLI2, we need to set port_state to READY and continue
5692 * discovery.
5693 */
5694 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5695 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005696 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005697
5698 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005699 vport->num_disc_nodes = 0;
5700 /* go thru NPR nodes and issue ELS PLOGIs */
5701 if (vport->fc_npr_cnt)
5702 lpfc_els_disc_plogi(vport);
5703
5704 if (!vport->num_disc_nodes) {
5705 spin_lock_irq(shost->host_lock);
5706 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5707 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005708 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005709 }
5710 }
James Smart92d7f7b2007-06-17 19:56:38 -05005711 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005712 } else {
5713 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005714 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005715
5716 if (num_sent)
5717 return;
5718
James Smart2e0fef82007-06-17 19:56:36 -05005719 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005720 /* Check to see if more RSCNs came in while we
5721 * were processing this one.
5722 */
James Smart2e0fef82007-06-17 19:56:36 -05005723 if ((vport->fc_rscn_id_cnt == 0) &&
5724 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5725 spin_lock_irq(shost->host_lock);
5726 vport->fc_flag &= ~FC_RSCN_MODE;
5727 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005728 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005729 } else
James Smart2e0fef82007-06-17 19:56:36 -05005730 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005731 }
5732 }
5733 return;
5734}
5735
5736/*
5737 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5738 * ring the match the sppecified nodelist.
5739 */
5740static void
James Smart2e0fef82007-06-17 19:56:36 -05005741lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005742{
James Smart2534ba72007-04-25 09:52:20 -04005743 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005744 IOCB_t *icmd;
5745 struct lpfc_iocbq *iocb, *next_iocb;
5746 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005747
James Smart895427b2017-02-12 13:52:30 -08005748 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005749 if (unlikely(!pring))
5750 return;
dea31012005-04-17 16:05:31 -05005751
5752 /* Error matching iocb on txq or txcmplq
5753 * First check the txq.
5754 */
James Smart2e0fef82007-06-17 19:56:36 -05005755 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005756 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5757 if (iocb->context1 != ndlp) {
5758 continue;
5759 }
5760 icmd = &iocb->iocb;
5761 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5762 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5763
James Smart2534ba72007-04-25 09:52:20 -04005764 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005765 }
5766 }
5767
5768 /* Next check the txcmplq */
5769 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5770 if (iocb->context1 != ndlp) {
5771 continue;
5772 }
5773 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005774 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5775 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005776 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005777 }
5778 }
James Smart2e0fef82007-06-17 19:56:36 -05005779 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005780
James Smarta257bf92009-04-06 18:48:10 -04005781 /* Cancel all the IOCBs from the completions list */
5782 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5783 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005784}
5785
Adrian Bunka6ababd2007-11-05 18:07:33 +01005786static void
James Smart2e0fef82007-06-17 19:56:36 -05005787lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005788{
5789 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005790 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005791
James Smart2e0fef82007-06-17 19:56:36 -05005792 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5793 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005794 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005795 if (!NLP_CHK_NODE_ACT(ndlp))
5796 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005797 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5798 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5799 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005800 }
dea31012005-04-17 16:05:31 -05005801 }
5802 }
dea31012005-04-17 16:05:31 -05005803}
5804
James Smart92d7f7b2007-06-17 19:56:38 -05005805void
5806lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5807{
5808 lpfc_els_flush_rscn(vport);
5809 lpfc_els_flush_cmd(vport);
5810 lpfc_disc_flush_list(vport);
5811}
5812
dea31012005-04-17 16:05:31 -05005813/*****************************************************************************/
5814/*
5815 * NAME: lpfc_disc_timeout
5816 *
5817 * FUNCTION: Fibre Channel driver discovery timeout routine.
5818 *
5819 * EXECUTION ENVIRONMENT: interrupt only
5820 *
5821 * CALLED FROM:
5822 * Timer function
5823 *
5824 * RETURNS:
5825 * none
5826 */
5827/*****************************************************************************/
5828void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005829lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005830{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005831 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005832 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005833 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005834 unsigned long flags = 0;
5835
5836 if (unlikely(!phba))
5837 return;
5838
James Smart5e9d9b82008-06-14 22:52:53 -04005839 spin_lock_irqsave(&vport->work_port_lock, flags);
5840 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5841 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005842 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005843 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005844
James Smart5e9d9b82008-06-14 22:52:53 -04005845 if (!tmo_posted)
5846 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005847 return;
5848}
5849
5850static void
James Smart2e0fef82007-06-17 19:56:36 -05005851lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005852{
James Smart2e0fef82007-06-17 19:56:36 -05005853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5854 struct lpfc_hba *phba = vport->phba;
5855 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005856 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005857 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005858 int rc, clrlaerr = 0;
5859
James Smart2e0fef82007-06-17 19:56:36 -05005860 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005861 return;
5862
James Smart2e0fef82007-06-17 19:56:36 -05005863 spin_lock_irq(shost->host_lock);
5864 vport->fc_flag &= ~FC_DISC_TMO;
5865 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005866
James Smart858c9f62007-06-17 19:56:39 -05005867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5868 "disc timeout: state:x%x rtry:x%x flg:x%x",
5869 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5870
James Smart2e0fef82007-06-17 19:56:36 -05005871 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005872
5873 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005874 /*
5875 * port_state is identically LPFC_LOCAL_CFG_LINK while
5876 * waiting for FAN timeout
5877 */
James Smarte8b62012007-08-02 11:10:09 -04005878 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5879 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005880
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005881 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005882 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005883 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005884 if (!NLP_CHK_NODE_ACT(ndlp))
5885 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005886 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5887 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005888 if (ndlp->nlp_type & NLP_FABRIC) {
5889 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005890 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005891
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005892 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005893 /* Fail outstanding IO now since device
5894 * is marked for PLOGI.
5895 */
James Smart2e0fef82007-06-17 19:56:36 -05005896 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005897 }
5898 }
James Smart92d7f7b2007-06-17 19:56:38 -05005899 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005900 if (phba->sli_rev <= LPFC_SLI_REV3)
5901 lpfc_initial_flogi(vport);
5902 else
5903 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005904 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005905 }
dea31012005-04-17 16:05:31 -05005906 break;
5907
James Smart92d7f7b2007-06-17 19:56:38 -05005908 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005909 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005910 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005911 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005912 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5913 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005914 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005915
5916 /* Assume no Fabric and go on with discovery.
5917 * Check for outstanding ELS FLOGI to abort.
5918 */
5919
5920 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005921 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005922
5923 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005924 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005925 break;
5926
5927 case LPFC_FABRIC_CFG_LINK:
5928 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5929 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005930 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5931 "0223 Timeout while waiting for "
5932 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005933 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005934 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005935 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005936 lpfc_els_abort(phba, ndlp);
5937
5938 /* ReStart discovery */
5939 goto restart_disc;
dea31012005-04-17 16:05:31 -05005940
5941 case LPFC_NS_QRY:
5942 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005943 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5944 "0224 NameServer Query timeout "
5945 "Data: x%x x%x\n",
5946 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005947
James Smart92d7f7b2007-06-17 19:56:38 -05005948 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5949 /* Try it one more time */
5950 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005951 vport->gidft_inp = 0;
5952 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005953 if (rc == 0)
5954 break;
dea31012005-04-17 16:05:31 -05005955 }
James Smart92d7f7b2007-06-17 19:56:38 -05005956 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005957
James Smart87af33f2007-10-27 13:37:43 -04005958restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005959 /*
5960 * Discovery is over.
5961 * set port_state to PORT_READY if SLI2.
5962 * cmpl_reg_vpi will set port_state to READY for SLI3.
5963 */
James Smart3772a992009-05-22 14:50:54 -04005964 if (phba->sli_rev < LPFC_SLI_REV4) {
5965 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5966 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005967 else {
James Smart3772a992009-05-22 14:50:54 -04005968 lpfc_issue_clear_la(phba, vport);
5969 vport->port_state = LPFC_VPORT_READY;
5970 }
dea31012005-04-17 16:05:31 -05005971 }
5972
5973 /* Setup and issue mailbox INITIALIZE LINK command */
5974 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5975 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005976 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5977 "0206 Device Discovery "
5978 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005979 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005980 break;
5981 }
5982
5983 lpfc_linkdown(phba);
5984 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5985 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005986 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005987 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005988 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005989 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005990 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005991 if (rc == MBX_NOT_FINISHED)
5992 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5993
5994 break;
5995
5996 case LPFC_DISC_AUTH:
5997 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005998 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5999 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05006000 lpfc_disc_flush_list(vport);
6001
James Smart92d7f7b2007-06-17 19:56:38 -05006002 /*
6003 * set port_state to PORT_READY if SLI2.
6004 * cmpl_reg_vpi will set port_state to READY for SLI3.
6005 */
James Smart3772a992009-05-22 14:50:54 -04006006 if (phba->sli_rev < LPFC_SLI_REV4) {
6007 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6008 lpfc_issue_reg_vpi(phba, vport);
6009 else { /* NPIV Not enabled */
6010 lpfc_issue_clear_la(phba, vport);
6011 vport->port_state = LPFC_VPORT_READY;
6012 }
dea31012005-04-17 16:05:31 -05006013 }
6014 break;
6015
James Smart2e0fef82007-06-17 19:56:36 -05006016 case LPFC_VPORT_READY:
6017 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04006018 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6019 "0231 RSCN timeout Data: x%x "
6020 "x%x\n",
6021 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05006022
6023 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05006024 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05006025
James Smart2e0fef82007-06-17 19:56:36 -05006026 lpfc_els_flush_rscn(vport);
6027 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05006028 }
6029 break;
James Smart2e0fef82007-06-17 19:56:36 -05006030
James Smart92d7f7b2007-06-17 19:56:38 -05006031 default:
James Smarte8b62012007-08-02 11:10:09 -04006032 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006033 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04006034 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05006035 break;
6036 }
6037
6038 switch (phba->link_state) {
6039 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05006040 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04006041 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6042 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05006043 clrlaerr = 1;
6044 break;
6045
James Smart09372822008-01-11 01:52:54 -05006046 case LPFC_LINK_UP:
6047 lpfc_issue_clear_la(phba, vport);
Bart Van Asschecd05c152019-03-28 11:06:18 -07006048 /* fall through */
James Smart2e0fef82007-06-17 19:56:36 -05006049 case LPFC_LINK_UNKNOWN:
6050 case LPFC_WARM_START:
6051 case LPFC_INIT_START:
6052 case LPFC_INIT_MBX_CMDS:
6053 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05006054 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04006055 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
6056 "0230 Unexpected timeout, hba link "
6057 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05006058 clrlaerr = 1;
6059 break;
James Smart92d7f7b2007-06-17 19:56:38 -05006060
6061 case LPFC_HBA_READY:
6062 break;
dea31012005-04-17 16:05:31 -05006063 }
6064
6065 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05006066 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08006067 if (phba->sli_rev != LPFC_SLI_REV4) {
6068 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6069 ~LPFC_STOP_IOCB_EVENT;
6070 psli->sli3_ring[LPFC_FCP_RING].flag &=
6071 ~LPFC_STOP_IOCB_EVENT;
6072 }
James Smart2e0fef82007-06-17 19:56:36 -05006073 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05006074 }
dea31012005-04-17 16:05:31 -05006075 return;
6076}
6077
dea31012005-04-17 16:05:31 -05006078/*
6079 * This routine handles processing a NameServer REG_LOGIN mailbox
6080 * command upon completion. It is setup in the LPFC_MBOXQ
6081 * as the completion routine when the command is
6082 * handed off to the SLI layer.
6083 */
6084void
James Smart2e0fef82007-06-17 19:56:36 -05006085lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05006086{
James Smart04c68492009-05-22 14:52:52 -04006087 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08006088 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6089 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05006090 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05006091
James Smart3e1f0712018-11-29 16:09:29 -08006092 pmb->ctx_buf = NULL;
6093 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05006094
James Smart6d368e52011-05-24 11:44:12 -04006095 if (phba->sli_rev < LPFC_SLI_REV4)
6096 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05006097 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05006098 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05006099 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart0f154222019-09-21 20:58:52 -07006100 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
James Smart32350662019-08-14 16:57:06 -07006101 "0004 rpi:%x DID:%x flg:%x %d map:%x x%px\n",
James Smartbe6bb942015-04-07 15:07:22 -04006102 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006103 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04006104 ndlp->nlp_usg_map, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006105 /*
6106 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05006107 * 0xfffffa (FDMI well known port).
6108 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6109 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05006110 */
James Smart4258e982015-12-16 18:11:58 -05006111 if (vport->port_type == LPFC_PHYSICAL_PORT)
6112 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04006113 else
James Smart4258e982015-12-16 18:11:58 -05006114 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6115
dea31012005-04-17 16:05:31 -05006116
James Smartfa4066b2008-01-11 01:53:27 -05006117 /* decrement the node reference count held for this callback
6118 * function.
6119 */
James Smart329f9bc2007-04-25 09:53:01 -04006120 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006121 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6122 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04006123 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006124
6125 return;
6126}
6127
James Smart685f0bf2007-04-25 09:53:08 -04006128static int
6129lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6130{
6131 uint16_t *rpi = param;
6132
James Smarteff4a012012-01-18 16:25:25 -05006133 /* check for active node */
6134 if (!NLP_CHK_NODE_ACT(ndlp))
6135 return 0;
6136
James Smart685f0bf2007-04-25 09:53:08 -04006137 return ndlp->nlp_rpi == *rpi;
6138}
6139
6140static int
6141lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6142{
6143 return memcmp(&ndlp->nlp_portname, param,
6144 sizeof(ndlp->nlp_portname)) == 0;
6145}
6146
Adrian Bunka6ababd2007-11-05 18:07:33 +01006147static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006148__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006149{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006150 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006151
James Smart2e0fef82007-06-17 19:56:36 -05006152 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006153 if (filter(ndlp, param)) {
6154 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006155 "3185 FIND node filter %ps DID "
James Smart32350662019-08-14 16:57:06 -07006156 "ndlp x%px did x%x flg x%x st x%x "
James Smart49382502017-11-20 16:00:38 -08006157 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006158 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006159 ndlp->nlp_flag, ndlp->nlp_state,
6160 ndlp->nlp_xri, ndlp->nlp_type,
6161 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006162 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006163 }
James Smart685f0bf2007-04-25 09:53:08 -04006164 }
James Smart34f5ad82012-08-03 12:35:03 -04006165 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
Sakari Ailus2d44d162019-09-04 19:04:23 +03006166 "3186 FIND node filter %ps NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006167 return NULL;
dea31012005-04-17 16:05:31 -05006168}
6169
James Smart685f0bf2007-04-25 09:53:08 -04006170/*
6171 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006172 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006173 */
6174struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006175__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006176{
James Smart2e0fef82007-06-17 19:56:36 -05006177 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006178}
6179
James Smart488d1462006-03-07 15:02:37 -05006180/*
James Smart685f0bf2007-04-25 09:53:08 -04006181 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006182 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006183 */
6184struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006185lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006186{
James Smart2e0fef82007-06-17 19:56:36 -05006187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006188 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006189
James Smart2e0fef82007-06-17 19:56:36 -05006190 spin_lock_irq(shost->host_lock);
6191 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6192 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006193 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006194}
6195
James Smartcb69f7d2011-12-13 13:21:57 -05006196/*
6197 * This routine looks up the ndlp lists for the given RPI. If the rpi
6198 * is found, the routine returns the node element list pointer else
6199 * return NULL.
6200 */
6201struct lpfc_nodelist *
6202lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6203{
6204 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6205 struct lpfc_nodelist *ndlp;
Fuqian Huang78d4b132019-08-12 16:31:34 +08006206 unsigned long flags;
James Smartcb69f7d2011-12-13 13:21:57 -05006207
Fuqian Huang78d4b132019-08-12 16:31:34 +08006208 spin_lock_irqsave(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006209 ndlp = __lpfc_findnode_rpi(vport, rpi);
Fuqian Huang78d4b132019-08-12 16:31:34 +08006210 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006211 return ndlp;
6212}
6213
6214/**
6215 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6216 * @phba: pointer to lpfc hba data structure.
6217 * @vpi: the physical host virtual N_Port identifier.
6218 *
6219 * This routine finds a vport on a HBA (referred by @phba) through a
6220 * @vpi. The function walks the HBA's vport list and returns the address
6221 * of the vport with the matching @vpi.
6222 *
6223 * Return code
6224 * NULL - No vport with the matching @vpi found
6225 * Otherwise - Address to the vport with the matching @vpi.
6226 **/
6227struct lpfc_vport *
6228lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6229{
6230 struct lpfc_vport *vport;
6231 unsigned long flags;
6232 int i = 0;
6233
6234 /* The physical ports are always vpi 0 - translate is unnecessary. */
6235 if (vpi > 0) {
6236 /*
6237 * Translate the physical vpi to the logical vpi. The
6238 * vport stores the logical vpi.
6239 */
6240 for (i = 0; i < phba->max_vpi; i++) {
6241 if (vpi == phba->vpi_ids[i])
6242 break;
6243 }
6244
6245 if (i >= phba->max_vpi) {
6246 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6247 "2936 Could not find Vport mapped "
6248 "to vpi %d\n", vpi);
6249 return NULL;
6250 }
6251 }
6252
James Smart523128e2018-09-10 10:30:46 -07006253 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006254 list_for_each_entry(vport, &phba->port_list, listentry) {
6255 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006256 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006257 return vport;
6258 }
6259 }
James Smart523128e2018-09-10 10:30:46 -07006260 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006261 return NULL;
6262}
6263
James Smart9d3d3402017-04-21 16:05:00 -07006264struct lpfc_nodelist *
6265lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006266{
James Smart9d3d3402017-04-21 16:05:00 -07006267 struct lpfc_nodelist *ndlp;
6268 int rpi = LPFC_RPI_ALLOC_ERROR;
6269
6270 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6271 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6272 if (rpi == LPFC_RPI_ALLOC_ERROR)
6273 return NULL;
6274 }
6275
6276 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6277 if (!ndlp) {
6278 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6279 lpfc_sli4_free_rpi(vport->phba, rpi);
6280 return NULL;
6281 }
6282
dea31012005-04-17 16:05:31 -05006283 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006284
6285 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006286 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006287 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006288 ndlp->nlp_rpi = rpi;
James Smart0f154222019-09-21 20:58:52 -07006289 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6290 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6291 "flg:x%x refcnt:%d map:x%x\n",
6292 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6293 ndlp->nlp_flag, kref_read(&ndlp->kref),
6294 ndlp->nlp_usg_map);
James Smartbe6bb942015-04-07 15:07:22 -04006295
James Smartcff261f2013-12-17 20:29:47 -05006296 ndlp->active_rrqs_xri_bitmap =
6297 mempool_alloc(vport->phba->active_rrq_pool,
6298 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006299 if (ndlp->active_rrqs_xri_bitmap)
6300 memset(ndlp->active_rrqs_xri_bitmap, 0,
6301 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006302 }
6303
James Smart725dd392013-10-10 12:23:30 -04006304
James Smart858c9f62007-06-17 19:56:39 -05006305
6306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6307 "node init: did:x%x",
6308 ndlp->nlp_DID, 0, 0);
6309
James Smart9d3d3402017-04-21 16:05:00 -07006310 return ndlp;
dea31012005-04-17 16:05:31 -05006311}
James Smart329f9bc2007-04-25 09:53:01 -04006312
James Smart98c9ea52007-10-27 13:37:33 -04006313/* This routine releases all resources associated with a specifc NPort's ndlp
6314 * and mempool_free's the nodelist.
6315 */
James Smart311464e2007-08-02 11:10:37 -04006316static void
James Smart329f9bc2007-04-25 09:53:01 -04006317lpfc_nlp_release(struct kref *kref)
6318{
James Smarte47c9092008-02-08 18:49:26 -05006319 struct lpfc_hba *phba;
6320 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04006321 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6322 kref);
James Smart858c9f62007-06-17 19:56:39 -05006323
6324 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6325 "node release: did:x%x flg:x%x type:x%x",
6326 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6327
James Smarte47c9092008-02-08 18:49:26 -05006328 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07006329 "0279 %s: ndlp:x%px did %x "
James Smartbe6bb942015-04-07 15:07:22 -04006330 "usgmap:x%x refcnt:%d rpi:%x\n",
James Smart32350662019-08-14 16:57:06 -07006331 __func__,
James Smart939723a2012-05-09 21:19:03 -04006332 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006333 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006334
6335 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05006336 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05006337
6338 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04006339 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006340 spin_lock_irqsave(&phba->ndlp_lock, flags);
6341 NLP_CLR_NODE_ACT(ndlp);
6342 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6343
6344 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04006345 if (NLP_CHK_FREE_REQ(ndlp)) {
6346 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05006347 if (phba->sli_rev == LPFC_SLI_REV4)
6348 mempool_free(ndlp->active_rrqs_xri_bitmap,
6349 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04006350 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04006351 }
James Smart329f9bc2007-04-25 09:53:01 -04006352}
6353
James Smart98c9ea52007-10-27 13:37:33 -04006354/* This routine bumps the reference count for a ndlp structure to ensure
6355 * that one discovery thread won't free a ndlp while another discovery thread
6356 * is using it.
6357 */
James Smart329f9bc2007-04-25 09:53:01 -04006358struct lpfc_nodelist *
6359lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6360{
James Smarte47c9092008-02-08 18:49:26 -05006361 struct lpfc_hba *phba;
6362 unsigned long flags;
6363
James Smart98c9ea52007-10-27 13:37:33 -04006364 if (ndlp) {
6365 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6366 "node get: did:x%x flg:x%x refcnt:x%x",
6367 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006368 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006369 /* The check of ndlp usage to prevent incrementing the
6370 * ndlp reference count that is in the process of being
6371 * released.
6372 */
James Smarta257bf92009-04-06 18:48:10 -04006373 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006374 spin_lock_irqsave(&phba->ndlp_lock, flags);
6375 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6376 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6377 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07006378 "0276 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05006379 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07006380 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006381 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006382 return NULL;
6383 } else
6384 kref_get(&ndlp->kref);
6385 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04006386 }
James Smart329f9bc2007-04-25 09:53:01 -04006387 return ndlp;
6388}
6389
James Smart98c9ea52007-10-27 13:37:33 -04006390/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05006391 * count goes to 0, this indicates the the associated nodelist should be
6392 * freed. Returning 1 indicates the ndlp resource has been released; on the
6393 * other hand, returning 0 indicates the ndlp resource has not been released
6394 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04006395 */
James Smart329f9bc2007-04-25 09:53:01 -04006396int
6397lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6398{
James Smarte47c9092008-02-08 18:49:26 -05006399 struct lpfc_hba *phba;
6400 unsigned long flags;
6401
6402 if (!ndlp)
6403 return 1;
6404
6405 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
James Smart32350662019-08-14 16:57:06 -07006406 "node put: did:x%x flg:x%x refcnt:x%x",
6407 ndlp->nlp_DID, ndlp->nlp_flag,
6408 kref_read(&ndlp->kref));
James Smarta257bf92009-04-06 18:48:10 -04006409 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006410 spin_lock_irqsave(&phba->ndlp_lock, flags);
6411 /* Check the ndlp memory free acknowledge flag to avoid the
6412 * possible race condition that kref_put got invoked again
6413 * after previous one has done ndlp memory free.
6414 */
6415 if (NLP_CHK_FREE_ACK(ndlp)) {
6416 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6417 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07006418 "0274 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05006419 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07006420 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006421 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006422 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006423 }
James Smarte47c9092008-02-08 18:49:26 -05006424 /* Check the ndlp inactivate log flag to avoid the possible
6425 * race condition that kref_put got invoked again after ndlp
6426 * is already in inactivating state.
6427 */
6428 if (NLP_CHK_IACT_REQ(ndlp)) {
6429 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6430 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
James Smart32350662019-08-14 16:57:06 -07006431 "0275 %s: ndlp:x%px "
James Smarte47c9092008-02-08 18:49:26 -05006432 "usgmap:x%x refcnt:%d\n",
James Smart32350662019-08-14 16:57:06 -07006433 __func__, (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006434 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006435 return 1;
6436 }
6437 /* For last put, mark the ndlp usage flags to make sure no
6438 * other kref_get and kref_put on the same ndlp shall get
6439 * in between the process when the final kref_put has been
6440 * invoked on this ndlp.
6441 */
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006442 if (kref_read(&ndlp->kref) == 1) {
James Smarte47c9092008-02-08 18:49:26 -05006443 /* Indicate ndlp is put to inactive state. */
6444 NLP_SET_IACT_REQ(ndlp);
6445 /* Acknowledge ndlp memory free has been seen. */
6446 if (NLP_CHK_FREE_REQ(ndlp))
6447 NLP_SET_FREE_ACK(ndlp);
6448 }
6449 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6450 /* Note, the kref_put returns 1 when decrementing a reference
6451 * count that was 1, it invokes the release callback function,
6452 * but it still left the reference count as 1 (not actually
6453 * performs the last decrementation). Otherwise, it actually
6454 * decrements the reference count and returns 0.
6455 */
6456 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04006457}
James Smart98c9ea52007-10-27 13:37:33 -04006458
6459/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006460 * by any other discovery thread. This routine returns 1 if the
6461 * ndlp has been freed. A return value of 0 indicates the ndlp is
6462 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006463 */
6464int
6465lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6466{
6467 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6468 "node not used: did:x%x flg:x%x refcnt:x%x",
6469 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006470 kref_read(&ndlp->kref));
6471 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006472 if (lpfc_nlp_put(ndlp))
6473 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006474 return 0;
6475}
James Smart6fb120a2009-05-22 14:52:59 -04006476
6477/**
6478 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6479 * @phba: Pointer to hba context object.
6480 *
6481 * This function iterate through all FC nodes associated
6482 * will all vports to check if there is any node with
6483 * fc_rports associated with it. If there is an fc_rport
6484 * associated with the node, then the node is either in
6485 * discovered state or its devloss_timer is pending.
6486 */
6487static int
6488lpfc_fcf_inuse(struct lpfc_hba *phba)
6489{
6490 struct lpfc_vport **vports;
6491 int i, ret = 0;
6492 struct lpfc_nodelist *ndlp;
6493 struct Scsi_Host *shost;
6494
6495 vports = lpfc_create_vport_work_array(phba);
6496
James Smart63e801c2010-11-20 23:14:19 -05006497 /* If driver cannot allocate memory, indicate fcf is in use */
6498 if (!vports)
6499 return 1;
6500
James Smart6fb120a2009-05-22 14:52:59 -04006501 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6502 shost = lpfc_shost_from_vport(vports[i]);
6503 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006504 /*
6505 * IF the CVL_RCVD bit is not set then we have sent the
6506 * flogi.
6507 * If dev_loss fires while we are waiting we do not want to
6508 * unreg the fcf.
6509 */
6510 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6511 spin_unlock_irq(shost->host_lock);
6512 ret = 1;
6513 goto out;
6514 }
James Smart6fb120a2009-05-22 14:52:59 -04006515 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6516 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6517 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6518 ret = 1;
6519 spin_unlock_irq(shost->host_lock);
6520 goto out;
James Smart80c17842012-03-01 22:35:45 -05006521 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6522 ret = 1;
James Smart0f154222019-09-21 20:58:52 -07006523 lpfc_printf_log(phba, KERN_INFO,
6524 LOG_NODE | LOG_DISCOVERY,
James Smart80c17842012-03-01 22:35:45 -05006525 "2624 RPI %x DID %x flag %x "
6526 "still logged in\n",
6527 ndlp->nlp_rpi, ndlp->nlp_DID,
6528 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006529 }
6530 }
6531 spin_unlock_irq(shost->host_lock);
6532 }
6533out:
6534 lpfc_destroy_vport_work_array(phba, vports);
6535 return ret;
6536}
6537
6538/**
6539 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6540 * @phba: Pointer to hba context object.
6541 * @mboxq: Pointer to mailbox object.
6542 *
6543 * This function frees memory associated with the mailbox command.
6544 */
James Smart1b511972011-12-13 13:23:09 -05006545void
James Smart6fb120a2009-05-22 14:52:59 -04006546lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6547{
6548 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006550
6551 if (mboxq->u.mb.mbxStatus) {
6552 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6553 "2555 UNREG_VFI mbxStatus error x%x "
6554 "HBA state x%x\n",
6555 mboxq->u.mb.mbxStatus, vport->port_state);
6556 }
James Smart38b92ef2010-08-04 16:11:39 -04006557 spin_lock_irq(shost->host_lock);
6558 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6559 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006560 mempool_free(mboxq, phba->mbox_mem_pool);
6561 return;
6562}
6563
6564/**
6565 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6566 * @phba: Pointer to hba context object.
6567 * @mboxq: Pointer to mailbox object.
6568 *
6569 * This function frees memory associated with the mailbox command.
6570 */
6571static void
6572lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6573{
6574 struct lpfc_vport *vport = mboxq->vport;
6575
6576 if (mboxq->u.mb.mbxStatus) {
6577 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6578 "2550 UNREG_FCFI mbxStatus error x%x "
6579 "HBA state x%x\n",
6580 mboxq->u.mb.mbxStatus, vport->port_state);
6581 }
6582 mempool_free(mboxq, phba->mbox_mem_pool);
6583 return;
6584}
6585
6586/**
James Smartecfd03c2010-02-12 14:41:27 -05006587 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006588 * @phba: Pointer to hba context object.
6589 *
James Smartecfd03c2010-02-12 14:41:27 -05006590 * This function prepare the HBA for unregistering the currently registered
6591 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6592 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006593 */
James Smartecfd03c2010-02-12 14:41:27 -05006594int
6595lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006596{
James Smart6fb120a2009-05-22 14:52:59 -04006597 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006598 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006599 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006600 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006601
James Smartecfd03c2010-02-12 14:41:27 -05006602 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006603 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006604 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006605
James Smart4d9ab992009-10-02 15:16:39 -04006606 /* At this point, all discovery is aborted */
6607 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006608
6609 /* Unregister VPIs */
6610 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006611 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006612 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006613 /* Stop FLOGI/FDISC retries */
6614 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6615 if (ndlp)
6616 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006617 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006618 if (phba->sli_rev == LPFC_SLI_REV4)
6619 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006620 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006621 shost = lpfc_shost_from_vport(vports[i]);
6622 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006623 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006624 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006625 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006626 }
6627 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006628 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6629 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6630 if (ndlp)
6631 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6632 lpfc_cleanup_pending_mbox(phba->pport);
6633 if (phba->sli_rev == LPFC_SLI_REV4)
6634 lpfc_sli4_unreg_all_rpis(phba->pport);
6635 lpfc_mbx_unreg_vpi(phba->pport);
6636 shost = lpfc_shost_from_vport(phba->pport);
6637 spin_lock_irq(shost->host_lock);
6638 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6639 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6640 spin_unlock_irq(shost->host_lock);
6641 }
James Smart6fb120a2009-05-22 14:52:59 -04006642
James Smart695a8142010-01-26 23:08:03 -05006643 /* Cleanup any outstanding ELS commands */
6644 lpfc_els_flush_all_cmd(phba);
6645
James Smart1b511972011-12-13 13:23:09 -05006646 /* Unregister the physical port VFI */
6647 rc = lpfc_issue_unreg_vfi(phba->pport);
6648 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006649}
6650
6651/**
6652 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6653 * @phba: Pointer to hba context object.
6654 *
6655 * This function issues synchronous unregister FCF mailbox command to HBA to
6656 * unregister the currently registered FCF record. The driver does not reset
6657 * the driver FCF usage state flags.
6658 *
6659 * Return 0 if successfully issued, none-zero otherwise.
6660 */
6661int
6662lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6663{
6664 LPFC_MBOXQ_t *mbox;
6665 int rc;
6666
James Smart6fb120a2009-05-22 14:52:59 -04006667 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6668 if (!mbox) {
6669 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006670 "2551 UNREG_FCFI mbox allocation failed"
6671 "HBA state x%x\n", phba->pport->port_state);
6672 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006673 }
James Smart6fb120a2009-05-22 14:52:59 -04006674 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6675 mbox->vport = phba->pport;
6676 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6677 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6678
6679 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006680 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6681 "2552 Unregister FCFI command failed rc x%x "
6682 "HBA state x%x\n",
6683 rc, phba->pport->port_state);
6684 return -EINVAL;
6685 }
6686 return 0;
6687}
6688
6689/**
6690 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6691 * @phba: Pointer to hba context object.
6692 *
6693 * This function unregisters the currently reigstered FCF. This function
6694 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6695 */
6696void
6697lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6698{
6699 int rc;
6700
6701 /* Preparation for unregistering fcf */
6702 rc = lpfc_unregister_fcf_prep(phba);
6703 if (rc) {
6704 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6705 "2748 Failed to prepare for unregistering "
6706 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006707 return;
6708 }
6709
James Smartecfd03c2010-02-12 14:41:27 -05006710 /* Now, unregister FCF record and reset HBA FCF state */
6711 rc = lpfc_sli4_unregister_fcf(phba);
6712 if (rc)
6713 return;
6714 /* Reset HBA FCF states after successful unregister FCF */
6715 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006716 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006717
6718 /*
6719 * If driver is not unloading, check if there is any other
6720 * FCF record that can be used for discovery.
6721 */
6722 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006723 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006724 return;
6725
James Smart0c9ab6f2010-02-26 14:15:57 -05006726 /* This is considered as the initial FCF discovery scan */
6727 spin_lock_irq(&phba->hbalock);
6728 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6729 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006730
6731 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006732 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006733
James Smart0c9ab6f2010-02-26 14:15:57 -05006734 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006735
James Smart0c9ab6f2010-02-26 14:15:57 -05006736 if (rc) {
6737 spin_lock_irq(&phba->hbalock);
6738 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6739 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006740 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006741 "2553 lpfc_unregister_unused_fcf failed "
6742 "to read FCF record HBA state x%x\n",
6743 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006744 }
James Smartecfd03c2010-02-12 14:41:27 -05006745}
6746
6747/**
6748 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6749 * @phba: Pointer to hba context object.
6750 *
6751 * This function just unregisters the currently reigstered FCF. It does not
6752 * try to find another FCF for discovery.
6753 */
6754void
6755lpfc_unregister_fcf(struct lpfc_hba *phba)
6756{
6757 int rc;
6758
6759 /* Preparation for unregistering fcf */
6760 rc = lpfc_unregister_fcf_prep(phba);
6761 if (rc) {
6762 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6763 "2749 Failed to prepare for unregistering "
6764 "HBA's FCF record: rc=%d\n", rc);
6765 return;
6766 }
6767
6768 /* Now, unregister FCF record and reset HBA FCF state */
6769 rc = lpfc_sli4_unregister_fcf(phba);
6770 if (rc)
6771 return;
6772 /* Set proper HBA FCF states after successful unregister FCF */
6773 spin_lock_irq(&phba->hbalock);
6774 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6775 spin_unlock_irq(&phba->hbalock);
6776}
6777
6778/**
6779 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6780 * @phba: Pointer to hba context object.
6781 *
6782 * This function check if there are any connected remote port for the FCF and
6783 * if all the devices are disconnected, this function unregister FCFI.
6784 * This function also tries to use another FCF for discovery.
6785 */
6786void
6787lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6788{
6789 /*
James Smart3804dc82010-07-14 15:31:37 -04006790 * If HBA is not running in FIP mode, if HBA does not support
6791 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6792 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006793 */
6794 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006795 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006796 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006797 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006798 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006799 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006800 spin_unlock_irq(&phba->hbalock);
6801 return;
6802 }
6803 spin_unlock_irq(&phba->hbalock);
6804
6805 if (lpfc_fcf_inuse(phba))
6806 return;
6807
6808 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006809}
6810
6811/**
6812 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6813 * @phba: Pointer to hba context object.
6814 * @buff: Buffer containing the FCF connection table as in the config
6815 * region.
6816 * This function create driver data structure for the FCF connection
6817 * record table read from config region 23.
6818 */
6819static void
6820lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6821 uint8_t *buff)
6822{
6823 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6824 struct lpfc_fcf_conn_hdr *conn_hdr;
6825 struct lpfc_fcf_conn_rec *conn_rec;
6826 uint32_t record_count;
6827 int i;
6828
6829 /* Free the current connect table */
6830 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006831 &phba->fcf_conn_rec_list, list) {
6832 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006833 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006834 }
James Smart6fb120a2009-05-22 14:52:59 -04006835
6836 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6837 record_count = conn_hdr->length * sizeof(uint32_t)/
6838 sizeof(struct lpfc_fcf_conn_rec);
6839
6840 conn_rec = (struct lpfc_fcf_conn_rec *)
6841 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6842
6843 for (i = 0; i < record_count; i++) {
6844 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6845 continue;
6846 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6847 GFP_KERNEL);
6848 if (!conn_entry) {
6849 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6850 "2566 Failed to allocate connection"
6851 " table entry\n");
6852 return;
6853 }
6854
6855 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6856 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006857 list_add_tail(&conn_entry->list,
6858 &phba->fcf_conn_rec_list);
6859 }
James Smartdf0d0852013-05-31 17:05:08 -04006860
6861 if (!list_empty(&phba->fcf_conn_rec_list)) {
6862 i = 0;
6863 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6864 list) {
6865 conn_rec = &conn_entry->conn_rec;
6866 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6867 "3345 FCF connection list rec[%02d]: "
6868 "flags:x%04x, vtag:x%04x, "
6869 "fabric_name:x%02x:%02x:%02x:%02x:"
6870 "%02x:%02x:%02x:%02x, "
6871 "switch_name:x%02x:%02x:%02x:%02x:"
6872 "%02x:%02x:%02x:%02x\n", i++,
6873 conn_rec->flags, conn_rec->vlan_tag,
6874 conn_rec->fabric_name[0],
6875 conn_rec->fabric_name[1],
6876 conn_rec->fabric_name[2],
6877 conn_rec->fabric_name[3],
6878 conn_rec->fabric_name[4],
6879 conn_rec->fabric_name[5],
6880 conn_rec->fabric_name[6],
6881 conn_rec->fabric_name[7],
6882 conn_rec->switch_name[0],
6883 conn_rec->switch_name[1],
6884 conn_rec->switch_name[2],
6885 conn_rec->switch_name[3],
6886 conn_rec->switch_name[4],
6887 conn_rec->switch_name[5],
6888 conn_rec->switch_name[6],
6889 conn_rec->switch_name[7]);
6890 }
6891 }
James Smart6fb120a2009-05-22 14:52:59 -04006892}
6893
6894/**
6895 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6896 * @phba: Pointer to hba context object.
6897 * @buff: Buffer containing the FCoE parameter data structure.
6898 *
6899 * This function update driver data structure with config
6900 * parameters read from config region 23.
6901 */
6902static void
6903lpfc_read_fcoe_param(struct lpfc_hba *phba,
6904 uint8_t *buff)
6905{
6906 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6907 struct lpfc_fcoe_params *fcoe_param;
6908
6909 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6910 buff;
6911 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006912 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006913
6914 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6915 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6916 return;
6917
James Smart6fb120a2009-05-22 14:52:59 -04006918 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6919 phba->valid_vlan = 1;
6920 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6921 0xFFF;
6922 }
6923
6924 phba->fc_map[0] = fcoe_param->fc_map[0];
6925 phba->fc_map[1] = fcoe_param->fc_map[1];
6926 phba->fc_map[2] = fcoe_param->fc_map[2];
6927 return;
6928}
6929
6930/**
6931 * lpfc_get_rec_conf23 - Get a record type in config region data.
6932 * @buff: Buffer containing config region 23 data.
6933 * @size: Size of the data buffer.
6934 * @rec_type: Record type to be searched.
6935 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006936 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006937 * of the record specified by record_type. If record found, this
6938 * function return pointer to the record else return NULL.
6939 */
6940static uint8_t *
6941lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6942{
6943 uint32_t offset = 0, rec_length;
6944
6945 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6946 (size < sizeof(uint32_t)))
6947 return NULL;
6948
6949 rec_length = buff[offset + 1];
6950
6951 /*
6952 * One TLV record has one word header and number of data words
6953 * specified in the rec_length field of the record header.
6954 */
6955 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6956 <= size) {
6957 if (buff[offset] == rec_type)
6958 return &buff[offset];
6959
6960 if (buff[offset] == LPFC_REGION23_LAST_REC)
6961 return NULL;
6962
6963 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6964 rec_length = buff[offset + 1];
6965 }
6966 return NULL;
6967}
6968
6969/**
6970 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6971 * @phba: Pointer to lpfc_hba data structure.
6972 * @buff: Buffer containing config region 23 data.
6973 * @size: Size of the data buffer.
6974 *
Stefan Weileef35c22010-08-06 21:11:15 +02006975 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006976 * populate driver data structure with the parameters.
6977 */
6978void
6979lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6980 uint8_t *buff,
6981 uint32_t size)
6982{
James Smarteb016562014-09-03 12:58:06 -04006983 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006984 uint8_t *rec_ptr;
6985
6986 /*
6987 * If data size is less than 2 words signature and version cannot be
6988 * verified.
6989 */
6990 if (size < 2*sizeof(uint32_t))
6991 return;
6992
6993 /* Check the region signature first */
6994 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6995 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6996 "2567 Config region 23 has bad signature\n");
6997 return;
6998 }
6999
7000 offset += 4;
7001
7002 /* Check the data structure version */
7003 if (buff[offset] != LPFC_REGION23_VERSION) {
7004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7005 "2568 Config region 23 has bad version\n");
7006 return;
7007 }
7008 offset += 4;
7009
James Smart6fb120a2009-05-22 14:52:59 -04007010 /* Read FCoE param record */
7011 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7012 size - offset, FCOE_PARAM_TYPE);
7013 if (rec_ptr)
7014 lpfc_read_fcoe_param(phba, rec_ptr);
7015
7016 /* Read FCF connection table */
7017 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7018 size - offset, FCOE_CONN_TBL_TYPE);
7019 if (rec_ptr)
7020 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
7021
7022}