blob: 8857f559e6c32673c1ca28f7418ec2d46627383d [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 Smart128bdda2018-01-30 15:59:03 -08004 * Copyright (C) 2017-2018 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 & FCP_XRI_ABORT_EVENT)
642 lpfc_sli4_fcp_xri_abort_event_proc(phba);
643 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
644 lpfc_sli4_els_xri_abort_event_proc(phba);
645 if (phba->hba_flag & ASYNC_EVENT)
646 lpfc_sli4_async_event_proc(phba);
647 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
648 spin_lock_irq(&phba->hbalock);
649 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
650 spin_unlock_irq(&phba->hbalock);
651 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
652 }
James Smartecfd03c2010-02-12 14:41:27 -0500653 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
654 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400655 }
656
James Smart549e55c2007-08-02 11:09:51 -0400657 vports = lpfc_create_vport_work_array(phba);
658 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400659 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400660 /*
661 * We could have no vports in array if unloading, so if
662 * this happens then just use the pport
663 */
664 if (vports[i] == NULL && i == 0)
665 vport = phba->pport;
666 else
667 vport = vports[i];
668 if (vport == NULL)
669 break;
James Smart58da1ff2008-04-07 10:15:56 -0400670 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400671 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400672 vport->work_port_events &= ~work_port_events;
673 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400674 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400675 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400676 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400677 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400678 if (work_port_events & WORKER_HB_TMO)
679 lpfc_hb_timeout_handler(phba);
680 if (work_port_events & WORKER_MBOX_TMO)
681 lpfc_mbox_timeout_handler(phba);
682 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
683 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400684 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
685 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500686 if (work_port_events & WORKER_DELAYED_DISC_TMO)
687 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500688 }
James Smart09372822008-01-11 01:52:54 -0500689 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500690
James Smart895427b2017-02-12 13:52:30 -0800691 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500692 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
693 status >>= (4*LPFC_ELS_RING);
James Smart0c9c6a72017-05-15 15:20:39 -0700694 if (pring && (status & HA_RXMASK ||
695 pring->flag & LPFC_DEFERRED_RING_EVENT ||
696 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400697 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500698 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart161df4f02018-01-30 15:58:54 -0800699 /* Preserve legacy behavior. */
700 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
701 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500702 } else {
James Smartae9e28f2017-05-15 15:20:51 -0700703 if (phba->link_state >= LPFC_LINK_UP ||
704 phba->link_flag & LS_MDS_LOOPBACK) {
James Smart94661502013-03-01 16:37:29 -0500705 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
706 lpfc_sli_handle_slow_ring_event(phba, pring,
707 (status &
708 HA_RXMASK));
709 }
James Smart858c9f62007-06-17 19:56:39 -0500710 }
James Smartdc19e3b2018-05-24 21:08:57 -0700711 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart2a9bf3d2010-06-07 15:24:45 -0400712 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500713 /*
714 * Turn on Ring interrupts
715 */
James Smart3772a992009-05-22 14:50:54 -0400716 if (phba->sli_rev <= LPFC_SLI_REV3) {
717 spin_lock_irq(&phba->hbalock);
718 control = readl(phba->HCregaddr);
719 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
720 lpfc_debugfs_slow_ring_trc(phba,
721 "WRK Enable ring: cntl:x%x hacopy:x%x",
722 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400723
James Smart3772a992009-05-22 14:50:54 -0400724 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
725 writel(control, phba->HCregaddr);
726 readl(phba->HCregaddr); /* flush */
727 } else {
728 lpfc_debugfs_slow_ring_trc(phba,
729 "WRK Ring ok: cntl:x%x hacopy:x%x",
730 control, ha_copy, 0);
731 }
732 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500733 }
734 }
James Smart2e0fef82007-06-17 19:56:36 -0500735 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500736}
737
dea31012005-04-17 16:05:31 -0500738int
739lpfc_do_work(void *p)
740{
741 struct lpfc_hba *phba = p;
742 int rc;
dea31012005-04-17 16:05:31 -0500743
Dongsheng Yang8698a742014-03-11 18:09:12 +0800744 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400745 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400746 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500747
James Smart3a55b532008-12-04 22:38:54 -0500748 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400749 /* wait and check worker queue activities */
750 rc = wait_event_interruptible(phba->work_waitq,
751 (test_and_clear_bit(LPFC_DATA_READY,
752 &phba->data_flags)
753 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500754 /* Signal wakeup shall terminate the worker thread */
755 if (rc) {
756 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
757 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500758 break;
James Smart3a55b532008-12-04 22:38:54 -0500759 }
dea31012005-04-17 16:05:31 -0500760
James Smart5e9d9b82008-06-14 22:52:53 -0400761 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500762 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500763 }
James Smart3a55b532008-12-04 22:38:54 -0500764 phba->worker_thread = NULL;
765 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
766 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500767 return 0;
768}
769
770/*
771 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300772 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500773 * embedding it in the IOCB.
774 */
775int
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500777 uint32_t evt)
778{
779 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500780 unsigned long flags;
dea31012005-04-17 16:05:31 -0500781
782 /*
783 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
784 * be queued to worker thread for processing
785 */
James Smart92d7f7b2007-06-17 19:56:38 -0500786 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500787 if (!evtp)
788 return 0;
789
790 evtp->evt_arg1 = arg1;
791 evtp->evt_arg2 = arg2;
792 evtp->evt = evt;
793
James Smarted957682007-06-17 19:56:37 -0500794 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400795 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500796 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500797
James Smart5e9d9b82008-06-14 22:52:53 -0400798 lpfc_worker_wake_up(phba);
799
dea31012005-04-17 16:05:31 -0500800 return 1;
801}
802
James Smart92d7f7b2007-06-17 19:56:38 -0500803void
804lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
805{
James Smart09372822008-01-11 01:52:54 -0500806 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500807 struct lpfc_hba *phba = vport->phba;
808 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500809
810 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500811 if (!NLP_CHK_NODE_ACT(ndlp))
812 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500813 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
814 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400815 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
816 ((vport->port_type == LPFC_NPIV_PORT) &&
817 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500818 lpfc_unreg_rpi(vport, ndlp);
819
820 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400821 if ((phba->sli_rev < LPFC_SLI_REV4) &&
822 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500823 continue;
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -0400824 lpfc_disc_state_machine(vport, ndlp, NULL,
825 remove
826 ? NLP_EVT_DEVICE_RM
827 : NLP_EVT_DEVICE_RECOVERY);
James Smart92d7f7b2007-06-17 19:56:38 -0500828 }
829 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400830 if (phba->sli_rev == LPFC_SLI_REV4)
831 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500832 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500833 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500834 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500835 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500836 }
837}
838
James Smart87af33f2007-10-27 13:37:43 -0400839void
James Smart98c9ea52007-10-27 13:37:33 -0400840lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500841{
James Smart695a8142010-01-26 23:08:03 -0500842 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
843
James Smart45ed1192009-10-02 15:17:02 -0400844 /* Cleanup any outstanding received buffers */
845 lpfc_cleanup_rcv_buffers(vport);
846
James Smart92d7f7b2007-06-17 19:56:38 -0500847 /* Cleanup any outstanding RSCN activity */
848 lpfc_els_flush_rscn(vport);
849
850 /* Cleanup any outstanding ELS commands */
851 lpfc_els_flush_cmd(vport);
852
853 lpfc_cleanup_rpis(vport, 0);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* Turn off discovery timer if its running */
856 lpfc_can_disctmo(vport);
857}
858
James Smart3772a992009-05-22 14:50:54 -0400859void
James Smart98c9ea52007-10-27 13:37:33 -0400860lpfc_linkdown_port(struct lpfc_vport *vport)
861{
James Smarta0f2d3e2017-02-12 13:52:31 -0800862 struct lpfc_hba *phba = vport->phba;
James Smart98c9ea52007-10-27 13:37:33 -0400863 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
864
James Smarta0f2d3e2017-02-12 13:52:31 -0800865 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
866 fc_host_post_event(shost, fc_get_event_number(),
867 FCH_EVT_LINKDOWN, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400868
869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
870 "Link Down: state:x%x rtry:x%x flg:x%x",
871 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
872
873 lpfc_port_link_failure(vport);
874
James Smart92494142011-02-16 12:39:44 -0500875 /* Stop delayed Nport discovery */
876 spin_lock_irq(shost->host_lock);
877 vport->fc_flag &= ~FC_DISC_DELAYED;
878 spin_unlock_irq(shost->host_lock);
879 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400880}
881
dea31012005-04-17 16:05:31 -0500882int
James Smart685f0bf2007-04-25 09:53:08 -0400883lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500884{
James Smart2e0fef82007-06-17 19:56:36 -0500885 struct lpfc_vport *vport = phba->pport;
886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400887 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400888 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400889 int i;
dea31012005-04-17 16:05:31 -0500890
James Smart3163f722008-02-08 18:50:25 -0500891 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500892 return 0;
James Smartaacc20e2009-12-21 17:02:51 -0500893
894 /* Block all SCSI stack I/Os */
895 lpfc_scsi_dev_block(phba);
896
James Smart0a9e9682018-11-29 16:09:36 -0800897 phba->defer_flogi_acc_flag = false;
898
James Smart2e0fef82007-06-17 19:56:36 -0500899 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500900 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500901 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500902 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500903 phba->link_state = LPFC_LINK_DOWN;
James Smart72100cc2010-02-12 14:43:01 -0500904 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500905 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500906 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500907 }
James Smart549e55c2007-08-02 11:09:51 -0400908 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800909 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400910 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400911 /* Issue a LINK DOWN event to all nodes */
912 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800913
914 vports[i]->fc_myDID = 0;
915
James Smart01649562017-02-12 13:52:32 -0800916 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -0800917 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800918 if (phba->nvmet_support)
919 lpfc_nvmet_update_targetport(phba);
920 else
James Smart8c258642017-02-12 13:52:36 -0800921 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800922 }
James Smart549e55c2007-08-02 11:09:51 -0400923 }
James Smart895427b2017-02-12 13:52:30 -0800924 }
James Smart09372822008-01-11 01:52:54 -0500925 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500926 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500927 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
928 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400929 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500930 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500931 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400932 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500933 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500934 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500935 }
936 }
937
dea31012005-04-17 16:05:31 -0500938 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500939 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500940 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
941 if (mb) {
dea31012005-04-17 16:05:31 -0500942 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500943 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500944 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400945 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500946 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500947 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500948 }
949 }
James Smart2e0fef82007-06-17 19:56:36 -0500950 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500951 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smartd496b9a2018-10-23 13:41:08 -0700952 phba->pport->rcv_flogi_cnt = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500953 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500954 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500955 return 0;
dea31012005-04-17 16:05:31 -0500956}
957
James Smart92d7f7b2007-06-17 19:56:38 -0500958static void
959lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500960{
James Smart92d7f7b2007-06-17 19:56:38 -0500961 struct lpfc_nodelist *ndlp;
962
963 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarta3da8252018-03-05 12:04:06 -0800964 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
James Smarte47c9092008-02-08 18:49:26 -0500965 if (!NLP_CHK_NODE_ACT(ndlp))
966 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500967 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
968 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500969 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500970 /* On Linkup its safe to clean up the ndlp
971 * from Fabric connections.
972 */
James Smart92d7f7b2007-06-17 19:56:38 -0500973 if (ndlp->nlp_DID != Fabric_DID)
974 lpfc_unreg_rpi(vport, ndlp);
975 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
976 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500977 /* Fail outstanding IO now since device is
978 * marked for PLOGI.
979 */
James Smart92d7f7b2007-06-17 19:56:38 -0500980 lpfc_unreg_rpi(vport, ndlp);
981 }
982 }
983}
984
985static void
986lpfc_linkup_port(struct lpfc_vport *vport)
987{
988 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500989 struct lpfc_hba *phba = vport->phba;
990
991 if ((vport->load_flag & FC_UNLOADING) != 0)
992 return;
993
James Smart858c9f62007-06-17 19:56:39 -0500994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
995 "Link Up: top:x%x speed:x%x flg:x%x",
996 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
997
James Smart92d7f7b2007-06-17 19:56:38 -0500998 /* If NPIV is not enabled, only bring the physical port up */
999 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1000 (vport != phba->pport))
1001 return;
dea31012005-04-17 16:05:31 -05001002
James Smarta0f2d3e2017-02-12 13:52:31 -08001003 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1004 fc_host_post_event(shost, fc_get_event_number(),
1005 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001006
James Smart2e0fef82007-06-17 19:56:36 -05001007 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001008 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1009 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1010 vport->fc_flag |= FC_NDISC_ACTIVE;
1011 vport->fc_ns_retry = 0;
1012 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001013
James Smart92d7f7b2007-06-17 19:56:38 -05001014 if (vport->fc_flag & FC_LBIT)
1015 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001016
James Smart92d7f7b2007-06-17 19:56:38 -05001017}
1018
1019static int
1020lpfc_linkup(struct lpfc_hba *phba)
1021{
James Smart549e55c2007-08-02 11:09:51 -04001022 struct lpfc_vport **vports;
1023 int i;
James Smartd496b9a2018-10-23 13:41:08 -07001024 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
James Smart92d7f7b2007-06-17 19:56:38 -05001025
1026 phba->link_state = LPFC_LINK_UP;
1027
1028 /* Unblock fabric iocbs if they are blocked */
1029 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1030 del_timer_sync(&phba->fabric_block_timer);
1031
James Smart549e55c2007-08-02 11:09:51 -04001032 vports = lpfc_create_vport_work_array(phba);
1033 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001034 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001035 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001036 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001037
James Smartd496b9a2018-10-23 13:41:08 -07001038 /* Clear the pport flogi counter in case the link down was
1039 * absorbed without an ACQE. No lock here - in worker thread
1040 * and discovery is synchronized.
1041 */
1042 spin_lock_irq(shost->host_lock);
1043 phba->pport->rcv_flogi_cnt = 0;
1044 spin_unlock_irq(shost->host_lock);
James Smart0a9e9682018-11-29 16:09:36 -08001045
1046 /* reinitialize initial FLOGI flag */
1047 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1048 phba->defer_flogi_acc_flag = false;
1049
dea31012005-04-17 16:05:31 -05001050 return 0;
1051}
1052
1053/*
1054 * This routine handles processing a CLEAR_LA mailbox
1055 * command upon completion. It is setup in the LPFC_MBOXQ
1056 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001057 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001058 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001059static void
James Smart2e0fef82007-06-17 19:56:36 -05001060lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001061{
James Smart2e0fef82007-06-17 19:56:36 -05001062 struct lpfc_vport *vport = pmb->vport;
1063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1064 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001065 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001066 uint32_t control;
1067
dea31012005-04-17 16:05:31 -05001068 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001069 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1070 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001071
1072 /* Check for error */
1073 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001074 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001075 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1076 "0320 CLEAR_LA mbxStatus error x%x hba "
1077 "state x%x\n",
1078 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001079 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001080 goto out;
1081 }
1082
James Smart92d7f7b2007-06-17 19:56:38 -05001083 if (vport->port_type == LPFC_PHYSICAL_PORT)
1084 phba->link_state = LPFC_HBA_READY;
1085
1086 spin_lock_irq(&phba->hbalock);
1087 psli->sli_flag |= LPFC_PROCESS_LA;
1088 control = readl(phba->HCregaddr);
1089 control |= HC_LAINT_ENA;
1090 writel(control, phba->HCregaddr);
1091 readl(phba->HCregaddr); /* flush */
1092 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001093 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001094 return;
dea31012005-04-17 16:05:31 -05001095
dea31012005-04-17 16:05:31 -05001096out:
1097 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001098 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1099 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001100 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001101
James Smart2e0fef82007-06-17 19:56:36 -05001102 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001103 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001104 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001105
James Smart2e0fef82007-06-17 19:56:36 -05001106 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001107
1108 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001109
1110 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001111 psli->sli_flag |= LPFC_PROCESS_LA;
1112 control = readl(phba->HCregaddr);
1113 control |= HC_LAINT_ENA;
1114 writel(control, phba->HCregaddr);
1115 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001116 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001117
1118 return;
1119}
1120
James Smart2e0fef82007-06-17 19:56:36 -05001121
James Smartd6de08c2015-12-16 18:11:53 -05001122void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001123lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001124{
James Smart2e0fef82007-06-17 19:56:36 -05001125 struct lpfc_vport *vport = pmb->vport;
James Smart44fd7fe2017-08-23 16:55:47 -07001126 uint8_t bbscn = 0;
dea31012005-04-17 16:05:31 -05001127
James Smart04c68492009-05-22 14:52:52 -04001128 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001129 goto out;
dea31012005-04-17 16:05:31 -05001130
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001131 mempool_free(pmb, phba->mbox_mem_pool);
1132
James Smart1b511972011-12-13 13:23:09 -05001133 /* don't perform discovery for SLI4 loopback diagnostic test */
1134 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1135 !(phba->hba_flag & HBA_FCOE_MODE) &&
1136 (phba->link_flag & LS_LOOPBACK_MODE))
1137 return;
1138
James Smart76a95d72010-11-20 23:11:48 -05001139 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001140 vport->fc_flag & FC_PUBLIC_LOOP &&
1141 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001142 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001143 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001144 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1145 */
James Smart2e0fef82007-06-17 19:56:36 -05001146 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001147 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001148 }
dea31012005-04-17 16:05:31 -05001149
James Smart2e0fef82007-06-17 19:56:36 -05001150 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001151 * LPFC_FLOGI while waiting for FLOGI cmpl
1152 */
James Smart44fd7fe2017-08-23 16:55:47 -07001153 if (vport->port_state != LPFC_FLOGI) {
1154 if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
1155 bbscn = bf_get(lpfc_bbscn_def,
1156 &phba->sli4_hba.bbscn_params);
1157 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
1158 vport->fc_sparam.cmn.bbRcvSizeMsb |= (bbscn << 4);
1159 }
James Smart92d7f7b2007-06-17 19:56:38 -05001160 lpfc_initial_flogi(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001161 } else if (vport->fc_flag & FC_PT2PT) {
James Smartd6de08c2015-12-16 18:11:53 -05001162 lpfc_disc_start(vport);
James Smart44fd7fe2017-08-23 16:55:47 -07001163 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001164 return;
dea31012005-04-17 16:05:31 -05001165
1166out:
James Smarte8b62012007-08-02 11:10:09 -04001167 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1168 "0306 CONFIG_LINK mbxStatus error x%x "
1169 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001170 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001171 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001172
1173 lpfc_linkdown(phba);
1174
James Smarte8b62012007-08-02 11:10:09 -04001175 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1176 "0200 CONFIG_LINK bad hba state x%x\n",
1177 vport->port_state);
dea31012005-04-17 16:05:31 -05001178
James Smart92d7f7b2007-06-17 19:56:38 -05001179 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001180 return;
1181}
1182
James Smart7d791df2011-07-22 18:37:52 -04001183/**
1184 * lpfc_sli4_clear_fcf_rr_bmask
1185 * @phba pointer to the struct lpfc_hba for this port.
1186 * This fucnction resets the round robin bit mask and clears the
1187 * fcf priority list. The list deletions are done while holding the
1188 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1189 * from the lpfc_fcf_pri record.
1190 **/
1191void
1192lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1193{
1194 struct lpfc_fcf_pri *fcf_pri;
1195 struct lpfc_fcf_pri *next_fcf_pri;
1196 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1197 spin_lock_irq(&phba->hbalock);
1198 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1199 &phba->fcf.fcf_pri_list, list) {
1200 list_del_init(&fcf_pri->list);
1201 fcf_pri->fcf_rec.flag = 0;
1202 }
1203 spin_unlock_irq(&phba->hbalock);
1204}
dea31012005-04-17 16:05:31 -05001205static void
James Smart6fb120a2009-05-22 14:52:59 -04001206lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1207{
1208 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001209
1210 if (mboxq->u.mb.mbxStatus) {
1211 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1212 "2017 REG_FCFI mbxStatus error x%x "
1213 "HBA state x%x\n",
1214 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001215 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001216 }
1217
1218 /* Start FCoE discovery by sending a FLOGI. */
1219 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1220 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001221 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001222 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001223 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001224
James Smart32b97932009-07-19 10:01:21 -04001225 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001226 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1227 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001228 goto fail_out;
1229
1230 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001231 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001232 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001233 phba->hba_flag &= ~FCF_TS_INPROG;
1234 if (vport->port_state != LPFC_FLOGI) {
1235 phba->hba_flag |= FCF_RR_INPROG;
1236 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001237 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001238 goto out;
1239 }
1240 spin_unlock_irq(&phba->hbalock);
1241 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001242
James Smarta93ff372010-10-22 11:06:08 -04001243fail_out:
1244 spin_lock_irq(&phba->hbalock);
1245 phba->hba_flag &= ~FCF_RR_INPROG;
1246 spin_unlock_irq(&phba->hbalock);
1247out:
James Smart6fb120a2009-05-22 14:52:59 -04001248 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001249}
1250
1251/**
1252 * lpfc_fab_name_match - Check if the fcf fabric name match.
1253 * @fab_name: pointer to fabric name.
1254 * @new_fcf_record: pointer to fcf record.
1255 *
1256 * This routine compare the fcf record's fabric name with provided
1257 * fabric name. If the fabric name are identical this function
1258 * returns 1 else return 0.
1259 **/
1260static uint32_t
1261lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1262{
James Smartecfd03c2010-02-12 14:41:27 -05001263 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001264 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001265 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1266 return 0;
1267 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1268 return 0;
1269 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1270 return 0;
1271 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1272 return 0;
1273 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1274 return 0;
1275 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1276 return 0;
1277 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1278 return 0;
1279 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001280}
1281
1282/**
James Smart8fa38512009-07-19 10:01:03 -04001283 * lpfc_sw_name_match - Check if the fcf switch name match.
1284 * @fab_name: pointer to fabric name.
1285 * @new_fcf_record: pointer to fcf record.
1286 *
1287 * This routine compare the fcf record's switch name with provided
1288 * switch name. If the switch name are identical this function
1289 * returns 1 else return 0.
1290 **/
1291static uint32_t
1292lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1293{
James Smartecfd03c2010-02-12 14:41:27 -05001294 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001295 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001296 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1297 return 0;
1298 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1299 return 0;
1300 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1301 return 0;
1302 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1303 return 0;
1304 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1305 return 0;
1306 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1307 return 0;
1308 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1309 return 0;
1310 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001311}
1312
1313/**
James Smart6fb120a2009-05-22 14:52:59 -04001314 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001315 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001316 * @new_fcf_record: pointer to fcf record.
1317 *
1318 * This routine compare the fcf record's mac address with HBA's
1319 * FCF mac address. If the mac addresses are identical this function
1320 * returns 1 else return 0.
1321 **/
1322static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001323lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001324{
James Smartecfd03c2010-02-12 14:41:27 -05001325 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001326 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001327 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1328 return 0;
1329 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1330 return 0;
1331 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1332 return 0;
1333 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1334 return 0;
1335 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1336 return 0;
1337 return 1;
1338}
1339
1340static bool
1341lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1342{
1343 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001344}
1345
1346/**
James Smart7d791df2011-07-22 18:37:52 -04001347 * lpfc_update_fcf_record - Update driver fcf record
1348 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1349 * @phba: pointer to lpfc hba data structure.
1350 * @fcf_index: Index for the lpfc_fcf_record.
1351 * @new_fcf_record: pointer to hba fcf record.
1352 *
1353 * This routine updates the driver FCF priority record from the new HBA FCF
1354 * record. This routine is called with the host lock held.
1355 **/
1356static void
1357__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1358 struct fcf_record *new_fcf_record
1359 )
1360{
1361 struct lpfc_fcf_pri *fcf_pri;
1362
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001363 lockdep_assert_held(&phba->hbalock);
1364
James Smart7d791df2011-07-22 18:37:52 -04001365 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1366 fcf_pri->fcf_rec.fcf_index = fcf_index;
1367 /* FCF record priority */
1368 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1369
1370}
1371
1372/**
James Smart6fb120a2009-05-22 14:52:59 -04001373 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001374 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001375 * @new_fcf_record: pointer to fcf record.
1376 *
1377 * This routine copies the FCF information from the FCF
1378 * record to lpfc_hba data structure.
1379 **/
1380static void
James Smartecfd03c2010-02-12 14:41:27 -05001381lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1382 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001383{
James Smartecfd03c2010-02-12 14:41:27 -05001384 /* Fabric name */
1385 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001386 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001387 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001388 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001389 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001390 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001391 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001392 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001393 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001394 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001395 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001396 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001397 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001398 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001399 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001400 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001401 /* Mac address */
1402 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1403 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1404 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1405 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1406 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1407 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1408 /* FCF record index */
1409 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1410 /* FCF record priority */
1411 fcf_rec->priority = new_fcf_record->fip_priority;
1412 /* Switch name */
1413 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001414 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001415 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001416 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001417 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001418 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001419 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001420 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001421 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001422 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001423 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001424 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001425 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001426 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001427 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001428 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001429}
1430
1431/**
James Smartecfd03c2010-02-12 14:41:27 -05001432 * lpfc_update_fcf_record - Update driver fcf record
1433 * @phba: pointer to lpfc hba data structure.
1434 * @fcf_rec: pointer to driver fcf record.
1435 * @new_fcf_record: pointer to hba fcf record.
1436 * @addr_mode: address mode to be set to the driver fcf record.
1437 * @vlan_id: vlan tag to be set to the driver fcf record.
1438 * @flag: flag bits to be set to the driver fcf record.
1439 *
1440 * This routine updates the driver FCF record from the new HBA FCF record
1441 * together with the address mode, vlan_id, and other informations. This
1442 * routine is called with the host lock held.
1443 **/
1444static void
1445__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1446 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1447 uint16_t vlan_id, uint32_t flag)
1448{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001449 lockdep_assert_held(&phba->hbalock);
1450
James Smartecfd03c2010-02-12 14:41:27 -05001451 /* Copy the fields from the HBA's FCF record */
1452 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1453 /* Update other fields of driver FCF record */
1454 fcf_rec->addr_mode = addr_mode;
1455 fcf_rec->vlan_id = vlan_id;
1456 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001457 __lpfc_update_fcf_record_pri(phba,
1458 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1459 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001460}
1461
1462/**
James Smart6fb120a2009-05-22 14:52:59 -04001463 * lpfc_register_fcf - Register the FCF with hba.
1464 * @phba: pointer to lpfc hba data structure.
1465 *
1466 * This routine issues a register fcfi mailbox command to register
1467 * the fcf with HBA.
1468 **/
1469static void
1470lpfc_register_fcf(struct lpfc_hba *phba)
1471{
1472 LPFC_MBOXQ_t *fcf_mbxq;
1473 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001474
James Smartd439d282010-09-29 11:18:45 -04001475 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001476 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001477 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001478 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001479 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001480 return;
1481 }
1482
1483 /* The FCF is already registered, start discovery */
1484 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001485 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001486 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001487 if (phba->pport->port_state != LPFC_FLOGI &&
1488 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001489 phba->hba_flag |= FCF_RR_INPROG;
1490 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001491 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001492 return;
1493 }
1494 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001495 return;
1496 }
James Smartd439d282010-09-29 11:18:45 -04001497 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001498
James Smarta93ff372010-10-22 11:06:08 -04001499 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001500 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001501 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001502 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001503 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001504 return;
James Smart4d9ab992009-10-02 15:16:39 -04001505 }
James Smart6fb120a2009-05-22 14:52:59 -04001506
1507 lpfc_reg_fcfi(phba, fcf_mbxq);
1508 fcf_mbxq->vport = phba->pport;
1509 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1510 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001511 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001512 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001513 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001514 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001515 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001516 }
James Smart6fb120a2009-05-22 14:52:59 -04001517
1518 return;
1519}
1520
1521/**
1522 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1523 * @phba: pointer to lpfc hba data structure.
1524 * @new_fcf_record: pointer to fcf record.
1525 * @boot_flag: Indicates if this record used by boot bios.
1526 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001527 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001528 *
1529 * This routine compare the fcf record with connect list obtained from the
1530 * config region to decide if this FCF can be used for SAN discovery. It returns
1531 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1532 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1533 * is used by boot bios and addr_mode will indicate the addressing mode to be
1534 * used for this FCF when the function returns.
1535 * If the FCF record need to be used with a particular vlan id, the vlan is
1536 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001537 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001538 **/
1539static int
1540lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1541 struct fcf_record *new_fcf_record,
1542 uint32_t *boot_flag, uint32_t *addr_mode,
1543 uint16_t *vlan_id)
1544{
1545 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001546 int i, j, fcf_vlan_id = 0;
1547
1548 /* Find the lowest VLAN id in the FCF record */
1549 for (i = 0; i < 512; i++) {
1550 if (new_fcf_record->vlan_bitmap[i]) {
1551 fcf_vlan_id = i * 8;
1552 j = 0;
1553 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1554 j++;
1555 fcf_vlan_id++;
1556 }
1557 break;
1558 }
1559 }
James Smart6fb120a2009-05-22 14:52:59 -04001560
James Smart26979ce2012-09-29 11:31:55 -04001561 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001562 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001563 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1564 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001565 return 0;
1566
James Smart45ed1192009-10-02 15:17:02 -04001567 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001568 *boot_flag = 0;
1569 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1570 new_fcf_record);
1571 if (phba->valid_vlan)
1572 *vlan_id = phba->vlan_id;
1573 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001574 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001575 return 1;
1576 }
1577
1578 /*
1579 * If there are no FCF connection table entry, driver connect to all
1580 * FCFs.
1581 */
1582 if (list_empty(&phba->fcf_conn_rec_list)) {
1583 *boot_flag = 0;
1584 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1585 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001586
1587 /*
1588 * When there are no FCF connect entries, use driver's default
1589 * addressing mode - FPMA.
1590 */
1591 if (*addr_mode & LPFC_FCF_FPMA)
1592 *addr_mode = LPFC_FCF_FPMA;
1593
James Smart4d9ab992009-10-02 15:16:39 -04001594 /* If FCF record report a vlan id use that vlan id */
1595 if (fcf_vlan_id)
1596 *vlan_id = fcf_vlan_id;
1597 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001598 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001599 return 1;
1600 }
1601
James Smartecfd03c2010-02-12 14:41:27 -05001602 list_for_each_entry(conn_entry,
1603 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001604 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1605 continue;
1606
1607 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1608 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001609 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001610 continue;
James Smart8fa38512009-07-19 10:01:03 -04001611 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1612 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1613 new_fcf_record))
1614 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001615 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1616 /*
1617 * If the vlan bit map does not have the bit set for the
1618 * vlan id to be used, then it is not a match.
1619 */
1620 if (!(new_fcf_record->vlan_bitmap
1621 [conn_entry->conn_rec.vlan_tag / 8] &
1622 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1623 continue;
1624 }
1625
1626 /*
James Smart0c287582009-06-10 17:22:56 -04001627 * If connection record does not support any addressing mode,
1628 * skip the FCF record.
1629 */
1630 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1631 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1632 continue;
1633
1634 /*
James Smart6fb120a2009-05-22 14:52:59 -04001635 * Check if the connection record specifies a required
1636 * addressing mode.
1637 */
1638 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1639 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1640
1641 /*
1642 * If SPMA required but FCF not support this continue.
1643 */
1644 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1645 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1646 new_fcf_record) & LPFC_FCF_SPMA))
1647 continue;
1648
1649 /*
1650 * If FPMA 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_FPMA))
1655 continue;
1656 }
1657
1658 /*
1659 * This fcf record matches filtering criteria.
1660 */
1661 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1662 *boot_flag = 1;
1663 else
1664 *boot_flag = 0;
1665
James Smart0c287582009-06-10 17:22:56 -04001666 /*
1667 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001668 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001669 * by FCF, allow fabric to pick the addressing mode.
1670 */
James Smart6fb120a2009-05-22 14:52:59 -04001671 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1672 new_fcf_record);
1673 /*
1674 * If the user specified a required address mode, assign that
1675 * address mode
1676 */
1677 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1678 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1679 *addr_mode = (conn_entry->conn_rec.flags &
1680 FCFCNCT_AM_SPMA) ?
1681 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1682 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001683 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001684 * addr mode only if FCF support the addr_mode.
1685 */
1686 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1687 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1688 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1689 (*addr_mode & LPFC_FCF_SPMA))
1690 *addr_mode = LPFC_FCF_SPMA;
1691 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1692 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1693 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1694 (*addr_mode & LPFC_FCF_FPMA))
1695 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001696
James Smart4d9ab992009-10-02 15:16:39 -04001697 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001698 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1699 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001700 /*
1701 * If no vlan id is specified in connect list, use the vlan id
1702 * in the FCF record
1703 */
1704 else if (fcf_vlan_id)
1705 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001706 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001707 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001708
1709 return 1;
1710 }
1711
1712 return 0;
1713}
1714
1715/**
James Smart32b97932009-07-19 10:01:21 -04001716 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1717 * @phba: pointer to lpfc hba data structure.
1718 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1719 *
1720 * This function check if there is any fcoe event pending while driver
1721 * scan FCF entries. If there is any pending event, it will restart the
1722 * FCF saning and return 1 else return 0.
1723 */
1724int
1725lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1726{
James Smart32b97932009-07-19 10:01:21 -04001727 /*
1728 * If the Link is up and no FCoE events while in the
1729 * FCF discovery, no need to restart FCF discovery.
1730 */
1731 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001732 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001733 return 0;
1734
James Smart0c9ab6f2010-02-26 14:15:57 -05001735 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1736 "2768 Pending link or FCF event during current "
1737 "handling of the previous event: link_state:x%x, "
1738 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1739 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1740 phba->fcoe_eventtag);
1741
James Smart32b97932009-07-19 10:01:21 -04001742 spin_lock_irq(&phba->hbalock);
1743 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1744 spin_unlock_irq(&phba->hbalock);
1745
James Smart0c9ab6f2010-02-26 14:15:57 -05001746 if (phba->link_state >= LPFC_LINK_UP) {
1747 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1748 "2780 Restart FCF table scan due to "
1749 "pending FCF event:evt_tag_at_scan:x%x, "
1750 "evt_tag_current:x%x\n",
1751 phba->fcoe_eventtag_at_fcf_scan,
1752 phba->fcoe_eventtag);
1753 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1754 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001755 /*
James Smarta93ff372010-10-22 11:06:08 -04001756 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001757 * flag
1758 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001759 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1760 "2833 Stop FCF discovery process due to link "
1761 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001762 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001763 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001764 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001765 spin_unlock_irq(&phba->hbalock);
1766 }
James Smart32b97932009-07-19 10:01:21 -04001767
James Smart0c9ab6f2010-02-26 14:15:57 -05001768 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001769 if (unreg_fcf) {
1770 spin_lock_irq(&phba->hbalock);
1771 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1772 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001773 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001774 }
James Smart32b97932009-07-19 10:01:21 -04001775 return 1;
1776}
1777
1778/**
James Smart999d8132010-03-15 11:24:56 -04001779 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1780 * @phba: pointer to lpfc hba data structure.
1781 * @fcf_cnt: number of eligible fcf record seen so far.
1782 *
1783 * This function makes an running random selection decision on FCF record to
1784 * use through a sequence of @fcf_cnt eligible FCF records with equal
1785 * probability. To perform integer manunipulation of random numbers with
1786 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001787 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001788 *
1789 * Returns true when outcome is for the newly read FCF record should be
1790 * chosen; otherwise, return false when outcome is for keeping the previously
1791 * chosen FCF record.
1792 **/
1793static bool
1794lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1795{
1796 uint32_t rand_num;
1797
1798 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001799 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001800
1801 /* Decision with probability 1/fcf_cnt */
1802 if ((fcf_cnt * rand_num) < 0xFFFF)
1803 return true;
1804 else
1805 return false;
1806}
1807
1808/**
James Smart3804dc82010-07-14 15:31:37 -04001809 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001810 * @phba: pointer to lpfc hba data structure.
1811 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001812 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001813 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001814 * This routine parses the non-embedded fcf mailbox command by performing the
1815 * necessarily error checking, non-embedded read FCF record mailbox command
1816 * SGE parsing, and endianness swapping.
1817 *
1818 * Returns the pointer to the new FCF record in the non-embedded mailbox
1819 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001820 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001821static struct fcf_record *
1822lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1823 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001824{
1825 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001826 struct lpfc_mbx_sge sge;
1827 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001828 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001829 union lpfc_sli4_cfg_shdr *shdr;
1830 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001831
James Smart6fb120a2009-05-22 14:52:59 -04001832 /* Get the first SGE entry from the non-embedded DMA memory. This
1833 * routine only uses a single SGE.
1834 */
1835 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001836 if (unlikely(!mboxq->sge_array)) {
1837 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1838 "2524 Failed to get the non-embedded SGE "
1839 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001840 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001841 }
1842 virt_addr = mboxq->sge_array->addr[0];
1843
1844 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001845 lpfc_sli_pcimem_bcopy(shdr, shdr,
1846 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001847 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001848 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001849 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001850 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001851 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1852 if_type == LPFC_SLI_INTF_IF_TYPE_2)
James Smart0c9ab6f2010-02-26 14:15:57 -05001853 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001854 "2726 READ_FCF_RECORD Indicates empty "
1855 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001856 else
1857 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001858 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001859 "with status x%x add_status x%x, "
1860 "mbx\n", shdr_status, shdr_add_status);
1861 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001862 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001863
1864 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001865 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1866 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1867 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001868 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001869 new_fcf_record = (struct fcf_record *)(virt_addr +
1870 sizeof(struct lpfc_mbx_read_fcf_tbl));
1871 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001872 offsetof(struct fcf_record, vlan_bitmap));
1873 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1874 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001875
James Smart0c9ab6f2010-02-26 14:15:57 -05001876 return new_fcf_record;
1877}
1878
1879/**
1880 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1881 * @phba: pointer to lpfc hba data structure.
1882 * @fcf_record: pointer to the fcf record.
1883 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1884 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1885 *
1886 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1887 * enabled.
1888 **/
1889static void
1890lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1891 struct fcf_record *fcf_record,
1892 uint16_t vlan_id,
1893 uint16_t next_fcf_index)
1894{
1895 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1896 "2764 READ_FCF_RECORD:\n"
1897 "\tFCF_Index : x%x\n"
1898 "\tFCF_Avail : x%x\n"
1899 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001900 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001901 "\tFIP_Priority : x%x\n"
1902 "\tMAC_Provider : x%x\n"
1903 "\tLowest VLANID : x%x\n"
1904 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1905 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1906 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1907 "\tNext_FCF_Index: x%x\n",
1908 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1909 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1910 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001911 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001912 fcf_record->fip_priority,
1913 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1914 vlan_id,
1915 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1916 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1917 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1918 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1919 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1920 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1921 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1922 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1923 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1924 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1925 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1926 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1927 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1928 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1929 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1930 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1931 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1932 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1933 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1934 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1935 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1936 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1937 next_fcf_index);
1938}
1939
1940/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001941 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1942 * @phba: pointer to lpfc hba data structure.
1943 * @fcf_rec: pointer to an existing FCF record.
1944 * @new_fcf_record: pointer to a new FCF record.
1945 * @new_vlan_id: vlan id from the new FCF record.
1946 *
1947 * This function performs matching test of a new FCF record against an existing
1948 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1949 * will not be used as part of the FCF record matching criteria.
1950 *
1951 * Returns true if all the fields matching, otherwise returns false.
1952 */
1953static bool
1954lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1955 struct lpfc_fcf_rec *fcf_rec,
1956 struct fcf_record *new_fcf_record,
1957 uint16_t new_vlan_id)
1958{
1959 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1960 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1961 return false;
1962 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1963 return false;
1964 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1965 return false;
1966 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1967 return false;
James Smart7d791df2011-07-22 18:37:52 -04001968 if (fcf_rec->priority != new_fcf_record->fip_priority)
1969 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001970 return true;
1971}
1972
1973/**
James Smarta93ff372010-10-22 11:06:08 -04001974 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1975 * @vport: Pointer to vport object.
1976 * @fcf_index: index to next fcf.
1977 *
1978 * This function processing the roundrobin fcf failover to next fcf index.
1979 * When this function is invoked, there will be a current fcf registered
1980 * for flogi.
1981 * Return: 0 for continue retrying flogi on currently registered fcf;
1982 * 1 for stop flogi on currently registered fcf;
1983 */
1984int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1985{
1986 struct lpfc_hba *phba = vport->phba;
1987 int rc;
1988
1989 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1990 spin_lock_irq(&phba->hbalock);
1991 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1992 spin_unlock_irq(&phba->hbalock);
1993 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1994 "2872 Devloss tmo with no eligible "
1995 "FCF, unregister in-use FCF (x%x) "
1996 "and rescan FCF table\n",
1997 phba->fcf.current_rec.fcf_indx);
1998 lpfc_unregister_fcf_rescan(phba);
1999 goto stop_flogi_current_fcf;
2000 }
2001 /* Mark the end to FLOGI roundrobin failover */
2002 phba->hba_flag &= ~FCF_RR_INPROG;
2003 /* Allow action to new fcf asynchronous event */
2004 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2005 spin_unlock_irq(&phba->hbalock);
2006 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2007 "2865 No FCF available, stop roundrobin FCF "
2008 "failover and change port state:x%x/x%x\n",
2009 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2010 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart036cad12018-10-23 13:41:06 -07002011
2012 if (!phba->fcf.fcf_redisc_attempted) {
2013 lpfc_unregister_fcf(phba);
2014
2015 rc = lpfc_sli4_redisc_fcf_table(phba);
2016 if (!rc) {
2017 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2018 "3195 Rediscover FCF table\n");
2019 phba->fcf.fcf_redisc_attempted = 1;
2020 lpfc_sli4_clear_fcf_rr_bmask(phba);
2021 } else {
2022 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2023 "3196 Rediscover FCF table "
2024 "failed. Status:x%x\n", rc);
2025 }
2026 } else {
2027 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2028 "3197 Already rediscover FCF table "
2029 "attempted. No more retry\n");
2030 }
James Smarta93ff372010-10-22 11:06:08 -04002031 goto stop_flogi_current_fcf;
2032 } else {
2033 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2034 "2794 Try FLOGI roundrobin FCF failover to "
2035 "(x%x)\n", fcf_index);
2036 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2037 if (rc)
2038 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2039 "2761 FLOGI roundrobin FCF failover "
2040 "failed (rc:x%x) to read FCF (x%x)\n",
2041 rc, phba->fcf.current_rec.fcf_indx);
2042 else
2043 goto stop_flogi_current_fcf;
2044 }
2045 return 0;
2046
2047stop_flogi_current_fcf:
2048 lpfc_can_disctmo(vport);
2049 return 1;
2050}
2051
2052/**
James Smart7d791df2011-07-22 18:37:52 -04002053 * lpfc_sli4_fcf_pri_list_del
2054 * @phba: pointer to lpfc hba data structure.
2055 * @fcf_index the index of the fcf record to delete
2056 * This routine checks the on list flag of the fcf_index to be deleted.
2057 * If it is one the list then it is removed from the list, and the flag
2058 * is cleared. This routine grab the hbalock before removing the fcf
2059 * record from the list.
2060 **/
2061static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2062 uint16_t fcf_index)
2063{
2064 struct lpfc_fcf_pri *new_fcf_pri;
2065
2066 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2067 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2068 "3058 deleting idx x%x pri x%x flg x%x\n",
2069 fcf_index, new_fcf_pri->fcf_rec.priority,
2070 new_fcf_pri->fcf_rec.flag);
2071 spin_lock_irq(&phba->hbalock);
2072 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2073 if (phba->fcf.current_rec.priority ==
2074 new_fcf_pri->fcf_rec.priority)
2075 phba->fcf.eligible_fcf_cnt--;
2076 list_del_init(&new_fcf_pri->list);
2077 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2078 }
2079 spin_unlock_irq(&phba->hbalock);
2080}
2081
2082/**
2083 * lpfc_sli4_set_fcf_flogi_fail
2084 * @phba: pointer to lpfc hba data structure.
2085 * @fcf_index the index of the fcf record to update
2086 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2087 * flag so the the round robin slection for the particular priority level
2088 * will try a different fcf record that does not have this bit set.
2089 * If the fcf record is re-read for any reason this flag is cleared brfore
2090 * adding it to the priority list.
2091 **/
2092void
2093lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2094{
2095 struct lpfc_fcf_pri *new_fcf_pri;
2096 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2097 spin_lock_irq(&phba->hbalock);
2098 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2099 spin_unlock_irq(&phba->hbalock);
2100}
2101
2102/**
2103 * lpfc_sli4_fcf_pri_list_add
2104 * @phba: pointer to lpfc hba data structure.
2105 * @fcf_index the index of the fcf record to add
2106 * This routine checks the priority of the fcf_index to be added.
2107 * If it is a lower priority than the current head of the fcf_pri list
2108 * then it is added to the list in the right order.
2109 * If it is the same priority as the current head of the list then it
2110 * is added to the head of the list and its bit in the rr_bmask is set.
2111 * If the fcf_index to be added is of a higher priority than the current
2112 * head of the list then the rr_bmask is cleared, its bit is set in the
2113 * rr_bmask and it is added to the head of the list.
2114 * returns:
2115 * 0=success 1=failure
2116 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002117static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2118 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002119 struct fcf_record *new_fcf_record)
2120{
2121 uint16_t current_fcf_pri;
2122 uint16_t last_index;
2123 struct lpfc_fcf_pri *fcf_pri;
2124 struct lpfc_fcf_pri *next_fcf_pri;
2125 struct lpfc_fcf_pri *new_fcf_pri;
2126 int ret;
2127
2128 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2129 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2130 "3059 adding idx x%x pri x%x flg x%x\n",
2131 fcf_index, new_fcf_record->fip_priority,
2132 new_fcf_pri->fcf_rec.flag);
2133 spin_lock_irq(&phba->hbalock);
2134 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2135 list_del_init(&new_fcf_pri->list);
2136 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2137 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2138 if (list_empty(&phba->fcf.fcf_pri_list)) {
2139 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2140 ret = lpfc_sli4_fcf_rr_index_set(phba,
2141 new_fcf_pri->fcf_rec.fcf_index);
2142 goto out;
2143 }
2144
2145 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2146 LPFC_SLI4_FCF_TBL_INDX_MAX);
2147 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2148 ret = 0; /* Empty rr list */
2149 goto out;
2150 }
2151 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2152 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2153 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2154 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2155 memset(phba->fcf.fcf_rr_bmask, 0,
2156 sizeof(*phba->fcf.fcf_rr_bmask));
2157 /* fcfs_at_this_priority_level = 1; */
2158 phba->fcf.eligible_fcf_cnt = 1;
2159 } else
2160 /* fcfs_at_this_priority_level++; */
2161 phba->fcf.eligible_fcf_cnt++;
2162 ret = lpfc_sli4_fcf_rr_index_set(phba,
2163 new_fcf_pri->fcf_rec.fcf_index);
2164 goto out;
2165 }
2166
2167 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2168 &phba->fcf.fcf_pri_list, list) {
2169 if (new_fcf_pri->fcf_rec.priority <=
2170 fcf_pri->fcf_rec.priority) {
2171 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2172 list_add(&new_fcf_pri->list,
2173 &phba->fcf.fcf_pri_list);
2174 else
2175 list_add(&new_fcf_pri->list,
2176 &((struct lpfc_fcf_pri *)
2177 fcf_pri->list.prev)->list);
2178 ret = 0;
2179 goto out;
2180 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2181 || new_fcf_pri->fcf_rec.priority <
2182 next_fcf_pri->fcf_rec.priority) {
2183 list_add(&new_fcf_pri->list, &fcf_pri->list);
2184 ret = 0;
2185 goto out;
2186 }
2187 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2188 continue;
2189
2190 }
2191 ret = 1;
2192out:
2193 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2194 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2195 spin_unlock_irq(&phba->hbalock);
2196 return ret;
2197}
2198
2199/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002200 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2201 * @phba: pointer to lpfc hba data structure.
2202 * @mboxq: pointer to mailbox object.
2203 *
2204 * This function iterates through all the fcf records available in
2205 * HBA and chooses the optimal FCF record for discovery. After finding
2206 * the FCF for discovery it registers the FCF record and kicks start
2207 * discovery.
2208 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2209 * use an FCF record which matches fabric name and mac address of the
2210 * currently used FCF record.
2211 * If the driver supports only one FCF, it will try to use the FCF record
2212 * used by BOOT_BIOS.
2213 */
2214void
2215lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2216{
2217 struct fcf_record *new_fcf_record;
2218 uint32_t boot_flag, addr_mode;
2219 uint16_t fcf_index, next_fcf_index;
2220 struct lpfc_fcf_rec *fcf_rec = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08002221 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
James Smart999d8132010-03-15 11:24:56 -04002222 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002223 int rc;
2224
2225 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002226 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002227 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2228 return;
2229 }
2230
2231 /* Parse the FCF record from the non-embedded mailbox command */
2232 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2233 &next_fcf_index);
2234 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002235 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002236 "2765 Mailbox command READ_FCF_RECORD "
2237 "failed to retrieve a FCF record.\n");
2238 /* Let next new FCF event trigger fast failover */
2239 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002240 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002241 spin_unlock_irq(&phba->hbalock);
2242 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2243 return;
2244 }
2245
2246 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002247 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2248 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002249
2250 /* Log the FCF record information if turned on */
2251 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2252 next_fcf_index);
2253
James Smart6fb120a2009-05-22 14:52:59 -04002254 /*
2255 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002256 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002257 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002258 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002259 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002260 lpfc_sli4_fcf_pri_list_del(phba,
2261 bf_get(lpfc_fcf_record_fcf_index,
2262 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002263 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002264 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002265 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002266 bf_get(lpfc_fcf_record_fcf_index,
2267 new_fcf_record),
2268 bf_get(lpfc_fcf_record_fcf_avail,
2269 new_fcf_record),
2270 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002271 new_fcf_record),
2272 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002273 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002274 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2275 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2276 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002277 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2278 phba->fcf.current_rec.fcf_indx) {
2279 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2280 "2862 FCF (x%x) matches property "
2281 "of in-use FCF (x%x)\n",
2282 bf_get(lpfc_fcf_record_fcf_index,
2283 new_fcf_record),
2284 phba->fcf.current_rec.fcf_indx);
2285 goto read_next_fcf;
2286 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002287 /*
2288 * In case the current in-use FCF record becomes
2289 * invalid/unavailable during FCF discovery that
2290 * was not triggered by fast FCF failover process,
2291 * treat it as fast FCF failover.
2292 */
2293 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2294 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2295 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2296 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002297 "(x%x), enter FCF failover "
2298 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002299 phba->fcf.current_rec.fcf_indx);
2300 spin_lock_irq(&phba->hbalock);
2301 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2302 spin_unlock_irq(&phba->hbalock);
2303 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2304 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2305 LPFC_FCOE_FCF_GET_FIRST);
2306 return;
2307 }
2308 }
James Smart6fb120a2009-05-22 14:52:59 -04002309 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002310 } else {
2311 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002312 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2313 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002314 if (rc)
2315 goto read_next_fcf;
2316 }
2317
James Smart6fb120a2009-05-22 14:52:59 -04002318 /*
2319 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002320 * FCF record for the discovery. The condition that a rescan
2321 * matches the in-use FCF record: fabric name, switch name, mac
2322 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002323 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002324 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002325 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002326 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2327 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002328 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002329 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2330 phba->fcf.current_rec.fcf_indx) {
2331 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2332 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2333 /* Stop FCF redisc wait timer */
2334 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2335 phba);
2336 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2337 /* Fast failover, mark completed */
2338 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2339 spin_unlock_irq(&phba->hbalock);
2340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2341 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002342 "FCF (x%x), port_state:x%x, "
2343 "fc_flag:x%x\n",
2344 phba->fcf.current_rec.fcf_indx,
2345 phba->pport->port_state,
2346 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002347 goto out;
2348 } else
2349 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2350 "2863 New FCF (x%x) matches "
2351 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002352 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002353 new_fcf_record),
2354 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002355 }
James Smartecfd03c2010-02-12 14:41:27 -05002356 /*
2357 * Read next FCF record from HBA searching for the matching
2358 * with in-use record only if not during the fast failover
2359 * period. In case of fast failover period, it shall try to
2360 * determine whether the FCF record just read should be the
2361 * next candidate.
2362 */
2363 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002364 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002365 goto read_next_fcf;
2366 }
James Smart6fb120a2009-05-22 14:52:59 -04002367 }
James Smartecfd03c2010-02-12 14:41:27 -05002368 /*
2369 * Update on failover FCF record only if it's in FCF fast-failover
2370 * period; otherwise, update on current FCF record.
2371 */
James Smartfc2b9892010-02-26 14:15:29 -05002372 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2373 fcf_rec = &phba->fcf.failover_rec;
2374 else
James Smartecfd03c2010-02-12 14:41:27 -05002375 fcf_rec = &phba->fcf.current_rec;
2376
James Smart6fb120a2009-05-22 14:52:59 -04002377 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2378 /*
James Smartecfd03c2010-02-12 14:41:27 -05002379 * If the driver FCF record does not have boot flag
2380 * set and new hba fcf record has boot flag set, use
2381 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002382 */
James Smartecfd03c2010-02-12 14:41:27 -05002383 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2384 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002385 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2386 "2837 Update current FCF record "
2387 "(x%x) with new FCF record (x%x)\n",
2388 fcf_rec->fcf_indx,
2389 bf_get(lpfc_fcf_record_fcf_index,
2390 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002391 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2392 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002393 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002394 goto read_next_fcf;
2395 }
2396 /*
James Smartecfd03c2010-02-12 14:41:27 -05002397 * If the driver FCF record has boot flag set and the
2398 * new hba FCF record does not have boot flag, read
2399 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002400 */
James Smartecfd03c2010-02-12 14:41:27 -05002401 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002402 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002403 goto read_next_fcf;
2404 }
2405 /*
James Smartecfd03c2010-02-12 14:41:27 -05002406 * If the new hba FCF record has lower priority value
2407 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002408 */
James Smartfc2b9892010-02-26 14:15:29 -05002409 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002410 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002411 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2412 "2838 Update current FCF record "
2413 "(x%x) with new FCF record (x%x)\n",
2414 fcf_rec->fcf_indx,
2415 bf_get(lpfc_fcf_record_fcf_index,
2416 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002417 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2418 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002419 /* Reset running random FCF selection count */
2420 phba->fcf.eligible_fcf_cnt = 1;
2421 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2422 /* Update running random FCF selection count */
2423 phba->fcf.eligible_fcf_cnt++;
2424 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2425 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002426 if (select_new_fcf) {
2427 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2428 "2839 Update current FCF record "
2429 "(x%x) with new FCF record (x%x)\n",
2430 fcf_rec->fcf_indx,
2431 bf_get(lpfc_fcf_record_fcf_index,
2432 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002433 /* Choose the new FCF by random selection */
2434 __lpfc_update_fcf_record(phba, fcf_rec,
2435 new_fcf_record,
2436 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002437 }
James Smart6fb120a2009-05-22 14:52:59 -04002438 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002439 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002440 goto read_next_fcf;
2441 }
2442 /*
James Smartecfd03c2010-02-12 14:41:27 -05002443 * This is the first suitable FCF record, choose this record for
2444 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002445 */
James Smartecfd03c2010-02-12 14:41:27 -05002446 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002447 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002448 "2840 Update initial FCF candidate "
2449 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002450 bf_get(lpfc_fcf_record_fcf_index,
2451 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002452 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2453 addr_mode, vlan_id, (boot_flag ?
2454 BOOT_ENABLE : 0));
2455 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002456 /* Setup initial running random FCF selection count */
2457 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002458 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002459 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002460 goto read_next_fcf;
2461
2462read_next_fcf:
2463 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002464 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2465 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2466 /*
2467 * Case of FCF fast failover scan
2468 */
2469
2470 /*
2471 * It has not found any suitable FCF record, cancel
2472 * FCF scan inprogress, and do nothing
2473 */
2474 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002475 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002476 "2782 No suitable FCF found: "
2477 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002478 phba->fcoe_eventtag_at_fcf_scan,
2479 bf_get(lpfc_fcf_record_fcf_index,
2480 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002481 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002482 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2483 phba->hba_flag &= ~FCF_TS_INPROG;
2484 spin_unlock_irq(&phba->hbalock);
2485 /* Unregister in-use FCF and rescan */
2486 lpfc_printf_log(phba, KERN_INFO,
2487 LOG_FIP,
2488 "2864 On devloss tmo "
2489 "unreg in-use FCF and "
2490 "rescan FCF table\n");
2491 lpfc_unregister_fcf_rescan(phba);
2492 return;
2493 }
2494 /*
2495 * Let next new FCF event trigger fast failover
2496 */
2497 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002498 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002499 return;
2500 }
2501 /*
2502 * It has found a suitable FCF record that is not
2503 * the same as in-use FCF record, unregister the
2504 * in-use FCF record, replace the in-use FCF record
2505 * with the new FCF record, mark FCF fast failover
2506 * completed, and then start register the new FCF
2507 * record.
2508 */
2509
James Smart0c9ab6f2010-02-26 14:15:57 -05002510 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002511 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002512
2513 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002514 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002515 "2842 Replace in-use FCF (x%x) "
2516 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002517 phba->fcf.current_rec.fcf_indx,
2518 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002519 memcpy(&phba->fcf.current_rec,
2520 &phba->fcf.failover_rec,
2521 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002522 /*
2523 * Mark the fast FCF failover rediscovery completed
2524 * and the start of the first round of the roundrobin
2525 * FCF failover.
2526 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002527 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002528 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002529 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002530 /* Register to the new FCF record */
2531 lpfc_register_fcf(phba);
2532 } else {
2533 /*
2534 * In case of transaction period to fast FCF failover,
2535 * do nothing when search to the end of the FCF table.
2536 */
2537 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2538 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2539 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002540
James Smart7d791df2011-07-22 18:37:52 -04002541 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2542 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002543 /*
2544 * In case the current in-use FCF record no
2545 * longer existed during FCF discovery that
2546 * was not triggered by fast FCF failover
2547 * process, treat it as fast FCF failover.
2548 */
2549 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2550 "2841 In-use FCF record (x%x) "
2551 "not reported, entering fast "
2552 "FCF failover mode scanning.\n",
2553 phba->fcf.current_rec.fcf_indx);
2554 spin_lock_irq(&phba->hbalock);
2555 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2556 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002557 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2558 LPFC_FCOE_FCF_GET_FIRST);
2559 return;
2560 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002561 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002562 lpfc_register_fcf(phba);
2563 }
2564 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002565 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002566 return;
2567
2568out:
2569 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2570 lpfc_register_fcf(phba);
2571
2572 return;
2573}
2574
2575/**
James Smarta93ff372010-10-22 11:06:08 -04002576 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002577 * @phba: pointer to lpfc hba data structure.
2578 * @mboxq: pointer to mailbox object.
2579 *
James Smarta93ff372010-10-22 11:06:08 -04002580 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002581 * read FCF record mailbox command from the eligible FCF record bmask for
2582 * performing the failover. If the FCF read back is not valid/available, it
2583 * fails through to retrying FLOGI to the currently registered FCF again.
2584 * Otherwise, if the FCF read back is valid and available, it will set the
2585 * newly read FCF record to the failover FCF record, unregister currently
2586 * registered FCF record, copy the failover FCF record to the current
2587 * FCF record, and then register the current FCF record before proceeding
2588 * to trying FLOGI on the new failover FCF.
2589 */
2590void
2591lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2592{
2593 struct fcf_record *new_fcf_record;
2594 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002595 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002596 uint16_t current_fcf_index;
2597 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002598 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002599
James Smarta93ff372010-10-22 11:06:08 -04002600 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002601 if (phba->link_state < LPFC_LINK_UP) {
2602 spin_lock_irq(&phba->hbalock);
2603 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002604 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002605 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002606 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002607 }
2608
2609 /* Parse the FCF record from the non-embedded mailbox command */
2610 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2611 &next_fcf_index);
2612 if (!new_fcf_record) {
2613 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2614 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002615 "failed to retrieve a FCF record. "
2616 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2617 phba->fcf.fcf_flag);
2618 lpfc_unregister_fcf_rescan(phba);
2619 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002620 }
2621
2622 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002623 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2624 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002625
2626 /* Log the FCF record information if turned on */
2627 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2628 next_fcf_index);
2629
James Smarta93ff372010-10-22 11:06:08 -04002630 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2631 if (!rc) {
2632 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2633 "2848 Remove ineligible FCF (x%x) from "
2634 "from roundrobin bmask\n", fcf_index);
2635 /* Clear roundrobin bmask bit for ineligible FCF */
2636 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2637 /* Perform next round of roundrobin FCF failover */
2638 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2639 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2640 if (rc)
2641 goto out;
2642 goto error_out;
2643 }
2644
2645 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2646 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2647 "2760 Perform FLOGI roundrobin FCF failover: "
2648 "FCF (x%x) back to FCF (x%x)\n",
2649 phba->fcf.current_rec.fcf_indx, fcf_index);
2650 /* Wait 500 ms before retrying FLOGI to current FCF */
2651 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002652 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002653 goto out;
2654 }
2655
James Smart0c9ab6f2010-02-26 14:15:57 -05002656 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002657 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002658 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2659 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002660 spin_lock_irq(&phba->hbalock);
2661 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2662 new_fcf_record, addr_mode, vlan_id,
2663 (boot_flag ? BOOT_ENABLE : 0));
2664 spin_unlock_irq(&phba->hbalock);
2665
2666 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2667
2668 /* Unregister the current in-use FCF record */
2669 lpfc_unregister_fcf(phba);
2670
2671 /* Replace in-use record with the new record */
2672 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2673 sizeof(struct lpfc_fcf_rec));
2674
2675 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002676 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2677 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002678
James Smarta93ff372010-10-22 11:06:08 -04002679error_out:
2680 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002681out:
2682 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002683}
2684
2685/**
2686 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2687 * @phba: pointer to lpfc hba data structure.
2688 * @mboxq: pointer to mailbox object.
2689 *
2690 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002691 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002692 * failover when a new FCF event happened. If the FCF read back is
2693 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002694 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002695 */
2696void
2697lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2698{
2699 struct fcf_record *new_fcf_record;
2700 uint32_t boot_flag, addr_mode;
2701 uint16_t fcf_index, next_fcf_index;
2702 uint16_t vlan_id;
2703 int rc;
2704
2705 /* If link state is not up, no need to proceed */
2706 if (phba->link_state < LPFC_LINK_UP)
2707 goto out;
2708
2709 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002710 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002711 goto out;
2712
2713 /* Parse the FCF record from the non-embedded mailbox command */
2714 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2715 &next_fcf_index);
2716 if (!new_fcf_record) {
2717 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2718 "2767 Mailbox command READ_FCF_RECORD "
2719 "failed to retrieve a FCF record.\n");
2720 goto out;
2721 }
2722
2723 /* Check the connection list for eligibility */
2724 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2725 &addr_mode, &vlan_id);
2726
2727 /* Log the FCF record information if turned on */
2728 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2729 next_fcf_index);
2730
2731 if (!rc)
2732 goto out;
2733
2734 /* Update the eligible FCF record index bmask */
2735 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002736
2737 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002738
2739out:
2740 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2741}
2742
2743/**
James Smart76a95d72010-11-20 23:11:48 -05002744 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2745 * @phba: pointer to lpfc hba data structure.
2746 * @mboxq: pointer to mailbox data structure.
2747 *
2748 * This function handles completion of init vfi mailbox command.
2749 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002750static void
James Smart76a95d72010-11-20 23:11:48 -05002751lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2752{
2753 struct lpfc_vport *vport = mboxq->vport;
2754
James Smartdf9e1b52011-12-13 13:22:17 -05002755 /*
2756 * VFI not supported on interface type 0, just do the flogi
2757 * Also continue if the VFI is in use - just use the same one.
2758 */
2759 if (mboxq->u.mb.mbxStatus &&
2760 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2761 LPFC_SLI_INTF_IF_TYPE_0) &&
2762 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002763 lpfc_printf_vlog(vport, KERN_ERR,
2764 LOG_MBOX,
2765 "2891 Init VFI mailbox failed 0x%x\n",
2766 mboxq->u.mb.mbxStatus);
2767 mempool_free(mboxq, phba->mbox_mem_pool);
2768 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2769 return;
2770 }
James Smart73d91e52011-10-10 21:32:10 -04002771
James Smart76a95d72010-11-20 23:11:48 -05002772 lpfc_initial_flogi(vport);
2773 mempool_free(mboxq, phba->mbox_mem_pool);
2774 return;
2775}
2776
2777/**
2778 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2779 * @vport: pointer to lpfc_vport data structure.
2780 *
2781 * This function issue a init_vfi mailbox command to initialize the VFI and
2782 * VPI for the physical port.
2783 */
2784void
2785lpfc_issue_init_vfi(struct lpfc_vport *vport)
2786{
2787 LPFC_MBOXQ_t *mboxq;
2788 int rc;
2789 struct lpfc_hba *phba = vport->phba;
2790
2791 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2792 if (!mboxq) {
2793 lpfc_printf_vlog(vport, KERN_ERR,
2794 LOG_MBOX, "2892 Failed to allocate "
2795 "init_vfi mailbox\n");
2796 return;
2797 }
2798 lpfc_init_vfi(mboxq, vport);
2799 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2800 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2801 if (rc == MBX_NOT_FINISHED) {
2802 lpfc_printf_vlog(vport, KERN_ERR,
2803 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2804 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2805 }
2806}
2807
2808/**
James Smart1c6834a2009-07-19 10:01:26 -04002809 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2810 * @phba: pointer to lpfc hba data structure.
2811 * @mboxq: pointer to mailbox data structure.
2812 *
2813 * This function handles completion of init vpi mailbox command.
2814 */
James Smart695a8142010-01-26 23:08:03 -05002815void
James Smart1c6834a2009-07-19 10:01:26 -04002816lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2817{
2818 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002819 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2821
James Smart1c6834a2009-07-19 10:01:26 -04002822 if (mboxq->u.mb.mbxStatus) {
2823 lpfc_printf_vlog(vport, KERN_ERR,
2824 LOG_MBOX,
2825 "2609 Init VPI mailbox failed 0x%x\n",
2826 mboxq->u.mb.mbxStatus);
2827 mempool_free(mboxq, phba->mbox_mem_pool);
2828 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2829 return;
2830 }
James Smart72100cc2010-02-12 14:43:01 -05002831 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002832 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002833 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002834
James Smart695a8142010-01-26 23:08:03 -05002835 /* If this port is physical port or FDISC is done, do reg_vpi */
2836 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2837 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2838 if (!ndlp)
2839 lpfc_printf_vlog(vport, KERN_ERR,
2840 LOG_DISCOVERY,
2841 "2731 Cannot find fabric "
2842 "controller node\n");
2843 else
2844 lpfc_register_new_vport(phba, vport, ndlp);
2845 mempool_free(mboxq, phba->mbox_mem_pool);
2846 return;
2847 }
2848
James Smart1c6834a2009-07-19 10:01:26 -04002849 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2850 lpfc_initial_fdisc(vport);
2851 else {
2852 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002853 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2854 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002855 }
James Smart695a8142010-01-26 23:08:03 -05002856 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002857 return;
2858}
2859
2860/**
James Smartecfd03c2010-02-12 14:41:27 -05002861 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2862 * @vport: pointer to lpfc_vport data structure.
2863 *
2864 * This function issue a init_vpi mailbox command to initialize
2865 * VPI for the vport.
2866 */
2867void
2868lpfc_issue_init_vpi(struct lpfc_vport *vport)
2869{
2870 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002871 int rc, vpi;
2872
2873 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2874 vpi = lpfc_alloc_vpi(vport->phba);
2875 if (!vpi) {
2876 lpfc_printf_vlog(vport, KERN_ERR,
2877 LOG_MBOX,
2878 "3303 Failed to obtain vport vpi\n");
2879 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2880 return;
2881 }
2882 vport->vpi = vpi;
2883 }
James Smartecfd03c2010-02-12 14:41:27 -05002884
2885 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2886 if (!mboxq) {
2887 lpfc_printf_vlog(vport, KERN_ERR,
2888 LOG_MBOX, "2607 Failed to allocate "
2889 "init_vpi mailbox\n");
2890 return;
2891 }
2892 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2893 mboxq->vport = vport;
2894 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2895 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2896 if (rc == MBX_NOT_FINISHED) {
2897 lpfc_printf_vlog(vport, KERN_ERR,
2898 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2899 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2900 }
2901}
2902
2903/**
James Smart6fb120a2009-05-22 14:52:59 -04002904 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2905 * @phba: pointer to lpfc hba data structure.
2906 *
2907 * This function loops through the list of vports on the @phba and issues an
2908 * FDISC if possible.
2909 */
2910void
2911lpfc_start_fdiscs(struct lpfc_hba *phba)
2912{
2913 struct lpfc_vport **vports;
2914 int i;
2915
2916 vports = lpfc_create_vport_work_array(phba);
2917 if (vports != NULL) {
2918 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2919 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2920 continue;
2921 /* There are no vpi for this vport */
2922 if (vports[i]->vpi > phba->max_vpi) {
2923 lpfc_vport_set_state(vports[i],
2924 FC_VPORT_FAILED);
2925 continue;
2926 }
James Smart76a95d72010-11-20 23:11:48 -05002927 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002928 lpfc_vport_set_state(vports[i],
2929 FC_VPORT_LINKDOWN);
2930 continue;
2931 }
James Smart1c6834a2009-07-19 10:01:26 -04002932 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002933 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002934 continue;
2935 }
James Smart6fb120a2009-05-22 14:52:59 -04002936 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2937 lpfc_initial_fdisc(vports[i]);
2938 else {
2939 lpfc_vport_set_state(vports[i],
2940 FC_VPORT_NO_FABRIC_SUPP);
2941 lpfc_printf_vlog(vports[i], KERN_ERR,
2942 LOG_ELS,
2943 "0259 No NPIV "
2944 "Fabric support\n");
2945 }
2946 }
2947 }
2948 lpfc_destroy_vport_work_array(phba, vports);
2949}
2950
2951void
2952lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2953{
James Smart3e1f0712018-11-29 16:09:29 -08002954 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
James Smart6fb120a2009-05-22 14:52:59 -04002955 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002956 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002957
James Smartf5eca9b2012-03-01 22:37:54 -05002958 /*
2959 * VFI not supported for interface type 0, so ignore any mailbox
2960 * error (except VFI in use) and continue with the discovery.
2961 */
2962 if (mboxq->u.mb.mbxStatus &&
2963 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2964 LPFC_SLI_INTF_IF_TYPE_0) &&
2965 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002966 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2967 "2018 REG_VFI mbxStatus error x%x "
2968 "HBA state x%x\n",
2969 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002970 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002971 /* FLOGI failed, use loop map to make discovery list */
2972 lpfc_disc_list_loopmap(vport);
2973 /* Start discovery */
2974 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002975 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002976 }
2977 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002978 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002979 }
James Smartae05ebe2013-03-01 16:35:38 -05002980
James Smarte74c03c2013-04-17 20:15:19 -04002981 /* If the VFI is already registered, there is nothing else to do
2982 * Unless this was a VFI update and we are in PT2PT mode, then
2983 * we should drop through to set the port state to ready.
2984 */
James Smartae05ebe2013-03-01 16:35:38 -05002985 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04002986 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2987 vport->fc_flag & FC_PT2PT))
2988 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05002989
James Smartc8685952009-11-18 15:39:16 -05002990 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002991 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002992 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002993 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002994 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04002995 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002996 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04002997
James Smart1b511972011-12-13 13:23:09 -05002998 /* In case SLI4 FC loopback test, we are ready */
2999 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3000 (phba->link_flag & LS_LOOPBACK_MODE)) {
3001 phba->link_state = LPFC_HBA_READY;
3002 goto out_free_mem;
3003 }
3004
James Smarte74c03c2013-04-17 20:15:19 -04003005 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3006 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3007 "alpacnt:%d LinkState:%x topology:%x\n",
3008 vport->port_state, vport->fc_flag, vport->fc_myDID,
3009 vport->phba->alpa_map[0],
3010 phba->link_state, phba->fc_topology);
3011
James Smart6fb120a2009-05-22 14:52:59 -04003012 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04003013 /*
3014 * For private loop or for NPort pt2pt,
3015 * just start discovery and we are done.
3016 */
3017 if ((vport->fc_flag & FC_PT2PT) ||
3018 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3019 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3020
James Smart76a95d72010-11-20 23:11:48 -05003021 /* Use loop map to make discovery list */
3022 lpfc_disc_list_loopmap(vport);
3023 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04003024 if (vport->fc_flag & FC_PT2PT)
3025 vport->port_state = LPFC_VPORT_READY;
3026 else
3027 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05003028 } else {
3029 lpfc_start_fdiscs(phba);
3030 lpfc_do_scr_ns_plogi(phba, vport);
3031 }
James Smart6fb120a2009-05-22 14:52:59 -04003032 }
3033
James Smart1b511972011-12-13 13:23:09 -05003034out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04003035 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05003036 if (dmabuf) {
3037 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3038 kfree(dmabuf);
3039 }
James Smart6fb120a2009-05-22 14:52:59 -04003040 return;
3041}
3042
3043static void
James Smart2e0fef82007-06-17 19:56:36 -05003044lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003045{
James Smart6fb120a2009-05-22 14:52:59 -04003046 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003047 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart2e0fef82007-06-17 19:56:36 -05003048 struct lpfc_vport *vport = pmb->vport;
James Smartaeb3c812017-04-21 16:05:02 -07003049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart21bf0b92015-08-31 16:48:21 -04003050 struct serv_parm *sp = &vport->fc_sparam;
3051 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003052
3053 /* Check for error */
3054 if (mb->mbxStatus) {
3055 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003056 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3057 "0319 READ_SPARAM mbxStatus error x%x "
3058 "hba state x%x>\n",
3059 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003060 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003061 goto out;
3062 }
3063
James Smart2e0fef82007-06-17 19:56:36 -05003064 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003065 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003066
3067 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3068 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3069 ed_tov = (ed_tov + 999999) / 1000000;
3070
3071 phba->fc_edtov = ed_tov;
3072 phba->fc_ratov = (2 * ed_tov) / 1000;
3073 if (phba->fc_ratov < FF_DEF_RATOV) {
3074 /* RA_TOV should be atleast 10sec for initial flogi */
3075 phba->fc_ratov = FF_DEF_RATOV;
3076 }
3077
James Smart05580562011-05-24 11:40:48 -04003078 lpfc_update_vport_wwn(vport);
James Smartaeb3c812017-04-21 16:05:02 -07003079 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05003080 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3081 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3082 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3083 }
3084
dea31012005-04-17 16:05:31 -05003085 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3086 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003087 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003088 return;
3089
3090out:
James Smart3e1f0712018-11-29 16:09:29 -08003091 pmb->ctx_buf = NULL;
dea31012005-04-17 16:05:31 -05003092 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3093 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003094 lpfc_issue_clear_la(phba, vport);
3095 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003096 return;
3097}
3098
3099static void
James Smart76a95d72010-11-20 23:11:48 -05003100lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003101{
James Smart92d7f7b2007-06-17 19:56:38 -05003102 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003103 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003104 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003105 int i;
James Smart14691152006-12-02 13:34:28 -05003106 struct lpfc_dmabuf *mp;
3107 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003108 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003109 uint32_t fc_flags = 0;
James Smart14691152006-12-02 13:34:28 -05003110
James Smart92d7f7b2007-06-17 19:56:38 -05003111 spin_lock_irq(&phba->hbalock);
James Smarta085e872015-12-16 18:12:02 -05003112 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3113
3114 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3115 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3116 case LPFC_LINK_SPEED_1GHZ:
3117 case LPFC_LINK_SPEED_2GHZ:
3118 case LPFC_LINK_SPEED_4GHZ:
3119 case LPFC_LINK_SPEED_8GHZ:
3120 case LPFC_LINK_SPEED_10GHZ:
3121 case LPFC_LINK_SPEED_16GHZ:
3122 case LPFC_LINK_SPEED_32GHZ:
James Smartfbd8a6b2018-02-22 08:18:45 -08003123 case LPFC_LINK_SPEED_64GHZ:
James Smart1dc5ec22018-10-23 13:41:11 -07003124 case LPFC_LINK_SPEED_128GHZ:
James Smarta085e872015-12-16 18:12:02 -05003125 break;
3126 default:
3127 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3128 break;
3129 }
dea31012005-04-17 16:05:31 -05003130 }
3131
James Smarte74c03c2013-04-17 20:15:19 -04003132 if (phba->fc_topology &&
3133 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3134 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3135 "3314 Toplogy changed was 0x%x is 0x%x\n",
3136 phba->fc_topology,
3137 bf_get(lpfc_mbx_read_top_topology, la));
3138 phba->fc_topology_changed = 1;
3139 }
3140
James Smart76a95d72010-11-20 23:11:48 -05003141 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003142 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003143
James Smartdf9e1b52011-12-13 13:22:17 -05003144 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003145 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003146 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003147
James Smart6a9c52c2009-10-02 15:16:51 -04003148 /* if npiv is enabled and this adapter supports npiv log
3149 * a message that npiv is not supported in this topology
3150 */
3151 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003152 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3153 "1309 Link Up Event npiv not supported in loop "
3154 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003155 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003156 if (bf_get(lpfc_mbx_read_top_il, la))
3157 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003158
James Smart76a95d72010-11-20 23:11:48 -05003159 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3160 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003161
3162 if (i == 0) {
3163 phba->alpa_map[0] = 0;
3164 } else {
James Smarte8b62012007-08-02 11:10:09 -04003165 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003166 int numalpa, j, k;
3167 union {
3168 uint8_t pamap[16];
3169 struct {
3170 uint32_t wd1;
3171 uint32_t wd2;
3172 uint32_t wd3;
3173 uint32_t wd4;
3174 } pa;
3175 } un;
3176 numalpa = phba->alpa_map[0];
3177 j = 0;
3178 while (j < numalpa) {
3179 memset(un.pamap, 0, 16);
3180 for (k = 1; j < numalpa; k++) {
3181 un.pamap[k - 1] =
3182 phba->alpa_map[j + 1];
3183 j++;
3184 if (k == 16)
3185 break;
3186 }
3187 /* Link Up Event ALPA map */
3188 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003189 KERN_WARNING,
3190 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003191 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003192 "ALPA map Data: x%x "
3193 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003194 un.pa.wd1, un.pa.wd2,
3195 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003196 }
3197 }
3198 }
3199 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003200 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003201 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003202 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003203 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3204 }
James Smart2e0fef82007-06-17 19:56:36 -05003205 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003206 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003207 }
James Smart92d7f7b2007-06-17 19:56:38 -05003208 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003209
James Smart38c20672013-03-01 16:37:44 -05003210 if (fc_flags) {
3211 spin_lock_irq(shost->host_lock);
3212 vport->fc_flag |= fc_flags;
3213 spin_unlock_irq(shost->host_lock);
3214 }
3215
dea31012005-04-17 16:05:31 -05003216 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05003217 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3218 if (!sparam_mbox)
3219 goto out;
3220
3221 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3222 if (rc) {
3223 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3224 goto out;
3225 }
3226 sparam_mbox->vport = vport;
3227 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3228 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3229 if (rc == MBX_NOT_FINISHED) {
James Smart3e1f0712018-11-29 16:09:29 -08003230 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
James Smart9f1177a2010-02-26 14:12:57 -05003231 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3232 kfree(mp);
3233 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3234 goto out;
dea31012005-04-17 16:05:31 -05003235 }
3236
James Smart76a95d72010-11-20 23:11:48 -05003237 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04003238 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3239 if (!cfglink_mbox)
3240 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05003241 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05003242 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05003243 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05003244 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04003245 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04003246 if (rc == MBX_NOT_FINISHED) {
3247 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3248 goto out;
3249 }
3250 } else {
James Smart32b97932009-07-19 10:01:21 -04003251 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003252 /*
3253 * Add the driver's default FCF record at FCF index 0 now. This
3254 * is phase 1 implementation that support FCF index 0 and driver
3255 * defaults.
3256 */
James Smart45ed1192009-10-02 15:17:02 -04003257 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003258 fcf_record = kzalloc(sizeof(struct fcf_record),
3259 GFP_KERNEL);
3260 if (unlikely(!fcf_record)) {
3261 lpfc_printf_log(phba, KERN_ERR,
3262 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003263 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003264 "fcf record\n");
3265 rc = -ENODEV;
3266 goto out;
3267 }
3268
3269 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3270 LPFC_FCOE_FCF_DEF_INDEX);
3271 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3272 if (unlikely(rc)) {
3273 lpfc_printf_log(phba, KERN_ERR,
3274 LOG_MBOX | LOG_SLI,
3275 "2013 Could not manually add FCF "
3276 "record 0, status %d\n", rc);
3277 rc = -ENODEV;
3278 kfree(fcf_record);
3279 goto out;
3280 }
3281 kfree(fcf_record);
3282 }
3283 /*
3284 * The driver is expected to do FIP/FCF. Call the port
3285 * and get the FCF Table.
3286 */
James Smart32b97932009-07-19 10:01:21 -04003287 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003288 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart32b97932009-07-19 10:01:21 -04003289 spin_unlock_irq(&phba->hbalock);
3290 return;
3291 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003292 /* This is the initial FCF discovery scan */
3293 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04003294 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003295 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3296 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003297 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3298 LPFC_FCOE_FCF_GET_FIRST);
3299 if (rc) {
3300 spin_lock_irq(&phba->hbalock);
3301 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3302 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04003303 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003304 }
James Smart38b92ef2010-08-04 16:11:39 -04003305 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003306 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003307 }
James Smart6fb120a2009-05-22 14:52:59 -04003308
3309 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003310out:
3311 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003312 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3313 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3314 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003315 lpfc_issue_clear_la(phba, vport);
3316 return;
dea31012005-04-17 16:05:31 -05003317}
3318
3319static void
James Smart84774a42008-08-24 21:50:06 -04003320lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003321{
dea31012005-04-17 16:05:31 -05003322 uint32_t control;
3323 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003324 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003325 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003326 if (phba->sli_rev <= LPFC_SLI_REV3) {
3327 control = readl(phba->HCregaddr);
3328 control |= HC_LAINT_ENA;
3329 writel(control, phba->HCregaddr);
3330 readl(phba->HCregaddr); /* flush */
3331 }
James Smart2e0fef82007-06-17 19:56:36 -05003332 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003333}
3334
James Smart84774a42008-08-24 21:50:06 -04003335static void
3336lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3337{
3338 lpfc_linkdown(phba);
3339 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003340 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003341 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3342}
3343
3344
dea31012005-04-17 16:05:31 -05003345/*
James Smart76a95d72010-11-20 23:11:48 -05003346 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003347 * command upon completion. It is setup in the LPFC_MBOXQ
3348 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003349 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003350 */
3351void
James Smart76a95d72010-11-20 23:11:48 -05003352lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003353{
James Smart2e0fef82007-06-17 19:56:36 -05003354 struct lpfc_vport *vport = pmb->vport;
3355 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003356 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003357 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003358 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003359 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smartaeb3c812017-04-21 16:05:02 -07003360 uint8_t attn_type;
dea31012005-04-17 16:05:31 -05003361
James Smart0d2b6b82008-06-14 22:52:47 -04003362 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003363 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003364 if (pring)
3365 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart895427b2017-02-12 13:52:30 -08003366
dea31012005-04-17 16:05:31 -05003367 /* Check for error */
3368 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003369 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003370 "1307 READ_LA mbox error x%x state x%x\n",
3371 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003372 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003373 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003374 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003375 }
3376
James Smart76a95d72010-11-20 23:11:48 -05003377 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
James Smartaeb3c812017-04-21 16:05:02 -07003378 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
dea31012005-04-17 16:05:31 -05003379
3380 memcpy(&phba->alpa_map[0], mp->virt, 128);
3381
James Smart2e0fef82007-06-17 19:56:36 -05003382 spin_lock_irq(shost->host_lock);
James Smart76a95d72010-11-20 23:11:48 -05003383 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003384 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003385 else
James Smart2e0fef82007-06-17 19:56:36 -05003386 vport->fc_flag &= ~FC_BYPASSED_MODE;
3387 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003388
James Smartbe0c0082013-03-01 16:38:14 -05003389 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003390 phba->fc_stat.LinkMultiEvent++;
James Smartaeb3c812017-04-21 16:05:02 -07003391 if (attn_type == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003392 if (phba->fc_eventTag != 0)
3393 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003394 }
dea31012005-04-17 16:05:31 -05003395
3396 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003397 if (phba->sli_rev < LPFC_SLI_REV4) {
3398 spin_lock_irq(&phba->hbalock);
3399 if (bf_get(lpfc_mbx_read_top_mm, la))
3400 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3401 else
3402 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3403 spin_unlock_irq(&phba->hbalock);
3404 }
dea31012005-04-17 16:05:31 -05003405
James Smart4d9ab992009-10-02 15:16:39 -04003406 phba->link_events++;
James Smartaeb3c812017-04-21 16:05:02 -07003407 if ((attn_type == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003408 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003409 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003410 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003411 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003412 "1306 Link Up Event in loop back mode "
3413 "x%x received Data: x%x x%x x%x x%x\n",
3414 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003415 bf_get(lpfc_mbx_read_top_alpa_granted,
3416 la),
3417 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003418 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003419 } else {
3420 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003421 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003422 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003423 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003424 bf_get(lpfc_mbx_read_top_alpa_granted,
3425 la),
3426 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003427 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003428 bf_get(lpfc_mbx_read_top_mm, la),
3429 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003430 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003431 }
James Smart92d7f7b2007-06-17 19:56:38 -05003432 lpfc_mbx_process_link_up(phba, la);
James Smartaeb3c812017-04-21 16:05:02 -07003433 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3434 attn_type == LPFC_ATT_UNEXP_WWPN) {
dea31012005-04-17 16:05:31 -05003435 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003436 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003437 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3438 "1308 Link Down Event in loop back mode "
3439 "x%x received "
3440 "Data: x%x x%x x%x\n",
3441 la->eventTag, phba->fc_eventTag,
3442 phba->pport->port_state, vport->fc_flag);
James Smartaeb3c812017-04-21 16:05:02 -07003443 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3444 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3445 "1313 Link Down UNEXP WWPN Event x%x received "
3446 "Data: x%x x%x x%x x%x x%x\n",
3447 la->eventTag, phba->fc_eventTag,
3448 phba->pport->port_state, vport->fc_flag,
3449 bf_get(lpfc_mbx_read_top_mm, la),
3450 bf_get(lpfc_mbx_read_top_fa, la));
James Smart1b511972011-12-13 13:23:09 -05003451 else
James Smart3163f722008-02-08 18:50:25 -05003452 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003453 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003454 "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,
James Smart76a95d72010-11-20 23:11:48 -05003457 bf_get(lpfc_mbx_read_top_mm, la),
3458 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003459 lpfc_mbx_issue_link_down(phba);
3460 }
James Smartaeb3c812017-04-21 16:05:02 -07003461 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3462 attn_type == LPFC_ATT_LINK_UP) {
James Smart84774a42008-08-24 21:50:06 -04003463 if (phba->link_state != LPFC_LINK_DOWN) {
3464 phba->fc_stat.LinkDown++;
3465 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3466 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003467 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003468 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003469 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003470 lpfc_mbx_issue_link_down(phba);
3471 } else
3472 lpfc_enable_la(phba);
3473
3474 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3475 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3476 "Data: x%x x%x x%x\n",
3477 la->eventTag, phba->fc_eventTag,
3478 phba->pport->port_state, vport->fc_flag);
3479 /*
3480 * The cmnd that triggered this will be waiting for this
3481 * signal.
3482 */
3483 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3484 if (phba->wait_4_mlo_maint_flg) {
3485 phba->wait_4_mlo_maint_flg = 0;
3486 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003487 }
James Smart84774a42008-08-24 21:50:06 -04003488 }
3489
James Smartbe0c0082013-03-01 16:38:14 -05003490 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3491 bf_get(lpfc_mbx_read_top_fa, la)) {
3492 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003493 lpfc_issue_clear_la(phba, vport);
3494 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003495 "1311 fa %d\n",
3496 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003497 }
3498
James Smart76a95d72010-11-20 23:11:48 -05003499lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003500 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3501 kfree(mp);
3502 mempool_free(pmb, phba->mbox_mem_pool);
3503 return;
3504}
3505
3506/*
3507 * This routine handles processing a REG_LOGIN mailbox
3508 * command upon completion. It is setup in the LPFC_MBOXQ
3509 * as the completion routine when the command is
3510 * handed off to the SLI layer.
3511 */
3512void
James Smart2e0fef82007-06-17 19:56:36 -05003513lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003514{
James Smart2e0fef82007-06-17 19:56:36 -05003515 struct lpfc_vport *vport = pmb->vport;
James Smart3e1f0712018-11-29 16:09:29 -08003516 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3517 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smartffc95492010-06-07 15:23:17 -04003518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003519
James Smart3e1f0712018-11-29 16:09:29 -08003520 pmb->ctx_buf = NULL;
3521 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05003522
James Smartbe6bb942015-04-07 15:07:22 -04003523 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3524 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3525 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003526 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003527 ndlp->nlp_usg_map, ndlp);
James Smartffc95492010-06-07 15:23:17 -04003528 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3529 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3530
James Smart40426292010-12-15 17:58:10 -05003531 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3532 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003533 /* We rcvd a rscn after issuing this
3534 * mbox reg login, we may have cycled
3535 * back through the state and be
3536 * back at reg login state so this
3537 * mbox needs to be ignored becase
3538 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003539 * process.
James Smartffc95492010-06-07 15:23:17 -04003540 */
3541 spin_lock_irq(shost->host_lock);
3542 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3543 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003544
3545 /*
3546 * We cannot leave the RPI registered because
3547 * if we go thru discovery again for this ndlp
3548 * a subsequent REG_RPI will fail.
3549 */
3550 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3551 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b2015-12-16 18:11:55 -05003552 }
3553
3554 /* Call state machine */
3555 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003556
dea31012005-04-17 16:05:31 -05003557 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3558 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003559 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003560 /* decrement the node reference count held for this callback
3561 * function.
3562 */
James Smart329f9bc2007-04-25 09:53:01 -04003563 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003564
3565 return;
3566}
3567
James Smart92d7f7b2007-06-17 19:56:38 -05003568static void
3569lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3570{
James Smart04c68492009-05-22 14:52:52 -04003571 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003572 struct lpfc_vport *vport = pmb->vport;
3573 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3574
3575 switch (mb->mbxStatus) {
3576 case 0x0011:
3577 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003578 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3579 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3580 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003581 break;
James Smart78730cf2010-04-06 15:06:30 -04003582 /* If VPI is busy, reset the HBA */
3583 case 0x9700:
3584 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3585 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3586 vport->vpi, mb->mbxStatus);
3587 if (!(phba->pport->load_flag & FC_UNLOADING))
3588 lpfc_workq_post_event(phba, NULL, NULL,
3589 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003590 }
James Smart72100cc2010-02-12 14:43:01 -05003591 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003592 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003593 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003594 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003595 vport->unreg_vpi_cmpl = VPORT_OK;
3596 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003597 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003598 /*
3599 * This shost reference might have been taken at the beginning of
3600 * lpfc_vport_delete()
3601 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003602 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003603 scsi_host_put(shost);
3604}
3605
James Smartd7c255b2008-08-24 21:50:00 -04003606int
James Smart92d7f7b2007-06-17 19:56:38 -05003607lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3608{
3609 struct lpfc_hba *phba = vport->phba;
3610 LPFC_MBOXQ_t *mbox;
3611 int rc;
3612
3613 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3614 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003615 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003616
3617 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3618 mbox->vport = vport;
3619 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003620 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003621 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003622 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3623 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003624 mempool_free(mbox, phba->mbox_mem_pool);
3625 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003626 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003627 }
James Smartd7c255b2008-08-24 21:50:00 -04003628 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003629}
3630
3631static void
3632lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3633{
3634 struct lpfc_vport *vport = pmb->vport;
3635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003636 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003637
3638 switch (mb->mbxStatus) {
3639 case 0x0011:
3640 case 0x9601:
3641 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003642 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3643 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3644 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003645 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3646 spin_lock_irq(shost->host_lock);
3647 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3648 spin_unlock_irq(shost->host_lock);
3649 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003650
James Smart01649562017-02-12 13:52:32 -08003651 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -08003652 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003653 if (phba->nvmet_support)
3654 lpfc_nvmet_update_targetport(phba);
3655 else
James Smart8c258642017-02-12 13:52:36 -08003656 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003657 }
James Smart92d7f7b2007-06-17 19:56:38 -05003658 goto out;
3659 }
James Smart92d7f7b2007-06-17 19:56:38 -05003660
James Smart72100cc2010-02-12 14:43:01 -05003661 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003662 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003663 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003664 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003665 vport->num_disc_nodes = 0;
3666 /* go thru NPR list and issue ELS PLOGIs */
3667 if (vport->fc_npr_cnt)
3668 lpfc_els_disc_plogi(vport);
3669
3670 if (!vport->num_disc_nodes) {
3671 spin_lock_irq(shost->host_lock);
3672 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3673 spin_unlock_irq(shost->host_lock);
3674 lpfc_can_disctmo(vport);
3675 }
3676 vport->port_state = LPFC_VPORT_READY;
3677
3678out:
3679 mempool_free(pmb, phba->mbox_mem_pool);
3680 return;
3681}
3682
James Smart21e9a0a2009-05-22 14:53:21 -04003683/**
3684 * lpfc_create_static_vport - Read HBA config region to create static vports.
3685 * @phba: pointer to lpfc hba data structure.
3686 *
3687 * This routine issue a DUMP mailbox command for config region 22 to get
3688 * the list of static vports to be created. The function create vports
3689 * based on the information returned from the HBA.
3690 **/
3691void
3692lpfc_create_static_vport(struct lpfc_hba *phba)
3693{
3694 LPFC_MBOXQ_t *pmb = NULL;
3695 MAILBOX_t *mb;
3696 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003697 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003698 struct fc_vport_identifiers vport_id;
3699 struct fc_vport *new_fc_vport;
3700 struct Scsi_Host *shost;
3701 struct lpfc_vport *vport;
3702 uint16_t offset = 0;
3703 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003704 struct lpfc_dmabuf *mp;
3705 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003706
3707 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3708 if (!pmb) {
3709 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3710 "0542 lpfc_create_static_vport failed to"
3711 " allocate mailbox memory\n");
3712 return;
3713 }
James Smartcdcc2342012-08-14 14:26:35 -04003714 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003715 mb = &pmb->u.mb;
3716
3717 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3718 if (!vport_info) {
3719 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3720 "0543 lpfc_create_static_vport failed to"
3721 " allocate vport_info\n");
3722 mempool_free(pmb, phba->mbox_mem_pool);
3723 return;
3724 }
3725
3726 vport_buff = (uint8_t *) vport_info;
3727 do {
James Smartcdcc2342012-08-14 14:26:35 -04003728 /* free dma buffer from previous round */
James Smart3e1f0712018-11-29 16:09:29 -08003729 if (pmb->ctx_buf) {
3730 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smartcdcc2342012-08-14 14:26:35 -04003731 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3732 kfree(mp);
3733 }
James Smart1c6834a2009-07-19 10:01:26 -04003734 if (lpfc_dump_static_vport(phba, pmb, offset))
3735 goto out;
3736
James Smart21e9a0a2009-05-22 14:53:21 -04003737 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003738 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3739 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003740
James Smartcdcc2342012-08-14 14:26:35 -04003741 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003742 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3743 "0544 lpfc_create_static_vport failed to"
3744 " issue dump mailbox command ret 0x%x "
3745 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003746 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003747 goto out;
3748 }
3749
James Smart1c6834a2009-07-19 10:01:26 -04003750 if (phba->sli_rev == LPFC_SLI_REV4) {
3751 byte_count = pmb->u.mqe.un.mb_words[5];
James Smart3e1f0712018-11-29 16:09:29 -08003752 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003753 if (byte_count > sizeof(struct static_vport_info) -
3754 offset)
3755 byte_count = sizeof(struct static_vport_info)
3756 - offset;
3757 memcpy(vport_buff + offset, mp->virt, byte_count);
3758 offset += byte_count;
3759 } else {
3760 if (mb->un.varDmp.word_cnt >
3761 sizeof(struct static_vport_info) - offset)
3762 mb->un.varDmp.word_cnt =
3763 sizeof(struct static_vport_info)
3764 - offset;
3765 byte_count = mb->un.varDmp.word_cnt;
3766 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3767 vport_buff + offset,
3768 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003769
James Smart1c6834a2009-07-19 10:01:26 -04003770 offset += byte_count;
3771 }
James Smart21e9a0a2009-05-22 14:53:21 -04003772
James Smart1c6834a2009-07-19 10:01:26 -04003773 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003774 offset < sizeof(struct static_vport_info));
3775
3776
3777 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3778 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3779 != VPORT_INFO_REV)) {
3780 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3781 "0545 lpfc_create_static_vport bad"
3782 " information header 0x%x 0x%x\n",
3783 le32_to_cpu(vport_info->signature),
3784 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3785
3786 goto out;
3787 }
3788
3789 shost = lpfc_shost_from_vport(phba->pport);
3790
3791 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3792 memset(&vport_id, 0, sizeof(vport_id));
3793 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3794 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3795 if (!vport_id.port_name || !vport_id.node_name)
3796 continue;
3797
3798 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3799 vport_id.vport_type = FC_PORTTYPE_NPIV;
3800 vport_id.disable = false;
3801 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3802
3803 if (!new_fc_vport) {
3804 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3805 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003806 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003807 continue;
3808 }
3809
3810 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3811 vport->vport_flag |= STATIC_VPORT;
3812 }
3813
3814out:
James Smart21e9a0a2009-05-22 14:53:21 -04003815 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003816 if (mbx_wait_rc != MBX_TIMEOUT) {
James Smart3e1f0712018-11-29 16:09:29 -08003817 if (pmb->ctx_buf) {
3818 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
James Smart1c6834a2009-07-19 10:01:26 -04003819 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3820 kfree(mp);
3821 }
James Smart21e9a0a2009-05-22 14:53:21 -04003822 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003823 }
James Smart21e9a0a2009-05-22 14:53:21 -04003824
3825 return;
3826}
3827
dea31012005-04-17 16:05:31 -05003828/*
3829 * This routine handles processing a Fabric REG_LOGIN mailbox
3830 * command upon completion. It is setup in the LPFC_MBOXQ
3831 * as the completion routine when the command is
3832 * handed off to the SLI layer.
3833 */
3834void
James Smart2e0fef82007-06-17 19:56:36 -05003835lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003836{
James Smart92d7f7b2007-06-17 19:56:38 -05003837 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003838 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003839 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
James Smart92d7f7b2007-06-17 19:56:38 -05003840 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003841 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003842
James Smart3e1f0712018-11-29 16:09:29 -08003843 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3844 pmb->ctx_ndlp = NULL;
3845 pmb->ctx_buf = NULL;
James Smartd439d282010-09-29 11:18:45 -04003846
dea31012005-04-17 16:05:31 -05003847 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003848 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3849 "0258 Register Fabric login error: 0x%x\n",
3850 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003851 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3852 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003853 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003854
James Smart76a95d72010-11-20 23:11:48 -05003855 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003856 /* FLOGI failed, use loop map to make discovery list */
3857 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003858
James Smart92d7f7b2007-06-17 19:56:38 -05003859 /* Start discovery */
3860 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003861 /* Decrement the reference count to ndlp after the
3862 * reference to the ndlp are done.
3863 */
3864 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003865 return;
3866 }
3867
3868 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003869 /* Decrement the reference count to ndlp after the reference
3870 * to the ndlp are done.
3871 */
3872 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003873 return;
3874 }
3875
James Smart6d368e52011-05-24 11:44:12 -04003876 if (phba->sli_rev < LPFC_SLI_REV4)
3877 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003878 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003879 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003881
James Smart2e0fef82007-06-17 19:56:36 -05003882 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003883 /* when physical port receive logo donot start
3884 * vport discovery */
3885 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3886 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003887 else {
3888 shost = lpfc_shost_from_vport(vport);
3889 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003890 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003891 spin_unlock_irq(shost->host_lock);
3892 }
James Smart92d7f7b2007-06-17 19:56:38 -05003893 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003894 }
3895
3896 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3897 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003898 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003899
3900 /* Drop the reference count from the mbox at the end after
3901 * all the current reference to the ndlp have been done.
3902 */
3903 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003904 return;
3905}
3906
James Smarta0f2d3e2017-02-12 13:52:31 -08003907 /*
3908 * This routine will issue a GID_FT for each FC4 Type supported
3909 * by the driver. ALL GID_FTs must complete before discovery is started.
3910 */
3911int
3912lpfc_issue_gidft(struct lpfc_vport *vport)
3913{
3914 struct lpfc_hba *phba = vport->phba;
3915
3916 /* Good status, issue CT Request to NameServer */
3917 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3918 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
3919 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3920 /* Cannot issue NameServer FCP Query, so finish up
3921 * discovery
3922 */
3923 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3924 "0604 %s FC TYPE %x %s\n",
3925 "Failed to issue GID_FT to ",
3926 FC_TYPE_FCP,
3927 "Finishing discovery.");
3928 return 0;
3929 }
3930 vport->gidft_inp++;
3931 }
3932
3933 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3934 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3935 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3936 /* Cannot issue NameServer NVME Query, so finish up
3937 * discovery
3938 */
3939 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3940 "0605 %s FC_TYPE %x %s %d\n",
3941 "Failed to issue GID_FT to ",
3942 FC_TYPE_NVME,
3943 "Finishing discovery: gidftinp ",
3944 vport->gidft_inp);
3945 if (vport->gidft_inp == 0)
3946 return 0;
3947 } else
3948 vport->gidft_inp++;
3949 }
3950 return vport->gidft_inp;
3951}
3952
James Smart7ea92eb2018-10-23 13:41:10 -07003953/**
3954 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3955 * @vport: The virtual port for which this call is being executed.
3956 *
3957 * This routine will issue a GID_PT to get a list of all N_Ports
3958 *
3959 * Return value :
3960 * 0 - Failure to issue a GID_PT
3961 * 1 - GID_PT issued
3962 **/
3963int
3964lpfc_issue_gidpt(struct lpfc_vport *vport)
3965{
3966 /* Good status, issue CT Request to NameServer */
3967 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
3968 /* Cannot issue NameServer FCP Query, so finish up
3969 * discovery
3970 */
3971 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3972 "0606 %s Port TYPE %x %s\n",
3973 "Failed to issue GID_PT to ",
3974 GID_PT_N_PORT,
3975 "Finishing discovery.");
3976 return 0;
3977 }
3978 vport->gidft_inp++;
3979 return 1;
3980}
3981
dea31012005-04-17 16:05:31 -05003982/*
3983 * This routine handles processing a NameServer REG_LOGIN mailbox
3984 * command upon completion. It is setup in the LPFC_MBOXQ
3985 * as the completion routine when the command is
3986 * handed off to the SLI layer.
3987 */
3988void
James Smart2e0fef82007-06-17 19:56:36 -05003989lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003990{
James Smart21e9a0a2009-05-22 14:53:21 -04003991 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08003992 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3993 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003994 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05003995
James Smart3e1f0712018-11-29 16:09:29 -08003996 pmb->ctx_buf = NULL;
3997 pmb->ctx_ndlp = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08003998 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04003999
dea31012005-04-17 16:05:31 -05004000 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04004001 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4002 "0260 Register NameServer error: 0x%x\n",
4003 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08004004
4005out:
James Smartfa4066b2008-01-11 01:53:27 -05004006 /* decrement the node reference count held for this
4007 * callback function.
4008 */
James Smart329f9bc2007-04-25 09:53:01 -04004009 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004010 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4011 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04004012 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04004013
4014 /* If no other thread is using the ndlp, free it */
4015 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05004016
James Smart76a95d72010-11-20 23:11:48 -05004017 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05004018 /*
4019 * RegLogin failed, use loop map to make discovery
4020 * list
4021 */
4022 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004023
James Smart92d7f7b2007-06-17 19:56:38 -05004024 /* Start discovery */
4025 lpfc_disc_start(vport);
4026 return;
4027 }
4028 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05004029 return;
4030 }
4031
James Smart6d368e52011-05-24 11:44:12 -04004032 if (phba->sli_rev < LPFC_SLI_REV4)
4033 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05004034 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05004035 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004036 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004037 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4038 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
4039 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004040 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004041 ndlp->nlp_usg_map, ndlp);
dea31012005-04-17 16:05:31 -05004042
James Smart2e0fef82007-06-17 19:56:36 -05004043 if (vport->port_state < LPFC_VPORT_READY) {
4044 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05004045 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4046 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4047 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4048 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08004049
4050 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4051 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4052 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4053
4054 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4055 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08004056 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4057 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05004058
4059 /* Issue SCR just before NameServer GID_FT Query */
4060 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05004061 }
4062
James Smart2e0fef82007-06-17 19:56:36 -05004063 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08004064 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05004065 goto out;
dea31012005-04-17 16:05:31 -05004066
James Smarta0f2d3e2017-02-12 13:52:31 -08004067 /*
4068 * At this point in time we may need to wait for multiple
4069 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4070 *
4071 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05004072 * callback function.
4073 */
James Smart329f9bc2007-04-25 09:53:01 -04004074 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004075 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4076 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05004077 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004078
4079 return;
4080}
4081
4082static void
James Smart2e0fef82007-06-17 19:56:36 -05004083lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004084{
James Smart2e0fef82007-06-17 19:56:36 -05004085 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4086 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05004087 struct lpfc_rport_data *rdata;
4088 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004089 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004090
James Smart895427b2017-02-12 13:52:30 -08004091 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4092 return;
4093
dea31012005-04-17 16:05:31 -05004094 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004095 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4096 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004097 rport_ids.port_id = ndlp->nlp_DID;
4098 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004099
James Smart329f9bc2007-04-25 09:53:01 -04004100 /*
4101 * We leave our node pointer in rport->dd_data when we unregister a
4102 * FCP target port. But fc_remote_port_add zeros the space to which
4103 * rport->dd_data points. So, if we're reusing a previously
4104 * registered port, drop the reference that we took the last time we
4105 * registered the port.
4106 */
James Smart466e8402015-05-21 13:55:28 -04004107 rport = ndlp->rport;
4108 if (rport) {
4109 rdata = rport->dd_data;
4110 /* break the link before dropping the ref */
4111 ndlp->rport = NULL;
James Smart2ade92a2017-03-04 09:30:38 -08004112 if (rdata) {
4113 if (rdata->pnode == ndlp)
4114 lpfc_nlp_put(ndlp);
4115 rdata->pnode = NULL;
4116 }
James Smart466e8402015-05-21 13:55:28 -04004117 /* drop reference for earlier registeration */
4118 put_device(&rport->dev);
4119 }
James Smart858c9f62007-06-17 19:56:39 -05004120
4121 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4122 "rport add: did:x%x flg:x%x type x%x",
4123 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4124
James Smart9589b0622011-04-16 11:03:17 -04004125 /* Don't add the remote port if unloading. */
4126 if (vport->load_flag & FC_UNLOADING)
4127 return;
4128
James Smart2e0fef82007-06-17 19:56:36 -05004129 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004130 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004131 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4132 "Warning: fc_remote_port_add failed\n");
4133 return;
4134 }
4135
4136 /* initialize static port data */
4137 rport->maxframe_size = ndlp->nlp_maxframe;
4138 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004139 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004140 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004141
4142 if (ndlp->nlp_type & NLP_FCP_TARGET)
4143 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
4144 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4145 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4146
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004147 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4148 fc_remote_port_rolechg(rport, rport_ids.roles);
4149
James Smart34f5ad82012-08-03 12:35:03 -04004150 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4151 "3183 rport register x%06x, rport %p role x%x\n",
4152 ndlp->nlp_DID, rport, rport_ids.roles);
4153
James Smart071fbd3d2006-04-15 11:53:20 -04004154 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004155 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004156 ndlp->nlp_sid = rport->scsi_target_id;
4157 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004158 return;
4159}
4160
4161static void
James Smart2e0fef82007-06-17 19:56:36 -05004162lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004163{
4164 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004165 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004166 struct lpfc_hba *phba = vport->phba;
4167
4168 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4169 return;
James Smartc01f3202006-08-18 17:47:08 -04004170
James Smart2ea259e2017-02-12 13:52:27 -08004171 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004172 "rport delete: did:x%x flg:x%x type x%x",
4173 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4174
James Smart2ea259e2017-02-12 13:52:27 -08004175 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart34f5ad82012-08-03 12:35:03 -04004176 "3184 rport unregister x%06x, rport %p\n",
4177 ndlp->nlp_DID, rport);
4178
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004179 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004180
4181 return;
4182}
4183
James Smartde0c5b32007-04-25 09:52:27 -04004184static void
James Smart2e0fef82007-06-17 19:56:36 -05004185lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004186{
James Smart2e0fef82007-06-17 19:56:36 -05004187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4188
4189 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004190 switch (state) {
4191 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004192 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004193 break;
4194 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004195 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004196 break;
4197 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004198 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004199 break;
4200 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004201 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004202 break;
4203 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004204 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004205 break;
4206 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004207 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004208 break;
4209 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004210 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004211 break;
4212 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004213 if (vport->fc_npr_cnt == 0 && count == -1)
4214 vport->fc_npr_cnt = 0;
4215 else
4216 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004217 break;
4218 }
James Smart2e0fef82007-06-17 19:56:36 -05004219 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004220}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004221
James Smartde0c5b32007-04-25 09:52:27 -04004222static void
James Smart2e0fef82007-06-17 19:56:36 -05004223lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004224 int old_state, int new_state)
4225{
James Smart2e0fef82007-06-17 19:56:36 -05004226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4227
James Smartde0c5b32007-04-25 09:52:27 -04004228 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004229 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4230 ndlp->nlp_type |= NLP_FC_NODE;
4231 }
4232 if (new_state == NLP_STE_MAPPED_NODE)
4233 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4234 if (new_state == NLP_STE_NPR_NODE)
4235 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004236
James Smarta0f2d3e2017-02-12 13:52:31 -08004237 /* FCP and NVME Transport interface */
4238 if ((old_state == NLP_STE_MAPPED_NODE ||
4239 old_state == NLP_STE_UNMAPPED_NODE)) {
4240 if (ndlp->rport) {
4241 vport->phba->nport_event_cnt++;
4242 lpfc_unregister_remote_port(ndlp);
4243 }
4244
James Smart1c5b12f2017-04-21 16:05:03 -07004245 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004246 vport->phba->nport_event_cnt++;
James Smart3b5bde692017-11-20 16:00:39 -08004247 if (vport->phba->nvmet_support == 0) {
4248 /* Start devloss if target. */
4249 if (ndlp->nlp_type & NLP_NVME_TARGET)
4250 lpfc_nvme_unregister_port(vport, ndlp);
4251 } else {
James Smart6599e122017-06-01 21:07:00 -07004252 /* NVMET has no upcall. */
4253 lpfc_nlp_put(ndlp);
James Smart3b5bde692017-11-20 16:00:39 -08004254 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004255 }
James Smartde0c5b32007-04-25 09:52:27 -04004256 }
dea31012005-04-17 16:05:31 -05004257
James Smarta0f2d3e2017-02-12 13:52:31 -08004258 /* FCP and NVME Transport interfaces */
4259
James Smartde0c5b32007-04-25 09:52:27 -04004260 if (new_state == NLP_STE_MAPPED_NODE ||
4261 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart01a8aed2018-09-10 10:30:41 -07004262 if (ndlp->nlp_fc4_type ||
James Smart92721c32017-06-01 21:06:59 -07004263 ndlp->nlp_DID == Fabric_DID ||
4264 ndlp->nlp_DID == NameServer_DID ||
4265 ndlp->nlp_DID == FDMI_DID) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004266 vport->phba->nport_event_cnt++;
4267 /*
4268 * Tell the fc transport about the port, if we haven't
4269 * already. If we have, and it's a scsi entity, be
4270 */
4271 lpfc_register_remote_port(vport, ndlp);
4272 }
4273 /* Notify the NVME transport of this new rport. */
James Smart09559e82017-06-15 22:56:46 -07004274 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4275 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004276 if (vport->phba->nvmet_support == 0) {
4277 /* Register this rport with the transport.
James Smart3b5bde692017-11-20 16:00:39 -08004278 * Only NVME Target Rports are registered with
4279 * the transport.
James Smarta0f2d3e2017-02-12 13:52:31 -08004280 */
James Smart3b5bde692017-11-20 16:00:39 -08004281 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4282 vport->phba->nport_event_cnt++;
4283 lpfc_nvme_register_port(vport, ndlp);
4284 }
James Smart8c258642017-02-12 13:52:36 -08004285 } else {
4286 /* Just take an NDLP ref count since the
4287 * target does not register rports.
4288 */
4289 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004290 }
4291 }
James Smartde0c5b32007-04-25 09:52:27 -04004292 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004293
James Smartea2151b2008-09-07 11:52:10 -04004294 if ((new_state == NLP_STE_MAPPED_NODE) &&
4295 (vport->stat_data_enabled)) {
4296 /*
4297 * A new target is discovered, if there is no buffer for
4298 * statistical data collection allocate buffer.
4299 */
4300 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4301 sizeof(struct lpfc_scsicmd_bkt),
4302 GFP_KERNEL);
4303
4304 if (!ndlp->lat_data)
4305 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4306 "0286 lpfc_nlp_state_cleanup failed to "
4307 "allocate statistical data buffer DID "
4308 "0x%x\n", ndlp->nlp_DID);
4309 }
James Smart858c9f62007-06-17 19:56:39 -05004310 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004311 * If the node just added to Mapped list was an FCP target,
4312 * but the remote port registration failed or assigned a target
4313 * id outside the presentable range - move the node to the
4314 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004315 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004316 if ((new_state == NLP_STE_MAPPED_NODE) &&
4317 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004318 (!ndlp->rport ||
4319 ndlp->rport->scsi_target_id == -1 ||
4320 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004321 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004322 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004323 spin_unlock_irq(shost->host_lock);
4324 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004325 }
James Smartde0c5b32007-04-25 09:52:27 -04004326}
4327
James Smart685f0bf2007-04-25 09:53:08 -04004328static char *
4329lpfc_nlp_state_name(char *buffer, size_t size, int state)
4330{
4331 static char *states[] = {
4332 [NLP_STE_UNUSED_NODE] = "UNUSED",
4333 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4334 [NLP_STE_ADISC_ISSUE] = "ADISC",
4335 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4336 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004337 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004338 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4339 [NLP_STE_MAPPED_NODE] = "MAPPED",
4340 [NLP_STE_NPR_NODE] = "NPR",
4341 };
4342
James Smart311464e2007-08-02 11:10:37 -04004343 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004344 strlcpy(buffer, states[state], size);
4345 else
4346 snprintf(buffer, size, "unknown (%d)", state);
4347 return buffer;
4348}
4349
James Smartde0c5b32007-04-25 09:52:27 -04004350void
James Smart2e0fef82007-06-17 19:56:36 -05004351lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4352 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004353{
James Smart2e0fef82007-06-17 19:56:36 -05004354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004355 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004356 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004357
James Smarte8b62012007-08-02 11:10:09 -04004358 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4359 "0904 NPort state transition x%06x, %s -> %s\n",
4360 ndlp->nlp_DID,
4361 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4362 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004363
4364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4365 "node statechg did:x%x old:%d ste:%d",
4366 ndlp->nlp_DID, old_state, state);
4367
James Smartde0c5b32007-04-25 09:52:27 -04004368 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004369 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004370 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004371 if (old_state == NLP_STE_UNMAPPED_NODE) {
4372 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4373 ndlp->nlp_type &= ~NLP_FC_NODE;
4374 }
4375
James Smart685f0bf2007-04-25 09:53:08 -04004376 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004377 spin_lock_irq(shost->host_lock);
4378 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4379 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004380 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004381 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004382
4383 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004384 lpfc_nlp_counters(vport, state, 1);
4385 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004386}
4387
4388void
James Smarte47c9092008-02-08 18:49:26 -05004389lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4390{
4391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4392
4393 if (list_empty(&ndlp->nlp_listp)) {
4394 spin_lock_irq(shost->host_lock);
4395 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4396 spin_unlock_irq(shost->host_lock);
4397 }
4398}
4399
4400void
James Smart2e0fef82007-06-17 19:56:36 -05004401lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004402{
James Smart2e0fef82007-06-17 19:56:36 -05004403 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4404
James Smart0d2b6b82008-06-14 22:52:47 -04004405 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004406 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004407 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4408 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004409 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004410 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004411 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004412 NLP_STE_UNUSED_NODE);
4413}
4414
Adrian Bunk4d9db012008-02-14 23:24:02 +02004415static void
James Smarte47c9092008-02-08 18:49:26 -05004416lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4417{
James Smart0d2b6b82008-06-14 22:52:47 -04004418 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004419 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4420 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4421 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4422 NLP_STE_UNUSED_NODE);
4423}
James Smart109f6ed2008-12-04 22:39:08 -05004424/**
James Smart3621a712009-04-06 18:47:14 -04004425 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004426 * @vport: Pointer to Virtual Port object.
4427 * @ndlp: Pointer to FC node object.
4428 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004429 *
4430 * This function is always called when node object need to be initialized.
4431 * It initializes all the fields of the node object. Although the reference
4432 * to phba from @ndlp can be obtained indirectly through it's reference to
4433 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4434 * to the life-span of the @ndlp might go beyond the existence of @vport as
4435 * the final release of ndlp is determined by its reference count. And, the
4436 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004437 **/
4438static inline void
4439lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4440 uint32_t did)
4441{
4442 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4443 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
Kees Cookf22eb4d2017-09-06 20:24:26 -07004444 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
James Smart109f6ed2008-12-04 22:39:08 -05004445 ndlp->nlp_DID = did;
4446 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004447 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004448 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004449 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004450 kref_init(&ndlp->kref);
4451 NLP_INT_NODE_ACT(ndlp);
4452 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004453 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smartdea16bd2018-11-29 16:09:30 -08004454 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
James Smart109f6ed2008-12-04 22:39:08 -05004455}
James Smarte47c9092008-02-08 18:49:26 -05004456
4457struct lpfc_nodelist *
4458lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4459 int state)
4460{
4461 struct lpfc_hba *phba = vport->phba;
James Smartdea16bd2018-11-29 16:09:30 -08004462 uint32_t did, flag;
James Smarte47c9092008-02-08 18:49:26 -05004463 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004464 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart9d3d3402017-04-21 16:05:00 -07004465 int rpi = LPFC_RPI_ALLOC_ERROR;
James Smartdea16bd2018-11-29 16:09:30 -08004466 uint32_t defer_did = 0;
James Smarte47c9092008-02-08 18:49:26 -05004467
4468 if (!ndlp)
4469 return NULL;
4470
James Smart9d3d3402017-04-21 16:05:00 -07004471 if (phba->sli_rev == LPFC_SLI_REV4) {
4472 rpi = lpfc_sli4_alloc_rpi(vport->phba);
4473 if (rpi == LPFC_RPI_ALLOC_ERROR)
4474 return NULL;
4475 }
4476
James Smarte47c9092008-02-08 18:49:26 -05004477 spin_lock_irqsave(&phba->ndlp_lock, flags);
4478 /* The ndlp should not be in memory free mode */
4479 if (NLP_CHK_FREE_REQ(ndlp)) {
4480 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4481 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4482 "0277 lpfc_enable_node: ndlp:x%p "
4483 "usgmap:x%x refcnt:%d\n",
4484 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004485 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004486 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004487 }
4488 /* The ndlp should not already be in active mode */
4489 if (NLP_CHK_NODE_ACT(ndlp)) {
4490 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4491 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4492 "0278 lpfc_enable_node: ndlp:x%p "
4493 "usgmap:x%x refcnt:%d\n",
4494 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004495 kref_read(&ndlp->kref));
James Smart9d3d3402017-04-21 16:05:00 -07004496 goto free_rpi;
James Smarte47c9092008-02-08 18:49:26 -05004497 }
4498
James Smartdea16bd2018-11-29 16:09:30 -08004499 /* First preserve the orginal DID, xri_bitmap and some flags */
James Smarte47c9092008-02-08 18:49:26 -05004500 did = ndlp->nlp_DID;
James Smartdea16bd2018-11-29 16:09:30 -08004501 flag = (ndlp->nlp_flag & NLP_UNREG_INP);
4502 if (flag & NLP_UNREG_INP)
4503 defer_did = ndlp->nlp_defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004504 if (phba->sli_rev == LPFC_SLI_REV4)
4505 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004506
James Smartdea16bd2018-11-29 16:09:30 -08004507 /* Zero ndlp except of ndlp linked list pointer */
James Smarte47c9092008-02-08 18:49:26 -05004508 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4509 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smarte47c9092008-02-08 18:49:26 -05004510
James Smartdea16bd2018-11-29 16:09:30 -08004511 /* Next reinitialize and restore saved objects */
4512 lpfc_initialize_node(vport, ndlp, did);
4513 ndlp->nlp_flag |= flag;
4514 if (flag & NLP_UNREG_INP)
4515 ndlp->nlp_defer_did = defer_did;
James Smartcff261f2013-12-17 20:29:47 -05004516 if (phba->sli_rev == LPFC_SLI_REV4)
4517 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4518
James Smarte47c9092008-02-08 18:49:26 -05004519 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smartbe6bb942015-04-07 15:07:22 -04004520 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07004521 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04004522 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4523 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4524 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4525 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004526 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004527 ndlp->nlp_usg_map, ndlp);
4528 }
James Smart725dd392013-10-10 12:23:30 -04004529
James Smarte47c9092008-02-08 18:49:26 -05004530
4531 if (state != NLP_STE_UNUSED_NODE)
4532 lpfc_nlp_set_state(vport, ndlp, state);
4533
4534 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4535 "node enable: did:x%x",
4536 ndlp->nlp_DID, 0, 0);
4537 return ndlp;
James Smart9d3d3402017-04-21 16:05:00 -07004538
4539free_rpi:
4540 if (phba->sli_rev == LPFC_SLI_REV4)
4541 lpfc_sli4_free_rpi(vport->phba, rpi);
4542 return NULL;
James Smartde0c5b32007-04-25 09:52:27 -04004543}
4544
4545void
James Smart2e0fef82007-06-17 19:56:36 -05004546lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004547{
James Smart87af33f2007-10-27 13:37:43 -04004548 /*
James Smartfa4066b2008-01-11 01:53:27 -05004549 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004550 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004551 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4552 * until ALL other outstanding threads have completed. We check
4553 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004554 */
James Smartfa4066b2008-01-11 01:53:27 -05004555 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4556 return;
James Smart51ef4c22007-08-02 11:10:31 -04004557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004558 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004559 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004560 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004561 }
James Smart02902172015-05-21 13:55:17 -04004562
4563 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004564 return;
dea31012005-04-17 16:05:31 -05004565}
4566
4567/*
4568 * Start / ReStart rescue timer for Discovery / RSCN handling
4569 */
4570void
James Smart2e0fef82007-06-17 19:56:36 -05004571lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004572{
James Smart2e0fef82007-06-17 19:56:36 -05004573 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4574 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004575 uint32_t tmo;
4576
James Smart2e0fef82007-06-17 19:56:36 -05004577 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004578 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004579 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4580 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004581 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004582 * FC spec states we need 3 * ratov for CT requests
4583 */
4584 tmo = ((phba->fc_ratov * 3) + 3);
4585 }
dea31012005-04-17 16:05:31 -05004586
James Smart858c9f62007-06-17 19:56:39 -05004587
4588 if (!timer_pending(&vport->fc_disctmo)) {
4589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4590 "set disc timer: tmo:x%x state:x%x flg:x%x",
4591 tmo, vport->port_state, vport->fc_flag);
4592 }
4593
James Smart256ec0d2013-04-17 20:14:58 -04004594 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004595 spin_lock_irq(shost->host_lock);
4596 vport->fc_flag |= FC_DISC_TMO;
4597 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004598
4599 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004600 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4601 "0247 Start Discovery Timer state x%x "
4602 "Data: x%x x%lx x%x x%x\n",
4603 vport->port_state, tmo,
4604 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4605 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004606
4607 return;
4608}
4609
4610/*
4611 * Cancel rescue timer for Discovery / RSCN handling
4612 */
4613int
James Smart2e0fef82007-06-17 19:56:36 -05004614lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004615{
James Smart2e0fef82007-06-17 19:56:36 -05004616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004617 unsigned long iflags;
4618
James Smart858c9f62007-06-17 19:56:39 -05004619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4620 "can disc timer: state:x%x rtry:x%x flg:x%x",
4621 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4622
dea31012005-04-17 16:05:31 -05004623 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004624 if (vport->fc_flag & FC_DISC_TMO) {
4625 spin_lock_irqsave(shost->host_lock, iflags);
4626 vport->fc_flag &= ~FC_DISC_TMO;
4627 spin_unlock_irqrestore(shost->host_lock, iflags);
4628 del_timer_sync(&vport->fc_disctmo);
4629 spin_lock_irqsave(&vport->work_port_lock, iflags);
4630 vport->work_port_events &= ~WORKER_DISC_TMO;
4631 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004632 }
4633
4634 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004635 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4636 "0248 Cancel Discovery Timer state x%x "
4637 "Data: x%x x%x x%x\n",
4638 vport->port_state, vport->fc_flag,
4639 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004640 return 0;
dea31012005-04-17 16:05:31 -05004641}
4642
4643/*
4644 * Check specified ring for outstanding IOCB on the SLI queue
4645 * Return true if iocb matches the specified nport
4646 */
4647int
James Smart2e0fef82007-06-17 19:56:36 -05004648lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4649 struct lpfc_sli_ring *pring,
4650 struct lpfc_iocbq *iocb,
4651 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004652{
James Smart2e0fef82007-06-17 19:56:36 -05004653 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004654 struct lpfc_vport *vport = ndlp->vport;
4655
4656 if (iocb->vport != vport)
4657 return 0;
4658
dea31012005-04-17 16:05:31 -05004659 if (pring->ringno == LPFC_ELS_RING) {
4660 switch (icmd->ulpCommand) {
4661 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004662 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004663 return 1;
dea31012005-04-17 16:05:31 -05004664 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004665 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4666 return 1;
dea31012005-04-17 16:05:31 -05004667 case CMD_XMIT_ELS_RSP64_CX:
4668 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004669 return 1;
dea31012005-04-17 16:05:31 -05004670 }
James Smart895427b2017-02-12 13:52:30 -08004671 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004672 /* Skip match check if waiting to relogin to FCP target */
4673 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004674 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004675 return 0;
dea31012005-04-17 16:05:31 -05004676 }
4677 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004678 return 1;
dea31012005-04-17 16:05:31 -05004679 }
dea31012005-04-17 16:05:31 -05004680 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004681 return 0;
dea31012005-04-17 16:05:31 -05004682}
4683
James Smart895427b2017-02-12 13:52:30 -08004684static void
4685__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4686 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4687 struct list_head *dequeue_list)
4688{
4689 struct lpfc_iocbq *iocb, *next_iocb;
4690
4691 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4692 /* Check to see if iocb matches the nport */
4693 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4694 /* match, dequeue */
4695 list_move_tail(&iocb->list, dequeue_list);
4696 }
4697}
4698
4699static void
4700lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4701 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4702{
4703 struct lpfc_sli *psli = &phba->sli;
4704 uint32_t i;
4705
4706 spin_lock_irq(&phba->hbalock);
4707 for (i = 0; i < psli->num_rings; i++)
4708 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4709 dequeue_list);
4710 spin_unlock_irq(&phba->hbalock);
4711}
4712
4713static void
4714lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4715 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4716{
4717 struct lpfc_sli_ring *pring;
4718 struct lpfc_queue *qp = NULL;
4719
4720 spin_lock_irq(&phba->hbalock);
4721 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4722 pring = qp->pring;
4723 if (!pring)
4724 continue;
James Smart2ade92a2017-03-04 09:30:38 -08004725 spin_lock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004726 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
James Smart2ade92a2017-03-04 09:30:38 -08004727 spin_unlock(&pring->ring_lock);
James Smart895427b2017-02-12 13:52:30 -08004728 }
4729 spin_unlock_irq(&phba->hbalock);
4730}
4731
dea31012005-04-17 16:05:31 -05004732/*
4733 * Free resources / clean up outstanding I/Os
4734 * associated with nlp_rpi in the LPFC_NODELIST entry.
4735 */
4736static int
James Smart2e0fef82007-06-17 19:56:36 -05004737lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004738{
James Smart2534ba72007-04-25 09:52:20 -04004739 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004740
James Smart92d7f7b2007-06-17 19:56:38 -05004741 lpfc_fabric_abort_nport(ndlp);
4742
dea31012005-04-17 16:05:31 -05004743 /*
4744 * Everything that matches on txcmplq will be returned
4745 * by firmware with a no rpi error.
4746 */
James Smart40426292010-12-15 17:58:10 -05004747 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004748 if (phba->sli_rev != LPFC_SLI_REV4)
4749 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4750 else
4751 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004752 }
James Smart2534ba72007-04-25 09:52:20 -04004753
James Smarta257bf92009-04-06 18:48:10 -04004754 /* Cancel all the IOCBs from the completions list */
4755 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4756 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004757
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004758 return 0;
dea31012005-04-17 16:05:31 -05004759}
4760
James Smart086a3452012-08-14 14:25:21 -04004761/**
4762 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4763 * @phba: Pointer to HBA context object.
4764 * @pmb: Pointer to mailbox object.
4765 *
4766 * This function will issue an ELS LOGO command after completing
4767 * the UNREG_RPI.
4768 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004769static void
James Smart086a3452012-08-14 14:25:21 -04004770lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4771{
4772 struct lpfc_vport *vport = pmb->vport;
4773 struct lpfc_nodelist *ndlp;
4774
James Smart3e1f0712018-11-29 16:09:29 -08004775 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
James Smart086a3452012-08-14 14:25:21 -04004776 if (!ndlp)
4777 return;
4778 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004779 mempool_free(pmb, phba->mbox_mem_pool);
James Smartdea16bd2018-11-29 16:09:30 -08004780
4781 /* Check to see if there are any deferred events to process */
4782 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
4783 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
4784 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4785 "1434 UNREG cmpl deferred logo x%x "
4786 "on NPort x%x Data: x%x %p\n",
4787 ndlp->nlp_rpi, ndlp->nlp_DID,
4788 ndlp->nlp_defer_did, ndlp);
4789
4790 ndlp->nlp_flag &= ~NLP_UNREG_INP;
4791 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4792 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4793 }
James Smart086a3452012-08-14 14:25:21 -04004794}
4795
dea31012005-04-17 16:05:31 -05004796/*
4797 * Free rpi associated with LPFC_NODELIST entry.
4798 * This routine is called from lpfc_freenode(), when we are removing
4799 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4800 * LOGO that completes successfully, and we are waiting to PLOGI back
4801 * to the remote NPort. In addition, it is called after we receive
4802 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4803 * we are waiting to PLOGI back to the remote NPort.
4804 */
4805int
James Smart2e0fef82007-06-17 19:56:36 -05004806lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004807{
James Smart2e0fef82007-06-17 19:56:36 -05004808 struct lpfc_hba *phba = vport->phba;
4809 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004810 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004811 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004812
James Smartf454a9a2013-09-06 12:20:07 -04004813 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4814 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4815 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4816 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4817 "3366 RPI x%x needs to be "
4818 "unregistered nlp_flag x%x "
4819 "did x%x\n",
4820 ndlp->nlp_rpi, ndlp->nlp_flag,
4821 ndlp->nlp_DID);
James Smartdea16bd2018-11-29 16:09:30 -08004822
4823 /* If there is already an UNREG in progress for this ndlp,
4824 * no need to queue up another one.
4825 */
4826 if (ndlp->nlp_flag & NLP_UNREG_INP) {
4827 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4828 "1436 unreg_rpi SKIP UNREG x%x on "
4829 "NPort x%x deferred x%x flg x%x "
4830 "Data: %p\n",
4831 ndlp->nlp_rpi, ndlp->nlp_DID,
4832 ndlp->nlp_defer_did,
4833 ndlp->nlp_flag, ndlp);
4834 goto out;
4835 }
4836
James Smart2e0fef82007-06-17 19:56:36 -05004837 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4838 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004839 /* SLI4 ports require the physical rpi value. */
4840 rpi = ndlp->nlp_rpi;
4841 if (phba->sli_rev == LPFC_SLI_REV4)
4842 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004843
James Smart6d368e52011-05-24 11:44:12 -04004844 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004845 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004846 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
James Smart3e1f0712018-11-29 16:09:29 -08004847 mbox->ctx_ndlp = ndlp;
James Smart086a3452012-08-14 14:25:21 -04004848 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4849 } else {
James Smartbe6bb942015-04-07 15:07:22 -04004850 if (phba->sli_rev == LPFC_SLI_REV4 &&
4851 (!(vport->load_flag & FC_UNLOADING)) &&
4852 (bf_get(lpfc_sli_intf_if_type,
4853 &phba->sli4_hba.sli_intf) ==
James Smarta6517db2016-03-31 14:12:29 -07004854 LPFC_SLI_INTF_IF_TYPE_2) &&
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004855 (kref_read(&ndlp->kref) > 0)) {
James Smart3e1f0712018-11-29 16:09:29 -08004856 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004857 mbox->mbox_cmpl =
4858 lpfc_sli4_unreg_rpi_cmpl_clr;
James Smart7c5e5182015-05-22 10:42:43 -04004859 /*
4860 * accept PLOGIs after unreg_rpi_cmpl
4861 */
4862 acc_plogi = 0;
James Smartdea16bd2018-11-29 16:09:30 -08004863 } else {
4864 mbox->ctx_ndlp = ndlp;
James Smartbe6bb942015-04-07 15:07:22 -04004865 mbox->mbox_cmpl =
4866 lpfc_sli_def_mbox_cmpl;
James Smartdea16bd2018-11-29 16:09:30 -08004867 }
James Smart086a3452012-08-14 14:25:21 -04004868 }
James Smartdea16bd2018-11-29 16:09:30 -08004869 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
4870 Fabric_DID_MASK) &&
4871 (!(vport->fc_flag & FC_OFFLINE_MODE)))
4872 ndlp->nlp_flag |= NLP_UNREG_INP;
4873
4874 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4875 "1433 unreg_rpi UNREG x%x on "
4876 "NPort x%x deferred flg x%x Data:%p\n",
4877 ndlp->nlp_rpi, ndlp->nlp_DID,
4878 ndlp->nlp_flag, ndlp);
James Smart086a3452012-08-14 14:25:21 -04004879
James Smart0b727fe2007-10-27 13:37:25 -04004880 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004881 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004882 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004883 acc_plogi = 1;
4884 }
dea31012005-04-17 16:05:31 -05004885 }
dea31012005-04-17 16:05:31 -05004886 lpfc_no_rpi(phba, ndlp);
James Smartdea16bd2018-11-29 16:09:30 -08004887out:
James Smart40426292010-12-15 17:58:10 -05004888 if (phba->sli_rev != LPFC_SLI_REV4)
4889 ndlp->nlp_rpi = 0;
4890 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004891 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004892 if (acc_plogi)
4893 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004894 return 1;
4895 }
James Smart7c5e5182015-05-22 10:42:43 -04004896 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004897 return 0;
4898}
4899
James Smartecfd03c2010-02-12 14:41:27 -05004900/**
4901 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4902 * @phba: pointer to lpfc hba data structure.
4903 *
4904 * This routine is invoked to unregister all the currently registered RPIs
4905 * to the HBA.
4906 **/
4907void
4908lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4909{
4910 struct lpfc_vport **vports;
4911 struct lpfc_nodelist *ndlp;
4912 struct Scsi_Host *shost;
4913 int i;
4914
4915 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004916 if (!vports) {
4917 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4918 "2884 Vport array allocation failed \n");
4919 return;
4920 }
James Smartecfd03c2010-02-12 14:41:27 -05004921 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4922 shost = lpfc_shost_from_vport(vports[i]);
4923 spin_lock_irq(shost->host_lock);
4924 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004925 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004926 /* The mempool_alloc might sleep */
4927 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004928 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004929 spin_lock_irq(shost->host_lock);
4930 }
James Smartecfd03c2010-02-12 14:41:27 -05004931 }
4932 spin_unlock_irq(shost->host_lock);
4933 }
4934 lpfc_destroy_vport_work_array(phba, vports);
4935}
4936
James Smart92d7f7b2007-06-17 19:56:38 -05004937void
4938lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4939{
4940 struct lpfc_hba *phba = vport->phba;
4941 LPFC_MBOXQ_t *mbox;
4942 int rc;
4943
James Smart5af5eee2010-10-22 11:06:38 -04004944 if (phba->sli_rev == LPFC_SLI_REV4) {
4945 lpfc_sli4_unreg_all_rpis(vport);
4946 return;
4947 }
4948
James Smart92d7f7b2007-06-17 19:56:38 -05004949 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4950 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004951 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4952 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004953 mbox->vport = vport;
4954 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08004955 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05004956 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004957 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004958 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04004959
4960 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4961 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4962 "1836 Could not issue "
4963 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004964 }
4965}
4966
4967void
4968lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4969{
4970 struct lpfc_hba *phba = vport->phba;
4971 LPFC_MBOXQ_t *mbox;
4972 int rc;
4973
4974 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4975 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004976 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4977 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004978 mbox->vport = vport;
4979 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -08004980 mbox->ctx_ndlp = NULL;
James Smart09372822008-01-11 01:52:54 -05004981 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004982 if (rc != MBX_TIMEOUT)
4983 mempool_free(mbox, phba->mbox_mem_pool);
4984
4985 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04004986 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4987 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04004988 "unreg_did (default rpis) status %d\n",
4989 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004990 }
4991}
4992
dea31012005-04-17 16:05:31 -05004993/*
4994 * Free resources associated with LPFC_NODELIST entry
4995 * so it can be freed.
4996 */
4997static int
James Smart2e0fef82007-06-17 19:56:36 -05004998lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004999{
James Smart2e0fef82007-06-17 19:56:36 -05005000 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5001 struct lpfc_hba *phba = vport->phba;
5002 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05005003 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05005004
5005 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04005006 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5007 "0900 Cleanup node for NPort x%x "
5008 "Data: x%x x%x x%x\n",
5009 ndlp->nlp_DID, ndlp->nlp_flag,
5010 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005011 if (NLP_CHK_FREE_REQ(ndlp)) {
5012 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5013 "0280 lpfc_cleanup_node: ndlp:x%p "
5014 "usgmap:x%x refcnt:%d\n",
5015 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005016 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005017 lpfc_dequeue_node(vport, ndlp);
5018 } else {
5019 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5020 "0281 lpfc_cleanup_node: ndlp:x%p "
5021 "usgmap:x%x refcnt:%d\n",
5022 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005023 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005024 lpfc_disable_node(vport, ndlp);
5025 }
dea31012005-04-17 16:05:31 -05005026
James Smart086a3452012-08-14 14:25:21 -04005027
5028 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5029
dea31012005-04-17 16:05:31 -05005030 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5031 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04005032 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005033 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005034 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5035 mb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005036 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5037 }
5038 }
James Smart33ccf8d2006-08-17 11:57:58 -04005039
James Smart2e0fef82007-06-17 19:56:36 -05005040 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04005041 /* Cleanup REG_LOGIN completions which are not yet processed */
5042 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5043 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04005044 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart3e1f0712018-11-29 16:09:29 -08005045 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
James Smart5ac6b302010-10-22 11:05:36 -04005046 continue;
5047
James Smart3e1f0712018-11-29 16:09:29 -08005048 mb->ctx_ndlp = NULL;
James Smart5ac6b302010-10-22 11:05:36 -04005049 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5050 }
5051
dea31012005-04-17 16:05:31 -05005052 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04005053 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04005054 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart3e1f0712018-11-29 16:09:29 -08005055 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5056 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
dea31012005-04-17 16:05:31 -05005057 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05005058 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05005059 kfree(mp);
5060 }
5061 list_del(&mb->list);
5062 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05005063 /* We shall not invoke the lpfc_nlp_put to decrement
5064 * the ndlp reference count as we are in the process
5065 * of lpfc_nlp_release.
5066 */
dea31012005-04-17 16:05:31 -05005067 }
5068 }
James Smart2e0fef82007-06-17 19:56:36 -05005069 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005070
James Smarte47c9092008-02-08 18:49:26 -05005071 lpfc_els_abort(phba, ndlp);
5072
James Smart2e0fef82007-06-17 19:56:36 -05005073 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04005074 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05005075 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005076
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005077 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05005078 del_timer_sync(&ndlp->nlp_delayfunc);
5079
James Smart0d2b6b82008-06-14 22:52:47 -04005080 list_del_init(&ndlp->els_retry_evt.evt_listp);
5081 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05005082 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005083 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05005084
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005085 return 0;
dea31012005-04-17 16:05:31 -05005086}
5087
5088/*
5089 * Check to see if we can free the nlp back to the freelist.
5090 * If we are in the middle of using the nlp in the discovery state
5091 * machine, defer the free till we reach the end of the state machine.
5092 */
James Smart329f9bc2007-04-25 09:53:01 -04005093static void
James Smart2e0fef82007-06-17 19:56:36 -05005094lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005095{
James Smarta8adb832007-10-27 13:37:53 -04005096 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04005097 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04005098 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04005099 LPFC_MBOXQ_t *mbox;
5100 int rc;
dea31012005-04-17 16:05:31 -05005101
James Smart0d2b6b82008-06-14 22:52:47 -04005102 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04005103 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05005104 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
Dick Kennedye8bcf0a2017-09-29 17:34:32 -07005105 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5106 phba->sli_rev != LPFC_SLI_REV4) {
James Smarta8adb832007-10-27 13:37:53 -04005107 /* For this case we need to cleanup the default rpi
5108 * allocated by the firmware.
5109 */
James Smartbe6bb942015-04-07 15:07:22 -04005110 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5111 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5112 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005113 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005114 ndlp->nlp_usg_map, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04005115 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
5116 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04005117 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05005118 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04005119 if (rc) {
5120 mempool_free(mbox, phba->mbox_mem_pool);
5121 }
5122 else {
5123 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
5124 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
5125 mbox->vport = vport;
James Smart3e1f0712018-11-29 16:09:29 -08005126 mbox->ctx_ndlp = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04005127 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5128 if (rc == MBX_NOT_FINISHED) {
5129 mempool_free(mbox, phba->mbox_mem_pool);
5130 }
5131 }
5132 }
5133 }
James Smart2e0fef82007-06-17 19:56:36 -05005134 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04005135
James Smart2e0fef82007-06-17 19:56:36 -05005136 /*
James Smart466e8402015-05-21 13:55:28 -04005137 * ndlp->rport must be set to NULL before it reaches here
5138 * i.e. break rport/node link before doing lpfc_nlp_put for
5139 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05005140 */
James Smart92d7f7b2007-06-17 19:56:38 -05005141 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04005142 /*
5143 * extra lpfc_nlp_put dropped the reference of ndlp
5144 * for registered rport so need to cleanup rport
5145 */
5146 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
5147 "0940 removed node x%p DID x%x "
5148 " rport not null %p\n",
5149 ndlp, ndlp->nlp_DID, ndlp->rport);
5150 rport = ndlp->rport;
5151 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04005152 rdata->pnode = NULL;
5153 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04005154 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05005155 }
dea31012005-04-17 16:05:31 -05005156}
5157
5158static int
James Smart2e0fef82007-06-17 19:56:36 -05005159lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5160 uint32_t did)
dea31012005-04-17 16:05:31 -05005161{
James Smart2e0fef82007-06-17 19:56:36 -05005162 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005163
5164 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005165 return 0;
dea31012005-04-17 16:05:31 -05005166
dea31012005-04-17 16:05:31 -05005167 /* First check for Direct match */
5168 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005169 return 1;
dea31012005-04-17 16:05:31 -05005170
5171 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005172 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005173 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005174 return 0;
dea31012005-04-17 16:05:31 -05005175 }
5176
5177 matchdid.un.word = did;
5178 ndlpdid.un.word = ndlp->nlp_DID;
5179 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5180 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5181 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005182 /* This code is supposed to match the ID
5183 * for a private loop device that is
5184 * connect to fl_port. But we need to
5185 * check that the port did not just go
5186 * from pt2pt to fabric or we could end
5187 * up matching ndlp->nlp_DID 000001 to
5188 * fabric DID 0x20101
5189 */
dea31012005-04-17 16:05:31 -05005190 if ((ndlpdid.un.b.domain == 0) &&
5191 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005192 if (ndlpdid.un.b.id &&
5193 vport->phba->fc_topology ==
5194 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005195 return 1;
dea31012005-04-17 16:05:31 -05005196 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005197 return 0;
dea31012005-04-17 16:05:31 -05005198 }
5199
5200 matchdid.un.word = ndlp->nlp_DID;
5201 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5202 (mydid.un.b.area == ndlpdid.un.b.area)) {
5203 if ((matchdid.un.b.domain == 0) &&
5204 (matchdid.un.b.area == 0)) {
5205 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005206 return 1;
dea31012005-04-17 16:05:31 -05005207 }
5208 }
5209 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005210 return 0;
dea31012005-04-17 16:05:31 -05005211}
5212
James Smart685f0bf2007-04-25 09:53:08 -04005213/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005214static struct lpfc_nodelist *
5215__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005216{
James Smart2fb9bd82006-12-02 13:33:57 -05005217 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005218 uint32_t data1;
5219
James Smart2e0fef82007-06-17 19:56:36 -05005220 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5221 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04005222 data1 = (((uint32_t) ndlp->nlp_state << 24) |
5223 ((uint32_t) ndlp->nlp_xri << 16) |
5224 ((uint32_t) ndlp->nlp_type << 8) |
5225 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04005226 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5227 "0929 FIND node DID "
James Smartcff261f2013-12-17 20:29:47 -05005228 "Data: x%p x%x x%x x%x %p\n",
James Smarte8b62012007-08-02 11:10:09 -04005229 ndlp, ndlp->nlp_DID,
James Smartcff261f2013-12-17 20:29:47 -05005230 ndlp->nlp_flag, data1,
5231 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005232 return ndlp;
dea31012005-04-17 16:05:31 -05005233 }
5234 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005235
dea31012005-04-17 16:05:31 -05005236 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005237 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5238 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005239 return NULL;
5240}
5241
5242struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005243lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005244{
James Smart2e0fef82007-06-17 19:56:36 -05005245 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005246 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005247 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005248
James Smartfedd3b72011-02-16 12:39:24 -05005249 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005250 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005251 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005252 return ndlp;
5253}
5254
5255struct lpfc_nodelist *
5256lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5257{
5258 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5259 struct lpfc_nodelist *ndlp;
5260
5261 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005262 if (!ndlp) {
James Smart1c5b12f2017-04-21 16:05:03 -07005263 if (vport->phba->nvmet_support)
5264 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005265 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5266 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005267 return NULL;
James Smart9d3d3402017-04-21 16:05:00 -07005268 ndlp = lpfc_nlp_init(vport, did);
dea31012005-04-17 16:05:31 -05005269 if (!ndlp)
5270 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005271 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5272 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005273 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005274 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005275 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005276 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005277 if (vport->phba->nvmet_support)
5278 return NULL;
James Smarte47c9092008-02-08 18:49:26 -05005279 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
5280 if (!ndlp)
5281 return NULL;
5282 spin_lock_irq(shost->host_lock);
5283 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5284 spin_unlock_irq(shost->host_lock);
5285 return ndlp;
dea31012005-04-17 16:05:31 -05005286 }
James Smarte47c9092008-02-08 18:49:26 -05005287
James Smart1c5b12f2017-04-21 16:05:03 -07005288 /* The NVME Target does not want to actively manage an rport.
5289 * The goal is to allow the target to reset its state and clear
5290 * pending IO in preparation for the initiator to recover.
5291 */
James Smart58da1ff2008-04-07 10:15:56 -04005292 if ((vport->fc_flag & FC_RSCN_MODE) &&
5293 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005294 if (lpfc_rscn_payload_check(vport, did)) {
James Smart1c5b12f2017-04-21 16:05:03 -07005295
5296 /* Since this node is marked for discovery,
5297 * delay timeout is not needed.
5298 */
5299 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5300
5301 /* NVME Target mode waits until rport is known to be
5302 * impacted by the RSCN before it transitions. No
5303 * active management - just go to NPR provided the
5304 * node had a valid login.
5305 */
5306 if (vport->phba->nvmet_support)
5307 return ndlp;
5308
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005309 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005310 * we don't need to try to discover it again.
5311 */
5312 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
5313 return NULL;
5314
James Smarta257bf92009-04-06 18:48:10 -04005315 spin_lock_irq(shost->host_lock);
5316 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5317 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04005318 } else
dea31012005-04-17 16:05:31 -05005319 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005320 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07005321 /* If the initiator received a PLOGI from this NPort or if the
5322 * initiator is already in the process of discovery on it,
5323 * there's no need to try to discover it again.
James Smart87af33f2007-10-27 13:37:43 -04005324 */
James Smart685f0bf2007-04-25 09:53:08 -04005325 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005326 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
James Smart1c5b12f2017-04-21 16:05:03 -07005327 (!vport->phba->nvmet_support &&
5328 ndlp->nlp_flag & NLP_RCV_PLOGI))
dea31012005-04-17 16:05:31 -05005329 return NULL;
James Smart1c5b12f2017-04-21 16:05:03 -07005330
James Smart8c258642017-02-12 13:52:36 -08005331 if (vport->phba->nvmet_support)
5332 return ndlp;
James Smart1c5b12f2017-04-21 16:05:03 -07005333
5334 /* Moving to NPR state clears unsolicited flags and
5335 * allows for rediscovery
5336 */
5337 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5338
James Smart2e0fef82007-06-17 19:56:36 -05005339 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005340 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005341 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005342 }
5343 return ndlp;
5344}
5345
5346/* Build a list of nodes to discover based on the loopmap */
5347void
James Smart2e0fef82007-06-17 19:56:36 -05005348lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005349{
James Smart2e0fef82007-06-17 19:56:36 -05005350 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005351 int j;
5352 uint32_t alpa, index;
5353
James Smart2e0fef82007-06-17 19:56:36 -05005354 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005355 return;
James Smart2e0fef82007-06-17 19:56:36 -05005356
James Smart76a95d72010-11-20 23:11:48 -05005357 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005358 return;
dea31012005-04-17 16:05:31 -05005359
5360 /* Check for loop map present or not */
5361 if (phba->alpa_map[0]) {
5362 for (j = 1; j <= phba->alpa_map[0]; j++) {
5363 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005364 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005365 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005366 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005367 }
5368 } else {
5369 /* No alpamap, so try all alpa's */
5370 for (j = 0; j < FC_MAXLOOP; j++) {
5371 /* If cfg_scan_down is set, start from highest
5372 * ALPA (0xef) to lowest (0x1).
5373 */
James Smart3de2a652007-08-02 11:09:59 -04005374 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005375 index = j;
5376 else
5377 index = FC_MAXLOOP - j - 1;
5378 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005379 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005380 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005381 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005382 }
5383 }
5384 return;
5385}
5386
James Smart895427b2017-02-12 13:52:30 -08005387/* SLI3 only */
dea31012005-04-17 16:05:31 -05005388void
James Smart2e0fef82007-06-17 19:56:36 -05005389lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005390{
dea31012005-04-17 16:05:31 -05005391 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005392 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005393 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5394 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005395 int rc;
5396
James Smart92d7f7b2007-06-17 19:56:38 -05005397 /*
5398 * if it's not a physical port or if we already send
5399 * clear_la then don't send it.
5400 */
5401 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005402 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5403 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005404 return;
5405
James Smart2e0fef82007-06-17 19:56:36 -05005406 /* Link up discovery */
5407 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5408 phba->link_state = LPFC_CLEAR_LA;
5409 lpfc_clear_la(phba, mbox);
5410 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5411 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005412 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005413 if (rc == MBX_NOT_FINISHED) {
5414 mempool_free(mbox, phba->mbox_mem_pool);
5415 lpfc_disc_flush_list(vport);
5416 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5417 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005418 phba->link_state = LPFC_HBA_ERROR;
5419 }
5420 }
5421}
5422
5423/* Reg_vpi to tell firmware to resume normal operations */
5424void
5425lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5426{
5427 LPFC_MBOXQ_t *regvpimbox;
5428
5429 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5430 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005431 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005432 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5433 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005434 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005435 == MBX_NOT_FINISHED) {
5436 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005437 }
5438 }
5439}
5440
5441/* Start Link up / RSCN discovery on NPR nodes */
5442void
5443lpfc_disc_start(struct lpfc_vport *vport)
5444{
5445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5446 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005447 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005448 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005449
James Smarte74c03c2013-04-17 20:15:19 -04005450 if (!lpfc_is_link_up(phba)) {
5451 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5452 "3315 Link is not up %x\n",
5453 phba->link_state);
dea31012005-04-17 16:05:31 -05005454 return;
James Smarte74c03c2013-04-17 20:15:19 -04005455 }
James Smart2e0fef82007-06-17 19:56:36 -05005456
5457 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005458 clear_la_pending = 1;
5459 else
5460 clear_la_pending = 0;
5461
James Smart2e0fef82007-06-17 19:56:36 -05005462 if (vport->port_state < LPFC_VPORT_READY)
5463 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005464
James Smart2e0fef82007-06-17 19:56:36 -05005465 lpfc_set_disctmo(vport);
5466
James Smart2e0fef82007-06-17 19:56:36 -05005467 vport->fc_prevDID = vport->fc_myDID;
5468 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005469
5470 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005471 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5472 "0202 Start Discovery hba state x%x "
5473 "Data: x%x x%x x%x\n",
5474 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5475 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005476
5477 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005478 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005479
5480 if (num_sent)
5481 return;
5482
James Smart6fa139f2013-04-17 20:20:00 -04005483 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005484 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005485 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005486 !(vport->fc_flag & FC_RSCN_MODE) &&
5487 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005488 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005489 lpfc_issue_reg_vpi(phba, vport);
5490 return;
5491 }
James Smart2e0fef82007-06-17 19:56:36 -05005492
James Smart92d7f7b2007-06-17 19:56:38 -05005493 /*
5494 * For SLI2, we need to set port_state to READY and continue
5495 * discovery.
5496 */
5497 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5498 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005499 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005500
5501 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005502 vport->num_disc_nodes = 0;
5503 /* go thru NPR nodes and issue ELS PLOGIs */
5504 if (vport->fc_npr_cnt)
5505 lpfc_els_disc_plogi(vport);
5506
5507 if (!vport->num_disc_nodes) {
5508 spin_lock_irq(shost->host_lock);
5509 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5510 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005511 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005512 }
5513 }
James Smart92d7f7b2007-06-17 19:56:38 -05005514 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005515 } else {
5516 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005517 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005518
5519 if (num_sent)
5520 return;
5521
James Smart2e0fef82007-06-17 19:56:36 -05005522 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005523 /* Check to see if more RSCNs came in while we
5524 * were processing this one.
5525 */
James Smart2e0fef82007-06-17 19:56:36 -05005526 if ((vport->fc_rscn_id_cnt == 0) &&
5527 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5528 spin_lock_irq(shost->host_lock);
5529 vport->fc_flag &= ~FC_RSCN_MODE;
5530 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005531 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005532 } else
James Smart2e0fef82007-06-17 19:56:36 -05005533 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005534 }
5535 }
5536 return;
5537}
5538
5539/*
5540 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5541 * ring the match the sppecified nodelist.
5542 */
5543static void
James Smart2e0fef82007-06-17 19:56:36 -05005544lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005545{
James Smart2534ba72007-04-25 09:52:20 -04005546 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005547 IOCB_t *icmd;
5548 struct lpfc_iocbq *iocb, *next_iocb;
5549 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005550
James Smart895427b2017-02-12 13:52:30 -08005551 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07005552 if (unlikely(!pring))
5553 return;
dea31012005-04-17 16:05:31 -05005554
5555 /* Error matching iocb on txq or txcmplq
5556 * First check the txq.
5557 */
James Smart2e0fef82007-06-17 19:56:36 -05005558 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005559 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5560 if (iocb->context1 != ndlp) {
5561 continue;
5562 }
5563 icmd = &iocb->iocb;
5564 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5565 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5566
James Smart2534ba72007-04-25 09:52:20 -04005567 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005568 }
5569 }
5570
5571 /* Next check the txcmplq */
5572 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5573 if (iocb->context1 != ndlp) {
5574 continue;
5575 }
5576 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005577 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5578 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005579 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005580 }
5581 }
James Smart2e0fef82007-06-17 19:56:36 -05005582 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005583
James Smarta257bf92009-04-06 18:48:10 -04005584 /* Cancel all the IOCBs from the completions list */
5585 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5586 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005587}
5588
Adrian Bunka6ababd2007-11-05 18:07:33 +01005589static void
James Smart2e0fef82007-06-17 19:56:36 -05005590lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005591{
5592 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005593 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005594
James Smart2e0fef82007-06-17 19:56:36 -05005595 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5596 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005597 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005598 if (!NLP_CHK_NODE_ACT(ndlp))
5599 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005600 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5601 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5602 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005603 }
dea31012005-04-17 16:05:31 -05005604 }
5605 }
dea31012005-04-17 16:05:31 -05005606}
5607
James Smart92d7f7b2007-06-17 19:56:38 -05005608void
5609lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5610{
5611 lpfc_els_flush_rscn(vport);
5612 lpfc_els_flush_cmd(vport);
5613 lpfc_disc_flush_list(vport);
5614}
5615
dea31012005-04-17 16:05:31 -05005616/*****************************************************************************/
5617/*
5618 * NAME: lpfc_disc_timeout
5619 *
5620 * FUNCTION: Fibre Channel driver discovery timeout routine.
5621 *
5622 * EXECUTION ENVIRONMENT: interrupt only
5623 *
5624 * CALLED FROM:
5625 * Timer function
5626 *
5627 * RETURNS:
5628 * none
5629 */
5630/*****************************************************************************/
5631void
Kees Cookf22eb4d2017-09-06 20:24:26 -07005632lpfc_disc_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05005633{
Kees Cookf22eb4d2017-09-06 20:24:26 -07005634 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
James Smart2e0fef82007-06-17 19:56:36 -05005635 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005636 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005637 unsigned long flags = 0;
5638
5639 if (unlikely(!phba))
5640 return;
5641
James Smart5e9d9b82008-06-14 22:52:53 -04005642 spin_lock_irqsave(&vport->work_port_lock, flags);
5643 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5644 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005645 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005646 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005647
James Smart5e9d9b82008-06-14 22:52:53 -04005648 if (!tmo_posted)
5649 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005650 return;
5651}
5652
5653static void
James Smart2e0fef82007-06-17 19:56:36 -05005654lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005655{
James Smart2e0fef82007-06-17 19:56:36 -05005656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5657 struct lpfc_hba *phba = vport->phba;
5658 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005659 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005660 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005661 int rc, clrlaerr = 0;
5662
James Smart2e0fef82007-06-17 19:56:36 -05005663 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005664 return;
5665
James Smart2e0fef82007-06-17 19:56:36 -05005666 spin_lock_irq(shost->host_lock);
5667 vport->fc_flag &= ~FC_DISC_TMO;
5668 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005669
James Smart858c9f62007-06-17 19:56:39 -05005670 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5671 "disc timeout: state:x%x rtry:x%x flg:x%x",
5672 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5673
James Smart2e0fef82007-06-17 19:56:36 -05005674 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005675
5676 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005677 /*
5678 * port_state is identically LPFC_LOCAL_CFG_LINK while
5679 * waiting for FAN timeout
5680 */
James Smarte8b62012007-08-02 11:10:09 -04005681 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5682 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005683
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005684 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005685 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005686 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005687 if (!NLP_CHK_NODE_ACT(ndlp))
5688 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005689 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5690 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005691 if (ndlp->nlp_type & NLP_FABRIC) {
5692 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005693 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005694
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005695 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005696 /* Fail outstanding IO now since device
5697 * is marked for PLOGI.
5698 */
James Smart2e0fef82007-06-17 19:56:36 -05005699 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005700 }
5701 }
James Smart92d7f7b2007-06-17 19:56:38 -05005702 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005703 if (phba->sli_rev <= LPFC_SLI_REV3)
5704 lpfc_initial_flogi(vport);
5705 else
5706 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005707 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005708 }
dea31012005-04-17 16:05:31 -05005709 break;
5710
James Smart92d7f7b2007-06-17 19:56:38 -05005711 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005712 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005713 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005714 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005715 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5716 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005717 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005718
5719 /* Assume no Fabric and go on with discovery.
5720 * Check for outstanding ELS FLOGI to abort.
5721 */
5722
5723 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005724 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005725
5726 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005727 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005728 break;
5729
5730 case LPFC_FABRIC_CFG_LINK:
5731 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5732 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005733 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5734 "0223 Timeout while waiting for "
5735 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005736 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005737 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005738 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005739 lpfc_els_abort(phba, ndlp);
5740
5741 /* ReStart discovery */
5742 goto restart_disc;
dea31012005-04-17 16:05:31 -05005743
5744 case LPFC_NS_QRY:
5745 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005746 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5747 "0224 NameServer Query timeout "
5748 "Data: x%x x%x\n",
5749 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005750
James Smart92d7f7b2007-06-17 19:56:38 -05005751 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5752 /* Try it one more time */
5753 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005754 vport->gidft_inp = 0;
5755 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005756 if (rc == 0)
5757 break;
dea31012005-04-17 16:05:31 -05005758 }
James Smart92d7f7b2007-06-17 19:56:38 -05005759 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005760
James Smart87af33f2007-10-27 13:37:43 -04005761restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005762 /*
5763 * Discovery is over.
5764 * set port_state to PORT_READY if SLI2.
5765 * cmpl_reg_vpi will set port_state to READY for SLI3.
5766 */
James Smart3772a992009-05-22 14:50:54 -04005767 if (phba->sli_rev < LPFC_SLI_REV4) {
5768 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5769 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005770 else {
James Smart3772a992009-05-22 14:50:54 -04005771 lpfc_issue_clear_la(phba, vport);
5772 vport->port_state = LPFC_VPORT_READY;
5773 }
dea31012005-04-17 16:05:31 -05005774 }
5775
5776 /* Setup and issue mailbox INITIALIZE LINK command */
5777 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5778 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005779 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5780 "0206 Device Discovery "
5781 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005782 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005783 break;
5784 }
5785
5786 lpfc_linkdown(phba);
5787 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5788 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005789 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005790 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005791 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005792 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005793 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005794 if (rc == MBX_NOT_FINISHED)
5795 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5796
5797 break;
5798
5799 case LPFC_DISC_AUTH:
5800 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005801 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5802 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005803 lpfc_disc_flush_list(vport);
5804
James Smart92d7f7b2007-06-17 19:56:38 -05005805 /*
5806 * set port_state to PORT_READY if SLI2.
5807 * cmpl_reg_vpi will set port_state to READY for SLI3.
5808 */
James Smart3772a992009-05-22 14:50:54 -04005809 if (phba->sli_rev < LPFC_SLI_REV4) {
5810 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5811 lpfc_issue_reg_vpi(phba, vport);
5812 else { /* NPIV Not enabled */
5813 lpfc_issue_clear_la(phba, vport);
5814 vport->port_state = LPFC_VPORT_READY;
5815 }
dea31012005-04-17 16:05:31 -05005816 }
5817 break;
5818
James Smart2e0fef82007-06-17 19:56:36 -05005819 case LPFC_VPORT_READY:
5820 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04005821 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5822 "0231 RSCN timeout Data: x%x "
5823 "x%x\n",
5824 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005825
5826 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005827 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005828
James Smart2e0fef82007-06-17 19:56:36 -05005829 lpfc_els_flush_rscn(vport);
5830 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005831 }
5832 break;
James Smart2e0fef82007-06-17 19:56:36 -05005833
James Smart92d7f7b2007-06-17 19:56:38 -05005834 default:
James Smarte8b62012007-08-02 11:10:09 -04005835 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005836 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005837 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005838 break;
5839 }
5840
5841 switch (phba->link_state) {
5842 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005843 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005844 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5845 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005846 clrlaerr = 1;
5847 break;
5848
James Smart09372822008-01-11 01:52:54 -05005849 case LPFC_LINK_UP:
5850 lpfc_issue_clear_la(phba, vport);
5851 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05005852 case LPFC_LINK_UNKNOWN:
5853 case LPFC_WARM_START:
5854 case LPFC_INIT_START:
5855 case LPFC_INIT_MBX_CMDS:
5856 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005857 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005858 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5859 "0230 Unexpected timeout, hba link "
5860 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005861 clrlaerr = 1;
5862 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005863
5864 case LPFC_HBA_READY:
5865 break;
dea31012005-04-17 16:05:31 -05005866 }
5867
5868 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005869 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005870 if (phba->sli_rev != LPFC_SLI_REV4) {
5871 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5872 ~LPFC_STOP_IOCB_EVENT;
5873 psli->sli3_ring[LPFC_FCP_RING].flag &=
5874 ~LPFC_STOP_IOCB_EVENT;
5875 }
James Smart2e0fef82007-06-17 19:56:36 -05005876 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005877 }
dea31012005-04-17 16:05:31 -05005878 return;
5879}
5880
dea31012005-04-17 16:05:31 -05005881/*
5882 * This routine handles processing a NameServer REG_LOGIN mailbox
5883 * command upon completion. It is setup in the LPFC_MBOXQ
5884 * as the completion routine when the command is
5885 * handed off to the SLI layer.
5886 */
5887void
James Smart2e0fef82007-06-17 19:56:36 -05005888lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005889{
James Smart04c68492009-05-22 14:52:52 -04005890 MAILBOX_t *mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -08005891 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
5892 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005893 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005894
James Smart3e1f0712018-11-29 16:09:29 -08005895 pmb->ctx_buf = NULL;
5896 pmb->ctx_ndlp = NULL;
dea31012005-04-17 16:05:31 -05005897
James Smart6d368e52011-05-24 11:44:12 -04005898 if (phba->sli_rev < LPFC_SLI_REV4)
5899 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005900 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005901 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04005903 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5904 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5905 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005906 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005907 ndlp->nlp_usg_map, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005908 /*
5909 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05005910 * 0xfffffa (FDMI well known port).
5911 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5912 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05005913 */
James Smart4258e982015-12-16 18:11:58 -05005914 if (vport->port_type == LPFC_PHYSICAL_PORT)
5915 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04005916 else
James Smart4258e982015-12-16 18:11:58 -05005917 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
5918
dea31012005-04-17 16:05:31 -05005919
James Smartfa4066b2008-01-11 01:53:27 -05005920 /* decrement the node reference count held for this callback
5921 * function.
5922 */
James Smart329f9bc2007-04-25 09:53:01 -04005923 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005924 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5925 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04005926 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005927
5928 return;
5929}
5930
James Smart685f0bf2007-04-25 09:53:08 -04005931static int
5932lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5933{
5934 uint16_t *rpi = param;
5935
James Smarteff4a012012-01-18 16:25:25 -05005936 /* check for active node */
5937 if (!NLP_CHK_NODE_ACT(ndlp))
5938 return 0;
5939
James Smart685f0bf2007-04-25 09:53:08 -04005940 return ndlp->nlp_rpi == *rpi;
5941}
5942
5943static int
5944lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5945{
5946 return memcmp(&ndlp->nlp_portname, param,
5947 sizeof(ndlp->nlp_portname)) == 0;
5948}
5949
Adrian Bunka6ababd2007-11-05 18:07:33 +01005950static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005951__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05005952{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005953 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005954
James Smart2e0fef82007-06-17 19:56:36 -05005955 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04005956 if (filter(ndlp, param)) {
5957 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5958 "3185 FIND node filter %p DID "
James Smart49382502017-11-20 16:00:38 -08005959 "ndlp %p did x%x flg x%x st x%x "
5960 "xri x%x type x%x rpi x%x\n",
James Smart34f5ad82012-08-03 12:35:03 -04005961 filter, ndlp, ndlp->nlp_DID,
James Smart49382502017-11-20 16:00:38 -08005962 ndlp->nlp_flag, ndlp->nlp_state,
5963 ndlp->nlp_xri, ndlp->nlp_type,
5964 ndlp->nlp_rpi);
James Smart685f0bf2007-04-25 09:53:08 -04005965 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04005966 }
James Smart685f0bf2007-04-25 09:53:08 -04005967 }
James Smart34f5ad82012-08-03 12:35:03 -04005968 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5969 "3186 FIND node filter %p NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005970 return NULL;
dea31012005-04-17 16:05:31 -05005971}
5972
James Smart685f0bf2007-04-25 09:53:08 -04005973/*
5974 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05005975 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04005976 */
5977struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005978__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04005979{
James Smart2e0fef82007-06-17 19:56:36 -05005980 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04005981}
5982
James Smart488d1462006-03-07 15:02:37 -05005983/*
James Smart685f0bf2007-04-25 09:53:08 -04005984 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05005985 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05005986 */
5987struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005988lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05005989{
James Smart2e0fef82007-06-17 19:56:36 -05005990 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05005991 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05005992
James Smart2e0fef82007-06-17 19:56:36 -05005993 spin_lock_irq(shost->host_lock);
5994 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5995 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05005996 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05005997}
5998
James Smartcb69f7d2011-12-13 13:21:57 -05005999/*
6000 * This routine looks up the ndlp lists for the given RPI. If the rpi
6001 * is found, the routine returns the node element list pointer else
6002 * return NULL.
6003 */
6004struct lpfc_nodelist *
6005lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6006{
6007 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6008 struct lpfc_nodelist *ndlp;
6009
6010 spin_lock_irq(shost->host_lock);
6011 ndlp = __lpfc_findnode_rpi(vport, rpi);
6012 spin_unlock_irq(shost->host_lock);
6013 return ndlp;
6014}
6015
6016/**
6017 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6018 * @phba: pointer to lpfc hba data structure.
6019 * @vpi: the physical host virtual N_Port identifier.
6020 *
6021 * This routine finds a vport on a HBA (referred by @phba) through a
6022 * @vpi. The function walks the HBA's vport list and returns the address
6023 * of the vport with the matching @vpi.
6024 *
6025 * Return code
6026 * NULL - No vport with the matching @vpi found
6027 * Otherwise - Address to the vport with the matching @vpi.
6028 **/
6029struct lpfc_vport *
6030lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6031{
6032 struct lpfc_vport *vport;
6033 unsigned long flags;
6034 int i = 0;
6035
6036 /* The physical ports are always vpi 0 - translate is unnecessary. */
6037 if (vpi > 0) {
6038 /*
6039 * Translate the physical vpi to the logical vpi. The
6040 * vport stores the logical vpi.
6041 */
6042 for (i = 0; i < phba->max_vpi; i++) {
6043 if (vpi == phba->vpi_ids[i])
6044 break;
6045 }
6046
6047 if (i >= phba->max_vpi) {
6048 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
6049 "2936 Could not find Vport mapped "
6050 "to vpi %d\n", vpi);
6051 return NULL;
6052 }
6053 }
6054
James Smart523128e2018-09-10 10:30:46 -07006055 spin_lock_irqsave(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006056 list_for_each_entry(vport, &phba->port_list, listentry) {
6057 if (vport->vpi == i) {
James Smart523128e2018-09-10 10:30:46 -07006058 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006059 return vport;
6060 }
6061 }
James Smart523128e2018-09-10 10:30:46 -07006062 spin_unlock_irqrestore(&phba->port_list_lock, flags);
James Smartcb69f7d2011-12-13 13:21:57 -05006063 return NULL;
6064}
6065
James Smart9d3d3402017-04-21 16:05:00 -07006066struct lpfc_nodelist *
6067lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05006068{
James Smart9d3d3402017-04-21 16:05:00 -07006069 struct lpfc_nodelist *ndlp;
6070 int rpi = LPFC_RPI_ALLOC_ERROR;
6071
6072 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6073 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6074 if (rpi == LPFC_RPI_ALLOC_ERROR)
6075 return NULL;
6076 }
6077
6078 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6079 if (!ndlp) {
6080 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6081 lpfc_sli4_free_rpi(vport->phba, rpi);
6082 return NULL;
6083 }
6084
dea31012005-04-17 16:05:31 -05006085 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05006086
6087 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04006088 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05006089 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart9d3d3402017-04-21 16:05:00 -07006090 ndlp->nlp_rpi = rpi;
James Smartbe6bb942015-04-07 15:07:22 -04006091 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6092 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
6093 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
6094 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006095 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04006096 ndlp->nlp_usg_map, ndlp);
6097
James Smartcff261f2013-12-17 20:29:47 -05006098 ndlp->active_rrqs_xri_bitmap =
6099 mempool_alloc(vport->phba->active_rrq_pool,
6100 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04006101 if (ndlp->active_rrqs_xri_bitmap)
6102 memset(ndlp->active_rrqs_xri_bitmap, 0,
6103 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05006104 }
6105
James Smart725dd392013-10-10 12:23:30 -04006106
James Smart858c9f62007-06-17 19:56:39 -05006107
6108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6109 "node init: did:x%x",
6110 ndlp->nlp_DID, 0, 0);
6111
James Smart9d3d3402017-04-21 16:05:00 -07006112 return ndlp;
dea31012005-04-17 16:05:31 -05006113}
James Smart329f9bc2007-04-25 09:53:01 -04006114
James Smart98c9ea52007-10-27 13:37:33 -04006115/* This routine releases all resources associated with a specifc NPort's ndlp
6116 * and mempool_free's the nodelist.
6117 */
James Smart311464e2007-08-02 11:10:37 -04006118static void
James Smart329f9bc2007-04-25 09:53:01 -04006119lpfc_nlp_release(struct kref *kref)
6120{
James Smarte47c9092008-02-08 18:49:26 -05006121 struct lpfc_hba *phba;
6122 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04006123 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6124 kref);
James Smart858c9f62007-06-17 19:56:39 -05006125
6126 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6127 "node release: did:x%x flg:x%x type:x%x",
6128 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6129
James Smarte47c9092008-02-08 18:49:26 -05006130 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart939723a2012-05-09 21:19:03 -04006131 "0279 lpfc_nlp_release: ndlp:x%p did %x "
James Smartbe6bb942015-04-07 15:07:22 -04006132 "usgmap:x%x refcnt:%d rpi:%x\n",
James Smart939723a2012-05-09 21:19:03 -04006133 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006134 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006135
6136 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05006137 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05006138
6139 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04006140 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006141 spin_lock_irqsave(&phba->ndlp_lock, flags);
6142 NLP_CLR_NODE_ACT(ndlp);
6143 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart40426292010-12-15 17:58:10 -05006144 if (phba->sli_rev == LPFC_SLI_REV4)
6145 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05006146
6147 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04006148 if (NLP_CHK_FREE_REQ(ndlp)) {
6149 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05006150 if (phba->sli_rev == LPFC_SLI_REV4)
6151 mempool_free(ndlp->active_rrqs_xri_bitmap,
6152 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04006153 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04006154 }
James Smart329f9bc2007-04-25 09:53:01 -04006155}
6156
James Smart98c9ea52007-10-27 13:37:33 -04006157/* This routine bumps the reference count for a ndlp structure to ensure
6158 * that one discovery thread won't free a ndlp while another discovery thread
6159 * is using it.
6160 */
James Smart329f9bc2007-04-25 09:53:01 -04006161struct lpfc_nodelist *
6162lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6163{
James Smarte47c9092008-02-08 18:49:26 -05006164 struct lpfc_hba *phba;
6165 unsigned long flags;
6166
James Smart98c9ea52007-10-27 13:37:33 -04006167 if (ndlp) {
6168 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6169 "node get: did:x%x flg:x%x refcnt:x%x",
6170 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006171 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006172 /* The check of ndlp usage to prevent incrementing the
6173 * ndlp reference count that is in the process of being
6174 * released.
6175 */
James Smarta257bf92009-04-06 18:48:10 -04006176 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006177 spin_lock_irqsave(&phba->ndlp_lock, flags);
6178 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
6179 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6180 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6181 "0276 lpfc_nlp_get: ndlp:x%p "
6182 "usgmap:x%x refcnt:%d\n",
6183 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006184 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006185 return NULL;
6186 } else
6187 kref_get(&ndlp->kref);
6188 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04006189 }
James Smart329f9bc2007-04-25 09:53:01 -04006190 return ndlp;
6191}
6192
James Smart98c9ea52007-10-27 13:37:33 -04006193/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05006194 * count goes to 0, this indicates the the associated nodelist should be
6195 * freed. Returning 1 indicates the ndlp resource has been released; on the
6196 * other hand, returning 0 indicates the ndlp resource has not been released
6197 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04006198 */
James Smart329f9bc2007-04-25 09:53:01 -04006199int
6200lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6201{
James Smarte47c9092008-02-08 18:49:26 -05006202 struct lpfc_hba *phba;
6203 unsigned long flags;
6204
6205 if (!ndlp)
6206 return 1;
6207
6208 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6209 "node put: did:x%x flg:x%x refcnt:x%x",
6210 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006211 kref_read(&ndlp->kref));
James Smarta257bf92009-04-06 18:48:10 -04006212 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006213 spin_lock_irqsave(&phba->ndlp_lock, flags);
6214 /* Check the ndlp memory free acknowledge flag to avoid the
6215 * possible race condition that kref_put got invoked again
6216 * after previous one has done ndlp memory free.
6217 */
6218 if (NLP_CHK_FREE_ACK(ndlp)) {
6219 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6220 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6221 "0274 lpfc_nlp_put: ndlp:x%p "
6222 "usgmap:x%x refcnt:%d\n",
6223 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006224 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006225 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006226 }
James Smarte47c9092008-02-08 18:49:26 -05006227 /* Check the ndlp inactivate log flag to avoid the possible
6228 * race condition that kref_put got invoked again after ndlp
6229 * is already in inactivating state.
6230 */
6231 if (NLP_CHK_IACT_REQ(ndlp)) {
6232 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6233 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6234 "0275 lpfc_nlp_put: ndlp:x%p "
6235 "usgmap:x%x refcnt:%d\n",
6236 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006237 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006238 return 1;
6239 }
6240 /* For last put, mark the ndlp usage flags to make sure no
6241 * other kref_get and kref_put on the same ndlp shall get
6242 * in between the process when the final kref_put has been
6243 * invoked on this ndlp.
6244 */
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006245 if (kref_read(&ndlp->kref) == 1) {
James Smarte47c9092008-02-08 18:49:26 -05006246 /* Indicate ndlp is put to inactive state. */
6247 NLP_SET_IACT_REQ(ndlp);
6248 /* Acknowledge ndlp memory free has been seen. */
6249 if (NLP_CHK_FREE_REQ(ndlp))
6250 NLP_SET_FREE_ACK(ndlp);
6251 }
6252 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6253 /* Note, the kref_put returns 1 when decrementing a reference
6254 * count that was 1, it invokes the release callback function,
6255 * but it still left the reference count as 1 (not actually
6256 * performs the last decrementation). Otherwise, it actually
6257 * decrements the reference count and returns 0.
6258 */
6259 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04006260}
James Smart98c9ea52007-10-27 13:37:33 -04006261
6262/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006263 * by any other discovery thread. This routine returns 1 if the
6264 * ndlp has been freed. A return value of 0 indicates the ndlp is
6265 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006266 */
6267int
6268lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6269{
6270 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6271 "node not used: did:x%x flg:x%x refcnt:x%x",
6272 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006273 kref_read(&ndlp->kref));
6274 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006275 if (lpfc_nlp_put(ndlp))
6276 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006277 return 0;
6278}
James Smart6fb120a2009-05-22 14:52:59 -04006279
6280/**
6281 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6282 * @phba: Pointer to hba context object.
6283 *
6284 * This function iterate through all FC nodes associated
6285 * will all vports to check if there is any node with
6286 * fc_rports associated with it. If there is an fc_rport
6287 * associated with the node, then the node is either in
6288 * discovered state or its devloss_timer is pending.
6289 */
6290static int
6291lpfc_fcf_inuse(struct lpfc_hba *phba)
6292{
6293 struct lpfc_vport **vports;
6294 int i, ret = 0;
6295 struct lpfc_nodelist *ndlp;
6296 struct Scsi_Host *shost;
6297
6298 vports = lpfc_create_vport_work_array(phba);
6299
James Smart63e801c2010-11-20 23:14:19 -05006300 /* If driver cannot allocate memory, indicate fcf is in use */
6301 if (!vports)
6302 return 1;
6303
James Smart6fb120a2009-05-22 14:52:59 -04006304 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6305 shost = lpfc_shost_from_vport(vports[i]);
6306 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006307 /*
6308 * IF the CVL_RCVD bit is not set then we have sent the
6309 * flogi.
6310 * If dev_loss fires while we are waiting we do not want to
6311 * unreg the fcf.
6312 */
6313 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6314 spin_unlock_irq(shost->host_lock);
6315 ret = 1;
6316 goto out;
6317 }
James Smart6fb120a2009-05-22 14:52:59 -04006318 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6319 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6320 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6321 ret = 1;
6322 spin_unlock_irq(shost->host_lock);
6323 goto out;
James Smart80c17842012-03-01 22:35:45 -05006324 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6325 ret = 1;
James Smart891478a2009-11-18 15:40:23 -05006326 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart80c17842012-03-01 22:35:45 -05006327 "2624 RPI %x DID %x flag %x "
6328 "still logged in\n",
6329 ndlp->nlp_rpi, ndlp->nlp_DID,
6330 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006331 }
6332 }
6333 spin_unlock_irq(shost->host_lock);
6334 }
6335out:
6336 lpfc_destroy_vport_work_array(phba, vports);
6337 return ret;
6338}
6339
6340/**
6341 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6342 * @phba: Pointer to hba context object.
6343 * @mboxq: Pointer to mailbox object.
6344 *
6345 * This function frees memory associated with the mailbox command.
6346 */
James Smart1b511972011-12-13 13:23:09 -05006347void
James Smart6fb120a2009-05-22 14:52:59 -04006348lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6349{
6350 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006351 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006352
6353 if (mboxq->u.mb.mbxStatus) {
6354 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6355 "2555 UNREG_VFI mbxStatus error x%x "
6356 "HBA state x%x\n",
6357 mboxq->u.mb.mbxStatus, vport->port_state);
6358 }
James Smart38b92ef2010-08-04 16:11:39 -04006359 spin_lock_irq(shost->host_lock);
6360 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6361 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006362 mempool_free(mboxq, phba->mbox_mem_pool);
6363 return;
6364}
6365
6366/**
6367 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6368 * @phba: Pointer to hba context object.
6369 * @mboxq: Pointer to mailbox object.
6370 *
6371 * This function frees memory associated with the mailbox command.
6372 */
6373static void
6374lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6375{
6376 struct lpfc_vport *vport = mboxq->vport;
6377
6378 if (mboxq->u.mb.mbxStatus) {
6379 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6380 "2550 UNREG_FCFI mbxStatus error x%x "
6381 "HBA state x%x\n",
6382 mboxq->u.mb.mbxStatus, vport->port_state);
6383 }
6384 mempool_free(mboxq, phba->mbox_mem_pool);
6385 return;
6386}
6387
6388/**
James Smartecfd03c2010-02-12 14:41:27 -05006389 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006390 * @phba: Pointer to hba context object.
6391 *
James Smartecfd03c2010-02-12 14:41:27 -05006392 * This function prepare the HBA for unregistering the currently registered
6393 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6394 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006395 */
James Smartecfd03c2010-02-12 14:41:27 -05006396int
6397lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006398{
James Smart6fb120a2009-05-22 14:52:59 -04006399 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006400 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006401 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006402 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006403
James Smartecfd03c2010-02-12 14:41:27 -05006404 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006405 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006406 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006407
James Smart4d9ab992009-10-02 15:16:39 -04006408 /* At this point, all discovery is aborted */
6409 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006410
6411 /* Unregister VPIs */
6412 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006413 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006414 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006415 /* Stop FLOGI/FDISC retries */
6416 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6417 if (ndlp)
6418 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006419 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006420 if (phba->sli_rev == LPFC_SLI_REV4)
6421 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006422 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006423 shost = lpfc_shost_from_vport(vports[i]);
6424 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006425 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006426 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006427 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006428 }
6429 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006430 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6431 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6432 if (ndlp)
6433 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6434 lpfc_cleanup_pending_mbox(phba->pport);
6435 if (phba->sli_rev == LPFC_SLI_REV4)
6436 lpfc_sli4_unreg_all_rpis(phba->pport);
6437 lpfc_mbx_unreg_vpi(phba->pport);
6438 shost = lpfc_shost_from_vport(phba->pport);
6439 spin_lock_irq(shost->host_lock);
6440 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6441 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6442 spin_unlock_irq(shost->host_lock);
6443 }
James Smart6fb120a2009-05-22 14:52:59 -04006444
James Smart695a8142010-01-26 23:08:03 -05006445 /* Cleanup any outstanding ELS commands */
6446 lpfc_els_flush_all_cmd(phba);
6447
James Smart1b511972011-12-13 13:23:09 -05006448 /* Unregister the physical port VFI */
6449 rc = lpfc_issue_unreg_vfi(phba->pport);
6450 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006451}
6452
6453/**
6454 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6455 * @phba: Pointer to hba context object.
6456 *
6457 * This function issues synchronous unregister FCF mailbox command to HBA to
6458 * unregister the currently registered FCF record. The driver does not reset
6459 * the driver FCF usage state flags.
6460 *
6461 * Return 0 if successfully issued, none-zero otherwise.
6462 */
6463int
6464lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6465{
6466 LPFC_MBOXQ_t *mbox;
6467 int rc;
6468
James Smart6fb120a2009-05-22 14:52:59 -04006469 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6470 if (!mbox) {
6471 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006472 "2551 UNREG_FCFI mbox allocation failed"
6473 "HBA state x%x\n", phba->pport->port_state);
6474 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006475 }
James Smart6fb120a2009-05-22 14:52:59 -04006476 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6477 mbox->vport = phba->pport;
6478 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6479 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6480
6481 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006482 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6483 "2552 Unregister FCFI command failed rc x%x "
6484 "HBA state x%x\n",
6485 rc, phba->pport->port_state);
6486 return -EINVAL;
6487 }
6488 return 0;
6489}
6490
6491/**
6492 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6493 * @phba: Pointer to hba context object.
6494 *
6495 * This function unregisters the currently reigstered FCF. This function
6496 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6497 */
6498void
6499lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6500{
6501 int rc;
6502
6503 /* Preparation for unregistering fcf */
6504 rc = lpfc_unregister_fcf_prep(phba);
6505 if (rc) {
6506 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6507 "2748 Failed to prepare for unregistering "
6508 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006509 return;
6510 }
6511
James Smartecfd03c2010-02-12 14:41:27 -05006512 /* Now, unregister FCF record and reset HBA FCF state */
6513 rc = lpfc_sli4_unregister_fcf(phba);
6514 if (rc)
6515 return;
6516 /* Reset HBA FCF states after successful unregister FCF */
6517 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006518 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006519
6520 /*
6521 * If driver is not unloading, check if there is any other
6522 * FCF record that can be used for discovery.
6523 */
6524 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006525 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006526 return;
6527
James Smart0c9ab6f2010-02-26 14:15:57 -05006528 /* This is considered as the initial FCF discovery scan */
6529 spin_lock_irq(&phba->hbalock);
6530 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6531 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006532
6533 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006534 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006535
James Smart0c9ab6f2010-02-26 14:15:57 -05006536 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006537
James Smart0c9ab6f2010-02-26 14:15:57 -05006538 if (rc) {
6539 spin_lock_irq(&phba->hbalock);
6540 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6541 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006542 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006543 "2553 lpfc_unregister_unused_fcf failed "
6544 "to read FCF record HBA state x%x\n",
6545 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006546 }
James Smartecfd03c2010-02-12 14:41:27 -05006547}
6548
6549/**
6550 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6551 * @phba: Pointer to hba context object.
6552 *
6553 * This function just unregisters the currently reigstered FCF. It does not
6554 * try to find another FCF for discovery.
6555 */
6556void
6557lpfc_unregister_fcf(struct lpfc_hba *phba)
6558{
6559 int rc;
6560
6561 /* Preparation for unregistering fcf */
6562 rc = lpfc_unregister_fcf_prep(phba);
6563 if (rc) {
6564 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6565 "2749 Failed to prepare for unregistering "
6566 "HBA's FCF record: rc=%d\n", rc);
6567 return;
6568 }
6569
6570 /* Now, unregister FCF record and reset HBA FCF state */
6571 rc = lpfc_sli4_unregister_fcf(phba);
6572 if (rc)
6573 return;
6574 /* Set proper HBA FCF states after successful unregister FCF */
6575 spin_lock_irq(&phba->hbalock);
6576 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6577 spin_unlock_irq(&phba->hbalock);
6578}
6579
6580/**
6581 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6582 * @phba: Pointer to hba context object.
6583 *
6584 * This function check if there are any connected remote port for the FCF and
6585 * if all the devices are disconnected, this function unregister FCFI.
6586 * This function also tries to use another FCF for discovery.
6587 */
6588void
6589lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6590{
6591 /*
James Smart3804dc82010-07-14 15:31:37 -04006592 * If HBA is not running in FIP mode, if HBA does not support
6593 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6594 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006595 */
6596 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006597 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006598 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006599 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006600 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006601 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006602 spin_unlock_irq(&phba->hbalock);
6603 return;
6604 }
6605 spin_unlock_irq(&phba->hbalock);
6606
6607 if (lpfc_fcf_inuse(phba))
6608 return;
6609
6610 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006611}
6612
6613/**
6614 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6615 * @phba: Pointer to hba context object.
6616 * @buff: Buffer containing the FCF connection table as in the config
6617 * region.
6618 * This function create driver data structure for the FCF connection
6619 * record table read from config region 23.
6620 */
6621static void
6622lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6623 uint8_t *buff)
6624{
6625 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6626 struct lpfc_fcf_conn_hdr *conn_hdr;
6627 struct lpfc_fcf_conn_rec *conn_rec;
6628 uint32_t record_count;
6629 int i;
6630
6631 /* Free the current connect table */
6632 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006633 &phba->fcf_conn_rec_list, list) {
6634 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006635 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006636 }
James Smart6fb120a2009-05-22 14:52:59 -04006637
6638 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6639 record_count = conn_hdr->length * sizeof(uint32_t)/
6640 sizeof(struct lpfc_fcf_conn_rec);
6641
6642 conn_rec = (struct lpfc_fcf_conn_rec *)
6643 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6644
6645 for (i = 0; i < record_count; i++) {
6646 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6647 continue;
6648 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6649 GFP_KERNEL);
6650 if (!conn_entry) {
6651 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6652 "2566 Failed to allocate connection"
6653 " table entry\n");
6654 return;
6655 }
6656
6657 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6658 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006659 list_add_tail(&conn_entry->list,
6660 &phba->fcf_conn_rec_list);
6661 }
James Smartdf0d0852013-05-31 17:05:08 -04006662
6663 if (!list_empty(&phba->fcf_conn_rec_list)) {
6664 i = 0;
6665 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6666 list) {
6667 conn_rec = &conn_entry->conn_rec;
6668 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6669 "3345 FCF connection list rec[%02d]: "
6670 "flags:x%04x, vtag:x%04x, "
6671 "fabric_name:x%02x:%02x:%02x:%02x:"
6672 "%02x:%02x:%02x:%02x, "
6673 "switch_name:x%02x:%02x:%02x:%02x:"
6674 "%02x:%02x:%02x:%02x\n", i++,
6675 conn_rec->flags, conn_rec->vlan_tag,
6676 conn_rec->fabric_name[0],
6677 conn_rec->fabric_name[1],
6678 conn_rec->fabric_name[2],
6679 conn_rec->fabric_name[3],
6680 conn_rec->fabric_name[4],
6681 conn_rec->fabric_name[5],
6682 conn_rec->fabric_name[6],
6683 conn_rec->fabric_name[7],
6684 conn_rec->switch_name[0],
6685 conn_rec->switch_name[1],
6686 conn_rec->switch_name[2],
6687 conn_rec->switch_name[3],
6688 conn_rec->switch_name[4],
6689 conn_rec->switch_name[5],
6690 conn_rec->switch_name[6],
6691 conn_rec->switch_name[7]);
6692 }
6693 }
James Smart6fb120a2009-05-22 14:52:59 -04006694}
6695
6696/**
6697 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6698 * @phba: Pointer to hba context object.
6699 * @buff: Buffer containing the FCoE parameter data structure.
6700 *
6701 * This function update driver data structure with config
6702 * parameters read from config region 23.
6703 */
6704static void
6705lpfc_read_fcoe_param(struct lpfc_hba *phba,
6706 uint8_t *buff)
6707{
6708 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6709 struct lpfc_fcoe_params *fcoe_param;
6710
6711 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6712 buff;
6713 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006714 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006715
6716 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6717 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6718 return;
6719
James Smart6fb120a2009-05-22 14:52:59 -04006720 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6721 phba->valid_vlan = 1;
6722 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6723 0xFFF;
6724 }
6725
6726 phba->fc_map[0] = fcoe_param->fc_map[0];
6727 phba->fc_map[1] = fcoe_param->fc_map[1];
6728 phba->fc_map[2] = fcoe_param->fc_map[2];
6729 return;
6730}
6731
6732/**
6733 * lpfc_get_rec_conf23 - Get a record type in config region data.
6734 * @buff: Buffer containing config region 23 data.
6735 * @size: Size of the data buffer.
6736 * @rec_type: Record type to be searched.
6737 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006738 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006739 * of the record specified by record_type. If record found, this
6740 * function return pointer to the record else return NULL.
6741 */
6742static uint8_t *
6743lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6744{
6745 uint32_t offset = 0, rec_length;
6746
6747 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6748 (size < sizeof(uint32_t)))
6749 return NULL;
6750
6751 rec_length = buff[offset + 1];
6752
6753 /*
6754 * One TLV record has one word header and number of data words
6755 * specified in the rec_length field of the record header.
6756 */
6757 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6758 <= size) {
6759 if (buff[offset] == rec_type)
6760 return &buff[offset];
6761
6762 if (buff[offset] == LPFC_REGION23_LAST_REC)
6763 return NULL;
6764
6765 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6766 rec_length = buff[offset + 1];
6767 }
6768 return NULL;
6769}
6770
6771/**
6772 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6773 * @phba: Pointer to lpfc_hba data structure.
6774 * @buff: Buffer containing config region 23 data.
6775 * @size: Size of the data buffer.
6776 *
Stefan Weileef35c22010-08-06 21:11:15 +02006777 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006778 * populate driver data structure with the parameters.
6779 */
6780void
6781lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6782 uint8_t *buff,
6783 uint32_t size)
6784{
James Smarteb016562014-09-03 12:58:06 -04006785 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006786 uint8_t *rec_ptr;
6787
6788 /*
6789 * If data size is less than 2 words signature and version cannot be
6790 * verified.
6791 */
6792 if (size < 2*sizeof(uint32_t))
6793 return;
6794
6795 /* Check the region signature first */
6796 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6798 "2567 Config region 23 has bad signature\n");
6799 return;
6800 }
6801
6802 offset += 4;
6803
6804 /* Check the data structure version */
6805 if (buff[offset] != LPFC_REGION23_VERSION) {
6806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6807 "2568 Config region 23 has bad version\n");
6808 return;
6809 }
6810 offset += 4;
6811
James Smart6fb120a2009-05-22 14:52:59 -04006812 /* Read FCoE param record */
6813 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6814 size - offset, FCOE_PARAM_TYPE);
6815 if (rec_ptr)
6816 lpfc_read_fcoe_param(phba, rec_ptr);
6817
6818 /* Read FCF connection table */
6819 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6820 size - offset, FCOE_CONN_TBL_TYPE);
6821 if (rec_ptr)
6822 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6823
6824}