blob: 28ecaa7fc715ba900b85888df66a17ba2a9acac3 [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 Smartc01f3202006-08-18 17:47:08 -0400121
122 rdata = rport->dd_data;
123 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400124 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400125 return;
James Smartc01f3202006-08-18 17:47:08 -0400126
James Smart858c9f62007-06-17 19:56:39 -0500127 vport = ndlp->vport;
128 phba = vport->phba;
129
130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
131 "rport devlosscb: sid:x%x did:x%x flg:x%x",
132 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
133
James Smart34f5ad82012-08-03 12:35:03 -0400134 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
135 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
136 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
137
James Smarta8adb832007-10-27 13:37:53 -0400138 /* Don't defer this if we are in the process of deleting the vport
139 * or unloading the driver. The unload will cleanup the node
140 * appropriately we just need to cleanup the ndlp rport info here.
141 */
142 if (vport->load_flag & FC_UNLOADING) {
143 put_node = rdata->pnode != NULL;
144 put_rport = ndlp->rport != NULL;
145 rdata->pnode = NULL;
146 ndlp->rport = NULL;
147 if (put_node)
148 lpfc_nlp_put(ndlp);
149 if (put_rport)
150 put_device(&rport->dev);
151 return;
152 }
153
154 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
155 return;
156
James Smart466e8402015-05-21 13:55:28 -0400157 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
158 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
159 "6789 rport name %llx != node port name %llx",
160 rport->port_name,
161 wwn_to_u64(ndlp->nlp_portname.u.wwn));
James Smart34f5ad82012-08-03 12:35:03 -0400162
James Smart858c9f62007-06-17 19:56:39 -0500163 evtp = &ndlp->dev_loss_evt;
164
James Smart466e8402015-05-21 13:55:28 -0400165 if (!list_empty(&evtp->evt_listp)) {
166 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
167 "6790 rport name %llx dev_loss_evt pending",
168 rport->port_name);
James Smart858c9f62007-06-17 19:56:39 -0500169 return;
James Smart466e8402015-05-21 13:55:28 -0400170 }
James Smart858c9f62007-06-17 19:56:39 -0500171
James Smart466e8402015-05-21 13:55:28 -0400172 shost = lpfc_shost_from_vport(vport);
173 spin_lock_irq(shost->host_lock);
174 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
175 spin_unlock_irq(shost->host_lock);
James Smarta62a4352013-04-17 20:18:19 -0400176
James Smartfa4066b2008-01-11 01:53:27 -0500177 /* We need to hold the node by incrementing the reference
178 * count until this queued work is done
179 */
James Smart466e8402015-05-21 13:55:28 -0400180 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
181
182 spin_lock_irq(&phba->hbalock);
James Smart5e9d9b82008-06-14 22:52:53 -0400183 if (evtp->evt_arg1) {
184 evtp->evt = LPFC_EVT_DEV_LOSS;
185 list_add_tail(&evtp->evt_listp, &phba->work_list);
186 lpfc_worker_wake_up(phba);
187 }
James Smart858c9f62007-06-17 19:56:39 -0500188 spin_unlock_irq(&phba->hbalock);
189
James Smart858c9f62007-06-17 19:56:39 -0500190 return;
191}
192
James Smarta93ff372010-10-22 11:06:08 -0400193/**
194 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
195 * @ndlp: Pointer to remote node object.
196 *
197 * This function is called from the worker thread when devloss timeout timer
198 * expires. For SLI4 host, this routine shall return 1 when at lease one
199 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
200 * routine shall return 0 when there is no remote node is still in use of FCF
201 * when devloss timeout happened to this @ndlp.
202 **/
203static int
James Smart858c9f62007-06-17 19:56:39 -0500204lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
205{
206 struct lpfc_rport_data *rdata;
207 struct fc_rport *rport;
208 struct lpfc_vport *vport;
209 struct lpfc_hba *phba;
James Smart466e8402015-05-21 13:55:28 -0400210 struct Scsi_Host *shost;
James Smart858c9f62007-06-17 19:56:39 -0500211 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400212 int put_node;
James Smart858c9f62007-06-17 19:56:39 -0500213 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400214 int fcf_inuse = 0;
James Smart858c9f62007-06-17 19:56:39 -0500215
216 rport = ndlp->rport;
James Smart858c9f62007-06-17 19:56:39 -0500217 vport = ndlp->vport;
James Smart466e8402015-05-21 13:55:28 -0400218 shost = lpfc_shost_from_vport(vport);
219
220 spin_lock_irq(shost->host_lock);
221 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
222 spin_unlock_irq(shost->host_lock);
223
224 if (!rport)
225 return fcf_inuse;
226
227 name = (uint8_t *) &ndlp->nlp_portname;
James Smart858c9f62007-06-17 19:56:39 -0500228 phba = vport->phba;
229
James Smarta93ff372010-10-22 11:06:08 -0400230 if (phba->sli_rev == LPFC_SLI_REV4)
231 fcf_inuse = lpfc_fcf_inuse(phba);
232
James Smart858c9f62007-06-17 19:56:39 -0500233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
234 "rport devlosstmo:did:x%x type:x%x id:x%x",
235 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
236
James Smart34f5ad82012-08-03 12:35:03 -0400237 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
238 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
239 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
240
James Smart466e8402015-05-21 13:55:28 -0400241 /*
242 * lpfc_nlp_remove if reached with dangling rport drops the
243 * reference. To make sure that does not happen clear rport
244 * pointer in ndlp before lpfc_nlp_put.
245 */
246 rdata = rport->dd_data;
247
James Smarta8adb832007-10-27 13:37:53 -0400248 /* Don't defer this if we are in the process of deleting the vport
249 * or unloading the driver. The unload will cleanup the node
250 * appropriately we just need to cleanup the ndlp rport info here.
251 */
252 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500253 if (ndlp->nlp_sid != NLP_NO_SID) {
254 /* flush the target */
255 lpfc_sli_abort_iocb(vport,
James Smart895427b2017-02-12 13:52:30 -0800256 &phba->sli.sli3_ring[LPFC_FCP_RING],
257 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smart09372822008-01-11 01:52:54 -0500258 }
James Smarta8adb832007-10-27 13:37:53 -0400259 put_node = rdata->pnode != NULL;
James Smarta8adb832007-10-27 13:37:53 -0400260 rdata->pnode = NULL;
261 ndlp->rport = NULL;
262 if (put_node)
263 lpfc_nlp_put(ndlp);
James Smart466e8402015-05-21 13:55:28 -0400264 put_device(&rport->dev);
265
James Smarta93ff372010-10-22 11:06:08 -0400266 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400267 }
268
James Smartd7c255b2008-08-24 21:50:00 -0400269 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
270 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
271 "0284 Devloss timeout Ignored on "
272 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
273 "NPort x%x\n",
274 *name, *(name+1), *(name+2), *(name+3),
275 *(name+4), *(name+5), *(name+6), *(name+7),
276 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400277 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400278 }
James Smart858c9f62007-06-17 19:56:39 -0500279
James Smart466e8402015-05-21 13:55:28 -0400280 put_node = rdata->pnode != NULL;
281 rdata->pnode = NULL;
282 ndlp->rport = NULL;
283 if (put_node)
284 lpfc_nlp_put(ndlp);
285 put_device(&rport->dev);
286
287 if (ndlp->nlp_type & NLP_FABRIC)
James Smarta93ff372010-10-22 11:06:08 -0400288 return fcf_inuse;
James Smart82085712007-04-25 09:52:41 -0400289
dea31012005-04-17 16:05:31 -0500290 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400291 warn_on = 1;
James Smart895427b2017-02-12 13:52:30 -0800292 lpfc_sli_abort_iocb(vport, &phba->sli.sli3_ring[LPFC_FCP_RING],
James Smart51ef4c22007-08-02 11:10:31 -0400293 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500294 }
James Smartc01f3202006-08-18 17:47:08 -0400295
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400296 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400297 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
298 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400299 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
300 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400301 *name, *(name+1), *(name+2), *(name+3),
302 *(name+4), *(name+5), *(name+6), *(name+7),
303 ndlp->nlp_DID, ndlp->nlp_flag,
304 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400305 } else {
James Smarte8b62012007-08-02 11:10:09 -0400306 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
307 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400308 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
309 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400310 *name, *(name+1), *(name+2), *(name+3),
311 *(name+4), *(name+5), *(name+6), *(name+7),
312 ndlp->nlp_DID, ndlp->nlp_flag,
313 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400314 }
315
James Smart2ade92a2017-03-04 09:30:38 -0800316 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400317 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400318 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400319 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
320 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500321 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400322
James Smarta93ff372010-10-22 11:06:08 -0400323 return fcf_inuse;
324}
325
326/**
327 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
328 * @phba: Pointer to hba context object.
329 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
330 * @nlp_did: remote node identifer with devloss timeout.
331 *
332 * This function is called from the worker thread after invoking devloss
333 * timeout handler and releasing the reference count for the ndlp with
334 * which the devloss timeout was handled for SLI4 host. For the devloss
335 * timeout of the last remote node which had been in use of FCF, when this
336 * routine is invoked, it shall be guaranteed that none of the remote are
337 * in-use of FCF. When devloss timeout to the last remote using the FCF,
338 * if the FIP engine is neither in FCF table scan process nor roundrobin
339 * failover process, the in-use FCF shall be unregistered. If the FIP
340 * engine is in FCF discovery process, the devloss timeout state shall
341 * be set for either the FCF table scan process or roundrobin failover
342 * process to unregister the in-use FCF.
343 **/
344static void
345lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
346 uint32_t nlp_did)
347{
348 /* If devloss timeout happened to a remote node when FCF had no
349 * longer been in-use, do nothing.
350 */
351 if (!fcf_inuse)
352 return;
353
354 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
355 spin_lock_irq(&phba->hbalock);
356 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
357 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
358 spin_unlock_irq(&phba->hbalock);
359 return;
360 }
361 phba->hba_flag |= HBA_DEVLOSS_TMO;
362 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
363 "2847 Last remote node (x%x) using "
364 "FCF devloss tmo\n", nlp_did);
365 }
366 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
367 spin_unlock_irq(&phba->hbalock);
368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
369 "2868 Devloss tmo to FCF rediscovery "
370 "in progress\n");
371 return;
372 }
373 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
374 spin_unlock_irq(&phba->hbalock);
375 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
376 "2869 Devloss tmo to idle FIP engine, "
377 "unreg in-use FCF and rescan.\n");
378 /* Unregister in-use FCF and rescan */
379 lpfc_unregister_fcf_rescan(phba);
380 return;
381 }
382 spin_unlock_irq(&phba->hbalock);
383 if (phba->hba_flag & FCF_TS_INPROG)
384 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
385 "2870 FCF table scan in progress\n");
386 if (phba->hba_flag & FCF_RR_INPROG)
387 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
388 "2871 FLOGI roundrobin FCF failover "
389 "in progress\n");
390 }
James Smart6fb120a2009-05-22 14:52:59 -0400391 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500392}
James Smartc01f3202006-08-18 17:47:08 -0400393
James Smartea2151b2008-09-07 11:52:10 -0400394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400396 * @phba: Pointer to hba context object.
397 *
398 * This function is called from the functions which need to post
399 * events from interrupt context. This function allocates data
400 * structure required for posting event. It also keeps track of
401 * number of events pending and prevent event storm when there are
402 * too many events.
403 **/
404struct lpfc_fast_path_event *
405lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
406 struct lpfc_fast_path_event *ret;
407
408 /* If there are lot of fast event do not exhaust memory due to this */
409 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
410 return NULL;
411
412 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
413 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400414 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400415 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400416 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
417 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
418 }
James Smartea2151b2008-09-07 11:52:10 -0400419 return ret;
420}
421
422/**
James Smart3621a712009-04-06 18:47:14 -0400423 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400424 * @phba: Pointer to hba context object.
425 * @evt: Event object which need to be freed.
426 *
427 * This function frees the data structure required for posting
428 * events.
429 **/
430void
431lpfc_free_fast_evt(struct lpfc_hba *phba,
432 struct lpfc_fast_path_event *evt) {
433
434 atomic_dec(&phba->fast_event_count);
435 kfree(evt);
436}
437
438/**
James Smart3621a712009-04-06 18:47:14 -0400439 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400440 * @phba: Pointer to hba context object.
441 * @evtp: Event data structure.
442 *
443 * This function is called from worker thread, when the interrupt
444 * context need to post an event. This function posts the event
445 * to fc transport netlink interface.
446 **/
447static void
448lpfc_send_fastpath_evt(struct lpfc_hba *phba,
449 struct lpfc_work_evt *evtp)
450{
451 unsigned long evt_category, evt_sub_category;
452 struct lpfc_fast_path_event *fast_evt_data;
453 char *evt_data;
454 uint32_t evt_data_size;
455 struct Scsi_Host *shost;
456
457 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
458 work_evt);
459
460 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
461 evt_sub_category = (unsigned long) fast_evt_data->un.
462 fabric_evt.subcategory;
463 shost = lpfc_shost_from_vport(fast_evt_data->vport);
464 if (evt_category == FC_REG_FABRIC_EVENT) {
465 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
466 evt_data = (char *) &fast_evt_data->un.read_check_error;
467 evt_data_size = sizeof(fast_evt_data->un.
468 read_check_error);
469 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500470 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400471 evt_data = (char *) &fast_evt_data->un.fabric_evt;
472 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
473 } else {
474 lpfc_free_fast_evt(phba, fast_evt_data);
475 return;
476 }
477 } else if (evt_category == FC_REG_SCSI_EVENT) {
478 switch (evt_sub_category) {
479 case LPFC_EVENT_QFULL:
480 case LPFC_EVENT_DEVBSY:
481 evt_data = (char *) &fast_evt_data->un.scsi_evt;
482 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
483 break;
484 case LPFC_EVENT_CHECK_COND:
485 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
486 evt_data_size = sizeof(fast_evt_data->un.
487 check_cond_evt);
488 break;
489 case LPFC_EVENT_VARQUEDEPTH:
490 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
491 evt_data_size = sizeof(fast_evt_data->un.
492 queue_depth_evt);
493 break;
494 default:
495 lpfc_free_fast_evt(phba, fast_evt_data);
496 return;
497 }
498 } else {
499 lpfc_free_fast_evt(phba, fast_evt_data);
500 return;
501 }
502
James Smart895427b2017-02-12 13:52:30 -0800503 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
504 fc_host_post_vendor_event(shost,
505 fc_get_event_number(),
506 evt_data_size,
507 evt_data,
508 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400509
510 lpfc_free_fast_evt(phba, fast_evt_data);
511 return;
512}
513
dea31012005-04-17 16:05:31 -0500514static void
James Smart2e0fef82007-06-17 19:56:36 -0500515lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500516{
517 struct lpfc_work_evt *evtp = NULL;
518 struct lpfc_nodelist *ndlp;
519 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400520 int fcf_inuse;
521 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500522
James Smart2e0fef82007-06-17 19:56:36 -0500523 spin_lock_irq(&phba->hbalock);
524 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500525 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
526 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500527 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500528 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500529 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500530 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500531 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500532 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500533 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500534 /* decrement the node reference count held
535 * for this queued work
536 */
537 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500538 break;
James Smart858c9f62007-06-17 19:56:39 -0500539 case LPFC_EVT_DEV_LOSS:
540 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400541 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500542 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500543 /* decrement the node reference count held for
544 * this queued work
545 */
James Smarta93ff372010-10-22 11:06:08 -0400546 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500547 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400548 if (phba->sli_rev == LPFC_SLI_REV4)
549 lpfc_sli4_post_dev_loss_tmo_handler(phba,
550 fcf_inuse,
551 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500552 break;
dea31012005-04-17 16:05:31 -0500553 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500554 if (phba->link_state < LPFC_LINK_DOWN)
555 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500556 else
James Smart2e0fef82007-06-17 19:56:36 -0500557 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500558 complete((struct completion *)(evtp->evt_arg2));
559 break;
James Smart46fa3112007-04-25 09:51:45 -0400560 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500561 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400562 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400563 *(int *)(evtp->evt_arg1) = 0;
564 complete((struct completion *)(evtp->evt_arg2));
565 break;
566 case LPFC_EVT_OFFLINE:
567 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500568 lpfc_sli_brdrestart(phba);
569 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400570 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
571 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500572 complete((struct completion *)(evtp->evt_arg2));
573 break;
574 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400575 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500576 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500577 lpfc_sli_brdreset(phba);
578 lpfc_hba_down_post(phba);
579 *(int *)(evtp->evt_arg1) =
580 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400581 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500582 complete((struct completion *)(evtp->evt_arg2));
583 break;
584 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400585 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500586 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500587 = (phba->pport->stopped)
588 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400589 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500590 complete((struct completion *)(evtp->evt_arg2));
591 break;
James Smartea2151b2008-09-07 11:52:10 -0400592 case LPFC_EVT_FASTPATH_MGMT_EVT:
593 lpfc_send_fastpath_evt(phba, evtp);
594 free_evt = 0;
595 break;
James Smart78730cf2010-04-06 15:06:30 -0400596 case LPFC_EVT_RESET_HBA:
597 if (!(phba->pport->load_flag & FC_UNLOADING))
598 lpfc_reset_hba(phba);
599 break;
dea31012005-04-17 16:05:31 -0500600 }
601 if (free_evt)
602 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500603 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500604 }
James Smart2e0fef82007-06-17 19:56:36 -0500605 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500606
607}
608
James Smart311464e2007-08-02 11:10:37 -0400609static void
James Smart2e0fef82007-06-17 19:56:36 -0500610lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500611{
612 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500613 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400614 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400615 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400616 int i;
dea31012005-04-17 16:05:31 -0500617
James Smart2e0fef82007-06-17 19:56:36 -0500618 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500619 ha_copy = phba->work_ha;
620 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500621 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500622
James Smartda0436e2009-05-22 14:51:39 -0400623 /* First, try to post the next mailbox command to SLI4 device */
624 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
625 lpfc_sli4_post_async_mbox(phba);
626
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500627 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400628 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500629 lpfc_handle_eratt(phba);
630
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500631 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500632 lpfc_sli_handle_mb_event(phba);
633
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500634 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500635 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400636
James Smartda0436e2009-05-22 14:51:39 -0400637 /* Process SLI4 events */
638 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500639 if (phba->hba_flag & HBA_RRQ_ACTIVE)
640 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400641 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
642 lpfc_sli4_els_xri_abort_event_proc(phba);
643 if (phba->hba_flag & ASYNC_EVENT)
644 lpfc_sli4_async_event_proc(phba);
645 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
646 spin_lock_irq(&phba->hbalock);
647 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
648 spin_unlock_irq(&phba->hbalock);
649 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
650 }
James Smartecfd03c2010-02-12 14:41:27 -0500651 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
652 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400653 }
654
James Smart549e55c2007-08-02 11:09:51 -0400655 vports = lpfc_create_vport_work_array(phba);
656 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400657 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400658 /*
659 * We could have no vports in array if unloading, so if
660 * this happens then just use the pport
661 */
662 if (vports[i] == NULL && i == 0)
663 vport = phba->pport;
664 else
665 vport = vports[i];
666 if (vport == NULL)
667 break;
James Smart58da1ff2008-04-07 10:15:56 -0400668 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400669 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400670 vport->work_port_events &= ~work_port_events;
671 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400672 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400673 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400674 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400675 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400676 if (work_port_events & WORKER_HB_TMO)
677 lpfc_hb_timeout_handler(phba);
678 if (work_port_events & WORKER_MBOX_TMO)
679 lpfc_mbox_timeout_handler(phba);
680 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
681 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400682 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
683 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500684 if (work_port_events & WORKER_DELAYED_DISC_TMO)
685 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500686 }
James Smart09372822008-01-11 01:52:54 -0500687 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500688
James Smart895427b2017-02-12 13:52:30 -0800689 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500690 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
691 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700692 if (pring && (status & HA_RXMASK ||
693 pring->flag & LPFC_DEFERRED_RING_EVENT ||
694 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400695 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500696 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800697 /* Preserve legacy behavior. */
698 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
699 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500700 } else {
James Smartae9e28f2017-05-15 15:20:51 -0700701 if (phba->link_state >= LPFC_LINK_UP ||
702 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500703 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
704 lpfc_sli_handle_slow_ring_event(phba, pring,
705 (status &
706 HA_RXMASK));
707 }
James Smart858c9f62007-06-17 19:56:39 -0500708 }
James Smartdc19e3b2018-05-24 21:08:57 -0700709 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400710 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500711 /*
712 * Turn on Ring interrupts
713 */
James Smart3772a992009-05-22 14:50:54 -0400714 if (phba->sli_rev <= LPFC_SLI_REV3) {
715 spin_lock_irq(&phba->hbalock);
716 control = readl(phba->HCregaddr);
717 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
718 lpfc_debugfs_slow_ring_trc(phba,
719 "WRK Enable ring: cntl:x%x hacopy:x%x",
720 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400721
James Smart3772a992009-05-22 14:50:54 -0400722 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
723 writel(control, phba->HCregaddr);
724 readl(phba->HCregaddr); /* flush */
725 } else {
726 lpfc_debugfs_slow_ring_trc(phba,
727 "WRK Ring ok: cntl:x%x hacopy:x%x",
728 control, ha_copy, 0);
729 }
730 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500731 }
732 }
James Smart2e0fef82007-06-17 19:56:36 -0500733 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500734}
735
dea31012005-04-17 16:05:31 -0500736int
737lpfc_do_work(void *p)
738{
739 struct lpfc_hba *phba = p;
740 int rc;
dea31012005-04-17 16:05:31 -0500741
Dongsheng Yang8698a742014-03-11 18:09:12 +0800742 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400743 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400744 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500745
James Smart3a55b532008-12-04 22:38:54 -0500746 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400747 /* wait and check worker queue activities */
748 rc = wait_event_interruptible(phba->work_waitq,
749 (test_and_clear_bit(LPFC_DATA_READY,
750 &phba->data_flags)
751 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500752 /* Signal wakeup shall terminate the worker thread */
753 if (rc) {
754 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
755 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500756 break;
James Smart3a55b532008-12-04 22:38:54 -0500757 }
dea31012005-04-17 16:05:31 -0500758
James Smart5e9d9b82008-06-14 22:52:53 -0400759 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500760 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500761 }
James Smart3a55b532008-12-04 22:38:54 -0500762 phba->worker_thread = NULL;
763 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
764 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500765 return 0;
766}
767
768/*
769 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300770 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500771 * embedding it in the IOCB.
772 */
773int
James Smart2e0fef82007-06-17 19:56:36 -0500774lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500775 uint32_t evt)
776{
777 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500778 unsigned long flags;
dea31012005-04-17 16:05:31 -0500779
780 /*
781 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
782 * be queued to worker thread for processing
783 */
James Smart92d7f7b2007-06-17 19:56:38 -0500784 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500785 if (!evtp)
786 return 0;
787
788 evtp->evt_arg1 = arg1;
789 evtp->evt_arg2 = arg2;
790 evtp->evt = evt;
791
James Smarted957682007-06-17 19:56:37 -0500792 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400793 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500794 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500795
James Smart5e9d9b82008-06-14 22:52:53 -0400796 lpfc_worker_wake_up(phba);
797
dea31012005-04-17 16:05:31 -0500798 return 1;
799}
800
James Smart92d7f7b2007-06-17 19:56:38 -0500801void
802lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
803{
James Smart09372822008-01-11 01:52:54 -0500804 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500805 struct lpfc_hba *phba = vport->phba;
806 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500807
808 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500809 if (!NLP_CHK_NODE_ACT(ndlp))
810 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500811 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
812 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400813 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
814 ((vport->port_type == LPFC_NPIV_PORT) &&
815 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500816 lpfc_unreg_rpi(vport, ndlp);
817
818 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400819 if ((phba->sli_rev < LPFC_SLI_REV4) &&
820 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500821 continue;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -0400822 lpfc_disc_state_machine(vport, ndlp, NULL,
823 remove
824 ? NLP_EVT_DEVICE_RM
825 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -0500826 }
827 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400828 if (phba->sli_rev == LPFC_SLI_REV4)
829 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500830 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500831 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500832 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500833 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500834 }
835}
836
James Smart87af33f2007-10-27 13:37:43 -0400837void
James Smart98c9ea52007-10-27 13:37:33 -0400838lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500839{
James Smart695a8142010-01-26 23:08:03 -0500840 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
841
James Smart45ed1192009-10-02 15:17:02 -0400842 /* Cleanup any outstanding received buffers */
843 lpfc_cleanup_rcv_buffers(vport);
844
James Smart92d7f7b2007-06-17 19:56:38 -0500845 /* Cleanup any outstanding RSCN activity */
846 lpfc_els_flush_rscn(vport);
847
848 /* Cleanup any outstanding ELS commands */
849 lpfc_els_flush_cmd(vport);
850
851 lpfc_cleanup_rpis(vport, 0);
852
James Smart92d7f7b2007-06-17 19:56:38 -0500853 /* Turn off discovery timer if its running */
854 lpfc_can_disctmo(vport);
855}
856
James Smart3772a992009-05-22 14:50:54 -0400857void
James Smart98c9ea52007-10-27 13:37:33 -0400858lpfc_linkdown_port(struct lpfc_vport *vport)
859{
860 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
861
James Smartf6e84792019-01-28 11:14:38 -0800862 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -0800863 fc_host_post_event(shost, fc_get_event_number(),
864 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400865
866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
867 "Link Down: state:x%x rtry:x%x flg:x%x",
868 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
869
870 lpfc_port_link_failure(vport);
871
James Smart92494142011-02-16 12:39:44 -0500872 /* Stop delayed Nport discovery */
873 spin_lock_irq(shost->host_lock);
874 vport->fc_flag &= ~FC_DISC_DELAYED;
875 spin_unlock_irq(shost->host_lock);
876 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400877}
878
dea31012005-04-17 16:05:31 -0500879int
James Smart685f0bf2007-04-25 09:53:08 -0400880lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500881{
James Smart2e0fef82007-06-17 19:56:36 -0500882 struct lpfc_vport *vport = phba->pport;
883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400884 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400885 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400886 int i;
dea31012005-04-17 16:05:31 -0500887
James Smart19193ff2019-03-12 16:30:25 -0700888 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500889 return 0;
James Smart19193ff2019-03-12 16:30:25 -0700890
James Smartaacc20e2009-12-21 17:02:51 -0500891 /* Block all SCSI stack I/Os */
892 lpfc_scsi_dev_block(phba);
893
James Smart0a9e9682018-11-29 16:09:36 -0800894 phba->defer_flogi_acc_flag = false;
895
James Smart2e0fef82007-06-17 19:56:36 -0500896 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500897 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500898 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500899 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500900 phba->link_state = LPFC_LINK_DOWN;
James Smart2977a092018-12-13 15:17:52 -0800901 if (phba->sli4_hba.conf_trunk) {
902 phba->trunk_link.link0.state = 0;
903 phba->trunk_link.link1.state = 0;
904 phba->trunk_link.link2.state = 0;
905 phba->trunk_link.link3.state = 0;
906 }
James Smart72100cc2010-02-12 14:43:01 -0500907 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500908 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500909 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500910 }
James Smart549e55c2007-08-02 11:09:51 -0400911 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800912 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400913 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400914 /* Issue a LINK DOWN event to all nodes */
915 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800916
917 vports[i]->fc_myDID = 0;
918
James Smartf6e84792019-01-28 11:14:38 -0800919 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
920 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800921 if (phba->nvmet_support)
922 lpfc_nvmet_update_targetport(phba);
923 else
James Smart8c258642017-02-12 13:52:36 -0800924 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800925 }
James Smart549e55c2007-08-02 11:09:51 -0400926 }
James Smart895427b2017-02-12 13:52:30 -0800927 }
James Smart09372822008-01-11 01:52:54 -0500928 lpfc_destroy_vport_work_array(phba, vports);
James Smartc95a3b42019-03-12 16:30:07 -0700929
930 /* Clean up any SLI3 firmware default rpi's */
931 if (phba->sli_rev > LPFC_SLI_REV3)
932 goto skip_unreg_did;
933
James Smart2e0fef82007-06-17 19:56:36 -0500934 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
935 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400936 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500937 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500938 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400939 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500940 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500941 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500942 }
943 }
944
James Smartc95a3b42019-03-12 16:30:07 -0700945 skip_unreg_did:
dea31012005-04-17 16:05:31 -0500946 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500947 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500948 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
949 if (mb) {
dea31012005-04-17 16:05:31 -0500950 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500951 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500952 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400953 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500954 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500955 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500956 }
957 }
James Smart2e0fef82007-06-17 19:56:36 -0500958 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500959 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -0700960 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500961 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500962 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500963 return 0;
dea31012005-04-17 16:05:31 -0500964}
965
James Smart92d7f7b2007-06-17 19:56:38 -0500966static void
967lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500968{
James Smart92d7f7b2007-06-17 19:56:38 -0500969 struct lpfc_nodelist *ndlp;
970
971 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -0800972 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smarte47c9092008-02-08 18:49:26 -0500973 if (!NLP_CHK_NODE_ACT(ndlp))
974 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500975 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
976 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500977 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500978 /* On Linkup its safe to clean up the ndlp
979 * from Fabric connections.
980 */
James Smart92d7f7b2007-06-17 19:56:38 -0500981 if (ndlp->nlp_DID != Fabric_DID)
982 lpfc_unreg_rpi(vport, ndlp);
983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
984 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500985 /* Fail outstanding IO now since device is
986 * marked for PLOGI.
987 */
James Smart92d7f7b2007-06-17 19:56:38 -0500988 lpfc_unreg_rpi(vport, ndlp);
989 }
990 }
991}
992
993static void
994lpfc_linkup_port(struct lpfc_vport *vport)
995{
996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500997 struct lpfc_hba *phba = vport->phba;
998
999 if ((vport->load_flag & FC_UNLOADING) != 0)
1000 return;
1001
James Smart858c9f62007-06-17 19:56:39 -05001002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1003 "Link Up: top:x%x speed:x%x flg:x%x",
1004 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1005
James Smart92d7f7b2007-06-17 19:56:38 -05001006 /* If NPIV is not enabled, only bring the physical port up */
1007 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1008 (vport != phba->pport))
1009 return;
dea31012005-04-17 16:05:31 -05001010
James Smartf6e84792019-01-28 11:14:38 -08001011 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08001012 fc_host_post_event(shost, fc_get_event_number(),
1013 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001014
James Smart2e0fef82007-06-17 19:56:36 -05001015 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001016 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1017 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1018 vport->fc_flag |= FC_NDISC_ACTIVE;
1019 vport->fc_ns_retry = 0;
1020 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001021
James Smart92d7f7b2007-06-17 19:56:38 -05001022 if (vport->fc_flag & FC_LBIT)
1023 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001024
James Smart92d7f7b2007-06-17 19:56:38 -05001025}
1026
1027static int
1028lpfc_linkup(struct lpfc_hba *phba)
1029{
James Smart549e55c2007-08-02 11:09:51 -04001030 struct lpfc_vport **vports;
1031 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001032 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001033
1034 phba->link_state = LPFC_LINK_UP;
1035
1036 /* Unblock fabric iocbs if they are blocked */
1037 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1038 del_timer_sync(&phba->fabric_block_timer);
1039
James Smart549e55c2007-08-02 11:09:51 -04001040 vports = lpfc_create_vport_work_array(phba);
1041 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001042 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001043 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001044 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001045
James Smartd496b9a2018-10-23 13:41:08 -07001046 /* Clear the pport flogi counter in case the link down was
1047 * absorbed without an ACQE. No lock here - in worker thread
1048 * and discovery is synchronized.
1049 */
1050 spin_lock_irq(shost->host_lock);
1051 phba->pport->rcv_flogi_cnt = 0;
1052 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001053
1054 /* reinitialize initial FLOGI flag */
1055 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1056 phba->defer_flogi_acc_flag = false;
1057
dea31012005-04-17 16:05:31 -05001058 return 0;
1059}
1060
1061/*
1062 * This routine handles processing a CLEAR_LA mailbox
1063 * command upon completion. It is setup in the LPFC_MBOXQ
1064 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001065 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001066 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001067static void
James Smart2e0fef82007-06-17 19:56:36 -05001068lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001069{
James Smart2e0fef82007-06-17 19:56:36 -05001070 struct lpfc_vport *vport = pmb->vport;
1071 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1072 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001073 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001074 uint32_t control;
1075
dea31012005-04-17 16:05:31 -05001076 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001077 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1078 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001079
1080 /* Check for error */
1081 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001082 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001083 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1084 "0320 CLEAR_LA mbxStatus error x%x hba "
1085 "state x%x\n",
1086 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001087 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001088 goto out;
1089 }
1090
James Smart92d7f7b2007-06-17 19:56:38 -05001091 if (vport->port_type == LPFC_PHYSICAL_PORT)
1092 phba->link_state = LPFC_HBA_READY;
1093
1094 spin_lock_irq(&phba->hbalock);
1095 psli->sli_flag |= LPFC_PROCESS_LA;
1096 control = readl(phba->HCregaddr);
1097 control |= HC_LAINT_ENA;
1098 writel(control, phba->HCregaddr);
1099 readl(phba->HCregaddr); /* flush */
1100 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001101 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001102 return;
dea31012005-04-17 16:05:31 -05001103
dea31012005-04-17 16:05:31 -05001104out:
1105 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001106 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1107 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001108 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001109
James Smart2e0fef82007-06-17 19:56:36 -05001110 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001111 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001113
James Smart2e0fef82007-06-17 19:56:36 -05001114 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001115
1116 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001117
1118 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001119 psli->sli_flag |= LPFC_PROCESS_LA;
1120 control = readl(phba->HCregaddr);
1121 control |= HC_LAINT_ENA;
1122 writel(control, phba->HCregaddr);
1123 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001124 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001125
1126 return;
1127}
1128
James Smart2e0fef82007-06-17 19:56:36 -05001129
James Smartd6de08c2015-12-16 18:11:53 -05001130void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001131lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001132{
James Smart2e0fef82007-06-17 19:56:36 -05001133 struct lpfc_vport *vport = pmb->vport;
James Smart44fd7fe2017-08-23 16:55:47 -07001134 uint8_t bbscn = 0;
dea31012005-04-17 16:05:31 -05001135
James Smart04c68492009-05-22 14:52:52 -04001136 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001137 goto out;
dea31012005-04-17 16:05:31 -05001138
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001139 mempool_free(pmb, phba->mbox_mem_pool);
1140
James Smart1b511972011-12-13 13:23:09 -05001141 /* don't perform discovery for SLI4 loopback diagnostic test */
1142 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1143 !(phba->hba_flag & HBA_FCOE_MODE) &&
1144 (phba->link_flag & LS_LOOPBACK_MODE))
1145 return;
1146
James Smart76a95d72010-11-20 23:11:48 -05001147 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001148 vport->fc_flag & FC_PUBLIC_LOOP &&
1149 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001150 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001151 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001152 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1153 */
James Smart2e0fef82007-06-17 19:56:36 -05001154 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001155 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001156 }
dea31012005-04-17 16:05:31 -05001157
James Smart2e0fef82007-06-17 19:56:36 -05001158 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001159 * LPFC_FLOGI while waiting for FLOGI cmpl
1160 */
James Smart44fd7fe2017-08-23 16:55:47 -07001161 if (vport->port_state != LPFC_FLOGI) {
1162 if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
1163 bbscn = bf_get(lpfc_bbscn_def,
1164 &phba->sli4_hba.bbscn_params);
1165 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
1166 vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4);
1167 }
James Smart92d7f7b2007-06-17 19:56:38 -05001168 lpfc_initial_flogi(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001169 } else if (vport->fc_flag & FC_PT2PT) {
James Smartd6de08c2015-12-16 18:11:53 -05001170 lpfc_disc_start(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001171 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001172 return;
dea31012005-04-17 16:05:31 -05001173
1174out:
James Smarte8b62012007-08-02 11:10:09 -04001175 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1176 "0306 CONFIG_LINK mbxStatus error x%x "
1177 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001178 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001179 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001180
1181 lpfc_linkdown(phba);
1182
James Smarte8b62012007-08-02 11:10:09 -04001183 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1184 "0200 CONFIG_LINK bad hba state x%x\n",
1185 vport->port_state);
dea31012005-04-17 16:05:31 -05001186
James Smart92d7f7b2007-06-17 19:56:38 -05001187 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001188 return;
1189}
1190
James Smart7d791df2011-07-22 18:37:52 -04001191/**
1192 * lpfc_sli4_clear_fcf_rr_bmask
1193 * @phba pointer to the struct lpfc_hba for this port.
1194 * This fucnction resets the round robin bit mask and clears the
1195 * fcf priority list. The list deletions are done while holding the
1196 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1197 * from the lpfc_fcf_pri record.
1198 **/
1199void
1200lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1201{
1202 struct lpfc_fcf_pri *fcf_pri;
1203 struct lpfc_fcf_pri *next_fcf_pri;
1204 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1205 spin_lock_irq(&phba->hbalock);
1206 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1207 &phba->fcf.fcf_pri_list, list) {
1208 list_del_init(&fcf_pri->list);
1209 fcf_pri->fcf_rec.flag = 0;
1210 }
1211 spin_unlock_irq(&phba->hbalock);
1212}
dea31012005-04-17 16:05:31 -05001213static void
James Smart6fb120a2009-05-22 14:52:59 -04001214lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1215{
1216 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001217
1218 if (mboxq->u.mb.mbxStatus) {
1219 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1220 "2017 REG_FCFI mbxStatus error x%x "
1221 "HBA state x%x\n",
1222 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001223 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001224 }
1225
1226 /* Start FCoE discovery by sending a FLOGI. */
1227 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1228 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001229 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001230 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001231 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001232
James Smart32b97932009-07-19 10:01:21 -04001233 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001234 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1235 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001236 goto fail_out;
1237
1238 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001239 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001240 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001241 phba->hba_flag &= ~FCF_TS_INPROG;
1242 if (vport->port_state != LPFC_FLOGI) {
1243 phba->hba_flag |= FCF_RR_INPROG;
1244 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001245 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001246 goto out;
1247 }
1248 spin_unlock_irq(&phba->hbalock);
1249 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001250
James Smarta93ff372010-10-22 11:06:08 -04001251fail_out:
1252 spin_lock_irq(&phba->hbalock);
1253 phba->hba_flag &= ~FCF_RR_INPROG;
1254 spin_unlock_irq(&phba->hbalock);
1255out:
James Smart6fb120a2009-05-22 14:52:59 -04001256 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001257}
1258
1259/**
1260 * lpfc_fab_name_match - Check if the fcf fabric name match.
1261 * @fab_name: pointer to fabric name.
1262 * @new_fcf_record: pointer to fcf record.
1263 *
1264 * This routine compare the fcf record's fabric name with provided
1265 * fabric name. If the fabric name are identical this function
1266 * returns 1 else return 0.
1267 **/
1268static uint32_t
1269lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1270{
James Smartecfd03c2010-02-12 14:41:27 -05001271 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001272 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001273 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1274 return 0;
1275 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1276 return 0;
1277 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1278 return 0;
1279 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1280 return 0;
1281 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1282 return 0;
1283 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1284 return 0;
1285 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1286 return 0;
1287 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001288}
1289
1290/**
James Smart8fa38512009-07-19 10:01:03 -04001291 * lpfc_sw_name_match - Check if the fcf switch name match.
1292 * @fab_name: pointer to fabric name.
1293 * @new_fcf_record: pointer to fcf record.
1294 *
1295 * This routine compare the fcf record's switch name with provided
1296 * switch name. If the switch name are identical this function
1297 * returns 1 else return 0.
1298 **/
1299static uint32_t
1300lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1301{
James Smartecfd03c2010-02-12 14:41:27 -05001302 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001303 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001304 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1305 return 0;
1306 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1307 return 0;
1308 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1309 return 0;
1310 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1311 return 0;
1312 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1313 return 0;
1314 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1315 return 0;
1316 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1317 return 0;
1318 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001319}
1320
1321/**
James Smart6fb120a2009-05-22 14:52:59 -04001322 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001323 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001324 * @new_fcf_record: pointer to fcf record.
1325 *
1326 * This routine compare the fcf record's mac address with HBA's
1327 * FCF mac address. If the mac addresses are identical this function
1328 * returns 1 else return 0.
1329 **/
1330static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001331lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001332{
James Smartecfd03c2010-02-12 14:41:27 -05001333 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001334 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001335 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1336 return 0;
1337 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1338 return 0;
1339 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1340 return 0;
1341 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1342 return 0;
1343 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1344 return 0;
1345 return 1;
1346}
1347
1348static bool
1349lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1350{
1351 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001352}
1353
1354/**
James Smart7d791df2011-07-22 18:37:52 -04001355 * lpfc_update_fcf_record - Update driver fcf record
1356 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1357 * @phba: pointer to lpfc hba data structure.
1358 * @fcf_index: Index for the lpfc_fcf_record.
1359 * @new_fcf_record: pointer to hba fcf record.
1360 *
1361 * This routine updates the driver FCF priority record from the new HBA FCF
1362 * record. This routine is called with the host lock held.
1363 **/
1364static void
1365__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1366 struct fcf_record *new_fcf_record
1367 )
1368{
1369 struct lpfc_fcf_pri *fcf_pri;
1370
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001371 lockdep_assert_held(&phba->hbalock);
1372
James Smart7d791df2011-07-22 18:37:52 -04001373 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1374 fcf_pri->fcf_rec.fcf_index = fcf_index;
1375 /* FCF record priority */
1376 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1377
1378}
1379
1380/**
James Smart6fb120a2009-05-22 14:52:59 -04001381 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001382 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001383 * @new_fcf_record: pointer to fcf record.
1384 *
1385 * This routine copies the FCF information from the FCF
1386 * record to lpfc_hba data structure.
1387 **/
1388static void
James Smartecfd03c2010-02-12 14:41:27 -05001389lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1390 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001391{
James Smartecfd03c2010-02-12 14:41:27 -05001392 /* Fabric name */
1393 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001394 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001395 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001396 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001397 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001398 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001399 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001400 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001401 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001402 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001403 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001404 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001405 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001406 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001407 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001408 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001409 /* Mac address */
1410 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1411 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1412 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1413 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1414 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1415 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1416 /* FCF record index */
1417 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1418 /* FCF record priority */
1419 fcf_rec->priority = new_fcf_record->fip_priority;
1420 /* Switch name */
1421 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001422 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001423 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001424 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001425 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001426 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001427 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001428 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001429 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001430 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001431 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001432 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001433 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001434 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001435 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001436 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001437}
1438
1439/**
James Smartecfd03c2010-02-12 14:41:27 -05001440 * lpfc_update_fcf_record - Update driver fcf record
1441 * @phba: pointer to lpfc hba data structure.
1442 * @fcf_rec: pointer to driver fcf record.
1443 * @new_fcf_record: pointer to hba fcf record.
1444 * @addr_mode: address mode to be set to the driver fcf record.
1445 * @vlan_id: vlan tag to be set to the driver fcf record.
1446 * @flag: flag bits to be set to the driver fcf record.
1447 *
1448 * This routine updates the driver FCF record from the new HBA FCF record
1449 * together with the address mode, vlan_id, and other informations. This
1450 * routine is called with the host lock held.
1451 **/
1452static void
1453__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1454 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1455 uint16_t vlan_id, uint32_t flag)
1456{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001457 lockdep_assert_held(&phba->hbalock);
1458
James Smartecfd03c2010-02-12 14:41:27 -05001459 /* Copy the fields from the HBA's FCF record */
1460 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1461 /* Update other fields of driver FCF record */
1462 fcf_rec->addr_mode = addr_mode;
1463 fcf_rec->vlan_id = vlan_id;
1464 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001465 __lpfc_update_fcf_record_pri(phba,
1466 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1467 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001468}
1469
1470/**
James Smart6fb120a2009-05-22 14:52:59 -04001471 * lpfc_register_fcf - Register the FCF with hba.
1472 * @phba: pointer to lpfc hba data structure.
1473 *
1474 * This routine issues a register fcfi mailbox command to register
1475 * the fcf with HBA.
1476 **/
1477static void
1478lpfc_register_fcf(struct lpfc_hba *phba)
1479{
1480 LPFC_MBOXQ_t *fcf_mbxq;
1481 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001482
James Smartd439d282010-09-29 11:18:45 -04001483 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001484 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001485 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001486 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001487 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001488 return;
1489 }
1490
1491 /* The FCF is already registered, start discovery */
1492 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001493 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001494 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001495 if (phba->pport->port_state != LPFC_FLOGI &&
1496 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001497 phba->hba_flag |= FCF_RR_INPROG;
1498 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001499 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001500 return;
1501 }
1502 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001503 return;
1504 }
James Smartd439d282010-09-29 11:18:45 -04001505 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001506
James Smarta93ff372010-10-22 11:06:08 -04001507 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001508 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001509 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001510 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001511 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001512 return;
James Smart4d9ab992009-10-02 15:16:39 -04001513 }
James Smart6fb120a2009-05-22 14:52:59 -04001514
1515 lpfc_reg_fcfi(phba, fcf_mbxq);
1516 fcf_mbxq->vport = phba->pport;
1517 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1518 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001519 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001520 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001521 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001522 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001523 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001524 }
James Smart6fb120a2009-05-22 14:52:59 -04001525
1526 return;
1527}
1528
1529/**
1530 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1531 * @phba: pointer to lpfc hba data structure.
1532 * @new_fcf_record: pointer to fcf record.
1533 * @boot_flag: Indicates if this record used by boot bios.
1534 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001535 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001536 *
1537 * This routine compare the fcf record with connect list obtained from the
1538 * config region to decide if this FCF can be used for SAN discovery. It returns
1539 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1540 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1541 * is used by boot bios and addr_mode will indicate the addressing mode to be
1542 * used for this FCF when the function returns.
1543 * If the FCF record need to be used with a particular vlan id, the vlan is
1544 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001545 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001546 **/
1547static int
1548lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1549 struct fcf_record *new_fcf_record,
1550 uint32_t *boot_flag, uint32_t *addr_mode,
1551 uint16_t *vlan_id)
1552{
1553 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001554 int i, j, fcf_vlan_id = 0;
1555
1556 /* Find the lowest VLAN id in the FCF record */
1557 for (i = 0; i < 512; i++) {
1558 if (new_fcf_record->vlan_bitmap[i]) {
1559 fcf_vlan_id = i * 8;
1560 j = 0;
1561 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1562 j++;
1563 fcf_vlan_id++;
1564 }
1565 break;
1566 }
1567 }
James Smart6fb120a2009-05-22 14:52:59 -04001568
James Smart26979ce2012-09-29 11:31:55 -04001569 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001570 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001571 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1572 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001573 return 0;
1574
James Smart45ed1192009-10-02 15:17:02 -04001575 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001576 *boot_flag = 0;
1577 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1578 new_fcf_record);
1579 if (phba->valid_vlan)
1580 *vlan_id = phba->vlan_id;
1581 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001582 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001583 return 1;
1584 }
1585
1586 /*
1587 * If there are no FCF connection table entry, driver connect to all
1588 * FCFs.
1589 */
1590 if (list_empty(&phba->fcf_conn_rec_list)) {
1591 *boot_flag = 0;
1592 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1593 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001594
1595 /*
1596 * When there are no FCF connect entries, use driver's default
1597 * addressing mode - FPMA.
1598 */
1599 if (*addr_mode & LPFC_FCF_FPMA)
1600 *addr_mode = LPFC_FCF_FPMA;
1601
James Smart4d9ab992009-10-02 15:16:39 -04001602 /* If FCF record report a vlan id use that vlan id */
1603 if (fcf_vlan_id)
1604 *vlan_id = fcf_vlan_id;
1605 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001606 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001607 return 1;
1608 }
1609
James Smartecfd03c2010-02-12 14:41:27 -05001610 list_for_each_entry(conn_entry,
1611 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001612 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1613 continue;
1614
1615 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1616 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001617 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001618 continue;
James Smart8fa38512009-07-19 10:01:03 -04001619 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1620 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1621 new_fcf_record))
1622 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001623 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1624 /*
1625 * If the vlan bit map does not have the bit set for the
1626 * vlan id to be used, then it is not a match.
1627 */
1628 if (!(new_fcf_record->vlan_bitmap
1629 [conn_entry->conn_rec.vlan_tag / 8] &
1630 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1631 continue;
1632 }
1633
1634 /*
James Smart0c287582009-06-10 17:22:56 -04001635 * If connection record does not support any addressing mode,
1636 * skip the FCF record.
1637 */
1638 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1639 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1640 continue;
1641
1642 /*
James Smart6fb120a2009-05-22 14:52:59 -04001643 * Check if the connection record specifies a required
1644 * addressing mode.
1645 */
1646 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1647 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1648
1649 /*
1650 * If SPMA required but FCF not support this continue.
1651 */
1652 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1653 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1654 new_fcf_record) & LPFC_FCF_SPMA))
1655 continue;
1656
1657 /*
1658 * If FPMA required but FCF not support this continue.
1659 */
1660 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1661 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1662 new_fcf_record) & LPFC_FCF_FPMA))
1663 continue;
1664 }
1665
1666 /*
1667 * This fcf record matches filtering criteria.
1668 */
1669 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1670 *boot_flag = 1;
1671 else
1672 *boot_flag = 0;
1673
James Smart0c287582009-06-10 17:22:56 -04001674 /*
1675 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001676 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001677 * by FCF, allow fabric to pick the addressing mode.
1678 */
James Smart6fb120a2009-05-22 14:52:59 -04001679 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1680 new_fcf_record);
1681 /*
1682 * If the user specified a required address mode, assign that
1683 * address mode
1684 */
1685 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1686 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1687 *addr_mode = (conn_entry->conn_rec.flags &
1688 FCFCNCT_AM_SPMA) ?
1689 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1690 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001691 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001692 * addr mode only if FCF support the addr_mode.
1693 */
1694 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1695 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1696 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1697 (*addr_mode & LPFC_FCF_SPMA))
1698 *addr_mode = LPFC_FCF_SPMA;
1699 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1700 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1701 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1702 (*addr_mode & LPFC_FCF_FPMA))
1703 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001704
James Smart4d9ab992009-10-02 15:16:39 -04001705 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001706 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1707 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001708 /*
1709 * If no vlan id is specified in connect list, use the vlan id
1710 * in the FCF record
1711 */
1712 else if (fcf_vlan_id)
1713 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001714 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001715 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001716
1717 return 1;
1718 }
1719
1720 return 0;
1721}
1722
1723/**
James Smart32b97932009-07-19 10:01:21 -04001724 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1725 * @phba: pointer to lpfc hba data structure.
1726 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1727 *
1728 * This function check if there is any fcoe event pending while driver
1729 * scan FCF entries. If there is any pending event, it will restart the
1730 * FCF saning and return 1 else return 0.
1731 */
1732int
1733lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1734{
James Smart32b97932009-07-19 10:01:21 -04001735 /*
1736 * If the Link is up and no FCoE events while in the
1737 * FCF discovery, no need to restart FCF discovery.
1738 */
1739 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001740 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001741 return 0;
1742
James Smart0c9ab6f2010-02-26 14:15:57 -05001743 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1744 "2768 Pending link or FCF event during current "
1745 "handling of the previous event: link_state:x%x, "
1746 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1747 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1748 phba->fcoe_eventtag);
1749
James Smart32b97932009-07-19 10:01:21 -04001750 spin_lock_irq(&phba->hbalock);
1751 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1752 spin_unlock_irq(&phba->hbalock);
1753
James Smart0c9ab6f2010-02-26 14:15:57 -05001754 if (phba->link_state >= LPFC_LINK_UP) {
1755 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1756 "2780 Restart FCF table scan due to "
1757 "pending FCF event:evt_tag_at_scan:x%x, "
1758 "evt_tag_current:x%x\n",
1759 phba->fcoe_eventtag_at_fcf_scan,
1760 phba->fcoe_eventtag);
1761 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1762 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001763 /*
James Smarta93ff372010-10-22 11:06:08 -04001764 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001765 * flag
1766 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001767 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1768 "2833 Stop FCF discovery process due to link "
1769 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001770 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001771 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001772 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001773 spin_unlock_irq(&phba->hbalock);
1774 }
James Smart32b97932009-07-19 10:01:21 -04001775
James Smart0c9ab6f2010-02-26 14:15:57 -05001776 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001777 if (unreg_fcf) {
1778 spin_lock_irq(&phba->hbalock);
1779 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1780 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001781 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001782 }
James Smart32b97932009-07-19 10:01:21 -04001783 return 1;
1784}
1785
1786/**
James Smart999d8132010-03-15 11:24:56 -04001787 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1788 * @phba: pointer to lpfc hba data structure.
1789 * @fcf_cnt: number of eligible fcf record seen so far.
1790 *
1791 * This function makes an running random selection decision on FCF record to
1792 * use through a sequence of @fcf_cnt eligible FCF records with equal
1793 * probability. To perform integer manunipulation of random numbers with
1794 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001795 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001796 *
1797 * Returns true when outcome is for the newly read FCF record should be
1798 * chosen; otherwise, return false when outcome is for keeping the previously
1799 * chosen FCF record.
1800 **/
1801static bool
1802lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1803{
1804 uint32_t rand_num;
1805
1806 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001807 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001808
1809 /* Decision with probability 1/fcf_cnt */
1810 if ((fcf_cnt * rand_num) < 0xFFFF)
1811 return true;
1812 else
1813 return false;
1814}
1815
1816/**
James Smart3804dc82010-07-14 15:31:37 -04001817 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001818 * @phba: pointer to lpfc hba data structure.
1819 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001820 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001821 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001822 * This routine parses the non-embedded fcf mailbox command by performing the
1823 * necessarily error checking, non-embedded read FCF record mailbox command
1824 * SGE parsing, and endianness swapping.
1825 *
1826 * Returns the pointer to the new FCF record in the non-embedded mailbox
1827 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001828 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001829static struct fcf_record *
1830lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1831 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001832{
1833 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001834 struct lpfc_mbx_sge sge;
1835 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001836 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001837 union lpfc_sli4_cfg_shdr *shdr;
1838 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001839
James Smart6fb120a2009-05-22 14:52:59 -04001840 /* Get the first SGE entry from the non-embedded DMA memory. This
1841 * routine only uses a single SGE.
1842 */
1843 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001844 if (unlikely(!mboxq->sge_array)) {
1845 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1846 "2524 Failed to get the non-embedded SGE "
1847 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001848 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001849 }
1850 virt_addr = mboxq->sge_array->addr[0];
1851
1852 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001853 lpfc_sli_pcimem_bcopy(shdr, shdr,
1854 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001855 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001856 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001857 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001858 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001859 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1860 if_type == LPFC_SLI_INTF_IF_TYPE_2)
James Smart0c9ab6f2010-02-26 14:15:57 -05001861 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001862 "2726 READ_FCF_RECORD Indicates empty "
1863 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001864 else
1865 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001866 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001867 "with status x%x add_status x%x, "
1868 "mbx\n", shdr_status, shdr_add_status);
1869 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001870 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001871
1872 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001873 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1874 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1875 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001876 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001877 new_fcf_record = (struct fcf_record *)(virt_addr +
1878 sizeof(struct lpfc_mbx_read_fcf_tbl));
1879 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001880 offsetof(struct fcf_record, vlan_bitmap));
1881 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1882 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001883
James Smart0c9ab6f2010-02-26 14:15:57 -05001884 return new_fcf_record;
1885}
1886
1887/**
1888 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1889 * @phba: pointer to lpfc hba data structure.
1890 * @fcf_record: pointer to the fcf record.
1891 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1892 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1893 *
1894 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1895 * enabled.
1896 **/
1897static void
1898lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1899 struct fcf_record *fcf_record,
1900 uint16_t vlan_id,
1901 uint16_t next_fcf_index)
1902{
1903 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1904 "2764 READ_FCF_RECORD:\n"
1905 "\tFCF_Index : x%x\n"
1906 "\tFCF_Avail : x%x\n"
1907 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001908 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001909 "\tFIP_Priority : x%x\n"
1910 "\tMAC_Provider : x%x\n"
1911 "\tLowest VLANID : x%x\n"
1912 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1913 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1914 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1915 "\tNext_FCF_Index: x%x\n",
1916 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1917 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1918 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001919 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001920 fcf_record->fip_priority,
1921 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1922 vlan_id,
1923 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1924 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1925 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1926 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1927 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1928 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1929 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1930 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1931 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1932 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1933 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1934 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1935 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1936 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1937 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1938 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1939 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1940 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1941 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1942 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1943 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1944 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1945 next_fcf_index);
1946}
1947
1948/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001949 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1950 * @phba: pointer to lpfc hba data structure.
1951 * @fcf_rec: pointer to an existing FCF record.
1952 * @new_fcf_record: pointer to a new FCF record.
1953 * @new_vlan_id: vlan id from the new FCF record.
1954 *
1955 * This function performs matching test of a new FCF record against an existing
1956 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1957 * will not be used as part of the FCF record matching criteria.
1958 *
1959 * Returns true if all the fields matching, otherwise returns false.
1960 */
1961static bool
1962lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1963 struct lpfc_fcf_rec *fcf_rec,
1964 struct fcf_record *new_fcf_record,
1965 uint16_t new_vlan_id)
1966{
1967 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1968 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1969 return false;
1970 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1971 return false;
1972 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1973 return false;
1974 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1975 return false;
James Smart7d791df2011-07-22 18:37:52 -04001976 if (fcf_rec->priority != new_fcf_record->fip_priority)
1977 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001978 return true;
1979}
1980
1981/**
James Smarta93ff372010-10-22 11:06:08 -04001982 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1983 * @vport: Pointer to vport object.
1984 * @fcf_index: index to next fcf.
1985 *
1986 * This function processing the roundrobin fcf failover to next fcf index.
1987 * When this function is invoked, there will be a current fcf registered
1988 * for flogi.
1989 * Return: 0 for continue retrying flogi on currently registered fcf;
1990 * 1 for stop flogi on currently registered fcf;
1991 */
1992int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1993{
1994 struct lpfc_hba *phba = vport->phba;
1995 int rc;
1996
1997 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1998 spin_lock_irq(&phba->hbalock);
1999 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2000 spin_unlock_irq(&phba->hbalock);
2001 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2002 "2872 Devloss tmo with no eligible "
2003 "FCF, unregister in-use FCF (x%x) "
2004 "and rescan FCF table\n",
2005 phba->fcf.current_rec.fcf_indx);
2006 lpfc_unregister_fcf_rescan(phba);
2007 goto stop_flogi_current_fcf;
2008 }
2009 /* Mark the end to FLOGI roundrobin failover */
2010 phba->hba_flag &= ~FCF_RR_INPROG;
2011 /* Allow action to new fcf asynchronous event */
2012 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2013 spin_unlock_irq(&phba->hbalock);
2014 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2015 "2865 No FCF available, stop roundrobin FCF "
2016 "failover and change port state:x%x/x%x\n",
2017 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2018 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002019
2020 if (!phba->fcf.fcf_redisc_attempted) {
2021 lpfc_unregister_fcf(phba);
2022
2023 rc = lpfc_sli4_redisc_fcf_table(phba);
2024 if (!rc) {
2025 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2026 "3195 Rediscover FCF table\n");
2027 phba->fcf.fcf_redisc_attempted = 1;
2028 lpfc_sli4_clear_fcf_rr_bmask(phba);
2029 } else {
2030 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2031 "3196 Rediscover FCF table "
2032 "failed. Status:x%x\n", rc);
2033 }
2034 } else {
2035 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2036 "3197 Already rediscover FCF table "
2037 "attempted. No more retry\n");
2038 }
James Smarta93ff372010-10-22 11:06:08 -04002039 goto stop_flogi_current_fcf;
2040 } else {
2041 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2042 "2794 Try FLOGI roundrobin FCF failover to "
2043 "(x%x)\n", fcf_index);
2044 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2045 if (rc)
2046 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2047 "2761 FLOGI roundrobin FCF failover "
2048 "failed (rc:x%x) to read FCF (x%x)\n",
2049 rc, phba->fcf.current_rec.fcf_indx);
2050 else
2051 goto stop_flogi_current_fcf;
2052 }
2053 return 0;
2054
2055stop_flogi_current_fcf:
2056 lpfc_can_disctmo(vport);
2057 return 1;
2058}
2059
2060/**
James Smart7d791df2011-07-22 18:37:52 -04002061 * lpfc_sli4_fcf_pri_list_del
2062 * @phba: pointer to lpfc hba data structure.
2063 * @fcf_index the index of the fcf record to delete
2064 * This routine checks the on list flag of the fcf_index to be deleted.
2065 * If it is one the list then it is removed from the list, and the flag
2066 * is cleared. This routine grab the hbalock before removing the fcf
2067 * record from the list.
2068 **/
2069static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2070 uint16_t fcf_index)
2071{
2072 struct lpfc_fcf_pri *new_fcf_pri;
2073
2074 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2075 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2076 "3058 deleting idx x%x pri x%x flg x%x\n",
2077 fcf_index, new_fcf_pri->fcf_rec.priority,
2078 new_fcf_pri->fcf_rec.flag);
2079 spin_lock_irq(&phba->hbalock);
2080 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2081 if (phba->fcf.current_rec.priority ==
2082 new_fcf_pri->fcf_rec.priority)
2083 phba->fcf.eligible_fcf_cnt--;
2084 list_del_init(&new_fcf_pri->list);
2085 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2086 }
2087 spin_unlock_irq(&phba->hbalock);
2088}
2089
2090/**
2091 * lpfc_sli4_set_fcf_flogi_fail
2092 * @phba: pointer to lpfc hba data structure.
2093 * @fcf_index the index of the fcf record to update
2094 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2095 * flag so the the round robin slection for the particular priority level
2096 * will try a different fcf record that does not have this bit set.
2097 * If the fcf record is re-read for any reason this flag is cleared brfore
2098 * adding it to the priority list.
2099 **/
2100void
2101lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2102{
2103 struct lpfc_fcf_pri *new_fcf_pri;
2104 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2105 spin_lock_irq(&phba->hbalock);
2106 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2107 spin_unlock_irq(&phba->hbalock);
2108}
2109
2110/**
2111 * lpfc_sli4_fcf_pri_list_add
2112 * @phba: pointer to lpfc hba data structure.
2113 * @fcf_index the index of the fcf record to add
2114 * This routine checks the priority of the fcf_index to be added.
2115 * If it is a lower priority than the current head of the fcf_pri list
2116 * then it is added to the list in the right order.
2117 * If it is the same priority as the current head of the list then it
2118 * is added to the head of the list and its bit in the rr_bmask is set.
2119 * If the fcf_index to be added is of a higher priority than the current
2120 * head of the list then the rr_bmask is cleared, its bit is set in the
2121 * rr_bmask and it is added to the head of the list.
2122 * returns:
2123 * 0=success 1=failure
2124 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002125static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2126 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002127 struct fcf_record *new_fcf_record)
2128{
2129 uint16_t current_fcf_pri;
2130 uint16_t last_index;
2131 struct lpfc_fcf_pri *fcf_pri;
2132 struct lpfc_fcf_pri *next_fcf_pri;
2133 struct lpfc_fcf_pri *new_fcf_pri;
2134 int ret;
2135
2136 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2137 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2138 "3059 adding idx x%x pri x%x flg x%x\n",
2139 fcf_index, new_fcf_record->fip_priority,
2140 new_fcf_pri->fcf_rec.flag);
2141 spin_lock_irq(&phba->hbalock);
2142 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2143 list_del_init(&new_fcf_pri->list);
2144 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2145 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2146 if (list_empty(&phba->fcf.fcf_pri_list)) {
2147 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2148 ret = lpfc_sli4_fcf_rr_index_set(phba,
2149 new_fcf_pri->fcf_rec.fcf_index);
2150 goto out;
2151 }
2152
2153 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2154 LPFC_SLI4_FCF_TBL_INDX_MAX);
2155 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2156 ret = 0; /* Empty rr list */
2157 goto out;
2158 }
2159 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2160 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2161 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2162 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2163 memset(phba->fcf.fcf_rr_bmask, 0,
2164 sizeof(*phba->fcf.fcf_rr_bmask));
2165 /* fcfs_at_this_priority_level = 1; */
2166 phba->fcf.eligible_fcf_cnt = 1;
2167 } else
2168 /* fcfs_at_this_priority_level++; */
2169 phba->fcf.eligible_fcf_cnt++;
2170 ret = lpfc_sli4_fcf_rr_index_set(phba,
2171 new_fcf_pri->fcf_rec.fcf_index);
2172 goto out;
2173 }
2174
2175 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2176 &phba->fcf.fcf_pri_list, list) {
2177 if (new_fcf_pri->fcf_rec.priority <=
2178 fcf_pri->fcf_rec.priority) {
2179 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2180 list_add(&new_fcf_pri->list,
2181 &phba->fcf.fcf_pri_list);
2182 else
2183 list_add(&new_fcf_pri->list,
2184 &((struct lpfc_fcf_pri *)
2185 fcf_pri->list.prev)->list);
2186 ret = 0;
2187 goto out;
2188 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2189 || new_fcf_pri->fcf_rec.priority <
2190 next_fcf_pri->fcf_rec.priority) {
2191 list_add(&new_fcf_pri->list, &fcf_pri->list);
2192 ret = 0;
2193 goto out;
2194 }
2195 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2196 continue;
2197
2198 }
2199 ret = 1;
2200out:
2201 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2202 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2203 spin_unlock_irq(&phba->hbalock);
2204 return ret;
2205}
2206
2207/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002208 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2209 * @phba: pointer to lpfc hba data structure.
2210 * @mboxq: pointer to mailbox object.
2211 *
2212 * This function iterates through all the fcf records available in
2213 * HBA and chooses the optimal FCF record for discovery. After finding
2214 * the FCF for discovery it registers the FCF record and kicks start
2215 * discovery.
2216 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2217 * use an FCF record which matches fabric name and mac address of the
2218 * currently used FCF record.
2219 * If the driver supports only one FCF, it will try to use the FCF record
2220 * used by BOOT_BIOS.
2221 */
2222void
2223lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2224{
2225 struct fcf_record *new_fcf_record;
2226 uint32_t boot_flag, addr_mode;
2227 uint16_t fcf_index, next_fcf_index;
2228 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002229 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002230 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002231 int rc;
2232
2233 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002234 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002235 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2236 return;
2237 }
2238
2239 /* Parse the FCF record from the non-embedded mailbox command */
2240 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2241 &next_fcf_index);
2242 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002243 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002244 "2765 Mailbox command READ_FCF_RECORD "
2245 "failed to retrieve a FCF record.\n");
2246 /* Let next new FCF event trigger fast failover */
2247 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002248 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002249 spin_unlock_irq(&phba->hbalock);
2250 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2251 return;
2252 }
2253
2254 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002255 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2256 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002257
2258 /* Log the FCF record information if turned on */
2259 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2260 next_fcf_index);
2261
James Smart6fb120a2009-05-22 14:52:59 -04002262 /*
2263 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002264 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002265 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002266 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002267 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002268 lpfc_sli4_fcf_pri_list_del(phba,
2269 bf_get(lpfc_fcf_record_fcf_index,
2270 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002271 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002272 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002273 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002274 bf_get(lpfc_fcf_record_fcf_index,
2275 new_fcf_record),
2276 bf_get(lpfc_fcf_record_fcf_avail,
2277 new_fcf_record),
2278 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002279 new_fcf_record),
2280 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002281 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002282 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2283 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2284 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002285 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2286 phba->fcf.current_rec.fcf_indx) {
2287 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2288 "2862 FCF (x%x) matches property "
2289 "of in-use FCF (x%x)\n",
2290 bf_get(lpfc_fcf_record_fcf_index,
2291 new_fcf_record),
2292 phba->fcf.current_rec.fcf_indx);
2293 goto read_next_fcf;
2294 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002295 /*
2296 * In case the current in-use FCF record becomes
2297 * invalid/unavailable during FCF discovery that
2298 * was not triggered by fast FCF failover process,
2299 * treat it as fast FCF failover.
2300 */
2301 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2302 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2303 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2304 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002305 "(x%x), enter FCF failover "
2306 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002307 phba->fcf.current_rec.fcf_indx);
2308 spin_lock_irq(&phba->hbalock);
2309 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2310 spin_unlock_irq(&phba->hbalock);
2311 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2312 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2313 LPFC_FCOE_FCF_GET_FIRST);
2314 return;
2315 }
2316 }
James Smart6fb120a2009-05-22 14:52:59 -04002317 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002318 } else {
2319 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002320 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2321 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002322 if (rc)
2323 goto read_next_fcf;
2324 }
2325
James Smart6fb120a2009-05-22 14:52:59 -04002326 /*
2327 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002328 * FCF record for the discovery. The condition that a rescan
2329 * matches the in-use FCF record: fabric name, switch name, mac
2330 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002331 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002332 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002333 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002334 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2335 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002336 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002337 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2338 phba->fcf.current_rec.fcf_indx) {
2339 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2340 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2341 /* Stop FCF redisc wait timer */
2342 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2343 phba);
2344 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2345 /* Fast failover, mark completed */
2346 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2347 spin_unlock_irq(&phba->hbalock);
2348 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2349 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002350 "FCF (x%x), port_state:x%x, "
2351 "fc_flag:x%x\n",
2352 phba->fcf.current_rec.fcf_indx,
2353 phba->pport->port_state,
2354 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002355 goto out;
2356 } else
2357 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2358 "2863 New FCF (x%x) matches "
2359 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002360 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002361 new_fcf_record),
2362 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002363 }
James Smartecfd03c2010-02-12 14:41:27 -05002364 /*
2365 * Read next FCF record from HBA searching for the matching
2366 * with in-use record only if not during the fast failover
2367 * period. In case of fast failover period, it shall try to
2368 * determine whether the FCF record just read should be the
2369 * next candidate.
2370 */
2371 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002372 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002373 goto read_next_fcf;
2374 }
James Smart6fb120a2009-05-22 14:52:59 -04002375 }
James Smartecfd03c2010-02-12 14:41:27 -05002376 /*
2377 * Update on failover FCF record only if it's in FCF fast-failover
2378 * period; otherwise, update on current FCF record.
2379 */
James Smartfc2b9892010-02-26 14:15:29 -05002380 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2381 fcf_rec = &phba->fcf.failover_rec;
2382 else
James Smartecfd03c2010-02-12 14:41:27 -05002383 fcf_rec = &phba->fcf.current_rec;
2384
James Smart6fb120a2009-05-22 14:52:59 -04002385 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2386 /*
James Smartecfd03c2010-02-12 14:41:27 -05002387 * If the driver FCF record does not have boot flag
2388 * set and new hba fcf record has boot flag set, use
2389 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002390 */
James Smartecfd03c2010-02-12 14:41:27 -05002391 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2392 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002393 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2394 "2837 Update current FCF record "
2395 "(x%x) with new FCF record (x%x)\n",
2396 fcf_rec->fcf_indx,
2397 bf_get(lpfc_fcf_record_fcf_index,
2398 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002399 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2400 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002401 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002402 goto read_next_fcf;
2403 }
2404 /*
James Smartecfd03c2010-02-12 14:41:27 -05002405 * If the driver FCF record has boot flag set and the
2406 * new hba FCF record does not have boot flag, read
2407 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002408 */
James Smartecfd03c2010-02-12 14:41:27 -05002409 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002410 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002411 goto read_next_fcf;
2412 }
2413 /*
James Smartecfd03c2010-02-12 14:41:27 -05002414 * If the new hba FCF record has lower priority value
2415 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002416 */
James Smartfc2b9892010-02-26 14:15:29 -05002417 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002418 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002419 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2420 "2838 Update current FCF record "
2421 "(x%x) with new FCF record (x%x)\n",
2422 fcf_rec->fcf_indx,
2423 bf_get(lpfc_fcf_record_fcf_index,
2424 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002425 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2426 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002427 /* Reset running random FCF selection count */
2428 phba->fcf.eligible_fcf_cnt = 1;
2429 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2430 /* Update running random FCF selection count */
2431 phba->fcf.eligible_fcf_cnt++;
2432 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2433 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002434 if (select_new_fcf) {
2435 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2436 "2839 Update current FCF record "
2437 "(x%x) with new FCF record (x%x)\n",
2438 fcf_rec->fcf_indx,
2439 bf_get(lpfc_fcf_record_fcf_index,
2440 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002441 /* Choose the new FCF by random selection */
2442 __lpfc_update_fcf_record(phba, fcf_rec,
2443 new_fcf_record,
2444 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002445 }
James Smart6fb120a2009-05-22 14:52:59 -04002446 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002447 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002448 goto read_next_fcf;
2449 }
2450 /*
James Smartecfd03c2010-02-12 14:41:27 -05002451 * This is the first suitable FCF record, choose this record for
2452 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002453 */
James Smartecfd03c2010-02-12 14:41:27 -05002454 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002455 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002456 "2840 Update initial FCF candidate "
2457 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002458 bf_get(lpfc_fcf_record_fcf_index,
2459 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002460 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2461 addr_mode, vlan_id, (boot_flag ?
2462 BOOT_ENABLE : 0));
2463 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002464 /* Setup initial running random FCF selection count */
2465 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002466 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002467 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002468 goto read_next_fcf;
2469
2470read_next_fcf:
2471 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002472 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2473 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2474 /*
2475 * Case of FCF fast failover scan
2476 */
2477
2478 /*
2479 * It has not found any suitable FCF record, cancel
2480 * FCF scan inprogress, and do nothing
2481 */
2482 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002483 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002484 "2782 No suitable FCF found: "
2485 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002486 phba->fcoe_eventtag_at_fcf_scan,
2487 bf_get(lpfc_fcf_record_fcf_index,
2488 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002489 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002490 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2491 phba->hba_flag &= ~FCF_TS_INPROG;
2492 spin_unlock_irq(&phba->hbalock);
2493 /* Unregister in-use FCF and rescan */
2494 lpfc_printf_log(phba, KERN_INFO,
2495 LOG_FIP,
2496 "2864 On devloss tmo "
2497 "unreg in-use FCF and "
2498 "rescan FCF table\n");
2499 lpfc_unregister_fcf_rescan(phba);
2500 return;
2501 }
2502 /*
2503 * Let next new FCF event trigger fast failover
2504 */
2505 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002506 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002507 return;
2508 }
2509 /*
2510 * It has found a suitable FCF record that is not
2511 * the same as in-use FCF record, unregister the
2512 * in-use FCF record, replace the in-use FCF record
2513 * with the new FCF record, mark FCF fast failover
2514 * completed, and then start register the new FCF
2515 * record.
2516 */
2517
James Smart0c9ab6f2010-02-26 14:15:57 -05002518 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002519 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002520
2521 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002522 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002523 "2842 Replace in-use FCF (x%x) "
2524 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002525 phba->fcf.current_rec.fcf_indx,
2526 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002527 memcpy(&phba->fcf.current_rec,
2528 &phba->fcf.failover_rec,
2529 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002530 /*
2531 * Mark the fast FCF failover rediscovery completed
2532 * and the start of the first round of the roundrobin
2533 * FCF failover.
2534 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002535 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002536 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002537 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002538 /* Register to the new FCF record */
2539 lpfc_register_fcf(phba);
2540 } else {
2541 /*
2542 * In case of transaction period to fast FCF failover,
2543 * do nothing when search to the end of the FCF table.
2544 */
2545 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2546 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2547 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002548
James Smart7d791df2011-07-22 18:37:52 -04002549 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2550 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002551 /*
2552 * In case the current in-use FCF record no
2553 * longer existed during FCF discovery that
2554 * was not triggered by fast FCF failover
2555 * process, treat it as fast FCF failover.
2556 */
2557 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2558 "2841 In-use FCF record (x%x) "
2559 "not reported, entering fast "
2560 "FCF failover mode scanning.\n",
2561 phba->fcf.current_rec.fcf_indx);
2562 spin_lock_irq(&phba->hbalock);
2563 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2564 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002565 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2566 LPFC_FCOE_FCF_GET_FIRST);
2567 return;
2568 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002569 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002570 lpfc_register_fcf(phba);
2571 }
2572 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002573 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002574 return;
2575
2576out:
2577 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2578 lpfc_register_fcf(phba);
2579
2580 return;
2581}
2582
2583/**
James Smarta93ff372010-10-22 11:06:08 -04002584 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002585 * @phba: pointer to lpfc hba data structure.
2586 * @mboxq: pointer to mailbox object.
2587 *
James Smarta93ff372010-10-22 11:06:08 -04002588 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002589 * read FCF record mailbox command from the eligible FCF record bmask for
2590 * performing the failover. If the FCF read back is not valid/available, it
2591 * fails through to retrying FLOGI to the currently registered FCF again.
2592 * Otherwise, if the FCF read back is valid and available, it will set the
2593 * newly read FCF record to the failover FCF record, unregister currently
2594 * registered FCF record, copy the failover FCF record to the current
2595 * FCF record, and then register the current FCF record before proceeding
2596 * to trying FLOGI on the new failover FCF.
2597 */
2598void
2599lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2600{
2601 struct fcf_record *new_fcf_record;
2602 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002603 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002604 uint16_t current_fcf_index;
2605 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002606 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002607
James Smarta93ff372010-10-22 11:06:08 -04002608 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002609 if (phba->link_state < LPFC_LINK_UP) {
2610 spin_lock_irq(&phba->hbalock);
2611 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002612 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002613 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002614 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002615 }
2616
2617 /* Parse the FCF record from the non-embedded mailbox command */
2618 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2619 &next_fcf_index);
2620 if (!new_fcf_record) {
2621 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2622 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002623 "failed to retrieve a FCF record. "
2624 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2625 phba->fcf.fcf_flag);
2626 lpfc_unregister_fcf_rescan(phba);
2627 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002628 }
2629
2630 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002631 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2632 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002633
2634 /* Log the FCF record information if turned on */
2635 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2636 next_fcf_index);
2637
James Smarta93ff372010-10-22 11:06:08 -04002638 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2639 if (!rc) {
2640 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2641 "2848 Remove ineligible FCF (x%x) from "
2642 "from roundrobin bmask\n", fcf_index);
2643 /* Clear roundrobin bmask bit for ineligible FCF */
2644 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2645 /* Perform next round of roundrobin FCF failover */
2646 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2647 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2648 if (rc)
2649 goto out;
2650 goto error_out;
2651 }
2652
2653 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2654 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2655 "2760 Perform FLOGI roundrobin FCF failover: "
2656 "FCF (x%x) back to FCF (x%x)\n",
2657 phba->fcf.current_rec.fcf_indx, fcf_index);
2658 /* Wait 500 ms before retrying FLOGI to current FCF */
2659 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002660 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002661 goto out;
2662 }
2663
James Smart0c9ab6f2010-02-26 14:15:57 -05002664 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002665 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002666 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2667 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002668 spin_lock_irq(&phba->hbalock);
2669 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2670 new_fcf_record, addr_mode, vlan_id,
2671 (boot_flag ? BOOT_ENABLE : 0));
2672 spin_unlock_irq(&phba->hbalock);
2673
2674 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2675
2676 /* Unregister the current in-use FCF record */
2677 lpfc_unregister_fcf(phba);
2678
2679 /* Replace in-use record with the new record */
2680 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2681 sizeof(struct lpfc_fcf_rec));
2682
2683 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002684 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2685 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002686
James Smarta93ff372010-10-22 11:06:08 -04002687error_out:
2688 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002689out:
2690 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002691}
2692
2693/**
2694 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2695 * @phba: pointer to lpfc hba data structure.
2696 * @mboxq: pointer to mailbox object.
2697 *
2698 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002699 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002700 * failover when a new FCF event happened. If the FCF read back is
2701 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002702 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002703 */
2704void
2705lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2706{
2707 struct fcf_record *new_fcf_record;
2708 uint32_t boot_flag, addr_mode;
2709 uint16_t fcf_index, next_fcf_index;
2710 uint16_t vlan_id;
2711 int rc;
2712
2713 /* If link state is not up, no need to proceed */
2714 if (phba->link_state < LPFC_LINK_UP)
2715 goto out;
2716
2717 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002718 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002719 goto out;
2720
2721 /* Parse the FCF record from the non-embedded mailbox command */
2722 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2723 &next_fcf_index);
2724 if (!new_fcf_record) {
2725 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2726 "2767 Mailbox command READ_FCF_RECORD "
2727 "failed to retrieve a FCF record.\n");
2728 goto out;
2729 }
2730
2731 /* Check the connection list for eligibility */
2732 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2733 &addr_mode, &vlan_id);
2734
2735 /* Log the FCF record information if turned on */
2736 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2737 next_fcf_index);
2738
2739 if (!rc)
2740 goto out;
2741
2742 /* Update the eligible FCF record index bmask */
2743 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002744
2745 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002746
2747out:
2748 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2749}
2750
2751/**
James Smart76a95d72010-11-20 23:11:48 -05002752 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2753 * @phba: pointer to lpfc hba data structure.
2754 * @mboxq: pointer to mailbox data structure.
2755 *
2756 * This function handles completion of init vfi mailbox command.
2757 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002758static void
James Smart76a95d72010-11-20 23:11:48 -05002759lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2760{
2761 struct lpfc_vport *vport = mboxq->vport;
2762
James Smartdf9e1b52011-12-13 13:22:17 -05002763 /*
2764 * VFI not supported on interface type 0, just do the flogi
2765 * Also continue if the VFI is in use - just use the same one.
2766 */
2767 if (mboxq->u.mb.mbxStatus &&
2768 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2769 LPFC_SLI_INTF_IF_TYPE_0) &&
2770 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002771 lpfc_printf_vlog(vport, KERN_ERR,
2772 LOG_MBOX,
2773 "2891 Init VFI mailbox failed 0x%x\n",
2774 mboxq->u.mb.mbxStatus);
2775 mempool_free(mboxq, phba->mbox_mem_pool);
2776 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2777 return;
2778 }
James Smart73d91e52011-10-10 21:32:10 -04002779
James Smart76a95d72010-11-20 23:11:48 -05002780 lpfc_initial_flogi(vport);
2781 mempool_free(mboxq, phba->mbox_mem_pool);
2782 return;
2783}
2784
2785/**
2786 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2787 * @vport: pointer to lpfc_vport data structure.
2788 *
2789 * This function issue a init_vfi mailbox command to initialize the VFI and
2790 * VPI for the physical port.
2791 */
2792void
2793lpfc_issue_init_vfi(struct lpfc_vport *vport)
2794{
2795 LPFC_MBOXQ_t *mboxq;
2796 int rc;
2797 struct lpfc_hba *phba = vport->phba;
2798
2799 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2800 if (!mboxq) {
2801 lpfc_printf_vlog(vport, KERN_ERR,
2802 LOG_MBOX, "2892 Failed to allocate "
2803 "init_vfi mailbox\n");
2804 return;
2805 }
2806 lpfc_init_vfi(mboxq, vport);
2807 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2808 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2809 if (rc == MBX_NOT_FINISHED) {
2810 lpfc_printf_vlog(vport, KERN_ERR,
2811 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2812 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2813 }
2814}
2815
2816/**
James Smart1c6834a2009-07-19 10:01:26 -04002817 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2818 * @phba: pointer to lpfc hba data structure.
2819 * @mboxq: pointer to mailbox data structure.
2820 *
2821 * This function handles completion of init vpi mailbox command.
2822 */
James Smart695a8142010-01-26 23:08:03 -05002823void
James Smart1c6834a2009-07-19 10:01:26 -04002824lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2825{
2826 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002827 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2829
James Smart1c6834a2009-07-19 10:01:26 -04002830 if (mboxq->u.mb.mbxStatus) {
2831 lpfc_printf_vlog(vport, KERN_ERR,
2832 LOG_MBOX,
2833 "2609 Init VPI mailbox failed 0x%x\n",
2834 mboxq->u.mb.mbxStatus);
2835 mempool_free(mboxq, phba->mbox_mem_pool);
2836 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2837 return;
2838 }
James Smart72100cc2010-02-12 14:43:01 -05002839 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002840 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002841 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002842
James Smart695a8142010-01-26 23:08:03 -05002843 /* If this port is physical port or FDISC is done, do reg_vpi */
2844 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2845 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2846 if (!ndlp)
2847 lpfc_printf_vlog(vport, KERN_ERR,
2848 LOG_DISCOVERY,
2849 "2731 Cannot find fabric "
2850 "controller node\n");
2851 else
2852 lpfc_register_new_vport(phba, vport, ndlp);
2853 mempool_free(mboxq, phba->mbox_mem_pool);
2854 return;
2855 }
2856
James Smart1c6834a2009-07-19 10:01:26 -04002857 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2858 lpfc_initial_fdisc(vport);
2859 else {
2860 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002861 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2862 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002863 }
James Smart695a8142010-01-26 23:08:03 -05002864 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002865 return;
2866}
2867
2868/**
James Smartecfd03c2010-02-12 14:41:27 -05002869 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2870 * @vport: pointer to lpfc_vport data structure.
2871 *
2872 * This function issue a init_vpi mailbox command to initialize
2873 * VPI for the vport.
2874 */
2875void
2876lpfc_issue_init_vpi(struct lpfc_vport *vport)
2877{
2878 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002879 int rc, vpi;
2880
2881 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2882 vpi = lpfc_alloc_vpi(vport->phba);
2883 if (!vpi) {
2884 lpfc_printf_vlog(vport, KERN_ERR,
2885 LOG_MBOX,
2886 "3303 Failed to obtain vport vpi\n");
2887 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2888 return;
2889 }
2890 vport->vpi = vpi;
2891 }
James Smartecfd03c2010-02-12 14:41:27 -05002892
2893 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2894 if (!mboxq) {
2895 lpfc_printf_vlog(vport, KERN_ERR,
2896 LOG_MBOX, "2607 Failed to allocate "
2897 "init_vpi mailbox\n");
2898 return;
2899 }
2900 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2901 mboxq->vport = vport;
2902 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2903 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2904 if (rc == MBX_NOT_FINISHED) {
2905 lpfc_printf_vlog(vport, KERN_ERR,
2906 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2907 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2908 }
2909}
2910
2911/**
James Smart6fb120a2009-05-22 14:52:59 -04002912 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2913 * @phba: pointer to lpfc hba data structure.
2914 *
2915 * This function loops through the list of vports on the @phba and issues an
2916 * FDISC if possible.
2917 */
2918void
2919lpfc_start_fdiscs(struct lpfc_hba *phba)
2920{
2921 struct lpfc_vport **vports;
2922 int i;
2923
2924 vports = lpfc_create_vport_work_array(phba);
2925 if (vports != NULL) {
2926 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2927 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2928 continue;
2929 /* There are no vpi for this vport */
2930 if (vports[i]->vpi > phba->max_vpi) {
2931 lpfc_vport_set_state(vports[i],
2932 FC_VPORT_FAILED);
2933 continue;
2934 }
James Smart76a95d72010-11-20 23:11:48 -05002935 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002936 lpfc_vport_set_state(vports[i],
2937 FC_VPORT_LINKDOWN);
2938 continue;
2939 }
James Smart1c6834a2009-07-19 10:01:26 -04002940 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002941 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002942 continue;
2943 }
James Smart6fb120a2009-05-22 14:52:59 -04002944 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2945 lpfc_initial_fdisc(vports[i]);
2946 else {
2947 lpfc_vport_set_state(vports[i],
2948 FC_VPORT_NO_FABRIC_SUPP);
2949 lpfc_printf_vlog(vports[i], KERN_ERR,
2950 LOG_ELS,
2951 "0259 No NPIV "
2952 "Fabric support\n");
2953 }
2954 }
2955 }
2956 lpfc_destroy_vport_work_array(phba, vports);
2957}
2958
2959void
2960lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2961{
James Smart3e1f0712018-11-29 16:09:29 -08002962 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04002963 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002965
James Smartf5eca9b2012-03-01 22:37:54 -05002966 /*
2967 * VFI not supported for interface type 0, so ignore any mailbox
2968 * error (except VFI in use) and continue with the discovery.
2969 */
2970 if (mboxq->u.mb.mbxStatus &&
2971 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2972 LPFC_SLI_INTF_IF_TYPE_0) &&
2973 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002974 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2975 "2018 REG_VFI mbxStatus error x%x "
2976 "HBA state x%x\n",
2977 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002978 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002979 /* FLOGI failed, use loop map to make discovery list */
2980 lpfc_disc_list_loopmap(vport);
2981 /* Start discovery */
2982 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002983 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002984 }
2985 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002986 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002987 }
James Smartae05ebe2013-03-01 16:35:38 -05002988
James Smarte74c03c2013-04-17 20:15:19 -04002989 /* If the VFI is already registered, there is nothing else to do
2990 * Unless this was a VFI update and we are in PT2PT mode, then
2991 * we should drop through to set the port state to ready.
2992 */
James Smartae05ebe2013-03-01 16:35:38 -05002993 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04002994 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2995 vport->fc_flag & FC_PT2PT))
2996 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05002997
James Smartc8685952009-11-18 15:39:16 -05002998 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002999 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003000 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003001 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003002 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04003003 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003004 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04003005
James Smart1b511972011-12-13 13:23:09 -05003006 /* In case SLI4 FC loopback test, we are ready */
3007 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3008 (phba->link_flag & LS_LOOPBACK_MODE)) {
3009 phba->link_state = LPFC_HBA_READY;
3010 goto out_free_mem;
3011 }
3012
James Smarte74c03c2013-04-17 20:15:19 -04003013 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3014 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3015 "alpacnt:%d LinkState:%x topology:%x\n",
3016 vport->port_state, vport->fc_flag, vport->fc_myDID,
3017 vport->phba->alpa_map[0],
3018 phba->link_state, phba->fc_topology);
3019
James Smart6fb120a2009-05-22 14:52:59 -04003020 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003021 /*
3022 * For private loop or for NPort pt2pt,
3023 * just start discovery and we are done.
3024 */
3025 if ((vport->fc_flag & FC_PT2PT) ||
3026 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3027 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3028
James Smart76a95d72010-11-20 23:11:48 -05003029 /* Use loop map to make discovery list */
3030 lpfc_disc_list_loopmap(vport);
3031 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003032 if (vport->fc_flag & FC_PT2PT)
3033 vport->port_state = LPFC_VPORT_READY;
3034 else
3035 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003036 } else {
3037 lpfc_start_fdiscs(phba);
3038 lpfc_do_scr_ns_plogi(phba, vport);
3039 }
James Smart6fb120a2009-05-22 14:52:59 -04003040 }
3041
James Smart1b511972011-12-13 13:23:09 -05003042out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003043 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003044 if (dmabuf) {
3045 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3046 kfree(dmabuf);
3047 }
James Smart6fb120a2009-05-22 14:52:59 -04003048 return;
3049}
3050
3051static void
James Smart2e0fef82007-06-17 19:56:36 -05003052lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003053{
James Smart6fb120a2009-05-22 14:52:59 -04003054 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003055 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003056 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003057 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003058 struct serv_parm *sp = &vport->fc_sparam;
3059 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003060
3061 /* Check for error */
3062 if (mb->mbxStatus) {
3063 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003064 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3065 "0319 READ_SPARAM mbxStatus error x%x "
3066 "hba state x%x>\n",
3067 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003068 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003069 goto out;
3070 }
3071
James Smart2e0fef82007-06-17 19:56:36 -05003072 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003073 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003074
3075 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3076 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3077 ed_tov = (ed_tov + 999999) / 1000000;
3078
3079 phba->fc_edtov = ed_tov;
3080 phba->fc_ratov = (2 * ed_tov) / 1000;
3081 if (phba->fc_ratov < FF_DEF_RATOV) {
3082 /* RA_TOV should be atleast 10sec for initial flogi */
3083 phba->fc_ratov = FF_DEF_RATOV;
3084 }
3085
James Smart05580562011-05-24 11:40:48 -04003086 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003087 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003088 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3089 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3090 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3091 }
3092
dea31012005-04-17 16:05:31 -05003093 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3094 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003095 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003096 return;
3097
3098out:
James Smart3e1f0712018-11-29 16:09:29 -08003099 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3101 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003102 lpfc_issue_clear_la(phba, vport);
3103 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003104 return;
3105}
3106
3107static void
James Smart76a95d72010-11-20 23:11:48 -05003108lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003109{
James Smart92d7f7b2007-06-17 19:56:38 -05003110 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003111 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003112 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003113 int i;
James Smart14691152006-12-02 13:34:28 -05003114 struct lpfc_dmabuf *mp;
3115 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003116 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003117 uint32_t fc_flags = 0;
James Smart14691152006-12-02 13:34:28 -05003118
James Smart92d7f7b2007-06-17 19:56:38 -05003119 spin_lock_irq(&phba->hbalock);
James Smarta085e872015-12-16 18:12:02 -05003120 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3121
3122 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3123 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3124 case LPFC_LINK_SPEED_1GHZ:
3125 case LPFC_LINK_SPEED_2GHZ:
3126 case LPFC_LINK_SPEED_4GHZ:
3127 case LPFC_LINK_SPEED_8GHZ:
3128 case LPFC_LINK_SPEED_10GHZ:
3129 case LPFC_LINK_SPEED_16GHZ:
3130 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003131 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003132 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003133 break;
3134 default:
3135 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3136 break;
3137 }
dea31012005-04-17 16:05:31 -05003138 }
3139
James Smarte74c03c2013-04-17 20:15:19 -04003140 if (phba->fc_topology &&
3141 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3142 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3143 "3314 Toplogy changed was 0x%x is 0x%x\n",
3144 phba->fc_topology,
3145 bf_get(lpfc_mbx_read_top_topology, la));
3146 phba->fc_topology_changed = 1;
3147 }
3148
James Smart76a95d72010-11-20 23:11:48 -05003149 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003150 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003151
James Smartdf9e1b52011-12-13 13:22:17 -05003152 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003153 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003154 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003155
James Smart6a9c52c2009-10-02 15:16:51 -04003156 /* if npiv is enabled and this adapter supports npiv log
3157 * a message that npiv is not supported in this topology
3158 */
3159 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003160 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3161 "1309 Link Up Event npiv not supported in loop "
3162 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003163 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003164 if (bf_get(lpfc_mbx_read_top_il, la))
3165 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003166
James Smart76a95d72010-11-20 23:11:48 -05003167 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3168 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003169
3170 if (i == 0) {
3171 phba->alpa_map[0] = 0;
3172 } else {
James Smarte8b62012007-08-02 11:10:09 -04003173 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003174 int numalpa, j, k;
3175 union {
3176 uint8_t pamap[16];
3177 struct {
3178 uint32_t wd1;
3179 uint32_t wd2;
3180 uint32_t wd3;
3181 uint32_t wd4;
3182 } pa;
3183 } un;
3184 numalpa = phba->alpa_map[0];
3185 j = 0;
3186 while (j < numalpa) {
3187 memset(un.pamap, 0, 16);
3188 for (k = 1; j < numalpa; k++) {
3189 un.pamap[k - 1] =
3190 phba->alpa_map[j + 1];
3191 j++;
3192 if (k == 16)
3193 break;
3194 }
3195 /* Link Up Event ALPA map */
3196 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003197 KERN_WARNING,
3198 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003199 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003200 "ALPA map Data: x%x "
3201 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003202 un.pa.wd1, un.pa.wd2,
3203 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003204 }
3205 }
3206 }
3207 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003208 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003209 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003210 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003211 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3212 }
James Smart2e0fef82007-06-17 19:56:36 -05003213 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003214 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003215 }
James Smart92d7f7b2007-06-17 19:56:38 -05003216 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003217
James Smart38c20672013-03-01 16:37:44 -05003218 if (fc_flags) {
3219 spin_lock_irq(shost->host_lock);
3220 vport->fc_flag |= fc_flags;
3221 spin_unlock_irq(shost->host_lock);
3222 }
3223
dea31012005-04-17 16:05:31 -05003224 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05003225 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3226 if (!sparam_mbox)
3227 goto out;
3228
3229 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3230 if (rc) {
3231 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3232 goto out;
3233 }
3234 sparam_mbox->vport = vport;
3235 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3236 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3237 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003238 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003239 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3240 kfree(mp);
3241 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3242 goto out;
dea31012005-04-17 16:05:31 -05003243 }
3244
James Smart76a95d72010-11-20 23:11:48 -05003245 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04003246 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3247 if (!cfglink_mbox)
3248 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05003249 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05003250 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05003251 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05003252 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04003253 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04003254 if (rc == MBX_NOT_FINISHED) {
3255 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3256 goto out;
3257 }
3258 } else {
James Smart32b97932009-07-19 10:01:21 -04003259 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003260 /*
3261 * Add the driver's default FCF record at FCF index 0 now. This
3262 * is phase 1 implementation that support FCF index 0 and driver
3263 * defaults.
3264 */
James Smart45ed1192009-10-02 15:17:02 -04003265 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003266 fcf_record = kzalloc(sizeof(struct fcf_record),
3267 GFP_KERNEL);
3268 if (unlikely(!fcf_record)) {
3269 lpfc_printf_log(phba, KERN_ERR,
3270 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003271 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003272 "fcf record\n");
3273 rc = -ENODEV;
3274 goto out;
3275 }
3276
3277 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3278 LPFC_FCOE_FCF_DEF_INDEX);
3279 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3280 if (unlikely(rc)) {
3281 lpfc_printf_log(phba, KERN_ERR,
3282 LOG_MBOX | LOG_SLI,
3283 "2013 Could not manually add FCF "
3284 "record 0, status %d\n", rc);
3285 rc = -ENODEV;
3286 kfree(fcf_record);
3287 goto out;
3288 }
3289 kfree(fcf_record);
3290 }
3291 /*
3292 * The driver is expected to do FIP/FCF. Call the port
3293 * and get the FCF Table.
3294 */
James Smart32b97932009-07-19 10:01:21 -04003295 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003296 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart32b97932009-07-19 10:01:21 -04003297 spin_unlock_irq(&phba->hbalock);
3298 return;
3299 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003300 /* This is the initial FCF discovery scan */
3301 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04003302 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003303 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3304 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003305 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3306 LPFC_FCOE_FCF_GET_FIRST);
3307 if (rc) {
3308 spin_lock_irq(&phba->hbalock);
3309 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3310 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04003311 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003312 }
James Smart38b92ef2010-08-04 16:11:39 -04003313 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003314 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003315 }
James Smart6fb120a2009-05-22 14:52:59 -04003316
3317 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003318out:
3319 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003320 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3321 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3322 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003323 lpfc_issue_clear_la(phba, vport);
3324 return;
dea31012005-04-17 16:05:31 -05003325}
3326
3327static void
James Smart84774a42008-08-24 21:50:06 -04003328lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003329{
dea31012005-04-17 16:05:31 -05003330 uint32_t control;
3331 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003332 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003333 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003334 if (phba->sli_rev <= LPFC_SLI_REV3) {
3335 control = readl(phba->HCregaddr);
3336 control |= HC_LAINT_ENA;
3337 writel(control, phba->HCregaddr);
3338 readl(phba->HCregaddr); /* flush */
3339 }
James Smart2e0fef82007-06-17 19:56:36 -05003340 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003341}
3342
James Smart84774a42008-08-24 21:50:06 -04003343static void
3344lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3345{
3346 lpfc_linkdown(phba);
3347 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003348 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003349 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3350}
3351
3352
dea31012005-04-17 16:05:31 -05003353/*
James Smart76a95d72010-11-20 23:11:48 -05003354 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003355 * command upon completion. It is setup in the LPFC_MBOXQ
3356 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003357 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003358 */
3359void
James Smart76a95d72010-11-20 23:11:48 -05003360lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003361{
James Smart2e0fef82007-06-17 19:56:36 -05003362 struct lpfc_vport *vport = pmb->vport;
3363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003364 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003365 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003366 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003367 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003368 uint8_t attn_type;
dea31012005-04-17 16:05:31 -05003369
James Smart0d2b6b82008-06-14 22:52:47 -04003370 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003371 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003372 if (pring)
3373 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003374
dea31012005-04-17 16:05:31 -05003375 /* Check for error */
3376 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003377 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003378 "1307 READ_LA mbox error x%x state x%x\n",
3379 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003380 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003381 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003382 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003383 }
3384
James Smart76a95d72010-11-20 23:11:48 -05003385 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003386 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003387
3388 memcpy(&phba->alpa_map[0], mp->virt, 128);
3389
James Smart2e0fef82007-06-17 19:56:36 -05003390 spin_lock_irq(shost->host_lock);
James Smart76a95d72010-11-20 23:11:48 -05003391 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003392 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003393 else
James Smart2e0fef82007-06-17 19:56:36 -05003394 vport->fc_flag &= ~FC_BYPASSED_MODE;
3395 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003396
James Smartbe0c0082013-03-01 16:38:14 -05003397 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003398 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003399 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003400 if (phba->fc_eventTag != 0)
3401 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003402 }
dea31012005-04-17 16:05:31 -05003403
3404 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003405 if (phba->sli_rev < LPFC_SLI_REV4) {
3406 spin_lock_irq(&phba->hbalock);
3407 if (bf_get(lpfc_mbx_read_top_mm, la))
3408 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3409 else
3410 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3411 spin_unlock_irq(&phba->hbalock);
3412 }
dea31012005-04-17 16:05:31 -05003413
James Smart4d9ab992009-10-02 15:16:39 -04003414 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003415 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003416 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003417 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003418 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003419 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003420 "1306 Link Up Event in loop back mode "
3421 "x%x received Data: x%x x%x x%x x%x\n",
3422 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003423 bf_get(lpfc_mbx_read_top_alpa_granted,
3424 la),
3425 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003426 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003427 } else {
3428 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003429 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003430 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003431 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003432 bf_get(lpfc_mbx_read_top_alpa_granted,
3433 la),
3434 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003435 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003436 bf_get(lpfc_mbx_read_top_mm, la),
3437 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003438 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003439 }
James Smart92d7f7b2007-06-17 19:56:38 -05003440 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003441 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3442 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003443 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003444 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003445 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3446 "1308 Link Down Event in loop back mode "
3447 "x%x received "
3448 "Data: x%x x%x x%x\n",
3449 la->eventTag, phba->fc_eventTag,
3450 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003451 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3452 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3453 "1313 Link Down UNEXP WWPN Event x%x received "
3454 "Data: x%x x%x x%x x%x x%x\n",
3455 la->eventTag, phba->fc_eventTag,
3456 phba->pport->port_state, vport->fc_flag,
3457 bf_get(lpfc_mbx_read_top_mm, la),
3458 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003459 else
James Smart3163f722008-02-08 18:50:25 -05003460 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003461 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003462 "Data: x%x x%x x%x x%x x%x\n",
3463 la->eventTag, phba->fc_eventTag,
3464 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003465 bf_get(lpfc_mbx_read_top_mm, la),
3466 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003467 lpfc_mbx_issue_link_down(phba);
3468 }
James Smartaeb3c812017-04-21 16:05:02 -07003469 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3470 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003471 if (phba->link_state != LPFC_LINK_DOWN) {
3472 phba->fc_stat.LinkDown++;
3473 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3474 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003475 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003476 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003477 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003478 lpfc_mbx_issue_link_down(phba);
3479 } else
3480 lpfc_enable_la(phba);
3481
3482 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3483 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3484 "Data: x%x x%x x%x\n",
3485 la->eventTag, phba->fc_eventTag,
3486 phba->pport->port_state, vport->fc_flag);
3487 /*
3488 * The cmnd that triggered this will be waiting for this
3489 * signal.
3490 */
3491 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3492 if (phba->wait_4_mlo_maint_flg) {
3493 phba->wait_4_mlo_maint_flg = 0;
3494 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003495 }
James Smart84774a42008-08-24 21:50:06 -04003496 }
3497
James Smartbe0c0082013-03-01 16:38:14 -05003498 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3499 bf_get(lpfc_mbx_read_top_fa, la)) {
3500 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003501 lpfc_issue_clear_la(phba, vport);
3502 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003503 "1311 fa %d\n",
3504 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003505 }
3506
James Smart76a95d72010-11-20 23:11:48 -05003507lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003508 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3509 kfree(mp);
3510 mempool_free(pmb, phba->mbox_mem_pool);
3511 return;
3512}
3513
3514/*
3515 * This routine handles processing a REG_LOGIN mailbox
3516 * command upon completion. It is setup in the LPFC_MBOXQ
3517 * as the completion routine when the command is
3518 * handed off to the SLI layer.
3519 */
3520void
James Smart2e0fef82007-06-17 19:56:36 -05003521lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003522{
James Smart2e0fef82007-06-17 19:56:36 -05003523 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003524 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3525 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smartffc95492010-06-07 15:23:17 -04003526 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003527
James Smart3e1f0712018-11-29 16:09:29 -08003528 pmb->ctx_buf = NULL;
3529 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003530
James Smartbe6bb942015-04-07 15:07:22 -04003531 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3532 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3533 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003534 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003535 ndlp->nlp_usg_map, ndlp);
James Smartffc95492010-06-07 15:23:17 -04003536 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3537 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3538
James Smart40426292010-12-15 17:58:10 -05003539 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3540 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003541 /* We rcvd a rscn after issuing this
3542 * mbox reg login, we may have cycled
3543 * back through the state and be
3544 * back at reg login state so this
3545 * mbox needs to be ignored becase
3546 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003547 * process.
James Smartffc95492010-06-07 15:23:17 -04003548 */
3549 spin_lock_irq(shost->host_lock);
3550 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3551 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003552
3553 /*
3554 * We cannot leave the RPI registered because
3555 * if we go thru discovery again for this ndlp
3556 * a subsequent REG_RPI will fail.
3557 */
3558 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3559 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b2015-12-16 18:11:55 -05003560 }
3561
3562 /* Call state machine */
3563 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003564
dea31012005-04-17 16:05:31 -05003565 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3566 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003567 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003568 /* decrement the node reference count held for this callback
3569 * function.
3570 */
James Smart329f9bc2007-04-25 09:53:01 -04003571 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003572
3573 return;
3574}
3575
James Smart92d7f7b2007-06-17 19:56:38 -05003576static void
3577lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3578{
James Smart04c68492009-05-22 14:52:52 -04003579 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003580 struct lpfc_vport *vport = pmb->vport;
3581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3582
3583 switch (mb->mbxStatus) {
3584 case 0x0011:
3585 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003586 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3587 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3588 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003589 break;
James Smart78730cf2010-04-06 15:06:30 -04003590 /* If VPI is busy, reset the HBA */
3591 case 0x9700:
3592 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3593 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3594 vport->vpi, mb->mbxStatus);
3595 if (!(phba->pport->load_flag & FC_UNLOADING))
3596 lpfc_workq_post_event(phba, NULL, NULL,
3597 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003598 }
James Smart72100cc2010-02-12 14:43:01 -05003599 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003600 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003601 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003602 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003603 vport->unreg_vpi_cmpl = VPORT_OK;
3604 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003605 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003606 /*
3607 * This shost reference might have been taken at the beginning of
3608 * lpfc_vport_delete()
3609 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003610 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003611 scsi_host_put(shost);
3612}
3613
James Smartd7c255b2008-08-24 21:50:00 -04003614int
James Smart92d7f7b2007-06-17 19:56:38 -05003615lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3616{
3617 struct lpfc_hba *phba = vport->phba;
3618 LPFC_MBOXQ_t *mbox;
3619 int rc;
3620
3621 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3622 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003623 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003624
3625 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3626 mbox->vport = vport;
3627 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003628 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003629 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003630 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3631 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003632 mempool_free(mbox, phba->mbox_mem_pool);
3633 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003634 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003635 }
James Smartd7c255b2008-08-24 21:50:00 -04003636 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003637}
3638
3639static void
3640lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3641{
3642 struct lpfc_vport *vport = pmb->vport;
3643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003644 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003645
3646 switch (mb->mbxStatus) {
3647 case 0x0011:
3648 case 0x9601:
3649 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003650 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3651 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3652 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003653 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3654 spin_lock_irq(shost->host_lock);
3655 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3656 spin_unlock_irq(shost->host_lock);
3657 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003658
James Smartf6e84792019-01-28 11:14:38 -08003659 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3660 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003661 if (phba->nvmet_support)
3662 lpfc_nvmet_update_targetport(phba);
3663 else
James Smart8c258642017-02-12 13:52:36 -08003664 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003665 }
James Smart92d7f7b2007-06-17 19:56:38 -05003666 goto out;
3667 }
James Smart92d7f7b2007-06-17 19:56:38 -05003668
James Smart72100cc2010-02-12 14:43:01 -05003669 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003670 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003671 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003672 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003673 vport->num_disc_nodes = 0;
3674 /* go thru NPR list and issue ELS PLOGIs */
3675 if (vport->fc_npr_cnt)
3676 lpfc_els_disc_plogi(vport);
3677
3678 if (!vport->num_disc_nodes) {
3679 spin_lock_irq(shost->host_lock);
3680 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3681 spin_unlock_irq(shost->host_lock);
3682 lpfc_can_disctmo(vport);
3683 }
3684 vport->port_state = LPFC_VPORT_READY;
3685
3686out:
3687 mempool_free(pmb, phba->mbox_mem_pool);
3688 return;
3689}
3690
James Smart21e9a0a2009-05-22 14:53:21 -04003691/**
3692 * lpfc_create_static_vport - Read HBA config region to create static vports.
3693 * @phba: pointer to lpfc hba data structure.
3694 *
3695 * This routine issue a DUMP mailbox command for config region 22 to get
3696 * the list of static vports to be created. The function create vports
3697 * based on the information returned from the HBA.
3698 **/
3699void
3700lpfc_create_static_vport(struct lpfc_hba *phba)
3701{
3702 LPFC_MBOXQ_t *pmb = NULL;
3703 MAILBOX_t *mb;
3704 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003705 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003706 struct fc_vport_identifiers vport_id;
3707 struct fc_vport *new_fc_vport;
3708 struct Scsi_Host *shost;
3709 struct lpfc_vport *vport;
3710 uint16_t offset = 0;
3711 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003712 struct lpfc_dmabuf *mp;
3713 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003714
3715 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3716 if (!pmb) {
3717 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3718 "0542 lpfc_create_static_vport failed to"
3719 " allocate mailbox memory\n");
3720 return;
3721 }
James Smartcdcc2342012-08-14 14:26:35 -04003722 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003723 mb = &pmb->u.mb;
3724
3725 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3726 if (!vport_info) {
3727 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3728 "0543 lpfc_create_static_vport failed to"
3729 " allocate vport_info\n");
3730 mempool_free(pmb, phba->mbox_mem_pool);
3731 return;
3732 }
3733
3734 vport_buff = (uint8_t *) vport_info;
3735 do {
James Smartcdcc2342012-08-14 14:26:35 -04003736 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003737 if (pmb->ctx_buf) {
3738 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003739 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3740 kfree(mp);
3741 }
James Smart1c6834a2009-07-19 10:01:26 -04003742 if (lpfc_dump_static_vport(phba, pmb, offset))
3743 goto out;
3744
James Smart21e9a0a2009-05-22 14:53:21 -04003745 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003746 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3747 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003748
James Smartcdcc2342012-08-14 14:26:35 -04003749 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003750 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3751 "0544 lpfc_create_static_vport failed to"
3752 " issue dump mailbox command ret 0x%x "
3753 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003754 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003755 goto out;
3756 }
3757
James Smart1c6834a2009-07-19 10:01:26 -04003758 if (phba->sli_rev == LPFC_SLI_REV4) {
3759 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003760 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003761 if (byte_count > sizeof(struct static_vport_info) -
3762 offset)
3763 byte_count = sizeof(struct static_vport_info)
3764 - offset;
3765 memcpy(vport_buff + offset, mp->virt, byte_count);
3766 offset += byte_count;
3767 } else {
3768 if (mb->un.varDmp.word_cnt >
3769 sizeof(struct static_vport_info) - offset)
3770 mb->un.varDmp.word_cnt =
3771 sizeof(struct static_vport_info)
3772 - offset;
3773 byte_count = mb->un.varDmp.word_cnt;
3774 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3775 vport_buff + offset,
3776 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003777
James Smart1c6834a2009-07-19 10:01:26 -04003778 offset += byte_count;
3779 }
James Smart21e9a0a2009-05-22 14:53:21 -04003780
James Smart1c6834a2009-07-19 10:01:26 -04003781 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003782 offset < sizeof(struct static_vport_info));
3783
3784
3785 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3786 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3787 != VPORT_INFO_REV)) {
3788 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3789 "0545 lpfc_create_static_vport bad"
3790 " information header 0x%x 0x%x\n",
3791 le32_to_cpu(vport_info->signature),
3792 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3793
3794 goto out;
3795 }
3796
3797 shost = lpfc_shost_from_vport(phba->pport);
3798
3799 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3800 memset(&vport_id, 0, sizeof(vport_id));
3801 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3802 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3803 if (!vport_id.port_name || !vport_id.node_name)
3804 continue;
3805
3806 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3807 vport_id.vport_type = FC_PORTTYPE_NPIV;
3808 vport_id.disable = false;
3809 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3810
3811 if (!new_fc_vport) {
3812 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3813 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003814 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003815 continue;
3816 }
3817
3818 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3819 vport->vport_flag |= STATIC_VPORT;
3820 }
3821
3822out:
James Smart21e9a0a2009-05-22 14:53:21 -04003823 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003824 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003825 if (pmb->ctx_buf) {
3826 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003827 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3828 kfree(mp);
3829 }
James Smart21e9a0a2009-05-22 14:53:21 -04003830 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003831 }
James Smart21e9a0a2009-05-22 14:53:21 -04003832
3833 return;
3834}
3835
dea31012005-04-17 16:05:31 -05003836/*
3837 * This routine handles processing a Fabric REG_LOGIN mailbox
3838 * command upon completion. It is setup in the LPFC_MBOXQ
3839 * as the completion routine when the command is
3840 * handed off to the SLI layer.
3841 */
3842void
James Smart2e0fef82007-06-17 19:56:36 -05003843lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003844{
James Smart92d7f7b2007-06-17 19:56:38 -05003845 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003846 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003847 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003848 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003849 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003850
James Smart3e1f0712018-11-29 16:09:29 -08003851 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3852 pmb->ctx_ndlp = NULL;
3853 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003854
dea31012005-04-17 16:05:31 -05003855 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003856 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3857 "0258 Register Fabric login error: 0x%x\n",
3858 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003859 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3860 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003861 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003862
James Smart76a95d72010-11-20 23:11:48 -05003863 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003864 /* FLOGI failed, use loop map to make discovery list */
3865 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003866
James Smart92d7f7b2007-06-17 19:56:38 -05003867 /* Start discovery */
3868 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003869 /* Decrement the reference count to ndlp after the
3870 * reference to the ndlp are done.
3871 */
3872 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003873 return;
3874 }
3875
3876 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003877 /* Decrement the reference count to ndlp after the reference
3878 * to the ndlp are done.
3879 */
3880 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003881 return;
3882 }
3883
James Smart6d368e52011-05-24 11:44:12 -04003884 if (phba->sli_rev < LPFC_SLI_REV4)
3885 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003886 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003887 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003888 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003889
James Smart2e0fef82007-06-17 19:56:36 -05003890 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003891 /* when physical port receive logo donot start
3892 * vport discovery */
3893 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3894 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003895 else {
3896 shost = lpfc_shost_from_vport(vport);
3897 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003898 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003899 spin_unlock_irq(shost->host_lock);
3900 }
James Smart92d7f7b2007-06-17 19:56:38 -05003901 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003902 }
3903
3904 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3905 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003906 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003907
3908 /* Drop the reference count from the mbox at the end after
3909 * all the current reference to the ndlp have been done.
3910 */
3911 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003912 return;
3913}
3914
James Smarta0f2d3e2017-02-12 13:52:31 -08003915 /*
3916 * This routine will issue a GID_FT for each FC4 Type supported
3917 * by the driver. ALL GID_FTs must complete before discovery is started.
3918 */
3919int
3920lpfc_issue_gidft(struct lpfc_vport *vport)
3921{
James Smarta0f2d3e2017-02-12 13:52:31 -08003922 /* Good status, issue CT Request to NameServer */
James Smartf6e84792019-01-28 11:14:38 -08003923 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3924 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003925 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3926 /* Cannot issue NameServer FCP Query, so finish up
3927 * discovery
3928 */
3929 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3930 "0604 %s FC TYPE %x %s\n",
3931 "Failed to issue GID_FT to ",
3932 FC_TYPE_FCP,
3933 "Finishing discovery.");
3934 return 0;
3935 }
3936 vport->gidft_inp++;
3937 }
3938
James Smartf6e84792019-01-28 11:14:38 -08003939 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3940 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smarta0f2d3e2017-02-12 13:52:31 -08003941 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3942 /* Cannot issue NameServer NVME Query, so finish up
3943 * discovery
3944 */
3945 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3946 "0605 %s FC_TYPE %x %s %d\n",
3947 "Failed to issue GID_FT to ",
3948 FC_TYPE_NVME,
3949 "Finishing discovery: gidftinp ",
3950 vport->gidft_inp);
3951 if (vport->gidft_inp == 0)
3952 return 0;
3953 } else
3954 vport->gidft_inp++;
3955 }
3956 return vport->gidft_inp;
3957}
3958
James Smart7ea92eb2018-10-23 13:41:10 -07003959/**
3960 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3961 * @vport: The virtual port for which this call is being executed.
3962 *
3963 * This routine will issue a GID_PT to get a list of all N_Ports
3964 *
3965 * Return value :
3966 * 0 - Failure to issue a GID_PT
3967 * 1 - GID_PT issued
3968 **/
3969int
3970lpfc_issue_gidpt(struct lpfc_vport *vport)
3971{
3972 /* Good status, issue CT Request to NameServer */
3973 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
3974 /* Cannot issue NameServer FCP Query, so finish up
3975 * discovery
3976 */
3977 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3978 "0606 %s Port TYPE %x %s\n",
3979 "Failed to issue GID_PT to ",
3980 GID_PT_N_PORT,
3981 "Finishing discovery.");
3982 return 0;
3983 }
3984 vport->gidft_inp++;
3985 return 1;
3986}
3987
dea31012005-04-17 16:05:31 -05003988/*
3989 * This routine handles processing a NameServer REG_LOGIN mailbox
3990 * command upon completion. It is setup in the LPFC_MBOXQ
3991 * as the completion routine when the command is
3992 * handed off to the SLI layer.
3993 */
3994void
James Smart2e0fef82007-06-17 19:56:36 -05003995lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003996{
James Smart21e9a0a2009-05-22 14:53:21 -04003997 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003998 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3999 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004000 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004001
James Smart3e1f0712018-11-29 16:09:29 -08004002 pmb->ctx_buf = NULL;
4003 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08004004 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04004005
dea31012005-04-17 16:05:31 -05004006 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04004007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4008 "0260 Register NameServer error: 0x%x\n",
4009 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004010
4011out:
James Smartfa4066b2008-01-11 01:53:27 -05004012 /* decrement the node reference count held for this
4013 * callback function.
4014 */
James Smart329f9bc2007-04-25 09:53:01 -04004015 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004016 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4017 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004018 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004019
4020 /* If no other thread is using the ndlp, free it */
4021 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05004022
James Smart76a95d72010-11-20 23:11:48 -05004023 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004024 /*
4025 * RegLogin failed, use loop map to make discovery
4026 * list
4027 */
4028 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004029
James Smart92d7f7b2007-06-17 19:56:38 -05004030 /* Start discovery */
4031 lpfc_disc_start(vport);
4032 return;
4033 }
4034 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004035 return;
4036 }
4037
James Smart6d368e52011-05-24 11:44:12 -04004038 if (phba->sli_rev < LPFC_SLI_REV4)
4039 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004040 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004041 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004042 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004043 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4044 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
4045 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004046 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004047 ndlp->nlp_usg_map, ndlp);
dea31012005-04-17 16:05:31 -05004048
James Smart2e0fef82007-06-17 19:56:36 -05004049 if (vport->port_state < LPFC_VPORT_READY) {
4050 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004051 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4052 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4053 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4054 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004055
James Smartf6e84792019-01-28 11:14:38 -08004056 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4057 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
James Smarta0f2d3e2017-02-12 13:52:31 -08004058 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4059
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_NVME))
James Smart01649562017-02-12 13:52:32 -08004062 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4063 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004064
4065 /* Issue SCR just before NameServer GID_FT Query */
4066 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05004067 }
4068
James Smart2e0fef82007-06-17 19:56:36 -05004069 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004070 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004071 goto out;
dea31012005-04-17 16:05:31 -05004072
James Smarta0f2d3e2017-02-12 13:52:31 -08004073 /*
4074 * At this point in time we may need to wait for multiple
4075 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4076 *
4077 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004078 * callback function.
4079 */
James Smart329f9bc2007-04-25 09:53:01 -04004080 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004081 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4082 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004083 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004084
4085 return;
4086}
4087
4088static void
James Smart2e0fef82007-06-17 19:56:36 -05004089lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004090{
James Smart2e0fef82007-06-17 19:56:36 -05004091 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4092 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004093 struct lpfc_rport_data *rdata;
4094 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004095 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004096
James Smartf6e84792019-01-28 11:14:38 -08004097 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smart895427b2017-02-12 13:52:30 -08004098 return;
4099
dea31012005-04-17 16:05:31 -05004100 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004101 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4102 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004103 rport_ids.port_id = ndlp->nlp_DID;
4104 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004105
James Smart329f9bc2007-04-25 09:53:01 -04004106 /*
4107 * We leave our node pointer in rport->dd_data when we unregister a
4108 * FCP target port. But fc_remote_port_add zeros the space to which
4109 * rport->dd_data points. So, if we're reusing a previously
4110 * registered port, drop the reference that we took the last time we
4111 * registered the port.
4112 */
James Smart466e8402015-05-21 13:55:28 -04004113 rport = ndlp->rport;
4114 if (rport) {
4115 rdata = rport->dd_data;
4116 /* break the link before dropping the ref */
4117 ndlp->rport = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08004118 if (rdata) {
4119 if (rdata->pnode == ndlp)
4120 lpfc_nlp_put(ndlp);
4121 rdata->pnode = NULL;
4122 }
James Smart466e8402015-05-21 13:55:28 -04004123 /* drop reference for earlier registeration */
4124 put_device(&rport->dev);
4125 }
James Smart858c9f62007-06-17 19:56:39 -05004126
4127 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4128 "rport add: did:x%x flg:x%x type x%x",
4129 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4130
James Smart9589b0622011-04-16 11:03:17 -04004131 /* Don't add the remote port if unloading. */
4132 if (vport->load_flag & FC_UNLOADING)
4133 return;
4134
James Smart2e0fef82007-06-17 19:56:36 -05004135 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004136 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004137 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4138 "Warning: fc_remote_port_add failed\n");
4139 return;
4140 }
4141
4142 /* initialize static port data */
4143 rport->maxframe_size = ndlp->nlp_maxframe;
4144 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004145 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004146 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004147
4148 if (ndlp->nlp_type & NLP_FCP_TARGET)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004149 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004150 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
Hannes Reineckea6a6d052019-04-10 16:16:19 +02004151 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4152 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4153 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4154 if (ndlp->nlp_type & NLP_NVME_TARGET)
4155 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4156 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4157 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004158
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004159 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4160 fc_remote_port_rolechg(rport, rport_ids.roles);
4161
James Smart34f5ad82012-08-03 12:35:03 -04004162 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4163 "3183 rport register x%06x, rport %p role x%x\n",
4164 ndlp->nlp_DID, rport, rport_ids.roles);
4165
James Smart071fbd3d2006-04-15 11:53:20 -04004166 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004167 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004168 ndlp->nlp_sid = rport->scsi_target_id;
4169 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004170 return;
4171}
4172
4173static void
James Smart2e0fef82007-06-17 19:56:36 -05004174lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004175{
4176 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004177 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004178
James Smartf6e84792019-01-28 11:14:38 -08004179 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
James Smarta0f2d3e2017-02-12 13:52:31 -08004180 return;
James Smartc01f3202006-08-18 17:47:08 -04004181
James Smart2ea259e2017-02-12 13:52:27 -08004182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004183 "rport delete: did:x%x flg:x%x type x%x",
4184 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4185
James Smart2ea259e2017-02-12 13:52:27 -08004186 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart34f5ad82012-08-03 12:35:03 -04004187 "3184 rport unregister x%06x, rport %p\n",
4188 ndlp->nlp_DID, rport);
4189
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004190 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004191
4192 return;
4193}
4194
James Smartde0c5b32007-04-25 09:52:27 -04004195static void
James Smart2e0fef82007-06-17 19:56:36 -05004196lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004197{
James Smart2e0fef82007-06-17 19:56:36 -05004198 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4199
4200 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004201 switch (state) {
4202 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004203 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004204 break;
4205 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004206 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004207 break;
4208 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004209 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004210 break;
4211 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004212 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004213 break;
4214 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004215 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004216 break;
4217 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004218 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004219 break;
4220 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004221 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004222 break;
4223 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004224 if (vport->fc_npr_cnt == 0 && count == -1)
4225 vport->fc_npr_cnt = 0;
4226 else
4227 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004228 break;
4229 }
James Smart2e0fef82007-06-17 19:56:36 -05004230 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004231}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004232
James Smartde0c5b32007-04-25 09:52:27 -04004233static void
James Smart2e0fef82007-06-17 19:56:36 -05004234lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004235 int old_state, int new_state)
4236{
James Smart2e0fef82007-06-17 19:56:36 -05004237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4238
James Smartde0c5b32007-04-25 09:52:27 -04004239 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004240 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4241 ndlp->nlp_type |= NLP_FC_NODE;
4242 }
4243 if (new_state == NLP_STE_MAPPED_NODE)
4244 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4245 if (new_state == NLP_STE_NPR_NODE)
4246 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004247
James Smarta0f2d3e2017-02-12 13:52:31 -08004248 /* FCP and NVME Transport interface */
4249 if ((old_state == NLP_STE_MAPPED_NODE ||
4250 old_state == NLP_STE_UNMAPPED_NODE)) {
4251 if (ndlp->rport) {
4252 vport->phba->nport_event_cnt++;
4253 lpfc_unregister_remote_port(ndlp);
4254 }
4255
James Smart1c5b12f2017-04-21 16:05:03 -07004256 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004257 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004258 if (vport->phba->nvmet_support == 0) {
4259 /* Start devloss if target. */
4260 if (ndlp->nlp_type & NLP_NVME_TARGET)
4261 lpfc_nvme_unregister_port(vport, ndlp);
4262 } else {
James Smart6599e122017-06-01 21:07:00 -07004263 /* NVMET has no upcall. */
4264 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004265 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004266 }
James Smartde0c5b32007-04-25 09:52:27 -04004267 }
dea31012005-04-17 16:05:31 -05004268
James Smarta0f2d3e2017-02-12 13:52:31 -08004269 /* FCP and NVME Transport interfaces */
4270
James Smartde0c5b32007-04-25 09:52:27 -04004271 if (new_state == NLP_STE_MAPPED_NODE ||
4272 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart01a8aed2018-09-10 10:30:41 -07004273 if (ndlp->nlp_fc4_type ||
James Smart92721c32017-06-01 21:06:59 -07004274 ndlp->nlp_DID == Fabric_DID ||
4275 ndlp->nlp_DID == NameServer_DID ||
4276 ndlp->nlp_DID == FDMI_DID) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004277 vport->phba->nport_event_cnt++;
4278 /*
4279 * Tell the fc transport about the port, if we haven't
4280 * already. If we have, and it's a scsi entity, be
4281 */
4282 lpfc_register_remote_port(vport, ndlp);
4283 }
4284 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004285 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4286 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004287 if (vport->phba->nvmet_support == 0) {
4288 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004289 * Only NVME Target Rports are registered with
4290 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004291 */
James Smart3b5bde692017-11-20 16:00:39 -08004292 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4293 vport->phba->nport_event_cnt++;
4294 lpfc_nvme_register_port(vport, ndlp);
4295 }
James Smart8c258642017-02-12 13:52:36 -08004296 } else {
4297 /* Just take an NDLP ref count since the
4298 * target does not register rports.
4299 */
4300 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004301 }
4302 }
James Smartde0c5b32007-04-25 09:52:27 -04004303 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004304
James Smartea2151b2008-09-07 11:52:10 -04004305 if ((new_state == NLP_STE_MAPPED_NODE) &&
4306 (vport->stat_data_enabled)) {
4307 /*
4308 * A new target is discovered, if there is no buffer for
4309 * statistical data collection allocate buffer.
4310 */
4311 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4312 sizeof(struct lpfc_scsicmd_bkt),
4313 GFP_KERNEL);
4314
4315 if (!ndlp->lat_data)
4316 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4317 "0286 lpfc_nlp_state_cleanup failed to "
4318 "allocate statistical data buffer DID "
4319 "0x%x\n", ndlp->nlp_DID);
4320 }
James Smart858c9f62007-06-17 19:56:39 -05004321 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004322 * If the node just added to Mapped list was an FCP target,
4323 * but the remote port registration failed or assigned a target
4324 * id outside the presentable range - move the node to the
4325 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004326 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004327 if ((new_state == NLP_STE_MAPPED_NODE) &&
4328 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004329 (!ndlp->rport ||
4330 ndlp->rport->scsi_target_id == -1 ||
4331 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004332 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004333 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004334 spin_unlock_irq(shost->host_lock);
4335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004336 }
James Smartde0c5b32007-04-25 09:52:27 -04004337}
4338
James Smart685f0bf2007-04-25 09:53:08 -04004339static char *
4340lpfc_nlp_state_name(char *buffer, size_t size, int state)
4341{
4342 static char *states[] = {
4343 [NLP_STE_UNUSED_NODE] = "UNUSED",
4344 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4345 [NLP_STE_ADISC_ISSUE] = "ADISC",
4346 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4347 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004348 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004349 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4350 [NLP_STE_MAPPED_NODE] = "MAPPED",
4351 [NLP_STE_NPR_NODE] = "NPR",
4352 };
4353
James Smart311464e2007-08-02 11:10:37 -04004354 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004355 strlcpy(buffer, states[state], size);
4356 else
4357 snprintf(buffer, size, "unknown (%d)", state);
4358 return buffer;
4359}
4360
James Smartde0c5b32007-04-25 09:52:27 -04004361void
James Smart2e0fef82007-06-17 19:56:36 -05004362lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4363 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004364{
James Smart2e0fef82007-06-17 19:56:36 -05004365 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004366 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004367 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004368
James Smarte8b62012007-08-02 11:10:09 -04004369 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4370 "0904 NPort state transition x%06x, %s -> %s\n",
4371 ndlp->nlp_DID,
4372 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4373 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004374
4375 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4376 "node statechg did:x%x old:%d ste:%d",
4377 ndlp->nlp_DID, old_state, state);
4378
James Smartde0c5b32007-04-25 09:52:27 -04004379 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004380 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004381 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004382 if (old_state == NLP_STE_UNMAPPED_NODE) {
4383 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4384 ndlp->nlp_type &= ~NLP_FC_NODE;
4385 }
4386
James Smart685f0bf2007-04-25 09:53:08 -04004387 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004388 spin_lock_irq(shost->host_lock);
4389 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4390 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004391 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004392 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004393
4394 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004395 lpfc_nlp_counters(vport, state, 1);
4396 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004397}
4398
4399void
James Smarte47c9092008-02-08 18:49:26 -05004400lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4401{
4402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4403
4404 if (list_empty(&ndlp->nlp_listp)) {
4405 spin_lock_irq(shost->host_lock);
4406 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4407 spin_unlock_irq(shost->host_lock);
4408 }
4409}
4410
4411void
James Smart2e0fef82007-06-17 19:56:36 -05004412lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004413{
James Smart2e0fef82007-06-17 19:56:36 -05004414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4415
James Smart0d2b6b82008-06-14 22:52:47 -04004416 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004417 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004418 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4419 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004420 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004421 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004422 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004423 NLP_STE_UNUSED_NODE);
4424}
4425
Adrian Bunk4d9db012008-02-14 23:24:02 +02004426static void
James Smarte47c9092008-02-08 18:49:26 -05004427lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4428{
James Smart0d2b6b82008-06-14 22:52:47 -04004429 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004430 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4431 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4432 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4433 NLP_STE_UNUSED_NODE);
4434}
James Smart109f6ed2008-12-04 22:39:08 -05004435/**
James Smart3621a712009-04-06 18:47:14 -04004436 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004437 * @vport: Pointer to Virtual Port object.
4438 * @ndlp: Pointer to FC node object.
4439 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004440 *
4441 * This function is always called when node object need to be initialized.
4442 * It initializes all the fields of the node object. Although the reference
4443 * to phba from @ndlp can be obtained indirectly through it's reference to
4444 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4445 * to the life-span of the @ndlp might go beyond the existence of @vport as
4446 * the final release of ndlp is determined by its reference count. And, the
4447 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004448 **/
4449static inline void
4450lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4451 uint32_t did)
4452{
4453 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4454 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004455 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smart109f6ed2008-12-04 22:39:08 -05004456 ndlp->nlp_DID = did;
4457 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004458 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004459 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004460 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004461 kref_init(&ndlp->kref);
4462 NLP_INT_NODE_ACT(ndlp);
4463 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004464 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004465 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004466}
James Smarte47c9092008-02-08 18:49:26 -05004467
4468struct lpfc_nodelist *
4469lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4470 int state)
4471{
4472 struct lpfc_hba *phba = vport->phba;
James Smartdea16bd2018-11-29 16:09:30 -08004473 uint32_t did, flag;
James Smarte47c9092008-02-08 18:49:26 -05004474 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004475 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart9d3d3402017-04-21 16:05:00 -07004476 int rpi = LPFC_RPI_ALLOC_ERROR;
James Smartdea16bd2018-11-29 16:09:30 -08004477 uint32_t defer_did = 0;
James Smarte47c9092008-02-08 18:49:26 -05004478
4479 if (!ndlp)
4480 return NULL;
4481
James Smart9d3d3402017-04-21 16:05:00 -07004482 if (phba->sli_rev == LPFC_SLI_REV4) {
4483 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4484 if (rpi == LPFC_RPI_ALLOC_ERROR)
4485 return NULL;
4486 }
4487
James Smarte47c9092008-02-08 18:49:26 -05004488 spin_lock_irqsave(&phba->ndlp_lock, flags);
4489 /* The ndlp should not be in memory free mode */
4490 if (NLP_CHK_FREE_REQ(ndlp)) {
4491 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4492 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4493 "0277 lpfc_enable_node: ndlp:x%p "
4494 "usgmap:x%x refcnt:%d\n",
4495 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004496 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004497 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004498 }
4499 /* The ndlp should not already be in active mode */
4500 if (NLP_CHK_NODE_ACT(ndlp)) {
4501 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4502 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4503 "0278 lpfc_enable_node: ndlp:x%p "
4504 "usgmap:x%x refcnt:%d\n",
4505 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004506 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004507 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004508 }
4509
James Smartdea16bd2018-11-29 16:09:30 -08004510 /* First preserve the orginal DID, xri_bitmap and some flags */
James Smarte47c9092008-02-08 18:49:26 -05004511 did = ndlp->nlp_DID;
James Smartdea16bd2018-11-29 16:09:30 -08004512 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4513 if (flag & NLP_UNREG_INP)
4514 defer_did = ndlp->nlp_defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004515 if (phba->sli_rev == LPFC_SLI_REV4)
4516 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004517
James Smartdea16bd2018-11-29 16:09:30 -08004518 /* Zero ndlp except of ndlp linked list pointer */
James Smarte47c9092008-02-08 18:49:26 -05004519 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4520 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smarte47c9092008-02-08 18:49:26 -05004521
James Smartdea16bd2018-11-29 16:09:30 -08004522 /* Next reinitialize and restore saved objects */
4523 lpfc_initialize_node(vport, ndlp, did);
4524 ndlp->nlp_flag |= flag;
4525 if (flag & NLP_UNREG_INP)
4526 ndlp->nlp_defer_did = defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004527 if (phba->sli_rev == LPFC_SLI_REV4)
4528 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4529
James Smarte47c9092008-02-08 18:49:26 -05004530 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smartbe6bb942015-04-07 15:07:22 -04004531 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07004532 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04004533 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4534 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4535 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4536 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004537 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004538 ndlp->nlp_usg_map, ndlp);
4539 }
James Smart725dd392013-10-10 12:23:30 -04004540
James Smarte47c9092008-02-08 18:49:26 -05004541
4542 if (state != NLP_STE_UNUSED_NODE)
4543 lpfc_nlp_set_state(vport, ndlp, state);
4544
4545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4546 "node enable: did:x%x",
4547 ndlp->nlp_DID, 0, 0);
4548 return ndlp;
James Smart9d3d3402017-04-21 16:05:00 -07004549
4550free_rpi:
4551 if (phba->sli_rev == LPFC_SLI_REV4)
4552 lpfc_sli4_free_rpi(vport->phba, rpi);
4553 return NULL;
James Smartde0c5b32007-04-25 09:52:27 -04004554}
4555
4556void
James Smart2e0fef82007-06-17 19:56:36 -05004557lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004558{
James Smart87af33f2007-10-27 13:37:43 -04004559 /*
James Smartfa4066b2008-01-11 01:53:27 -05004560 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004561 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004562 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4563 * until ALL other outstanding threads have completed. We check
4564 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004565 */
James Smartfa4066b2008-01-11 01:53:27 -05004566 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4567 return;
James Smart51ef4c22007-08-02 11:10:31 -04004568 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004569 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004570 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004571 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004572 }
James Smart02902172015-05-21 13:55:17 -04004573
4574 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004575 return;
dea31012005-04-17 16:05:31 -05004576}
4577
4578/*
4579 * Start / ReStart rescue timer for Discovery / RSCN handling
4580 */
4581void
James Smart2e0fef82007-06-17 19:56:36 -05004582lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004583{
James Smart2e0fef82007-06-17 19:56:36 -05004584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4585 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004586 uint32_t tmo;
4587
James Smart2e0fef82007-06-17 19:56:36 -05004588 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004589 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004590 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4591 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004592 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004593 * FC spec states we need 3 * ratov for CT requests
4594 */
4595 tmo = ((phba->fc_ratov * 3) + 3);
4596 }
dea31012005-04-17 16:05:31 -05004597
James Smart858c9f62007-06-17 19:56:39 -05004598
4599 if (!timer_pending(&vport->fc_disctmo)) {
4600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4601 "set disc timer: tmo:x%x state:x%x flg:x%x",
4602 tmo, vport->port_state, vport->fc_flag);
4603 }
4604
James Smart256ec0d2013-04-17 20:14:58 -04004605 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004606 spin_lock_irq(shost->host_lock);
4607 vport->fc_flag |= FC_DISC_TMO;
4608 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004609
4610 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004611 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4612 "0247 Start Discovery Timer state x%x "
4613 "Data: x%x x%lx x%x x%x\n",
4614 vport->port_state, tmo,
4615 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4616 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004617
4618 return;
4619}
4620
4621/*
4622 * Cancel rescue timer for Discovery / RSCN handling
4623 */
4624int
James Smart2e0fef82007-06-17 19:56:36 -05004625lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004626{
James Smart2e0fef82007-06-17 19:56:36 -05004627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004628 unsigned long iflags;
4629
James Smart858c9f62007-06-17 19:56:39 -05004630 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4631 "can disc timer: state:x%x rtry:x%x flg:x%x",
4632 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4633
dea31012005-04-17 16:05:31 -05004634 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004635 if (vport->fc_flag & FC_DISC_TMO) {
4636 spin_lock_irqsave(shost->host_lock, iflags);
4637 vport->fc_flag &= ~FC_DISC_TMO;
4638 spin_unlock_irqrestore(shost->host_lock, iflags);
4639 del_timer_sync(&vport->fc_disctmo);
4640 spin_lock_irqsave(&vport->work_port_lock, iflags);
4641 vport->work_port_events &= ~WORKER_DISC_TMO;
4642 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004643 }
4644
4645 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004646 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4647 "0248 Cancel Discovery Timer state x%x "
4648 "Data: x%x x%x x%x\n",
4649 vport->port_state, vport->fc_flag,
4650 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004651 return 0;
dea31012005-04-17 16:05:31 -05004652}
4653
4654/*
4655 * Check specified ring for outstanding IOCB on the SLI queue
4656 * Return true if iocb matches the specified nport
4657 */
4658int
James Smart2e0fef82007-06-17 19:56:36 -05004659lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4660 struct lpfc_sli_ring *pring,
4661 struct lpfc_iocbq *iocb,
4662 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004663{
James Smart2e0fef82007-06-17 19:56:36 -05004664 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004665 struct lpfc_vport *vport = ndlp->vport;
4666
4667 if (iocb->vport != vport)
4668 return 0;
4669
dea31012005-04-17 16:05:31 -05004670 if (pring->ringno == LPFC_ELS_RING) {
4671 switch (icmd->ulpCommand) {
4672 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004673 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004674 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004675 /* fall through */
dea31012005-04-17 16:05:31 -05004676 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004677 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4678 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004679 /* fall through */
dea31012005-04-17 16:05:31 -05004680 case CMD_XMIT_ELS_RSP64_CX:
4681 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004682 return 1;
Bart Van Asschecd05c152019-03-28 11:06:18 -07004683 /* fall through */
dea31012005-04-17 16:05:31 -05004684 }
James Smart895427b2017-02-12 13:52:30 -08004685 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004686 /* Skip match check if waiting to relogin to FCP target */
4687 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004688 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004689 return 0;
dea31012005-04-17 16:05:31 -05004690 }
4691 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004692 return 1;
dea31012005-04-17 16:05:31 -05004693 }
dea31012005-04-17 16:05:31 -05004694 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004695 return 0;
dea31012005-04-17 16:05:31 -05004696}
4697
James Smart895427b2017-02-12 13:52:30 -08004698static void
4699__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4700 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4701 struct list_head *dequeue_list)
4702{
4703 struct lpfc_iocbq *iocb, *next_iocb;
4704
4705 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4706 /* Check to see if iocb matches the nport */
4707 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4708 /* match, dequeue */
4709 list_move_tail(&iocb->list, dequeue_list);
4710 }
4711}
4712
4713static void
4714lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4715 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4716{
4717 struct lpfc_sli *psli = &phba->sli;
4718 uint32_t i;
4719
4720 spin_lock_irq(&phba->hbalock);
4721 for (i = 0; i < psli->num_rings; i++)
4722 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4723 dequeue_list);
4724 spin_unlock_irq(&phba->hbalock);
4725}
4726
4727static void
4728lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4729 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4730{
4731 struct lpfc_sli_ring *pring;
4732 struct lpfc_queue *qp = NULL;
4733
4734 spin_lock_irq(&phba->hbalock);
4735 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4736 pring = qp->pring;
4737 if (!pring)
4738 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004739 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004740 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004741 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004742 }
4743 spin_unlock_irq(&phba->hbalock);
4744}
4745
dea31012005-04-17 16:05:31 -05004746/*
4747 * Free resources / clean up outstanding I/Os
4748 * associated with nlp_rpi in the LPFC_NODELIST entry.
4749 */
4750static int
James Smart2e0fef82007-06-17 19:56:36 -05004751lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004752{
James Smart2534ba72007-04-25 09:52:20 -04004753 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004754
James Smart92d7f7b2007-06-17 19:56:38 -05004755 lpfc_fabric_abort_nport(ndlp);
4756
dea31012005-04-17 16:05:31 -05004757 /*
4758 * Everything that matches on txcmplq will be returned
4759 * by firmware with a no rpi error.
4760 */
James Smart40426292010-12-15 17:58:10 -05004761 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004762 if (phba->sli_rev != LPFC_SLI_REV4)
4763 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4764 else
4765 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004766 }
James Smart2534ba72007-04-25 09:52:20 -04004767
James Smarta257bf92009-04-06 18:48:10 -04004768 /* Cancel all the IOCBs from the completions list */
4769 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4770 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004771
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004772 return 0;
dea31012005-04-17 16:05:31 -05004773}
4774
James Smart086a3452012-08-14 14:25:21 -04004775/**
4776 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4777 * @phba: Pointer to HBA context object.
4778 * @pmb: Pointer to mailbox object.
4779 *
4780 * This function will issue an ELS LOGO command after completing
4781 * the UNREG_RPI.
4782 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004783static void
James Smart086a3452012-08-14 14:25:21 -04004784lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4785{
4786 struct lpfc_vport *vport = pmb->vport;
4787 struct lpfc_nodelist *ndlp;
4788
James Smart3e1f0712018-11-29 16:09:29 -08004789 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004790 if (!ndlp)
4791 return;
4792 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004793 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004794
4795 /* Check to see if there are any deferred events to process */
4796 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4797 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4798 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4799 "1434 UNREG cmpl deferred logo x%x "
4800 "on NPort x%x Data: x%x %p\n",
4801 ndlp->nlp_rpi, ndlp->nlp_DID,
4802 ndlp->nlp_defer_did, ndlp);
4803
4804 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4805 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4806 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart00292e02018-12-13 15:17:55 -08004807 } else {
4808 ndlp->nlp_flag &= ~NLP_UNREG_INP;
James Smartdea16bd2018-11-29 16:09:30 -08004809 }
James Smart086a3452012-08-14 14:25:21 -04004810}
4811
dea31012005-04-17 16:05:31 -05004812/*
4813 * Free rpi associated with LPFC_NODELIST entry.
4814 * This routine is called from lpfc_freenode(), when we are removing
4815 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4816 * LOGO that completes successfully, and we are waiting to PLOGI back
4817 * to the remote NPort. In addition, it is called after we receive
4818 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4819 * we are waiting to PLOGI back to the remote NPort.
4820 */
4821int
James Smart2e0fef82007-06-17 19:56:36 -05004822lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004823{
James Smart2e0fef82007-06-17 19:56:36 -05004824 struct lpfc_hba *phba = vport->phba;
4825 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004826 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004827 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004828
James Smartf454a9a2013-09-06 12:20:07 -04004829 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4830 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4831 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4832 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4833 "3366 RPI x%x needs to be "
4834 "unregistered nlp_flag x%x "
4835 "did x%x\n",
4836 ndlp->nlp_rpi, ndlp->nlp_flag,
4837 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004838
4839 /* If there is already an UNREG in progress for this ndlp,
4840 * no need to queue up another one.
4841 */
4842 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4843 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4844 "1436 unreg_rpi SKIP UNREG x%x on "
4845 "NPort x%x deferred x%x flg x%x "
4846 "Data: %p\n",
4847 ndlp->nlp_rpi, ndlp->nlp_DID,
4848 ndlp->nlp_defer_did,
4849 ndlp->nlp_flag, ndlp);
4850 goto out;
4851 }
4852
James Smart2e0fef82007-06-17 19:56:36 -05004853 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4854 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004855 /* SLI4 ports require the physical rpi value. */
4856 rpi = ndlp->nlp_rpi;
4857 if (phba->sli_rev == LPFC_SLI_REV4)
4858 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004859
James Smart6d368e52011-05-24 11:44:12 -04004860 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004861 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004862 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
James Smart3e1f0712018-11-29 16:09:29 -08004863 mbox->ctx_ndlp = ndlp;
James Smart086a3452012-08-14 14:25:21 -04004864 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4865 } else {
James Smartbe6bb942015-04-07 15:07:22 -04004866 if (phba->sli_rev == LPFC_SLI_REV4 &&
4867 (!(vport->load_flag & FC_UNLOADING)) &&
4868 (bf_get(lpfc_sli_intf_if_type,
James Smart719162b2018-12-10 19:37:01 -08004869 &phba->sli4_hba.sli_intf) >=
James Smarta6517db2016-03-31 14:12:29 -07004870 LPFC_SLI_INTF_IF_TYPE_2) &&
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004871 (kref_read(&ndlp->kref) > 0)) {
James Smart3e1f0712018-11-29 16:09:29 -08004872 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004873 mbox->mbox_cmpl =
4874 lpfc_sli4_unreg_rpi_cmpl_clr;
James Smart7c5e5182015-05-22 10:42:43 -04004875 /*
4876 * accept PLOGIs after unreg_rpi_cmpl
4877 */
4878 acc_plogi = 0;
James Smart9b164062019-03-12 16:30:06 -07004879 } else if (vport->load_flag & FC_UNLOADING) {
4880 mbox->ctx_ndlp = NULL;
4881 mbox->mbox_cmpl =
4882 lpfc_sli_def_mbox_cmpl;
James Smartdea16bd2018-11-29 16:09:30 -08004883 } else {
4884 mbox->ctx_ndlp = ndlp;
James Smartbe6bb942015-04-07 15:07:22 -04004885 mbox->mbox_cmpl =
4886 lpfc_sli_def_mbox_cmpl;
James Smartdea16bd2018-11-29 16:09:30 -08004887 }
James Smart086a3452012-08-14 14:25:21 -04004888 }
James Smartdea16bd2018-11-29 16:09:30 -08004889 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4890 Fabric_DID_MASK) &&
4891 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4892 ndlp->nlp_flag |= NLP_UNREG_INP;
4893
4894 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4895 "1433 unreg_rpi UNREG x%x on "
4896 "NPort x%x deferred flg x%x Data:%p\n",
4897 ndlp->nlp_rpi, ndlp->nlp_DID,
4898 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004899
James Smart0b727fe2007-10-27 13:37:25 -04004900 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004901 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004902 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004903 acc_plogi = 1;
4904 }
dea31012005-04-17 16:05:31 -05004905 }
dea31012005-04-17 16:05:31 -05004906 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004907out:
James Smart40426292010-12-15 17:58:10 -05004908 if (phba->sli_rev != LPFC_SLI_REV4)
4909 ndlp->nlp_rpi = 0;
4910 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004911 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004912 if (acc_plogi)
4913 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004914 return 1;
4915 }
James Smart7c5e5182015-05-22 10:42:43 -04004916 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004917 return 0;
4918}
4919
James Smartecfd03c2010-02-12 14:41:27 -05004920/**
4921 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4922 * @phba: pointer to lpfc hba data structure.
4923 *
4924 * This routine is invoked to unregister all the currently registered RPIs
4925 * to the HBA.
4926 **/
4927void
4928lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4929{
4930 struct lpfc_vport **vports;
4931 struct lpfc_nodelist *ndlp;
4932 struct Scsi_Host *shost;
4933 int i;
4934
4935 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004936 if (!vports) {
4937 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4938 "2884 Vport array allocation failed \n");
4939 return;
4940 }
James Smartecfd03c2010-02-12 14:41:27 -05004941 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4942 shost = lpfc_shost_from_vport(vports[i]);
4943 spin_lock_irq(shost->host_lock);
4944 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004945 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004946 /* The mempool_alloc might sleep */
4947 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004948 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004949 spin_lock_irq(shost->host_lock);
4950 }
James Smartecfd03c2010-02-12 14:41:27 -05004951 }
4952 spin_unlock_irq(shost->host_lock);
4953 }
4954 lpfc_destroy_vport_work_array(phba, vports);
4955}
4956
James Smart92d7f7b2007-06-17 19:56:38 -05004957void
4958lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4959{
4960 struct lpfc_hba *phba = vport->phba;
4961 LPFC_MBOXQ_t *mbox;
4962 int rc;
4963
James Smart5af5eee2010-10-22 11:06:38 -04004964 if (phba->sli_rev == LPFC_SLI_REV4) {
4965 lpfc_sli4_unreg_all_rpis(vport);
4966 return;
4967 }
4968
James Smart92d7f7b2007-06-17 19:56:38 -05004969 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4970 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004971 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4972 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004973 mbox->vport = vport;
4974 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08004975 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05004976 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004977 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004978 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04004979
4980 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4981 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4982 "1836 Could not issue "
4983 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004984 }
4985}
4986
4987void
4988lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4989{
4990 struct lpfc_hba *phba = vport->phba;
4991 LPFC_MBOXQ_t *mbox;
4992 int rc;
4993
James Smartc95a3b42019-03-12 16:30:07 -07004994 /* Unreg DID is an SLI3 operation. */
4995 if (phba->sli_rev > LPFC_SLI_REV3)
4996 return;
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_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
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)
5007 mempool_free(mbox, phba->mbox_mem_pool);
5008
5009 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04005010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
5011 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04005012 "unreg_did (default rpis) status %d\n",
5013 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05005014 }
5015}
5016
dea31012005-04-17 16:05:31 -05005017/*
5018 * Free resources associated with LPFC_NODELIST entry
5019 * so it can be freed.
5020 */
5021static int
James Smart2e0fef82007-06-17 19:56:36 -05005022lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005023{
James Smart2e0fef82007-06-17 19:56:36 -05005024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5025 struct lpfc_hba *phba = vport->phba;
5026 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005027 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05005028
5029 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005030 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5031 "0900 Cleanup node for NPort x%x "
5032 "Data: x%x x%x x%x\n",
5033 ndlp->nlp_DID, ndlp->nlp_flag,
5034 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005035 if (NLP_CHK_FREE_REQ(ndlp)) {
5036 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5037 "0280 lpfc_cleanup_node: ndlp:x%p "
5038 "usgmap:x%x refcnt:%d\n",
5039 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005040 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005041 lpfc_dequeue_node(vport, ndlp);
5042 } else {
5043 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5044 "0281 lpfc_cleanup_node: ndlp:x%p "
5045 "usgmap:x%x refcnt:%d\n",
5046 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005047 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005048 lpfc_disable_node(vport, ndlp);
5049 }
dea31012005-04-17 16:05:31 -05005050
James Smart086a3452012-08-14 14:25:21 -04005051
5052 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5053
dea31012005-04-17 16:05:31 -05005054 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5055 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005056 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005057 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005058 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5059 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005060 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5061 }
5062 }
James Smart33ccf8d2006-08-17 11:57:58 -04005063
James Smart2e0fef82007-06-17 19:56:36 -05005064 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005065 /* Cleanup REG_LOGIN completions which are not yet processed */
5066 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5067 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005068 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005069 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005070 continue;
5071
James Smart3e1f0712018-11-29 16:09:29 -08005072 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005073 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5074 }
5075
dea31012005-04-17 16:05:31 -05005076 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005077 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005078 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005079 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5080 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005081 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005082 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005083 kfree(mp);
5084 }
5085 list_del(&mb->list);
5086 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005087 /* We shall not invoke the lpfc_nlp_put to decrement
5088 * the ndlp reference count as we are in the process
5089 * of lpfc_nlp_release.
5090 */
dea31012005-04-17 16:05:31 -05005091 }
5092 }
James Smart2e0fef82007-06-17 19:56:36 -05005093 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005094
James Smarte47c9092008-02-08 18:49:26 -05005095 lpfc_els_abort(phba, ndlp);
5096
James Smart2e0fef82007-06-17 19:56:36 -05005097 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04005098 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05005099 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005100
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005101 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005102 del_timer_sync(&ndlp->nlp_delayfunc);
5103
James Smart0d2b6b82008-06-14 22:52:47 -04005104 list_del_init(&ndlp->els_retry_evt.evt_listp);
5105 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005106 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005107 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05005108
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005109 return 0;
dea31012005-04-17 16:05:31 -05005110}
5111
5112/*
5113 * Check to see if we can free the nlp back to the freelist.
5114 * If we are in the middle of using the nlp in the discovery state
5115 * machine, defer the free till we reach the end of the state machine.
5116 */
James Smart329f9bc2007-04-25 09:53:01 -04005117static void
James Smart2e0fef82007-06-17 19:56:36 -05005118lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005119{
James Smarta8adb832007-10-27 13:37:53 -04005120 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04005121 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04005122 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04005123 LPFC_MBOXQ_t *mbox;
5124 int rc;
dea31012005-04-17 16:05:31 -05005125
James Smart0d2b6b82008-06-14 22:52:47 -04005126 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04005127 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05005128 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
Dick Kennedye8bcf0a2017-09-29 17:34:32 -07005129 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5130 phba->sli_rev != LPFC_SLI_REV4) {
James Smarta8adb832007-10-27 13:37:53 -04005131 /* For this case we need to cleanup the default rpi
5132 * allocated by the firmware.
5133 */
James Smartbe6bb942015-04-07 15:07:22 -04005134 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5135 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5136 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005137 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005138 ndlp->nlp_usg_map, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04005139 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5140 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04005141 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05005142 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04005143 if (rc) {
5144 mempool_free(mbox, phba->mbox_mem_pool);
5145 }
5146 else {
5147 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5148 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5149 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08005150 mbox->ctx_ndlp = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04005151 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5152 if (rc == MBX_NOT_FINISHED) {
5153 mempool_free(mbox, phba->mbox_mem_pool);
5154 }
5155 }
5156 }
5157 }
James Smart2e0fef82007-06-17 19:56:36 -05005158 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04005159
James Smart2e0fef82007-06-17 19:56:36 -05005160 /*
James Smart466e8402015-05-21 13:55:28 -04005161 * ndlp->rport must be set to NULL before it reaches here
5162 * i.e. break rport/node link before doing lpfc_nlp_put for
5163 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05005164 */
James Smart92d7f7b2007-06-17 19:56:38 -05005165 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04005166 /*
5167 * extra lpfc_nlp_put dropped the reference of ndlp
5168 * for registered rport so need to cleanup rport
5169 */
5170 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5171 "0940 removed node x%p DID x%x "
5172 " rport not null %p\n",
5173 ndlp, ndlp->nlp_DID, ndlp->rport);
5174 rport = ndlp->rport;
5175 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04005176 rdata->pnode = NULL;
5177 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04005178 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05005179 }
dea31012005-04-17 16:05:31 -05005180}
5181
5182static int
James Smart2e0fef82007-06-17 19:56:36 -05005183lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5184 uint32_t did)
dea31012005-04-17 16:05:31 -05005185{
James Smart2e0fef82007-06-17 19:56:36 -05005186 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005187
5188 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005189 return 0;
dea31012005-04-17 16:05:31 -05005190
dea31012005-04-17 16:05:31 -05005191 /* First check for Direct match */
5192 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005193 return 1;
dea31012005-04-17 16:05:31 -05005194
5195 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005196 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005197 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005198 return 0;
dea31012005-04-17 16:05:31 -05005199 }
5200
5201 matchdid.un.word = did;
5202 ndlpdid.un.word = ndlp->nlp_DID;
5203 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5204 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5205 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005206 /* This code is supposed to match the ID
5207 * for a private loop device that is
5208 * connect to fl_port. But we need to
5209 * check that the port did not just go
5210 * from pt2pt to fabric or we could end
5211 * up matching ndlp->nlp_DID 000001 to
5212 * fabric DID 0x20101
5213 */
dea31012005-04-17 16:05:31 -05005214 if ((ndlpdid.un.b.domain == 0) &&
5215 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005216 if (ndlpdid.un.b.id &&
5217 vport->phba->fc_topology ==
5218 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005219 return 1;
dea31012005-04-17 16:05:31 -05005220 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005221 return 0;
dea31012005-04-17 16:05:31 -05005222 }
5223
5224 matchdid.un.word = ndlp->nlp_DID;
5225 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5226 (mydid.un.b.area == ndlpdid.un.b.area)) {
5227 if ((matchdid.un.b.domain == 0) &&
5228 (matchdid.un.b.area == 0)) {
5229 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005230 return 1;
dea31012005-04-17 16:05:31 -05005231 }
5232 }
5233 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005234 return 0;
dea31012005-04-17 16:05:31 -05005235}
5236
James Smart685f0bf2007-04-25 09:53:08 -04005237/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005238static struct lpfc_nodelist *
5239__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005240{
James Smart2fb9bd82006-12-02 13:33:57 -05005241 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005242 uint32_t data1;
5243
James Smart2e0fef82007-06-17 19:56:36 -05005244 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5245 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04005246 data1 = (((uint32_t) ndlp->nlp_state << 24) |
5247 ((uint32_t) ndlp->nlp_xri << 16) |
5248 ((uint32_t) ndlp->nlp_type << 8) |
5249 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04005250 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5251 "0929 FIND node DID "
James Smartcff261f2013-12-17 20:29:47 -05005252 "Data: x%p x%x x%x x%x %p\n",
James Smarte8b62012007-08-02 11:10:09 -04005253 ndlp, ndlp->nlp_DID,
James Smartcff261f2013-12-17 20:29:47 -05005254 ndlp->nlp_flag, data1,
5255 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005256 return ndlp;
dea31012005-04-17 16:05:31 -05005257 }
5258 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005259
dea31012005-04-17 16:05:31 -05005260 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005261 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5262 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005263 return NULL;
5264}
5265
5266struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005267lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005268{
James Smart2e0fef82007-06-17 19:56:36 -05005269 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005270 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005271 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005272
James Smartfedd3b72011-02-16 12:39:24 -05005273 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005274 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005275 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005276 return ndlp;
5277}
5278
5279struct lpfc_nodelist *
James Smartf60cb932019-05-14 14:58:05 -07005280lpfc_findnode_mapped(struct lpfc_vport *vport)
5281{
5282 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5283 struct lpfc_nodelist *ndlp;
5284 uint32_t data1;
5285 unsigned long iflags;
5286
5287 spin_lock_irqsave(shost->host_lock, iflags);
5288
5289 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5290 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5291 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5292 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5293 ((uint32_t)ndlp->nlp_xri << 16) |
5294 ((uint32_t)ndlp->nlp_type << 8) |
5295 ((uint32_t)ndlp->nlp_rpi & 0xff));
5296 spin_unlock_irqrestore(shost->host_lock, iflags);
5297 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5298 "2025 FIND node DID "
5299 "Data: x%p x%x x%x x%x %p\n",
5300 ndlp, ndlp->nlp_DID,
5301 ndlp->nlp_flag, data1,
5302 ndlp->active_rrqs_xri_bitmap);
5303 return ndlp;
5304 }
5305 }
5306 spin_unlock_irqrestore(shost->host_lock, iflags);
5307
5308 /* FIND node did <did> NOT FOUND */
5309 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5310 "2026 FIND mapped did NOT FOUND.\n");
5311 return NULL;
5312}
5313
5314struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005315lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5316{
5317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5318 struct lpfc_nodelist *ndlp;
5319
5320 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005321 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005322 if (vport->phba->nvmet_support)
5323 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005324 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5325 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005326 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005327 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005328 if (!ndlp)
5329 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005330 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5331 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005332 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005333 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005334 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005335 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005336 if (vport->phba->nvmet_support)
5337 return NULL;
James Smarte47c9092008-02-08 18:49:26 -05005338 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
5339 if (!ndlp)
5340 return NULL;
5341 spin_lock_irq(shost->host_lock);
5342 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5343 spin_unlock_irq(shost->host_lock);
5344 return ndlp;
dea31012005-04-17 16:05:31 -05005345 }
James Smarte47c9092008-02-08 18:49:26 -05005346
James Smart1c5b12f2017-04-21 16:05:03 -07005347 /* The NVME Target does not want to actively manage an rport.
5348 * The goal is to allow the target to reset its state and clear
5349 * pending IO in preparation for the initiator to recover.
5350 */
James Smart58da1ff2008-04-07 10:15:56 -04005351 if ((vport->fc_flag & FC_RSCN_MODE) &&
5352 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005353 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005354
5355 /* Since this node is marked for discovery,
5356 * delay timeout is not needed.
5357 */
5358 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5359
5360 /* NVME Target mode waits until rport is known to be
5361 * impacted by the RSCN before it transitions. No
5362 * active management - just go to NPR provided the
5363 * node had a valid login.
5364 */
5365 if (vport->phba->nvmet_support)
5366 return ndlp;
5367
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005368 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005369 * we don't need to try to discover it again.
5370 */
5371 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
5372 return NULL;
5373
James Smarta257bf92009-04-06 18:48:10 -04005374 spin_lock_irq(shost->host_lock);
5375 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5376 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04005377 } else
dea31012005-04-17 16:05:31 -05005378 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005379 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07005380 /* If the initiator received a PLOGI from this NPort or if the
5381 * initiator is already in the process of discovery on it,
5382 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005383 */
James Smart685f0bf2007-04-25 09:53:08 -04005384 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005385 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005386 (!vport->phba->nvmet_support &&
5387 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005388 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005389
James Smart8c258642017-02-12 13:52:36 -08005390 if (vport->phba->nvmet_support)
5391 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005392
5393 /* Moving to NPR state clears unsolicited flags and
5394 * allows for rediscovery
5395 */
5396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5397
James Smart2e0fef82007-06-17 19:56:36 -05005398 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005399 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005400 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005401 }
5402 return ndlp;
5403}
5404
5405/* Build a list of nodes to discover based on the loopmap */
5406void
James Smart2e0fef82007-06-17 19:56:36 -05005407lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005408{
James Smart2e0fef82007-06-17 19:56:36 -05005409 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005410 int j;
5411 uint32_t alpa, index;
5412
James Smart2e0fef82007-06-17 19:56:36 -05005413 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005414 return;
James Smart2e0fef82007-06-17 19:56:36 -05005415
James Smart76a95d72010-11-20 23:11:48 -05005416 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005417 return;
dea31012005-04-17 16:05:31 -05005418
5419 /* Check for loop map present or not */
5420 if (phba->alpa_map[0]) {
5421 for (j = 1; j <= phba->alpa_map[0]; j++) {
5422 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005423 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005424 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005425 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005426 }
5427 } else {
5428 /* No alpamap, so try all alpa's */
5429 for (j = 0; j < FC_MAXLOOP; j++) {
5430 /* If cfg_scan_down is set, start from highest
5431 * ALPA (0xef) to lowest (0x1).
5432 */
James Smart3de2a652007-08-02 11:09:59 -04005433 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005434 index = j;
5435 else
5436 index = FC_MAXLOOP - j - 1;
5437 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005438 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005439 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005440 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005441 }
5442 }
5443 return;
5444}
5445
James Smart895427b2017-02-12 13:52:30 -08005446/* SLI3 only */
dea31012005-04-17 16:05:31 -05005447void
James Smart2e0fef82007-06-17 19:56:36 -05005448lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005449{
dea31012005-04-17 16:05:31 -05005450 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005451 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005452 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5453 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005454 int rc;
5455
James Smart92d7f7b2007-06-17 19:56:38 -05005456 /*
5457 * if it's not a physical port or if we already send
5458 * clear_la then don't send it.
5459 */
5460 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005461 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5462 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005463 return;
5464
James Smart2e0fef82007-06-17 19:56:36 -05005465 /* Link up discovery */
5466 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5467 phba->link_state = LPFC_CLEAR_LA;
5468 lpfc_clear_la(phba, mbox);
5469 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5470 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005471 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005472 if (rc == MBX_NOT_FINISHED) {
5473 mempool_free(mbox, phba->mbox_mem_pool);
5474 lpfc_disc_flush_list(vport);
5475 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5476 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005477 phba->link_state = LPFC_HBA_ERROR;
5478 }
5479 }
5480}
5481
5482/* Reg_vpi to tell firmware to resume normal operations */
5483void
5484lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5485{
5486 LPFC_MBOXQ_t *regvpimbox;
5487
5488 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5489 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005490 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005491 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5492 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005493 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005494 == MBX_NOT_FINISHED) {
5495 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005496 }
5497 }
5498}
5499
5500/* Start Link up / RSCN discovery on NPR nodes */
5501void
5502lpfc_disc_start(struct lpfc_vport *vport)
5503{
5504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5505 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005506 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005507 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005508
James Smarte74c03c2013-04-17 20:15:19 -04005509 if (!lpfc_is_link_up(phba)) {
5510 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5511 "3315 Link is not up %x\n",
5512 phba->link_state);
dea31012005-04-17 16:05:31 -05005513 return;
James Smarte74c03c2013-04-17 20:15:19 -04005514 }
James Smart2e0fef82007-06-17 19:56:36 -05005515
5516 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005517 clear_la_pending = 1;
5518 else
5519 clear_la_pending = 0;
5520
James Smart2e0fef82007-06-17 19:56:36 -05005521 if (vport->port_state < LPFC_VPORT_READY)
5522 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005523
James Smart2e0fef82007-06-17 19:56:36 -05005524 lpfc_set_disctmo(vport);
5525
James Smart2e0fef82007-06-17 19:56:36 -05005526 vport->fc_prevDID = vport->fc_myDID;
5527 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005528
5529 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005530 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5531 "0202 Start Discovery hba state x%x "
5532 "Data: x%x x%x x%x\n",
5533 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5534 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005535
5536 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005537 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005538
5539 if (num_sent)
5540 return;
5541
James Smart6fa139f2013-04-17 20:20:00 -04005542 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005543 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005544 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005545 !(vport->fc_flag & FC_RSCN_MODE) &&
5546 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005547 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005548 lpfc_issue_reg_vpi(phba, vport);
5549 return;
5550 }
James Smart2e0fef82007-06-17 19:56:36 -05005551
James Smart92d7f7b2007-06-17 19:56:38 -05005552 /*
5553 * For SLI2, we need to set port_state to READY and continue
5554 * discovery.
5555 */
5556 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5557 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005558 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005559
5560 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005561 vport->num_disc_nodes = 0;
5562 /* go thru NPR nodes and issue ELS PLOGIs */
5563 if (vport->fc_npr_cnt)
5564 lpfc_els_disc_plogi(vport);
5565
5566 if (!vport->num_disc_nodes) {
5567 spin_lock_irq(shost->host_lock);
5568 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5569 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005570 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005571 }
5572 }
James Smart92d7f7b2007-06-17 19:56:38 -05005573 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005574 } else {
5575 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005576 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005577
5578 if (num_sent)
5579 return;
5580
James Smart2e0fef82007-06-17 19:56:36 -05005581 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005582 /* Check to see if more RSCNs came in while we
5583 * were processing this one.
5584 */
James Smart2e0fef82007-06-17 19:56:36 -05005585 if ((vport->fc_rscn_id_cnt == 0) &&
5586 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5587 spin_lock_irq(shost->host_lock);
5588 vport->fc_flag &= ~FC_RSCN_MODE;
5589 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005590 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005591 } else
James Smart2e0fef82007-06-17 19:56:36 -05005592 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005593 }
5594 }
5595 return;
5596}
5597
5598/*
5599 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5600 * ring the match the sppecified nodelist.
5601 */
5602static void
James Smart2e0fef82007-06-17 19:56:36 -05005603lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005604{
James Smart2534ba72007-04-25 09:52:20 -04005605 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005606 IOCB_t *icmd;
5607 struct lpfc_iocbq *iocb, *next_iocb;
5608 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005609
James Smart895427b2017-02-12 13:52:30 -08005610 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005611 if (unlikely(!pring))
5612 return;
dea31012005-04-17 16:05:31 -05005613
5614 /* Error matching iocb on txq or txcmplq
5615 * First check the txq.
5616 */
James Smart2e0fef82007-06-17 19:56:36 -05005617 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005618 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5619 if (iocb->context1 != ndlp) {
5620 continue;
5621 }
5622 icmd = &iocb->iocb;
5623 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5624 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5625
James Smart2534ba72007-04-25 09:52:20 -04005626 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005627 }
5628 }
5629
5630 /* Next check the txcmplq */
5631 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5632 if (iocb->context1 != ndlp) {
5633 continue;
5634 }
5635 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005636 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5637 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005638 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005639 }
5640 }
James Smart2e0fef82007-06-17 19:56:36 -05005641 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005642
James Smarta257bf92009-04-06 18:48:10 -04005643 /* Cancel all the IOCBs from the completions list */
5644 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5645 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005646}
5647
Adrian Bunka6ababd2007-11-05 18:07:33 +01005648static void
James Smart2e0fef82007-06-17 19:56:36 -05005649lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005650{
5651 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005652 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005653
James Smart2e0fef82007-06-17 19:56:36 -05005654 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5655 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005656 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005657 if (!NLP_CHK_NODE_ACT(ndlp))
5658 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005659 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5660 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5661 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005662 }
dea31012005-04-17 16:05:31 -05005663 }
5664 }
dea31012005-04-17 16:05:31 -05005665}
5666
James Smart92d7f7b2007-06-17 19:56:38 -05005667void
5668lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5669{
5670 lpfc_els_flush_rscn(vport);
5671 lpfc_els_flush_cmd(vport);
5672 lpfc_disc_flush_list(vport);
5673}
5674
dea31012005-04-17 16:05:31 -05005675/*****************************************************************************/
5676/*
5677 * NAME: lpfc_disc_timeout
5678 *
5679 * FUNCTION: Fibre Channel driver discovery timeout routine.
5680 *
5681 * EXECUTION ENVIRONMENT: interrupt only
5682 *
5683 * CALLED FROM:
5684 * Timer function
5685 *
5686 * RETURNS:
5687 * none
5688 */
5689/*****************************************************************************/
5690void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005691lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005692{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005693 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005694 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005695 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005696 unsigned long flags = 0;
5697
5698 if (unlikely(!phba))
5699 return;
5700
James Smart5e9d9b82008-06-14 22:52:53 -04005701 spin_lock_irqsave(&vport->work_port_lock, flags);
5702 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5703 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005704 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005705 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005706
James Smart5e9d9b82008-06-14 22:52:53 -04005707 if (!tmo_posted)
5708 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005709 return;
5710}
5711
5712static void
James Smart2e0fef82007-06-17 19:56:36 -05005713lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005714{
James Smart2e0fef82007-06-17 19:56:36 -05005715 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5716 struct lpfc_hba *phba = vport->phba;
5717 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005718 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005719 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005720 int rc, clrlaerr = 0;
5721
James Smart2e0fef82007-06-17 19:56:36 -05005722 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005723 return;
5724
James Smart2e0fef82007-06-17 19:56:36 -05005725 spin_lock_irq(shost->host_lock);
5726 vport->fc_flag &= ~FC_DISC_TMO;
5727 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005728
James Smart858c9f62007-06-17 19:56:39 -05005729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5730 "disc timeout: state:x%x rtry:x%x flg:x%x",
5731 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5732
James Smart2e0fef82007-06-17 19:56:36 -05005733 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005734
5735 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005736 /*
5737 * port_state is identically LPFC_LOCAL_CFG_LINK while
5738 * waiting for FAN timeout
5739 */
James Smarte8b62012007-08-02 11:10:09 -04005740 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5741 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005742
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005743 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005744 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005745 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005746 if (!NLP_CHK_NODE_ACT(ndlp))
5747 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005748 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5749 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005750 if (ndlp->nlp_type & NLP_FABRIC) {
5751 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005752 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005753
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005754 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005755 /* Fail outstanding IO now since device
5756 * is marked for PLOGI.
5757 */
James Smart2e0fef82007-06-17 19:56:36 -05005758 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005759 }
5760 }
James Smart92d7f7b2007-06-17 19:56:38 -05005761 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005762 if (phba->sli_rev <= LPFC_SLI_REV3)
5763 lpfc_initial_flogi(vport);
5764 else
5765 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005766 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005767 }
dea31012005-04-17 16:05:31 -05005768 break;
5769
James Smart92d7f7b2007-06-17 19:56:38 -05005770 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005771 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005772 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005773 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005774 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5775 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005776 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005777
5778 /* Assume no Fabric and go on with discovery.
5779 * Check for outstanding ELS FLOGI to abort.
5780 */
5781
5782 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005783 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005784
5785 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005786 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005787 break;
5788
5789 case LPFC_FABRIC_CFG_LINK:
5790 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5791 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005792 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5793 "0223 Timeout while waiting for "
5794 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005795 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005796 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005797 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005798 lpfc_els_abort(phba, ndlp);
5799
5800 /* ReStart discovery */
5801 goto restart_disc;
dea31012005-04-17 16:05:31 -05005802
5803 case LPFC_NS_QRY:
5804 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005805 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5806 "0224 NameServer Query timeout "
5807 "Data: x%x x%x\n",
5808 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005809
James Smart92d7f7b2007-06-17 19:56:38 -05005810 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5811 /* Try it one more time */
5812 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005813 vport->gidft_inp = 0;
5814 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005815 if (rc == 0)
5816 break;
dea31012005-04-17 16:05:31 -05005817 }
James Smart92d7f7b2007-06-17 19:56:38 -05005818 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005819
James Smart87af33f2007-10-27 13:37:43 -04005820restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005821 /*
5822 * Discovery is over.
5823 * set port_state to PORT_READY if SLI2.
5824 * cmpl_reg_vpi will set port_state to READY for SLI3.
5825 */
James Smart3772a992009-05-22 14:50:54 -04005826 if (phba->sli_rev < LPFC_SLI_REV4) {
5827 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5828 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005829 else {
James Smart3772a992009-05-22 14:50:54 -04005830 lpfc_issue_clear_la(phba, vport);
5831 vport->port_state = LPFC_VPORT_READY;
5832 }
dea31012005-04-17 16:05:31 -05005833 }
5834
5835 /* Setup and issue mailbox INITIALIZE LINK command */
5836 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5837 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005838 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5839 "0206 Device Discovery "
5840 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005841 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005842 break;
5843 }
5844
5845 lpfc_linkdown(phba);
5846 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5847 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005848 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005849 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005850 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005851 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005852 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005853 if (rc == MBX_NOT_FINISHED)
5854 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5855
5856 break;
5857
5858 case LPFC_DISC_AUTH:
5859 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005860 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5861 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005862 lpfc_disc_flush_list(vport);
5863
James Smart92d7f7b2007-06-17 19:56:38 -05005864 /*
5865 * set port_state to PORT_READY if SLI2.
5866 * cmpl_reg_vpi will set port_state to READY for SLI3.
5867 */
James Smart3772a992009-05-22 14:50:54 -04005868 if (phba->sli_rev < LPFC_SLI_REV4) {
5869 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5870 lpfc_issue_reg_vpi(phba, vport);
5871 else { /* NPIV Not enabled */
5872 lpfc_issue_clear_la(phba, vport);
5873 vport->port_state = LPFC_VPORT_READY;
5874 }
dea31012005-04-17 16:05:31 -05005875 }
5876 break;
5877
James Smart2e0fef82007-06-17 19:56:36 -05005878 case LPFC_VPORT_READY:
5879 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04005880 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5881 "0231 RSCN timeout Data: x%x "
5882 "x%x\n",
5883 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005884
5885 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005886 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005887
James Smart2e0fef82007-06-17 19:56:36 -05005888 lpfc_els_flush_rscn(vport);
5889 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005890 }
5891 break;
James Smart2e0fef82007-06-17 19:56:36 -05005892
James Smart92d7f7b2007-06-17 19:56:38 -05005893 default:
James Smarte8b62012007-08-02 11:10:09 -04005894 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005895 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005896 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005897 break;
5898 }
5899
5900 switch (phba->link_state) {
5901 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005902 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005903 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5904 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005905 clrlaerr = 1;
5906 break;
5907
James Smart09372822008-01-11 01:52:54 -05005908 case LPFC_LINK_UP:
5909 lpfc_issue_clear_la(phba, vport);
Bart Van Asschecd05c152019-03-28 11:06:18 -07005910 /* fall through */
James Smart2e0fef82007-06-17 19:56:36 -05005911 case LPFC_LINK_UNKNOWN:
5912 case LPFC_WARM_START:
5913 case LPFC_INIT_START:
5914 case LPFC_INIT_MBX_CMDS:
5915 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005916 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005917 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5918 "0230 Unexpected timeout, hba link "
5919 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005920 clrlaerr = 1;
5921 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005922
5923 case LPFC_HBA_READY:
5924 break;
dea31012005-04-17 16:05:31 -05005925 }
5926
5927 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005928 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005929 if (phba->sli_rev != LPFC_SLI_REV4) {
5930 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5931 ~LPFC_STOP_IOCB_EVENT;
5932 psli->sli3_ring[LPFC_FCP_RING].flag &=
5933 ~LPFC_STOP_IOCB_EVENT;
5934 }
James Smart2e0fef82007-06-17 19:56:36 -05005935 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005936 }
dea31012005-04-17 16:05:31 -05005937 return;
5938}
5939
dea31012005-04-17 16:05:31 -05005940/*
5941 * This routine handles processing a NameServer REG_LOGIN mailbox
5942 * command upon completion. It is setup in the LPFC_MBOXQ
5943 * as the completion routine when the command is
5944 * handed off to the SLI layer.
5945 */
5946void
James Smart2e0fef82007-06-17 19:56:36 -05005947lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005948{
James Smart04c68492009-05-22 14:52:52 -04005949 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08005950 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5951 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005952 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005953
James Smart3e1f0712018-11-29 16:09:29 -08005954 pmb->ctx_buf = NULL;
5955 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005956
James Smart6d368e52011-05-24 11:44:12 -04005957 if (phba->sli_rev < LPFC_SLI_REV4)
5958 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005959 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005960 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005961 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04005962 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5963 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5964 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005965 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005966 ndlp->nlp_usg_map, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005967 /*
5968 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05005969 * 0xfffffa (FDMI well known port).
5970 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5971 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05005972 */
James Smart4258e982015-12-16 18:11:58 -05005973 if (vport->port_type == LPFC_PHYSICAL_PORT)
5974 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04005975 else
James Smart4258e982015-12-16 18:11:58 -05005976 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
5977
dea31012005-04-17 16:05:31 -05005978
James Smartfa4066b2008-01-11 01:53:27 -05005979 /* decrement the node reference count held for this callback
5980 * function.
5981 */
James Smart329f9bc2007-04-25 09:53:01 -04005982 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005983 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5984 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04005985 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005986
5987 return;
5988}
5989
James Smart685f0bf2007-04-25 09:53:08 -04005990static int
5991lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5992{
5993 uint16_t *rpi = param;
5994
James Smarteff4a012012-01-18 16:25:25 -05005995 /* check for active node */
5996 if (!NLP_CHK_NODE_ACT(ndlp))
5997 return 0;
5998
James Smart685f0bf2007-04-25 09:53:08 -04005999 return ndlp->nlp_rpi == *rpi;
6000}
6001
6002static int
6003lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6004{
6005 return memcmp(&ndlp->nlp_portname, param,
6006 sizeof(ndlp->nlp_portname)) == 0;
6007}
6008
Adrian Bunka6ababd2007-11-05 18:07:33 +01006009static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006010__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05006011{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006012 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006013
James Smart2e0fef82007-06-17 19:56:36 -05006014 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04006015 if (filter(ndlp, param)) {
6016 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6017 "3185 FIND node filter %p DID "
James Smart49382502017-11-20 16:00:38 -08006018 "ndlp %p did x%x flg x%x st x%x "
6019 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04006020 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08006021 ndlp->nlp_flag, ndlp->nlp_state,
6022 ndlp->nlp_xri, ndlp->nlp_type,
6023 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006024 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04006025 }
James Smart685f0bf2007-04-25 09:53:08 -04006026 }
James Smart34f5ad82012-08-03 12:35:03 -04006027 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6028 "3186 FIND node filter %p NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04006029 return NULL;
dea31012005-04-17 16:05:31 -05006030}
6031
James Smart685f0bf2007-04-25 09:53:08 -04006032/*
6033 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05006034 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04006035 */
6036struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006037__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04006038{
James Smart2e0fef82007-06-17 19:56:36 -05006039 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04006040}
6041
James Smart488d1462006-03-07 15:02:37 -05006042/*
James Smart685f0bf2007-04-25 09:53:08 -04006043 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05006044 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05006045 */
6046struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05006047lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05006048{
James Smart2e0fef82007-06-17 19:56:36 -05006049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05006050 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05006051
James Smart2e0fef82007-06-17 19:56:36 -05006052 spin_lock_irq(shost->host_lock);
6053 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6054 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05006055 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05006056}
6057
James Smartcb69f7d2011-12-13 13:21:57 -05006058/*
6059 * This routine looks up the ndlp lists for the given RPI. If the rpi
6060 * is found, the routine returns the node element list pointer else
6061 * return NULL.
6062 */
6063struct lpfc_nodelist *
6064lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6065{
6066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6067 struct lpfc_nodelist *ndlp;
6068
6069 spin_lock_irq(shost->host_lock);
6070 ndlp = __lpfc_findnode_rpi(vport, rpi);
6071 spin_unlock_irq(shost->host_lock);
6072 return ndlp;
6073}
6074
6075/**
6076 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6077 * @phba: pointer to lpfc hba data structure.
6078 * @vpi: the physical host virtual N_Port identifier.
6079 *
6080 * This routine finds a vport on a HBA (referred by @phba) through a
6081 * @vpi. The function walks the HBA's vport list and returns the address
6082 * of the vport with the matching @vpi.
6083 *
6084 * Return code
6085 * NULL - No vport with the matching @vpi found
6086 * Otherwise - Address to the vport with the matching @vpi.
6087 **/
6088struct lpfc_vport *
6089lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6090{
6091 struct lpfc_vport *vport;
6092 unsigned long flags;
6093 int i = 0;
6094
6095 /* The physical ports are always vpi 0 - translate is unnecessary. */
6096 if (vpi > 0) {
6097 /*
6098 * Translate the physical vpi to the logical vpi. The
6099 * vport stores the logical vpi.
6100 */
6101 for (i = 0; i < phba->max_vpi; i++) {
6102 if (vpi == phba->vpi_ids[i])
6103 break;
6104 }
6105
6106 if (i >= phba->max_vpi) {
6107 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6108 "2936 Could not find Vport mapped "
6109 "to vpi %d\n", vpi);
6110 return NULL;
6111 }
6112 }
6113
James Smart523128e2018-09-10 10:30:46 -07006114 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006115 list_for_each_entry(vport, &phba->port_list, listentry) {
6116 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006117 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006118 return vport;
6119 }
6120 }
James Smart523128e2018-09-10 10:30:46 -07006121 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006122 return NULL;
6123}
6124
James Smart9d3d3402017-04-21 16:05:00 -07006125struct lpfc_nodelist *
6126lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006127{
James Smart9d3d3402017-04-21 16:05:00 -07006128 struct lpfc_nodelist *ndlp;
6129 int rpi = LPFC_RPI_ALLOC_ERROR;
6130
6131 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6132 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6133 if (rpi == LPFC_RPI_ALLOC_ERROR)
6134 return NULL;
6135 }
6136
6137 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6138 if (!ndlp) {
6139 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6140 lpfc_sli4_free_rpi(vport->phba, rpi);
6141 return NULL;
6142 }
6143
dea31012005-04-17 16:05:31 -05006144 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006145
6146 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006147 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006148 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006149 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04006150 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6151 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
6152 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
6153 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006154 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04006155 ndlp->nlp_usg_map, ndlp);
6156
James Smartcff261f2013-12-17 20:29:47 -05006157 ndlp->active_rrqs_xri_bitmap =
6158 mempool_alloc(vport->phba->active_rrq_pool,
6159 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006160 if (ndlp->active_rrqs_xri_bitmap)
6161 memset(ndlp->active_rrqs_xri_bitmap, 0,
6162 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006163 }
6164
James Smart725dd392013-10-10 12:23:30 -04006165
James Smart858c9f62007-06-17 19:56:39 -05006166
6167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6168 "node init: did:x%x",
6169 ndlp->nlp_DID, 0, 0);
6170
James Smart9d3d3402017-04-21 16:05:00 -07006171 return ndlp;
dea31012005-04-17 16:05:31 -05006172}
James Smart329f9bc2007-04-25 09:53:01 -04006173
James Smart98c9ea52007-10-27 13:37:33 -04006174/* This routine releases all resources associated with a specifc NPort's ndlp
6175 * and mempool_free's the nodelist.
6176 */
James Smart311464e2007-08-02 11:10:37 -04006177static void
James Smart329f9bc2007-04-25 09:53:01 -04006178lpfc_nlp_release(struct kref *kref)
6179{
James Smarte47c9092008-02-08 18:49:26 -05006180 struct lpfc_hba *phba;
6181 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04006182 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6183 kref);
James Smart858c9f62007-06-17 19:56:39 -05006184
6185 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6186 "node release: did:x%x flg:x%x type:x%x",
6187 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6188
James Smarte47c9092008-02-08 18:49:26 -05006189 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart939723a2012-05-09 21:19:03 -04006190 "0279 lpfc_nlp_release: ndlp:x%p did %x "
James Smartbe6bb942015-04-07 15:07:22 -04006191 "usgmap:x%x refcnt:%d rpi:%x\n",
James Smart939723a2012-05-09 21:19:03 -04006192 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006193 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006194
6195 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05006196 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05006197
6198 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04006199 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006200 spin_lock_irqsave(&phba->ndlp_lock, flags);
6201 NLP_CLR_NODE_ACT(ndlp);
6202 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart40426292010-12-15 17:58:10 -05006203 if (phba->sli_rev == LPFC_SLI_REV4)
6204 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006205
6206 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04006207 if (NLP_CHK_FREE_REQ(ndlp)) {
6208 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05006209 if (phba->sli_rev == LPFC_SLI_REV4)
6210 mempool_free(ndlp->active_rrqs_xri_bitmap,
6211 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04006212 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04006213 }
James Smart329f9bc2007-04-25 09:53:01 -04006214}
6215
James Smart98c9ea52007-10-27 13:37:33 -04006216/* This routine bumps the reference count for a ndlp structure to ensure
6217 * that one discovery thread won't free a ndlp while another discovery thread
6218 * is using it.
6219 */
James Smart329f9bc2007-04-25 09:53:01 -04006220struct lpfc_nodelist *
6221lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6222{
James Smarte47c9092008-02-08 18:49:26 -05006223 struct lpfc_hba *phba;
6224 unsigned long flags;
6225
James Smart98c9ea52007-10-27 13:37:33 -04006226 if (ndlp) {
6227 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6228 "node get: did:x%x flg:x%x refcnt:x%x",
6229 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006230 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006231 /* The check of ndlp usage to prevent incrementing the
6232 * ndlp reference count that is in the process of being
6233 * released.
6234 */
James Smarta257bf92009-04-06 18:48:10 -04006235 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006236 spin_lock_irqsave(&phba->ndlp_lock, flags);
6237 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6238 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6239 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6240 "0276 lpfc_nlp_get: ndlp:x%p "
6241 "usgmap:x%x refcnt:%d\n",
6242 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006243 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006244 return NULL;
6245 } else
6246 kref_get(&ndlp->kref);
6247 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04006248 }
James Smart329f9bc2007-04-25 09:53:01 -04006249 return ndlp;
6250}
6251
James Smart98c9ea52007-10-27 13:37:33 -04006252/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05006253 * count goes to 0, this indicates the the associated nodelist should be
6254 * freed. Returning 1 indicates the ndlp resource has been released; on the
6255 * other hand, returning 0 indicates the ndlp resource has not been released
6256 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04006257 */
James Smart329f9bc2007-04-25 09:53:01 -04006258int
6259lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6260{
James Smarte47c9092008-02-08 18:49:26 -05006261 struct lpfc_hba *phba;
6262 unsigned long flags;
6263
6264 if (!ndlp)
6265 return 1;
6266
6267 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6268 "node put: did:x%x flg:x%x refcnt:x%x",
6269 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006270 kref_read(&ndlp->kref));
James Smarta257bf92009-04-06 18:48:10 -04006271 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006272 spin_lock_irqsave(&phba->ndlp_lock, flags);
6273 /* Check the ndlp memory free acknowledge flag to avoid the
6274 * possible race condition that kref_put got invoked again
6275 * after previous one has done ndlp memory free.
6276 */
6277 if (NLP_CHK_FREE_ACK(ndlp)) {
6278 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6279 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6280 "0274 lpfc_nlp_put: ndlp:x%p "
6281 "usgmap:x%x refcnt:%d\n",
6282 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006283 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006284 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006285 }
James Smarte47c9092008-02-08 18:49:26 -05006286 /* Check the ndlp inactivate log flag to avoid the possible
6287 * race condition that kref_put got invoked again after ndlp
6288 * is already in inactivating state.
6289 */
6290 if (NLP_CHK_IACT_REQ(ndlp)) {
6291 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6292 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6293 "0275 lpfc_nlp_put: ndlp:x%p "
6294 "usgmap:x%x refcnt:%d\n",
6295 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006296 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006297 return 1;
6298 }
6299 /* For last put, mark the ndlp usage flags to make sure no
6300 * other kref_get and kref_put on the same ndlp shall get
6301 * in between the process when the final kref_put has been
6302 * invoked on this ndlp.
6303 */
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006304 if (kref_read(&ndlp->kref) == 1) {
James Smarte47c9092008-02-08 18:49:26 -05006305 /* Indicate ndlp is put to inactive state. */
6306 NLP_SET_IACT_REQ(ndlp);
6307 /* Acknowledge ndlp memory free has been seen. */
6308 if (NLP_CHK_FREE_REQ(ndlp))
6309 NLP_SET_FREE_ACK(ndlp);
6310 }
6311 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6312 /* Note, the kref_put returns 1 when decrementing a reference
6313 * count that was 1, it invokes the release callback function,
6314 * but it still left the reference count as 1 (not actually
6315 * performs the last decrementation). Otherwise, it actually
6316 * decrements the reference count and returns 0.
6317 */
6318 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04006319}
James Smart98c9ea52007-10-27 13:37:33 -04006320
6321/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006322 * by any other discovery thread. This routine returns 1 if the
6323 * ndlp has been freed. A return value of 0 indicates the ndlp is
6324 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006325 */
6326int
6327lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6328{
6329 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6330 "node not used: did:x%x flg:x%x refcnt:x%x",
6331 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006332 kref_read(&ndlp->kref));
6333 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006334 if (lpfc_nlp_put(ndlp))
6335 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006336 return 0;
6337}
James Smart6fb120a2009-05-22 14:52:59 -04006338
6339/**
6340 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6341 * @phba: Pointer to hba context object.
6342 *
6343 * This function iterate through all FC nodes associated
6344 * will all vports to check if there is any node with
6345 * fc_rports associated with it. If there is an fc_rport
6346 * associated with the node, then the node is either in
6347 * discovered state or its devloss_timer is pending.
6348 */
6349static int
6350lpfc_fcf_inuse(struct lpfc_hba *phba)
6351{
6352 struct lpfc_vport **vports;
6353 int i, ret = 0;
6354 struct lpfc_nodelist *ndlp;
6355 struct Scsi_Host *shost;
6356
6357 vports = lpfc_create_vport_work_array(phba);
6358
James Smart63e801c2010-11-20 23:14:19 -05006359 /* If driver cannot allocate memory, indicate fcf is in use */
6360 if (!vports)
6361 return 1;
6362
James Smart6fb120a2009-05-22 14:52:59 -04006363 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6364 shost = lpfc_shost_from_vport(vports[i]);
6365 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006366 /*
6367 * IF the CVL_RCVD bit is not set then we have sent the
6368 * flogi.
6369 * If dev_loss fires while we are waiting we do not want to
6370 * unreg the fcf.
6371 */
6372 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6373 spin_unlock_irq(shost->host_lock);
6374 ret = 1;
6375 goto out;
6376 }
James Smart6fb120a2009-05-22 14:52:59 -04006377 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6378 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6379 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6380 ret = 1;
6381 spin_unlock_irq(shost->host_lock);
6382 goto out;
James Smart80c17842012-03-01 22:35:45 -05006383 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6384 ret = 1;
James Smart891478a2009-11-18 15:40:23 -05006385 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart80c17842012-03-01 22:35:45 -05006386 "2624 RPI %x DID %x flag %x "
6387 "still logged in\n",
6388 ndlp->nlp_rpi, ndlp->nlp_DID,
6389 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006390 }
6391 }
6392 spin_unlock_irq(shost->host_lock);
6393 }
6394out:
6395 lpfc_destroy_vport_work_array(phba, vports);
6396 return ret;
6397}
6398
6399/**
6400 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6401 * @phba: Pointer to hba context object.
6402 * @mboxq: Pointer to mailbox object.
6403 *
6404 * This function frees memory associated with the mailbox command.
6405 */
James Smart1b511972011-12-13 13:23:09 -05006406void
James Smart6fb120a2009-05-22 14:52:59 -04006407lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6408{
6409 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006411
6412 if (mboxq->u.mb.mbxStatus) {
6413 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6414 "2555 UNREG_VFI mbxStatus error x%x "
6415 "HBA state x%x\n",
6416 mboxq->u.mb.mbxStatus, vport->port_state);
6417 }
James Smart38b92ef2010-08-04 16:11:39 -04006418 spin_lock_irq(shost->host_lock);
6419 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6420 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006421 mempool_free(mboxq, phba->mbox_mem_pool);
6422 return;
6423}
6424
6425/**
6426 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6427 * @phba: Pointer to hba context object.
6428 * @mboxq: Pointer to mailbox object.
6429 *
6430 * This function frees memory associated with the mailbox command.
6431 */
6432static void
6433lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6434{
6435 struct lpfc_vport *vport = mboxq->vport;
6436
6437 if (mboxq->u.mb.mbxStatus) {
6438 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6439 "2550 UNREG_FCFI mbxStatus error x%x "
6440 "HBA state x%x\n",
6441 mboxq->u.mb.mbxStatus, vport->port_state);
6442 }
6443 mempool_free(mboxq, phba->mbox_mem_pool);
6444 return;
6445}
6446
6447/**
James Smartecfd03c2010-02-12 14:41:27 -05006448 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006449 * @phba: Pointer to hba context object.
6450 *
James Smartecfd03c2010-02-12 14:41:27 -05006451 * This function prepare the HBA for unregistering the currently registered
6452 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6453 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006454 */
James Smartecfd03c2010-02-12 14:41:27 -05006455int
6456lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006457{
James Smart6fb120a2009-05-22 14:52:59 -04006458 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006459 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006460 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006461 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006462
James Smartecfd03c2010-02-12 14:41:27 -05006463 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006464 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006465 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006466
James Smart4d9ab992009-10-02 15:16:39 -04006467 /* At this point, all discovery is aborted */
6468 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006469
6470 /* Unregister VPIs */
6471 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006472 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006473 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006474 /* Stop FLOGI/FDISC retries */
6475 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6476 if (ndlp)
6477 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006478 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006479 if (phba->sli_rev == LPFC_SLI_REV4)
6480 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006481 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006482 shost = lpfc_shost_from_vport(vports[i]);
6483 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006484 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006485 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006486 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006487 }
6488 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006489 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6490 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6491 if (ndlp)
6492 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6493 lpfc_cleanup_pending_mbox(phba->pport);
6494 if (phba->sli_rev == LPFC_SLI_REV4)
6495 lpfc_sli4_unreg_all_rpis(phba->pport);
6496 lpfc_mbx_unreg_vpi(phba->pport);
6497 shost = lpfc_shost_from_vport(phba->pport);
6498 spin_lock_irq(shost->host_lock);
6499 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6500 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6501 spin_unlock_irq(shost->host_lock);
6502 }
James Smart6fb120a2009-05-22 14:52:59 -04006503
James Smart695a8142010-01-26 23:08:03 -05006504 /* Cleanup any outstanding ELS commands */
6505 lpfc_els_flush_all_cmd(phba);
6506
James Smart1b511972011-12-13 13:23:09 -05006507 /* Unregister the physical port VFI */
6508 rc = lpfc_issue_unreg_vfi(phba->pport);
6509 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006510}
6511
6512/**
6513 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6514 * @phba: Pointer to hba context object.
6515 *
6516 * This function issues synchronous unregister FCF mailbox command to HBA to
6517 * unregister the currently registered FCF record. The driver does not reset
6518 * the driver FCF usage state flags.
6519 *
6520 * Return 0 if successfully issued, none-zero otherwise.
6521 */
6522int
6523lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6524{
6525 LPFC_MBOXQ_t *mbox;
6526 int rc;
6527
James Smart6fb120a2009-05-22 14:52:59 -04006528 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6529 if (!mbox) {
6530 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006531 "2551 UNREG_FCFI mbox allocation failed"
6532 "HBA state x%x\n", phba->pport->port_state);
6533 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006534 }
James Smart6fb120a2009-05-22 14:52:59 -04006535 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6536 mbox->vport = phba->pport;
6537 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6538 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6539
6540 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006541 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6542 "2552 Unregister FCFI command failed rc x%x "
6543 "HBA state x%x\n",
6544 rc, phba->pport->port_state);
6545 return -EINVAL;
6546 }
6547 return 0;
6548}
6549
6550/**
6551 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6552 * @phba: Pointer to hba context object.
6553 *
6554 * This function unregisters the currently reigstered FCF. This function
6555 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6556 */
6557void
6558lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6559{
6560 int rc;
6561
6562 /* Preparation for unregistering fcf */
6563 rc = lpfc_unregister_fcf_prep(phba);
6564 if (rc) {
6565 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6566 "2748 Failed to prepare for unregistering "
6567 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006568 return;
6569 }
6570
James Smartecfd03c2010-02-12 14:41:27 -05006571 /* Now, unregister FCF record and reset HBA FCF state */
6572 rc = lpfc_sli4_unregister_fcf(phba);
6573 if (rc)
6574 return;
6575 /* Reset HBA FCF states after successful unregister FCF */
6576 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006577 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006578
6579 /*
6580 * If driver is not unloading, check if there is any other
6581 * FCF record that can be used for discovery.
6582 */
6583 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006584 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006585 return;
6586
James Smart0c9ab6f2010-02-26 14:15:57 -05006587 /* This is considered as the initial FCF discovery scan */
6588 spin_lock_irq(&phba->hbalock);
6589 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6590 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006591
6592 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006593 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006594
James Smart0c9ab6f2010-02-26 14:15:57 -05006595 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006596
James Smart0c9ab6f2010-02-26 14:15:57 -05006597 if (rc) {
6598 spin_lock_irq(&phba->hbalock);
6599 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6600 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006601 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006602 "2553 lpfc_unregister_unused_fcf failed "
6603 "to read FCF record HBA state x%x\n",
6604 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006605 }
James Smartecfd03c2010-02-12 14:41:27 -05006606}
6607
6608/**
6609 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6610 * @phba: Pointer to hba context object.
6611 *
6612 * This function just unregisters the currently reigstered FCF. It does not
6613 * try to find another FCF for discovery.
6614 */
6615void
6616lpfc_unregister_fcf(struct lpfc_hba *phba)
6617{
6618 int rc;
6619
6620 /* Preparation for unregistering fcf */
6621 rc = lpfc_unregister_fcf_prep(phba);
6622 if (rc) {
6623 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6624 "2749 Failed to prepare for unregistering "
6625 "HBA's FCF record: rc=%d\n", rc);
6626 return;
6627 }
6628
6629 /* Now, unregister FCF record and reset HBA FCF state */
6630 rc = lpfc_sli4_unregister_fcf(phba);
6631 if (rc)
6632 return;
6633 /* Set proper HBA FCF states after successful unregister FCF */
6634 spin_lock_irq(&phba->hbalock);
6635 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6636 spin_unlock_irq(&phba->hbalock);
6637}
6638
6639/**
6640 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6641 * @phba: Pointer to hba context object.
6642 *
6643 * This function check if there are any connected remote port for the FCF and
6644 * if all the devices are disconnected, this function unregister FCFI.
6645 * This function also tries to use another FCF for discovery.
6646 */
6647void
6648lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6649{
6650 /*
James Smart3804dc82010-07-14 15:31:37 -04006651 * If HBA is not running in FIP mode, if HBA does not support
6652 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6653 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006654 */
6655 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006656 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006657 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006658 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006659 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006660 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006661 spin_unlock_irq(&phba->hbalock);
6662 return;
6663 }
6664 spin_unlock_irq(&phba->hbalock);
6665
6666 if (lpfc_fcf_inuse(phba))
6667 return;
6668
6669 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006670}
6671
6672/**
6673 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6674 * @phba: Pointer to hba context object.
6675 * @buff: Buffer containing the FCF connection table as in the config
6676 * region.
6677 * This function create driver data structure for the FCF connection
6678 * record table read from config region 23.
6679 */
6680static void
6681lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6682 uint8_t *buff)
6683{
6684 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6685 struct lpfc_fcf_conn_hdr *conn_hdr;
6686 struct lpfc_fcf_conn_rec *conn_rec;
6687 uint32_t record_count;
6688 int i;
6689
6690 /* Free the current connect table */
6691 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006692 &phba->fcf_conn_rec_list, list) {
6693 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006694 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006695 }
James Smart6fb120a2009-05-22 14:52:59 -04006696
6697 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6698 record_count = conn_hdr->length * sizeof(uint32_t)/
6699 sizeof(struct lpfc_fcf_conn_rec);
6700
6701 conn_rec = (struct lpfc_fcf_conn_rec *)
6702 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6703
6704 for (i = 0; i < record_count; i++) {
6705 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6706 continue;
6707 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6708 GFP_KERNEL);
6709 if (!conn_entry) {
6710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6711 "2566 Failed to allocate connection"
6712 " table entry\n");
6713 return;
6714 }
6715
6716 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6717 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006718 list_add_tail(&conn_entry->list,
6719 &phba->fcf_conn_rec_list);
6720 }
James Smartdf0d0852013-05-31 17:05:08 -04006721
6722 if (!list_empty(&phba->fcf_conn_rec_list)) {
6723 i = 0;
6724 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6725 list) {
6726 conn_rec = &conn_entry->conn_rec;
6727 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6728 "3345 FCF connection list rec[%02d]: "
6729 "flags:x%04x, vtag:x%04x, "
6730 "fabric_name:x%02x:%02x:%02x:%02x:"
6731 "%02x:%02x:%02x:%02x, "
6732 "switch_name:x%02x:%02x:%02x:%02x:"
6733 "%02x:%02x:%02x:%02x\n", i++,
6734 conn_rec->flags, conn_rec->vlan_tag,
6735 conn_rec->fabric_name[0],
6736 conn_rec->fabric_name[1],
6737 conn_rec->fabric_name[2],
6738 conn_rec->fabric_name[3],
6739 conn_rec->fabric_name[4],
6740 conn_rec->fabric_name[5],
6741 conn_rec->fabric_name[6],
6742 conn_rec->fabric_name[7],
6743 conn_rec->switch_name[0],
6744 conn_rec->switch_name[1],
6745 conn_rec->switch_name[2],
6746 conn_rec->switch_name[3],
6747 conn_rec->switch_name[4],
6748 conn_rec->switch_name[5],
6749 conn_rec->switch_name[6],
6750 conn_rec->switch_name[7]);
6751 }
6752 }
James Smart6fb120a2009-05-22 14:52:59 -04006753}
6754
6755/**
6756 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6757 * @phba: Pointer to hba context object.
6758 * @buff: Buffer containing the FCoE parameter data structure.
6759 *
6760 * This function update driver data structure with config
6761 * parameters read from config region 23.
6762 */
6763static void
6764lpfc_read_fcoe_param(struct lpfc_hba *phba,
6765 uint8_t *buff)
6766{
6767 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6768 struct lpfc_fcoe_params *fcoe_param;
6769
6770 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6771 buff;
6772 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006773 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006774
6775 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6776 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6777 return;
6778
James Smart6fb120a2009-05-22 14:52:59 -04006779 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6780 phba->valid_vlan = 1;
6781 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6782 0xFFF;
6783 }
6784
6785 phba->fc_map[0] = fcoe_param->fc_map[0];
6786 phba->fc_map[1] = fcoe_param->fc_map[1];
6787 phba->fc_map[2] = fcoe_param->fc_map[2];
6788 return;
6789}
6790
6791/**
6792 * lpfc_get_rec_conf23 - Get a record type in config region data.
6793 * @buff: Buffer containing config region 23 data.
6794 * @size: Size of the data buffer.
6795 * @rec_type: Record type to be searched.
6796 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006797 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006798 * of the record specified by record_type. If record found, this
6799 * function return pointer to the record else return NULL.
6800 */
6801static uint8_t *
6802lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6803{
6804 uint32_t offset = 0, rec_length;
6805
6806 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6807 (size < sizeof(uint32_t)))
6808 return NULL;
6809
6810 rec_length = buff[offset + 1];
6811
6812 /*
6813 * One TLV record has one word header and number of data words
6814 * specified in the rec_length field of the record header.
6815 */
6816 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6817 <= size) {
6818 if (buff[offset] == rec_type)
6819 return &buff[offset];
6820
6821 if (buff[offset] == LPFC_REGION23_LAST_REC)
6822 return NULL;
6823
6824 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6825 rec_length = buff[offset + 1];
6826 }
6827 return NULL;
6828}
6829
6830/**
6831 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6832 * @phba: Pointer to lpfc_hba data structure.
6833 * @buff: Buffer containing config region 23 data.
6834 * @size: Size of the data buffer.
6835 *
Stefan Weileef35c22010-08-06 21:11:15 +02006836 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006837 * populate driver data structure with the parameters.
6838 */
6839void
6840lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6841 uint8_t *buff,
6842 uint32_t size)
6843{
James Smarteb016562014-09-03 12:58:06 -04006844 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006845 uint8_t *rec_ptr;
6846
6847 /*
6848 * If data size is less than 2 words signature and version cannot be
6849 * verified.
6850 */
6851 if (size < 2*sizeof(uint32_t))
6852 return;
6853
6854 /* Check the region signature first */
6855 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6856 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6857 "2567 Config region 23 has bad signature\n");
6858 return;
6859 }
6860
6861 offset += 4;
6862
6863 /* Check the data structure version */
6864 if (buff[offset] != LPFC_REGION23_VERSION) {
6865 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6866 "2568 Config region 23 has bad version\n");
6867 return;
6868 }
6869 offset += 4;
6870
James Smart6fb120a2009-05-22 14:52:59 -04006871 /* Read FCoE param record */
6872 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6873 size - offset, FCOE_PARAM_TYPE);
6874 if (rec_ptr)
6875 lpfc_read_fcoe_param(phba, rec_ptr);
6876
6877 /* Read FCF connection table */
6878 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6879 size - offset, FCOE_CONN_TBL_TYPE);
6880 if (rec_ptr)
6881 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6882
6883}