[SCSI] lpfc 8.3.19: Add SLI4 FC Discovery support
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_hbadisc.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
d8e93df1 4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * 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. *
dea3101e 20 *******************************************************************/
21
dea3101e 22#include <linux/blkdev.h>
a93ff37a 23#include <linux/delay.h>
5a0e3ad6 24#include <linux/slab.h>
dea3101e 25#include <linux/pci.h>
26#include <linux/kthread.h>
27#include <linux/interrupt.h>
28
91886523 29#include <scsi/scsi.h>
dea3101e 30#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
33
da0436e9 34#include "lpfc_hw4.h"
dea3101e 35#include "lpfc_hw.h"
ea2151b4 36#include "lpfc_nl.h"
dea3101e 37#include "lpfc_disc.h"
38#include "lpfc_sli.h"
da0436e9 39#include "lpfc_sli4.h"
dea3101e 40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
92d7f7b0 44#include "lpfc_vport.h"
858c9f6c 45#include "lpfc_debugfs.h"
dea3101e 46
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
2e0fef85 64static void lpfc_disc_timeout_handler(struct lpfc_vport *);
a6ababd2 65static void lpfc_disc_flush_list(struct lpfc_vport *vport);
32b9793f 66static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
a93ff37a 67static int lpfc_fcf_inuse(struct lpfc_hba *);
dea3101e 68
c01f3208
JS
69void
70lpfc_terminate_rport_io(struct fc_rport *rport)
dea3101e 71{
c01f3208
JS
72 struct lpfc_rport_data *rdata;
73 struct lpfc_nodelist * ndlp;
74 struct lpfc_hba *phba;
dea3101e 75
c01f3208
JS
76 rdata = rport->dd_data;
77 ndlp = rdata->pnode;
78
58da1ffb 79 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
c01f3208
JS
80 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);
dea3101e 84 return;
85 }
86
a257bf90 87 phba = ndlp->phba;
c01f3208 88
858c9f6c
JS
89 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
c01f3208 93 if (ndlp->nlp_sid != NLP_NO_SID) {
51ef4c26
JS
94 lpfc_sli_abort_iocb(ndlp->vport,
95 &phba->sli.ring[phba->sli.fcp_ring],
96 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
c01f3208 97 }
c01f3208
JS
98}
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;
2e0fef85 108 struct lpfc_vport *vport;
858c9f6c 109 struct lpfc_hba *phba;
858c9f6c 110 struct lpfc_work_evt *evtp;
a8adb832
JS
111 int put_node;
112 int put_rport;
c01f3208
JS
113
114 rdata = rport->dd_data;
115 ndlp = rdata->pnode;
58da1ffb 116 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
c01f3208 117 return;
c01f3208 118
858c9f6c
JS
119 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
a8adb832
JS
126 /* Don't defer this if we are in the process of deleting the vport
127 * or unloading the driver. The unload will cleanup the node
128 * appropriately we just need to cleanup the ndlp rport info here.
129 */
130 if (vport->load_flag & FC_UNLOADING) {
131 put_node = rdata->pnode != NULL;
132 put_rport = ndlp->rport != NULL;
133 rdata->pnode = NULL;
134 ndlp->rport = NULL;
135 if (put_node)
136 lpfc_nlp_put(ndlp);
137 if (put_rport)
138 put_device(&rport->dev);
139 return;
140 }
141
142 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
143 return;
144
858c9f6c
JS
145 evtp = &ndlp->dev_loss_evt;
146
147 if (!list_empty(&evtp->evt_listp))
148 return;
149
150 spin_lock_irq(&phba->hbalock);
fa4066b6
JS
151 /* We need to hold the node by incrementing the reference
152 * count until this queued work is done
153 */
154 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
5e9d9b82
JS
155 if (evtp->evt_arg1) {
156 evtp->evt = LPFC_EVT_DEV_LOSS;
157 list_add_tail(&evtp->evt_listp, &phba->work_list);
158 lpfc_worker_wake_up(phba);
159 }
858c9f6c
JS
160 spin_unlock_irq(&phba->hbalock);
161
858c9f6c
JS
162 return;
163}
164
a93ff37a
JS
165/**
166 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
167 * @ndlp: Pointer to remote node object.
168 *
169 * This function is called from the worker thread when devloss timeout timer
170 * expires. For SLI4 host, this routine shall return 1 when at lease one
171 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
172 * routine shall return 0 when there is no remote node is still in use of FCF
173 * when devloss timeout happened to this @ndlp.
174 **/
175static int
858c9f6c
JS
176lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
177{
178 struct lpfc_rport_data *rdata;
179 struct fc_rport *rport;
180 struct lpfc_vport *vport;
181 struct lpfc_hba *phba;
182 uint8_t *name;
87af33fe
JS
183 int put_node;
184 int put_rport;
858c9f6c 185 int warn_on = 0;
a93ff37a 186 int fcf_inuse = 0;
858c9f6c
JS
187
188 rport = ndlp->rport;
189
190 if (!rport)
a93ff37a 191 return fcf_inuse;
858c9f6c
JS
192
193 rdata = rport->dd_data;
194 name = (uint8_t *) &ndlp->nlp_portname;
195 vport = ndlp->vport;
196 phba = vport->phba;
197
a93ff37a
JS
198 if (phba->sli_rev == LPFC_SLI_REV4)
199 fcf_inuse = lpfc_fcf_inuse(phba);
200
858c9f6c
JS
201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
202 "rport devlosstmo:did:x%x type:x%x id:x%x",
203 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
204
a8adb832
JS
205 /* Don't defer this if we are in the process of deleting the vport
206 * or unloading the driver. The unload will cleanup the node
207 * appropriately we just need to cleanup the ndlp rport info here.
208 */
209 if (vport->load_flag & FC_UNLOADING) {
09372820
JS
210 if (ndlp->nlp_sid != NLP_NO_SID) {
211 /* flush the target */
212 lpfc_sli_abort_iocb(vport,
213 &phba->sli.ring[phba->sli.fcp_ring],
214 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
215 }
a8adb832
JS
216 put_node = rdata->pnode != NULL;
217 put_rport = ndlp->rport != NULL;
218 rdata->pnode = NULL;
219 ndlp->rport = NULL;
220 if (put_node)
221 lpfc_nlp_put(ndlp);
222 if (put_rport)
223 put_device(&rport->dev);
a93ff37a 224 return fcf_inuse;
a8adb832
JS
225 }
226
d7c255b2
JS
227 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
228 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
229 "0284 Devloss timeout Ignored on "
230 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
231 "NPort x%x\n",
232 *name, *(name+1), *(name+2), *(name+3),
233 *(name+4), *(name+5), *(name+6), *(name+7),
234 ndlp->nlp_DID);
a93ff37a 235 return fcf_inuse;
d7c255b2 236 }
858c9f6c 237
92d7f7b0
JS
238 if (ndlp->nlp_type & NLP_FABRIC) {
239 /* We will clean up these Nodes in linkup */
240 put_node = rdata->pnode != NULL;
241 put_rport = ndlp->rport != NULL;
242 rdata->pnode = NULL;
243 ndlp->rport = NULL;
244 if (put_node)
245 lpfc_nlp_put(ndlp);
246 if (put_rport)
247 put_device(&rport->dev);
a93ff37a 248 return fcf_inuse;
92d7f7b0 249 }
82085718 250
dea3101e 251 if (ndlp->nlp_sid != NLP_NO_SID) {
6e8215e4 252 warn_on = 1;
dea3101e 253 /* flush the target */
51ef4c26
JS
254 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
255 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea3101e 256 }
c01f3208 257
6e8215e4 258 if (warn_on) {
e8b62011
JS
259 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
260 "0203 Devloss timeout on "
58da1ffb
JS
261 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
262 "NPort x%06x Data: x%x x%x x%x\n",
e8b62011
JS
263 *name, *(name+1), *(name+2), *(name+3),
264 *(name+4), *(name+5), *(name+6), *(name+7),
265 ndlp->nlp_DID, ndlp->nlp_flag,
266 ndlp->nlp_state, ndlp->nlp_rpi);
6e8215e4 267 } else {
e8b62011
JS
268 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
269 "0204 Devloss timeout on "
58da1ffb
JS
270 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
271 "NPort x%06x Data: x%x x%x x%x\n",
e8b62011
JS
272 *name, *(name+1), *(name+2), *(name+3),
273 *(name+4), *(name+5), *(name+6), *(name+7),
274 ndlp->nlp_DID, ndlp->nlp_flag,
275 ndlp->nlp_state, ndlp->nlp_rpi);
6e8215e4
JSEC
276 }
277
87af33fe
JS
278 put_node = rdata->pnode != NULL;
279 put_rport = ndlp->rport != NULL;
280 rdata->pnode = NULL;
281 ndlp->rport = NULL;
282 if (put_node)
283 lpfc_nlp_put(ndlp);
284 if (put_rport)
285 put_device(&rport->dev);
286
2e0fef85 287 if (!(vport->load_flag & FC_UNLOADING) &&
1dcb58e5 288 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
82085718 289 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
ffc95493 290 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
589a52d6
JS
291 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
292 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
2e0fef85 293 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
6fb120a7 294
a93ff37a
JS
295 return fcf_inuse;
296}
297
298/**
299 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
300 * @phba: Pointer to hba context object.
301 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
302 * @nlp_did: remote node identifer with devloss timeout.
303 *
304 * This function is called from the worker thread after invoking devloss
305 * timeout handler and releasing the reference count for the ndlp with
306 * which the devloss timeout was handled for SLI4 host. For the devloss
307 * timeout of the last remote node which had been in use of FCF, when this
308 * routine is invoked, it shall be guaranteed that none of the remote are
309 * in-use of FCF. When devloss timeout to the last remote using the FCF,
310 * if the FIP engine is neither in FCF table scan process nor roundrobin
311 * failover process, the in-use FCF shall be unregistered. If the FIP
312 * engine is in FCF discovery process, the devloss timeout state shall
313 * be set for either the FCF table scan process or roundrobin failover
314 * process to unregister the in-use FCF.
315 **/
316static void
317lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
318 uint32_t nlp_did)
319{
320 /* If devloss timeout happened to a remote node when FCF had no
321 * longer been in-use, do nothing.
322 */
323 if (!fcf_inuse)
324 return;
325
326 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
327 spin_lock_irq(&phba->hbalock);
328 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
329 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
330 spin_unlock_irq(&phba->hbalock);
331 return;
332 }
333 phba->hba_flag |= HBA_DEVLOSS_TMO;
334 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
335 "2847 Last remote node (x%x) using "
336 "FCF devloss tmo\n", nlp_did);
337 }
338 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
339 spin_unlock_irq(&phba->hbalock);
340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
341 "2868 Devloss tmo to FCF rediscovery "
342 "in progress\n");
343 return;
344 }
345 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
346 spin_unlock_irq(&phba->hbalock);
347 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
348 "2869 Devloss tmo to idle FIP engine, "
349 "unreg in-use FCF and rescan.\n");
350 /* Unregister in-use FCF and rescan */
351 lpfc_unregister_fcf_rescan(phba);
352 return;
353 }
354 spin_unlock_irq(&phba->hbalock);
355 if (phba->hba_flag & FCF_TS_INPROG)
356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
357 "2870 FCF table scan in progress\n");
358 if (phba->hba_flag & FCF_RR_INPROG)
359 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
360 "2871 FLOGI roundrobin FCF failover "
361 "in progress\n");
362 }
6fb120a7 363 lpfc_unregister_unused_fcf(phba);
92d7f7b0 364}
c01f3208 365
ea2151b4 366/**
3621a710 367 * lpfc_alloc_fast_evt - Allocates data structure for posting event
ea2151b4
JS
368 * @phba: Pointer to hba context object.
369 *
370 * This function is called from the functions which need to post
371 * events from interrupt context. This function allocates data
372 * structure required for posting event. It also keeps track of
373 * number of events pending and prevent event storm when there are
374 * too many events.
375 **/
376struct lpfc_fast_path_event *
377lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
378 struct lpfc_fast_path_event *ret;
379
380 /* If there are lot of fast event do not exhaust memory due to this */
381 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
382 return NULL;
383
384 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
385 GFP_ATOMIC);
6fb120a7 386 if (ret) {
ea2151b4 387 atomic_inc(&phba->fast_event_count);
6fb120a7
JS
388 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
389 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
390 }
ea2151b4
JS
391 return ret;
392}
393
394/**
3621a710 395 * lpfc_free_fast_evt - Frees event data structure
ea2151b4
JS
396 * @phba: Pointer to hba context object.
397 * @evt: Event object which need to be freed.
398 *
399 * This function frees the data structure required for posting
400 * events.
401 **/
402void
403lpfc_free_fast_evt(struct lpfc_hba *phba,
404 struct lpfc_fast_path_event *evt) {
405
406 atomic_dec(&phba->fast_event_count);
407 kfree(evt);
408}
409
410/**
3621a710 411 * lpfc_send_fastpath_evt - Posts events generated from fast path
ea2151b4
JS
412 * @phba: Pointer to hba context object.
413 * @evtp: Event data structure.
414 *
415 * This function is called from worker thread, when the interrupt
416 * context need to post an event. This function posts the event
417 * to fc transport netlink interface.
418 **/
419static void
420lpfc_send_fastpath_evt(struct lpfc_hba *phba,
421 struct lpfc_work_evt *evtp)
422{
423 unsigned long evt_category, evt_sub_category;
424 struct lpfc_fast_path_event *fast_evt_data;
425 char *evt_data;
426 uint32_t evt_data_size;
427 struct Scsi_Host *shost;
428
429 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
430 work_evt);
431
432 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
433 evt_sub_category = (unsigned long) fast_evt_data->un.
434 fabric_evt.subcategory;
435 shost = lpfc_shost_from_vport(fast_evt_data->vport);
436 if (evt_category == FC_REG_FABRIC_EVENT) {
437 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
438 evt_data = (char *) &fast_evt_data->un.read_check_error;
439 evt_data_size = sizeof(fast_evt_data->un.
440 read_check_error);
441 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
eaf15d5b 442 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
ea2151b4
JS
443 evt_data = (char *) &fast_evt_data->un.fabric_evt;
444 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
445 } else {
446 lpfc_free_fast_evt(phba, fast_evt_data);
447 return;
448 }
449 } else if (evt_category == FC_REG_SCSI_EVENT) {
450 switch (evt_sub_category) {
451 case LPFC_EVENT_QFULL:
452 case LPFC_EVENT_DEVBSY:
453 evt_data = (char *) &fast_evt_data->un.scsi_evt;
454 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
455 break;
456 case LPFC_EVENT_CHECK_COND:
457 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
458 evt_data_size = sizeof(fast_evt_data->un.
459 check_cond_evt);
460 break;
461 case LPFC_EVENT_VARQUEDEPTH:
462 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
463 evt_data_size = sizeof(fast_evt_data->un.
464 queue_depth_evt);
465 break;
466 default:
467 lpfc_free_fast_evt(phba, fast_evt_data);
468 return;
469 }
470 } else {
471 lpfc_free_fast_evt(phba, fast_evt_data);
472 return;
473 }
474
475 fc_host_post_vendor_event(shost,
476 fc_get_event_number(),
477 evt_data_size,
478 evt_data,
ddcc50f0 479 LPFC_NL_VENDOR_ID);
ea2151b4
JS
480
481 lpfc_free_fast_evt(phba, fast_evt_data);
482 return;
483}
484
dea3101e 485static void
2e0fef85 486lpfc_work_list_done(struct lpfc_hba *phba)
dea3101e 487{
488 struct lpfc_work_evt *evtp = NULL;
489 struct lpfc_nodelist *ndlp;
490 int free_evt;
a93ff37a
JS
491 int fcf_inuse;
492 uint32_t nlp_did;
dea3101e 493
2e0fef85
JS
494 spin_lock_irq(&phba->hbalock);
495 while (!list_empty(&phba->work_list)) {
dea3101e 496 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
497 evt_listp);
2e0fef85 498 spin_unlock_irq(&phba->hbalock);
dea3101e 499 free_evt = 1;
2fe165b6 500 switch (evtp->evt) {
dea3101e 501 case LPFC_EVT_ELS_RETRY:
2e0fef85 502 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea3101e 503 lpfc_els_retry_delay_handler(ndlp);
92d7f7b0 504 free_evt = 0; /* evt is part of ndlp */
fa4066b6
JS
505 /* decrement the node reference count held
506 * for this queued work
507 */
508 lpfc_nlp_put(ndlp);
dea3101e 509 break;
858c9f6c
JS
510 case LPFC_EVT_DEV_LOSS:
511 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
a93ff37a 512 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
858c9f6c 513 free_evt = 0;
fa4066b6
JS
514 /* decrement the node reference count held for
515 * this queued work
516 */
a93ff37a 517 nlp_did = ndlp->nlp_DID;
858c9f6c 518 lpfc_nlp_put(ndlp);
a93ff37a
JS
519 if (phba->sli_rev == LPFC_SLI_REV4)
520 lpfc_sli4_post_dev_loss_tmo_handler(phba,
521 fcf_inuse,
522 nlp_did);
858c9f6c 523 break;
dea3101e 524 case LPFC_EVT_ONLINE:
2e0fef85
JS
525 if (phba->link_state < LPFC_LINK_DOWN)
526 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
41415862 527 else
2e0fef85 528 *(int *) (evtp->evt_arg1) = 0;
dea3101e 529 complete((struct completion *)(evtp->evt_arg2));
530 break;
46fa311e 531 case LPFC_EVT_OFFLINE_PREP:
2e0fef85 532 if (phba->link_state >= LPFC_LINK_DOWN)
46fa311e
JS
533 lpfc_offline_prep(phba);
534 *(int *)(evtp->evt_arg1) = 0;
535 complete((struct completion *)(evtp->evt_arg2));
536 break;
537 case LPFC_EVT_OFFLINE:
538 lpfc_offline(phba);
41415862
JW
539 lpfc_sli_brdrestart(phba);
540 *(int *)(evtp->evt_arg1) =
46fa311e
JS
541 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
542 lpfc_unblock_mgmt_io(phba);
41415862
JW
543 complete((struct completion *)(evtp->evt_arg2));
544 break;
545 case LPFC_EVT_WARM_START:
46fa311e 546 lpfc_offline(phba);
9290831f 547 lpfc_reset_barrier(phba);
41415862
JW
548 lpfc_sli_brdreset(phba);
549 lpfc_hba_down_post(phba);
550 *(int *)(evtp->evt_arg1) =
551 lpfc_sli_brdready(phba, HS_MBRDY);
46fa311e 552 lpfc_unblock_mgmt_io(phba);
41415862
JW
553 complete((struct completion *)(evtp->evt_arg2));
554 break;
555 case LPFC_EVT_KILL:
46fa311e 556 lpfc_offline(phba);
9290831f 557 *(int *)(evtp->evt_arg1)
2e0fef85
JS
558 = (phba->pport->stopped)
559 ? 0 : lpfc_sli_brdkill(phba);
46fa311e 560 lpfc_unblock_mgmt_io(phba);
dea3101e 561 complete((struct completion *)(evtp->evt_arg2));
562 break;
ea2151b4
JS
563 case LPFC_EVT_FASTPATH_MGMT_EVT:
564 lpfc_send_fastpath_evt(phba, evtp);
565 free_evt = 0;
566 break;
78730cfe
JS
567 case LPFC_EVT_RESET_HBA:
568 if (!(phba->pport->load_flag & FC_UNLOADING))
569 lpfc_reset_hba(phba);
570 break;
dea3101e 571 }
572 if (free_evt)
573 kfree(evtp);
2e0fef85 574 spin_lock_irq(&phba->hbalock);
dea3101e 575 }
2e0fef85 576 spin_unlock_irq(&phba->hbalock);
dea3101e 577
578}
579
311464ec 580static void
2e0fef85 581lpfc_work_done(struct lpfc_hba *phba)
dea3101e 582{
583 struct lpfc_sli_ring *pring;
858c9f6c 584 uint32_t ha_copy, status, control, work_port_events;
549e55cd 585 struct lpfc_vport **vports;
51ef4c26 586 struct lpfc_vport *vport;
549e55cd 587 int i;
dea3101e 588
2e0fef85 589 spin_lock_irq(&phba->hbalock);
dea3101e 590 ha_copy = phba->work_ha;
591 phba->work_ha = 0;
2e0fef85 592 spin_unlock_irq(&phba->hbalock);
dea3101e 593
da0436e9
JS
594 /* First, try to post the next mailbox command to SLI4 device */
595 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
596 lpfc_sli4_post_async_mbox(phba);
597
2fe165b6 598 if (ha_copy & HA_ERATT)
9399627f 599 /* Handle the error attention event */
dea3101e 600 lpfc_handle_eratt(phba);
601
2fe165b6 602 if (ha_copy & HA_MBATT)
dea3101e 603 lpfc_sli_handle_mb_event(phba);
604
2fe165b6 605 if (ha_copy & HA_LATT)
dea3101e 606 lpfc_handle_latt(phba);
9399627f 607
da0436e9
JS
608 /* Process SLI4 events */
609 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
610 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
611 lpfc_sli4_fcp_xri_abort_event_proc(phba);
612 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
613 lpfc_sli4_els_xri_abort_event_proc(phba);
614 if (phba->hba_flag & ASYNC_EVENT)
615 lpfc_sli4_async_event_proc(phba);
616 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
617 spin_lock_irq(&phba->hbalock);
618 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
619 spin_unlock_irq(&phba->hbalock);
620 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
621 }
ecfd03c6
JS
622 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
623 lpfc_sli4_fcf_redisc_event_proc(phba);
da0436e9
JS
624 }
625
549e55cd
JS
626 vports = lpfc_create_vport_work_array(phba);
627 if (vports != NULL)
da0436e9 628 for (i = 0; i <= phba->max_vports; i++) {
51ef4c26
JS
629 /*
630 * We could have no vports in array if unloading, so if
631 * this happens then just use the pport
632 */
633 if (vports[i] == NULL && i == 0)
634 vport = phba->pport;
635 else
636 vport = vports[i];
637 if (vport == NULL)
638 break;
58da1ffb 639 spin_lock_irq(&vport->work_port_lock);
51ef4c26 640 work_port_events = vport->work_port_events;
58da1ffb
JS
641 vport->work_port_events &= ~work_port_events;
642 spin_unlock_irq(&vport->work_port_lock);
549e55cd 643 if (work_port_events & WORKER_DISC_TMO)
51ef4c26 644 lpfc_disc_timeout_handler(vport);
549e55cd 645 if (work_port_events & WORKER_ELS_TMO)
51ef4c26 646 lpfc_els_timeout_handler(vport);
549e55cd
JS
647 if (work_port_events & WORKER_HB_TMO)
648 lpfc_hb_timeout_handler(phba);
649 if (work_port_events & WORKER_MBOX_TMO)
650 lpfc_mbox_timeout_handler(phba);
651 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
652 lpfc_unblock_fabric_iocbs(phba);
653 if (work_port_events & WORKER_FDMI_TMO)
51ef4c26 654 lpfc_fdmi_timeout_handler(vport);
549e55cd
JS
655 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
656 lpfc_ramp_down_queue_handler(phba);
657 if (work_port_events & WORKER_RAMP_UP_QUEUE)
658 lpfc_ramp_up_queue_handler(phba);
92d7f7b0 659 }
09372820 660 lpfc_destroy_vport_work_array(phba, vports);
dea3101e 661
858c9f6c
JS
662 pring = &phba->sli.ring[LPFC_ELS_RING];
663 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
664 status >>= (4*LPFC_ELS_RING);
4d9ab994
JS
665 if ((status & HA_RXMASK) ||
666 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
45ed1190 667 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
0b727fea 668 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
858c9f6c 669 pring->flag |= LPFC_DEFERRED_RING_EVENT;
5e9d9b82
JS
670 /* Set the lpfc data pending flag */
671 set_bit(LPFC_DATA_READY, &phba->data_flags);
858c9f6c 672 } else {
58da1ffb 673 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
858c9f6c
JS
674 lpfc_sli_handle_slow_ring_event(phba, pring,
675 (status &
676 HA_RXMASK));
858c9f6c 677 }
bc73905a 678 if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
2a9bf3d0 679 lpfc_drain_txq(phba);
858c9f6c
JS
680 /*
681 * Turn on Ring interrupts
682 */
3772a991
JS
683 if (phba->sli_rev <= LPFC_SLI_REV3) {
684 spin_lock_irq(&phba->hbalock);
685 control = readl(phba->HCregaddr);
686 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
687 lpfc_debugfs_slow_ring_trc(phba,
688 "WRK Enable ring: cntl:x%x hacopy:x%x",
689 control, ha_copy, 0);
690
691 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
692 writel(control, phba->HCregaddr);
693 readl(phba->HCregaddr); /* flush */
694 } else {
695 lpfc_debugfs_slow_ring_trc(phba,
696 "WRK Ring ok: cntl:x%x hacopy:x%x",
697 control, ha_copy, 0);
698 }
699 spin_unlock_irq(&phba->hbalock);
a58cbd52 700 }
dea3101e 701 }
2e0fef85 702 lpfc_work_list_done(phba);
dea3101e 703}
704
dea3101e 705int
706lpfc_do_work(void *p)
707{
708 struct lpfc_hba *phba = p;
709 int rc;
dea3101e 710
711 set_user_nice(current, -20);
5e9d9b82 712 phba->data_flags = 0;
dea3101e 713
3a55b532 714 while (!kthread_should_stop()) {
5e9d9b82
JS
715 /* wait and check worker queue activities */
716 rc = wait_event_interruptible(phba->work_waitq,
717 (test_and_clear_bit(LPFC_DATA_READY,
718 &phba->data_flags)
719 || kthread_should_stop()));
3a55b532
JS
720 /* Signal wakeup shall terminate the worker thread */
721 if (rc) {
722 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
723 "0433 Wakeup on signal: rc=x%x\n", rc);
dea3101e 724 break;
3a55b532 725 }
dea3101e 726
5e9d9b82 727 /* Attend pending lpfc data processing */
dea3101e 728 lpfc_work_done(phba);
dea3101e 729 }
3a55b532
JS
730 phba->worker_thread = NULL;
731 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
732 "0432 Worker thread stopped.\n");
dea3101e 733 return 0;
734}
735
736/*
737 * This is only called to handle FC worker events. Since this a rare
738 * occurance, we allocate a struct lpfc_work_evt structure here instead of
739 * embedding it in the IOCB.
740 */
741int
2e0fef85 742lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea3101e 743 uint32_t evt)
744{
745 struct lpfc_work_evt *evtp;
ed957684 746 unsigned long flags;
dea3101e 747
748 /*
749 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
750 * be queued to worker thread for processing
751 */
92d7f7b0 752 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea3101e 753 if (!evtp)
754 return 0;
755
756 evtp->evt_arg1 = arg1;
757 evtp->evt_arg2 = arg2;
758 evtp->evt = evt;
759
ed957684 760 spin_lock_irqsave(&phba->hbalock, flags);
071fbd3d 761 list_add_tail(&evtp->evt_listp, &phba->work_list);
ed957684 762 spin_unlock_irqrestore(&phba->hbalock, flags);
dea3101e 763
5e9d9b82
JS
764 lpfc_worker_wake_up(phba);
765
dea3101e 766 return 1;
767}
768
92d7f7b0
JS
769void
770lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
771{
09372820 772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
92d7f7b0
JS
773 struct lpfc_hba *phba = vport->phba;
774 struct lpfc_nodelist *ndlp, *next_ndlp;
775 int rc;
776
777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
778 if (!NLP_CHK_NODE_ACT(ndlp))
779 continue;
92d7f7b0
JS
780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
781 continue;
98c9ea5c
JS
782 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
783 ((vport->port_type == LPFC_NPIV_PORT) &&
784 (ndlp->nlp_DID == NameServer_DID)))
92d7f7b0
JS
785 lpfc_unreg_rpi(vport, ndlp);
786
787 /* Leave Fabric nodes alone on link down */
4d9ab994
JS
788 if ((phba->sli_rev < LPFC_SLI_REV4) &&
789 (!remove && ndlp->nlp_type & NLP_FABRIC))
92d7f7b0
JS
790 continue;
791 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
792 remove
793 ? NLP_EVT_DEVICE_RM
794 : NLP_EVT_DEVICE_RECOVERY);
795 }
796 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
5af5eee7
JS
797 if (phba->sli_rev == LPFC_SLI_REV4)
798 lpfc_sli4_unreg_all_rpis(vport);
92d7f7b0 799 lpfc_mbx_unreg_vpi(vport);
09372820 800 spin_lock_irq(shost->host_lock);
92d7f7b0 801 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
09372820 802 spin_unlock_irq(shost->host_lock);
92d7f7b0
JS
803 }
804}
805
87af33fe 806void
98c9ea5c 807lpfc_port_link_failure(struct lpfc_vport *vport)
92d7f7b0 808{
695a814e
JS
809 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
810
45ed1190
JS
811 /* Cleanup any outstanding received buffers */
812 lpfc_cleanup_rcv_buffers(vport);
813
92d7f7b0
JS
814 /* Cleanup any outstanding RSCN activity */
815 lpfc_els_flush_rscn(vport);
816
817 /* Cleanup any outstanding ELS commands */
818 lpfc_els_flush_cmd(vport);
819
820 lpfc_cleanup_rpis(vport, 0);
821
92d7f7b0
JS
822 /* Turn off discovery timer if its running */
823 lpfc_can_disctmo(vport);
824}
825
3772a991 826void
98c9ea5c
JS
827lpfc_linkdown_port(struct lpfc_vport *vport)
828{
829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
830
831 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
832
833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
834 "Link Down: state:x%x rtry:x%x flg:x%x",
835 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
836
837 lpfc_port_link_failure(vport);
838
839}
840
dea3101e 841int
685f0bf7 842lpfc_linkdown(struct lpfc_hba *phba)
dea3101e 843{
2e0fef85
JS
844 struct lpfc_vport *vport = phba->pport;
845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
549e55cd 846 struct lpfc_vport **vports;
685f0bf7 847 LPFC_MBOXQ_t *mb;
549e55cd 848 int i;
dea3101e 849
3163f725 850 if (phba->link_state == LPFC_LINK_DOWN)
2e0fef85 851 return 0;
aacc20e3
JS
852
853 /* Block all SCSI stack I/Os */
854 lpfc_scsi_dev_block(phba);
855
2e0fef85 856 spin_lock_irq(&phba->hbalock);
ecfd03c6 857 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
72100cc4 858 spin_unlock_irq(&phba->hbalock);
92d7f7b0 859 if (phba->link_state > LPFC_LINK_DOWN) {
2e0fef85 860 phba->link_state = LPFC_LINK_DOWN;
72100cc4 861 spin_lock_irq(shost->host_lock);
92d7f7b0 862 phba->pport->fc_flag &= ~FC_LBIT;
72100cc4 863 spin_unlock_irq(shost->host_lock);
92d7f7b0 864 }
549e55cd
JS
865 vports = lpfc_create_vport_work_array(phba);
866 if (vports != NULL)
6fb120a7 867 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
549e55cd
JS
868 /* Issue a LINK DOWN event to all nodes */
869 lpfc_linkdown_port(vports[i]);
870 }
09372820 871 lpfc_destroy_vport_work_array(phba, vports);
dea3101e 872 /* Clean up any firmware default rpi's */
2e0fef85
JS
873 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
874 if (mb) {
92d7f7b0 875 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
ed957684 876 mb->vport = vport;
2e0fef85 877 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
0b727fea 878 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea3101e 879 == MBX_NOT_FINISHED) {
2e0fef85 880 mempool_free(mb, phba->mbox_mem_pool);
dea3101e 881 }
882 }
883
dea3101e 884 /* Setup myDID for link up if we are in pt2pt mode */
92d7f7b0
JS
885 if (phba->pport->fc_flag & FC_PT2PT) {
886 phba->pport->fc_myDID = 0;
2e0fef85
JS
887 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
888 if (mb) {
dea3101e 889 lpfc_config_link(phba, mb);
92d7f7b0 890 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
ed957684 891 mb->vport = vport;
0b727fea 892 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea3101e 893 == MBX_NOT_FINISHED) {
2e0fef85 894 mempool_free(mb, phba->mbox_mem_pool);
dea3101e 895 }
896 }
2e0fef85 897 spin_lock_irq(shost->host_lock);
92d7f7b0 898 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
2e0fef85 899 spin_unlock_irq(shost->host_lock);
dea3101e 900 }
2e0fef85 901
92d7f7b0
JS
902 return 0;
903}
dea3101e 904
92d7f7b0
JS
905static void
906lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
907{
908 struct lpfc_nodelist *ndlp;
dea3101e 909
92d7f7b0 910 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
e47c9093
JS
911 if (!NLP_CHK_NODE_ACT(ndlp))
912 continue;
92d7f7b0
JS
913 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
914 continue;
92d7f7b0 915 if (ndlp->nlp_type & NLP_FABRIC) {
e47c9093
JS
916 /* On Linkup its safe to clean up the ndlp
917 * from Fabric connections.
918 */
92d7f7b0
JS
919 if (ndlp->nlp_DID != Fabric_DID)
920 lpfc_unreg_rpi(vport, ndlp);
921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
922 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
e47c9093
JS
923 /* Fail outstanding IO now since device is
924 * marked for PLOGI.
925 */
92d7f7b0
JS
926 lpfc_unreg_rpi(vport, ndlp);
927 }
928 }
dea3101e 929}
930
92d7f7b0
JS
931static void
932lpfc_linkup_port(struct lpfc_vport *vport)
dea3101e 933{
92d7f7b0 934 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
92d7f7b0
JS
935 struct lpfc_hba *phba = vport->phba;
936
937 if ((vport->load_flag & FC_UNLOADING) != 0)
938 return;
939
858c9f6c
JS
940 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
941 "Link Up: top:x%x speed:x%x flg:x%x",
942 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
943
92d7f7b0
JS
944 /* If NPIV is not enabled, only bring the physical port up */
945 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
946 (vport != phba->pport))
947 return;
dea3101e 948
2e0fef85 949 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
d2873e4c 950
2e0fef85 951 spin_lock_irq(shost->host_lock);
2e0fef85
JS
952 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
953 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
954 vport->fc_flag |= FC_NDISC_ACTIVE;
955 vport->fc_ns_retry = 0;
956 spin_unlock_irq(shost->host_lock);
dea3101e 957
92d7f7b0
JS
958 if (vport->fc_flag & FC_LBIT)
959 lpfc_linkup_cleanup_nodes(vport);
dea3101e 960
92d7f7b0
JS
961}
962
963static int
964lpfc_linkup(struct lpfc_hba *phba)
965{
549e55cd
JS
966 struct lpfc_vport **vports;
967 int i;
92d7f7b0
JS
968
969 phba->link_state = LPFC_LINK_UP;
970
971 /* Unblock fabric iocbs if they are blocked */
972 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
973 del_timer_sync(&phba->fabric_block_timer);
974
549e55cd
JS
975 vports = lpfc_create_vport_work_array(phba);
976 if (vports != NULL)
6fb120a7 977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
549e55cd 978 lpfc_linkup_port(vports[i]);
09372820 979 lpfc_destroy_vport_work_array(phba, vports);
6fb120a7
JS
980 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
981 (phba->sli_rev < LPFC_SLI_REV4))
92d7f7b0 982 lpfc_issue_clear_la(phba, phba->pport);
dea3101e 983
984 return 0;
985}
986
987/*
988 * This routine handles processing a CLEAR_LA mailbox
989 * command upon completion. It is setup in the LPFC_MBOXQ
990 * as the completion routine when the command is
991 * handed off to the SLI layer.
992 */
a6ababd2 993static void
2e0fef85 994lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 995{
2e0fef85
JS
996 struct lpfc_vport *vport = pmb->vport;
997 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
998 struct lpfc_sli *psli = &phba->sli;
04c68496 999 MAILBOX_t *mb = &pmb->u.mb;
dea3101e 1000 uint32_t control;
1001
dea3101e 1002 /* Since we don't do discovery right now, turn these off here */
a4bc3379 1003 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea3101e 1004 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1005 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1006
1007 /* Check for error */
1008 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
92d7f7b0 1009 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
e8b62011
JS
1010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1011 "0320 CLEAR_LA mbxStatus error x%x hba "
1012 "state x%x\n",
1013 mb->mbxStatus, vport->port_state);
2e0fef85 1014 phba->link_state = LPFC_HBA_ERROR;
dea3101e 1015 goto out;
1016 }
1017
92d7f7b0
JS
1018 if (vport->port_type == LPFC_PHYSICAL_PORT)
1019 phba->link_state = LPFC_HBA_READY;
1020
1021 spin_lock_irq(&phba->hbalock);
1022 psli->sli_flag |= LPFC_PROCESS_LA;
1023 control = readl(phba->HCregaddr);
1024 control |= HC_LAINT_ENA;
1025 writel(control, phba->HCregaddr);
1026 readl(phba->HCregaddr); /* flush */
1027 spin_unlock_irq(&phba->hbalock);
1b32f6aa 1028 mempool_free(pmb, phba->mbox_mem_pool);
92d7f7b0 1029 return;
dea3101e 1030
dea3101e 1031out:
1032 /* Device Discovery completes */
e8b62011
JS
1033 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1034 "0225 Device Discovery completes\n");
2e0fef85 1035 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 1036
2e0fef85 1037 spin_lock_irq(shost->host_lock);
58da1ffb 1038 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
2e0fef85 1039 spin_unlock_irq(shost->host_lock);
dea3101e 1040
2e0fef85 1041 lpfc_can_disctmo(vport);
dea3101e 1042
1043 /* turn on Link Attention interrupts */
2e0fef85
JS
1044
1045 spin_lock_irq(&phba->hbalock);
dea3101e 1046 psli->sli_flag |= LPFC_PROCESS_LA;
1047 control = readl(phba->HCregaddr);
1048 control |= HC_LAINT_ENA;
1049 writel(control, phba->HCregaddr);
1050 readl(phba->HCregaddr); /* flush */
2e0fef85 1051 spin_unlock_irq(&phba->hbalock);
dea3101e 1052
1053 return;
1054}
1055
2e0fef85 1056
dea3101e 1057static void
25594c6b 1058lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 1059{
2e0fef85 1060 struct lpfc_vport *vport = pmb->vport;
dea3101e 1061
04c68496 1062 if (pmb->u.mb.mbxStatus)
dea3101e 1063 goto out;
dea3101e 1064
25594c6b
JW
1065 mempool_free(pmb, phba->mbox_mem_pool);
1066
76a95d75 1067 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
2e0fef85
JS
1068 vport->fc_flag & FC_PUBLIC_LOOP &&
1069 !(vport->fc_flag & FC_LBIT)) {
25594c6b 1070 /* Need to wait for FAN - use discovery timer
2e0fef85 1071 * for timeout. port_state is identically
25594c6b
JW
1072 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1073 */
2e0fef85 1074 lpfc_set_disctmo(vport);
25594c6b 1075 return;
92d7f7b0 1076 }
dea3101e 1077
2e0fef85 1078 /* Start discovery by sending a FLOGI. port_state is identically
25594c6b
JW
1079 * LPFC_FLOGI while waiting for FLOGI cmpl
1080 */
76a95d75 1081 if (vport->port_state != LPFC_FLOGI)
92d7f7b0 1082 lpfc_initial_flogi(vport);
25594c6b 1083 return;
dea3101e 1084
1085out:
e8b62011
JS
1086 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1087 "0306 CONFIG_LINK mbxStatus error x%x "
1088 "HBA state x%x\n",
04c68496 1089 pmb->u.mb.mbxStatus, vport->port_state);
92d7f7b0 1090 mempool_free(pmb, phba->mbox_mem_pool);
25594c6b 1091
92d7f7b0 1092 lpfc_linkdown(phba);
25594c6b 1093
e8b62011
JS
1094 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1095 "0200 CONFIG_LINK bad hba state x%x\n",
1096 vport->port_state);
dea3101e 1097
92d7f7b0 1098 lpfc_issue_clear_la(phba, vport);
dea3101e 1099 return;
1100}
1101
6fb120a7
JS
1102static void
1103lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1104{
1105 struct lpfc_vport *vport = mboxq->vport;
6fb120a7
JS
1106
1107 if (mboxq->u.mb.mbxStatus) {
1108 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1109 "2017 REG_FCFI mbxStatus error x%x "
1110 "HBA state x%x\n",
1111 mboxq->u.mb.mbxStatus, vport->port_state);
a93ff37a 1112 goto fail_out;
6fb120a7
JS
1113 }
1114
1115 /* Start FCoE discovery by sending a FLOGI. */
1116 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1117 /* Set the FCFI registered flag */
d439d286 1118 spin_lock_irq(&phba->hbalock);
6fb120a7 1119 phba->fcf.fcf_flag |= FCF_REGISTERED;
d439d286 1120 spin_unlock_irq(&phba->hbalock);
a93ff37a 1121
32b9793f 1122 /* If there is a pending FCoE event, restart FCF table scan. */
a93ff37a
JS
1123 if (lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1124 goto fail_out;
1125
1126 /* Mark successful completion of FCF table scan */
d439d286 1127 spin_lock_irq(&phba->hbalock);
ecfd03c6 1128 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
a93ff37a
JS
1129 phba->hba_flag &= ~FCF_TS_INPROG;
1130 if (vport->port_state != LPFC_FLOGI) {
1131 phba->hba_flag |= FCF_RR_INPROG;
1132 spin_unlock_irq(&phba->hbalock);
76a95d75 1133 lpfc_issue_init_vfi(vport);
a93ff37a
JS
1134 goto out;
1135 }
1136 spin_unlock_irq(&phba->hbalock);
1137 goto out;
6fb120a7 1138
a93ff37a
JS
1139fail_out:
1140 spin_lock_irq(&phba->hbalock);
1141 phba->hba_flag &= ~FCF_RR_INPROG;
1142 spin_unlock_irq(&phba->hbalock);
1143out:
6fb120a7 1144 mempool_free(mboxq, phba->mbox_mem_pool);
6fb120a7
JS
1145}
1146
1147/**
1148 * lpfc_fab_name_match - Check if the fcf fabric name match.
1149 * @fab_name: pointer to fabric name.
1150 * @new_fcf_record: pointer to fcf record.
1151 *
1152 * This routine compare the fcf record's fabric name with provided
1153 * fabric name. If the fabric name are identical this function
1154 * returns 1 else return 0.
1155 **/
1156static uint32_t
1157lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1158{
ecfd03c6
JS
1159 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1160 return 0;
1161 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1162 return 0;
1163 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1164 return 0;
1165 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1166 return 0;
1167 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1168 return 0;
1169 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
6fb120a7 1170 return 0;
ecfd03c6
JS
1171 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1172 return 0;
1173 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1174 return 0;
1175 return 1;
6fb120a7
JS
1176}
1177
8fa38513
JS
1178/**
1179 * lpfc_sw_name_match - Check if the fcf switch name match.
1180 * @fab_name: pointer to fabric name.
1181 * @new_fcf_record: pointer to fcf record.
1182 *
1183 * This routine compare the fcf record's switch name with provided
1184 * switch name. If the switch name are identical this function
1185 * returns 1 else return 0.
1186 **/
1187static uint32_t
1188lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1189{
ecfd03c6
JS
1190 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1191 return 0;
1192 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1193 return 0;
1194 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
8fa38513 1195 return 0;
ecfd03c6
JS
1196 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1197 return 0;
1198 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1199 return 0;
1200 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1201 return 0;
1202 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1203 return 0;
1204 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1205 return 0;
1206 return 1;
8fa38513
JS
1207}
1208
6fb120a7
JS
1209/**
1210 * lpfc_mac_addr_match - Check if the fcf mac address match.
ecfd03c6 1211 * @mac_addr: pointer to mac address.
6fb120a7
JS
1212 * @new_fcf_record: pointer to fcf record.
1213 *
1214 * This routine compare the fcf record's mac address with HBA's
1215 * FCF mac address. If the mac addresses are identical this function
1216 * returns 1 else return 0.
1217 **/
1218static uint32_t
ecfd03c6 1219lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
6fb120a7 1220{
ecfd03c6
JS
1221 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1222 return 0;
1223 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1224 return 0;
1225 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1226 return 0;
1227 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1228 return 0;
1229 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1230 return 0;
1231 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
6fb120a7 1232 return 0;
ecfd03c6
JS
1233 return 1;
1234}
1235
1236static bool
1237lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1238{
1239 return (curr_vlan_id == new_vlan_id);
6fb120a7
JS
1240}
1241
1242/**
1243 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
ecfd03c6 1244 * @fcf: pointer to driver fcf record.
6fb120a7
JS
1245 * @new_fcf_record: pointer to fcf record.
1246 *
1247 * This routine copies the FCF information from the FCF
1248 * record to lpfc_hba data structure.
1249 **/
1250static void
ecfd03c6
JS
1251lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1252 struct fcf_record *new_fcf_record)
6fb120a7 1253{
ecfd03c6
JS
1254 /* Fabric name */
1255 fcf_rec->fabric_name[0] =
6fb120a7 1256 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
ecfd03c6 1257 fcf_rec->fabric_name[1] =
6fb120a7 1258 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
ecfd03c6 1259 fcf_rec->fabric_name[2] =
6fb120a7 1260 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
ecfd03c6 1261 fcf_rec->fabric_name[3] =
6fb120a7 1262 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
ecfd03c6 1263 fcf_rec->fabric_name[4] =
6fb120a7 1264 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
ecfd03c6 1265 fcf_rec->fabric_name[5] =
6fb120a7 1266 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
ecfd03c6 1267 fcf_rec->fabric_name[6] =
6fb120a7 1268 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
ecfd03c6 1269 fcf_rec->fabric_name[7] =
6fb120a7 1270 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
ecfd03c6
JS
1271 /* Mac address */
1272 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1273 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1274 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1275 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1276 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1277 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1278 /* FCF record index */
1279 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1280 /* FCF record priority */
1281 fcf_rec->priority = new_fcf_record->fip_priority;
1282 /* Switch name */
1283 fcf_rec->switch_name[0] =
8fa38513 1284 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
ecfd03c6 1285 fcf_rec->switch_name[1] =
8fa38513 1286 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
ecfd03c6 1287 fcf_rec->switch_name[2] =
8fa38513 1288 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
ecfd03c6 1289 fcf_rec->switch_name[3] =
8fa38513 1290 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
ecfd03c6 1291 fcf_rec->switch_name[4] =
8fa38513 1292 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
ecfd03c6 1293 fcf_rec->switch_name[5] =
8fa38513 1294 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
ecfd03c6 1295 fcf_rec->switch_name[6] =
8fa38513 1296 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
ecfd03c6 1297 fcf_rec->switch_name[7] =
8fa38513 1298 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
6fb120a7
JS
1299}
1300
ecfd03c6
JS
1301/**
1302 * lpfc_update_fcf_record - Update driver fcf record
1303 * @phba: pointer to lpfc hba data structure.
1304 * @fcf_rec: pointer to driver fcf record.
1305 * @new_fcf_record: pointer to hba fcf record.
1306 * @addr_mode: address mode to be set to the driver fcf record.
1307 * @vlan_id: vlan tag to be set to the driver fcf record.
1308 * @flag: flag bits to be set to the driver fcf record.
1309 *
1310 * This routine updates the driver FCF record from the new HBA FCF record
1311 * together with the address mode, vlan_id, and other informations. This
1312 * routine is called with the host lock held.
1313 **/
1314static void
1315__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1316 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1317 uint16_t vlan_id, uint32_t flag)
1318{
1319 /* Copy the fields from the HBA's FCF record */
1320 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1321 /* Update other fields of driver FCF record */
1322 fcf_rec->addr_mode = addr_mode;
1323 fcf_rec->vlan_id = vlan_id;
1324 fcf_rec->flag |= (flag | RECORD_VALID);
1325}
1326
6fb120a7
JS
1327/**
1328 * lpfc_register_fcf - Register the FCF with hba.
1329 * @phba: pointer to lpfc hba data structure.
1330 *
1331 * This routine issues a register fcfi mailbox command to register
1332 * the fcf with HBA.
1333 **/
1334static void
1335lpfc_register_fcf(struct lpfc_hba *phba)
1336{
1337 LPFC_MBOXQ_t *fcf_mbxq;
1338 int rc;
6fb120a7 1339
d439d286 1340 spin_lock_irq(&phba->hbalock);
6fb120a7
JS
1341 /* If the FCF is not availabe do nothing. */
1342 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
a93ff37a 1343 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
d439d286 1344 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
1345 return;
1346 }
1347
1348 /* The FCF is already registered, start discovery */
1349 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
ecfd03c6 1350 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
a93ff37a
JS
1351 phba->hba_flag &= ~FCF_TS_INPROG;
1352 if (phba->pport->port_state != LPFC_FLOGI) {
1353 phba->hba_flag |= FCF_RR_INPROG;
1354 spin_unlock_irq(&phba->hbalock);
76a95d75 1355 lpfc_issue_init_vfi(phba->pport);
a93ff37a
JS
1356 return;
1357 }
1358 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
1359 return;
1360 }
d439d286 1361 spin_unlock_irq(&phba->hbalock);
6fb120a7 1362
a93ff37a 1363 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4d9ab994 1364 if (!fcf_mbxq) {
d439d286 1365 spin_lock_irq(&phba->hbalock);
a93ff37a 1366 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
d439d286 1367 spin_unlock_irq(&phba->hbalock);
6fb120a7 1368 return;
4d9ab994 1369 }
6fb120a7
JS
1370
1371 lpfc_reg_fcfi(phba, fcf_mbxq);
1372 fcf_mbxq->vport = phba->pport;
1373 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1374 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
4d9ab994 1375 if (rc == MBX_NOT_FINISHED) {
d439d286 1376 spin_lock_irq(&phba->hbalock);
a93ff37a 1377 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
d439d286 1378 spin_unlock_irq(&phba->hbalock);
6fb120a7 1379 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
4d9ab994 1380 }
6fb120a7
JS
1381
1382 return;
1383}
1384
1385/**
1386 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1387 * @phba: pointer to lpfc hba data structure.
1388 * @new_fcf_record: pointer to fcf record.
1389 * @boot_flag: Indicates if this record used by boot bios.
1390 * @addr_mode: The address mode to be used by this FCF
ecfd03c6 1391 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
6fb120a7
JS
1392 *
1393 * This routine compare the fcf record with connect list obtained from the
1394 * config region to decide if this FCF can be used for SAN discovery. It returns
1395 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1396 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1397 * is used by boot bios and addr_mode will indicate the addressing mode to be
1398 * used for this FCF when the function returns.
1399 * If the FCF record need to be used with a particular vlan id, the vlan is
1400 * set in the vlan_id on return of the function. If not VLAN tagging need to
dbb6b3ab 1401 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
6fb120a7
JS
1402 **/
1403static int
1404lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1405 struct fcf_record *new_fcf_record,
1406 uint32_t *boot_flag, uint32_t *addr_mode,
1407 uint16_t *vlan_id)
1408{
1409 struct lpfc_fcf_conn_entry *conn_entry;
4d9ab994
JS
1410 int i, j, fcf_vlan_id = 0;
1411
1412 /* Find the lowest VLAN id in the FCF record */
1413 for (i = 0; i < 512; i++) {
1414 if (new_fcf_record->vlan_bitmap[i]) {
1415 fcf_vlan_id = i * 8;
1416 j = 0;
1417 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1418 j++;
1419 fcf_vlan_id++;
1420 }
1421 break;
1422 }
1423 }
6fb120a7 1424
0c287589
JS
1425 /* If FCF not available return 0 */
1426 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1427 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
1428 return 0;
1429
45ed1190 1430 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
6fb120a7
JS
1431 *boot_flag = 0;
1432 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1433 new_fcf_record);
1434 if (phba->valid_vlan)
1435 *vlan_id = phba->vlan_id;
1436 else
dbb6b3ab 1437 *vlan_id = LPFC_FCOE_NULL_VID;
6fb120a7
JS
1438 return 1;
1439 }
1440
1441 /*
1442 * If there are no FCF connection table entry, driver connect to all
1443 * FCFs.
1444 */
1445 if (list_empty(&phba->fcf_conn_rec_list)) {
1446 *boot_flag = 0;
1447 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1448 new_fcf_record);
0c287589
JS
1449
1450 /*
1451 * When there are no FCF connect entries, use driver's default
1452 * addressing mode - FPMA.
1453 */
1454 if (*addr_mode & LPFC_FCF_FPMA)
1455 *addr_mode = LPFC_FCF_FPMA;
1456
4d9ab994
JS
1457 /* If FCF record report a vlan id use that vlan id */
1458 if (fcf_vlan_id)
1459 *vlan_id = fcf_vlan_id;
1460 else
dbb6b3ab 1461 *vlan_id = LPFC_FCOE_NULL_VID;
6fb120a7
JS
1462 return 1;
1463 }
1464
ecfd03c6
JS
1465 list_for_each_entry(conn_entry,
1466 &phba->fcf_conn_rec_list, list) {
6fb120a7
JS
1467 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1468 continue;
1469
1470 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1471 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
8fa38513
JS
1472 new_fcf_record))
1473 continue;
1474 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1475 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1476 new_fcf_record))
6fb120a7 1477 continue;
6fb120a7
JS
1478 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1479 /*
1480 * If the vlan bit map does not have the bit set for the
1481 * vlan id to be used, then it is not a match.
1482 */
1483 if (!(new_fcf_record->vlan_bitmap
1484 [conn_entry->conn_rec.vlan_tag / 8] &
1485 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1486 continue;
1487 }
1488
0c287589
JS
1489 /*
1490 * If connection record does not support any addressing mode,
1491 * skip the FCF record.
1492 */
1493 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1494 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1495 continue;
1496
6fb120a7
JS
1497 /*
1498 * Check if the connection record specifies a required
1499 * addressing mode.
1500 */
1501 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1502 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1503
1504 /*
1505 * If SPMA required but FCF not support this continue.
1506 */
1507 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1508 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1509 new_fcf_record) & LPFC_FCF_SPMA))
1510 continue;
1511
1512 /*
1513 * If FPMA required but FCF not support this continue.
1514 */
1515 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1516 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1517 new_fcf_record) & LPFC_FCF_FPMA))
1518 continue;
1519 }
1520
1521 /*
1522 * This fcf record matches filtering criteria.
1523 */
1524 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1525 *boot_flag = 1;
1526 else
1527 *boot_flag = 0;
1528
0c287589
JS
1529 /*
1530 * If user did not specify any addressing mode, or if the
1531 * prefered addressing mode specified by user is not supported
1532 * by FCF, allow fabric to pick the addressing mode.
1533 */
6fb120a7
JS
1534 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1535 new_fcf_record);
1536 /*
1537 * If the user specified a required address mode, assign that
1538 * address mode
1539 */
1540 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1541 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1542 *addr_mode = (conn_entry->conn_rec.flags &
1543 FCFCNCT_AM_SPMA) ?
1544 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1545 /*
1546 * If the user specified a prefered address mode, use the
1547 * addr mode only if FCF support the addr_mode.
1548 */
1549 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1550 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1551 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1552 (*addr_mode & LPFC_FCF_SPMA))
1553 *addr_mode = LPFC_FCF_SPMA;
1554 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1555 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1556 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1557 (*addr_mode & LPFC_FCF_FPMA))
1558 *addr_mode = LPFC_FCF_FPMA;
6fb120a7 1559
4d9ab994 1560 /* If matching connect list has a vlan id, use it */
6fb120a7
JS
1561 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1562 *vlan_id = conn_entry->conn_rec.vlan_tag;
4d9ab994
JS
1563 /*
1564 * If no vlan id is specified in connect list, use the vlan id
1565 * in the FCF record
1566 */
1567 else if (fcf_vlan_id)
1568 *vlan_id = fcf_vlan_id;
6fb120a7 1569 else
dbb6b3ab 1570 *vlan_id = LPFC_FCOE_NULL_VID;
6fb120a7
JS
1571
1572 return 1;
1573 }
1574
1575 return 0;
1576}
1577
32b9793f
JS
1578/**
1579 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1580 * @phba: pointer to lpfc hba data structure.
1581 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1582 *
1583 * This function check if there is any fcoe event pending while driver
1584 * scan FCF entries. If there is any pending event, it will restart the
1585 * FCF saning and return 1 else return 0.
1586 */
1587int
1588lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1589{
32b9793f
JS
1590 /*
1591 * If the Link is up and no FCoE events while in the
1592 * FCF discovery, no need to restart FCF discovery.
1593 */
1594 if ((phba->link_state >= LPFC_LINK_UP) &&
a93ff37a 1595 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
32b9793f
JS
1596 return 0;
1597
0c9ab6f5
JS
1598 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1599 "2768 Pending link or FCF event during current "
1600 "handling of the previous event: link_state:x%x, "
1601 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1602 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1603 phba->fcoe_eventtag);
1604
32b9793f
JS
1605 spin_lock_irq(&phba->hbalock);
1606 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1607 spin_unlock_irq(&phba->hbalock);
1608
0c9ab6f5
JS
1609 if (phba->link_state >= LPFC_LINK_UP) {
1610 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1611 "2780 Restart FCF table scan due to "
1612 "pending FCF event:evt_tag_at_scan:x%x, "
1613 "evt_tag_current:x%x\n",
1614 phba->fcoe_eventtag_at_fcf_scan,
1615 phba->fcoe_eventtag);
1616 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1617 } else {
4d9ab994 1618 /*
a93ff37a 1619 * Do not continue FCF discovery and clear FCF_TS_INPROG
4d9ab994
JS
1620 * flag
1621 */
dbb6b3ab
JS
1622 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1623 "2833 Stop FCF discovery process due to link "
1624 "state change (x%x)\n", phba->link_state);
1c6f4ef5 1625 spin_lock_irq(&phba->hbalock);
a93ff37a 1626 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
0c9ab6f5 1627 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1c6f4ef5
JS
1628 spin_unlock_irq(&phba->hbalock);
1629 }
32b9793f 1630
0c9ab6f5 1631 /* Unregister the currently registered FCF if required */
32b9793f
JS
1632 if (unreg_fcf) {
1633 spin_lock_irq(&phba->hbalock);
1634 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1635 spin_unlock_irq(&phba->hbalock);
0c9ab6f5 1636 lpfc_sli4_unregister_fcf(phba);
32b9793f 1637 }
32b9793f
JS
1638 return 1;
1639}
1640
6fb120a7 1641/**
999d813f
JS
1642 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1643 * @phba: pointer to lpfc hba data structure.
1644 * @fcf_cnt: number of eligible fcf record seen so far.
1645 *
1646 * This function makes an running random selection decision on FCF record to
1647 * use through a sequence of @fcf_cnt eligible FCF records with equal
1648 * probability. To perform integer manunipulation of random numbers with
1649 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1650 * from random32() are taken as the random random number generated.
1651 *
1652 * Returns true when outcome is for the newly read FCF record should be
1653 * chosen; otherwise, return false when outcome is for keeping the previously
1654 * chosen FCF record.
1655 **/
1656static bool
1657lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1658{
1659 uint32_t rand_num;
1660
1661 /* Get 16-bit uniform random number */
1662 rand_num = (0xFFFF & random32());
1663
1664 /* Decision with probability 1/fcf_cnt */
1665 if ((fcf_cnt * rand_num) < 0xFFFF)
1666 return true;
1667 else
1668 return false;
1669}
1670
1671/**
3804dc84 1672 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
6fb120a7
JS
1673 * @phba: pointer to lpfc hba data structure.
1674 * @mboxq: pointer to mailbox object.
0c9ab6f5 1675 * @next_fcf_index: pointer to holder of next fcf index.
6fb120a7 1676 *
0c9ab6f5
JS
1677 * This routine parses the non-embedded fcf mailbox command by performing the
1678 * necessarily error checking, non-embedded read FCF record mailbox command
1679 * SGE parsing, and endianness swapping.
1680 *
1681 * Returns the pointer to the new FCF record in the non-embedded mailbox
1682 * command DMA memory if successfully, other NULL.
6fb120a7 1683 */
0c9ab6f5
JS
1684static struct fcf_record *
1685lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1686 uint16_t *next_fcf_index)
6fb120a7
JS
1687{
1688 void *virt_addr;
1689 dma_addr_t phys_addr;
6fb120a7
JS
1690 struct lpfc_mbx_sge sge;
1691 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1692 uint32_t shdr_status, shdr_add_status;
1693 union lpfc_sli4_cfg_shdr *shdr;
1694 struct fcf_record *new_fcf_record;
32b9793f 1695
6fb120a7
JS
1696 /* Get the first SGE entry from the non-embedded DMA memory. This
1697 * routine only uses a single SGE.
1698 */
1699 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1700 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1701 if (unlikely(!mboxq->sge_array)) {
1702 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1703 "2524 Failed to get the non-embedded SGE "
1704 "virtual address\n");
0c9ab6f5 1705 return NULL;
6fb120a7
JS
1706 }
1707 virt_addr = mboxq->sge_array->addr[0];
1708
1709 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1710 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
0c9ab6f5 1711 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6fb120a7 1712 if (shdr_status || shdr_add_status) {
0c9ab6f5
JS
1713 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1714 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
def9c7a9
JS
1715 "2726 READ_FCF_RECORD Indicates empty "
1716 "FCF table.\n");
0c9ab6f5
JS
1717 else
1718 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
def9c7a9 1719 "2521 READ_FCF_RECORD mailbox failed "
0c9ab6f5
JS
1720 "with status x%x add_status x%x, "
1721 "mbx\n", shdr_status, shdr_add_status);
1722 return NULL;
6fb120a7 1723 }
0c9ab6f5
JS
1724
1725 /* Interpreting the returned information of the FCF record */
6fb120a7
JS
1726 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1727 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1728 sizeof(struct lpfc_mbx_read_fcf_tbl));
0c9ab6f5 1729 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
6fb120a7
JS
1730 new_fcf_record = (struct fcf_record *)(virt_addr +
1731 sizeof(struct lpfc_mbx_read_fcf_tbl));
1732 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
cb5172ea
JS
1733 offsetof(struct fcf_record, vlan_bitmap));
1734 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1735 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
6fb120a7 1736
0c9ab6f5
JS
1737 return new_fcf_record;
1738}
1739
1740/**
1741 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1742 * @phba: pointer to lpfc hba data structure.
1743 * @fcf_record: pointer to the fcf record.
1744 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1745 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1746 *
1747 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1748 * enabled.
1749 **/
1750static void
1751lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1752 struct fcf_record *fcf_record,
1753 uint16_t vlan_id,
1754 uint16_t next_fcf_index)
1755{
1756 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1757 "2764 READ_FCF_RECORD:\n"
1758 "\tFCF_Index : x%x\n"
1759 "\tFCF_Avail : x%x\n"
1760 "\tFCF_Valid : x%x\n"
1761 "\tFIP_Priority : x%x\n"
1762 "\tMAC_Provider : x%x\n"
1763 "\tLowest VLANID : x%x\n"
1764 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1765 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1766 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1767 "\tNext_FCF_Index: x%x\n",
1768 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1769 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1770 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1771 fcf_record->fip_priority,
1772 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1773 vlan_id,
1774 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1775 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1776 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1777 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1778 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1779 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1780 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1781 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1782 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1783 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1784 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1785 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1786 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1787 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1788 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1789 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1790 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1791 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1792 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1793 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1794 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1795 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1796 next_fcf_index);
1797}
1798
dbb6b3ab
JS
1799/**
1800 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1801 * @phba: pointer to lpfc hba data structure.
1802 * @fcf_rec: pointer to an existing FCF record.
1803 * @new_fcf_record: pointer to a new FCF record.
1804 * @new_vlan_id: vlan id from the new FCF record.
1805 *
1806 * This function performs matching test of a new FCF record against an existing
1807 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1808 * will not be used as part of the FCF record matching criteria.
1809 *
1810 * Returns true if all the fields matching, otherwise returns false.
1811 */
1812static bool
1813lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1814 struct lpfc_fcf_rec *fcf_rec,
1815 struct fcf_record *new_fcf_record,
1816 uint16_t new_vlan_id)
1817{
1818 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1819 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1820 return false;
1821 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1822 return false;
1823 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1824 return false;
1825 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1826 return false;
1827 return true;
1828}
1829
a93ff37a
JS
1830/**
1831 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1832 * @vport: Pointer to vport object.
1833 * @fcf_index: index to next fcf.
1834 *
1835 * This function processing the roundrobin fcf failover to next fcf index.
1836 * When this function is invoked, there will be a current fcf registered
1837 * for flogi.
1838 * Return: 0 for continue retrying flogi on currently registered fcf;
1839 * 1 for stop flogi on currently registered fcf;
1840 */
1841int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1842{
1843 struct lpfc_hba *phba = vport->phba;
1844 int rc;
1845
1846 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1847 spin_lock_irq(&phba->hbalock);
1848 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1849 spin_unlock_irq(&phba->hbalock);
1850 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1851 "2872 Devloss tmo with no eligible "
1852 "FCF, unregister in-use FCF (x%x) "
1853 "and rescan FCF table\n",
1854 phba->fcf.current_rec.fcf_indx);
1855 lpfc_unregister_fcf_rescan(phba);
1856 goto stop_flogi_current_fcf;
1857 }
1858 /* Mark the end to FLOGI roundrobin failover */
1859 phba->hba_flag &= ~FCF_RR_INPROG;
1860 /* Allow action to new fcf asynchronous event */
1861 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1862 spin_unlock_irq(&phba->hbalock);
1863 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1864 "2865 No FCF available, stop roundrobin FCF "
1865 "failover and change port state:x%x/x%x\n",
1866 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1867 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1868 goto stop_flogi_current_fcf;
1869 } else {
1870 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1871 "2794 Try FLOGI roundrobin FCF failover to "
1872 "(x%x)\n", fcf_index);
1873 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1874 if (rc)
1875 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1876 "2761 FLOGI roundrobin FCF failover "
1877 "failed (rc:x%x) to read FCF (x%x)\n",
1878 rc, phba->fcf.current_rec.fcf_indx);
1879 else
1880 goto stop_flogi_current_fcf;
1881 }
1882 return 0;
1883
1884stop_flogi_current_fcf:
1885 lpfc_can_disctmo(vport);
1886 return 1;
1887}
1888
0c9ab6f5
JS
1889/**
1890 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1891 * @phba: pointer to lpfc hba data structure.
1892 * @mboxq: pointer to mailbox object.
1893 *
1894 * This function iterates through all the fcf records available in
1895 * HBA and chooses the optimal FCF record for discovery. After finding
1896 * the FCF for discovery it registers the FCF record and kicks start
1897 * discovery.
1898 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1899 * use an FCF record which matches fabric name and mac address of the
1900 * currently used FCF record.
1901 * If the driver supports only one FCF, it will try to use the FCF record
1902 * used by BOOT_BIOS.
1903 */
1904void
1905lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1906{
1907 struct fcf_record *new_fcf_record;
1908 uint32_t boot_flag, addr_mode;
1909 uint16_t fcf_index, next_fcf_index;
1910 struct lpfc_fcf_rec *fcf_rec = NULL;
1911 uint16_t vlan_id;
999d813f
JS
1912 uint32_t seed;
1913 bool select_new_fcf;
0c9ab6f5
JS
1914 int rc;
1915
1916 /* If there is pending FCoE event restart FCF table scan */
a93ff37a 1917 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
0c9ab6f5
JS
1918 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1919 return;
1920 }
1921
1922 /* Parse the FCF record from the non-embedded mailbox command */
1923 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
1924 &next_fcf_index);
1925 if (!new_fcf_record) {
a93ff37a 1926 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
0c9ab6f5
JS
1927 "2765 Mailbox command READ_FCF_RECORD "
1928 "failed to retrieve a FCF record.\n");
1929 /* Let next new FCF event trigger fast failover */
1930 spin_lock_irq(&phba->hbalock);
a93ff37a 1931 phba->hba_flag &= ~FCF_TS_INPROG;
0c9ab6f5
JS
1932 spin_unlock_irq(&phba->hbalock);
1933 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1934 return;
1935 }
1936
1937 /* Check the FCF record against the connection list */
ecfd03c6
JS
1938 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1939 &addr_mode, &vlan_id);
0c9ab6f5
JS
1940
1941 /* Log the FCF record information if turned on */
1942 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
1943 next_fcf_index);
1944
6fb120a7
JS
1945 /*
1946 * If the fcf record does not match with connect list entries
0c9ab6f5 1947 * read the next entry; otherwise, this is an eligible FCF
a93ff37a 1948 * record for roundrobin FCF failover.
6fb120a7 1949 */
0c9ab6f5
JS
1950 if (!rc) {
1951 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
a93ff37a
JS
1952 "2781 FCF (x%x) failed connection "
1953 "list check: (x%x/x%x)\n",
0c9ab6f5
JS
1954 bf_get(lpfc_fcf_record_fcf_index,
1955 new_fcf_record),
1956 bf_get(lpfc_fcf_record_fcf_avail,
1957 new_fcf_record),
1958 bf_get(lpfc_fcf_record_fcf_valid,
1959 new_fcf_record));
dbb6b3ab
JS
1960 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
1961 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1962 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
5ac6b303
JS
1963 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
1964 phba->fcf.current_rec.fcf_indx) {
1965 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1966 "2862 FCF (x%x) matches property "
1967 "of in-use FCF (x%x)\n",
1968 bf_get(lpfc_fcf_record_fcf_index,
1969 new_fcf_record),
1970 phba->fcf.current_rec.fcf_indx);
1971 goto read_next_fcf;
1972 }
dbb6b3ab
JS
1973 /*
1974 * In case the current in-use FCF record becomes
1975 * invalid/unavailable during FCF discovery that
1976 * was not triggered by fast FCF failover process,
1977 * treat it as fast FCF failover.
1978 */
1979 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
1980 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1981 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1982 "2835 Invalid in-use FCF "
a93ff37a
JS
1983 "(x%x), enter FCF failover "
1984 "table scan.\n",
dbb6b3ab
JS
1985 phba->fcf.current_rec.fcf_indx);
1986 spin_lock_irq(&phba->hbalock);
1987 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
1988 spin_unlock_irq(&phba->hbalock);
1989 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1990 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
1991 LPFC_FCOE_FCF_GET_FIRST);
1992 return;
1993 }
1994 }
6fb120a7 1995 goto read_next_fcf;
0c9ab6f5
JS
1996 } else {
1997 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1998 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
1999 if (rc)
2000 goto read_next_fcf;
2001 }
2002
6fb120a7
JS
2003 /*
2004 * If this is not the first FCF discovery of the HBA, use last
ecfd03c6
JS
2005 * FCF record for the discovery. The condition that a rescan
2006 * matches the in-use FCF record: fabric name, switch name, mac
2007 * address, and vlan_id.
6fb120a7 2008 */
0c9ab6f5 2009 spin_lock_irq(&phba->hbalock);
6fb120a7 2010 if (phba->fcf.fcf_flag & FCF_IN_USE) {
dbb6b3ab
JS
2011 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2012 new_fcf_record, vlan_id)) {
5ac6b303
JS
2013 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2014 phba->fcf.current_rec.fcf_indx) {
2015 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2016 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2017 /* Stop FCF redisc wait timer */
2018 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2019 phba);
2020 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2021 /* Fast failover, mark completed */
2022 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2023 spin_unlock_irq(&phba->hbalock);
2024 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2025 "2836 New FCF matches in-use "
2026 "FCF (x%x)\n",
2027 phba->fcf.current_rec.fcf_indx);
2028 goto out;
2029 } else
2030 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2031 "2863 New FCF (x%x) matches "
2032 "property of in-use FCF (x%x)\n",
dbb6b3ab 2033 bf_get(lpfc_fcf_record_fcf_index,
5ac6b303
JS
2034 new_fcf_record),
2035 phba->fcf.current_rec.fcf_indx);
6fb120a7 2036 }
ecfd03c6
JS
2037 /*
2038 * Read next FCF record from HBA searching for the matching
2039 * with in-use record only if not during the fast failover
2040 * period. In case of fast failover period, it shall try to
2041 * determine whether the FCF record just read should be the
2042 * next candidate.
2043 */
2044 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
0c9ab6f5 2045 spin_unlock_irq(&phba->hbalock);
ecfd03c6
JS
2046 goto read_next_fcf;
2047 }
6fb120a7 2048 }
ecfd03c6
JS
2049 /*
2050 * Update on failover FCF record only if it's in FCF fast-failover
2051 * period; otherwise, update on current FCF record.
2052 */
fc2b989b
JS
2053 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2054 fcf_rec = &phba->fcf.failover_rec;
2055 else
ecfd03c6
JS
2056 fcf_rec = &phba->fcf.current_rec;
2057
6fb120a7
JS
2058 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2059 /*
ecfd03c6
JS
2060 * If the driver FCF record does not have boot flag
2061 * set and new hba fcf record has boot flag set, use
2062 * the new hba fcf record.
6fb120a7 2063 */
ecfd03c6
JS
2064 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2065 /* Choose this FCF record */
dbb6b3ab
JS
2066 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2067 "2837 Update current FCF record "
2068 "(x%x) with new FCF record (x%x)\n",
2069 fcf_rec->fcf_indx,
2070 bf_get(lpfc_fcf_record_fcf_index,
2071 new_fcf_record));
ecfd03c6
JS
2072 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2073 addr_mode, vlan_id, BOOT_ENABLE);
0c9ab6f5 2074 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
2075 goto read_next_fcf;
2076 }
2077 /*
ecfd03c6
JS
2078 * If the driver FCF record has boot flag set and the
2079 * new hba FCF record does not have boot flag, read
2080 * the next FCF record.
6fb120a7 2081 */
ecfd03c6 2082 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
0c9ab6f5 2083 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
2084 goto read_next_fcf;
2085 }
2086 /*
ecfd03c6
JS
2087 * If the new hba FCF record has lower priority value
2088 * than the driver FCF record, use the new record.
6fb120a7 2089 */
fc2b989b 2090 if (new_fcf_record->fip_priority < fcf_rec->priority) {
999d813f 2091 /* Choose the new FCF record with lower priority */
dbb6b3ab
JS
2092 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2093 "2838 Update current FCF record "
2094 "(x%x) with new FCF record (x%x)\n",
2095 fcf_rec->fcf_indx,
2096 bf_get(lpfc_fcf_record_fcf_index,
2097 new_fcf_record));
ecfd03c6
JS
2098 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2099 addr_mode, vlan_id, 0);
999d813f
JS
2100 /* Reset running random FCF selection count */
2101 phba->fcf.eligible_fcf_cnt = 1;
2102 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2103 /* Update running random FCF selection count */
2104 phba->fcf.eligible_fcf_cnt++;
2105 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2106 phba->fcf.eligible_fcf_cnt);
dbb6b3ab
JS
2107 if (select_new_fcf) {
2108 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2109 "2839 Update current FCF record "
2110 "(x%x) with new FCF record (x%x)\n",
2111 fcf_rec->fcf_indx,
2112 bf_get(lpfc_fcf_record_fcf_index,
2113 new_fcf_record));
999d813f
JS
2114 /* Choose the new FCF by random selection */
2115 __lpfc_update_fcf_record(phba, fcf_rec,
2116 new_fcf_record,
2117 addr_mode, vlan_id, 0);
dbb6b3ab 2118 }
6fb120a7 2119 }
0c9ab6f5 2120 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
2121 goto read_next_fcf;
2122 }
2123 /*
ecfd03c6
JS
2124 * This is the first suitable FCF record, choose this record for
2125 * initial best-fit FCF.
6fb120a7 2126 */
ecfd03c6 2127 if (fcf_rec) {
dbb6b3ab 2128 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
a93ff37a
JS
2129 "2840 Update initial FCF candidate "
2130 "with FCF (x%x)\n",
dbb6b3ab
JS
2131 bf_get(lpfc_fcf_record_fcf_index,
2132 new_fcf_record));
ecfd03c6
JS
2133 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2134 addr_mode, vlan_id, (boot_flag ?
2135 BOOT_ENABLE : 0));
2136 phba->fcf.fcf_flag |= FCF_AVAILABLE;
999d813f
JS
2137 /* Setup initial running random FCF selection count */
2138 phba->fcf.eligible_fcf_cnt = 1;
2139 /* Seeding the random number generator for random selection */
2140 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2141 srandom32(seed);
6fb120a7 2142 }
0c9ab6f5 2143 spin_unlock_irq(&phba->hbalock);
6fb120a7
JS
2144 goto read_next_fcf;
2145
2146read_next_fcf:
2147 lpfc_sli4_mbox_cmd_free(phba, mboxq);
ecfd03c6
JS
2148 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2149 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2150 /*
2151 * Case of FCF fast failover scan
2152 */
2153
2154 /*
2155 * It has not found any suitable FCF record, cancel
2156 * FCF scan inprogress, and do nothing
2157 */
2158 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
0c9ab6f5 2159 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
a93ff37a
JS
2160 "2782 No suitable FCF found: "
2161 "(x%x/x%x)\n",
0c9ab6f5
JS
2162 phba->fcoe_eventtag_at_fcf_scan,
2163 bf_get(lpfc_fcf_record_fcf_index,
2164 new_fcf_record));
a93ff37a
JS
2165 spin_lock_irq(&phba->hbalock);
2166 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2167 phba->hba_flag &= ~FCF_TS_INPROG;
2168 spin_unlock_irq(&phba->hbalock);
2169 /* Unregister in-use FCF and rescan */
2170 lpfc_printf_log(phba, KERN_INFO,
2171 LOG_FIP,
2172 "2864 On devloss tmo "
2173 "unreg in-use FCF and "
2174 "rescan FCF table\n");
2175 lpfc_unregister_fcf_rescan(phba);
2176 return;
2177 }
0c9ab6f5 2178 /*
a93ff37a 2179 * Let next new FCF event trigger fast failover
0c9ab6f5 2180 */
a93ff37a 2181 phba->hba_flag &= ~FCF_TS_INPROG;
0c9ab6f5 2182 spin_unlock_irq(&phba->hbalock);
ecfd03c6
JS
2183 return;
2184 }
2185 /*
2186 * It has found a suitable FCF record that is not
2187 * the same as in-use FCF record, unregister the
2188 * in-use FCF record, replace the in-use FCF record
2189 * with the new FCF record, mark FCF fast failover
2190 * completed, and then start register the new FCF
2191 * record.
2192 */
2193
0c9ab6f5 2194 /* Unregister the current in-use FCF record */
ecfd03c6 2195 lpfc_unregister_fcf(phba);
0c9ab6f5
JS
2196
2197 /* Replace in-use record with the new record */
dbb6b3ab 2198 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
a93ff37a
JS
2199 "2842 Replace in-use FCF (x%x) "
2200 "with failover FCF (x%x)\n",
dbb6b3ab
JS
2201 phba->fcf.current_rec.fcf_indx,
2202 phba->fcf.failover_rec.fcf_indx);
ecfd03c6
JS
2203 memcpy(&phba->fcf.current_rec,
2204 &phba->fcf.failover_rec,
2205 sizeof(struct lpfc_fcf_rec));
3804dc84
JS
2206 /*
2207 * Mark the fast FCF failover rediscovery completed
2208 * and the start of the first round of the roundrobin
2209 * FCF failover.
2210 */
0c9ab6f5 2211 spin_lock_irq(&phba->hbalock);
a93ff37a 2212 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
0c9ab6f5 2213 spin_unlock_irq(&phba->hbalock);
ecfd03c6
JS
2214 /* Register to the new FCF record */
2215 lpfc_register_fcf(phba);
2216 } else {
2217 /*
2218 * In case of transaction period to fast FCF failover,
2219 * do nothing when search to the end of the FCF table.
2220 */
2221 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2222 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2223 return;
dbb6b3ab
JS
2224
2225 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2226 /*
2227 * In case the current in-use FCF record no
2228 * longer existed during FCF discovery that
2229 * was not triggered by fast FCF failover
2230 * process, treat it as fast FCF failover.
2231 */
2232 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2233 "2841 In-use FCF record (x%x) "
2234 "not reported, entering fast "
2235 "FCF failover mode scanning.\n",
2236 phba->fcf.current_rec.fcf_indx);
2237 spin_lock_irq(&phba->hbalock);
2238 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2239 spin_unlock_irq(&phba->hbalock);
2240 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2241 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2242 LPFC_FCOE_FCF_GET_FIRST);
2243 return;
2244 }
0c9ab6f5 2245 /* Register to the new FCF record */
ecfd03c6
JS
2246 lpfc_register_fcf(phba);
2247 }
2248 } else
0c9ab6f5 2249 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
6fb120a7
JS
2250 return;
2251
2252out:
2253 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2254 lpfc_register_fcf(phba);
2255
2256 return;
2257}
2258
0c9ab6f5 2259/**
a93ff37a 2260 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
0c9ab6f5
JS
2261 * @phba: pointer to lpfc hba data structure.
2262 * @mboxq: pointer to mailbox object.
2263 *
a93ff37a 2264 * This is the callback function for FLOGI failure roundrobin FCF failover
0c9ab6f5
JS
2265 * read FCF record mailbox command from the eligible FCF record bmask for
2266 * performing the failover. If the FCF read back is not valid/available, it
2267 * fails through to retrying FLOGI to the currently registered FCF again.
2268 * Otherwise, if the FCF read back is valid and available, it will set the
2269 * newly read FCF record to the failover FCF record, unregister currently
2270 * registered FCF record, copy the failover FCF record to the current
2271 * FCF record, and then register the current FCF record before proceeding
2272 * to trying FLOGI on the new failover FCF.
2273 */
2274void
2275lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2276{
2277 struct fcf_record *new_fcf_record;
2278 uint32_t boot_flag, addr_mode;
a93ff37a 2279 uint16_t next_fcf_index, fcf_index;
0c9ab6f5
JS
2280 uint16_t current_fcf_index;
2281 uint16_t vlan_id;
a93ff37a 2282 int rc;
0c9ab6f5 2283
a93ff37a 2284 /* If link state is not up, stop the roundrobin failover process */
0c9ab6f5
JS
2285 if (phba->link_state < LPFC_LINK_UP) {
2286 spin_lock_irq(&phba->hbalock);
2287 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
a93ff37a 2288 phba->hba_flag &= ~FCF_RR_INPROG;
0c9ab6f5 2289 spin_unlock_irq(&phba->hbalock);
a93ff37a 2290 goto out;
0c9ab6f5
JS
2291 }
2292
2293 /* Parse the FCF record from the non-embedded mailbox command */
2294 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2295 &next_fcf_index);
2296 if (!new_fcf_record) {
2297 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2298 "2766 Mailbox command READ_FCF_RECORD "
2299 "failed to retrieve a FCF record.\n");
a93ff37a 2300 goto error_out;
0c9ab6f5
JS
2301 }
2302
2303 /* Get the needed parameters from FCF record */
a93ff37a
JS
2304 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2305 &addr_mode, &vlan_id);
0c9ab6f5
JS
2306
2307 /* Log the FCF record information if turned on */
2308 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2309 next_fcf_index);
2310
a93ff37a
JS
2311 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2312 if (!rc) {
2313 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2314 "2848 Remove ineligible FCF (x%x) from "
2315 "from roundrobin bmask\n", fcf_index);
2316 /* Clear roundrobin bmask bit for ineligible FCF */
2317 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2318 /* Perform next round of roundrobin FCF failover */
2319 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2320 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2321 if (rc)
2322 goto out;
2323 goto error_out;
2324 }
2325
2326 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2327 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2328 "2760 Perform FLOGI roundrobin FCF failover: "
2329 "FCF (x%x) back to FCF (x%x)\n",
2330 phba->fcf.current_rec.fcf_indx, fcf_index);
2331 /* Wait 500 ms before retrying FLOGI to current FCF */
2332 msleep(500);
76a95d75 2333 lpfc_issue_init_vfi(phba->pport);
a93ff37a
JS
2334 goto out;
2335 }
2336
0c9ab6f5 2337 /* Upload new FCF record to the failover FCF record */
dbb6b3ab 2338 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
a93ff37a
JS
2339 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2340 phba->fcf.failover_rec.fcf_indx, fcf_index);
0c9ab6f5
JS
2341 spin_lock_irq(&phba->hbalock);
2342 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2343 new_fcf_record, addr_mode, vlan_id,
2344 (boot_flag ? BOOT_ENABLE : 0));
2345 spin_unlock_irq(&phba->hbalock);
2346
2347 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2348
2349 /* Unregister the current in-use FCF record */
2350 lpfc_unregister_fcf(phba);
2351
2352 /* Replace in-use record with the new record */
2353 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2354 sizeof(struct lpfc_fcf_rec));
2355
2356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
a93ff37a
JS
2357 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2358 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
0c9ab6f5 2359
a93ff37a
JS
2360error_out:
2361 lpfc_register_fcf(phba);
0c9ab6f5
JS
2362out:
2363 lpfc_sli4_mbox_cmd_free(phba, mboxq);
0c9ab6f5
JS
2364}
2365
2366/**
2367 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2368 * @phba: pointer to lpfc hba data structure.
2369 * @mboxq: pointer to mailbox object.
2370 *
2371 * This is the callback function of read FCF record mailbox command for
a93ff37a 2372 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
0c9ab6f5
JS
2373 * failover when a new FCF event happened. If the FCF read back is
2374 * valid/available and it passes the connection list check, it updates
a93ff37a 2375 * the bmask for the eligible FCF record for roundrobin failover.
0c9ab6f5
JS
2376 */
2377void
2378lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2379{
2380 struct fcf_record *new_fcf_record;
2381 uint32_t boot_flag, addr_mode;
2382 uint16_t fcf_index, next_fcf_index;
2383 uint16_t vlan_id;
2384 int rc;
2385
2386 /* If link state is not up, no need to proceed */
2387 if (phba->link_state < LPFC_LINK_UP)
2388 goto out;
2389
2390 /* If FCF discovery period is over, no need to proceed */
3804dc84 2391 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
0c9ab6f5
JS
2392 goto out;
2393
2394 /* Parse the FCF record from the non-embedded mailbox command */
2395 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2396 &next_fcf_index);
2397 if (!new_fcf_record) {
2398 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2399 "2767 Mailbox command READ_FCF_RECORD "
2400 "failed to retrieve a FCF record.\n");
2401 goto out;
2402 }
2403
2404 /* Check the connection list for eligibility */
2405 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2406 &addr_mode, &vlan_id);
2407
2408 /* Log the FCF record information if turned on */
2409 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2410 next_fcf_index);
2411
2412 if (!rc)
2413 goto out;
2414
2415 /* Update the eligible FCF record index bmask */
2416 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2417 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
2418
2419out:
2420 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2421}
2422
76a95d75
JS
2423/**
2424 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2425 * @phba: pointer to lpfc hba data structure.
2426 * @mboxq: pointer to mailbox data structure.
2427 *
2428 * This function handles completion of init vfi mailbox command.
2429 */
2430void
2431lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2432{
2433 struct lpfc_vport *vport = mboxq->vport;
2434
2435 if (mboxq->u.mb.mbxStatus && (mboxq->u.mb.mbxStatus != 0x4002)) {
2436 lpfc_printf_vlog(vport, KERN_ERR,
2437 LOG_MBOX,
2438 "2891 Init VFI mailbox failed 0x%x\n",
2439 mboxq->u.mb.mbxStatus);
2440 mempool_free(mboxq, phba->mbox_mem_pool);
2441 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2442 return;
2443 }
2444 lpfc_initial_flogi(vport);
2445 mempool_free(mboxq, phba->mbox_mem_pool);
2446 return;
2447}
2448
2449/**
2450 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2451 * @vport: pointer to lpfc_vport data structure.
2452 *
2453 * This function issue a init_vfi mailbox command to initialize the VFI and
2454 * VPI for the physical port.
2455 */
2456void
2457lpfc_issue_init_vfi(struct lpfc_vport *vport)
2458{
2459 LPFC_MBOXQ_t *mboxq;
2460 int rc;
2461 struct lpfc_hba *phba = vport->phba;
2462
2463 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2464 if (!mboxq) {
2465 lpfc_printf_vlog(vport, KERN_ERR,
2466 LOG_MBOX, "2892 Failed to allocate "
2467 "init_vfi mailbox\n");
2468 return;
2469 }
2470 lpfc_init_vfi(mboxq, vport);
2471 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2472 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2473 if (rc == MBX_NOT_FINISHED) {
2474 lpfc_printf_vlog(vport, KERN_ERR,
2475 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2476 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2477 }
2478}
2479
1c6834a7
JS
2480/**
2481 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2482 * @phba: pointer to lpfc hba data structure.
2483 * @mboxq: pointer to mailbox data structure.
2484 *
2485 * This function handles completion of init vpi mailbox command.
2486 */
695a814e 2487void
1c6834a7
JS
2488lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2489{
2490 struct lpfc_vport *vport = mboxq->vport;
695a814e 2491 struct lpfc_nodelist *ndlp;
72100cc4
JS
2492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2493
1c6834a7
JS
2494 if (mboxq->u.mb.mbxStatus) {
2495 lpfc_printf_vlog(vport, KERN_ERR,
2496 LOG_MBOX,
2497 "2609 Init VPI mailbox failed 0x%x\n",
2498 mboxq->u.mb.mbxStatus);
2499 mempool_free(mboxq, phba->mbox_mem_pool);
2500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2501 return;
2502 }
72100cc4 2503 spin_lock_irq(shost->host_lock);
1c6834a7 2504 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
72100cc4 2505 spin_unlock_irq(shost->host_lock);
1c6834a7 2506
695a814e
JS
2507 /* If this port is physical port or FDISC is done, do reg_vpi */
2508 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2509 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2510 if (!ndlp)
2511 lpfc_printf_vlog(vport, KERN_ERR,
2512 LOG_DISCOVERY,
2513 "2731 Cannot find fabric "
2514 "controller node\n");
2515 else
2516 lpfc_register_new_vport(phba, vport, ndlp);
2517 mempool_free(mboxq, phba->mbox_mem_pool);
2518 return;
2519 }
2520
1c6834a7
JS
2521 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2522 lpfc_initial_fdisc(vport);
2523 else {
2524 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
6a9c52cf
JS
2525 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2526 "2606 No NPIV Fabric support\n");
1c6834a7 2527 }
695a814e 2528 mempool_free(mboxq, phba->mbox_mem_pool);
1c6834a7
JS
2529 return;
2530}
2531
ecfd03c6
JS
2532/**
2533 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2534 * @vport: pointer to lpfc_vport data structure.
2535 *
2536 * This function issue a init_vpi mailbox command to initialize
2537 * VPI for the vport.
2538 */
2539void
2540lpfc_issue_init_vpi(struct lpfc_vport *vport)
2541{
2542 LPFC_MBOXQ_t *mboxq;
2543 int rc;
2544
2545 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2546 if (!mboxq) {
2547 lpfc_printf_vlog(vport, KERN_ERR,
2548 LOG_MBOX, "2607 Failed to allocate "
2549 "init_vpi mailbox\n");
2550 return;
2551 }
2552 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2553 mboxq->vport = vport;
2554 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2555 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2556 if (rc == MBX_NOT_FINISHED) {
2557 lpfc_printf_vlog(vport, KERN_ERR,
2558 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2559 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2560 }
2561}
2562
6fb120a7
JS
2563/**
2564 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2565 * @phba: pointer to lpfc hba data structure.
2566 *
2567 * This function loops through the list of vports on the @phba and issues an
2568 * FDISC if possible.
2569 */
2570void
2571lpfc_start_fdiscs(struct lpfc_hba *phba)
2572{
2573 struct lpfc_vport **vports;
2574 int i;
2575
2576 vports = lpfc_create_vport_work_array(phba);
2577 if (vports != NULL) {
2578 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2579 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2580 continue;
2581 /* There are no vpi for this vport */
2582 if (vports[i]->vpi > phba->max_vpi) {
2583 lpfc_vport_set_state(vports[i],
2584 FC_VPORT_FAILED);
2585 continue;
2586 }
76a95d75 2587 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6fb120a7
JS
2588 lpfc_vport_set_state(vports[i],
2589 FC_VPORT_LINKDOWN);
2590 continue;
2591 }
1c6834a7 2592 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
ecfd03c6 2593 lpfc_issue_init_vpi(vports[i]);
1c6834a7
JS
2594 continue;
2595 }
6fb120a7
JS
2596 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2597 lpfc_initial_fdisc(vports[i]);
2598 else {
2599 lpfc_vport_set_state(vports[i],
2600 FC_VPORT_NO_FABRIC_SUPP);
2601 lpfc_printf_vlog(vports[i], KERN_ERR,
2602 LOG_ELS,
2603 "0259 No NPIV "
2604 "Fabric support\n");
2605 }
2606 }
2607 }
2608 lpfc_destroy_vport_work_array(phba, vports);
2609}
2610
2611void
2612lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2613{
2614 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2615 struct lpfc_vport *vport = mboxq->vport;
72100cc4 2616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6fb120a7
JS
2617
2618 if (mboxq->u.mb.mbxStatus) {
2619 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2620 "2018 REG_VFI mbxStatus error x%x "
2621 "HBA state x%x\n",
2622 mboxq->u.mb.mbxStatus, vport->port_state);
76a95d75 2623 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6fb120a7
JS
2624 /* FLOGI failed, use loop map to make discovery list */
2625 lpfc_disc_list_loopmap(vport);
2626 /* Start discovery */
2627 lpfc_disc_start(vport);
2628 goto fail_free_mem;
2629 }
2630 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2631 goto fail_free_mem;
2632 }
c868595d 2633 /* The VPI is implicitly registered when the VFI is registered */
72100cc4 2634 spin_lock_irq(shost->host_lock);
c868595d 2635 vport->vpi_state |= LPFC_VPI_REGISTERED;
695a814e 2636 vport->fc_flag |= FC_VFI_REGISTERED;
695a814e 2637 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
72100cc4 2638 spin_unlock_irq(shost->host_lock);
6fb120a7
JS
2639
2640 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
76a95d75
JS
2641 /* For private loop just start discovery and we are done. */
2642 if ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2643 (phba->alpa_map[0] == 0) &&
2644 !(vport->fc_flag & FC_PUBLIC_LOOP)) {
2645 /* Use loop map to make discovery list */
2646 lpfc_disc_list_loopmap(vport);
2647 /* Start discovery */
2648 lpfc_disc_start(vport);
2649 } else {
2650 lpfc_start_fdiscs(phba);
2651 lpfc_do_scr_ns_plogi(phba, vport);
2652 }
6fb120a7
JS
2653 }
2654
2655fail_free_mem:
2656 mempool_free(mboxq, phba->mbox_mem_pool);
2657 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2658 kfree(dmabuf);
2659 return;
2660}
2661
dea3101e 2662static void
2e0fef85 2663lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 2664{
6fb120a7 2665 MAILBOX_t *mb = &pmb->u.mb;
dea3101e 2666 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
2e0fef85 2667 struct lpfc_vport *vport = pmb->vport;
dea3101e 2668
2669
2670 /* Check for error */
2671 if (mb->mbxStatus) {
2672 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
e8b62011
JS
2673 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2674 "0319 READ_SPARAM mbxStatus error x%x "
2675 "hba state x%x>\n",
2676 mb->mbxStatus, vport->port_state);
dea3101e 2677 lpfc_linkdown(phba);
dea3101e 2678 goto out;
2679 }
2680
2e0fef85 2681 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea3101e 2682 sizeof (struct serv_parm));
a12e07bc 2683 if (phba->cfg_soft_wwnn)
2e0fef85
JS
2684 u64_to_wwn(phba->cfg_soft_wwnn,
2685 vport->fc_sparam.nodeName.u.wwn);
c3f28afa 2686 if (phba->cfg_soft_wwpn)
2e0fef85
JS
2687 u64_to_wwn(phba->cfg_soft_wwpn,
2688 vport->fc_sparam.portName.u.wwn);
92d7f7b0
JS
2689 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
2690 sizeof(vport->fc_nodename));
2691 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
2692 sizeof(vport->fc_portname));
2693 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2694 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2695 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2696 }
2697
dea3101e 2698 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2699 kfree(mp);
2e0fef85 2700 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 2701 return;
2702
2703out:
2704 pmb->context1 = NULL;
2705 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2706 kfree(mp);
92d7f7b0
JS
2707 lpfc_issue_clear_la(phba, vport);
2708 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 2709 return;
2710}
2711
2712static void
76a95d75 2713lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea3101e 2714{
92d7f7b0 2715 struct lpfc_vport *vport = phba->pport;
6fb120a7 2716 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
2e0fef85 2717 int i;
14691150
JS
2718 struct lpfc_dmabuf *mp;
2719 int rc;
6fb120a7 2720 struct fcf_record *fcf_record;
14691150 2721
92d7f7b0 2722 spin_lock_irq(&phba->hbalock);
76a95d75
JS
2723 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
2724 case LPFC_LINK_SPEED_1GHZ:
2725 case LPFC_LINK_SPEED_2GHZ:
2726 case LPFC_LINK_SPEED_4GHZ:
2727 case LPFC_LINK_SPEED_8GHZ:
2728 case LPFC_LINK_SPEED_10GHZ:
2729 case LPFC_LINK_SPEED_16GHZ:
2730 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
f4b4c68f 2731 break;
92d7f7b0 2732 default:
76a95d75 2733 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
92d7f7b0 2734 break;
dea3101e 2735 }
2736
76a95d75 2737 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
92d7f7b0 2738 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea3101e 2739
76a95d75 2740 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
92d7f7b0 2741 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea3101e 2742
6a9c52cf
JS
2743 /* if npiv is enabled and this adapter supports npiv log
2744 * a message that npiv is not supported in this topology
2745 */
2746 if (phba->cfg_enable_npiv && phba->max_vpi)
495a714c
JS
2747 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2748 "1309 Link Up Event npiv not supported in loop "
2749 "topology\n");
92d7f7b0 2750 /* Get Loop Map information */
76a95d75 2751 if (bf_get(lpfc_mbx_read_top_il, la))
2e0fef85 2752 vport->fc_flag |= FC_LBIT;
dea3101e 2753
76a95d75
JS
2754 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
2755 i = la->lilpBde64.tus.f.bdeSize;
dea3101e 2756
2757 if (i == 0) {
2758 phba->alpa_map[0] = 0;
2759 } else {
e8b62011 2760 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea3101e 2761 int numalpa, j, k;
2762 union {
2763 uint8_t pamap[16];
2764 struct {
2765 uint32_t wd1;
2766 uint32_t wd2;
2767 uint32_t wd3;
2768 uint32_t wd4;
2769 } pa;
2770 } un;
2771 numalpa = phba->alpa_map[0];
2772 j = 0;
2773 while (j < numalpa) {
2774 memset(un.pamap, 0, 16);
2775 for (k = 1; j < numalpa; k++) {
2776 un.pamap[k - 1] =
2777 phba->alpa_map[j + 1];
2778 j++;
2779 if (k == 16)
2780 break;
2781 }
2782 /* Link Up Event ALPA map */
2783 lpfc_printf_log(phba,
92d7f7b0
JS
2784 KERN_WARNING,
2785 LOG_LINK_EVENT,
e8b62011 2786 "1304 Link Up Event "
92d7f7b0
JS
2787 "ALPA map Data: x%x "
2788 "x%x x%x x%x\n",
92d7f7b0
JS
2789 un.pa.wd1, un.pa.wd2,
2790 un.pa.wd3, un.pa.wd4);
dea3101e 2791 }
2792 }
2793 }
2794 } else {
92d7f7b0 2795 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
78b2d852 2796 if (phba->max_vpi && phba->cfg_enable_npiv &&
92d7f7b0
JS
2797 (phba->sli_rev == 3))
2798 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
2799 }
2e0fef85
JS
2800 vport->fc_myDID = phba->fc_pref_DID;
2801 vport->fc_flag |= FC_LBIT;
dea3101e 2802 }
92d7f7b0 2803 spin_unlock_irq(&phba->hbalock);
dea3101e 2804
2805 lpfc_linkup(phba);
9f1177a3
JS
2806 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2807 if (!sparam_mbox)
2808 goto out;
2809
2810 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
2811 if (rc) {
2812 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2813 goto out;
2814 }
2815 sparam_mbox->vport = vport;
2816 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
2817 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
2818 if (rc == MBX_NOT_FINISHED) {
2819 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
2820 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2821 kfree(mp);
2822 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2823 goto out;
dea3101e 2824 }
2825
76a95d75 2826 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
6fb120a7
JS
2827 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2828 if (!cfglink_mbox)
2829 goto out;
2e0fef85 2830 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea3101e 2831 lpfc_config_link(phba, cfglink_mbox);
2e0fef85 2832 cfglink_mbox->vport = vport;
25594c6b 2833 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
0b727fea 2834 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
6fb120a7
JS
2835 if (rc == MBX_NOT_FINISHED) {
2836 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
2837 goto out;
2838 }
2839 } else {
32b9793f 2840 vport->port_state = LPFC_VPORT_UNKNOWN;
6fb120a7
JS
2841 /*
2842 * Add the driver's default FCF record at FCF index 0 now. This
2843 * is phase 1 implementation that support FCF index 0 and driver
2844 * defaults.
2845 */
45ed1190 2846 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
6fb120a7
JS
2847 fcf_record = kzalloc(sizeof(struct fcf_record),
2848 GFP_KERNEL);
2849 if (unlikely(!fcf_record)) {
2850 lpfc_printf_log(phba, KERN_ERR,
2851 LOG_MBOX | LOG_SLI,
2852 "2554 Could not allocate memmory for "
2853 "fcf record\n");
2854 rc = -ENODEV;
2855 goto out;
2856 }
2857
2858 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
2859 LPFC_FCOE_FCF_DEF_INDEX);
2860 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
2861 if (unlikely(rc)) {
2862 lpfc_printf_log(phba, KERN_ERR,
2863 LOG_MBOX | LOG_SLI,
2864 "2013 Could not manually add FCF "
2865 "record 0, status %d\n", rc);
2866 rc = -ENODEV;
2867 kfree(fcf_record);
2868 goto out;
2869 }
2870 kfree(fcf_record);
2871 }
2872 /*
2873 * The driver is expected to do FIP/FCF. Call the port
2874 * and get the FCF Table.
2875 */
32b9793f 2876 spin_lock_irq(&phba->hbalock);
a93ff37a 2877 if (phba->hba_flag & FCF_TS_INPROG) {
32b9793f
JS
2878 spin_unlock_irq(&phba->hbalock);
2879 return;
2880 }
0c9ab6f5
JS
2881 /* This is the initial FCF discovery scan */
2882 phba->fcf.fcf_flag |= FCF_INIT_DISC;
32b9793f 2883 spin_unlock_irq(&phba->hbalock);
0c9ab6f5
JS
2884 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2885 "2778 Start FCF table scan at linkup\n");
0c9ab6f5
JS
2886 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2887 LPFC_FCOE_FCF_GET_FIRST);
2888 if (rc) {
2889 spin_lock_irq(&phba->hbalock);
2890 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
2891 spin_unlock_irq(&phba->hbalock);
6fb120a7 2892 goto out;
0c9ab6f5 2893 }
38b92ef8
JS
2894 /* Reset FCF roundrobin bmask for new discovery */
2895 memset(phba->fcf.fcf_rr_bmask, 0,
2896 sizeof(*phba->fcf.fcf_rr_bmask));
dea3101e 2897 }
6fb120a7
JS
2898
2899 return;
92d7f7b0
JS
2900out:
2901 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e8b62011
JS
2902 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2903 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2904 vport->port_state, sparam_mbox, cfglink_mbox);
92d7f7b0
JS
2905 lpfc_issue_clear_la(phba, vport);
2906 return;
dea3101e 2907}
2908
2909static void
84774a4d 2910lpfc_enable_la(struct lpfc_hba *phba)
2e0fef85 2911{
dea3101e 2912 uint32_t control;
2913 struct lpfc_sli *psli = &phba->sli;
2e0fef85 2914 spin_lock_irq(&phba->hbalock);
dea3101e 2915 psli->sli_flag |= LPFC_PROCESS_LA;
3772a991
JS
2916 if (phba->sli_rev <= LPFC_SLI_REV3) {
2917 control = readl(phba->HCregaddr);
2918 control |= HC_LAINT_ENA;
2919 writel(control, phba->HCregaddr);
2920 readl(phba->HCregaddr); /* flush */
2921 }
2e0fef85 2922 spin_unlock_irq(&phba->hbalock);
dea3101e 2923}
2924
84774a4d
JS
2925static void
2926lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
2927{
2928 lpfc_linkdown(phba);
2929 lpfc_enable_la(phba);
6fb120a7 2930 lpfc_unregister_unused_fcf(phba);
84774a4d
JS
2931 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2932}
2933
2934
dea3101e 2935/*
76a95d75 2936 * This routine handles processing a READ_TOPOLOGY mailbox
dea3101e 2937 * command upon completion. It is setup in the LPFC_MBOXQ
2938 * as the completion routine when the command is
2939 * handed off to the SLI layer.
2940 */
2941void
76a95d75 2942lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 2943{
2e0fef85
JS
2944 struct lpfc_vport *vport = pmb->vport;
2945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
76a95d75 2946 struct lpfc_mbx_read_top *la;
04c68496 2947 MAILBOX_t *mb = &pmb->u.mb;
dea3101e 2948 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2949
0d2b6b83
JS
2950 /* Unblock ELS traffic */
2951 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea3101e 2952 /* Check for error */
2953 if (mb->mbxStatus) {
ed957684 2954 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
e8b62011
JS
2955 "1307 READ_LA mbox error x%x state x%x\n",
2956 mb->mbxStatus, vport->port_state);
dea3101e 2957 lpfc_mbx_issue_link_down(phba);
2e0fef85 2958 phba->link_state = LPFC_HBA_ERROR;
76a95d75 2959 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea3101e 2960 }
2961
76a95d75 2962 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
dea3101e 2963
2964 memcpy(&phba->alpa_map[0], mp->virt, 128);
2965
2e0fef85 2966 spin_lock_irq(shost->host_lock);
76a95d75 2967 if (bf_get(lpfc_mbx_read_top_pb, la))
2e0fef85 2968 vport->fc_flag |= FC_BYPASSED_MODE;
c9f8735b 2969 else
2e0fef85
JS
2970 vport->fc_flag &= ~FC_BYPASSED_MODE;
2971 spin_unlock_irq(shost->host_lock);
c9f8735b 2972
0c287589 2973 if ((phba->fc_eventTag < la->eventTag) ||
92d7f7b0 2974 (phba->fc_eventTag == la->eventTag)) {
dea3101e 2975 phba->fc_stat.LinkMultiEvent++;
76a95d75 2976 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
dea3101e 2977 if (phba->fc_eventTag != 0)
2978 lpfc_linkdown(phba);
92d7f7b0 2979 }
dea3101e 2980
2981 phba->fc_eventTag = la->eventTag;
72100cc4 2982 spin_lock_irq(&phba->hbalock);
76a95d75 2983 if (bf_get(lpfc_mbx_read_top_mm, la))
84774a4d
JS
2984 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2985 else
2986 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
72100cc4 2987 spin_unlock_irq(&phba->hbalock);
dea3101e 2988
4d9ab994 2989 phba->link_events++;
76a95d75
JS
2990 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
2991 (!bf_get(lpfc_mbx_read_top_mm, la))) {
dea3101e 2992 phba->fc_stat.LinkUp++;
2e0fef85 2993 if (phba->link_flag & LS_LOOPBACK_MODE) {
3163f725 2994 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
e8b62011
JS
2995 "1306 Link Up Event in loop back mode "
2996 "x%x received Data: x%x x%x x%x x%x\n",
2997 la->eventTag, phba->fc_eventTag,
76a95d75
JS
2998 bf_get(lpfc_mbx_read_top_alpa_granted,
2999 la),
3000 bf_get(lpfc_mbx_read_top_link_spd, la),
e8b62011 3001 phba->alpa_map[0]);
5b8bd0c9
JS
3002 } else {
3003 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
e8b62011 3004 "1303 Link Up Event x%x received "
84774a4d 3005 "Data: x%x x%x x%x x%x x%x x%x %d\n",
e8b62011 3006 la->eventTag, phba->fc_eventTag,
76a95d75
JS
3007 bf_get(lpfc_mbx_read_top_alpa_granted,
3008 la),
3009 bf_get(lpfc_mbx_read_top_link_spd, la),
84774a4d 3010 phba->alpa_map[0],
76a95d75
JS
3011 bf_get(lpfc_mbx_read_top_mm, la),
3012 bf_get(lpfc_mbx_read_top_fa, la),
84774a4d 3013 phba->wait_4_mlo_maint_flg);
5b8bd0c9 3014 }
92d7f7b0 3015 lpfc_mbx_process_link_up(phba, la);
76a95d75
JS
3016 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3017 LPFC_ATT_LINK_DOWN) {
dea3101e 3018 phba->fc_stat.LinkDown++;
3163f725
JS
3019 if (phba->link_flag & LS_LOOPBACK_MODE) {
3020 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3021 "1308 Link Down Event in loop back mode "
3022 "x%x received "
3023 "Data: x%x x%x x%x\n",
3024 la->eventTag, phba->fc_eventTag,
3025 phba->pport->port_state, vport->fc_flag);
3026 }
3027 else {
3028 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
e8b62011 3029 "1305 Link Down Event x%x received "
84774a4d
JS
3030 "Data: x%x x%x x%x x%x x%x\n",
3031 la->eventTag, phba->fc_eventTag,
3032 phba->pport->port_state, vport->fc_flag,
76a95d75
JS
3033 bf_get(lpfc_mbx_read_top_mm, la),
3034 bf_get(lpfc_mbx_read_top_fa, la));
84774a4d
JS
3035 }
3036 lpfc_mbx_issue_link_down(phba);
3037 }
76a95d75
JS
3038 if ((bf_get(lpfc_mbx_read_top_mm, la)) &&
3039 (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)) {
84774a4d
JS
3040 if (phba->link_state != LPFC_LINK_DOWN) {
3041 phba->fc_stat.LinkDown++;
3042 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3043 "1312 Link Down Event x%x received "
dea3101e 3044 "Data: x%x x%x x%x\n",
e8b62011 3045 la->eventTag, phba->fc_eventTag,
2e0fef85 3046 phba->pport->port_state, vport->fc_flag);
84774a4d
JS
3047 lpfc_mbx_issue_link_down(phba);
3048 } else
3049 lpfc_enable_la(phba);
3050
3051 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3052 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3053 "Data: x%x x%x x%x\n",
3054 la->eventTag, phba->fc_eventTag,
3055 phba->pport->port_state, vport->fc_flag);
3056 /*
3057 * The cmnd that triggered this will be waiting for this
3058 * signal.
3059 */
3060 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3061 if (phba->wait_4_mlo_maint_flg) {
3062 phba->wait_4_mlo_maint_flg = 0;
3063 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3163f725 3064 }
84774a4d
JS
3065 }
3066
76a95d75
JS
3067 if (bf_get(lpfc_mbx_read_top_fa, la)) {
3068 if (bf_get(lpfc_mbx_read_top_mm, la))
84774a4d
JS
3069 lpfc_issue_clear_la(phba, vport);
3070 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
76a95d75
JS
3071 "1311 fa %d\n",
3072 bf_get(lpfc_mbx_read_top_fa, la));
dea3101e 3073 }
3074
76a95d75 3075lpfc_mbx_cmpl_read_topology_free_mbuf:
dea3101e 3076 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3077 kfree(mp);
3078 mempool_free(pmb, phba->mbox_mem_pool);
3079 return;
3080}
3081
3082/*
3083 * This routine handles processing a REG_LOGIN mailbox
3084 * command upon completion. It is setup in the LPFC_MBOXQ
3085 * as the completion routine when the command is
3086 * handed off to the SLI layer.
3087 */
3088void
2e0fef85 3089lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 3090{
2e0fef85 3091 struct lpfc_vport *vport = pmb->vport;
92d7f7b0 3092 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2e0fef85 3093 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
ffc95493 3094 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 3095
dea3101e 3096 pmb->context1 = NULL;
d439d286 3097 pmb->context2 = NULL;
dea3101e 3098
ffc95493
JS
3099 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3100 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3101
3102 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3103 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3104 /* We rcvd a rscn after issuing this
3105 * mbox reg login, we may have cycled
3106 * back through the state and be
3107 * back at reg login state so this
3108 * mbox needs to be ignored becase
3109 * there is another reg login in
3110 * proccess.
3111 */
3112 spin_lock_irq(shost->host_lock);
3113 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3114 spin_unlock_irq(shost->host_lock);
3115 if (phba->sli_rev == LPFC_SLI_REV4)
3116 lpfc_sli4_free_rpi(phba,
3117 pmb->u.mb.un.varRegLogin.rpi);
3118
3119 } else
3120 /* Good status, call state machine */
3121 lpfc_disc_state_machine(vport, ndlp, pmb,
3122 NLP_EVT_CMPL_REG_LOGIN);
3123
dea3101e 3124 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3125 kfree(mp);
2e0fef85 3126 mempool_free(pmb, phba->mbox_mem_pool);
fa4066b6
JS
3127 /* decrement the node reference count held for this callback
3128 * function.
3129 */
329f9bc7 3130 lpfc_nlp_put(ndlp);
dea3101e 3131
3132 return;
3133}
3134
92d7f7b0
JS
3135static void
3136lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3137{
04c68496 3138 MAILBOX_t *mb = &pmb->u.mb;
92d7f7b0
JS
3139 struct lpfc_vport *vport = pmb->vport;
3140 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3141
3142 switch (mb->mbxStatus) {
3143 case 0x0011:
3144 case 0x0020:
e8b62011
JS
3145 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3146 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3147 mb->mbxStatus);
92d7f7b0 3148 break;
78730cfe
JS
3149 /* If VPI is busy, reset the HBA */
3150 case 0x9700:
3151 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3152 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3153 vport->vpi, mb->mbxStatus);
3154 if (!(phba->pport->load_flag & FC_UNLOADING))
3155 lpfc_workq_post_event(phba, NULL, NULL,
3156 LPFC_EVT_RESET_HBA);
92d7f7b0 3157 }
72100cc4 3158 spin_lock_irq(shost->host_lock);
c868595d 3159 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
1987807d 3160 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
72100cc4 3161 spin_unlock_irq(shost->host_lock);
92d7f7b0
JS
3162 vport->unreg_vpi_cmpl = VPORT_OK;
3163 mempool_free(pmb, phba->mbox_mem_pool);
3164 /*
3165 * This shost reference might have been taken at the beginning of
3166 * lpfc_vport_delete()
3167 */
1c6f4ef5 3168 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
92d7f7b0
JS
3169 scsi_host_put(shost);
3170}
3171
d7c255b2 3172int
92d7f7b0
JS
3173lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3174{
3175 struct lpfc_hba *phba = vport->phba;
3176 LPFC_MBOXQ_t *mbox;
3177 int rc;
3178
3179 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3180 if (!mbox)
d7c255b2 3181 return 1;
92d7f7b0
JS
3182
3183 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3184 mbox->vport = vport;
3185 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
0b727fea 3186 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
92d7f7b0 3187 if (rc == MBX_NOT_FINISHED) {
e8b62011
JS
3188 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3189 "1800 Could not issue unreg_vpi\n");
92d7f7b0
JS
3190 mempool_free(mbox, phba->mbox_mem_pool);
3191 vport->unreg_vpi_cmpl = VPORT_ERROR;
d7c255b2 3192 return rc;
92d7f7b0 3193 }
d7c255b2 3194 return 0;
92d7f7b0
JS
3195}
3196
3197static void
3198lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3199{
3200 struct lpfc_vport *vport = pmb->vport;
3201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
04c68496 3202 MAILBOX_t *mb = &pmb->u.mb;
92d7f7b0
JS
3203
3204 switch (mb->mbxStatus) {
3205 case 0x0011:
3206 case 0x9601:
3207 case 0x9602:
e8b62011
JS
3208 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3209 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3210 mb->mbxStatus);
92d7f7b0
JS
3211 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3212 spin_lock_irq(shost->host_lock);
3213 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3214 spin_unlock_irq(shost->host_lock);
3215 vport->fc_myDID = 0;
3216 goto out;
3217 }
92d7f7b0 3218
72100cc4 3219 spin_lock_irq(shost->host_lock);
c868595d 3220 vport->vpi_state |= LPFC_VPI_REGISTERED;
695a814e 3221 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
72100cc4 3222 spin_unlock_irq(shost->host_lock);
92d7f7b0
JS
3223 vport->num_disc_nodes = 0;
3224 /* go thru NPR list and issue ELS PLOGIs */
3225 if (vport->fc_npr_cnt)
3226 lpfc_els_disc_plogi(vport);
3227
3228 if (!vport->num_disc_nodes) {
3229 spin_lock_irq(shost->host_lock);
3230 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3231 spin_unlock_irq(shost->host_lock);
3232 lpfc_can_disctmo(vport);
3233 }
3234 vport->port_state = LPFC_VPORT_READY;
3235
3236out:
3237 mempool_free(pmb, phba->mbox_mem_pool);
3238 return;
3239}
3240
21e9a0a5
JS
3241/**
3242 * lpfc_create_static_vport - Read HBA config region to create static vports.
3243 * @phba: pointer to lpfc hba data structure.
3244 *
3245 * This routine issue a DUMP mailbox command for config region 22 to get
3246 * the list of static vports to be created. The function create vports
3247 * based on the information returned from the HBA.
3248 **/
3249void
3250lpfc_create_static_vport(struct lpfc_hba *phba)
3251{
3252 LPFC_MBOXQ_t *pmb = NULL;
3253 MAILBOX_t *mb;
3254 struct static_vport_info *vport_info;
1c6834a7 3255 int rc = 0, i;
21e9a0a5
JS
3256 struct fc_vport_identifiers vport_id;
3257 struct fc_vport *new_fc_vport;
3258 struct Scsi_Host *shost;
3259 struct lpfc_vport *vport;
3260 uint16_t offset = 0;
3261 uint8_t *vport_buff;
1c6834a7
JS
3262 struct lpfc_dmabuf *mp;
3263 uint32_t byte_count = 0;
21e9a0a5
JS
3264
3265 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3266 if (!pmb) {
3267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3268 "0542 lpfc_create_static_vport failed to"
3269 " allocate mailbox memory\n");
3270 return;
3271 }
3272
3273 mb = &pmb->u.mb;
3274
3275 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3276 if (!vport_info) {
3277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3278 "0543 lpfc_create_static_vport failed to"
3279 " allocate vport_info\n");
3280 mempool_free(pmb, phba->mbox_mem_pool);
3281 return;
3282 }
3283
3284 vport_buff = (uint8_t *) vport_info;
3285 do {
1c6834a7
JS
3286 if (lpfc_dump_static_vport(phba, pmb, offset))
3287 goto out;
3288
21e9a0a5
JS
3289 pmb->vport = phba->pport;
3290 rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
3291
3292 if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
3293 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3294 "0544 lpfc_create_static_vport failed to"
3295 " issue dump mailbox command ret 0x%x "
3296 "status 0x%x\n",
3297 rc, mb->mbxStatus);
3298 goto out;
3299 }
3300
1c6834a7
JS
3301 if (phba->sli_rev == LPFC_SLI_REV4) {
3302 byte_count = pmb->u.mqe.un.mb_words[5];
3303 mp = (struct lpfc_dmabuf *) pmb->context2;
3304 if (byte_count > sizeof(struct static_vport_info) -
3305 offset)
3306 byte_count = sizeof(struct static_vport_info)
3307 - offset;
3308 memcpy(vport_buff + offset, mp->virt, byte_count);
3309 offset += byte_count;
3310 } else {
3311 if (mb->un.varDmp.word_cnt >
3312 sizeof(struct static_vport_info) - offset)
3313 mb->un.varDmp.word_cnt =
3314 sizeof(struct static_vport_info)
3315 - offset;
3316 byte_count = mb->un.varDmp.word_cnt;
3317 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3318 vport_buff + offset,
3319 byte_count);
3320
3321 offset += byte_count;
3322 }
21e9a0a5 3323
1c6834a7 3324 } while (byte_count &&
21e9a0a5
JS
3325 offset < sizeof(struct static_vport_info));
3326
3327
3328 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3329 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3330 != VPORT_INFO_REV)) {
3331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3332 "0545 lpfc_create_static_vport bad"
3333 " information header 0x%x 0x%x\n",
3334 le32_to_cpu(vport_info->signature),
3335 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3336
3337 goto out;
3338 }
3339
3340 shost = lpfc_shost_from_vport(phba->pport);
3341
3342 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3343 memset(&vport_id, 0, sizeof(vport_id));
3344 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3345 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3346 if (!vport_id.port_name || !vport_id.node_name)
3347 continue;
3348
3349 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3350 vport_id.vport_type = FC_PORTTYPE_NPIV;
3351 vport_id.disable = false;
3352 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3353
3354 if (!new_fc_vport) {
3355 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3356 "0546 lpfc_create_static_vport failed to"
e4e74273 3357 " create vport\n");
21e9a0a5
JS
3358 continue;
3359 }
3360
3361 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3362 vport->vport_flag |= STATIC_VPORT;
3363 }
3364
3365out:
21e9a0a5 3366 kfree(vport_info);
1c6834a7
JS
3367 if (rc != MBX_TIMEOUT) {
3368 if (pmb->context2) {
3369 mp = (struct lpfc_dmabuf *) pmb->context2;
3370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3371 kfree(mp);
3372 }
21e9a0a5 3373 mempool_free(pmb, phba->mbox_mem_pool);
1c6834a7 3374 }
21e9a0a5
JS
3375
3376 return;
3377}
3378
dea3101e 3379/*
3380 * This routine handles processing a Fabric REG_LOGIN mailbox
3381 * command upon completion. It is setup in the LPFC_MBOXQ
3382 * as the completion routine when the command is
3383 * handed off to the SLI layer.
3384 */
3385void
2e0fef85 3386lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 3387{
92d7f7b0 3388 struct lpfc_vport *vport = pmb->vport;
21e9a0a5 3389 MAILBOX_t *mb = &pmb->u.mb;
2e0fef85 3390 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
92d7f7b0 3391 struct lpfc_nodelist *ndlp;
dea3101e 3392
549e55cd 3393 ndlp = (struct lpfc_nodelist *) pmb->context2;
329f9bc7
JS
3394 pmb->context1 = NULL;
3395 pmb->context2 = NULL;
d439d286 3396
dea3101e 3397 if (mb->mbxStatus) {
21e9a0a5
JS
3398 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3399 "0258 Register Fabric login error: 0x%x\n",
3400 mb->mbxStatus);
dea3101e 3401 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3402 kfree(mp);
329f9bc7 3403 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 3404
76a95d75 3405 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
92d7f7b0
JS
3406 /* FLOGI failed, use loop map to make discovery list */
3407 lpfc_disc_list_loopmap(vport);
3408
3409 /* Start discovery */
3410 lpfc_disc_start(vport);
e47c9093
JS
3411 /* Decrement the reference count to ndlp after the
3412 * reference to the ndlp are done.
3413 */
3414 lpfc_nlp_put(ndlp);
92d7f7b0
JS
3415 return;
3416 }
3417
3418 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
e47c9093
JS
3419 /* Decrement the reference count to ndlp after the reference
3420 * to the ndlp are done.
3421 */
3422 lpfc_nlp_put(ndlp);
dea3101e 3423 return;
3424 }
3425
dea3101e 3426 ndlp->nlp_rpi = mb->un.varWords[0];
21e9a0a5 3427 ndlp->nlp_flag |= NLP_RPI_VALID;
dea3101e 3428 ndlp->nlp_type |= NLP_FABRIC;
2e0fef85 3429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 3430
2e0fef85 3431 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4b40c59e
JS
3432 /* when physical port receive logo donot start
3433 * vport discovery */
3434 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3435 lpfc_start_fdiscs(phba);
3436 else
3437 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
92d7f7b0 3438 lpfc_do_scr_ns_plogi(phba, vport);
dea3101e 3439 }
3440
3441 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3442 kfree(mp);
329f9bc7 3443 mempool_free(pmb, phba->mbox_mem_pool);
e47c9093
JS
3444
3445 /* Drop the reference count from the mbox at the end after
3446 * all the current reference to the ndlp have been done.
3447 */
3448 lpfc_nlp_put(ndlp);
dea3101e 3449 return;
3450}
3451
3452/*
3453 * This routine handles processing a NameServer REG_LOGIN mailbox
3454 * command upon completion. It is setup in the LPFC_MBOXQ
3455 * as the completion routine when the command is
3456 * handed off to the SLI layer.
3457 */
3458void
2e0fef85 3459lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 3460{
21e9a0a5 3461 MAILBOX_t *mb = &pmb->u.mb;
2e0fef85
JS
3462 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3463 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3464 struct lpfc_vport *vport = pmb->vport;
dea3101e 3465
d439d286
JS
3466 pmb->context1 = NULL;
3467 pmb->context2 = NULL;
3468
dea3101e 3469 if (mb->mbxStatus) {
92d7f7b0 3470out:
21e9a0a5
JS
3471 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3472 "0260 Register NameServer error: 0x%x\n",
3473 mb->mbxStatus);
fa4066b6
JS
3474 /* decrement the node reference count held for this
3475 * callback function.
3476 */
329f9bc7 3477 lpfc_nlp_put(ndlp);
dea3101e 3478 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3479 kfree(mp);
de0c5b32 3480 mempool_free(pmb, phba->mbox_mem_pool);
87af33fe
JS
3481
3482 /* If no other thread is using the ndlp, free it */
3483 lpfc_nlp_not_used(ndlp);
dea3101e 3484
76a95d75 3485 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
92d7f7b0
JS
3486 /*
3487 * RegLogin failed, use loop map to make discovery
3488 * list
3489 */
3490 lpfc_disc_list_loopmap(vport);
dea3101e 3491
92d7f7b0
JS
3492 /* Start discovery */
3493 lpfc_disc_start(vport);
3494 return;
3495 }
3496 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea3101e 3497 return;
3498 }
3499
dea3101e 3500 ndlp->nlp_rpi = mb->un.varWords[0];
21e9a0a5 3501 ndlp->nlp_flag |= NLP_RPI_VALID;
dea3101e 3502 ndlp->nlp_type |= NLP_FABRIC;
2e0fef85 3503 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 3504
2e0fef85
JS
3505 if (vport->port_state < LPFC_VPORT_READY) {
3506 /* Link up discovery requires Fabric registration. */
92d7f7b0
JS
3507 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3508 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3509 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3510 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3511 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3512
3513 /* Issue SCR just before NameServer GID_FT Query */
3514 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea3101e 3515 }
3516
2e0fef85 3517 vport->fc_ns_retry = 0;
dea3101e 3518 /* Good status, issue CT Request to NameServer */
92d7f7b0 3519 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea3101e 3520 /* Cannot issue NameServer Query, so finish up discovery */
92d7f7b0 3521 goto out;
dea3101e 3522 }
3523
fa4066b6
JS
3524 /* decrement the node reference count held for this
3525 * callback function.
3526 */
329f9bc7 3527 lpfc_nlp_put(ndlp);
dea3101e 3528 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3529 kfree(mp);
2e0fef85 3530 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 3531
3532 return;
3533}
3534
3535static void
2e0fef85 3536lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 3537{
2e0fef85
JS
3538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3539 struct fc_rport *rport;
dea3101e 3540 struct lpfc_rport_data *rdata;
3541 struct fc_rport_identifiers rport_ids;
2e0fef85 3542 struct lpfc_hba *phba = vport->phba;
dea3101e 3543
3544 /* Remote port has reappeared. Re-register w/ FC transport */
68ce1eb5
AM
3545 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3546 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea3101e 3547 rport_ids.port_id = ndlp->nlp_DID;
3548 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea3101e 3549
329f9bc7
JS
3550 /*
3551 * We leave our node pointer in rport->dd_data when we unregister a
3552 * FCP target port. But fc_remote_port_add zeros the space to which
3553 * rport->dd_data points. So, if we're reusing a previously
3554 * registered port, drop the reference that we took the last time we
3555 * registered the port.
3556 */
3557 if (ndlp->rport && ndlp->rport->dd_data &&
e47c9093 3558 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
329f9bc7 3559 lpfc_nlp_put(ndlp);
858c9f6c
JS
3560
3561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3562 "rport add: did:x%x flg:x%x type x%x",
3563 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3564
2e0fef85 3565 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
329f9bc7 3566 if (!rport || !get_device(&rport->dev)) {
dea3101e 3567 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3568 "Warning: fc_remote_port_add failed\n");
3569 return;
3570 }
3571
3572 /* initialize static port data */
3573 rport->maxframe_size = ndlp->nlp_maxframe;
3574 rport->supported_classes = ndlp->nlp_class_sup;
dea3101e 3575 rdata = rport->dd_data;
329f9bc7 3576 rdata->pnode = lpfc_nlp_get(ndlp);
23dc04f1
JSEC
3577
3578 if (ndlp->nlp_type & NLP_FCP_TARGET)
3579 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3580 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3581 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3582
3583
3584 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3585 fc_remote_port_rolechg(rport, rport_ids.roles);
3586
071fbd3d 3587 if ((rport->scsi_target_id != -1) &&
92d7f7b0 3588 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
071fbd3d
JS
3589 ndlp->nlp_sid = rport->scsi_target_id;
3590 }
19a7b4ae
JSEC
3591 return;
3592}
3593
3594static void
2e0fef85 3595lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
19a7b4ae
JSEC
3596{
3597 struct fc_rport *rport = ndlp->rport;
c01f3208 3598
858c9f6c
JS
3599 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3600 "rport delete: did:x%x flg:x%x type x%x",
3601 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3602
19a7b4ae 3603 fc_remote_port_delete(rport);
dea3101e 3604
3605 return;
3606}
3607
de0c5b32 3608static void
2e0fef85 3609lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
dea3101e 3610{
2e0fef85
JS
3611 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3612
3613 spin_lock_irq(shost->host_lock);
de0c5b32
JS
3614 switch (state) {
3615 case NLP_STE_UNUSED_NODE:
2e0fef85 3616 vport->fc_unused_cnt += count;
de0c5b32
JS
3617 break;
3618 case NLP_STE_PLOGI_ISSUE:
2e0fef85 3619 vport->fc_plogi_cnt += count;
de0c5b32
JS
3620 break;
3621 case NLP_STE_ADISC_ISSUE:
2e0fef85 3622 vport->fc_adisc_cnt += count;
dea3101e 3623 break;
de0c5b32 3624 case NLP_STE_REG_LOGIN_ISSUE:
2e0fef85 3625 vport->fc_reglogin_cnt += count;
de0c5b32
JS
3626 break;
3627 case NLP_STE_PRLI_ISSUE:
2e0fef85 3628 vport->fc_prli_cnt += count;
de0c5b32
JS
3629 break;
3630 case NLP_STE_UNMAPPED_NODE:
2e0fef85 3631 vport->fc_unmap_cnt += count;
de0c5b32
JS
3632 break;
3633 case NLP_STE_MAPPED_NODE:
2e0fef85 3634 vport->fc_map_cnt += count;
de0c5b32
JS
3635 break;
3636 case NLP_STE_NPR_NODE:
2e0fef85 3637 vport->fc_npr_cnt += count;
de0c5b32
JS
3638 break;
3639 }
2e0fef85 3640 spin_unlock_irq(shost->host_lock);
de0c5b32 3641}
66a9ed66 3642
de0c5b32 3643static void
2e0fef85 3644lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
de0c5b32
JS
3645 int old_state, int new_state)
3646{
2e0fef85
JS
3647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3648
de0c5b32 3649 if (new_state == NLP_STE_UNMAPPED_NODE) {
de0c5b32
JS
3650 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3651 ndlp->nlp_type |= NLP_FC_NODE;
3652 }
3653 if (new_state == NLP_STE_MAPPED_NODE)
3654 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3655 if (new_state == NLP_STE_NPR_NODE)
3656 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
3657
3658 /* Transport interface */
3659 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
3660 old_state == NLP_STE_UNMAPPED_NODE)) {
2e0fef85
JS
3661 vport->phba->nport_event_cnt++;
3662 lpfc_unregister_remote_port(ndlp);
de0c5b32 3663 }
dea3101e 3664
de0c5b32
JS
3665 if (new_state == NLP_STE_MAPPED_NODE ||
3666 new_state == NLP_STE_UNMAPPED_NODE) {
2e0fef85 3667 vport->phba->nport_event_cnt++;
858c9f6c
JS
3668 /*
3669 * Tell the fc transport about the port, if we haven't
3670 * already. If we have, and it's a scsi entity, be
3671 * sure to unblock any attached scsi devices
3672 */
3673 lpfc_register_remote_port(vport, ndlp);
de0c5b32 3674 }
ea2151b4
JS
3675 if ((new_state == NLP_STE_MAPPED_NODE) &&
3676 (vport->stat_data_enabled)) {
3677 /*
3678 * A new target is discovered, if there is no buffer for
3679 * statistical data collection allocate buffer.
3680 */
3681 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
3682 sizeof(struct lpfc_scsicmd_bkt),
3683 GFP_KERNEL);
3684
3685 if (!ndlp->lat_data)
3686 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3687 "0286 lpfc_nlp_state_cleanup failed to "
3688 "allocate statistical data buffer DID "
3689 "0x%x\n", ndlp->nlp_DID);
3690 }
858c9f6c
JS
3691 /*
3692 * if we added to Mapped list, but the remote port
3693 * registration failed or assigned a target id outside
3694 * our presentable range - move the node to the
3695 * Unmapped List
3696 */
de0c5b32
JS
3697 if (new_state == NLP_STE_MAPPED_NODE &&
3698 (!ndlp->rport ||
3699 ndlp->rport->scsi_target_id == -1 ||
3700 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
2e0fef85 3701 spin_lock_irq(shost->host_lock);
de0c5b32 3702 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
2e0fef85
JS
3703 spin_unlock_irq(shost->host_lock);
3704 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 3705 }
de0c5b32
JS
3706}
3707
685f0bf7
JS
3708static char *
3709lpfc_nlp_state_name(char *buffer, size_t size, int state)
3710{
3711 static char *states[] = {
3712 [NLP_STE_UNUSED_NODE] = "UNUSED",
3713 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
3714 [NLP_STE_ADISC_ISSUE] = "ADISC",
3715 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
3716 [NLP_STE_PRLI_ISSUE] = "PRLI",
3717 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
3718 [NLP_STE_MAPPED_NODE] = "MAPPED",
3719 [NLP_STE_NPR_NODE] = "NPR",
3720 };
3721
311464ec 3722 if (state < NLP_STE_MAX_STATE && states[state])
685f0bf7
JS
3723 strlcpy(buffer, states[state], size);
3724 else
3725 snprintf(buffer, size, "unknown (%d)", state);
3726 return buffer;
3727}
3728
de0c5b32 3729void
2e0fef85
JS
3730lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3731 int state)
de0c5b32 3732{
2e0fef85 3733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
de0c5b32 3734 int old_state = ndlp->nlp_state;
685f0bf7 3735 char name1[16], name2[16];
de0c5b32 3736
e8b62011
JS
3737 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3738 "0904 NPort state transition x%06x, %s -> %s\n",
3739 ndlp->nlp_DID,
3740 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
3741 lpfc_nlp_state_name(name2, sizeof(name2), state));
858c9f6c
JS
3742
3743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3744 "node statechg did:x%x old:%d ste:%d",
3745 ndlp->nlp_DID, old_state, state);
3746
de0c5b32 3747 if (old_state == NLP_STE_NPR_NODE &&
de0c5b32 3748 state != NLP_STE_NPR_NODE)
2e0fef85 3749 lpfc_cancel_retry_delay_tmo(vport, ndlp);
de0c5b32
JS
3750 if (old_state == NLP_STE_UNMAPPED_NODE) {
3751 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
3752 ndlp->nlp_type &= ~NLP_FC_NODE;
3753 }
3754
685f0bf7 3755 if (list_empty(&ndlp->nlp_listp)) {
2e0fef85
JS
3756 spin_lock_irq(shost->host_lock);
3757 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3758 spin_unlock_irq(shost->host_lock);
685f0bf7 3759 } else if (old_state)
2e0fef85 3760 lpfc_nlp_counters(vport, old_state, -1);
de0c5b32
JS
3761
3762 ndlp->nlp_state = state;
2e0fef85
JS
3763 lpfc_nlp_counters(vport, state, 1);
3764 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
de0c5b32
JS
3765}
3766
e47c9093
JS
3767void
3768lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3769{
3770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3771
3772 if (list_empty(&ndlp->nlp_listp)) {
3773 spin_lock_irq(shost->host_lock);
3774 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3775 spin_unlock_irq(shost->host_lock);
3776 }
3777}
3778
de0c5b32 3779void
2e0fef85 3780lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
de0c5b32 3781{
2e0fef85
JS
3782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3783
0d2b6b83 3784 lpfc_cancel_retry_delay_tmo(vport, ndlp);
de0c5b32 3785 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
2e0fef85
JS
3786 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3787 spin_lock_irq(shost->host_lock);
685f0bf7 3788 list_del_init(&ndlp->nlp_listp);
2e0fef85 3789 spin_unlock_irq(shost->host_lock);
858c9f6c 3790 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
e47c9093
JS
3791 NLP_STE_UNUSED_NODE);
3792}
3793
4d9db01e 3794static void
e47c9093
JS
3795lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3796{
0d2b6b83 3797 lpfc_cancel_retry_delay_tmo(vport, ndlp);
e47c9093
JS
3798 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3799 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3800 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3801 NLP_STE_UNUSED_NODE);
3802}
109f6ed0 3803/**
3621a710 3804 * lpfc_initialize_node - Initialize all fields of node object
109f6ed0
JS
3805 * @vport: Pointer to Virtual Port object.
3806 * @ndlp: Pointer to FC node object.
3807 * @did: FC_ID of the node.
a257bf90
JS
3808 *
3809 * This function is always called when node object need to be initialized.
3810 * It initializes all the fields of the node object. Although the reference
3811 * to phba from @ndlp can be obtained indirectly through it's reference to
3812 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3813 * to the life-span of the @ndlp might go beyond the existence of @vport as
3814 * the final release of ndlp is determined by its reference count. And, the
3815 * operation on @ndlp needs the reference to phba.
109f6ed0
JS
3816 **/
3817static inline void
3818lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3819 uint32_t did)
3820{
3821 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
3822 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
3823 init_timer(&ndlp->nlp_delayfunc);
3824 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
3825 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
3826 ndlp->nlp_DID = did;
3827 ndlp->vport = vport;
a257bf90 3828 ndlp->phba = vport->phba;
109f6ed0
JS
3829 ndlp->nlp_sid = NLP_NO_SID;
3830 kref_init(&ndlp->kref);
3831 NLP_INT_NODE_ACT(ndlp);
3832 atomic_set(&ndlp->cmd_pending, 0);
7dc517df 3833 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
109f6ed0 3834}
e47c9093
JS
3835
3836struct lpfc_nodelist *
3837lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3838 int state)
3839{
3840 struct lpfc_hba *phba = vport->phba;
3841 uint32_t did;
3842 unsigned long flags;
3843
3844 if (!ndlp)
3845 return NULL;
3846
3847 spin_lock_irqsave(&phba->ndlp_lock, flags);
3848 /* The ndlp should not be in memory free mode */
3849 if (NLP_CHK_FREE_REQ(ndlp)) {
3850 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3851 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3852 "0277 lpfc_enable_node: ndlp:x%p "
3853 "usgmap:x%x refcnt:%d\n",
3854 (void *)ndlp, ndlp->nlp_usg_map,
3855 atomic_read(&ndlp->kref.refcount));
3856 return NULL;
3857 }
3858 /* The ndlp should not already be in active mode */
3859 if (NLP_CHK_NODE_ACT(ndlp)) {
3860 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3861 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3862 "0278 lpfc_enable_node: ndlp:x%p "
3863 "usgmap:x%x refcnt:%d\n",
3864 (void *)ndlp, ndlp->nlp_usg_map,
3865 atomic_read(&ndlp->kref.refcount));
3866 return NULL;
3867 }
3868
3869 /* Keep the original DID */
3870 did = ndlp->nlp_DID;
3871
3872 /* re-initialize ndlp except of ndlp linked list pointer */
3873 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
3874 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
109f6ed0 3875 lpfc_initialize_node(vport, ndlp, did);
e47c9093
JS
3876
3877 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3878
3879 if (state != NLP_STE_UNUSED_NODE)
3880 lpfc_nlp_set_state(vport, ndlp, state);
3881
3882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3883 "node enable: did:x%x",
3884 ndlp->nlp_DID, 0, 0);
3885 return ndlp;
de0c5b32
JS
3886}
3887
3888void
2e0fef85 3889lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
de0c5b32 3890{
87af33fe 3891 /*
fa4066b6 3892 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
87af33fe 3893 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
fa4066b6
JS
3894 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3895 * until ALL other outstanding threads have completed. We check
3896 * that the ndlp not already in the UNUSED state before we proceed.
87af33fe 3897 */
fa4066b6
JS
3898 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3899 return;
51ef4c26 3900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
87af33fe 3901 lpfc_nlp_put(ndlp);
98c9ea5c 3902 return;
dea3101e 3903}
3904
3905/*
3906 * Start / ReStart rescue timer for Discovery / RSCN handling
3907 */
3908void
2e0fef85 3909lpfc_set_disctmo(struct lpfc_vport *vport)
dea3101e 3910{
2e0fef85
JS
3911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3912 struct lpfc_hba *phba = vport->phba;
dea3101e 3913 uint32_t tmo;
3914
2e0fef85 3915 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
025dfdaf 3916 /* For FAN, timeout should be greater than edtov */
c9f8735b
JW
3917 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
3918 } else {
025dfdaf 3919 /* Normal discovery timeout should be > than ELS/CT timeout
c9f8735b
JW
3920 * FC spec states we need 3 * ratov for CT requests
3921 */
3922 tmo = ((phba->fc_ratov * 3) + 3);
3923 }
dea3101e 3924
858c9f6c
JS
3925
3926 if (!timer_pending(&vport->fc_disctmo)) {
3927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3928 "set disc timer: tmo:x%x state:x%x flg:x%x",
3929 tmo, vport->port_state, vport->fc_flag);
3930 }
3931
2e0fef85
JS
3932 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
3933 spin_lock_irq(shost->host_lock);
3934 vport->fc_flag |= FC_DISC_TMO;
3935 spin_unlock_irq(shost->host_lock);
dea3101e 3936
3937 /* Start Discovery Timer state <hba_state> */
e8b62011
JS
3938 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3939 "0247 Start Discovery Timer state x%x "
3940 "Data: x%x x%lx x%x x%x\n",
3941 vport->port_state, tmo,
3942 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
3943 vport->fc_adisc_cnt);
dea3101e 3944
3945 return;
3946}
3947
3948/*
3949 * Cancel rescue timer for Discovery / RSCN handling
3950 */
3951int
2e0fef85 3952lpfc_can_disctmo(struct lpfc_vport *vport)
dea3101e 3953{
2e0fef85 3954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2e0fef85
JS
3955 unsigned long iflags;
3956
858c9f6c
JS
3957 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3958 "can disc timer: state:x%x rtry:x%x flg:x%x",
3959 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
3960
dea3101e 3961 /* Turn off discovery timer if its running */
2e0fef85
JS
3962 if (vport->fc_flag & FC_DISC_TMO) {
3963 spin_lock_irqsave(shost->host_lock, iflags);
3964 vport->fc_flag &= ~FC_DISC_TMO;
3965 spin_unlock_irqrestore(shost->host_lock, iflags);
3966 del_timer_sync(&vport->fc_disctmo);
3967 spin_lock_irqsave(&vport->work_port_lock, iflags);
3968 vport->work_port_events &= ~WORKER_DISC_TMO;
3969 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea3101e 3970 }
3971
3972 /* Cancel Discovery Timer state <hba_state> */
e8b62011
JS
3973 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3974 "0248 Cancel Discovery Timer state x%x "
3975 "Data: x%x x%x x%x\n",
3976 vport->port_state, vport->fc_flag,
3977 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
2fe165b6 3978 return 0;
dea3101e 3979}
3980
3981/*
3982 * Check specified ring for outstanding IOCB on the SLI queue
3983 * Return true if iocb matches the specified nport
3984 */
3985int
2e0fef85
JS
3986lpfc_check_sli_ndlp(struct lpfc_hba *phba,
3987 struct lpfc_sli_ring *pring,
3988 struct lpfc_iocbq *iocb,
3989 struct lpfc_nodelist *ndlp)
dea3101e 3990{
2e0fef85
JS
3991 struct lpfc_sli *psli = &phba->sli;
3992 IOCB_t *icmd = &iocb->iocb;
92d7f7b0
JS
3993 struct lpfc_vport *vport = ndlp->vport;
3994
3995 if (iocb->vport != vport)
3996 return 0;
3997
dea3101e 3998 if (pring->ringno == LPFC_ELS_RING) {
3999 switch (icmd->ulpCommand) {
4000 case CMD_GEN_REQUEST64_CR:
21e9a0a5 4001 if (iocb->context_un.ndlp == ndlp)
2fe165b6 4002 return 1;
dea3101e 4003 case CMD_ELS_REQUEST64_CR:
10d4e957
JS
4004 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4005 return 1;
dea3101e 4006 case CMD_XMIT_ELS_RSP64_CX:
4007 if (iocb->context1 == (uint8_t *) ndlp)
2fe165b6 4008 return 1;
dea3101e 4009 }
a4bc3379 4010 } else if (pring->ringno == psli->extra_ring) {
dea3101e 4011
4012 } else if (pring->ringno == psli->fcp_ring) {
4013 /* Skip match check if waiting to relogin to FCP target */
4014 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
92d7f7b0 4015 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
2fe165b6 4016 return 0;
dea3101e 4017 }
4018 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
2fe165b6 4019 return 1;
dea3101e 4020 }
4021 } else if (pring->ringno == psli->next_ring) {
4022
4023 }
2fe165b6 4024 return 0;
dea3101e 4025}
4026
4027/*
4028 * Free resources / clean up outstanding I/Os
4029 * associated with nlp_rpi in the LPFC_NODELIST entry.
4030 */
4031static int
2e0fef85 4032lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea3101e 4033{
2534ba75 4034 LIST_HEAD(completions);
dea3101e 4035 struct lpfc_sli *psli;
4036 struct lpfc_sli_ring *pring;
4037 struct lpfc_iocbq *iocb, *next_iocb;
6a9c52cf 4038 uint32_t i;
dea3101e 4039
92d7f7b0
JS
4040 lpfc_fabric_abort_nport(ndlp);
4041
dea3101e 4042 /*
4043 * Everything that matches on txcmplq will be returned
4044 * by firmware with a no rpi error.
4045 */
4046 psli = &phba->sli;
21e9a0a5 4047 if (ndlp->nlp_flag & NLP_RPI_VALID) {
dea3101e 4048 /* Now process each ring */
4049 for (i = 0; i < psli->num_rings; i++) {
4050 pring = &psli->ring[i];
4051
2e0fef85 4052 spin_lock_irq(&phba->hbalock);
dea3101e 4053 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
2e0fef85 4054 list) {
dea3101e 4055 /*
4056 * Check to see if iocb matches the nport we are
4057 * looking for
4058 */
92d7f7b0
JS
4059 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4060 ndlp))) {
dea3101e 4061 /* It matches, so deque and call compl
4062 with an error */
2534ba75
JS
4063 list_move_tail(&iocb->list,
4064 &completions);
dea3101e 4065 pring->txq_cnt--;
dea3101e 4066 }
4067 }
2e0fef85 4068 spin_unlock_irq(&phba->hbalock);
dea3101e 4069 }
4070 }
2534ba75 4071
a257bf90
JS
4072 /* Cancel all the IOCBs from the completions list */
4073 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4074 IOERR_SLI_ABORTED);
2534ba75 4075
2fe165b6 4076 return 0;
dea3101e 4077}
4078
4079/*
4080 * Free rpi associated with LPFC_NODELIST entry.
4081 * This routine is called from lpfc_freenode(), when we are removing
4082 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4083 * LOGO that completes successfully, and we are waiting to PLOGI back
4084 * to the remote NPort. In addition, it is called after we receive
4085 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4086 * we are waiting to PLOGI back to the remote NPort.
4087 */
4088int
2e0fef85 4089lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 4090{
2e0fef85
JS
4091 struct lpfc_hba *phba = vport->phba;
4092 LPFC_MBOXQ_t *mbox;
dea3101e 4093 int rc;
4094
21e9a0a5 4095 if (ndlp->nlp_flag & NLP_RPI_VALID) {
2e0fef85
JS
4096 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4097 if (mbox) {
92d7f7b0 4098 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
ed957684 4099 mbox->vport = vport;
92d7f7b0 4100 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
0b727fea 4101 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea3101e 4102 if (rc == MBX_NOT_FINISHED)
2e0fef85 4103 mempool_free(mbox, phba->mbox_mem_pool);
dea3101e 4104 }
dea3101e 4105 lpfc_no_rpi(phba, ndlp);
d7c47992 4106
dea3101e 4107 ndlp->nlp_rpi = 0;
21e9a0a5 4108 ndlp->nlp_flag &= ~NLP_RPI_VALID;
0c287589 4109 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea3101e 4110 return 1;
4111 }
4112 return 0;
4113}
4114
ecfd03c6
JS
4115/**
4116 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4117 * @phba: pointer to lpfc hba data structure.
4118 *
4119 * This routine is invoked to unregister all the currently registered RPIs
4120 * to the HBA.
4121 **/
4122void
4123lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4124{
4125 struct lpfc_vport **vports;
4126 struct lpfc_nodelist *ndlp;
4127 struct Scsi_Host *shost;
4128 int i;
4129
4130 vports = lpfc_create_vport_work_array(phba);
63e801ce
JS
4131 if (!vports) {
4132 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4133 "2884 Vport array allocation failed \n");
4134 return;
4135 }
ecfd03c6
JS
4136 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4137 shost = lpfc_shost_from_vport(vports[i]);
4138 spin_lock_irq(shost->host_lock);
4139 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
0c9ab6f5
JS
4140 if (ndlp->nlp_flag & NLP_RPI_VALID) {
4141 /* The mempool_alloc might sleep */
4142 spin_unlock_irq(shost->host_lock);
ecfd03c6 4143 lpfc_unreg_rpi(vports[i], ndlp);
0c9ab6f5
JS
4144 spin_lock_irq(shost->host_lock);
4145 }
ecfd03c6
JS
4146 }
4147 spin_unlock_irq(shost->host_lock);
4148 }
4149 lpfc_destroy_vport_work_array(phba, vports);
4150}
4151
92d7f7b0
JS
4152void
4153lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4154{
4155 struct lpfc_hba *phba = vport->phba;
4156 LPFC_MBOXQ_t *mbox;
4157 int rc;
4158
5af5eee7
JS
4159 if (phba->sli_rev == LPFC_SLI_REV4) {
4160 lpfc_sli4_unreg_all_rpis(vport);
4161 return;
4162 }
4163
92d7f7b0
JS
4164 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4165 if (mbox) {
4166 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
4167 mbox->vport = vport;
4168 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
09372820
JS
4169 mbox->context1 = NULL;
4170 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
a257bf90 4171 if (rc != MBX_TIMEOUT)
92d7f7b0 4172 mempool_free(mbox, phba->mbox_mem_pool);
a257bf90
JS
4173
4174 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4175 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4176 "1836 Could not issue "
4177 "unreg_login(all_rpis) status %d\n", rc);
92d7f7b0
JS
4178 }
4179}
4180
4181void
4182lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4183{
4184 struct lpfc_hba *phba = vport->phba;
4185 LPFC_MBOXQ_t *mbox;
4186 int rc;
4187
4188 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4189 if (mbox) {
4190 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
4191 mbox->vport = vport;
4192 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
09372820
JS
4193 mbox->context1 = NULL;
4194 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
a257bf90
JS
4195 if (rc != MBX_TIMEOUT)
4196 mempool_free(mbox, phba->mbox_mem_pool);
4197
4198 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
e8b62011
JS
4199 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4200 "1815 Could not issue "
a257bf90
JS
4201 "unreg_did (default rpis) status %d\n",
4202 rc);
92d7f7b0
JS
4203 }
4204}
4205
dea3101e 4206/*
4207 * Free resources associated with LPFC_NODELIST entry
4208 * so it can be freed.
4209 */
4210static int
2e0fef85 4211lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 4212{
2e0fef85
JS
4213 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4214 struct lpfc_hba *phba = vport->phba;
4215 LPFC_MBOXQ_t *mb, *nextmb;
dea3101e 4216 struct lpfc_dmabuf *mp;
dea3101e 4217
4218 /* Cleanup node for NPort <nlp_DID> */
e8b62011
JS
4219 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4220 "0900 Cleanup node for NPort x%x "
4221 "Data: x%x x%x x%x\n",
4222 ndlp->nlp_DID, ndlp->nlp_flag,
4223 ndlp->nlp_state, ndlp->nlp_rpi);
e47c9093
JS
4224 if (NLP_CHK_FREE_REQ(ndlp)) {
4225 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4226 "0280 lpfc_cleanup_node: ndlp:x%p "
4227 "usgmap:x%x refcnt:%d\n",
4228 (void *)ndlp, ndlp->nlp_usg_map,
4229 atomic_read(&ndlp->kref.refcount));
4230 lpfc_dequeue_node(vport, ndlp);
4231 } else {
4232 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4233 "0281 lpfc_cleanup_node: ndlp:x%p "
4234 "usgmap:x%x refcnt:%d\n",
4235 (void *)ndlp, ndlp->nlp_usg_map,
4236 atomic_read(&ndlp->kref.refcount));
4237 lpfc_disable_node(vport, ndlp);
4238 }
dea3101e 4239
dea3101e 4240 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4241 if ((mb = phba->sli.mbox_active)) {
04c68496 4242 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
dea3101e 4243 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4244 mb->context2 = NULL;
4245 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4246 }
4247 }
33ccf8d1 4248
2e0fef85 4249 spin_lock_irq(&phba->hbalock);
5ac6b303
JS
4250 /* Cleanup REG_LOGIN completions which are not yet processed */
4251 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4252 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4253 (ndlp != (struct lpfc_nodelist *) mb->context2))
4254 continue;
4255
4256 mb->context2 = NULL;
4257 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4258 }
4259
dea3101e 4260 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
04c68496 4261 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
92d7f7b0 4262 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea3101e 4263 mp = (struct lpfc_dmabuf *) (mb->context1);
4264 if (mp) {
2e0fef85 4265 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea3101e 4266 kfree(mp);
4267 }
4268 list_del(&mb->list);
ffc95493
JS
4269 if (phba->sli_rev == LPFC_SLI_REV4)
4270 lpfc_sli4_free_rpi(phba,
4271 mb->u.mb.un.varRegLogin.rpi);
dea3101e 4272 mempool_free(mb, phba->mbox_mem_pool);
e47c9093
JS
4273 /* We shall not invoke the lpfc_nlp_put to decrement
4274 * the ndlp reference count as we are in the process
4275 * of lpfc_nlp_release.
4276 */
dea3101e 4277 }
4278 }
2e0fef85 4279 spin_unlock_irq(&phba->hbalock);
dea3101e 4280
e47c9093
JS
4281 lpfc_els_abort(phba, ndlp);
4282
2e0fef85 4283 spin_lock_irq(shost->host_lock);
c01f3208 4284 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2e0fef85 4285 spin_unlock_irq(shost->host_lock);
dea3101e 4286
5024ab17 4287 ndlp->nlp_last_elscmd = 0;
dea3101e 4288 del_timer_sync(&ndlp->nlp_delayfunc);
4289
0d2b6b83
JS
4290 list_del_init(&ndlp->els_retry_evt.evt_listp);
4291 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea3101e 4292
2e0fef85 4293 lpfc_unreg_rpi(vport, ndlp);
dea3101e 4294
2fe165b6 4295 return 0;
dea3101e 4296}
4297
4298/*
4299 * Check to see if we can free the nlp back to the freelist.
4300 * If we are in the middle of using the nlp in the discovery state
4301 * machine, defer the free till we reach the end of the state machine.
4302 */
329f9bc7 4303static void
2e0fef85 4304lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea3101e 4305{
a8adb832 4306 struct lpfc_hba *phba = vport->phba;
1dcb58e5 4307 struct lpfc_rport_data *rdata;
a8adb832
JS
4308 LPFC_MBOXQ_t *mbox;
4309 int rc;
dea3101e 4310
0d2b6b83 4311 lpfc_cancel_retry_delay_tmo(vport, ndlp);
21e9a0a5 4312 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
ffc95493 4313 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
21e9a0a5 4314 !(ndlp->nlp_flag & NLP_RPI_VALID)) {
a8adb832
JS
4315 /* For this case we need to cleanup the default rpi
4316 * allocated by the firmware.
4317 */
4318 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4319 != NULL) {
21e9a0a5 4320 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
a8adb832
JS
4321 (uint8_t *) &vport->fc_sparam, mbox, 0);
4322 if (rc) {
4323 mempool_free(mbox, phba->mbox_mem_pool);
4324 }
4325 else {
4326 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4327 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4328 mbox->vport = vport;
09372820 4329 mbox->context2 = NULL;
a8adb832
JS
4330 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4331 if (rc == MBX_NOT_FINISHED) {
4332 mempool_free(mbox, phba->mbox_mem_pool);
4333 }
4334 }
4335 }
4336 }
2e0fef85 4337 lpfc_cleanup_node(vport, ndlp);
1dcb58e5 4338
2e0fef85 4339 /*
92d7f7b0
JS
4340 * We can get here with a non-NULL ndlp->rport because when we
4341 * unregister a rport we don't break the rport/node linkage. So if we
4342 * do, make sure we don't leaving any dangling pointers behind.
2e0fef85 4343 */
92d7f7b0 4344 if (ndlp->rport) {
329f9bc7
JS
4345 rdata = ndlp->rport->dd_data;
4346 rdata->pnode = NULL;
4347 ndlp->rport = NULL;
dea3101e 4348 }
dea3101e 4349}
4350
4351static int
2e0fef85
JS
4352lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4353 uint32_t did)
dea3101e 4354{
2e0fef85 4355 D_ID mydid, ndlpdid, matchdid;
dea3101e 4356
4357 if (did == Bcast_DID)
2fe165b6 4358 return 0;
dea3101e 4359
dea3101e 4360 /* First check for Direct match */
4361 if (ndlp->nlp_DID == did)
2fe165b6 4362 return 1;
dea3101e 4363
4364 /* Next check for area/domain identically equals 0 match */
2e0fef85 4365 mydid.un.word = vport->fc_myDID;
dea3101e 4366 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
2fe165b6 4367 return 0;
dea3101e 4368 }
4369
4370 matchdid.un.word = did;
4371 ndlpdid.un.word = ndlp->nlp_DID;
4372 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4373 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4374 (mydid.un.b.area == matchdid.un.b.area)) {
4375 if ((ndlpdid.un.b.domain == 0) &&
4376 (ndlpdid.un.b.area == 0)) {
4377 if (ndlpdid.un.b.id)
2fe165b6 4378 return 1;
dea3101e 4379 }
2fe165b6 4380 return 0;
dea3101e 4381 }
4382
4383 matchdid.un.word = ndlp->nlp_DID;
4384 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4385 (mydid.un.b.area == ndlpdid.un.b.area)) {
4386 if ((matchdid.un.b.domain == 0) &&
4387 (matchdid.un.b.area == 0)) {
4388 if (matchdid.un.b.id)
2fe165b6 4389 return 1;
dea3101e 4390 }
4391 }
4392 }
2fe165b6 4393 return 0;
dea3101e 4394}
4395
685f0bf7 4396/* Search for a nodelist entry */
2e0fef85
JS
4397static struct lpfc_nodelist *
4398__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea3101e 4399{
2fb9bd8b 4400 struct lpfc_nodelist *ndlp;
dea3101e 4401 uint32_t data1;
4402
2e0fef85
JS
4403 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4404 if (lpfc_matchdid(vport, ndlp, did)) {
685f0bf7
JS
4405 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4406 ((uint32_t) ndlp->nlp_xri << 16) |
4407 ((uint32_t) ndlp->nlp_type << 8) |
4408 ((uint32_t) ndlp->nlp_rpi & 0xff));
e8b62011
JS
4409 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4410 "0929 FIND node DID "
4411 "Data: x%p x%x x%x x%x\n",
4412 ndlp, ndlp->nlp_DID,
4413 ndlp->nlp_flag, data1);
685f0bf7 4414 return ndlp;
dea3101e 4415 }
4416 }
66a9ed66 4417
dea3101e 4418 /* FIND node did <did> NOT FOUND */
e8b62011
JS
4419 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4420 "0932 FIND node did x%x NOT FOUND.\n", did);
dea3101e 4421 return NULL;
4422}
4423
4424struct lpfc_nodelist *
2e0fef85
JS
4425lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4426{
4427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4428 struct lpfc_nodelist *ndlp;
4429
4430 spin_lock_irq(shost->host_lock);
4431 ndlp = __lpfc_findnode_did(vport, did);
4432 spin_unlock_irq(shost->host_lock);
4433 return ndlp;
4434}
4435
4436struct lpfc_nodelist *
4437lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
dea3101e 4438{
2e0fef85 4439 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 4440 struct lpfc_nodelist *ndlp;
dea3101e 4441
2e0fef85 4442 ndlp = lpfc_findnode_did(vport, did);
c9f8735b 4443 if (!ndlp) {
2e0fef85
JS
4444 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4445 lpfc_rscn_payload_check(vport, did) == 0)
dea3101e 4446 return NULL;
4447 ndlp = (struct lpfc_nodelist *)
2e0fef85 4448 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea3101e 4449 if (!ndlp)
4450 return NULL;
2e0fef85
JS
4451 lpfc_nlp_init(vport, ndlp, did);
4452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4453 spin_lock_irq(shost->host_lock);
dea3101e 4454 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2e0fef85 4455 spin_unlock_irq(shost->host_lock);
dea3101e 4456 return ndlp;
e47c9093
JS
4457 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4458 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4459 if (!ndlp)
4460 return NULL;
4461 spin_lock_irq(shost->host_lock);
4462 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4463 spin_unlock_irq(shost->host_lock);
4464 return ndlp;
dea3101e 4465 }
e47c9093 4466
58da1ffb
JS
4467 if ((vport->fc_flag & FC_RSCN_MODE) &&
4468 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
2e0fef85 4469 if (lpfc_rscn_payload_check(vport, did)) {
87af33fe
JS
4470 /* If we've already recieved a PLOGI from this NPort
4471 * we don't need to try to discover it again.
4472 */
4473 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4474 return NULL;
4475
c9f8735b
JW
4476 /* Since this node is marked for discovery,
4477 * delay timeout is not needed.
4478 */
0d2b6b83 4479 lpfc_cancel_retry_delay_tmo(vport, ndlp);
a257bf90
JS
4480 spin_lock_irq(shost->host_lock);
4481 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4482 spin_unlock_irq(shost->host_lock);
071fbd3d 4483 } else
dea3101e 4484 ndlp = NULL;
2fe165b6 4485 } else {
87af33fe
JS
4486 /* If we've already recieved a PLOGI from this NPort,
4487 * or we are already in the process of discovery on it,
4488 * we don't need to try to discover it again.
4489 */
685f0bf7 4490 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
87af33fe
JS
4491 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4492 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea3101e 4493 return NULL;
2e0fef85
JS
4494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4495 spin_lock_irq(shost->host_lock);
dea3101e 4496 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2e0fef85 4497 spin_unlock_irq(shost->host_lock);
dea3101e 4498 }
4499 return ndlp;
4500}
4501
4502/* Build a list of nodes to discover based on the loopmap */
4503void
2e0fef85 4504lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea3101e 4505{
2e0fef85 4506 struct lpfc_hba *phba = vport->phba;
dea3101e 4507 int j;
4508 uint32_t alpa, index;
4509
2e0fef85 4510 if (!lpfc_is_link_up(phba))
dea3101e 4511 return;
2e0fef85 4512
76a95d75 4513 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea3101e 4514 return;
dea3101e 4515
4516 /* Check for loop map present or not */
4517 if (phba->alpa_map[0]) {
4518 for (j = 1; j <= phba->alpa_map[0]; j++) {
4519 alpa = phba->alpa_map[j];
2e0fef85 4520 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea3101e 4521 continue;
2e0fef85 4522 lpfc_setup_disc_node(vport, alpa);
dea3101e 4523 }
4524 } else {
4525 /* No alpamap, so try all alpa's */
4526 for (j = 0; j < FC_MAXLOOP; j++) {
4527 /* If cfg_scan_down is set, start from highest
4528 * ALPA (0xef) to lowest (0x1).
4529 */
3de2a653 4530 if (vport->cfg_scan_down)
dea3101e 4531 index = j;
4532 else
4533 index = FC_MAXLOOP - j - 1;
4534 alpa = lpfcAlpaArray[index];
2e0fef85 4535 if ((vport->fc_myDID & 0xff) == alpa)
dea3101e 4536 continue;
2e0fef85 4537 lpfc_setup_disc_node(vport, alpa);
dea3101e 4538 }
4539 }
4540 return;
4541}
4542
dea3101e 4543void
2e0fef85 4544lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea3101e 4545{
dea3101e 4546 LPFC_MBOXQ_t *mbox;
2e0fef85
JS
4547 struct lpfc_sli *psli = &phba->sli;
4548 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4549 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4550 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4551 int rc;
4552
92d7f7b0
JS
4553 /*
4554 * if it's not a physical port or if we already send
4555 * clear_la then don't send it.
4556 */
4557 if ((phba->link_state >= LPFC_CLEAR_LA) ||
da0436e9
JS
4558 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4559 (phba->sli_rev == LPFC_SLI_REV4))
92d7f7b0
JS
4560 return;
4561
2e0fef85
JS
4562 /* Link up discovery */
4563 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4564 phba->link_state = LPFC_CLEAR_LA;
4565 lpfc_clear_la(phba, mbox);
4566 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4567 mbox->vport = vport;
0b727fea 4568 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2e0fef85
JS
4569 if (rc == MBX_NOT_FINISHED) {
4570 mempool_free(mbox, phba->mbox_mem_pool);
4571 lpfc_disc_flush_list(vport);
4572 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4573 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4574 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
92d7f7b0
JS
4575 phba->link_state = LPFC_HBA_ERROR;
4576 }
4577 }
4578}
4579
4580/* Reg_vpi to tell firmware to resume normal operations */
4581void
4582lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4583{
4584 LPFC_MBOXQ_t *regvpimbox;
4585
4586 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4587 if (regvpimbox) {
da0436e9 4588 lpfc_reg_vpi(vport, regvpimbox);
92d7f7b0
JS
4589 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4590 regvpimbox->vport = vport;
0b727fea 4591 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
92d7f7b0
JS
4592 == MBX_NOT_FINISHED) {
4593 mempool_free(regvpimbox, phba->mbox_mem_pool);
2e0fef85
JS
4594 }
4595 }
4596}
4597
4598/* Start Link up / RSCN discovery on NPR nodes */
4599void
4600lpfc_disc_start(struct lpfc_vport *vport)
4601{
4602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4603 struct lpfc_hba *phba = vport->phba;
685f0bf7 4604 uint32_t num_sent;
dea3101e 4605 uint32_t clear_la_pending;
685f0bf7 4606 int did_changed;
dea3101e 4607
2e0fef85 4608 if (!lpfc_is_link_up(phba))
dea3101e 4609 return;
2e0fef85
JS
4610
4611 if (phba->link_state == LPFC_CLEAR_LA)
dea3101e 4612 clear_la_pending = 1;
4613 else
4614 clear_la_pending = 0;
4615
2e0fef85
JS
4616 if (vport->port_state < LPFC_VPORT_READY)
4617 vport->port_state = LPFC_DISC_AUTH;
dea3101e 4618
2e0fef85
JS
4619 lpfc_set_disctmo(vport);
4620
4621 if (vport->fc_prevDID == vport->fc_myDID)
dea3101e 4622 did_changed = 0;
2e0fef85 4623 else
dea3101e 4624 did_changed = 1;
2e0fef85
JS
4625
4626 vport->fc_prevDID = vport->fc_myDID;
4627 vport->num_disc_nodes = 0;
dea3101e 4628
4629 /* Start Discovery state <hba_state> */
e8b62011
JS
4630 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4631 "0202 Start Discovery hba state x%x "
4632 "Data: x%x x%x x%x\n",
4633 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
4634 vport->fc_adisc_cnt);
dea3101e 4635
4636 /* First do ADISCs - if any */
2e0fef85 4637 num_sent = lpfc_els_disc_adisc(vport);
dea3101e 4638
4639 if (num_sent)
4640 return;
4641
92d7f7b0
JS
4642 /*
4643 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4644 * continue discovery.
4645 */
4646 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1b32f6aa 4647 !(vport->fc_flag & FC_PT2PT) &&
da0436e9
JS
4648 !(vport->fc_flag & FC_RSCN_MODE) &&
4649 (phba->sli_rev < LPFC_SLI_REV4)) {
92d7f7b0
JS
4650 lpfc_issue_reg_vpi(phba, vport);
4651 return;
4652 }
4653
4654 /*
4655 * For SLI2, we need to set port_state to READY and continue
4656 * discovery.
4657 */
2e0fef85 4658 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
dea3101e 4659 /* If we get here, there is nothing to ADISC */
92d7f7b0 4660 if (vport->port_type == LPFC_PHYSICAL_PORT)
2e0fef85 4661 lpfc_issue_clear_la(phba, vport);
2e0fef85 4662
92d7f7b0 4663 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2e0fef85
JS
4664 vport->num_disc_nodes = 0;
4665 /* go thru NPR nodes and issue ELS PLOGIs */
4666 if (vport->fc_npr_cnt)
4667 lpfc_els_disc_plogi(vport);
4668
4669 if (!vport->num_disc_nodes) {
4670 spin_lock_irq(shost->host_lock);
4671 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4672 spin_unlock_irq(shost->host_lock);
92d7f7b0 4673 lpfc_can_disctmo(vport);
dea3101e 4674 }
4675 }
92d7f7b0 4676 vport->port_state = LPFC_VPORT_READY;
dea3101e 4677 } else {
4678 /* Next do PLOGIs - if any */
2e0fef85 4679 num_sent = lpfc_els_disc_plogi(vport);
dea3101e 4680
4681 if (num_sent)
4682 return;
4683
2e0fef85 4684 if (vport->fc_flag & FC_RSCN_MODE) {
dea3101e 4685 /* Check to see if more RSCNs came in while we
4686 * were processing this one.
4687 */
2e0fef85
JS
4688 if ((vport->fc_rscn_id_cnt == 0) &&
4689 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
4690 spin_lock_irq(shost->host_lock);
4691 vport->fc_flag &= ~FC_RSCN_MODE;
4692 spin_unlock_irq(shost->host_lock);
92d7f7b0 4693 lpfc_can_disctmo(vport);
2fe165b6 4694 } else
2e0fef85 4695 lpfc_els_handle_rscn(vport);
dea3101e 4696 }
4697 }
4698 return;
4699}
4700
4701/*
4702 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4703 * ring the match the sppecified nodelist.
4704 */
4705static void
2e0fef85 4706lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea3101e 4707{
2534ba75 4708 LIST_HEAD(completions);
dea3101e 4709 struct lpfc_sli *psli;
4710 IOCB_t *icmd;
4711 struct lpfc_iocbq *iocb, *next_iocb;
4712 struct lpfc_sli_ring *pring;
dea3101e 4713
4714 psli = &phba->sli;
4715 pring = &psli->ring[LPFC_ELS_RING];
4716
4717 /* Error matching iocb on txq or txcmplq
4718 * First check the txq.
4719 */
2e0fef85 4720 spin_lock_irq(&phba->hbalock);
dea3101e 4721 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4722 if (iocb->context1 != ndlp) {
4723 continue;
4724 }
4725 icmd = &iocb->iocb;
4726 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
4727 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
4728
2534ba75 4729 list_move_tail(&iocb->list, &completions);
dea3101e 4730 pring->txq_cnt--;
dea3101e 4731 }
4732 }
4733
4734 /* Next check the txcmplq */
4735 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
4736 if (iocb->context1 != ndlp) {
4737 continue;
4738 }
4739 icmd = &iocb->iocb;
2e0fef85
JS
4740 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
4741 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
2534ba75
JS
4742 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
4743 }
4744 }
2e0fef85 4745 spin_unlock_irq(&phba->hbalock);
dea3101e 4746
a257bf90
JS
4747 /* Cancel all the IOCBs from the completions list */
4748 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4749 IOERR_SLI_ABORTED);
dea3101e 4750}
4751
a6ababd2 4752static void
2e0fef85 4753lpfc_disc_flush_list(struct lpfc_vport *vport)
dea3101e 4754{
4755 struct lpfc_nodelist *ndlp, *next_ndlp;
2e0fef85 4756 struct lpfc_hba *phba = vport->phba;
dea3101e 4757
2e0fef85
JS
4758 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
4759 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
685f0bf7 4760 nlp_listp) {
e47c9093
JS
4761 if (!NLP_CHK_NODE_ACT(ndlp))
4762 continue;
685f0bf7
JS
4763 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4764 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
4765 lpfc_free_tx(phba, ndlp);
685f0bf7 4766 }
dea3101e 4767 }
4768 }
dea3101e 4769}
4770
92d7f7b0
JS
4771void
4772lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
4773{
4774 lpfc_els_flush_rscn(vport);
4775 lpfc_els_flush_cmd(vport);
4776 lpfc_disc_flush_list(vport);
4777}
4778
dea3101e 4779/*****************************************************************************/
4780/*
4781 * NAME: lpfc_disc_timeout
4782 *
4783 * FUNCTION: Fibre Channel driver discovery timeout routine.
4784 *
4785 * EXECUTION ENVIRONMENT: interrupt only
4786 *
4787 * CALLED FROM:
4788 * Timer function
4789 *
4790 * RETURNS:
4791 * none
4792 */
4793/*****************************************************************************/
4794void
4795lpfc_disc_timeout(unsigned long ptr)
4796{
2e0fef85
JS
4797 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4798 struct lpfc_hba *phba = vport->phba;
5e9d9b82 4799 uint32_t tmo_posted;
dea3101e 4800 unsigned long flags = 0;
4801
4802 if (unlikely(!phba))
4803 return;
4804
5e9d9b82
JS
4805 spin_lock_irqsave(&vport->work_port_lock, flags);
4806 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
4807 if (!tmo_posted)
2e0fef85 4808 vport->work_port_events |= WORKER_DISC_TMO;
5e9d9b82 4809 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2e0fef85 4810
5e9d9b82
JS
4811 if (!tmo_posted)
4812 lpfc_worker_wake_up(phba);
dea3101e 4813 return;
4814}
4815
4816static void
2e0fef85 4817lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea3101e 4818{
2e0fef85
JS
4819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4820 struct lpfc_hba *phba = vport->phba;
4821 struct lpfc_sli *psli = &phba->sli;
c9f8735b 4822 struct lpfc_nodelist *ndlp, *next_ndlp;
92d7f7b0 4823 LPFC_MBOXQ_t *initlinkmbox;
dea3101e 4824 int rc, clrlaerr = 0;
4825
2e0fef85 4826 if (!(vport->fc_flag & FC_DISC_TMO))
dea3101e 4827 return;
4828
2e0fef85
JS
4829 spin_lock_irq(shost->host_lock);
4830 vport->fc_flag &= ~FC_DISC_TMO;
4831 spin_unlock_irq(shost->host_lock);
dea3101e 4832
858c9f6c
JS
4833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4834 "disc timeout: state:x%x rtry:x%x flg:x%x",
4835 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4836
2e0fef85 4837 switch (vport->port_state) {
dea3101e 4838
4839 case LPFC_LOCAL_CFG_LINK:
2e0fef85
JS
4840 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4841 * FAN
4842 */
4843 /* FAN timeout */
e8b62011
JS
4844 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
4845 "0221 FAN timeout\n");
c9f8735b 4846 /* Start discovery by sending FLOGI, clean up old rpis */
2e0fef85 4847 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
685f0bf7 4848 nlp_listp) {
e47c9093
JS
4849 if (!NLP_CHK_NODE_ACT(ndlp))
4850 continue;
685f0bf7
JS
4851 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
4852 continue;
c9f8735b
JW
4853 if (ndlp->nlp_type & NLP_FABRIC) {
4854 /* Clean up the ndlp on Fabric connections */
2e0fef85 4855 lpfc_drop_node(vport, ndlp);
87af33fe 4856
2fe165b6 4857 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
c9f8735b
JW
4858 /* Fail outstanding IO now since device
4859 * is marked for PLOGI.
4860 */
2e0fef85 4861 lpfc_unreg_rpi(vport, ndlp);
c9f8735b
JW
4862 }
4863 }
92d7f7b0 4864 if (vport->port_state != LPFC_FLOGI) {
76a95d75
JS
4865 if (phba->sli_rev <= LPFC_SLI_REV3)
4866 lpfc_initial_flogi(vport);
4867 else
4868 lpfc_issue_init_vfi(vport);
0ff10d46 4869 return;
92d7f7b0 4870 }
dea3101e 4871 break;
4872
92d7f7b0 4873 case LPFC_FDISC:
dea3101e 4874 case LPFC_FLOGI:
2e0fef85 4875 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea3101e 4876 /* Initial FLOGI timeout */
e8b62011
JS
4877 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4878 "0222 Initial %s timeout\n",
87af33fe 4879 vport->vpi ? "FDISC" : "FLOGI");
dea3101e 4880
4881 /* Assume no Fabric and go on with discovery.
4882 * Check for outstanding ELS FLOGI to abort.
4883 */
4884
4885 /* FLOGI failed, so just use loop map to make discovery list */
2e0fef85 4886 lpfc_disc_list_loopmap(vport);
dea3101e 4887
4888 /* Start discovery */
2e0fef85 4889 lpfc_disc_start(vport);
dea3101e 4890 break;
4891
4892 case LPFC_FABRIC_CFG_LINK:
4893 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4894 NameServer login */
e8b62011
JS
4895 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4896 "0223 Timeout while waiting for "
4897 "NameServer login\n");
dea3101e 4898 /* Next look for NameServer ndlp */
2e0fef85 4899 ndlp = lpfc_findnode_did(vport, NameServer_DID);
e47c9093 4900 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
87af33fe
JS
4901 lpfc_els_abort(phba, ndlp);
4902
4903 /* ReStart discovery */
4904 goto restart_disc;
dea3101e 4905
4906 case LPFC_NS_QRY:
4907 /* Check for wait for NameServer Rsp timeout */
e8b62011
JS
4908 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4909 "0224 NameServer Query timeout "
4910 "Data: x%x x%x\n",
4911 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea3101e 4912
92d7f7b0
JS
4913 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
4914 /* Try it one more time */
4915 vport->fc_ns_retry++;
4916 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
4917 vport->fc_ns_retry, 0);
4918 if (rc == 0)
4919 break;
dea3101e 4920 }
92d7f7b0 4921 vport->fc_ns_retry = 0;
dea3101e 4922
87af33fe 4923restart_disc:
92d7f7b0
JS
4924 /*
4925 * Discovery is over.
4926 * set port_state to PORT_READY if SLI2.
4927 * cmpl_reg_vpi will set port_state to READY for SLI3.
4928 */
3772a991
JS
4929 if (phba->sli_rev < LPFC_SLI_REV4) {
4930 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4931 lpfc_issue_reg_vpi(phba, vport);
4932 else { /* NPIV Not enabled */
4933 lpfc_issue_clear_la(phba, vport);
4934 vport->port_state = LPFC_VPORT_READY;
4935 }
dea3101e 4936 }
4937
4938 /* Setup and issue mailbox INITIALIZE LINK command */
4939 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4940 if (!initlinkmbox) {
e8b62011
JS
4941 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4942 "0206 Device Discovery "
4943 "completion error\n");
2e0fef85 4944 phba->link_state = LPFC_HBA_ERROR;
dea3101e 4945 break;
4946 }
4947
4948 lpfc_linkdown(phba);
4949 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
4950 phba->cfg_link_speed);
04c68496 4951 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
ed957684 4952 initlinkmbox->vport = vport;
92d7f7b0 4953 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
0b727fea 4954 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5b8bd0c9 4955 lpfc_set_loopback_flag(phba);
dea3101e 4956 if (rc == MBX_NOT_FINISHED)
4957 mempool_free(initlinkmbox, phba->mbox_mem_pool);
4958
4959 break;
4960
4961 case LPFC_DISC_AUTH:
4962 /* Node Authentication timeout */
e8b62011
JS
4963 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4964 "0227 Node Authentication timeout\n");
2e0fef85
JS
4965 lpfc_disc_flush_list(vport);
4966
92d7f7b0
JS
4967 /*
4968 * set port_state to PORT_READY if SLI2.
4969 * cmpl_reg_vpi will set port_state to READY for SLI3.
4970 */
3772a991
JS
4971 if (phba->sli_rev < LPFC_SLI_REV4) {
4972 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4973 lpfc_issue_reg_vpi(phba, vport);
4974 else { /* NPIV Not enabled */
4975 lpfc_issue_clear_la(phba, vport);
4976 vport->port_state = LPFC_VPORT_READY;
4977 }
dea3101e 4978 }
4979 break;
4980
2e0fef85
JS
4981 case LPFC_VPORT_READY:
4982 if (vport->fc_flag & FC_RSCN_MODE) {
e8b62011
JS
4983 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4984 "0231 RSCN timeout Data: x%x "
4985 "x%x\n",
4986 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea3101e 4987
4988 /* Cleanup any outstanding ELS commands */
2e0fef85 4989 lpfc_els_flush_cmd(vport);
dea3101e 4990
2e0fef85
JS
4991 lpfc_els_flush_rscn(vport);
4992 lpfc_disc_flush_list(vport);
dea3101e 4993 }
4994 break;
2e0fef85 4995
92d7f7b0 4996 default:
e8b62011 4997 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
d7c255b2 4998 "0273 Unexpected discovery timeout, "
e8b62011 4999 "vport State x%x\n", vport->port_state);
2e0fef85
JS
5000 break;
5001 }
5002
5003 switch (phba->link_state) {
5004 case LPFC_CLEAR_LA:
92d7f7b0 5005 /* CLEAR LA timeout */
e8b62011
JS
5006 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5007 "0228 CLEAR LA timeout\n");
2e0fef85
JS
5008 clrlaerr = 1;
5009 break;
5010
09372820
JS
5011 case LPFC_LINK_UP:
5012 lpfc_issue_clear_la(phba, vport);
5013 /* Drop thru */
2e0fef85
JS
5014 case LPFC_LINK_UNKNOWN:
5015 case LPFC_WARM_START:
5016 case LPFC_INIT_START:
5017 case LPFC_INIT_MBX_CMDS:
5018 case LPFC_LINK_DOWN:
2e0fef85 5019 case LPFC_HBA_ERROR:
e8b62011
JS
5020 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5021 "0230 Unexpected timeout, hba link "
5022 "state x%x\n", phba->link_state);
2e0fef85
JS
5023 clrlaerr = 1;
5024 break;
92d7f7b0
JS
5025
5026 case LPFC_HBA_READY:
5027 break;
dea3101e 5028 }
5029
5030 if (clrlaerr) {
2e0fef85 5031 lpfc_disc_flush_list(vport);
a4bc3379 5032 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea3101e 5033 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5034 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2e0fef85 5035 vport->port_state = LPFC_VPORT_READY;
dea3101e 5036 }
5037
5038 return;
5039}
5040
dea3101e 5041/*
5042 * This routine handles processing a NameServer REG_LOGIN mailbox
5043 * command upon completion. It is setup in the LPFC_MBOXQ
5044 * as the completion routine when the command is
5045 * handed off to the SLI layer.
5046 */
5047void
2e0fef85 5048lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 5049{
04c68496 5050 MAILBOX_t *mb = &pmb->u.mb;
2e0fef85
JS
5051 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5052 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5053 struct lpfc_vport *vport = pmb->vport;
dea3101e 5054
5055 pmb->context1 = NULL;
d439d286 5056 pmb->context2 = NULL;
dea3101e 5057
dea3101e 5058 ndlp->nlp_rpi = mb->un.varWords[0];
21e9a0a5 5059 ndlp->nlp_flag |= NLP_RPI_VALID;
dea3101e 5060 ndlp->nlp_type |= NLP_FABRIC;
2e0fef85 5061 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea3101e 5062
2e0fef85
JS
5063 /*
5064 * Start issuing Fabric-Device Management Interface (FDMI) command to
5065 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5066 * fdmi-on=2 (supporting RPA/hostnmae)
dea3101e 5067 */
2e0fef85 5068
3de2a653 5069 if (vport->cfg_fdmi_on == 1)
2e0fef85
JS
5070 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5071 else
5072 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea3101e 5073
fa4066b6
JS
5074 /* decrement the node reference count held for this callback
5075 * function.
5076 */
329f9bc7 5077 lpfc_nlp_put(ndlp);
dea3101e 5078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5079 kfree(mp);
329f9bc7 5080 mempool_free(pmb, phba->mbox_mem_pool);
dea3101e 5081
5082 return;
5083}
5084
685f0bf7
JS
5085static int
5086lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5087{
5088 uint16_t *rpi = param;
5089
5090 return ndlp->nlp_rpi == *rpi;
5091}
5092
5093static int
5094lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5095{
5096 return memcmp(&ndlp->nlp_portname, param,
5097 sizeof(ndlp->nlp_portname)) == 0;
5098}
5099
a6ababd2 5100static struct lpfc_nodelist *
2e0fef85 5101__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea3101e 5102{
21568f53 5103 struct lpfc_nodelist *ndlp;
dea3101e 5104
2e0fef85 5105 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
87af33fe 5106 if (filter(ndlp, param))
685f0bf7
JS
5107 return ndlp;
5108 }
21568f53 5109 return NULL;
dea3101e 5110}
5111
685f0bf7
JS
5112/*
5113 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2e0fef85 5114 * returns the node list element pointer else return NULL.
685f0bf7
JS
5115 */
5116struct lpfc_nodelist *
2e0fef85 5117__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
685f0bf7 5118{
2e0fef85 5119 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
685f0bf7
JS
5120}
5121
488d1469 5122/*
685f0bf7 5123 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2e0fef85 5124 * returns the node element list pointer else return NULL.
488d1469
JS
5125 */
5126struct lpfc_nodelist *
2e0fef85 5127lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
488d1469 5128{
2e0fef85 5129 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
488d1469 5130 struct lpfc_nodelist *ndlp;
488d1469 5131
2e0fef85
JS
5132 spin_lock_irq(shost->host_lock);
5133 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5134 spin_unlock_irq(shost->host_lock);
858c9f6c 5135 return ndlp;
488d1469
JS
5136}
5137
dea3101e 5138void
2e0fef85
JS
5139lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5140 uint32_t did)
dea3101e 5141{
5142 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
109f6ed0
JS
5143
5144 lpfc_initialize_node(vport, ndlp, did);
685f0bf7 5145 INIT_LIST_HEAD(&ndlp->nlp_listp);
858c9f6c
JS
5146
5147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5148 "node init: did:x%x",
5149 ndlp->nlp_DID, 0, 0);
5150
dea3101e 5151 return;
5152}
329f9bc7 5153
98c9ea5c
JS
5154/* This routine releases all resources associated with a specifc NPort's ndlp
5155 * and mempool_free's the nodelist.
5156 */
311464ec 5157static void
329f9bc7
JS
5158lpfc_nlp_release(struct kref *kref)
5159{
e47c9093
JS
5160 struct lpfc_hba *phba;
5161 unsigned long flags;
329f9bc7
JS
5162 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5163 kref);
858c9f6c
JS
5164
5165 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5166 "node release: did:x%x flg:x%x type:x%x",
5167 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5168
e47c9093
JS
5169 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5170 "0279 lpfc_nlp_release: ndlp:x%p "
5171 "usgmap:x%x refcnt:%d\n",
5172 (void *)ndlp, ndlp->nlp_usg_map,
5173 atomic_read(&ndlp->kref.refcount));
5174
5175 /* remove ndlp from action. */
2e0fef85 5176 lpfc_nlp_remove(ndlp->vport, ndlp);
e47c9093
JS
5177
5178 /* clear the ndlp active flag for all release cases */
a257bf90 5179 phba = ndlp->phba;
e47c9093
JS
5180 spin_lock_irqsave(&phba->ndlp_lock, flags);
5181 NLP_CLR_NODE_ACT(ndlp);
5182 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5183
5184 /* free ndlp memory for final ndlp release */
ea2151b4
JS
5185 if (NLP_CHK_FREE_REQ(ndlp)) {
5186 kfree(ndlp->lat_data);
a257bf90 5187 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
ea2151b4 5188 }
329f9bc7
JS
5189}
5190
98c9ea5c
JS
5191/* This routine bumps the reference count for a ndlp structure to ensure
5192 * that one discovery thread won't free a ndlp while another discovery thread
5193 * is using it.
5194 */
329f9bc7
JS
5195struct lpfc_nodelist *
5196lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5197{
e47c9093
JS
5198 struct lpfc_hba *phba;
5199 unsigned long flags;
5200
98c9ea5c
JS
5201 if (ndlp) {
5202 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5203 "node get: did:x%x flg:x%x refcnt:x%x",
5204 ndlp->nlp_DID, ndlp->nlp_flag,
5205 atomic_read(&ndlp->kref.refcount));
e47c9093
JS
5206 /* The check of ndlp usage to prevent incrementing the
5207 * ndlp reference count that is in the process of being
5208 * released.
5209 */
a257bf90 5210 phba = ndlp->phba;
e47c9093
JS
5211 spin_lock_irqsave(&phba->ndlp_lock, flags);
5212 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5213 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5214 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5215 "0276 lpfc_nlp_get: ndlp:x%p "
5216 "usgmap:x%x refcnt:%d\n",
5217 (void *)ndlp, ndlp->nlp_usg_map,
5218 atomic_read(&ndlp->kref.refcount));
5219 return NULL;
5220 } else
5221 kref_get(&ndlp->kref);
5222 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
98c9ea5c 5223 }
329f9bc7
JS
5224 return ndlp;
5225}
5226
98c9ea5c 5227/* This routine decrements the reference count for a ndlp structure. If the
e47c9093
JS
5228 * count goes to 0, this indicates the the associated nodelist should be
5229 * freed. Returning 1 indicates the ndlp resource has been released; on the
5230 * other hand, returning 0 indicates the ndlp resource has not been released
5231 * yet.
98c9ea5c 5232 */
329f9bc7
JS
5233int
5234lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5235{
e47c9093
JS
5236 struct lpfc_hba *phba;
5237 unsigned long flags;
5238
5239 if (!ndlp)
5240 return 1;
5241
5242 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5243 "node put: did:x%x flg:x%x refcnt:x%x",
5244 ndlp->nlp_DID, ndlp->nlp_flag,
5245 atomic_read(&ndlp->kref.refcount));
a257bf90 5246 phba = ndlp->phba;
e47c9093
JS
5247 spin_lock_irqsave(&phba->ndlp_lock, flags);
5248 /* Check the ndlp memory free acknowledge flag to avoid the
5249 * possible race condition that kref_put got invoked again
5250 * after previous one has done ndlp memory free.
5251 */
5252 if (NLP_CHK_FREE_ACK(ndlp)) {
5253 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5254 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5255 "0274 lpfc_nlp_put: ndlp:x%p "
5256 "usgmap:x%x refcnt:%d\n",
5257 (void *)ndlp, ndlp->nlp_usg_map,
5258 atomic_read(&ndlp->kref.refcount));
5259 return 1;
5260 }
5261 /* Check the ndlp inactivate log flag to avoid the possible
5262 * race condition that kref_put got invoked again after ndlp
5263 * is already in inactivating state.
5264 */
5265 if (NLP_CHK_IACT_REQ(ndlp)) {
5266 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5267 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5268 "0275 lpfc_nlp_put: ndlp:x%p "
5269 "usgmap:x%x refcnt:%d\n",
5270 (void *)ndlp, ndlp->nlp_usg_map,
5271 atomic_read(&ndlp->kref.refcount));
5272 return 1;
98c9ea5c 5273 }
e47c9093
JS
5274 /* For last put, mark the ndlp usage flags to make sure no
5275 * other kref_get and kref_put on the same ndlp shall get
5276 * in between the process when the final kref_put has been
5277 * invoked on this ndlp.
5278 */
5279 if (atomic_read(&ndlp->kref.refcount) == 1) {
5280 /* Indicate ndlp is put to inactive state. */
5281 NLP_SET_IACT_REQ(ndlp);
5282 /* Acknowledge ndlp memory free has been seen. */
5283 if (NLP_CHK_FREE_REQ(ndlp))
5284 NLP_SET_FREE_ACK(ndlp);
5285 }
5286 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5287 /* Note, the kref_put returns 1 when decrementing a reference
5288 * count that was 1, it invokes the release callback function,
5289 * but it still left the reference count as 1 (not actually
5290 * performs the last decrementation). Otherwise, it actually
5291 * decrements the reference count and returns 0.
5292 */
5293 return kref_put(&ndlp->kref, lpfc_nlp_release);
329f9bc7 5294}
98c9ea5c
JS
5295
5296/* This routine free's the specified nodelist if it is not in use
e47c9093
JS
5297 * by any other discovery thread. This routine returns 1 if the
5298 * ndlp has been freed. A return value of 0 indicates the ndlp is
5299 * not yet been released.
98c9ea5c
JS
5300 */
5301int
5302lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5303{
5304 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5305 "node not used: did:x%x flg:x%x refcnt:x%x",
5306 ndlp->nlp_DID, ndlp->nlp_flag,
5307 atomic_read(&ndlp->kref.refcount));
e47c9093
JS
5308 if (atomic_read(&ndlp->kref.refcount) == 1)
5309 if (lpfc_nlp_put(ndlp))
5310 return 1;
98c9ea5c
JS
5311 return 0;
5312}
6fb120a7
JS
5313
5314/**
5315 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5316 * @phba: Pointer to hba context object.
5317 *
5318 * This function iterate through all FC nodes associated
5319 * will all vports to check if there is any node with
5320 * fc_rports associated with it. If there is an fc_rport
5321 * associated with the node, then the node is either in
5322 * discovered state or its devloss_timer is pending.
5323 */
5324static int
5325lpfc_fcf_inuse(struct lpfc_hba *phba)
5326{
5327 struct lpfc_vport **vports;
5328 int i, ret = 0;
5329 struct lpfc_nodelist *ndlp;
5330 struct Scsi_Host *shost;
5331
5332 vports = lpfc_create_vport_work_array(phba);
5333
63e801ce
JS
5334 /* If driver cannot allocate memory, indicate fcf is in use */
5335 if (!vports)
5336 return 1;
5337
6fb120a7
JS
5338 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5339 shost = lpfc_shost_from_vport(vports[i]);
5340 spin_lock_irq(shost->host_lock);
5341 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5342 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5343 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5344 ret = 1;
5345 spin_unlock_irq(shost->host_lock);
5346 goto out;
891478a2
JS
5347 } else {
5348 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5349 "2624 RPI %x DID %x flg %x still "
5350 "logged in\n",
5351 ndlp->nlp_rpi, ndlp->nlp_DID,
5352 ndlp->nlp_flag);
5353 if (ndlp->nlp_flag & NLP_RPI_VALID)
5354 ret = 1;
6fb120a7
JS
5355 }
5356 }
5357 spin_unlock_irq(shost->host_lock);
5358 }
5359out:
5360 lpfc_destroy_vport_work_array(phba, vports);
5361 return ret;
5362}
5363
5364/**
5365 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5366 * @phba: Pointer to hba context object.
5367 * @mboxq: Pointer to mailbox object.
5368 *
5369 * This function frees memory associated with the mailbox command.
5370 */
5371static void
5372lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5373{
5374 struct lpfc_vport *vport = mboxq->vport;
38b92ef8 5375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6fb120a7
JS
5376
5377 if (mboxq->u.mb.mbxStatus) {
5378 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5379 "2555 UNREG_VFI mbxStatus error x%x "
5380 "HBA state x%x\n",
5381 mboxq->u.mb.mbxStatus, vport->port_state);
5382 }
38b92ef8
JS
5383 spin_lock_irq(shost->host_lock);
5384 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5385 spin_unlock_irq(shost->host_lock);
6fb120a7
JS
5386 mempool_free(mboxq, phba->mbox_mem_pool);
5387 return;
5388}
5389
5390/**
5391 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5392 * @phba: Pointer to hba context object.
5393 * @mboxq: Pointer to mailbox object.
5394 *
5395 * This function frees memory associated with the mailbox command.
5396 */
5397static void
5398lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5399{
5400 struct lpfc_vport *vport = mboxq->vport;
5401
5402 if (mboxq->u.mb.mbxStatus) {
5403 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5404 "2550 UNREG_FCFI mbxStatus error x%x "
5405 "HBA state x%x\n",
5406 mboxq->u.mb.mbxStatus, vport->port_state);
5407 }
5408 mempool_free(mboxq, phba->mbox_mem_pool);
5409 return;
5410}
5411
5412/**
ecfd03c6 5413 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6fb120a7
JS
5414 * @phba: Pointer to hba context object.
5415 *
ecfd03c6
JS
5416 * This function prepare the HBA for unregistering the currently registered
5417 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5418 * VFIs.
6fb120a7 5419 */
ecfd03c6
JS
5420int
5421lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6fb120a7
JS
5422{
5423 LPFC_MBOXQ_t *mbox;
6fb120a7 5424 struct lpfc_vport **vports;
695a814e 5425 struct lpfc_nodelist *ndlp;
72100cc4 5426 struct Scsi_Host *shost;
ecfd03c6 5427 int i, rc;
6fb120a7 5428
ecfd03c6 5429 /* Unregister RPIs */
6fb120a7 5430 if (lpfc_fcf_inuse(phba))
ecfd03c6 5431 lpfc_unreg_hba_rpis(phba);
6fb120a7 5432
4d9ab994
JS
5433 /* At this point, all discovery is aborted */
5434 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6fb120a7
JS
5435
5436 /* Unregister VPIs */
5437 vports = lpfc_create_vport_work_array(phba);
ecfd03c6 5438 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6fb120a7 5439 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
695a814e
JS
5440 /* Stop FLOGI/FDISC retries */
5441 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5442 if (ndlp)
5443 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
78730cfe 5444 lpfc_cleanup_pending_mbox(vports[i]);
5af5eee7
JS
5445 if (phba->sli_rev == LPFC_SLI_REV4)
5446 lpfc_sli4_unreg_all_rpis(vports[i]);
6fb120a7 5447 lpfc_mbx_unreg_vpi(vports[i]);
72100cc4
JS
5448 shost = lpfc_shost_from_vport(vports[i]);
5449 spin_lock_irq(shost->host_lock);
891478a2 5450 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
c868595d 5451 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
72100cc4 5452 spin_unlock_irq(shost->host_lock);
6fb120a7
JS
5453 }
5454 lpfc_destroy_vport_work_array(phba, vports);
5455
695a814e
JS
5456 /* Cleanup any outstanding ELS commands */
5457 lpfc_els_flush_all_cmd(phba);
5458
6fb120a7
JS
5459 /* Unregister VFI */
5460 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5461 if (!mbox) {
5462 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
ecfd03c6
JS
5463 "2556 UNREG_VFI mbox allocation failed"
5464 "HBA state x%x\n", phba->pport->port_state);
5465 return -ENOMEM;
6fb120a7
JS
5466 }
5467
6669f9bb 5468 lpfc_unreg_vfi(mbox, phba->pport);
6fb120a7
JS
5469 mbox->vport = phba->pport;
5470 mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
5471
5472 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5473 if (rc == MBX_NOT_FINISHED) {
5474 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
ecfd03c6
JS
5475 "2557 UNREG_VFI issue mbox failed rc x%x "
5476 "HBA state x%x\n",
5477 rc, phba->pport->port_state);
6fb120a7 5478 mempool_free(mbox, phba->mbox_mem_pool);
ecfd03c6 5479 return -EIO;
6fb120a7
JS
5480 }
5481
72100cc4
JS
5482 shost = lpfc_shost_from_vport(phba->pport);
5483 spin_lock_irq(shost->host_lock);
695a814e 5484 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
72100cc4 5485 spin_unlock_irq(shost->host_lock);
695a814e 5486
ecfd03c6
JS
5487 return 0;
5488}
5489
5490/**
5491 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5492 * @phba: Pointer to hba context object.
5493 *
5494 * This function issues synchronous unregister FCF mailbox command to HBA to
5495 * unregister the currently registered FCF record. The driver does not reset
5496 * the driver FCF usage state flags.
5497 *
5498 * Return 0 if successfully issued, none-zero otherwise.
5499 */
5500int
5501lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
5502{
5503 LPFC_MBOXQ_t *mbox;
5504 int rc;
5505
6fb120a7
JS
5506 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5507 if (!mbox) {
5508 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
ecfd03c6
JS
5509 "2551 UNREG_FCFI mbox allocation failed"
5510 "HBA state x%x\n", phba->pport->port_state);
5511 return -ENOMEM;
6fb120a7 5512 }
6fb120a7
JS
5513 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
5514 mbox->vport = phba->pport;
5515 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
5516 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5517
5518 if (rc == MBX_NOT_FINISHED) {
ecfd03c6
JS
5519 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5520 "2552 Unregister FCFI command failed rc x%x "
5521 "HBA state x%x\n",
5522 rc, phba->pport->port_state);
5523 return -EINVAL;
5524 }
5525 return 0;
5526}
5527
5528/**
5529 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5530 * @phba: Pointer to hba context object.
5531 *
5532 * This function unregisters the currently reigstered FCF. This function
5533 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5534 */
5535void
5536lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5537{
5538 int rc;
5539
5540 /* Preparation for unregistering fcf */
5541 rc = lpfc_unregister_fcf_prep(phba);
5542 if (rc) {
5543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5544 "2748 Failed to prepare for unregistering "
5545 "HBA's FCF record: rc=%d\n", rc);
6fb120a7
JS
5546 return;
5547 }
5548
ecfd03c6
JS
5549 /* Now, unregister FCF record and reset HBA FCF state */
5550 rc = lpfc_sli4_unregister_fcf(phba);
5551 if (rc)
5552 return;
5553 /* Reset HBA FCF states after successful unregister FCF */
5554 phba->fcf.fcf_flag = 0;
fc2b989b 5555 phba->fcf.current_rec.flag = 0;
6fb120a7
JS
5556
5557 /*
5558 * If driver is not unloading, check if there is any other
5559 * FCF record that can be used for discovery.
5560 */
5561 if ((phba->pport->load_flag & FC_UNLOADING) ||
ecfd03c6 5562 (phba->link_state < LPFC_LINK_UP))
6fb120a7
JS
5563 return;
5564
0c9ab6f5
JS
5565 /* This is considered as the initial FCF discovery scan */
5566 spin_lock_irq(&phba->hbalock);
5567 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5568 spin_unlock_irq(&phba->hbalock);
38b92ef8
JS
5569
5570 /* Reset FCF roundrobin bmask for new discovery */
5571 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
5572
0c9ab6f5 5573 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6fb120a7 5574
0c9ab6f5
JS
5575 if (rc) {
5576 spin_lock_irq(&phba->hbalock);
5577 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
5578 spin_unlock_irq(&phba->hbalock);
6fb120a7 5579 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
ecfd03c6
JS
5580 "2553 lpfc_unregister_unused_fcf failed "
5581 "to read FCF record HBA state x%x\n",
5582 phba->pport->port_state);
0c9ab6f5 5583 }
ecfd03c6
JS
5584}
5585
5586/**
5587 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5588 * @phba: Pointer to hba context object.
5589 *
5590 * This function just unregisters the currently reigstered FCF. It does not
5591 * try to find another FCF for discovery.
5592 */
5593void
5594lpfc_unregister_fcf(struct lpfc_hba *phba)
5595{
5596 int rc;
5597
5598 /* Preparation for unregistering fcf */
5599 rc = lpfc_unregister_fcf_prep(phba);
5600 if (rc) {
5601 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5602 "2749 Failed to prepare for unregistering "
5603 "HBA's FCF record: rc=%d\n", rc);
5604 return;
5605 }
5606
5607 /* Now, unregister FCF record and reset HBA FCF state */
5608 rc = lpfc_sli4_unregister_fcf(phba);
5609 if (rc)
5610 return;
5611 /* Set proper HBA FCF states after successful unregister FCF */
5612 spin_lock_irq(&phba->hbalock);
5613 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
5614 spin_unlock_irq(&phba->hbalock);
5615}
5616
5617/**
5618 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5619 * @phba: Pointer to hba context object.
5620 *
5621 * This function check if there are any connected remote port for the FCF and
5622 * if all the devices are disconnected, this function unregister FCFI.
5623 * This function also tries to use another FCF for discovery.
5624 */
5625void
5626lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
5627{
5628 /*
3804dc84
JS
5629 * If HBA is not running in FIP mode, if HBA does not support
5630 * FCoE, if FCF discovery is ongoing, or if FCF has not been
5631 * registered, do nothing.
ecfd03c6
JS
5632 */
5633 spin_lock_irq(&phba->hbalock);
76a95d75 5634 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
ecfd03c6 5635 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
dbb6b3ab 5636 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
3804dc84 5637 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
dbb6b3ab 5638 (phba->pport->port_state == LPFC_FLOGI)) {
ecfd03c6
JS
5639 spin_unlock_irq(&phba->hbalock);
5640 return;
5641 }
5642 spin_unlock_irq(&phba->hbalock);
5643
5644 if (lpfc_fcf_inuse(phba))
5645 return;
5646
5647 lpfc_unregister_fcf_rescan(phba);
6fb120a7
JS
5648}
5649
5650/**
5651 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5652 * @phba: Pointer to hba context object.
5653 * @buff: Buffer containing the FCF connection table as in the config
5654 * region.
5655 * This function create driver data structure for the FCF connection
5656 * record table read from config region 23.
5657 */
5658static void
5659lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
5660 uint8_t *buff)
5661{
5662 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5663 struct lpfc_fcf_conn_hdr *conn_hdr;
5664 struct lpfc_fcf_conn_rec *conn_rec;
5665 uint32_t record_count;
5666 int i;
5667
5668 /* Free the current connect table */
5669 list_for_each_entry_safe(conn_entry, next_conn_entry,
4d9ab994
JS
5670 &phba->fcf_conn_rec_list, list) {
5671 list_del_init(&conn_entry->list);
6fb120a7 5672 kfree(conn_entry);
4d9ab994 5673 }
6fb120a7
JS
5674
5675 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
5676 record_count = conn_hdr->length * sizeof(uint32_t)/
5677 sizeof(struct lpfc_fcf_conn_rec);
5678
5679 conn_rec = (struct lpfc_fcf_conn_rec *)
5680 (buff + sizeof(struct lpfc_fcf_conn_hdr));
5681
5682 for (i = 0; i < record_count; i++) {
5683 if (!(conn_rec[i].flags & FCFCNCT_VALID))
5684 continue;
5685 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
5686 GFP_KERNEL);
5687 if (!conn_entry) {
5688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5689 "2566 Failed to allocate connection"
5690 " table entry\n");
5691 return;
5692 }
5693
5694 memcpy(&conn_entry->conn_rec, &conn_rec[i],
5695 sizeof(struct lpfc_fcf_conn_rec));
5696 conn_entry->conn_rec.vlan_tag =
5697 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
5698 conn_entry->conn_rec.flags =
5699 le16_to_cpu(conn_entry->conn_rec.flags);
5700 list_add_tail(&conn_entry->list,
5701 &phba->fcf_conn_rec_list);
5702 }
5703}
5704
5705/**
5706 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5707 * @phba: Pointer to hba context object.
5708 * @buff: Buffer containing the FCoE parameter data structure.
5709 *
5710 * This function update driver data structure with config
5711 * parameters read from config region 23.
5712 */
5713static void
5714lpfc_read_fcoe_param(struct lpfc_hba *phba,
5715 uint8_t *buff)
5716{
5717 struct lpfc_fip_param_hdr *fcoe_param_hdr;
5718 struct lpfc_fcoe_params *fcoe_param;
5719
5720 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
5721 buff;
5722 fcoe_param = (struct lpfc_fcoe_params *)
32b9793f 5723 (buff + sizeof(struct lpfc_fip_param_hdr));
6fb120a7
JS
5724
5725 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
5726 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
5727 return;
5728
6fb120a7
JS
5729 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
5730 phba->valid_vlan = 1;
5731 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
5732 0xFFF;
5733 }
5734
5735 phba->fc_map[0] = fcoe_param->fc_map[0];
5736 phba->fc_map[1] = fcoe_param->fc_map[1];
5737 phba->fc_map[2] = fcoe_param->fc_map[2];
5738 return;
5739}
5740
5741/**
5742 * lpfc_get_rec_conf23 - Get a record type in config region data.
5743 * @buff: Buffer containing config region 23 data.
5744 * @size: Size of the data buffer.
5745 * @rec_type: Record type to be searched.
5746 *
5747 * This function searches config region data to find the begining
5748 * of the record specified by record_type. If record found, this
5749 * function return pointer to the record else return NULL.
5750 */
5751static uint8_t *
5752lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
5753{
5754 uint32_t offset = 0, rec_length;
5755
5756 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
5757 (size < sizeof(uint32_t)))
5758 return NULL;
5759
5760 rec_length = buff[offset + 1];
5761
5762 /*
5763 * One TLV record has one word header and number of data words
5764 * specified in the rec_length field of the record header.
5765 */
5766 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
5767 <= size) {
5768 if (buff[offset] == rec_type)
5769 return &buff[offset];
5770
5771 if (buff[offset] == LPFC_REGION23_LAST_REC)
5772 return NULL;
5773
5774 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
5775 rec_length = buff[offset + 1];
5776 }
5777 return NULL;
5778}
5779
5780/**
5781 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5782 * @phba: Pointer to lpfc_hba data structure.
5783 * @buff: Buffer containing config region 23 data.
5784 * @size: Size of the data buffer.
5785 *
eef35c2d 5786 * This function parses the FCoE config parameters in config region 23 and
6fb120a7
JS
5787 * populate driver data structure with the parameters.
5788 */
5789void
5790lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
5791 uint8_t *buff,
5792 uint32_t size)
5793{
5794 uint32_t offset = 0, rec_length;
5795 uint8_t *rec_ptr;
5796
5797 /*
5798 * If data size is less than 2 words signature and version cannot be
5799 * verified.
5800 */
5801 if (size < 2*sizeof(uint32_t))
5802 return;
5803
5804 /* Check the region signature first */
5805 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
5806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5807 "2567 Config region 23 has bad signature\n");
5808 return;
5809 }
5810
5811 offset += 4;
5812
5813 /* Check the data structure version */
5814 if (buff[offset] != LPFC_REGION23_VERSION) {
5815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5816 "2568 Config region 23 has bad version\n");
5817 return;
5818 }
5819 offset += 4;
5820
5821 rec_length = buff[offset + 1];
5822
5823 /* Read FCoE param record */
5824 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5825 size - offset, FCOE_PARAM_TYPE);
5826 if (rec_ptr)
5827 lpfc_read_fcoe_param(phba, rec_ptr);
5828
5829 /* Read FCF connection table */
5830 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5831 size - offset, FCOE_CONN_TBL_TYPE);
5832 if (rec_ptr)
5833 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
5834
5835}
This page took 0.970317 seconds and 5 git commands to generate.