blob: 2d929a5e8354dab11871d65e9b36bc22a5a333eb [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 Smartb857ff32014-04-04 13:52:50 -04004 * Copyright (C) 2004-2014 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
James Smarta93ff372010-10-22 11:06:08 -040023#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/pci.h>
26#include <linux/kthread.h>
27#include <linux/interrupt.h>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
33
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050035#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050044#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050045#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050046
47/* AlpaArray for assignment of scsid for scan-down and bind_method */
48static uint8_t lpfcAlpaArray[] = {
49 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
50 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
51 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
52 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
53 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
54 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
55 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
56 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
57 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
58 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
59 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
60 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
61 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
62};
63
James Smart2e0fef82007-06-17 19:56:36 -050064static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010065static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040066static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040067static int lpfc_fcf_inuse(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050068
James Smartc01f3202006-08-18 17:47:08 -040069void
70lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050071{
James Smartc01f3202006-08-18 17:47:08 -040072 struct lpfc_rport_data *rdata;
73 struct lpfc_nodelist * ndlp;
74 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050075
James Smartc01f3202006-08-18 17:47:08 -040076 rdata = rport->dd_data;
77 ndlp = rdata->pnode;
78
James Smart58da1ff2008-04-07 10:15:56 -040079 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040080 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
81 printk(KERN_ERR "Cannot find remote node"
82 " to terminate I/O Data x%x\n",
83 rport->port_id);
dea31012005-04-17 16:05:31 -050084 return;
85 }
86
James Smarta257bf92009-04-06 18:48:10 -040087 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050088
James Smart858c9f62007-06-17 19:56:39 -050089 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
90 "rport terminate: sid:x%x did:x%x flg:x%x",
91 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
92
James Smartc01f3202006-08-18 17:47:08 -040093 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -040094 lpfc_sli_abort_iocb(ndlp->vport,
95 &phba->sli.ring[phba->sli.fcp_ring],
96 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -040097 }
James Smartc01f3202006-08-18 17:47:08 -040098}
99
100/*
101 * This function will be called when dev_loss_tmo fire.
102 */
103void
104lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
105{
106 struct lpfc_rport_data *rdata;
107 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500108 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500109 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500110 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400111 int put_node;
112 int put_rport;
James Smartc01f3202006-08-18 17:47:08 -0400113
114 rdata = rport->dd_data;
115 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400116 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400117 return;
James Smartc01f3202006-08-18 17:47:08 -0400118
James Smart858c9f62007-06-17 19:56:39 -0500119 vport = ndlp->vport;
120 phba = vport->phba;
121
122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
123 "rport devlosscb: sid:x%x did:x%x flg:x%x",
124 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
125
James Smart34f5ad82012-08-03 12:35:03 -0400126 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
127 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
128 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
129
James Smarta8adb832007-10-27 13:37:53 -0400130 /* Don't defer this if we are in the process of deleting the vport
131 * or unloading the driver. The unload will cleanup the node
132 * appropriately we just need to cleanup the ndlp rport info here.
133 */
134 if (vport->load_flag & FC_UNLOADING) {
135 put_node = rdata->pnode != NULL;
136 put_rport = ndlp->rport != NULL;
137 rdata->pnode = NULL;
138 ndlp->rport = NULL;
139 if (put_node)
140 lpfc_nlp_put(ndlp);
141 if (put_rport)
142 put_device(&rport->dev);
143 return;
144 }
145
146 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
147 return;
148
James Smart34f5ad82012-08-03 12:35:03 -0400149 if (ndlp->nlp_type & NLP_FABRIC) {
150
151 /* If the WWPN of the rport and ndlp don't match, ignore it */
152 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) {
153 put_device(&rport->dev);
154 return;
155 }
James Smart12838e72014-09-03 12:57:19 -0400156
157 put_node = rdata->pnode != NULL;
158 put_rport = ndlp->rport != NULL;
159 rdata->pnode = NULL;
160 ndlp->rport = NULL;
161 if (put_node)
162 lpfc_nlp_put(ndlp);
163 if (put_rport)
164 put_device(&rport->dev);
165 return;
James Smart34f5ad82012-08-03 12:35:03 -0400166 }
167
James Smart858c9f62007-06-17 19:56:39 -0500168 evtp = &ndlp->dev_loss_evt;
169
170 if (!list_empty(&evtp->evt_listp))
171 return;
172
James Smarta62a4352013-04-17 20:18:19 -0400173 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart12838e72014-09-03 12:57:19 -0400174 ndlp->nlp_add_flag |= NLP_IN_DEV_LOSS;
James Smarta62a4352013-04-17 20:18:19 -0400175
James Smart858c9f62007-06-17 19:56:39 -0500176 spin_lock_irq(&phba->hbalock);
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 Smart5e9d9b82008-06-14 22:52:53 -0400180 if (evtp->evt_arg1) {
181 evtp->evt = LPFC_EVT_DEV_LOSS;
182 list_add_tail(&evtp->evt_listp, &phba->work_list);
183 lpfc_worker_wake_up(phba);
184 }
James Smart858c9f62007-06-17 19:56:39 -0500185 spin_unlock_irq(&phba->hbalock);
186
James Smart858c9f62007-06-17 19:56:39 -0500187 return;
188}
189
James Smarta93ff372010-10-22 11:06:08 -0400190/**
191 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
192 * @ndlp: Pointer to remote node object.
193 *
194 * This function is called from the worker thread when devloss timeout timer
195 * expires. For SLI4 host, this routine shall return 1 when at lease one
196 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
197 * routine shall return 0 when there is no remote node is still in use of FCF
198 * when devloss timeout happened to this @ndlp.
199 **/
200static int
James Smart858c9f62007-06-17 19:56:39 -0500201lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
202{
203 struct lpfc_rport_data *rdata;
204 struct fc_rport *rport;
205 struct lpfc_vport *vport;
206 struct lpfc_hba *phba;
207 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400208 int put_node;
209 int put_rport;
James Smart858c9f62007-06-17 19:56:39 -0500210 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400211 int fcf_inuse = 0;
James Smart858c9f62007-06-17 19:56:39 -0500212
213 rport = ndlp->rport;
214
James Smart12838e72014-09-03 12:57:19 -0400215 if (!rport) {
216 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
James Smarta93ff372010-10-22 11:06:08 -0400217 return fcf_inuse;
James Smart12838e72014-09-03 12:57:19 -0400218 }
James Smart858c9f62007-06-17 19:56:39 -0500219
220 rdata = rport->dd_data;
221 name = (uint8_t *) &ndlp->nlp_portname;
222 vport = ndlp->vport;
223 phba = vport->phba;
224
James Smarta93ff372010-10-22 11:06:08 -0400225 if (phba->sli_rev == LPFC_SLI_REV4)
226 fcf_inuse = lpfc_fcf_inuse(phba);
227
James Smart858c9f62007-06-17 19:56:39 -0500228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
229 "rport devlosstmo:did:x%x type:x%x id:x%x",
230 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
231
James Smart34f5ad82012-08-03 12:35:03 -0400232 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
233 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
234 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
235
James Smarta8adb832007-10-27 13:37:53 -0400236 /* Don't defer this if we are in the process of deleting the vport
237 * or unloading the driver. The unload will cleanup the node
238 * appropriately we just need to cleanup the ndlp rport info here.
239 */
240 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500241 if (ndlp->nlp_sid != NLP_NO_SID) {
242 /* flush the target */
243 lpfc_sli_abort_iocb(vport,
244 &phba->sli.ring[phba->sli.fcp_ring],
245 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
246 }
James Smarta8adb832007-10-27 13:37:53 -0400247 put_node = rdata->pnode != NULL;
248 put_rport = ndlp->rport != NULL;
249 rdata->pnode = NULL;
250 ndlp->rport = NULL;
James Smart12838e72014-09-03 12:57:19 -0400251 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
James Smarta8adb832007-10-27 13:37:53 -0400252 if (put_node)
253 lpfc_nlp_put(ndlp);
254 if (put_rport)
255 put_device(&rport->dev);
James Smarta93ff372010-10-22 11:06:08 -0400256 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400257 }
258
James Smartd7c255b2008-08-24 21:50:00 -0400259 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
260 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
261 "0284 Devloss timeout Ignored on "
262 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
263 "NPort x%x\n",
264 *name, *(name+1), *(name+2), *(name+3),
265 *(name+4), *(name+5), *(name+6), *(name+7),
266 ndlp->nlp_DID);
James Smart12838e72014-09-03 12:57:19 -0400267 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
James Smarta93ff372010-10-22 11:06:08 -0400268 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400269 }
James Smart858c9f62007-06-17 19:56:39 -0500270
James Smart92d7f7b2007-06-17 19:56:38 -0500271 if (ndlp->nlp_type & NLP_FABRIC) {
272 /* We will clean up these Nodes in linkup */
273 put_node = rdata->pnode != NULL;
274 put_rport = ndlp->rport != NULL;
275 rdata->pnode = NULL;
276 ndlp->rport = NULL;
James Smart12838e72014-09-03 12:57:19 -0400277 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
James Smart92d7f7b2007-06-17 19:56:38 -0500278 if (put_node)
279 lpfc_nlp_put(ndlp);
280 if (put_rport)
281 put_device(&rport->dev);
James Smarta93ff372010-10-22 11:06:08 -0400282 return fcf_inuse;
James Smart92d7f7b2007-06-17 19:56:38 -0500283 }
James Smart82085712007-04-25 09:52:41 -0400284
dea31012005-04-17 16:05:31 -0500285 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400286 warn_on = 1;
dea31012005-04-17 16:05:31 -0500287 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -0400288 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
289 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500290 }
James Smartc01f3202006-08-18 17:47:08 -0400291
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400292 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400293 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
294 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400295 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
296 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400297 *name, *(name+1), *(name+2), *(name+3),
298 *(name+4), *(name+5), *(name+6), *(name+7),
299 ndlp->nlp_DID, ndlp->nlp_flag,
300 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400301 } else {
James Smarte8b62012007-08-02 11:10:09 -0400302 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
303 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400304 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
305 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400306 *name, *(name+1), *(name+2), *(name+3),
307 *(name+4), *(name+5), *(name+6), *(name+7),
308 ndlp->nlp_DID, ndlp->nlp_flag,
309 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400310 }
311
James Smart87af33f2007-10-27 13:37:43 -0400312 put_node = rdata->pnode != NULL;
313 put_rport = ndlp->rport != NULL;
314 rdata->pnode = NULL;
315 ndlp->rport = NULL;
James Smart12838e72014-09-03 12:57:19 -0400316 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
James Smart87af33f2007-10-27 13:37:43 -0400317 if (put_node)
318 lpfc_nlp_put(ndlp);
319 if (put_rport)
320 put_device(&rport->dev);
321
James Smart2e0fef82007-06-17 19:56:36 -0500322 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400323 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400324 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400325 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400326 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
327 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500328 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400329
James Smarta93ff372010-10-22 11:06:08 -0400330 return fcf_inuse;
331}
332
333/**
334 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
335 * @phba: Pointer to hba context object.
336 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
337 * @nlp_did: remote node identifer with devloss timeout.
338 *
339 * This function is called from the worker thread after invoking devloss
340 * timeout handler and releasing the reference count for the ndlp with
341 * which the devloss timeout was handled for SLI4 host. For the devloss
342 * timeout of the last remote node which had been in use of FCF, when this
343 * routine is invoked, it shall be guaranteed that none of the remote are
344 * in-use of FCF. When devloss timeout to the last remote using the FCF,
345 * if the FIP engine is neither in FCF table scan process nor roundrobin
346 * failover process, the in-use FCF shall be unregistered. If the FIP
347 * engine is in FCF discovery process, the devloss timeout state shall
348 * be set for either the FCF table scan process or roundrobin failover
349 * process to unregister the in-use FCF.
350 **/
351static void
352lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
353 uint32_t nlp_did)
354{
355 /* If devloss timeout happened to a remote node when FCF had no
356 * longer been in-use, do nothing.
357 */
358 if (!fcf_inuse)
359 return;
360
361 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
362 spin_lock_irq(&phba->hbalock);
363 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
364 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
365 spin_unlock_irq(&phba->hbalock);
366 return;
367 }
368 phba->hba_flag |= HBA_DEVLOSS_TMO;
369 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
370 "2847 Last remote node (x%x) using "
371 "FCF devloss tmo\n", nlp_did);
372 }
373 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
374 spin_unlock_irq(&phba->hbalock);
375 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
376 "2868 Devloss tmo to FCF rediscovery "
377 "in progress\n");
378 return;
379 }
380 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
381 spin_unlock_irq(&phba->hbalock);
382 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
383 "2869 Devloss tmo to idle FIP engine, "
384 "unreg in-use FCF and rescan.\n");
385 /* Unregister in-use FCF and rescan */
386 lpfc_unregister_fcf_rescan(phba);
387 return;
388 }
389 spin_unlock_irq(&phba->hbalock);
390 if (phba->hba_flag & FCF_TS_INPROG)
391 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
392 "2870 FCF table scan in progress\n");
393 if (phba->hba_flag & FCF_RR_INPROG)
394 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
395 "2871 FLOGI roundrobin FCF failover "
396 "in progress\n");
397 }
James Smart6fb120a2009-05-22 14:52:59 -0400398 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500399}
James Smartc01f3202006-08-18 17:47:08 -0400400
James Smartea2151b2008-09-07 11:52:10 -0400401/**
James Smart3621a712009-04-06 18:47:14 -0400402 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400403 * @phba: Pointer to hba context object.
404 *
405 * This function is called from the functions which need to post
406 * events from interrupt context. This function allocates data
407 * structure required for posting event. It also keeps track of
408 * number of events pending and prevent event storm when there are
409 * too many events.
410 **/
411struct lpfc_fast_path_event *
412lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
413 struct lpfc_fast_path_event *ret;
414
415 /* If there are lot of fast event do not exhaust memory due to this */
416 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
417 return NULL;
418
419 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
420 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400421 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400422 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400423 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
424 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
425 }
James Smartea2151b2008-09-07 11:52:10 -0400426 return ret;
427}
428
429/**
James Smart3621a712009-04-06 18:47:14 -0400430 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400431 * @phba: Pointer to hba context object.
432 * @evt: Event object which need to be freed.
433 *
434 * This function frees the data structure required for posting
435 * events.
436 **/
437void
438lpfc_free_fast_evt(struct lpfc_hba *phba,
439 struct lpfc_fast_path_event *evt) {
440
441 atomic_dec(&phba->fast_event_count);
442 kfree(evt);
443}
444
445/**
James Smart3621a712009-04-06 18:47:14 -0400446 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400447 * @phba: Pointer to hba context object.
448 * @evtp: Event data structure.
449 *
450 * This function is called from worker thread, when the interrupt
451 * context need to post an event. This function posts the event
452 * to fc transport netlink interface.
453 **/
454static void
455lpfc_send_fastpath_evt(struct lpfc_hba *phba,
456 struct lpfc_work_evt *evtp)
457{
458 unsigned long evt_category, evt_sub_category;
459 struct lpfc_fast_path_event *fast_evt_data;
460 char *evt_data;
461 uint32_t evt_data_size;
462 struct Scsi_Host *shost;
463
464 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
465 work_evt);
466
467 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
468 evt_sub_category = (unsigned long) fast_evt_data->un.
469 fabric_evt.subcategory;
470 shost = lpfc_shost_from_vport(fast_evt_data->vport);
471 if (evt_category == FC_REG_FABRIC_EVENT) {
472 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
473 evt_data = (char *) &fast_evt_data->un.read_check_error;
474 evt_data_size = sizeof(fast_evt_data->un.
475 read_check_error);
476 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500477 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400478 evt_data = (char *) &fast_evt_data->un.fabric_evt;
479 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
480 } else {
481 lpfc_free_fast_evt(phba, fast_evt_data);
482 return;
483 }
484 } else if (evt_category == FC_REG_SCSI_EVENT) {
485 switch (evt_sub_category) {
486 case LPFC_EVENT_QFULL:
487 case LPFC_EVENT_DEVBSY:
488 evt_data = (char *) &fast_evt_data->un.scsi_evt;
489 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
490 break;
491 case LPFC_EVENT_CHECK_COND:
492 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
493 evt_data_size = sizeof(fast_evt_data->un.
494 check_cond_evt);
495 break;
496 case LPFC_EVENT_VARQUEDEPTH:
497 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
498 evt_data_size = sizeof(fast_evt_data->un.
499 queue_depth_evt);
500 break;
501 default:
502 lpfc_free_fast_evt(phba, fast_evt_data);
503 return;
504 }
505 } else {
506 lpfc_free_fast_evt(phba, fast_evt_data);
507 return;
508 }
509
510 fc_host_post_vendor_event(shost,
511 fc_get_event_number(),
512 evt_data_size,
513 evt_data,
James Smartddcc50f2008-12-04 22:38:46 -0500514 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400515
516 lpfc_free_fast_evt(phba, fast_evt_data);
517 return;
518}
519
dea31012005-04-17 16:05:31 -0500520static void
James Smart2e0fef82007-06-17 19:56:36 -0500521lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500522{
523 struct lpfc_work_evt *evtp = NULL;
524 struct lpfc_nodelist *ndlp;
525 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400526 int fcf_inuse;
527 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500528
James Smart2e0fef82007-06-17 19:56:36 -0500529 spin_lock_irq(&phba->hbalock);
530 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500531 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
532 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500533 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500534 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500535 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500536 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500537 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500538 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500539 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500540 /* decrement the node reference count held
541 * for this queued work
542 */
543 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500544 break;
James Smart858c9f62007-06-17 19:56:39 -0500545 case LPFC_EVT_DEV_LOSS:
546 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400547 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500548 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500549 /* decrement the node reference count held for
550 * this queued work
551 */
James Smarta93ff372010-10-22 11:06:08 -0400552 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500553 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400554 if (phba->sli_rev == LPFC_SLI_REV4)
555 lpfc_sli4_post_dev_loss_tmo_handler(phba,
556 fcf_inuse,
557 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500558 break;
dea31012005-04-17 16:05:31 -0500559 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500560 if (phba->link_state < LPFC_LINK_DOWN)
561 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500562 else
James Smart2e0fef82007-06-17 19:56:36 -0500563 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500564 complete((struct completion *)(evtp->evt_arg2));
565 break;
James Smart46fa3112007-04-25 09:51:45 -0400566 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500567 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart618a5232012-06-12 13:54:36 -0400568 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
James Smart46fa3112007-04-25 09:51:45 -0400569 *(int *)(evtp->evt_arg1) = 0;
570 complete((struct completion *)(evtp->evt_arg2));
571 break;
572 case LPFC_EVT_OFFLINE:
573 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500574 lpfc_sli_brdrestart(phba);
575 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400576 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
577 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500578 complete((struct completion *)(evtp->evt_arg2));
579 break;
580 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400581 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500582 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500583 lpfc_sli_brdreset(phba);
584 lpfc_hba_down_post(phba);
585 *(int *)(evtp->evt_arg1) =
586 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400587 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500588 complete((struct completion *)(evtp->evt_arg2));
589 break;
590 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400591 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500592 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500593 = (phba->pport->stopped)
594 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400595 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500596 complete((struct completion *)(evtp->evt_arg2));
597 break;
James Smartea2151b2008-09-07 11:52:10 -0400598 case LPFC_EVT_FASTPATH_MGMT_EVT:
599 lpfc_send_fastpath_evt(phba, evtp);
600 free_evt = 0;
601 break;
James Smart78730cf2010-04-06 15:06:30 -0400602 case LPFC_EVT_RESET_HBA:
603 if (!(phba->pport->load_flag & FC_UNLOADING))
604 lpfc_reset_hba(phba);
605 break;
dea31012005-04-17 16:05:31 -0500606 }
607 if (free_evt)
608 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500609 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500610 }
James Smart2e0fef82007-06-17 19:56:36 -0500611 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500612
613}
614
James Smart311464e2007-08-02 11:10:37 -0400615static void
James Smart2e0fef82007-06-17 19:56:36 -0500616lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500617{
618 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500619 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400620 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400621 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400622 int i;
dea31012005-04-17 16:05:31 -0500623
James Smart2e0fef82007-06-17 19:56:36 -0500624 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500625 ha_copy = phba->work_ha;
626 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500627 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500628
James Smartda0436e2009-05-22 14:51:39 -0400629 /* First, try to post the next mailbox command to SLI4 device */
630 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
631 lpfc_sli4_post_async_mbox(phba);
632
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500633 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400634 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500635 lpfc_handle_eratt(phba);
636
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500637 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500638 lpfc_sli_handle_mb_event(phba);
639
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500640 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500641 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400642
James Smartda0436e2009-05-22 14:51:39 -0400643 /* Process SLI4 events */
644 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
James Smart19ca7602010-11-20 23:11:55 -0500645 if (phba->hba_flag & HBA_RRQ_ACTIVE)
646 lpfc_handle_rrq_active(phba);
James Smartda0436e2009-05-22 14:51:39 -0400647 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
648 lpfc_sli4_fcp_xri_abort_event_proc(phba);
649 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
650 lpfc_sli4_els_xri_abort_event_proc(phba);
651 if (phba->hba_flag & ASYNC_EVENT)
652 lpfc_sli4_async_event_proc(phba);
653 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
654 spin_lock_irq(&phba->hbalock);
655 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
656 spin_unlock_irq(&phba->hbalock);
657 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
658 }
James Smartecfd03c2010-02-12 14:41:27 -0500659 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
660 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400661 }
662
James Smart549e55c2007-08-02 11:09:51 -0400663 vports = lpfc_create_vport_work_array(phba);
664 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400665 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400666 /*
667 * We could have no vports in array if unloading, so if
668 * this happens then just use the pport
669 */
670 if (vports[i] == NULL && i == 0)
671 vport = phba->pport;
672 else
673 vport = vports[i];
674 if (vport == NULL)
675 break;
James Smart58da1ff2008-04-07 10:15:56 -0400676 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400677 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400678 vport->work_port_events &= ~work_port_events;
679 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400680 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400681 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400682 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400683 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400684 if (work_port_events & WORKER_HB_TMO)
685 lpfc_hb_timeout_handler(phba);
686 if (work_port_events & WORKER_MBOX_TMO)
687 lpfc_mbox_timeout_handler(phba);
688 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
689 lpfc_unblock_fabric_iocbs(phba);
690 if (work_port_events & WORKER_FDMI_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400691 lpfc_fdmi_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400692 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
693 lpfc_ramp_down_queue_handler(phba);
James Smart92494142011-02-16 12:39:44 -0500694 if (work_port_events & WORKER_DELAYED_DISC_TMO)
695 lpfc_delayed_disc_timeout_handler(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500696 }
James Smart09372822008-01-11 01:52:54 -0500697 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500698
James Smart858c9f62007-06-17 19:56:39 -0500699 pring = &phba->sli.ring[LPFC_ELS_RING];
700 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
701 status >>= (4*LPFC_ELS_RING);
James Smart4d9ab992009-10-02 15:16:39 -0400702 if ((status & HA_RXMASK) ||
703 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
James Smart45ed1192009-10-02 15:17:02 -0400704 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400705 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500706 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400707 /* Set the lpfc data pending flag */
708 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500709 } else {
James Smart94661502013-03-01 16:37:29 -0500710 if (phba->link_state >= LPFC_LINK_UP) {
711 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
712 lpfc_sli_handle_slow_ring_event(phba, pring,
713 (status &
714 HA_RXMASK));
715 }
James Smart858c9f62007-06-17 19:56:39 -0500716 }
James Smart0e9bb8d2013-03-01 16:35:12 -0500717 if ((phba->sli_rev == LPFC_SLI_REV4) &
718 (!list_empty(&pring->txq)))
James Smart2a9bf3d2010-06-07 15:24:45 -0400719 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500720 /*
721 * Turn on Ring interrupts
722 */
James Smart3772a992009-05-22 14:50:54 -0400723 if (phba->sli_rev <= LPFC_SLI_REV3) {
724 spin_lock_irq(&phba->hbalock);
725 control = readl(phba->HCregaddr);
726 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
727 lpfc_debugfs_slow_ring_trc(phba,
728 "WRK Enable ring: cntl:x%x hacopy:x%x",
729 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400730
James Smart3772a992009-05-22 14:50:54 -0400731 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
732 writel(control, phba->HCregaddr);
733 readl(phba->HCregaddr); /* flush */
734 } else {
735 lpfc_debugfs_slow_ring_trc(phba,
736 "WRK Ring ok: cntl:x%x hacopy:x%x",
737 control, ha_copy, 0);
738 }
739 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500740 }
741 }
James Smart2e0fef82007-06-17 19:56:36 -0500742 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500743}
744
dea31012005-04-17 16:05:31 -0500745int
746lpfc_do_work(void *p)
747{
748 struct lpfc_hba *phba = p;
749 int rc;
dea31012005-04-17 16:05:31 -0500750
Dongsheng Yang8698a742014-03-11 18:09:12 +0800751 set_user_nice(current, MIN_NICE);
James Smart043c9562012-05-09 21:17:43 -0400752 current->flags |= PF_NOFREEZE;
James Smart5e9d9b82008-06-14 22:52:53 -0400753 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500754
James Smart3a55b532008-12-04 22:38:54 -0500755 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400756 /* wait and check worker queue activities */
757 rc = wait_event_interruptible(phba->work_waitq,
758 (test_and_clear_bit(LPFC_DATA_READY,
759 &phba->data_flags)
760 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500761 /* Signal wakeup shall terminate the worker thread */
762 if (rc) {
763 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
764 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500765 break;
James Smart3a55b532008-12-04 22:38:54 -0500766 }
dea31012005-04-17 16:05:31 -0500767
James Smart5e9d9b82008-06-14 22:52:53 -0400768 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500769 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500770 }
James Smart3a55b532008-12-04 22:38:54 -0500771 phba->worker_thread = NULL;
772 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
773 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500774 return 0;
775}
776
777/*
778 * This is only called to handle FC worker events. Since this a rare
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300779 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
dea31012005-04-17 16:05:31 -0500780 * embedding it in the IOCB.
781 */
782int
James Smart2e0fef82007-06-17 19:56:36 -0500783lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500784 uint32_t evt)
785{
786 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500787 unsigned long flags;
dea31012005-04-17 16:05:31 -0500788
789 /*
790 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
791 * be queued to worker thread for processing
792 */
James Smart92d7f7b2007-06-17 19:56:38 -0500793 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500794 if (!evtp)
795 return 0;
796
797 evtp->evt_arg1 = arg1;
798 evtp->evt_arg2 = arg2;
799 evtp->evt = evt;
800
James Smarted957682007-06-17 19:56:37 -0500801 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400802 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500803 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500804
James Smart5e9d9b82008-06-14 22:52:53 -0400805 lpfc_worker_wake_up(phba);
806
dea31012005-04-17 16:05:31 -0500807 return 1;
808}
809
James Smart92d7f7b2007-06-17 19:56:38 -0500810void
811lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
812{
James Smart09372822008-01-11 01:52:54 -0500813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500814 struct lpfc_hba *phba = vport->phba;
815 struct lpfc_nodelist *ndlp, *next_ndlp;
816 int rc;
817
818 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500819 if (!NLP_CHK_NODE_ACT(ndlp))
820 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500821 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
822 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400823 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
824 ((vport->port_type == LPFC_NPIV_PORT) &&
825 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500826 lpfc_unreg_rpi(vport, ndlp);
827
828 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400829 if ((phba->sli_rev < LPFC_SLI_REV4) &&
830 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500831 continue;
832 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
833 remove
834 ? NLP_EVT_DEVICE_RM
835 : NLP_EVT_DEVICE_RECOVERY);
836 }
837 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400838 if (phba->sli_rev == LPFC_SLI_REV4)
839 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500840 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500841 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500842 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500843 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500844 }
845}
846
James Smart87af33f2007-10-27 13:37:43 -0400847void
James Smart98c9ea52007-10-27 13:37:33 -0400848lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500849{
James Smart695a8142010-01-26 23:08:03 -0500850 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
851
James Smart45ed1192009-10-02 15:17:02 -0400852 /* Cleanup any outstanding received buffers */
853 lpfc_cleanup_rcv_buffers(vport);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* Cleanup any outstanding RSCN activity */
856 lpfc_els_flush_rscn(vport);
857
858 /* Cleanup any outstanding ELS commands */
859 lpfc_els_flush_cmd(vport);
860
861 lpfc_cleanup_rpis(vport, 0);
862
James Smart92d7f7b2007-06-17 19:56:38 -0500863 /* Turn off discovery timer if its running */
864 lpfc_can_disctmo(vport);
865}
866
James Smart3772a992009-05-22 14:50:54 -0400867void
James Smart98c9ea52007-10-27 13:37:33 -0400868lpfc_linkdown_port(struct lpfc_vport *vport)
869{
870 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
871
872 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
873
874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
875 "Link Down: state:x%x rtry:x%x flg:x%x",
876 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
877
878 lpfc_port_link_failure(vport);
879
James Smart92494142011-02-16 12:39:44 -0500880 /* Stop delayed Nport discovery */
881 spin_lock_irq(shost->host_lock);
882 vport->fc_flag &= ~FC_DISC_DELAYED;
883 spin_unlock_irq(shost->host_lock);
884 del_timer_sync(&vport->delayed_disc_tmo);
James Smart98c9ea52007-10-27 13:37:33 -0400885}
886
dea31012005-04-17 16:05:31 -0500887int
James Smart685f0bf2007-04-25 09:53:08 -0400888lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500889{
James Smart2e0fef82007-06-17 19:56:36 -0500890 struct lpfc_vport *vport = phba->pport;
891 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400892 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400893 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400894 int i;
dea31012005-04-17 16:05:31 -0500895
James Smart3163f722008-02-08 18:50:25 -0500896 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500897 return 0;
James Smartaacc20e2009-12-21 17:02:51 -0500898
899 /* Block all SCSI stack I/Os */
900 lpfc_scsi_dev_block(phba);
901
James Smart2e0fef82007-06-17 19:56:36 -0500902 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500903 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500904 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500905 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500906 phba->link_state = LPFC_LINK_DOWN;
James Smart72100cc2010-02-12 14:43:01 -0500907 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500908 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500909 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500910 }
James Smart549e55c2007-08-02 11:09:51 -0400911 vports = lpfc_create_vport_work_array(phba);
912 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -0400913 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400914 /* Issue a LINK DOWN event to all nodes */
915 lpfc_linkdown_port(vports[i]);
916 }
James Smart09372822008-01-11 01:52:54 -0500917 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500918 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500919 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
920 if (mb) {
James Smart6d368e52011-05-24 11:44:12 -0400921 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
James Smarted957682007-06-17 19:56:37 -0500922 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500923 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400924 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500925 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500926 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500927 }
928 }
929
dea31012005-04-17 16:05:31 -0500930 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500931 if (phba->pport->fc_flag & FC_PT2PT) {
932 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500933 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
934 if (mb) {
dea31012005-04-17 16:05:31 -0500935 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500936 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500937 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400938 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500939 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500940 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500941 }
942 }
James Smart2e0fef82007-06-17 19:56:36 -0500943 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500944 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500945 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500946 }
James Smart2e0fef82007-06-17 19:56:36 -0500947
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500948 return 0;
dea31012005-04-17 16:05:31 -0500949}
950
James Smart92d7f7b2007-06-17 19:56:38 -0500951static void
952lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500953{
James Smart92d7f7b2007-06-17 19:56:38 -0500954 struct lpfc_nodelist *ndlp;
955
956 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500957 if (!NLP_CHK_NODE_ACT(ndlp))
958 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500959 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
960 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500961 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500962 /* On Linkup its safe to clean up the ndlp
963 * from Fabric connections.
964 */
James Smart92d7f7b2007-06-17 19:56:38 -0500965 if (ndlp->nlp_DID != Fabric_DID)
966 lpfc_unreg_rpi(vport, ndlp);
967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
968 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500969 /* Fail outstanding IO now since device is
970 * marked for PLOGI.
971 */
James Smart92d7f7b2007-06-17 19:56:38 -0500972 lpfc_unreg_rpi(vport, ndlp);
973 }
974 }
975}
976
977static void
978lpfc_linkup_port(struct lpfc_vport *vport)
979{
980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500981 struct lpfc_hba *phba = vport->phba;
982
983 if ((vport->load_flag & FC_UNLOADING) != 0)
984 return;
985
James Smart858c9f62007-06-17 19:56:39 -0500986 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
987 "Link Up: top:x%x speed:x%x flg:x%x",
988 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
989
James Smart92d7f7b2007-06-17 19:56:38 -0500990 /* If NPIV is not enabled, only bring the physical port up */
991 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
992 (vport != phba->pport))
993 return;
dea31012005-04-17 16:05:31 -0500994
James Smart2e0fef82007-06-17 19:56:36 -0500995 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400996
James Smart2e0fef82007-06-17 19:56:36 -0500997 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500998 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
999 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1000 vport->fc_flag |= FC_NDISC_ACTIVE;
1001 vport->fc_ns_retry = 0;
1002 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001003
James Smart92d7f7b2007-06-17 19:56:38 -05001004 if (vport->fc_flag & FC_LBIT)
1005 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -05001006
James Smart92d7f7b2007-06-17 19:56:38 -05001007}
1008
1009static int
1010lpfc_linkup(struct lpfc_hba *phba)
1011{
James Smart549e55c2007-08-02 11:09:51 -04001012 struct lpfc_vport **vports;
1013 int i;
James Smart92d7f7b2007-06-17 19:56:38 -05001014
1015 phba->link_state = LPFC_LINK_UP;
1016
1017 /* Unblock fabric iocbs if they are blocked */
1018 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1019 del_timer_sync(&phba->fabric_block_timer);
1020
James Smart549e55c2007-08-02 11:09:51 -04001021 vports = lpfc_create_vport_work_array(phba);
1022 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -04001023 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -04001024 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -05001025 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -05001026
1027 return 0;
1028}
1029
1030/*
1031 * This routine handles processing a CLEAR_LA mailbox
1032 * command upon completion. It is setup in the LPFC_MBOXQ
1033 * as the completion routine when the command is
1034 * handed off to the SLI layer.
1035 */
Adrian Bunka6ababd2007-11-05 18:07:33 +01001036static void
James Smart2e0fef82007-06-17 19:56:36 -05001037lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001038{
James Smart2e0fef82007-06-17 19:56:36 -05001039 struct lpfc_vport *vport = pmb->vport;
1040 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1041 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -04001042 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001043 uint32_t control;
1044
dea31012005-04-17 16:05:31 -05001045 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -05001046 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001047 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1048 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1049
1050 /* Check for error */
1051 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001052 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001053 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1054 "0320 CLEAR_LA mbxStatus error x%x hba "
1055 "state x%x\n",
1056 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001057 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001058 goto out;
1059 }
1060
James Smart92d7f7b2007-06-17 19:56:38 -05001061 if (vport->port_type == LPFC_PHYSICAL_PORT)
1062 phba->link_state = LPFC_HBA_READY;
1063
1064 spin_lock_irq(&phba->hbalock);
1065 psli->sli_flag |= LPFC_PROCESS_LA;
1066 control = readl(phba->HCregaddr);
1067 control |= HC_LAINT_ENA;
1068 writel(control, phba->HCregaddr);
1069 readl(phba->HCregaddr); /* flush */
1070 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001071 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001072 return;
dea31012005-04-17 16:05:31 -05001073
dea31012005-04-17 16:05:31 -05001074out:
1075 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001076 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1077 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001078 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001079
James Smart2e0fef82007-06-17 19:56:36 -05001080 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001081 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001082 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001083
James Smart2e0fef82007-06-17 19:56:36 -05001084 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001085
1086 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001087
1088 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001089 psli->sli_flag |= LPFC_PROCESS_LA;
1090 control = readl(phba->HCregaddr);
1091 control |= HC_LAINT_ENA;
1092 writel(control, phba->HCregaddr);
1093 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001094 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001095
1096 return;
1097}
1098
James Smart2e0fef82007-06-17 19:56:36 -05001099
dea31012005-04-17 16:05:31 -05001100static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001101lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001102{
James Smart2e0fef82007-06-17 19:56:36 -05001103 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001104
James Smart04c68492009-05-22 14:52:52 -04001105 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001106 goto out;
dea31012005-04-17 16:05:31 -05001107
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001108 mempool_free(pmb, phba->mbox_mem_pool);
1109
James Smart1b511972011-12-13 13:23:09 -05001110 /* don't perform discovery for SLI4 loopback diagnostic test */
1111 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1112 !(phba->hba_flag & HBA_FCOE_MODE) &&
1113 (phba->link_flag & LS_LOOPBACK_MODE))
1114 return;
1115
James Smart76a95d72010-11-20 23:11:48 -05001116 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001117 vport->fc_flag & FC_PUBLIC_LOOP &&
1118 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001119 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001120 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001121 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1122 */
James Smart2e0fef82007-06-17 19:56:36 -05001123 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001124 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001125 }
dea31012005-04-17 16:05:31 -05001126
James Smart2e0fef82007-06-17 19:56:36 -05001127 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001128 * LPFC_FLOGI while waiting for FLOGI cmpl
1129 */
James Smarte6446432012-05-09 21:16:42 -04001130 if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI)
James Smart92d7f7b2007-06-17 19:56:38 -05001131 lpfc_initial_flogi(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001132 return;
dea31012005-04-17 16:05:31 -05001133
1134out:
James Smarte8b62012007-08-02 11:10:09 -04001135 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1136 "0306 CONFIG_LINK mbxStatus error x%x "
1137 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001138 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001139 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001140
1141 lpfc_linkdown(phba);
1142
James Smarte8b62012007-08-02 11:10:09 -04001143 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1144 "0200 CONFIG_LINK bad hba state x%x\n",
1145 vport->port_state);
dea31012005-04-17 16:05:31 -05001146
James Smart92d7f7b2007-06-17 19:56:38 -05001147 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001148 return;
1149}
1150
James Smart7d791df2011-07-22 18:37:52 -04001151/**
1152 * lpfc_sli4_clear_fcf_rr_bmask
1153 * @phba pointer to the struct lpfc_hba for this port.
1154 * This fucnction resets the round robin bit mask and clears the
1155 * fcf priority list. The list deletions are done while holding the
1156 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1157 * from the lpfc_fcf_pri record.
1158 **/
1159void
1160lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1161{
1162 struct lpfc_fcf_pri *fcf_pri;
1163 struct lpfc_fcf_pri *next_fcf_pri;
1164 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1165 spin_lock_irq(&phba->hbalock);
1166 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1167 &phba->fcf.fcf_pri_list, list) {
1168 list_del_init(&fcf_pri->list);
1169 fcf_pri->fcf_rec.flag = 0;
1170 }
1171 spin_unlock_irq(&phba->hbalock);
1172}
dea31012005-04-17 16:05:31 -05001173static void
James Smart6fb120a2009-05-22 14:52:59 -04001174lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1175{
1176 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001177
1178 if (mboxq->u.mb.mbxStatus) {
1179 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1180 "2017 REG_FCFI mbxStatus error x%x "
1181 "HBA state x%x\n",
1182 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001183 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001184 }
1185
1186 /* Start FCoE discovery by sending a FLOGI. */
1187 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1188 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001189 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001190 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001191 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001192
James Smart32b97932009-07-19 10:01:21 -04001193 /* If there is a pending FCoE event, restart FCF table scan. */
James Smart7d791df2011-07-22 18:37:52 -04001194 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1195 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
James Smarta93ff372010-10-22 11:06:08 -04001196 goto fail_out;
1197
1198 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001199 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001200 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001201 phba->hba_flag &= ~FCF_TS_INPROG;
1202 if (vport->port_state != LPFC_FLOGI) {
1203 phba->hba_flag |= FCF_RR_INPROG;
1204 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001205 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001206 goto out;
1207 }
1208 spin_unlock_irq(&phba->hbalock);
1209 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001210
James Smarta93ff372010-10-22 11:06:08 -04001211fail_out:
1212 spin_lock_irq(&phba->hbalock);
1213 phba->hba_flag &= ~FCF_RR_INPROG;
1214 spin_unlock_irq(&phba->hbalock);
1215out:
James Smart6fb120a2009-05-22 14:52:59 -04001216 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001217}
1218
1219/**
1220 * lpfc_fab_name_match - Check if the fcf fabric name match.
1221 * @fab_name: pointer to fabric name.
1222 * @new_fcf_record: pointer to fcf record.
1223 *
1224 * This routine compare the fcf record's fabric name with provided
1225 * fabric name. If the fabric name are identical this function
1226 * returns 1 else return 0.
1227 **/
1228static uint32_t
1229lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1230{
James Smartecfd03c2010-02-12 14:41:27 -05001231 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001232 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001233 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1234 return 0;
1235 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1236 return 0;
1237 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1238 return 0;
1239 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1240 return 0;
1241 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1242 return 0;
1243 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1244 return 0;
1245 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1246 return 0;
1247 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001248}
1249
1250/**
James Smart8fa38512009-07-19 10:01:03 -04001251 * lpfc_sw_name_match - Check if the fcf switch name match.
1252 * @fab_name: pointer to fabric name.
1253 * @new_fcf_record: pointer to fcf record.
1254 *
1255 * This routine compare the fcf record's switch name with provided
1256 * switch name. If the switch name are identical this function
1257 * returns 1 else return 0.
1258 **/
1259static uint32_t
1260lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1261{
James Smartecfd03c2010-02-12 14:41:27 -05001262 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001263 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001264 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1265 return 0;
1266 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1267 return 0;
1268 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1269 return 0;
1270 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1271 return 0;
1272 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1273 return 0;
1274 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1275 return 0;
1276 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1277 return 0;
1278 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001279}
1280
1281/**
James Smart6fb120a2009-05-22 14:52:59 -04001282 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001283 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001284 * @new_fcf_record: pointer to fcf record.
1285 *
1286 * This routine compare the fcf record's mac address with HBA's
1287 * FCF mac address. If the mac addresses are identical this function
1288 * returns 1 else return 0.
1289 **/
1290static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001291lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001292{
James Smartecfd03c2010-02-12 14:41:27 -05001293 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001294 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001295 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1296 return 0;
1297 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1298 return 0;
1299 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1300 return 0;
1301 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1302 return 0;
1303 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1304 return 0;
1305 return 1;
1306}
1307
1308static bool
1309lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1310{
1311 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001312}
1313
1314/**
James Smart7d791df2011-07-22 18:37:52 -04001315 * lpfc_update_fcf_record - Update driver fcf record
1316 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1317 * @phba: pointer to lpfc hba data structure.
1318 * @fcf_index: Index for the lpfc_fcf_record.
1319 * @new_fcf_record: pointer to hba fcf record.
1320 *
1321 * This routine updates the driver FCF priority record from the new HBA FCF
1322 * record. This routine is called with the host lock held.
1323 **/
1324static void
1325__lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1326 struct fcf_record *new_fcf_record
1327 )
1328{
1329 struct lpfc_fcf_pri *fcf_pri;
1330
1331 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1332 fcf_pri->fcf_rec.fcf_index = fcf_index;
1333 /* FCF record priority */
1334 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1335
1336}
1337
1338/**
James Smart6fb120a2009-05-22 14:52:59 -04001339 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001340 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001341 * @new_fcf_record: pointer to fcf record.
1342 *
1343 * This routine copies the FCF information from the FCF
1344 * record to lpfc_hba data structure.
1345 **/
1346static void
James Smartecfd03c2010-02-12 14:41:27 -05001347lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1348 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001349{
James Smartecfd03c2010-02-12 14:41:27 -05001350 /* Fabric name */
1351 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001352 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001353 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001354 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001355 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001356 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001357 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001358 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001359 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001360 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001361 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001362 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001363 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001364 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001365 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001366 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001367 /* Mac address */
1368 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1369 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1370 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1371 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1372 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1373 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1374 /* FCF record index */
1375 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1376 /* FCF record priority */
1377 fcf_rec->priority = new_fcf_record->fip_priority;
1378 /* Switch name */
1379 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001380 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001381 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001382 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001383 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001384 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001385 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001386 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001387 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001388 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001389 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001390 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001391 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001392 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001393 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001394 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001395}
1396
1397/**
James Smartecfd03c2010-02-12 14:41:27 -05001398 * lpfc_update_fcf_record - Update driver fcf record
1399 * @phba: pointer to lpfc hba data structure.
1400 * @fcf_rec: pointer to driver fcf record.
1401 * @new_fcf_record: pointer to hba fcf record.
1402 * @addr_mode: address mode to be set to the driver fcf record.
1403 * @vlan_id: vlan tag to be set to the driver fcf record.
1404 * @flag: flag bits to be set to the driver fcf record.
1405 *
1406 * This routine updates the driver FCF record from the new HBA FCF record
1407 * together with the address mode, vlan_id, and other informations. This
1408 * routine is called with the host lock held.
1409 **/
1410static void
1411__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1412 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1413 uint16_t vlan_id, uint32_t flag)
1414{
1415 /* Copy the fields from the HBA's FCF record */
1416 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1417 /* Update other fields of driver FCF record */
1418 fcf_rec->addr_mode = addr_mode;
1419 fcf_rec->vlan_id = vlan_id;
1420 fcf_rec->flag |= (flag | RECORD_VALID);
James Smart7d791df2011-07-22 18:37:52 -04001421 __lpfc_update_fcf_record_pri(phba,
1422 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1423 new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001424}
1425
1426/**
James Smart6fb120a2009-05-22 14:52:59 -04001427 * lpfc_register_fcf - Register the FCF with hba.
1428 * @phba: pointer to lpfc hba data structure.
1429 *
1430 * This routine issues a register fcfi mailbox command to register
1431 * the fcf with HBA.
1432 **/
1433static void
1434lpfc_register_fcf(struct lpfc_hba *phba)
1435{
1436 LPFC_MBOXQ_t *fcf_mbxq;
1437 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001438
James Smartd439d282010-09-29 11:18:45 -04001439 spin_lock_irq(&phba->hbalock);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001440 /* If the FCF is not available do nothing. */
James Smart6fb120a2009-05-22 14:52:59 -04001441 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001442 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001443 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001444 return;
1445 }
1446
1447 /* The FCF is already registered, start discovery */
1448 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001449 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001450 phba->hba_flag &= ~FCF_TS_INPROG;
James Smarte74c03c2013-04-17 20:15:19 -04001451 if (phba->pport->port_state != LPFC_FLOGI &&
1452 phba->pport->fc_flag & FC_FABRIC) {
James Smarta93ff372010-10-22 11:06:08 -04001453 phba->hba_flag |= FCF_RR_INPROG;
1454 spin_unlock_irq(&phba->hbalock);
James Smartbf086112011-08-21 21:48:13 -04001455 lpfc_initial_flogi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001456 return;
1457 }
1458 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001459 return;
1460 }
James Smartd439d282010-09-29 11:18:45 -04001461 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001462
James Smarta93ff372010-10-22 11:06:08 -04001463 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001464 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001465 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001466 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001467 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001468 return;
James Smart4d9ab992009-10-02 15:16:39 -04001469 }
James Smart6fb120a2009-05-22 14:52:59 -04001470
1471 lpfc_reg_fcfi(phba, fcf_mbxq);
1472 fcf_mbxq->vport = phba->pport;
1473 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1474 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001475 if (rc == MBX_NOT_FINISHED) {
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 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001480 }
James Smart6fb120a2009-05-22 14:52:59 -04001481
1482 return;
1483}
1484
1485/**
1486 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1487 * @phba: pointer to lpfc hba data structure.
1488 * @new_fcf_record: pointer to fcf record.
1489 * @boot_flag: Indicates if this record used by boot bios.
1490 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001491 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001492 *
1493 * This routine compare the fcf record with connect list obtained from the
1494 * config region to decide if this FCF can be used for SAN discovery. It returns
1495 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1496 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1497 * is used by boot bios and addr_mode will indicate the addressing mode to be
1498 * used for this FCF when the function returns.
1499 * If the FCF record need to be used with a particular vlan id, the vlan is
1500 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001501 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001502 **/
1503static int
1504lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1505 struct fcf_record *new_fcf_record,
1506 uint32_t *boot_flag, uint32_t *addr_mode,
1507 uint16_t *vlan_id)
1508{
1509 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001510 int i, j, fcf_vlan_id = 0;
1511
1512 /* Find the lowest VLAN id in the FCF record */
1513 for (i = 0; i < 512; i++) {
1514 if (new_fcf_record->vlan_bitmap[i]) {
1515 fcf_vlan_id = i * 8;
1516 j = 0;
1517 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1518 j++;
1519 fcf_vlan_id++;
1520 }
1521 break;
1522 }
1523 }
James Smart6fb120a2009-05-22 14:52:59 -04001524
James Smart26979ce2012-09-29 11:31:55 -04001525 /* FCF not valid/available or solicitation in progress */
James Smart0c287582009-06-10 17:22:56 -04001526 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
James Smart26979ce2012-09-29 11:31:55 -04001527 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1528 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
James Smart0c287582009-06-10 17:22:56 -04001529 return 0;
1530
James Smart45ed1192009-10-02 15:17:02 -04001531 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001532 *boot_flag = 0;
1533 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1534 new_fcf_record);
1535 if (phba->valid_vlan)
1536 *vlan_id = phba->vlan_id;
1537 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001538 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001539 return 1;
1540 }
1541
1542 /*
1543 * If there are no FCF connection table entry, driver connect to all
1544 * FCFs.
1545 */
1546 if (list_empty(&phba->fcf_conn_rec_list)) {
1547 *boot_flag = 0;
1548 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1549 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001550
1551 /*
1552 * When there are no FCF connect entries, use driver's default
1553 * addressing mode - FPMA.
1554 */
1555 if (*addr_mode & LPFC_FCF_FPMA)
1556 *addr_mode = LPFC_FCF_FPMA;
1557
James Smart4d9ab992009-10-02 15:16:39 -04001558 /* If FCF record report a vlan id use that vlan id */
1559 if (fcf_vlan_id)
1560 *vlan_id = fcf_vlan_id;
1561 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001562 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001563 return 1;
1564 }
1565
James Smartecfd03c2010-02-12 14:41:27 -05001566 list_for_each_entry(conn_entry,
1567 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001568 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1569 continue;
1570
1571 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1572 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001573 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001574 continue;
James Smart8fa38512009-07-19 10:01:03 -04001575 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1576 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1577 new_fcf_record))
1578 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001579 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1580 /*
1581 * If the vlan bit map does not have the bit set for the
1582 * vlan id to be used, then it is not a match.
1583 */
1584 if (!(new_fcf_record->vlan_bitmap
1585 [conn_entry->conn_rec.vlan_tag / 8] &
1586 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1587 continue;
1588 }
1589
1590 /*
James Smart0c287582009-06-10 17:22:56 -04001591 * If connection record does not support any addressing mode,
1592 * skip the FCF record.
1593 */
1594 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1595 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1596 continue;
1597
1598 /*
James Smart6fb120a2009-05-22 14:52:59 -04001599 * Check if the connection record specifies a required
1600 * addressing mode.
1601 */
1602 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1603 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1604
1605 /*
1606 * If SPMA required but FCF not support this continue.
1607 */
1608 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1609 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1610 new_fcf_record) & LPFC_FCF_SPMA))
1611 continue;
1612
1613 /*
1614 * If FPMA required but FCF not support this continue.
1615 */
1616 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1617 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1618 new_fcf_record) & LPFC_FCF_FPMA))
1619 continue;
1620 }
1621
1622 /*
1623 * This fcf record matches filtering criteria.
1624 */
1625 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1626 *boot_flag = 1;
1627 else
1628 *boot_flag = 0;
1629
James Smart0c287582009-06-10 17:22:56 -04001630 /*
1631 * If user did not specify any addressing mode, or if the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001632 * preferred addressing mode specified by user is not supported
James Smart0c287582009-06-10 17:22:56 -04001633 * by FCF, allow fabric to pick the addressing mode.
1634 */
James Smart6fb120a2009-05-22 14:52:59 -04001635 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1636 new_fcf_record);
1637 /*
1638 * If the user specified a required address mode, assign that
1639 * address mode
1640 */
1641 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1642 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1643 *addr_mode = (conn_entry->conn_rec.flags &
1644 FCFCNCT_AM_SPMA) ?
1645 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1646 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001647 * If the user specified a preferred address mode, use the
James Smart6fb120a2009-05-22 14:52:59 -04001648 * addr mode only if FCF support the addr_mode.
1649 */
1650 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1651 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1652 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1653 (*addr_mode & LPFC_FCF_SPMA))
1654 *addr_mode = LPFC_FCF_SPMA;
1655 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1656 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1657 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1658 (*addr_mode & LPFC_FCF_FPMA))
1659 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001660
James Smart4d9ab992009-10-02 15:16:39 -04001661 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001662 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1663 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001664 /*
1665 * If no vlan id is specified in connect list, use the vlan id
1666 * in the FCF record
1667 */
1668 else if (fcf_vlan_id)
1669 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001670 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001671 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001672
1673 return 1;
1674 }
1675
1676 return 0;
1677}
1678
1679/**
James Smart32b97932009-07-19 10:01:21 -04001680 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1681 * @phba: pointer to lpfc hba data structure.
1682 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1683 *
1684 * This function check if there is any fcoe event pending while driver
1685 * scan FCF entries. If there is any pending event, it will restart the
1686 * FCF saning and return 1 else return 0.
1687 */
1688int
1689lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1690{
James Smart32b97932009-07-19 10:01:21 -04001691 /*
1692 * If the Link is up and no FCoE events while in the
1693 * FCF discovery, no need to restart FCF discovery.
1694 */
1695 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001696 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001697 return 0;
1698
James Smart0c9ab6f2010-02-26 14:15:57 -05001699 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1700 "2768 Pending link or FCF event during current "
1701 "handling of the previous event: link_state:x%x, "
1702 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1703 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1704 phba->fcoe_eventtag);
1705
James Smart32b97932009-07-19 10:01:21 -04001706 spin_lock_irq(&phba->hbalock);
1707 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1708 spin_unlock_irq(&phba->hbalock);
1709
James Smart0c9ab6f2010-02-26 14:15:57 -05001710 if (phba->link_state >= LPFC_LINK_UP) {
1711 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1712 "2780 Restart FCF table scan due to "
1713 "pending FCF event:evt_tag_at_scan:x%x, "
1714 "evt_tag_current:x%x\n",
1715 phba->fcoe_eventtag_at_fcf_scan,
1716 phba->fcoe_eventtag);
1717 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1718 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001719 /*
James Smarta93ff372010-10-22 11:06:08 -04001720 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001721 * flag
1722 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001723 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1724 "2833 Stop FCF discovery process due to link "
1725 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001726 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001727 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001728 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001729 spin_unlock_irq(&phba->hbalock);
1730 }
James Smart32b97932009-07-19 10:01:21 -04001731
James Smart0c9ab6f2010-02-26 14:15:57 -05001732 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001733 if (unreg_fcf) {
1734 spin_lock_irq(&phba->hbalock);
1735 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1736 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001737 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001738 }
James Smart32b97932009-07-19 10:01:21 -04001739 return 1;
1740}
1741
1742/**
James Smart999d8132010-03-15 11:24:56 -04001743 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1744 * @phba: pointer to lpfc hba data structure.
1745 * @fcf_cnt: number of eligible fcf record seen so far.
1746 *
1747 * This function makes an running random selection decision on FCF record to
1748 * use through a sequence of @fcf_cnt eligible FCF records with equal
1749 * probability. To perform integer manunipulation of random numbers with
1750 * size unit32_t, the lower 16 bits of the 32-bit random number returned
Akinobu Mita3b60a642013-04-29 16:21:35 -07001751 * from prandom_u32() are taken as the random random number generated.
James Smart999d8132010-03-15 11:24:56 -04001752 *
1753 * Returns true when outcome is for the newly read FCF record should be
1754 * chosen; otherwise, return false when outcome is for keeping the previously
1755 * chosen FCF record.
1756 **/
1757static bool
1758lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1759{
1760 uint32_t rand_num;
1761
1762 /* Get 16-bit uniform random number */
Akinobu Mita3b60a642013-04-29 16:21:35 -07001763 rand_num = 0xFFFF & prandom_u32();
James Smart999d8132010-03-15 11:24:56 -04001764
1765 /* Decision with probability 1/fcf_cnt */
1766 if ((fcf_cnt * rand_num) < 0xFFFF)
1767 return true;
1768 else
1769 return false;
1770}
1771
1772/**
James Smart3804dc82010-07-14 15:31:37 -04001773 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001774 * @phba: pointer to lpfc hba data structure.
1775 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001776 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001777 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001778 * This routine parses the non-embedded fcf mailbox command by performing the
1779 * necessarily error checking, non-embedded read FCF record mailbox command
1780 * SGE parsing, and endianness swapping.
1781 *
1782 * Returns the pointer to the new FCF record in the non-embedded mailbox
1783 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001784 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001785static struct fcf_record *
1786lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1787 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001788{
1789 void *virt_addr;
1790 dma_addr_t phys_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001791 struct lpfc_mbx_sge sge;
1792 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1793 uint32_t shdr_status, shdr_add_status;
1794 union lpfc_sli4_cfg_shdr *shdr;
1795 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001796
James Smart6fb120a2009-05-22 14:52:59 -04001797 /* Get the first SGE entry from the non-embedded DMA memory. This
1798 * routine only uses a single SGE.
1799 */
1800 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1801 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1802 if (unlikely(!mboxq->sge_array)) {
1803 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1804 "2524 Failed to get the non-embedded SGE "
1805 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001806 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001807 }
1808 virt_addr = mboxq->sge_array->addr[0];
1809
1810 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
James Smart25626692013-03-01 16:36:54 -05001811 lpfc_sli_pcimem_bcopy(shdr, shdr,
1812 sizeof(union lpfc_sli4_cfg_shdr));
James Smart6fb120a2009-05-22 14:52:59 -04001813 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smart0c9ab6f2010-02-26 14:15:57 -05001814 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001815 if (shdr_status || shdr_add_status) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001816 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1817 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001818 "2726 READ_FCF_RECORD Indicates empty "
1819 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001820 else
1821 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001822 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001823 "with status x%x add_status x%x, "
1824 "mbx\n", shdr_status, shdr_add_status);
1825 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001826 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001827
1828 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001829 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1830 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1831 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001832 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001833 new_fcf_record = (struct fcf_record *)(virt_addr +
1834 sizeof(struct lpfc_mbx_read_fcf_tbl));
1835 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001836 offsetof(struct fcf_record, vlan_bitmap));
1837 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1838 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001839
James Smart0c9ab6f2010-02-26 14:15:57 -05001840 return new_fcf_record;
1841}
1842
1843/**
1844 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1845 * @phba: pointer to lpfc hba data structure.
1846 * @fcf_record: pointer to the fcf record.
1847 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1848 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1849 *
1850 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1851 * enabled.
1852 **/
1853static void
1854lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1855 struct fcf_record *fcf_record,
1856 uint16_t vlan_id,
1857 uint16_t next_fcf_index)
1858{
1859 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1860 "2764 READ_FCF_RECORD:\n"
1861 "\tFCF_Index : x%x\n"
1862 "\tFCF_Avail : x%x\n"
1863 "\tFCF_Valid : x%x\n"
James Smart26979ce2012-09-29 11:31:55 -04001864 "\tFCF_SOL : x%x\n"
James Smart0c9ab6f2010-02-26 14:15:57 -05001865 "\tFIP_Priority : x%x\n"
1866 "\tMAC_Provider : x%x\n"
1867 "\tLowest VLANID : x%x\n"
1868 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1869 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1870 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1871 "\tNext_FCF_Index: x%x\n",
1872 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1873 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1874 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
James Smart26979ce2012-09-29 11:31:55 -04001875 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
James Smart0c9ab6f2010-02-26 14:15:57 -05001876 fcf_record->fip_priority,
1877 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1878 vlan_id,
1879 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1880 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1881 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1882 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1883 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1884 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1885 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1886 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1887 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1888 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1889 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1890 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1891 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1892 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1893 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1894 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1895 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1896 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1897 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1898 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1899 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1900 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1901 next_fcf_index);
1902}
1903
1904/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001905 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1906 * @phba: pointer to lpfc hba data structure.
1907 * @fcf_rec: pointer to an existing FCF record.
1908 * @new_fcf_record: pointer to a new FCF record.
1909 * @new_vlan_id: vlan id from the new FCF record.
1910 *
1911 * This function performs matching test of a new FCF record against an existing
1912 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1913 * will not be used as part of the FCF record matching criteria.
1914 *
1915 * Returns true if all the fields matching, otherwise returns false.
1916 */
1917static bool
1918lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1919 struct lpfc_fcf_rec *fcf_rec,
1920 struct fcf_record *new_fcf_record,
1921 uint16_t new_vlan_id)
1922{
1923 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1924 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1925 return false;
1926 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1927 return false;
1928 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1929 return false;
1930 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1931 return false;
James Smart7d791df2011-07-22 18:37:52 -04001932 if (fcf_rec->priority != new_fcf_record->fip_priority)
1933 return false;
James Smartdbb6b3a2010-06-08 18:31:37 -04001934 return true;
1935}
1936
1937/**
James Smarta93ff372010-10-22 11:06:08 -04001938 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1939 * @vport: Pointer to vport object.
1940 * @fcf_index: index to next fcf.
1941 *
1942 * This function processing the roundrobin fcf failover to next fcf index.
1943 * When this function is invoked, there will be a current fcf registered
1944 * for flogi.
1945 * Return: 0 for continue retrying flogi on currently registered fcf;
1946 * 1 for stop flogi on currently registered fcf;
1947 */
1948int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1949{
1950 struct lpfc_hba *phba = vport->phba;
1951 int rc;
1952
1953 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1954 spin_lock_irq(&phba->hbalock);
1955 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1956 spin_unlock_irq(&phba->hbalock);
1957 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1958 "2872 Devloss tmo with no eligible "
1959 "FCF, unregister in-use FCF (x%x) "
1960 "and rescan FCF table\n",
1961 phba->fcf.current_rec.fcf_indx);
1962 lpfc_unregister_fcf_rescan(phba);
1963 goto stop_flogi_current_fcf;
1964 }
1965 /* Mark the end to FLOGI roundrobin failover */
1966 phba->hba_flag &= ~FCF_RR_INPROG;
1967 /* Allow action to new fcf asynchronous event */
1968 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1969 spin_unlock_irq(&phba->hbalock);
1970 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1971 "2865 No FCF available, stop roundrobin FCF "
1972 "failover and change port state:x%x/x%x\n",
1973 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1974 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1975 goto stop_flogi_current_fcf;
1976 } else {
1977 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1978 "2794 Try FLOGI roundrobin FCF failover to "
1979 "(x%x)\n", fcf_index);
1980 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1981 if (rc)
1982 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1983 "2761 FLOGI roundrobin FCF failover "
1984 "failed (rc:x%x) to read FCF (x%x)\n",
1985 rc, phba->fcf.current_rec.fcf_indx);
1986 else
1987 goto stop_flogi_current_fcf;
1988 }
1989 return 0;
1990
1991stop_flogi_current_fcf:
1992 lpfc_can_disctmo(vport);
1993 return 1;
1994}
1995
1996/**
James Smart7d791df2011-07-22 18:37:52 -04001997 * lpfc_sli4_fcf_pri_list_del
1998 * @phba: pointer to lpfc hba data structure.
1999 * @fcf_index the index of the fcf record to delete
2000 * This routine checks the on list flag of the fcf_index to be deleted.
2001 * If it is one the list then it is removed from the list, and the flag
2002 * is cleared. This routine grab the hbalock before removing the fcf
2003 * record from the list.
2004 **/
2005static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2006 uint16_t fcf_index)
2007{
2008 struct lpfc_fcf_pri *new_fcf_pri;
2009
2010 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2011 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2012 "3058 deleting idx x%x pri x%x flg x%x\n",
2013 fcf_index, new_fcf_pri->fcf_rec.priority,
2014 new_fcf_pri->fcf_rec.flag);
2015 spin_lock_irq(&phba->hbalock);
2016 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2017 if (phba->fcf.current_rec.priority ==
2018 new_fcf_pri->fcf_rec.priority)
2019 phba->fcf.eligible_fcf_cnt--;
2020 list_del_init(&new_fcf_pri->list);
2021 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2022 }
2023 spin_unlock_irq(&phba->hbalock);
2024}
2025
2026/**
2027 * lpfc_sli4_set_fcf_flogi_fail
2028 * @phba: pointer to lpfc hba data structure.
2029 * @fcf_index the index of the fcf record to update
2030 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2031 * flag so the the round robin slection for the particular priority level
2032 * will try a different fcf record that does not have this bit set.
2033 * If the fcf record is re-read for any reason this flag is cleared brfore
2034 * adding it to the priority list.
2035 **/
2036void
2037lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2038{
2039 struct lpfc_fcf_pri *new_fcf_pri;
2040 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2041 spin_lock_irq(&phba->hbalock);
2042 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2043 spin_unlock_irq(&phba->hbalock);
2044}
2045
2046/**
2047 * lpfc_sli4_fcf_pri_list_add
2048 * @phba: pointer to lpfc hba data structure.
2049 * @fcf_index the index of the fcf record to add
2050 * This routine checks the priority of the fcf_index to be added.
2051 * If it is a lower priority than the current head of the fcf_pri list
2052 * then it is added to the list in the right order.
2053 * If it is the same priority as the current head of the list then it
2054 * is added to the head of the list and its bit in the rr_bmask is set.
2055 * If the fcf_index to be added is of a higher priority than the current
2056 * head of the list then the rr_bmask is cleared, its bit is set in the
2057 * rr_bmask and it is added to the head of the list.
2058 * returns:
2059 * 0=success 1=failure
2060 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04002061static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2062 uint16_t fcf_index,
James Smart7d791df2011-07-22 18:37:52 -04002063 struct fcf_record *new_fcf_record)
2064{
2065 uint16_t current_fcf_pri;
2066 uint16_t last_index;
2067 struct lpfc_fcf_pri *fcf_pri;
2068 struct lpfc_fcf_pri *next_fcf_pri;
2069 struct lpfc_fcf_pri *new_fcf_pri;
2070 int ret;
2071
2072 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2073 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2074 "3059 adding idx x%x pri x%x flg x%x\n",
2075 fcf_index, new_fcf_record->fip_priority,
2076 new_fcf_pri->fcf_rec.flag);
2077 spin_lock_irq(&phba->hbalock);
2078 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2079 list_del_init(&new_fcf_pri->list);
2080 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2081 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2082 if (list_empty(&phba->fcf.fcf_pri_list)) {
2083 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2084 ret = lpfc_sli4_fcf_rr_index_set(phba,
2085 new_fcf_pri->fcf_rec.fcf_index);
2086 goto out;
2087 }
2088
2089 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2090 LPFC_SLI4_FCF_TBL_INDX_MAX);
2091 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2092 ret = 0; /* Empty rr list */
2093 goto out;
2094 }
2095 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2096 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2097 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2098 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2099 memset(phba->fcf.fcf_rr_bmask, 0,
2100 sizeof(*phba->fcf.fcf_rr_bmask));
2101 /* fcfs_at_this_priority_level = 1; */
2102 phba->fcf.eligible_fcf_cnt = 1;
2103 } else
2104 /* fcfs_at_this_priority_level++; */
2105 phba->fcf.eligible_fcf_cnt++;
2106 ret = lpfc_sli4_fcf_rr_index_set(phba,
2107 new_fcf_pri->fcf_rec.fcf_index);
2108 goto out;
2109 }
2110
2111 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2112 &phba->fcf.fcf_pri_list, list) {
2113 if (new_fcf_pri->fcf_rec.priority <=
2114 fcf_pri->fcf_rec.priority) {
2115 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2116 list_add(&new_fcf_pri->list,
2117 &phba->fcf.fcf_pri_list);
2118 else
2119 list_add(&new_fcf_pri->list,
2120 &((struct lpfc_fcf_pri *)
2121 fcf_pri->list.prev)->list);
2122 ret = 0;
2123 goto out;
2124 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2125 || new_fcf_pri->fcf_rec.priority <
2126 next_fcf_pri->fcf_rec.priority) {
2127 list_add(&new_fcf_pri->list, &fcf_pri->list);
2128 ret = 0;
2129 goto out;
2130 }
2131 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2132 continue;
2133
2134 }
2135 ret = 1;
2136out:
2137 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2138 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2139 spin_unlock_irq(&phba->hbalock);
2140 return ret;
2141}
2142
2143/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002144 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2145 * @phba: pointer to lpfc hba data structure.
2146 * @mboxq: pointer to mailbox object.
2147 *
2148 * This function iterates through all the fcf records available in
2149 * HBA and chooses the optimal FCF record for discovery. After finding
2150 * the FCF for discovery it registers the FCF record and kicks start
2151 * discovery.
2152 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2153 * use an FCF record which matches fabric name and mac address of the
2154 * currently used FCF record.
2155 * If the driver supports only one FCF, it will try to use the FCF record
2156 * used by BOOT_BIOS.
2157 */
2158void
2159lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2160{
2161 struct fcf_record *new_fcf_record;
2162 uint32_t boot_flag, addr_mode;
2163 uint16_t fcf_index, next_fcf_index;
2164 struct lpfc_fcf_rec *fcf_rec = NULL;
2165 uint16_t vlan_id;
James Smart999d8132010-03-15 11:24:56 -04002166 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002167 int rc;
2168
2169 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04002170 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002171 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2172 return;
2173 }
2174
2175 /* Parse the FCF record from the non-embedded mailbox command */
2176 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2177 &next_fcf_index);
2178 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04002179 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05002180 "2765 Mailbox command READ_FCF_RECORD "
2181 "failed to retrieve a FCF record.\n");
2182 /* Let next new FCF event trigger fast failover */
2183 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002184 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002185 spin_unlock_irq(&phba->hbalock);
2186 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2187 return;
2188 }
2189
2190 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05002191 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2192 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002193
2194 /* Log the FCF record information if turned on */
2195 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2196 next_fcf_index);
2197
James Smart6fb120a2009-05-22 14:52:59 -04002198 /*
2199 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05002200 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04002201 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04002202 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002203 if (!rc) {
James Smart7d791df2011-07-22 18:37:52 -04002204 lpfc_sli4_fcf_pri_list_del(phba,
2205 bf_get(lpfc_fcf_record_fcf_index,
2206 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002207 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002208 "2781 FCF (x%x) failed connection "
James Smart26979ce2012-09-29 11:31:55 -04002209 "list check: (x%x/x%x/%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002210 bf_get(lpfc_fcf_record_fcf_index,
2211 new_fcf_record),
2212 bf_get(lpfc_fcf_record_fcf_avail,
2213 new_fcf_record),
2214 bf_get(lpfc_fcf_record_fcf_valid,
James Smart26979ce2012-09-29 11:31:55 -04002215 new_fcf_record),
2216 bf_get(lpfc_fcf_record_fcf_sol,
James Smart0c9ab6f2010-02-26 14:15:57 -05002217 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04002218 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2219 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2220 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04002221 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2222 phba->fcf.current_rec.fcf_indx) {
2223 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2224 "2862 FCF (x%x) matches property "
2225 "of in-use FCF (x%x)\n",
2226 bf_get(lpfc_fcf_record_fcf_index,
2227 new_fcf_record),
2228 phba->fcf.current_rec.fcf_indx);
2229 goto read_next_fcf;
2230 }
James Smartdbb6b3a2010-06-08 18:31:37 -04002231 /*
2232 * In case the current in-use FCF record becomes
2233 * invalid/unavailable during FCF discovery that
2234 * was not triggered by fast FCF failover process,
2235 * treat it as fast FCF failover.
2236 */
2237 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2238 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2239 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2240 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04002241 "(x%x), enter FCF failover "
2242 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002243 phba->fcf.current_rec.fcf_indx);
2244 spin_lock_irq(&phba->hbalock);
2245 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2246 spin_unlock_irq(&phba->hbalock);
2247 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2248 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2249 LPFC_FCOE_FCF_GET_FIRST);
2250 return;
2251 }
2252 }
James Smart6fb120a2009-05-22 14:52:59 -04002253 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05002254 } else {
2255 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002256 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2257 new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002258 if (rc)
2259 goto read_next_fcf;
2260 }
2261
James Smart6fb120a2009-05-22 14:52:59 -04002262 /*
2263 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002264 * FCF record for the discovery. The condition that a rescan
2265 * matches the in-use FCF record: fabric name, switch name, mac
2266 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002267 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002268 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002269 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smart7d791df2011-07-22 18:37:52 -04002270 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2271 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
James Smartdbb6b3a2010-06-08 18:31:37 -04002272 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002273 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2274 phba->fcf.current_rec.fcf_indx) {
2275 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2276 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2277 /* Stop FCF redisc wait timer */
2278 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2279 phba);
2280 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2281 /* Fast failover, mark completed */
2282 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2283 spin_unlock_irq(&phba->hbalock);
2284 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2285 "2836 New FCF matches in-use "
James Smart88f43a02013-04-17 20:19:44 -04002286 "FCF (x%x), port_state:x%x, "
2287 "fc_flag:x%x\n",
2288 phba->fcf.current_rec.fcf_indx,
2289 phba->pport->port_state,
2290 phba->pport->fc_flag);
James Smart5ac6b302010-10-22 11:05:36 -04002291 goto out;
2292 } else
2293 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2294 "2863 New FCF (x%x) matches "
2295 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002296 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002297 new_fcf_record),
2298 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002299 }
James Smartecfd03c2010-02-12 14:41:27 -05002300 /*
2301 * Read next FCF record from HBA searching for the matching
2302 * with in-use record only if not during the fast failover
2303 * period. In case of fast failover period, it shall try to
2304 * determine whether the FCF record just read should be the
2305 * next candidate.
2306 */
2307 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002308 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002309 goto read_next_fcf;
2310 }
James Smart6fb120a2009-05-22 14:52:59 -04002311 }
James Smartecfd03c2010-02-12 14:41:27 -05002312 /*
2313 * Update on failover FCF record only if it's in FCF fast-failover
2314 * period; otherwise, update on current FCF record.
2315 */
James Smartfc2b9892010-02-26 14:15:29 -05002316 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2317 fcf_rec = &phba->fcf.failover_rec;
2318 else
James Smartecfd03c2010-02-12 14:41:27 -05002319 fcf_rec = &phba->fcf.current_rec;
2320
James Smart6fb120a2009-05-22 14:52:59 -04002321 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2322 /*
James Smartecfd03c2010-02-12 14:41:27 -05002323 * If the driver FCF record does not have boot flag
2324 * set and new hba fcf record has boot flag set, use
2325 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002326 */
James Smartecfd03c2010-02-12 14:41:27 -05002327 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2328 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002329 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2330 "2837 Update current FCF record "
2331 "(x%x) with new FCF record (x%x)\n",
2332 fcf_rec->fcf_indx,
2333 bf_get(lpfc_fcf_record_fcf_index,
2334 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002335 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2336 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002337 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002338 goto read_next_fcf;
2339 }
2340 /*
James Smartecfd03c2010-02-12 14:41:27 -05002341 * If the driver FCF record has boot flag set and the
2342 * new hba FCF record does not have boot flag, read
2343 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002344 */
James Smartecfd03c2010-02-12 14:41:27 -05002345 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002346 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002347 goto read_next_fcf;
2348 }
2349 /*
James Smartecfd03c2010-02-12 14:41:27 -05002350 * If the new hba FCF record has lower priority value
2351 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002352 */
James Smartfc2b9892010-02-26 14:15:29 -05002353 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002354 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002355 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2356 "2838 Update current FCF record "
2357 "(x%x) with new FCF record (x%x)\n",
2358 fcf_rec->fcf_indx,
2359 bf_get(lpfc_fcf_record_fcf_index,
2360 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002361 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2362 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002363 /* Reset running random FCF selection count */
2364 phba->fcf.eligible_fcf_cnt = 1;
2365 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2366 /* Update running random FCF selection count */
2367 phba->fcf.eligible_fcf_cnt++;
2368 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2369 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002370 if (select_new_fcf) {
2371 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2372 "2839 Update current FCF record "
2373 "(x%x) with new FCF record (x%x)\n",
2374 fcf_rec->fcf_indx,
2375 bf_get(lpfc_fcf_record_fcf_index,
2376 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002377 /* Choose the new FCF by random selection */
2378 __lpfc_update_fcf_record(phba, fcf_rec,
2379 new_fcf_record,
2380 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002381 }
James Smart6fb120a2009-05-22 14:52:59 -04002382 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002383 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002384 goto read_next_fcf;
2385 }
2386 /*
James Smartecfd03c2010-02-12 14:41:27 -05002387 * This is the first suitable FCF record, choose this record for
2388 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002389 */
James Smartecfd03c2010-02-12 14:41:27 -05002390 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002391 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002392 "2840 Update initial FCF candidate "
2393 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002394 bf_get(lpfc_fcf_record_fcf_index,
2395 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002396 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2397 addr_mode, vlan_id, (boot_flag ?
2398 BOOT_ENABLE : 0));
2399 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002400 /* Setup initial running random FCF selection count */
2401 phba->fcf.eligible_fcf_cnt = 1;
James Smart6fb120a2009-05-22 14:52:59 -04002402 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002403 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002404 goto read_next_fcf;
2405
2406read_next_fcf:
2407 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002408 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2409 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2410 /*
2411 * Case of FCF fast failover scan
2412 */
2413
2414 /*
2415 * It has not found any suitable FCF record, cancel
2416 * FCF scan inprogress, and do nothing
2417 */
2418 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002419 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002420 "2782 No suitable FCF found: "
2421 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002422 phba->fcoe_eventtag_at_fcf_scan,
2423 bf_get(lpfc_fcf_record_fcf_index,
2424 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002425 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002426 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2427 phba->hba_flag &= ~FCF_TS_INPROG;
2428 spin_unlock_irq(&phba->hbalock);
2429 /* Unregister in-use FCF and rescan */
2430 lpfc_printf_log(phba, KERN_INFO,
2431 LOG_FIP,
2432 "2864 On devloss tmo "
2433 "unreg in-use FCF and "
2434 "rescan FCF table\n");
2435 lpfc_unregister_fcf_rescan(phba);
2436 return;
2437 }
2438 /*
2439 * Let next new FCF event trigger fast failover
2440 */
2441 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002442 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002443 return;
2444 }
2445 /*
2446 * It has found a suitable FCF record that is not
2447 * the same as in-use FCF record, unregister the
2448 * in-use FCF record, replace the in-use FCF record
2449 * with the new FCF record, mark FCF fast failover
2450 * completed, and then start register the new FCF
2451 * record.
2452 */
2453
James Smart0c9ab6f2010-02-26 14:15:57 -05002454 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002455 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002456
2457 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002458 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002459 "2842 Replace in-use FCF (x%x) "
2460 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002461 phba->fcf.current_rec.fcf_indx,
2462 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002463 memcpy(&phba->fcf.current_rec,
2464 &phba->fcf.failover_rec,
2465 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002466 /*
2467 * Mark the fast FCF failover rediscovery completed
2468 * and the start of the first round of the roundrobin
2469 * FCF failover.
2470 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002471 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002472 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002473 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002474 /* Register to the new FCF record */
2475 lpfc_register_fcf(phba);
2476 } else {
2477 /*
2478 * In case of transaction period to fast FCF failover,
2479 * do nothing when search to the end of the FCF table.
2480 */
2481 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2482 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2483 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002484
James Smart7d791df2011-07-22 18:37:52 -04002485 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2486 phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002487 /*
2488 * In case the current in-use FCF record no
2489 * longer existed during FCF discovery that
2490 * was not triggered by fast FCF failover
2491 * process, treat it as fast FCF failover.
2492 */
2493 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2494 "2841 In-use FCF record (x%x) "
2495 "not reported, entering fast "
2496 "FCF failover mode scanning.\n",
2497 phba->fcf.current_rec.fcf_indx);
2498 spin_lock_irq(&phba->hbalock);
2499 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2500 spin_unlock_irq(&phba->hbalock);
James Smartdbb6b3a2010-06-08 18:31:37 -04002501 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2502 LPFC_FCOE_FCF_GET_FIRST);
2503 return;
2504 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002505 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002506 lpfc_register_fcf(phba);
2507 }
2508 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002509 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002510 return;
2511
2512out:
2513 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2514 lpfc_register_fcf(phba);
2515
2516 return;
2517}
2518
2519/**
James Smarta93ff372010-10-22 11:06:08 -04002520 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002521 * @phba: pointer to lpfc hba data structure.
2522 * @mboxq: pointer to mailbox object.
2523 *
James Smarta93ff372010-10-22 11:06:08 -04002524 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002525 * read FCF record mailbox command from the eligible FCF record bmask for
2526 * performing the failover. If the FCF read back is not valid/available, it
2527 * fails through to retrying FLOGI to the currently registered FCF again.
2528 * Otherwise, if the FCF read back is valid and available, it will set the
2529 * newly read FCF record to the failover FCF record, unregister currently
2530 * registered FCF record, copy the failover FCF record to the current
2531 * FCF record, and then register the current FCF record before proceeding
2532 * to trying FLOGI on the new failover FCF.
2533 */
2534void
2535lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2536{
2537 struct fcf_record *new_fcf_record;
2538 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002539 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002540 uint16_t current_fcf_index;
2541 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002542 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002543
James Smarta93ff372010-10-22 11:06:08 -04002544 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002545 if (phba->link_state < LPFC_LINK_UP) {
2546 spin_lock_irq(&phba->hbalock);
2547 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002548 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002549 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002550 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002551 }
2552
2553 /* Parse the FCF record from the non-embedded mailbox command */
2554 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2555 &next_fcf_index);
2556 if (!new_fcf_record) {
2557 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2558 "2766 Mailbox command READ_FCF_RECORD "
James Smart646a2dd2013-12-17 20:29:22 -05002559 "failed to retrieve a FCF record. "
2560 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2561 phba->fcf.fcf_flag);
2562 lpfc_unregister_fcf_rescan(phba);
2563 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002564 }
2565
2566 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002567 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2568 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002569
2570 /* Log the FCF record information if turned on */
2571 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2572 next_fcf_index);
2573
James Smarta93ff372010-10-22 11:06:08 -04002574 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2575 if (!rc) {
2576 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2577 "2848 Remove ineligible FCF (x%x) from "
2578 "from roundrobin bmask\n", fcf_index);
2579 /* Clear roundrobin bmask bit for ineligible FCF */
2580 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2581 /* Perform next round of roundrobin FCF failover */
2582 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2583 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2584 if (rc)
2585 goto out;
2586 goto error_out;
2587 }
2588
2589 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2590 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2591 "2760 Perform FLOGI roundrobin FCF failover: "
2592 "FCF (x%x) back to FCF (x%x)\n",
2593 phba->fcf.current_rec.fcf_indx, fcf_index);
2594 /* Wait 500 ms before retrying FLOGI to current FCF */
2595 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002596 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002597 goto out;
2598 }
2599
James Smart0c9ab6f2010-02-26 14:15:57 -05002600 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002601 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002602 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2603 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002604 spin_lock_irq(&phba->hbalock);
2605 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2606 new_fcf_record, addr_mode, vlan_id,
2607 (boot_flag ? BOOT_ENABLE : 0));
2608 spin_unlock_irq(&phba->hbalock);
2609
2610 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2611
2612 /* Unregister the current in-use FCF record */
2613 lpfc_unregister_fcf(phba);
2614
2615 /* Replace in-use record with the new record */
2616 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2617 sizeof(struct lpfc_fcf_rec));
2618
2619 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002620 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2621 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002622
James Smarta93ff372010-10-22 11:06:08 -04002623error_out:
2624 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002625out:
2626 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002627}
2628
2629/**
2630 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2631 * @phba: pointer to lpfc hba data structure.
2632 * @mboxq: pointer to mailbox object.
2633 *
2634 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002635 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002636 * failover when a new FCF event happened. If the FCF read back is
2637 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002638 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002639 */
2640void
2641lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2642{
2643 struct fcf_record *new_fcf_record;
2644 uint32_t boot_flag, addr_mode;
2645 uint16_t fcf_index, next_fcf_index;
2646 uint16_t vlan_id;
2647 int rc;
2648
2649 /* If link state is not up, no need to proceed */
2650 if (phba->link_state < LPFC_LINK_UP)
2651 goto out;
2652
2653 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002654 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002655 goto out;
2656
2657 /* Parse the FCF record from the non-embedded mailbox command */
2658 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2659 &next_fcf_index);
2660 if (!new_fcf_record) {
2661 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2662 "2767 Mailbox command READ_FCF_RECORD "
2663 "failed to retrieve a FCF record.\n");
2664 goto out;
2665 }
2666
2667 /* Check the connection list for eligibility */
2668 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2669 &addr_mode, &vlan_id);
2670
2671 /* Log the FCF record information if turned on */
2672 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2673 next_fcf_index);
2674
2675 if (!rc)
2676 goto out;
2677
2678 /* Update the eligible FCF record index bmask */
2679 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
James Smart7d791df2011-07-22 18:37:52 -04002680
2681 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
James Smart0c9ab6f2010-02-26 14:15:57 -05002682
2683out:
2684 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2685}
2686
2687/**
James Smart76a95d72010-11-20 23:11:48 -05002688 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2689 * @phba: pointer to lpfc hba data structure.
2690 * @mboxq: pointer to mailbox data structure.
2691 *
2692 * This function handles completion of init vfi mailbox command.
2693 */
Rashika Kheriab86a6752014-09-03 12:55:17 -04002694static void
James Smart76a95d72010-11-20 23:11:48 -05002695lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2696{
2697 struct lpfc_vport *vport = mboxq->vport;
2698
James Smartdf9e1b52011-12-13 13:22:17 -05002699 /*
2700 * VFI not supported on interface type 0, just do the flogi
2701 * Also continue if the VFI is in use - just use the same one.
2702 */
2703 if (mboxq->u.mb.mbxStatus &&
2704 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2705 LPFC_SLI_INTF_IF_TYPE_0) &&
2706 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart76a95d72010-11-20 23:11:48 -05002707 lpfc_printf_vlog(vport, KERN_ERR,
2708 LOG_MBOX,
2709 "2891 Init VFI mailbox failed 0x%x\n",
2710 mboxq->u.mb.mbxStatus);
2711 mempool_free(mboxq, phba->mbox_mem_pool);
2712 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2713 return;
2714 }
James Smart73d91e52011-10-10 21:32:10 -04002715
James Smart76a95d72010-11-20 23:11:48 -05002716 lpfc_initial_flogi(vport);
2717 mempool_free(mboxq, phba->mbox_mem_pool);
2718 return;
2719}
2720
2721/**
2722 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2723 * @vport: pointer to lpfc_vport data structure.
2724 *
2725 * This function issue a init_vfi mailbox command to initialize the VFI and
2726 * VPI for the physical port.
2727 */
2728void
2729lpfc_issue_init_vfi(struct lpfc_vport *vport)
2730{
2731 LPFC_MBOXQ_t *mboxq;
2732 int rc;
2733 struct lpfc_hba *phba = vport->phba;
2734
2735 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2736 if (!mboxq) {
2737 lpfc_printf_vlog(vport, KERN_ERR,
2738 LOG_MBOX, "2892 Failed to allocate "
2739 "init_vfi mailbox\n");
2740 return;
2741 }
2742 lpfc_init_vfi(mboxq, vport);
2743 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2744 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2745 if (rc == MBX_NOT_FINISHED) {
2746 lpfc_printf_vlog(vport, KERN_ERR,
2747 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2748 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2749 }
2750}
2751
2752/**
James Smart1c6834a2009-07-19 10:01:26 -04002753 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2754 * @phba: pointer to lpfc hba data structure.
2755 * @mboxq: pointer to mailbox data structure.
2756 *
2757 * This function handles completion of init vpi mailbox command.
2758 */
James Smart695a8142010-01-26 23:08:03 -05002759void
James Smart1c6834a2009-07-19 10:01:26 -04002760lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2761{
2762 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002763 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2765
James Smart1c6834a2009-07-19 10:01:26 -04002766 if (mboxq->u.mb.mbxStatus) {
2767 lpfc_printf_vlog(vport, KERN_ERR,
2768 LOG_MBOX,
2769 "2609 Init VPI mailbox failed 0x%x\n",
2770 mboxq->u.mb.mbxStatus);
2771 mempool_free(mboxq, phba->mbox_mem_pool);
2772 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2773 return;
2774 }
James Smart72100cc2010-02-12 14:43:01 -05002775 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002776 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002777 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002778
James Smart695a8142010-01-26 23:08:03 -05002779 /* If this port is physical port or FDISC is done, do reg_vpi */
2780 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2781 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2782 if (!ndlp)
2783 lpfc_printf_vlog(vport, KERN_ERR,
2784 LOG_DISCOVERY,
2785 "2731 Cannot find fabric "
2786 "controller node\n");
2787 else
2788 lpfc_register_new_vport(phba, vport, ndlp);
2789 mempool_free(mboxq, phba->mbox_mem_pool);
2790 return;
2791 }
2792
James Smart1c6834a2009-07-19 10:01:26 -04002793 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2794 lpfc_initial_fdisc(vport);
2795 else {
2796 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002797 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2798 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002799 }
James Smart695a8142010-01-26 23:08:03 -05002800 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002801 return;
2802}
2803
2804/**
James Smartecfd03c2010-02-12 14:41:27 -05002805 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2806 * @vport: pointer to lpfc_vport data structure.
2807 *
2808 * This function issue a init_vpi mailbox command to initialize
2809 * VPI for the vport.
2810 */
2811void
2812lpfc_issue_init_vpi(struct lpfc_vport *vport)
2813{
2814 LPFC_MBOXQ_t *mboxq;
James Smart16a3a202013-04-17 20:14:38 -04002815 int rc, vpi;
2816
2817 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2818 vpi = lpfc_alloc_vpi(vport->phba);
2819 if (!vpi) {
2820 lpfc_printf_vlog(vport, KERN_ERR,
2821 LOG_MBOX,
2822 "3303 Failed to obtain vport vpi\n");
2823 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2824 return;
2825 }
2826 vport->vpi = vpi;
2827 }
James Smartecfd03c2010-02-12 14:41:27 -05002828
2829 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2830 if (!mboxq) {
2831 lpfc_printf_vlog(vport, KERN_ERR,
2832 LOG_MBOX, "2607 Failed to allocate "
2833 "init_vpi mailbox\n");
2834 return;
2835 }
2836 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2837 mboxq->vport = vport;
2838 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2839 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2840 if (rc == MBX_NOT_FINISHED) {
2841 lpfc_printf_vlog(vport, KERN_ERR,
2842 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2843 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2844 }
2845}
2846
2847/**
James Smart6fb120a2009-05-22 14:52:59 -04002848 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2849 * @phba: pointer to lpfc hba data structure.
2850 *
2851 * This function loops through the list of vports on the @phba and issues an
2852 * FDISC if possible.
2853 */
2854void
2855lpfc_start_fdiscs(struct lpfc_hba *phba)
2856{
2857 struct lpfc_vport **vports;
2858 int i;
2859
2860 vports = lpfc_create_vport_work_array(phba);
2861 if (vports != NULL) {
2862 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2863 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2864 continue;
2865 /* There are no vpi for this vport */
2866 if (vports[i]->vpi > phba->max_vpi) {
2867 lpfc_vport_set_state(vports[i],
2868 FC_VPORT_FAILED);
2869 continue;
2870 }
James Smart76a95d72010-11-20 23:11:48 -05002871 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002872 lpfc_vport_set_state(vports[i],
2873 FC_VPORT_LINKDOWN);
2874 continue;
2875 }
James Smart1c6834a2009-07-19 10:01:26 -04002876 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002877 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002878 continue;
2879 }
James Smart6fb120a2009-05-22 14:52:59 -04002880 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2881 lpfc_initial_fdisc(vports[i]);
2882 else {
2883 lpfc_vport_set_state(vports[i],
2884 FC_VPORT_NO_FABRIC_SUPP);
2885 lpfc_printf_vlog(vports[i], KERN_ERR,
2886 LOG_ELS,
2887 "0259 No NPIV "
2888 "Fabric support\n");
2889 }
2890 }
2891 }
2892 lpfc_destroy_vport_work_array(phba, vports);
2893}
2894
2895void
2896lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2897{
2898 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2899 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002901
James Smartf5eca9b2012-03-01 22:37:54 -05002902 /*
2903 * VFI not supported for interface type 0, so ignore any mailbox
2904 * error (except VFI in use) and continue with the discovery.
2905 */
2906 if (mboxq->u.mb.mbxStatus &&
2907 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2908 LPFC_SLI_INTF_IF_TYPE_0) &&
2909 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
James Smart6fb120a2009-05-22 14:52:59 -04002910 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2911 "2018 REG_VFI mbxStatus error x%x "
2912 "HBA state x%x\n",
2913 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002914 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002915 /* FLOGI failed, use loop map to make discovery list */
2916 lpfc_disc_list_loopmap(vport);
2917 /* Start discovery */
2918 lpfc_disc_start(vport);
James Smart1b511972011-12-13 13:23:09 -05002919 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002920 }
2921 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart1b511972011-12-13 13:23:09 -05002922 goto out_free_mem;
James Smart6fb120a2009-05-22 14:52:59 -04002923 }
James Smartae05ebe2013-03-01 16:35:38 -05002924
James Smarte74c03c2013-04-17 20:15:19 -04002925 /* If the VFI is already registered, there is nothing else to do
2926 * Unless this was a VFI update and we are in PT2PT mode, then
2927 * we should drop through to set the port state to ready.
2928 */
James Smartae05ebe2013-03-01 16:35:38 -05002929 if (vport->fc_flag & FC_VFI_REGISTERED)
James Smarte74c03c2013-04-17 20:15:19 -04002930 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2931 vport->fc_flag & FC_PT2PT))
2932 goto out_free_mem;
James Smartae05ebe2013-03-01 16:35:38 -05002933
James Smartc8685952009-11-18 15:39:16 -05002934 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002935 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002936 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002937 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002938 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart5248a742011-07-22 18:37:06 -04002939 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002940 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04002941
James Smart1b511972011-12-13 13:23:09 -05002942 /* In case SLI4 FC loopback test, we are ready */
2943 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2944 (phba->link_flag & LS_LOOPBACK_MODE)) {
2945 phba->link_state = LPFC_HBA_READY;
2946 goto out_free_mem;
2947 }
2948
James Smarte74c03c2013-04-17 20:15:19 -04002949 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2950 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
2951 "alpacnt:%d LinkState:%x topology:%x\n",
2952 vport->port_state, vport->fc_flag, vport->fc_myDID,
2953 vport->phba->alpa_map[0],
2954 phba->link_state, phba->fc_topology);
2955
James Smart6fb120a2009-05-22 14:52:59 -04002956 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart939723a2012-05-09 21:19:03 -04002957 /*
2958 * For private loop or for NPort pt2pt,
2959 * just start discovery and we are done.
2960 */
2961 if ((vport->fc_flag & FC_PT2PT) ||
2962 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2963 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2964
James Smart76a95d72010-11-20 23:11:48 -05002965 /* Use loop map to make discovery list */
2966 lpfc_disc_list_loopmap(vport);
2967 /* Start discovery */
James Smarte74c03c2013-04-17 20:15:19 -04002968 if (vport->fc_flag & FC_PT2PT)
2969 vport->port_state = LPFC_VPORT_READY;
2970 else
2971 lpfc_disc_start(vport);
James Smart76a95d72010-11-20 23:11:48 -05002972 } else {
2973 lpfc_start_fdiscs(phba);
2974 lpfc_do_scr_ns_plogi(phba, vport);
2975 }
James Smart6fb120a2009-05-22 14:52:59 -04002976 }
2977
James Smart1b511972011-12-13 13:23:09 -05002978out_free_mem:
James Smart6fb120a2009-05-22 14:52:59 -04002979 mempool_free(mboxq, phba->mbox_mem_pool);
2980 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2981 kfree(dmabuf);
2982 return;
2983}
2984
2985static void
James Smart2e0fef82007-06-17 19:56:36 -05002986lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002987{
James Smart6fb120a2009-05-22 14:52:59 -04002988 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002989 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002990 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002991
2992
2993 /* Check for error */
2994 if (mb->mbxStatus) {
2995 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04002996 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2997 "0319 READ_SPARAM mbxStatus error x%x "
2998 "hba state x%x>\n",
2999 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003000 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05003001 goto out;
3002 }
3003
James Smart2e0fef82007-06-17 19:56:36 -05003004 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05003005 sizeof (struct serv_parm));
James Smart05580562011-05-24 11:40:48 -04003006 lpfc_update_vport_wwn(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003007 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3008 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3009 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3010 }
3011
dea31012005-04-17 16:05:31 -05003012 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3013 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003014 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003015 return;
3016
3017out:
3018 pmb->context1 = NULL;
3019 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3020 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05003021 lpfc_issue_clear_la(phba, vport);
3022 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003023 return;
3024}
3025
3026static void
James Smart76a95d72010-11-20 23:11:48 -05003027lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05003028{
James Smart92d7f7b2007-06-17 19:56:38 -05003029 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04003030 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smartdf9e1b52011-12-13 13:22:17 -05003031 struct Scsi_Host *shost;
James Smart2e0fef82007-06-17 19:56:36 -05003032 int i;
James Smart14691152006-12-02 13:34:28 -05003033 struct lpfc_dmabuf *mp;
3034 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04003035 struct fcf_record *fcf_record;
James Smart38c20672013-03-01 16:37:44 -05003036 uint32_t fc_flags = 0;
James Smart14691152006-12-02 13:34:28 -05003037
James Smart92d7f7b2007-06-17 19:56:38 -05003038 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05003039 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3040 case LPFC_LINK_SPEED_1GHZ:
3041 case LPFC_LINK_SPEED_2GHZ:
3042 case LPFC_LINK_SPEED_4GHZ:
3043 case LPFC_LINK_SPEED_8GHZ:
3044 case LPFC_LINK_SPEED_10GHZ:
3045 case LPFC_LINK_SPEED_16GHZ:
3046 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
James Smartf4b4c682009-05-22 14:53:12 -04003047 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003048 default:
James Smart76a95d72010-11-20 23:11:48 -05003049 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
James Smart92d7f7b2007-06-17 19:56:38 -05003050 break;
dea31012005-04-17 16:05:31 -05003051 }
3052
James Smarte74c03c2013-04-17 20:15:19 -04003053 if (phba->fc_topology &&
3054 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3055 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3056 "3314 Toplogy changed was 0x%x is 0x%x\n",
3057 phba->fc_topology,
3058 bf_get(lpfc_mbx_read_top_topology, la));
3059 phba->fc_topology_changed = 1;
3060 }
3061
James Smart76a95d72010-11-20 23:11:48 -05003062 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05003063 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05003064
James Smartdf9e1b52011-12-13 13:22:17 -05003065 shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003066 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003067 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05003068
James Smart6a9c52c2009-10-02 15:16:51 -04003069 /* if npiv is enabled and this adapter supports npiv log
3070 * a message that npiv is not supported in this topology
3071 */
3072 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04003073 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3074 "1309 Link Up Event npiv not supported in loop "
3075 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003076 /* Get Loop Map information */
James Smart38c20672013-03-01 16:37:44 -05003077 if (bf_get(lpfc_mbx_read_top_il, la))
3078 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003079
James Smart76a95d72010-11-20 23:11:48 -05003080 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3081 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05003082
3083 if (i == 0) {
3084 phba->alpa_map[0] = 0;
3085 } else {
James Smarte8b62012007-08-02 11:10:09 -04003086 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05003087 int numalpa, j, k;
3088 union {
3089 uint8_t pamap[16];
3090 struct {
3091 uint32_t wd1;
3092 uint32_t wd2;
3093 uint32_t wd3;
3094 uint32_t wd4;
3095 } pa;
3096 } un;
3097 numalpa = phba->alpa_map[0];
3098 j = 0;
3099 while (j < numalpa) {
3100 memset(un.pamap, 0, 16);
3101 for (k = 1; j < numalpa; k++) {
3102 un.pamap[k - 1] =
3103 phba->alpa_map[j + 1];
3104 j++;
3105 if (k == 16)
3106 break;
3107 }
3108 /* Link Up Event ALPA map */
3109 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05003110 KERN_WARNING,
3111 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003112 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05003113 "ALPA map Data: x%x "
3114 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003115 un.pa.wd1, un.pa.wd2,
3116 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05003117 }
3118 }
3119 }
3120 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05003121 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04003122 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smartdf9e1b52011-12-13 13:22:17 -05003123 (phba->sli_rev >= LPFC_SLI_REV3))
James Smart92d7f7b2007-06-17 19:56:38 -05003124 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3125 }
James Smart2e0fef82007-06-17 19:56:36 -05003126 vport->fc_myDID = phba->fc_pref_DID;
James Smart38c20672013-03-01 16:37:44 -05003127 fc_flags |= FC_LBIT;
dea31012005-04-17 16:05:31 -05003128 }
James Smart92d7f7b2007-06-17 19:56:38 -05003129 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003130
James Smart38c20672013-03-01 16:37:44 -05003131 if (fc_flags) {
3132 spin_lock_irq(shost->host_lock);
3133 vport->fc_flag |= fc_flags;
3134 spin_unlock_irq(shost->host_lock);
3135 }
3136
dea31012005-04-17 16:05:31 -05003137 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05003138 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3139 if (!sparam_mbox)
3140 goto out;
3141
3142 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3143 if (rc) {
3144 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3145 goto out;
3146 }
3147 sparam_mbox->vport = vport;
3148 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3149 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3150 if (rc == MBX_NOT_FINISHED) {
3151 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3152 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3153 kfree(mp);
3154 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3155 goto out;
dea31012005-04-17 16:05:31 -05003156 }
3157
James Smart76a95d72010-11-20 23:11:48 -05003158 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04003159 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3160 if (!cfglink_mbox)
3161 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05003162 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05003163 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05003164 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05003165 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04003166 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04003167 if (rc == MBX_NOT_FINISHED) {
3168 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3169 goto out;
3170 }
3171 } else {
James Smart32b97932009-07-19 10:01:21 -04003172 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04003173 /*
3174 * Add the driver's default FCF record at FCF index 0 now. This
3175 * is phase 1 implementation that support FCF index 0 and driver
3176 * defaults.
3177 */
James Smart45ed1192009-10-02 15:17:02 -04003178 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04003179 fcf_record = kzalloc(sizeof(struct fcf_record),
3180 GFP_KERNEL);
3181 if (unlikely(!fcf_record)) {
3182 lpfc_printf_log(phba, KERN_ERR,
3183 LOG_MBOX | LOG_SLI,
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04003184 "2554 Could not allocate memory for "
James Smart6fb120a2009-05-22 14:52:59 -04003185 "fcf record\n");
3186 rc = -ENODEV;
3187 goto out;
3188 }
3189
3190 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3191 LPFC_FCOE_FCF_DEF_INDEX);
3192 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3193 if (unlikely(rc)) {
3194 lpfc_printf_log(phba, KERN_ERR,
3195 LOG_MBOX | LOG_SLI,
3196 "2013 Could not manually add FCF "
3197 "record 0, status %d\n", rc);
3198 rc = -ENODEV;
3199 kfree(fcf_record);
3200 goto out;
3201 }
3202 kfree(fcf_record);
3203 }
3204 /*
3205 * The driver is expected to do FIP/FCF. Call the port
3206 * and get the FCF Table.
3207 */
James Smart32b97932009-07-19 10:01:21 -04003208 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04003209 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart32b97932009-07-19 10:01:21 -04003210 spin_unlock_irq(&phba->hbalock);
3211 return;
3212 }
James Smart0c9ab6f2010-02-26 14:15:57 -05003213 /* This is the initial FCF discovery scan */
3214 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04003215 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05003216 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3217 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05003218 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3219 LPFC_FCOE_FCF_GET_FIRST);
3220 if (rc) {
3221 spin_lock_irq(&phba->hbalock);
3222 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3223 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04003224 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05003225 }
James Smart38b92ef2010-08-04 16:11:39 -04003226 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04003227 lpfc_sli4_clear_fcf_rr_bmask(phba);
dea31012005-04-17 16:05:31 -05003228 }
James Smart6fb120a2009-05-22 14:52:59 -04003229
3230 return;
James Smart92d7f7b2007-06-17 19:56:38 -05003231out:
3232 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04003233 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3234 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3235 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05003236 lpfc_issue_clear_la(phba, vport);
3237 return;
dea31012005-04-17 16:05:31 -05003238}
3239
3240static void
James Smart84774a42008-08-24 21:50:06 -04003241lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05003242{
dea31012005-04-17 16:05:31 -05003243 uint32_t control;
3244 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05003245 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003246 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04003247 if (phba->sli_rev <= LPFC_SLI_REV3) {
3248 control = readl(phba->HCregaddr);
3249 control |= HC_LAINT_ENA;
3250 writel(control, phba->HCregaddr);
3251 readl(phba->HCregaddr); /* flush */
3252 }
James Smart2e0fef82007-06-17 19:56:36 -05003253 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003254}
3255
James Smart84774a42008-08-24 21:50:06 -04003256static void
3257lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3258{
3259 lpfc_linkdown(phba);
3260 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04003261 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04003262 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3263}
3264
3265
dea31012005-04-17 16:05:31 -05003266/*
James Smart76a95d72010-11-20 23:11:48 -05003267 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05003268 * command upon completion. It is setup in the LPFC_MBOXQ
3269 * as the completion routine when the command is
3270 * handed off to the SLI layer.
3271 */
3272void
James Smart76a95d72010-11-20 23:11:48 -05003273lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003274{
James Smart2e0fef82007-06-17 19:56:36 -05003275 struct lpfc_vport *vport = pmb->vport;
3276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05003277 struct lpfc_mbx_read_top *la;
James Smart04c68492009-05-22 14:52:52 -04003278 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05003279 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3280
James Smart0d2b6b82008-06-14 22:52:47 -04003281 /* Unblock ELS traffic */
3282 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05003283 /* Check for error */
3284 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05003285 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003286 "1307 READ_LA mbox error x%x state x%x\n",
3287 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05003288 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05003289 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05003290 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05003291 }
3292
James Smart76a95d72010-11-20 23:11:48 -05003293 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
dea31012005-04-17 16:05:31 -05003294
3295 memcpy(&phba->alpa_map[0], mp->virt, 128);
3296
James Smart2e0fef82007-06-17 19:56:36 -05003297 spin_lock_irq(shost->host_lock);
James Smart76a95d72010-11-20 23:11:48 -05003298 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05003299 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003300 else
James Smart2e0fef82007-06-17 19:56:36 -05003301 vport->fc_flag &= ~FC_BYPASSED_MODE;
3302 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003303
James Smartbe0c0082013-03-01 16:38:14 -05003304 if (phba->fc_eventTag <= la->eventTag) {
dea31012005-04-17 16:05:31 -05003305 phba->fc_stat.LinkMultiEvent++;
James Smart76a95d72010-11-20 23:11:48 -05003306 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05003307 if (phba->fc_eventTag != 0)
3308 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05003309 }
dea31012005-04-17 16:05:31 -05003310
3311 phba->fc_eventTag = la->eventTag;
James Smartbe0c0082013-03-01 16:38:14 -05003312 if (phba->sli_rev < LPFC_SLI_REV4) {
3313 spin_lock_irq(&phba->hbalock);
3314 if (bf_get(lpfc_mbx_read_top_mm, la))
3315 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3316 else
3317 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3318 spin_unlock_irq(&phba->hbalock);
3319 }
dea31012005-04-17 16:05:31 -05003320
James Smart4d9ab992009-10-02 15:16:39 -04003321 phba->link_events++;
James Smart76a95d72010-11-20 23:11:48 -05003322 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
James Smartbe0c0082013-03-01 16:38:14 -05003323 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
dea31012005-04-17 16:05:31 -05003324 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05003325 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05003326 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003327 "1306 Link Up Event in loop back mode "
3328 "x%x received Data: x%x x%x x%x x%x\n",
3329 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003330 bf_get(lpfc_mbx_read_top_alpa_granted,
3331 la),
3332 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003333 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003334 } else {
3335 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003336 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003337 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003338 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003339 bf_get(lpfc_mbx_read_top_alpa_granted,
3340 la),
3341 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003342 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003343 bf_get(lpfc_mbx_read_top_mm, la),
3344 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003345 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003346 }
James Smart92d7f7b2007-06-17 19:56:38 -05003347 lpfc_mbx_process_link_up(phba, la);
James Smart76a95d72010-11-20 23:11:48 -05003348 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3349 LPFC_ATT_LINK_DOWN) {
dea31012005-04-17 16:05:31 -05003350 phba->fc_stat.LinkDown++;
James Smart1b511972011-12-13 13:23:09 -05003351 if (phba->link_flag & LS_LOOPBACK_MODE)
James Smart3163f722008-02-08 18:50:25 -05003352 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3353 "1308 Link Down Event in loop back mode "
3354 "x%x received "
3355 "Data: x%x x%x x%x\n",
3356 la->eventTag, phba->fc_eventTag,
3357 phba->pport->port_state, vport->fc_flag);
James Smart1b511972011-12-13 13:23:09 -05003358 else
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 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003361 "Data: x%x x%x x%x x%x x%x\n",
3362 la->eventTag, phba->fc_eventTag,
3363 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003364 bf_get(lpfc_mbx_read_top_mm, la),
3365 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003366 lpfc_mbx_issue_link_down(phba);
3367 }
James Smartbe0c0082013-03-01 16:38:14 -05003368 if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) &&
3369 ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) {
James Smart84774a42008-08-24 21:50:06 -04003370 if (phba->link_state != LPFC_LINK_DOWN) {
3371 phba->fc_stat.LinkDown++;
3372 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3373 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003374 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003375 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003376 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003377 lpfc_mbx_issue_link_down(phba);
3378 } else
3379 lpfc_enable_la(phba);
3380
3381 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3382 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3383 "Data: x%x x%x x%x\n",
3384 la->eventTag, phba->fc_eventTag,
3385 phba->pport->port_state, vport->fc_flag);
3386 /*
3387 * The cmnd that triggered this will be waiting for this
3388 * signal.
3389 */
3390 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3391 if (phba->wait_4_mlo_maint_flg) {
3392 phba->wait_4_mlo_maint_flg = 0;
3393 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003394 }
James Smart84774a42008-08-24 21:50:06 -04003395 }
3396
James Smartbe0c0082013-03-01 16:38:14 -05003397 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3398 bf_get(lpfc_mbx_read_top_fa, la)) {
3399 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
James Smart84774a42008-08-24 21:50:06 -04003400 lpfc_issue_clear_la(phba, vport);
3401 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003402 "1311 fa %d\n",
3403 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003404 }
3405
James Smart76a95d72010-11-20 23:11:48 -05003406lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3408 kfree(mp);
3409 mempool_free(pmb, phba->mbox_mem_pool);
3410 return;
3411}
3412
3413/*
3414 * This routine handles processing a REG_LOGIN mailbox
3415 * command upon completion. It is setup in the LPFC_MBOXQ
3416 * as the completion routine when the command is
3417 * handed off to the SLI layer.
3418 */
3419void
James Smart2e0fef82007-06-17 19:56:36 -05003420lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003421{
James Smart2e0fef82007-06-17 19:56:36 -05003422 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003423 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05003424 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smartffc95492010-06-07 15:23:17 -04003425 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003426
dea31012005-04-17 16:05:31 -05003427 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003428 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05003429
James Smartffc95492010-06-07 15:23:17 -04003430 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3431 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3432
James Smart40426292010-12-15 17:58:10 -05003433 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3434 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
James Smartffc95492010-06-07 15:23:17 -04003435 /* We rcvd a rscn after issuing this
3436 * mbox reg login, we may have cycled
3437 * back through the state and be
3438 * back at reg login state so this
3439 * mbox needs to be ignored becase
3440 * there is another reg login in
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003441 * process.
James Smartffc95492010-06-07 15:23:17 -04003442 */
3443 spin_lock_irq(shost->host_lock);
3444 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3445 spin_unlock_irq(shost->host_lock);
James Smartffc95492010-06-07 15:23:17 -04003446 } else
3447 /* Good status, call state machine */
3448 lpfc_disc_state_machine(vport, ndlp, pmb,
3449 NLP_EVT_CMPL_REG_LOGIN);
3450
dea31012005-04-17 16:05:31 -05003451 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3452 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003453 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003454 /* decrement the node reference count held for this callback
3455 * function.
3456 */
James Smart329f9bc2007-04-25 09:53:01 -04003457 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003458
3459 return;
3460}
3461
James Smart92d7f7b2007-06-17 19:56:38 -05003462static void
3463lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3464{
James Smart04c68492009-05-22 14:52:52 -04003465 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003466 struct lpfc_vport *vport = pmb->vport;
3467 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3468
3469 switch (mb->mbxStatus) {
3470 case 0x0011:
3471 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003472 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3473 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3474 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003475 break;
James Smart78730cf2010-04-06 15:06:30 -04003476 /* If VPI is busy, reset the HBA */
3477 case 0x9700:
3478 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3479 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3480 vport->vpi, mb->mbxStatus);
3481 if (!(phba->pport->load_flag & FC_UNLOADING))
3482 lpfc_workq_post_event(phba, NULL, NULL,
3483 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003484 }
James Smart72100cc2010-02-12 14:43:01 -05003485 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003486 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003487 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003488 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003489 vport->unreg_vpi_cmpl = VPORT_OK;
3490 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1151e3e2011-02-16 12:39:35 -05003491 lpfc_cleanup_vports_rrqs(vport, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003492 /*
3493 * This shost reference might have been taken at the beginning of
3494 * lpfc_vport_delete()
3495 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003496 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003497 scsi_host_put(shost);
3498}
3499
James Smartd7c255b2008-08-24 21:50:00 -04003500int
James Smart92d7f7b2007-06-17 19:56:38 -05003501lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3502{
3503 struct lpfc_hba *phba = vport->phba;
3504 LPFC_MBOXQ_t *mbox;
3505 int rc;
3506
3507 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3508 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003509 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003510
3511 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3512 mbox->vport = vport;
3513 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003514 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003515 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003516 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3517 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003518 mempool_free(mbox, phba->mbox_mem_pool);
3519 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003520 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003521 }
James Smartd7c255b2008-08-24 21:50:00 -04003522 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003523}
3524
3525static void
3526lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3527{
3528 struct lpfc_vport *vport = pmb->vport;
3529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003530 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003531
3532 switch (mb->mbxStatus) {
3533 case 0x0011:
3534 case 0x9601:
3535 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003536 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3537 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3538 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003539 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3540 spin_lock_irq(shost->host_lock);
3541 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3542 spin_unlock_irq(shost->host_lock);
3543 vport->fc_myDID = 0;
3544 goto out;
3545 }
James Smart92d7f7b2007-06-17 19:56:38 -05003546
James Smart72100cc2010-02-12 14:43:01 -05003547 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003548 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003549 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003550 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003551 vport->num_disc_nodes = 0;
3552 /* go thru NPR list and issue ELS PLOGIs */
3553 if (vport->fc_npr_cnt)
3554 lpfc_els_disc_plogi(vport);
3555
3556 if (!vport->num_disc_nodes) {
3557 spin_lock_irq(shost->host_lock);
3558 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3559 spin_unlock_irq(shost->host_lock);
3560 lpfc_can_disctmo(vport);
3561 }
3562 vport->port_state = LPFC_VPORT_READY;
3563
3564out:
3565 mempool_free(pmb, phba->mbox_mem_pool);
3566 return;
3567}
3568
James Smart21e9a0a2009-05-22 14:53:21 -04003569/**
3570 * lpfc_create_static_vport - Read HBA config region to create static vports.
3571 * @phba: pointer to lpfc hba data structure.
3572 *
3573 * This routine issue a DUMP mailbox command for config region 22 to get
3574 * the list of static vports to be created. The function create vports
3575 * based on the information returned from the HBA.
3576 **/
3577void
3578lpfc_create_static_vport(struct lpfc_hba *phba)
3579{
3580 LPFC_MBOXQ_t *pmb = NULL;
3581 MAILBOX_t *mb;
3582 struct static_vport_info *vport_info;
James Smartcdcc2342012-08-14 14:26:35 -04003583 int mbx_wait_rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003584 struct fc_vport_identifiers vport_id;
3585 struct fc_vport *new_fc_vport;
3586 struct Scsi_Host *shost;
3587 struct lpfc_vport *vport;
3588 uint16_t offset = 0;
3589 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003590 struct lpfc_dmabuf *mp;
3591 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003592
3593 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3594 if (!pmb) {
3595 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3596 "0542 lpfc_create_static_vport failed to"
3597 " allocate mailbox memory\n");
3598 return;
3599 }
James Smartcdcc2342012-08-14 14:26:35 -04003600 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
James Smart21e9a0a2009-05-22 14:53:21 -04003601 mb = &pmb->u.mb;
3602
3603 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3604 if (!vport_info) {
3605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3606 "0543 lpfc_create_static_vport failed to"
3607 " allocate vport_info\n");
3608 mempool_free(pmb, phba->mbox_mem_pool);
3609 return;
3610 }
3611
3612 vport_buff = (uint8_t *) vport_info;
3613 do {
James Smartcdcc2342012-08-14 14:26:35 -04003614 /* free dma buffer from previous round */
3615 if (pmb->context1) {
3616 mp = (struct lpfc_dmabuf *)pmb->context1;
3617 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3618 kfree(mp);
3619 }
James Smart1c6834a2009-07-19 10:01:26 -04003620 if (lpfc_dump_static_vport(phba, pmb, offset))
3621 goto out;
3622
James Smart21e9a0a2009-05-22 14:53:21 -04003623 pmb->vport = phba->pport;
James Smartcdcc2342012-08-14 14:26:35 -04003624 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3625 LPFC_MBOX_TMO);
James Smart21e9a0a2009-05-22 14:53:21 -04003626
James Smartcdcc2342012-08-14 14:26:35 -04003627 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003628 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3629 "0544 lpfc_create_static_vport failed to"
3630 " issue dump mailbox command ret 0x%x "
3631 "status 0x%x\n",
James Smartcdcc2342012-08-14 14:26:35 -04003632 mbx_wait_rc, mb->mbxStatus);
James Smart21e9a0a2009-05-22 14:53:21 -04003633 goto out;
3634 }
3635
James Smart1c6834a2009-07-19 10:01:26 -04003636 if (phba->sli_rev == LPFC_SLI_REV4) {
3637 byte_count = pmb->u.mqe.un.mb_words[5];
James Smartcdcc2342012-08-14 14:26:35 -04003638 mp = (struct lpfc_dmabuf *)pmb->context1;
James Smart1c6834a2009-07-19 10:01:26 -04003639 if (byte_count > sizeof(struct static_vport_info) -
3640 offset)
3641 byte_count = sizeof(struct static_vport_info)
3642 - offset;
3643 memcpy(vport_buff + offset, mp->virt, byte_count);
3644 offset += byte_count;
3645 } else {
3646 if (mb->un.varDmp.word_cnt >
3647 sizeof(struct static_vport_info) - offset)
3648 mb->un.varDmp.word_cnt =
3649 sizeof(struct static_vport_info)
3650 - offset;
3651 byte_count = mb->un.varDmp.word_cnt;
3652 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3653 vport_buff + offset,
3654 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003655
James Smart1c6834a2009-07-19 10:01:26 -04003656 offset += byte_count;
3657 }
James Smart21e9a0a2009-05-22 14:53:21 -04003658
James Smart1c6834a2009-07-19 10:01:26 -04003659 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003660 offset < sizeof(struct static_vport_info));
3661
3662
3663 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3664 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3665 != VPORT_INFO_REV)) {
3666 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3667 "0545 lpfc_create_static_vport bad"
3668 " information header 0x%x 0x%x\n",
3669 le32_to_cpu(vport_info->signature),
3670 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3671
3672 goto out;
3673 }
3674
3675 shost = lpfc_shost_from_vport(phba->pport);
3676
3677 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3678 memset(&vport_id, 0, sizeof(vport_id));
3679 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3680 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3681 if (!vport_id.port_name || !vport_id.node_name)
3682 continue;
3683
3684 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3685 vport_id.vport_type = FC_PORTTYPE_NPIV;
3686 vport_id.disable = false;
3687 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3688
3689 if (!new_fc_vport) {
3690 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3691 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003692 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003693 continue;
3694 }
3695
3696 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3697 vport->vport_flag |= STATIC_VPORT;
3698 }
3699
3700out:
James Smart21e9a0a2009-05-22 14:53:21 -04003701 kfree(vport_info);
James Smartcdcc2342012-08-14 14:26:35 -04003702 if (mbx_wait_rc != MBX_TIMEOUT) {
3703 if (pmb->context1) {
3704 mp = (struct lpfc_dmabuf *)pmb->context1;
James Smart1c6834a2009-07-19 10:01:26 -04003705 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3706 kfree(mp);
3707 }
James Smart21e9a0a2009-05-22 14:53:21 -04003708 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003709 }
James Smart21e9a0a2009-05-22 14:53:21 -04003710
3711 return;
3712}
3713
dea31012005-04-17 16:05:31 -05003714/*
3715 * This routine handles processing a Fabric REG_LOGIN mailbox
3716 * command upon completion. It is setup in the LPFC_MBOXQ
3717 * as the completion routine when the command is
3718 * handed off to the SLI layer.
3719 */
3720void
James Smart2e0fef82007-06-17 19:56:36 -05003721lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003722{
James Smart92d7f7b2007-06-17 19:56:38 -05003723 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003724 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003725 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05003726 struct lpfc_nodelist *ndlp;
James Smartdf9e1b52011-12-13 13:22:17 -05003727 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003728
James Smart549e55c2007-08-02 11:09:51 -04003729 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04003730 pmb->context1 = NULL;
3731 pmb->context2 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003732
dea31012005-04-17 16:05:31 -05003733 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003734 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3735 "0258 Register Fabric login error: 0x%x\n",
3736 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003737 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3738 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003739 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003740
James Smart76a95d72010-11-20 23:11:48 -05003741 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003742 /* FLOGI failed, use loop map to make discovery list */
3743 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003744
James Smart92d7f7b2007-06-17 19:56:38 -05003745 /* Start discovery */
3746 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003747 /* Decrement the reference count to ndlp after the
3748 * reference to the ndlp are done.
3749 */
3750 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003751 return;
3752 }
3753
3754 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003755 /* Decrement the reference count to ndlp after the reference
3756 * to the ndlp are done.
3757 */
3758 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003759 return;
3760 }
3761
James Smart6d368e52011-05-24 11:44:12 -04003762 if (phba->sli_rev < LPFC_SLI_REV4)
3763 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003764 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003765 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003767
James Smart2e0fef82007-06-17 19:56:36 -05003768 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003769 /* when physical port receive logo donot start
3770 * vport discovery */
3771 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3772 lpfc_start_fdiscs(phba);
James Smartdf9e1b52011-12-13 13:22:17 -05003773 else {
3774 shost = lpfc_shost_from_vport(vport);
3775 spin_lock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04003776 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smartdf9e1b52011-12-13 13:22:17 -05003777 spin_unlock_irq(shost->host_lock);
3778 }
James Smart92d7f7b2007-06-17 19:56:38 -05003779 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003780 }
3781
3782 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3783 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003784 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003785
3786 /* Drop the reference count from the mbox at the end after
3787 * all the current reference to the ndlp have been done.
3788 */
3789 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003790 return;
3791}
3792
3793/*
3794 * This routine handles processing a NameServer REG_LOGIN mailbox
3795 * command upon completion. It is setup in the LPFC_MBOXQ
3796 * as the completion routine when the command is
3797 * handed off to the SLI layer.
3798 */
3799void
James Smart2e0fef82007-06-17 19:56:36 -05003800lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003801{
James Smart21e9a0a2009-05-22 14:53:21 -04003802 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003803 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3804 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3805 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05003806
James Smartd439d282010-09-29 11:18:45 -04003807 pmb->context1 = NULL;
3808 pmb->context2 = NULL;
3809
dea31012005-04-17 16:05:31 -05003810 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05003811out:
James Smart21e9a0a2009-05-22 14:53:21 -04003812 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3813 "0260 Register NameServer error: 0x%x\n",
3814 mb->mbxStatus);
James Smartfa4066b2008-01-11 01:53:27 -05003815 /* decrement the node reference count held for this
3816 * callback function.
3817 */
James Smart329f9bc2007-04-25 09:53:01 -04003818 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003819 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3820 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04003821 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04003822
3823 /* If no other thread is using the ndlp, free it */
3824 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05003825
James Smart76a95d72010-11-20 23:11:48 -05003826 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003827 /*
3828 * RegLogin failed, use loop map to make discovery
3829 * list
3830 */
3831 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003832
James Smart92d7f7b2007-06-17 19:56:38 -05003833 /* Start discovery */
3834 lpfc_disc_start(vport);
3835 return;
3836 }
3837 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05003838 return;
3839 }
3840
James Smart6d368e52011-05-24 11:44:12 -04003841 if (phba->sli_rev < LPFC_SLI_REV4)
3842 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05003843 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05003844 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003845 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003846
James Smart2e0fef82007-06-17 19:56:36 -05003847 if (vport->port_state < LPFC_VPORT_READY) {
3848 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05003849 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3850 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3851 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3852 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3853 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3854
3855 /* Issue SCR just before NameServer GID_FT Query */
3856 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05003857 }
3858
James Smart2e0fef82007-06-17 19:56:36 -05003859 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05003860 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003861 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05003862 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05003863 goto out;
dea31012005-04-17 16:05:31 -05003864 }
3865
James Smartfa4066b2008-01-11 01:53:27 -05003866 /* decrement the node reference count held for this
3867 * callback function.
3868 */
James Smart329f9bc2007-04-25 09:53:01 -04003869 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003870 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3871 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003872 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003873
3874 return;
3875}
3876
3877static void
James Smart2e0fef82007-06-17 19:56:36 -05003878lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003879{
James Smart2e0fef82007-06-17 19:56:36 -05003880 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3881 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05003882 struct lpfc_rport_data *rdata;
3883 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05003884 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003885
3886 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003887 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3888 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05003889 rport_ids.port_id = ndlp->nlp_DID;
3890 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05003891
James Smart329f9bc2007-04-25 09:53:01 -04003892 /*
3893 * We leave our node pointer in rport->dd_data when we unregister a
3894 * FCP target port. But fc_remote_port_add zeros the space to which
3895 * rport->dd_data points. So, if we're reusing a previously
3896 * registered port, drop the reference that we took the last time we
3897 * registered the port.
3898 */
3899 if (ndlp->rport && ndlp->rport->dd_data &&
James Smarte47c9092008-02-08 18:49:26 -05003900 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04003901 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05003902
3903 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3904 "rport add: did:x%x flg:x%x type x%x",
3905 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3906
James Smart9589b0622011-04-16 11:03:17 -04003907 /* Don't add the remote port if unloading. */
3908 if (vport->load_flag & FC_UNLOADING)
3909 return;
3910
James Smart2e0fef82007-06-17 19:56:36 -05003911 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04003912 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05003913 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3914 "Warning: fc_remote_port_add failed\n");
3915 return;
3916 }
3917
3918 /* initialize static port data */
3919 rport->maxframe_size = ndlp->nlp_maxframe;
3920 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05003921 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04003922 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05003923
3924 if (ndlp->nlp_type & NLP_FCP_TARGET)
3925 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3926 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3927 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3928
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05003929 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3930 fc_remote_port_rolechg(rport, rport_ids.roles);
3931
James Smart34f5ad82012-08-03 12:35:03 -04003932 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3933 "3183 rport register x%06x, rport %p role x%x\n",
3934 ndlp->nlp_DID, rport, rport_ids.roles);
3935
James Smart071fbd3d2006-04-15 11:53:20 -04003936 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05003937 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04003938 ndlp->nlp_sid = rport->scsi_target_id;
3939 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003940 return;
3941}
3942
3943static void
James Smart2e0fef82007-06-17 19:56:36 -05003944lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003945{
3946 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04003947
James Smart858c9f62007-06-17 19:56:39 -05003948 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3949 "rport delete: did:x%x flg:x%x type x%x",
3950 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3951
James Smart34f5ad82012-08-03 12:35:03 -04003952 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3953 "3184 rport unregister x%06x, rport %p\n",
3954 ndlp->nlp_DID, rport);
3955
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003956 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05003957
3958 return;
3959}
3960
James Smartde0c5b32007-04-25 09:52:27 -04003961static void
James Smart2e0fef82007-06-17 19:56:36 -05003962lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04003963{
James Smart2e0fef82007-06-17 19:56:36 -05003964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3965
3966 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003967 switch (state) {
3968 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003969 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003970 break;
3971 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003972 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003973 break;
3974 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003975 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003976 break;
3977 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003978 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003979 break;
3980 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003981 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003982 break;
3983 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003984 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003985 break;
3986 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003987 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003988 break;
3989 case NLP_STE_NPR_NODE:
James Smart646a2dd2013-12-17 20:29:22 -05003990 if (vport->fc_npr_cnt == 0 && count == -1)
3991 vport->fc_npr_cnt = 0;
3992 else
3993 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003994 break;
3995 }
James Smart2e0fef82007-06-17 19:56:36 -05003996 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003997}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003998
James Smartde0c5b32007-04-25 09:52:27 -04003999static void
James Smart2e0fef82007-06-17 19:56:36 -05004000lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004001 int old_state, int new_state)
4002{
James Smart2e0fef82007-06-17 19:56:36 -05004003 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4004
James Smartde0c5b32007-04-25 09:52:27 -04004005 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04004006 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4007 ndlp->nlp_type |= NLP_FC_NODE;
4008 }
4009 if (new_state == NLP_STE_MAPPED_NODE)
4010 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4011 if (new_state == NLP_STE_NPR_NODE)
4012 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05004013
James Smartde0c5b32007-04-25 09:52:27 -04004014 /* Transport interface */
4015 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
4016 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05004017 vport->phba->nport_event_cnt++;
4018 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004019 }
dea31012005-04-17 16:05:31 -05004020
James Smartde0c5b32007-04-25 09:52:27 -04004021 if (new_state == NLP_STE_MAPPED_NODE ||
4022 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004023 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05004024 /*
4025 * Tell the fc transport about the port, if we haven't
4026 * already. If we have, and it's a scsi entity, be
4027 * sure to unblock any attached scsi devices
4028 */
4029 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004030 }
James Smartea2151b2008-09-07 11:52:10 -04004031 if ((new_state == NLP_STE_MAPPED_NODE) &&
4032 (vport->stat_data_enabled)) {
4033 /*
4034 * A new target is discovered, if there is no buffer for
4035 * statistical data collection allocate buffer.
4036 */
4037 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4038 sizeof(struct lpfc_scsicmd_bkt),
4039 GFP_KERNEL);
4040
4041 if (!ndlp->lat_data)
4042 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4043 "0286 lpfc_nlp_state_cleanup failed to "
4044 "allocate statistical data buffer DID "
4045 "0x%x\n", ndlp->nlp_DID);
4046 }
James Smart858c9f62007-06-17 19:56:39 -05004047 /*
4048 * if we added to Mapped list, but the remote port
4049 * registration failed or assigned a target id outside
4050 * our presentable range - move the node to the
4051 * Unmapped List
4052 */
James Smartde0c5b32007-04-25 09:52:27 -04004053 if (new_state == NLP_STE_MAPPED_NODE &&
4054 (!ndlp->rport ||
4055 ndlp->rport->scsi_target_id == -1 ||
4056 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05004057 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04004058 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05004059 spin_unlock_irq(shost->host_lock);
4060 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004061 }
James Smartde0c5b32007-04-25 09:52:27 -04004062}
4063
James Smart685f0bf2007-04-25 09:53:08 -04004064static char *
4065lpfc_nlp_state_name(char *buffer, size_t size, int state)
4066{
4067 static char *states[] = {
4068 [NLP_STE_UNUSED_NODE] = "UNUSED",
4069 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4070 [NLP_STE_ADISC_ISSUE] = "ADISC",
4071 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4072 [NLP_STE_PRLI_ISSUE] = "PRLI",
James Smart086a3452012-08-14 14:25:21 -04004073 [NLP_STE_LOGO_ISSUE] = "LOGO",
James Smart685f0bf2007-04-25 09:53:08 -04004074 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4075 [NLP_STE_MAPPED_NODE] = "MAPPED",
4076 [NLP_STE_NPR_NODE] = "NPR",
4077 };
4078
James Smart311464e2007-08-02 11:10:37 -04004079 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04004080 strlcpy(buffer, states[state], size);
4081 else
4082 snprintf(buffer, size, "unknown (%d)", state);
4083 return buffer;
4084}
4085
James Smartde0c5b32007-04-25 09:52:27 -04004086void
James Smart2e0fef82007-06-17 19:56:36 -05004087lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4088 int state)
James Smartde0c5b32007-04-25 09:52:27 -04004089{
James Smart2e0fef82007-06-17 19:56:36 -05004090 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04004091 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04004092 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04004093
James Smarte8b62012007-08-02 11:10:09 -04004094 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4095 "0904 NPort state transition x%06x, %s -> %s\n",
4096 ndlp->nlp_DID,
4097 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4098 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05004099
4100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4101 "node statechg did:x%x old:%d ste:%d",
4102 ndlp->nlp_DID, old_state, state);
4103
James Smartde0c5b32007-04-25 09:52:27 -04004104 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04004105 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05004106 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004107 if (old_state == NLP_STE_UNMAPPED_NODE) {
4108 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4109 ndlp->nlp_type &= ~NLP_FC_NODE;
4110 }
4111
James Smart685f0bf2007-04-25 09:53:08 -04004112 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004113 spin_lock_irq(shost->host_lock);
4114 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4115 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004116 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05004117 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04004118
4119 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05004120 lpfc_nlp_counters(vport, state, 1);
4121 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04004122}
4123
4124void
James Smarte47c9092008-02-08 18:49:26 -05004125lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4126{
4127 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4128
4129 if (list_empty(&ndlp->nlp_listp)) {
4130 spin_lock_irq(shost->host_lock);
4131 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4132 spin_unlock_irq(shost->host_lock);
4133 }
4134}
4135
4136void
James Smart2e0fef82007-06-17 19:56:36 -05004137lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004138{
James Smart2e0fef82007-06-17 19:56:36 -05004139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4140
James Smart0d2b6b82008-06-14 22:52:47 -04004141 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04004142 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05004143 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4144 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004145 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05004146 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004147 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05004148 NLP_STE_UNUSED_NODE);
4149}
4150
Adrian Bunk4d9db012008-02-14 23:24:02 +02004151static void
James Smarte47c9092008-02-08 18:49:26 -05004152lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4153{
James Smart0d2b6b82008-06-14 22:52:47 -04004154 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004155 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4156 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4157 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4158 NLP_STE_UNUSED_NODE);
4159}
James Smart109f6ed2008-12-04 22:39:08 -05004160/**
James Smart3621a712009-04-06 18:47:14 -04004161 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05004162 * @vport: Pointer to Virtual Port object.
4163 * @ndlp: Pointer to FC node object.
4164 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04004165 *
4166 * This function is always called when node object need to be initialized.
4167 * It initializes all the fields of the node object. Although the reference
4168 * to phba from @ndlp can be obtained indirectly through it's reference to
4169 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4170 * to the life-span of the @ndlp might go beyond the existence of @vport as
4171 * the final release of ndlp is determined by its reference count. And, the
4172 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05004173 **/
4174static inline void
4175lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4176 uint32_t did)
4177{
4178 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4179 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4180 init_timer(&ndlp->nlp_delayfunc);
4181 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4182 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4183 ndlp->nlp_DID = did;
4184 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04004185 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05004186 ndlp->nlp_sid = NLP_NO_SID;
4187 kref_init(&ndlp->kref);
4188 NLP_INT_NODE_ACT(ndlp);
4189 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04004190 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart109f6ed2008-12-04 22:39:08 -05004191}
James Smarte47c9092008-02-08 18:49:26 -05004192
4193struct lpfc_nodelist *
4194lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4195 int state)
4196{
4197 struct lpfc_hba *phba = vport->phba;
4198 uint32_t did;
4199 unsigned long flags;
James Smartcff261f2013-12-17 20:29:47 -05004200 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smarte47c9092008-02-08 18:49:26 -05004201
4202 if (!ndlp)
4203 return NULL;
4204
4205 spin_lock_irqsave(&phba->ndlp_lock, flags);
4206 /* The ndlp should not be in memory free mode */
4207 if (NLP_CHK_FREE_REQ(ndlp)) {
4208 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4209 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4210 "0277 lpfc_enable_node: ndlp:x%p "
4211 "usgmap:x%x refcnt:%d\n",
4212 (void *)ndlp, ndlp->nlp_usg_map,
4213 atomic_read(&ndlp->kref.refcount));
4214 return NULL;
4215 }
4216 /* The ndlp should not already be in active mode */
4217 if (NLP_CHK_NODE_ACT(ndlp)) {
4218 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4219 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4220 "0278 lpfc_enable_node: ndlp:x%p "
4221 "usgmap:x%x refcnt:%d\n",
4222 (void *)ndlp, ndlp->nlp_usg_map,
4223 atomic_read(&ndlp->kref.refcount));
4224 return NULL;
4225 }
4226
4227 /* Keep the original DID */
4228 did = ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05004229 if (phba->sli_rev == LPFC_SLI_REV4)
4230 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
James Smarte47c9092008-02-08 18:49:26 -05004231
4232 /* re-initialize ndlp except of ndlp linked list pointer */
4233 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4234 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smart109f6ed2008-12-04 22:39:08 -05004235 lpfc_initialize_node(vport, ndlp, did);
James Smarte47c9092008-02-08 18:49:26 -05004236
James Smartcff261f2013-12-17 20:29:47 -05004237 if (phba->sli_rev == LPFC_SLI_REV4)
4238 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4239
James Smarte47c9092008-02-08 18:49:26 -05004240 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart725dd392013-10-10 12:23:30 -04004241 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4242 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
4243
James Smarte47c9092008-02-08 18:49:26 -05004244
4245 if (state != NLP_STE_UNUSED_NODE)
4246 lpfc_nlp_set_state(vport, ndlp, state);
4247
4248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4249 "node enable: did:x%x",
4250 ndlp->nlp_DID, 0, 0);
4251 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04004252}
4253
4254void
James Smart2e0fef82007-06-17 19:56:36 -05004255lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04004256{
James Smart87af33f2007-10-27 13:37:43 -04004257 /*
James Smartfa4066b2008-01-11 01:53:27 -05004258 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04004259 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05004260 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4261 * until ALL other outstanding threads have completed. We check
4262 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04004263 */
James Smartfa4066b2008-01-11 01:53:27 -05004264 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4265 return;
James Smart51ef4c22007-08-02 11:10:31 -04004266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart1151e3e2011-02-16 12:39:35 -05004267 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4268 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004269 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04004270 return;
dea31012005-04-17 16:05:31 -05004271}
4272
4273/*
4274 * Start / ReStart rescue timer for Discovery / RSCN handling
4275 */
4276void
James Smart2e0fef82007-06-17 19:56:36 -05004277lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004278{
James Smart2e0fef82007-06-17 19:56:36 -05004279 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4280 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004281 uint32_t tmo;
4282
James Smart2e0fef82007-06-17 19:56:36 -05004283 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004284 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004285 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4286 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02004287 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004288 * FC spec states we need 3 * ratov for CT requests
4289 */
4290 tmo = ((phba->fc_ratov * 3) + 3);
4291 }
dea31012005-04-17 16:05:31 -05004292
James Smart858c9f62007-06-17 19:56:39 -05004293
4294 if (!timer_pending(&vport->fc_disctmo)) {
4295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4296 "set disc timer: tmo:x%x state:x%x flg:x%x",
4297 tmo, vport->port_state, vport->fc_flag);
4298 }
4299
James Smart256ec0d2013-04-17 20:14:58 -04004300 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
James Smart2e0fef82007-06-17 19:56:36 -05004301 spin_lock_irq(shost->host_lock);
4302 vport->fc_flag |= FC_DISC_TMO;
4303 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004304
4305 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004306 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4307 "0247 Start Discovery Timer state x%x "
4308 "Data: x%x x%lx x%x x%x\n",
4309 vport->port_state, tmo,
4310 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4311 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004312
4313 return;
4314}
4315
4316/*
4317 * Cancel rescue timer for Discovery / RSCN handling
4318 */
4319int
James Smart2e0fef82007-06-17 19:56:36 -05004320lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004321{
James Smart2e0fef82007-06-17 19:56:36 -05004322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004323 unsigned long iflags;
4324
James Smart858c9f62007-06-17 19:56:39 -05004325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4326 "can disc timer: state:x%x rtry:x%x flg:x%x",
4327 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4328
dea31012005-04-17 16:05:31 -05004329 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05004330 if (vport->fc_flag & FC_DISC_TMO) {
4331 spin_lock_irqsave(shost->host_lock, iflags);
4332 vport->fc_flag &= ~FC_DISC_TMO;
4333 spin_unlock_irqrestore(shost->host_lock, iflags);
4334 del_timer_sync(&vport->fc_disctmo);
4335 spin_lock_irqsave(&vport->work_port_lock, iflags);
4336 vport->work_port_events &= ~WORKER_DISC_TMO;
4337 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05004338 }
4339
4340 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004341 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4342 "0248 Cancel Discovery Timer state x%x "
4343 "Data: x%x x%x x%x\n",
4344 vport->port_state, vport->fc_flag,
4345 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004346 return 0;
dea31012005-04-17 16:05:31 -05004347}
4348
4349/*
4350 * Check specified ring for outstanding IOCB on the SLI queue
4351 * Return true if iocb matches the specified nport
4352 */
4353int
James Smart2e0fef82007-06-17 19:56:36 -05004354lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4355 struct lpfc_sli_ring *pring,
4356 struct lpfc_iocbq *iocb,
4357 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004358{
James Smart2e0fef82007-06-17 19:56:36 -05004359 struct lpfc_sli *psli = &phba->sli;
4360 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05004361 struct lpfc_vport *vport = ndlp->vport;
4362
4363 if (iocb->vport != vport)
4364 return 0;
4365
dea31012005-04-17 16:05:31 -05004366 if (pring->ringno == LPFC_ELS_RING) {
4367 switch (icmd->ulpCommand) {
4368 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004369 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004370 return 1;
dea31012005-04-17 16:05:31 -05004371 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004372 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4373 return 1;
dea31012005-04-17 16:05:31 -05004374 case CMD_XMIT_ELS_RSP64_CX:
4375 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004376 return 1;
dea31012005-04-17 16:05:31 -05004377 }
James Smarta4bc3372006-12-02 13:34:16 -05004378 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05004379
4380 } else if (pring->ringno == psli->fcp_ring) {
4381 /* Skip match check if waiting to relogin to FCP target */
4382 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004383 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004384 return 0;
dea31012005-04-17 16:05:31 -05004385 }
4386 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004387 return 1;
dea31012005-04-17 16:05:31 -05004388 }
4389 } else if (pring->ringno == psli->next_ring) {
4390
4391 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004392 return 0;
dea31012005-04-17 16:05:31 -05004393}
4394
4395/*
4396 * Free resources / clean up outstanding I/Os
4397 * associated with nlp_rpi in the LPFC_NODELIST entry.
4398 */
4399static int
James Smart2e0fef82007-06-17 19:56:36 -05004400lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004401{
James Smart2534ba72007-04-25 09:52:20 -04004402 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004403 struct lpfc_sli *psli;
4404 struct lpfc_sli_ring *pring;
4405 struct lpfc_iocbq *iocb, *next_iocb;
James Smart6a9c52c2009-10-02 15:16:51 -04004406 uint32_t i;
dea31012005-04-17 16:05:31 -05004407
James Smart92d7f7b2007-06-17 19:56:38 -05004408 lpfc_fabric_abort_nport(ndlp);
4409
dea31012005-04-17 16:05:31 -05004410 /*
4411 * Everything that matches on txcmplq will be returned
4412 * by firmware with a no rpi error.
4413 */
4414 psli = &phba->sli;
James Smart40426292010-12-15 17:58:10 -05004415 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
dea31012005-04-17 16:05:31 -05004416 /* Now process each ring */
4417 for (i = 0; i < psli->num_rings; i++) {
4418 pring = &psli->ring[i];
4419
James Smart2e0fef82007-06-17 19:56:36 -05004420 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004421 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05004422 list) {
dea31012005-04-17 16:05:31 -05004423 /*
4424 * Check to see if iocb matches the nport we are
4425 * looking for
4426 */
James Smart92d7f7b2007-06-17 19:56:38 -05004427 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4428 ndlp))) {
dea31012005-04-17 16:05:31 -05004429 /* It matches, so deque and call compl
4430 with an error */
James Smart2534ba72007-04-25 09:52:20 -04004431 list_move_tail(&iocb->list,
4432 &completions);
dea31012005-04-17 16:05:31 -05004433 }
4434 }
James Smart2e0fef82007-06-17 19:56:36 -05004435 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004436 }
4437 }
James Smart2534ba72007-04-25 09:52:20 -04004438
James Smarta257bf92009-04-06 18:48:10 -04004439 /* Cancel all the IOCBs from the completions list */
4440 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4441 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004442
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004443 return 0;
dea31012005-04-17 16:05:31 -05004444}
4445
James Smart086a3452012-08-14 14:25:21 -04004446/**
4447 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4448 * @phba: Pointer to HBA context object.
4449 * @pmb: Pointer to mailbox object.
4450 *
4451 * This function will issue an ELS LOGO command after completing
4452 * the UNREG_RPI.
4453 **/
Rashika Kheriab86a6752014-09-03 12:55:17 -04004454static void
James Smart086a3452012-08-14 14:25:21 -04004455lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4456{
4457 struct lpfc_vport *vport = pmb->vport;
4458 struct lpfc_nodelist *ndlp;
4459
4460 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4461 if (!ndlp)
4462 return;
4463 lpfc_issue_els_logo(vport, ndlp, 0);
James Smart4aa74c32013-09-06 12:19:06 -04004464 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04004465}
4466
dea31012005-04-17 16:05:31 -05004467/*
4468 * Free rpi associated with LPFC_NODELIST entry.
4469 * This routine is called from lpfc_freenode(), when we are removing
4470 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4471 * LOGO that completes successfully, and we are waiting to PLOGI back
4472 * to the remote NPort. In addition, it is called after we receive
4473 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4474 * we are waiting to PLOGI back to the remote NPort.
4475 */
4476int
James Smart2e0fef82007-06-17 19:56:36 -05004477lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004478{
James Smart2e0fef82007-06-17 19:56:36 -05004479 struct lpfc_hba *phba = vport->phba;
4480 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05004481 int rc;
James Smart6d368e52011-05-24 11:44:12 -04004482 uint16_t rpi;
dea31012005-04-17 16:05:31 -05004483
James Smartf454a9a2013-09-06 12:20:07 -04004484 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4485 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4486 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4487 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4488 "3366 RPI x%x needs to be "
4489 "unregistered nlp_flag x%x "
4490 "did x%x\n",
4491 ndlp->nlp_rpi, ndlp->nlp_flag,
4492 ndlp->nlp_DID);
James Smart2e0fef82007-06-17 19:56:36 -05004493 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4494 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004495 /* SLI4 ports require the physical rpi value. */
4496 rpi = ndlp->nlp_rpi;
4497 if (phba->sli_rev == LPFC_SLI_REV4)
4498 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
James Smart086a3452012-08-14 14:25:21 -04004499
James Smart6d368e52011-05-24 11:44:12 -04004500 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004501 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004502 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4503 mbox->context1 = ndlp;
4504 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4505 } else {
4506 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4507 }
4508
James Smart0b727fe2007-10-27 13:37:25 -04004509 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -05004510 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05004511 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004512 }
dea31012005-04-17 16:05:31 -05004513 lpfc_no_rpi(phba, ndlp);
James Smartd7c47992010-06-08 18:31:54 -04004514
James Smart40426292010-12-15 17:58:10 -05004515 if (phba->sli_rev != LPFC_SLI_REV4)
4516 ndlp->nlp_rpi = 0;
4517 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
James Smart0c287582009-06-10 17:22:56 -04004518 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -05004519 return 1;
4520 }
4521 return 0;
4522}
4523
James Smartecfd03c2010-02-12 14:41:27 -05004524/**
4525 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4526 * @phba: pointer to lpfc hba data structure.
4527 *
4528 * This routine is invoked to unregister all the currently registered RPIs
4529 * to the HBA.
4530 **/
4531void
4532lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4533{
4534 struct lpfc_vport **vports;
4535 struct lpfc_nodelist *ndlp;
4536 struct Scsi_Host *shost;
4537 int i;
4538
4539 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004540 if (!vports) {
4541 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4542 "2884 Vport array allocation failed \n");
4543 return;
4544 }
James Smartecfd03c2010-02-12 14:41:27 -05004545 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4546 shost = lpfc_shost_from_vport(vports[i]);
4547 spin_lock_irq(shost->host_lock);
4548 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart40426292010-12-15 17:58:10 -05004549 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004550 /* The mempool_alloc might sleep */
4551 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004552 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004553 spin_lock_irq(shost->host_lock);
4554 }
James Smartecfd03c2010-02-12 14:41:27 -05004555 }
4556 spin_unlock_irq(shost->host_lock);
4557 }
4558 lpfc_destroy_vport_work_array(phba, vports);
4559}
4560
James Smart92d7f7b2007-06-17 19:56:38 -05004561void
4562lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4563{
4564 struct lpfc_hba *phba = vport->phba;
4565 LPFC_MBOXQ_t *mbox;
4566 int rc;
4567
James Smart5af5eee2010-10-22 11:06:38 -04004568 if (phba->sli_rev == LPFC_SLI_REV4) {
4569 lpfc_sli4_unreg_all_rpis(vport);
4570 return;
4571 }
4572
James Smart92d7f7b2007-06-17 19:56:38 -05004573 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4574 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004575 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4576 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004577 mbox->vport = vport;
4578 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004579 mbox->context1 = NULL;
4580 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004581 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004582 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04004583
4584 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4585 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4586 "1836 Could not issue "
4587 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004588 }
4589}
4590
4591void
4592lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4593{
4594 struct lpfc_hba *phba = vport->phba;
4595 LPFC_MBOXQ_t *mbox;
4596 int rc;
4597
4598 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4599 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -04004600 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4601 mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004602 mbox->vport = vport;
4603 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004604 mbox->context1 = NULL;
4605 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004606 if (rc != MBX_TIMEOUT)
4607 mempool_free(mbox, phba->mbox_mem_pool);
4608
4609 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04004610 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4611 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04004612 "unreg_did (default rpis) status %d\n",
4613 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004614 }
4615}
4616
dea31012005-04-17 16:05:31 -05004617/*
4618 * Free resources associated with LPFC_NODELIST entry
4619 * so it can be freed.
4620 */
4621static int
James Smart2e0fef82007-06-17 19:56:36 -05004622lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004623{
James Smart2e0fef82007-06-17 19:56:36 -05004624 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4625 struct lpfc_hba *phba = vport->phba;
4626 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05004627 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05004628
4629 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04004630 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4631 "0900 Cleanup node for NPort x%x "
4632 "Data: x%x x%x x%x\n",
4633 ndlp->nlp_DID, ndlp->nlp_flag,
4634 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05004635 if (NLP_CHK_FREE_REQ(ndlp)) {
4636 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4637 "0280 lpfc_cleanup_node: ndlp:x%p "
4638 "usgmap:x%x refcnt:%d\n",
4639 (void *)ndlp, ndlp->nlp_usg_map,
4640 atomic_read(&ndlp->kref.refcount));
4641 lpfc_dequeue_node(vport, ndlp);
4642 } else {
4643 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4644 "0281 lpfc_cleanup_node: ndlp:x%p "
4645 "usgmap:x%x refcnt:%d\n",
4646 (void *)ndlp, ndlp->nlp_usg_map,
4647 atomic_read(&ndlp->kref.refcount));
4648 lpfc_disable_node(vport, ndlp);
4649 }
dea31012005-04-17 16:05:31 -05004650
James Smart086a3452012-08-14 14:25:21 -04004651
4652 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4653
dea31012005-04-17 16:05:31 -05004654 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4655 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04004656 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04004657 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
dea31012005-04-17 16:05:31 -05004658 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4659 mb->context2 = NULL;
4660 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4661 }
4662 }
James Smart33ccf8d2006-08-17 11:57:58 -04004663
James Smart2e0fef82007-06-17 19:56:36 -05004664 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04004665 /* Cleanup REG_LOGIN completions which are not yet processed */
4666 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4667 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
James Smart086a3452012-08-14 14:25:21 -04004668 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
James Smart5ac6b302010-10-22 11:05:36 -04004669 (ndlp != (struct lpfc_nodelist *) mb->context2))
4670 continue;
4671
4672 mb->context2 = NULL;
4673 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4674 }
4675
dea31012005-04-17 16:05:31 -05004676 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04004677 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart086a3452012-08-14 14:25:21 -04004678 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004679 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05004680 mp = (struct lpfc_dmabuf *) (mb->context1);
4681 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05004682 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05004683 kfree(mp);
4684 }
4685 list_del(&mb->list);
4686 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05004687 /* We shall not invoke the lpfc_nlp_put to decrement
4688 * the ndlp reference count as we are in the process
4689 * of lpfc_nlp_release.
4690 */
dea31012005-04-17 16:05:31 -05004691 }
4692 }
James Smart2e0fef82007-06-17 19:56:36 -05004693 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004694
James Smarte47c9092008-02-08 18:49:26 -05004695 lpfc_els_abort(phba, ndlp);
4696
James Smart2e0fef82007-06-17 19:56:36 -05004697 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04004698 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004699 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004700
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004701 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05004702 del_timer_sync(&ndlp->nlp_delayfunc);
4703
James Smart0d2b6b82008-06-14 22:52:47 -04004704 list_del_init(&ndlp->els_retry_evt.evt_listp);
4705 list_del_init(&ndlp->dev_loss_evt.evt_listp);
James Smart1151e3e2011-02-16 12:39:35 -05004706 lpfc_cleanup_vports_rrqs(vport, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004707 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05004708
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004709 return 0;
dea31012005-04-17 16:05:31 -05004710}
4711
4712/*
4713 * Check to see if we can free the nlp back to the freelist.
4714 * If we are in the middle of using the nlp in the discovery state
4715 * machine, defer the free till we reach the end of the state machine.
4716 */
James Smart329f9bc2007-04-25 09:53:01 -04004717static void
James Smart2e0fef82007-06-17 19:56:36 -05004718lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004719{
James Smarta8adb832007-10-27 13:37:53 -04004720 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04004721 struct lpfc_rport_data *rdata;
James Smarta8adb832007-10-27 13:37:53 -04004722 LPFC_MBOXQ_t *mbox;
4723 int rc;
dea31012005-04-17 16:05:31 -05004724
James Smart0d2b6b82008-06-14 22:52:47 -04004725 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04004726 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smart40426292010-12-15 17:58:10 -05004727 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4728 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
James Smarta8adb832007-10-27 13:37:53 -04004729 /* For this case we need to cleanup the default rpi
4730 * allocated by the firmware.
4731 */
4732 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4733 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04004734 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smart40426292010-12-15 17:58:10 -05004735 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
James Smarta8adb832007-10-27 13:37:53 -04004736 if (rc) {
4737 mempool_free(mbox, phba->mbox_mem_pool);
4738 }
4739 else {
4740 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4741 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4742 mbox->vport = vport;
James Smart086a3452012-08-14 14:25:21 -04004743 mbox->context2 = ndlp;
James Smarta8adb832007-10-27 13:37:53 -04004744 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4745 if (rc == MBX_NOT_FINISHED) {
4746 mempool_free(mbox, phba->mbox_mem_pool);
4747 }
4748 }
4749 }
4750 }
James Smart2e0fef82007-06-17 19:56:36 -05004751 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04004752
James Smart2e0fef82007-06-17 19:56:36 -05004753 /*
James Smart92d7f7b2007-06-17 19:56:38 -05004754 * We can get here with a non-NULL ndlp->rport because when we
4755 * unregister a rport we don't break the rport/node linkage. So if we
4756 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05004757 */
James Smart92d7f7b2007-06-17 19:56:38 -05004758 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04004759 rdata = ndlp->rport->dd_data;
4760 rdata->pnode = NULL;
4761 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05004762 }
dea31012005-04-17 16:05:31 -05004763}
4764
4765static int
James Smart2e0fef82007-06-17 19:56:36 -05004766lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4767 uint32_t did)
dea31012005-04-17 16:05:31 -05004768{
James Smart2e0fef82007-06-17 19:56:36 -05004769 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05004770
4771 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004772 return 0;
dea31012005-04-17 16:05:31 -05004773
dea31012005-04-17 16:05:31 -05004774 /* First check for Direct match */
4775 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004776 return 1;
dea31012005-04-17 16:05:31 -05004777
4778 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05004779 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004780 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004781 return 0;
dea31012005-04-17 16:05:31 -05004782 }
4783
4784 matchdid.un.word = did;
4785 ndlpdid.un.word = ndlp->nlp_DID;
4786 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4787 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4788 (mydid.un.b.area == matchdid.un.b.area)) {
4789 if ((ndlpdid.un.b.domain == 0) &&
4790 (ndlpdid.un.b.area == 0)) {
4791 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004792 return 1;
dea31012005-04-17 16:05:31 -05004793 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004794 return 0;
dea31012005-04-17 16:05:31 -05004795 }
4796
4797 matchdid.un.word = ndlp->nlp_DID;
4798 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4799 (mydid.un.b.area == ndlpdid.un.b.area)) {
4800 if ((matchdid.un.b.domain == 0) &&
4801 (matchdid.un.b.area == 0)) {
4802 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004803 return 1;
dea31012005-04-17 16:05:31 -05004804 }
4805 }
4806 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004807 return 0;
dea31012005-04-17 16:05:31 -05004808}
4809
James Smart685f0bf2007-04-25 09:53:08 -04004810/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05004811static struct lpfc_nodelist *
4812__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004813{
James Smart2fb9bd82006-12-02 13:33:57 -05004814 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004815 uint32_t data1;
4816
James Smart2e0fef82007-06-17 19:56:36 -05004817 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4818 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04004819 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4820 ((uint32_t) ndlp->nlp_xri << 16) |
4821 ((uint32_t) ndlp->nlp_type << 8) |
4822 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04004823 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4824 "0929 FIND node DID "
James Smartcff261f2013-12-17 20:29:47 -05004825 "Data: x%p x%x x%x x%x %p\n",
James Smarte8b62012007-08-02 11:10:09 -04004826 ndlp, ndlp->nlp_DID,
James Smartcff261f2013-12-17 20:29:47 -05004827 ndlp->nlp_flag, data1,
4828 ndlp->active_rrqs_xri_bitmap);
James Smart685f0bf2007-04-25 09:53:08 -04004829 return ndlp;
dea31012005-04-17 16:05:31 -05004830 }
4831 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004832
dea31012005-04-17 16:05:31 -05004833 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04004834 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4835 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05004836 return NULL;
4837}
4838
4839struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004840lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004841{
James Smart2e0fef82007-06-17 19:56:36 -05004842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004843 struct lpfc_nodelist *ndlp;
James Smartfedd3b72011-02-16 12:39:24 -05004844 unsigned long iflags;
dea31012005-04-17 16:05:31 -05004845
James Smartfedd3b72011-02-16 12:39:24 -05004846 spin_lock_irqsave(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05004847 ndlp = __lpfc_findnode_did(vport, did);
James Smartfedd3b72011-02-16 12:39:24 -05004848 spin_unlock_irqrestore(shost->host_lock, iflags);
James Smart2e0fef82007-06-17 19:56:36 -05004849 return ndlp;
4850}
4851
4852struct lpfc_nodelist *
4853lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4854{
4855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4856 struct lpfc_nodelist *ndlp;
4857
4858 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004859 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05004860 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4861 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05004862 return NULL;
4863 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05004864 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05004865 if (!ndlp)
4866 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004867 lpfc_nlp_init(vport, ndlp, did);
4868 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4869 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004870 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004871 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004872 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05004873 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4874 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4875 if (!ndlp)
4876 return NULL;
4877 spin_lock_irq(shost->host_lock);
4878 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4879 spin_unlock_irq(shost->host_lock);
4880 return ndlp;
dea31012005-04-17 16:05:31 -05004881 }
James Smarte47c9092008-02-08 18:49:26 -05004882
James Smart58da1ff2008-04-07 10:15:56 -04004883 if ((vport->fc_flag & FC_RSCN_MODE) &&
4884 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05004885 if (lpfc_rscn_payload_check(vport, did)) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004886 /* If we've already received a PLOGI from this NPort
James Smart87af33f2007-10-27 13:37:43 -04004887 * we don't need to try to discover it again.
4888 */
4889 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4890 return NULL;
4891
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004892 /* Since this node is marked for discovery,
4893 * delay timeout is not needed.
4894 */
James Smart0d2b6b82008-06-14 22:52:47 -04004895 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarta257bf92009-04-06 18:48:10 -04004896 spin_lock_irq(shost->host_lock);
4897 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4898 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04004899 } else
dea31012005-04-17 16:05:31 -05004900 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004901 } else {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004902 /* If we've already received a PLOGI from this NPort,
James Smart87af33f2007-10-27 13:37:43 -04004903 * or we are already in the process of discovery on it,
4904 * we don't need to try to discover it again.
4905 */
James Smart685f0bf2007-04-25 09:53:08 -04004906 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04004907 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4908 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05004909 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004910 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4911 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004912 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004913 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004914 }
4915 return ndlp;
4916}
4917
4918/* Build a list of nodes to discover based on the loopmap */
4919void
James Smart2e0fef82007-06-17 19:56:36 -05004920lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004921{
James Smart2e0fef82007-06-17 19:56:36 -05004922 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004923 int j;
4924 uint32_t alpa, index;
4925
James Smart2e0fef82007-06-17 19:56:36 -05004926 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05004927 return;
James Smart2e0fef82007-06-17 19:56:36 -05004928
James Smart76a95d72010-11-20 23:11:48 -05004929 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05004930 return;
dea31012005-04-17 16:05:31 -05004931
4932 /* Check for loop map present or not */
4933 if (phba->alpa_map[0]) {
4934 for (j = 1; j <= phba->alpa_map[0]; j++) {
4935 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05004936 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05004937 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004938 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004939 }
4940 } else {
4941 /* No alpamap, so try all alpa's */
4942 for (j = 0; j < FC_MAXLOOP; j++) {
4943 /* If cfg_scan_down is set, start from highest
4944 * ALPA (0xef) to lowest (0x1).
4945 */
James Smart3de2a652007-08-02 11:09:59 -04004946 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05004947 index = j;
4948 else
4949 index = FC_MAXLOOP - j - 1;
4950 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05004951 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05004952 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004953 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004954 }
4955 }
4956 return;
4957}
4958
dea31012005-04-17 16:05:31 -05004959void
James Smart2e0fef82007-06-17 19:56:36 -05004960lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004961{
dea31012005-04-17 16:05:31 -05004962 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05004963 struct lpfc_sli *psli = &phba->sli;
4964 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4965 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4966 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4967 int rc;
4968
James Smart92d7f7b2007-06-17 19:56:38 -05004969 /*
4970 * if it's not a physical port or if we already send
4971 * clear_la then don't send it.
4972 */
4973 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04004974 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4975 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05004976 return;
4977
James Smart2e0fef82007-06-17 19:56:36 -05004978 /* Link up discovery */
4979 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4980 phba->link_state = LPFC_CLEAR_LA;
4981 lpfc_clear_la(phba, mbox);
4982 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4983 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004984 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05004985 if (rc == MBX_NOT_FINISHED) {
4986 mempool_free(mbox, phba->mbox_mem_pool);
4987 lpfc_disc_flush_list(vport);
4988 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4989 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4990 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05004991 phba->link_state = LPFC_HBA_ERROR;
4992 }
4993 }
4994}
4995
4996/* Reg_vpi to tell firmware to resume normal operations */
4997void
4998lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4999{
5000 LPFC_MBOXQ_t *regvpimbox;
5001
5002 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5003 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04005004 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05005005 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5006 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04005007 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005008 == MBX_NOT_FINISHED) {
5009 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005010 }
5011 }
5012}
5013
5014/* Start Link up / RSCN discovery on NPR nodes */
5015void
5016lpfc_disc_start(struct lpfc_vport *vport)
5017{
5018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5019 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04005020 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05005021 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04005022 int did_changed;
dea31012005-04-17 16:05:31 -05005023
James Smarte74c03c2013-04-17 20:15:19 -04005024 if (!lpfc_is_link_up(phba)) {
5025 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5026 "3315 Link is not up %x\n",
5027 phba->link_state);
dea31012005-04-17 16:05:31 -05005028 return;
James Smarte74c03c2013-04-17 20:15:19 -04005029 }
James Smart2e0fef82007-06-17 19:56:36 -05005030
5031 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05005032 clear_la_pending = 1;
5033 else
5034 clear_la_pending = 0;
5035
James Smart2e0fef82007-06-17 19:56:36 -05005036 if (vport->port_state < LPFC_VPORT_READY)
5037 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05005038
James Smart2e0fef82007-06-17 19:56:36 -05005039 lpfc_set_disctmo(vport);
5040
5041 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05005042 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005043 else
dea31012005-04-17 16:05:31 -05005044 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05005045
5046 vport->fc_prevDID = vport->fc_myDID;
5047 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05005048
5049 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04005050 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5051 "0202 Start Discovery hba state x%x "
5052 "Data: x%x x%x x%x\n",
5053 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5054 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05005055
5056 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005057 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05005058
5059 if (num_sent)
5060 return;
5061
James Smart6fa139f2013-04-17 20:20:00 -04005062 /* Register the VPI for SLI3, NPIV only. */
James Smart92d7f7b2007-06-17 19:56:38 -05005063 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05005064 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04005065 !(vport->fc_flag & FC_RSCN_MODE) &&
5066 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart6fa139f2013-04-17 20:20:00 -04005067 if (vport->port_type == LPFC_PHYSICAL_PORT)
5068 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005069 lpfc_issue_reg_vpi(phba, vport);
5070 return;
5071 }
James Smart2e0fef82007-06-17 19:56:36 -05005072
James Smart92d7f7b2007-06-17 19:56:38 -05005073 /*
5074 * For SLI2, we need to set port_state to READY and continue
5075 * discovery.
5076 */
5077 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5078 /* If we get here, there is nothing to ADISC */
5079 if (vport->port_type == LPFC_PHYSICAL_PORT)
5080 lpfc_issue_clear_la(phba, vport);
5081
5082 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005083 vport->num_disc_nodes = 0;
5084 /* go thru NPR nodes and issue ELS PLOGIs */
5085 if (vport->fc_npr_cnt)
5086 lpfc_els_disc_plogi(vport);
5087
5088 if (!vport->num_disc_nodes) {
5089 spin_lock_irq(shost->host_lock);
5090 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5091 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005092 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05005093 }
5094 }
James Smart92d7f7b2007-06-17 19:56:38 -05005095 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005096 } else {
5097 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05005098 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05005099
5100 if (num_sent)
5101 return;
5102
James Smart2e0fef82007-06-17 19:56:36 -05005103 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05005104 /* Check to see if more RSCNs came in while we
5105 * were processing this one.
5106 */
James Smart2e0fef82007-06-17 19:56:36 -05005107 if ((vport->fc_rscn_id_cnt == 0) &&
5108 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5109 spin_lock_irq(shost->host_lock);
5110 vport->fc_flag &= ~FC_RSCN_MODE;
5111 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005112 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005113 } else
James Smart2e0fef82007-06-17 19:56:36 -05005114 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005115 }
5116 }
5117 return;
5118}
5119
5120/*
5121 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5122 * ring the match the sppecified nodelist.
5123 */
5124static void
James Smart2e0fef82007-06-17 19:56:36 -05005125lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005126{
James Smart2534ba72007-04-25 09:52:20 -04005127 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05005128 struct lpfc_sli *psli;
5129 IOCB_t *icmd;
5130 struct lpfc_iocbq *iocb, *next_iocb;
5131 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05005132
5133 psli = &phba->sli;
5134 pring = &psli->ring[LPFC_ELS_RING];
5135
5136 /* Error matching iocb on txq or txcmplq
5137 * First check the txq.
5138 */
James Smart2e0fef82007-06-17 19:56:36 -05005139 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005140 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5141 if (iocb->context1 != ndlp) {
5142 continue;
5143 }
5144 icmd = &iocb->iocb;
5145 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5146 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5147
James Smart2534ba72007-04-25 09:52:20 -04005148 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05005149 }
5150 }
5151
5152 /* Next check the txcmplq */
5153 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5154 if (iocb->context1 != ndlp) {
5155 continue;
5156 }
5157 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05005158 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5159 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04005160 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05005161 }
5162 }
James Smart2e0fef82007-06-17 19:56:36 -05005163 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005164
James Smarta257bf92009-04-06 18:48:10 -04005165 /* Cancel all the IOCBs from the completions list */
5166 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5167 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05005168}
5169
Adrian Bunka6ababd2007-11-05 18:07:33 +01005170static void
James Smart2e0fef82007-06-17 19:56:36 -05005171lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005172{
5173 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005174 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005175
James Smart2e0fef82007-06-17 19:56:36 -05005176 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5177 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005178 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005179 if (!NLP_CHK_NODE_ACT(ndlp))
5180 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005181 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5182 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5183 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04005184 }
dea31012005-04-17 16:05:31 -05005185 }
5186 }
dea31012005-04-17 16:05:31 -05005187}
5188
James Smart92d7f7b2007-06-17 19:56:38 -05005189void
5190lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5191{
5192 lpfc_els_flush_rscn(vport);
5193 lpfc_els_flush_cmd(vport);
5194 lpfc_disc_flush_list(vport);
5195}
5196
dea31012005-04-17 16:05:31 -05005197/*****************************************************************************/
5198/*
5199 * NAME: lpfc_disc_timeout
5200 *
5201 * FUNCTION: Fibre Channel driver discovery timeout routine.
5202 *
5203 * EXECUTION ENVIRONMENT: interrupt only
5204 *
5205 * CALLED FROM:
5206 * Timer function
5207 *
5208 * RETURNS:
5209 * none
5210 */
5211/*****************************************************************************/
5212void
5213lpfc_disc_timeout(unsigned long ptr)
5214{
James Smart2e0fef82007-06-17 19:56:36 -05005215 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5216 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005217 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005218 unsigned long flags = 0;
5219
5220 if (unlikely(!phba))
5221 return;
5222
James Smart5e9d9b82008-06-14 22:52:53 -04005223 spin_lock_irqsave(&vport->work_port_lock, flags);
5224 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5225 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005226 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005227 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05005228
James Smart5e9d9b82008-06-14 22:52:53 -04005229 if (!tmo_posted)
5230 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005231 return;
5232}
5233
5234static void
James Smart2e0fef82007-06-17 19:56:36 -05005235lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005236{
James Smart2e0fef82007-06-17 19:56:36 -05005237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5238 struct lpfc_hba *phba = vport->phba;
5239 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005240 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05005241 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05005242 int rc, clrlaerr = 0;
5243
James Smart2e0fef82007-06-17 19:56:36 -05005244 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05005245 return;
5246
James Smart2e0fef82007-06-17 19:56:36 -05005247 spin_lock_irq(shost->host_lock);
5248 vport->fc_flag &= ~FC_DISC_TMO;
5249 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005250
James Smart858c9f62007-06-17 19:56:39 -05005251 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5252 "disc timeout: state:x%x rtry:x%x flg:x%x",
5253 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5254
James Smart2e0fef82007-06-17 19:56:36 -05005255 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05005256
5257 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05005258 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
5259 * FAN
5260 */
5261 /* FAN timeout */
James Smarte8b62012007-08-02 11:10:09 -04005262 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5263 "0221 FAN timeout\n");
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005264 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05005265 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04005266 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005267 if (!NLP_CHK_NODE_ACT(ndlp))
5268 continue;
James Smart685f0bf2007-04-25 09:53:08 -04005269 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5270 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005271 if (ndlp->nlp_type & NLP_FABRIC) {
5272 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05005273 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005274
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005275 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005276 /* Fail outstanding IO now since device
5277 * is marked for PLOGI.
5278 */
James Smart2e0fef82007-06-17 19:56:36 -05005279 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005280 }
5281 }
James Smart92d7f7b2007-06-17 19:56:38 -05005282 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05005283 if (phba->sli_rev <= LPFC_SLI_REV3)
5284 lpfc_initial_flogi(vport);
5285 else
5286 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05005287 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005288 }
dea31012005-04-17 16:05:31 -05005289 break;
5290
James Smart92d7f7b2007-06-17 19:56:38 -05005291 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05005292 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05005293 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05005294 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04005295 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5296 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04005297 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05005298
5299 /* Assume no Fabric and go on with discovery.
5300 * Check for outstanding ELS FLOGI to abort.
5301 */
5302
5303 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05005304 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05005305
5306 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05005307 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05005308 break;
5309
5310 case LPFC_FABRIC_CFG_LINK:
5311 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5312 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04005313 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5314 "0223 Timeout while waiting for "
5315 "NameServer login\n");
dea31012005-04-17 16:05:31 -05005316 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05005317 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005318 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04005319 lpfc_els_abort(phba, ndlp);
5320
5321 /* ReStart discovery */
5322 goto restart_disc;
dea31012005-04-17 16:05:31 -05005323
5324 case LPFC_NS_QRY:
5325 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04005326 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5327 "0224 NameServer Query timeout "
5328 "Data: x%x x%x\n",
5329 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005330
James Smart92d7f7b2007-06-17 19:56:38 -05005331 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5332 /* Try it one more time */
5333 vport->fc_ns_retry++;
5334 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
5335 vport->fc_ns_retry, 0);
5336 if (rc == 0)
5337 break;
dea31012005-04-17 16:05:31 -05005338 }
James Smart92d7f7b2007-06-17 19:56:38 -05005339 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05005340
James Smart87af33f2007-10-27 13:37:43 -04005341restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05005342 /*
5343 * Discovery is over.
5344 * set port_state to PORT_READY if SLI2.
5345 * cmpl_reg_vpi will set port_state to READY for SLI3.
5346 */
James Smart3772a992009-05-22 14:50:54 -04005347 if (phba->sli_rev < LPFC_SLI_REV4) {
5348 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5349 lpfc_issue_reg_vpi(phba, vport);
James Smart6d368e52011-05-24 11:44:12 -04005350 else {
James Smart3772a992009-05-22 14:50:54 -04005351 lpfc_issue_clear_la(phba, vport);
5352 vport->port_state = LPFC_VPORT_READY;
5353 }
dea31012005-04-17 16:05:31 -05005354 }
5355
5356 /* Setup and issue mailbox INITIALIZE LINK command */
5357 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5358 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04005359 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5360 "0206 Device Discovery "
5361 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05005362 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05005363 break;
5364 }
5365
5366 lpfc_linkdown(phba);
5367 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5368 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04005369 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05005370 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05005371 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04005372 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04005373 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05005374 if (rc == MBX_NOT_FINISHED)
5375 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5376
5377 break;
5378
5379 case LPFC_DISC_AUTH:
5380 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04005381 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5382 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005383 lpfc_disc_flush_list(vport);
5384
James Smart92d7f7b2007-06-17 19:56:38 -05005385 /*
5386 * set port_state to PORT_READY if SLI2.
5387 * cmpl_reg_vpi will set port_state to READY for SLI3.
5388 */
James Smart3772a992009-05-22 14:50:54 -04005389 if (phba->sli_rev < LPFC_SLI_REV4) {
5390 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5391 lpfc_issue_reg_vpi(phba, vport);
5392 else { /* NPIV Not enabled */
5393 lpfc_issue_clear_la(phba, vport);
5394 vport->port_state = LPFC_VPORT_READY;
5395 }
dea31012005-04-17 16:05:31 -05005396 }
5397 break;
5398
James Smart2e0fef82007-06-17 19:56:36 -05005399 case LPFC_VPORT_READY:
5400 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04005401 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5402 "0231 RSCN timeout Data: x%x "
5403 "x%x\n",
5404 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05005405
5406 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05005407 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05005408
James Smart2e0fef82007-06-17 19:56:36 -05005409 lpfc_els_flush_rscn(vport);
5410 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05005411 }
5412 break;
James Smart2e0fef82007-06-17 19:56:36 -05005413
James Smart92d7f7b2007-06-17 19:56:38 -05005414 default:
James Smarte8b62012007-08-02 11:10:09 -04005415 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005416 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04005417 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005418 break;
5419 }
5420
5421 switch (phba->link_state) {
5422 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005423 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005424 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5425 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005426 clrlaerr = 1;
5427 break;
5428
James Smart09372822008-01-11 01:52:54 -05005429 case LPFC_LINK_UP:
5430 lpfc_issue_clear_la(phba, vport);
5431 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05005432 case LPFC_LINK_UNKNOWN:
5433 case LPFC_WARM_START:
5434 case LPFC_INIT_START:
5435 case LPFC_INIT_MBX_CMDS:
5436 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005437 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005438 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5439 "0230 Unexpected timeout, hba link "
5440 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005441 clrlaerr = 1;
5442 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005443
5444 case LPFC_HBA_READY:
5445 break;
dea31012005-04-17 16:05:31 -05005446 }
5447
5448 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005449 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05005450 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05005451 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5452 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05005453 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005454 }
5455
5456 return;
5457}
5458
dea31012005-04-17 16:05:31 -05005459/*
5460 * This routine handles processing a NameServer REG_LOGIN mailbox
5461 * command upon completion. It is setup in the LPFC_MBOXQ
5462 * as the completion routine when the command is
5463 * handed off to the SLI layer.
5464 */
5465void
James Smart2e0fef82007-06-17 19:56:36 -05005466lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005467{
James Smart04c68492009-05-22 14:52:52 -04005468 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05005469 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5470 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5471 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005472
5473 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04005474 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005475
James Smart6d368e52011-05-24 11:44:12 -04005476 if (phba->sli_rev < LPFC_SLI_REV4)
5477 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart40426292010-12-15 17:58:10 -05005478 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
dea31012005-04-17 16:05:31 -05005479 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005480 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05005481
James Smart2e0fef82007-06-17 19:56:36 -05005482 /*
5483 * Start issuing Fabric-Device Management Interface (FDMI) command to
5484 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5485 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05005486 */
James Smart2e0fef82007-06-17 19:56:36 -05005487
James Smart3de2a652007-08-02 11:09:59 -04005488 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05005489 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5490 else
James Smart256ec0d2013-04-17 20:14:58 -04005491 mod_timer(&vport->fc_fdmitmo,
5492 jiffies + msecs_to_jiffies(1000 * 60));
dea31012005-04-17 16:05:31 -05005493
James Smartfa4066b2008-01-11 01:53:27 -05005494 /* decrement the node reference count held for this callback
5495 * function.
5496 */
James Smart329f9bc2007-04-25 09:53:01 -04005497 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005498 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5499 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04005500 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005501
5502 return;
5503}
5504
James Smart685f0bf2007-04-25 09:53:08 -04005505static int
5506lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5507{
5508 uint16_t *rpi = param;
5509
James Smarteff4a012012-01-18 16:25:25 -05005510 /* check for active node */
5511 if (!NLP_CHK_NODE_ACT(ndlp))
5512 return 0;
5513
James Smart685f0bf2007-04-25 09:53:08 -04005514 return ndlp->nlp_rpi == *rpi;
5515}
5516
5517static int
5518lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5519{
5520 return memcmp(&ndlp->nlp_portname, param,
5521 sizeof(ndlp->nlp_portname)) == 0;
5522}
5523
Adrian Bunka6ababd2007-11-05 18:07:33 +01005524static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005525__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05005526{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005527 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005528
James Smart2e0fef82007-06-17 19:56:36 -05005529 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart34f5ad82012-08-03 12:35:03 -04005530 if (filter(ndlp, param)) {
5531 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5532 "3185 FIND node filter %p DID "
5533 "Data: x%p x%x x%x\n",
5534 filter, ndlp, ndlp->nlp_DID,
5535 ndlp->nlp_flag);
James Smart685f0bf2007-04-25 09:53:08 -04005536 return ndlp;
James Smart34f5ad82012-08-03 12:35:03 -04005537 }
James Smart685f0bf2007-04-25 09:53:08 -04005538 }
James Smart34f5ad82012-08-03 12:35:03 -04005539 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5540 "3186 FIND node filter %p NOT FOUND.\n", filter);
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005541 return NULL;
dea31012005-04-17 16:05:31 -05005542}
5543
James Smart685f0bf2007-04-25 09:53:08 -04005544/*
5545 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05005546 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04005547 */
5548struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005549__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04005550{
James Smart2e0fef82007-06-17 19:56:36 -05005551 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04005552}
5553
James Smart488d1462006-03-07 15:02:37 -05005554/*
James Smart685f0bf2007-04-25 09:53:08 -04005555 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05005556 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05005557 */
5558struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005559lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05005560{
James Smart2e0fef82007-06-17 19:56:36 -05005561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05005562 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05005563
James Smart2e0fef82007-06-17 19:56:36 -05005564 spin_lock_irq(shost->host_lock);
5565 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5566 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05005567 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05005568}
5569
James Smartcb69f7d2011-12-13 13:21:57 -05005570/*
5571 * This routine looks up the ndlp lists for the given RPI. If the rpi
5572 * is found, the routine returns the node element list pointer else
5573 * return NULL.
5574 */
5575struct lpfc_nodelist *
5576lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5577{
5578 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5579 struct lpfc_nodelist *ndlp;
5580
5581 spin_lock_irq(shost->host_lock);
5582 ndlp = __lpfc_findnode_rpi(vport, rpi);
5583 spin_unlock_irq(shost->host_lock);
5584 return ndlp;
5585}
5586
5587/**
5588 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5589 * @phba: pointer to lpfc hba data structure.
5590 * @vpi: the physical host virtual N_Port identifier.
5591 *
5592 * This routine finds a vport on a HBA (referred by @phba) through a
5593 * @vpi. The function walks the HBA's vport list and returns the address
5594 * of the vport with the matching @vpi.
5595 *
5596 * Return code
5597 * NULL - No vport with the matching @vpi found
5598 * Otherwise - Address to the vport with the matching @vpi.
5599 **/
5600struct lpfc_vport *
5601lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5602{
5603 struct lpfc_vport *vport;
5604 unsigned long flags;
5605 int i = 0;
5606
5607 /* The physical ports are always vpi 0 - translate is unnecessary. */
5608 if (vpi > 0) {
5609 /*
5610 * Translate the physical vpi to the logical vpi. The
5611 * vport stores the logical vpi.
5612 */
5613 for (i = 0; i < phba->max_vpi; i++) {
5614 if (vpi == phba->vpi_ids[i])
5615 break;
5616 }
5617
5618 if (i >= phba->max_vpi) {
5619 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5620 "2936 Could not find Vport mapped "
5621 "to vpi %d\n", vpi);
5622 return NULL;
5623 }
5624 }
5625
5626 spin_lock_irqsave(&phba->hbalock, flags);
5627 list_for_each_entry(vport, &phba->port_list, listentry) {
5628 if (vport->vpi == i) {
5629 spin_unlock_irqrestore(&phba->hbalock, flags);
5630 return vport;
5631 }
5632 }
5633 spin_unlock_irqrestore(&phba->hbalock, flags);
5634 return NULL;
5635}
5636
dea31012005-04-17 16:05:31 -05005637void
James Smart2e0fef82007-06-17 19:56:36 -05005638lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5639 uint32_t did)
dea31012005-04-17 16:05:31 -05005640{
5641 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05005642
5643 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04005644 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smartcff261f2013-12-17 20:29:47 -05005645 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
James Smart725dd392013-10-10 12:23:30 -04005646 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
James Smartcff261f2013-12-17 20:29:47 -05005647 ndlp->active_rrqs_xri_bitmap =
5648 mempool_alloc(vport->phba->active_rrq_pool,
5649 GFP_KERNEL);
James Smart59c5f612014-05-21 08:05:10 -04005650 if (ndlp->active_rrqs_xri_bitmap)
5651 memset(ndlp->active_rrqs_xri_bitmap, 0,
5652 ndlp->phba->cfg_rrq_xri_bitmap_sz);
James Smartcff261f2013-12-17 20:29:47 -05005653 }
5654
James Smart725dd392013-10-10 12:23:30 -04005655
James Smart858c9f62007-06-17 19:56:39 -05005656
5657 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5658 "node init: did:x%x",
5659 ndlp->nlp_DID, 0, 0);
5660
dea31012005-04-17 16:05:31 -05005661 return;
5662}
James Smart329f9bc2007-04-25 09:53:01 -04005663
James Smart98c9ea52007-10-27 13:37:33 -04005664/* This routine releases all resources associated with a specifc NPort's ndlp
5665 * and mempool_free's the nodelist.
5666 */
James Smart311464e2007-08-02 11:10:37 -04005667static void
James Smart329f9bc2007-04-25 09:53:01 -04005668lpfc_nlp_release(struct kref *kref)
5669{
James Smarte47c9092008-02-08 18:49:26 -05005670 struct lpfc_hba *phba;
5671 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04005672 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5673 kref);
James Smart858c9f62007-06-17 19:56:39 -05005674
5675 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5676 "node release: did:x%x flg:x%x type:x%x",
5677 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5678
James Smarte47c9092008-02-08 18:49:26 -05005679 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
James Smart939723a2012-05-09 21:19:03 -04005680 "0279 lpfc_nlp_release: ndlp:x%p did %x "
James Smarte47c9092008-02-08 18:49:26 -05005681 "usgmap:x%x refcnt:%d\n",
James Smart939723a2012-05-09 21:19:03 -04005682 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
James Smarte47c9092008-02-08 18:49:26 -05005683 atomic_read(&ndlp->kref.refcount));
5684
5685 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05005686 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05005687
5688 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04005689 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005690 spin_lock_irqsave(&phba->ndlp_lock, flags);
5691 NLP_CLR_NODE_ACT(ndlp);
5692 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart40426292010-12-15 17:58:10 -05005693 if (phba->sli_rev == LPFC_SLI_REV4)
5694 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05005695
5696 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04005697 if (NLP_CHK_FREE_REQ(ndlp)) {
5698 kfree(ndlp->lat_data);
James Smartcff261f2013-12-17 20:29:47 -05005699 if (phba->sli_rev == LPFC_SLI_REV4)
5700 mempool_free(ndlp->active_rrqs_xri_bitmap,
5701 ndlp->phba->active_rrq_pool);
James Smarta257bf92009-04-06 18:48:10 -04005702 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04005703 }
James Smart329f9bc2007-04-25 09:53:01 -04005704}
5705
James Smart98c9ea52007-10-27 13:37:33 -04005706/* This routine bumps the reference count for a ndlp structure to ensure
5707 * that one discovery thread won't free a ndlp while another discovery thread
5708 * is using it.
5709 */
James Smart329f9bc2007-04-25 09:53:01 -04005710struct lpfc_nodelist *
5711lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5712{
James Smarte47c9092008-02-08 18:49:26 -05005713 struct lpfc_hba *phba;
5714 unsigned long flags;
5715
James Smart98c9ea52007-10-27 13:37:33 -04005716 if (ndlp) {
5717 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5718 "node get: did:x%x flg:x%x refcnt:x%x",
5719 ndlp->nlp_DID, ndlp->nlp_flag,
5720 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05005721 /* The check of ndlp usage to prevent incrementing the
5722 * ndlp reference count that is in the process of being
5723 * released.
5724 */
James Smarta257bf92009-04-06 18:48:10 -04005725 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005726 spin_lock_irqsave(&phba->ndlp_lock, flags);
5727 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5728 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5729 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5730 "0276 lpfc_nlp_get: ndlp:x%p "
5731 "usgmap:x%x refcnt:%d\n",
5732 (void *)ndlp, ndlp->nlp_usg_map,
5733 atomic_read(&ndlp->kref.refcount));
5734 return NULL;
5735 } else
5736 kref_get(&ndlp->kref);
5737 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04005738 }
James Smart329f9bc2007-04-25 09:53:01 -04005739 return ndlp;
5740}
5741
James Smart98c9ea52007-10-27 13:37:33 -04005742/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05005743 * count goes to 0, this indicates the the associated nodelist should be
5744 * freed. Returning 1 indicates the ndlp resource has been released; on the
5745 * other hand, returning 0 indicates the ndlp resource has not been released
5746 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04005747 */
James Smart329f9bc2007-04-25 09:53:01 -04005748int
5749lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5750{
James Smarte47c9092008-02-08 18:49:26 -05005751 struct lpfc_hba *phba;
5752 unsigned long flags;
5753
5754 if (!ndlp)
5755 return 1;
5756
5757 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5758 "node put: did:x%x flg:x%x refcnt:x%x",
5759 ndlp->nlp_DID, ndlp->nlp_flag,
5760 atomic_read(&ndlp->kref.refcount));
James Smarta257bf92009-04-06 18:48:10 -04005761 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005762 spin_lock_irqsave(&phba->ndlp_lock, flags);
5763 /* Check the ndlp memory free acknowledge flag to avoid the
5764 * possible race condition that kref_put got invoked again
5765 * after previous one has done ndlp memory free.
5766 */
5767 if (NLP_CHK_FREE_ACK(ndlp)) {
5768 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5769 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5770 "0274 lpfc_nlp_put: ndlp:x%p "
5771 "usgmap:x%x refcnt:%d\n",
5772 (void *)ndlp, ndlp->nlp_usg_map,
5773 atomic_read(&ndlp->kref.refcount));
5774 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04005775 }
James Smarte47c9092008-02-08 18:49:26 -05005776 /* Check the ndlp inactivate log flag to avoid the possible
5777 * race condition that kref_put got invoked again after ndlp
5778 * is already in inactivating state.
5779 */
5780 if (NLP_CHK_IACT_REQ(ndlp)) {
5781 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5782 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5783 "0275 lpfc_nlp_put: ndlp:x%p "
5784 "usgmap:x%x refcnt:%d\n",
5785 (void *)ndlp, ndlp->nlp_usg_map,
5786 atomic_read(&ndlp->kref.refcount));
5787 return 1;
5788 }
5789 /* For last put, mark the ndlp usage flags to make sure no
5790 * other kref_get and kref_put on the same ndlp shall get
5791 * in between the process when the final kref_put has been
5792 * invoked on this ndlp.
5793 */
5794 if (atomic_read(&ndlp->kref.refcount) == 1) {
5795 /* Indicate ndlp is put to inactive state. */
5796 NLP_SET_IACT_REQ(ndlp);
5797 /* Acknowledge ndlp memory free has been seen. */
5798 if (NLP_CHK_FREE_REQ(ndlp))
5799 NLP_SET_FREE_ACK(ndlp);
5800 }
5801 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5802 /* Note, the kref_put returns 1 when decrementing a reference
5803 * count that was 1, it invokes the release callback function,
5804 * but it still left the reference count as 1 (not actually
5805 * performs the last decrementation). Otherwise, it actually
5806 * decrements the reference count and returns 0.
5807 */
5808 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04005809}
James Smart98c9ea52007-10-27 13:37:33 -04005810
5811/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05005812 * by any other discovery thread. This routine returns 1 if the
5813 * ndlp has been freed. A return value of 0 indicates the ndlp is
5814 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04005815 */
5816int
5817lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5818{
5819 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5820 "node not used: did:x%x flg:x%x refcnt:x%x",
5821 ndlp->nlp_DID, ndlp->nlp_flag,
5822 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05005823 if (atomic_read(&ndlp->kref.refcount) == 1)
5824 if (lpfc_nlp_put(ndlp))
5825 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04005826 return 0;
5827}
James Smart6fb120a2009-05-22 14:52:59 -04005828
5829/**
5830 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5831 * @phba: Pointer to hba context object.
5832 *
5833 * This function iterate through all FC nodes associated
5834 * will all vports to check if there is any node with
5835 * fc_rports associated with it. If there is an fc_rport
5836 * associated with the node, then the node is either in
5837 * discovered state or its devloss_timer is pending.
5838 */
5839static int
5840lpfc_fcf_inuse(struct lpfc_hba *phba)
5841{
5842 struct lpfc_vport **vports;
5843 int i, ret = 0;
5844 struct lpfc_nodelist *ndlp;
5845 struct Scsi_Host *shost;
5846
5847 vports = lpfc_create_vport_work_array(phba);
5848
James Smart63e801c2010-11-20 23:14:19 -05005849 /* If driver cannot allocate memory, indicate fcf is in use */
5850 if (!vports)
5851 return 1;
5852
James Smart6fb120a2009-05-22 14:52:59 -04005853 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5854 shost = lpfc_shost_from_vport(vports[i]);
5855 spin_lock_irq(shost->host_lock);
James Smart05580562011-05-24 11:40:48 -04005856 /*
5857 * IF the CVL_RCVD bit is not set then we have sent the
5858 * flogi.
5859 * If dev_loss fires while we are waiting we do not want to
5860 * unreg the fcf.
5861 */
5862 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
5863 spin_unlock_irq(shost->host_lock);
5864 ret = 1;
5865 goto out;
5866 }
James Smart6fb120a2009-05-22 14:52:59 -04005867 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5868 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5869 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5870 ret = 1;
5871 spin_unlock_irq(shost->host_lock);
5872 goto out;
James Smart80c17842012-03-01 22:35:45 -05005873 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5874 ret = 1;
James Smart891478a2009-11-18 15:40:23 -05005875 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart80c17842012-03-01 22:35:45 -05005876 "2624 RPI %x DID %x flag %x "
5877 "still logged in\n",
5878 ndlp->nlp_rpi, ndlp->nlp_DID,
5879 ndlp->nlp_flag);
James Smart6fb120a2009-05-22 14:52:59 -04005880 }
5881 }
5882 spin_unlock_irq(shost->host_lock);
5883 }
5884out:
5885 lpfc_destroy_vport_work_array(phba, vports);
5886 return ret;
5887}
5888
5889/**
5890 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5891 * @phba: Pointer to hba context object.
5892 * @mboxq: Pointer to mailbox object.
5893 *
5894 * This function frees memory associated with the mailbox command.
5895 */
James Smart1b511972011-12-13 13:23:09 -05005896void
James Smart6fb120a2009-05-22 14:52:59 -04005897lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5898{
5899 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04005900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04005901
5902 if (mboxq->u.mb.mbxStatus) {
5903 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5904 "2555 UNREG_VFI mbxStatus error x%x "
5905 "HBA state x%x\n",
5906 mboxq->u.mb.mbxStatus, vport->port_state);
5907 }
James Smart38b92ef2010-08-04 16:11:39 -04005908 spin_lock_irq(shost->host_lock);
5909 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5910 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005911 mempool_free(mboxq, phba->mbox_mem_pool);
5912 return;
5913}
5914
5915/**
5916 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5917 * @phba: Pointer to hba context object.
5918 * @mboxq: Pointer to mailbox object.
5919 *
5920 * This function frees memory associated with the mailbox command.
5921 */
5922static void
5923lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5924{
5925 struct lpfc_vport *vport = mboxq->vport;
5926
5927 if (mboxq->u.mb.mbxStatus) {
5928 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5929 "2550 UNREG_FCFI mbxStatus error x%x "
5930 "HBA state x%x\n",
5931 mboxq->u.mb.mbxStatus, vport->port_state);
5932 }
5933 mempool_free(mboxq, phba->mbox_mem_pool);
5934 return;
5935}
5936
5937/**
James Smartecfd03c2010-02-12 14:41:27 -05005938 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04005939 * @phba: Pointer to hba context object.
5940 *
James Smartecfd03c2010-02-12 14:41:27 -05005941 * This function prepare the HBA for unregistering the currently registered
5942 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5943 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04005944 */
James Smartecfd03c2010-02-12 14:41:27 -05005945int
5946lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04005947{
James Smart6fb120a2009-05-22 14:52:59 -04005948 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05005949 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05005950 struct Scsi_Host *shost;
James Smarte74c03c2013-04-17 20:15:19 -04005951 int i = 0, rc;
James Smart6fb120a2009-05-22 14:52:59 -04005952
James Smartecfd03c2010-02-12 14:41:27 -05005953 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04005954 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05005955 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04005956
James Smart4d9ab992009-10-02 15:16:39 -04005957 /* At this point, all discovery is aborted */
5958 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04005959
5960 /* Unregister VPIs */
5961 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05005962 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04005963 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05005964 /* Stop FLOGI/FDISC retries */
5965 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5966 if (ndlp)
5967 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04005968 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04005969 if (phba->sli_rev == LPFC_SLI_REV4)
5970 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04005971 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05005972 shost = lpfc_shost_from_vport(vports[i]);
5973 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05005974 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05005975 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05005976 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005977 }
5978 lpfc_destroy_vport_work_array(phba, vports);
James Smarte74c03c2013-04-17 20:15:19 -04005979 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
5980 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
5981 if (ndlp)
5982 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
5983 lpfc_cleanup_pending_mbox(phba->pport);
5984 if (phba->sli_rev == LPFC_SLI_REV4)
5985 lpfc_sli4_unreg_all_rpis(phba->pport);
5986 lpfc_mbx_unreg_vpi(phba->pport);
5987 shost = lpfc_shost_from_vport(phba->pport);
5988 spin_lock_irq(shost->host_lock);
5989 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
5990 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
5991 spin_unlock_irq(shost->host_lock);
5992 }
James Smart6fb120a2009-05-22 14:52:59 -04005993
James Smart695a8142010-01-26 23:08:03 -05005994 /* Cleanup any outstanding ELS commands */
5995 lpfc_els_flush_all_cmd(phba);
5996
James Smart1b511972011-12-13 13:23:09 -05005997 /* Unregister the physical port VFI */
5998 rc = lpfc_issue_unreg_vfi(phba->pport);
5999 return rc;
James Smartecfd03c2010-02-12 14:41:27 -05006000}
6001
6002/**
6003 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6004 * @phba: Pointer to hba context object.
6005 *
6006 * This function issues synchronous unregister FCF mailbox command to HBA to
6007 * unregister the currently registered FCF record. The driver does not reset
6008 * the driver FCF usage state flags.
6009 *
6010 * Return 0 if successfully issued, none-zero otherwise.
6011 */
6012int
6013lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6014{
6015 LPFC_MBOXQ_t *mbox;
6016 int rc;
6017
James Smart6fb120a2009-05-22 14:52:59 -04006018 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6019 if (!mbox) {
6020 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006021 "2551 UNREG_FCFI mbox allocation failed"
6022 "HBA state x%x\n", phba->pport->port_state);
6023 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04006024 }
James Smart6fb120a2009-05-22 14:52:59 -04006025 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6026 mbox->vport = phba->pport;
6027 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6028 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6029
6030 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05006031 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6032 "2552 Unregister FCFI command failed rc x%x "
6033 "HBA state x%x\n",
6034 rc, phba->pport->port_state);
6035 return -EINVAL;
6036 }
6037 return 0;
6038}
6039
6040/**
6041 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6042 * @phba: Pointer to hba context object.
6043 *
6044 * This function unregisters the currently reigstered FCF. This function
6045 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6046 */
6047void
6048lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6049{
6050 int rc;
6051
6052 /* Preparation for unregistering fcf */
6053 rc = lpfc_unregister_fcf_prep(phba);
6054 if (rc) {
6055 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6056 "2748 Failed to prepare for unregistering "
6057 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04006058 return;
6059 }
6060
James Smartecfd03c2010-02-12 14:41:27 -05006061 /* Now, unregister FCF record and reset HBA FCF state */
6062 rc = lpfc_sli4_unregister_fcf(phba);
6063 if (rc)
6064 return;
6065 /* Reset HBA FCF states after successful unregister FCF */
6066 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05006067 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04006068
6069 /*
6070 * If driver is not unloading, check if there is any other
6071 * FCF record that can be used for discovery.
6072 */
6073 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05006074 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04006075 return;
6076
James Smart0c9ab6f2010-02-26 14:15:57 -05006077 /* This is considered as the initial FCF discovery scan */
6078 spin_lock_irq(&phba->hbalock);
6079 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6080 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04006081
6082 /* Reset FCF roundrobin bmask for new discovery */
James Smart7d791df2011-07-22 18:37:52 -04006083 lpfc_sli4_clear_fcf_rr_bmask(phba);
James Smart38b92ef2010-08-04 16:11:39 -04006084
James Smart0c9ab6f2010-02-26 14:15:57 -05006085 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04006086
James Smart0c9ab6f2010-02-26 14:15:57 -05006087 if (rc) {
6088 spin_lock_irq(&phba->hbalock);
6089 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6090 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04006091 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05006092 "2553 lpfc_unregister_unused_fcf failed "
6093 "to read FCF record HBA state x%x\n",
6094 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05006095 }
James Smartecfd03c2010-02-12 14:41:27 -05006096}
6097
6098/**
6099 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6100 * @phba: Pointer to hba context object.
6101 *
6102 * This function just unregisters the currently reigstered FCF. It does not
6103 * try to find another FCF for discovery.
6104 */
6105void
6106lpfc_unregister_fcf(struct lpfc_hba *phba)
6107{
6108 int rc;
6109
6110 /* Preparation for unregistering fcf */
6111 rc = lpfc_unregister_fcf_prep(phba);
6112 if (rc) {
6113 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6114 "2749 Failed to prepare for unregistering "
6115 "HBA's FCF record: rc=%d\n", rc);
6116 return;
6117 }
6118
6119 /* Now, unregister FCF record and reset HBA FCF state */
6120 rc = lpfc_sli4_unregister_fcf(phba);
6121 if (rc)
6122 return;
6123 /* Set proper HBA FCF states after successful unregister FCF */
6124 spin_lock_irq(&phba->hbalock);
6125 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6126 spin_unlock_irq(&phba->hbalock);
6127}
6128
6129/**
6130 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6131 * @phba: Pointer to hba context object.
6132 *
6133 * This function check if there are any connected remote port for the FCF and
6134 * if all the devices are disconnected, this function unregister FCFI.
6135 * This function also tries to use another FCF for discovery.
6136 */
6137void
6138lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6139{
6140 /*
James Smart3804dc82010-07-14 15:31:37 -04006141 * If HBA is not running in FIP mode, if HBA does not support
6142 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6143 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05006144 */
6145 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05006146 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05006147 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006148 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04006149 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04006150 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05006151 spin_unlock_irq(&phba->hbalock);
6152 return;
6153 }
6154 spin_unlock_irq(&phba->hbalock);
6155
6156 if (lpfc_fcf_inuse(phba))
6157 return;
6158
6159 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04006160}
6161
6162/**
6163 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6164 * @phba: Pointer to hba context object.
6165 * @buff: Buffer containing the FCF connection table as in the config
6166 * region.
6167 * This function create driver data structure for the FCF connection
6168 * record table read from config region 23.
6169 */
6170static void
6171lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6172 uint8_t *buff)
6173{
6174 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6175 struct lpfc_fcf_conn_hdr *conn_hdr;
6176 struct lpfc_fcf_conn_rec *conn_rec;
6177 uint32_t record_count;
6178 int i;
6179
6180 /* Free the current connect table */
6181 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04006182 &phba->fcf_conn_rec_list, list) {
6183 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04006184 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04006185 }
James Smart6fb120a2009-05-22 14:52:59 -04006186
6187 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6188 record_count = conn_hdr->length * sizeof(uint32_t)/
6189 sizeof(struct lpfc_fcf_conn_rec);
6190
6191 conn_rec = (struct lpfc_fcf_conn_rec *)
6192 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6193
6194 for (i = 0; i < record_count; i++) {
6195 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6196 continue;
6197 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6198 GFP_KERNEL);
6199 if (!conn_entry) {
6200 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6201 "2566 Failed to allocate connection"
6202 " table entry\n");
6203 return;
6204 }
6205
6206 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6207 sizeof(struct lpfc_fcf_conn_rec));
James Smart6fb120a2009-05-22 14:52:59 -04006208 list_add_tail(&conn_entry->list,
6209 &phba->fcf_conn_rec_list);
6210 }
James Smartdf0d0852013-05-31 17:05:08 -04006211
6212 if (!list_empty(&phba->fcf_conn_rec_list)) {
6213 i = 0;
6214 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6215 list) {
6216 conn_rec = &conn_entry->conn_rec;
6217 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6218 "3345 FCF connection list rec[%02d]: "
6219 "flags:x%04x, vtag:x%04x, "
6220 "fabric_name:x%02x:%02x:%02x:%02x:"
6221 "%02x:%02x:%02x:%02x, "
6222 "switch_name:x%02x:%02x:%02x:%02x:"
6223 "%02x:%02x:%02x:%02x\n", i++,
6224 conn_rec->flags, conn_rec->vlan_tag,
6225 conn_rec->fabric_name[0],
6226 conn_rec->fabric_name[1],
6227 conn_rec->fabric_name[2],
6228 conn_rec->fabric_name[3],
6229 conn_rec->fabric_name[4],
6230 conn_rec->fabric_name[5],
6231 conn_rec->fabric_name[6],
6232 conn_rec->fabric_name[7],
6233 conn_rec->switch_name[0],
6234 conn_rec->switch_name[1],
6235 conn_rec->switch_name[2],
6236 conn_rec->switch_name[3],
6237 conn_rec->switch_name[4],
6238 conn_rec->switch_name[5],
6239 conn_rec->switch_name[6],
6240 conn_rec->switch_name[7]);
6241 }
6242 }
James Smart6fb120a2009-05-22 14:52:59 -04006243}
6244
6245/**
6246 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6247 * @phba: Pointer to hba context object.
6248 * @buff: Buffer containing the FCoE parameter data structure.
6249 *
6250 * This function update driver data structure with config
6251 * parameters read from config region 23.
6252 */
6253static void
6254lpfc_read_fcoe_param(struct lpfc_hba *phba,
6255 uint8_t *buff)
6256{
6257 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6258 struct lpfc_fcoe_params *fcoe_param;
6259
6260 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6261 buff;
6262 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04006263 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04006264
6265 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6266 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6267 return;
6268
James Smart6fb120a2009-05-22 14:52:59 -04006269 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6270 phba->valid_vlan = 1;
6271 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6272 0xFFF;
6273 }
6274
6275 phba->fc_map[0] = fcoe_param->fc_map[0];
6276 phba->fc_map[1] = fcoe_param->fc_map[1];
6277 phba->fc_map[2] = fcoe_param->fc_map[2];
6278 return;
6279}
6280
6281/**
6282 * lpfc_get_rec_conf23 - Get a record type in config region data.
6283 * @buff: Buffer containing config region 23 data.
6284 * @size: Size of the data buffer.
6285 * @rec_type: Record type to be searched.
6286 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006287 * This function searches config region data to find the beginning
James Smart6fb120a2009-05-22 14:52:59 -04006288 * of the record specified by record_type. If record found, this
6289 * function return pointer to the record else return NULL.
6290 */
6291static uint8_t *
6292lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6293{
6294 uint32_t offset = 0, rec_length;
6295
6296 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6297 (size < sizeof(uint32_t)))
6298 return NULL;
6299
6300 rec_length = buff[offset + 1];
6301
6302 /*
6303 * One TLV record has one word header and number of data words
6304 * specified in the rec_length field of the record header.
6305 */
6306 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6307 <= size) {
6308 if (buff[offset] == rec_type)
6309 return &buff[offset];
6310
6311 if (buff[offset] == LPFC_REGION23_LAST_REC)
6312 return NULL;
6313
6314 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6315 rec_length = buff[offset + 1];
6316 }
6317 return NULL;
6318}
6319
6320/**
6321 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6322 * @phba: Pointer to lpfc_hba data structure.
6323 * @buff: Buffer containing config region 23 data.
6324 * @size: Size of the data buffer.
6325 *
Stefan Weileef35c22010-08-06 21:11:15 +02006326 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04006327 * populate driver data structure with the parameters.
6328 */
6329void
6330lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6331 uint8_t *buff,
6332 uint32_t size)
6333{
6334 uint32_t offset = 0, rec_length;
6335 uint8_t *rec_ptr;
6336
6337 /*
6338 * If data size is less than 2 words signature and version cannot be
6339 * verified.
6340 */
6341 if (size < 2*sizeof(uint32_t))
6342 return;
6343
6344 /* Check the region signature first */
6345 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6346 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6347 "2567 Config region 23 has bad signature\n");
6348 return;
6349 }
6350
6351 offset += 4;
6352
6353 /* Check the data structure version */
6354 if (buff[offset] != LPFC_REGION23_VERSION) {
6355 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6356 "2568 Config region 23 has bad version\n");
6357 return;
6358 }
6359 offset += 4;
6360
6361 rec_length = buff[offset + 1];
6362
6363 /* Read FCoE param record */
6364 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6365 size - offset, FCOE_PARAM_TYPE);
6366 if (rec_ptr)
6367 lpfc_read_fcoe_param(phba, rec_ptr);
6368
6369 /* Read FCF connection table */
6370 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6371 size - offset, FCOE_CONN_TBL_TYPE);
6372 if (rec_ptr)
6373 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
6374
6375}