blob: c8d14709343fb9edc2684e3a4cd63c26e9686521 [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 Smart0d041212019-01-28 11:14:41 -08004 * Copyright (C) 2017-2019 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>
dea31012005-04-17 16:05:31 -050031
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040032#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050033#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h>
James Smarta0f2d3e2017-02-12 13:52:31 -080036#include <scsi/fc/fc_fs.h>
37
38#include <linux/nvme-fc-driver.h>
dea31012005-04-17 16:05:31 -050039
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040042#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_disc.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050046#include "lpfc.h"
James Smarta0f2d3e2017-02-12 13:52:31 -080047#include "lpfc_scsi.h"
48#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050049#include "lpfc_logmsg.h"
50#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050051#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050052#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050053
54/* AlpaArray for assignment of scsid for scan-down and bind_method */
55static uint8_t lpfcAlpaArray[] = {
56 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
57 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
58 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
59 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
60 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
61 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
62 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
63 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
64 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
65 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
66 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
67 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
68 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
69};
70
James Smart2e0fef82007-06-17 19:56:36 -050071static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010072static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040073static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040074static int lpfc_fcf_inuse(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050075
James Smartc01f3202006-08-18 17:47:08 -040076void
77lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050078{
James Smartc01f3202006-08-18 17:47:08 -040079 struct lpfc_rport_data *rdata;
80 struct lpfc_nodelist * ndlp;
81 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050082
James Smartc01f3202006-08-18 17:47:08 -040083 rdata = rport->dd_data;
84 ndlp = rdata->pnode;
85
James Smart58da1ff2008-04-07 10:15:56 -040086 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040087 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
88 printk(KERN_ERR "Cannot find remote node"
89 " to terminate I/O Data x%x\n",
90 rport->port_id);
dea31012005-04-17 16:05:31 -050091 return;
92 }
93
James Smarta257bf92009-04-06 18:48:10 -040094 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050095
James Smart858c9f62007-06-17 19:56:39 -050096 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
97 "rport terminate: sid:x%x did:x%x flg:x%x",
98 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
99
James Smartc01f3202006-08-18 17:47:08 -0400100 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -0400101 lpfc_sli_abort_iocb(ndlp->vport,
James Smart895427b2017-02-12 13:52:30 -0800102 &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400103 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -0400104 }
James Smartc01f3202006-08-18 17:47:08 -0400105}
106
107/*
108 * This function will be called when dev_loss_tmo fire.
109 */
110void
111lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
112{
113 struct lpfc_rport_data *rdata;
114 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500115 struct lpfc_vport *vport;
James Smart466e8402015-05-21 13:55:28 -0400116 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500117 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500118 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400119 int put_node;
120 int put_rport;
James Smart894bb172019-08-14 16:56:52 -0700121 unsigned long iflags;
James Smartc01f3202006-08-18 17:47:08 -0400122
123 rdata = rport->dd_data;
124 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400125 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400126 return;
James Smartc01f3202006-08-18 17:47:08 -0400127
James Smart858c9f62007-06-17 19:56:39 -0500128 vport = ndlp->vport;
129 phba = vport->phba;
130
131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
132 "rport devlosscb: sid:x%x did:x%x flg:x%x",
133 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
134
James Smart34f5ad82012-08-03 12:35:03 -0400135 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
136 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
137 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
138
James Smarta8adb832007-10-27 13:37:53 -0400139 /* Don't defer this if we are in the process of deleting the vport
140 * or unloading the driver. The unload will cleanup the node
141 * appropriately we just need to cleanup the ndlp rport info here.
142 */
143 if (vport->load_flag & FC_UNLOADING) {
144 put_node = rdata->pnode != NULL;
145 put_rport = ndlp->rport != NULL;
146 rdata->pnode = NULL;
147 ndlp->rport = NULL;
148 if (put_node)
149 lpfc_nlp_put(ndlp);
150 if (put_rport)
151 put_device(&rport->dev);
152 return;
153 }
154
155 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
156 return;
157
James Smart466e8402015-05-21 13:55:28 -0400158 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
159 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
160 "6789 rport name %llx != node port name %llx",
161 rport->port_name,
162 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400163
James Smart858c9f62007-06-17 19:56:39 -0500164 evtp = &ndlp->dev_loss_evt;
165
James Smart466e8402015-05-21 13:55:28 -0400166 if (!list_empty(&evtp->evt_listp)) {
167 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
168 "6790 rport name %llx dev_loss_evt pending",
169 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500170 return;
James Smart466e8402015-05-21 13:55:28 -0400171 }
James Smart858c9f62007-06-17 19:56:39 -0500172
James Smart466e8402015-05-21 13:55:28 -0400173 shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -0700174 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400175 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700176 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smarta62a4352013-04-17 20:18:19 -0400177
James Smartfa4066b2008-01-11 01:53:27 -0500178 /* We need to hold the node by incrementing the reference
179 * count until this queued work is done
180 */
James Smart466e8402015-05-21 13:55:28 -0400181 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
182
James Smart894bb172019-08-14 16:56:52 -0700183 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart5e9d9b82008-06-14 22:52:53 -0400184 if (evtp->evt_arg1) {
185 evtp->evt = LPFC_EVT_DEV_LOSS;
186 list_add_tail(&evtp->evt_listp, &phba->work_list);
187 lpfc_worker_wake_up(phba);
188 }
James Smart894bb172019-08-14 16:56:52 -0700189 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart858c9f62007-06-17 19:56:39 -0500190
James Smart858c9f62007-06-17 19:56:39 -0500191 return;
192}
193
James Smarta93ff372010-10-22 11:06:08 -0400194/**
195 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
196 * @ndlp: Pointer to remote node object.
197 *
198 * This function is called from the worker thread when devloss timeout timer
199 * expires. For SLI4 host, this routine shall return 1 when at lease one
200 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
201 * routine shall return 0 when there is no remote node is still in use of FCF
202 * when devloss timeout happened to this @ndlp.
203 **/
204static int
James Smart858c9f62007-06-17 19:56:39 -0500205lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
206{
207 struct lpfc_rport_data *rdata;
208 struct fc_rport *rport;
209 struct lpfc_vport *vport;
210 struct lpfc_hba *phba;
James Smart466e8402015-05-21 13:55:28 -0400211 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500212 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400213 int put_node;
James Smart858c9f62007-06-17 19:56:39 -0500214 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400215 int fcf_inuse = 0;
James Smart894bb172019-08-14 16:56:52 -0700216 unsigned long iflags;
James Smart858c9f62007-06-17 19:56:39 -0500217
218 rport = ndlp->rport;
James Smart858c9f62007-06-17 19:56:39 -0500219 vport = ndlp->vport;
James Smart466e8402015-05-21 13:55:28 -0400220 shost = lpfc_shost_from_vport(vport);
221
James Smart894bb172019-08-14 16:56:52 -0700222 spin_lock_irqsave(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400223 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
James Smart894bb172019-08-14 16:56:52 -0700224 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart466e8402015-05-21 13:55:28 -0400225
226 if (!rport)
227 return fcf_inuse;
228
229 name = (uint8_t *) &ndlp->nlp_portname;
James Smart858c9f62007-06-17 19:56:39 -0500230 phba = vport->phba;
231
James Smarta93ff372010-10-22 11:06:08 -0400232 if (phba->sli_rev == LPFC_SLI_REV4)
233 fcf_inuse = lpfc_fcf_inuse(phba);
234
James Smart858c9f62007-06-17 19:56:39 -0500235 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
236 "rport devlosstmo:did:x%x type:x%x id:x%x",
237 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
238
James Smart34f5ad82012-08-03 12:35:03 -0400239 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
240 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
241 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
242
James Smart466e8402015-05-21 13:55:28 -0400243 /*
244 * lpfc_nlp_remove if reached with dangling rport drops the
245 * reference. To make sure that does not happen clear rport
246 * pointer in ndlp before lpfc_nlp_put.
247 */
248 rdata = rport->dd_data;
249
James Smarta8adb832007-10-27 13:37:53 -0400250 /* Don't defer this if we are in the process of deleting the vport
251 * or unloading the driver. The unload will cleanup the node
252 * appropriately we just need to cleanup the ndlp rport info here.
253 */
254 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500255 if (ndlp->nlp_sid != NLP_NO_SID) {
256 /* flush the target */
257 lpfc_sli_abort_iocb(vport,
James Smart895427b2017-02-12 13:52:30 -0800258 &phba->sli.sli3_ring[LPFC_FCP_RING],
259 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smart09372822008-01-11 01:52:54 -0500260 }
James Smarta8adb832007-10-27 13:37:53 -0400261 put_node = rdata->pnode != NULL;
James Smarta8adb832007-10-27 13:37:53 -0400262 rdata->pnode = NULL;
263 ndlp->rport = NULL;
264 if (put_node)
265 lpfc_nlp_put(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400266 put_device(&rport->dev);
267
James Smarta93ff372010-10-22 11:06:08 -0400268 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400269 }
270
James Smartd7c255b2008-08-24 21:50:00 -0400271 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
272 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
273 "0284 Devloss timeout Ignored on "
274 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
275 "NPort x%x\n",
276 *name, *(name+1), *(name+2), *(name+3),
277 *(name+4), *(name+5), *(name+6), *(name+7),
278 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400279 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400280 }
James Smart858c9f62007-06-17 19:56:39 -0500281
James Smart466e8402015-05-21 13:55:28 -0400282 put_node = rdata->pnode != NULL;
283 rdata->pnode = NULL;
284 ndlp->rport = NULL;
285 if (put_node)
286 lpfc_nlp_put(ndlp);
287 put_device(&rport->dev);
288
289 if (ndlp->nlp_type & NLP_FABRIC)
James Smarta93ff372010-10-22 11:06:08 -0400290 return fcf_inuse;
James Smart82085712007-04-25 09:52:41 -0400291
dea31012005-04-17 16:05:31 -0500292 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400293 warn_on = 1;
James Smart895427b2017-02-12 13:52:30 -0800294 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400295 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500296 }
James Smartc01f3202006-08-18 17:47:08 -0400297
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400298 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400299 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
300 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400301 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
302 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400303 *name, *(name+1), *(name+2), *(name+3),
304 *(name+4), *(name+5), *(name+6), *(name+7),
305 ndlp->nlp_DID, ndlp->nlp_flag,
306 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400307 } else {
James Smarte8b62012007-08-02 11:10:09 -0400308 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
309 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400310 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
311 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400312 *name, *(name+1), *(name+2), *(name+3),
313 *(name+4), *(name+5), *(name+6), *(name+7),
314 ndlp->nlp_DID, ndlp->nlp_flag,
315 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400316 }
317
James Smart2ade92a2017-03-04 09:30:38 -0800318 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400319 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400320 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400321 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
322 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500323 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400324
James Smarta93ff372010-10-22 11:06:08 -0400325 return fcf_inuse;
326}
327
328/**
329 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
330 * @phba: Pointer to hba context object.
331 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
332 * @nlp_did: remote node identifer with devloss timeout.
333 *
334 * This function is called from the worker thread after invoking devloss
335 * timeout handler and releasing the reference count for the ndlp with
336 * which the devloss timeout was handled for SLI4 host. For the devloss
337 * timeout of the last remote node which had been in use of FCF, when this
338 * routine is invoked, it shall be guaranteed that none of the remote are
339 * in-use of FCF. When devloss timeout to the last remote using the FCF,
340 * if the FIP engine is neither in FCF table scan process nor roundrobin
341 * failover process, the in-use FCF shall be unregistered. If the FIP
342 * engine is in FCF discovery process, the devloss timeout state shall
343 * be set for either the FCF table scan process or roundrobin failover
344 * process to unregister the in-use FCF.
345 **/
346static void
347lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
348 uint32_t nlp_did)
349{
350 /* If devloss timeout happened to a remote node when FCF had no
351 * longer been in-use, do nothing.
352 */
353 if (!fcf_inuse)
354 return;
355
356 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
357 spin_lock_irq(&phba->hbalock);
358 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
359 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
360 spin_unlock_irq(&phba->hbalock);
361 return;
362 }
363 phba->hba_flag |= HBA_DEVLOSS_TMO;
364 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
365 "2847 Last remote node (x%x) using "
366 "FCF devloss tmo\n", nlp_did);
367 }
368 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
369 spin_unlock_irq(&phba->hbalock);
370 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
371 "2868 Devloss tmo to FCF rediscovery "
372 "in progress\n");
373 return;
374 }
375 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
376 spin_unlock_irq(&phba->hbalock);
377 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
378 "2869 Devloss tmo to idle FIP engine, "
379 "unreg in-use FCF and rescan.\n");
380 /* Unregister in-use FCF and rescan */
381 lpfc_unregister_fcf_rescan(phba);
382 return;
383 }
384 spin_unlock_irq(&phba->hbalock);
385 if (phba->hba_flag & FCF_TS_INPROG)
386 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
387 "2870 FCF table scan in progress\n");
388 if (phba->hba_flag & FCF_RR_INPROG)
389 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
390 "2871 FLOGI roundrobin FCF failover "
391 "in progress\n");
392 }
James Smart6fb120a2009-05-22 14:52:59 -0400393 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500394}
James Smartc01f3202006-08-18 17:47:08 -0400395
James Smartea2151b2008-09-07 11:52:10 -0400396/**
James Smart3621a712009-04-06 18:47:14 -0400397 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400398 * @phba: Pointer to hba context object.
399 *
400 * This function is called from the functions which need to post
401 * events from interrupt context. This function allocates data
402 * structure required for posting event. It also keeps track of
403 * number of events pending and prevent event storm when there are
404 * too many events.
405 **/
406struct lpfc_fast_path_event *
407lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
408 struct lpfc_fast_path_event *ret;
409
410 /* If there are lot of fast event do not exhaust memory due to this */
411 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
412 return NULL;
413
414 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
415 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400416 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400417 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400418 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
419 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
420 }
James Smartea2151b2008-09-07 11:52:10 -0400421 return ret;
422}
423
424/**
James Smart3621a712009-04-06 18:47:14 -0400425 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400426 * @phba: Pointer to hba context object.
427 * @evt: Event object which need to be freed.
428 *
429 * This function frees the data structure required for posting
430 * events.
431 **/
432void
433lpfc_free_fast_evt(struct lpfc_hba *phba,
434 struct lpfc_fast_path_event *evt) {
435
436 atomic_dec(&phba->fast_event_count);
437 kfree(evt);
438}
439
440/**
James Smart3621a712009-04-06 18:47:14 -0400441 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400442 * @phba: Pointer to hba context object.
443 * @evtp: Event data structure.
444 *
445 * This function is called from worker thread, when the interrupt
446 * context need to post an event. This function posts the event
447 * to fc transport netlink interface.
448 **/
449static void
450lpfc_send_fastpath_evt(struct lpfc_hba *phba,
451 struct lpfc_work_evt *evtp)
452{
453 unsigned long evt_category, evt_sub_category;
454 struct lpfc_fast_path_event *fast_evt_data;
455 char *evt_data;
456 uint32_t evt_data_size;
457 struct Scsi_Host *shost;
458
459 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
460 work_evt);
461
462 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
463 evt_sub_category = (unsigned long) fast_evt_data->un.
464 fabric_evt.subcategory;
465 shost = lpfc_shost_from_vport(fast_evt_data->vport);
466 if (evt_category == FC_REG_FABRIC_EVENT) {
467 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
468 evt_data = (char *) &fast_evt_data->un.read_check_error;
469 evt_data_size = sizeof(fast_evt_data->un.
470 read_check_error);
471 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500472 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400473 evt_data = (char *) &fast_evt_data->un.fabric_evt;
474 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
475 } else {
476 lpfc_free_fast_evt(phba, fast_evt_data);
477 return;
478 }
479 } else if (evt_category == FC_REG_SCSI_EVENT) {
480 switch (evt_sub_category) {
481 case LPFC_EVENT_QFULL:
482 case LPFC_EVENT_DEVBSY:
483 evt_data = (char *) &fast_evt_data->un.scsi_evt;
484 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
485 break;
486 case LPFC_EVENT_CHECK_COND:
487 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
488 evt_data_size = sizeof(fast_evt_data->un.
489 check_cond_evt);
490 break;
491 case LPFC_EVENT_VARQUEDEPTH:
492 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
493 evt_data_size = sizeof(fast_evt_data->un.
494 queue_depth_evt);
495 break;
496 default:
497 lpfc_free_fast_evt(phba, fast_evt_data);
498 return;
499 }
500 } else {
501 lpfc_free_fast_evt(phba, fast_evt_data);
502 return;
503 }
504
James Smart895427b2017-02-12 13:52:30 -0800505 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
506 fc_host_post_vendor_event(shost,
507 fc_get_event_number(),
508 evt_data_size,
509 evt_data,
510 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400511
512 lpfc_free_fast_evt(phba, fast_evt_data);
513 return;
514}
515
dea31012005-04-17 16:05:31 -0500516static void
James Smart2e0fef82007-06-17 19:56:36 -0500517lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500518{
519 struct lpfc_work_evt *evtp = NULL;
520 struct lpfc_nodelist *ndlp;
521 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400522 int fcf_inuse;
523 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500524
James Smart2e0fef82007-06-17 19:56:36 -0500525 spin_lock_irq(&phba->hbalock);
526 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500527 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
528 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500529 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500530 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500531 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500532 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500533 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500534 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500535 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500536 /* decrement the node reference count held
537 * for this queued work
538 */
539 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500540 break;
James Smart858c9f62007-06-17 19:56:39 -0500541 case LPFC_EVT_DEV_LOSS:
542 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400543 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500544 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500545 /* decrement the node reference count held for
546 * this queued work
547 */
James Smarta93ff372010-10-22 11:06:08 -0400548 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500549 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400550 if (phba->sli_rev == LPFC_SLI_REV4)
551 lpfc_sli4_post_dev_loss_tmo_handler(phba,
552 fcf_inuse,
553 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500554 break;
dea31012005-04-17 16:05:31 -0500555 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500556 if (phba->link_state < LPFC_LINK_DOWN)
557 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500558 else
James Smart2e0fef82007-06-17 19:56:36 -0500559 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500560 complete((struct completion *)(evtp->evt_arg2));
561 break;
James Smart46fa3112007-04-25 09:51:45 -0400562 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500563 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400564 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400565 *(int *)(evtp->evt_arg1) = 0;
566 complete((struct completion *)(evtp->evt_arg2));
567 break;
568 case LPFC_EVT_OFFLINE:
569 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500570 lpfc_sli_brdrestart(phba);
571 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400572 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
573 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500574 complete((struct completion *)(evtp->evt_arg2));
575 break;
576 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400577 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500578 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500579 lpfc_sli_brdreset(phba);
580 lpfc_hba_down_post(phba);
581 *(int *)(evtp->evt_arg1) =
582 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400583 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500584 complete((struct completion *)(evtp->evt_arg2));
585 break;
586 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400587 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500588 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500589 = (phba->pport->stopped)
590 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400591 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500592 complete((struct completion *)(evtp->evt_arg2));
593 break;
James Smartea2151b2008-09-07 11:52:10 -0400594 case LPFC_EVT_FASTPATH_MGMT_EVT:
595 lpfc_send_fastpath_evt(phba, evtp);
596 free_evt = 0;
597 break;
James Smart78730cf2010-04-06 15:06:30 -0400598 case LPFC_EVT_RESET_HBA:
599 if (!(phba->pport->load_flag & FC_UNLOADING))
600 lpfc_reset_hba(phba);
601 break;
dea31012005-04-17 16:05:31 -0500602 }
603 if (free_evt)
604 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500605 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500606 }
James Smart2e0fef82007-06-17 19:56:36 -0500607 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500608
609}
610
James Smart311464e2007-08-02 11:10:37 -0400611static void
James Smart2e0fef82007-06-17 19:56:36 -0500612lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500613{
614 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500615 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400616 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400617 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400618 int i;
dea31012005-04-17 16:05:31 -0500619
James Smart2e0fef82007-06-17 19:56:36 -0500620 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500621 ha_copy = phba->work_ha;
622 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500623 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500624
James Smartda0436e2009-05-22 14:51:39 -0400625 /* First, try to post the next mailbox command to SLI4 device */
626 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
627 lpfc_sli4_post_async_mbox(phba);
628
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500629 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400630 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500631 lpfc_handle_eratt(phba);
632
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500633 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500634 lpfc_sli_handle_mb_event(phba);
635
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500636 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500637 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400638
James Smartda0436e2009-05-22 14:51:39 -0400639 /* Process SLI4 events */
640 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500641 if (phba->hba_flag & HBA_RRQ_ACTIVE)
642 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400643 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
644 lpfc_sli4_els_xri_abort_event_proc(phba);
645 if (phba->hba_flag & ASYNC_EVENT)
646 lpfc_sli4_async_event_proc(phba);
647 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
648 spin_lock_irq(&phba->hbalock);
649 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
650 spin_unlock_irq(&phba->hbalock);
651 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
652 }
James Smartecfd03c2010-02-12 14:41:27 -0500653 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
654 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400655 }
656
James Smart549e55c2007-08-02 11:09:51 -0400657 vports = lpfc_create_vport_work_array(phba);
658 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400659 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400660 /*
661 * We could have no vports in array if unloading, so if
662 * this happens then just use the pport
663 */
664 if (vports[i] == NULL && i == 0)
665 vport = phba->pport;
666 else
667 vport = vports[i];
668 if (vport == NULL)
669 break;
James Smart58da1ff2008-04-07 10:15:56 -0400670 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400671 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400672 vport->work_port_events &= ~work_port_events;
673 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400674 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400675 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400676 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400677 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400678 if (work_port_events & WORKER_HB_TMO)
679 lpfc_hb_timeout_handler(phba);
680 if (work_port_events & WORKER_MBOX_TMO)
681 lpfc_mbox_timeout_handler(phba);
682 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
683 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400684 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
685 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500686 if (work_port_events & WORKER_DELAYED_DISC_TMO)
687 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500688 }
James Smart09372822008-01-11 01:52:54 -0500689 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500690
James Smart895427b2017-02-12 13:52:30 -0800691 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500692 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
693 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700694 if (pring && (status & HA_RXMASK ||
695 pring->flag & LPFC_DEFERRED_RING_EVENT ||
696 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400697 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500698 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800699 /* Preserve legacy behavior. */
700 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
701 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500702 } else {
James Smartae9e28f2017-05-15 15:20:51 -0700703 if (phba->link_state >= LPFC_LINK_UP ||
704 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500705 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
706 lpfc_sli_handle_slow_ring_event(phba, pring,
707 (status &
708 HA_RXMASK));
709 }
James Smart858c9f62007-06-17 19:56:39 -0500710 }
James Smartdc19e3b2018-05-24 21:08:57 -0700711 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400712 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500713 /*
714 * Turn on Ring interrupts
715 */
James Smart3772a992009-05-22 14:50:54 -0400716 if (phba->sli_rev <= LPFC_SLI_REV3) {
717 spin_lock_irq(&phba->hbalock);
718 control = readl(phba->HCregaddr);
719 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
720 lpfc_debugfs_slow_ring_trc(phba,
721 "WRK Enable ring: cntl:x%x hacopy:x%x",
722 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400723
James Smart3772a992009-05-22 14:50:54 -0400724 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
725 writel(control, phba->HCregaddr);
726 readl(phba->HCregaddr); /* flush */
727 } else {
728 lpfc_debugfs_slow_ring_trc(phba,
729 "WRK Ring ok: cntl:x%x hacopy:x%x",
730 control, ha_copy, 0);
731 }
732 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500733 }
734 }
James Smart2e0fef82007-06-17 19:56:36 -0500735 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500736}
737
dea31012005-04-17 16:05:31 -0500738int
739lpfc_do_work(void *p)
740{
741 struct lpfc_hba *phba = p;
742 int rc;
dea31012005-04-17 16:05:31 -0500743
Dongsheng Yang8698a742014-03-11 18:09:12 +0800744 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400745 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400746 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500747
James Smart3a55b532008-12-04 22:38:54 -0500748 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400749 /* wait and check worker queue activities */
750 rc = wait_event_interruptible(phba->work_waitq,
751 (test_and_clear_bit(LPFC_DATA_READY,
752 &phba->data_flags)
753 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500754 /* Signal wakeup shall terminate the worker thread */
755 if (rc) {
756 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
757 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500758 break;
James Smart3a55b532008-12-04 22:38:54 -0500759 }
dea31012005-04-17 16:05:31 -0500760
James Smart5e9d9b82008-06-14 22:52:53 -0400761 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500762 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500763 }
James Smart3a55b532008-12-04 22:38:54 -0500764 phba->worker_thread = NULL;
765 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
766 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500767 return 0;
768}
769
770/*
771 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300772 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500773 * embedding it in the IOCB.
774 */
775int
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500777 uint32_t evt)
778{
779 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500780 unsigned long flags;
dea31012005-04-17 16:05:31 -0500781
782 /*
783 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
784 * be queued to worker thread for processing
785 */
James Smart92d7f7b2007-06-17 19:56:38 -0500786 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500787 if (!evtp)
788 return 0;
789
790 evtp->evt_arg1 = arg1;
791 evtp->evt_arg2 = arg2;
792 evtp->evt = evt;
793
James Smarted957682007-06-17 19:56:37 -0500794 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400795 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500796 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500797
James Smart5e9d9b82008-06-14 22:52:53 -0400798 lpfc_worker_wake_up(phba);
799
dea31012005-04-17 16:05:31 -0500800 return 1;
801}
802
James Smart92d7f7b2007-06-17 19:56:38 -0500803void
804lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
805{
James Smart09372822008-01-11 01:52:54 -0500806 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500807 struct lpfc_hba *phba = vport->phba;
808 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500809
810 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500811 if (!NLP_CHK_NODE_ACT(ndlp))
812 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500813 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
814 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400815 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
816 ((vport->port_type == LPFC_NPIV_PORT) &&
817 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500818 lpfc_unreg_rpi(vport, ndlp);
819
820 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400821 if ((phba->sli_rev < LPFC_SLI_REV4) &&
822 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500823 continue;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -0400824 lpfc_disc_state_machine(vport, ndlp, NULL,
825 remove
826 ? NLP_EVT_DEVICE_RM
827 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -0500828 }
829 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400830 if (phba->sli_rev == LPFC_SLI_REV4)
831 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500832 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500833 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500834 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500835 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500836 }
837}
838
James Smart87af33f2007-10-27 13:37:43 -0400839void
James Smart98c9ea52007-10-27 13:37:33 -0400840lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500841{
James Smart695a8142010-01-26 23:08:03 -0500842 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
843
James Smart45ed1192009-10-02 15:17:02 -0400844 /* Cleanup any outstanding received buffers */
845 lpfc_cleanup_rcv_buffers(vport);
846
James Smart92d7f7b2007-06-17 19:56:38 -0500847 /* Cleanup any outstanding RSCN activity */
848 lpfc_els_flush_rscn(vport);
849
850 /* Cleanup any outstanding ELS commands */
851 lpfc_els_flush_cmd(vport);
852
853 lpfc_cleanup_rpis(vport, 0);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* Turn off discovery timer if its running */
856 lpfc_can_disctmo(vport);
857}
858
James Smart3772a992009-05-22 14:50:54 -0400859void
James Smart98c9ea52007-10-27 13:37:33 -0400860lpfc_linkdown_port(struct lpfc_vport *vport)
861{
862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
863
James Smartf6e84792019-01-28 11:14:38 -0800864 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -0800865 fc_host_post_event(shost, fc_get_event_number(),
866 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400867
868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
869 "Link Down: state:x%x rtry:x%x flg:x%x",
870 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
871
872 lpfc_port_link_failure(vport);
873
James Smart92494142011-02-16 12:39:44 -0500874 /* Stop delayed Nport discovery */
875 spin_lock_irq(shost->host_lock);
876 vport->fc_flag &= ~FC_DISC_DELAYED;
877 spin_unlock_irq(shost->host_lock);
878 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400879}
880
dea31012005-04-17 16:05:31 -0500881int
James Smart685f0bf2007-04-25 09:53:08 -0400882lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500883{
James Smart2e0fef82007-06-17 19:56:36 -0500884 struct lpfc_vport *vport = phba->pport;
885 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400886 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400887 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400888 int i;
dea31012005-04-17 16:05:31 -0500889
James Smart19193ff2019-03-12 16:30:25 -0700890 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500891 return 0;
James Smart19193ff2019-03-12 16:30:25 -0700892
James Smartaacc20e2009-12-21 17:02:51 -0500893 /* Block all SCSI stack I/Os */
894 lpfc_scsi_dev_block(phba);
895
James Smart0a9e9682018-11-29 16:09:36 -0800896 phba->defer_flogi_acc_flag = false;
897
James Smart2e0fef82007-06-17 19:56:36 -0500898 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500899 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500900 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500901 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500902 phba->link_state = LPFC_LINK_DOWN;
James Smart2977a092018-12-13 15:17:52 -0800903 if (phba->sli4_hba.conf_trunk) {
904 phba->trunk_link.link0.state = 0;
905 phba->trunk_link.link1.state = 0;
906 phba->trunk_link.link2.state = 0;
907 phba->trunk_link.link3.state = 0;
908 }
James Smart72100cc2010-02-12 14:43:01 -0500909 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500910 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500911 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500912 }
James Smart549e55c2007-08-02 11:09:51 -0400913 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800914 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400915 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400916 /* Issue a LINK DOWN event to all nodes */
917 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800918
919 vports[i]->fc_myDID = 0;
920
James Smartf6e84792019-01-28 11:14:38 -0800921 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
922 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800923 if (phba->nvmet_support)
924 lpfc_nvmet_update_targetport(phba);
925 else
James Smart8c258642017-02-12 13:52:36 -0800926 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800927 }
James Smart549e55c2007-08-02 11:09:51 -0400928 }
James Smart895427b2017-02-12 13:52:30 -0800929 }
James Smart09372822008-01-11 01:52:54 -0500930 lpfc_destroy_vport_work_array(phba, vports);
James Smartc95a3b42019-03-12 16:30:07 -0700931
932 /* Clean up any SLI3 firmware default rpi's */
933 if (phba->sli_rev > LPFC_SLI_REV3)
934 goto skip_unreg_did;
935
James Smart2e0fef82007-06-17 19:56:36 -0500936 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
937 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400938 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500939 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500940 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400941 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500942 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500943 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500944 }
945 }
946
James Smartc95a3b42019-03-12 16:30:07 -0700947 skip_unreg_did:
dea31012005-04-17 16:05:31 -0500948 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500949 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500950 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
951 if (mb) {
dea31012005-04-17 16:05:31 -0500952 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500953 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500954 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400955 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500956 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500957 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500958 }
959 }
James Smart2e0fef82007-06-17 19:56:36 -0500960 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500961 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -0700962 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500963 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500964 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500965 return 0;
dea31012005-04-17 16:05:31 -0500966}
967
James Smart92d7f7b2007-06-17 19:56:38 -0500968static void
969lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500970{
James Smart92d7f7b2007-06-17 19:56:38 -0500971 struct lpfc_nodelist *ndlp;
972
973 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -0800974 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smarte47c9092008-02-08 18:49:26 -0500975 if (!NLP_CHK_NODE_ACT(ndlp))
976 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500977 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
978 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500979 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500980 /* On Linkup its safe to clean up the ndlp
981 * from Fabric connections.
982 */
James Smart92d7f7b2007-06-17 19:56:38 -0500983 if (ndlp->nlp_DID != Fabric_DID)
984 lpfc_unreg_rpi(vport, ndlp);
985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
986 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500987 /* Fail outstanding IO now since device is
988 * marked for PLOGI.
989 */
James Smart92d7f7b2007-06-17 19:56:38 -0500990 lpfc_unreg_rpi(vport, ndlp);
991 }
992 }
993}
994
995static void
996lpfc_linkup_port(struct lpfc_vport *vport)
997{
998 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500999 struct lpfc_hba *phba = vport->phba;
1000
1001 if ((vport->load_flag & FC_UNLOADING) != 0)
1002 return;
1003
James Smart858c9f62007-06-17 19:56:39 -05001004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1005 "Link Up: top:x%x speed:x%x flg:x%x",
1006 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1007
James Smart92d7f7b2007-06-17 19:56:38 -05001008 /* If NPIV is not enabled, only bring the physical port up */
1009 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1010 (vport != phba->pport))
1011 return;
dea31012005-04-17 16:05:31 -05001012
James Smartf6e84792019-01-28 11:14:38 -08001013 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001014 fc_host_post_event(shost, fc_get_event_number(),
1015 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001016
James Smart2e0fef82007-06-17 19:56:36 -05001017 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001018 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1019 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1020 vport->fc_flag |= FC_NDISC_ACTIVE;
1021 vport->fc_ns_retry = 0;
1022 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001023
James Smart92d7f7b2007-06-17 19:56:38 -05001024 if (vport->fc_flag & FC_LBIT)
1025 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001026
James Smart92d7f7b2007-06-17 19:56:38 -05001027}
1028
1029static int
1030lpfc_linkup(struct lpfc_hba *phba)
1031{
James Smart549e55c2007-08-02 11:09:51 -04001032 struct lpfc_vport **vports;
1033 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001034 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001035
1036 phba->link_state = LPFC_LINK_UP;
1037
1038 /* Unblock fabric iocbs if they are blocked */
1039 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1040 del_timer_sync(&phba->fabric_block_timer);
1041
James Smart549e55c2007-08-02 11:09:51 -04001042 vports = lpfc_create_vport_work_array(phba);
1043 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001044 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001045 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001046 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001047
James Smartd496b9a2018-10-23 13:41:08 -07001048 /* Clear the pport flogi counter in case the link down was
1049 * absorbed without an ACQE. No lock here - in worker thread
1050 * and discovery is synchronized.
1051 */
1052 spin_lock_irq(shost->host_lock);
1053 phba->pport->rcv_flogi_cnt = 0;
1054 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001055
1056 /* reinitialize initial FLOGI flag */
1057 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1058 phba->defer_flogi_acc_flag = false;
1059
dea31012005-04-17 16:05:31 -05001060 return 0;
1061}
1062
1063/*
1064 * This routine handles processing a CLEAR_LA mailbox
1065 * command upon completion. It is setup in the LPFC_MBOXQ
1066 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001067 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001068 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001069static void
James Smart2e0fef82007-06-17 19:56:36 -05001070lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001071{
James Smart2e0fef82007-06-17 19:56:36 -05001072 struct lpfc_vport *vport = pmb->vport;
1073 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1074 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001075 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001076 uint32_t control;
1077
dea31012005-04-17 16:05:31 -05001078 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001079 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1080 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001081
1082 /* Check for error */
1083 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001084 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001085 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1086 "0320 CLEAR_LA mbxStatus error x%x hba "
1087 "state x%x\n",
1088 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001089 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001090 goto out;
1091 }
1092
James Smart92d7f7b2007-06-17 19:56:38 -05001093 if (vport->port_type == LPFC_PHYSICAL_PORT)
1094 phba->link_state = LPFC_HBA_READY;
1095
1096 spin_lock_irq(&phba->hbalock);
1097 psli->sli_flag |= LPFC_PROCESS_LA;
1098 control = readl(phba->HCregaddr);
1099 control |= HC_LAINT_ENA;
1100 writel(control, phba->HCregaddr);
1101 readl(phba->HCregaddr); /* flush */
1102 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001103 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001104 return;
dea31012005-04-17 16:05:31 -05001105
dea31012005-04-17 16:05:31 -05001106out:
1107 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001108 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1109 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001110 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001111
James Smart2e0fef82007-06-17 19:56:36 -05001112 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001113 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001114 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001115
James Smart2e0fef82007-06-17 19:56:36 -05001116 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001117
1118 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001119
1120 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001121 psli->sli_flag |= LPFC_PROCESS_LA;
1122 control = readl(phba->HCregaddr);
1123 control |= HC_LAINT_ENA;
1124 writel(control, phba->HCregaddr);
1125 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001126 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001127
1128 return;
1129}
1130
James Smart2e0fef82007-06-17 19:56:36 -05001131
James Smartd6de08c2015-12-16 18:11:53 -05001132void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001133lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001134{
James Smart2e0fef82007-06-17 19:56:36 -05001135 struct lpfc_vport *vport = pmb->vport;
James Smart44fd7fe2017-08-23 16:55:47 -07001136 uint8_t bbscn = 0;
dea31012005-04-17 16:05:31 -05001137
James Smart04c68492009-05-22 14:52:52 -04001138 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001139 goto out;
dea31012005-04-17 16:05:31 -05001140
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001141 mempool_free(pmb, phba->mbox_mem_pool);
1142
James Smart1b511972011-12-13 13:23:09 -05001143 /* don't perform discovery for SLI4 loopback diagnostic test */
1144 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1145 !(phba->hba_flag & HBA_FCOE_MODE) &&
1146 (phba->link_flag & LS_LOOPBACK_MODE))
1147 return;
1148
James Smart76a95d72010-11-20 23:11:48 -05001149 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001150 vport->fc_flag & FC_PUBLIC_LOOP &&
1151 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001152 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001153 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001154 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1155 */
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001157 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001158 }
dea31012005-04-17 16:05:31 -05001159
James Smart2e0fef82007-06-17 19:56:36 -05001160 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001161 * LPFC_FLOGI while waiting for FLOGI cmpl
1162 */
James Smart44fd7fe2017-08-23 16:55:47 -07001163 if (vport->port_state != LPFC_FLOGI) {
1164 if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
1165 bbscn = bf_get(lpfc_bbscn_def,
1166 &phba->sli4_hba.bbscn_params);
1167 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
1168 vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4);
1169 }
James Smart92d7f7b2007-06-17 19:56:38 -05001170 lpfc_initial_flogi(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001171 } else if (vport->fc_flag & FC_PT2PT) {
James Smartd6de08c2015-12-16 18:11:53 -05001172 lpfc_disc_start(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001173 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001174 return;
dea31012005-04-17 16:05:31 -05001175
1176out:
James Smarte8b62012007-08-02 11:10:09 -04001177 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1178 "0306 CONFIG_LINK mbxStatus error x%x "
1179 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001180 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001181 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001182
1183 lpfc_linkdown(phba);
1184
James Smarte8b62012007-08-02 11:10:09 -04001185 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1186 "0200 CONFIG_LINK bad hba state x%x\n",
1187 vport->port_state);
dea31012005-04-17 16:05:31 -05001188
James Smart92d7f7b2007-06-17 19:56:38 -05001189 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001190 return;
1191}
1192
James Smart7d791df2011-07-22 18:37:52 -04001193/**
1194 * lpfc_sli4_clear_fcf_rr_bmask
1195 * @phba pointer to the struct lpfc_hba for this port.
1196 * This fucnction resets the round robin bit mask and clears the
1197 * fcf priority list. The list deletions are done while holding the
1198 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1199 * from the lpfc_fcf_pri record.
1200 **/
1201void
1202lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1203{
1204 struct lpfc_fcf_pri *fcf_pri;
1205 struct lpfc_fcf_pri *next_fcf_pri;
1206 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1207 spin_lock_irq(&phba->hbalock);
1208 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1209 &phba->fcf.fcf_pri_list, list) {
1210 list_del_init(&fcf_pri->list);
1211 fcf_pri->fcf_rec.flag = 0;
1212 }
1213 spin_unlock_irq(&phba->hbalock);
1214}
dea31012005-04-17 16:05:31 -05001215static void
James Smart6fb120a2009-05-22 14:52:59 -04001216lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1217{
1218 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001219
1220 if (mboxq->u.mb.mbxStatus) {
1221 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1222 "2017 REG_FCFI mbxStatus error x%x "
1223 "HBA state x%x\n",
1224 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001225 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001226 }
1227
1228 /* Start FCoE discovery by sending a FLOGI. */
1229 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1230 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001231 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001232 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001233 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001234
James Smart32b97932009-07-19 10:01:21 -04001235 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001236 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1237 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001238 goto fail_out;
1239
1240 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001241 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001242 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001243 phba->hba_flag &= ~FCF_TS_INPROG;
1244 if (vport->port_state != LPFC_FLOGI) {
1245 phba->hba_flag |= FCF_RR_INPROG;
1246 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001247 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001248 goto out;
1249 }
1250 spin_unlock_irq(&phba->hbalock);
1251 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001252
James Smarta93ff372010-10-22 11:06:08 -04001253fail_out:
1254 spin_lock_irq(&phba->hbalock);
1255 phba->hba_flag &= ~FCF_RR_INPROG;
1256 spin_unlock_irq(&phba->hbalock);
1257out:
James Smart6fb120a2009-05-22 14:52:59 -04001258 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001259}
1260
1261/**
1262 * lpfc_fab_name_match - Check if the fcf fabric name match.
1263 * @fab_name: pointer to fabric name.
1264 * @new_fcf_record: pointer to fcf record.
1265 *
1266 * This routine compare the fcf record's fabric name with provided
1267 * fabric name. If the fabric name are identical this function
1268 * returns 1 else return 0.
1269 **/
1270static uint32_t
1271lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1272{
James Smartecfd03c2010-02-12 14:41:27 -05001273 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001274 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001275 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1276 return 0;
1277 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1278 return 0;
1279 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1280 return 0;
1281 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1282 return 0;
1283 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1284 return 0;
1285 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1286 return 0;
1287 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1288 return 0;
1289 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001290}
1291
1292/**
James Smart8fa38512009-07-19 10:01:03 -04001293 * lpfc_sw_name_match - Check if the fcf switch name match.
1294 * @fab_name: pointer to fabric name.
1295 * @new_fcf_record: pointer to fcf record.
1296 *
1297 * This routine compare the fcf record's switch name with provided
1298 * switch name. If the switch name are identical this function
1299 * returns 1 else return 0.
1300 **/
1301static uint32_t
1302lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1303{
James Smartecfd03c2010-02-12 14:41:27 -05001304 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001305 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001306 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1307 return 0;
1308 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1309 return 0;
1310 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1311 return 0;
1312 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1313 return 0;
1314 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1315 return 0;
1316 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1317 return 0;
1318 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1319 return 0;
1320 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001321}
1322
1323/**
James Smart6fb120a2009-05-22 14:52:59 -04001324 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001325 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001326 * @new_fcf_record: pointer to fcf record.
1327 *
1328 * This routine compare the fcf record's mac address with HBA's
1329 * FCF mac address. If the mac addresses are identical this function
1330 * returns 1 else return 0.
1331 **/
1332static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001333lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001334{
James Smartecfd03c2010-02-12 14:41:27 -05001335 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001336 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001337 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1338 return 0;
1339 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1340 return 0;
1341 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1342 return 0;
1343 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1344 return 0;
1345 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1346 return 0;
1347 return 1;
1348}
1349
1350static bool
1351lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1352{
1353 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001354}
1355
1356/**
James Smart7d791df2011-07-22 18:37:52 -04001357 * lpfc_update_fcf_record - Update driver fcf record
1358 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1359 * @phba: pointer to lpfc hba data structure.
1360 * @fcf_index: Index for the lpfc_fcf_record.
1361 * @new_fcf_record: pointer to hba fcf record.
1362 *
1363 * This routine updates the driver FCF priority record from the new HBA FCF
1364 * record. This routine is called with the host lock held.
1365 **/
1366static void
1367__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1368 struct fcf_record *new_fcf_record
1369 )
1370{
1371 struct lpfc_fcf_pri *fcf_pri;
1372
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001373 lockdep_assert_held(&phba->hbalock);
1374
James Smart7d791df2011-07-22 18:37:52 -04001375 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1376 fcf_pri->fcf_rec.fcf_index = fcf_index;
1377 /* FCF record priority */
1378 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1379
1380}
1381
1382/**
James Smart6fb120a2009-05-22 14:52:59 -04001383 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001384 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001385 * @new_fcf_record: pointer to fcf record.
1386 *
1387 * This routine copies the FCF information from the FCF
1388 * record to lpfc_hba data structure.
1389 **/
1390static void
James Smartecfd03c2010-02-12 14:41:27 -05001391lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1392 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001393{
James Smartecfd03c2010-02-12 14:41:27 -05001394 /* Fabric name */
1395 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001396 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001397 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001398 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001399 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001400 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001401 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001402 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001403 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001404 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001405 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001406 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001407 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001408 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001409 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001410 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001411 /* Mac address */
1412 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1413 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1414 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1415 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1416 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1417 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1418 /* FCF record index */
1419 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1420 /* FCF record priority */
1421 fcf_rec->priority = new_fcf_record->fip_priority;
1422 /* Switch name */
1423 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001424 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001425 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001426 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001427 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001428 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001429 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001430 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001431 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001432 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001433 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001434 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001435 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001436 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001437 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001438 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001439}
1440
1441/**
James Smartecfd03c2010-02-12 14:41:27 -05001442 * lpfc_update_fcf_record - Update driver fcf record
1443 * @phba: pointer to lpfc hba data structure.
1444 * @fcf_rec: pointer to driver fcf record.
1445 * @new_fcf_record: pointer to hba fcf record.
1446 * @addr_mode: address mode to be set to the driver fcf record.
1447 * @vlan_id: vlan tag to be set to the driver fcf record.
1448 * @flag: flag bits to be set to the driver fcf record.
1449 *
1450 * This routine updates the driver FCF record from the new HBA FCF record
1451 * together with the address mode, vlan_id, and other informations. This
1452 * routine is called with the host lock held.
1453 **/
1454static void
1455__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1456 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1457 uint16_t vlan_id, uint32_t flag)
1458{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001459 lockdep_assert_held(&phba->hbalock);
1460
James Smartecfd03c2010-02-12 14:41:27 -05001461 /* Copy the fields from the HBA's FCF record */
1462 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1463 /* Update other fields of driver FCF record */
1464 fcf_rec->addr_mode = addr_mode;
1465 fcf_rec->vlan_id = vlan_id;
1466 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001467 __lpfc_update_fcf_record_pri(phba,
1468 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1469 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001470}
1471
1472/**
James Smart6fb120a2009-05-22 14:52:59 -04001473 * lpfc_register_fcf - Register the FCF with hba.
1474 * @phba: pointer to lpfc hba data structure.
1475 *
1476 * This routine issues a register fcfi mailbox command to register
1477 * the fcf with HBA.
1478 **/
1479static void
1480lpfc_register_fcf(struct lpfc_hba *phba)
1481{
1482 LPFC_MBOXQ_t *fcf_mbxq;
1483 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001484
James Smartd439d282010-09-29 11:18:45 -04001485 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001486 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001487 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001488 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001489 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001490 return;
1491 }
1492
1493 /* The FCF is already registered, start discovery */
1494 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001495 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001496 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001497 if (phba->pport->port_state != LPFC_FLOGI &&
1498 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001499 phba->hba_flag |= FCF_RR_INPROG;
1500 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001501 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001502 return;
1503 }
1504 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001505 return;
1506 }
James Smartd439d282010-09-29 11:18:45 -04001507 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001508
James Smarta93ff372010-10-22 11:06:08 -04001509 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001510 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001511 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001512 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001513 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001514 return;
James Smart4d9ab992009-10-02 15:16:39 -04001515 }
James Smart6fb120a2009-05-22 14:52:59 -04001516
1517 lpfc_reg_fcfi(phba, fcf_mbxq);
1518 fcf_mbxq->vport = phba->pport;
1519 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1520 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001521 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001522 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001523 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001524 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001525 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001526 }
James Smart6fb120a2009-05-22 14:52:59 -04001527
1528 return;
1529}
1530
1531/**
1532 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1533 * @phba: pointer to lpfc hba data structure.
1534 * @new_fcf_record: pointer to fcf record.
1535 * @boot_flag: Indicates if this record used by boot bios.
1536 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001537 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001538 *
1539 * This routine compare the fcf record with connect list obtained from the
1540 * config region to decide if this FCF can be used for SAN discovery. It returns
1541 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1542 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1543 * is used by boot bios and addr_mode will indicate the addressing mode to be
1544 * used for this FCF when the function returns.
1545 * If the FCF record need to be used with a particular vlan id, the vlan is
1546 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001547 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001548 **/
1549static int
1550lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1551 struct fcf_record *new_fcf_record,
1552 uint32_t *boot_flag, uint32_t *addr_mode,
1553 uint16_t *vlan_id)
1554{
1555 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001556 int i, j, fcf_vlan_id = 0;
1557
1558 /* Find the lowest VLAN id in the FCF record */
1559 for (i = 0; i < 512; i++) {
1560 if (new_fcf_record->vlan_bitmap[i]) {
1561 fcf_vlan_id = i * 8;
1562 j = 0;
1563 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1564 j++;
1565 fcf_vlan_id++;
1566 }
1567 break;
1568 }
1569 }
James Smart6fb120a2009-05-22 14:52:59 -04001570
James Smart26979ce2012-09-29 11:31:55 -04001571 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001572 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001573 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1574 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001575 return 0;
1576
James Smart45ed1192009-10-02 15:17:02 -04001577 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001578 *boot_flag = 0;
1579 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1580 new_fcf_record);
1581 if (phba->valid_vlan)
1582 *vlan_id = phba->vlan_id;
1583 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001584 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001585 return 1;
1586 }
1587
1588 /*
1589 * If there are no FCF connection table entry, driver connect to all
1590 * FCFs.
1591 */
1592 if (list_empty(&phba->fcf_conn_rec_list)) {
1593 *boot_flag = 0;
1594 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1595 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001596
1597 /*
1598 * When there are no FCF connect entries, use driver's default
1599 * addressing mode - FPMA.
1600 */
1601 if (*addr_mode & LPFC_FCF_FPMA)
1602 *addr_mode = LPFC_FCF_FPMA;
1603
James Smart4d9ab992009-10-02 15:16:39 -04001604 /* If FCF record report a vlan id use that vlan id */
1605 if (fcf_vlan_id)
1606 *vlan_id = fcf_vlan_id;
1607 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001608 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001609 return 1;
1610 }
1611
James Smartecfd03c2010-02-12 14:41:27 -05001612 list_for_each_entry(conn_entry,
1613 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001614 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1615 continue;
1616
1617 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1618 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001619 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001620 continue;
James Smart8fa38512009-07-19 10:01:03 -04001621 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1622 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1623 new_fcf_record))
1624 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001625 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1626 /*
1627 * If the vlan bit map does not have the bit set for the
1628 * vlan id to be used, then it is not a match.
1629 */
1630 if (!(new_fcf_record->vlan_bitmap
1631 [conn_entry->conn_rec.vlan_tag / 8] &
1632 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1633 continue;
1634 }
1635
1636 /*
James Smart0c287582009-06-10 17:22:56 -04001637 * If connection record does not support any addressing mode,
1638 * skip the FCF record.
1639 */
1640 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1641 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1642 continue;
1643
1644 /*
James Smart6fb120a2009-05-22 14:52:59 -04001645 * Check if the connection record specifies a required
1646 * addressing mode.
1647 */
1648 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1649 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1650
1651 /*
1652 * If SPMA required but FCF not support this continue.
1653 */
1654 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1655 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1656 new_fcf_record) & LPFC_FCF_SPMA))
1657 continue;
1658
1659 /*
1660 * If FPMA required but FCF not support this continue.
1661 */
1662 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1663 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1664 new_fcf_record) & LPFC_FCF_FPMA))
1665 continue;
1666 }
1667
1668 /*
1669 * This fcf record matches filtering criteria.
1670 */
1671 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1672 *boot_flag = 1;
1673 else
1674 *boot_flag = 0;
1675
James Smart0c287582009-06-10 17:22:56 -04001676 /*
1677 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001678 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001679 * by FCF, allow fabric to pick the addressing mode.
1680 */
James Smart6fb120a2009-05-22 14:52:59 -04001681 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1682 new_fcf_record);
1683 /*
1684 * If the user specified a required address mode, assign that
1685 * address mode
1686 */
1687 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1688 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1689 *addr_mode = (conn_entry->conn_rec.flags &
1690 FCFCNCT_AM_SPMA) ?
1691 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1692 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001693 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001694 * addr mode only if FCF support the addr_mode.
1695 */
1696 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1697 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1698 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1699 (*addr_mode & LPFC_FCF_SPMA))
1700 *addr_mode = LPFC_FCF_SPMA;
1701 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1702 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1703 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1704 (*addr_mode & LPFC_FCF_FPMA))
1705 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001706
James Smart4d9ab992009-10-02 15:16:39 -04001707 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001708 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1709 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001710 /*
1711 * If no vlan id is specified in connect list, use the vlan id
1712 * in the FCF record
1713 */
1714 else if (fcf_vlan_id)
1715 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001716 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001717 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001718
1719 return 1;
1720 }
1721
1722 return 0;
1723}
1724
1725/**
James Smart32b97932009-07-19 10:01:21 -04001726 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1727 * @phba: pointer to lpfc hba data structure.
1728 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1729 *
1730 * This function check if there is any fcoe event pending while driver
1731 * scan FCF entries. If there is any pending event, it will restart the
1732 * FCF saning and return 1 else return 0.
1733 */
1734int
1735lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1736{
James Smart32b97932009-07-19 10:01:21 -04001737 /*
1738 * If the Link is up and no FCoE events while in the
1739 * FCF discovery, no need to restart FCF discovery.
1740 */
1741 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001742 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001743 return 0;
1744
James Smart0c9ab6f2010-02-26 14:15:57 -05001745 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1746 "2768 Pending link or FCF event during current "
1747 "handling of the previous event: link_state:x%x, "
1748 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1749 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1750 phba->fcoe_eventtag);
1751
James Smart32b97932009-07-19 10:01:21 -04001752 spin_lock_irq(&phba->hbalock);
1753 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1754 spin_unlock_irq(&phba->hbalock);
1755
James Smart0c9ab6f2010-02-26 14:15:57 -05001756 if (phba->link_state >= LPFC_LINK_UP) {
1757 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1758 "2780 Restart FCF table scan due to "
1759 "pending FCF event:evt_tag_at_scan:x%x, "
1760 "evt_tag_current:x%x\n",
1761 phba->fcoe_eventtag_at_fcf_scan,
1762 phba->fcoe_eventtag);
1763 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1764 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001765 /*
James Smarta93ff372010-10-22 11:06:08 -04001766 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001767 * flag
1768 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001769 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1770 "2833 Stop FCF discovery process due to link "
1771 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001772 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001773 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001774 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001775 spin_unlock_irq(&phba->hbalock);
1776 }
James Smart32b97932009-07-19 10:01:21 -04001777
James Smart0c9ab6f2010-02-26 14:15:57 -05001778 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001779 if (unreg_fcf) {
1780 spin_lock_irq(&phba->hbalock);
1781 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1782 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001783 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001784 }
James Smart32b97932009-07-19 10:01:21 -04001785 return 1;
1786}
1787
1788/**
James Smart999d8132010-03-15 11:24:56 -04001789 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1790 * @phba: pointer to lpfc hba data structure.
1791 * @fcf_cnt: number of eligible fcf record seen so far.
1792 *
1793 * This function makes an running random selection decision on FCF record to
1794 * use through a sequence of @fcf_cnt eligible FCF records with equal
1795 * probability. To perform integer manunipulation of random numbers with
1796 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001797 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001798 *
1799 * Returns true when outcome is for the newly read FCF record should be
1800 * chosen; otherwise, return false when outcome is for keeping the previously
1801 * chosen FCF record.
1802 **/
1803static bool
1804lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1805{
1806 uint32_t rand_num;
1807
1808 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001809 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001810
1811 /* Decision with probability 1/fcf_cnt */
1812 if ((fcf_cnt * rand_num) < 0xFFFF)
1813 return true;
1814 else
1815 return false;
1816}
1817
1818/**
James Smart3804dc82010-07-14 15:31:37 -04001819 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001820 * @phba: pointer to lpfc hba data structure.
1821 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001822 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001823 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001824 * This routine parses the non-embedded fcf mailbox command by performing the
1825 * necessarily error checking, non-embedded read FCF record mailbox command
1826 * SGE parsing, and endianness swapping.
1827 *
1828 * Returns the pointer to the new FCF record in the non-embedded mailbox
1829 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001830 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001831static struct fcf_record *
1832lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1833 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001834{
1835 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001836 struct lpfc_mbx_sge sge;
1837 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001838 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001839 union lpfc_sli4_cfg_shdr *shdr;
1840 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001841
James Smart6fb120a2009-05-22 14:52:59 -04001842 /* Get the first SGE entry from the non-embedded DMA memory. This
1843 * routine only uses a single SGE.
1844 */
1845 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001846 if (unlikely(!mboxq->sge_array)) {
1847 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1848 "2524 Failed to get the non-embedded SGE "
1849 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001850 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001851 }
1852 virt_addr = mboxq->sge_array->addr[0];
1853
1854 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001855 lpfc_sli_pcimem_bcopy(shdr, shdr,
1856 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001857 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001858 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001859 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001860 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001861 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1862 if_type == LPFC_SLI_INTF_IF_TYPE_2)
James Smart0c9ab6f2010-02-26 14:15:57 -05001863 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001864 "2726 READ_FCF_RECORD Indicates empty "
1865 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001866 else
1867 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001868 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001869 "with status x%x add_status x%x, "
1870 "mbx\n", shdr_status, shdr_add_status);
1871 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001872 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001873
1874 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001875 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1876 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1877 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001878 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001879 new_fcf_record = (struct fcf_record *)(virt_addr +
1880 sizeof(struct lpfc_mbx_read_fcf_tbl));
1881 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001882 offsetof(struct fcf_record, vlan_bitmap));
1883 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1884 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001885
James Smart0c9ab6f2010-02-26 14:15:57 -05001886 return new_fcf_record;
1887}
1888
1889/**
1890 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1891 * @phba: pointer to lpfc hba data structure.
1892 * @fcf_record: pointer to the fcf record.
1893 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1894 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1895 *
1896 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1897 * enabled.
1898 **/
1899static void
1900lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1901 struct fcf_record *fcf_record,
1902 uint16_t vlan_id,
1903 uint16_t next_fcf_index)
1904{
1905 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1906 "2764 READ_FCF_RECORD:\n"
1907 "\tFCF_Index : x%x\n"
1908 "\tFCF_Avail : x%x\n"
1909 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001910 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001911 "\tFIP_Priority : x%x\n"
1912 "\tMAC_Provider : x%x\n"
1913 "\tLowest VLANID : x%x\n"
1914 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1915 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1916 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1917 "\tNext_FCF_Index: x%x\n",
1918 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1919 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1920 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001921 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001922 fcf_record->fip_priority,
1923 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1924 vlan_id,
1925 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1926 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1927 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1928 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1929 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1930 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1931 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1932 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1933 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1934 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1935 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1936 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1937 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1938 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1939 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1940 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1941 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1942 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1943 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1944 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1945 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1946 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1947 next_fcf_index);
1948}
1949
1950/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001951 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1952 * @phba: pointer to lpfc hba data structure.
1953 * @fcf_rec: pointer to an existing FCF record.
1954 * @new_fcf_record: pointer to a new FCF record.
1955 * @new_vlan_id: vlan id from the new FCF record.
1956 *
1957 * This function performs matching test of a new FCF record against an existing
1958 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1959 * will not be used as part of the FCF record matching criteria.
1960 *
1961 * Returns true if all the fields matching, otherwise returns false.
1962 */
1963static bool
1964lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1965 struct lpfc_fcf_rec *fcf_rec,
1966 struct fcf_record *new_fcf_record,
1967 uint16_t new_vlan_id)
1968{
1969 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1970 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1971 return false;
1972 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1973 return false;
1974 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1975 return false;
1976 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1977 return false;
James Smart7d791df2011-07-22 18:37:52 -04001978 if (fcf_rec->priority != new_fcf_record->fip_priority)
1979 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001980 return true;
1981}
1982
1983/**
James Smarta93ff372010-10-22 11:06:08 -04001984 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1985 * @vport: Pointer to vport object.
1986 * @fcf_index: index to next fcf.
1987 *
1988 * This function processing the roundrobin fcf failover to next fcf index.
1989 * When this function is invoked, there will be a current fcf registered
1990 * for flogi.
1991 * Return: 0 for continue retrying flogi on currently registered fcf;
1992 * 1 for stop flogi on currently registered fcf;
1993 */
1994int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1995{
1996 struct lpfc_hba *phba = vport->phba;
1997 int rc;
1998
1999 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2000 spin_lock_irq(&phba->hbalock);
2001 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2002 spin_unlock_irq(&phba->hbalock);
2003 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2004 "2872 Devloss tmo with no eligible "
2005 "FCF, unregister in-use FCF (x%x) "
2006 "and rescan FCF table\n",
2007 phba->fcf.current_rec.fcf_indx);
2008 lpfc_unregister_fcf_rescan(phba);
2009 goto stop_flogi_current_fcf;
2010 }
2011 /* Mark the end to FLOGI roundrobin failover */
2012 phba->hba_flag &= ~FCF_RR_INPROG;
2013 /* Allow action to new fcf asynchronous event */
2014 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2015 spin_unlock_irq(&phba->hbalock);
2016 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2017 "2865 No FCF available, stop roundrobin FCF "
2018 "failover and change port state:x%x/x%x\n",
2019 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2020 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002021
2022 if (!phba->fcf.fcf_redisc_attempted) {
2023 lpfc_unregister_fcf(phba);
2024
2025 rc = lpfc_sli4_redisc_fcf_table(phba);
2026 if (!rc) {
2027 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2028 "3195 Rediscover FCF table\n");
2029 phba->fcf.fcf_redisc_attempted = 1;
2030 lpfc_sli4_clear_fcf_rr_bmask(phba);
2031 } else {
2032 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2033 "3196 Rediscover FCF table "
2034 "failed. Status:x%x\n", rc);
2035 }
2036 } else {
2037 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2038 "3197 Already rediscover FCF table "
2039 "attempted. No more retry\n");
2040 }
James Smarta93ff372010-10-22 11:06:08 -04002041 goto stop_flogi_current_fcf;
2042 } else {
2043 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2044 "2794 Try FLOGI roundrobin FCF failover to "
2045 "(x%x)\n", fcf_index);
2046 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2047 if (rc)
2048 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2049 "2761 FLOGI roundrobin FCF failover "
2050 "failed (rc:x%x) to read FCF (x%x)\n",
2051 rc, phba->fcf.current_rec.fcf_indx);
2052 else
2053 goto stop_flogi_current_fcf;
2054 }
2055 return 0;
2056
2057stop_flogi_current_fcf:
2058 lpfc_can_disctmo(vport);
2059 return 1;
2060}
2061
2062/**
James Smart7d791df2011-07-22 18:37:52 -04002063 * lpfc_sli4_fcf_pri_list_del
2064 * @phba: pointer to lpfc hba data structure.
2065 * @fcf_index the index of the fcf record to delete
2066 * This routine checks the on list flag of the fcf_index to be deleted.
2067 * If it is one the list then it is removed from the list, and the flag
2068 * is cleared. This routine grab the hbalock before removing the fcf
2069 * record from the list.
2070 **/
2071static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2072 uint16_t fcf_index)
2073{
2074 struct lpfc_fcf_pri *new_fcf_pri;
2075
2076 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2077 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2078 "3058 deleting idx x%x pri x%x flg x%x\n",
2079 fcf_index, new_fcf_pri->fcf_rec.priority,
2080 new_fcf_pri->fcf_rec.flag);
2081 spin_lock_irq(&phba->hbalock);
2082 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2083 if (phba->fcf.current_rec.priority ==
2084 new_fcf_pri->fcf_rec.priority)
2085 phba->fcf.eligible_fcf_cnt--;
2086 list_del_init(&new_fcf_pri->list);
2087 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2088 }
2089 spin_unlock_irq(&phba->hbalock);
2090}
2091
2092/**
2093 * lpfc_sli4_set_fcf_flogi_fail
2094 * @phba: pointer to lpfc hba data structure.
2095 * @fcf_index the index of the fcf record to update
2096 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2097 * flag so the the round robin slection for the particular priority level
2098 * will try a different fcf record that does not have this bit set.
2099 * If the fcf record is re-read for any reason this flag is cleared brfore
2100 * adding it to the priority list.
2101 **/
2102void
2103lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2104{
2105 struct lpfc_fcf_pri *new_fcf_pri;
2106 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2107 spin_lock_irq(&phba->hbalock);
2108 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2109 spin_unlock_irq(&phba->hbalock);
2110}
2111
2112/**
2113 * lpfc_sli4_fcf_pri_list_add
2114 * @phba: pointer to lpfc hba data structure.
2115 * @fcf_index the index of the fcf record to add
2116 * This routine checks the priority of the fcf_index to be added.
2117 * If it is a lower priority than the current head of the fcf_pri list
2118 * then it is added to the list in the right order.
2119 * If it is the same priority as the current head of the list then it
2120 * is added to the head of the list and its bit in the rr_bmask is set.
2121 * If the fcf_index to be added is of a higher priority than the current
2122 * head of the list then the rr_bmask is cleared, its bit is set in the
2123 * rr_bmask and it is added to the head of the list.
2124 * returns:
2125 * 0=success 1=failure
2126 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002127static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2128 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002129 struct fcf_record *new_fcf_record)
2130{
2131 uint16_t current_fcf_pri;
2132 uint16_t last_index;
2133 struct lpfc_fcf_pri *fcf_pri;
2134 struct lpfc_fcf_pri *next_fcf_pri;
2135 struct lpfc_fcf_pri *new_fcf_pri;
2136 int ret;
2137
2138 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2139 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2140 "3059 adding idx x%x pri x%x flg x%x\n",
2141 fcf_index, new_fcf_record->fip_priority,
2142 new_fcf_pri->fcf_rec.flag);
2143 spin_lock_irq(&phba->hbalock);
2144 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2145 list_del_init(&new_fcf_pri->list);
2146 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2147 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2148 if (list_empty(&phba->fcf.fcf_pri_list)) {
2149 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2150 ret = lpfc_sli4_fcf_rr_index_set(phba,
2151 new_fcf_pri->fcf_rec.fcf_index);
2152 goto out;
2153 }
2154
2155 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2156 LPFC_SLI4_FCF_TBL_INDX_MAX);
2157 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2158 ret = 0; /* Empty rr list */
2159 goto out;
2160 }
2161 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2162 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2163 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2164 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2165 memset(phba->fcf.fcf_rr_bmask, 0,
2166 sizeof(*phba->fcf.fcf_rr_bmask));
2167 /* fcfs_at_this_priority_level = 1; */
2168 phba->fcf.eligible_fcf_cnt = 1;
2169 } else
2170 /* fcfs_at_this_priority_level++; */
2171 phba->fcf.eligible_fcf_cnt++;
2172 ret = lpfc_sli4_fcf_rr_index_set(phba,
2173 new_fcf_pri->fcf_rec.fcf_index);
2174 goto out;
2175 }
2176
2177 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2178 &phba->fcf.fcf_pri_list, list) {
2179 if (new_fcf_pri->fcf_rec.priority <=
2180 fcf_pri->fcf_rec.priority) {
2181 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2182 list_add(&new_fcf_pri->list,
2183 &phba->fcf.fcf_pri_list);
2184 else
2185 list_add(&new_fcf_pri->list,
2186 &((struct lpfc_fcf_pri *)
2187 fcf_pri->list.prev)->list);
2188 ret = 0;
2189 goto out;
2190 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2191 || new_fcf_pri->fcf_rec.priority <
2192 next_fcf_pri->fcf_rec.priority) {
2193 list_add(&new_fcf_pri->list, &fcf_pri->list);
2194 ret = 0;
2195 goto out;
2196 }
2197 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2198 continue;
2199
2200 }
2201 ret = 1;
2202out:
2203 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2204 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2205 spin_unlock_irq(&phba->hbalock);
2206 return ret;
2207}
2208
2209/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002210 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2211 * @phba: pointer to lpfc hba data structure.
2212 * @mboxq: pointer to mailbox object.
2213 *
2214 * This function iterates through all the fcf records available in
2215 * HBA and chooses the optimal FCF record for discovery. After finding
2216 * the FCF for discovery it registers the FCF record and kicks start
2217 * discovery.
2218 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2219 * use an FCF record which matches fabric name and mac address of the
2220 * currently used FCF record.
2221 * If the driver supports only one FCF, it will try to use the FCF record
2222 * used by BOOT_BIOS.
2223 */
2224void
2225lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2226{
2227 struct fcf_record *new_fcf_record;
2228 uint32_t boot_flag, addr_mode;
2229 uint16_t fcf_index, next_fcf_index;
2230 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002231 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002232 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002233 int rc;
2234
2235 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002236 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002237 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2238 return;
2239 }
2240
2241 /* Parse the FCF record from the non-embedded mailbox command */
2242 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2243 &next_fcf_index);
2244 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002245 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002246 "2765 Mailbox command READ_FCF_RECORD "
2247 "failed to retrieve a FCF record.\n");
2248 /* Let next new FCF event trigger fast failover */
2249 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002250 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002251 spin_unlock_irq(&phba->hbalock);
2252 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2253 return;
2254 }
2255
2256 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002257 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2258 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002259
2260 /* Log the FCF record information if turned on */
2261 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2262 next_fcf_index);
2263
James Smart6fb120a2009-05-22 14:52:59 -04002264 /*
2265 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002266 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002267 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002268 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002269 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002270 lpfc_sli4_fcf_pri_list_del(phba,
2271 bf_get(lpfc_fcf_record_fcf_index,
2272 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002273 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002274 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002275 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002276 bf_get(lpfc_fcf_record_fcf_index,
2277 new_fcf_record),
2278 bf_get(lpfc_fcf_record_fcf_avail,
2279 new_fcf_record),
2280 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002281 new_fcf_record),
2282 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002283 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002284 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2285 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2286 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002287 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2288 phba->fcf.current_rec.fcf_indx) {
2289 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2290 "2862 FCF (x%x) matches property "
2291 "of in-use FCF (x%x)\n",
2292 bf_get(lpfc_fcf_record_fcf_index,
2293 new_fcf_record),
2294 phba->fcf.current_rec.fcf_indx);
2295 goto read_next_fcf;
2296 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002297 /*
2298 * In case the current in-use FCF record becomes
2299 * invalid/unavailable during FCF discovery that
2300 * was not triggered by fast FCF failover process,
2301 * treat it as fast FCF failover.
2302 */
2303 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2304 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2305 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2306 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002307 "(x%x), enter FCF failover "
2308 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002309 phba->fcf.current_rec.fcf_indx);
2310 spin_lock_irq(&phba->hbalock);
2311 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2312 spin_unlock_irq(&phba->hbalock);
2313 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2314 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2315 LPFC_FCOE_FCF_GET_FIRST);
2316 return;
2317 }
2318 }
James Smart6fb120a2009-05-22 14:52:59 -04002319 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002320 } else {
2321 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002322 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2323 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002324 if (rc)
2325 goto read_next_fcf;
2326 }
2327
James Smart6fb120a2009-05-22 14:52:59 -04002328 /*
2329 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002330 * FCF record for the discovery. The condition that a rescan
2331 * matches the in-use FCF record: fabric name, switch name, mac
2332 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002333 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002334 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002335 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002336 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2337 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002338 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002339 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2340 phba->fcf.current_rec.fcf_indx) {
2341 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2342 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2343 /* Stop FCF redisc wait timer */
2344 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2345 phba);
2346 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2347 /* Fast failover, mark completed */
2348 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2349 spin_unlock_irq(&phba->hbalock);
2350 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2351 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002352 "FCF (x%x), port_state:x%x, "
2353 "fc_flag:x%x\n",
2354 phba->fcf.current_rec.fcf_indx,
2355 phba->pport->port_state,
2356 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002357 goto out;
2358 } else
2359 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2360 "2863 New FCF (x%x) matches "
2361 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002362 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002363 new_fcf_record),
2364 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002365 }
James Smartecfd03c2010-02-12 14:41:27 -05002366 /*
2367 * Read next FCF record from HBA searching for the matching
2368 * with in-use record only if not during the fast failover
2369 * period. In case of fast failover period, it shall try to
2370 * determine whether the FCF record just read should be the
2371 * next candidate.
2372 */
2373 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002374 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002375 goto read_next_fcf;
2376 }
James Smart6fb120a2009-05-22 14:52:59 -04002377 }
James Smartecfd03c2010-02-12 14:41:27 -05002378 /*
2379 * Update on failover FCF record only if it's in FCF fast-failover
2380 * period; otherwise, update on current FCF record.
2381 */
James Smartfc2b9892010-02-26 14:15:29 -05002382 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2383 fcf_rec = &phba->fcf.failover_rec;
2384 else
James Smartecfd03c2010-02-12 14:41:27 -05002385 fcf_rec = &phba->fcf.current_rec;
2386
James Smart6fb120a2009-05-22 14:52:59 -04002387 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2388 /*
James Smartecfd03c2010-02-12 14:41:27 -05002389 * If the driver FCF record does not have boot flag
2390 * set and new hba fcf record has boot flag set, use
2391 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002392 */
James Smartecfd03c2010-02-12 14:41:27 -05002393 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2394 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002395 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2396 "2837 Update current FCF record "
2397 "(x%x) with new FCF record (x%x)\n",
2398 fcf_rec->fcf_indx,
2399 bf_get(lpfc_fcf_record_fcf_index,
2400 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002401 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2402 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002403 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002404 goto read_next_fcf;
2405 }
2406 /*
James Smartecfd03c2010-02-12 14:41:27 -05002407 * If the driver FCF record has boot flag set and the
2408 * new hba FCF record does not have boot flag, read
2409 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002410 */
James Smartecfd03c2010-02-12 14:41:27 -05002411 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002412 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002413 goto read_next_fcf;
2414 }
2415 /*
James Smartecfd03c2010-02-12 14:41:27 -05002416 * If the new hba FCF record has lower priority value
2417 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002418 */
James Smartfc2b9892010-02-26 14:15:29 -05002419 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002420 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002421 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2422 "2838 Update current FCF record "
2423 "(x%x) with new FCF record (x%x)\n",
2424 fcf_rec->fcf_indx,
2425 bf_get(lpfc_fcf_record_fcf_index,
2426 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002427 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2428 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002429 /* Reset running random FCF selection count */
2430 phba->fcf.eligible_fcf_cnt = 1;
2431 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2432 /* Update running random FCF selection count */
2433 phba->fcf.eligible_fcf_cnt++;
2434 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2435 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002436 if (select_new_fcf) {
2437 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2438 "2839 Update current FCF record "
2439 "(x%x) with new FCF record (x%x)\n",
2440 fcf_rec->fcf_indx,
2441 bf_get(lpfc_fcf_record_fcf_index,
2442 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002443 /* Choose the new FCF by random selection */
2444 __lpfc_update_fcf_record(phba, fcf_rec,
2445 new_fcf_record,
2446 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002447 }
James Smart6fb120a2009-05-22 14:52:59 -04002448 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002449 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002450 goto read_next_fcf;
2451 }
2452 /*
James Smartecfd03c2010-02-12 14:41:27 -05002453 * This is the first suitable FCF record, choose this record for
2454 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002455 */
James Smartecfd03c2010-02-12 14:41:27 -05002456 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002457 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002458 "2840 Update initial FCF candidate "
2459 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002460 bf_get(lpfc_fcf_record_fcf_index,
2461 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002462 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2463 addr_mode, vlan_id, (boot_flag ?
2464 BOOT_ENABLE : 0));
2465 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002466 /* Setup initial running random FCF selection count */
2467 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002468 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002469 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002470 goto read_next_fcf;
2471
2472read_next_fcf:
2473 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002474 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2475 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2476 /*
2477 * Case of FCF fast failover scan
2478 */
2479
2480 /*
2481 * It has not found any suitable FCF record, cancel
2482 * FCF scan inprogress, and do nothing
2483 */
2484 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002485 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002486 "2782 No suitable FCF found: "
2487 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002488 phba->fcoe_eventtag_at_fcf_scan,
2489 bf_get(lpfc_fcf_record_fcf_index,
2490 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002491 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002492 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2493 phba->hba_flag &= ~FCF_TS_INPROG;
2494 spin_unlock_irq(&phba->hbalock);
2495 /* Unregister in-use FCF and rescan */
2496 lpfc_printf_log(phba, KERN_INFO,
2497 LOG_FIP,
2498 "2864 On devloss tmo "
2499 "unreg in-use FCF and "
2500 "rescan FCF table\n");
2501 lpfc_unregister_fcf_rescan(phba);
2502 return;
2503 }
2504 /*
2505 * Let next new FCF event trigger fast failover
2506 */
2507 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002508 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002509 return;
2510 }
2511 /*
2512 * It has found a suitable FCF record that is not
2513 * the same as in-use FCF record, unregister the
2514 * in-use FCF record, replace the in-use FCF record
2515 * with the new FCF record, mark FCF fast failover
2516 * completed, and then start register the new FCF
2517 * record.
2518 */
2519
James Smart0c9ab6f2010-02-26 14:15:57 -05002520 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002521 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002522
2523 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002524 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002525 "2842 Replace in-use FCF (x%x) "
2526 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002527 phba->fcf.current_rec.fcf_indx,
2528 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002529 memcpy(&phba->fcf.current_rec,
2530 &phba->fcf.failover_rec,
2531 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002532 /*
2533 * Mark the fast FCF failover rediscovery completed
2534 * and the start of the first round of the roundrobin
2535 * FCF failover.
2536 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002537 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002538 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002539 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002540 /* Register to the new FCF record */
2541 lpfc_register_fcf(phba);
2542 } else {
2543 /*
2544 * In case of transaction period to fast FCF failover,
2545 * do nothing when search to the end of the FCF table.
2546 */
2547 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2548 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2549 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002550
James Smart7d791df2011-07-22 18:37:52 -04002551 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2552 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002553 /*
2554 * In case the current in-use FCF record no
2555 * longer existed during FCF discovery that
2556 * was not triggered by fast FCF failover
2557 * process, treat it as fast FCF failover.
2558 */
2559 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2560 "2841 In-use FCF record (x%x) "
2561 "not reported, entering fast "
2562 "FCF failover mode scanning.\n",
2563 phba->fcf.current_rec.fcf_indx);
2564 spin_lock_irq(&phba->hbalock);
2565 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2566 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002567 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2568 LPFC_FCOE_FCF_GET_FIRST);
2569 return;
2570 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002571 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002572 lpfc_register_fcf(phba);
2573 }
2574 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002575 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002576 return;
2577
2578out:
2579 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2580 lpfc_register_fcf(phba);
2581
2582 return;
2583}
2584
2585/**
James Smarta93ff372010-10-22 11:06:08 -04002586 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002587 * @phba: pointer to lpfc hba data structure.
2588 * @mboxq: pointer to mailbox object.
2589 *
James Smarta93ff372010-10-22 11:06:08 -04002590 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002591 * read FCF record mailbox command from the eligible FCF record bmask for
2592 * performing the failover. If the FCF read back is not valid/available, it
2593 * fails through to retrying FLOGI to the currently registered FCF again.
2594 * Otherwise, if the FCF read back is valid and available, it will set the
2595 * newly read FCF record to the failover FCF record, unregister currently
2596 * registered FCF record, copy the failover FCF record to the current
2597 * FCF record, and then register the current FCF record before proceeding
2598 * to trying FLOGI on the new failover FCF.
2599 */
2600void
2601lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2602{
2603 struct fcf_record *new_fcf_record;
2604 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002605 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002606 uint16_t current_fcf_index;
2607 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002608 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002609
James Smarta93ff372010-10-22 11:06:08 -04002610 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002611 if (phba->link_state < LPFC_LINK_UP) {
2612 spin_lock_irq(&phba->hbalock);
2613 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002614 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002615 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002616 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002617 }
2618
2619 /* Parse the FCF record from the non-embedded mailbox command */
2620 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2621 &next_fcf_index);
2622 if (!new_fcf_record) {
2623 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2624 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002625 "failed to retrieve a FCF record. "
2626 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2627 phba->fcf.fcf_flag);
2628 lpfc_unregister_fcf_rescan(phba);
2629 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002630 }
2631
2632 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002633 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2634 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002635
2636 /* Log the FCF record information if turned on */
2637 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2638 next_fcf_index);
2639
James Smarta93ff372010-10-22 11:06:08 -04002640 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2641 if (!rc) {
2642 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2643 "2848 Remove ineligible FCF (x%x) from "
2644 "from roundrobin bmask\n", fcf_index);
2645 /* Clear roundrobin bmask bit for ineligible FCF */
2646 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2647 /* Perform next round of roundrobin FCF failover */
2648 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2649 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2650 if (rc)
2651 goto out;
2652 goto error_out;
2653 }
2654
2655 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2656 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2657 "2760 Perform FLOGI roundrobin FCF failover: "
2658 "FCF (x%x) back to FCF (x%x)\n",
2659 phba->fcf.current_rec.fcf_indx, fcf_index);
2660 /* Wait 500 ms before retrying FLOGI to current FCF */
2661 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002662 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002663 goto out;
2664 }
2665
James Smart0c9ab6f2010-02-26 14:15:57 -05002666 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002667 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002668 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2669 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002670 spin_lock_irq(&phba->hbalock);
2671 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2672 new_fcf_record, addr_mode, vlan_id,
2673 (boot_flag ? BOOT_ENABLE : 0));
2674 spin_unlock_irq(&phba->hbalock);
2675
2676 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2677
2678 /* Unregister the current in-use FCF record */
2679 lpfc_unregister_fcf(phba);
2680
2681 /* Replace in-use record with the new record */
2682 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2683 sizeof(struct lpfc_fcf_rec));
2684
2685 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002686 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2687 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002688
James Smarta93ff372010-10-22 11:06:08 -04002689error_out:
2690 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002691out:
2692 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002693}
2694
2695/**
2696 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2697 * @phba: pointer to lpfc hba data structure.
2698 * @mboxq: pointer to mailbox object.
2699 *
2700 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002701 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002702 * failover when a new FCF event happened. If the FCF read back is
2703 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002704 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002705 */
2706void
2707lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2708{
2709 struct fcf_record *new_fcf_record;
2710 uint32_t boot_flag, addr_mode;
2711 uint16_t fcf_index, next_fcf_index;
2712 uint16_t vlan_id;
2713 int rc;
2714
2715 /* If link state is not up, no need to proceed */
2716 if (phba->link_state < LPFC_LINK_UP)
2717 goto out;
2718
2719 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002720 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002721 goto out;
2722
2723 /* Parse the FCF record from the non-embedded mailbox command */
2724 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2725 &next_fcf_index);
2726 if (!new_fcf_record) {
2727 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2728 "2767 Mailbox command READ_FCF_RECORD "
2729 "failed to retrieve a FCF record.\n");
2730 goto out;
2731 }
2732
2733 /* Check the connection list for eligibility */
2734 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2735 &addr_mode, &vlan_id);
2736
2737 /* Log the FCF record information if turned on */
2738 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2739 next_fcf_index);
2740
2741 if (!rc)
2742 goto out;
2743
2744 /* Update the eligible FCF record index bmask */
2745 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002746
2747 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002748
2749out:
2750 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2751}
2752
2753/**
James Smart76a95d72010-11-20 23:11:48 -05002754 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2755 * @phba: pointer to lpfc hba data structure.
2756 * @mboxq: pointer to mailbox data structure.
2757 *
2758 * This function handles completion of init vfi mailbox command.
2759 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002760static void
James Smart76a95d72010-11-20 23:11:48 -05002761lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2762{
2763 struct lpfc_vport *vport = mboxq->vport;
2764
James Smartdf9e1b52011-12-13 13:22:17 -05002765 /*
2766 * VFI not supported on interface type 0, just do the flogi
2767 * Also continue if the VFI is in use - just use the same one.
2768 */
2769 if (mboxq->u.mb.mbxStatus &&
2770 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2771 LPFC_SLI_INTF_IF_TYPE_0) &&
2772 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002773 lpfc_printf_vlog(vport, KERN_ERR,
2774 LOG_MBOX,
2775 "2891 Init VFI mailbox failed 0x%x\n",
2776 mboxq->u.mb.mbxStatus);
2777 mempool_free(mboxq, phba->mbox_mem_pool);
2778 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2779 return;
2780 }
James Smart73d91e52011-10-10 21:32:10 -04002781
James Smart76a95d72010-11-20 23:11:48 -05002782 lpfc_initial_flogi(vport);
2783 mempool_free(mboxq, phba->mbox_mem_pool);
2784 return;
2785}
2786
2787/**
2788 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2789 * @vport: pointer to lpfc_vport data structure.
2790 *
2791 * This function issue a init_vfi mailbox command to initialize the VFI and
2792 * VPI for the physical port.
2793 */
2794void
2795lpfc_issue_init_vfi(struct lpfc_vport *vport)
2796{
2797 LPFC_MBOXQ_t *mboxq;
2798 int rc;
2799 struct lpfc_hba *phba = vport->phba;
2800
2801 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2802 if (!mboxq) {
2803 lpfc_printf_vlog(vport, KERN_ERR,
2804 LOG_MBOX, "2892 Failed to allocate "
2805 "init_vfi mailbox\n");
2806 return;
2807 }
2808 lpfc_init_vfi(mboxq, vport);
2809 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2810 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2811 if (rc == MBX_NOT_FINISHED) {
2812 lpfc_printf_vlog(vport, KERN_ERR,
2813 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2814 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2815 }
2816}
2817
2818/**
James Smart1c6834a2009-07-19 10:01:26 -04002819 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2820 * @phba: pointer to lpfc hba data structure.
2821 * @mboxq: pointer to mailbox data structure.
2822 *
2823 * This function handles completion of init vpi mailbox command.
2824 */
James Smart695a8142010-01-26 23:08:03 -05002825void
James Smart1c6834a2009-07-19 10:01:26 -04002826lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2827{
2828 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002829 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002830 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2831
James Smart1c6834a2009-07-19 10:01:26 -04002832 if (mboxq->u.mb.mbxStatus) {
2833 lpfc_printf_vlog(vport, KERN_ERR,
2834 LOG_MBOX,
2835 "2609 Init VPI mailbox failed 0x%x\n",
2836 mboxq->u.mb.mbxStatus);
2837 mempool_free(mboxq, phba->mbox_mem_pool);
2838 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2839 return;
2840 }
James Smart72100cc2010-02-12 14:43:01 -05002841 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002842 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002843 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002844
James Smart695a8142010-01-26 23:08:03 -05002845 /* If this port is physical port or FDISC is done, do reg_vpi */
2846 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2847 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2848 if (!ndlp)
2849 lpfc_printf_vlog(vport, KERN_ERR,
2850 LOG_DISCOVERY,
2851 "2731 Cannot find fabric "
2852 "controller node\n");
2853 else
2854 lpfc_register_new_vport(phba, vport, ndlp);
2855 mempool_free(mboxq, phba->mbox_mem_pool);
2856 return;
2857 }
2858
James Smart1c6834a2009-07-19 10:01:26 -04002859 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2860 lpfc_initial_fdisc(vport);
2861 else {
2862 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002863 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2864 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002865 }
James Smart695a8142010-01-26 23:08:03 -05002866 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002867 return;
2868}
2869
2870/**
James Smartecfd03c2010-02-12 14:41:27 -05002871 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2872 * @vport: pointer to lpfc_vport data structure.
2873 *
2874 * This function issue a init_vpi mailbox command to initialize
2875 * VPI for the vport.
2876 */
2877void
2878lpfc_issue_init_vpi(struct lpfc_vport *vport)
2879{
2880 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002881 int rc, vpi;
2882
2883 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2884 vpi = lpfc_alloc_vpi(vport->phba);
2885 if (!vpi) {
2886 lpfc_printf_vlog(vport, KERN_ERR,
2887 LOG_MBOX,
2888 "3303 Failed to obtain vport vpi\n");
2889 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2890 return;
2891 }
2892 vport->vpi = vpi;
2893 }
James Smartecfd03c2010-02-12 14:41:27 -05002894
2895 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2896 if (!mboxq) {
2897 lpfc_printf_vlog(vport, KERN_ERR,
2898 LOG_MBOX, "2607 Failed to allocate "
2899 "init_vpi mailbox\n");
2900 return;
2901 }
2902 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2903 mboxq->vport = vport;
2904 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2905 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2906 if (rc == MBX_NOT_FINISHED) {
2907 lpfc_printf_vlog(vport, KERN_ERR,
2908 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2909 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2910 }
2911}
2912
2913/**
James Smart6fb120a2009-05-22 14:52:59 -04002914 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2915 * @phba: pointer to lpfc hba data structure.
2916 *
2917 * This function loops through the list of vports on the @phba and issues an
2918 * FDISC if possible.
2919 */
2920void
2921lpfc_start_fdiscs(struct lpfc_hba *phba)
2922{
2923 struct lpfc_vport **vports;
2924 int i;
2925
2926 vports = lpfc_create_vport_work_array(phba);
2927 if (vports != NULL) {
2928 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2929 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2930 continue;
2931 /* There are no vpi for this vport */
2932 if (vports[i]->vpi > phba->max_vpi) {
2933 lpfc_vport_set_state(vports[i],
2934 FC_VPORT_FAILED);
2935 continue;
2936 }
James Smart76a95d72010-11-20 23:11:48 -05002937 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002938 lpfc_vport_set_state(vports[i],
2939 FC_VPORT_LINKDOWN);
2940 continue;
2941 }
James Smart1c6834a2009-07-19 10:01:26 -04002942 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002943 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002944 continue;
2945 }
James Smart6fb120a2009-05-22 14:52:59 -04002946 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2947 lpfc_initial_fdisc(vports[i]);
2948 else {
2949 lpfc_vport_set_state(vports[i],
2950 FC_VPORT_NO_FABRIC_SUPP);
2951 lpfc_printf_vlog(vports[i], KERN_ERR,
2952 LOG_ELS,
2953 "0259 No NPIV "
2954 "Fabric support\n");
2955 }
2956 }
2957 }
2958 lpfc_destroy_vport_work_array(phba, vports);
2959}
2960
2961void
2962lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2963{
James Smart3e1f0712018-11-29 16:09:29 -08002964 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04002965 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002966 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002967
James Smartf5eca9b2012-03-01 22:37:54 -05002968 /*
2969 * VFI not supported for interface type 0, so ignore any mailbox
2970 * error (except VFI in use) and continue with the discovery.
2971 */
2972 if (mboxq->u.mb.mbxStatus &&
2973 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2974 LPFC_SLI_INTF_IF_TYPE_0) &&
2975 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002976 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2977 "2018 REG_VFI mbxStatus error x%x "
2978 "HBA state x%x\n",
2979 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002980 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002981 /* FLOGI failed, use loop map to make discovery list */
2982 lpfc_disc_list_loopmap(vport);
2983 /* Start discovery */
2984 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002985 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002986 }
2987 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002988 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002989 }
James Smartae05ebe2013-03-01 16:35:38 -05002990
James Smarte74c03c2013-04-17 20:15:19 -04002991 /* If the VFI is already registered, there is nothing else to do
2992 * Unless this was a VFI update and we are in PT2PT mode, then
2993 * we should drop through to set the port state to ready.
2994 */
James Smartae05ebe2013-03-01 16:35:38 -05002995 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04002996 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2997 vport->fc_flag & FC_PT2PT))
2998 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05002999
James Smartc8685952009-11-18 15:39:16 -05003000 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05003001 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003002 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003003 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003004 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003005 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003006 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003007
James Smart1b511972011-12-13 13:23:09 -05003008 /* In case SLI4 FC loopback test, we are ready */
3009 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3010 (phba->link_flag & LS_LOOPBACK_MODE)) {
3011 phba->link_state = LPFC_HBA_READY;
3012 goto out_free_mem;
3013 }
3014
James Smarte74c03c2013-04-17 20:15:19 -04003015 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3016 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3017 "alpacnt:%d LinkState:%x topology:%x\n",
3018 vport->port_state, vport->fc_flag, vport->fc_myDID,
3019 vport->phba->alpa_map[0],
3020 phba->link_state, phba->fc_topology);
3021
James Smart6fb120a2009-05-22 14:52:59 -04003022 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003023 /*
3024 * For private loop or for NPort pt2pt,
3025 * just start discovery and we are done.
3026 */
3027 if ((vport->fc_flag & FC_PT2PT) ||
3028 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3029 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3030
James Smart76a95d72010-11-20 23:11:48 -05003031 /* Use loop map to make discovery list */
3032 lpfc_disc_list_loopmap(vport);
3033 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003034 if (vport->fc_flag & FC_PT2PT)
3035 vport->port_state = LPFC_VPORT_READY;
3036 else
3037 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003038 } else {
3039 lpfc_start_fdiscs(phba);
3040 lpfc_do_scr_ns_plogi(phba, vport);
3041 }
James Smart6fb120a2009-05-22 14:52:59 -04003042 }
3043
James Smart1b511972011-12-13 13:23:09 -05003044out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003045 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003046 if (dmabuf) {
3047 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3048 kfree(dmabuf);
3049 }
James Smart6fb120a2009-05-22 14:52:59 -04003050 return;
3051}
3052
3053static void
James Smart2e0fef82007-06-17 19:56:36 -05003054lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003055{
James Smart6fb120a2009-05-22 14:52:59 -04003056 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003057 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003058 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003060 struct serv_parm *sp = &vport->fc_sparam;
3061 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003062
3063 /* Check for error */
3064 if (mb->mbxStatus) {
3065 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003066 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3067 "0319 READ_SPARAM mbxStatus error x%x "
3068 "hba state x%x>\n",
3069 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003070 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003071 goto out;
3072 }
3073
James Smart2e0fef82007-06-17 19:56:36 -05003074 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003075 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003076
3077 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3078 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3079 ed_tov = (ed_tov + 999999) / 1000000;
3080
3081 phba->fc_edtov = ed_tov;
3082 phba->fc_ratov = (2 * ed_tov) / 1000;
3083 if (phba->fc_ratov < FF_DEF_RATOV) {
3084 /* RA_TOV should be atleast 10sec for initial flogi */
3085 phba->fc_ratov = FF_DEF_RATOV;
3086 }
3087
James Smart05580562011-05-24 11:40:48 -04003088 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003089 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003090 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3091 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3092 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3093 }
3094
dea31012005-04-17 16:05:31 -05003095 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3096 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003097 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003098 return;
3099
3100out:
James Smart3e1f0712018-11-29 16:09:29 -08003101 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003102 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3103 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003104 lpfc_issue_clear_la(phba, vport);
3105 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003106 return;
3107}
3108
3109static void
James Smart76a95d72010-11-20 23:11:48 -05003110lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003111{
James Smart92d7f7b2007-06-17 19:56:38 -05003112 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003113 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003114 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003115 int i;
James Smart14691152006-12-02 13:34:28 -05003116 struct lpfc_dmabuf *mp;
3117 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003118 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003119 uint32_t fc_flags = 0;
James Smart894bb172019-08-14 16:56:52 -07003120 unsigned long iflags;
James Smart14691152006-12-02 13:34:28 -05003121
James Smart894bb172019-08-14 16:56:52 -07003122 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta085e872015-12-16 18:12:02 -05003123 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3124
3125 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3126 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3127 case LPFC_LINK_SPEED_1GHZ:
3128 case LPFC_LINK_SPEED_2GHZ:
3129 case LPFC_LINK_SPEED_4GHZ:
3130 case LPFC_LINK_SPEED_8GHZ:
3131 case LPFC_LINK_SPEED_10GHZ:
3132 case LPFC_LINK_SPEED_16GHZ:
3133 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003134 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003135 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003136 break;
3137 default:
3138 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3139 break;
3140 }
dea31012005-04-17 16:05:31 -05003141 }
3142
James Smarte74c03c2013-04-17 20:15:19 -04003143 if (phba->fc_topology &&
3144 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3145 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3146 "3314 Toplogy changed was 0x%x is 0x%x\n",
3147 phba->fc_topology,
3148 bf_get(lpfc_mbx_read_top_topology, la));
3149 phba->fc_topology_changed = 1;
3150 }
3151
James Smart76a95d72010-11-20 23:11:48 -05003152 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003153 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003154
James Smartdf9e1b52011-12-13 13:22:17 -05003155 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003156 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003157 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003158
James Smart6a9c52c2009-10-02 15:16:51 -04003159 /* if npiv is enabled and this adapter supports npiv log
3160 * a message that npiv is not supported in this topology
3161 */
3162 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003163 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3164 "1309 Link Up Event npiv not supported in loop "
3165 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003166 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003167 if (bf_get(lpfc_mbx_read_top_il, la))
3168 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003169
James Smart76a95d72010-11-20 23:11:48 -05003170 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3171 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003172
3173 if (i == 0) {
3174 phba->alpa_map[0] = 0;
3175 } else {
James Smarte8b62012007-08-02 11:10:09 -04003176 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003177 int numalpa, j, k;
3178 union {
3179 uint8_t pamap[16];
3180 struct {
3181 uint32_t wd1;
3182 uint32_t wd2;
3183 uint32_t wd3;
3184 uint32_t wd4;
3185 } pa;
3186 } un;
3187 numalpa = phba->alpa_map[0];
3188 j = 0;
3189 while (j < numalpa) {
3190 memset(un.pamap, 0, 16);
3191 for (k = 1; j < numalpa; k++) {
3192 un.pamap[k - 1] =
3193 phba->alpa_map[j + 1];
3194 j++;
3195 if (k == 16)
3196 break;
3197 }
3198 /* Link Up Event ALPA map */
3199 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003200 KERN_WARNING,
3201 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003202 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003203 "ALPA map Data: x%x "
3204 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003205 un.pa.wd1, un.pa.wd2,
3206 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003207 }
3208 }
3209 }
3210 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003211 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003212 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003213 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003214 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3215 }
James Smart2e0fef82007-06-17 19:56:36 -05003216 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003217 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003218 }
James Smart894bb172019-08-14 16:56:52 -07003219 spin_unlock_irqrestore(&phba->hbalock, iflags);
dea31012005-04-17 16:05:31 -05003220
James Smart38c20672013-03-01 16:37:44 -05003221 if (fc_flags) {
James Smart894bb172019-08-14 16:56:52 -07003222 spin_lock_irqsave(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003223 vport->fc_flag |= fc_flags;
James Smart894bb172019-08-14 16:56:52 -07003224 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart38c20672013-03-01 16:37:44 -05003225 }
3226
dea31012005-04-17 16:05:31 -05003227 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05003228 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3229 if (!sparam_mbox)
3230 goto out;
3231
3232 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3233 if (rc) {
3234 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3235 goto out;
3236 }
3237 sparam_mbox->vport = vport;
3238 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3239 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3240 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003241 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003242 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3243 kfree(mp);
3244 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3245 goto out;
dea31012005-04-17 16:05:31 -05003246 }
3247
James Smart76a95d72010-11-20 23:11:48 -05003248 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04003249 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3250 if (!cfglink_mbox)
3251 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05003252 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05003253 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05003254 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05003255 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04003256 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04003257 if (rc == MBX_NOT_FINISHED) {
3258 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3259 goto out;
3260 }
3261 } else {
James Smart32b97932009-07-19 10:01:21 -04003262 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003263 /*
3264 * Add the driver's default FCF record at FCF index 0 now. This
3265 * is phase 1 implementation that support FCF index 0 and driver
3266 * defaults.
3267 */
James Smart45ed1192009-10-02 15:17:02 -04003268 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003269 fcf_record = kzalloc(sizeof(struct fcf_record),
3270 GFP_KERNEL);
3271 if (unlikely(!fcf_record)) {
3272 lpfc_printf_log(phba, KERN_ERR,
3273 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003274 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003275 "fcf record\n");
3276 rc = -ENODEV;
3277 goto out;
3278 }
3279
3280 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3281 LPFC_FCOE_FCF_DEF_INDEX);
3282 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3283 if (unlikely(rc)) {
3284 lpfc_printf_log(phba, KERN_ERR,
3285 LOG_MBOX | LOG_SLI,
3286 "2013 Could not manually add FCF "
3287 "record 0, status %d\n", rc);
3288 rc = -ENODEV;
3289 kfree(fcf_record);
3290 goto out;
3291 }
3292 kfree(fcf_record);
3293 }
3294 /*
3295 * The driver is expected to do FIP/FCF. Call the port
3296 * and get the FCF Table.
3297 */
James Smart894bb172019-08-14 16:56:52 -07003298 spin_lock_irqsave(&phba->hbalock, iflags);
James Smarta93ff372010-10-22 11:06:08 -04003299 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart894bb172019-08-14 16:56:52 -07003300 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart32b97932009-07-19 10:01:21 -04003301 return;
3302 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003303 /* This is the initial FCF discovery scan */
3304 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003305 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003306 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3307 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003308 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3309 LPFC_FCOE_FCF_GET_FIRST);
3310 if (rc) {
James Smart894bb172019-08-14 16:56:52 -07003311 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart0c9ab6f2010-02-26 14:15:57 -05003312 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
James Smart894bb172019-08-14 16:56:52 -07003313 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smart6fb120a2009-05-22 14:52:59 -04003314 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003315 }
James Smart38b92ef2010-08-04 16:11:39 -04003316 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003317 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003318 }
James Smart6fb120a2009-05-22 14:52:59 -04003319
3320 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003321out:
3322 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003323 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3324 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3325 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003326 lpfc_issue_clear_la(phba, vport);
3327 return;
dea31012005-04-17 16:05:31 -05003328}
3329
3330static void
James Smart84774a42008-08-24 21:50:06 -04003331lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003332{
dea31012005-04-17 16:05:31 -05003333 uint32_t control;
3334 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003335 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003336 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003337 if (phba->sli_rev <= LPFC_SLI_REV3) {
3338 control = readl(phba->HCregaddr);
3339 control |= HC_LAINT_ENA;
3340 writel(control, phba->HCregaddr);
3341 readl(phba->HCregaddr); /* flush */
3342 }
James Smart2e0fef82007-06-17 19:56:36 -05003343 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003344}
3345
James Smart84774a42008-08-24 21:50:06 -04003346static void
3347lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3348{
3349 lpfc_linkdown(phba);
3350 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003351 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003352 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3353}
3354
3355
dea31012005-04-17 16:05:31 -05003356/*
James Smart76a95d72010-11-20 23:11:48 -05003357 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003358 * command upon completion. It is setup in the LPFC_MBOXQ
3359 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003360 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003361 */
3362void
James Smart76a95d72010-11-20 23:11:48 -05003363lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003364{
James Smart2e0fef82007-06-17 19:56:36 -05003365 struct lpfc_vport *vport = pmb->vport;
3366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003367 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003368 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003369 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003370 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003371 uint8_t attn_type;
James Smart894bb172019-08-14 16:56:52 -07003372 unsigned long iflags;
dea31012005-04-17 16:05:31 -05003373
James Smart0d2b6b82008-06-14 22:52:47 -04003374 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003375 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003376 if (pring)
3377 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003378
dea31012005-04-17 16:05:31 -05003379 /* Check for error */
3380 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003381 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003382 "1307 READ_LA mbox error x%x state x%x\n",
3383 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003384 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003385 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003386 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003387 }
3388
James Smart76a95d72010-11-20 23:11:48 -05003389 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003390 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003391
3392 memcpy(&phba->alpa_map[0], mp->virt, 128);
3393
James Smart894bb172019-08-14 16:56:52 -07003394 spin_lock_irqsave(shost->host_lock, iflags);
James Smart76a95d72010-11-20 23:11:48 -05003395 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003396 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003397 else
James Smart2e0fef82007-06-17 19:56:36 -05003398 vport->fc_flag &= ~FC_BYPASSED_MODE;
James Smart894bb172019-08-14 16:56:52 -07003399 spin_unlock_irqrestore(shost->host_lock, iflags);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003400
James Smartbe0c0082013-03-01 16:38:14 -05003401 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003402 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003403 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003404 if (phba->fc_eventTag != 0)
3405 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003406 }
dea31012005-04-17 16:05:31 -05003407
3408 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003409 if (phba->sli_rev < LPFC_SLI_REV4) {
James Smart894bb172019-08-14 16:56:52 -07003410 spin_lock_irqsave(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003411 if (bf_get(lpfc_mbx_read_top_mm, la))
3412 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3413 else
3414 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart894bb172019-08-14 16:56:52 -07003415 spin_unlock_irqrestore(&phba->hbalock, iflags);
James Smartbe0c0082013-03-01 16:38:14 -05003416 }
dea31012005-04-17 16:05:31 -05003417
James Smart4d9ab992009-10-02 15:16:39 -04003418 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003419 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003420 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003421 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003422 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003423 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003424 "1306 Link Up Event in loop back mode "
3425 "x%x received Data: x%x x%x x%x x%x\n",
3426 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003427 bf_get(lpfc_mbx_read_top_alpa_granted,
3428 la),
3429 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003430 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003431 } else {
3432 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003433 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003434 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003435 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003436 bf_get(lpfc_mbx_read_top_alpa_granted,
3437 la),
3438 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003439 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003440 bf_get(lpfc_mbx_read_top_mm, la),
3441 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003442 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003443 }
James Smart92d7f7b2007-06-17 19:56:38 -05003444 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003445 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3446 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003447 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -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,
3450 "1308 Link Down Event in loop back mode "
3451 "x%x received "
3452 "Data: x%x x%x x%x\n",
3453 la->eventTag, phba->fc_eventTag,
3454 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003455 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3456 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3457 "1313 Link Down UNEXP WWPN Event x%x received "
3458 "Data: x%x x%x x%x x%x x%x\n",
3459 la->eventTag, phba->fc_eventTag,
3460 phba->pport->port_state, vport->fc_flag,
3461 bf_get(lpfc_mbx_read_top_mm, la),
3462 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003463 else
James Smart3163f722008-02-08 18:50:25 -05003464 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003465 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003466 "Data: x%x x%x x%x x%x x%x\n",
3467 la->eventTag, phba->fc_eventTag,
3468 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003469 bf_get(lpfc_mbx_read_top_mm, la),
3470 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003471 lpfc_mbx_issue_link_down(phba);
3472 }
James Smartaeb3c812017-04-21 16:05:02 -07003473 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3474 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003475 if (phba->link_state != LPFC_LINK_DOWN) {
3476 phba->fc_stat.LinkDown++;
3477 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3478 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003479 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003480 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003481 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003482 lpfc_mbx_issue_link_down(phba);
3483 } else
3484 lpfc_enable_la(phba);
3485
3486 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3487 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3488 "Data: x%x x%x x%x\n",
3489 la->eventTag, phba->fc_eventTag,
3490 phba->pport->port_state, vport->fc_flag);
3491 /*
3492 * The cmnd that triggered this will be waiting for this
3493 * signal.
3494 */
3495 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3496 if (phba->wait_4_mlo_maint_flg) {
3497 phba->wait_4_mlo_maint_flg = 0;
3498 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003499 }
James Smart84774a42008-08-24 21:50:06 -04003500 }
3501
James Smartbe0c0082013-03-01 16:38:14 -05003502 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3503 bf_get(lpfc_mbx_read_top_fa, la)) {
3504 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003505 lpfc_issue_clear_la(phba, vport);
3506 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003507 "1311 fa %d\n",
3508 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003509 }
3510
James Smart76a95d72010-11-20 23:11:48 -05003511lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003512 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3513 kfree(mp);
3514 mempool_free(pmb, phba->mbox_mem_pool);
3515 return;
3516}
3517
3518/*
3519 * This routine handles processing a REG_LOGIN mailbox
3520 * command upon completion. It is setup in the LPFC_MBOXQ
3521 * as the completion routine when the command is
3522 * handed off to the SLI layer.
3523 */
3524void
James Smart2e0fef82007-06-17 19:56:36 -05003525lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003526{
James Smart2e0fef82007-06-17 19:56:36 -05003527 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003528 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3529 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smartffc95492010-06-07 15:23:17 -04003530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003531
James Smart3e1f0712018-11-29 16:09:29 -08003532 pmb->ctx_buf = NULL;
3533 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003534
James Smartbe6bb942015-04-07 15:07:22 -04003535 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3536 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3537 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003538 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003539 ndlp->nlp_usg_map, ndlp);
James Smartffc95492010-06-07 15:23:17 -04003540 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3541 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3542
James Smart40426292010-12-15 17:58:10 -05003543 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3544 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003545 /* We rcvd a rscn after issuing this
3546 * mbox reg login, we may have cycled
3547 * back through the state and be
3548 * back at reg login state so this
3549 * mbox needs to be ignored becase
3550 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003551 * process.
James Smartffc95492010-06-07 15:23:17 -04003552 */
3553 spin_lock_irq(shost->host_lock);
3554 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3555 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003556
3557 /*
3558 * We cannot leave the RPI registered because
3559 * if we go thru discovery again for this ndlp
3560 * a subsequent REG_RPI will fail.
3561 */
3562 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3563 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003564 }
3565
3566 /* Call state machine */
3567 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003568
dea31012005-04-17 16:05:31 -05003569 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3570 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003571 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003572 /* decrement the node reference count held for this callback
3573 * function.
3574 */
James Smart329f9bc2007-04-25 09:53:01 -04003575 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003576
3577 return;
3578}
3579
James Smart92d7f7b2007-06-17 19:56:38 -05003580static void
3581lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3582{
James Smart04c68492009-05-22 14:52:52 -04003583 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003584 struct lpfc_vport *vport = pmb->vport;
3585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3586
3587 switch (mb->mbxStatus) {
3588 case 0x0011:
3589 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003590 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3591 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3592 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003593 break;
James Smart78730cf2010-04-06 15:06:30 -04003594 /* If VPI is busy, reset the HBA */
3595 case 0x9700:
3596 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3597 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3598 vport->vpi, mb->mbxStatus);
3599 if (!(phba->pport->load_flag & FC_UNLOADING))
3600 lpfc_workq_post_event(phba, NULL, NULL,
3601 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003602 }
James Smart72100cc2010-02-12 14:43:01 -05003603 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003604 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003605 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003606 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003607 vport->unreg_vpi_cmpl = VPORT_OK;
3608 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003609 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003610 /*
3611 * This shost reference might have been taken at the beginning of
3612 * lpfc_vport_delete()
3613 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003614 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003615 scsi_host_put(shost);
3616}
3617
James Smartd7c255b2008-08-24 21:50:00 -04003618int
James Smart92d7f7b2007-06-17 19:56:38 -05003619lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3620{
3621 struct lpfc_hba *phba = vport->phba;
3622 LPFC_MBOXQ_t *mbox;
3623 int rc;
3624
3625 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3626 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003627 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003628
3629 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3630 mbox->vport = vport;
3631 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003632 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003633 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003634 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3635 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003636 mempool_free(mbox, phba->mbox_mem_pool);
3637 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003638 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003639 }
James Smartd7c255b2008-08-24 21:50:00 -04003640 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003641}
3642
3643static void
3644lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3645{
3646 struct lpfc_vport *vport = pmb->vport;
3647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003648 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003649
3650 switch (mb->mbxStatus) {
3651 case 0x0011:
3652 case 0x9601:
3653 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003654 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3655 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3656 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003657 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3658 spin_lock_irq(shost->host_lock);
3659 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3660 spin_unlock_irq(shost->host_lock);
3661 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003662
James Smartf6e84792019-01-28 11:14:38 -08003663 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3664 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003665 if (phba->nvmet_support)
3666 lpfc_nvmet_update_targetport(phba);
3667 else
James Smart8c258642017-02-12 13:52:36 -08003668 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003669 }
James Smart92d7f7b2007-06-17 19:56:38 -05003670 goto out;
3671 }
James Smart92d7f7b2007-06-17 19:56:38 -05003672
James Smart72100cc2010-02-12 14:43:01 -05003673 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003674 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003675 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003676 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003677 vport->num_disc_nodes = 0;
3678 /* go thru NPR list and issue ELS PLOGIs */
3679 if (vport->fc_npr_cnt)
3680 lpfc_els_disc_plogi(vport);
3681
3682 if (!vport->num_disc_nodes) {
3683 spin_lock_irq(shost->host_lock);
3684 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3685 spin_unlock_irq(shost->host_lock);
3686 lpfc_can_disctmo(vport);
3687 }
3688 vport->port_state = LPFC_VPORT_READY;
3689
3690out:
3691 mempool_free(pmb, phba->mbox_mem_pool);
3692 return;
3693}
3694
James Smart21e9a0a2009-05-22 14:53:21 -04003695/**
3696 * lpfc_create_static_vport - Read HBA config region to create static vports.
3697 * @phba: pointer to lpfc hba data structure.
3698 *
3699 * This routine issue a DUMP mailbox command for config region 22 to get
3700 * the list of static vports to be created. The function create vports
3701 * based on the information returned from the HBA.
3702 **/
3703void
3704lpfc_create_static_vport(struct lpfc_hba *phba)
3705{
3706 LPFC_MBOXQ_t *pmb = NULL;
3707 MAILBOX_t *mb;
3708 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003709 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003710 struct fc_vport_identifiers vport_id;
3711 struct fc_vport *new_fc_vport;
3712 struct Scsi_Host *shost;
3713 struct lpfc_vport *vport;
3714 uint16_t offset = 0;
3715 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003716 struct lpfc_dmabuf *mp;
3717 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003718
3719 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3720 if (!pmb) {
3721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3722 "0542 lpfc_create_static_vport failed to"
3723 " allocate mailbox memory\n");
3724 return;
3725 }
James Smartcdcc2342012-08-14 14:26:35 -04003726 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003727 mb = &pmb->u.mb;
3728
3729 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3730 if (!vport_info) {
3731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3732 "0543 lpfc_create_static_vport failed to"
3733 " allocate vport_info\n");
3734 mempool_free(pmb, phba->mbox_mem_pool);
3735 return;
3736 }
3737
3738 vport_buff = (uint8_t *) vport_info;
3739 do {
James Smartcdcc2342012-08-14 14:26:35 -04003740 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003741 if (pmb->ctx_buf) {
3742 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003743 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3744 kfree(mp);
3745 }
James Smart1c6834a2009-07-19 10:01:26 -04003746 if (lpfc_dump_static_vport(phba, pmb, offset))
3747 goto out;
3748
James Smart21e9a0a2009-05-22 14:53:21 -04003749 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003750 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3751 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003752
James Smartcdcc2342012-08-14 14:26:35 -04003753 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003754 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3755 "0544 lpfc_create_static_vport failed to"
3756 " issue dump mailbox command ret 0x%x "
3757 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003758 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003759 goto out;
3760 }
3761
James Smart1c6834a2009-07-19 10:01:26 -04003762 if (phba->sli_rev == LPFC_SLI_REV4) {
3763 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003764 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003765 if (byte_count > sizeof(struct static_vport_info) -
3766 offset)
3767 byte_count = sizeof(struct static_vport_info)
3768 - offset;
3769 memcpy(vport_buff + offset, mp->virt, byte_count);
3770 offset += byte_count;
3771 } else {
3772 if (mb->un.varDmp.word_cnt >
3773 sizeof(struct static_vport_info) - offset)
3774 mb->un.varDmp.word_cnt =
3775 sizeof(struct static_vport_info)
3776 - offset;
3777 byte_count = mb->un.varDmp.word_cnt;
3778 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3779 vport_buff + offset,
3780 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003781
James Smart1c6834a2009-07-19 10:01:26 -04003782 offset += byte_count;
3783 }
James Smart21e9a0a2009-05-22 14:53:21 -04003784
James Smart1c6834a2009-07-19 10:01:26 -04003785 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003786 offset < sizeof(struct static_vport_info));
3787
3788
3789 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3790 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3791 != VPORT_INFO_REV)) {
3792 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3793 "0545 lpfc_create_static_vport bad"
3794 " information header 0x%x 0x%x\n",
3795 le32_to_cpu(vport_info->signature),
3796 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3797
3798 goto out;
3799 }
3800
3801 shost = lpfc_shost_from_vport(phba->pport);
3802
3803 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3804 memset(&vport_id, 0, sizeof(vport_id));
3805 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3806 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3807 if (!vport_id.port_name || !vport_id.node_name)
3808 continue;
3809
3810 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3811 vport_id.vport_type = FC_PORTTYPE_NPIV;
3812 vport_id.disable = false;
3813 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3814
3815 if (!new_fc_vport) {
3816 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3817 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003818 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003819 continue;
3820 }
3821
3822 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3823 vport->vport_flag |= STATIC_VPORT;
3824 }
3825
3826out:
James Smart21e9a0a2009-05-22 14:53:21 -04003827 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003828 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003829 if (pmb->ctx_buf) {
3830 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003831 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3832 kfree(mp);
3833 }
James Smart21e9a0a2009-05-22 14:53:21 -04003834 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003835 }
James Smart21e9a0a2009-05-22 14:53:21 -04003836
3837 return;
3838}
3839
dea31012005-04-17 16:05:31 -05003840/*
3841 * This routine handles processing a Fabric REG_LOGIN mailbox
3842 * command upon completion. It is setup in the LPFC_MBOXQ
3843 * as the completion routine when the command is
3844 * handed off to the SLI layer.
3845 */
3846void
James Smart2e0fef82007-06-17 19:56:36 -05003847lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003848{
James Smart92d7f7b2007-06-17 19:56:38 -05003849 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003850 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003851 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003852 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003853 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003854
James Smart3e1f0712018-11-29 16:09:29 -08003855 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3856 pmb->ctx_ndlp = NULL;
3857 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003858
dea31012005-04-17 16:05:31 -05003859 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003860 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3861 "0258 Register Fabric login error: 0x%x\n",
3862 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003863 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3864 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003865 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003866
James Smart76a95d72010-11-20 23:11:48 -05003867 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003868 /* FLOGI failed, use loop map to make discovery list */
3869 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003870
James Smart92d7f7b2007-06-17 19:56:38 -05003871 /* Start discovery */
3872 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003873 /* Decrement the reference count to ndlp after the
3874 * reference to the ndlp are done.
3875 */
3876 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003877 return;
3878 }
3879
3880 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003881 /* Decrement the reference count to ndlp after the reference
3882 * to the ndlp are done.
3883 */
3884 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003885 return;
3886 }
3887
James Smart6d368e52011-05-24 11:44:12 -04003888 if (phba->sli_rev < LPFC_SLI_REV4)
3889 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003890 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003891 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003892 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003893
James Smart2e0fef82007-06-17 19:56:36 -05003894 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003895 /* when physical port receive logo donot start
3896 * vport discovery */
3897 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3898 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003899 else {
3900 shost = lpfc_shost_from_vport(vport);
3901 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003902 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003903 spin_unlock_irq(shost->host_lock);
3904 }
James Smart92d7f7b2007-06-17 19:56:38 -05003905 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003906 }
3907
3908 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3909 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003910 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003911
3912 /* Drop the reference count from the mbox at the end after
3913 * all the current reference to the ndlp have been done.
3914 */
3915 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003916 return;
3917}
3918
James Smarta0f2d3e2017-02-12 13:52:31 -08003919 /*
3920 * This routine will issue a GID_FT for each FC4 Type supported
3921 * by the driver. ALL GID_FTs must complete before discovery is started.
3922 */
3923int
3924lpfc_issue_gidft(struct lpfc_vport *vport)
3925{
James Smarta0f2d3e2017-02-12 13:52:31 -08003926 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08003927 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3928 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003929 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3930 /* Cannot issue NameServer FCP Query, so finish up
3931 * discovery
3932 */
3933 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3934 "0604 %s FC TYPE %x %s\n",
3935 "Failed to issue GID_FT to ",
3936 FC_TYPE_FCP,
3937 "Finishing discovery.");
3938 return 0;
3939 }
3940 vport->gidft_inp++;
3941 }
3942
James Smartf6e84792019-01-28 11:14:38 -08003943 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3944 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003945 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3946 /* Cannot issue NameServer NVME Query, so finish up
3947 * discovery
3948 */
3949 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3950 "0605 %s FC_TYPE %x %s %d\n",
3951 "Failed to issue GID_FT to ",
3952 FC_TYPE_NVME,
3953 "Finishing discovery: gidftinp ",
3954 vport->gidft_inp);
3955 if (vport->gidft_inp == 0)
3956 return 0;
3957 } else
3958 vport->gidft_inp++;
3959 }
3960 return vport->gidft_inp;
3961}
3962
James Smart7ea92eb2018-10-23 13:41:10 -07003963/**
3964 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3965 * @vport: The virtual port for which this call is being executed.
3966 *
3967 * This routine will issue a GID_PT to get a list of all N_Ports
3968 *
3969 * Return value :
3970 * 0 - Failure to issue a GID_PT
3971 * 1 - GID_PT issued
3972 **/
3973int
3974lpfc_issue_gidpt(struct lpfc_vport *vport)
3975{
3976 /* Good status, issue CT Request to NameServer */
3977 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
3978 /* Cannot issue NameServer FCP Query, so finish up
3979 * discovery
3980 */
3981 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3982 "0606 %s Port TYPE %x %s\n",
3983 "Failed to issue GID_PT to ",
3984 GID_PT_N_PORT,
3985 "Finishing discovery.");
3986 return 0;
3987 }
3988 vport->gidft_inp++;
3989 return 1;
3990}
3991
dea31012005-04-17 16:05:31 -05003992/*
3993 * This routine handles processing a NameServer REG_LOGIN mailbox
3994 * command upon completion. It is setup in the LPFC_MBOXQ
3995 * as the completion routine when the command is
3996 * handed off to the SLI layer.
3997 */
3998void
James Smart2e0fef82007-06-17 19:56:36 -05003999lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004000{
James Smart21e9a0a2009-05-22 14:53:21 -04004001 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08004002 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4003 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004004 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004005
James Smart3e1f0712018-11-29 16:09:29 -08004006 pmb->ctx_buf = NULL;
4007 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004008 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004009
dea31012005-04-17 16:05:31 -05004010 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04004011 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4012 "0260 Register NameServer error: 0x%x\n",
4013 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004014
4015out:
James Smartfa4066b2008-01-11 01:53:27 -05004016 /* decrement the node reference count held for this
4017 * callback function.
4018 */
James Smart329f9bc2007-04-25 09:53:01 -04004019 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004020 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4021 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004022 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004023
4024 /* If no other thread is using the ndlp, free it */
4025 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05004026
James Smart76a95d72010-11-20 23:11:48 -05004027 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004028 /*
4029 * RegLogin failed, use loop map to make discovery
4030 * list
4031 */
4032 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004033
James Smart92d7f7b2007-06-17 19:56:38 -05004034 /* Start discovery */
4035 lpfc_disc_start(vport);
4036 return;
4037 }
4038 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004039 return;
4040 }
4041
James Smart6d368e52011-05-24 11:44:12 -04004042 if (phba->sli_rev < LPFC_SLI_REV4)
4043 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004044 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004045 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004046 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004047 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4048 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
4049 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004050 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004051 ndlp->nlp_usg_map, ndlp);
dea31012005-04-17 16:05:31 -05004052
James Smart2e0fef82007-06-17 19:56:36 -05004053 if (vport->port_state < LPFC_VPORT_READY) {
4054 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004055 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4056 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4057 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4058 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004059
James Smartf6e84792019-01-28 11:14:38 -08004060 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4061 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004062 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4063
James Smartf6e84792019-01-28 11:14:38 -08004064 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4065 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08004066 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4067 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004068
4069 /* Issue SCR just before NameServer GID_FT Query */
4070 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05004071 }
4072
James Smart2e0fef82007-06-17 19:56:36 -05004073 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004074 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004075 goto out;
dea31012005-04-17 16:05:31 -05004076
James Smarta0f2d3e2017-02-12 13:52:31 -08004077 /*
4078 * At this point in time we may need to wait for multiple
4079 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4080 *
4081 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004082 * callback function.
4083 */
James Smart329f9bc2007-04-25 09:53:01 -04004084 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004085 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4086 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004087 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004088
4089 return;
4090}
4091
4092static void
James Smart2e0fef82007-06-17 19:56:36 -05004093lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004094{
James Smart2e0fef82007-06-17 19:56:36 -05004095 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4096 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004097 struct lpfc_rport_data *rdata;
4098 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004099 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004100
James Smartf6e84792019-01-28 11:14:38 -08004101 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004102 return;
4103
dea31012005-04-17 16:05:31 -05004104 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004105 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4106 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004107 rport_ids.port_id = ndlp->nlp_DID;
4108 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004109
James Smart329f9bc2007-04-25 09:53:01 -04004110 /*
4111 * We leave our node pointer in rport->dd_data when we unregister a
4112 * FCP target port. But fc_remote_port_add zeros the space to which
4113 * rport->dd_data points. So, if we're reusing a previously
4114 * registered port, drop the reference that we took the last time we
4115 * registered the port.
4116 */
James Smart466e8402015-05-21 13:55:28 -04004117 rport = ndlp->rport;
4118 if (rport) {
4119 rdata = rport->dd_data;
4120 /* break the link before dropping the ref */
4121 ndlp->rport = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08004122 if (rdata) {
4123 if (rdata->pnode == ndlp)
4124 lpfc_nlp_put(ndlp);
4125 rdata->pnode = NULL;
4126 }
James Smart466e8402015-05-21 13:55:28 -04004127 /* drop reference for earlier registeration */
4128 put_device(&rport->dev);
4129 }
James Smart858c9f62007-06-17 19:56:39 -05004130
4131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4132 "rport add: did:x%x flg:x%x type x%x",
4133 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4134
James Smart9589b0622011-04-16 11:03:17 -04004135 /* Don't add the remote port if unloading. */
4136 if (vport->load_flag & FC_UNLOADING)
4137 return;
4138
James Smart2e0fef82007-06-17 19:56:36 -05004139 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004140 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004141 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4142 "Warning: fc_remote_port_add failed\n");
4143 return;
4144 }
4145
4146 /* initialize static port data */
4147 rport->maxframe_size = ndlp->nlp_maxframe;
4148 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004149 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004150 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004151
4152 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004153 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004154 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004155 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4156 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4157 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4158 if (ndlp->nlp_type & NLP_NVME_TARGET)
4159 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4160 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4161 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004162
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004163 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4164 fc_remote_port_rolechg(rport, rport_ids.roles);
4165
James Smart34f5ad82012-08-03 12:35:03 -04004166 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4167 "3183 rport register x%06x, rport %p role x%x\n",
4168 ndlp->nlp_DID, rport, rport_ids.roles);
4169
James Smart071fbd3d2006-04-15 11:53:20 -04004170 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004171 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004172 ndlp->nlp_sid = rport->scsi_target_id;
4173 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004174 return;
4175}
4176
4177static void
James Smart2e0fef82007-06-17 19:56:36 -05004178lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004179{
4180 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004181 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004182
James Smartf6e84792019-01-28 11:14:38 -08004183 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004184 return;
James Smartc01f3202006-08-18 17:47:08 -04004185
James Smart2ea259e2017-02-12 13:52:27 -08004186 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004187 "rport delete: did:x%x flg:x%x type x%x",
4188 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4189
James Smart2ea259e2017-02-12 13:52:27 -08004190 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart34f5ad82012-08-03 12:35:03 -04004191 "3184 rport unregister x%06x, rport %p\n",
4192 ndlp->nlp_DID, rport);
4193
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004194 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004195
4196 return;
4197}
4198
James Smartde0c5b32007-04-25 09:52:27 -04004199static void
James Smart2e0fef82007-06-17 19:56:36 -05004200lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004201{
James Smart2e0fef82007-06-17 19:56:36 -05004202 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart894bb172019-08-14 16:56:52 -07004203 unsigned long iflags;
James Smart2e0fef82007-06-17 19:56:36 -05004204
James Smart894bb172019-08-14 16:56:52 -07004205 spin_lock_irqsave(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004206 switch (state) {
4207 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004208 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004209 break;
4210 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004211 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004212 break;
4213 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004214 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004215 break;
4216 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004217 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004218 break;
4219 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004220 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004221 break;
4222 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004223 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004224 break;
4225 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004226 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004227 break;
4228 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004229 if (vport->fc_npr_cnt == 0 && count == -1)
4230 vport->fc_npr_cnt = 0;
4231 else
4232 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004233 break;
4234 }
James Smart894bb172019-08-14 16:56:52 -07004235 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smartde0c5b32007-04-25 09:52:27 -04004236}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004237
James Smartde0c5b32007-04-25 09:52:27 -04004238static void
James Smart2e0fef82007-06-17 19:56:36 -05004239lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004240 int old_state, int new_state)
4241{
James Smart2e0fef82007-06-17 19:56:36 -05004242 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4243
James Smartde0c5b32007-04-25 09:52:27 -04004244 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004245 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4246 ndlp->nlp_type |= NLP_FC_NODE;
4247 }
4248 if (new_state == NLP_STE_MAPPED_NODE)
4249 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4250 if (new_state == NLP_STE_NPR_NODE)
4251 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004252
James Smarta0f2d3e2017-02-12 13:52:31 -08004253 /* FCP and NVME Transport interface */
4254 if ((old_state == NLP_STE_MAPPED_NODE ||
4255 old_state == NLP_STE_UNMAPPED_NODE)) {
4256 if (ndlp->rport) {
4257 vport->phba->nport_event_cnt++;
4258 lpfc_unregister_remote_port(ndlp);
4259 }
4260
James Smart1c5b12f2017-04-21 16:05:03 -07004261 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004262 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004263 if (vport->phba->nvmet_support == 0) {
4264 /* Start devloss if target. */
4265 if (ndlp->nlp_type & NLP_NVME_TARGET)
4266 lpfc_nvme_unregister_port(vport, ndlp);
4267 } else {
James Smart6599e122017-06-01 21:07:00 -07004268 /* NVMET has no upcall. */
4269 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004270 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004271 }
James Smartde0c5b32007-04-25 09:52:27 -04004272 }
dea31012005-04-17 16:05:31 -05004273
James Smarta0f2d3e2017-02-12 13:52:31 -08004274 /* FCP and NVME Transport interfaces */
4275
James Smartde0c5b32007-04-25 09:52:27 -04004276 if (new_state == NLP_STE_MAPPED_NODE ||
4277 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart01a8aed2018-09-10 10:30:41 -07004278 if (ndlp->nlp_fc4_type ||
James Smart92721c32017-06-01 21:06:59 -07004279 ndlp->nlp_DID == Fabric_DID ||
4280 ndlp->nlp_DID == NameServer_DID ||
4281 ndlp->nlp_DID == FDMI_DID) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004282 vport->phba->nport_event_cnt++;
4283 /*
4284 * Tell the fc transport about the port, if we haven't
4285 * already. If we have, and it's a scsi entity, be
4286 */
4287 lpfc_register_remote_port(vport, ndlp);
4288 }
4289 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004290 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4291 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004292 if (vport->phba->nvmet_support == 0) {
4293 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004294 * Only NVME Target Rports are registered with
4295 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004296 */
James Smart3b5bde692017-11-20 16:00:39 -08004297 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4298 vport->phba->nport_event_cnt++;
4299 lpfc_nvme_register_port(vport, ndlp);
4300 }
James Smart8c258642017-02-12 13:52:36 -08004301 } else {
4302 /* Just take an NDLP ref count since the
4303 * target does not register rports.
4304 */
4305 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004306 }
4307 }
James Smartde0c5b32007-04-25 09:52:27 -04004308 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004309
James Smartea2151b2008-09-07 11:52:10 -04004310 if ((new_state == NLP_STE_MAPPED_NODE) &&
4311 (vport->stat_data_enabled)) {
4312 /*
4313 * A new target is discovered, if there is no buffer for
4314 * statistical data collection allocate buffer.
4315 */
4316 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4317 sizeof(struct lpfc_scsicmd_bkt),
4318 GFP_KERNEL);
4319
4320 if (!ndlp->lat_data)
4321 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4322 "0286 lpfc_nlp_state_cleanup failed to "
4323 "allocate statistical data buffer DID "
4324 "0x%x\n", ndlp->nlp_DID);
4325 }
James Smart858c9f62007-06-17 19:56:39 -05004326 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004327 * If the node just added to Mapped list was an FCP target,
4328 * but the remote port registration failed or assigned a target
4329 * id outside the presentable range - move the node to the
4330 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004331 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004332 if ((new_state == NLP_STE_MAPPED_NODE) &&
4333 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004334 (!ndlp->rport ||
4335 ndlp->rport->scsi_target_id == -1 ||
4336 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004337 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004338 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004339 spin_unlock_irq(shost->host_lock);
4340 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004341 }
James Smartde0c5b32007-04-25 09:52:27 -04004342}
4343
James Smart685f0bf2007-04-25 09:53:08 -04004344static char *
4345lpfc_nlp_state_name(char *buffer, size_t size, int state)
4346{
4347 static char *states[] = {
4348 [NLP_STE_UNUSED_NODE] = "UNUSED",
4349 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4350 [NLP_STE_ADISC_ISSUE] = "ADISC",
4351 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4352 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004353 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004354 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4355 [NLP_STE_MAPPED_NODE] = "MAPPED",
4356 [NLP_STE_NPR_NODE] = "NPR",
4357 };
4358
James Smart311464e2007-08-02 11:10:37 -04004359 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004360 strlcpy(buffer, states[state], size);
4361 else
4362 snprintf(buffer, size, "unknown (%d)", state);
4363 return buffer;
4364}
4365
James Smartde0c5b32007-04-25 09:52:27 -04004366void
James Smart2e0fef82007-06-17 19:56:36 -05004367lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4368 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004369{
James Smart2e0fef82007-06-17 19:56:36 -05004370 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004371 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004372 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004373
James Smarte8b62012007-08-02 11:10:09 -04004374 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4375 "0904 NPort state transition x%06x, %s -> %s\n",
4376 ndlp->nlp_DID,
4377 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4378 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004379
4380 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4381 "node statechg did:x%x old:%d ste:%d",
4382 ndlp->nlp_DID, old_state, state);
4383
James Smartde0c5b32007-04-25 09:52:27 -04004384 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004385 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004386 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004387 if (old_state == NLP_STE_UNMAPPED_NODE) {
4388 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4389 ndlp->nlp_type &= ~NLP_FC_NODE;
4390 }
4391
James Smart685f0bf2007-04-25 09:53:08 -04004392 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004393 spin_lock_irq(shost->host_lock);
4394 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4395 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004396 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004397 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004398
4399 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004400 lpfc_nlp_counters(vport, state, 1);
4401 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004402}
4403
4404void
James Smarte47c9092008-02-08 18:49:26 -05004405lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4406{
4407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4408
4409 if (list_empty(&ndlp->nlp_listp)) {
4410 spin_lock_irq(shost->host_lock);
4411 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4412 spin_unlock_irq(shost->host_lock);
4413 }
4414}
4415
4416void
James Smart2e0fef82007-06-17 19:56:36 -05004417lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004418{
James Smart2e0fef82007-06-17 19:56:36 -05004419 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4420
James Smart0d2b6b82008-06-14 22:52:47 -04004421 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004422 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004423 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4424 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004425 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004426 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004427 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004428 NLP_STE_UNUSED_NODE);
4429}
4430
Adrian Bunk4d9db012008-02-14 23:24:02 +02004431static void
James Smarte47c9092008-02-08 18:49:26 -05004432lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4433{
James Smart0d2b6b82008-06-14 22:52:47 -04004434 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004435 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4436 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4437 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4438 NLP_STE_UNUSED_NODE);
4439}
James Smart109f6ed2008-12-04 22:39:08 -05004440/**
James Smart3621a712009-04-06 18:47:14 -04004441 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004442 * @vport: Pointer to Virtual Port object.
4443 * @ndlp: Pointer to FC node object.
4444 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004445 *
4446 * This function is always called when node object need to be initialized.
4447 * It initializes all the fields of the node object. Although the reference
4448 * to phba from @ndlp can be obtained indirectly through it's reference to
4449 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4450 * to the life-span of the @ndlp might go beyond the existence of @vport as
4451 * the final release of ndlp is determined by its reference count. And, the
4452 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004453 **/
4454static inline void
4455lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4456 uint32_t did)
4457{
4458 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4459 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004460 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smart109f6ed2008-12-04 22:39:08 -05004461 ndlp->nlp_DID = did;
4462 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004463 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004464 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004465 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004466 kref_init(&ndlp->kref);
4467 NLP_INT_NODE_ACT(ndlp);
4468 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004469 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004470 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004471}
James Smarte47c9092008-02-08 18:49:26 -05004472
4473struct lpfc_nodelist *
4474lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4475 int state)
4476{
4477 struct lpfc_hba *phba = vport->phba;
James Smartdea16bd2018-11-29 16:09:30 -08004478 uint32_t did, flag;
James Smarte47c9092008-02-08 18:49:26 -05004479 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004480 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart9d3d3402017-04-21 16:05:00 -07004481 int rpi = LPFC_RPI_ALLOC_ERROR;
James Smartdea16bd2018-11-29 16:09:30 -08004482 uint32_t defer_did = 0;
James Smarte47c9092008-02-08 18:49:26 -05004483
4484 if (!ndlp)
4485 return NULL;
4486
James Smart9d3d3402017-04-21 16:05:00 -07004487 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smartb95b2112019-08-14 16:56:47 -07004488 if (ndlp->nlp_rpi == LPFC_RPI_ALLOC_ERROR)
4489 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4490 else
4491 rpi = ndlp->nlp_rpi;
4492
4493 if (rpi == LPFC_RPI_ALLOC_ERROR) {
4494 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4495 "0359 %s: ndlp:x%px "
4496 "usgmap:x%x refcnt:%d FAILED RPI "
4497 " ALLOC\n",
4498 __func__,
4499 (void *)ndlp, ndlp->nlp_usg_map,
4500 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004501 return NULL;
James Smartb95b2112019-08-14 16:56:47 -07004502 }
James Smart9d3d3402017-04-21 16:05:00 -07004503 }
4504
James Smarte47c9092008-02-08 18:49:26 -05004505 spin_lock_irqsave(&phba->ndlp_lock, flags);
4506 /* The ndlp should not be in memory free mode */
4507 if (NLP_CHK_FREE_REQ(ndlp)) {
4508 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4509 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4510 "0277 lpfc_enable_node: ndlp:x%p "
4511 "usgmap:x%x refcnt:%d\n",
4512 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004513 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004514 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004515 }
4516 /* The ndlp should not already be in active mode */
4517 if (NLP_CHK_NODE_ACT(ndlp)) {
4518 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4519 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4520 "0278 lpfc_enable_node: ndlp:x%p "
4521 "usgmap:x%x refcnt:%d\n",
4522 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004523 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004524 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004525 }
4526
James Smartdea16bd2018-11-29 16:09:30 -08004527 /* First preserve the orginal DID, xri_bitmap and some flags */
James Smarte47c9092008-02-08 18:49:26 -05004528 did = ndlp->nlp_DID;
James Smartdea16bd2018-11-29 16:09:30 -08004529 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4530 if (flag & NLP_UNREG_INP)
4531 defer_did = ndlp->nlp_defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004532 if (phba->sli_rev == LPFC_SLI_REV4)
4533 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004534
James Smartdea16bd2018-11-29 16:09:30 -08004535 /* Zero ndlp except of ndlp linked list pointer */
James Smarte47c9092008-02-08 18:49:26 -05004536 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4537 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smarte47c9092008-02-08 18:49:26 -05004538
James Smartdea16bd2018-11-29 16:09:30 -08004539 /* Next reinitialize and restore saved objects */
4540 lpfc_initialize_node(vport, ndlp, did);
4541 ndlp->nlp_flag |= flag;
4542 if (flag & NLP_UNREG_INP)
4543 ndlp->nlp_defer_did = defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004544 if (phba->sli_rev == LPFC_SLI_REV4)
4545 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4546
James Smarte47c9092008-02-08 18:49:26 -05004547 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smartbe6bb942015-04-07 15:07:22 -04004548 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07004549 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04004550 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4551 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4552 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4553 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004554 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004555 ndlp->nlp_usg_map, ndlp);
4556 }
James Smart725dd392013-10-10 12:23:30 -04004557
James Smarte47c9092008-02-08 18:49:26 -05004558
4559 if (state != NLP_STE_UNUSED_NODE)
4560 lpfc_nlp_set_state(vport, ndlp, state);
James Smartb95b2112019-08-14 16:56:47 -07004561 else
4562 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4563 "0013 rpi:%x DID:%x flg:%x refcnt:%d "
4564 "map:%x x%px STATE=UNUSED\n",
4565 ndlp->nlp_rpi, ndlp->nlp_DID,
4566 ndlp->nlp_flag,
4567 kref_read(&ndlp->kref),
4568 ndlp->nlp_usg_map, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004569
4570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4571 "node enable: did:x%x",
4572 ndlp->nlp_DID, 0, 0);
4573 return ndlp;
James Smart9d3d3402017-04-21 16:05:00 -07004574
4575free_rpi:
4576 if (phba->sli_rev == LPFC_SLI_REV4)
4577 lpfc_sli4_free_rpi(vport->phba, rpi);
4578 return NULL;
James Smartde0c5b32007-04-25 09:52:27 -04004579}
4580
4581void
James Smart2e0fef82007-06-17 19:56:36 -05004582lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004583{
James Smart87af33f2007-10-27 13:37:43 -04004584 /*
James Smartfa4066b2008-01-11 01:53:27 -05004585 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004586 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004587 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4588 * until ALL other outstanding threads have completed. We check
4589 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004590 */
James Smartfa4066b2008-01-11 01:53:27 -05004591 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4592 return;
James Smart51ef4c22007-08-02 11:10:31 -04004593 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004594 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004595 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004596 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004597 }
James Smart02902172015-05-21 13:55:17 -04004598
4599 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004600 return;
dea31012005-04-17 16:05:31 -05004601}
4602
4603/*
4604 * Start / ReStart rescue timer for Discovery / RSCN handling
4605 */
4606void
James Smart2e0fef82007-06-17 19:56:36 -05004607lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004608{
James Smart2e0fef82007-06-17 19:56:36 -05004609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4610 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004611 uint32_t tmo;
4612
James Smart2e0fef82007-06-17 19:56:36 -05004613 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004614 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004615 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4616 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004617 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004618 * FC spec states we need 3 * ratov for CT requests
4619 */
4620 tmo = ((phba->fc_ratov * 3) + 3);
4621 }
dea31012005-04-17 16:05:31 -05004622
James Smart858c9f62007-06-17 19:56:39 -05004623
4624 if (!timer_pending(&vport->fc_disctmo)) {
4625 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4626 "set disc timer: tmo:x%x state:x%x flg:x%x",
4627 tmo, vport->port_state, vport->fc_flag);
4628 }
4629
James Smart256ec0d2013-04-17 20:14:58 -04004630 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004631 spin_lock_irq(shost->host_lock);
4632 vport->fc_flag |= FC_DISC_TMO;
4633 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004634
4635 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004636 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4637 "0247 Start Discovery Timer state x%x "
4638 "Data: x%x x%lx x%x x%x\n",
4639 vport->port_state, tmo,
4640 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4641 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004642
4643 return;
4644}
4645
4646/*
4647 * Cancel rescue timer for Discovery / RSCN handling
4648 */
4649int
James Smart2e0fef82007-06-17 19:56:36 -05004650lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004651{
James Smart2e0fef82007-06-17 19:56:36 -05004652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004653 unsigned long iflags;
4654
James Smart858c9f62007-06-17 19:56:39 -05004655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4656 "can disc timer: state:x%x rtry:x%x flg:x%x",
4657 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4658
dea31012005-04-17 16:05:31 -05004659 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004660 if (vport->fc_flag & FC_DISC_TMO) {
4661 spin_lock_irqsave(shost->host_lock, iflags);
4662 vport->fc_flag &= ~FC_DISC_TMO;
4663 spin_unlock_irqrestore(shost->host_lock, iflags);
4664 del_timer_sync(&vport->fc_disctmo);
4665 spin_lock_irqsave(&vport->work_port_lock, iflags);
4666 vport->work_port_events &= ~WORKER_DISC_TMO;
4667 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004668 }
4669
4670 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004671 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4672 "0248 Cancel Discovery Timer state x%x "
4673 "Data: x%x x%x x%x\n",
4674 vport->port_state, vport->fc_flag,
4675 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004676 return 0;
dea31012005-04-17 16:05:31 -05004677}
4678
4679/*
4680 * Check specified ring for outstanding IOCB on the SLI queue
4681 * Return true if iocb matches the specified nport
4682 */
4683int
James Smart2e0fef82007-06-17 19:56:36 -05004684lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4685 struct lpfc_sli_ring *pring,
4686 struct lpfc_iocbq *iocb,
4687 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004688{
James Smart2e0fef82007-06-17 19:56:36 -05004689 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004690 struct lpfc_vport *vport = ndlp->vport;
4691
4692 if (iocb->vport != vport)
4693 return 0;
4694
dea31012005-04-17 16:05:31 -05004695 if (pring->ringno == LPFC_ELS_RING) {
4696 switch (icmd->ulpCommand) {
4697 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004698 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004699 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004700 /* fall through */
dea31012005-04-17 16:05:31 -05004701 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004702 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4703 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004704 /* fall through */
dea31012005-04-17 16:05:31 -05004705 case CMD_XMIT_ELS_RSP64_CX:
4706 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004707 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004708 /* fall through */
dea31012005-04-17 16:05:31 -05004709 }
James Smart895427b2017-02-12 13:52:30 -08004710 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004711 /* Skip match check if waiting to relogin to FCP target */
4712 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004713 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004714 return 0;
dea31012005-04-17 16:05:31 -05004715 }
4716 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004717 return 1;
dea31012005-04-17 16:05:31 -05004718 }
dea31012005-04-17 16:05:31 -05004719 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004720 return 0;
dea31012005-04-17 16:05:31 -05004721}
4722
James Smart895427b2017-02-12 13:52:30 -08004723static void
4724__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4725 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4726 struct list_head *dequeue_list)
4727{
4728 struct lpfc_iocbq *iocb, *next_iocb;
4729
4730 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4731 /* Check to see if iocb matches the nport */
4732 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4733 /* match, dequeue */
4734 list_move_tail(&iocb->list, dequeue_list);
4735 }
4736}
4737
4738static void
4739lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4740 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4741{
4742 struct lpfc_sli *psli = &phba->sli;
4743 uint32_t i;
4744
4745 spin_lock_irq(&phba->hbalock);
4746 for (i = 0; i < psli->num_rings; i++)
4747 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4748 dequeue_list);
4749 spin_unlock_irq(&phba->hbalock);
4750}
4751
4752static void
4753lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4754 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4755{
4756 struct lpfc_sli_ring *pring;
4757 struct lpfc_queue *qp = NULL;
4758
4759 spin_lock_irq(&phba->hbalock);
4760 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4761 pring = qp->pring;
4762 if (!pring)
4763 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004764 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004765 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004766 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004767 }
4768 spin_unlock_irq(&phba->hbalock);
4769}
4770
dea31012005-04-17 16:05:31 -05004771/*
4772 * Free resources / clean up outstanding I/Os
4773 * associated with nlp_rpi in the LPFC_NODELIST entry.
4774 */
4775static int
James Smart2e0fef82007-06-17 19:56:36 -05004776lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004777{
James Smart2534ba72007-04-25 09:52:20 -04004778 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004779
James Smart92d7f7b2007-06-17 19:56:38 -05004780 lpfc_fabric_abort_nport(ndlp);
4781
dea31012005-04-17 16:05:31 -05004782 /*
4783 * Everything that matches on txcmplq will be returned
4784 * by firmware with a no rpi error.
4785 */
James Smart40426292010-12-15 17:58:10 -05004786 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004787 if (phba->sli_rev != LPFC_SLI_REV4)
4788 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4789 else
4790 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004791 }
James Smart2534ba72007-04-25 09:52:20 -04004792
James Smarta257bf92009-04-06 18:48:10 -04004793 /* Cancel all the IOCBs from the completions list */
4794 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4795 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004796
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004797 return 0;
dea31012005-04-17 16:05:31 -05004798}
4799
James Smart086a3452012-08-14 14:25:21 -04004800/**
4801 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4802 * @phba: Pointer to HBA context object.
4803 * @pmb: Pointer to mailbox object.
4804 *
4805 * This function will issue an ELS LOGO command after completing
4806 * the UNREG_RPI.
4807 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004808static void
James Smart086a3452012-08-14 14:25:21 -04004809lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4810{
4811 struct lpfc_vport *vport = pmb->vport;
4812 struct lpfc_nodelist *ndlp;
4813
James Smart3e1f0712018-11-29 16:09:29 -08004814 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004815 if (!ndlp)
4816 return;
4817 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004818 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004819
4820 /* Check to see if there are any deferred events to process */
4821 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4822 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4823 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4824 "1434 UNREG cmpl deferred logo x%x "
4825 "on NPort x%x Data: x%x %p\n",
4826 ndlp->nlp_rpi, ndlp->nlp_DID,
4827 ndlp->nlp_defer_did, ndlp);
4828
4829 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4830 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4831 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08004832 } else {
James Smart4f1a2fe2019-08-14 16:56:32 -07004833 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
4834 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
4835 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
4836 }
James Smart00292e02018-12-13 15:17:55 -08004837 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smartdea16bd2018-11-29 16:09:30 -08004838 }
James Smart086a3452012-08-14 14:25:21 -04004839}
4840
dea31012005-04-17 16:05:31 -05004841/*
4842 * Free rpi associated with LPFC_NODELIST entry.
4843 * This routine is called from lpfc_freenode(), when we are removing
4844 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4845 * LOGO that completes successfully, and we are waiting to PLOGI back
4846 * to the remote NPort. In addition, it is called after we receive
4847 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4848 * we are waiting to PLOGI back to the remote NPort.
4849 */
4850int
James Smart2e0fef82007-06-17 19:56:36 -05004851lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004852{
James Smart2e0fef82007-06-17 19:56:36 -05004853 struct lpfc_hba *phba = vport->phba;
4854 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004855 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004856 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004857
James Smartf454a9a2013-09-06 12:20:07 -04004858 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4859 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4860 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4861 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4862 "3366 RPI x%x needs to be "
4863 "unregistered nlp_flag x%x "
4864 "did x%x\n",
4865 ndlp->nlp_rpi, ndlp->nlp_flag,
4866 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004867
4868 /* If there is already an UNREG in progress for this ndlp,
4869 * no need to queue up another one.
4870 */
4871 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4872 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4873 "1436 unreg_rpi SKIP UNREG x%x on "
4874 "NPort x%x deferred x%x flg x%x "
4875 "Data: %p\n",
4876 ndlp->nlp_rpi, ndlp->nlp_DID,
4877 ndlp->nlp_defer_did,
4878 ndlp->nlp_flag, ndlp);
4879 goto out;
4880 }
4881
James Smart2e0fef82007-06-17 19:56:36 -05004882 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4883 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004884 /* SLI4 ports require the physical rpi value. */
4885 rpi = ndlp->nlp_rpi;
4886 if (phba->sli_rev == LPFC_SLI_REV4)
4887 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004888
James Smart6d368e52011-05-24 11:44:12 -04004889 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004890 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004891 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
James Smart3e1f0712018-11-29 16:09:29 -08004892 mbox->ctx_ndlp = ndlp;
James Smart086a3452012-08-14 14:25:21 -04004893 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4894 } else {
James Smartbe6bb942015-04-07 15:07:22 -04004895 if (phba->sli_rev == LPFC_SLI_REV4 &&
4896 (!(vport->load_flag & FC_UNLOADING)) &&
4897 (bf_get(lpfc_sli_intf_if_type,
James Smart719162b2018-12-10 19:37:01 -08004898 &phba->sli4_hba.sli_intf) >=
James Smarta6517db2016-03-31 14:12:29 -07004899 LPFC_SLI_INTF_IF_TYPE_2) &&
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004900 (kref_read(&ndlp->kref) > 0)) {
James Smart3e1f0712018-11-29 16:09:29 -08004901 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004902 mbox->mbox_cmpl =
4903 lpfc_sli4_unreg_rpi_cmpl_clr;
James Smart7c5e5182015-05-22 10:42:43 -04004904 /*
4905 * accept PLOGIs after unreg_rpi_cmpl
4906 */
4907 acc_plogi = 0;
James Smart9b164062019-03-12 16:30:06 -07004908 } else if (vport->load_flag & FC_UNLOADING) {
4909 mbox->ctx_ndlp = NULL;
4910 mbox->mbox_cmpl =
4911 lpfc_sli_def_mbox_cmpl;
James Smartdea16bd2018-11-29 16:09:30 -08004912 } else {
4913 mbox->ctx_ndlp = ndlp;
James Smartbe6bb942015-04-07 15:07:22 -04004914 mbox->mbox_cmpl =
4915 lpfc_sli_def_mbox_cmpl;
James Smartdea16bd2018-11-29 16:09:30 -08004916 }
James Smart086a3452012-08-14 14:25:21 -04004917 }
James Smartdea16bd2018-11-29 16:09:30 -08004918 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4919 Fabric_DID_MASK) &&
4920 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4921 ndlp->nlp_flag |= NLP_UNREG_INP;
4922
4923 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4924 "1433 unreg_rpi UNREG x%x on "
4925 "NPort x%x deferred flg x%x Data:%p\n",
4926 ndlp->nlp_rpi, ndlp->nlp_DID,
4927 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004928
James Smart0b727fe2007-10-27 13:37:25 -04004929 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004930 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004931 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004932 acc_plogi = 1;
4933 }
dea31012005-04-17 16:05:31 -05004934 }
dea31012005-04-17 16:05:31 -05004935 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004936out:
James Smart40426292010-12-15 17:58:10 -05004937 if (phba->sli_rev != LPFC_SLI_REV4)
4938 ndlp->nlp_rpi = 0;
4939 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004940 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004941 if (acc_plogi)
4942 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004943 return 1;
4944 }
James Smart7c5e5182015-05-22 10:42:43 -04004945 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004946 return 0;
4947}
4948
James Smartecfd03c2010-02-12 14:41:27 -05004949/**
4950 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4951 * @phba: pointer to lpfc hba data structure.
4952 *
4953 * This routine is invoked to unregister all the currently registered RPIs
4954 * to the HBA.
4955 **/
4956void
4957lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4958{
4959 struct lpfc_vport **vports;
4960 struct lpfc_nodelist *ndlp;
4961 struct Scsi_Host *shost;
4962 int i;
4963
4964 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004965 if (!vports) {
4966 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4967 "2884 Vport array allocation failed \n");
4968 return;
4969 }
James Smartecfd03c2010-02-12 14:41:27 -05004970 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4971 shost = lpfc_shost_from_vport(vports[i]);
4972 spin_lock_irq(shost->host_lock);
4973 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004974 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004975 /* The mempool_alloc might sleep */
4976 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004977 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004978 spin_lock_irq(shost->host_lock);
4979 }
James Smartecfd03c2010-02-12 14:41:27 -05004980 }
4981 spin_unlock_irq(shost->host_lock);
4982 }
4983 lpfc_destroy_vport_work_array(phba, vports);
4984}
4985
James Smart92d7f7b2007-06-17 19:56:38 -05004986void
4987lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4988{
4989 struct lpfc_hba *phba = vport->phba;
4990 LPFC_MBOXQ_t *mbox;
4991 int rc;
4992
James Smart5af5eee2010-10-22 11:06:38 -04004993 if (phba->sli_rev == LPFC_SLI_REV4) {
4994 lpfc_sli4_unreg_all_rpis(vport);
4995 return;
4996 }
4997
James Smart92d7f7b2007-06-17 19:56:38 -05004998 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4999 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005000 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5001 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005002 mbox->vport = vport;
5003 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005004 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005005 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005006 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005007 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04005008
5009 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5011 "1836 Could not issue "
5012 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005013 }
5014}
5015
5016void
5017lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5018{
5019 struct lpfc_hba *phba = vport->phba;
5020 LPFC_MBOXQ_t *mbox;
5021 int rc;
5022
James Smartc95a3b42019-03-12 16:30:07 -07005023 /* Unreg DID is an SLI3 operation. */
5024 if (phba->sli_rev > LPFC_SLI_REV3)
5025 return;
5026
James Smart92d7f7b2007-06-17 19:56:38 -05005027 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5028 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04005029 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5030 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005031 mbox->vport = vport;
5032 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08005033 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05005034 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04005035 if (rc != MBX_TIMEOUT)
5036 mempool_free(mbox, phba->mbox_mem_pool);
5037
5038 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04005039 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5040 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005041 "unreg_did (default rpis) status %d\n",
5042 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005043 }
5044}
5045
dea31012005-04-17 16:05:31 -05005046/*
5047 * Free resources associated with LPFC_NODELIST entry
5048 * so it can be freed.
5049 */
5050static int
James Smart2e0fef82007-06-17 19:56:36 -05005051lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005052{
James Smart2e0fef82007-06-17 19:56:36 -05005053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5054 struct lpfc_hba *phba = vport->phba;
5055 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005056 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05005057
5058 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005059 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5060 "0900 Cleanup node for NPort x%x "
5061 "Data: x%x x%x x%x\n",
5062 ndlp->nlp_DID, ndlp->nlp_flag,
5063 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005064 if (NLP_CHK_FREE_REQ(ndlp)) {
5065 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5066 "0280 lpfc_cleanup_node: ndlp:x%p "
5067 "usgmap:x%x refcnt:%d\n",
5068 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005069 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005070 lpfc_dequeue_node(vport, ndlp);
5071 } else {
5072 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5073 "0281 lpfc_cleanup_node: ndlp:x%p "
5074 "usgmap:x%x refcnt:%d\n",
5075 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005076 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005077 lpfc_disable_node(vport, ndlp);
5078 }
dea31012005-04-17 16:05:31 -05005079
James Smart086a3452012-08-14 14:25:21 -04005080
5081 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5082
dea31012005-04-17 16:05:31 -05005083 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5084 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005085 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005086 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005087 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5088 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005089 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5090 }
5091 }
James Smart33ccf8d2006-08-17 11:57:58 -04005092
James Smart2e0fef82007-06-17 19:56:36 -05005093 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005094 /* Cleanup REG_LOGIN completions which are not yet processed */
5095 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5096 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005097 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005098 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005099 continue;
5100
James Smart3e1f0712018-11-29 16:09:29 -08005101 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005102 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5103 }
5104
dea31012005-04-17 16:05:31 -05005105 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005106 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005107 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005108 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5109 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005110 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005111 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005112 kfree(mp);
5113 }
5114 list_del(&mb->list);
5115 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005116 /* We shall not invoke the lpfc_nlp_put to decrement
5117 * the ndlp reference count as we are in the process
5118 * of lpfc_nlp_release.
5119 */
dea31012005-04-17 16:05:31 -05005120 }
5121 }
James Smart2e0fef82007-06-17 19:56:36 -05005122 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005123
James Smarte47c9092008-02-08 18:49:26 -05005124 lpfc_els_abort(phba, ndlp);
5125
James Smart2e0fef82007-06-17 19:56:36 -05005126 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04005127 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05005128 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005129
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005130 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005131 del_timer_sync(&ndlp->nlp_delayfunc);
5132
James Smart0d2b6b82008-06-14 22:52:47 -04005133 list_del_init(&ndlp->els_retry_evt.evt_listp);
5134 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005135 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart4f1a2fe2019-08-14 16:56:32 -07005136 if (phba->sli_rev == LPFC_SLI_REV4)
5137 ndlp->nlp_flag |= NLP_RELEASE_RPI;
James Smart2e0fef82007-06-17 19:56:36 -05005138 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05005139
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005140 return 0;
dea31012005-04-17 16:05:31 -05005141}
5142
5143/*
5144 * Check to see if we can free the nlp back to the freelist.
5145 * If we are in the middle of using the nlp in the discovery state
5146 * machine, defer the free till we reach the end of the state machine.
5147 */
James Smart329f9bc2007-04-25 09:53:01 -04005148static void
James Smart2e0fef82007-06-17 19:56:36 -05005149lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005150{
James Smarta8adb832007-10-27 13:37:53 -04005151 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04005152 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04005153 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04005154 LPFC_MBOXQ_t *mbox;
5155 int rc;
dea31012005-04-17 16:05:31 -05005156
James Smart0d2b6b82008-06-14 22:52:47 -04005157 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04005158 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05005159 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
Dick Kennedye8bcf0a2017-09-29 17:34:32 -07005160 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5161 phba->sli_rev != LPFC_SLI_REV4) {
James Smarta8adb832007-10-27 13:37:53 -04005162 /* For this case we need to cleanup the default rpi
5163 * allocated by the firmware.
5164 */
James Smartbe6bb942015-04-07 15:07:22 -04005165 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5166 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5167 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005168 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005169 ndlp->nlp_usg_map, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04005170 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5171 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04005172 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05005173 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04005174 if (rc) {
5175 mempool_free(mbox, phba->mbox_mem_pool);
5176 }
5177 else {
5178 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5179 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5180 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08005181 mbox->ctx_ndlp = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04005182 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5183 if (rc == MBX_NOT_FINISHED) {
5184 mempool_free(mbox, phba->mbox_mem_pool);
5185 }
5186 }
5187 }
5188 }
James Smart2e0fef82007-06-17 19:56:36 -05005189 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04005190
James Smart2e0fef82007-06-17 19:56:36 -05005191 /*
James Smart466e8402015-05-21 13:55:28 -04005192 * ndlp->rport must be set to NULL before it reaches here
5193 * i.e. break rport/node link before doing lpfc_nlp_put for
5194 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05005195 */
James Smart92d7f7b2007-06-17 19:56:38 -05005196 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04005197 /*
5198 * extra lpfc_nlp_put dropped the reference of ndlp
5199 * for registered rport so need to cleanup rport
5200 */
5201 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5202 "0940 removed node x%p DID x%x "
5203 " rport not null %p\n",
5204 ndlp, ndlp->nlp_DID, ndlp->rport);
5205 rport = ndlp->rport;
5206 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04005207 rdata->pnode = NULL;
5208 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04005209 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05005210 }
dea31012005-04-17 16:05:31 -05005211}
5212
5213static int
James Smart2e0fef82007-06-17 19:56:36 -05005214lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5215 uint32_t did)
dea31012005-04-17 16:05:31 -05005216{
James Smart2e0fef82007-06-17 19:56:36 -05005217 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005218
5219 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005220 return 0;
dea31012005-04-17 16:05:31 -05005221
dea31012005-04-17 16:05:31 -05005222 /* First check for Direct match */
5223 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005224 return 1;
dea31012005-04-17 16:05:31 -05005225
5226 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005227 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005228 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005229 return 0;
dea31012005-04-17 16:05:31 -05005230 }
5231
5232 matchdid.un.word = did;
5233 ndlpdid.un.word = ndlp->nlp_DID;
5234 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5235 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5236 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005237 /* This code is supposed to match the ID
5238 * for a private loop device that is
5239 * connect to fl_port. But we need to
5240 * check that the port did not just go
5241 * from pt2pt to fabric or we could end
5242 * up matching ndlp->nlp_DID 000001 to
5243 * fabric DID 0x20101
5244 */
dea31012005-04-17 16:05:31 -05005245 if ((ndlpdid.un.b.domain == 0) &&
5246 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005247 if (ndlpdid.un.b.id &&
5248 vport->phba->fc_topology ==
5249 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005250 return 1;
dea31012005-04-17 16:05:31 -05005251 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005252 return 0;
dea31012005-04-17 16:05:31 -05005253 }
5254
5255 matchdid.un.word = ndlp->nlp_DID;
5256 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5257 (mydid.un.b.area == ndlpdid.un.b.area)) {
5258 if ((matchdid.un.b.domain == 0) &&
5259 (matchdid.un.b.area == 0)) {
5260 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005261 return 1;
dea31012005-04-17 16:05:31 -05005262 }
5263 }
5264 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005265 return 0;
dea31012005-04-17 16:05:31 -05005266}
5267
James Smart685f0bf2007-04-25 09:53:08 -04005268/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005269static struct lpfc_nodelist *
5270__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005271{
James Smart2fb9bd82006-12-02 13:33:57 -05005272 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005273 uint32_t data1;
5274
James Smart2e0fef82007-06-17 19:56:36 -05005275 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5276 if (lpfc_matchdid(vport, ndlp, did)) {
James Smartb95b2112019-08-14 16:56:47 -07005277 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5278 ((uint32_t)ndlp->nlp_xri << 16) |
5279 ((uint32_t)ndlp->nlp_type << 8) |
5280 ((uint32_t)ndlp->nlp_usg_map & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04005281 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5282 "0929 FIND node DID "
James Smartb95b2112019-08-14 16:56:47 -07005283 "Data: x%px x%x x%x x%x x%x x%px\n",
James Smarte8b62012007-08-02 11:10:09 -04005284 ndlp, ndlp->nlp_DID,
James Smartb95b2112019-08-14 16:56:47 -07005285 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
James Smartcff261f2013-12-17 20:29:47 -05005286 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005287 return ndlp;
dea31012005-04-17 16:05:31 -05005288 }
5289 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005290
dea31012005-04-17 16:05:31 -05005291 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005292 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5293 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005294 return NULL;
5295}
5296
5297struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005298lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005299{
James Smart2e0fef82007-06-17 19:56:36 -05005300 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005301 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005302 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005303
James Smartfedd3b72011-02-16 12:39:24 -05005304 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005305 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005306 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005307 return ndlp;
5308}
5309
5310struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005311lpfc_findnode_mapped(struct lpfc_vport *vport)
5312{
5313 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5314 struct lpfc_nodelist *ndlp;
5315 uint32_t data1;
5316 unsigned long iflags;
5317
5318 spin_lock_irqsave(shost->host_lock, iflags);
5319
5320 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5321 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5322 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5323 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5324 ((uint32_t)ndlp->nlp_xri << 16) |
5325 ((uint32_t)ndlp->nlp_type << 8) |
5326 ((uint32_t)ndlp->nlp_rpi & 0xff));
5327 spin_unlock_irqrestore(shost->host_lock, iflags);
5328 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5329 "2025 FIND node DID "
5330 "Data: x%p x%x x%x x%x %p\n",
5331 ndlp, ndlp->nlp_DID,
5332 ndlp->nlp_flag, data1,
5333 ndlp->active_rrqs_xri_bitmap);
5334 return ndlp;
5335 }
5336 }
5337 spin_unlock_irqrestore(shost->host_lock, iflags);
5338
5339 /* FIND node did <did> NOT FOUND */
5340 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5341 "2026 FIND mapped did NOT FOUND.\n");
5342 return NULL;
5343}
5344
5345struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005346lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5347{
5348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5349 struct lpfc_nodelist *ndlp;
5350
5351 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005352 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005353 if (vport->phba->nvmet_support)
5354 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005355 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5356 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005357 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005358 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005359 if (!ndlp)
5360 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005361 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5362 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005363 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005364 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005365 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005366 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005367 if (vport->phba->nvmet_support)
5368 return NULL;
James Smarte47c9092008-02-08 18:49:26 -05005369 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
James Smartb95b2112019-08-14 16:56:47 -07005370 if (!ndlp) {
5371 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI,
5372 "0014 Could not enable ndlp\n");
James Smarte47c9092008-02-08 18:49:26 -05005373 return NULL;
James Smartb95b2112019-08-14 16:56:47 -07005374 }
James Smarte47c9092008-02-08 18:49:26 -05005375 spin_lock_irq(shost->host_lock);
5376 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5377 spin_unlock_irq(shost->host_lock);
5378 return ndlp;
dea31012005-04-17 16:05:31 -05005379 }
James Smarte47c9092008-02-08 18:49:26 -05005380
James Smart1c5b12f2017-04-21 16:05:03 -07005381 /* The NVME Target does not want to actively manage an rport.
5382 * The goal is to allow the target to reset its state and clear
5383 * pending IO in preparation for the initiator to recover.
5384 */
James Smart58da1ff2008-04-07 10:15:56 -04005385 if ((vport->fc_flag & FC_RSCN_MODE) &&
5386 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005387 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005388
5389 /* Since this node is marked for discovery,
5390 * delay timeout is not needed.
5391 */
5392 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5393
5394 /* NVME Target mode waits until rport is known to be
5395 * impacted by the RSCN before it transitions. No
5396 * active management - just go to NPR provided the
5397 * node had a valid login.
5398 */
5399 if (vport->phba->nvmet_support)
5400 return ndlp;
5401
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005402 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005403 * we don't need to try to discover it again.
5404 */
5405 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
5406 return NULL;
5407
James Smarta257bf92009-04-06 18:48:10 -04005408 spin_lock_irq(shost->host_lock);
5409 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5410 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04005411 } else
dea31012005-04-17 16:05:31 -05005412 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005413 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07005414 /* If the initiator received a PLOGI from this NPort or if the
5415 * initiator is already in the process of discovery on it,
5416 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005417 */
James Smart685f0bf2007-04-25 09:53:08 -04005418 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005419 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005420 (!vport->phba->nvmet_support &&
5421 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005422 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005423
James Smart8c258642017-02-12 13:52:36 -08005424 if (vport->phba->nvmet_support)
5425 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005426
5427 /* Moving to NPR state clears unsolicited flags and
5428 * allows for rediscovery
5429 */
5430 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5431
James Smart2e0fef82007-06-17 19:56:36 -05005432 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005433 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005434 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005435 }
5436 return ndlp;
5437}
5438
5439/* Build a list of nodes to discover based on the loopmap */
5440void
James Smart2e0fef82007-06-17 19:56:36 -05005441lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005442{
James Smart2e0fef82007-06-17 19:56:36 -05005443 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005444 int j;
5445 uint32_t alpa, index;
5446
James Smart2e0fef82007-06-17 19:56:36 -05005447 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005448 return;
James Smart2e0fef82007-06-17 19:56:36 -05005449
James Smart76a95d72010-11-20 23:11:48 -05005450 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005451 return;
dea31012005-04-17 16:05:31 -05005452
5453 /* Check for loop map present or not */
5454 if (phba->alpa_map[0]) {
5455 for (j = 1; j <= phba->alpa_map[0]; j++) {
5456 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005457 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005458 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005459 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005460 }
5461 } else {
5462 /* No alpamap, so try all alpa's */
5463 for (j = 0; j < FC_MAXLOOP; j++) {
5464 /* If cfg_scan_down is set, start from highest
5465 * ALPA (0xef) to lowest (0x1).
5466 */
James Smart3de2a652007-08-02 11:09:59 -04005467 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005468 index = j;
5469 else
5470 index = FC_MAXLOOP - j - 1;
5471 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005472 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005473 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005474 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005475 }
5476 }
5477 return;
5478}
5479
James Smart895427b2017-02-12 13:52:30 -08005480/* SLI3 only */
dea31012005-04-17 16:05:31 -05005481void
James Smart2e0fef82007-06-17 19:56:36 -05005482lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005483{
dea31012005-04-17 16:05:31 -05005484 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005485 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005486 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5487 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005488 int rc;
5489
James Smart92d7f7b2007-06-17 19:56:38 -05005490 /*
5491 * if it's not a physical port or if we already send
5492 * clear_la then don't send it.
5493 */
5494 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005495 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5496 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005497 return;
5498
James Smart2e0fef82007-06-17 19:56:36 -05005499 /* Link up discovery */
5500 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5501 phba->link_state = LPFC_CLEAR_LA;
5502 lpfc_clear_la(phba, mbox);
5503 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5504 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005505 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005506 if (rc == MBX_NOT_FINISHED) {
5507 mempool_free(mbox, phba->mbox_mem_pool);
5508 lpfc_disc_flush_list(vport);
5509 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5510 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005511 phba->link_state = LPFC_HBA_ERROR;
5512 }
5513 }
5514}
5515
5516/* Reg_vpi to tell firmware to resume normal operations */
5517void
5518lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5519{
5520 LPFC_MBOXQ_t *regvpimbox;
5521
5522 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5523 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005524 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005525 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5526 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005527 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005528 == MBX_NOT_FINISHED) {
5529 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005530 }
5531 }
5532}
5533
5534/* Start Link up / RSCN discovery on NPR nodes */
5535void
5536lpfc_disc_start(struct lpfc_vport *vport)
5537{
5538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5539 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005540 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005541 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005542
James Smarte74c03c2013-04-17 20:15:19 -04005543 if (!lpfc_is_link_up(phba)) {
5544 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5545 "3315 Link is not up %x\n",
5546 phba->link_state);
dea31012005-04-17 16:05:31 -05005547 return;
James Smarte74c03c2013-04-17 20:15:19 -04005548 }
James Smart2e0fef82007-06-17 19:56:36 -05005549
5550 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005551 clear_la_pending = 1;
5552 else
5553 clear_la_pending = 0;
5554
James Smart2e0fef82007-06-17 19:56:36 -05005555 if (vport->port_state < LPFC_VPORT_READY)
5556 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005557
James Smart2e0fef82007-06-17 19:56:36 -05005558 lpfc_set_disctmo(vport);
5559
James Smart2e0fef82007-06-17 19:56:36 -05005560 vport->fc_prevDID = vport->fc_myDID;
5561 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005562
5563 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005564 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5565 "0202 Start Discovery hba state x%x "
5566 "Data: x%x x%x x%x\n",
5567 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5568 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005569
5570 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005571 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005572
5573 if (num_sent)
5574 return;
5575
James Smart6fa139f2013-04-17 20:20:00 -04005576 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005577 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005578 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005579 !(vport->fc_flag & FC_RSCN_MODE) &&
5580 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005581 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005582 lpfc_issue_reg_vpi(phba, vport);
5583 return;
5584 }
James Smart2e0fef82007-06-17 19:56:36 -05005585
James Smart92d7f7b2007-06-17 19:56:38 -05005586 /*
5587 * For SLI2, we need to set port_state to READY and continue
5588 * discovery.
5589 */
5590 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5591 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005592 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005593
5594 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005595 vport->num_disc_nodes = 0;
5596 /* go thru NPR nodes and issue ELS PLOGIs */
5597 if (vport->fc_npr_cnt)
5598 lpfc_els_disc_plogi(vport);
5599
5600 if (!vport->num_disc_nodes) {
5601 spin_lock_irq(shost->host_lock);
5602 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5603 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005604 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005605 }
5606 }
James Smart92d7f7b2007-06-17 19:56:38 -05005607 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005608 } else {
5609 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005610 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005611
5612 if (num_sent)
5613 return;
5614
James Smart2e0fef82007-06-17 19:56:36 -05005615 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005616 /* Check to see if more RSCNs came in while we
5617 * were processing this one.
5618 */
James Smart2e0fef82007-06-17 19:56:36 -05005619 if ((vport->fc_rscn_id_cnt == 0) &&
5620 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5621 spin_lock_irq(shost->host_lock);
5622 vport->fc_flag &= ~FC_RSCN_MODE;
5623 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005624 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005625 } else
James Smart2e0fef82007-06-17 19:56:36 -05005626 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005627 }
5628 }
5629 return;
5630}
5631
5632/*
5633 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5634 * ring the match the sppecified nodelist.
5635 */
5636static void
James Smart2e0fef82007-06-17 19:56:36 -05005637lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005638{
James Smart2534ba72007-04-25 09:52:20 -04005639 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005640 IOCB_t *icmd;
5641 struct lpfc_iocbq *iocb, *next_iocb;
5642 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005643
James Smart895427b2017-02-12 13:52:30 -08005644 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005645 if (unlikely(!pring))
5646 return;
dea31012005-04-17 16:05:31 -05005647
5648 /* Error matching iocb on txq or txcmplq
5649 * First check the txq.
5650 */
James Smart2e0fef82007-06-17 19:56:36 -05005651 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005652 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5653 if (iocb->context1 != ndlp) {
5654 continue;
5655 }
5656 icmd = &iocb->iocb;
5657 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5658 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5659
James Smart2534ba72007-04-25 09:52:20 -04005660 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005661 }
5662 }
5663
5664 /* Next check the txcmplq */
5665 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5666 if (iocb->context1 != ndlp) {
5667 continue;
5668 }
5669 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005670 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5671 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005672 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005673 }
5674 }
James Smart2e0fef82007-06-17 19:56:36 -05005675 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005676
James Smarta257bf92009-04-06 18:48:10 -04005677 /* Cancel all the IOCBs from the completions list */
5678 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5679 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005680}
5681
Adrian Bunka6ababd2007-11-05 18:07:33 +01005682static void
James Smart2e0fef82007-06-17 19:56:36 -05005683lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005684{
5685 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005686 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005687
James Smart2e0fef82007-06-17 19:56:36 -05005688 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5689 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005690 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005691 if (!NLP_CHK_NODE_ACT(ndlp))
5692 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005693 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5694 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5695 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005696 }
dea31012005-04-17 16:05:31 -05005697 }
5698 }
dea31012005-04-17 16:05:31 -05005699}
5700
James Smart92d7f7b2007-06-17 19:56:38 -05005701void
5702lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5703{
5704 lpfc_els_flush_rscn(vport);
5705 lpfc_els_flush_cmd(vport);
5706 lpfc_disc_flush_list(vport);
5707}
5708
dea31012005-04-17 16:05:31 -05005709/*****************************************************************************/
5710/*
5711 * NAME: lpfc_disc_timeout
5712 *
5713 * FUNCTION: Fibre Channel driver discovery timeout routine.
5714 *
5715 * EXECUTION ENVIRONMENT: interrupt only
5716 *
5717 * CALLED FROM:
5718 * Timer function
5719 *
5720 * RETURNS:
5721 * none
5722 */
5723/*****************************************************************************/
5724void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005725lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005726{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005727 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005728 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005729 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005730 unsigned long flags = 0;
5731
5732 if (unlikely(!phba))
5733 return;
5734
James Smart5e9d9b82008-06-14 22:52:53 -04005735 spin_lock_irqsave(&vport->work_port_lock, flags);
5736 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5737 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005738 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005739 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005740
James Smart5e9d9b82008-06-14 22:52:53 -04005741 if (!tmo_posted)
5742 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005743 return;
5744}
5745
5746static void
James Smart2e0fef82007-06-17 19:56:36 -05005747lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005748{
James Smart2e0fef82007-06-17 19:56:36 -05005749 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5750 struct lpfc_hba *phba = vport->phba;
5751 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005752 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005753 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005754 int rc, clrlaerr = 0;
5755
James Smart2e0fef82007-06-17 19:56:36 -05005756 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005757 return;
5758
James Smart2e0fef82007-06-17 19:56:36 -05005759 spin_lock_irq(shost->host_lock);
5760 vport->fc_flag &= ~FC_DISC_TMO;
5761 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005762
James Smart858c9f62007-06-17 19:56:39 -05005763 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5764 "disc timeout: state:x%x rtry:x%x flg:x%x",
5765 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5766
James Smart2e0fef82007-06-17 19:56:36 -05005767 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005768
5769 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005770 /*
5771 * port_state is identically LPFC_LOCAL_CFG_LINK while
5772 * waiting for FAN timeout
5773 */
James Smarte8b62012007-08-02 11:10:09 -04005774 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5775 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005776
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005777 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005778 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005779 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005780 if (!NLP_CHK_NODE_ACT(ndlp))
5781 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005782 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5783 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005784 if (ndlp->nlp_type & NLP_FABRIC) {
5785 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005786 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005787
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005788 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005789 /* Fail outstanding IO now since device
5790 * is marked for PLOGI.
5791 */
James Smart2e0fef82007-06-17 19:56:36 -05005792 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005793 }
5794 }
James Smart92d7f7b2007-06-17 19:56:38 -05005795 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005796 if (phba->sli_rev <= LPFC_SLI_REV3)
5797 lpfc_initial_flogi(vport);
5798 else
5799 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005800 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005801 }
dea31012005-04-17 16:05:31 -05005802 break;
5803
James Smart92d7f7b2007-06-17 19:56:38 -05005804 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005805 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005806 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005807 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005808 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5809 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005810 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005811
5812 /* Assume no Fabric and go on with discovery.
5813 * Check for outstanding ELS FLOGI to abort.
5814 */
5815
5816 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005817 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005818
5819 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005820 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005821 break;
5822
5823 case LPFC_FABRIC_CFG_LINK:
5824 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5825 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005826 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5827 "0223 Timeout while waiting for "
5828 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005829 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005830 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005831 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005832 lpfc_els_abort(phba, ndlp);
5833
5834 /* ReStart discovery */
5835 goto restart_disc;
dea31012005-04-17 16:05:31 -05005836
5837 case LPFC_NS_QRY:
5838 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005839 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5840 "0224 NameServer Query timeout "
5841 "Data: x%x x%x\n",
5842 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005843
James Smart92d7f7b2007-06-17 19:56:38 -05005844 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5845 /* Try it one more time */
5846 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005847 vport->gidft_inp = 0;
5848 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005849 if (rc == 0)
5850 break;
dea31012005-04-17 16:05:31 -05005851 }
James Smart92d7f7b2007-06-17 19:56:38 -05005852 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005853
James Smart87af33f2007-10-27 13:37:43 -04005854restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005855 /*
5856 * Discovery is over.
5857 * set port_state to PORT_READY if SLI2.
5858 * cmpl_reg_vpi will set port_state to READY for SLI3.
5859 */
James Smart3772a992009-05-22 14:50:54 -04005860 if (phba->sli_rev < LPFC_SLI_REV4) {
5861 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5862 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005863 else {
James Smart3772a992009-05-22 14:50:54 -04005864 lpfc_issue_clear_la(phba, vport);
5865 vport->port_state = LPFC_VPORT_READY;
5866 }
dea31012005-04-17 16:05:31 -05005867 }
5868
5869 /* Setup and issue mailbox INITIALIZE LINK command */
5870 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5871 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005872 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5873 "0206 Device Discovery "
5874 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005875 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005876 break;
5877 }
5878
5879 lpfc_linkdown(phba);
5880 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5881 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005882 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005883 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005884 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005885 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005886 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005887 if (rc == MBX_NOT_FINISHED)
5888 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5889
5890 break;
5891
5892 case LPFC_DISC_AUTH:
5893 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005894 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5895 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005896 lpfc_disc_flush_list(vport);
5897
James Smart92d7f7b2007-06-17 19:56:38 -05005898 /*
5899 * set port_state to PORT_READY if SLI2.
5900 * cmpl_reg_vpi will set port_state to READY for SLI3.
5901 */
James Smart3772a992009-05-22 14:50:54 -04005902 if (phba->sli_rev < LPFC_SLI_REV4) {
5903 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5904 lpfc_issue_reg_vpi(phba, vport);
5905 else { /* NPIV Not enabled */
5906 lpfc_issue_clear_la(phba, vport);
5907 vport->port_state = LPFC_VPORT_READY;
5908 }
dea31012005-04-17 16:05:31 -05005909 }
5910 break;
5911
James Smart2e0fef82007-06-17 19:56:36 -05005912 case LPFC_VPORT_READY:
5913 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04005914 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5915 "0231 RSCN timeout Data: x%x "
5916 "x%x\n",
5917 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005918
5919 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005920 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005921
James Smart2e0fef82007-06-17 19:56:36 -05005922 lpfc_els_flush_rscn(vport);
5923 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005924 }
5925 break;
James Smart2e0fef82007-06-17 19:56:36 -05005926
James Smart92d7f7b2007-06-17 19:56:38 -05005927 default:
James Smarte8b62012007-08-02 11:10:09 -04005928 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005929 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005930 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005931 break;
5932 }
5933
5934 switch (phba->link_state) {
5935 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005936 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005937 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5938 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005939 clrlaerr = 1;
5940 break;
5941
James Smart09372822008-01-11 01:52:54 -05005942 case LPFC_LINK_UP:
5943 lpfc_issue_clear_la(phba, vport);
Bart Van Asschecd05c152019-03-28 11:06:18 -07005944 /* fall through */
James Smart2e0fef82007-06-17 19:56:36 -05005945 case LPFC_LINK_UNKNOWN:
5946 case LPFC_WARM_START:
5947 case LPFC_INIT_START:
5948 case LPFC_INIT_MBX_CMDS:
5949 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005950 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005951 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5952 "0230 Unexpected timeout, hba link "
5953 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005954 clrlaerr = 1;
5955 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005956
5957 case LPFC_HBA_READY:
5958 break;
dea31012005-04-17 16:05:31 -05005959 }
5960
5961 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005962 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005963 if (phba->sli_rev != LPFC_SLI_REV4) {
5964 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5965 ~LPFC_STOP_IOCB_EVENT;
5966 psli->sli3_ring[LPFC_FCP_RING].flag &=
5967 ~LPFC_STOP_IOCB_EVENT;
5968 }
James Smart2e0fef82007-06-17 19:56:36 -05005969 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005970 }
dea31012005-04-17 16:05:31 -05005971 return;
5972}
5973
dea31012005-04-17 16:05:31 -05005974/*
5975 * This routine handles processing a NameServer REG_LOGIN mailbox
5976 * command upon completion. It is setup in the LPFC_MBOXQ
5977 * as the completion routine when the command is
5978 * handed off to the SLI layer.
5979 */
5980void
James Smart2e0fef82007-06-17 19:56:36 -05005981lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005982{
James Smart04c68492009-05-22 14:52:52 -04005983 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08005984 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5985 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005986 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005987
James Smart3e1f0712018-11-29 16:09:29 -08005988 pmb->ctx_buf = NULL;
5989 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005990
James Smart6d368e52011-05-24 11:44:12 -04005991 if (phba->sli_rev < LPFC_SLI_REV4)
5992 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005993 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005994 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04005996 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5997 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5998 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005999 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04006000 ndlp->nlp_usg_map, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006001 /*
6002 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05006003 * 0xfffffa (FDMI well known port).
6004 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6005 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05006006 */
James Smart4258e982015-12-16 18:11:58 -05006007 if (vport->port_type == LPFC_PHYSICAL_PORT)
6008 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04006009 else
James Smart4258e982015-12-16 18:11:58 -05006010 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6011
dea31012005-04-17 16:05:31 -05006012
James Smartfa4066b2008-01-11 01:53:27 -05006013 /* decrement the node reference count held for this callback
6014 * function.
6015 */
James Smart329f9bc2007-04-25 09:53:01 -04006016 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006017 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6018 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04006019 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05006020
6021 return;
6022}
6023
James Smart685f0bf2007-04-25 09:53:08 -04006024static int
6025lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6026{
6027 uint16_t *rpi = param;
6028
James Smarteff4a012012-01-18 16:25:25 -05006029 /* check for active node */
6030 if (!NLP_CHK_NODE_ACT(ndlp))
6031 return 0;
6032
James Smart685f0bf2007-04-25 09:53:08 -04006033 return ndlp->nlp_rpi == *rpi;
6034}
6035
6036static int
6037lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6038{
6039 return memcmp(&ndlp->nlp_portname, param,
6040 sizeof(ndlp->nlp_portname)) == 0;
6041}
6042
Adrian Bunka6ababd2007-11-05 18:07:33 +01006043static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006044__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006045{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006046 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006047
James Smart2e0fef82007-06-17 19:56:36 -05006048 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006049 if (filter(ndlp, param)) {
6050 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6051 "3185 FIND node filter %p DID "
James Smart49382502017-11-20 16:00:38 -08006052 "ndlp %p did x%x flg x%x st x%x "
6053 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006054 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006055 ndlp->nlp_flag, ndlp->nlp_state,
6056 ndlp->nlp_xri, ndlp->nlp_type,
6057 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006058 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006059 }
James Smart685f0bf2007-04-25 09:53:08 -04006060 }
James Smart34f5ad82012-08-03 12:35:03 -04006061 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6062 "3186 FIND node filter %p NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006063 return NULL;
dea31012005-04-17 16:05:31 -05006064}
6065
James Smart685f0bf2007-04-25 09:53:08 -04006066/*
6067 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006068 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006069 */
6070struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006071__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006072{
James Smart2e0fef82007-06-17 19:56:36 -05006073 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006074}
6075
James Smart488d1462006-03-07 15:02:37 -05006076/*
James Smart685f0bf2007-04-25 09:53:08 -04006077 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006078 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006079 */
6080struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006081lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006082{
James Smart2e0fef82007-06-17 19:56:36 -05006083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006084 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006085
James Smart2e0fef82007-06-17 19:56:36 -05006086 spin_lock_irq(shost->host_lock);
6087 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6088 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006089 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006090}
6091
James Smartcb69f7d2011-12-13 13:21:57 -05006092/*
6093 * This routine looks up the ndlp lists for the given RPI. If the rpi
6094 * is found, the routine returns the node element list pointer else
6095 * return NULL.
6096 */
6097struct lpfc_nodelist *
6098lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6099{
6100 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6101 struct lpfc_nodelist *ndlp;
Fuqian Huang78d4b132019-08-12 16:31:34 +08006102 unsigned long flags;
James Smartcb69f7d2011-12-13 13:21:57 -05006103
Fuqian Huang78d4b132019-08-12 16:31:34 +08006104 spin_lock_irqsave(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006105 ndlp = __lpfc_findnode_rpi(vport, rpi);
Fuqian Huang78d4b132019-08-12 16:31:34 +08006106 spin_unlock_irqrestore(shost->host_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006107 return ndlp;
6108}
6109
6110/**
6111 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6112 * @phba: pointer to lpfc hba data structure.
6113 * @vpi: the physical host virtual N_Port identifier.
6114 *
6115 * This routine finds a vport on a HBA (referred by @phba) through a
6116 * @vpi. The function walks the HBA's vport list and returns the address
6117 * of the vport with the matching @vpi.
6118 *
6119 * Return code
6120 * NULL - No vport with the matching @vpi found
6121 * Otherwise - Address to the vport with the matching @vpi.
6122 **/
6123struct lpfc_vport *
6124lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6125{
6126 struct lpfc_vport *vport;
6127 unsigned long flags;
6128 int i = 0;
6129
6130 /* The physical ports are always vpi 0 - translate is unnecessary. */
6131 if (vpi > 0) {
6132 /*
6133 * Translate the physical vpi to the logical vpi. The
6134 * vport stores the logical vpi.
6135 */
6136 for (i = 0; i < phba->max_vpi; i++) {
6137 if (vpi == phba->vpi_ids[i])
6138 break;
6139 }
6140
6141 if (i >= phba->max_vpi) {
6142 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6143 "2936 Could not find Vport mapped "
6144 "to vpi %d\n", vpi);
6145 return NULL;
6146 }
6147 }
6148
James Smart523128e2018-09-10 10:30:46 -07006149 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006150 list_for_each_entry(vport, &phba->port_list, listentry) {
6151 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006152 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006153 return vport;
6154 }
6155 }
James Smart523128e2018-09-10 10:30:46 -07006156 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006157 return NULL;
6158}
6159
James Smart9d3d3402017-04-21 16:05:00 -07006160struct lpfc_nodelist *
6161lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006162{
James Smart9d3d3402017-04-21 16:05:00 -07006163 struct lpfc_nodelist *ndlp;
6164 int rpi = LPFC_RPI_ALLOC_ERROR;
6165
6166 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6167 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6168 if (rpi == LPFC_RPI_ALLOC_ERROR)
6169 return NULL;
6170 }
6171
6172 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6173 if (!ndlp) {
6174 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6175 lpfc_sli4_free_rpi(vport->phba, rpi);
6176 return NULL;
6177 }
6178
dea31012005-04-17 16:05:31 -05006179 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006180
6181 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006182 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006183 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006184 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04006185 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6186 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
6187 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
6188 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006189 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04006190 ndlp->nlp_usg_map, ndlp);
6191
James Smartcff261f2013-12-17 20:29:47 -05006192 ndlp->active_rrqs_xri_bitmap =
6193 mempool_alloc(vport->phba->active_rrq_pool,
6194 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006195 if (ndlp->active_rrqs_xri_bitmap)
6196 memset(ndlp->active_rrqs_xri_bitmap, 0,
6197 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006198 }
6199
James Smart725dd392013-10-10 12:23:30 -04006200
James Smart858c9f62007-06-17 19:56:39 -05006201
6202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6203 "node init: did:x%x",
6204 ndlp->nlp_DID, 0, 0);
6205
James Smart9d3d3402017-04-21 16:05:00 -07006206 return ndlp;
dea31012005-04-17 16:05:31 -05006207}
James Smart329f9bc2007-04-25 09:53:01 -04006208
James Smart98c9ea52007-10-27 13:37:33 -04006209/* This routine releases all resources associated with a specifc NPort's ndlp
6210 * and mempool_free's the nodelist.
6211 */
James Smart311464e2007-08-02 11:10:37 -04006212static void
James Smart329f9bc2007-04-25 09:53:01 -04006213lpfc_nlp_release(struct kref *kref)
6214{
James Smarte47c9092008-02-08 18:49:26 -05006215 struct lpfc_hba *phba;
6216 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04006217 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6218 kref);
James Smart858c9f62007-06-17 19:56:39 -05006219
6220 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6221 "node release: did:x%x flg:x%x type:x%x",
6222 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6223
James Smarte47c9092008-02-08 18:49:26 -05006224 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart939723a2012-05-09 21:19:03 -04006225 "0279 lpfc_nlp_release: ndlp:x%p did %x "
James Smartbe6bb942015-04-07 15:07:22 -04006226 "usgmap:x%x refcnt:%d rpi:%x\n",
James Smart939723a2012-05-09 21:19:03 -04006227 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006228 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006229
6230 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05006231 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05006232
6233 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04006234 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006235 spin_lock_irqsave(&phba->ndlp_lock, flags);
6236 NLP_CLR_NODE_ACT(ndlp);
6237 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6238
6239 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04006240 if (NLP_CHK_FREE_REQ(ndlp)) {
6241 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05006242 if (phba->sli_rev == LPFC_SLI_REV4)
6243 mempool_free(ndlp->active_rrqs_xri_bitmap,
6244 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04006245 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04006246 }
James Smart329f9bc2007-04-25 09:53:01 -04006247}
6248
James Smart98c9ea52007-10-27 13:37:33 -04006249/* This routine bumps the reference count for a ndlp structure to ensure
6250 * that one discovery thread won't free a ndlp while another discovery thread
6251 * is using it.
6252 */
James Smart329f9bc2007-04-25 09:53:01 -04006253struct lpfc_nodelist *
6254lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6255{
James Smarte47c9092008-02-08 18:49:26 -05006256 struct lpfc_hba *phba;
6257 unsigned long flags;
6258
James Smart98c9ea52007-10-27 13:37:33 -04006259 if (ndlp) {
6260 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6261 "node get: did:x%x flg:x%x refcnt:x%x",
6262 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006263 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006264 /* The check of ndlp usage to prevent incrementing the
6265 * ndlp reference count that is in the process of being
6266 * released.
6267 */
James Smarta257bf92009-04-06 18:48:10 -04006268 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006269 spin_lock_irqsave(&phba->ndlp_lock, flags);
6270 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6271 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6272 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6273 "0276 lpfc_nlp_get: ndlp:x%p "
6274 "usgmap:x%x refcnt:%d\n",
6275 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006276 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006277 return NULL;
6278 } else
6279 kref_get(&ndlp->kref);
6280 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04006281 }
James Smart329f9bc2007-04-25 09:53:01 -04006282 return ndlp;
6283}
6284
James Smart98c9ea52007-10-27 13:37:33 -04006285/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05006286 * count goes to 0, this indicates the the associated nodelist should be
6287 * freed. Returning 1 indicates the ndlp resource has been released; on the
6288 * other hand, returning 0 indicates the ndlp resource has not been released
6289 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04006290 */
James Smart329f9bc2007-04-25 09:53:01 -04006291int
6292lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6293{
James Smarte47c9092008-02-08 18:49:26 -05006294 struct lpfc_hba *phba;
6295 unsigned long flags;
6296
6297 if (!ndlp)
6298 return 1;
6299
6300 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6301 "node put: did:x%x flg:x%x refcnt:x%x",
6302 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006303 kref_read(&ndlp->kref));
James Smarta257bf92009-04-06 18:48:10 -04006304 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006305 spin_lock_irqsave(&phba->ndlp_lock, flags);
6306 /* Check the ndlp memory free acknowledge flag to avoid the
6307 * possible race condition that kref_put got invoked again
6308 * after previous one has done ndlp memory free.
6309 */
6310 if (NLP_CHK_FREE_ACK(ndlp)) {
6311 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6312 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6313 "0274 lpfc_nlp_put: ndlp:x%p "
6314 "usgmap:x%x refcnt:%d\n",
6315 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006316 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006317 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006318 }
James Smarte47c9092008-02-08 18:49:26 -05006319 /* Check the ndlp inactivate log flag to avoid the possible
6320 * race condition that kref_put got invoked again after ndlp
6321 * is already in inactivating state.
6322 */
6323 if (NLP_CHK_IACT_REQ(ndlp)) {
6324 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6325 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6326 "0275 lpfc_nlp_put: ndlp:x%p "
6327 "usgmap:x%x refcnt:%d\n",
6328 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006329 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006330 return 1;
6331 }
6332 /* For last put, mark the ndlp usage flags to make sure no
6333 * other kref_get and kref_put on the same ndlp shall get
6334 * in between the process when the final kref_put has been
6335 * invoked on this ndlp.
6336 */
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006337 if (kref_read(&ndlp->kref) == 1) {
James Smarte47c9092008-02-08 18:49:26 -05006338 /* Indicate ndlp is put to inactive state. */
6339 NLP_SET_IACT_REQ(ndlp);
6340 /* Acknowledge ndlp memory free has been seen. */
6341 if (NLP_CHK_FREE_REQ(ndlp))
6342 NLP_SET_FREE_ACK(ndlp);
6343 }
6344 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6345 /* Note, the kref_put returns 1 when decrementing a reference
6346 * count that was 1, it invokes the release callback function,
6347 * but it still left the reference count as 1 (not actually
6348 * performs the last decrementation). Otherwise, it actually
6349 * decrements the reference count and returns 0.
6350 */
6351 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04006352}
James Smart98c9ea52007-10-27 13:37:33 -04006353
6354/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006355 * by any other discovery thread. This routine returns 1 if the
6356 * ndlp has been freed. A return value of 0 indicates the ndlp is
6357 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006358 */
6359int
6360lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6361{
6362 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6363 "node not used: did:x%x flg:x%x refcnt:x%x",
6364 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006365 kref_read(&ndlp->kref));
6366 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006367 if (lpfc_nlp_put(ndlp))
6368 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006369 return 0;
6370}
James Smart6fb120a2009-05-22 14:52:59 -04006371
6372/**
6373 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6374 * @phba: Pointer to hba context object.
6375 *
6376 * This function iterate through all FC nodes associated
6377 * will all vports to check if there is any node with
6378 * fc_rports associated with it. If there is an fc_rport
6379 * associated with the node, then the node is either in
6380 * discovered state or its devloss_timer is pending.
6381 */
6382static int
6383lpfc_fcf_inuse(struct lpfc_hba *phba)
6384{
6385 struct lpfc_vport **vports;
6386 int i, ret = 0;
6387 struct lpfc_nodelist *ndlp;
6388 struct Scsi_Host *shost;
6389
6390 vports = lpfc_create_vport_work_array(phba);
6391
James Smart63e801c2010-11-20 23:14:19 -05006392 /* If driver cannot allocate memory, indicate fcf is in use */
6393 if (!vports)
6394 return 1;
6395
James Smart6fb120a2009-05-22 14:52:59 -04006396 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6397 shost = lpfc_shost_from_vport(vports[i]);
6398 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006399 /*
6400 * IF the CVL_RCVD bit is not set then we have sent the
6401 * flogi.
6402 * If dev_loss fires while we are waiting we do not want to
6403 * unreg the fcf.
6404 */
6405 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6406 spin_unlock_irq(shost->host_lock);
6407 ret = 1;
6408 goto out;
6409 }
James Smart6fb120a2009-05-22 14:52:59 -04006410 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6411 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6412 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6413 ret = 1;
6414 spin_unlock_irq(shost->host_lock);
6415 goto out;
James Smart80c17842012-03-01 22:35:45 -05006416 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6417 ret = 1;
James Smart891478a2009-11-18 15:40:23 -05006418 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart80c17842012-03-01 22:35:45 -05006419 "2624 RPI %x DID %x flag %x "
6420 "still logged in\n",
6421 ndlp->nlp_rpi, ndlp->nlp_DID,
6422 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006423 }
6424 }
6425 spin_unlock_irq(shost->host_lock);
6426 }
6427out:
6428 lpfc_destroy_vport_work_array(phba, vports);
6429 return ret;
6430}
6431
6432/**
6433 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6434 * @phba: Pointer to hba context object.
6435 * @mboxq: Pointer to mailbox object.
6436 *
6437 * This function frees memory associated with the mailbox command.
6438 */
James Smart1b511972011-12-13 13:23:09 -05006439void
James Smart6fb120a2009-05-22 14:52:59 -04006440lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6441{
6442 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006444
6445 if (mboxq->u.mb.mbxStatus) {
6446 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6447 "2555 UNREG_VFI mbxStatus error x%x "
6448 "HBA state x%x\n",
6449 mboxq->u.mb.mbxStatus, vport->port_state);
6450 }
James Smart38b92ef2010-08-04 16:11:39 -04006451 spin_lock_irq(shost->host_lock);
6452 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6453 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006454 mempool_free(mboxq, phba->mbox_mem_pool);
6455 return;
6456}
6457
6458/**
6459 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6460 * @phba: Pointer to hba context object.
6461 * @mboxq: Pointer to mailbox object.
6462 *
6463 * This function frees memory associated with the mailbox command.
6464 */
6465static void
6466lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6467{
6468 struct lpfc_vport *vport = mboxq->vport;
6469
6470 if (mboxq->u.mb.mbxStatus) {
6471 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6472 "2550 UNREG_FCFI mbxStatus error x%x "
6473 "HBA state x%x\n",
6474 mboxq->u.mb.mbxStatus, vport->port_state);
6475 }
6476 mempool_free(mboxq, phba->mbox_mem_pool);
6477 return;
6478}
6479
6480/**
James Smartecfd03c2010-02-12 14:41:27 -05006481 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006482 * @phba: Pointer to hba context object.
6483 *
James Smartecfd03c2010-02-12 14:41:27 -05006484 * This function prepare the HBA for unregistering the currently registered
6485 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6486 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006487 */
James Smartecfd03c2010-02-12 14:41:27 -05006488int
6489lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006490{
James Smart6fb120a2009-05-22 14:52:59 -04006491 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006492 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006493 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006494 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006495
James Smartecfd03c2010-02-12 14:41:27 -05006496 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006497 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006498 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006499
James Smart4d9ab992009-10-02 15:16:39 -04006500 /* At this point, all discovery is aborted */
6501 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006502
6503 /* Unregister VPIs */
6504 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006505 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006506 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006507 /* Stop FLOGI/FDISC retries */
6508 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6509 if (ndlp)
6510 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006511 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006512 if (phba->sli_rev == LPFC_SLI_REV4)
6513 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006514 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006515 shost = lpfc_shost_from_vport(vports[i]);
6516 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006517 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006518 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006519 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006520 }
6521 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006522 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6523 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6524 if (ndlp)
6525 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6526 lpfc_cleanup_pending_mbox(phba->pport);
6527 if (phba->sli_rev == LPFC_SLI_REV4)
6528 lpfc_sli4_unreg_all_rpis(phba->pport);
6529 lpfc_mbx_unreg_vpi(phba->pport);
6530 shost = lpfc_shost_from_vport(phba->pport);
6531 spin_lock_irq(shost->host_lock);
6532 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6533 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6534 spin_unlock_irq(shost->host_lock);
6535 }
James Smart6fb120a2009-05-22 14:52:59 -04006536
James Smart695a8142010-01-26 23:08:03 -05006537 /* Cleanup any outstanding ELS commands */
6538 lpfc_els_flush_all_cmd(phba);
6539
James Smart1b511972011-12-13 13:23:09 -05006540 /* Unregister the physical port VFI */
6541 rc = lpfc_issue_unreg_vfi(phba->pport);
6542 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006543}
6544
6545/**
6546 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6547 * @phba: Pointer to hba context object.
6548 *
6549 * This function issues synchronous unregister FCF mailbox command to HBA to
6550 * unregister the currently registered FCF record. The driver does not reset
6551 * the driver FCF usage state flags.
6552 *
6553 * Return 0 if successfully issued, none-zero otherwise.
6554 */
6555int
6556lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6557{
6558 LPFC_MBOXQ_t *mbox;
6559 int rc;
6560
James Smart6fb120a2009-05-22 14:52:59 -04006561 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6562 if (!mbox) {
6563 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006564 "2551 UNREG_FCFI mbox allocation failed"
6565 "HBA state x%x\n", phba->pport->port_state);
6566 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006567 }
James Smart6fb120a2009-05-22 14:52:59 -04006568 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6569 mbox->vport = phba->pport;
6570 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6571 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6572
6573 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006574 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6575 "2552 Unregister FCFI command failed rc x%x "
6576 "HBA state x%x\n",
6577 rc, phba->pport->port_state);
6578 return -EINVAL;
6579 }
6580 return 0;
6581}
6582
6583/**
6584 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6585 * @phba: Pointer to hba context object.
6586 *
6587 * This function unregisters the currently reigstered FCF. This function
6588 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6589 */
6590void
6591lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6592{
6593 int rc;
6594
6595 /* Preparation for unregistering fcf */
6596 rc = lpfc_unregister_fcf_prep(phba);
6597 if (rc) {
6598 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6599 "2748 Failed to prepare for unregistering "
6600 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006601 return;
6602 }
6603
James Smartecfd03c2010-02-12 14:41:27 -05006604 /* Now, unregister FCF record and reset HBA FCF state */
6605 rc = lpfc_sli4_unregister_fcf(phba);
6606 if (rc)
6607 return;
6608 /* Reset HBA FCF states after successful unregister FCF */
6609 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006610 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006611
6612 /*
6613 * If driver is not unloading, check if there is any other
6614 * FCF record that can be used for discovery.
6615 */
6616 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006617 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006618 return;
6619
James Smart0c9ab6f2010-02-26 14:15:57 -05006620 /* This is considered as the initial FCF discovery scan */
6621 spin_lock_irq(&phba->hbalock);
6622 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6623 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006624
6625 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006626 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006627
James Smart0c9ab6f2010-02-26 14:15:57 -05006628 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006629
James Smart0c9ab6f2010-02-26 14:15:57 -05006630 if (rc) {
6631 spin_lock_irq(&phba->hbalock);
6632 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6633 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006634 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006635 "2553 lpfc_unregister_unused_fcf failed "
6636 "to read FCF record HBA state x%x\n",
6637 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006638 }
James Smartecfd03c2010-02-12 14:41:27 -05006639}
6640
6641/**
6642 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6643 * @phba: Pointer to hba context object.
6644 *
6645 * This function just unregisters the currently reigstered FCF. It does not
6646 * try to find another FCF for discovery.
6647 */
6648void
6649lpfc_unregister_fcf(struct lpfc_hba *phba)
6650{
6651 int rc;
6652
6653 /* Preparation for unregistering fcf */
6654 rc = lpfc_unregister_fcf_prep(phba);
6655 if (rc) {
6656 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6657 "2749 Failed to prepare for unregistering "
6658 "HBA's FCF record: rc=%d\n", rc);
6659 return;
6660 }
6661
6662 /* Now, unregister FCF record and reset HBA FCF state */
6663 rc = lpfc_sli4_unregister_fcf(phba);
6664 if (rc)
6665 return;
6666 /* Set proper HBA FCF states after successful unregister FCF */
6667 spin_lock_irq(&phba->hbalock);
6668 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6669 spin_unlock_irq(&phba->hbalock);
6670}
6671
6672/**
6673 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6674 * @phba: Pointer to hba context object.
6675 *
6676 * This function check if there are any connected remote port for the FCF and
6677 * if all the devices are disconnected, this function unregister FCFI.
6678 * This function also tries to use another FCF for discovery.
6679 */
6680void
6681lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6682{
6683 /*
James Smart3804dc82010-07-14 15:31:37 -04006684 * If HBA is not running in FIP mode, if HBA does not support
6685 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6686 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006687 */
6688 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006689 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006690 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006691 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006692 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006693 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006694 spin_unlock_irq(&phba->hbalock);
6695 return;
6696 }
6697 spin_unlock_irq(&phba->hbalock);
6698
6699 if (lpfc_fcf_inuse(phba))
6700 return;
6701
6702 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006703}
6704
6705/**
6706 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6707 * @phba: Pointer to hba context object.
6708 * @buff: Buffer containing the FCF connection table as in the config
6709 * region.
6710 * This function create driver data structure for the FCF connection
6711 * record table read from config region 23.
6712 */
6713static void
6714lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6715 uint8_t *buff)
6716{
6717 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6718 struct lpfc_fcf_conn_hdr *conn_hdr;
6719 struct lpfc_fcf_conn_rec *conn_rec;
6720 uint32_t record_count;
6721 int i;
6722
6723 /* Free the current connect table */
6724 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006725 &phba->fcf_conn_rec_list, list) {
6726 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006727 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006728 }
James Smart6fb120a2009-05-22 14:52:59 -04006729
6730 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6731 record_count = conn_hdr->length * sizeof(uint32_t)/
6732 sizeof(struct lpfc_fcf_conn_rec);
6733
6734 conn_rec = (struct lpfc_fcf_conn_rec *)
6735 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6736
6737 for (i = 0; i < record_count; i++) {
6738 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6739 continue;
6740 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6741 GFP_KERNEL);
6742 if (!conn_entry) {
6743 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6744 "2566 Failed to allocate connection"
6745 " table entry\n");
6746 return;
6747 }
6748
6749 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6750 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006751 list_add_tail(&conn_entry->list,
6752 &phba->fcf_conn_rec_list);
6753 }
James Smartdf0d0852013-05-31 17:05:08 -04006754
6755 if (!list_empty(&phba->fcf_conn_rec_list)) {
6756 i = 0;
6757 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6758 list) {
6759 conn_rec = &conn_entry->conn_rec;
6760 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6761 "3345 FCF connection list rec[%02d]: "
6762 "flags:x%04x, vtag:x%04x, "
6763 "fabric_name:x%02x:%02x:%02x:%02x:"
6764 "%02x:%02x:%02x:%02x, "
6765 "switch_name:x%02x:%02x:%02x:%02x:"
6766 "%02x:%02x:%02x:%02x\n", i++,
6767 conn_rec->flags, conn_rec->vlan_tag,
6768 conn_rec->fabric_name[0],
6769 conn_rec->fabric_name[1],
6770 conn_rec->fabric_name[2],
6771 conn_rec->fabric_name[3],
6772 conn_rec->fabric_name[4],
6773 conn_rec->fabric_name[5],
6774 conn_rec->fabric_name[6],
6775 conn_rec->fabric_name[7],
6776 conn_rec->switch_name[0],
6777 conn_rec->switch_name[1],
6778 conn_rec->switch_name[2],
6779 conn_rec->switch_name[3],
6780 conn_rec->switch_name[4],
6781 conn_rec->switch_name[5],
6782 conn_rec->switch_name[6],
6783 conn_rec->switch_name[7]);
6784 }
6785 }
James Smart6fb120a2009-05-22 14:52:59 -04006786}
6787
6788/**
6789 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6790 * @phba: Pointer to hba context object.
6791 * @buff: Buffer containing the FCoE parameter data structure.
6792 *
6793 * This function update driver data structure with config
6794 * parameters read from config region 23.
6795 */
6796static void
6797lpfc_read_fcoe_param(struct lpfc_hba *phba,
6798 uint8_t *buff)
6799{
6800 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6801 struct lpfc_fcoe_params *fcoe_param;
6802
6803 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6804 buff;
6805 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006806 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006807
6808 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6809 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6810 return;
6811
James Smart6fb120a2009-05-22 14:52:59 -04006812 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6813 phba->valid_vlan = 1;
6814 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6815 0xFFF;
6816 }
6817
6818 phba->fc_map[0] = fcoe_param->fc_map[0];
6819 phba->fc_map[1] = fcoe_param->fc_map[1];
6820 phba->fc_map[2] = fcoe_param->fc_map[2];
6821 return;
6822}
6823
6824/**
6825 * lpfc_get_rec_conf23 - Get a record type in config region data.
6826 * @buff: Buffer containing config region 23 data.
6827 * @size: Size of the data buffer.
6828 * @rec_type: Record type to be searched.
6829 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006830 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006831 * of the record specified by record_type. If record found, this
6832 * function return pointer to the record else return NULL.
6833 */
6834static uint8_t *
6835lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6836{
6837 uint32_t offset = 0, rec_length;
6838
6839 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6840 (size < sizeof(uint32_t)))
6841 return NULL;
6842
6843 rec_length = buff[offset + 1];
6844
6845 /*
6846 * One TLV record has one word header and number of data words
6847 * specified in the rec_length field of the record header.
6848 */
6849 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6850 <= size) {
6851 if (buff[offset] == rec_type)
6852 return &buff[offset];
6853
6854 if (buff[offset] == LPFC_REGION23_LAST_REC)
6855 return NULL;
6856
6857 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6858 rec_length = buff[offset + 1];
6859 }
6860 return NULL;
6861}
6862
6863/**
6864 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6865 * @phba: Pointer to lpfc_hba data structure.
6866 * @buff: Buffer containing config region 23 data.
6867 * @size: Size of the data buffer.
6868 *
Stefan Weileef35c22010-08-06 21:11:15 +02006869 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006870 * populate driver data structure with the parameters.
6871 */
6872void
6873lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6874 uint8_t *buff,
6875 uint32_t size)
6876{
James Smarteb016562014-09-03 12:58:06 -04006877 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006878 uint8_t *rec_ptr;
6879
6880 /*
6881 * If data size is less than 2 words signature and version cannot be
6882 * verified.
6883 */
6884 if (size < 2*sizeof(uint32_t))
6885 return;
6886
6887 /* Check the region signature first */
6888 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6890 "2567 Config region 23 has bad signature\n");
6891 return;
6892 }
6893
6894 offset += 4;
6895
6896 /* Check the data structure version */
6897 if (buff[offset] != LPFC_REGION23_VERSION) {
6898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6899 "2568 Config region 23 has bad version\n");
6900 return;
6901 }
6902 offset += 4;
6903
James Smart6fb120a2009-05-22 14:52:59 -04006904 /* Read FCoE param record */
6905 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6906 size - offset, FCOE_PARAM_TYPE);
6907 if (rec_ptr)
6908 lpfc_read_fcoe_param(phba, rec_ptr);
6909
6910 /* Read FCF connection table */
6911 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6912 size - offset, FCOE_CONN_TBL_TYPE);
6913 if (rec_ptr)
6914 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6915
6916}