blob: 194a14d5f8a9821bf7c3ddc562049db294ce3e07 [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 Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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 Smart2e0fef82007-06-17 19:56:36 -0500316 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400317 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400318 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400319 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400320 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
321 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500322 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400323
James Smarta93ff372010-10-22 11:06:08 -0400324 return fcf_inuse;
325}
326
327/**
328 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
329 * @phba: Pointer to hba context object.
330 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
331 * @nlp_did: remote node identifer with devloss timeout.
332 *
333 * This function is called from the worker thread after invoking devloss
334 * timeout handler and releasing the reference count for the ndlp with
335 * which the devloss timeout was handled for SLI4 host. For the devloss
336 * timeout of the last remote node which had been in use of FCF, when this
337 * routine is invoked, it shall be guaranteed that none of the remote are
338 * in-use of FCF. When devloss timeout to the last remote using the FCF,
339 * if the FIP engine is neither in FCF table scan process nor roundrobin
340 * failover process, the in-use FCF shall be unregistered. If the FIP
341 * engine is in FCF discovery process, the devloss timeout state shall
342 * be set for either the FCF table scan process or roundrobin failover
343 * process to unregister the in-use FCF.
344 **/
345static void
346lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
347 uint32_t nlp_did)
348{
349 /* If devloss timeout happened to a remote node when FCF had no
350 * longer been in-use, do nothing.
351 */
352 if (!fcf_inuse)
353 return;
354
355 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
356 spin_lock_irq(&phba->hbalock);
357 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
358 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
359 spin_unlock_irq(&phba->hbalock);
360 return;
361 }
362 phba->hba_flag |= HBA_DEVLOSS_TMO;
363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
364 "2847 Last remote node (x%x) using "
365 "FCF devloss tmo\n", nlp_did);
366 }
367 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
368 spin_unlock_irq(&phba->hbalock);
369 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
370 "2868 Devloss tmo to FCF rediscovery "
371 "in progress\n");
372 return;
373 }
374 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
375 spin_unlock_irq(&phba->hbalock);
376 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
377 "2869 Devloss tmo to idle FIP engine, "
378 "unreg in-use FCF and rescan.\n");
379 /* Unregister in-use FCF and rescan */
380 lpfc_unregister_fcf_rescan(phba);
381 return;
382 }
383 spin_unlock_irq(&phba->hbalock);
384 if (phba->hba_flag & FCF_TS_INPROG)
385 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
386 "2870 FCF table scan in progress\n");
387 if (phba->hba_flag & FCF_RR_INPROG)
388 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
389 "2871 FLOGI roundrobin FCF failover "
390 "in progress\n");
391 }
James Smart6fb120a2009-05-22 14:52:59 -0400392 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500393}
James Smartc01f3202006-08-18 17:47:08 -0400394
James Smartea2151b2008-09-07 11:52:10 -0400395/**
James Smart3621a712009-04-06 18:47:14 -0400396 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400397 * @phba: Pointer to hba context object.
398 *
399 * This function is called from the functions which need to post
400 * events from interrupt context. This function allocates data
401 * structure required for posting event. It also keeps track of
402 * number of events pending and prevent event storm when there are
403 * too many events.
404 **/
405struct lpfc_fast_path_event *
406lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
407 struct lpfc_fast_path_event *ret;
408
409 /* If there are lot of fast event do not exhaust memory due to this */
410 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
411 return NULL;
412
413 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
414 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400415 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400416 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400417 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
418 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
419 }
James Smartea2151b2008-09-07 11:52:10 -0400420 return ret;
421}
422
423/**
James Smart3621a712009-04-06 18:47:14 -0400424 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400425 * @phba: Pointer to hba context object.
426 * @evt: Event object which need to be freed.
427 *
428 * This function frees the data structure required for posting
429 * events.
430 **/
431void
432lpfc_free_fast_evt(struct lpfc_hba *phba,
433 struct lpfc_fast_path_event *evt) {
434
435 atomic_dec(&phba->fast_event_count);
436 kfree(evt);
437}
438
439/**
James Smart3621a712009-04-06 18:47:14 -0400440 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400441 * @phba: Pointer to hba context object.
442 * @evtp: Event data structure.
443 *
444 * This function is called from worker thread, when the interrupt
445 * context need to post an event. This function posts the event
446 * to fc transport netlink interface.
447 **/
448static void
449lpfc_send_fastpath_evt(struct lpfc_hba *phba,
450 struct lpfc_work_evt *evtp)
451{
452 unsigned long evt_category, evt_sub_category;
453 struct lpfc_fast_path_event *fast_evt_data;
454 char *evt_data;
455 uint32_t evt_data_size;
456 struct Scsi_Host *shost;
457
458 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
459 work_evt);
460
461 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
462 evt_sub_category = (unsigned long) fast_evt_data->un.
463 fabric_evt.subcategory;
464 shost = lpfc_shost_from_vport(fast_evt_data->vport);
465 if (evt_category == FC_REG_FABRIC_EVENT) {
466 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
467 evt_data = (char *) &fast_evt_data->un.read_check_error;
468 evt_data_size = sizeof(fast_evt_data->un.
469 read_check_error);
470 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500471 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400472 evt_data = (char *) &fast_evt_data->un.fabric_evt;
473 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
474 } else {
475 lpfc_free_fast_evt(phba, fast_evt_data);
476 return;
477 }
478 } else if (evt_category == FC_REG_SCSI_EVENT) {
479 switch (evt_sub_category) {
480 case LPFC_EVENT_QFULL:
481 case LPFC_EVENT_DEVBSY:
482 evt_data = (char *) &fast_evt_data->un.scsi_evt;
483 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
484 break;
485 case LPFC_EVENT_CHECK_COND:
486 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
487 evt_data_size = sizeof(fast_evt_data->un.
488 check_cond_evt);
489 break;
490 case LPFC_EVENT_VARQUEDEPTH:
491 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
492 evt_data_size = sizeof(fast_evt_data->un.
493 queue_depth_evt);
494 break;
495 default:
496 lpfc_free_fast_evt(phba, fast_evt_data);
497 return;
498 }
499 } else {
500 lpfc_free_fast_evt(phba, fast_evt_data);
501 return;
502 }
503
James Smart895427b2017-02-12 13:52:30 -0800504 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
505 fc_host_post_vendor_event(shost,
506 fc_get_event_number(),
507 evt_data_size,
508 evt_data,
509 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400510
511 lpfc_free_fast_evt(phba, fast_evt_data);
512 return;
513}
514
dea31012005-04-17 16:05:31 -0500515static void
James Smart2e0fef82007-06-17 19:56:36 -0500516lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500517{
518 struct lpfc_work_evt *evtp = NULL;
519 struct lpfc_nodelist *ndlp;
520 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400521 int fcf_inuse;
522 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500523
James Smart2e0fef82007-06-17 19:56:36 -0500524 spin_lock_irq(&phba->hbalock);
525 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500526 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
527 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500528 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500529 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500530 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500531 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500532 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500533 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500534 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500535 /* decrement the node reference count held
536 * for this queued work
537 */
538 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500539 break;
James Smart858c9f62007-06-17 19:56:39 -0500540 case LPFC_EVT_DEV_LOSS:
541 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400542 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500543 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500544 /* decrement the node reference count held for
545 * this queued work
546 */
James Smarta93ff372010-10-22 11:06:08 -0400547 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500548 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400549 if (phba->sli_rev == LPFC_SLI_REV4)
550 lpfc_sli4_post_dev_loss_tmo_handler(phba,
551 fcf_inuse,
552 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500553 break;
dea31012005-04-17 16:05:31 -0500554 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500555 if (phba->link_state < LPFC_LINK_DOWN)
556 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500557 else
James Smart2e0fef82007-06-17 19:56:36 -0500558 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500559 complete((struct completion *)(evtp->evt_arg2));
560 break;
James Smart46fa3112007-04-25 09:51:45 -0400561 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500562 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400563 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400564 *(int *)(evtp->evt_arg1) = 0;
565 complete((struct completion *)(evtp->evt_arg2));
566 break;
567 case LPFC_EVT_OFFLINE:
568 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500569 lpfc_sli_brdrestart(phba);
570 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400571 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
572 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500573 complete((struct completion *)(evtp->evt_arg2));
574 break;
575 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400576 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500577 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500578 lpfc_sli_brdreset(phba);
579 lpfc_hba_down_post(phba);
580 *(int *)(evtp->evt_arg1) =
581 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400582 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500583 complete((struct completion *)(evtp->evt_arg2));
584 break;
585 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400586 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500587 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500588 = (phba->pport->stopped)
589 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400590 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500591 complete((struct completion *)(evtp->evt_arg2));
592 break;
James Smartea2151b2008-09-07 11:52:10 -0400593 case LPFC_EVT_FASTPATH_MGMT_EVT:
594 lpfc_send_fastpath_evt(phba, evtp);
595 free_evt = 0;
596 break;
James Smart78730cf2010-04-06 15:06:30 -0400597 case LPFC_EVT_RESET_HBA:
598 if (!(phba->pport->load_flag & FC_UNLOADING))
599 lpfc_reset_hba(phba);
600 break;
dea31012005-04-17 16:05:31 -0500601 }
602 if (free_evt)
603 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500604 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500605 }
James Smart2e0fef82007-06-17 19:56:36 -0500606 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500607
608}
609
James Smart311464e2007-08-02 11:10:37 -0400610static void
James Smart2e0fef82007-06-17 19:56:36 -0500611lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500612{
613 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500614 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400615 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400616 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400617 int i;
dea31012005-04-17 16:05:31 -0500618
James Smart2e0fef82007-06-17 19:56:36 -0500619 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500620 ha_copy = phba->work_ha;
621 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500622 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500623
James Smartda0436e2009-05-22 14:51:39 -0400624 /* First, try to post the next mailbox command to SLI4 device */
625 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
626 lpfc_sli4_post_async_mbox(phba);
627
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500628 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400629 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500630 lpfc_handle_eratt(phba);
631
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500632 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500633 lpfc_sli_handle_mb_event(phba);
634
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500635 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500636 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400637
James Smartda0436e2009-05-22 14:51:39 -0400638 /* Process SLI4 events */
639 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500640 if (phba->hba_flag & HBA_RRQ_ACTIVE)
641 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400642 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
643 lpfc_sli4_fcp_xri_abort_event_proc(phba);
644 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
645 lpfc_sli4_els_xri_abort_event_proc(phba);
646 if (phba->hba_flag & ASYNC_EVENT)
647 lpfc_sli4_async_event_proc(phba);
648 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
649 spin_lock_irq(&phba->hbalock);
650 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
651 spin_unlock_irq(&phba->hbalock);
652 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
653 }
James Smartecfd03c2010-02-12 14:41:27 -0500654 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
655 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400656 }
657
James Smart549e55c2007-08-02 11:09:51 -0400658 vports = lpfc_create_vport_work_array(phba);
659 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400660 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400661 /*
662 * We could have no vports in array if unloading, so if
663 * this happens then just use the pport
664 */
665 if (vports[i] == NULL && i == 0)
666 vport = phba->pport;
667 else
668 vport = vports[i];
669 if (vport == NULL)
670 break;
James Smart58da1ff2008-04-07 10:15:56 -0400671 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400672 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400673 vport->work_port_events &= ~work_port_events;
674 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400675 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400676 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400677 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400678 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400679 if (work_port_events & WORKER_HB_TMO)
680 lpfc_hb_timeout_handler(phba);
681 if (work_port_events & WORKER_MBOX_TMO)
682 lpfc_mbox_timeout_handler(phba);
683 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
684 lpfc_unblock_fabric_iocbs(phba);
James Smart549e55c2007-08-02 11:09:51 -0400685 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
686 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500687 if (work_port_events & WORKER_DELAYED_DISC_TMO)
688 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500689 }
James Smart09372822008-01-11 01:52:54 -0500690 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500691
James Smart895427b2017-02-12 13:52:30 -0800692 pring = lpfc_phba_elsring(phba);
James Smart858c9f62007-06-17 19:56:39 -0500693 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
694 status >>= (4*LPFC_ELS_RING);
James Smart4d9ab992009-10-02 15:16:39 -0400695 if ((status & HA_RXMASK) ||
696 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
James Smart45ed1192009-10-02 15:17:02 -0400697 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400698 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500699 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400700 /* Set the lpfc data pending flag */
701 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500702 } else {
James Smart94661502013-03-01 16:37:29 -0500703 if (phba->link_state >= LPFC_LINK_UP) {
704 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
705 lpfc_sli_handle_slow_ring_event(phba, pring,
706 (status &
707 HA_RXMASK));
708 }
James Smart858c9f62007-06-17 19:56:39 -0500709 }
Sebastian Herbsztb1039182015-07-22 10:53:22 +0200710 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart0e9bb8d2013-03-01 16:35:12 -0500711 (!list_empty(&pring->txq)))
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 Smart2e0fef82007-06-17 19:56:36 -0500897 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500898 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500899 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500900 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500901 phba->link_state = LPFC_LINK_DOWN;
James Smart72100cc2010-02-12 14:43:01 -0500902 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500903 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500904 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500905 }
James Smart549e55c2007-08-02 11:09:51 -0400906 vports = lpfc_create_vport_work_array(phba);
James Smart895427b2017-02-12 13:52:30 -0800907 if (vports != NULL) {
James Smart6fb120a2009-05-22 14:52:59 -0400908 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400909 /* Issue a LINK DOWN event to all nodes */
910 lpfc_linkdown_port(vports[i]);
James Smart895427b2017-02-12 13:52:30 -0800911
912 vports[i]->fc_myDID = 0;
913
James Smart01649562017-02-12 13:52:32 -0800914 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -0800915 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -0800916 if (phba->nvmet_support)
917 lpfc_nvmet_update_targetport(phba);
918 else
James Smart8c258642017-02-12 13:52:36 -0800919 lpfc_nvme_update_localport(vports[i]);
James Smart8c258642017-02-12 13:52:36 -0800920 }
James Smart549e55c2007-08-02 11:09:51 -0400921 }
James Smart895427b2017-02-12 13:52:30 -0800922 }
James Smart09372822008-01-11 01:52:54 -0500923 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500924 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500925 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
926 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400927 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500928 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500929 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400930 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500931 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500932 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500933 }
934 }
935
dea31012005-04-17 16:05:31 -0500936 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500937 if (phba->pport->fc_flag & FC_PT2PT) {
James Smart2e0fef82007-06-17 19:56:36 -0500938 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
939 if (mb) {
dea31012005-04-17 16:05:31 -0500940 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500941 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500942 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400943 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500944 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500945 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500946 }
947 }
James Smart2e0fef82007-06-17 19:56:36 -0500948 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500949 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500950 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500951 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500952 return 0;
dea31012005-04-17 16:05:31 -0500953}
954
James Smart92d7f7b2007-06-17 19:56:38 -0500955static void
956lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500957{
James Smart92d7f7b2007-06-17 19:56:38 -0500958 struct lpfc_nodelist *ndlp;
959
960 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500961 if (!NLP_CHK_NODE_ACT(ndlp))
962 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500963 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
964 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500965 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500966 /* On Linkup its safe to clean up the ndlp
967 * from Fabric connections.
968 */
James Smart92d7f7b2007-06-17 19:56:38 -0500969 if (ndlp->nlp_DID != Fabric_DID)
970 lpfc_unreg_rpi(vport, ndlp);
971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
972 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500973 /* Fail outstanding IO now since device is
974 * marked for PLOGI.
975 */
James Smart92d7f7b2007-06-17 19:56:38 -0500976 lpfc_unreg_rpi(vport, ndlp);
977 }
978 }
979}
980
981static void
982lpfc_linkup_port(struct lpfc_vport *vport)
983{
984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500985 struct lpfc_hba *phba = vport->phba;
986
987 if ((vport->load_flag & FC_UNLOADING) != 0)
988 return;
989
James Smart858c9f62007-06-17 19:56:39 -0500990 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
991 "Link Up: top:x%x speed:x%x flg:x%x",
992 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
993
James Smart92d7f7b2007-06-17 19:56:38 -0500994 /* If NPIV is not enabled, only bring the physical port up */
995 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
996 (vport != phba->pport))
997 return;
dea31012005-04-17 16:05:31 -0500998
James Smarta0f2d3e2017-02-12 13:52:31 -0800999 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1000 fc_host_post_event(shost, fc_get_event_number(),
1001 FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -04001002
James Smart2e0fef82007-06-17 19:56:36 -05001003 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05001004 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1005 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1006 vport->fc_flag |= FC_NDISC_ACTIVE;
1007 vport->fc_ns_retry = 0;
1008 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001009
James Smart92d7f7b2007-06-17 19:56:38 -05001010 if (vport->fc_flag & FC_LBIT)
1011 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001012
James Smart92d7f7b2007-06-17 19:56:38 -05001013}
1014
1015static int
1016lpfc_linkup(struct lpfc_hba *phba)
1017{
James Smart549e55c2007-08-02 11:09:51 -04001018 struct lpfc_vport **vports;
1019 int i;
James Smart92d7f7b2007-06-17 19:56:38 -05001020
1021 phba->link_state = LPFC_LINK_UP;
1022
1023 /* Unblock fabric iocbs if they are blocked */
1024 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1025 del_timer_sync(&phba->fabric_block_timer);
1026
James Smart549e55c2007-08-02 11:09:51 -04001027 vports = lpfc_create_vport_work_array(phba);
1028 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001029 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001030 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001031 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001032
1033 return 0;
1034}
1035
1036/*
1037 * This routine handles processing a CLEAR_LA mailbox
1038 * command upon completion. It is setup in the LPFC_MBOXQ
1039 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08001040 * handed off to the SLI layer. SLI3 only.
dea31012005-04-17 16:05:31 -05001041 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001042static void
James Smart2e0fef82007-06-17 19:56:36 -05001043lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001044{
James Smart2e0fef82007-06-17 19:56:36 -05001045 struct lpfc_vport *vport = pmb->vport;
1046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1047 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001048 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001049 uint32_t control;
1050
dea31012005-04-17 16:05:31 -05001051 /* Since we don't do discovery right now, turn these off here */
James Smart895427b2017-02-12 13:52:30 -08001052 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1053 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001054
1055 /* Check for error */
1056 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001057 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001058 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1059 "0320 CLEAR_LA mbxStatus error x%x hba "
1060 "state x%x\n",
1061 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001062 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001063 goto out;
1064 }
1065
James Smart92d7f7b2007-06-17 19:56:38 -05001066 if (vport->port_type == LPFC_PHYSICAL_PORT)
1067 phba->link_state = LPFC_HBA_READY;
1068
1069 spin_lock_irq(&phba->hbalock);
1070 psli->sli_flag |= LPFC_PROCESS_LA;
1071 control = readl(phba->HCregaddr);
1072 control |= HC_LAINT_ENA;
1073 writel(control, phba->HCregaddr);
1074 readl(phba->HCregaddr); /* flush */
1075 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001076 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001077 return;
dea31012005-04-17 16:05:31 -05001078
dea31012005-04-17 16:05:31 -05001079out:
1080 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001081 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1082 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001083 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001084
James Smart2e0fef82007-06-17 19:56:36 -05001085 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001086 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001087 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001088
James Smart2e0fef82007-06-17 19:56:36 -05001089 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001090
1091 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001092
1093 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001094 psli->sli_flag |= LPFC_PROCESS_LA;
1095 control = readl(phba->HCregaddr);
1096 control |= HC_LAINT_ENA;
1097 writel(control, phba->HCregaddr);
1098 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001099 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001100
1101 return;
1102}
1103
James Smart2e0fef82007-06-17 19:56:36 -05001104
James Smartd6de08c2015-12-16 18:11:53 -05001105void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001106lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001107{
James Smart2e0fef82007-06-17 19:56:36 -05001108 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001109
James Smart04c68492009-05-22 14:52:52 -04001110 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001111 goto out;
dea31012005-04-17 16:05:31 -05001112
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001113 mempool_free(pmb, phba->mbox_mem_pool);
1114
James Smart1b511972011-12-13 13:23:09 -05001115 /* don't perform discovery for SLI4 loopback diagnostic test */
1116 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1117 !(phba->hba_flag & HBA_FCOE_MODE) &&
1118 (phba->link_flag & LS_LOOPBACK_MODE))
1119 return;
1120
James Smart76a95d72010-11-20 23:11:48 -05001121 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001122 vport->fc_flag & FC_PUBLIC_LOOP &&
1123 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001124 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001125 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001126 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1127 */
James Smart2e0fef82007-06-17 19:56:36 -05001128 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001129 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001130 }
dea31012005-04-17 16:05:31 -05001131
James Smart2e0fef82007-06-17 19:56:36 -05001132 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001133 * LPFC_FLOGI while waiting for FLOGI cmpl
1134 */
James Smartd6de08c2015-12-16 18:11:53 -05001135 if (vport->port_state != LPFC_FLOGI)
James Smart92d7f7b2007-06-17 19:56:38 -05001136 lpfc_initial_flogi(vport);
James Smartd6de08c2015-12-16 18:11:53 -05001137 else if (vport->fc_flag & FC_PT2PT)
1138 lpfc_disc_start(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001139 return;
dea31012005-04-17 16:05:31 -05001140
1141out:
James Smarte8b62012007-08-02 11:10:09 -04001142 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1143 "0306 CONFIG_LINK mbxStatus error x%x "
1144 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001145 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001146 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001147
1148 lpfc_linkdown(phba);
1149
James Smarte8b62012007-08-02 11:10:09 -04001150 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1151 "0200 CONFIG_LINK bad hba state x%x\n",
1152 vport->port_state);
dea31012005-04-17 16:05:31 -05001153
James Smart92d7f7b2007-06-17 19:56:38 -05001154 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001155 return;
1156}
1157
James Smart7d791df2011-07-22 18:37:52 -04001158/**
1159 * lpfc_sli4_clear_fcf_rr_bmask
1160 * @phba pointer to the struct lpfc_hba for this port.
1161 * This fucnction resets the round robin bit mask and clears the
1162 * fcf priority list. The list deletions are done while holding the
1163 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1164 * from the lpfc_fcf_pri record.
1165 **/
1166void
1167lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1168{
1169 struct lpfc_fcf_pri *fcf_pri;
1170 struct lpfc_fcf_pri *next_fcf_pri;
1171 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1172 spin_lock_irq(&phba->hbalock);
1173 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1174 &phba->fcf.fcf_pri_list, list) {
1175 list_del_init(&fcf_pri->list);
1176 fcf_pri->fcf_rec.flag = 0;
1177 }
1178 spin_unlock_irq(&phba->hbalock);
1179}
dea31012005-04-17 16:05:31 -05001180static void
James Smart6fb120a2009-05-22 14:52:59 -04001181lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1182{
1183 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001184
1185 if (mboxq->u.mb.mbxStatus) {
1186 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1187 "2017 REG_FCFI mbxStatus error x%x "
1188 "HBA state x%x\n",
1189 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001190 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001191 }
1192
1193 /* Start FCoE discovery by sending a FLOGI. */
1194 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1195 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001196 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001197 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001198 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001199
James Smart32b97932009-07-19 10:01:21 -04001200 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001201 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1202 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001203 goto fail_out;
1204
1205 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001206 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001207 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001208 phba->hba_flag &= ~FCF_TS_INPROG;
1209 if (vport->port_state != LPFC_FLOGI) {
1210 phba->hba_flag |= FCF_RR_INPROG;
1211 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001212 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001213 goto out;
1214 }
1215 spin_unlock_irq(&phba->hbalock);
1216 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001217
James Smarta93ff372010-10-22 11:06:08 -04001218fail_out:
1219 spin_lock_irq(&phba->hbalock);
1220 phba->hba_flag &= ~FCF_RR_INPROG;
1221 spin_unlock_irq(&phba->hbalock);
1222out:
James Smart6fb120a2009-05-22 14:52:59 -04001223 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001224}
1225
1226/**
1227 * lpfc_fab_name_match - Check if the fcf fabric name match.
1228 * @fab_name: pointer to fabric name.
1229 * @new_fcf_record: pointer to fcf record.
1230 *
1231 * This routine compare the fcf record's fabric name with provided
1232 * fabric name. If the fabric name are identical this function
1233 * returns 1 else return 0.
1234 **/
1235static uint32_t
1236lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1237{
James Smartecfd03c2010-02-12 14:41:27 -05001238 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001239 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001240 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1241 return 0;
1242 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1243 return 0;
1244 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1245 return 0;
1246 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1247 return 0;
1248 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1249 return 0;
1250 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1251 return 0;
1252 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1253 return 0;
1254 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001255}
1256
1257/**
James Smart8fa38512009-07-19 10:01:03 -04001258 * lpfc_sw_name_match - Check if the fcf switch name match.
1259 * @fab_name: pointer to fabric name.
1260 * @new_fcf_record: pointer to fcf record.
1261 *
1262 * This routine compare the fcf record's switch name with provided
1263 * switch name. If the switch name are identical this function
1264 * returns 1 else return 0.
1265 **/
1266static uint32_t
1267lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1268{
James Smartecfd03c2010-02-12 14:41:27 -05001269 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001270 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001271 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1272 return 0;
1273 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1274 return 0;
1275 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1276 return 0;
1277 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1278 return 0;
1279 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1280 return 0;
1281 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1282 return 0;
1283 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1284 return 0;
1285 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001286}
1287
1288/**
James Smart6fb120a2009-05-22 14:52:59 -04001289 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001290 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001291 * @new_fcf_record: pointer to fcf record.
1292 *
1293 * This routine compare the fcf record's mac address with HBA's
1294 * FCF mac address. If the mac addresses are identical this function
1295 * returns 1 else return 0.
1296 **/
1297static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001298lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001299{
James Smartecfd03c2010-02-12 14:41:27 -05001300 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001301 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001302 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1303 return 0;
1304 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1305 return 0;
1306 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1307 return 0;
1308 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1309 return 0;
1310 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1311 return 0;
1312 return 1;
1313}
1314
1315static bool
1316lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1317{
1318 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001319}
1320
1321/**
James Smart7d791df2011-07-22 18:37:52 -04001322 * lpfc_update_fcf_record - Update driver fcf record
1323 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1324 * @phba: pointer to lpfc hba data structure.
1325 * @fcf_index: Index for the lpfc_fcf_record.
1326 * @new_fcf_record: pointer to hba fcf record.
1327 *
1328 * This routine updates the driver FCF priority record from the new HBA FCF
1329 * record. This routine is called with the host lock held.
1330 **/
1331static void
1332__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1333 struct fcf_record *new_fcf_record
1334 )
1335{
1336 struct lpfc_fcf_pri *fcf_pri;
1337
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001338 lockdep_assert_held(&phba->hbalock);
1339
James Smart7d791df2011-07-22 18:37:52 -04001340 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1341 fcf_pri->fcf_rec.fcf_index = fcf_index;
1342 /* FCF record priority */
1343 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1344
1345}
1346
1347/**
James Smart6fb120a2009-05-22 14:52:59 -04001348 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001349 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001350 * @new_fcf_record: pointer to fcf record.
1351 *
1352 * This routine copies the FCF information from the FCF
1353 * record to lpfc_hba data structure.
1354 **/
1355static void
James Smartecfd03c2010-02-12 14:41:27 -05001356lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1357 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001358{
James Smartecfd03c2010-02-12 14:41:27 -05001359 /* Fabric name */
1360 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001361 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001362 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001363 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001364 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001365 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001366 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001367 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001368 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001369 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001370 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001371 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001372 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001373 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001374 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001375 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001376 /* Mac address */
1377 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1378 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1379 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1380 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1381 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1382 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1383 /* FCF record index */
1384 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1385 /* FCF record priority */
1386 fcf_rec->priority = new_fcf_record->fip_priority;
1387 /* Switch name */
1388 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001389 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001390 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001391 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001392 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001393 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001394 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001395 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001396 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001397 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001398 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001399 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001400 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001401 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001402 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001403 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001404}
1405
1406/**
James Smartecfd03c2010-02-12 14:41:27 -05001407 * lpfc_update_fcf_record - Update driver fcf record
1408 * @phba: pointer to lpfc hba data structure.
1409 * @fcf_rec: pointer to driver fcf record.
1410 * @new_fcf_record: pointer to hba fcf record.
1411 * @addr_mode: address mode to be set to the driver fcf record.
1412 * @vlan_id: vlan tag to be set to the driver fcf record.
1413 * @flag: flag bits to be set to the driver fcf record.
1414 *
1415 * This routine updates the driver FCF record from the new HBA FCF record
1416 * together with the address mode, vlan_id, and other informations. This
1417 * routine is called with the host lock held.
1418 **/
1419static void
1420__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1421 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1422 uint16_t vlan_id, uint32_t flag)
1423{
Johannes Thumshirn1c2ba472016-01-20 16:22:22 +01001424 lockdep_assert_held(&phba->hbalock);
1425
James Smartecfd03c2010-02-12 14:41:27 -05001426 /* Copy the fields from the HBA's FCF record */
1427 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1428 /* Update other fields of driver FCF record */
1429 fcf_rec->addr_mode = addr_mode;
1430 fcf_rec->vlan_id = vlan_id;
1431 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001432 __lpfc_update_fcf_record_pri(phba,
1433 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1434 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001435}
1436
1437/**
James Smart6fb120a2009-05-22 14:52:59 -04001438 * lpfc_register_fcf - Register the FCF with hba.
1439 * @phba: pointer to lpfc hba data structure.
1440 *
1441 * This routine issues a register fcfi mailbox command to register
1442 * the fcf with HBA.
1443 **/
1444static void
1445lpfc_register_fcf(struct lpfc_hba *phba)
1446{
1447 LPFC_MBOXQ_t *fcf_mbxq;
1448 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001449
James Smartd439d282010-09-29 11:18:45 -04001450 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001451 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001452 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001453 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001454 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001455 return;
1456 }
1457
1458 /* The FCF is already registered, start discovery */
1459 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001460 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001461 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001462 if (phba->pport->port_state != LPFC_FLOGI &&
1463 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001464 phba->hba_flag |= FCF_RR_INPROG;
1465 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001466 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001467 return;
1468 }
1469 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001470 return;
1471 }
James Smartd439d282010-09-29 11:18:45 -04001472 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001473
James Smarta93ff372010-10-22 11:06:08 -04001474 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001475 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001476 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001477 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001478 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001479 return;
James Smart4d9ab992009-10-02 15:16:39 -04001480 }
James Smart6fb120a2009-05-22 14:52:59 -04001481
1482 lpfc_reg_fcfi(phba, fcf_mbxq);
1483 fcf_mbxq->vport = phba->pport;
1484 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1485 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001486 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001487 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001488 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001489 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001490 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001491 }
James Smart6fb120a2009-05-22 14:52:59 -04001492
1493 return;
1494}
1495
1496/**
1497 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1498 * @phba: pointer to lpfc hba data structure.
1499 * @new_fcf_record: pointer to fcf record.
1500 * @boot_flag: Indicates if this record used by boot bios.
1501 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001502 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001503 *
1504 * This routine compare the fcf record with connect list obtained from the
1505 * config region to decide if this FCF can be used for SAN discovery. It returns
1506 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1507 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1508 * is used by boot bios and addr_mode will indicate the addressing mode to be
1509 * used for this FCF when the function returns.
1510 * If the FCF record need to be used with a particular vlan id, the vlan is
1511 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001512 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001513 **/
1514static int
1515lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1516 struct fcf_record *new_fcf_record,
1517 uint32_t *boot_flag, uint32_t *addr_mode,
1518 uint16_t *vlan_id)
1519{
1520 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001521 int i, j, fcf_vlan_id = 0;
1522
1523 /* Find the lowest VLAN id in the FCF record */
1524 for (i = 0; i < 512; i++) {
1525 if (new_fcf_record->vlan_bitmap[i]) {
1526 fcf_vlan_id = i * 8;
1527 j = 0;
1528 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1529 j++;
1530 fcf_vlan_id++;
1531 }
1532 break;
1533 }
1534 }
James Smart6fb120a2009-05-22 14:52:59 -04001535
James Smart26979ce2012-09-29 11:31:55 -04001536 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001537 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001538 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1539 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001540 return 0;
1541
James Smart45ed1192009-10-02 15:17:02 -04001542 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001543 *boot_flag = 0;
1544 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1545 new_fcf_record);
1546 if (phba->valid_vlan)
1547 *vlan_id = phba->vlan_id;
1548 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001549 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001550 return 1;
1551 }
1552
1553 /*
1554 * If there are no FCF connection table entry, driver connect to all
1555 * FCFs.
1556 */
1557 if (list_empty(&phba->fcf_conn_rec_list)) {
1558 *boot_flag = 0;
1559 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1560 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001561
1562 /*
1563 * When there are no FCF connect entries, use driver's default
1564 * addressing mode - FPMA.
1565 */
1566 if (*addr_mode & LPFC_FCF_FPMA)
1567 *addr_mode = LPFC_FCF_FPMA;
1568
James Smart4d9ab992009-10-02 15:16:39 -04001569 /* If FCF record report a vlan id use that vlan id */
1570 if (fcf_vlan_id)
1571 *vlan_id = fcf_vlan_id;
1572 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001573 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001574 return 1;
1575 }
1576
James Smartecfd03c2010-02-12 14:41:27 -05001577 list_for_each_entry(conn_entry,
1578 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001579 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1580 continue;
1581
1582 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1583 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001584 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001585 continue;
James Smart8fa38512009-07-19 10:01:03 -04001586 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1587 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1588 new_fcf_record))
1589 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001590 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1591 /*
1592 * If the vlan bit map does not have the bit set for the
1593 * vlan id to be used, then it is not a match.
1594 */
1595 if (!(new_fcf_record->vlan_bitmap
1596 [conn_entry->conn_rec.vlan_tag / 8] &
1597 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1598 continue;
1599 }
1600
1601 /*
James Smart0c287582009-06-10 17:22:56 -04001602 * If connection record does not support any addressing mode,
1603 * skip the FCF record.
1604 */
1605 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1606 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1607 continue;
1608
1609 /*
James Smart6fb120a2009-05-22 14:52:59 -04001610 * Check if the connection record specifies a required
1611 * addressing mode.
1612 */
1613 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1614 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1615
1616 /*
1617 * If SPMA required but FCF not support this continue.
1618 */
1619 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1620 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1621 new_fcf_record) & LPFC_FCF_SPMA))
1622 continue;
1623
1624 /*
1625 * If FPMA required but FCF not support this continue.
1626 */
1627 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1628 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1629 new_fcf_record) & LPFC_FCF_FPMA))
1630 continue;
1631 }
1632
1633 /*
1634 * This fcf record matches filtering criteria.
1635 */
1636 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1637 *boot_flag = 1;
1638 else
1639 *boot_flag = 0;
1640
James Smart0c287582009-06-10 17:22:56 -04001641 /*
1642 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001643 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001644 * by FCF, allow fabric to pick the addressing mode.
1645 */
James Smart6fb120a2009-05-22 14:52:59 -04001646 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1647 new_fcf_record);
1648 /*
1649 * If the user specified a required address mode, assign that
1650 * address mode
1651 */
1652 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1653 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1654 *addr_mode = (conn_entry->conn_rec.flags &
1655 FCFCNCT_AM_SPMA) ?
1656 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1657 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001658 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001659 * addr mode only if FCF support the addr_mode.
1660 */
1661 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1662 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1663 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1664 (*addr_mode & LPFC_FCF_SPMA))
1665 *addr_mode = LPFC_FCF_SPMA;
1666 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1667 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1668 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1669 (*addr_mode & LPFC_FCF_FPMA))
1670 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001671
James Smart4d9ab992009-10-02 15:16:39 -04001672 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001673 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1674 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001675 /*
1676 * If no vlan id is specified in connect list, use the vlan id
1677 * in the FCF record
1678 */
1679 else if (fcf_vlan_id)
1680 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001681 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001682 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001683
1684 return 1;
1685 }
1686
1687 return 0;
1688}
1689
1690/**
James Smart32b97932009-07-19 10:01:21 -04001691 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1692 * @phba: pointer to lpfc hba data structure.
1693 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1694 *
1695 * This function check if there is any fcoe event pending while driver
1696 * scan FCF entries. If there is any pending event, it will restart the
1697 * FCF saning and return 1 else return 0.
1698 */
1699int
1700lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1701{
James Smart32b97932009-07-19 10:01:21 -04001702 /*
1703 * If the Link is up and no FCoE events while in the
1704 * FCF discovery, no need to restart FCF discovery.
1705 */
1706 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001707 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001708 return 0;
1709
James Smart0c9ab6f2010-02-26 14:15:57 -05001710 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1711 "2768 Pending link or FCF event during current "
1712 "handling of the previous event: link_state:x%x, "
1713 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1714 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1715 phba->fcoe_eventtag);
1716
James Smart32b97932009-07-19 10:01:21 -04001717 spin_lock_irq(&phba->hbalock);
1718 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1719 spin_unlock_irq(&phba->hbalock);
1720
James Smart0c9ab6f2010-02-26 14:15:57 -05001721 if (phba->link_state >= LPFC_LINK_UP) {
1722 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1723 "2780 Restart FCF table scan due to "
1724 "pending FCF event:evt_tag_at_scan:x%x, "
1725 "evt_tag_current:x%x\n",
1726 phba->fcoe_eventtag_at_fcf_scan,
1727 phba->fcoe_eventtag);
1728 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1729 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001730 /*
James Smarta93ff372010-10-22 11:06:08 -04001731 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001732 * flag
1733 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001734 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1735 "2833 Stop FCF discovery process due to link "
1736 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001737 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001738 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001739 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001740 spin_unlock_irq(&phba->hbalock);
1741 }
James Smart32b97932009-07-19 10:01:21 -04001742
James Smart0c9ab6f2010-02-26 14:15:57 -05001743 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001744 if (unreg_fcf) {
1745 spin_lock_irq(&phba->hbalock);
1746 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1747 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001748 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001749 }
James Smart32b97932009-07-19 10:01:21 -04001750 return 1;
1751}
1752
1753/**
James Smart999d8132010-03-15 11:24:56 -04001754 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1755 * @phba: pointer to lpfc hba data structure.
1756 * @fcf_cnt: number of eligible fcf record seen so far.
1757 *
1758 * This function makes an running random selection decision on FCF record to
1759 * use through a sequence of @fcf_cnt eligible FCF records with equal
1760 * probability. To perform integer manunipulation of random numbers with
1761 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001762 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001763 *
1764 * Returns true when outcome is for the newly read FCF record should be
1765 * chosen; otherwise, return false when outcome is for keeping the previously
1766 * chosen FCF record.
1767 **/
1768static bool
1769lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1770{
1771 uint32_t rand_num;
1772
1773 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001774 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001775
1776 /* Decision with probability 1/fcf_cnt */
1777 if ((fcf_cnt * rand_num) < 0xFFFF)
1778 return true;
1779 else
1780 return false;
1781}
1782
1783/**
James Smart3804dc82010-07-14 15:31:37 -04001784 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001785 * @phba: pointer to lpfc hba data structure.
1786 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001787 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001788 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001789 * This routine parses the non-embedded fcf mailbox command by performing the
1790 * necessarily error checking, non-embedded read FCF record mailbox command
1791 * SGE parsing, and endianness swapping.
1792 *
1793 * Returns the pointer to the new FCF record in the non-embedded mailbox
1794 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001795 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001796static struct fcf_record *
1797lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1798 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001799{
1800 void *virt_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001801 struct lpfc_mbx_sge sge;
1802 struct lpfc_mbx_read_fcf_tbl *read_fcf;
James Smartf818ea72015-05-21 13:55:29 -04001803 uint32_t shdr_status, shdr_add_status, if_type;
James Smart6fb120a2009-05-22 14:52:59 -04001804 union lpfc_sli4_cfg_shdr *shdr;
1805 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001806
James Smart6fb120a2009-05-22 14:52:59 -04001807 /* Get the first SGE entry from the non-embedded DMA memory. This
1808 * routine only uses a single SGE.
1809 */
1810 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smart6fb120a2009-05-22 14:52:59 -04001811 if (unlikely(!mboxq->sge_array)) {
1812 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1813 "2524 Failed to get the non-embedded SGE "
1814 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001815 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001816 }
1817 virt_addr = mboxq->sge_array->addr[0];
1818
1819 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001820 lpfc_sli_pcimem_bcopy(shdr, shdr,
1821 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001822 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smartf818ea72015-05-21 13:55:29 -04001823 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
James Smart0c9ab6f2010-02-26 14:15:57 -05001824 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001825 if (shdr_status || shdr_add_status) {
James Smartf818ea72015-05-21 13:55:29 -04001826 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1827 if_type == LPFC_SLI_INTF_IF_TYPE_2)
James Smart0c9ab6f2010-02-26 14:15:57 -05001828 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001829 "2726 READ_FCF_RECORD Indicates empty "
1830 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001831 else
1832 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001833 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001834 "with status x%x add_status x%x, "
1835 "mbx\n", shdr_status, shdr_add_status);
1836 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001837 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001838
1839 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001840 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1841 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1842 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001843 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001844 new_fcf_record = (struct fcf_record *)(virt_addr +
1845 sizeof(struct lpfc_mbx_read_fcf_tbl));
1846 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001847 offsetof(struct fcf_record, vlan_bitmap));
1848 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1849 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001850
James Smart0c9ab6f2010-02-26 14:15:57 -05001851 return new_fcf_record;
1852}
1853
1854/**
1855 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1856 * @phba: pointer to lpfc hba data structure.
1857 * @fcf_record: pointer to the fcf record.
1858 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1859 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1860 *
1861 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1862 * enabled.
1863 **/
1864static void
1865lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1866 struct fcf_record *fcf_record,
1867 uint16_t vlan_id,
1868 uint16_t next_fcf_index)
1869{
1870 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1871 "2764 READ_FCF_RECORD:\n"
1872 "\tFCF_Index : x%x\n"
1873 "\tFCF_Avail : x%x\n"
1874 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001875 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001876 "\tFIP_Priority : x%x\n"
1877 "\tMAC_Provider : x%x\n"
1878 "\tLowest VLANID : x%x\n"
1879 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1880 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1881 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1882 "\tNext_FCF_Index: x%x\n",
1883 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1884 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1885 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001886 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001887 fcf_record->fip_priority,
1888 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1889 vlan_id,
1890 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1891 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1892 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1893 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1894 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1895 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1896 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1897 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1898 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1899 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1900 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1901 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1902 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1903 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1904 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1905 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1906 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1907 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1908 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1909 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1910 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1911 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1912 next_fcf_index);
1913}
1914
1915/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001916 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1917 * @phba: pointer to lpfc hba data structure.
1918 * @fcf_rec: pointer to an existing FCF record.
1919 * @new_fcf_record: pointer to a new FCF record.
1920 * @new_vlan_id: vlan id from the new FCF record.
1921 *
1922 * This function performs matching test of a new FCF record against an existing
1923 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1924 * will not be used as part of the FCF record matching criteria.
1925 *
1926 * Returns true if all the fields matching, otherwise returns false.
1927 */
1928static bool
1929lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1930 struct lpfc_fcf_rec *fcf_rec,
1931 struct fcf_record *new_fcf_record,
1932 uint16_t new_vlan_id)
1933{
1934 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1935 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1936 return false;
1937 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1938 return false;
1939 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1940 return false;
1941 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1942 return false;
James Smart7d791df2011-07-22 18:37:52 -04001943 if (fcf_rec->priority != new_fcf_record->fip_priority)
1944 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001945 return true;
1946}
1947
1948/**
James Smarta93ff372010-10-22 11:06:08 -04001949 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1950 * @vport: Pointer to vport object.
1951 * @fcf_index: index to next fcf.
1952 *
1953 * This function processing the roundrobin fcf failover to next fcf index.
1954 * When this function is invoked, there will be a current fcf registered
1955 * for flogi.
1956 * Return: 0 for continue retrying flogi on currently registered fcf;
1957 * 1 for stop flogi on currently registered fcf;
1958 */
1959int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1960{
1961 struct lpfc_hba *phba = vport->phba;
1962 int rc;
1963
1964 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1965 spin_lock_irq(&phba->hbalock);
1966 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1967 spin_unlock_irq(&phba->hbalock);
1968 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1969 "2872 Devloss tmo with no eligible "
1970 "FCF, unregister in-use FCF (x%x) "
1971 "and rescan FCF table\n",
1972 phba->fcf.current_rec.fcf_indx);
1973 lpfc_unregister_fcf_rescan(phba);
1974 goto stop_flogi_current_fcf;
1975 }
1976 /* Mark the end to FLOGI roundrobin failover */
1977 phba->hba_flag &= ~FCF_RR_INPROG;
1978 /* Allow action to new fcf asynchronous event */
1979 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1980 spin_unlock_irq(&phba->hbalock);
1981 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1982 "2865 No FCF available, stop roundrobin FCF "
1983 "failover and change port state:x%x/x%x\n",
1984 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1985 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1986 goto stop_flogi_current_fcf;
1987 } else {
1988 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1989 "2794 Try FLOGI roundrobin FCF failover to "
1990 "(x%x)\n", fcf_index);
1991 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1992 if (rc)
1993 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1994 "2761 FLOGI roundrobin FCF failover "
1995 "failed (rc:x%x) to read FCF (x%x)\n",
1996 rc, phba->fcf.current_rec.fcf_indx);
1997 else
1998 goto stop_flogi_current_fcf;
1999 }
2000 return 0;
2001
2002stop_flogi_current_fcf:
2003 lpfc_can_disctmo(vport);
2004 return 1;
2005}
2006
2007/**
James Smart7d791df2011-07-22 18:37:52 -04002008 * lpfc_sli4_fcf_pri_list_del
2009 * @phba: pointer to lpfc hba data structure.
2010 * @fcf_index the index of the fcf record to delete
2011 * This routine checks the on list flag of the fcf_index to be deleted.
2012 * If it is one the list then it is removed from the list, and the flag
2013 * is cleared. This routine grab the hbalock before removing the fcf
2014 * record from the list.
2015 **/
2016static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2017 uint16_t fcf_index)
2018{
2019 struct lpfc_fcf_pri *new_fcf_pri;
2020
2021 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2022 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2023 "3058 deleting idx x%x pri x%x flg x%x\n",
2024 fcf_index, new_fcf_pri->fcf_rec.priority,
2025 new_fcf_pri->fcf_rec.flag);
2026 spin_lock_irq(&phba->hbalock);
2027 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2028 if (phba->fcf.current_rec.priority ==
2029 new_fcf_pri->fcf_rec.priority)
2030 phba->fcf.eligible_fcf_cnt--;
2031 list_del_init(&new_fcf_pri->list);
2032 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2033 }
2034 spin_unlock_irq(&phba->hbalock);
2035}
2036
2037/**
2038 * lpfc_sli4_set_fcf_flogi_fail
2039 * @phba: pointer to lpfc hba data structure.
2040 * @fcf_index the index of the fcf record to update
2041 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2042 * flag so the the round robin slection for the particular priority level
2043 * will try a different fcf record that does not have this bit set.
2044 * If the fcf record is re-read for any reason this flag is cleared brfore
2045 * adding it to the priority list.
2046 **/
2047void
2048lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2049{
2050 struct lpfc_fcf_pri *new_fcf_pri;
2051 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2052 spin_lock_irq(&phba->hbalock);
2053 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2054 spin_unlock_irq(&phba->hbalock);
2055}
2056
2057/**
2058 * lpfc_sli4_fcf_pri_list_add
2059 * @phba: pointer to lpfc hba data structure.
2060 * @fcf_index the index of the fcf record to add
2061 * This routine checks the priority of the fcf_index to be added.
2062 * If it is a lower priority than the current head of the fcf_pri list
2063 * then it is added to the list in the right order.
2064 * If it is the same priority as the current head of the list then it
2065 * is added to the head of the list and its bit in the rr_bmask is set.
2066 * If the fcf_index to be added is of a higher priority than the current
2067 * head of the list then the rr_bmask is cleared, its bit is set in the
2068 * rr_bmask and it is added to the head of the list.
2069 * returns:
2070 * 0=success 1=failure
2071 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002072static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2073 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002074 struct fcf_record *new_fcf_record)
2075{
2076 uint16_t current_fcf_pri;
2077 uint16_t last_index;
2078 struct lpfc_fcf_pri *fcf_pri;
2079 struct lpfc_fcf_pri *next_fcf_pri;
2080 struct lpfc_fcf_pri *new_fcf_pri;
2081 int ret;
2082
2083 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2084 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2085 "3059 adding idx x%x pri x%x flg x%x\n",
2086 fcf_index, new_fcf_record->fip_priority,
2087 new_fcf_pri->fcf_rec.flag);
2088 spin_lock_irq(&phba->hbalock);
2089 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2090 list_del_init(&new_fcf_pri->list);
2091 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2092 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2093 if (list_empty(&phba->fcf.fcf_pri_list)) {
2094 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2095 ret = lpfc_sli4_fcf_rr_index_set(phba,
2096 new_fcf_pri->fcf_rec.fcf_index);
2097 goto out;
2098 }
2099
2100 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2101 LPFC_SLI4_FCF_TBL_INDX_MAX);
2102 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2103 ret = 0; /* Empty rr list */
2104 goto out;
2105 }
2106 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2107 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2108 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2109 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2110 memset(phba->fcf.fcf_rr_bmask, 0,
2111 sizeof(*phba->fcf.fcf_rr_bmask));
2112 /* fcfs_at_this_priority_level = 1; */
2113 phba->fcf.eligible_fcf_cnt = 1;
2114 } else
2115 /* fcfs_at_this_priority_level++; */
2116 phba->fcf.eligible_fcf_cnt++;
2117 ret = lpfc_sli4_fcf_rr_index_set(phba,
2118 new_fcf_pri->fcf_rec.fcf_index);
2119 goto out;
2120 }
2121
2122 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2123 &phba->fcf.fcf_pri_list, list) {
2124 if (new_fcf_pri->fcf_rec.priority <=
2125 fcf_pri->fcf_rec.priority) {
2126 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2127 list_add(&new_fcf_pri->list,
2128 &phba->fcf.fcf_pri_list);
2129 else
2130 list_add(&new_fcf_pri->list,
2131 &((struct lpfc_fcf_pri *)
2132 fcf_pri->list.prev)->list);
2133 ret = 0;
2134 goto out;
2135 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2136 || new_fcf_pri->fcf_rec.priority <
2137 next_fcf_pri->fcf_rec.priority) {
2138 list_add(&new_fcf_pri->list, &fcf_pri->list);
2139 ret = 0;
2140 goto out;
2141 }
2142 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2143 continue;
2144
2145 }
2146 ret = 1;
2147out:
2148 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2149 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2150 spin_unlock_irq(&phba->hbalock);
2151 return ret;
2152}
2153
2154/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002155 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2156 * @phba: pointer to lpfc hba data structure.
2157 * @mboxq: pointer to mailbox object.
2158 *
2159 * This function iterates through all the fcf records available in
2160 * HBA and chooses the optimal FCF record for discovery. After finding
2161 * the FCF for discovery it registers the FCF record and kicks start
2162 * discovery.
2163 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2164 * use an FCF record which matches fabric name and mac address of the
2165 * currently used FCF record.
2166 * If the driver supports only one FCF, it will try to use the FCF record
2167 * used by BOOT_BIOS.
2168 */
2169void
2170lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2171{
2172 struct fcf_record *new_fcf_record;
2173 uint32_t boot_flag, addr_mode;
2174 uint16_t fcf_index, next_fcf_index;
2175 struct lpfc_fcf_rec *fcf_rec = NULL;
2176 uint16_t vlan_id;
James Smart999d8132010-03-15 11:24:56 -04002177 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002178 int rc;
2179
2180 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002181 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002182 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2183 return;
2184 }
2185
2186 /* Parse the FCF record from the non-embedded mailbox command */
2187 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2188 &next_fcf_index);
2189 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002190 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002191 "2765 Mailbox command READ_FCF_RECORD "
2192 "failed to retrieve a FCF record.\n");
2193 /* Let next new FCF event trigger fast failover */
2194 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002195 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002196 spin_unlock_irq(&phba->hbalock);
2197 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2198 return;
2199 }
2200
2201 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002202 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2203 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002204
2205 /* Log the FCF record information if turned on */
2206 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2207 next_fcf_index);
2208
James Smart6fb120a2009-05-22 14:52:59 -04002209 /*
2210 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002211 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002212 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002213 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002214 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002215 lpfc_sli4_fcf_pri_list_del(phba,
2216 bf_get(lpfc_fcf_record_fcf_index,
2217 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002218 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002219 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002220 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002221 bf_get(lpfc_fcf_record_fcf_index,
2222 new_fcf_record),
2223 bf_get(lpfc_fcf_record_fcf_avail,
2224 new_fcf_record),
2225 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002226 new_fcf_record),
2227 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002228 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002229 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2230 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2231 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002232 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2233 phba->fcf.current_rec.fcf_indx) {
2234 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2235 "2862 FCF (x%x) matches property "
2236 "of in-use FCF (x%x)\n",
2237 bf_get(lpfc_fcf_record_fcf_index,
2238 new_fcf_record),
2239 phba->fcf.current_rec.fcf_indx);
2240 goto read_next_fcf;
2241 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002242 /*
2243 * In case the current in-use FCF record becomes
2244 * invalid/unavailable during FCF discovery that
2245 * was not triggered by fast FCF failover process,
2246 * treat it as fast FCF failover.
2247 */
2248 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2249 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2250 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2251 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002252 "(x%x), enter FCF failover "
2253 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002254 phba->fcf.current_rec.fcf_indx);
2255 spin_lock_irq(&phba->hbalock);
2256 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2257 spin_unlock_irq(&phba->hbalock);
2258 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2259 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2260 LPFC_FCOE_FCF_GET_FIRST);
2261 return;
2262 }
2263 }
James Smart6fb120a2009-05-22 14:52:59 -04002264 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002265 } else {
2266 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002267 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2268 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002269 if (rc)
2270 goto read_next_fcf;
2271 }
2272
James Smart6fb120a2009-05-22 14:52:59 -04002273 /*
2274 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002275 * FCF record for the discovery. The condition that a rescan
2276 * matches the in-use FCF record: fabric name, switch name, mac
2277 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002278 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002279 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002280 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002281 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2282 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002283 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002284 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2285 phba->fcf.current_rec.fcf_indx) {
2286 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2287 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2288 /* Stop FCF redisc wait timer */
2289 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2290 phba);
2291 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2292 /* Fast failover, mark completed */
2293 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2294 spin_unlock_irq(&phba->hbalock);
2295 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2296 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002297 "FCF (x%x), port_state:x%x, "
2298 "fc_flag:x%x\n",
2299 phba->fcf.current_rec.fcf_indx,
2300 phba->pport->port_state,
2301 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002302 goto out;
2303 } else
2304 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2305 "2863 New FCF (x%x) matches "
2306 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002307 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002308 new_fcf_record),
2309 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002310 }
James Smartecfd03c2010-02-12 14:41:27 -05002311 /*
2312 * Read next FCF record from HBA searching for the matching
2313 * with in-use record only if not during the fast failover
2314 * period. In case of fast failover period, it shall try to
2315 * determine whether the FCF record just read should be the
2316 * next candidate.
2317 */
2318 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002319 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002320 goto read_next_fcf;
2321 }
James Smart6fb120a2009-05-22 14:52:59 -04002322 }
James Smartecfd03c2010-02-12 14:41:27 -05002323 /*
2324 * Update on failover FCF record only if it's in FCF fast-failover
2325 * period; otherwise, update on current FCF record.
2326 */
James Smartfc2b9892010-02-26 14:15:29 -05002327 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2328 fcf_rec = &phba->fcf.failover_rec;
2329 else
James Smartecfd03c2010-02-12 14:41:27 -05002330 fcf_rec = &phba->fcf.current_rec;
2331
James Smart6fb120a2009-05-22 14:52:59 -04002332 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2333 /*
James Smartecfd03c2010-02-12 14:41:27 -05002334 * If the driver FCF record does not have boot flag
2335 * set and new hba fcf record has boot flag set, use
2336 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002337 */
James Smartecfd03c2010-02-12 14:41:27 -05002338 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2339 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2341 "2837 Update current FCF record "
2342 "(x%x) with new FCF record (x%x)\n",
2343 fcf_rec->fcf_indx,
2344 bf_get(lpfc_fcf_record_fcf_index,
2345 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002346 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2347 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002348 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002349 goto read_next_fcf;
2350 }
2351 /*
James Smartecfd03c2010-02-12 14:41:27 -05002352 * If the driver FCF record has boot flag set and the
2353 * new hba FCF record does not have boot flag, read
2354 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002355 */
James Smartecfd03c2010-02-12 14:41:27 -05002356 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002357 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002358 goto read_next_fcf;
2359 }
2360 /*
James Smartecfd03c2010-02-12 14:41:27 -05002361 * If the new hba FCF record has lower priority value
2362 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002363 */
James Smartfc2b9892010-02-26 14:15:29 -05002364 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002365 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002366 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2367 "2838 Update current FCF record "
2368 "(x%x) with new FCF record (x%x)\n",
2369 fcf_rec->fcf_indx,
2370 bf_get(lpfc_fcf_record_fcf_index,
2371 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002372 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2373 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002374 /* Reset running random FCF selection count */
2375 phba->fcf.eligible_fcf_cnt = 1;
2376 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2377 /* Update running random FCF selection count */
2378 phba->fcf.eligible_fcf_cnt++;
2379 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2380 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002381 if (select_new_fcf) {
2382 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2383 "2839 Update current FCF record "
2384 "(x%x) with new FCF record (x%x)\n",
2385 fcf_rec->fcf_indx,
2386 bf_get(lpfc_fcf_record_fcf_index,
2387 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002388 /* Choose the new FCF by random selection */
2389 __lpfc_update_fcf_record(phba, fcf_rec,
2390 new_fcf_record,
2391 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002392 }
James Smart6fb120a2009-05-22 14:52:59 -04002393 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002394 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002395 goto read_next_fcf;
2396 }
2397 /*
James Smartecfd03c2010-02-12 14:41:27 -05002398 * This is the first suitable FCF record, choose this record for
2399 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002400 */
James Smartecfd03c2010-02-12 14:41:27 -05002401 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002402 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002403 "2840 Update initial FCF candidate "
2404 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002405 bf_get(lpfc_fcf_record_fcf_index,
2406 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002407 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2408 addr_mode, vlan_id, (boot_flag ?
2409 BOOT_ENABLE : 0));
2410 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002411 /* Setup initial running random FCF selection count */
2412 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002413 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002414 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002415 goto read_next_fcf;
2416
2417read_next_fcf:
2418 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002419 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2420 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2421 /*
2422 * Case of FCF fast failover scan
2423 */
2424
2425 /*
2426 * It has not found any suitable FCF record, cancel
2427 * FCF scan inprogress, and do nothing
2428 */
2429 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002430 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002431 "2782 No suitable FCF found: "
2432 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002433 phba->fcoe_eventtag_at_fcf_scan,
2434 bf_get(lpfc_fcf_record_fcf_index,
2435 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002436 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002437 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2438 phba->hba_flag &= ~FCF_TS_INPROG;
2439 spin_unlock_irq(&phba->hbalock);
2440 /* Unregister in-use FCF and rescan */
2441 lpfc_printf_log(phba, KERN_INFO,
2442 LOG_FIP,
2443 "2864 On devloss tmo "
2444 "unreg in-use FCF and "
2445 "rescan FCF table\n");
2446 lpfc_unregister_fcf_rescan(phba);
2447 return;
2448 }
2449 /*
2450 * Let next new FCF event trigger fast failover
2451 */
2452 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002453 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002454 return;
2455 }
2456 /*
2457 * It has found a suitable FCF record that is not
2458 * the same as in-use FCF record, unregister the
2459 * in-use FCF record, replace the in-use FCF record
2460 * with the new FCF record, mark FCF fast failover
2461 * completed, and then start register the new FCF
2462 * record.
2463 */
2464
James Smart0c9ab6f2010-02-26 14:15:57 -05002465 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002466 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002467
2468 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002469 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002470 "2842 Replace in-use FCF (x%x) "
2471 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002472 phba->fcf.current_rec.fcf_indx,
2473 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002474 memcpy(&phba->fcf.current_rec,
2475 &phba->fcf.failover_rec,
2476 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002477 /*
2478 * Mark the fast FCF failover rediscovery completed
2479 * and the start of the first round of the roundrobin
2480 * FCF failover.
2481 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002482 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002483 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002484 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002485 /* Register to the new FCF record */
2486 lpfc_register_fcf(phba);
2487 } else {
2488 /*
2489 * In case of transaction period to fast FCF failover,
2490 * do nothing when search to the end of the FCF table.
2491 */
2492 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2493 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2494 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002495
James Smart7d791df2011-07-22 18:37:52 -04002496 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2497 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002498 /*
2499 * In case the current in-use FCF record no
2500 * longer existed during FCF discovery that
2501 * was not triggered by fast FCF failover
2502 * process, treat it as fast FCF failover.
2503 */
2504 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2505 "2841 In-use FCF record (x%x) "
2506 "not reported, entering fast "
2507 "FCF failover mode scanning.\n",
2508 phba->fcf.current_rec.fcf_indx);
2509 spin_lock_irq(&phba->hbalock);
2510 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2511 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002512 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2513 LPFC_FCOE_FCF_GET_FIRST);
2514 return;
2515 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002516 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002517 lpfc_register_fcf(phba);
2518 }
2519 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002520 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002521 return;
2522
2523out:
2524 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2525 lpfc_register_fcf(phba);
2526
2527 return;
2528}
2529
2530/**
James Smarta93ff372010-10-22 11:06:08 -04002531 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002532 * @phba: pointer to lpfc hba data structure.
2533 * @mboxq: pointer to mailbox object.
2534 *
James Smarta93ff372010-10-22 11:06:08 -04002535 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002536 * read FCF record mailbox command from the eligible FCF record bmask for
2537 * performing the failover. If the FCF read back is not valid/available, it
2538 * fails through to retrying FLOGI to the currently registered FCF again.
2539 * Otherwise, if the FCF read back is valid and available, it will set the
2540 * newly read FCF record to the failover FCF record, unregister currently
2541 * registered FCF record, copy the failover FCF record to the current
2542 * FCF record, and then register the current FCF record before proceeding
2543 * to trying FLOGI on the new failover FCF.
2544 */
2545void
2546lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2547{
2548 struct fcf_record *new_fcf_record;
2549 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002550 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002551 uint16_t current_fcf_index;
2552 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002553 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002554
James Smarta93ff372010-10-22 11:06:08 -04002555 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002556 if (phba->link_state < LPFC_LINK_UP) {
2557 spin_lock_irq(&phba->hbalock);
2558 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002559 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002560 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002561 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002562 }
2563
2564 /* Parse the FCF record from the non-embedded mailbox command */
2565 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2566 &next_fcf_index);
2567 if (!new_fcf_record) {
2568 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2569 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002570 "failed to retrieve a FCF record. "
2571 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2572 phba->fcf.fcf_flag);
2573 lpfc_unregister_fcf_rescan(phba);
2574 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002575 }
2576
2577 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002578 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2579 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002580
2581 /* Log the FCF record information if turned on */
2582 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2583 next_fcf_index);
2584
James Smarta93ff372010-10-22 11:06:08 -04002585 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2586 if (!rc) {
2587 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2588 "2848 Remove ineligible FCF (x%x) from "
2589 "from roundrobin bmask\n", fcf_index);
2590 /* Clear roundrobin bmask bit for ineligible FCF */
2591 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2592 /* Perform next round of roundrobin FCF failover */
2593 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2594 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2595 if (rc)
2596 goto out;
2597 goto error_out;
2598 }
2599
2600 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2601 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2602 "2760 Perform FLOGI roundrobin FCF failover: "
2603 "FCF (x%x) back to FCF (x%x)\n",
2604 phba->fcf.current_rec.fcf_indx, fcf_index);
2605 /* Wait 500 ms before retrying FLOGI to current FCF */
2606 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002607 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002608 goto out;
2609 }
2610
James Smart0c9ab6f2010-02-26 14:15:57 -05002611 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002612 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002613 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2614 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002615 spin_lock_irq(&phba->hbalock);
2616 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2617 new_fcf_record, addr_mode, vlan_id,
2618 (boot_flag ? BOOT_ENABLE : 0));
2619 spin_unlock_irq(&phba->hbalock);
2620
2621 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2622
2623 /* Unregister the current in-use FCF record */
2624 lpfc_unregister_fcf(phba);
2625
2626 /* Replace in-use record with the new record */
2627 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2628 sizeof(struct lpfc_fcf_rec));
2629
2630 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002631 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2632 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002633
James Smarta93ff372010-10-22 11:06:08 -04002634error_out:
2635 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002636out:
2637 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002638}
2639
2640/**
2641 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2642 * @phba: pointer to lpfc hba data structure.
2643 * @mboxq: pointer to mailbox object.
2644 *
2645 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002646 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002647 * failover when a new FCF event happened. If the FCF read back is
2648 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002649 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002650 */
2651void
2652lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2653{
2654 struct fcf_record *new_fcf_record;
2655 uint32_t boot_flag, addr_mode;
2656 uint16_t fcf_index, next_fcf_index;
2657 uint16_t vlan_id;
2658 int rc;
2659
2660 /* If link state is not up, no need to proceed */
2661 if (phba->link_state < LPFC_LINK_UP)
2662 goto out;
2663
2664 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002665 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002666 goto out;
2667
2668 /* Parse the FCF record from the non-embedded mailbox command */
2669 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2670 &next_fcf_index);
2671 if (!new_fcf_record) {
2672 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2673 "2767 Mailbox command READ_FCF_RECORD "
2674 "failed to retrieve a FCF record.\n");
2675 goto out;
2676 }
2677
2678 /* Check the connection list for eligibility */
2679 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2680 &addr_mode, &vlan_id);
2681
2682 /* Log the FCF record information if turned on */
2683 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2684 next_fcf_index);
2685
2686 if (!rc)
2687 goto out;
2688
2689 /* Update the eligible FCF record index bmask */
2690 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002691
2692 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002693
2694out:
2695 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2696}
2697
2698/**
James Smart76a95d72010-11-20 23:11:48 -05002699 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2700 * @phba: pointer to lpfc hba data structure.
2701 * @mboxq: pointer to mailbox data structure.
2702 *
2703 * This function handles completion of init vfi mailbox command.
2704 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002705static void
James Smart76a95d72010-11-20 23:11:48 -05002706lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2707{
2708 struct lpfc_vport *vport = mboxq->vport;
2709
James Smartdf9e1b52011-12-13 13:22:17 -05002710 /*
2711 * VFI not supported on interface type 0, just do the flogi
2712 * Also continue if the VFI is in use - just use the same one.
2713 */
2714 if (mboxq->u.mb.mbxStatus &&
2715 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2716 LPFC_SLI_INTF_IF_TYPE_0) &&
2717 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002718 lpfc_printf_vlog(vport, KERN_ERR,
2719 LOG_MBOX,
2720 "2891 Init VFI mailbox failed 0x%x\n",
2721 mboxq->u.mb.mbxStatus);
2722 mempool_free(mboxq, phba->mbox_mem_pool);
2723 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2724 return;
2725 }
James Smart73d91e52011-10-10 21:32:10 -04002726
James Smart76a95d72010-11-20 23:11:48 -05002727 lpfc_initial_flogi(vport);
2728 mempool_free(mboxq, phba->mbox_mem_pool);
2729 return;
2730}
2731
2732/**
2733 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2734 * @vport: pointer to lpfc_vport data structure.
2735 *
2736 * This function issue a init_vfi mailbox command to initialize the VFI and
2737 * VPI for the physical port.
2738 */
2739void
2740lpfc_issue_init_vfi(struct lpfc_vport *vport)
2741{
2742 LPFC_MBOXQ_t *mboxq;
2743 int rc;
2744 struct lpfc_hba *phba = vport->phba;
2745
2746 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2747 if (!mboxq) {
2748 lpfc_printf_vlog(vport, KERN_ERR,
2749 LOG_MBOX, "2892 Failed to allocate "
2750 "init_vfi mailbox\n");
2751 return;
2752 }
2753 lpfc_init_vfi(mboxq, vport);
2754 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2755 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2756 if (rc == MBX_NOT_FINISHED) {
2757 lpfc_printf_vlog(vport, KERN_ERR,
2758 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2759 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2760 }
2761}
2762
2763/**
James Smart1c6834a2009-07-19 10:01:26 -04002764 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2765 * @phba: pointer to lpfc hba data structure.
2766 * @mboxq: pointer to mailbox data structure.
2767 *
2768 * This function handles completion of init vpi mailbox command.
2769 */
James Smart695a8142010-01-26 23:08:03 -05002770void
James Smart1c6834a2009-07-19 10:01:26 -04002771lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2772{
2773 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002774 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002775 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2776
James Smart1c6834a2009-07-19 10:01:26 -04002777 if (mboxq->u.mb.mbxStatus) {
2778 lpfc_printf_vlog(vport, KERN_ERR,
2779 LOG_MBOX,
2780 "2609 Init VPI mailbox failed 0x%x\n",
2781 mboxq->u.mb.mbxStatus);
2782 mempool_free(mboxq, phba->mbox_mem_pool);
2783 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2784 return;
2785 }
James Smart72100cc2010-02-12 14:43:01 -05002786 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002787 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002788 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002789
James Smart695a8142010-01-26 23:08:03 -05002790 /* If this port is physical port or FDISC is done, do reg_vpi */
2791 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2792 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2793 if (!ndlp)
2794 lpfc_printf_vlog(vport, KERN_ERR,
2795 LOG_DISCOVERY,
2796 "2731 Cannot find fabric "
2797 "controller node\n");
2798 else
2799 lpfc_register_new_vport(phba, vport, ndlp);
2800 mempool_free(mboxq, phba->mbox_mem_pool);
2801 return;
2802 }
2803
James Smart1c6834a2009-07-19 10:01:26 -04002804 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2805 lpfc_initial_fdisc(vport);
2806 else {
2807 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002808 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2809 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002810 }
James Smart695a8142010-01-26 23:08:03 -05002811 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002812 return;
2813}
2814
2815/**
James Smartecfd03c2010-02-12 14:41:27 -05002816 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2817 * @vport: pointer to lpfc_vport data structure.
2818 *
2819 * This function issue a init_vpi mailbox command to initialize
2820 * VPI for the vport.
2821 */
2822void
2823lpfc_issue_init_vpi(struct lpfc_vport *vport)
2824{
2825 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002826 int rc, vpi;
2827
2828 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2829 vpi = lpfc_alloc_vpi(vport->phba);
2830 if (!vpi) {
2831 lpfc_printf_vlog(vport, KERN_ERR,
2832 LOG_MBOX,
2833 "3303 Failed to obtain vport vpi\n");
2834 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2835 return;
2836 }
2837 vport->vpi = vpi;
2838 }
James Smartecfd03c2010-02-12 14:41:27 -05002839
2840 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2841 if (!mboxq) {
2842 lpfc_printf_vlog(vport, KERN_ERR,
2843 LOG_MBOX, "2607 Failed to allocate "
2844 "init_vpi mailbox\n");
2845 return;
2846 }
2847 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2848 mboxq->vport = vport;
2849 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2850 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2851 if (rc == MBX_NOT_FINISHED) {
2852 lpfc_printf_vlog(vport, KERN_ERR,
2853 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2854 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2855 }
2856}
2857
2858/**
James Smart6fb120a2009-05-22 14:52:59 -04002859 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2860 * @phba: pointer to lpfc hba data structure.
2861 *
2862 * This function loops through the list of vports on the @phba and issues an
2863 * FDISC if possible.
2864 */
2865void
2866lpfc_start_fdiscs(struct lpfc_hba *phba)
2867{
2868 struct lpfc_vport **vports;
2869 int i;
2870
2871 vports = lpfc_create_vport_work_array(phba);
2872 if (vports != NULL) {
2873 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2874 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2875 continue;
2876 /* There are no vpi for this vport */
2877 if (vports[i]->vpi > phba->max_vpi) {
2878 lpfc_vport_set_state(vports[i],
2879 FC_VPORT_FAILED);
2880 continue;
2881 }
James Smart76a95d72010-11-20 23:11:48 -05002882 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002883 lpfc_vport_set_state(vports[i],
2884 FC_VPORT_LINKDOWN);
2885 continue;
2886 }
James Smart1c6834a2009-07-19 10:01:26 -04002887 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002888 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002889 continue;
2890 }
James Smart6fb120a2009-05-22 14:52:59 -04002891 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2892 lpfc_initial_fdisc(vports[i]);
2893 else {
2894 lpfc_vport_set_state(vports[i],
2895 FC_VPORT_NO_FABRIC_SUPP);
2896 lpfc_printf_vlog(vports[i], KERN_ERR,
2897 LOG_ELS,
2898 "0259 No NPIV "
2899 "Fabric support\n");
2900 }
2901 }
2902 }
2903 lpfc_destroy_vport_work_array(phba, vports);
2904}
2905
2906void
2907lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2908{
2909 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2910 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002912
James Smartf5eca9b2012-03-01 22:37:54 -05002913 /*
2914 * VFI not supported for interface type 0, so ignore any mailbox
2915 * error (except VFI in use) and continue with the discovery.
2916 */
2917 if (mboxq->u.mb.mbxStatus &&
2918 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2919 LPFC_SLI_INTF_IF_TYPE_0) &&
2920 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002921 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2922 "2018 REG_VFI mbxStatus error x%x "
2923 "HBA state x%x\n",
2924 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002925 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002926 /* FLOGI failed, use loop map to make discovery list */
2927 lpfc_disc_list_loopmap(vport);
2928 /* Start discovery */
2929 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002930 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002931 }
2932 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002933 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002934 }
James Smartae05ebe2013-03-01 16:35:38 -05002935
James Smarte74c03c2013-04-17 20:15:19 -04002936 /* If the VFI is already registered, there is nothing else to do
2937 * Unless this was a VFI update and we are in PT2PT mode, then
2938 * we should drop through to set the port state to ready.
2939 */
James Smartae05ebe2013-03-01 16:35:38 -05002940 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04002941 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2942 vport->fc_flag & FC_PT2PT))
2943 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05002944
James Smartc8685952009-11-18 15:39:16 -05002945 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002946 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002947 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002948 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002949 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04002950 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002951 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04002952
James Smart1b511972011-12-13 13:23:09 -05002953 /* In case SLI4 FC loopback test, we are ready */
2954 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2955 (phba->link_flag & LS_LOOPBACK_MODE)) {
2956 phba->link_state = LPFC_HBA_READY;
2957 goto out_free_mem;
2958 }
2959
James Smarte74c03c2013-04-17 20:15:19 -04002960 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2961 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
2962 "alpacnt:%d LinkState:%x topology:%x\n",
2963 vport->port_state, vport->fc_flag, vport->fc_myDID,
2964 vport->phba->alpa_map[0],
2965 phba->link_state, phba->fc_topology);
2966
James Smart6fb120a2009-05-22 14:52:59 -04002967 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04002968 /*
2969 * For private loop or for NPort pt2pt,
2970 * just start discovery and we are done.
2971 */
2972 if ((vport->fc_flag & FC_PT2PT) ||
2973 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2974 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2975
James Smart76a95d72010-11-20 23:11:48 -05002976 /* Use loop map to make discovery list */
2977 lpfc_disc_list_loopmap(vport);
2978 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04002979 if (vport->fc_flag & FC_PT2PT)
2980 vport->port_state = LPFC_VPORT_READY;
2981 else
2982 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05002983 } else {
2984 lpfc_start_fdiscs(phba);
2985 lpfc_do_scr_ns_plogi(phba, vport);
2986 }
James Smart6fb120a2009-05-22 14:52:59 -04002987 }
2988
James Smart1b511972011-12-13 13:23:09 -05002989out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04002990 mempool_free(mboxq, phba->mbox_mem_pool);
James Smartd6de08c2015-12-16 18:11:53 -05002991 if (dmabuf) {
2992 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2993 kfree(dmabuf);
2994 }
James Smart6fb120a2009-05-22 14:52:59 -04002995 return;
2996}
2997
2998static void
James Smart2e0fef82007-06-17 19:56:36 -05002999lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003000{
James Smart6fb120a2009-05-22 14:52:59 -04003001 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05003002 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05003003 struct lpfc_vport *vport = pmb->vport;
James Smart21bf0b92015-08-31 16:48:21 -04003004 struct serv_parm *sp = &vport->fc_sparam;
3005 uint32_t ed_tov;
dea31012005-04-17 16:05:31 -05003006
3007 /* Check for error */
3008 if (mb->mbxStatus) {
3009 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3011 "0319 READ_SPARAM mbxStatus error x%x "
3012 "hba state x%x>\n",
3013 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003014 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003015 goto out;
3016 }
3017
James Smart2e0fef82007-06-17 19:56:36 -05003018 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003019 sizeof (struct serv_parm));
James Smart21bf0b92015-08-31 16:48:21 -04003020
3021 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3022 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3023 ed_tov = (ed_tov + 999999) / 1000000;
3024
3025 phba->fc_edtov = ed_tov;
3026 phba->fc_ratov = (2 * ed_tov) / 1000;
3027 if (phba->fc_ratov < FF_DEF_RATOV) {
3028 /* RA_TOV should be atleast 10sec for initial flogi */
3029 phba->fc_ratov = FF_DEF_RATOV;
3030 }
3031
James Smart05580562011-05-24 11:40:48 -04003032 lpfc_update_vport_wwn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003033 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3034 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3035 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3036 }
3037
dea31012005-04-17 16:05:31 -05003038 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3039 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003040 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003041 return;
3042
3043out:
3044 pmb->context1 = NULL;
3045 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3046 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003047 lpfc_issue_clear_la(phba, vport);
3048 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003049 return;
3050}
3051
3052static void
James Smart76a95d72010-11-20 23:11:48 -05003053lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003054{
James Smart92d7f7b2007-06-17 19:56:38 -05003055 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003056 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003057 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003058 int i;
James Smart14691152006-12-02 13:34:28 -05003059 struct lpfc_dmabuf *mp;
3060 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003061 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003062 uint32_t fc_flags = 0;
James Smart14691152006-12-02 13:34:28 -05003063
James Smart92d7f7b2007-06-17 19:56:38 -05003064 spin_lock_irq(&phba->hbalock);
James Smarta085e872015-12-16 18:12:02 -05003065 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3066
3067 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3068 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3069 case LPFC_LINK_SPEED_1GHZ:
3070 case LPFC_LINK_SPEED_2GHZ:
3071 case LPFC_LINK_SPEED_4GHZ:
3072 case LPFC_LINK_SPEED_8GHZ:
3073 case LPFC_LINK_SPEED_10GHZ:
3074 case LPFC_LINK_SPEED_16GHZ:
3075 case LPFC_LINK_SPEED_32GHZ:
3076 break;
3077 default:
3078 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3079 break;
3080 }
dea31012005-04-17 16:05:31 -05003081 }
3082
James Smarte74c03c2013-04-17 20:15:19 -04003083 if (phba->fc_topology &&
3084 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3085 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3086 "3314 Toplogy changed was 0x%x is 0x%x\n",
3087 phba->fc_topology,
3088 bf_get(lpfc_mbx_read_top_topology, la));
3089 phba->fc_topology_changed = 1;
3090 }
3091
James Smart76a95d72010-11-20 23:11:48 -05003092 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003093 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003094
James Smartdf9e1b52011-12-13 13:22:17 -05003095 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003096 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003097 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003098
James Smart6a9c52c2009-10-02 15:16:51 -04003099 /* if npiv is enabled and this adapter supports npiv log
3100 * a message that npiv is not supported in this topology
3101 */
3102 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003103 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3104 "1309 Link Up Event npiv not supported in loop "
3105 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003106 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003107 if (bf_get(lpfc_mbx_read_top_il, la))
3108 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003109
James Smart76a95d72010-11-20 23:11:48 -05003110 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3111 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003112
3113 if (i == 0) {
3114 phba->alpa_map[0] = 0;
3115 } else {
James Smarte8b62012007-08-02 11:10:09 -04003116 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003117 int numalpa, j, k;
3118 union {
3119 uint8_t pamap[16];
3120 struct {
3121 uint32_t wd1;
3122 uint32_t wd2;
3123 uint32_t wd3;
3124 uint32_t wd4;
3125 } pa;
3126 } un;
3127 numalpa = phba->alpa_map[0];
3128 j = 0;
3129 while (j < numalpa) {
3130 memset(un.pamap, 0, 16);
3131 for (k = 1; j < numalpa; k++) {
3132 un.pamap[k - 1] =
3133 phba->alpa_map[j + 1];
3134 j++;
3135 if (k == 16)
3136 break;
3137 }
3138 /* Link Up Event ALPA map */
3139 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003140 KERN_WARNING,
3141 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003142 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003143 "ALPA map Data: x%x "
3144 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003145 un.pa.wd1, un.pa.wd2,
3146 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003147 }
3148 }
3149 }
3150 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003151 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003152 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003153 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003154 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3155 }
James Smart2e0fef82007-06-17 19:56:36 -05003156 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003157 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003158 }
James Smart92d7f7b2007-06-17 19:56:38 -05003159 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003160
James Smart38c20672013-03-01 16:37:44 -05003161 if (fc_flags) {
3162 spin_lock_irq(shost->host_lock);
3163 vport->fc_flag |= fc_flags;
3164 spin_unlock_irq(shost->host_lock);
3165 }
3166
dea31012005-04-17 16:05:31 -05003167 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05003168 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3169 if (!sparam_mbox)
3170 goto out;
3171
3172 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3173 if (rc) {
3174 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3175 goto out;
3176 }
3177 sparam_mbox->vport = vport;
3178 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3179 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3180 if (rc == MBX_NOT_FINISHED) {
3181 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3182 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3183 kfree(mp);
3184 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3185 goto out;
dea31012005-04-17 16:05:31 -05003186 }
3187
James Smart76a95d72010-11-20 23:11:48 -05003188 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04003189 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3190 if (!cfglink_mbox)
3191 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05003192 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05003193 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05003194 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05003195 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04003196 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04003197 if (rc == MBX_NOT_FINISHED) {
3198 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3199 goto out;
3200 }
3201 } else {
James Smart32b97932009-07-19 10:01:21 -04003202 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003203 /*
3204 * Add the driver's default FCF record at FCF index 0 now. This
3205 * is phase 1 implementation that support FCF index 0 and driver
3206 * defaults.
3207 */
James Smart45ed1192009-10-02 15:17:02 -04003208 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003209 fcf_record = kzalloc(sizeof(struct fcf_record),
3210 GFP_KERNEL);
3211 if (unlikely(!fcf_record)) {
3212 lpfc_printf_log(phba, KERN_ERR,
3213 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003214 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003215 "fcf record\n");
3216 rc = -ENODEV;
3217 goto out;
3218 }
3219
3220 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3221 LPFC_FCOE_FCF_DEF_INDEX);
3222 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3223 if (unlikely(rc)) {
3224 lpfc_printf_log(phba, KERN_ERR,
3225 LOG_MBOX | LOG_SLI,
3226 "2013 Could not manually add FCF "
3227 "record 0, status %d\n", rc);
3228 rc = -ENODEV;
3229 kfree(fcf_record);
3230 goto out;
3231 }
3232 kfree(fcf_record);
3233 }
3234 /*
3235 * The driver is expected to do FIP/FCF. Call the port
3236 * and get the FCF Table.
3237 */
James Smart32b97932009-07-19 10:01:21 -04003238 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003239 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart32b97932009-07-19 10:01:21 -04003240 spin_unlock_irq(&phba->hbalock);
3241 return;
3242 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003243 /* This is the initial FCF discovery scan */
3244 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04003245 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003246 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3247 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003248 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3249 LPFC_FCOE_FCF_GET_FIRST);
3250 if (rc) {
3251 spin_lock_irq(&phba->hbalock);
3252 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3253 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04003254 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003255 }
James Smart38b92ef2010-08-04 16:11:39 -04003256 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003257 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003258 }
James Smart6fb120a2009-05-22 14:52:59 -04003259
3260 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003261out:
3262 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003263 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3264 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3265 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003266 lpfc_issue_clear_la(phba, vport);
3267 return;
dea31012005-04-17 16:05:31 -05003268}
3269
3270static void
James Smart84774a42008-08-24 21:50:06 -04003271lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003272{
dea31012005-04-17 16:05:31 -05003273 uint32_t control;
3274 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003275 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003276 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003277 if (phba->sli_rev <= LPFC_SLI_REV3) {
3278 control = readl(phba->HCregaddr);
3279 control |= HC_LAINT_ENA;
3280 writel(control, phba->HCregaddr);
3281 readl(phba->HCregaddr); /* flush */
3282 }
James Smart2e0fef82007-06-17 19:56:36 -05003283 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003284}
3285
James Smart84774a42008-08-24 21:50:06 -04003286static void
3287lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3288{
3289 lpfc_linkdown(phba);
3290 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003291 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003292 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3293}
3294
3295
dea31012005-04-17 16:05:31 -05003296/*
James Smart76a95d72010-11-20 23:11:48 -05003297 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003298 * command upon completion. It is setup in the LPFC_MBOXQ
3299 * as the completion routine when the command is
James Smart895427b2017-02-12 13:52:30 -08003300 * handed off to the SLI layer. SLI4 only.
dea31012005-04-17 16:05:31 -05003301 */
3302void
James Smart76a95d72010-11-20 23:11:48 -05003303lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003304{
James Smart2e0fef82007-06-17 19:56:36 -05003305 struct lpfc_vport *vport = pmb->vport;
3306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003307 struct lpfc_mbx_read_top *la;
James Smart895427b2017-02-12 13:52:30 -08003308 struct lpfc_sli_ring *pring;
James Smart04c68492009-05-22 14:52:52 -04003309 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05003310 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3311
James Smart0d2b6b82008-06-14 22:52:47 -04003312 /* Unblock ELS traffic */
James Smart895427b2017-02-12 13:52:30 -08003313 pring = lpfc_phba_elsring(phba);
3314 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3315
dea31012005-04-17 16:05:31 -05003316 /* Check for error */
3317 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003318 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003319 "1307 READ_LA mbox error x%x state x%x\n",
3320 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003321 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003322 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003323 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003324 }
3325
James Smart76a95d72010-11-20 23:11:48 -05003326 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
dea31012005-04-17 16:05:31 -05003327
3328 memcpy(&phba->alpa_map[0], mp->virt, 128);
3329
James Smart2e0fef82007-06-17 19:56:36 -05003330 spin_lock_irq(shost->host_lock);
James Smart76a95d72010-11-20 23:11:48 -05003331 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003332 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003333 else
James Smart2e0fef82007-06-17 19:56:36 -05003334 vport->fc_flag &= ~FC_BYPASSED_MODE;
3335 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003336
James Smartbe0c0082013-03-01 16:38:14 -05003337 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003338 phba->fc_stat.LinkMultiEvent++;
James Smart76a95d72010-11-20 23:11:48 -05003339 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003340 if (phba->fc_eventTag != 0)
3341 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003342 }
dea31012005-04-17 16:05:31 -05003343
3344 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003345 if (phba->sli_rev < LPFC_SLI_REV4) {
3346 spin_lock_irq(&phba->hbalock);
3347 if (bf_get(lpfc_mbx_read_top_mm, la))
3348 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3349 else
3350 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3351 spin_unlock_irq(&phba->hbalock);
3352 }
dea31012005-04-17 16:05:31 -05003353
James Smart4d9ab992009-10-02 15:16:39 -04003354 phba->link_events++;
James Smart76a95d72010-11-20 23:11:48 -05003355 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003356 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003357 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003358 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003359 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003360 "1306 Link Up Event in loop back mode "
3361 "x%x received Data: x%x x%x x%x x%x\n",
3362 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003363 bf_get(lpfc_mbx_read_top_alpa_granted,
3364 la),
3365 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003366 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003367 } else {
3368 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003369 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003370 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003371 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003372 bf_get(lpfc_mbx_read_top_alpa_granted,
3373 la),
3374 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003375 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003376 bf_get(lpfc_mbx_read_top_mm, la),
3377 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003378 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003379 }
James Smart92d7f7b2007-06-17 19:56:38 -05003380 lpfc_mbx_process_link_up(phba, la);
James Smart76a95d72010-11-20 23:11:48 -05003381 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3382 LPFC_ATT_LINK_DOWN) {
dea31012005-04-17 16:05:31 -05003383 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003384 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003385 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3386 "1308 Link Down Event in loop back mode "
3387 "x%x received "
3388 "Data: x%x x%x x%x\n",
3389 la->eventTag, phba->fc_eventTag,
3390 phba->pport->port_state, vport->fc_flag);
James Smart1b511972011-12-13 13:23:09 -05003391 else
James Smart3163f722008-02-08 18:50:25 -05003392 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003393 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003394 "Data: x%x x%x x%x x%x x%x\n",
3395 la->eventTag, phba->fc_eventTag,
3396 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003397 bf_get(lpfc_mbx_read_top_mm, la),
3398 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003399 lpfc_mbx_issue_link_down(phba);
3400 }
James Smartbe0c0082013-03-01 16:38:14 -05003401 if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) &&
3402 ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) {
James Smart84774a42008-08-24 21:50:06 -04003403 if (phba->link_state != LPFC_LINK_DOWN) {
3404 phba->fc_stat.LinkDown++;
3405 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3406 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003407 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003408 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003409 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003410 lpfc_mbx_issue_link_down(phba);
3411 } else
3412 lpfc_enable_la(phba);
3413
3414 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3415 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3416 "Data: x%x x%x x%x\n",
3417 la->eventTag, phba->fc_eventTag,
3418 phba->pport->port_state, vport->fc_flag);
3419 /*
3420 * The cmnd that triggered this will be waiting for this
3421 * signal.
3422 */
3423 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3424 if (phba->wait_4_mlo_maint_flg) {
3425 phba->wait_4_mlo_maint_flg = 0;
3426 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003427 }
James Smart84774a42008-08-24 21:50:06 -04003428 }
3429
James Smartbe0c0082013-03-01 16:38:14 -05003430 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3431 bf_get(lpfc_mbx_read_top_fa, la)) {
3432 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003433 lpfc_issue_clear_la(phba, vport);
3434 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003435 "1311 fa %d\n",
3436 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003437 }
3438
James Smart76a95d72010-11-20 23:11:48 -05003439lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003440 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3441 kfree(mp);
3442 mempool_free(pmb, phba->mbox_mem_pool);
3443 return;
3444}
3445
3446/*
3447 * This routine handles processing a REG_LOGIN mailbox
3448 * command upon completion. It is setup in the LPFC_MBOXQ
3449 * as the completion routine when the command is
3450 * handed off to the SLI layer.
3451 */
3452void
James Smart2e0fef82007-06-17 19:56:36 -05003453lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003454{
James Smart2e0fef82007-06-17 19:56:36 -05003455 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003456 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05003457 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smartffc95492010-06-07 15:23:17 -04003458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003459
dea31012005-04-17 16:05:31 -05003460 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003461 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05003462
James Smartbe6bb942015-04-07 15:07:22 -04003463 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3464 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3465 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003466 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003467 ndlp->nlp_usg_map, ndlp);
James Smartffc95492010-06-07 15:23:17 -04003468 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3469 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3470
James Smart40426292010-12-15 17:58:10 -05003471 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3472 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003473 /* We rcvd a rscn after issuing this
3474 * mbox reg login, we may have cycled
3475 * back through the state and be
3476 * back at reg login state so this
3477 * mbox needs to be ignored becase
3478 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003479 * process.
James Smartffc95492010-06-07 15:23:17 -04003480 */
3481 spin_lock_irq(shost->host_lock);
3482 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3483 spin_unlock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -08003484
3485 /*
3486 * We cannot leave the RPI registered because
3487 * if we go thru discovery again for this ndlp
3488 * a subsequent REG_RPI will fail.
3489 */
3490 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3491 lpfc_unreg_rpi(vport, ndlp);
James Smart4b7789b72015-12-16 18:11:55 -05003492 }
3493
3494 /* Call state machine */
3495 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
James Smartffc95492010-06-07 15:23:17 -04003496
dea31012005-04-17 16:05:31 -05003497 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3498 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003499 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003500 /* decrement the node reference count held for this callback
3501 * function.
3502 */
James Smart329f9bc2007-04-25 09:53:01 -04003503 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003504
3505 return;
3506}
3507
James Smart92d7f7b2007-06-17 19:56:38 -05003508static void
3509lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3510{
James Smart04c68492009-05-22 14:52:52 -04003511 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003512 struct lpfc_vport *vport = pmb->vport;
3513 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3514
3515 switch (mb->mbxStatus) {
3516 case 0x0011:
3517 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003518 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3519 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3520 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003521 break;
James Smart78730cf2010-04-06 15:06:30 -04003522 /* If VPI is busy, reset the HBA */
3523 case 0x9700:
3524 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3525 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3526 vport->vpi, mb->mbxStatus);
3527 if (!(phba->pport->load_flag & FC_UNLOADING))
3528 lpfc_workq_post_event(phba, NULL, NULL,
3529 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003530 }
James Smart72100cc2010-02-12 14:43:01 -05003531 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003532 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003533 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003534 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003535 vport->unreg_vpi_cmpl = VPORT_OK;
3536 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003537 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003538 /*
3539 * This shost reference might have been taken at the beginning of
3540 * lpfc_vport_delete()
3541 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003542 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003543 scsi_host_put(shost);
3544}
3545
James Smartd7c255b2008-08-24 21:50:00 -04003546int
James Smart92d7f7b2007-06-17 19:56:38 -05003547lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3548{
3549 struct lpfc_hba *phba = vport->phba;
3550 LPFC_MBOXQ_t *mbox;
3551 int rc;
3552
3553 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3554 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003555 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003556
3557 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3558 mbox->vport = vport;
3559 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003560 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003561 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003562 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3563 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003564 mempool_free(mbox, phba->mbox_mem_pool);
3565 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003566 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003567 }
James Smartd7c255b2008-08-24 21:50:00 -04003568 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003569}
3570
3571static void
3572lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3573{
3574 struct lpfc_vport *vport = pmb->vport;
3575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003576 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003577
3578 switch (mb->mbxStatus) {
3579 case 0x0011:
3580 case 0x9601:
3581 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003582 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3583 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3584 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003585 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3586 spin_lock_irq(shost->host_lock);
3587 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3588 spin_unlock_irq(shost->host_lock);
3589 vport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003590
James Smart01649562017-02-12 13:52:32 -08003591 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -08003592 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08003593 if (phba->nvmet_support)
3594 lpfc_nvmet_update_targetport(phba);
3595 else
James Smart8c258642017-02-12 13:52:36 -08003596 lpfc_nvme_update_localport(vport);
James Smart8c258642017-02-12 13:52:36 -08003597 }
James Smart92d7f7b2007-06-17 19:56:38 -05003598 goto out;
3599 }
James Smart92d7f7b2007-06-17 19:56:38 -05003600
James Smart72100cc2010-02-12 14:43:01 -05003601 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003602 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003603 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003604 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003605 vport->num_disc_nodes = 0;
3606 /* go thru NPR list and issue ELS PLOGIs */
3607 if (vport->fc_npr_cnt)
3608 lpfc_els_disc_plogi(vport);
3609
3610 if (!vport->num_disc_nodes) {
3611 spin_lock_irq(shost->host_lock);
3612 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3613 spin_unlock_irq(shost->host_lock);
3614 lpfc_can_disctmo(vport);
3615 }
3616 vport->port_state = LPFC_VPORT_READY;
3617
3618out:
3619 mempool_free(pmb, phba->mbox_mem_pool);
3620 return;
3621}
3622
James Smart21e9a0a2009-05-22 14:53:21 -04003623/**
3624 * lpfc_create_static_vport - Read HBA config region to create static vports.
3625 * @phba: pointer to lpfc hba data structure.
3626 *
3627 * This routine issue a DUMP mailbox command for config region 22 to get
3628 * the list of static vports to be created. The function create vports
3629 * based on the information returned from the HBA.
3630 **/
3631void
3632lpfc_create_static_vport(struct lpfc_hba *phba)
3633{
3634 LPFC_MBOXQ_t *pmb = NULL;
3635 MAILBOX_t *mb;
3636 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003637 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003638 struct fc_vport_identifiers vport_id;
3639 struct fc_vport *new_fc_vport;
3640 struct Scsi_Host *shost;
3641 struct lpfc_vport *vport;
3642 uint16_t offset = 0;
3643 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003644 struct lpfc_dmabuf *mp;
3645 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003646
3647 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3648 if (!pmb) {
3649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3650 "0542 lpfc_create_static_vport failed to"
3651 " allocate mailbox memory\n");
3652 return;
3653 }
James Smartcdcc2342012-08-14 14:26:35 -04003654 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003655 mb = &pmb->u.mb;
3656
3657 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3658 if (!vport_info) {
3659 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3660 "0543 lpfc_create_static_vport failed to"
3661 " allocate vport_info\n");
3662 mempool_free(pmb, phba->mbox_mem_pool);
3663 return;
3664 }
3665
3666 vport_buff = (uint8_t *) vport_info;
3667 do {
James Smartcdcc2342012-08-14 14:26:35 -04003668 /* free dma buffer from previous round */
3669 if (pmb->context1) {
3670 mp = (struct lpfc_dmabuf *)pmb->context1;
3671 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3672 kfree(mp);
3673 }
James Smart1c6834a2009-07-19 10:01:26 -04003674 if (lpfc_dump_static_vport(phba, pmb, offset))
3675 goto out;
3676
James Smart21e9a0a2009-05-22 14:53:21 -04003677 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003678 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3679 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003680
James Smartcdcc2342012-08-14 14:26:35 -04003681 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003682 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3683 "0544 lpfc_create_static_vport failed to"
3684 " issue dump mailbox command ret 0x%x "
3685 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003686 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003687 goto out;
3688 }
3689
James Smart1c6834a2009-07-19 10:01:26 -04003690 if (phba->sli_rev == LPFC_SLI_REV4) {
3691 byte_count = pmb->u.mqe.un.mb_words[5];
James Smartcdcc2342012-08-14 14:26:35 -04003692 mp = (struct lpfc_dmabuf *)pmb->context1;
James Smart1c6834a2009-07-19 10:01:26 -04003693 if (byte_count > sizeof(struct static_vport_info) -
3694 offset)
3695 byte_count = sizeof(struct static_vport_info)
3696 - offset;
3697 memcpy(vport_buff + offset, mp->virt, byte_count);
3698 offset += byte_count;
3699 } else {
3700 if (mb->un.varDmp.word_cnt >
3701 sizeof(struct static_vport_info) - offset)
3702 mb->un.varDmp.word_cnt =
3703 sizeof(struct static_vport_info)
3704 - offset;
3705 byte_count = mb->un.varDmp.word_cnt;
3706 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3707 vport_buff + offset,
3708 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003709
James Smart1c6834a2009-07-19 10:01:26 -04003710 offset += byte_count;
3711 }
James Smart21e9a0a2009-05-22 14:53:21 -04003712
James Smart1c6834a2009-07-19 10:01:26 -04003713 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003714 offset < sizeof(struct static_vport_info));
3715
3716
3717 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3718 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3719 != VPORT_INFO_REV)) {
3720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3721 "0545 lpfc_create_static_vport bad"
3722 " information header 0x%x 0x%x\n",
3723 le32_to_cpu(vport_info->signature),
3724 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3725
3726 goto out;
3727 }
3728
3729 shost = lpfc_shost_from_vport(phba->pport);
3730
3731 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3732 memset(&vport_id, 0, sizeof(vport_id));
3733 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3734 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3735 if (!vport_id.port_name || !vport_id.node_name)
3736 continue;
3737
3738 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3739 vport_id.vport_type = FC_PORTTYPE_NPIV;
3740 vport_id.disable = false;
3741 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3742
3743 if (!new_fc_vport) {
3744 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3745 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003746 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003747 continue;
3748 }
3749
3750 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3751 vport->vport_flag |= STATIC_VPORT;
3752 }
3753
3754out:
James Smart21e9a0a2009-05-22 14:53:21 -04003755 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003756 if (mbx_wait_rc != MBX_TIMEOUT) {
3757 if (pmb->context1) {
3758 mp = (struct lpfc_dmabuf *)pmb->context1;
James Smart1c6834a2009-07-19 10:01:26 -04003759 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3760 kfree(mp);
3761 }
James Smart21e9a0a2009-05-22 14:53:21 -04003762 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003763 }
James Smart21e9a0a2009-05-22 14:53:21 -04003764
3765 return;
3766}
3767
dea31012005-04-17 16:05:31 -05003768/*
3769 * This routine handles processing a Fabric REG_LOGIN mailbox
3770 * command upon completion. It is setup in the LPFC_MBOXQ
3771 * as the completion routine when the command is
3772 * handed off to the SLI layer.
3773 */
3774void
James Smart2e0fef82007-06-17 19:56:36 -05003775lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003776{
James Smart92d7f7b2007-06-17 19:56:38 -05003777 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003778 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003779 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05003780 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003781 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003782
James Smart549e55c2007-08-02 11:09:51 -04003783 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04003784 pmb->context1 = NULL;
3785 pmb->context2 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003786
dea31012005-04-17 16:05:31 -05003787 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003788 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3789 "0258 Register Fabric login error: 0x%x\n",
3790 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003791 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3792 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003793 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003794
James Smart76a95d72010-11-20 23:11:48 -05003795 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003796 /* FLOGI failed, use loop map to make discovery list */
3797 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003798
James Smart92d7f7b2007-06-17 19:56:38 -05003799 /* Start discovery */
3800 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003801 /* Decrement the reference count to ndlp after the
3802 * reference to the ndlp are done.
3803 */
3804 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003805 return;
3806 }
3807
3808 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003809 /* Decrement the reference count to ndlp after the reference
3810 * to the ndlp are done.
3811 */
3812 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003813 return;
3814 }
3815
James Smart6d368e52011-05-24 11:44:12 -04003816 if (phba->sli_rev < LPFC_SLI_REV4)
3817 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003818 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003819 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003820 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003821
James Smart2e0fef82007-06-17 19:56:36 -05003822 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003823 /* when physical port receive logo donot start
3824 * vport discovery */
3825 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3826 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003827 else {
3828 shost = lpfc_shost_from_vport(vport);
3829 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003830 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003831 spin_unlock_irq(shost->host_lock);
3832 }
James Smart92d7f7b2007-06-17 19:56:38 -05003833 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003834 }
3835
3836 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3837 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003838 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003839
3840 /* Drop the reference count from the mbox at the end after
3841 * all the current reference to the ndlp have been done.
3842 */
3843 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003844 return;
3845}
3846
James Smarta0f2d3e2017-02-12 13:52:31 -08003847 /*
3848 * This routine will issue a GID_FT for each FC4 Type supported
3849 * by the driver. ALL GID_FTs must complete before discovery is started.
3850 */
3851int
3852lpfc_issue_gidft(struct lpfc_vport *vport)
3853{
3854 struct lpfc_hba *phba = vport->phba;
3855
3856 /* Good status, issue CT Request to NameServer */
3857 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3858 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
3859 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
3860 /* Cannot issue NameServer FCP Query, so finish up
3861 * discovery
3862 */
3863 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3864 "0604 %s FC TYPE %x %s\n",
3865 "Failed to issue GID_FT to ",
3866 FC_TYPE_FCP,
3867 "Finishing discovery.");
3868 return 0;
3869 }
3870 vport->gidft_inp++;
3871 }
3872
3873 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3874 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3875 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
3876 /* Cannot issue NameServer NVME Query, so finish up
3877 * discovery
3878 */
3879 lpfc_printf_vlog(vport, KERN_ERR, LOG_SLI,
3880 "0605 %s FC_TYPE %x %s %d\n",
3881 "Failed to issue GID_FT to ",
3882 FC_TYPE_NVME,
3883 "Finishing discovery: gidftinp ",
3884 vport->gidft_inp);
3885 if (vport->gidft_inp == 0)
3886 return 0;
3887 } else
3888 vport->gidft_inp++;
3889 }
3890 return vport->gidft_inp;
3891}
3892
dea31012005-04-17 16:05:31 -05003893/*
3894 * This routine handles processing a NameServer REG_LOGIN mailbox
3895 * command upon completion. It is setup in the LPFC_MBOXQ
3896 * as the completion routine when the command is
3897 * handed off to the SLI layer.
3898 */
3899void
James Smart2e0fef82007-06-17 19:56:36 -05003900lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003901{
James Smart21e9a0a2009-05-22 14:53:21 -04003902 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003903 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3904 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3905 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05003906
James Smartd439d282010-09-29 11:18:45 -04003907 pmb->context1 = NULL;
3908 pmb->context2 = NULL;
James Smarta0f2d3e2017-02-12 13:52:31 -08003909 vport->gidft_inp = 0;
James Smartd439d282010-09-29 11:18:45 -04003910
dea31012005-04-17 16:05:31 -05003911 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003912 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3913 "0260 Register NameServer error: 0x%x\n",
3914 mb->mbxStatus);
James Smarta0f2d3e2017-02-12 13:52:31 -08003915
3916out:
James Smartfa4066b2008-01-11 01:53:27 -05003917 /* decrement the node reference count held for this
3918 * callback function.
3919 */
James Smart329f9bc2007-04-25 09:53:01 -04003920 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003921 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3922 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04003923 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04003924
3925 /* If no other thread is using the ndlp, free it */
3926 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05003927
James Smart76a95d72010-11-20 23:11:48 -05003928 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003929 /*
3930 * RegLogin failed, use loop map to make discovery
3931 * list
3932 */
3933 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003934
James Smart92d7f7b2007-06-17 19:56:38 -05003935 /* Start discovery */
3936 lpfc_disc_start(vport);
3937 return;
3938 }
3939 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05003940 return;
3941 }
3942
James Smart6d368e52011-05-24 11:44:12 -04003943 if (phba->sli_rev < LPFC_SLI_REV4)
3944 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003945 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003946 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003947 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04003948 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3949 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
3950 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003951 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003952 ndlp->nlp_usg_map, ndlp);
dea31012005-04-17 16:05:31 -05003953
James Smart2e0fef82007-06-17 19:56:36 -05003954 if (vport->port_state < LPFC_VPORT_READY) {
3955 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05003956 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3957 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3958 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3959 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
James Smarta0f2d3e2017-02-12 13:52:31 -08003960
3961 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3962 (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
3963 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
3964
3965 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3966 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
James Smart01649562017-02-12 13:52:32 -08003967 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
3968 FC_TYPE_NVME);
James Smart92d7f7b2007-06-17 19:56:38 -05003969
3970 /* Issue SCR just before NameServer GID_FT Query */
3971 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05003972 }
3973
James Smart2e0fef82007-06-17 19:56:36 -05003974 vport->fc_ns_retry = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08003975 if (lpfc_issue_gidft(vport) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003976 goto out;
dea31012005-04-17 16:05:31 -05003977
James Smarta0f2d3e2017-02-12 13:52:31 -08003978 /*
3979 * At this point in time we may need to wait for multiple
3980 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
3981 *
3982 * decrement the node reference count held for this
James Smartfa4066b2008-01-11 01:53:27 -05003983 * callback function.
3984 */
James Smart329f9bc2007-04-25 09:53:01 -04003985 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003986 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3987 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003988 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003989
3990 return;
3991}
3992
3993static void
James Smart2e0fef82007-06-17 19:56:36 -05003994lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003995{
James Smart2e0fef82007-06-17 19:56:36 -05003996 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3997 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05003998 struct lpfc_rport_data *rdata;
3999 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05004000 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004001
James Smart895427b2017-02-12 13:52:30 -08004002 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4003 return;
4004
dea31012005-04-17 16:05:31 -05004005 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07004006 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4007 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05004008 rport_ids.port_id = ndlp->nlp_DID;
4009 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05004010
James Smart329f9bc2007-04-25 09:53:01 -04004011 /*
4012 * We leave our node pointer in rport->dd_data when we unregister a
4013 * FCP target port. But fc_remote_port_add zeros the space to which
4014 * rport->dd_data points. So, if we're reusing a previously
4015 * registered port, drop the reference that we took the last time we
4016 * registered the port.
4017 */
James Smart466e8402015-05-21 13:55:28 -04004018 rport = ndlp->rport;
4019 if (rport) {
4020 rdata = rport->dd_data;
4021 /* break the link before dropping the ref */
4022 ndlp->rport = NULL;
4023 if (rdata && rdata->pnode == ndlp)
4024 lpfc_nlp_put(ndlp);
4025 rdata->pnode = NULL;
4026 /* drop reference for earlier registeration */
4027 put_device(&rport->dev);
4028 }
James Smart858c9f62007-06-17 19:56:39 -05004029
4030 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4031 "rport add: did:x%x flg:x%x type x%x",
4032 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4033
James Smart9589b0622011-04-16 11:03:17 -04004034 /* Don't add the remote port if unloading. */
4035 if (vport->load_flag & FC_UNLOADING)
4036 return;
4037
James Smart2e0fef82007-06-17 19:56:36 -05004038 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04004039 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05004040 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4041 "Warning: fc_remote_port_add failed\n");
4042 return;
4043 }
4044
4045 /* initialize static port data */
4046 rport->maxframe_size = ndlp->nlp_maxframe;
4047 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05004048 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004049 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004050
4051 if (ndlp->nlp_type & NLP_FCP_TARGET)
4052 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
4053 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4054 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4055
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05004056 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4057 fc_remote_port_rolechg(rport, rport_ids.roles);
4058
James Smart34f5ad82012-08-03 12:35:03 -04004059 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4060 "3183 rport register x%06x, rport %p role x%x\n",
4061 ndlp->nlp_DID, rport, rport_ids.roles);
4062
James Smart071fbd3d2006-04-15 11:53:20 -04004063 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004064 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04004065 ndlp->nlp_sid = rport->scsi_target_id;
4066 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004067 return;
4068}
4069
4070static void
James Smart2e0fef82007-06-17 19:56:36 -05004071lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004072{
4073 struct fc_rport *rport = ndlp->rport;
James Smart2ea259e2017-02-12 13:52:27 -08004074 struct lpfc_vport *vport = ndlp->vport;
James Smarta0f2d3e2017-02-12 13:52:31 -08004075 struct lpfc_hba *phba = vport->phba;
4076
4077 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4078 return;
James Smartc01f3202006-08-18 17:47:08 -04004079
James Smart2ea259e2017-02-12 13:52:27 -08004080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
James Smart858c9f62007-06-17 19:56:39 -05004081 "rport delete: did:x%x flg:x%x type x%x",
4082 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4083
James Smart2ea259e2017-02-12 13:52:27 -08004084 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
James Smart34f5ad82012-08-03 12:35:03 -04004085 "3184 rport unregister x%06x, rport %p\n",
4086 ndlp->nlp_DID, rport);
4087
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004088 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05004089
4090 return;
4091}
4092
James Smartde0c5b32007-04-25 09:52:27 -04004093static void
James Smart2e0fef82007-06-17 19:56:36 -05004094lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04004095{
James Smart2e0fef82007-06-17 19:56:36 -05004096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4097
4098 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004099 switch (state) {
4100 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004101 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004102 break;
4103 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004104 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004105 break;
4106 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004107 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004108 break;
4109 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004110 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004111 break;
4112 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05004113 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004114 break;
4115 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004116 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004117 break;
4118 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05004119 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004120 break;
4121 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05004122 if (vport->fc_npr_cnt == 0 && count == -1)
4123 vport->fc_npr_cnt = 0;
4124 else
4125 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04004126 break;
4127 }
James Smart2e0fef82007-06-17 19:56:36 -05004128 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004129}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004130
James Smartde0c5b32007-04-25 09:52:27 -04004131static void
James Smart2e0fef82007-06-17 19:56:36 -05004132lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004133 int old_state, int new_state)
4134{
James Smart2e0fef82007-06-17 19:56:36 -05004135 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarta0f2d3e2017-02-12 13:52:31 -08004136 struct lpfc_hba *phba = vport->phba;
James Smart2e0fef82007-06-17 19:56:36 -05004137
James Smartde0c5b32007-04-25 09:52:27 -04004138 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004139 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4140 ndlp->nlp_type |= NLP_FC_NODE;
4141 }
4142 if (new_state == NLP_STE_MAPPED_NODE)
4143 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4144 if (new_state == NLP_STE_NPR_NODE)
4145 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004146
James Smarta0f2d3e2017-02-12 13:52:31 -08004147 /* FCP and NVME Transport interface */
4148 if ((old_state == NLP_STE_MAPPED_NODE ||
4149 old_state == NLP_STE_UNMAPPED_NODE)) {
4150 if (ndlp->rport) {
4151 vport->phba->nport_event_cnt++;
4152 lpfc_unregister_remote_port(ndlp);
4153 }
4154
4155 /* Notify the NVME transport of this rport's loss */
4156 if (((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4157 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) &&
4158 (vport->phba->nvmet_support == 0) &&
4159 ((ndlp->nlp_fc4_type & NLP_FC4_NVME) ||
4160 (ndlp->nlp_DID == Fabric_DID))) {
4161 vport->phba->nport_event_cnt++;
James Smart01649562017-02-12 13:52:32 -08004162 lpfc_nvme_unregister_port(vport, ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004163 }
James Smartde0c5b32007-04-25 09:52:27 -04004164 }
dea31012005-04-17 16:05:31 -05004165
James Smarta0f2d3e2017-02-12 13:52:31 -08004166 /* FCP and NVME Transport interfaces */
4167
James Smartde0c5b32007-04-25 09:52:27 -04004168 if (new_state == NLP_STE_MAPPED_NODE ||
4169 new_state == NLP_STE_UNMAPPED_NODE) {
James Smarta0f2d3e2017-02-12 13:52:31 -08004170 if ((ndlp->nlp_fc4_type & NLP_FC4_FCP) ||
4171 (ndlp->nlp_DID == Fabric_DID)) {
4172 vport->phba->nport_event_cnt++;
4173 /*
4174 * Tell the fc transport about the port, if we haven't
4175 * already. If we have, and it's a scsi entity, be
4176 */
4177 lpfc_register_remote_port(vport, ndlp);
4178 }
4179 /* Notify the NVME transport of this new rport. */
4180 if (ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4181 if (vport->phba->nvmet_support == 0) {
4182 /* Register this rport with the transport.
4183 * Initiators take the NDLP ref count in
4184 * the register.
4185 */
4186 vport->phba->nport_event_cnt++;
James Smart01649562017-02-12 13:52:32 -08004187 lpfc_nvme_register_port(vport, ndlp);
James Smart8c258642017-02-12 13:52:36 -08004188 } else {
4189 /* Just take an NDLP ref count since the
4190 * target does not register rports.
4191 */
4192 lpfc_nlp_get(ndlp);
James Smarta0f2d3e2017-02-12 13:52:31 -08004193 }
4194 }
James Smartde0c5b32007-04-25 09:52:27 -04004195 }
James Smarta0f2d3e2017-02-12 13:52:31 -08004196
James Smartea2151b2008-09-07 11:52:10 -04004197 if ((new_state == NLP_STE_MAPPED_NODE) &&
4198 (vport->stat_data_enabled)) {
4199 /*
4200 * A new target is discovered, if there is no buffer for
4201 * statistical data collection allocate buffer.
4202 */
4203 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4204 sizeof(struct lpfc_scsicmd_bkt),
4205 GFP_KERNEL);
4206
4207 if (!ndlp->lat_data)
4208 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4209 "0286 lpfc_nlp_state_cleanup failed to "
4210 "allocate statistical data buffer DID "
4211 "0x%x\n", ndlp->nlp_DID);
4212 }
James Smart858c9f62007-06-17 19:56:39 -05004213 /*
James Smarta0f2d3e2017-02-12 13:52:31 -08004214 * If the node just added to Mapped list was an FCP target,
4215 * but the remote port registration failed or assigned a target
4216 * id outside the presentable range - move the node to the
4217 * Unmapped List.
James Smart858c9f62007-06-17 19:56:39 -05004218 */
James Smarta0f2d3e2017-02-12 13:52:31 -08004219 if ((new_state == NLP_STE_MAPPED_NODE) &&
4220 (ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smartde0c5b32007-04-25 09:52:27 -04004221 (!ndlp->rport ||
4222 ndlp->rport->scsi_target_id == -1 ||
4223 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004224 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004225 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004226 spin_unlock_irq(shost->host_lock);
4227 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004228 }
James Smartde0c5b32007-04-25 09:52:27 -04004229}
4230
James Smart685f0bf2007-04-25 09:53:08 -04004231static char *
4232lpfc_nlp_state_name(char *buffer, size_t size, int state)
4233{
4234 static char *states[] = {
4235 [NLP_STE_UNUSED_NODE] = "UNUSED",
4236 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4237 [NLP_STE_ADISC_ISSUE] = "ADISC",
4238 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4239 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004240 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004241 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4242 [NLP_STE_MAPPED_NODE] = "MAPPED",
4243 [NLP_STE_NPR_NODE] = "NPR",
4244 };
4245
James Smart311464e2007-08-02 11:10:37 -04004246 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004247 strlcpy(buffer, states[state], size);
4248 else
4249 snprintf(buffer, size, "unknown (%d)", state);
4250 return buffer;
4251}
4252
James Smartde0c5b32007-04-25 09:52:27 -04004253void
James Smart2e0fef82007-06-17 19:56:36 -05004254lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4255 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004256{
James Smart2e0fef82007-06-17 19:56:36 -05004257 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004258 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004259 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004260
James Smarte8b62012007-08-02 11:10:09 -04004261 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4262 "0904 NPort state transition x%06x, %s -> %s\n",
4263 ndlp->nlp_DID,
4264 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4265 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004266
4267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4268 "node statechg did:x%x old:%d ste:%d",
4269 ndlp->nlp_DID, old_state, state);
4270
James Smartde0c5b32007-04-25 09:52:27 -04004271 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004272 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004273 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004274 if (old_state == NLP_STE_UNMAPPED_NODE) {
4275 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4276 ndlp->nlp_type &= ~NLP_FC_NODE;
4277 }
4278
James Smart685f0bf2007-04-25 09:53:08 -04004279 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004280 spin_lock_irq(shost->host_lock);
4281 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4282 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004283 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004284 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004285
4286 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004287 lpfc_nlp_counters(vport, state, 1);
4288 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004289}
4290
4291void
James Smarte47c9092008-02-08 18:49:26 -05004292lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4293{
4294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4295
4296 if (list_empty(&ndlp->nlp_listp)) {
4297 spin_lock_irq(shost->host_lock);
4298 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4299 spin_unlock_irq(shost->host_lock);
4300 }
4301}
4302
4303void
James Smart2e0fef82007-06-17 19:56:36 -05004304lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004305{
James Smart2e0fef82007-06-17 19:56:36 -05004306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4307
James Smart0d2b6b82008-06-14 22:52:47 -04004308 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004309 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004310 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4311 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004312 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004313 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004314 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004315 NLP_STE_UNUSED_NODE);
4316}
4317
Adrian Bunk4d9db012008-02-14 23:24:02 +02004318static void
James Smarte47c9092008-02-08 18:49:26 -05004319lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4320{
James Smart0d2b6b82008-06-14 22:52:47 -04004321 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004322 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4323 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4324 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4325 NLP_STE_UNUSED_NODE);
4326}
James Smart109f6ed2008-12-04 22:39:08 -05004327/**
James Smart3621a712009-04-06 18:47:14 -04004328 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004329 * @vport: Pointer to Virtual Port object.
4330 * @ndlp: Pointer to FC node object.
4331 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004332 *
4333 * This function is always called when node object need to be initialized.
4334 * It initializes all the fields of the node object. Although the reference
4335 * to phba from @ndlp can be obtained indirectly through it's reference to
4336 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4337 * to the life-span of the @ndlp might go beyond the existence of @vport as
4338 * the final release of ndlp is determined by its reference count. And, the
4339 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004340 **/
4341static inline void
4342lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4343 uint32_t did)
4344{
4345 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4346 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4347 init_timer(&ndlp->nlp_delayfunc);
4348 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4349 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4350 ndlp->nlp_DID = did;
4351 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004352 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004353 ndlp->nlp_sid = NLP_NO_SID;
James Smarta0f2d3e2017-02-12 13:52:31 -08004354 ndlp->nlp_fc4_type = NLP_FC4_NONE;
James Smart109f6ed2008-12-04 22:39:08 -05004355 kref_init(&ndlp->kref);
4356 NLP_INT_NODE_ACT(ndlp);
4357 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004358 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart109f6ed2008-12-04 22:39:08 -05004359}
James Smarte47c9092008-02-08 18:49:26 -05004360
4361struct lpfc_nodelist *
4362lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4363 int state)
4364{
4365 struct lpfc_hba *phba = vport->phba;
4366 uint32_t did;
4367 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004368 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smarte47c9092008-02-08 18:49:26 -05004369
4370 if (!ndlp)
4371 return NULL;
4372
4373 spin_lock_irqsave(&phba->ndlp_lock, flags);
4374 /* The ndlp should not be in memory free mode */
4375 if (NLP_CHK_FREE_REQ(ndlp)) {
4376 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4377 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4378 "0277 lpfc_enable_node: ndlp:x%p "
4379 "usgmap:x%x refcnt:%d\n",
4380 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004381 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05004382 return NULL;
4383 }
4384 /* The ndlp should not already be in active mode */
4385 if (NLP_CHK_NODE_ACT(ndlp)) {
4386 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4387 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4388 "0278 lpfc_enable_node: ndlp:x%p "
4389 "usgmap:x%x refcnt:%d\n",
4390 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004391 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05004392 return NULL;
4393 }
4394
4395 /* Keep the original DID */
4396 did = ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05004397 if (phba->sli_rev == LPFC_SLI_REV4)
4398 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004399
4400 /* re-initialize ndlp except of ndlp linked list pointer */
4401 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4402 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smart109f6ed2008-12-04 22:39:08 -05004403 lpfc_initialize_node(vport, ndlp, did);
James Smarte47c9092008-02-08 18:49:26 -05004404
James Smartcff261f2013-12-17 20:29:47 -05004405 if (phba->sli_rev == LPFC_SLI_REV4)
4406 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4407
James Smarte47c9092008-02-08 18:49:26 -05004408 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smartbe6bb942015-04-07 15:07:22 -04004409 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart725dd392013-10-10 12:23:30 -04004410 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
James Smartbe6bb942015-04-07 15:07:22 -04004411 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4412 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4413 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4414 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004415 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004416 ndlp->nlp_usg_map, ndlp);
4417 }
James Smart725dd392013-10-10 12:23:30 -04004418
James Smarte47c9092008-02-08 18:49:26 -05004419
4420 if (state != NLP_STE_UNUSED_NODE)
4421 lpfc_nlp_set_state(vport, ndlp, state);
4422
4423 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4424 "node enable: did:x%x",
4425 ndlp->nlp_DID, 0, 0);
4426 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04004427}
4428
4429void
James Smart2e0fef82007-06-17 19:56:36 -05004430lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004431{
James Smart87af33f2007-10-27 13:37:43 -04004432 /*
James Smartfa4066b2008-01-11 01:53:27 -05004433 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004434 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004435 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4436 * until ALL other outstanding threads have completed. We check
4437 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004438 */
James Smartfa4066b2008-01-11 01:53:27 -05004439 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4440 return;
James Smart51ef4c22007-08-02 11:10:31 -04004441 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04004442 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart1151e3e2011-02-16 12:39:35 -05004443 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004444 lpfc_unreg_rpi(vport, ndlp);
James Smartbe6bb942015-04-07 15:07:22 -04004445 }
James Smart02902172015-05-21 13:55:17 -04004446
4447 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004448 return;
dea31012005-04-17 16:05:31 -05004449}
4450
4451/*
4452 * Start / ReStart rescue timer for Discovery / RSCN handling
4453 */
4454void
James Smart2e0fef82007-06-17 19:56:36 -05004455lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004456{
James Smart2e0fef82007-06-17 19:56:36 -05004457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4458 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004459 uint32_t tmo;
4460
James Smart2e0fef82007-06-17 19:56:36 -05004461 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004462 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004463 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4464 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004465 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004466 * FC spec states we need 3 * ratov for CT requests
4467 */
4468 tmo = ((phba->fc_ratov * 3) + 3);
4469 }
dea31012005-04-17 16:05:31 -05004470
James Smart858c9f62007-06-17 19:56:39 -05004471
4472 if (!timer_pending(&vport->fc_disctmo)) {
4473 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4474 "set disc timer: tmo:x%x state:x%x flg:x%x",
4475 tmo, vport->port_state, vport->fc_flag);
4476 }
4477
James Smart256ec0d2013-04-17 20:14:58 -04004478 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004479 spin_lock_irq(shost->host_lock);
4480 vport->fc_flag |= FC_DISC_TMO;
4481 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004482
4483 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004484 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4485 "0247 Start Discovery Timer state x%x "
4486 "Data: x%x x%lx x%x x%x\n",
4487 vport->port_state, tmo,
4488 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4489 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004490
4491 return;
4492}
4493
4494/*
4495 * Cancel rescue timer for Discovery / RSCN handling
4496 */
4497int
James Smart2e0fef82007-06-17 19:56:36 -05004498lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004499{
James Smart2e0fef82007-06-17 19:56:36 -05004500 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004501 unsigned long iflags;
4502
James Smart858c9f62007-06-17 19:56:39 -05004503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4504 "can disc timer: state:x%x rtry:x%x flg:x%x",
4505 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4506
dea31012005-04-17 16:05:31 -05004507 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004508 if (vport->fc_flag & FC_DISC_TMO) {
4509 spin_lock_irqsave(shost->host_lock, iflags);
4510 vport->fc_flag &= ~FC_DISC_TMO;
4511 spin_unlock_irqrestore(shost->host_lock, iflags);
4512 del_timer_sync(&vport->fc_disctmo);
4513 spin_lock_irqsave(&vport->work_port_lock, iflags);
4514 vport->work_port_events &= ~WORKER_DISC_TMO;
4515 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004516 }
4517
4518 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004519 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4520 "0248 Cancel Discovery Timer state x%x "
4521 "Data: x%x x%x x%x\n",
4522 vport->port_state, vport->fc_flag,
4523 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004524 return 0;
dea31012005-04-17 16:05:31 -05004525}
4526
4527/*
4528 * Check specified ring for outstanding IOCB on the SLI queue
4529 * Return true if iocb matches the specified nport
4530 */
4531int
James Smart2e0fef82007-06-17 19:56:36 -05004532lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4533 struct lpfc_sli_ring *pring,
4534 struct lpfc_iocbq *iocb,
4535 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004536{
James Smart2e0fef82007-06-17 19:56:36 -05004537 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004538 struct lpfc_vport *vport = ndlp->vport;
4539
4540 if (iocb->vport != vport)
4541 return 0;
4542
dea31012005-04-17 16:05:31 -05004543 if (pring->ringno == LPFC_ELS_RING) {
4544 switch (icmd->ulpCommand) {
4545 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004546 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004547 return 1;
dea31012005-04-17 16:05:31 -05004548 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004549 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4550 return 1;
dea31012005-04-17 16:05:31 -05004551 case CMD_XMIT_ELS_RSP64_CX:
4552 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004553 return 1;
dea31012005-04-17 16:05:31 -05004554 }
James Smart895427b2017-02-12 13:52:30 -08004555 } else if (pring->ringno == LPFC_FCP_RING) {
dea31012005-04-17 16:05:31 -05004556 /* Skip match check if waiting to relogin to FCP target */
4557 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004558 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004559 return 0;
dea31012005-04-17 16:05:31 -05004560 }
4561 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004562 return 1;
dea31012005-04-17 16:05:31 -05004563 }
dea31012005-04-17 16:05:31 -05004564 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004565 return 0;
dea31012005-04-17 16:05:31 -05004566}
4567
James Smart895427b2017-02-12 13:52:30 -08004568static void
4569__lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4570 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4571 struct list_head *dequeue_list)
4572{
4573 struct lpfc_iocbq *iocb, *next_iocb;
4574
4575 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4576 /* Check to see if iocb matches the nport */
4577 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
4578 /* match, dequeue */
4579 list_move_tail(&iocb->list, dequeue_list);
4580 }
4581}
4582
4583static void
4584lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
4585 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4586{
4587 struct lpfc_sli *psli = &phba->sli;
4588 uint32_t i;
4589
4590 spin_lock_irq(&phba->hbalock);
4591 for (i = 0; i < psli->num_rings; i++)
4592 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
4593 dequeue_list);
4594 spin_unlock_irq(&phba->hbalock);
4595}
4596
4597static void
4598lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
4599 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
4600{
4601 struct lpfc_sli_ring *pring;
4602 struct lpfc_queue *qp = NULL;
4603
4604 spin_lock_irq(&phba->hbalock);
4605 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
4606 pring = qp->pring;
4607 if (!pring)
4608 continue;
4609 spin_lock_irq(&pring->ring_lock);
4610 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
4611 spin_unlock_irq(&pring->ring_lock);
4612 }
4613 spin_unlock_irq(&phba->hbalock);
4614}
4615
dea31012005-04-17 16:05:31 -05004616/*
4617 * Free resources / clean up outstanding I/Os
4618 * associated with nlp_rpi in the LPFC_NODELIST entry.
4619 */
4620static int
James Smart2e0fef82007-06-17 19:56:36 -05004621lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004622{
James Smart2534ba72007-04-25 09:52:20 -04004623 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004624
James Smart92d7f7b2007-06-17 19:56:38 -05004625 lpfc_fabric_abort_nport(ndlp);
4626
dea31012005-04-17 16:05:31 -05004627 /*
4628 * Everything that matches on txcmplq will be returned
4629 * by firmware with a no rpi error.
4630 */
James Smart40426292010-12-15 17:58:10 -05004631 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart895427b2017-02-12 13:52:30 -08004632 if (phba->sli_rev != LPFC_SLI_REV4)
4633 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
4634 else
4635 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
dea31012005-04-17 16:05:31 -05004636 }
James Smart2534ba72007-04-25 09:52:20 -04004637
James Smarta257bf92009-04-06 18:48:10 -04004638 /* Cancel all the IOCBs from the completions list */
4639 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4640 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004641
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004642 return 0;
dea31012005-04-17 16:05:31 -05004643}
4644
James Smart086a3452012-08-14 14:25:21 -04004645/**
4646 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4647 * @phba: Pointer to HBA context object.
4648 * @pmb: Pointer to mailbox object.
4649 *
4650 * This function will issue an ELS LOGO command after completing
4651 * the UNREG_RPI.
4652 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004653static void
James Smart086a3452012-08-14 14:25:21 -04004654lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4655{
4656 struct lpfc_vport *vport = pmb->vport;
4657 struct lpfc_nodelist *ndlp;
4658
4659 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4660 if (!ndlp)
4661 return;
4662 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004663 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04004664}
4665
dea31012005-04-17 16:05:31 -05004666/*
4667 * Free rpi associated with LPFC_NODELIST entry.
4668 * This routine is called from lpfc_freenode(), when we are removing
4669 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4670 * LOGO that completes successfully, and we are waiting to PLOGI back
4671 * to the remote NPort. In addition, it is called after we receive
4672 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4673 * we are waiting to PLOGI back to the remote NPort.
4674 */
4675int
James Smart2e0fef82007-06-17 19:56:36 -05004676lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004677{
James Smart2e0fef82007-06-17 19:56:36 -05004678 struct lpfc_hba *phba = vport->phba;
4679 LPFC_MBOXQ_t *mbox;
James Smart7c5e5182015-05-22 10:42:43 -04004680 int rc, acc_plogi = 1;
James Smart6d368e52011-05-24 11:44:12 -04004681 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004682
James Smartf454a9a2013-09-06 12:20:07 -04004683 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4684 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4685 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4686 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4687 "3366 RPI x%x needs to be "
4688 "unregistered nlp_flag x%x "
4689 "did x%x\n",
4690 ndlp->nlp_rpi, ndlp->nlp_flag,
4691 ndlp->nlp_DID);
James Smart2e0fef82007-06-17 19:56:36 -05004692 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4693 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004694 /* SLI4 ports require the physical rpi value. */
4695 rpi = ndlp->nlp_rpi;
4696 if (phba->sli_rev == LPFC_SLI_REV4)
4697 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004698
James Smart6d368e52011-05-24 11:44:12 -04004699 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004700 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004701 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4702 mbox->context1 = ndlp;
4703 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4704 } else {
James Smartbe6bb942015-04-07 15:07:22 -04004705 if (phba->sli_rev == LPFC_SLI_REV4 &&
4706 (!(vport->load_flag & FC_UNLOADING)) &&
4707 (bf_get(lpfc_sli_intf_if_type,
4708 &phba->sli4_hba.sli_intf) ==
James Smarta6517db2016-03-31 14:12:29 -07004709 LPFC_SLI_INTF_IF_TYPE_2) &&
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004710 (kref_read(&ndlp->kref) > 0)) {
James Smartbe6bb942015-04-07 15:07:22 -04004711 mbox->context1 = lpfc_nlp_get(ndlp);
4712 mbox->mbox_cmpl =
4713 lpfc_sli4_unreg_rpi_cmpl_clr;
James Smart7c5e5182015-05-22 10:42:43 -04004714 /*
4715 * accept PLOGIs after unreg_rpi_cmpl
4716 */
4717 acc_plogi = 0;
James Smartbe6bb942015-04-07 15:07:22 -04004718 } else
4719 mbox->mbox_cmpl =
4720 lpfc_sli_def_mbox_cmpl;
James Smart086a3452012-08-14 14:25:21 -04004721 }
4722
James Smart0b727fe2007-10-27 13:37:25 -04004723 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart7c5e5182015-05-22 10:42:43 -04004724 if (rc == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -05004725 mempool_free(mbox, phba->mbox_mem_pool);
James Smart7c5e5182015-05-22 10:42:43 -04004726 acc_plogi = 1;
4727 }
dea31012005-04-17 16:05:31 -05004728 }
dea31012005-04-17 16:05:31 -05004729 lpfc_no_rpi(phba, ndlp);
James Smartd7c47992010-06-08 18:31:54 -04004730
James Smart40426292010-12-15 17:58:10 -05004731 if (phba->sli_rev != LPFC_SLI_REV4)
4732 ndlp->nlp_rpi = 0;
4733 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004734 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart7c5e5182015-05-22 10:42:43 -04004735 if (acc_plogi)
4736 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004737 return 1;
4738 }
James Smart7c5e5182015-05-22 10:42:43 -04004739 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
dea31012005-04-17 16:05:31 -05004740 return 0;
4741}
4742
James Smartecfd03c2010-02-12 14:41:27 -05004743/**
4744 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4745 * @phba: pointer to lpfc hba data structure.
4746 *
4747 * This routine is invoked to unregister all the currently registered RPIs
4748 * to the HBA.
4749 **/
4750void
4751lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4752{
4753 struct lpfc_vport **vports;
4754 struct lpfc_nodelist *ndlp;
4755 struct Scsi_Host *shost;
4756 int i;
4757
4758 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004759 if (!vports) {
4760 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4761 "2884 Vport array allocation failed \n");
4762 return;
4763 }
James Smartecfd03c2010-02-12 14:41:27 -05004764 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4765 shost = lpfc_shost_from_vport(vports[i]);
4766 spin_lock_irq(shost->host_lock);
4767 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004768 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004769 /* The mempool_alloc might sleep */
4770 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004771 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004772 spin_lock_irq(shost->host_lock);
4773 }
James Smartecfd03c2010-02-12 14:41:27 -05004774 }
4775 spin_unlock_irq(shost->host_lock);
4776 }
4777 lpfc_destroy_vport_work_array(phba, vports);
4778}
4779
James Smart92d7f7b2007-06-17 19:56:38 -05004780void
4781lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4782{
4783 struct lpfc_hba *phba = vport->phba;
4784 LPFC_MBOXQ_t *mbox;
4785 int rc;
4786
James Smart5af5eee2010-10-22 11:06:38 -04004787 if (phba->sli_rev == LPFC_SLI_REV4) {
4788 lpfc_sli4_unreg_all_rpis(vport);
4789 return;
4790 }
4791
James Smart92d7f7b2007-06-17 19:56:38 -05004792 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4793 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004794 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4795 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004796 mbox->vport = vport;
4797 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004798 mbox->context1 = NULL;
4799 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004800 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004801 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04004802
4803 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4804 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4805 "1836 Could not issue "
4806 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004807 }
4808}
4809
4810void
4811lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4812{
4813 struct lpfc_hba *phba = vport->phba;
4814 LPFC_MBOXQ_t *mbox;
4815 int rc;
4816
4817 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4818 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004819 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4820 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004821 mbox->vport = vport;
4822 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004823 mbox->context1 = NULL;
4824 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004825 if (rc != MBX_TIMEOUT)
4826 mempool_free(mbox, phba->mbox_mem_pool);
4827
4828 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04004829 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4830 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04004831 "unreg_did (default rpis) status %d\n",
4832 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004833 }
4834}
4835
dea31012005-04-17 16:05:31 -05004836/*
4837 * Free resources associated with LPFC_NODELIST entry
4838 * so it can be freed.
4839 */
4840static int
James Smart2e0fef82007-06-17 19:56:36 -05004841lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004842{
James Smart2e0fef82007-06-17 19:56:36 -05004843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4844 struct lpfc_hba *phba = vport->phba;
4845 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05004846 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05004847
4848 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04004849 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4850 "0900 Cleanup node for NPort x%x "
4851 "Data: x%x x%x x%x\n",
4852 ndlp->nlp_DID, ndlp->nlp_flag,
4853 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05004854 if (NLP_CHK_FREE_REQ(ndlp)) {
4855 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4856 "0280 lpfc_cleanup_node: ndlp:x%p "
4857 "usgmap:x%x refcnt:%d\n",
4858 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004859 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05004860 lpfc_dequeue_node(vport, ndlp);
4861 } else {
4862 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4863 "0281 lpfc_cleanup_node: ndlp:x%p "
4864 "usgmap:x%x refcnt:%d\n",
4865 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004866 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05004867 lpfc_disable_node(vport, ndlp);
4868 }
dea31012005-04-17 16:05:31 -05004869
James Smart086a3452012-08-14 14:25:21 -04004870
4871 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4872
dea31012005-04-17 16:05:31 -05004873 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4874 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04004875 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04004876 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
dea31012005-04-17 16:05:31 -05004877 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4878 mb->context2 = NULL;
4879 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4880 }
4881 }
James Smart33ccf8d2006-08-17 11:57:58 -04004882
James Smart2e0fef82007-06-17 19:56:36 -05004883 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04004884 /* Cleanup REG_LOGIN completions which are not yet processed */
4885 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4886 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04004887 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart5ac6b302010-10-22 11:05:36 -04004888 (ndlp != (struct lpfc_nodelist *) mb->context2))
4889 continue;
4890
4891 mb->context2 = NULL;
4892 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4893 }
4894
dea31012005-04-17 16:05:31 -05004895 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04004896 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04004897 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004898 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05004899 mp = (struct lpfc_dmabuf *) (mb->context1);
4900 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05004901 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05004902 kfree(mp);
4903 }
4904 list_del(&mb->list);
4905 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05004906 /* We shall not invoke the lpfc_nlp_put to decrement
4907 * the ndlp reference count as we are in the process
4908 * of lpfc_nlp_release.
4909 */
dea31012005-04-17 16:05:31 -05004910 }
4911 }
James Smart2e0fef82007-06-17 19:56:36 -05004912 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004913
James Smarte47c9092008-02-08 18:49:26 -05004914 lpfc_els_abort(phba, ndlp);
4915
James Smart2e0fef82007-06-17 19:56:36 -05004916 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04004917 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004918 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004919
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004920 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05004921 del_timer_sync(&ndlp->nlp_delayfunc);
4922
James Smart0d2b6b82008-06-14 22:52:47 -04004923 list_del_init(&ndlp->els_retry_evt.evt_listp);
4924 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05004925 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004926 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05004927
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004928 return 0;
dea31012005-04-17 16:05:31 -05004929}
4930
4931/*
4932 * Check to see if we can free the nlp back to the freelist.
4933 * If we are in the middle of using the nlp in the discovery state
4934 * machine, defer the free till we reach the end of the state machine.
4935 */
James Smart329f9bc2007-04-25 09:53:01 -04004936static void
James Smart2e0fef82007-06-17 19:56:36 -05004937lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004938{
James Smarta8adb832007-10-27 13:37:53 -04004939 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04004940 struct lpfc_rport_data *rdata;
James Smart466e8402015-05-21 13:55:28 -04004941 struct fc_rport *rport;
James Smarta8adb832007-10-27 13:37:53 -04004942 LPFC_MBOXQ_t *mbox;
4943 int rc;
dea31012005-04-17 16:05:31 -05004944
James Smart0d2b6b82008-06-14 22:52:47 -04004945 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04004946 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05004947 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4948 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smarta8adb832007-10-27 13:37:53 -04004949 /* For this case we need to cleanup the default rpi
4950 * allocated by the firmware.
4951 */
James Smartbe6bb942015-04-07 15:07:22 -04004952 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4953 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
4954 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01004955 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04004956 ndlp->nlp_usg_map, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04004957 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4958 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04004959 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05004960 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04004961 if (rc) {
4962 mempool_free(mbox, phba->mbox_mem_pool);
4963 }
4964 else {
4965 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4966 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4967 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004968 mbox->context2 = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04004969 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4970 if (rc == MBX_NOT_FINISHED) {
4971 mempool_free(mbox, phba->mbox_mem_pool);
4972 }
4973 }
4974 }
4975 }
James Smart2e0fef82007-06-17 19:56:36 -05004976 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04004977
James Smart2e0fef82007-06-17 19:56:36 -05004978 /*
James Smart466e8402015-05-21 13:55:28 -04004979 * ndlp->rport must be set to NULL before it reaches here
4980 * i.e. break rport/node link before doing lpfc_nlp_put for
4981 * registered rport and then drop the reference of rport.
James Smart2e0fef82007-06-17 19:56:36 -05004982 */
James Smart92d7f7b2007-06-17 19:56:38 -05004983 if (ndlp->rport) {
James Smart466e8402015-05-21 13:55:28 -04004984 /*
4985 * extra lpfc_nlp_put dropped the reference of ndlp
4986 * for registered rport so need to cleanup rport
4987 */
4988 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4989 "0940 removed node x%p DID x%x "
4990 " rport not null %p\n",
4991 ndlp, ndlp->nlp_DID, ndlp->rport);
4992 rport = ndlp->rport;
4993 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04004994 rdata->pnode = NULL;
4995 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04004996 put_device(&rport->dev);
dea31012005-04-17 16:05:31 -05004997 }
dea31012005-04-17 16:05:31 -05004998}
4999
5000static int
James Smart2e0fef82007-06-17 19:56:36 -05005001lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5002 uint32_t did)
dea31012005-04-17 16:05:31 -05005003{
James Smart2e0fef82007-06-17 19:56:36 -05005004 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05005005
5006 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005007 return 0;
dea31012005-04-17 16:05:31 -05005008
dea31012005-04-17 16:05:31 -05005009 /* First check for Direct match */
5010 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005011 return 1;
dea31012005-04-17 16:05:31 -05005012
5013 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05005014 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005015 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005016 return 0;
dea31012005-04-17 16:05:31 -05005017 }
5018
5019 matchdid.un.word = did;
5020 ndlpdid.un.word = ndlp->nlp_DID;
5021 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5022 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5023 (mydid.un.b.area == matchdid.un.b.area)) {
James Smart6b337e02015-05-21 13:55:23 -04005024 /* This code is supposed to match the ID
5025 * for a private loop device that is
5026 * connect to fl_port. But we need to
5027 * check that the port did not just go
5028 * from pt2pt to fabric or we could end
5029 * up matching ndlp->nlp_DID 000001 to
5030 * fabric DID 0x20101
5031 */
dea31012005-04-17 16:05:31 -05005032 if ((ndlpdid.un.b.domain == 0) &&
5033 (ndlpdid.un.b.area == 0)) {
James Smart6b337e02015-05-21 13:55:23 -04005034 if (ndlpdid.un.b.id &&
5035 vport->phba->fc_topology ==
5036 LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005037 return 1;
dea31012005-04-17 16:05:31 -05005038 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005039 return 0;
dea31012005-04-17 16:05:31 -05005040 }
5041
5042 matchdid.un.word = ndlp->nlp_DID;
5043 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5044 (mydid.un.b.area == ndlpdid.un.b.area)) {
5045 if ((matchdid.un.b.domain == 0) &&
5046 (matchdid.un.b.area == 0)) {
5047 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005048 return 1;
dea31012005-04-17 16:05:31 -05005049 }
5050 }
5051 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005052 return 0;
dea31012005-04-17 16:05:31 -05005053}
5054
James Smart685f0bf2007-04-25 09:53:08 -04005055/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05005056static struct lpfc_nodelist *
5057__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005058{
James Smart2fb9bd82006-12-02 13:33:57 -05005059 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005060 uint32_t data1;
5061
James Smart2e0fef82007-06-17 19:56:36 -05005062 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5063 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04005064 data1 = (((uint32_t) ndlp->nlp_state << 24) |
5065 ((uint32_t) ndlp->nlp_xri << 16) |
5066 ((uint32_t) ndlp->nlp_type << 8) |
5067 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04005068 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5069 "0929 FIND node DID "
James Smartcff261f2013-12-17 20:29:47 -05005070 "Data: x%p x%x x%x x%x %p\n",
James Smarte8b62012007-08-02 11:10:09 -04005071 ndlp, ndlp->nlp_DID,
James Smartcff261f2013-12-17 20:29:47 -05005072 ndlp->nlp_flag, data1,
5073 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04005074 return ndlp;
dea31012005-04-17 16:05:31 -05005075 }
5076 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05005077
dea31012005-04-17 16:05:31 -05005078 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04005079 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5080 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05005081 return NULL;
5082}
5083
5084struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005085lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005086{
James Smart2e0fef82007-06-17 19:56:36 -05005087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005088 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05005089 unsigned long iflags;
dea31012005-04-17 16:05:31 -05005090
James Smartfedd3b72011-02-16 12:39:24 -05005091 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005092 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05005093 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05005094 return ndlp;
5095}
5096
5097struct lpfc_nodelist *
5098lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5099{
5100 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5101 struct lpfc_nodelist *ndlp;
5102
5103 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005104 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05005105 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5106 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05005107 return NULL;
5108 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05005109 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05005110 if (!ndlp)
5111 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005112 lpfc_nlp_init(vport, ndlp, did);
5113 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart8c258642017-02-12 13:52:36 -08005114 if (vport->phba->nvmet_support)
5115 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005116 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005117 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005118 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005119 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005120 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5121 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
5122 if (!ndlp)
5123 return NULL;
James Smart8c258642017-02-12 13:52:36 -08005124 if (vport->phba->nvmet_support)
5125 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05005126 spin_lock_irq(shost->host_lock);
5127 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5128 spin_unlock_irq(shost->host_lock);
5129 return ndlp;
dea31012005-04-17 16:05:31 -05005130 }
James Smarte47c9092008-02-08 18:49:26 -05005131
James Smart58da1ff2008-04-07 10:15:56 -04005132 if ((vport->fc_flag & FC_RSCN_MODE) &&
5133 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05005134 if (lpfc_rscn_payload_check(vport, did)) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005135 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04005136 * we don't need to try to discover it again.
5137 */
5138 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
5139 return NULL;
5140
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005141 /* Since this node is marked for discovery,
5142 * delay timeout is not needed.
5143 */
James Smart0d2b6b82008-06-14 22:52:47 -04005144 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart8c258642017-02-12 13:52:36 -08005145 if (vport->phba->nvmet_support)
5146 return ndlp;
James Smarta257bf92009-04-06 18:48:10 -04005147 spin_lock_irq(shost->host_lock);
5148 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5149 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04005150 } else
dea31012005-04-17 16:05:31 -05005151 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005152 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005153 /* If we've already received a PLOGI from this NPort,
James Smart87af33f2007-10-27 13:37:43 -04005154 * or we are already in the process of discovery on it,
5155 * we don't need to try to discover it again.
5156 */
James Smart685f0bf2007-04-25 09:53:08 -04005157 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04005158 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5159 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05005160 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005161 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart8c258642017-02-12 13:52:36 -08005162 if (vport->phba->nvmet_support)
5163 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005164 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005165 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05005166 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005167 }
5168 return ndlp;
5169}
5170
5171/* Build a list of nodes to discover based on the loopmap */
5172void
James Smart2e0fef82007-06-17 19:56:36 -05005173lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005174{
James Smart2e0fef82007-06-17 19:56:36 -05005175 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005176 int j;
5177 uint32_t alpa, index;
5178
James Smart2e0fef82007-06-17 19:56:36 -05005179 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05005180 return;
James Smart2e0fef82007-06-17 19:56:36 -05005181
James Smart76a95d72010-11-20 23:11:48 -05005182 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05005183 return;
dea31012005-04-17 16:05:31 -05005184
5185 /* Check for loop map present or not */
5186 if (phba->alpa_map[0]) {
5187 for (j = 1; j <= phba->alpa_map[0]; j++) {
5188 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05005189 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05005190 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005191 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005192 }
5193 } else {
5194 /* No alpamap, so try all alpa's */
5195 for (j = 0; j < FC_MAXLOOP; j++) {
5196 /* If cfg_scan_down is set, start from highest
5197 * ALPA (0xef) to lowest (0x1).
5198 */
James Smart3de2a652007-08-02 11:09:59 -04005199 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05005200 index = j;
5201 else
5202 index = FC_MAXLOOP - j - 1;
5203 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05005204 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05005205 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005206 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05005207 }
5208 }
5209 return;
5210}
5211
James Smart895427b2017-02-12 13:52:30 -08005212/* SLI3 only */
dea31012005-04-17 16:05:31 -05005213void
James Smart2e0fef82007-06-17 19:56:36 -05005214lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005215{
dea31012005-04-17 16:05:31 -05005216 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05005217 struct lpfc_sli *psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005218 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5219 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
James Smart2e0fef82007-06-17 19:56:36 -05005220 int rc;
5221
James Smart92d7f7b2007-06-17 19:56:38 -05005222 /*
5223 * if it's not a physical port or if we already send
5224 * clear_la then don't send it.
5225 */
5226 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04005227 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5228 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05005229 return;
5230
James Smart2e0fef82007-06-17 19:56:36 -05005231 /* Link up discovery */
5232 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5233 phba->link_state = LPFC_CLEAR_LA;
5234 lpfc_clear_la(phba, mbox);
5235 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5236 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005237 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05005238 if (rc == MBX_NOT_FINISHED) {
5239 mempool_free(mbox, phba->mbox_mem_pool);
5240 lpfc_disc_flush_list(vport);
5241 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5242 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05005243 phba->link_state = LPFC_HBA_ERROR;
5244 }
5245 }
5246}
5247
5248/* Reg_vpi to tell firmware to resume normal operations */
5249void
5250lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5251{
5252 LPFC_MBOXQ_t *regvpimbox;
5253
5254 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5255 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005256 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005257 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5258 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005259 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005260 == MBX_NOT_FINISHED) {
5261 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005262 }
5263 }
5264}
5265
5266/* Start Link up / RSCN discovery on NPR nodes */
5267void
5268lpfc_disc_start(struct lpfc_vport *vport)
5269{
5270 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5271 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005272 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005273 uint32_t clear_la_pending;
dea31012005-04-17 16:05:31 -05005274
James Smarte74c03c2013-04-17 20:15:19 -04005275 if (!lpfc_is_link_up(phba)) {
5276 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5277 "3315 Link is not up %x\n",
5278 phba->link_state);
dea31012005-04-17 16:05:31 -05005279 return;
James Smarte74c03c2013-04-17 20:15:19 -04005280 }
James Smart2e0fef82007-06-17 19:56:36 -05005281
5282 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005283 clear_la_pending = 1;
5284 else
5285 clear_la_pending = 0;
5286
James Smart2e0fef82007-06-17 19:56:36 -05005287 if (vport->port_state < LPFC_VPORT_READY)
5288 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005289
James Smart2e0fef82007-06-17 19:56:36 -05005290 lpfc_set_disctmo(vport);
5291
James Smart2e0fef82007-06-17 19:56:36 -05005292 vport->fc_prevDID = vport->fc_myDID;
5293 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005294
5295 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005296 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5297 "0202 Start Discovery hba state x%x "
5298 "Data: x%x x%x x%x\n",
5299 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5300 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005301
5302 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005303 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005304
5305 if (num_sent)
5306 return;
5307
James Smart6fa139f2013-04-17 20:20:00 -04005308 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005309 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005310 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005311 !(vport->fc_flag & FC_RSCN_MODE) &&
5312 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart85c0f172015-04-07 15:07:12 -04005313 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005314 lpfc_issue_reg_vpi(phba, vport);
5315 return;
5316 }
James Smart2e0fef82007-06-17 19:56:36 -05005317
James Smart92d7f7b2007-06-17 19:56:38 -05005318 /*
5319 * For SLI2, we need to set port_state to READY and continue
5320 * discovery.
5321 */
5322 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5323 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04005324 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005325
5326 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005327 vport->num_disc_nodes = 0;
5328 /* go thru NPR nodes and issue ELS PLOGIs */
5329 if (vport->fc_npr_cnt)
5330 lpfc_els_disc_plogi(vport);
5331
5332 if (!vport->num_disc_nodes) {
5333 spin_lock_irq(shost->host_lock);
5334 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5335 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005336 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005337 }
5338 }
James Smart92d7f7b2007-06-17 19:56:38 -05005339 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005340 } else {
5341 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005342 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005343
5344 if (num_sent)
5345 return;
5346
James Smart2e0fef82007-06-17 19:56:36 -05005347 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005348 /* Check to see if more RSCNs came in while we
5349 * were processing this one.
5350 */
James Smart2e0fef82007-06-17 19:56:36 -05005351 if ((vport->fc_rscn_id_cnt == 0) &&
5352 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5353 spin_lock_irq(shost->host_lock);
5354 vport->fc_flag &= ~FC_RSCN_MODE;
5355 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005356 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005357 } else
James Smart2e0fef82007-06-17 19:56:36 -05005358 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005359 }
5360 }
5361 return;
5362}
5363
5364/*
5365 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5366 * ring the match the sppecified nodelist.
5367 */
5368static void
James Smart2e0fef82007-06-17 19:56:36 -05005369lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005370{
James Smart2534ba72007-04-25 09:52:20 -04005371 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005372 struct lpfc_sli *psli;
5373 IOCB_t *icmd;
5374 struct lpfc_iocbq *iocb, *next_iocb;
5375 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005376
5377 psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08005378 pring = lpfc_phba_elsring(phba);
dea31012005-04-17 16:05:31 -05005379
5380 /* Error matching iocb on txq or txcmplq
5381 * First check the txq.
5382 */
James Smart2e0fef82007-06-17 19:56:36 -05005383 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005384 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5385 if (iocb->context1 != ndlp) {
5386 continue;
5387 }
5388 icmd = &iocb->iocb;
5389 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5390 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5391
James Smart2534ba72007-04-25 09:52:20 -04005392 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005393 }
5394 }
5395
5396 /* Next check the txcmplq */
5397 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5398 if (iocb->context1 != ndlp) {
5399 continue;
5400 }
5401 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005402 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5403 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005404 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005405 }
5406 }
James Smart2e0fef82007-06-17 19:56:36 -05005407 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005408
James Smarta257bf92009-04-06 18:48:10 -04005409 /* Cancel all the IOCBs from the completions list */
5410 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5411 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005412}
5413
Adrian Bunka6ababd2007-11-05 18:07:33 +01005414static void
James Smart2e0fef82007-06-17 19:56:36 -05005415lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005416{
5417 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005418 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005419
James Smart2e0fef82007-06-17 19:56:36 -05005420 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5421 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005422 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005423 if (!NLP_CHK_NODE_ACT(ndlp))
5424 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005425 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5426 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5427 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005428 }
dea31012005-04-17 16:05:31 -05005429 }
5430 }
dea31012005-04-17 16:05:31 -05005431}
5432
James Smart92d7f7b2007-06-17 19:56:38 -05005433void
5434lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5435{
5436 lpfc_els_flush_rscn(vport);
5437 lpfc_els_flush_cmd(vport);
5438 lpfc_disc_flush_list(vport);
5439}
5440
dea31012005-04-17 16:05:31 -05005441/*****************************************************************************/
5442/*
5443 * NAME: lpfc_disc_timeout
5444 *
5445 * FUNCTION: Fibre Channel driver discovery timeout routine.
5446 *
5447 * EXECUTION ENVIRONMENT: interrupt only
5448 *
5449 * CALLED FROM:
5450 * Timer function
5451 *
5452 * RETURNS:
5453 * none
5454 */
5455/*****************************************************************************/
5456void
5457lpfc_disc_timeout(unsigned long ptr)
5458{
James Smart2e0fef82007-06-17 19:56:36 -05005459 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5460 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005461 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005462 unsigned long flags = 0;
5463
5464 if (unlikely(!phba))
5465 return;
5466
James Smart5e9d9b82008-06-14 22:52:53 -04005467 spin_lock_irqsave(&vport->work_port_lock, flags);
5468 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5469 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005470 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005471 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005472
James Smart5e9d9b82008-06-14 22:52:53 -04005473 if (!tmo_posted)
5474 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005475 return;
5476}
5477
5478static void
James Smart2e0fef82007-06-17 19:56:36 -05005479lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005480{
James Smart2e0fef82007-06-17 19:56:36 -05005481 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5482 struct lpfc_hba *phba = vport->phba;
5483 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005484 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005485 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005486 int rc, clrlaerr = 0;
5487
James Smart2e0fef82007-06-17 19:56:36 -05005488 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005489 return;
5490
James Smart2e0fef82007-06-17 19:56:36 -05005491 spin_lock_irq(shost->host_lock);
5492 vport->fc_flag &= ~FC_DISC_TMO;
5493 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005494
James Smart858c9f62007-06-17 19:56:39 -05005495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5496 "disc timeout: state:x%x rtry:x%x flg:x%x",
5497 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5498
James Smart2e0fef82007-06-17 19:56:36 -05005499 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005500
5501 case LPFC_LOCAL_CFG_LINK:
James Smarta0f2d3e2017-02-12 13:52:31 -08005502 /*
5503 * port_state is identically LPFC_LOCAL_CFG_LINK while
5504 * waiting for FAN timeout
5505 */
James Smarte8b62012007-08-02 11:10:09 -04005506 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5507 "0221 FAN timeout\n");
James Smarta0f2d3e2017-02-12 13:52:31 -08005508
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005509 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005510 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005511 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005512 if (!NLP_CHK_NODE_ACT(ndlp))
5513 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005514 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5515 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005516 if (ndlp->nlp_type & NLP_FABRIC) {
5517 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005518 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005519
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005520 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005521 /* Fail outstanding IO now since device
5522 * is marked for PLOGI.
5523 */
James Smart2e0fef82007-06-17 19:56:36 -05005524 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005525 }
5526 }
James Smart92d7f7b2007-06-17 19:56:38 -05005527 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005528 if (phba->sli_rev <= LPFC_SLI_REV3)
5529 lpfc_initial_flogi(vport);
5530 else
5531 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005532 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005533 }
dea31012005-04-17 16:05:31 -05005534 break;
5535
James Smart92d7f7b2007-06-17 19:56:38 -05005536 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005537 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005538 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005539 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005540 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5541 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005542 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005543
5544 /* Assume no Fabric and go on with discovery.
5545 * Check for outstanding ELS FLOGI to abort.
5546 */
5547
5548 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005549 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005550
5551 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005552 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005553 break;
5554
5555 case LPFC_FABRIC_CFG_LINK:
5556 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5557 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005558 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5559 "0223 Timeout while waiting for "
5560 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005561 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005562 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005563 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005564 lpfc_els_abort(phba, ndlp);
5565
5566 /* ReStart discovery */
5567 goto restart_disc;
dea31012005-04-17 16:05:31 -05005568
5569 case LPFC_NS_QRY:
5570 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005571 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5572 "0224 NameServer Query timeout "
5573 "Data: x%x x%x\n",
5574 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005575
James Smart92d7f7b2007-06-17 19:56:38 -05005576 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5577 /* Try it one more time */
5578 vport->fc_ns_retry++;
James Smarta0f2d3e2017-02-12 13:52:31 -08005579 vport->gidft_inp = 0;
5580 rc = lpfc_issue_gidft(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005581 if (rc == 0)
5582 break;
dea31012005-04-17 16:05:31 -05005583 }
James Smart92d7f7b2007-06-17 19:56:38 -05005584 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005585
James Smart87af33f2007-10-27 13:37:43 -04005586restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005587 /*
5588 * Discovery is over.
5589 * set port_state to PORT_READY if SLI2.
5590 * cmpl_reg_vpi will set port_state to READY for SLI3.
5591 */
James Smart3772a992009-05-22 14:50:54 -04005592 if (phba->sli_rev < LPFC_SLI_REV4) {
5593 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5594 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005595 else {
James Smart3772a992009-05-22 14:50:54 -04005596 lpfc_issue_clear_la(phba, vport);
5597 vport->port_state = LPFC_VPORT_READY;
5598 }
dea31012005-04-17 16:05:31 -05005599 }
5600
5601 /* Setup and issue mailbox INITIALIZE LINK command */
5602 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5603 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005604 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5605 "0206 Device Discovery "
5606 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005607 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005608 break;
5609 }
5610
5611 lpfc_linkdown(phba);
5612 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5613 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005614 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005615 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005616 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005617 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005618 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005619 if (rc == MBX_NOT_FINISHED)
5620 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5621
5622 break;
5623
5624 case LPFC_DISC_AUTH:
5625 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005626 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5627 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005628 lpfc_disc_flush_list(vport);
5629
James Smart92d7f7b2007-06-17 19:56:38 -05005630 /*
5631 * set port_state to PORT_READY if SLI2.
5632 * cmpl_reg_vpi will set port_state to READY for SLI3.
5633 */
James Smart3772a992009-05-22 14:50:54 -04005634 if (phba->sli_rev < LPFC_SLI_REV4) {
5635 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5636 lpfc_issue_reg_vpi(phba, vport);
5637 else { /* NPIV Not enabled */
5638 lpfc_issue_clear_la(phba, vport);
5639 vport->port_state = LPFC_VPORT_READY;
5640 }
dea31012005-04-17 16:05:31 -05005641 }
5642 break;
5643
James Smart2e0fef82007-06-17 19:56:36 -05005644 case LPFC_VPORT_READY:
5645 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04005646 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5647 "0231 RSCN timeout Data: x%x "
5648 "x%x\n",
5649 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005650
5651 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005652 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005653
James Smart2e0fef82007-06-17 19:56:36 -05005654 lpfc_els_flush_rscn(vport);
5655 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005656 }
5657 break;
James Smart2e0fef82007-06-17 19:56:36 -05005658
James Smart92d7f7b2007-06-17 19:56:38 -05005659 default:
James Smarte8b62012007-08-02 11:10:09 -04005660 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005661 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005662 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005663 break;
5664 }
5665
5666 switch (phba->link_state) {
5667 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005668 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005669 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5670 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005671 clrlaerr = 1;
5672 break;
5673
James Smart09372822008-01-11 01:52:54 -05005674 case LPFC_LINK_UP:
5675 lpfc_issue_clear_la(phba, vport);
5676 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05005677 case LPFC_LINK_UNKNOWN:
5678 case LPFC_WARM_START:
5679 case LPFC_INIT_START:
5680 case LPFC_INIT_MBX_CMDS:
5681 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005682 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005683 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5684 "0230 Unexpected timeout, hba link "
5685 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005686 clrlaerr = 1;
5687 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005688
5689 case LPFC_HBA_READY:
5690 break;
dea31012005-04-17 16:05:31 -05005691 }
5692
5693 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005694 lpfc_disc_flush_list(vport);
James Smart895427b2017-02-12 13:52:30 -08005695 if (phba->sli_rev != LPFC_SLI_REV4) {
5696 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
5697 ~LPFC_STOP_IOCB_EVENT;
5698 psli->sli3_ring[LPFC_FCP_RING].flag &=
5699 ~LPFC_STOP_IOCB_EVENT;
5700 }
James Smart2e0fef82007-06-17 19:56:36 -05005701 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005702 }
dea31012005-04-17 16:05:31 -05005703 return;
5704}
5705
dea31012005-04-17 16:05:31 -05005706/*
5707 * This routine handles processing a NameServer REG_LOGIN mailbox
5708 * command upon completion. It is setup in the LPFC_MBOXQ
5709 * as the completion routine when the command is
5710 * handed off to the SLI layer.
5711 */
5712void
James Smart2e0fef82007-06-17 19:56:36 -05005713lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005714{
James Smart04c68492009-05-22 14:52:52 -04005715 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05005716 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5717 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5718 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005719
5720 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04005721 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005722
James Smart6d368e52011-05-24 11:44:12 -04005723 if (phba->sli_rev < LPFC_SLI_REV4)
5724 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005725 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005726 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smartbe6bb942015-04-07 15:07:22 -04005728 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5729 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5730 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005731 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005732 ndlp->nlp_usg_map, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005733 /*
5734 * Start issuing Fabric-Device Management Interface (FDMI) command to
James Smart4258e982015-12-16 18:11:58 -05005735 * 0xfffffa (FDMI well known port).
5736 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5737 * DPRT -> RPRT (vports)
dea31012005-04-17 16:05:31 -05005738 */
James Smart4258e982015-12-16 18:11:58 -05005739 if (vport->port_type == LPFC_PHYSICAL_PORT)
5740 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
James Smart76b2c342015-04-07 15:07:19 -04005741 else
James Smart4258e982015-12-16 18:11:58 -05005742 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
5743
dea31012005-04-17 16:05:31 -05005744
James Smartfa4066b2008-01-11 01:53:27 -05005745 /* decrement the node reference count held for this callback
5746 * function.
5747 */
James Smart329f9bc2007-04-25 09:53:01 -04005748 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005749 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5750 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04005751 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005752
5753 return;
5754}
5755
James Smart685f0bf2007-04-25 09:53:08 -04005756static int
5757lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5758{
5759 uint16_t *rpi = param;
5760
James Smarteff4a012012-01-18 16:25:25 -05005761 /* check for active node */
5762 if (!NLP_CHK_NODE_ACT(ndlp))
5763 return 0;
5764
James Smart685f0bf2007-04-25 09:53:08 -04005765 return ndlp->nlp_rpi == *rpi;
5766}
5767
5768static int
5769lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5770{
5771 return memcmp(&ndlp->nlp_portname, param,
5772 sizeof(ndlp->nlp_portname)) == 0;
5773}
5774
Adrian Bunka6ababd2007-11-05 18:07:33 +01005775static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005776__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05005777{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005778 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005779
James Smart2e0fef82007-06-17 19:56:36 -05005780 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04005781 if (filter(ndlp, param)) {
5782 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5783 "3185 FIND node filter %p DID "
5784 "Data: x%p x%x x%x\n",
5785 filter, ndlp, ndlp->nlp_DID,
5786 ndlp->nlp_flag);
James Smart685f0bf2007-04-25 09:53:08 -04005787 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04005788 }
James Smart685f0bf2007-04-25 09:53:08 -04005789 }
James Smart34f5ad82012-08-03 12:35:03 -04005790 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5791 "3186 FIND node filter %p NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005792 return NULL;
dea31012005-04-17 16:05:31 -05005793}
5794
James Smart685f0bf2007-04-25 09:53:08 -04005795/*
5796 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05005797 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04005798 */
5799struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005800__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04005801{
James Smart2e0fef82007-06-17 19:56:36 -05005802 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04005803}
5804
James Smart488d1462006-03-07 15:02:37 -05005805/*
James Smart685f0bf2007-04-25 09:53:08 -04005806 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05005807 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05005808 */
5809struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005810lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05005811{
James Smart2e0fef82007-06-17 19:56:36 -05005812 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05005813 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05005814
James Smart2e0fef82007-06-17 19:56:36 -05005815 spin_lock_irq(shost->host_lock);
5816 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5817 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05005818 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05005819}
5820
James Smartcb69f7d2011-12-13 13:21:57 -05005821/*
5822 * This routine looks up the ndlp lists for the given RPI. If the rpi
5823 * is found, the routine returns the node element list pointer else
5824 * return NULL.
5825 */
5826struct lpfc_nodelist *
5827lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5828{
5829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5830 struct lpfc_nodelist *ndlp;
5831
5832 spin_lock_irq(shost->host_lock);
5833 ndlp = __lpfc_findnode_rpi(vport, rpi);
5834 spin_unlock_irq(shost->host_lock);
5835 return ndlp;
5836}
5837
5838/**
5839 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5840 * @phba: pointer to lpfc hba data structure.
5841 * @vpi: the physical host virtual N_Port identifier.
5842 *
5843 * This routine finds a vport on a HBA (referred by @phba) through a
5844 * @vpi. The function walks the HBA's vport list and returns the address
5845 * of the vport with the matching @vpi.
5846 *
5847 * Return code
5848 * NULL - No vport with the matching @vpi found
5849 * Otherwise - Address to the vport with the matching @vpi.
5850 **/
5851struct lpfc_vport *
5852lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5853{
5854 struct lpfc_vport *vport;
5855 unsigned long flags;
5856 int i = 0;
5857
5858 /* The physical ports are always vpi 0 - translate is unnecessary. */
5859 if (vpi > 0) {
5860 /*
5861 * Translate the physical vpi to the logical vpi. The
5862 * vport stores the logical vpi.
5863 */
5864 for (i = 0; i < phba->max_vpi; i++) {
5865 if (vpi == phba->vpi_ids[i])
5866 break;
5867 }
5868
5869 if (i >= phba->max_vpi) {
5870 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5871 "2936 Could not find Vport mapped "
5872 "to vpi %d\n", vpi);
5873 return NULL;
5874 }
5875 }
5876
5877 spin_lock_irqsave(&phba->hbalock, flags);
5878 list_for_each_entry(vport, &phba->port_list, listentry) {
5879 if (vport->vpi == i) {
5880 spin_unlock_irqrestore(&phba->hbalock, flags);
5881 return vport;
5882 }
5883 }
5884 spin_unlock_irqrestore(&phba->hbalock, flags);
5885 return NULL;
5886}
5887
dea31012005-04-17 16:05:31 -05005888void
James Smart2e0fef82007-06-17 19:56:36 -05005889lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5890 uint32_t did)
dea31012005-04-17 16:05:31 -05005891{
5892 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05005893
5894 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04005895 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05005896 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart725dd392013-10-10 12:23:30 -04005897 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
James Smartbe6bb942015-04-07 15:07:22 -04005898 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5899 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
5900 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
5901 ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005902 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04005903 ndlp->nlp_usg_map, ndlp);
5904
James Smartcff261f2013-12-17 20:29:47 -05005905 ndlp->active_rrqs_xri_bitmap =
5906 mempool_alloc(vport->phba->active_rrq_pool,
5907 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04005908 if (ndlp->active_rrqs_xri_bitmap)
5909 memset(ndlp->active_rrqs_xri_bitmap, 0,
5910 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05005911 }
5912
James Smart725dd392013-10-10 12:23:30 -04005913
James Smart858c9f62007-06-17 19:56:39 -05005914
5915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5916 "node init: did:x%x",
5917 ndlp->nlp_DID, 0, 0);
5918
dea31012005-04-17 16:05:31 -05005919 return;
5920}
James Smart329f9bc2007-04-25 09:53:01 -04005921
James Smart98c9ea52007-10-27 13:37:33 -04005922/* This routine releases all resources associated with a specifc NPort's ndlp
5923 * and mempool_free's the nodelist.
5924 */
James Smart311464e2007-08-02 11:10:37 -04005925static void
James Smart329f9bc2007-04-25 09:53:01 -04005926lpfc_nlp_release(struct kref *kref)
5927{
James Smarte47c9092008-02-08 18:49:26 -05005928 struct lpfc_hba *phba;
5929 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04005930 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5931 kref);
James Smart858c9f62007-06-17 19:56:39 -05005932
5933 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5934 "node release: did:x%x flg:x%x type:x%x",
5935 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5936
James Smarte47c9092008-02-08 18:49:26 -05005937 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart939723a2012-05-09 21:19:03 -04005938 "0279 lpfc_nlp_release: ndlp:x%p did %x "
James Smartbe6bb942015-04-07 15:07:22 -04005939 "usgmap:x%x refcnt:%d rpi:%x\n",
James Smart939723a2012-05-09 21:19:03 -04005940 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005941 kref_read(&ndlp->kref), ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005942
5943 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05005944 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05005945
5946 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04005947 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005948 spin_lock_irqsave(&phba->ndlp_lock, flags);
5949 NLP_CLR_NODE_ACT(ndlp);
5950 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart40426292010-12-15 17:58:10 -05005951 if (phba->sli_rev == LPFC_SLI_REV4)
5952 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005953
5954 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04005955 if (NLP_CHK_FREE_REQ(ndlp)) {
5956 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05005957 if (phba->sli_rev == LPFC_SLI_REV4)
5958 mempool_free(ndlp->active_rrqs_xri_bitmap,
5959 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04005960 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04005961 }
James Smart329f9bc2007-04-25 09:53:01 -04005962}
5963
James Smart98c9ea52007-10-27 13:37:33 -04005964/* This routine bumps the reference count for a ndlp structure to ensure
5965 * that one discovery thread won't free a ndlp while another discovery thread
5966 * is using it.
5967 */
James Smart329f9bc2007-04-25 09:53:01 -04005968struct lpfc_nodelist *
5969lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5970{
James Smarte47c9092008-02-08 18:49:26 -05005971 struct lpfc_hba *phba;
5972 unsigned long flags;
5973
James Smart98c9ea52007-10-27 13:37:33 -04005974 if (ndlp) {
5975 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5976 "node get: did:x%x flg:x%x refcnt:x%x",
5977 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005978 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005979 /* The check of ndlp usage to prevent incrementing the
5980 * ndlp reference count that is in the process of being
5981 * released.
5982 */
James Smarta257bf92009-04-06 18:48:10 -04005983 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005984 spin_lock_irqsave(&phba->ndlp_lock, flags);
5985 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5986 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5987 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5988 "0276 lpfc_nlp_get: ndlp:x%p "
5989 "usgmap:x%x refcnt:%d\n",
5990 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01005991 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05005992 return NULL;
5993 } else
5994 kref_get(&ndlp->kref);
5995 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04005996 }
James Smart329f9bc2007-04-25 09:53:01 -04005997 return ndlp;
5998}
5999
James Smart98c9ea52007-10-27 13:37:33 -04006000/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05006001 * count goes to 0, this indicates the the associated nodelist should be
6002 * freed. Returning 1 indicates the ndlp resource has been released; on the
6003 * other hand, returning 0 indicates the ndlp resource has not been released
6004 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04006005 */
James Smart329f9bc2007-04-25 09:53:01 -04006006int
6007lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6008{
James Smarte47c9092008-02-08 18:49:26 -05006009 struct lpfc_hba *phba;
6010 unsigned long flags;
6011
6012 if (!ndlp)
6013 return 1;
6014
6015 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6016 "node put: did:x%x flg:x%x refcnt:x%x",
6017 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006018 kref_read(&ndlp->kref));
James Smarta257bf92009-04-06 18:48:10 -04006019 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05006020 spin_lock_irqsave(&phba->ndlp_lock, flags);
6021 /* Check the ndlp memory free acknowledge flag to avoid the
6022 * possible race condition that kref_put got invoked again
6023 * after previous one has done ndlp memory free.
6024 */
6025 if (NLP_CHK_FREE_ACK(ndlp)) {
6026 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6027 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6028 "0274 lpfc_nlp_put: ndlp:x%p "
6029 "usgmap:x%x refcnt:%d\n",
6030 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006031 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006032 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006033 }
James Smarte47c9092008-02-08 18:49:26 -05006034 /* Check the ndlp inactivate log flag to avoid the possible
6035 * race condition that kref_put got invoked again after ndlp
6036 * is already in inactivating state.
6037 */
6038 if (NLP_CHK_IACT_REQ(ndlp)) {
6039 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6040 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6041 "0275 lpfc_nlp_put: ndlp:x%p "
6042 "usgmap:x%x refcnt:%d\n",
6043 (void *)ndlp, ndlp->nlp_usg_map,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006044 kref_read(&ndlp->kref));
James Smarte47c9092008-02-08 18:49:26 -05006045 return 1;
6046 }
6047 /* For last put, mark the ndlp usage flags to make sure no
6048 * other kref_get and kref_put on the same ndlp shall get
6049 * in between the process when the final kref_put has been
6050 * invoked on this ndlp.
6051 */
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006052 if (kref_read(&ndlp->kref) == 1) {
James Smarte47c9092008-02-08 18:49:26 -05006053 /* Indicate ndlp is put to inactive state. */
6054 NLP_SET_IACT_REQ(ndlp);
6055 /* Acknowledge ndlp memory free has been seen. */
6056 if (NLP_CHK_FREE_REQ(ndlp))
6057 NLP_SET_FREE_ACK(ndlp);
6058 }
6059 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
6060 /* Note, the kref_put returns 1 when decrementing a reference
6061 * count that was 1, it invokes the release callback function,
6062 * but it still left the reference count as 1 (not actually
6063 * performs the last decrementation). Otherwise, it actually
6064 * decrements the reference count and returns 0.
6065 */
6066 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04006067}
James Smart98c9ea52007-10-27 13:37:33 -04006068
6069/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05006070 * by any other discovery thread. This routine returns 1 if the
6071 * ndlp has been freed. A return value of 0 indicates the ndlp is
6072 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04006073 */
6074int
6075lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6076{
6077 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6078 "node not used: did:x%x flg:x%x refcnt:x%x",
6079 ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01006080 kref_read(&ndlp->kref));
6081 if (kref_read(&ndlp->kref) == 1)
James Smarte47c9092008-02-08 18:49:26 -05006082 if (lpfc_nlp_put(ndlp))
6083 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04006084 return 0;
6085}
James Smart6fb120a2009-05-22 14:52:59 -04006086
6087/**
6088 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6089 * @phba: Pointer to hba context object.
6090 *
6091 * This function iterate through all FC nodes associated
6092 * will all vports to check if there is any node with
6093 * fc_rports associated with it. If there is an fc_rport
6094 * associated with the node, then the node is either in
6095 * discovered state or its devloss_timer is pending.
6096 */
6097static int
6098lpfc_fcf_inuse(struct lpfc_hba *phba)
6099{
6100 struct lpfc_vport **vports;
6101 int i, ret = 0;
6102 struct lpfc_nodelist *ndlp;
6103 struct Scsi_Host *shost;
6104
6105 vports = lpfc_create_vport_work_array(phba);
6106
James Smart63e801c2010-11-20 23:14:19 -05006107 /* If driver cannot allocate memory, indicate fcf is in use */
6108 if (!vports)
6109 return 1;
6110
James Smart6fb120a2009-05-22 14:52:59 -04006111 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6112 shost = lpfc_shost_from_vport(vports[i]);
6113 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04006114 /*
6115 * IF the CVL_RCVD bit is not set then we have sent the
6116 * flogi.
6117 * If dev_loss fires while we are waiting we do not want to
6118 * unreg the fcf.
6119 */
6120 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6121 spin_unlock_irq(shost->host_lock);
6122 ret = 1;
6123 goto out;
6124 }
James Smart6fb120a2009-05-22 14:52:59 -04006125 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6126 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
6127 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6128 ret = 1;
6129 spin_unlock_irq(shost->host_lock);
6130 goto out;
James Smart80c17842012-03-01 22:35:45 -05006131 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6132 ret = 1;
James Smart891478a2009-11-18 15:40:23 -05006133 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart80c17842012-03-01 22:35:45 -05006134 "2624 RPI %x DID %x flag %x "
6135 "still logged in\n",
6136 ndlp->nlp_rpi, ndlp->nlp_DID,
6137 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04006138 }
6139 }
6140 spin_unlock_irq(shost->host_lock);
6141 }
6142out:
6143 lpfc_destroy_vport_work_array(phba, vports);
6144 return ret;
6145}
6146
6147/**
6148 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6149 * @phba: Pointer to hba context object.
6150 * @mboxq: Pointer to mailbox object.
6151 *
6152 * This function frees memory associated with the mailbox command.
6153 */
James Smart1b511972011-12-13 13:23:09 -05006154void
James Smart6fb120a2009-05-22 14:52:59 -04006155lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6156{
6157 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04006158 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04006159
6160 if (mboxq->u.mb.mbxStatus) {
6161 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6162 "2555 UNREG_VFI mbxStatus error x%x "
6163 "HBA state x%x\n",
6164 mboxq->u.mb.mbxStatus, vport->port_state);
6165 }
James Smart38b92ef2010-08-04 16:11:39 -04006166 spin_lock_irq(shost->host_lock);
6167 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6168 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006169 mempool_free(mboxq, phba->mbox_mem_pool);
6170 return;
6171}
6172
6173/**
6174 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6175 * @phba: Pointer to hba context object.
6176 * @mboxq: Pointer to mailbox object.
6177 *
6178 * This function frees memory associated with the mailbox command.
6179 */
6180static void
6181lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6182{
6183 struct lpfc_vport *vport = mboxq->vport;
6184
6185 if (mboxq->u.mb.mbxStatus) {
6186 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6187 "2550 UNREG_FCFI mbxStatus error x%x "
6188 "HBA state x%x\n",
6189 mboxq->u.mb.mbxStatus, vport->port_state);
6190 }
6191 mempool_free(mboxq, phba->mbox_mem_pool);
6192 return;
6193}
6194
6195/**
James Smartecfd03c2010-02-12 14:41:27 -05006196 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04006197 * @phba: Pointer to hba context object.
6198 *
James Smartecfd03c2010-02-12 14:41:27 -05006199 * This function prepare the HBA for unregistering the currently registered
6200 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6201 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04006202 */
James Smartecfd03c2010-02-12 14:41:27 -05006203int
6204lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04006205{
James Smart6fb120a2009-05-22 14:52:59 -04006206 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05006207 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05006208 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04006209 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04006210
James Smartecfd03c2010-02-12 14:41:27 -05006211 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04006212 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05006213 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006214
James Smart4d9ab992009-10-02 15:16:39 -04006215 /* At this point, all discovery is aborted */
6216 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04006217
6218 /* Unregister VPIs */
6219 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05006220 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04006221 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05006222 /* Stop FLOGI/FDISC retries */
6223 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6224 if (ndlp)
6225 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04006226 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04006227 if (phba->sli_rev == LPFC_SLI_REV4)
6228 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04006229 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05006230 shost = lpfc_shost_from_vport(vports[i]);
6231 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05006232 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05006233 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05006234 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04006235 }
6236 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04006237 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6238 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6239 if (ndlp)
6240 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6241 lpfc_cleanup_pending_mbox(phba->pport);
6242 if (phba->sli_rev == LPFC_SLI_REV4)
6243 lpfc_sli4_unreg_all_rpis(phba->pport);
6244 lpfc_mbx_unreg_vpi(phba->pport);
6245 shost = lpfc_shost_from_vport(phba->pport);
6246 spin_lock_irq(shost->host_lock);
6247 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6248 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6249 spin_unlock_irq(shost->host_lock);
6250 }
James Smart6fb120a2009-05-22 14:52:59 -04006251
James Smart695a8142010-01-26 23:08:03 -05006252 /* Cleanup any outstanding ELS commands */
6253 lpfc_els_flush_all_cmd(phba);
6254
James Smart1b511972011-12-13 13:23:09 -05006255 /* Unregister the physical port VFI */
6256 rc = lpfc_issue_unreg_vfi(phba->pport);
6257 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006258}
6259
6260/**
6261 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6262 * @phba: Pointer to hba context object.
6263 *
6264 * This function issues synchronous unregister FCF mailbox command to HBA to
6265 * unregister the currently registered FCF record. The driver does not reset
6266 * the driver FCF usage state flags.
6267 *
6268 * Return 0 if successfully issued, none-zero otherwise.
6269 */
6270int
6271lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6272{
6273 LPFC_MBOXQ_t *mbox;
6274 int rc;
6275
James Smart6fb120a2009-05-22 14:52:59 -04006276 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6277 if (!mbox) {
6278 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006279 "2551 UNREG_FCFI mbox allocation failed"
6280 "HBA state x%x\n", phba->pport->port_state);
6281 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006282 }
James Smart6fb120a2009-05-22 14:52:59 -04006283 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6284 mbox->vport = phba->pport;
6285 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6286 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6287
6288 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006289 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6290 "2552 Unregister FCFI command failed rc x%x "
6291 "HBA state x%x\n",
6292 rc, phba->pport->port_state);
6293 return -EINVAL;
6294 }
6295 return 0;
6296}
6297
6298/**
6299 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6300 * @phba: Pointer to hba context object.
6301 *
6302 * This function unregisters the currently reigstered FCF. This function
6303 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6304 */
6305void
6306lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6307{
6308 int rc;
6309
6310 /* Preparation for unregistering fcf */
6311 rc = lpfc_unregister_fcf_prep(phba);
6312 if (rc) {
6313 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6314 "2748 Failed to prepare for unregistering "
6315 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006316 return;
6317 }
6318
James Smartecfd03c2010-02-12 14:41:27 -05006319 /* Now, unregister FCF record and reset HBA FCF state */
6320 rc = lpfc_sli4_unregister_fcf(phba);
6321 if (rc)
6322 return;
6323 /* Reset HBA FCF states after successful unregister FCF */
6324 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006325 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006326
6327 /*
6328 * If driver is not unloading, check if there is any other
6329 * FCF record that can be used for discovery.
6330 */
6331 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006332 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006333 return;
6334
James Smart0c9ab6f2010-02-26 14:15:57 -05006335 /* This is considered as the initial FCF discovery scan */
6336 spin_lock_irq(&phba->hbalock);
6337 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6338 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006339
6340 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006341 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006342
James Smart0c9ab6f2010-02-26 14:15:57 -05006343 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006344
James Smart0c9ab6f2010-02-26 14:15:57 -05006345 if (rc) {
6346 spin_lock_irq(&phba->hbalock);
6347 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6348 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006349 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006350 "2553 lpfc_unregister_unused_fcf failed "
6351 "to read FCF record HBA state x%x\n",
6352 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006353 }
James Smartecfd03c2010-02-12 14:41:27 -05006354}
6355
6356/**
6357 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6358 * @phba: Pointer to hba context object.
6359 *
6360 * This function just unregisters the currently reigstered FCF. It does not
6361 * try to find another FCF for discovery.
6362 */
6363void
6364lpfc_unregister_fcf(struct lpfc_hba *phba)
6365{
6366 int rc;
6367
6368 /* Preparation for unregistering fcf */
6369 rc = lpfc_unregister_fcf_prep(phba);
6370 if (rc) {
6371 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6372 "2749 Failed to prepare for unregistering "
6373 "HBA's FCF record: rc=%d\n", rc);
6374 return;
6375 }
6376
6377 /* Now, unregister FCF record and reset HBA FCF state */
6378 rc = lpfc_sli4_unregister_fcf(phba);
6379 if (rc)
6380 return;
6381 /* Set proper HBA FCF states after successful unregister FCF */
6382 spin_lock_irq(&phba->hbalock);
6383 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6384 spin_unlock_irq(&phba->hbalock);
6385}
6386
6387/**
6388 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6389 * @phba: Pointer to hba context object.
6390 *
6391 * This function check if there are any connected remote port for the FCF and
6392 * if all the devices are disconnected, this function unregister FCFI.
6393 * This function also tries to use another FCF for discovery.
6394 */
6395void
6396lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6397{
6398 /*
James Smart3804dc82010-07-14 15:31:37 -04006399 * If HBA is not running in FIP mode, if HBA does not support
6400 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6401 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006402 */
6403 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006404 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006405 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006406 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006407 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006408 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006409 spin_unlock_irq(&phba->hbalock);
6410 return;
6411 }
6412 spin_unlock_irq(&phba->hbalock);
6413
6414 if (lpfc_fcf_inuse(phba))
6415 return;
6416
6417 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006418}
6419
6420/**
6421 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6422 * @phba: Pointer to hba context object.
6423 * @buff: Buffer containing the FCF connection table as in the config
6424 * region.
6425 * This function create driver data structure for the FCF connection
6426 * record table read from config region 23.
6427 */
6428static void
6429lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6430 uint8_t *buff)
6431{
6432 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6433 struct lpfc_fcf_conn_hdr *conn_hdr;
6434 struct lpfc_fcf_conn_rec *conn_rec;
6435 uint32_t record_count;
6436 int i;
6437
6438 /* Free the current connect table */
6439 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006440 &phba->fcf_conn_rec_list, list) {
6441 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006442 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006443 }
James Smart6fb120a2009-05-22 14:52:59 -04006444
6445 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6446 record_count = conn_hdr->length * sizeof(uint32_t)/
6447 sizeof(struct lpfc_fcf_conn_rec);
6448
6449 conn_rec = (struct lpfc_fcf_conn_rec *)
6450 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6451
6452 for (i = 0; i < record_count; i++) {
6453 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6454 continue;
6455 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6456 GFP_KERNEL);
6457 if (!conn_entry) {
6458 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6459 "2566 Failed to allocate connection"
6460 " table entry\n");
6461 return;
6462 }
6463
6464 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6465 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006466 list_add_tail(&conn_entry->list,
6467 &phba->fcf_conn_rec_list);
6468 }
James Smartdf0d0852013-05-31 17:05:08 -04006469
6470 if (!list_empty(&phba->fcf_conn_rec_list)) {
6471 i = 0;
6472 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6473 list) {
6474 conn_rec = &conn_entry->conn_rec;
6475 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6476 "3345 FCF connection list rec[%02d]: "
6477 "flags:x%04x, vtag:x%04x, "
6478 "fabric_name:x%02x:%02x:%02x:%02x:"
6479 "%02x:%02x:%02x:%02x, "
6480 "switch_name:x%02x:%02x:%02x:%02x:"
6481 "%02x:%02x:%02x:%02x\n", i++,
6482 conn_rec->flags, conn_rec->vlan_tag,
6483 conn_rec->fabric_name[0],
6484 conn_rec->fabric_name[1],
6485 conn_rec->fabric_name[2],
6486 conn_rec->fabric_name[3],
6487 conn_rec->fabric_name[4],
6488 conn_rec->fabric_name[5],
6489 conn_rec->fabric_name[6],
6490 conn_rec->fabric_name[7],
6491 conn_rec->switch_name[0],
6492 conn_rec->switch_name[1],
6493 conn_rec->switch_name[2],
6494 conn_rec->switch_name[3],
6495 conn_rec->switch_name[4],
6496 conn_rec->switch_name[5],
6497 conn_rec->switch_name[6],
6498 conn_rec->switch_name[7]);
6499 }
6500 }
James Smart6fb120a2009-05-22 14:52:59 -04006501}
6502
6503/**
6504 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6505 * @phba: Pointer to hba context object.
6506 * @buff: Buffer containing the FCoE parameter data structure.
6507 *
6508 * This function update driver data structure with config
6509 * parameters read from config region 23.
6510 */
6511static void
6512lpfc_read_fcoe_param(struct lpfc_hba *phba,
6513 uint8_t *buff)
6514{
6515 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6516 struct lpfc_fcoe_params *fcoe_param;
6517
6518 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6519 buff;
6520 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006521 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006522
6523 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6524 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6525 return;
6526
James Smart6fb120a2009-05-22 14:52:59 -04006527 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6528 phba->valid_vlan = 1;
6529 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6530 0xFFF;
6531 }
6532
6533 phba->fc_map[0] = fcoe_param->fc_map[0];
6534 phba->fc_map[1] = fcoe_param->fc_map[1];
6535 phba->fc_map[2] = fcoe_param->fc_map[2];
6536 return;
6537}
6538
6539/**
6540 * lpfc_get_rec_conf23 - Get a record type in config region data.
6541 * @buff: Buffer containing config region 23 data.
6542 * @size: Size of the data buffer.
6543 * @rec_type: Record type to be searched.
6544 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006545 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006546 * of the record specified by record_type. If record found, this
6547 * function return pointer to the record else return NULL.
6548 */
6549static uint8_t *
6550lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6551{
6552 uint32_t offset = 0, rec_length;
6553
6554 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6555 (size < sizeof(uint32_t)))
6556 return NULL;
6557
6558 rec_length = buff[offset + 1];
6559
6560 /*
6561 * One TLV record has one word header and number of data words
6562 * specified in the rec_length field of the record header.
6563 */
6564 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6565 <= size) {
6566 if (buff[offset] == rec_type)
6567 return &buff[offset];
6568
6569 if (buff[offset] == LPFC_REGION23_LAST_REC)
6570 return NULL;
6571
6572 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6573 rec_length = buff[offset + 1];
6574 }
6575 return NULL;
6576}
6577
6578/**
6579 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6580 * @phba: Pointer to lpfc_hba data structure.
6581 * @buff: Buffer containing config region 23 data.
6582 * @size: Size of the data buffer.
6583 *
Stefan Weileef35c22010-08-06 21:11:15 +02006584 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006585 * populate driver data structure with the parameters.
6586 */
6587void
6588lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6589 uint8_t *buff,
6590 uint32_t size)
6591{
James Smarteb016562014-09-03 12:58:06 -04006592 uint32_t offset = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006593 uint8_t *rec_ptr;
6594
6595 /*
6596 * If data size is less than 2 words signature and version cannot be
6597 * verified.
6598 */
6599 if (size < 2*sizeof(uint32_t))
6600 return;
6601
6602 /* Check the region signature first */
6603 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6604 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6605 "2567 Config region 23 has bad signature\n");
6606 return;
6607 }
6608
6609 offset += 4;
6610
6611 /* Check the data structure version */
6612 if (buff[offset] != LPFC_REGION23_VERSION) {
6613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6614 "2568 Config region 23 has bad version\n");
6615 return;
6616 }
6617 offset += 4;
6618
James Smart6fb120a2009-05-22 14:52:59 -04006619 /* Read FCoE param record */
6620 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6621 size - offset, FCOE_PARAM_TYPE);
6622 if (rec_ptr)
6623 lpfc_read_fcoe_param(phba, rec_ptr);
6624
6625 /* Read FCF connection table */
6626 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6627 size - offset, FCOE_CONN_TBL_TYPE);
6628 if (rec_ptr)
6629 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6630
6631}