1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray
[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
71 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
73 static int lpfc_fcf_inuse(struct lpfc_hba
*);
74 static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
76 /* The source of a terminate rport I/O is either a dev_loss_tmo
77 * event or a call to fc_remove_host. While the rport should be
78 * valid during these downcalls, the transport can call twice
79 * in a single event. This routine provides somoe protection
80 * as the NDLP isn't really free, just released to the pool.
83 lpfc_rport_invalid(struct fc_rport
*rport
)
85 struct lpfc_rport_data
*rdata
;
86 struct lpfc_nodelist
*ndlp
;
89 pr_err("**** %s: NULL rport, exit.\n", __func__
);
93 rdata
= rport
->dd_data
;
95 pr_err("**** %s: NULL dd_data on rport %p SID x%x\n",
96 __func__
, rport
, rport
->scsi_target_id
);
102 pr_err("**** %s: NULL ndlp on rport %p SID x%x\n",
103 __func__
, rport
, rport
->scsi_target_id
);
108 pr_err("**** %s: Null vport on ndlp %p, DID x%x rport %p "
109 "SID x%x\n", __func__
, ndlp
, ndlp
->nlp_DID
, rport
,
110 rport
->scsi_target_id
);
117 lpfc_terminate_rport_io(struct fc_rport
*rport
)
119 struct lpfc_rport_data
*rdata
;
120 struct lpfc_nodelist
*ndlp
;
121 struct lpfc_vport
*vport
;
123 if (lpfc_rport_invalid(rport
))
126 rdata
= rport
->dd_data
;
129 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
130 "rport terminate: sid:x%x did:x%x flg:x%x",
131 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
133 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
134 lpfc_sli_abort_iocb(vport
,
135 &vport
->phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
136 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
141 * This function will be called when dev_loss_tmo fire.
144 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
146 struct lpfc_nodelist
*ndlp
;
147 struct lpfc_vport
*vport
;
148 struct lpfc_hba
*phba
;
149 struct lpfc_work_evt
*evtp
;
150 unsigned long iflags
;
152 ndlp
= ((struct lpfc_rport_data
*)rport
->dd_data
)->pnode
;
159 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
160 "rport devlosscb: sid:x%x did:x%x flg:x%x",
161 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
163 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
164 "3181 dev_loss_callbk x%06x, rport %p flg x%x "
165 "load_flag x%x refcnt %d\n",
166 ndlp
->nlp_DID
, ndlp
->rport
, ndlp
->nlp_flag
,
167 vport
->load_flag
, kref_read(&ndlp
->kref
));
169 /* Don't schedule a worker thread event if the vport is going down.
170 * The teardown process cleans up the node via lpfc_drop_node.
172 if (vport
->load_flag
& FC_UNLOADING
) {
173 ((struct lpfc_rport_data
*)rport
->dd_data
)->pnode
= NULL
;
176 ndlp
->fc4_xpt_flags
&= ~SCSI_XPT_REGD
;
178 /* Remove the node reference from remote_port_add now.
179 * The driver will not call remote_port_delete.
185 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
188 if (rport
->port_name
!= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
))
189 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
190 "6789 rport name %llx != node port name %llx",
192 wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
));
194 evtp
= &ndlp
->dev_loss_evt
;
196 if (!list_empty(&evtp
->evt_listp
)) {
197 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
198 "6790 rport name %llx dev_loss_evt pending\n",
203 spin_lock_irqsave(&ndlp
->lock
, iflags
);
204 ndlp
->nlp_flag
|= NLP_IN_DEV_LOSS
;
205 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
208 * The backend does not expect any more calls associated with this
209 * rport. Remove the association between rport and ndlp.
211 ndlp
->fc4_xpt_flags
&= ~SCSI_XPT_REGD
;
212 ((struct lpfc_rport_data
*)rport
->dd_data
)->pnode
= NULL
;
214 spin_unlock_irqrestore(&ndlp
->lock
, iflags
);
216 /* We need to hold the node by incrementing the reference
217 * count until this queued work is done
219 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
221 spin_lock_irqsave(&phba
->hbalock
, iflags
);
222 if (evtp
->evt_arg1
) {
223 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
224 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
225 lpfc_worker_wake_up(phba
);
227 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
233 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
234 * @ndlp: Pointer to remote node object.
236 * This function is called from the worker thread when devloss timeout timer
237 * expires. For SLI4 host, this routine shall return 1 when at lease one
238 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
239 * routine shall return 0 when there is no remote node is still in use of FCF
240 * when devloss timeout happened to this @ndlp.
243 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
245 struct lpfc_vport
*vport
;
246 struct lpfc_hba
*phba
;
250 unsigned long iflags
;
253 name
= (uint8_t *)&ndlp
->nlp_portname
;
256 spin_lock_irqsave(&ndlp
->lock
, iflags
);
257 ndlp
->nlp_flag
&= ~NLP_IN_DEV_LOSS
;
258 spin_unlock_irqrestore(&ndlp
->lock
, iflags
);
260 if (phba
->sli_rev
== LPFC_SLI_REV4
)
261 fcf_inuse
= lpfc_fcf_inuse(phba
);
263 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
264 "rport devlosstmo:did:x%x type:x%x id:x%x",
265 ndlp
->nlp_DID
, ndlp
->nlp_type
, ndlp
->nlp_sid
);
267 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
268 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
269 __func__
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
270 ndlp
->fc4_xpt_flags
, kref_read(&ndlp
->kref
));
272 /* If the driver is recovering the rport, ignore devloss. */
273 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
274 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
275 "0284 Devloss timeout Ignored on "
276 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
278 *name
, *(name
+1), *(name
+2), *(name
+3),
279 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
284 /* Fabric nodes are done. */
285 if (ndlp
->nlp_type
& NLP_FABRIC
) {
290 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
292 lpfc_sli_abort_iocb(vport
, &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
293 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
297 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
298 "0203 Devloss timeout on "
299 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
300 "NPort x%06x Data: x%x x%x x%x\n",
301 *name
, *(name
+1), *(name
+2), *(name
+3),
302 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
303 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
304 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
306 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_TRACE_EVENT
,
307 "0204 Devloss timeout on "
308 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
309 "NPort x%06x Data: x%x x%x x%x\n",
310 *name
, *(name
+1), *(name
+2), *(name
+3),
311 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
312 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
313 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
316 if (!(ndlp
->fc4_xpt_flags
& NVME_XPT_REGD
))
317 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
323 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
324 * @phba: Pointer to hba context object.
325 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
326 * @nlp_did: remote node identifer with devloss timeout.
328 * This function is called from the worker thread after invoking devloss
329 * timeout handler and releasing the reference count for the ndlp with
330 * which the devloss timeout was handled for SLI4 host. For the devloss
331 * timeout of the last remote node which had been in use of FCF, when this
332 * routine is invoked, it shall be guaranteed that none of the remote are
333 * in-use of FCF. When devloss timeout to the last remote using the FCF,
334 * if the FIP engine is neither in FCF table scan process nor roundrobin
335 * failover process, the in-use FCF shall be unregistered. If the FIP
336 * engine is in FCF discovery process, the devloss timeout state shall
337 * be set for either the FCF table scan process or roundrobin failover
338 * process to unregister the in-use FCF.
341 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba
*phba
, int fcf_inuse
,
344 /* If devloss timeout happened to a remote node when FCF had no
345 * longer been in-use, do nothing.
350 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) && !lpfc_fcf_inuse(phba
)) {
351 spin_lock_irq(&phba
->hbalock
);
352 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
353 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
354 spin_unlock_irq(&phba
->hbalock
);
357 phba
->hba_flag
|= HBA_DEVLOSS_TMO
;
358 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
359 "2847 Last remote node (x%x) using "
360 "FCF devloss tmo\n", nlp_did
);
362 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PROG
) {
363 spin_unlock_irq(&phba
->hbalock
);
364 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
365 "2868 Devloss tmo to FCF rediscovery "
369 if (!(phba
->hba_flag
& (FCF_TS_INPROG
| FCF_RR_INPROG
))) {
370 spin_unlock_irq(&phba
->hbalock
);
371 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
372 "2869 Devloss tmo to idle FIP engine, "
373 "unreg in-use FCF and rescan.\n");
374 /* Unregister in-use FCF and rescan */
375 lpfc_unregister_fcf_rescan(phba
);
378 spin_unlock_irq(&phba
->hbalock
);
379 if (phba
->hba_flag
& FCF_TS_INPROG
)
380 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
381 "2870 FCF table scan in progress\n");
382 if (phba
->hba_flag
& FCF_RR_INPROG
)
383 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
384 "2871 FLOGI roundrobin FCF failover "
387 lpfc_unregister_unused_fcf(phba
);
391 * lpfc_alloc_fast_evt - Allocates data structure for posting event
392 * @phba: Pointer to hba context object.
394 * This function is called from the functions which need to post
395 * events from interrupt context. This function allocates data
396 * structure required for posting event. It also keeps track of
397 * number of events pending and prevent event storm when there are
400 struct lpfc_fast_path_event
*
401 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
402 struct lpfc_fast_path_event
*ret
;
404 /* If there are lot of fast event do not exhaust memory due to this */
405 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
408 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
411 atomic_inc(&phba
->fast_event_count
);
412 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
413 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
419 * lpfc_free_fast_evt - Frees event data structure
420 * @phba: Pointer to hba context object.
421 * @evt: Event object which need to be freed.
423 * This function frees the data structure required for posting
427 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
428 struct lpfc_fast_path_event
*evt
) {
430 atomic_dec(&phba
->fast_event_count
);
435 * lpfc_send_fastpath_evt - Posts events generated from fast path
436 * @phba: Pointer to hba context object.
437 * @evtp: Event data structure.
439 * This function is called from worker thread, when the interrupt
440 * context need to post an event. This function posts the event
441 * to fc transport netlink interface.
444 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
445 struct lpfc_work_evt
*evtp
)
447 unsigned long evt_category
, evt_sub_category
;
448 struct lpfc_fast_path_event
*fast_evt_data
;
450 uint32_t evt_data_size
;
451 struct Scsi_Host
*shost
;
453 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
456 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
457 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
458 fabric_evt
.subcategory
;
459 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
460 if (evt_category
== FC_REG_FABRIC_EVENT
) {
461 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
462 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
463 evt_data_size
= sizeof(fast_evt_data
->un
.
465 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
466 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
467 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
468 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
470 lpfc_free_fast_evt(phba
, fast_evt_data
);
473 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
474 switch (evt_sub_category
) {
475 case LPFC_EVENT_QFULL
:
476 case LPFC_EVENT_DEVBSY
:
477 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
478 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
480 case LPFC_EVENT_CHECK_COND
:
481 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
482 evt_data_size
= sizeof(fast_evt_data
->un
.
485 case LPFC_EVENT_VARQUEDEPTH
:
486 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
487 evt_data_size
= sizeof(fast_evt_data
->un
.
491 lpfc_free_fast_evt(phba
, fast_evt_data
);
495 lpfc_free_fast_evt(phba
, fast_evt_data
);
499 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
500 fc_host_post_vendor_event(shost
,
501 fc_get_event_number(),
506 lpfc_free_fast_evt(phba
, fast_evt_data
);
511 lpfc_work_list_done(struct lpfc_hba
*phba
)
513 struct lpfc_work_evt
*evtp
= NULL
;
514 struct lpfc_nodelist
*ndlp
;
519 spin_lock_irq(&phba
->hbalock
);
520 while (!list_empty(&phba
->work_list
)) {
521 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
523 spin_unlock_irq(&phba
->hbalock
);
526 case LPFC_EVT_ELS_RETRY
:
527 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
528 lpfc_els_retry_delay_handler(ndlp
);
529 free_evt
= 0; /* evt is part of ndlp */
530 /* decrement the node reference count held
531 * for this queued work
535 case LPFC_EVT_DEV_LOSS
:
536 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
537 fcf_inuse
= lpfc_dev_loss_tmo_handler(ndlp
);
539 /* decrement the node reference count held for
542 nlp_did
= ndlp
->nlp_DID
;
544 if (phba
->sli_rev
== LPFC_SLI_REV4
)
545 lpfc_sli4_post_dev_loss_tmo_handler(phba
,
549 case LPFC_EVT_RECOVER_PORT
:
550 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
551 lpfc_sli_abts_recover_port(ndlp
->vport
, ndlp
);
553 /* decrement the node reference count held for
558 case LPFC_EVT_ONLINE
:
559 if (phba
->link_state
< LPFC_LINK_DOWN
)
560 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
562 *(int *) (evtp
->evt_arg1
) = 0;
563 complete((struct completion
*)(evtp
->evt_arg2
));
565 case LPFC_EVT_OFFLINE_PREP
:
566 if (phba
->link_state
>= LPFC_LINK_DOWN
)
567 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
568 *(int *)(evtp
->evt_arg1
) = 0;
569 complete((struct completion
*)(evtp
->evt_arg2
));
571 case LPFC_EVT_OFFLINE
:
573 lpfc_sli_brdrestart(phba
);
574 *(int *)(evtp
->evt_arg1
) =
575 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
576 lpfc_unblock_mgmt_io(phba
);
577 complete((struct completion
*)(evtp
->evt_arg2
));
579 case LPFC_EVT_WARM_START
:
581 lpfc_reset_barrier(phba
);
582 lpfc_sli_brdreset(phba
);
583 lpfc_hba_down_post(phba
);
584 *(int *)(evtp
->evt_arg1
) =
585 lpfc_sli_brdready(phba
, HS_MBRDY
);
586 lpfc_unblock_mgmt_io(phba
);
587 complete((struct completion
*)(evtp
->evt_arg2
));
591 *(int *)(evtp
->evt_arg1
)
592 = (phba
->pport
->stopped
)
593 ? 0 : lpfc_sli_brdkill(phba
);
594 lpfc_unblock_mgmt_io(phba
);
595 complete((struct completion
*)(evtp
->evt_arg2
));
597 case LPFC_EVT_FASTPATH_MGMT_EVT
:
598 lpfc_send_fastpath_evt(phba
, evtp
);
601 case LPFC_EVT_RESET_HBA
:
602 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
603 lpfc_reset_hba(phba
);
608 spin_lock_irq(&phba
->hbalock
);
610 spin_unlock_irq(&phba
->hbalock
);
615 lpfc_work_done(struct lpfc_hba
*phba
)
617 struct lpfc_sli_ring
*pring
;
618 uint32_t ha_copy
, status
, control
, work_port_events
;
619 struct lpfc_vport
**vports
;
620 struct lpfc_vport
*vport
;
623 spin_lock_irq(&phba
->hbalock
);
624 ha_copy
= phba
->work_ha
;
626 spin_unlock_irq(&phba
->hbalock
);
628 /* First, try to post the next mailbox command to SLI4 device */
629 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
630 lpfc_sli4_post_async_mbox(phba
);
632 if (ha_copy
& HA_ERATT
)
633 /* Handle the error attention event */
634 lpfc_handle_eratt(phba
);
636 if (ha_copy
& HA_MBATT
)
637 lpfc_sli_handle_mb_event(phba
);
639 if (ha_copy
& HA_LATT
)
640 lpfc_handle_latt(phba
);
642 /* Process SLI4 events */
643 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
644 if (phba
->hba_flag
& HBA_RRQ_ACTIVE
)
645 lpfc_handle_rrq_active(phba
);
646 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
647 lpfc_sli4_els_xri_abort_event_proc(phba
);
648 if (phba
->hba_flag
& ASYNC_EVENT
)
649 lpfc_sli4_async_event_proc(phba
);
650 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
651 spin_lock_irq(&phba
->hbalock
);
652 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
653 spin_unlock_irq(&phba
->hbalock
);
654 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
656 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
)
657 lpfc_sli4_fcf_redisc_event_proc(phba
);
660 vports
= lpfc_create_vport_work_array(phba
);
662 for (i
= 0; i
<= phba
->max_vports
; i
++) {
664 * We could have no vports in array if unloading, so if
665 * this happens then just use the pport
667 if (vports
[i
] == NULL
&& i
== 0)
673 spin_lock_irq(&vport
->work_port_lock
);
674 work_port_events
= vport
->work_port_events
;
675 vport
->work_port_events
&= ~work_port_events
;
676 spin_unlock_irq(&vport
->work_port_lock
);
677 if (work_port_events
& WORKER_DISC_TMO
)
678 lpfc_disc_timeout_handler(vport
);
679 if (work_port_events
& WORKER_ELS_TMO
)
680 lpfc_els_timeout_handler(vport
);
681 if (work_port_events
& WORKER_HB_TMO
)
682 lpfc_hb_timeout_handler(phba
);
683 if (work_port_events
& WORKER_MBOX_TMO
)
684 lpfc_mbox_timeout_handler(phba
);
685 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
686 lpfc_unblock_fabric_iocbs(phba
);
687 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
688 lpfc_ramp_down_queue_handler(phba
);
689 if (work_port_events
& WORKER_DELAYED_DISC_TMO
)
690 lpfc_delayed_disc_timeout_handler(vport
);
692 lpfc_destroy_vport_work_array(phba
, vports
);
694 pring
= lpfc_phba_elsring(phba
);
695 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
696 status
>>= (4*LPFC_ELS_RING
);
697 if (pring
&& (status
& HA_RXMASK
||
698 pring
->flag
& LPFC_DEFERRED_RING_EVENT
||
699 phba
->hba_flag
& HBA_SP_QUEUE_EVT
)) {
700 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
701 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
702 /* Preserve legacy behavior. */
703 if (!(phba
->hba_flag
& HBA_SP_QUEUE_EVT
))
704 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
706 /* Driver could have abort request completed in queue
707 * when link goes down. Allow for this transition.
709 if (phba
->link_state
>= LPFC_LINK_DOWN
||
710 phba
->link_flag
& LS_MDS_LOOPBACK
) {
711 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
712 lpfc_sli_handle_slow_ring_event(phba
, pring
,
717 if (phba
->sli_rev
== LPFC_SLI_REV4
)
718 lpfc_drain_txq(phba
);
720 * Turn on Ring interrupts
722 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
723 spin_lock_irq(&phba
->hbalock
);
724 control
= readl(phba
->HCregaddr
);
725 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
726 lpfc_debugfs_slow_ring_trc(phba
,
727 "WRK Enable ring: cntl:x%x hacopy:x%x",
728 control
, ha_copy
, 0);
730 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
731 writel(control
, phba
->HCregaddr
);
732 readl(phba
->HCregaddr
); /* flush */
734 lpfc_debugfs_slow_ring_trc(phba
,
735 "WRK Ring ok: cntl:x%x hacopy:x%x",
736 control
, ha_copy
, 0);
738 spin_unlock_irq(&phba
->hbalock
);
741 lpfc_work_list_done(phba
);
745 lpfc_do_work(void *p
)
747 struct lpfc_hba
*phba
= p
;
750 set_user_nice(current
, MIN_NICE
);
751 current
->flags
|= PF_NOFREEZE
;
752 phba
->data_flags
= 0;
754 while (!kthread_should_stop()) {
755 /* wait and check worker queue activities */
756 rc
= wait_event_interruptible(phba
->work_waitq
,
757 (test_and_clear_bit(LPFC_DATA_READY
,
759 || kthread_should_stop()));
760 /* Signal wakeup shall terminate the worker thread */
762 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
763 "0433 Wakeup on signal: rc=x%x\n", rc
);
767 /* Attend pending lpfc data processing */
768 lpfc_work_done(phba
);
770 phba
->worker_thread
= NULL
;
771 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
772 "0432 Worker thread stopped.\n");
777 * This is only called to handle FC worker events. Since this a rare
778 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
779 * embedding it in the IOCB.
782 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
785 struct lpfc_work_evt
*evtp
;
789 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
790 * be queued to worker thread for processing
792 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
796 evtp
->evt_arg1
= arg1
;
797 evtp
->evt_arg2
= arg2
;
800 spin_lock_irqsave(&phba
->hbalock
, flags
);
801 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
802 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
804 lpfc_worker_wake_up(phba
);
810 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
812 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
813 struct lpfc_hba
*phba
= vport
->phba
;
814 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
816 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
817 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
820 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
821 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
822 ((ndlp
->nlp_DID
== NameServer_DID
) ||
823 (ndlp
->nlp_DID
== FDMI_DID
))))
824 lpfc_unreg_rpi(vport
, ndlp
);
826 /* Leave Fabric nodes alone on link down */
827 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
828 (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
))
831 /* Notify transport of connectivity loss to trigger cleanup. */
832 if (phba
->nvmet_support
&&
833 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
)
834 lpfc_nvmet_invalidate_host(phba
, ndlp
);
836 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
839 : NLP_EVT_DEVICE_RECOVERY
);
841 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
842 if (phba
->sli_rev
== LPFC_SLI_REV4
)
843 lpfc_sli4_unreg_all_rpis(vport
);
844 lpfc_mbx_unreg_vpi(vport
);
845 spin_lock_irq(shost
->host_lock
);
846 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
847 spin_unlock_irq(shost
->host_lock
);
852 lpfc_port_link_failure(struct lpfc_vport
*vport
)
854 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
856 /* Cleanup any outstanding received buffers */
857 lpfc_cleanup_rcv_buffers(vport
);
859 /* Cleanup any outstanding RSCN activity */
860 lpfc_els_flush_rscn(vport
);
862 /* Cleanup any outstanding ELS commands */
863 lpfc_els_flush_cmd(vport
);
865 lpfc_cleanup_rpis(vport
, 0);
867 /* Turn off discovery timer if its running */
868 lpfc_can_disctmo(vport
);
872 lpfc_linkdown_port(struct lpfc_vport
*vport
)
874 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
876 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
877 fc_host_post_event(shost
, fc_get_event_number(),
878 FCH_EVT_LINKDOWN
, 0);
880 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
881 "Link Down: state:x%x rtry:x%x flg:x%x",
882 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
884 lpfc_port_link_failure(vport
);
886 /* Stop delayed Nport discovery */
887 spin_lock_irq(shost
->host_lock
);
888 vport
->fc_flag
&= ~FC_DISC_DELAYED
;
889 spin_unlock_irq(shost
->host_lock
);
890 del_timer_sync(&vport
->delayed_disc_tmo
);
894 lpfc_linkdown(struct lpfc_hba
*phba
)
896 struct lpfc_vport
*vport
= phba
->pport
;
897 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
898 struct lpfc_vport
**vports
;
902 if (phba
->link_state
== LPFC_LINK_DOWN
)
905 /* Block all SCSI stack I/Os */
906 lpfc_scsi_dev_block(phba
);
908 phba
->defer_flogi_acc_flag
= false;
910 spin_lock_irq(&phba
->hbalock
);
911 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
912 spin_unlock_irq(&phba
->hbalock
);
913 if (phba
->link_state
> LPFC_LINK_DOWN
) {
914 phba
->link_state
= LPFC_LINK_DOWN
;
915 if (phba
->sli4_hba
.conf_trunk
) {
916 phba
->trunk_link
.link0
.state
= 0;
917 phba
->trunk_link
.link1
.state
= 0;
918 phba
->trunk_link
.link2
.state
= 0;
919 phba
->trunk_link
.link3
.state
= 0;
920 phba
->sli4_hba
.link_state
.logical_speed
=
921 LPFC_LINK_SPEED_UNKNOWN
;
923 spin_lock_irq(shost
->host_lock
);
924 phba
->pport
->fc_flag
&= ~FC_LBIT
;
925 spin_unlock_irq(shost
->host_lock
);
927 vports
= lpfc_create_vport_work_array(phba
);
928 if (vports
!= NULL
) {
929 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
930 /* Issue a LINK DOWN event to all nodes */
931 lpfc_linkdown_port(vports
[i
]);
933 vports
[i
]->fc_myDID
= 0;
935 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
936 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
937 if (phba
->nvmet_support
)
938 lpfc_nvmet_update_targetport(phba
);
940 lpfc_nvme_update_localport(vports
[i
]);
944 lpfc_destroy_vport_work_array(phba
, vports
);
946 /* Clean up any SLI3 firmware default rpi's */
947 if (phba
->sli_rev
> LPFC_SLI_REV3
)
950 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
952 lpfc_unreg_did(phba
, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS
, mb
);
954 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
955 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
956 == MBX_NOT_FINISHED
) {
957 mempool_free(mb
, phba
->mbox_mem_pool
);
962 /* Setup myDID for link up if we are in pt2pt mode */
963 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
964 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
966 lpfc_config_link(phba
, mb
);
967 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
969 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
970 == MBX_NOT_FINISHED
) {
971 mempool_free(mb
, phba
->mbox_mem_pool
);
974 spin_lock_irq(shost
->host_lock
);
975 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
976 phba
->pport
->rcv_flogi_cnt
= 0;
977 spin_unlock_irq(shost
->host_lock
);
983 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
985 struct lpfc_nodelist
*ndlp
;
987 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
988 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
990 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
992 if (ndlp
->nlp_type
& NLP_FABRIC
) {
993 /* On Linkup its safe to clean up the ndlp
994 * from Fabric connections.
996 if (ndlp
->nlp_DID
!= Fabric_DID
)
997 lpfc_unreg_rpi(vport
, ndlp
);
998 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
999 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
1000 /* Fail outstanding IO now since device is
1003 lpfc_unreg_rpi(vport
, ndlp
);
1009 lpfc_linkup_port(struct lpfc_vport
*vport
)
1011 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1012 struct lpfc_hba
*phba
= vport
->phba
;
1014 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
1017 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1018 "Link Up: top:x%x speed:x%x flg:x%x",
1019 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
1021 /* If NPIV is not enabled, only bring the physical port up */
1022 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1023 (vport
!= phba
->pport
))
1026 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
1027 fc_host_post_event(shost
, fc_get_event_number(),
1030 spin_lock_irq(shost
->host_lock
);
1031 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
1032 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
1033 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
1034 vport
->fc_ns_retry
= 0;
1035 spin_unlock_irq(shost
->host_lock
);
1037 lpfc_linkup_cleanup_nodes(vport
);
1041 lpfc_linkup(struct lpfc_hba
*phba
)
1043 struct lpfc_vport
**vports
;
1045 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
1047 phba
->link_state
= LPFC_LINK_UP
;
1049 /* Unblock fabric iocbs if they are blocked */
1050 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
1051 del_timer_sync(&phba
->fabric_block_timer
);
1053 vports
= lpfc_create_vport_work_array(phba
);
1055 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1056 lpfc_linkup_port(vports
[i
]);
1057 lpfc_destroy_vport_work_array(phba
, vports
);
1059 /* Clear the pport flogi counter in case the link down was
1060 * absorbed without an ACQE. No lock here - in worker thread
1061 * and discovery is synchronized.
1063 spin_lock_irq(shost
->host_lock
);
1064 phba
->pport
->rcv_flogi_cnt
= 0;
1065 spin_unlock_irq(shost
->host_lock
);
1067 /* reinitialize initial FLOGI flag */
1068 phba
->hba_flag
&= ~(HBA_FLOGI_ISSUED
);
1069 phba
->defer_flogi_acc_flag
= false;
1075 * This routine handles processing a CLEAR_LA mailbox
1076 * command upon completion. It is setup in the LPFC_MBOXQ
1077 * as the completion routine when the command is
1078 * handed off to the SLI layer. SLI3 only.
1081 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1083 struct lpfc_vport
*vport
= pmb
->vport
;
1084 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1085 struct lpfc_sli
*psli
= &phba
->sli
;
1086 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1089 /* Since we don't do discovery right now, turn these off here */
1090 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1091 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1093 /* Check for error */
1094 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
1095 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1096 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1097 "0320 CLEAR_LA mbxStatus error x%x hba "
1099 mb
->mbxStatus
, vport
->port_state
);
1100 phba
->link_state
= LPFC_HBA_ERROR
;
1104 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1105 phba
->link_state
= LPFC_HBA_READY
;
1107 spin_lock_irq(&phba
->hbalock
);
1108 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1109 control
= readl(phba
->HCregaddr
);
1110 control
|= HC_LAINT_ENA
;
1111 writel(control
, phba
->HCregaddr
);
1112 readl(phba
->HCregaddr
); /* flush */
1113 spin_unlock_irq(&phba
->hbalock
);
1114 mempool_free(pmb
, phba
->mbox_mem_pool
);
1118 /* Device Discovery completes */
1119 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1120 "0225 Device Discovery completes\n");
1121 mempool_free(pmb
, phba
->mbox_mem_pool
);
1123 spin_lock_irq(shost
->host_lock
);
1124 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
1125 spin_unlock_irq(shost
->host_lock
);
1127 lpfc_can_disctmo(vport
);
1129 /* turn on Link Attention interrupts */
1131 spin_lock_irq(&phba
->hbalock
);
1132 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1133 control
= readl(phba
->HCregaddr
);
1134 control
|= HC_LAINT_ENA
;
1135 writel(control
, phba
->HCregaddr
);
1136 readl(phba
->HCregaddr
); /* flush */
1137 spin_unlock_irq(&phba
->hbalock
);
1143 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1145 struct lpfc_vport
*vport
= pmb
->vport
;
1146 LPFC_MBOXQ_t
*sparam_mb
;
1147 struct lpfc_dmabuf
*sparam_mp
;
1150 if (pmb
->u
.mb
.mbxStatus
)
1153 mempool_free(pmb
, phba
->mbox_mem_pool
);
1155 /* don't perform discovery for SLI4 loopback diagnostic test */
1156 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1157 !(phba
->hba_flag
& HBA_FCOE_MODE
) &&
1158 (phba
->link_flag
& LS_LOOPBACK_MODE
))
1161 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
&&
1162 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
1163 !(vport
->fc_flag
& FC_LBIT
)) {
1164 /* Need to wait for FAN - use discovery timer
1165 * for timeout. port_state is identically
1166 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1168 lpfc_set_disctmo(vport
);
1172 /* Start discovery by sending a FLOGI. port_state is identically
1173 * LPFC_FLOGI while waiting for FLOGI cmpl.
1175 if (vport
->port_state
!= LPFC_FLOGI
) {
1176 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1177 * bb-credit recovery is in place.
1179 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
&&
1180 !(phba
->link_flag
& LS_LOOPBACK_MODE
)) {
1181 sparam_mb
= mempool_alloc(phba
->mbox_mem_pool
,
1186 rc
= lpfc_read_sparam(phba
, sparam_mb
, 0);
1188 mempool_free(sparam_mb
, phba
->mbox_mem_pool
);
1191 sparam_mb
->vport
= vport
;
1192 sparam_mb
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1193 rc
= lpfc_sli_issue_mbox(phba
, sparam_mb
, MBX_NOWAIT
);
1194 if (rc
== MBX_NOT_FINISHED
) {
1195 sparam_mp
= (struct lpfc_dmabuf
*)
1197 lpfc_mbuf_free(phba
, sparam_mp
->virt
,
1200 sparam_mb
->ctx_buf
= NULL
;
1201 mempool_free(sparam_mb
, phba
->mbox_mem_pool
);
1205 phba
->hba_flag
|= HBA_DEFER_FLOGI
;
1207 lpfc_initial_flogi(vport
);
1210 if (vport
->fc_flag
& FC_PT2PT
)
1211 lpfc_disc_start(vport
);
1216 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1217 "0306 CONFIG_LINK mbxStatus error x%x "
1219 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
1221 mempool_free(pmb
, phba
->mbox_mem_pool
);
1223 lpfc_linkdown(phba
);
1225 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1226 "0200 CONFIG_LINK bad hba state x%x\n",
1229 lpfc_issue_clear_la(phba
, vport
);
1234 * lpfc_sli4_clear_fcf_rr_bmask
1235 * @phba: pointer to the struct lpfc_hba for this port.
1236 * This fucnction resets the round robin bit mask and clears the
1237 * fcf priority list. The list deletions are done while holding the
1238 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1239 * from the lpfc_fcf_pri record.
1242 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba
*phba
)
1244 struct lpfc_fcf_pri
*fcf_pri
;
1245 struct lpfc_fcf_pri
*next_fcf_pri
;
1246 memset(phba
->fcf
.fcf_rr_bmask
, 0, sizeof(*phba
->fcf
.fcf_rr_bmask
));
1247 spin_lock_irq(&phba
->hbalock
);
1248 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
1249 &phba
->fcf
.fcf_pri_list
, list
) {
1250 list_del_init(&fcf_pri
->list
);
1251 fcf_pri
->fcf_rec
.flag
= 0;
1253 spin_unlock_irq(&phba
->hbalock
);
1256 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1258 struct lpfc_vport
*vport
= mboxq
->vport
;
1260 if (mboxq
->u
.mb
.mbxStatus
) {
1261 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1262 "2017 REG_FCFI mbxStatus error x%x "
1263 "HBA state x%x\n", mboxq
->u
.mb
.mbxStatus
,
1268 /* Start FCoE discovery by sending a FLOGI. */
1269 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1270 /* Set the FCFI registered flag */
1271 spin_lock_irq(&phba
->hbalock
);
1272 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1273 spin_unlock_irq(&phba
->hbalock
);
1275 /* If there is a pending FCoE event, restart FCF table scan. */
1276 if ((!(phba
->hba_flag
& FCF_RR_INPROG
)) &&
1277 lpfc_check_pending_fcoe_event(phba
, LPFC_UNREG_FCF
))
1280 /* Mark successful completion of FCF table scan */
1281 spin_lock_irq(&phba
->hbalock
);
1282 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1283 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1284 if (vport
->port_state
!= LPFC_FLOGI
) {
1285 phba
->hba_flag
|= FCF_RR_INPROG
;
1286 spin_unlock_irq(&phba
->hbalock
);
1287 lpfc_issue_init_vfi(vport
);
1290 spin_unlock_irq(&phba
->hbalock
);
1294 spin_lock_irq(&phba
->hbalock
);
1295 phba
->hba_flag
&= ~FCF_RR_INPROG
;
1296 spin_unlock_irq(&phba
->hbalock
);
1298 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1302 * lpfc_fab_name_match - Check if the fcf fabric name match.
1303 * @fab_name: pointer to fabric name.
1304 * @new_fcf_record: pointer to fcf record.
1306 * This routine compare the fcf record's fabric name with provided
1307 * fabric name. If the fabric name are identical this function
1308 * returns 1 else return 0.
1311 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1313 if (fab_name
[0] != bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
))
1315 if (fab_name
[1] != bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
))
1317 if (fab_name
[2] != bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
))
1319 if (fab_name
[3] != bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
))
1321 if (fab_name
[4] != bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
))
1323 if (fab_name
[5] != bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
))
1325 if (fab_name
[6] != bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
))
1327 if (fab_name
[7] != bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
))
1333 * lpfc_sw_name_match - Check if the fcf switch name match.
1334 * @sw_name: pointer to switch name.
1335 * @new_fcf_record: pointer to fcf record.
1337 * This routine compare the fcf record's switch name with provided
1338 * switch name. If the switch name are identical this function
1339 * returns 1 else return 0.
1342 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1344 if (sw_name
[0] != bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
))
1346 if (sw_name
[1] != bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
))
1348 if (sw_name
[2] != bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
))
1350 if (sw_name
[3] != bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
))
1352 if (sw_name
[4] != bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
))
1354 if (sw_name
[5] != bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
))
1356 if (sw_name
[6] != bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
))
1358 if (sw_name
[7] != bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
))
1364 * lpfc_mac_addr_match - Check if the fcf mac address match.
1365 * @mac_addr: pointer to mac address.
1366 * @new_fcf_record: pointer to fcf record.
1368 * This routine compare the fcf record's mac address with HBA's
1369 * FCF mac address. If the mac addresses are identical this function
1370 * returns 1 else return 0.
1373 lpfc_mac_addr_match(uint8_t *mac_addr
, struct fcf_record
*new_fcf_record
)
1375 if (mac_addr
[0] != bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
))
1377 if (mac_addr
[1] != bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
))
1379 if (mac_addr
[2] != bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
))
1381 if (mac_addr
[3] != bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
))
1383 if (mac_addr
[4] != bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
))
1385 if (mac_addr
[5] != bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
))
1391 lpfc_vlan_id_match(uint16_t curr_vlan_id
, uint16_t new_vlan_id
)
1393 return (curr_vlan_id
== new_vlan_id
);
1397 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1398 * @phba: pointer to lpfc hba data structure.
1399 * @fcf_index: Index for the lpfc_fcf_record.
1400 * @new_fcf_record: pointer to hba fcf record.
1402 * This routine updates the driver FCF priority record from the new HBA FCF
1403 * record. The hbalock is asserted held in the code path calling this
1407 __lpfc_update_fcf_record_pri(struct lpfc_hba
*phba
, uint16_t fcf_index
,
1408 struct fcf_record
*new_fcf_record
1411 struct lpfc_fcf_pri
*fcf_pri
;
1413 fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
1414 fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
1415 /* FCF record priority */
1416 fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
1421 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1422 * @fcf_rec: pointer to driver fcf record.
1423 * @new_fcf_record: pointer to fcf record.
1425 * This routine copies the FCF information from the FCF
1426 * record to lpfc_hba data structure.
1429 lpfc_copy_fcf_record(struct lpfc_fcf_rec
*fcf_rec
,
1430 struct fcf_record
*new_fcf_record
)
1433 fcf_rec
->fabric_name
[0] =
1434 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1435 fcf_rec
->fabric_name
[1] =
1436 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1437 fcf_rec
->fabric_name
[2] =
1438 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1439 fcf_rec
->fabric_name
[3] =
1440 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1441 fcf_rec
->fabric_name
[4] =
1442 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1443 fcf_rec
->fabric_name
[5] =
1444 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1445 fcf_rec
->fabric_name
[6] =
1446 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1447 fcf_rec
->fabric_name
[7] =
1448 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1450 fcf_rec
->mac_addr
[0] = bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1451 fcf_rec
->mac_addr
[1] = bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1452 fcf_rec
->mac_addr
[2] = bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1453 fcf_rec
->mac_addr
[3] = bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1454 fcf_rec
->mac_addr
[4] = bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1455 fcf_rec
->mac_addr
[5] = bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1456 /* FCF record index */
1457 fcf_rec
->fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1458 /* FCF record priority */
1459 fcf_rec
->priority
= new_fcf_record
->fip_priority
;
1461 fcf_rec
->switch_name
[0] =
1462 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1463 fcf_rec
->switch_name
[1] =
1464 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1465 fcf_rec
->switch_name
[2] =
1466 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1467 fcf_rec
->switch_name
[3] =
1468 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1469 fcf_rec
->switch_name
[4] =
1470 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1471 fcf_rec
->switch_name
[5] =
1472 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1473 fcf_rec
->switch_name
[6] =
1474 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1475 fcf_rec
->switch_name
[7] =
1476 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1480 * lpfc_update_fcf_record - Update driver fcf record
1481 * @phba: pointer to lpfc hba data structure.
1482 * @fcf_rec: pointer to driver fcf record.
1483 * @new_fcf_record: pointer to hba fcf record.
1484 * @addr_mode: address mode to be set to the driver fcf record.
1485 * @vlan_id: vlan tag to be set to the driver fcf record.
1486 * @flag: flag bits to be set to the driver fcf record.
1488 * This routine updates the driver FCF record from the new HBA FCF record
1489 * together with the address mode, vlan_id, and other informations. This
1490 * routine is called with the hbalock held.
1493 __lpfc_update_fcf_record(struct lpfc_hba
*phba
, struct lpfc_fcf_rec
*fcf_rec
,
1494 struct fcf_record
*new_fcf_record
, uint32_t addr_mode
,
1495 uint16_t vlan_id
, uint32_t flag
)
1497 lockdep_assert_held(&phba
->hbalock
);
1499 /* Copy the fields from the HBA's FCF record */
1500 lpfc_copy_fcf_record(fcf_rec
, new_fcf_record
);
1501 /* Update other fields of driver FCF record */
1502 fcf_rec
->addr_mode
= addr_mode
;
1503 fcf_rec
->vlan_id
= vlan_id
;
1504 fcf_rec
->flag
|= (flag
| RECORD_VALID
);
1505 __lpfc_update_fcf_record_pri(phba
,
1506 bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
),
1511 * lpfc_register_fcf - Register the FCF with hba.
1512 * @phba: pointer to lpfc hba data structure.
1514 * This routine issues a register fcfi mailbox command to register
1518 lpfc_register_fcf(struct lpfc_hba
*phba
)
1520 LPFC_MBOXQ_t
*fcf_mbxq
;
1523 spin_lock_irq(&phba
->hbalock
);
1524 /* If the FCF is not available do nothing. */
1525 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1526 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1527 spin_unlock_irq(&phba
->hbalock
);
1531 /* The FCF is already registered, start discovery */
1532 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1533 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1534 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1535 if (phba
->pport
->port_state
!= LPFC_FLOGI
&&
1536 phba
->pport
->fc_flag
& FC_FABRIC
) {
1537 phba
->hba_flag
|= FCF_RR_INPROG
;
1538 spin_unlock_irq(&phba
->hbalock
);
1539 lpfc_initial_flogi(phba
->pport
);
1542 spin_unlock_irq(&phba
->hbalock
);
1545 spin_unlock_irq(&phba
->hbalock
);
1547 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1549 spin_lock_irq(&phba
->hbalock
);
1550 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1551 spin_unlock_irq(&phba
->hbalock
);
1555 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1556 fcf_mbxq
->vport
= phba
->pport
;
1557 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1558 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1559 if (rc
== MBX_NOT_FINISHED
) {
1560 spin_lock_irq(&phba
->hbalock
);
1561 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1562 spin_unlock_irq(&phba
->hbalock
);
1563 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1570 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1571 * @phba: pointer to lpfc hba data structure.
1572 * @new_fcf_record: pointer to fcf record.
1573 * @boot_flag: Indicates if this record used by boot bios.
1574 * @addr_mode: The address mode to be used by this FCF
1575 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1577 * This routine compare the fcf record with connect list obtained from the
1578 * config region to decide if this FCF can be used for SAN discovery. It returns
1579 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1580 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1581 * is used by boot bios and addr_mode will indicate the addressing mode to be
1582 * used for this FCF when the function returns.
1583 * If the FCF record need to be used with a particular vlan id, the vlan is
1584 * set in the vlan_id on return of the function. If not VLAN tagging need to
1585 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1588 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1589 struct fcf_record
*new_fcf_record
,
1590 uint32_t *boot_flag
, uint32_t *addr_mode
,
1593 struct lpfc_fcf_conn_entry
*conn_entry
;
1594 int i
, j
, fcf_vlan_id
= 0;
1596 /* Find the lowest VLAN id in the FCF record */
1597 for (i
= 0; i
< 512; i
++) {
1598 if (new_fcf_record
->vlan_bitmap
[i
]) {
1599 fcf_vlan_id
= i
* 8;
1601 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1609 /* FCF not valid/available or solicitation in progress */
1610 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1611 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
) ||
1612 bf_get(lpfc_fcf_record_fcf_sol
, new_fcf_record
))
1615 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1617 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1619 if (phba
->valid_vlan
)
1620 *vlan_id
= phba
->vlan_id
;
1622 *vlan_id
= LPFC_FCOE_NULL_VID
;
1627 * If there are no FCF connection table entry, driver connect to all
1630 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1632 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1636 * When there are no FCF connect entries, use driver's default
1637 * addressing mode - FPMA.
1639 if (*addr_mode
& LPFC_FCF_FPMA
)
1640 *addr_mode
= LPFC_FCF_FPMA
;
1642 /* If FCF record report a vlan id use that vlan id */
1644 *vlan_id
= fcf_vlan_id
;
1646 *vlan_id
= LPFC_FCOE_NULL_VID
;
1650 list_for_each_entry(conn_entry
,
1651 &phba
->fcf_conn_rec_list
, list
) {
1652 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1655 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1656 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1659 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1660 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1663 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1665 * If the vlan bit map does not have the bit set for the
1666 * vlan id to be used, then it is not a match.
1668 if (!(new_fcf_record
->vlan_bitmap
1669 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1670 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1675 * If connection record does not support any addressing mode,
1676 * skip the FCF record.
1678 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1679 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1683 * Check if the connection record specifies a required
1686 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1687 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1690 * If SPMA required but FCF not support this continue.
1692 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1693 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1694 new_fcf_record
) & LPFC_FCF_SPMA
))
1698 * If FPMA required but FCF not support this continue.
1700 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1701 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1702 new_fcf_record
) & LPFC_FCF_FPMA
))
1707 * This fcf record matches filtering criteria.
1709 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1715 * If user did not specify any addressing mode, or if the
1716 * preferred addressing mode specified by user is not supported
1717 * by FCF, allow fabric to pick the addressing mode.
1719 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1722 * If the user specified a required address mode, assign that
1725 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1726 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1727 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1729 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1731 * If the user specified a preferred address mode, use the
1732 * addr mode only if FCF support the addr_mode.
1734 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1735 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1736 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1737 (*addr_mode
& LPFC_FCF_SPMA
))
1738 *addr_mode
= LPFC_FCF_SPMA
;
1739 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1740 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1741 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1742 (*addr_mode
& LPFC_FCF_FPMA
))
1743 *addr_mode
= LPFC_FCF_FPMA
;
1745 /* If matching connect list has a vlan id, use it */
1746 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1747 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1749 * If no vlan id is specified in connect list, use the vlan id
1752 else if (fcf_vlan_id
)
1753 *vlan_id
= fcf_vlan_id
;
1755 *vlan_id
= LPFC_FCOE_NULL_VID
;
1764 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1765 * @phba: pointer to lpfc hba data structure.
1766 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1768 * This function check if there is any fcoe event pending while driver
1769 * scan FCF entries. If there is any pending event, it will restart the
1770 * FCF saning and return 1 else return 0.
1773 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1776 * If the Link is up and no FCoE events while in the
1777 * FCF discovery, no need to restart FCF discovery.
1779 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1780 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1783 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1784 "2768 Pending link or FCF event during current "
1785 "handling of the previous event: link_state:x%x, "
1786 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1787 phba
->link_state
, phba
->fcoe_eventtag_at_fcf_scan
,
1788 phba
->fcoe_eventtag
);
1790 spin_lock_irq(&phba
->hbalock
);
1791 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1792 spin_unlock_irq(&phba
->hbalock
);
1794 if (phba
->link_state
>= LPFC_LINK_UP
) {
1795 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1796 "2780 Restart FCF table scan due to "
1797 "pending FCF event:evt_tag_at_scan:x%x, "
1798 "evt_tag_current:x%x\n",
1799 phba
->fcoe_eventtag_at_fcf_scan
,
1800 phba
->fcoe_eventtag
);
1801 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1804 * Do not continue FCF discovery and clear FCF_TS_INPROG
1807 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1808 "2833 Stop FCF discovery process due to link "
1809 "state change (x%x)\n", phba
->link_state
);
1810 spin_lock_irq(&phba
->hbalock
);
1811 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1812 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
| FCF_DISCOVERY
);
1813 spin_unlock_irq(&phba
->hbalock
);
1816 /* Unregister the currently registered FCF if required */
1818 spin_lock_irq(&phba
->hbalock
);
1819 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1820 spin_unlock_irq(&phba
->hbalock
);
1821 lpfc_sli4_unregister_fcf(phba
);
1827 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1828 * @phba: pointer to lpfc hba data structure.
1829 * @fcf_cnt: number of eligible fcf record seen so far.
1831 * This function makes an running random selection decision on FCF record to
1832 * use through a sequence of @fcf_cnt eligible FCF records with equal
1833 * probability. To perform integer manunipulation of random numbers with
1834 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1835 * from prandom_u32() are taken as the random random number generated.
1837 * Returns true when outcome is for the newly read FCF record should be
1838 * chosen; otherwise, return false when outcome is for keeping the previously
1839 * chosen FCF record.
1842 lpfc_sli4_new_fcf_random_select(struct lpfc_hba
*phba
, uint32_t fcf_cnt
)
1846 /* Get 16-bit uniform random number */
1847 rand_num
= 0xFFFF & prandom_u32();
1849 /* Decision with probability 1/fcf_cnt */
1850 if ((fcf_cnt
* rand_num
) < 0xFFFF)
1857 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1858 * @phba: pointer to lpfc hba data structure.
1859 * @mboxq: pointer to mailbox object.
1860 * @next_fcf_index: pointer to holder of next fcf index.
1862 * This routine parses the non-embedded fcf mailbox command by performing the
1863 * necessarily error checking, non-embedded read FCF record mailbox command
1864 * SGE parsing, and endianness swapping.
1866 * Returns the pointer to the new FCF record in the non-embedded mailbox
1867 * command DMA memory if successfully, other NULL.
1869 static struct fcf_record
*
1870 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
1871 uint16_t *next_fcf_index
)
1874 struct lpfc_mbx_sge sge
;
1875 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1876 uint32_t shdr_status
, shdr_add_status
, if_type
;
1877 union lpfc_sli4_cfg_shdr
*shdr
;
1878 struct fcf_record
*new_fcf_record
;
1880 /* Get the first SGE entry from the non-embedded DMA memory. This
1881 * routine only uses a single SGE.
1883 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1884 if (unlikely(!mboxq
->sge_array
)) {
1885 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1886 "2524 Failed to get the non-embedded SGE "
1887 "virtual address\n");
1890 virt_addr
= mboxq
->sge_array
->addr
[0];
1892 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1893 lpfc_sli_pcimem_bcopy(shdr
, shdr
,
1894 sizeof(union lpfc_sli4_cfg_shdr
));
1895 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1896 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1897 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
1898 if (shdr_status
|| shdr_add_status
) {
1899 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
||
1900 if_type
== LPFC_SLI_INTF_IF_TYPE_2
)
1901 lpfc_printf_log(phba
, KERN_ERR
,
1903 "2726 READ_FCF_RECORD Indicates empty "
1906 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
1907 "2521 READ_FCF_RECORD mailbox failed "
1908 "with status x%x add_status x%x, "
1909 "mbx\n", shdr_status
, shdr_add_status
);
1913 /* Interpreting the returned information of the FCF record */
1914 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1915 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1916 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1917 *next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1918 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1919 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1920 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1921 offsetof(struct fcf_record
, vlan_bitmap
));
1922 new_fcf_record
->word137
= le32_to_cpu(new_fcf_record
->word137
);
1923 new_fcf_record
->word138
= le32_to_cpu(new_fcf_record
->word138
);
1925 return new_fcf_record
;
1929 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1930 * @phba: pointer to lpfc hba data structure.
1931 * @fcf_record: pointer to the fcf record.
1932 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1933 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1935 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1939 lpfc_sli4_log_fcf_record_info(struct lpfc_hba
*phba
,
1940 struct fcf_record
*fcf_record
,
1942 uint16_t next_fcf_index
)
1944 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1945 "2764 READ_FCF_RECORD:\n"
1946 "\tFCF_Index : x%x\n"
1947 "\tFCF_Avail : x%x\n"
1948 "\tFCF_Valid : x%x\n"
1950 "\tFIP_Priority : x%x\n"
1951 "\tMAC_Provider : x%x\n"
1952 "\tLowest VLANID : x%x\n"
1953 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1954 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1955 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1956 "\tNext_FCF_Index: x%x\n",
1957 bf_get(lpfc_fcf_record_fcf_index
, fcf_record
),
1958 bf_get(lpfc_fcf_record_fcf_avail
, fcf_record
),
1959 bf_get(lpfc_fcf_record_fcf_valid
, fcf_record
),
1960 bf_get(lpfc_fcf_record_fcf_sol
, fcf_record
),
1961 fcf_record
->fip_priority
,
1962 bf_get(lpfc_fcf_record_mac_addr_prov
, fcf_record
),
1964 bf_get(lpfc_fcf_record_mac_0
, fcf_record
),
1965 bf_get(lpfc_fcf_record_mac_1
, fcf_record
),
1966 bf_get(lpfc_fcf_record_mac_2
, fcf_record
),
1967 bf_get(lpfc_fcf_record_mac_3
, fcf_record
),
1968 bf_get(lpfc_fcf_record_mac_4
, fcf_record
),
1969 bf_get(lpfc_fcf_record_mac_5
, fcf_record
),
1970 bf_get(lpfc_fcf_record_fab_name_0
, fcf_record
),
1971 bf_get(lpfc_fcf_record_fab_name_1
, fcf_record
),
1972 bf_get(lpfc_fcf_record_fab_name_2
, fcf_record
),
1973 bf_get(lpfc_fcf_record_fab_name_3
, fcf_record
),
1974 bf_get(lpfc_fcf_record_fab_name_4
, fcf_record
),
1975 bf_get(lpfc_fcf_record_fab_name_5
, fcf_record
),
1976 bf_get(lpfc_fcf_record_fab_name_6
, fcf_record
),
1977 bf_get(lpfc_fcf_record_fab_name_7
, fcf_record
),
1978 bf_get(lpfc_fcf_record_switch_name_0
, fcf_record
),
1979 bf_get(lpfc_fcf_record_switch_name_1
, fcf_record
),
1980 bf_get(lpfc_fcf_record_switch_name_2
, fcf_record
),
1981 bf_get(lpfc_fcf_record_switch_name_3
, fcf_record
),
1982 bf_get(lpfc_fcf_record_switch_name_4
, fcf_record
),
1983 bf_get(lpfc_fcf_record_switch_name_5
, fcf_record
),
1984 bf_get(lpfc_fcf_record_switch_name_6
, fcf_record
),
1985 bf_get(lpfc_fcf_record_switch_name_7
, fcf_record
),
1990 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1991 * @phba: pointer to lpfc hba data structure.
1992 * @fcf_rec: pointer to an existing FCF record.
1993 * @new_fcf_record: pointer to a new FCF record.
1994 * @new_vlan_id: vlan id from the new FCF record.
1996 * This function performs matching test of a new FCF record against an existing
1997 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1998 * will not be used as part of the FCF record matching criteria.
2000 * Returns true if all the fields matching, otherwise returns false.
2003 lpfc_sli4_fcf_record_match(struct lpfc_hba
*phba
,
2004 struct lpfc_fcf_rec
*fcf_rec
,
2005 struct fcf_record
*new_fcf_record
,
2006 uint16_t new_vlan_id
)
2008 if (new_vlan_id
!= LPFC_FCOE_IGNORE_VID
)
2009 if (!lpfc_vlan_id_match(fcf_rec
->vlan_id
, new_vlan_id
))
2011 if (!lpfc_mac_addr_match(fcf_rec
->mac_addr
, new_fcf_record
))
2013 if (!lpfc_sw_name_match(fcf_rec
->switch_name
, new_fcf_record
))
2015 if (!lpfc_fab_name_match(fcf_rec
->fabric_name
, new_fcf_record
))
2017 if (fcf_rec
->priority
!= new_fcf_record
->fip_priority
)
2023 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2024 * @vport: Pointer to vport object.
2025 * @fcf_index: index to next fcf.
2027 * This function processing the roundrobin fcf failover to next fcf index.
2028 * When this function is invoked, there will be a current fcf registered
2030 * Return: 0 for continue retrying flogi on currently registered fcf;
2031 * 1 for stop flogi on currently registered fcf;
2033 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport
*vport
, uint16_t fcf_index
)
2035 struct lpfc_hba
*phba
= vport
->phba
;
2038 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
2039 spin_lock_irq(&phba
->hbalock
);
2040 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2041 spin_unlock_irq(&phba
->hbalock
);
2042 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2043 "2872 Devloss tmo with no eligible "
2044 "FCF, unregister in-use FCF (x%x) "
2045 "and rescan FCF table\n",
2046 phba
->fcf
.current_rec
.fcf_indx
);
2047 lpfc_unregister_fcf_rescan(phba
);
2048 goto stop_flogi_current_fcf
;
2050 /* Mark the end to FLOGI roundrobin failover */
2051 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2052 /* Allow action to new fcf asynchronous event */
2053 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
2054 spin_unlock_irq(&phba
->hbalock
);
2055 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2056 "2865 No FCF available, stop roundrobin FCF "
2057 "failover and change port state:x%x/x%x\n",
2058 phba
->pport
->port_state
, LPFC_VPORT_UNKNOWN
);
2059 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2061 if (!phba
->fcf
.fcf_redisc_attempted
) {
2062 lpfc_unregister_fcf(phba
);
2064 rc
= lpfc_sli4_redisc_fcf_table(phba
);
2066 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2067 "3195 Rediscover FCF table\n");
2068 phba
->fcf
.fcf_redisc_attempted
= 1;
2069 lpfc_sli4_clear_fcf_rr_bmask(phba
);
2071 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2072 "3196 Rediscover FCF table "
2073 "failed. Status:x%x\n", rc
);
2076 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2077 "3197 Already rediscover FCF table "
2078 "attempted. No more retry\n");
2080 goto stop_flogi_current_fcf
;
2082 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_ELS
,
2083 "2794 Try FLOGI roundrobin FCF failover to "
2084 "(x%x)\n", fcf_index
);
2085 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
, fcf_index
);
2087 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
2088 "2761 FLOGI roundrobin FCF failover "
2089 "failed (rc:x%x) to read FCF (x%x)\n",
2090 rc
, phba
->fcf
.current_rec
.fcf_indx
);
2092 goto stop_flogi_current_fcf
;
2096 stop_flogi_current_fcf
:
2097 lpfc_can_disctmo(vport
);
2102 * lpfc_sli4_fcf_pri_list_del
2103 * @phba: pointer to lpfc hba data structure.
2104 * @fcf_index: the index of the fcf record to delete
2105 * This routine checks the on list flag of the fcf_index to be deleted.
2106 * If it is one the list then it is removed from the list, and the flag
2107 * is cleared. This routine grab the hbalock before removing the fcf
2108 * record from the list.
2110 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba
*phba
,
2113 struct lpfc_fcf_pri
*new_fcf_pri
;
2115 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2116 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2117 "3058 deleting idx x%x pri x%x flg x%x\n",
2118 fcf_index
, new_fcf_pri
->fcf_rec
.priority
,
2119 new_fcf_pri
->fcf_rec
.flag
);
2120 spin_lock_irq(&phba
->hbalock
);
2121 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
) {
2122 if (phba
->fcf
.current_rec
.priority
==
2123 new_fcf_pri
->fcf_rec
.priority
)
2124 phba
->fcf
.eligible_fcf_cnt
--;
2125 list_del_init(&new_fcf_pri
->list
);
2126 new_fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_ON_PRI_LIST
;
2128 spin_unlock_irq(&phba
->hbalock
);
2132 * lpfc_sli4_set_fcf_flogi_fail
2133 * @phba: pointer to lpfc hba data structure.
2134 * @fcf_index: the index of the fcf record to update
2135 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2136 * flag so the the round robin slection for the particular priority level
2137 * will try a different fcf record that does not have this bit set.
2138 * If the fcf record is re-read for any reason this flag is cleared brfore
2139 * adding it to the priority list.
2142 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba
*phba
, uint16_t fcf_index
)
2144 struct lpfc_fcf_pri
*new_fcf_pri
;
2145 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2146 spin_lock_irq(&phba
->hbalock
);
2147 new_fcf_pri
->fcf_rec
.flag
|= LPFC_FCF_FLOGI_FAILED
;
2148 spin_unlock_irq(&phba
->hbalock
);
2152 * lpfc_sli4_fcf_pri_list_add
2153 * @phba: pointer to lpfc hba data structure.
2154 * @fcf_index: the index of the fcf record to add
2155 * @new_fcf_record: pointer to a new FCF record.
2156 * This routine checks the priority of the fcf_index to be added.
2157 * If it is a lower priority than the current head of the fcf_pri list
2158 * then it is added to the list in the right order.
2159 * If it is the same priority as the current head of the list then it
2160 * is added to the head of the list and its bit in the rr_bmask is set.
2161 * If the fcf_index to be added is of a higher priority than the current
2162 * head of the list then the rr_bmask is cleared, its bit is set in the
2163 * rr_bmask and it is added to the head of the list.
2165 * 0=success 1=failure
2167 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba
*phba
,
2169 struct fcf_record
*new_fcf_record
)
2171 uint16_t current_fcf_pri
;
2172 uint16_t last_index
;
2173 struct lpfc_fcf_pri
*fcf_pri
;
2174 struct lpfc_fcf_pri
*next_fcf_pri
;
2175 struct lpfc_fcf_pri
*new_fcf_pri
;
2178 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2179 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2180 "3059 adding idx x%x pri x%x flg x%x\n",
2181 fcf_index
, new_fcf_record
->fip_priority
,
2182 new_fcf_pri
->fcf_rec
.flag
);
2183 spin_lock_irq(&phba
->hbalock
);
2184 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
)
2185 list_del_init(&new_fcf_pri
->list
);
2186 new_fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
2187 new_fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
2188 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
2189 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2190 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2191 new_fcf_pri
->fcf_rec
.fcf_index
);
2195 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
2196 LPFC_SLI4_FCF_TBL_INDX_MAX
);
2197 if (last_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
2198 ret
= 0; /* Empty rr list */
2201 current_fcf_pri
= phba
->fcf
.fcf_pri
[last_index
].fcf_rec
.priority
;
2202 if (new_fcf_pri
->fcf_rec
.priority
<= current_fcf_pri
) {
2203 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2204 if (new_fcf_pri
->fcf_rec
.priority
< current_fcf_pri
) {
2205 memset(phba
->fcf
.fcf_rr_bmask
, 0,
2206 sizeof(*phba
->fcf
.fcf_rr_bmask
));
2207 /* fcfs_at_this_priority_level = 1; */
2208 phba
->fcf
.eligible_fcf_cnt
= 1;
2210 /* fcfs_at_this_priority_level++; */
2211 phba
->fcf
.eligible_fcf_cnt
++;
2212 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2213 new_fcf_pri
->fcf_rec
.fcf_index
);
2217 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
2218 &phba
->fcf
.fcf_pri_list
, list
) {
2219 if (new_fcf_pri
->fcf_rec
.priority
<=
2220 fcf_pri
->fcf_rec
.priority
) {
2221 if (fcf_pri
->list
.prev
== &phba
->fcf
.fcf_pri_list
)
2222 list_add(&new_fcf_pri
->list
,
2223 &phba
->fcf
.fcf_pri_list
);
2225 list_add(&new_fcf_pri
->list
,
2226 &((struct lpfc_fcf_pri
*)
2227 fcf_pri
->list
.prev
)->list
);
2230 } else if (fcf_pri
->list
.next
== &phba
->fcf
.fcf_pri_list
2231 || new_fcf_pri
->fcf_rec
.priority
<
2232 next_fcf_pri
->fcf_rec
.priority
) {
2233 list_add(&new_fcf_pri
->list
, &fcf_pri
->list
);
2237 if (new_fcf_pri
->fcf_rec
.priority
> fcf_pri
->fcf_rec
.priority
)
2243 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2244 new_fcf_pri
->fcf_rec
.flag
= LPFC_FCF_ON_PRI_LIST
;
2245 spin_unlock_irq(&phba
->hbalock
);
2250 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2251 * @phba: pointer to lpfc hba data structure.
2252 * @mboxq: pointer to mailbox object.
2254 * This function iterates through all the fcf records available in
2255 * HBA and chooses the optimal FCF record for discovery. After finding
2256 * the FCF for discovery it registers the FCF record and kicks start
2258 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2259 * use an FCF record which matches fabric name and mac address of the
2260 * currently used FCF record.
2261 * If the driver supports only one FCF, it will try to use the FCF record
2262 * used by BOOT_BIOS.
2265 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2267 struct fcf_record
*new_fcf_record
;
2268 uint32_t boot_flag
, addr_mode
;
2269 uint16_t fcf_index
, next_fcf_index
;
2270 struct lpfc_fcf_rec
*fcf_rec
= NULL
;
2271 uint16_t vlan_id
= LPFC_FCOE_NULL_VID
;
2272 bool select_new_fcf
;
2275 /* If there is pending FCoE event restart FCF table scan */
2276 if (lpfc_check_pending_fcoe_event(phba
, LPFC_SKIP_UNREG_FCF
)) {
2277 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2281 /* Parse the FCF record from the non-embedded mailbox command */
2282 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2284 if (!new_fcf_record
) {
2285 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2286 "2765 Mailbox command READ_FCF_RECORD "
2287 "failed to retrieve a FCF record.\n");
2288 /* Let next new FCF event trigger fast failover */
2289 spin_lock_irq(&phba
->hbalock
);
2290 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2291 spin_unlock_irq(&phba
->hbalock
);
2292 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2296 /* Check the FCF record against the connection list */
2297 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2298 &addr_mode
, &vlan_id
);
2300 /* Log the FCF record information if turned on */
2301 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2305 * If the fcf record does not match with connect list entries
2306 * read the next entry; otherwise, this is an eligible FCF
2307 * record for roundrobin FCF failover.
2310 lpfc_sli4_fcf_pri_list_del(phba
,
2311 bf_get(lpfc_fcf_record_fcf_index
,
2313 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2314 "2781 FCF (x%x) failed connection "
2315 "list check: (x%x/x%x/%x)\n",
2316 bf_get(lpfc_fcf_record_fcf_index
,
2318 bf_get(lpfc_fcf_record_fcf_avail
,
2320 bf_get(lpfc_fcf_record_fcf_valid
,
2322 bf_get(lpfc_fcf_record_fcf_sol
,
2324 if ((phba
->fcf
.fcf_flag
& FCF_IN_USE
) &&
2325 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2326 new_fcf_record
, LPFC_FCOE_IGNORE_VID
)) {
2327 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) !=
2328 phba
->fcf
.current_rec
.fcf_indx
) {
2329 lpfc_printf_log(phba
, KERN_ERR
,
2331 "2862 FCF (x%x) matches property "
2332 "of in-use FCF (x%x)\n",
2333 bf_get(lpfc_fcf_record_fcf_index
,
2335 phba
->fcf
.current_rec
.fcf_indx
);
2339 * In case the current in-use FCF record becomes
2340 * invalid/unavailable during FCF discovery that
2341 * was not triggered by fast FCF failover process,
2342 * treat it as fast FCF failover.
2344 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
) &&
2345 !(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2346 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2347 "2835 Invalid in-use FCF "
2348 "(x%x), enter FCF failover "
2350 phba
->fcf
.current_rec
.fcf_indx
);
2351 spin_lock_irq(&phba
->hbalock
);
2352 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2353 spin_unlock_irq(&phba
->hbalock
);
2354 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2355 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2356 LPFC_FCOE_FCF_GET_FIRST
);
2362 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2363 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
,
2370 * If this is not the first FCF discovery of the HBA, use last
2371 * FCF record for the discovery. The condition that a rescan
2372 * matches the in-use FCF record: fabric name, switch name, mac
2373 * address, and vlan_id.
2375 spin_lock_irq(&phba
->hbalock
);
2376 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2377 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2378 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2379 new_fcf_record
, vlan_id
)) {
2380 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) ==
2381 phba
->fcf
.current_rec
.fcf_indx
) {
2382 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2383 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)
2384 /* Stop FCF redisc wait timer */
2385 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2387 else if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2388 /* Fast failover, mark completed */
2389 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2390 spin_unlock_irq(&phba
->hbalock
);
2391 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2392 "2836 New FCF matches in-use "
2393 "FCF (x%x), port_state:x%x, "
2395 phba
->fcf
.current_rec
.fcf_indx
,
2396 phba
->pport
->port_state
,
2397 phba
->pport
->fc_flag
);
2400 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
2401 "2863 New FCF (x%x) matches "
2402 "property of in-use FCF (x%x)\n",
2403 bf_get(lpfc_fcf_record_fcf_index
,
2405 phba
->fcf
.current_rec
.fcf_indx
);
2408 * Read next FCF record from HBA searching for the matching
2409 * with in-use record only if not during the fast failover
2410 * period. In case of fast failover period, it shall try to
2411 * determine whether the FCF record just read should be the
2414 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2415 spin_unlock_irq(&phba
->hbalock
);
2420 * Update on failover FCF record only if it's in FCF fast-failover
2421 * period; otherwise, update on current FCF record.
2423 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2424 fcf_rec
= &phba
->fcf
.failover_rec
;
2426 fcf_rec
= &phba
->fcf
.current_rec
;
2428 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
2430 * If the driver FCF record does not have boot flag
2431 * set and new hba fcf record has boot flag set, use
2432 * the new hba fcf record.
2434 if (boot_flag
&& !(fcf_rec
->flag
& BOOT_ENABLE
)) {
2435 /* Choose this FCF record */
2436 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2437 "2837 Update current FCF record "
2438 "(x%x) with new FCF record (x%x)\n",
2440 bf_get(lpfc_fcf_record_fcf_index
,
2442 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2443 addr_mode
, vlan_id
, BOOT_ENABLE
);
2444 spin_unlock_irq(&phba
->hbalock
);
2448 * If the driver FCF record has boot flag set and the
2449 * new hba FCF record does not have boot flag, read
2450 * the next FCF record.
2452 if (!boot_flag
&& (fcf_rec
->flag
& BOOT_ENABLE
)) {
2453 spin_unlock_irq(&phba
->hbalock
);
2457 * If the new hba FCF record has lower priority value
2458 * than the driver FCF record, use the new record.
2460 if (new_fcf_record
->fip_priority
< fcf_rec
->priority
) {
2461 /* Choose the new FCF record with lower priority */
2462 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2463 "2838 Update current FCF record "
2464 "(x%x) with new FCF record (x%x)\n",
2466 bf_get(lpfc_fcf_record_fcf_index
,
2468 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2469 addr_mode
, vlan_id
, 0);
2470 /* Reset running random FCF selection count */
2471 phba
->fcf
.eligible_fcf_cnt
= 1;
2472 } else if (new_fcf_record
->fip_priority
== fcf_rec
->priority
) {
2473 /* Update running random FCF selection count */
2474 phba
->fcf
.eligible_fcf_cnt
++;
2475 select_new_fcf
= lpfc_sli4_new_fcf_random_select(phba
,
2476 phba
->fcf
.eligible_fcf_cnt
);
2477 if (select_new_fcf
) {
2478 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2479 "2839 Update current FCF record "
2480 "(x%x) with new FCF record (x%x)\n",
2482 bf_get(lpfc_fcf_record_fcf_index
,
2484 /* Choose the new FCF by random selection */
2485 __lpfc_update_fcf_record(phba
, fcf_rec
,
2487 addr_mode
, vlan_id
, 0);
2490 spin_unlock_irq(&phba
->hbalock
);
2494 * This is the first suitable FCF record, choose this record for
2495 * initial best-fit FCF.
2498 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2499 "2840 Update initial FCF candidate "
2501 bf_get(lpfc_fcf_record_fcf_index
,
2503 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2504 addr_mode
, vlan_id
, (boot_flag
?
2506 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2507 /* Setup initial running random FCF selection count */
2508 phba
->fcf
.eligible_fcf_cnt
= 1;
2510 spin_unlock_irq(&phba
->hbalock
);
2514 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2515 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0) {
2516 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
) {
2518 * Case of FCF fast failover scan
2522 * It has not found any suitable FCF record, cancel
2523 * FCF scan inprogress, and do nothing
2525 if (!(phba
->fcf
.failover_rec
.flag
& RECORD_VALID
)) {
2526 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2527 "2782 No suitable FCF found: "
2529 phba
->fcoe_eventtag_at_fcf_scan
,
2530 bf_get(lpfc_fcf_record_fcf_index
,
2532 spin_lock_irq(&phba
->hbalock
);
2533 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2534 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2535 spin_unlock_irq(&phba
->hbalock
);
2536 /* Unregister in-use FCF and rescan */
2537 lpfc_printf_log(phba
, KERN_INFO
,
2539 "2864 On devloss tmo "
2540 "unreg in-use FCF and "
2541 "rescan FCF table\n");
2542 lpfc_unregister_fcf_rescan(phba
);
2546 * Let next new FCF event trigger fast failover
2548 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2549 spin_unlock_irq(&phba
->hbalock
);
2553 * It has found a suitable FCF record that is not
2554 * the same as in-use FCF record, unregister the
2555 * in-use FCF record, replace the in-use FCF record
2556 * with the new FCF record, mark FCF fast failover
2557 * completed, and then start register the new FCF
2561 /* Unregister the current in-use FCF record */
2562 lpfc_unregister_fcf(phba
);
2564 /* Replace in-use record with the new record */
2565 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2566 "2842 Replace in-use FCF (x%x) "
2567 "with failover FCF (x%x)\n",
2568 phba
->fcf
.current_rec
.fcf_indx
,
2569 phba
->fcf
.failover_rec
.fcf_indx
);
2570 memcpy(&phba
->fcf
.current_rec
,
2571 &phba
->fcf
.failover_rec
,
2572 sizeof(struct lpfc_fcf_rec
));
2574 * Mark the fast FCF failover rediscovery completed
2575 * and the start of the first round of the roundrobin
2578 spin_lock_irq(&phba
->hbalock
);
2579 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2580 spin_unlock_irq(&phba
->hbalock
);
2581 /* Register to the new FCF record */
2582 lpfc_register_fcf(phba
);
2585 * In case of transaction period to fast FCF failover,
2586 * do nothing when search to the end of the FCF table.
2588 if ((phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) ||
2589 (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
))
2592 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2593 phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2595 * In case the current in-use FCF record no
2596 * longer existed during FCF discovery that
2597 * was not triggered by fast FCF failover
2598 * process, treat it as fast FCF failover.
2600 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2601 "2841 In-use FCF record (x%x) "
2602 "not reported, entering fast "
2603 "FCF failover mode scanning.\n",
2604 phba
->fcf
.current_rec
.fcf_indx
);
2605 spin_lock_irq(&phba
->hbalock
);
2606 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2607 spin_unlock_irq(&phba
->hbalock
);
2608 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2609 LPFC_FCOE_FCF_GET_FIRST
);
2612 /* Register to the new FCF record */
2613 lpfc_register_fcf(phba
);
2616 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, next_fcf_index
);
2620 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2621 lpfc_register_fcf(phba
);
2627 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2628 * @phba: pointer to lpfc hba data structure.
2629 * @mboxq: pointer to mailbox object.
2631 * This is the callback function for FLOGI failure roundrobin FCF failover
2632 * read FCF record mailbox command from the eligible FCF record bmask for
2633 * performing the failover. If the FCF read back is not valid/available, it
2634 * fails through to retrying FLOGI to the currently registered FCF again.
2635 * Otherwise, if the FCF read back is valid and available, it will set the
2636 * newly read FCF record to the failover FCF record, unregister currently
2637 * registered FCF record, copy the failover FCF record to the current
2638 * FCF record, and then register the current FCF record before proceeding
2639 * to trying FLOGI on the new failover FCF.
2642 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2644 struct fcf_record
*new_fcf_record
;
2645 uint32_t boot_flag
, addr_mode
;
2646 uint16_t next_fcf_index
, fcf_index
;
2647 uint16_t current_fcf_index
;
2651 /* If link state is not up, stop the roundrobin failover process */
2652 if (phba
->link_state
< LPFC_LINK_UP
) {
2653 spin_lock_irq(&phba
->hbalock
);
2654 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
2655 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2656 spin_unlock_irq(&phba
->hbalock
);
2660 /* Parse the FCF record from the non-embedded mailbox command */
2661 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2663 if (!new_fcf_record
) {
2664 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2665 "2766 Mailbox command READ_FCF_RECORD "
2666 "failed to retrieve a FCF record. "
2667 "hba_flg x%x fcf_flg x%x\n", phba
->hba_flag
,
2668 phba
->fcf
.fcf_flag
);
2669 lpfc_unregister_fcf_rescan(phba
);
2673 /* Get the needed parameters from FCF record */
2674 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2675 &addr_mode
, &vlan_id
);
2677 /* Log the FCF record information if turned on */
2678 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2681 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2683 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2684 "2848 Remove ineligible FCF (x%x) from "
2685 "from roundrobin bmask\n", fcf_index
);
2686 /* Clear roundrobin bmask bit for ineligible FCF */
2687 lpfc_sli4_fcf_rr_index_clear(phba
, fcf_index
);
2688 /* Perform next round of roundrobin FCF failover */
2689 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
2690 rc
= lpfc_sli4_fcf_rr_next_proc(phba
->pport
, fcf_index
);
2696 if (fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
2697 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2698 "2760 Perform FLOGI roundrobin FCF failover: "
2699 "FCF (x%x) back to FCF (x%x)\n",
2700 phba
->fcf
.current_rec
.fcf_indx
, fcf_index
);
2701 /* Wait 500 ms before retrying FLOGI to current FCF */
2703 lpfc_issue_init_vfi(phba
->pport
);
2707 /* Upload new FCF record to the failover FCF record */
2708 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2709 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2710 phba
->fcf
.failover_rec
.fcf_indx
, fcf_index
);
2711 spin_lock_irq(&phba
->hbalock
);
2712 __lpfc_update_fcf_record(phba
, &phba
->fcf
.failover_rec
,
2713 new_fcf_record
, addr_mode
, vlan_id
,
2714 (boot_flag
? BOOT_ENABLE
: 0));
2715 spin_unlock_irq(&phba
->hbalock
);
2717 current_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
2719 /* Unregister the current in-use FCF record */
2720 lpfc_unregister_fcf(phba
);
2722 /* Replace in-use record with the new record */
2723 memcpy(&phba
->fcf
.current_rec
, &phba
->fcf
.failover_rec
,
2724 sizeof(struct lpfc_fcf_rec
));
2726 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2727 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2728 "(x%x) to FCF (x%x)\n", current_fcf_index
, fcf_index
);
2731 lpfc_register_fcf(phba
);
2733 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2737 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2738 * @phba: pointer to lpfc hba data structure.
2739 * @mboxq: pointer to mailbox object.
2741 * This is the callback function of read FCF record mailbox command for
2742 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2743 * failover when a new FCF event happened. If the FCF read back is
2744 * valid/available and it passes the connection list check, it updates
2745 * the bmask for the eligible FCF record for roundrobin failover.
2748 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2750 struct fcf_record
*new_fcf_record
;
2751 uint32_t boot_flag
, addr_mode
;
2752 uint16_t fcf_index
, next_fcf_index
;
2756 /* If link state is not up, no need to proceed */
2757 if (phba
->link_state
< LPFC_LINK_UP
)
2760 /* If FCF discovery period is over, no need to proceed */
2761 if (!(phba
->fcf
.fcf_flag
& FCF_DISCOVERY
))
2764 /* Parse the FCF record from the non-embedded mailbox command */
2765 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2767 if (!new_fcf_record
) {
2768 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2769 "2767 Mailbox command READ_FCF_RECORD "
2770 "failed to retrieve a FCF record.\n");
2774 /* Check the connection list for eligibility */
2775 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2776 &addr_mode
, &vlan_id
);
2778 /* Log the FCF record information if turned on */
2779 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2785 /* Update the eligible FCF record index bmask */
2786 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2788 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
, new_fcf_record
);
2791 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2795 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2796 * @phba: pointer to lpfc hba data structure.
2797 * @mboxq: pointer to mailbox data structure.
2799 * This function handles completion of init vfi mailbox command.
2802 lpfc_init_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2804 struct lpfc_vport
*vport
= mboxq
->vport
;
2807 * VFI not supported on interface type 0, just do the flogi
2808 * Also continue if the VFI is in use - just use the same one.
2810 if (mboxq
->u
.mb
.mbxStatus
&&
2811 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2812 LPFC_SLI_INTF_IF_TYPE_0
) &&
2813 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
2814 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2815 "2891 Init VFI mailbox failed 0x%x\n",
2816 mboxq
->u
.mb
.mbxStatus
);
2817 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2818 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2822 lpfc_initial_flogi(vport
);
2823 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2828 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2829 * @vport: pointer to lpfc_vport data structure.
2831 * This function issue a init_vfi mailbox command to initialize the VFI and
2832 * VPI for the physical port.
2835 lpfc_issue_init_vfi(struct lpfc_vport
*vport
)
2837 LPFC_MBOXQ_t
*mboxq
;
2839 struct lpfc_hba
*phba
= vport
->phba
;
2841 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2843 lpfc_printf_vlog(vport
, KERN_ERR
,
2844 LOG_TRACE_EVENT
, "2892 Failed to allocate "
2845 "init_vfi mailbox\n");
2848 lpfc_init_vfi(mboxq
, vport
);
2849 mboxq
->mbox_cmpl
= lpfc_init_vfi_cmpl
;
2850 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
2851 if (rc
== MBX_NOT_FINISHED
) {
2852 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2853 "2893 Failed to issue init_vfi mailbox\n");
2854 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2859 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2860 * @phba: pointer to lpfc hba data structure.
2861 * @mboxq: pointer to mailbox data structure.
2863 * This function handles completion of init vpi mailbox command.
2866 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2868 struct lpfc_vport
*vport
= mboxq
->vport
;
2869 struct lpfc_nodelist
*ndlp
;
2870 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2872 if (mboxq
->u
.mb
.mbxStatus
) {
2873 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2874 "2609 Init VPI mailbox failed 0x%x\n",
2875 mboxq
->u
.mb
.mbxStatus
);
2876 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2877 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2880 spin_lock_irq(shost
->host_lock
);
2881 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2882 spin_unlock_irq(shost
->host_lock
);
2884 /* If this port is physical port or FDISC is done, do reg_vpi */
2885 if ((phba
->pport
== vport
) || (vport
->port_state
== LPFC_FDISC
)) {
2886 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
2888 lpfc_printf_vlog(vport
, KERN_ERR
,
2890 "2731 Cannot find fabric "
2891 "controller node\n");
2893 lpfc_register_new_vport(phba
, vport
, ndlp
);
2894 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2898 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2899 lpfc_initial_fdisc(vport
);
2901 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
2902 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2903 "2606 No NPIV Fabric support\n");
2905 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2910 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2911 * @vport: pointer to lpfc_vport data structure.
2913 * This function issue a init_vpi mailbox command to initialize
2914 * VPI for the vport.
2917 lpfc_issue_init_vpi(struct lpfc_vport
*vport
)
2919 LPFC_MBOXQ_t
*mboxq
;
2922 if ((vport
->port_type
!= LPFC_PHYSICAL_PORT
) && (!vport
->vpi
)) {
2923 vpi
= lpfc_alloc_vpi(vport
->phba
);
2925 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2926 "3303 Failed to obtain vport vpi\n");
2927 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2933 mboxq
= mempool_alloc(vport
->phba
->mbox_mem_pool
, GFP_KERNEL
);
2935 lpfc_printf_vlog(vport
, KERN_ERR
,
2936 LOG_TRACE_EVENT
, "2607 Failed to allocate "
2937 "init_vpi mailbox\n");
2940 lpfc_init_vpi(vport
->phba
, mboxq
, vport
->vpi
);
2941 mboxq
->vport
= vport
;
2942 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
2943 rc
= lpfc_sli_issue_mbox(vport
->phba
, mboxq
, MBX_NOWAIT
);
2944 if (rc
== MBX_NOT_FINISHED
) {
2945 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2946 "2608 Failed to issue init_vpi mailbox\n");
2947 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2952 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2953 * @phba: pointer to lpfc hba data structure.
2955 * This function loops through the list of vports on the @phba and issues an
2956 * FDISC if possible.
2959 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
2961 struct lpfc_vport
**vports
;
2964 vports
= lpfc_create_vport_work_array(phba
);
2965 if (vports
!= NULL
) {
2966 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2967 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
2969 /* There are no vpi for this vport */
2970 if (vports
[i
]->vpi
> phba
->max_vpi
) {
2971 lpfc_vport_set_state(vports
[i
],
2975 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2976 lpfc_vport_set_state(vports
[i
],
2980 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
2981 lpfc_issue_init_vpi(vports
[i
]);
2984 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2985 lpfc_initial_fdisc(vports
[i
]);
2987 lpfc_vport_set_state(vports
[i
],
2988 FC_VPORT_NO_FABRIC_SUPP
);
2989 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
2992 "Fabric support\n");
2996 lpfc_destroy_vport_work_array(phba
, vports
);
3000 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
3002 struct lpfc_dmabuf
*dmabuf
= mboxq
->ctx_buf
;
3003 struct lpfc_vport
*vport
= mboxq
->vport
;
3004 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3007 * VFI not supported for interface type 0, so ignore any mailbox
3008 * error (except VFI in use) and continue with the discovery.
3010 if (mboxq
->u
.mb
.mbxStatus
&&
3011 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3012 LPFC_SLI_INTF_IF_TYPE_0
) &&
3013 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
3014 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3015 "2018 REG_VFI mbxStatus error x%x "
3017 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
3018 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3019 /* FLOGI failed, use loop map to make discovery list */
3020 lpfc_disc_list_loopmap(vport
);
3021 /* Start discovery */
3022 lpfc_disc_start(vport
);
3025 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3029 /* If the VFI is already registered, there is nothing else to do
3030 * Unless this was a VFI update and we are in PT2PT mode, then
3031 * we should drop through to set the port state to ready.
3033 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
3034 if (!(phba
->sli_rev
== LPFC_SLI_REV4
&&
3035 vport
->fc_flag
& FC_PT2PT
))
3038 /* The VPI is implicitly registered when the VFI is registered */
3039 spin_lock_irq(shost
->host_lock
);
3040 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3041 vport
->fc_flag
|= FC_VFI_REGISTERED
;
3042 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3043 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
3044 spin_unlock_irq(shost
->host_lock
);
3046 /* In case SLI4 FC loopback test, we are ready */
3047 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
3048 (phba
->link_flag
& LS_LOOPBACK_MODE
)) {
3049 phba
->link_state
= LPFC_HBA_READY
;
3053 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3054 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3055 "alpacnt:%d LinkState:%x topology:%x\n",
3056 vport
->port_state
, vport
->fc_flag
, vport
->fc_myDID
,
3057 vport
->phba
->alpa_map
[0],
3058 phba
->link_state
, phba
->fc_topology
);
3060 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3062 * For private loop or for NPort pt2pt,
3063 * just start discovery and we are done.
3065 if ((vport
->fc_flag
& FC_PT2PT
) ||
3066 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
3067 !(vport
->fc_flag
& FC_PUBLIC_LOOP
))) {
3069 /* Use loop map to make discovery list */
3070 lpfc_disc_list_loopmap(vport
);
3071 /* Start discovery */
3072 if (vport
->fc_flag
& FC_PT2PT
)
3073 vport
->port_state
= LPFC_VPORT_READY
;
3075 lpfc_disc_start(vport
);
3077 lpfc_start_fdiscs(phba
);
3078 lpfc_do_scr_ns_plogi(phba
, vport
);
3083 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3085 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
3092 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3094 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3095 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3096 struct lpfc_vport
*vport
= pmb
->vport
;
3097 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3098 struct serv_parm
*sp
= &vport
->fc_sparam
;
3101 /* Check for error */
3102 if (mb
->mbxStatus
) {
3103 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3104 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3105 "0319 READ_SPARAM mbxStatus error x%x "
3107 mb
->mbxStatus
, vport
->port_state
);
3108 lpfc_linkdown(phba
);
3112 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
3113 sizeof (struct serv_parm
));
3115 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
3116 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
3117 ed_tov
= (ed_tov
+ 999999) / 1000000;
3119 phba
->fc_edtov
= ed_tov
;
3120 phba
->fc_ratov
= (2 * ed_tov
) / 1000;
3121 if (phba
->fc_ratov
< FF_DEF_RATOV
) {
3122 /* RA_TOV should be atleast 10sec for initial flogi */
3123 phba
->fc_ratov
= FF_DEF_RATOV
;
3126 lpfc_update_vport_wwn(vport
);
3127 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3128 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
3129 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
3130 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
3133 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3135 mempool_free(pmb
, phba
->mbox_mem_pool
);
3137 /* Check if sending the FLOGI is being deferred to after we get
3138 * up to date CSPs from MBX_READ_SPARAM.
3140 if (phba
->hba_flag
& HBA_DEFER_FLOGI
) {
3141 lpfc_initial_flogi(vport
);
3142 phba
->hba_flag
&= ~HBA_DEFER_FLOGI
;
3147 pmb
->ctx_buf
= NULL
;
3148 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3150 lpfc_issue_clear_la(phba
, vport
);
3151 mempool_free(pmb
, phba
->mbox_mem_pool
);
3156 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, struct lpfc_mbx_read_top
*la
)
3158 struct lpfc_vport
*vport
= phba
->pport
;
3159 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
3160 struct Scsi_Host
*shost
;
3162 struct lpfc_dmabuf
*mp
;
3164 struct fcf_record
*fcf_record
;
3165 uint32_t fc_flags
= 0;
3166 unsigned long iflags
;
3168 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3169 phba
->fc_linkspeed
= bf_get(lpfc_mbx_read_top_link_spd
, la
);
3171 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3172 switch (bf_get(lpfc_mbx_read_top_link_spd
, la
)) {
3173 case LPFC_LINK_SPEED_1GHZ
:
3174 case LPFC_LINK_SPEED_2GHZ
:
3175 case LPFC_LINK_SPEED_4GHZ
:
3176 case LPFC_LINK_SPEED_8GHZ
:
3177 case LPFC_LINK_SPEED_10GHZ
:
3178 case LPFC_LINK_SPEED_16GHZ
:
3179 case LPFC_LINK_SPEED_32GHZ
:
3180 case LPFC_LINK_SPEED_64GHZ
:
3181 case LPFC_LINK_SPEED_128GHZ
:
3184 phba
->fc_linkspeed
= LPFC_LINK_SPEED_UNKNOWN
;
3189 if (phba
->fc_topology
&&
3190 phba
->fc_topology
!= bf_get(lpfc_mbx_read_top_topology
, la
)) {
3191 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3192 "3314 Toplogy changed was 0x%x is 0x%x\n",
3194 bf_get(lpfc_mbx_read_top_topology
, la
));
3195 phba
->fc_topology_changed
= 1;
3198 phba
->fc_topology
= bf_get(lpfc_mbx_read_top_topology
, la
);
3199 phba
->link_flag
&= ~(LS_NPIV_FAB_SUPPORTED
| LS_CT_VEN_RPA
);
3201 shost
= lpfc_shost_from_vport(vport
);
3202 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3203 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
3205 /* if npiv is enabled and this adapter supports npiv log
3206 * a message that npiv is not supported in this topology
3208 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
3209 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3210 "1309 Link Up Event npiv not supported in loop "
3212 /* Get Loop Map information */
3213 if (bf_get(lpfc_mbx_read_top_il
, la
))
3214 fc_flags
|= FC_LBIT
;
3216 vport
->fc_myDID
= bf_get(lpfc_mbx_read_top_alpa_granted
, la
);
3217 i
= la
->lilpBde64
.tus
.f
.bdeSize
;
3220 phba
->alpa_map
[0] = 0;
3222 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
3233 numalpa
= phba
->alpa_map
[0];
3235 while (j
< numalpa
) {
3236 memset(un
.pamap
, 0, 16);
3237 for (k
= 1; j
< numalpa
; k
++) {
3239 phba
->alpa_map
[j
+ 1];
3244 /* Link Up Event ALPA map */
3245 lpfc_printf_log(phba
,
3248 "1304 Link Up Event "
3249 "ALPA map Data: x%x "
3251 un
.pa
.wd1
, un
.pa
.wd2
,
3252 un
.pa
.wd3
, un
.pa
.wd4
);
3257 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
3258 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
3259 (phba
->sli_rev
>= LPFC_SLI_REV3
))
3260 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3262 vport
->fc_myDID
= phba
->fc_pref_DID
;
3263 fc_flags
|= FC_LBIT
;
3265 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3268 spin_lock_irqsave(shost
->host_lock
, iflags
);
3269 vport
->fc_flag
|= fc_flags
;
3270 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3276 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3280 rc
= lpfc_read_sparam(phba
, sparam_mbox
, 0);
3282 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3285 sparam_mbox
->vport
= vport
;
3286 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
3287 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
3288 if (rc
== MBX_NOT_FINISHED
) {
3289 mp
= (struct lpfc_dmabuf
*)sparam_mbox
->ctx_buf
;
3290 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3292 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3296 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3297 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3300 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
3301 lpfc_config_link(phba
, cfglink_mbox
);
3302 cfglink_mbox
->vport
= vport
;
3303 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
3304 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
3305 if (rc
== MBX_NOT_FINISHED
) {
3306 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
3310 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
3312 * Add the driver's default FCF record at FCF index 0 now. This
3313 * is phase 1 implementation that support FCF index 0 and driver
3316 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
3317 fcf_record
= kzalloc(sizeof(struct fcf_record
),
3319 if (unlikely(!fcf_record
)) {
3320 lpfc_printf_log(phba
, KERN_ERR
,
3322 "2554 Could not allocate memory for "
3328 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
3329 LPFC_FCOE_FCF_DEF_INDEX
);
3330 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
3332 lpfc_printf_log(phba
, KERN_ERR
,
3334 "2013 Could not manually add FCF "
3335 "record 0, status %d\n", rc
);
3343 * The driver is expected to do FIP/FCF. Call the port
3344 * and get the FCF Table.
3346 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3347 if (phba
->hba_flag
& FCF_TS_INPROG
) {
3348 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3351 /* This is the initial FCF discovery scan */
3352 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
3353 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3354 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3355 "2778 Start FCF table scan at linkup\n");
3356 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3357 LPFC_FCOE_FCF_GET_FIRST
);
3359 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3360 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
3361 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3364 /* Reset FCF roundrobin bmask for new discovery */
3365 lpfc_sli4_clear_fcf_rr_bmask(phba
);
3368 /* Prepare for LINK up registrations */
3369 memset(phba
->os_host_name
, 0, sizeof(phba
->os_host_name
));
3370 scnprintf(phba
->os_host_name
, sizeof(phba
->os_host_name
), "%s",
3371 init_utsname()->nodename
);
3374 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3375 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3376 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3377 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
3378 lpfc_issue_clear_la(phba
, vport
);
3383 lpfc_enable_la(struct lpfc_hba
*phba
)
3386 struct lpfc_sli
*psli
= &phba
->sli
;
3387 spin_lock_irq(&phba
->hbalock
);
3388 psli
->sli_flag
|= LPFC_PROCESS_LA
;
3389 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
3390 control
= readl(phba
->HCregaddr
);
3391 control
|= HC_LAINT_ENA
;
3392 writel(control
, phba
->HCregaddr
);
3393 readl(phba
->HCregaddr
); /* flush */
3395 spin_unlock_irq(&phba
->hbalock
);
3399 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
3401 lpfc_linkdown(phba
);
3402 lpfc_enable_la(phba
);
3403 lpfc_unregister_unused_fcf(phba
);
3404 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3409 * This routine handles processing a READ_TOPOLOGY mailbox
3410 * command upon completion. It is setup in the LPFC_MBOXQ
3411 * as the completion routine when the command is
3412 * handed off to the SLI layer. SLI4 only.
3415 lpfc_mbx_cmpl_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3417 struct lpfc_vport
*vport
= pmb
->vport
;
3418 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3419 struct lpfc_mbx_read_top
*la
;
3420 struct lpfc_sli_ring
*pring
;
3421 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3422 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3424 unsigned long iflags
;
3426 /* Unblock ELS traffic */
3427 pring
= lpfc_phba_elsring(phba
);
3429 pring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3431 /* Check for error */
3432 if (mb
->mbxStatus
) {
3433 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3434 "1307 READ_LA mbox error x%x state x%x\n",
3435 mb
->mbxStatus
, vport
->port_state
);
3436 lpfc_mbx_issue_link_down(phba
);
3437 phba
->link_state
= LPFC_HBA_ERROR
;
3438 goto lpfc_mbx_cmpl_read_topology_free_mbuf
;
3441 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3442 attn_type
= bf_get(lpfc_mbx_read_top_att_type
, la
);
3444 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
3446 spin_lock_irqsave(shost
->host_lock
, iflags
);
3447 if (bf_get(lpfc_mbx_read_top_pb
, la
))
3448 vport
->fc_flag
|= FC_BYPASSED_MODE
;
3450 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
3451 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3453 if (phba
->fc_eventTag
<= la
->eventTag
) {
3454 phba
->fc_stat
.LinkMultiEvent
++;
3455 if (attn_type
== LPFC_ATT_LINK_UP
)
3456 if (phba
->fc_eventTag
!= 0)
3457 lpfc_linkdown(phba
);
3460 phba
->fc_eventTag
= la
->eventTag
;
3461 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3462 spin_lock_irqsave(&phba
->hbalock
, iflags
);
3463 if (bf_get(lpfc_mbx_read_top_mm
, la
))
3464 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
3466 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
3467 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
3470 phba
->link_events
++;
3471 if ((attn_type
== LPFC_ATT_LINK_UP
) &&
3472 !(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)) {
3473 phba
->fc_stat
.LinkUp
++;
3474 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
3475 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3476 "1306 Link Up Event in loop back mode "
3477 "x%x received Data: x%x x%x x%x x%x\n",
3478 la
->eventTag
, phba
->fc_eventTag
,
3479 bf_get(lpfc_mbx_read_top_alpa_granted
,
3481 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3484 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3485 "1303 Link Up Event x%x received "
3486 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3487 la
->eventTag
, phba
->fc_eventTag
,
3488 bf_get(lpfc_mbx_read_top_alpa_granted
,
3490 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3492 bf_get(lpfc_mbx_read_top_mm
, la
),
3493 bf_get(lpfc_mbx_read_top_fa
, la
),
3494 phba
->wait_4_mlo_maint_flg
);
3496 lpfc_mbx_process_link_up(phba
, la
);
3497 } else if (attn_type
== LPFC_ATT_LINK_DOWN
||
3498 attn_type
== LPFC_ATT_UNEXP_WWPN
) {
3499 phba
->fc_stat
.LinkDown
++;
3500 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
3501 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3502 "1308 Link Down Event in loop back mode "
3504 "Data: x%x x%x x%x\n",
3505 la
->eventTag
, phba
->fc_eventTag
,
3506 phba
->pport
->port_state
, vport
->fc_flag
);
3507 else if (attn_type
== LPFC_ATT_UNEXP_WWPN
)
3508 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3509 "1313 Link Down Unexpected FA WWPN Event x%x "
3510 "received Data: x%x x%x x%x x%x x%x\n",
3511 la
->eventTag
, phba
->fc_eventTag
,
3512 phba
->pport
->port_state
, vport
->fc_flag
,
3513 bf_get(lpfc_mbx_read_top_mm
, la
),
3514 bf_get(lpfc_mbx_read_top_fa
, la
));
3516 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3517 "1305 Link Down Event x%x received "
3518 "Data: x%x x%x x%x x%x x%x\n",
3519 la
->eventTag
, phba
->fc_eventTag
,
3520 phba
->pport
->port_state
, vport
->fc_flag
,
3521 bf_get(lpfc_mbx_read_top_mm
, la
),
3522 bf_get(lpfc_mbx_read_top_fa
, la
));
3523 lpfc_mbx_issue_link_down(phba
);
3525 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
&&
3526 attn_type
== LPFC_ATT_LINK_UP
) {
3527 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
3528 phba
->fc_stat
.LinkDown
++;
3529 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3530 "1312 Link Down Event x%x received "
3531 "Data: x%x x%x x%x\n",
3532 la
->eventTag
, phba
->fc_eventTag
,
3533 phba
->pport
->port_state
, vport
->fc_flag
);
3534 lpfc_mbx_issue_link_down(phba
);
3536 lpfc_enable_la(phba
);
3538 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3539 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3540 "Data: x%x x%x x%x\n",
3541 la
->eventTag
, phba
->fc_eventTag
,
3542 phba
->pport
->port_state
, vport
->fc_flag
);
3544 * The cmnd that triggered this will be waiting for this
3547 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3548 if (phba
->wait_4_mlo_maint_flg
) {
3549 phba
->wait_4_mlo_maint_flg
= 0;
3550 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
3554 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3555 bf_get(lpfc_mbx_read_top_fa
, la
)) {
3556 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
3557 lpfc_issue_clear_la(phba
, vport
);
3558 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3560 bf_get(lpfc_mbx_read_top_fa
, la
));
3563 lpfc_mbx_cmpl_read_topology_free_mbuf
:
3564 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3566 mempool_free(pmb
, phba
->mbox_mem_pool
);
3571 * This routine handles processing a REG_LOGIN mailbox
3572 * command upon completion. It is setup in the LPFC_MBOXQ
3573 * as the completion routine when the command is
3574 * handed off to the SLI layer.
3577 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3579 struct lpfc_vport
*vport
= pmb
->vport
;
3580 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3581 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
3583 pmb
->ctx_buf
= NULL
;
3584 pmb
->ctx_ndlp
= NULL
;
3586 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
| LOG_NODE
| LOG_DISCOVERY
,
3587 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3588 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3589 kref_read(&ndlp
->kref
),
3591 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
3592 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3594 if (ndlp
->nlp_flag
& NLP_IGNR_REG_CMPL
||
3595 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) {
3596 /* We rcvd a rscn after issuing this
3597 * mbox reg login, we may have cycled
3598 * back through the state and be
3599 * back at reg login state so this
3600 * mbox needs to be ignored becase
3601 * there is another reg login in
3604 spin_lock_irq(&ndlp
->lock
);
3605 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
3606 spin_unlock_irq(&ndlp
->lock
);
3609 * We cannot leave the RPI registered because
3610 * if we go thru discovery again for this ndlp
3611 * a subsequent REG_RPI will fail.
3613 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3614 lpfc_unreg_rpi(vport
, ndlp
);
3617 /* Call state machine */
3618 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
3620 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3622 mempool_free(pmb
, phba
->mbox_mem_pool
);
3623 /* decrement the node reference count held for this callback
3632 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3634 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3635 struct lpfc_vport
*vport
= pmb
->vport
;
3636 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3638 switch (mb
->mbxStatus
) {
3641 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3642 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3645 /* If VPI is busy, reset the HBA */
3647 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3648 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3649 vport
->vpi
, mb
->mbxStatus
);
3650 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
3651 lpfc_workq_post_event(phba
, NULL
, NULL
,
3652 LPFC_EVT_RESET_HBA
);
3654 spin_lock_irq(shost
->host_lock
);
3655 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3656 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3657 spin_unlock_irq(shost
->host_lock
);
3658 vport
->unreg_vpi_cmpl
= VPORT_OK
;
3659 mempool_free(pmb
, phba
->mbox_mem_pool
);
3660 lpfc_cleanup_vports_rrqs(vport
, NULL
);
3662 * This shost reference might have been taken at the beginning of
3663 * lpfc_vport_delete()
3665 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
3666 scsi_host_put(shost
);
3670 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
3672 struct lpfc_hba
*phba
= vport
->phba
;
3676 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3680 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
3681 mbox
->vport
= vport
;
3682 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
3683 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3684 if (rc
== MBX_NOT_FINISHED
) {
3685 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3686 "1800 Could not issue unreg_vpi\n");
3687 mempool_free(mbox
, phba
->mbox_mem_pool
);
3688 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
3695 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3697 struct lpfc_vport
*vport
= pmb
->vport
;
3698 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3699 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3701 switch (mb
->mbxStatus
) {
3705 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3706 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3708 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3709 spin_lock_irq(shost
->host_lock
);
3710 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3711 spin_unlock_irq(shost
->host_lock
);
3712 vport
->fc_myDID
= 0;
3714 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3715 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3716 if (phba
->nvmet_support
)
3717 lpfc_nvmet_update_targetport(phba
);
3719 lpfc_nvme_update_localport(vport
);
3724 spin_lock_irq(shost
->host_lock
);
3725 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3726 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3727 spin_unlock_irq(shost
->host_lock
);
3728 vport
->num_disc_nodes
= 0;
3729 /* go thru NPR list and issue ELS PLOGIs */
3730 if (vport
->fc_npr_cnt
)
3731 lpfc_els_disc_plogi(vport
);
3733 if (!vport
->num_disc_nodes
) {
3734 spin_lock_irq(shost
->host_lock
);
3735 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3736 spin_unlock_irq(shost
->host_lock
);
3737 lpfc_can_disctmo(vport
);
3739 vport
->port_state
= LPFC_VPORT_READY
;
3742 mempool_free(pmb
, phba
->mbox_mem_pool
);
3747 * lpfc_create_static_vport - Read HBA config region to create static vports.
3748 * @phba: pointer to lpfc hba data structure.
3750 * This routine issue a DUMP mailbox command for config region 22 to get
3751 * the list of static vports to be created. The function create vports
3752 * based on the information returned from the HBA.
3755 lpfc_create_static_vport(struct lpfc_hba
*phba
)
3757 LPFC_MBOXQ_t
*pmb
= NULL
;
3759 struct static_vport_info
*vport_info
;
3760 int mbx_wait_rc
= 0, i
;
3761 struct fc_vport_identifiers vport_id
;
3762 struct fc_vport
*new_fc_vport
;
3763 struct Scsi_Host
*shost
;
3764 struct lpfc_vport
*vport
;
3765 uint16_t offset
= 0;
3766 uint8_t *vport_buff
;
3767 struct lpfc_dmabuf
*mp
;
3768 uint32_t byte_count
= 0;
3770 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3772 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3773 "0542 lpfc_create_static_vport failed to"
3774 " allocate mailbox memory\n");
3777 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
3780 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
3782 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3783 "0543 lpfc_create_static_vport failed to"
3784 " allocate vport_info\n");
3785 mempool_free(pmb
, phba
->mbox_mem_pool
);
3789 vport_buff
= (uint8_t *) vport_info
;
3791 /* free dma buffer from previous round */
3793 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3794 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3797 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
3800 pmb
->vport
= phba
->pport
;
3801 mbx_wait_rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
,
3804 if ((mbx_wait_rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
3805 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3806 "0544 lpfc_create_static_vport failed to"
3807 " issue dump mailbox command ret 0x%x "
3809 mbx_wait_rc
, mb
->mbxStatus
);
3813 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3814 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
3815 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3816 if (byte_count
> sizeof(struct static_vport_info
) -
3818 byte_count
= sizeof(struct static_vport_info
)
3820 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
3821 offset
+= byte_count
;
3823 if (mb
->un
.varDmp
.word_cnt
>
3824 sizeof(struct static_vport_info
) - offset
)
3825 mb
->un
.varDmp
.word_cnt
=
3826 sizeof(struct static_vport_info
)
3828 byte_count
= mb
->un
.varDmp
.word_cnt
;
3829 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
3830 vport_buff
+ offset
,
3833 offset
+= byte_count
;
3836 } while (byte_count
&&
3837 offset
< sizeof(struct static_vport_info
));
3840 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
3841 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
3842 != VPORT_INFO_REV
)) {
3843 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
3844 "0545 lpfc_create_static_vport bad"
3845 " information header 0x%x 0x%x\n",
3846 le32_to_cpu(vport_info
->signature
),
3847 le32_to_cpu(vport_info
->rev
) &
3848 VPORT_INFO_REV_MASK
);
3853 shost
= lpfc_shost_from_vport(phba
->pport
);
3855 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
3856 memset(&vport_id
, 0, sizeof(vport_id
));
3857 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
3858 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
3859 if (!vport_id
.port_name
|| !vport_id
.node_name
)
3862 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
3863 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
3864 vport_id
.disable
= false;
3865 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
3867 if (!new_fc_vport
) {
3868 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3869 "0546 lpfc_create_static_vport failed to"
3874 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
3875 vport
->vport_flag
|= STATIC_VPORT
;
3880 if (mbx_wait_rc
!= MBX_TIMEOUT
) {
3882 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3883 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3886 mempool_free(pmb
, phba
->mbox_mem_pool
);
3893 * This routine handles processing a Fabric REG_LOGIN mailbox
3894 * command upon completion. It is setup in the LPFC_MBOXQ
3895 * as the completion routine when the command is
3896 * handed off to the SLI layer.
3899 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3901 struct lpfc_vport
*vport
= pmb
->vport
;
3902 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3903 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3904 struct lpfc_nodelist
*ndlp
;
3905 struct Scsi_Host
*shost
;
3907 ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
3908 pmb
->ctx_ndlp
= NULL
;
3909 pmb
->ctx_buf
= NULL
;
3911 if (mb
->mbxStatus
) {
3912 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
3913 "0258 Register Fabric login error: 0x%x\n",
3915 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3917 mempool_free(pmb
, phba
->mbox_mem_pool
);
3919 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3920 /* FLOGI failed, use loop map to make discovery list */
3921 lpfc_disc_list_loopmap(vport
);
3923 /* Start discovery */
3924 lpfc_disc_start(vport
);
3925 /* Decrement the reference count to ndlp after the
3926 * reference to the ndlp are done.
3932 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3933 /* Decrement the reference count to ndlp after the reference
3934 * to the ndlp are done.
3940 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3941 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3942 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3943 ndlp
->nlp_type
|= NLP_FABRIC
;
3944 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3946 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3947 /* when physical port receive logo donot start
3948 * vport discovery */
3949 if (!(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
3950 lpfc_start_fdiscs(phba
);
3952 shost
= lpfc_shost_from_vport(vport
);
3953 spin_lock_irq(shost
->host_lock
);
3954 vport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
3955 spin_unlock_irq(shost
->host_lock
);
3957 lpfc_do_scr_ns_plogi(phba
, vport
);
3960 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3962 mempool_free(pmb
, phba
->mbox_mem_pool
);
3964 /* Drop the reference count from the mbox at the end after
3965 * all the current reference to the ndlp have been done.
3972 * This routine will issue a GID_FT for each FC4 Type supported
3973 * by the driver. ALL GID_FTs must complete before discovery is started.
3976 lpfc_issue_gidft(struct lpfc_vport
*vport
)
3978 /* Good status, issue CT Request to NameServer */
3979 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3980 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
)) {
3981 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_FCP
)) {
3982 /* Cannot issue NameServer FCP Query, so finish up
3985 lpfc_printf_vlog(vport
, KERN_ERR
,
3987 "0604 %s FC TYPE %x %s\n",
3988 "Failed to issue GID_FT to ",
3990 "Finishing discovery.");
3996 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3997 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3998 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_NVME
)) {
3999 /* Cannot issue NameServer NVME Query, so finish up
4002 lpfc_printf_vlog(vport
, KERN_ERR
,
4004 "0605 %s FC_TYPE %x %s %d\n",
4005 "Failed to issue GID_FT to ",
4007 "Finishing discovery: gidftinp ",
4009 if (vport
->gidft_inp
== 0)
4014 return vport
->gidft_inp
;
4018 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4019 * @vport: The virtual port for which this call is being executed.
4021 * This routine will issue a GID_PT to get a list of all N_Ports
4024 * 0 - Failure to issue a GID_PT
4028 lpfc_issue_gidpt(struct lpfc_vport
*vport
)
4030 /* Good status, issue CT Request to NameServer */
4031 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_PT
, 0, GID_PT_N_PORT
)) {
4032 /* Cannot issue NameServer FCP Query, so finish up
4035 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4036 "0606 %s Port TYPE %x %s\n",
4037 "Failed to issue GID_PT to ",
4039 "Finishing discovery.");
4047 * This routine handles processing a NameServer REG_LOGIN mailbox
4048 * command upon completion. It is setup in the LPFC_MBOXQ
4049 * as the completion routine when the command is
4050 * handed off to the SLI layer.
4053 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4055 MAILBOX_t
*mb
= &pmb
->u
.mb
;
4056 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
4057 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
4058 struct lpfc_vport
*vport
= pmb
->vport
;
4060 pmb
->ctx_buf
= NULL
;
4061 pmb
->ctx_ndlp
= NULL
;
4062 vport
->gidft_inp
= 0;
4064 if (mb
->mbxStatus
) {
4065 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4066 "0260 Register NameServer error: 0x%x\n",
4070 /* decrement the node reference count held for this
4071 * callback function.
4074 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4076 mempool_free(pmb
, phba
->mbox_mem_pool
);
4078 /* If the node is not registered with the scsi or nvme
4079 * transport, remove the fabric node. The failed reg_login
4082 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
))) {
4083 spin_lock_irq(&ndlp
->lock
);
4084 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
4085 spin_unlock_irq(&ndlp
->lock
);
4086 lpfc_nlp_not_used(ndlp
);
4089 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4091 * RegLogin failed, use loop map to make discovery
4094 lpfc_disc_list_loopmap(vport
);
4096 /* Start discovery */
4097 lpfc_disc_start(vport
);
4100 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4104 if (phba
->sli_rev
< LPFC_SLI_REV4
)
4105 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4106 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
4107 ndlp
->nlp_type
|= NLP_FABRIC
;
4108 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4109 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
| LOG_DISCOVERY
,
4110 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4111 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4112 kref_read(&ndlp
->kref
),
4115 if (vport
->port_state
< LPFC_VPORT_READY
) {
4116 /* Link up discovery requires Fabric registration. */
4117 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
4118 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
4119 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
4120 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
4122 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4123 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
))
4124 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, FC_TYPE_FCP
);
4126 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4127 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
))
4128 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0,
4131 /* Issue SCR just before NameServer GID_FT Query */
4132 lpfc_issue_els_scr(vport
, 0);
4134 if (!phba
->cfg_enable_mi
||
4135 phba
->sli4_hba
.pc_sli4_params
.mi_ver
< LPFC_MIB3_SUPPORT
)
4136 lpfc_issue_els_rdf(vport
, 0);
4139 vport
->fc_ns_retry
= 0;
4140 if (lpfc_issue_gidft(vport
) == 0)
4144 * At this point in time we may need to wait for multiple
4145 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4147 * decrement the node reference count held for this
4148 * callback function.
4151 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4153 mempool_free(pmb
, phba
->mbox_mem_pool
);
4159 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4161 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4162 struct fc_rport
*rport
;
4163 struct lpfc_rport_data
*rdata
;
4164 struct fc_rport_identifiers rport_ids
;
4165 struct lpfc_hba
*phba
= vport
->phba
;
4166 unsigned long flags
;
4168 if (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4171 /* Remote port has reappeared. Re-register w/ FC transport */
4172 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
4173 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
4174 rport_ids
.port_id
= ndlp
->nlp_DID
;
4175 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
4178 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4179 "rport add: did:x%x flg:x%x type x%x",
4180 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4182 /* Don't add the remote port if unloading. */
4183 if (vport
->load_flag
& FC_UNLOADING
)
4187 * Disassociate any older association between this ndlp and rport
4190 rdata
= ndlp
->rport
->dd_data
;
4191 rdata
->pnode
= NULL
;
4194 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
4196 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
4197 "Warning: fc_remote_port_add failed\n");
4201 /* Successful port add. Complete initializing node data */
4202 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
4203 rport
->supported_classes
= ndlp
->nlp_class_sup
;
4204 rdata
= rport
->dd_data
;
4205 rdata
->pnode
= lpfc_nlp_get(ndlp
);
4206 if (!rdata
->pnode
) {
4207 dev_warn(&phba
->pcidev
->dev
,
4208 "Warning - node ref failed. Unreg rport\n");
4209 fc_remote_port_delete(rport
);
4214 spin_lock_irqsave(&ndlp
->lock
, flags
);
4215 ndlp
->fc4_xpt_flags
|= SCSI_XPT_REGD
;
4216 spin_unlock_irqrestore(&ndlp
->lock
, flags
);
4218 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
4219 rport_ids
.roles
|= FC_PORT_ROLE_FCP_TARGET
;
4220 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
4221 rport_ids
.roles
|= FC_PORT_ROLE_FCP_INITIATOR
;
4222 if (ndlp
->nlp_type
& NLP_NVME_INITIATOR
)
4223 rport_ids
.roles
|= FC_PORT_ROLE_NVME_INITIATOR
;
4224 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
4225 rport_ids
.roles
|= FC_PORT_ROLE_NVME_TARGET
;
4226 if (ndlp
->nlp_type
& NLP_NVME_DISCOVERY
)
4227 rport_ids
.roles
|= FC_PORT_ROLE_NVME_DISCOVERY
;
4229 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
4230 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
4232 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4233 "3183 %s rport x%px DID x%x, role x%x\n",
4234 __func__
, rport
, rport
->port_id
, rport
->roles
);
4236 if ((rport
->scsi_target_id
!= -1) &&
4237 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
4238 ndlp
->nlp_sid
= rport
->scsi_target_id
;
4245 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
4247 struct fc_rport
*rport
= ndlp
->rport
;
4248 struct lpfc_vport
*vport
= ndlp
->vport
;
4250 if (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4253 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4254 "rport delete: did:x%x flg:x%x type x%x",
4255 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4257 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4258 "3184 rport unregister x%06x, rport x%px "
4260 ndlp
->nlp_DID
, rport
, ndlp
->fc4_xpt_flags
);
4262 fc_remote_port_delete(rport
);
4267 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
4269 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4270 unsigned long iflags
;
4272 spin_lock_irqsave(shost
->host_lock
, iflags
);
4274 case NLP_STE_UNUSED_NODE
:
4275 vport
->fc_unused_cnt
+= count
;
4277 case NLP_STE_PLOGI_ISSUE
:
4278 vport
->fc_plogi_cnt
+= count
;
4280 case NLP_STE_ADISC_ISSUE
:
4281 vport
->fc_adisc_cnt
+= count
;
4283 case NLP_STE_REG_LOGIN_ISSUE
:
4284 vport
->fc_reglogin_cnt
+= count
;
4286 case NLP_STE_PRLI_ISSUE
:
4287 vport
->fc_prli_cnt
+= count
;
4289 case NLP_STE_UNMAPPED_NODE
:
4290 vport
->fc_unmap_cnt
+= count
;
4292 case NLP_STE_MAPPED_NODE
:
4293 vport
->fc_map_cnt
+= count
;
4295 case NLP_STE_NPR_NODE
:
4296 if (vport
->fc_npr_cnt
== 0 && count
== -1)
4297 vport
->fc_npr_cnt
= 0;
4299 vport
->fc_npr_cnt
+= count
;
4302 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
4306 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4307 int old_state
, int new_state
)
4309 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
4310 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4311 ndlp
->nlp_type
|= NLP_FC_NODE
;
4313 if (new_state
== NLP_STE_MAPPED_NODE
)
4314 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4315 if (new_state
== NLP_STE_NPR_NODE
)
4316 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
4318 /* FCP and NVME Transport interface */
4319 if ((old_state
== NLP_STE_MAPPED_NODE
||
4320 old_state
== NLP_STE_UNMAPPED_NODE
)) {
4322 vport
->phba
->nport_event_cnt
++;
4323 lpfc_unregister_remote_port(ndlp
);
4326 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4327 vport
->phba
->nport_event_cnt
++;
4328 if (vport
->phba
->nvmet_support
== 0) {
4329 /* Start devloss if target. */
4330 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
4331 lpfc_nvme_unregister_port(vport
, ndlp
);
4333 /* NVMET has no upcall. */
4339 /* FCP and NVME Transport interfaces */
4341 if (new_state
== NLP_STE_MAPPED_NODE
||
4342 new_state
== NLP_STE_UNMAPPED_NODE
) {
4343 if (ndlp
->nlp_fc4_type
||
4344 ndlp
->nlp_DID
== Fabric_DID
||
4345 ndlp
->nlp_DID
== NameServer_DID
||
4346 ndlp
->nlp_DID
== FDMI_DID
) {
4347 vport
->phba
->nport_event_cnt
++;
4349 * Tell the fc transport about the port, if we haven't
4350 * already. If we have, and it's a scsi entity, be
4352 lpfc_register_remote_port(vport
, ndlp
);
4354 /* Notify the NVME transport of this new rport. */
4355 if (vport
->phba
->sli_rev
>= LPFC_SLI_REV4
&&
4356 ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4357 if (vport
->phba
->nvmet_support
== 0) {
4358 /* Register this rport with the transport.
4359 * Only NVME Target Rports are registered with
4362 if (ndlp
->nlp_type
& NLP_NVME_TARGET
) {
4363 vport
->phba
->nport_event_cnt
++;
4364 lpfc_nvme_register_port(vport
, ndlp
);
4367 /* Just take an NDLP ref count since the
4368 * target does not register rports.
4375 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4376 (vport
->stat_data_enabled
)) {
4378 * A new target is discovered, if there is no buffer for
4379 * statistical data collection allocate buffer.
4381 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
4382 sizeof(struct lpfc_scsicmd_bkt
),
4385 if (!ndlp
->lat_data
)
4386 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4387 "0286 lpfc_nlp_state_cleanup failed to "
4388 "allocate statistical data buffer DID "
4389 "0x%x\n", ndlp
->nlp_DID
);
4392 * If the node just added to Mapped list was an FCP target,
4393 * but the remote port registration failed or assigned a target
4394 * id outside the presentable range - move the node to the
4397 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4398 (ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4400 ndlp
->rport
->scsi_target_id
== -1 ||
4401 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
4402 spin_lock_irq(&ndlp
->lock
);
4403 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
4404 spin_unlock_irq(&ndlp
->lock
);
4405 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4410 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
4412 static char *states
[] = {
4413 [NLP_STE_UNUSED_NODE
] = "UNUSED",
4414 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
4415 [NLP_STE_ADISC_ISSUE
] = "ADISC",
4416 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
4417 [NLP_STE_PRLI_ISSUE
] = "PRLI",
4418 [NLP_STE_LOGO_ISSUE
] = "LOGO",
4419 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
4420 [NLP_STE_MAPPED_NODE
] = "MAPPED",
4421 [NLP_STE_NPR_NODE
] = "NPR",
4424 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
4425 strlcpy(buffer
, states
[state
], size
);
4427 snprintf(buffer
, size
, "unknown (%d)", state
);
4432 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4435 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4436 int old_state
= ndlp
->nlp_state
;
4437 int node_dropped
= ndlp
->nlp_flag
& NLP_DROPPED
;
4438 char name1
[16], name2
[16];
4440 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4441 "0904 NPort state transition x%06x, %s -> %s\n",
4443 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
4444 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
4446 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4447 "node statechg did:x%x old:%d ste:%d",
4448 ndlp
->nlp_DID
, old_state
, state
);
4450 if (node_dropped
&& old_state
== NLP_STE_UNUSED_NODE
&&
4451 state
!= NLP_STE_UNUSED_NODE
) {
4452 ndlp
->nlp_flag
&= ~NLP_DROPPED
;
4456 if (old_state
== NLP_STE_NPR_NODE
&&
4457 state
!= NLP_STE_NPR_NODE
)
4458 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4459 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
4460 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
4461 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
4464 if (list_empty(&ndlp
->nlp_listp
)) {
4465 spin_lock_irq(shost
->host_lock
);
4466 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4467 spin_unlock_irq(shost
->host_lock
);
4468 } else if (old_state
)
4469 lpfc_nlp_counters(vport
, old_state
, -1);
4471 ndlp
->nlp_state
= state
;
4472 lpfc_nlp_counters(vport
, state
, 1);
4473 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
4477 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4479 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4481 if (list_empty(&ndlp
->nlp_listp
)) {
4482 spin_lock_irq(shost
->host_lock
);
4483 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4484 spin_unlock_irq(shost
->host_lock
);
4489 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4491 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4493 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4494 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
4495 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
4496 spin_lock_irq(shost
->host_lock
);
4497 list_del_init(&ndlp
->nlp_listp
);
4498 spin_unlock_irq(shost
->host_lock
);
4499 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
4500 NLP_STE_UNUSED_NODE
);
4504 * lpfc_initialize_node - Initialize all fields of node object
4505 * @vport: Pointer to Virtual Port object.
4506 * @ndlp: Pointer to FC node object.
4507 * @did: FC_ID of the node.
4509 * This function is always called when node object need to be initialized.
4510 * It initializes all the fields of the node object. Although the reference
4511 * to phba from @ndlp can be obtained indirectly through it's reference to
4512 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4513 * to the life-span of the @ndlp might go beyond the existence of @vport as
4514 * the final release of ndlp is determined by its reference count. And, the
4515 * operation on @ndlp needs the reference to phba.
4518 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4521 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
4522 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
4523 timer_setup(&ndlp
->nlp_delayfunc
, lpfc_els_retry_delay
, 0);
4524 INIT_LIST_HEAD(&ndlp
->recovery_evt
.evt_listp
);
4526 ndlp
->nlp_DID
= did
;
4527 ndlp
->vport
= vport
;
4528 ndlp
->phba
= vport
->phba
;
4529 ndlp
->nlp_sid
= NLP_NO_SID
;
4530 ndlp
->nlp_fc4_type
= NLP_FC4_NONE
;
4531 kref_init(&ndlp
->kref
);
4532 atomic_set(&ndlp
->cmd_pending
, 0);
4533 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
4534 ndlp
->nlp_defer_did
= NLP_EVT_NOTHING_PENDING
;
4538 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4541 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4542 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4543 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4544 * until ALL other outstanding threads have completed. We check
4545 * that the ndlp not already in the UNUSED state before we proceed.
4547 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
4549 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4550 ndlp
->nlp_flag
|= NLP_DROPPED
;
4551 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4552 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
4553 lpfc_unreg_rpi(vport
, ndlp
);
4561 * Start / ReStart rescue timer for Discovery / RSCN handling
4564 lpfc_set_disctmo(struct lpfc_vport
*vport
)
4566 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4567 struct lpfc_hba
*phba
= vport
->phba
;
4570 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
4571 /* For FAN, timeout should be greater than edtov */
4572 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
4574 /* Normal discovery timeout should be > than ELS/CT timeout
4575 * FC spec states we need 3 * ratov for CT requests
4577 tmo
= ((phba
->fc_ratov
* 3) + 3);
4581 if (!timer_pending(&vport
->fc_disctmo
)) {
4582 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4583 "set disc timer: tmo:x%x state:x%x flg:x%x",
4584 tmo
, vport
->port_state
, vport
->fc_flag
);
4587 mod_timer(&vport
->fc_disctmo
, jiffies
+ msecs_to_jiffies(1000 * tmo
));
4588 spin_lock_irq(shost
->host_lock
);
4589 vport
->fc_flag
|= FC_DISC_TMO
;
4590 spin_unlock_irq(shost
->host_lock
);
4592 /* Start Discovery Timer state <hba_state> */
4593 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4594 "0247 Start Discovery Timer state x%x "
4595 "Data: x%x x%lx x%x x%x\n",
4596 vport
->port_state
, tmo
,
4597 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
4598 vport
->fc_adisc_cnt
);
4604 * Cancel rescue timer for Discovery / RSCN handling
4607 lpfc_can_disctmo(struct lpfc_vport
*vport
)
4609 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4610 unsigned long iflags
;
4612 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4613 "can disc timer: state:x%x rtry:x%x flg:x%x",
4614 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
4616 /* Turn off discovery timer if its running */
4617 if (vport
->fc_flag
& FC_DISC_TMO
) {
4618 spin_lock_irqsave(shost
->host_lock
, iflags
);
4619 vport
->fc_flag
&= ~FC_DISC_TMO
;
4620 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
4621 del_timer_sync(&vport
->fc_disctmo
);
4622 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
4623 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
4624 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
4627 /* Cancel Discovery Timer state <hba_state> */
4628 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4629 "0248 Cancel Discovery Timer state x%x "
4630 "Data: x%x x%x x%x\n",
4631 vport
->port_state
, vport
->fc_flag
,
4632 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
4637 * Check specified ring for outstanding IOCB on the SLI queue
4638 * Return true if iocb matches the specified nport
4641 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
4642 struct lpfc_sli_ring
*pring
,
4643 struct lpfc_iocbq
*iocb
,
4644 struct lpfc_nodelist
*ndlp
)
4646 IOCB_t
*icmd
= &iocb
->iocb
;
4647 struct lpfc_vport
*vport
= ndlp
->vport
;
4649 if (iocb
->vport
!= vport
)
4652 if (pring
->ringno
== LPFC_ELS_RING
) {
4653 switch (icmd
->ulpCommand
) {
4654 case CMD_GEN_REQUEST64_CR
:
4655 if (iocb
->context_un
.ndlp
== ndlp
)
4658 case CMD_ELS_REQUEST64_CR
:
4659 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
4662 case CMD_XMIT_ELS_RSP64_CX
:
4663 if (iocb
->context1
== (uint8_t *) ndlp
)
4666 } else if (pring
->ringno
== LPFC_FCP_RING
) {
4667 /* Skip match check if waiting to relogin to FCP target */
4668 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4669 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
4672 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
4680 __lpfc_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4681 struct lpfc_nodelist
*ndlp
, struct lpfc_sli_ring
*pring
,
4682 struct list_head
*dequeue_list
)
4684 struct lpfc_iocbq
*iocb
, *next_iocb
;
4686 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
4687 /* Check to see if iocb matches the nport */
4688 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
4689 /* match, dequeue */
4690 list_move_tail(&iocb
->list
, dequeue_list
);
4695 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4696 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4698 struct lpfc_sli
*psli
= &phba
->sli
;
4701 spin_lock_irq(&phba
->hbalock
);
4702 for (i
= 0; i
< psli
->num_rings
; i
++)
4703 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, &psli
->sli3_ring
[i
],
4705 spin_unlock_irq(&phba
->hbalock
);
4709 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4710 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4712 struct lpfc_sli_ring
*pring
;
4713 struct lpfc_queue
*qp
= NULL
;
4715 spin_lock_irq(&phba
->hbalock
);
4716 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
4720 spin_lock(&pring
->ring_lock
);
4721 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, pring
, dequeue_list
);
4722 spin_unlock(&pring
->ring_lock
);
4724 spin_unlock_irq(&phba
->hbalock
);
4728 * Free resources / clean up outstanding I/Os
4729 * associated with nlp_rpi in the LPFC_NODELIST entry.
4732 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4734 LIST_HEAD(completions
);
4736 lpfc_fabric_abort_nport(ndlp
);
4739 * Everything that matches on txcmplq will be returned
4740 * by firmware with a no rpi error.
4742 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4743 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4744 lpfc_sli3_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4746 lpfc_sli4_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4749 /* Cancel all the IOCBs from the completions list */
4750 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4757 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4758 * @phba: Pointer to HBA context object.
4759 * @pmb: Pointer to mailbox object.
4761 * This function will issue an ELS LOGO command after completing
4765 lpfc_nlp_logo_unreg(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4767 struct lpfc_vport
*vport
= pmb
->vport
;
4768 struct lpfc_nodelist
*ndlp
;
4770 ndlp
= (struct lpfc_nodelist
*)(pmb
->ctx_ndlp
);
4773 lpfc_issue_els_logo(vport
, ndlp
, 0);
4774 mempool_free(pmb
, phba
->mbox_mem_pool
);
4776 /* Check to see if there are any deferred events to process */
4777 if ((ndlp
->nlp_flag
& NLP_UNREG_INP
) &&
4778 (ndlp
->nlp_defer_did
!= NLP_EVT_NOTHING_PENDING
)) {
4779 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4780 "1434 UNREG cmpl deferred logo x%x "
4781 "on NPort x%x Data: x%x x%px\n",
4782 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4783 ndlp
->nlp_defer_did
, ndlp
);
4785 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
4786 ndlp
->nlp_defer_did
= NLP_EVT_NOTHING_PENDING
;
4787 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4789 if (ndlp
->nlp_flag
& NLP_RELEASE_RPI
) {
4790 lpfc_sli4_free_rpi(vport
->phba
, ndlp
->nlp_rpi
);
4791 ndlp
->nlp_flag
&= ~NLP_RELEASE_RPI
;
4792 ndlp
->nlp_rpi
= LPFC_RPI_ALLOC_ERROR
;
4794 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
4799 * Sets the mailbox completion handler to be used for the
4800 * unreg_rpi command. The handler varies based on the state of
4801 * the port and what will be happening to the rpi next.
4804 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
4805 struct lpfc_nodelist
*ndlp
, LPFC_MBOXQ_t
*mbox
)
4807 unsigned long iflags
;
4809 /* Driver always gets a reference on the mailbox job
4810 * in support of async jobs.
4812 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
4813 if (!mbox
->ctx_ndlp
)
4816 if (ndlp
->nlp_flag
& NLP_ISSUE_LOGO
) {
4817 mbox
->mbox_cmpl
= lpfc_nlp_logo_unreg
;
4819 } else if (phba
->sli_rev
== LPFC_SLI_REV4
&&
4820 (!(vport
->load_flag
& FC_UNLOADING
)) &&
4821 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) >=
4822 LPFC_SLI_INTF_IF_TYPE_2
) &&
4823 (kref_read(&ndlp
->kref
) > 0)) {
4824 mbox
->mbox_cmpl
= lpfc_sli4_unreg_rpi_cmpl_clr
;
4826 if (vport
->load_flag
& FC_UNLOADING
) {
4827 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4828 spin_lock_irqsave(&ndlp
->lock
, iflags
);
4829 ndlp
->nlp_flag
|= NLP_RELEASE_RPI
;
4830 spin_unlock_irqrestore(&ndlp
->lock
, iflags
);
4833 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4838 * Free rpi associated with LPFC_NODELIST entry.
4839 * This routine is called from lpfc_freenode(), when we are removing
4840 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4841 * LOGO that completes successfully, and we are waiting to PLOGI back
4842 * to the remote NPort. In addition, it is called after we receive
4843 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4844 * we are waiting to PLOGI back to the remote NPort.
4847 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4849 struct lpfc_hba
*phba
= vport
->phba
;
4851 int rc
, acc_plogi
= 1;
4854 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4855 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) {
4856 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
4857 lpfc_printf_vlog(vport
, KERN_INFO
,
4858 LOG_NODE
| LOG_DISCOVERY
,
4859 "3366 RPI x%x needs to be "
4860 "unregistered nlp_flag x%x "
4862 ndlp
->nlp_rpi
, ndlp
->nlp_flag
,
4865 /* If there is already an UNREG in progress for this ndlp,
4866 * no need to queue up another one.
4868 if (ndlp
->nlp_flag
& NLP_UNREG_INP
) {
4869 lpfc_printf_vlog(vport
, KERN_INFO
,
4870 LOG_NODE
| LOG_DISCOVERY
,
4871 "1436 unreg_rpi SKIP UNREG x%x on "
4872 "NPort x%x deferred x%x flg x%x "
4874 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4875 ndlp
->nlp_defer_did
,
4876 ndlp
->nlp_flag
, ndlp
);
4880 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4882 /* SLI4 ports require the physical rpi value. */
4883 rpi
= ndlp
->nlp_rpi
;
4884 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4885 rpi
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4887 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, mbox
);
4888 mbox
->vport
= vport
;
4889 lpfc_set_unreg_login_mbx_cmpl(phba
, vport
, ndlp
, mbox
);
4890 if (!mbox
->ctx_ndlp
) {
4891 mempool_free(mbox
, phba
->mbox_mem_pool
);
4895 if (mbox
->mbox_cmpl
== lpfc_sli4_unreg_rpi_cmpl_clr
)
4897 * accept PLOGIs after unreg_rpi_cmpl
4900 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) !=
4902 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
4903 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
4905 lpfc_printf_vlog(vport
, KERN_INFO
,
4906 LOG_NODE
| LOG_DISCOVERY
,
4907 "1433 unreg_rpi UNREG x%x on "
4908 "NPort x%x deferred flg x%x "
4910 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4911 ndlp
->nlp_flag
, ndlp
);
4913 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4914 if (rc
== MBX_NOT_FINISHED
) {
4915 mempool_free(mbox
, phba
->mbox_mem_pool
);
4919 lpfc_printf_vlog(vport
, KERN_INFO
,
4920 LOG_NODE
| LOG_DISCOVERY
,
4921 "1444 Failed to allocate mempool "
4922 "unreg_rpi UNREG x%x, "
4923 "DID x%x, flag x%x, "
4925 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4926 ndlp
->nlp_flag
, ndlp
);
4928 /* Because mempool_alloc failed, we
4929 * will issue a LOGO here and keep the rpi alive if
4932 if (!(vport
->load_flag
& FC_UNLOADING
)) {
4933 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
4934 lpfc_issue_els_logo(vport
, ndlp
, 0);
4935 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4936 lpfc_nlp_set_state(vport
, ndlp
,
4942 lpfc_no_rpi(phba
, ndlp
);
4944 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4946 ndlp
->nlp_flag
&= ~NLP_RPI_REGISTERED
;
4947 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4949 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4952 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4957 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4958 * @phba: pointer to lpfc hba data structure.
4960 * This routine is invoked to unregister all the currently registered RPIs
4964 lpfc_unreg_hba_rpis(struct lpfc_hba
*phba
)
4966 struct lpfc_vport
**vports
;
4967 struct lpfc_nodelist
*ndlp
;
4968 struct Scsi_Host
*shost
;
4971 vports
= lpfc_create_vport_work_array(phba
);
4973 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4974 "2884 Vport array allocation failed \n");
4977 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4978 shost
= lpfc_shost_from_vport(vports
[i
]);
4979 spin_lock_irq(shost
->host_lock
);
4980 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4981 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4982 /* The mempool_alloc might sleep */
4983 spin_unlock_irq(shost
->host_lock
);
4984 lpfc_unreg_rpi(vports
[i
], ndlp
);
4985 spin_lock_irq(shost
->host_lock
);
4988 spin_unlock_irq(shost
->host_lock
);
4990 lpfc_destroy_vport_work_array(phba
, vports
);
4994 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
4996 struct lpfc_hba
*phba
= vport
->phba
;
5000 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5001 lpfc_sli4_unreg_all_rpis(vport
);
5005 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5007 lpfc_unreg_login(phba
, vport
->vpi
, LPFC_UNREG_ALL_RPIS_VPORT
,
5009 mbox
->vport
= vport
;
5010 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5011 mbox
->ctx_ndlp
= NULL
;
5012 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
5013 if (rc
!= MBX_TIMEOUT
)
5014 mempool_free(mbox
, phba
->mbox_mem_pool
);
5016 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
5017 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5018 "1836 Could not issue "
5019 "unreg_login(all_rpis) status %d\n",
5025 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
5027 struct lpfc_hba
*phba
= vport
->phba
;
5031 /* Unreg DID is an SLI3 operation. */
5032 if (phba
->sli_rev
> LPFC_SLI_REV3
)
5035 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5037 lpfc_unreg_did(phba
, vport
->vpi
, LPFC_UNREG_ALL_DFLT_RPIS
,
5039 mbox
->vport
= vport
;
5040 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5041 mbox
->ctx_ndlp
= NULL
;
5042 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
5043 if (rc
!= MBX_TIMEOUT
)
5044 mempool_free(mbox
, phba
->mbox_mem_pool
);
5046 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
5047 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5048 "1815 Could not issue "
5049 "unreg_did (default rpis) status %d\n",
5055 * Free resources associated with LPFC_NODELIST entry
5056 * so it can be freed.
5059 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
5061 struct lpfc_hba
*phba
= vport
->phba
;
5062 LPFC_MBOXQ_t
*mb
, *nextmb
;
5063 struct lpfc_dmabuf
*mp
;
5065 /* Cleanup node for NPort <nlp_DID> */
5066 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5067 "0900 Cleanup node for NPort x%x "
5068 "Data: x%x x%x x%x\n",
5069 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5070 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
5071 lpfc_dequeue_node(vport
, ndlp
);
5073 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5075 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5076 if ((mb
= phba
->sli
.mbox_active
)) {
5077 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
5078 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
5079 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
5080 mb
->ctx_ndlp
= NULL
;
5081 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5085 spin_lock_irq(&phba
->hbalock
);
5086 /* Cleanup REG_LOGIN completions which are not yet processed */
5087 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
5088 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) ||
5089 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) ||
5090 (ndlp
!= (struct lpfc_nodelist
*)mb
->ctx_ndlp
))
5093 mb
->ctx_ndlp
= NULL
;
5094 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5097 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
5098 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
5099 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
5100 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
5101 mp
= (struct lpfc_dmabuf
*)(mb
->ctx_buf
);
5103 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5106 list_del(&mb
->list
);
5107 mempool_free(mb
, phba
->mbox_mem_pool
);
5108 /* We shall not invoke the lpfc_nlp_put to decrement
5109 * the ndlp reference count as we are in the process
5110 * of lpfc_nlp_release.
5114 spin_unlock_irq(&phba
->hbalock
);
5116 lpfc_els_abort(phba
, ndlp
);
5118 spin_lock_irq(&ndlp
->lock
);
5119 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
5120 spin_unlock_irq(&ndlp
->lock
);
5122 ndlp
->nlp_last_elscmd
= 0;
5123 del_timer_sync(&ndlp
->nlp_delayfunc
);
5125 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
5126 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
5127 list_del_init(&ndlp
->recovery_evt
.evt_listp
);
5128 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
5129 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5130 ndlp
->nlp_flag
|= NLP_RELEASE_RPI
;
5135 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5138 D_ID mydid
, ndlpdid
, matchdid
;
5140 if (did
== Bcast_DID
)
5143 /* First check for Direct match */
5144 if (ndlp
->nlp_DID
== did
)
5147 /* Next check for area/domain identically equals 0 match */
5148 mydid
.un
.word
= vport
->fc_myDID
;
5149 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
5153 matchdid
.un
.word
= did
;
5154 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
5155 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
5156 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
5157 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
5158 /* This code is supposed to match the ID
5159 * for a private loop device that is
5160 * connect to fl_port. But we need to
5161 * check that the port did not just go
5162 * from pt2pt to fabric or we could end
5163 * up matching ndlp->nlp_DID 000001 to
5164 * fabric DID 0x20101
5166 if ((ndlpdid
.un
.b
.domain
== 0) &&
5167 (ndlpdid
.un
.b
.area
== 0)) {
5168 if (ndlpdid
.un
.b
.id
&&
5169 vport
->phba
->fc_topology
==
5176 matchdid
.un
.word
= ndlp
->nlp_DID
;
5177 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
5178 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
5179 if ((matchdid
.un
.b
.domain
== 0) &&
5180 (matchdid
.un
.b
.area
== 0)) {
5181 if (matchdid
.un
.b
.id
)
5189 /* Search for a nodelist entry */
5190 static struct lpfc_nodelist
*
5191 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5193 struct lpfc_nodelist
*ndlp
;
5196 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5197 if (lpfc_matchdid(vport
, ndlp
, did
)) {
5198 data1
= (((uint32_t)ndlp
->nlp_state
<< 24) |
5199 ((uint32_t)ndlp
->nlp_xri
<< 16) |
5200 ((uint32_t)ndlp
->nlp_type
<< 8)
5202 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5203 "0929 FIND node DID "
5204 "Data: x%px x%x x%x x%x x%x x%px\n",
5205 ndlp
, ndlp
->nlp_DID
,
5206 ndlp
->nlp_flag
, data1
, ndlp
->nlp_rpi
,
5207 ndlp
->active_rrqs_xri_bitmap
);
5212 /* FIND node did <did> NOT FOUND */
5213 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5214 "0932 FIND node did x%x NOT FOUND.\n", did
);
5218 struct lpfc_nodelist
*
5219 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5221 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5222 struct lpfc_nodelist
*ndlp
;
5223 unsigned long iflags
;
5225 spin_lock_irqsave(shost
->host_lock
, iflags
);
5226 ndlp
= __lpfc_findnode_did(vport
, did
);
5227 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
5231 struct lpfc_nodelist
*
5232 lpfc_findnode_mapped(struct lpfc_vport
*vport
)
5234 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5235 struct lpfc_nodelist
*ndlp
;
5237 unsigned long iflags
;
5239 spin_lock_irqsave(shost
->host_lock
, iflags
);
5241 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5242 if (ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
||
5243 ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
5244 data1
= (((uint32_t)ndlp
->nlp_state
<< 24) |
5245 ((uint32_t)ndlp
->nlp_xri
<< 16) |
5246 ((uint32_t)ndlp
->nlp_type
<< 8) |
5247 ((uint32_t)ndlp
->nlp_rpi
& 0xff));
5248 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
5249 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5250 "2025 FIND node DID "
5251 "Data: x%px x%x x%x x%x x%px\n",
5252 ndlp
, ndlp
->nlp_DID
,
5253 ndlp
->nlp_flag
, data1
,
5254 ndlp
->active_rrqs_xri_bitmap
);
5258 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
5260 /* FIND node did <did> NOT FOUND */
5261 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5262 "2026 FIND mapped did NOT FOUND.\n");
5266 struct lpfc_nodelist
*
5267 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
5269 struct lpfc_nodelist
*ndlp
;
5271 ndlp
= lpfc_findnode_did(vport
, did
);
5273 if (vport
->phba
->nvmet_support
)
5275 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
5276 lpfc_rscn_payload_check(vport
, did
) == 0)
5278 ndlp
= lpfc_nlp_init(vport
, did
);
5281 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5283 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5284 "6453 Setup New Node 2B_DISC x%x "
5285 "Data:x%x x%x x%x\n",
5286 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5287 ndlp
->nlp_state
, vport
->fc_flag
);
5289 spin_lock_irq(&ndlp
->lock
);
5290 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5291 spin_unlock_irq(&ndlp
->lock
);
5295 /* The NVME Target does not want to actively manage an rport.
5296 * The goal is to allow the target to reset its state and clear
5297 * pending IO in preparation for the initiator to recover.
5299 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
5300 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
5301 if (lpfc_rscn_payload_check(vport
, did
)) {
5303 /* Since this node is marked for discovery,
5304 * delay timeout is not needed.
5306 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5308 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5309 "6455 Setup RSCN Node 2B_DISC x%x "
5310 "Data:x%x x%x x%x\n",
5311 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5312 ndlp
->nlp_state
, vport
->fc_flag
);
5314 /* NVME Target mode waits until rport is known to be
5315 * impacted by the RSCN before it transitions. No
5316 * active management - just go to NPR provided the
5317 * node had a valid login.
5319 if (vport
->phba
->nvmet_support
)
5322 /* If we've already received a PLOGI from this NPort
5323 * we don't need to try to discover it again.
5325 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
&&
5327 (NLP_FCP_TARGET
| NLP_NVME_TARGET
)))
5330 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5331 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5333 spin_lock_irq(&ndlp
->lock
);
5334 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5335 spin_unlock_irq(&ndlp
->lock
);
5337 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5338 "6456 Skip Setup RSCN Node x%x "
5339 "Data:x%x x%x x%x\n",
5340 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5341 ndlp
->nlp_state
, vport
->fc_flag
);
5345 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5346 "6457 Setup Active Node 2B_DISC x%x "
5347 "Data:x%x x%x x%x\n",
5348 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5349 ndlp
->nlp_state
, vport
->fc_flag
);
5351 /* If the initiator received a PLOGI from this NPort or if the
5352 * initiator is already in the process of discovery on it,
5353 * there's no need to try to discover it again.
5355 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
5356 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5357 (!vport
->phba
->nvmet_support
&&
5358 ndlp
->nlp_flag
& NLP_RCV_PLOGI
))
5361 if (vport
->phba
->nvmet_support
)
5364 /* Moving to NPR state clears unsolicited flags and
5365 * allows for rediscovery
5367 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5369 spin_lock_irq(&ndlp
->lock
);
5370 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5371 spin_unlock_irq(&ndlp
->lock
);
5376 /* Build a list of nodes to discover based on the loopmap */
5378 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
5380 struct lpfc_hba
*phba
= vport
->phba
;
5382 uint32_t alpa
, index
;
5384 if (!lpfc_is_link_up(phba
))
5387 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5390 /* Check for loop map present or not */
5391 if (phba
->alpa_map
[0]) {
5392 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
5393 alpa
= phba
->alpa_map
[j
];
5394 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
5396 lpfc_setup_disc_node(vport
, alpa
);
5399 /* No alpamap, so try all alpa's */
5400 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
5401 /* If cfg_scan_down is set, start from highest
5402 * ALPA (0xef) to lowest (0x1).
5404 if (vport
->cfg_scan_down
)
5407 index
= FC_MAXLOOP
- j
- 1;
5408 alpa
= lpfcAlpaArray
[index
];
5409 if ((vport
->fc_myDID
& 0xff) == alpa
)
5411 lpfc_setup_disc_node(vport
, alpa
);
5419 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5422 struct lpfc_sli
*psli
= &phba
->sli
;
5423 struct lpfc_sli_ring
*extra_ring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
5424 struct lpfc_sli_ring
*fcp_ring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
5428 * if it's not a physical port or if we already send
5429 * clear_la then don't send it.
5431 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
5432 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
5433 (phba
->sli_rev
== LPFC_SLI_REV4
))
5436 /* Link up discovery */
5437 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
5438 phba
->link_state
= LPFC_CLEAR_LA
;
5439 lpfc_clear_la(phba
, mbox
);
5440 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
5441 mbox
->vport
= vport
;
5442 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5443 if (rc
== MBX_NOT_FINISHED
) {
5444 mempool_free(mbox
, phba
->mbox_mem_pool
);
5445 lpfc_disc_flush_list(vport
);
5446 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5447 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5448 phba
->link_state
= LPFC_HBA_ERROR
;
5453 /* Reg_vpi to tell firmware to resume normal operations */
5455 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5457 LPFC_MBOXQ_t
*regvpimbox
;
5459 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5461 lpfc_reg_vpi(vport
, regvpimbox
);
5462 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
5463 regvpimbox
->vport
= vport
;
5464 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
5465 == MBX_NOT_FINISHED
) {
5466 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
5471 /* Start Link up / RSCN discovery on NPR nodes */
5473 lpfc_disc_start(struct lpfc_vport
*vport
)
5475 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5476 struct lpfc_hba
*phba
= vport
->phba
;
5478 uint32_t clear_la_pending
;
5480 if (!lpfc_is_link_up(phba
)) {
5481 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
5482 "3315 Link is not up %x\n",
5487 if (phba
->link_state
== LPFC_CLEAR_LA
)
5488 clear_la_pending
= 1;
5490 clear_la_pending
= 0;
5492 if (vport
->port_state
< LPFC_VPORT_READY
)
5493 vport
->port_state
= LPFC_DISC_AUTH
;
5495 lpfc_set_disctmo(vport
);
5497 vport
->fc_prevDID
= vport
->fc_myDID
;
5498 vport
->num_disc_nodes
= 0;
5500 /* Start Discovery state <hba_state> */
5501 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5502 "0202 Start Discovery port state x%x "
5503 "flg x%x Data: x%x x%x x%x\n",
5504 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
5505 vport
->fc_adisc_cnt
, vport
->fc_npr_cnt
);
5507 /* First do ADISCs - if any */
5508 num_sent
= lpfc_els_disc_adisc(vport
);
5513 /* Register the VPI for SLI3, NPIV only. */
5514 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5515 !(vport
->fc_flag
& FC_PT2PT
) &&
5516 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
5517 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
5518 lpfc_issue_clear_la(phba
, vport
);
5519 lpfc_issue_reg_vpi(phba
, vport
);
5524 * For SLI2, we need to set port_state to READY and continue
5527 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
5528 /* If we get here, there is nothing to ADISC */
5529 lpfc_issue_clear_la(phba
, vport
);
5531 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
5532 vport
->num_disc_nodes
= 0;
5533 /* go thru NPR nodes and issue ELS PLOGIs */
5534 if (vport
->fc_npr_cnt
)
5535 lpfc_els_disc_plogi(vport
);
5537 if (!vport
->num_disc_nodes
) {
5538 spin_lock_irq(shost
->host_lock
);
5539 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
5540 spin_unlock_irq(shost
->host_lock
);
5541 lpfc_can_disctmo(vport
);
5544 vport
->port_state
= LPFC_VPORT_READY
;
5546 /* Next do PLOGIs - if any */
5547 num_sent
= lpfc_els_disc_plogi(vport
);
5552 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5553 /* Check to see if more RSCNs came in while we
5554 * were processing this one.
5556 if ((vport
->fc_rscn_id_cnt
== 0) &&
5557 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
5558 spin_lock_irq(shost
->host_lock
);
5559 vport
->fc_flag
&= ~FC_RSCN_MODE
;
5560 spin_unlock_irq(shost
->host_lock
);
5561 lpfc_can_disctmo(vport
);
5563 lpfc_els_handle_rscn(vport
);
5570 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5571 * ring the match the sppecified nodelist.
5574 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
5576 LIST_HEAD(completions
);
5578 struct lpfc_iocbq
*iocb
, *next_iocb
;
5579 struct lpfc_sli_ring
*pring
;
5581 pring
= lpfc_phba_elsring(phba
);
5582 if (unlikely(!pring
))
5585 /* Error matching iocb on txq or txcmplq
5586 * First check the txq.
5588 spin_lock_irq(&phba
->hbalock
);
5589 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
5590 if (iocb
->context1
!= ndlp
) {
5594 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
5595 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
5597 list_move_tail(&iocb
->list
, &completions
);
5601 /* Next check the txcmplq */
5602 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
5603 if (iocb
->context1
!= ndlp
) {
5607 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
5608 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
5609 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
, NULL
);
5612 spin_unlock_irq(&phba
->hbalock
);
5614 /* Cancel all the IOCBs from the completions list */
5615 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5620 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
5622 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5623 struct lpfc_hba
*phba
= vport
->phba
;
5625 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
5626 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5628 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5629 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
5630 lpfc_free_tx(phba
, ndlp
);
5637 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
5639 lpfc_els_flush_rscn(vport
);
5640 lpfc_els_flush_cmd(vport
);
5641 lpfc_disc_flush_list(vport
);
5644 /*****************************************************************************/
5646 * NAME: lpfc_disc_timeout
5648 * FUNCTION: Fibre Channel driver discovery timeout routine.
5650 * EXECUTION ENVIRONMENT: interrupt only
5658 /*****************************************************************************/
5660 lpfc_disc_timeout(struct timer_list
*t
)
5662 struct lpfc_vport
*vport
= from_timer(vport
, t
, fc_disctmo
);
5663 struct lpfc_hba
*phba
= vport
->phba
;
5664 uint32_t tmo_posted
;
5665 unsigned long flags
= 0;
5667 if (unlikely(!phba
))
5670 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
5671 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
5673 vport
->work_port_events
|= WORKER_DISC_TMO
;
5674 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
5677 lpfc_worker_wake_up(phba
);
5682 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
5684 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5685 struct lpfc_hba
*phba
= vport
->phba
;
5686 struct lpfc_sli
*psli
= &phba
->sli
;
5687 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5688 LPFC_MBOXQ_t
*initlinkmbox
;
5689 int rc
, clrlaerr
= 0;
5691 if (!(vport
->fc_flag
& FC_DISC_TMO
))
5694 spin_lock_irq(shost
->host_lock
);
5695 vport
->fc_flag
&= ~FC_DISC_TMO
;
5696 spin_unlock_irq(shost
->host_lock
);
5698 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5699 "disc timeout: state:x%x rtry:x%x flg:x%x",
5700 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
5702 switch (vport
->port_state
) {
5704 case LPFC_LOCAL_CFG_LINK
:
5706 * port_state is identically LPFC_LOCAL_CFG_LINK while
5707 * waiting for FAN timeout
5709 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
5710 "0221 FAN timeout\n");
5712 /* Start discovery by sending FLOGI, clean up old rpis */
5713 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5715 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
5717 if (ndlp
->nlp_type
& NLP_FABRIC
) {
5718 /* Clean up the ndlp on Fabric connections */
5719 lpfc_drop_node(vport
, ndlp
);
5721 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
5722 /* Fail outstanding IO now since device
5723 * is marked for PLOGI.
5725 lpfc_unreg_rpi(vport
, ndlp
);
5728 if (vport
->port_state
!= LPFC_FLOGI
) {
5729 if (phba
->sli_rev
<= LPFC_SLI_REV3
)
5730 lpfc_initial_flogi(vport
);
5732 lpfc_issue_init_vfi(vport
);
5739 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5740 /* Initial FLOGI timeout */
5741 lpfc_printf_vlog(vport
, KERN_ERR
,
5743 "0222 Initial %s timeout\n",
5744 vport
->vpi
? "FDISC" : "FLOGI");
5746 /* Assume no Fabric and go on with discovery.
5747 * Check for outstanding ELS FLOGI to abort.
5750 /* FLOGI failed, so just use loop map to make discovery list */
5751 lpfc_disc_list_loopmap(vport
);
5753 /* Start discovery */
5754 lpfc_disc_start(vport
);
5757 case LPFC_FABRIC_CFG_LINK
:
5758 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5760 lpfc_printf_vlog(vport
, KERN_ERR
,
5762 "0223 Timeout while waiting for "
5763 "NameServer login\n");
5764 /* Next look for NameServer ndlp */
5765 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5767 lpfc_els_abort(phba
, ndlp
);
5769 /* ReStart discovery */
5773 /* Check for wait for NameServer Rsp timeout */
5774 lpfc_printf_vlog(vport
, KERN_ERR
,
5776 "0224 NameServer Query timeout "
5778 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5780 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
5781 /* Try it one more time */
5782 vport
->fc_ns_retry
++;
5783 vport
->gidft_inp
= 0;
5784 rc
= lpfc_issue_gidft(vport
);
5788 vport
->fc_ns_retry
= 0;
5792 * Discovery is over.
5793 * set port_state to PORT_READY if SLI2.
5794 * cmpl_reg_vpi will set port_state to READY for SLI3.
5796 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5797 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5798 lpfc_issue_reg_vpi(phba
, vport
);
5800 lpfc_issue_clear_la(phba
, vport
);
5801 vport
->port_state
= LPFC_VPORT_READY
;
5805 /* Setup and issue mailbox INITIALIZE LINK command */
5806 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5807 if (!initlinkmbox
) {
5808 lpfc_printf_vlog(vport
, KERN_ERR
,
5810 "0206 Device Discovery "
5811 "completion error\n");
5812 phba
->link_state
= LPFC_HBA_ERROR
;
5816 lpfc_linkdown(phba
);
5817 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
5818 phba
->cfg_link_speed
);
5819 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
5820 initlinkmbox
->vport
= vport
;
5821 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5822 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
5823 lpfc_set_loopback_flag(phba
);
5824 if (rc
== MBX_NOT_FINISHED
)
5825 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
5829 case LPFC_DISC_AUTH
:
5830 /* Node Authentication timeout */
5831 lpfc_printf_vlog(vport
, KERN_ERR
,
5833 "0227 Node Authentication timeout\n");
5834 lpfc_disc_flush_list(vport
);
5837 * set port_state to PORT_READY if SLI2.
5838 * cmpl_reg_vpi will set port_state to READY for SLI3.
5840 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5841 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5842 lpfc_issue_reg_vpi(phba
, vport
);
5843 else { /* NPIV Not enabled */
5844 lpfc_issue_clear_la(phba
, vport
);
5845 vport
->port_state
= LPFC_VPORT_READY
;
5850 case LPFC_VPORT_READY
:
5851 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5852 lpfc_printf_vlog(vport
, KERN_ERR
,
5854 "0231 RSCN timeout Data: x%x "
5856 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5858 /* Cleanup any outstanding ELS commands */
5859 lpfc_els_flush_cmd(vport
);
5861 lpfc_els_flush_rscn(vport
);
5862 lpfc_disc_flush_list(vport
);
5867 lpfc_printf_vlog(vport
, KERN_ERR
,
5869 "0273 Unexpected discovery timeout, "
5870 "vport State x%x\n", vport
->port_state
);
5874 switch (phba
->link_state
) {
5876 /* CLEAR LA timeout */
5877 lpfc_printf_vlog(vport
, KERN_ERR
,
5879 "0228 CLEAR LA timeout\n");
5884 lpfc_issue_clear_la(phba
, vport
);
5886 case LPFC_LINK_UNKNOWN
:
5887 case LPFC_WARM_START
:
5888 case LPFC_INIT_START
:
5889 case LPFC_INIT_MBX_CMDS
:
5890 case LPFC_LINK_DOWN
:
5891 case LPFC_HBA_ERROR
:
5892 lpfc_printf_vlog(vport
, KERN_ERR
,
5894 "0230 Unexpected timeout, hba link "
5895 "state x%x\n", phba
->link_state
);
5899 case LPFC_HBA_READY
:
5904 lpfc_disc_flush_list(vport
);
5905 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5906 psli
->sli3_ring
[(LPFC_EXTRA_RING
)].flag
&=
5907 ~LPFC_STOP_IOCB_EVENT
;
5908 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&=
5909 ~LPFC_STOP_IOCB_EVENT
;
5911 vport
->port_state
= LPFC_VPORT_READY
;
5917 * This routine handles processing a NameServer REG_LOGIN mailbox
5918 * command upon completion. It is setup in the LPFC_MBOXQ
5919 * as the completion routine when the command is
5920 * handed off to the SLI layer.
5923 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5925 MAILBOX_t
*mb
= &pmb
->u
.mb
;
5926 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
5927 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
5928 struct lpfc_vport
*vport
= pmb
->vport
;
5930 pmb
->ctx_buf
= NULL
;
5931 pmb
->ctx_ndlp
= NULL
;
5933 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5934 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
5935 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
5936 ndlp
->nlp_type
|= NLP_FABRIC
;
5937 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
5938 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
| LOG_DISCOVERY
,
5939 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
5940 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5941 kref_read(&ndlp
->kref
),
5944 * Start issuing Fabric-Device Management Interface (FDMI) command to
5945 * 0xfffffa (FDMI well known port).
5946 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5947 * DPRT -> RPRT (vports)
5949 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
5950 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
, 0);
5952 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DPRT
, 0);
5955 /* decrement the node reference count held for this callback
5959 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5961 mempool_free(pmb
, phba
->mbox_mem_pool
);
5967 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
5969 uint16_t *rpi
= param
;
5971 return ndlp
->nlp_rpi
== *rpi
;
5975 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
5977 return memcmp(&ndlp
->nlp_portname
, param
,
5978 sizeof(ndlp
->nlp_portname
)) == 0;
5981 static struct lpfc_nodelist
*
5982 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
5984 struct lpfc_nodelist
*ndlp
;
5986 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5987 if (filter(ndlp
, param
)) {
5988 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5989 "3185 FIND node filter %ps DID "
5990 "ndlp x%px did x%x flg x%x st x%x "
5991 "xri x%x type x%x rpi x%x\n",
5992 filter
, ndlp
, ndlp
->nlp_DID
,
5993 ndlp
->nlp_flag
, ndlp
->nlp_state
,
5994 ndlp
->nlp_xri
, ndlp
->nlp_type
,
5999 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
6000 "3186 FIND node filter %ps NOT FOUND.\n", filter
);
6005 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6006 * returns the node list element pointer else return NULL.
6008 struct lpfc_nodelist
*
6009 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
6011 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
6015 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6016 * returns the node element list pointer else return NULL.
6018 struct lpfc_nodelist
*
6019 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
6021 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6022 struct lpfc_nodelist
*ndlp
;
6024 spin_lock_irq(shost
->host_lock
);
6025 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
6026 spin_unlock_irq(shost
->host_lock
);
6031 * This routine looks up the ndlp lists for the given RPI. If the rpi
6032 * is found, the routine returns the node element list pointer else
6035 struct lpfc_nodelist
*
6036 lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
6038 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6039 struct lpfc_nodelist
*ndlp
;
6040 unsigned long flags
;
6042 spin_lock_irqsave(shost
->host_lock
, flags
);
6043 ndlp
= __lpfc_findnode_rpi(vport
, rpi
);
6044 spin_unlock_irqrestore(shost
->host_lock
, flags
);
6049 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6050 * @phba: pointer to lpfc hba data structure.
6051 * @vpi: the physical host virtual N_Port identifier.
6053 * This routine finds a vport on a HBA (referred by @phba) through a
6054 * @vpi. The function walks the HBA's vport list and returns the address
6055 * of the vport with the matching @vpi.
6058 * NULL - No vport with the matching @vpi found
6059 * Otherwise - Address to the vport with the matching @vpi.
6062 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
6064 struct lpfc_vport
*vport
;
6065 unsigned long flags
;
6068 /* The physical ports are always vpi 0 - translate is unnecessary. */
6071 * Translate the physical vpi to the logical vpi. The
6072 * vport stores the logical vpi.
6074 for (i
= 0; i
< phba
->max_vpi
; i
++) {
6075 if (vpi
== phba
->vpi_ids
[i
])
6079 if (i
>= phba
->max_vpi
) {
6080 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6081 "2936 Could not find Vport mapped "
6082 "to vpi %d\n", vpi
);
6087 spin_lock_irqsave(&phba
->port_list_lock
, flags
);
6088 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
6089 if (vport
->vpi
== i
) {
6090 spin_unlock_irqrestore(&phba
->port_list_lock
, flags
);
6094 spin_unlock_irqrestore(&phba
->port_list_lock
, flags
);
6098 struct lpfc_nodelist
*
6099 lpfc_nlp_init(struct lpfc_vport
*vport
, uint32_t did
)
6101 struct lpfc_nodelist
*ndlp
;
6102 int rpi
= LPFC_RPI_ALLOC_ERROR
;
6104 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6105 rpi
= lpfc_sli4_alloc_rpi(vport
->phba
);
6106 if (rpi
== LPFC_RPI_ALLOC_ERROR
)
6110 ndlp
= mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
6112 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6113 lpfc_sli4_free_rpi(vport
->phba
, rpi
);
6117 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
6119 spin_lock_init(&ndlp
->lock
);
6121 lpfc_initialize_node(vport
, ndlp
, did
);
6122 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
6123 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6124 ndlp
->nlp_rpi
= rpi
;
6125 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
| LOG_DISCOVERY
,
6126 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6127 "flg:x%x refcnt:%d\n",
6128 ndlp
, ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6129 ndlp
->nlp_flag
, kref_read(&ndlp
->kref
));
6131 ndlp
->active_rrqs_xri_bitmap
=
6132 mempool_alloc(vport
->phba
->active_rrq_pool
,
6134 if (ndlp
->active_rrqs_xri_bitmap
)
6135 memset(ndlp
->active_rrqs_xri_bitmap
, 0,
6136 ndlp
->phba
->cfg_rrq_xri_bitmap_sz
);
6141 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
6142 "node init: did:x%x",
6143 ndlp
->nlp_DID
, 0, 0);
6148 /* This routine releases all resources associated with a specifc NPort's ndlp
6149 * and mempool_free's the nodelist.
6152 lpfc_nlp_release(struct kref
*kref
)
6154 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
6156 struct lpfc_vport
*vport
= ndlp
->vport
;
6158 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6159 "node release: did:x%x flg:x%x type:x%x",
6160 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
6162 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
6163 "0279 %s: ndlp:%p did %x refcnt:%d rpi:%x\n",
6164 __func__
, ndlp
, ndlp
->nlp_DID
,
6165 kref_read(&ndlp
->kref
), ndlp
->nlp_rpi
);
6167 /* remove ndlp from action. */
6168 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
6169 lpfc_cleanup_node(vport
, ndlp
);
6171 /* Clear Node key fields to give other threads notice
6172 * that this node memory is not valid anymore.
6175 ndlp
->nlp_state
= NLP_STE_FREED_NODE
;
6177 ndlp
->fc4_xpt_flags
= 0;
6179 /* free ndlp memory for final ndlp release */
6180 kfree(ndlp
->lat_data
);
6181 if (ndlp
->phba
->sli_rev
== LPFC_SLI_REV4
)
6182 mempool_free(ndlp
->active_rrqs_xri_bitmap
,
6183 ndlp
->phba
->active_rrq_pool
);
6184 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
6187 /* This routine bumps the reference count for a ndlp structure to ensure
6188 * that one discovery thread won't free a ndlp while another discovery thread
6191 struct lpfc_nodelist
*
6192 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
6194 unsigned long flags
;
6197 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6198 "node get: did:x%x flg:x%x refcnt:x%x",
6199 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6200 kref_read(&ndlp
->kref
));
6202 /* The check of ndlp usage to prevent incrementing the
6203 * ndlp reference count that is in the process of being
6206 spin_lock_irqsave(&ndlp
->lock
, flags
);
6207 if (!kref_get_unless_zero(&ndlp
->kref
)) {
6208 spin_unlock_irqrestore(&ndlp
->lock
, flags
);
6209 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6210 "0276 %s: ndlp:x%px refcnt:%d\n",
6211 __func__
, (void *)ndlp
, kref_read(&ndlp
->kref
));
6214 spin_unlock_irqrestore(&ndlp
->lock
, flags
);
6216 WARN_ONCE(!ndlp
, "**** %s, get ref on NULL ndlp!", __func__
);
6222 /* This routine decrements the reference count for a ndlp structure. If the
6223 * count goes to 0, this indicates the associated nodelist should be freed.
6226 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
6229 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6230 "node put: did:x%x flg:x%x refcnt:x%x",
6231 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6232 kref_read(&ndlp
->kref
));
6234 WARN_ONCE(!ndlp
, "**** %s, put ref on NULL ndlp!", __func__
);
6237 return ndlp
? kref_put(&ndlp
->kref
, lpfc_nlp_release
) : 0;
6240 /* This routine free's the specified nodelist if it is not in use
6241 * by any other discovery thread. This routine returns 1 if the
6242 * ndlp has been freed. A return value of 0 indicates the ndlp is
6243 * not yet been released.
6246 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
6248 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6249 "node not used: did:x%x flg:x%x refcnt:x%x",
6250 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6251 kref_read(&ndlp
->kref
));
6252 if (kref_read(&ndlp
->kref
) == 1)
6253 if (lpfc_nlp_put(ndlp
))
6259 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6260 * @phba: Pointer to hba context object.
6262 * This function iterate through all FC nodes associated
6263 * will all vports to check if there is any node with
6264 * fc_rports associated with it. If there is an fc_rport
6265 * associated with the node, then the node is either in
6266 * discovered state or its devloss_timer is pending.
6269 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
6271 struct lpfc_vport
**vports
;
6273 struct lpfc_nodelist
*ndlp
;
6274 struct Scsi_Host
*shost
;
6276 vports
= lpfc_create_vport_work_array(phba
);
6278 /* If driver cannot allocate memory, indicate fcf is in use */
6282 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6283 shost
= lpfc_shost_from_vport(vports
[i
]);
6284 spin_lock_irq(shost
->host_lock
);
6286 * IF the CVL_RCVD bit is not set then we have sent the
6288 * If dev_loss fires while we are waiting we do not want to
6291 if (!(vports
[i
]->fc_flag
& FC_VPORT_CVL_RCVD
)) {
6292 spin_unlock_irq(shost
->host_lock
);
6296 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
6298 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
6300 spin_unlock_irq(shost
->host_lock
);
6302 } else if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
6304 lpfc_printf_log(phba
, KERN_INFO
,
6305 LOG_NODE
| LOG_DISCOVERY
,
6306 "2624 RPI %x DID %x flag %x "
6307 "still logged in\n",
6308 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6312 spin_unlock_irq(shost
->host_lock
);
6315 lpfc_destroy_vport_work_array(phba
, vports
);
6320 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6321 * @phba: Pointer to hba context object.
6322 * @mboxq: Pointer to mailbox object.
6324 * This function frees memory associated with the mailbox command.
6327 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6329 struct lpfc_vport
*vport
= mboxq
->vport
;
6330 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6332 if (mboxq
->u
.mb
.mbxStatus
) {
6333 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6334 "2555 UNREG_VFI mbxStatus error x%x "
6336 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6338 spin_lock_irq(shost
->host_lock
);
6339 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
6340 spin_unlock_irq(shost
->host_lock
);
6341 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6346 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6347 * @phba: Pointer to hba context object.
6348 * @mboxq: Pointer to mailbox object.
6350 * This function frees memory associated with the mailbox command.
6353 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6355 struct lpfc_vport
*vport
= mboxq
->vport
;
6357 if (mboxq
->u
.mb
.mbxStatus
) {
6358 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6359 "2550 UNREG_FCFI mbxStatus error x%x "
6361 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6363 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6368 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6369 * @phba: Pointer to hba context object.
6371 * This function prepare the HBA for unregistering the currently registered
6372 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6376 lpfc_unregister_fcf_prep(struct lpfc_hba
*phba
)
6378 struct lpfc_vport
**vports
;
6379 struct lpfc_nodelist
*ndlp
;
6380 struct Scsi_Host
*shost
;
6383 /* Unregister RPIs */
6384 if (lpfc_fcf_inuse(phba
))
6385 lpfc_unreg_hba_rpis(phba
);
6387 /* At this point, all discovery is aborted */
6388 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
6390 /* Unregister VPIs */
6391 vports
= lpfc_create_vport_work_array(phba
);
6392 if (vports
&& (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
6393 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6394 /* Stop FLOGI/FDISC retries */
6395 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6397 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6398 lpfc_cleanup_pending_mbox(vports
[i
]);
6399 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6400 lpfc_sli4_unreg_all_rpis(vports
[i
]);
6401 lpfc_mbx_unreg_vpi(vports
[i
]);
6402 shost
= lpfc_shost_from_vport(vports
[i
]);
6403 spin_lock_irq(shost
->host_lock
);
6404 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6405 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6406 spin_unlock_irq(shost
->host_lock
);
6408 lpfc_destroy_vport_work_array(phba
, vports
);
6409 if (i
== 0 && (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))) {
6410 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6412 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
6413 lpfc_cleanup_pending_mbox(phba
->pport
);
6414 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6415 lpfc_sli4_unreg_all_rpis(phba
->pport
);
6416 lpfc_mbx_unreg_vpi(phba
->pport
);
6417 shost
= lpfc_shost_from_vport(phba
->pport
);
6418 spin_lock_irq(shost
->host_lock
);
6419 phba
->pport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6420 phba
->pport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6421 spin_unlock_irq(shost
->host_lock
);
6424 /* Cleanup any outstanding ELS commands */
6425 lpfc_els_flush_all_cmd(phba
);
6427 /* Unregister the physical port VFI */
6428 rc
= lpfc_issue_unreg_vfi(phba
->pport
);
6433 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6434 * @phba: Pointer to hba context object.
6436 * This function issues synchronous unregister FCF mailbox command to HBA to
6437 * unregister the currently registered FCF record. The driver does not reset
6438 * the driver FCF usage state flags.
6440 * Return 0 if successfully issued, none-zero otherwise.
6443 lpfc_sli4_unregister_fcf(struct lpfc_hba
*phba
)
6448 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6450 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6451 "2551 UNREG_FCFI mbox allocation failed"
6452 "HBA state x%x\n", phba
->pport
->port_state
);
6455 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
6456 mbox
->vport
= phba
->pport
;
6457 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
6458 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
6460 if (rc
== MBX_NOT_FINISHED
) {
6461 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6462 "2552 Unregister FCFI command failed rc x%x "
6464 rc
, phba
->pport
->port_state
);
6471 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6472 * @phba: Pointer to hba context object.
6474 * This function unregisters the currently reigstered FCF. This function
6475 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6478 lpfc_unregister_fcf_rescan(struct lpfc_hba
*phba
)
6482 /* Preparation for unregistering fcf */
6483 rc
= lpfc_unregister_fcf_prep(phba
);
6485 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6486 "2748 Failed to prepare for unregistering "
6487 "HBA's FCF record: rc=%d\n", rc
);
6491 /* Now, unregister FCF record and reset HBA FCF state */
6492 rc
= lpfc_sli4_unregister_fcf(phba
);
6495 /* Reset HBA FCF states after successful unregister FCF */
6496 phba
->fcf
.fcf_flag
= 0;
6497 phba
->fcf
.current_rec
.flag
= 0;
6500 * If driver is not unloading, check if there is any other
6501 * FCF record that can be used for discovery.
6503 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
6504 (phba
->link_state
< LPFC_LINK_UP
))
6507 /* This is considered as the initial FCF discovery scan */
6508 spin_lock_irq(&phba
->hbalock
);
6509 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
6510 spin_unlock_irq(&phba
->hbalock
);
6512 /* Reset FCF roundrobin bmask for new discovery */
6513 lpfc_sli4_clear_fcf_rr_bmask(phba
);
6515 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
6518 spin_lock_irq(&phba
->hbalock
);
6519 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
6520 spin_unlock_irq(&phba
->hbalock
);
6521 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6522 "2553 lpfc_unregister_unused_fcf failed "
6523 "to read FCF record HBA state x%x\n",
6524 phba
->pport
->port_state
);
6529 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6530 * @phba: Pointer to hba context object.
6532 * This function just unregisters the currently reigstered FCF. It does not
6533 * try to find another FCF for discovery.
6536 lpfc_unregister_fcf(struct lpfc_hba
*phba
)
6540 /* Preparation for unregistering fcf */
6541 rc
= lpfc_unregister_fcf_prep(phba
);
6543 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6544 "2749 Failed to prepare for unregistering "
6545 "HBA's FCF record: rc=%d\n", rc
);
6549 /* Now, unregister FCF record and reset HBA FCF state */
6550 rc
= lpfc_sli4_unregister_fcf(phba
);
6553 /* Set proper HBA FCF states after successful unregister FCF */
6554 spin_lock_irq(&phba
->hbalock
);
6555 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
6556 spin_unlock_irq(&phba
->hbalock
);
6560 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6561 * @phba: Pointer to hba context object.
6563 * This function check if there are any connected remote port for the FCF and
6564 * if all the devices are disconnected, this function unregister FCFI.
6565 * This function also tries to use another FCF for discovery.
6568 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
6571 * If HBA is not running in FIP mode, if HBA does not support
6572 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6573 * registered, do nothing.
6575 spin_lock_irq(&phba
->hbalock
);
6576 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) ||
6577 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
6578 !(phba
->hba_flag
& HBA_FIP_SUPPORT
) ||
6579 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) ||
6580 (phba
->pport
->port_state
== LPFC_FLOGI
)) {
6581 spin_unlock_irq(&phba
->hbalock
);
6584 spin_unlock_irq(&phba
->hbalock
);
6586 if (lpfc_fcf_inuse(phba
))
6589 lpfc_unregister_fcf_rescan(phba
);
6593 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6594 * @phba: Pointer to hba context object.
6595 * @buff: Buffer containing the FCF connection table as in the config
6597 * This function create driver data structure for the FCF connection
6598 * record table read from config region 23.
6601 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
6604 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
6605 struct lpfc_fcf_conn_hdr
*conn_hdr
;
6606 struct lpfc_fcf_conn_rec
*conn_rec
;
6607 uint32_t record_count
;
6610 /* Free the current connect table */
6611 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
6612 &phba
->fcf_conn_rec_list
, list
) {
6613 list_del_init(&conn_entry
->list
);
6617 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
6618 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
6619 sizeof(struct lpfc_fcf_conn_rec
);
6621 conn_rec
= (struct lpfc_fcf_conn_rec
*)
6622 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
6624 for (i
= 0; i
< record_count
; i
++) {
6625 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
6627 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
6630 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6631 "2566 Failed to allocate connection"
6636 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
6637 sizeof(struct lpfc_fcf_conn_rec
));
6638 list_add_tail(&conn_entry
->list
,
6639 &phba
->fcf_conn_rec_list
);
6642 if (!list_empty(&phba
->fcf_conn_rec_list
)) {
6644 list_for_each_entry(conn_entry
, &phba
->fcf_conn_rec_list
,
6646 conn_rec
= &conn_entry
->conn_rec
;
6647 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6648 "3345 FCF connection list rec[%02d]: "
6649 "flags:x%04x, vtag:x%04x, "
6650 "fabric_name:x%02x:%02x:%02x:%02x:"
6651 "%02x:%02x:%02x:%02x, "
6652 "switch_name:x%02x:%02x:%02x:%02x:"
6653 "%02x:%02x:%02x:%02x\n", i
++,
6654 conn_rec
->flags
, conn_rec
->vlan_tag
,
6655 conn_rec
->fabric_name
[0],
6656 conn_rec
->fabric_name
[1],
6657 conn_rec
->fabric_name
[2],
6658 conn_rec
->fabric_name
[3],
6659 conn_rec
->fabric_name
[4],
6660 conn_rec
->fabric_name
[5],
6661 conn_rec
->fabric_name
[6],
6662 conn_rec
->fabric_name
[7],
6663 conn_rec
->switch_name
[0],
6664 conn_rec
->switch_name
[1],
6665 conn_rec
->switch_name
[2],
6666 conn_rec
->switch_name
[3],
6667 conn_rec
->switch_name
[4],
6668 conn_rec
->switch_name
[5],
6669 conn_rec
->switch_name
[6],
6670 conn_rec
->switch_name
[7]);
6676 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6677 * @phba: Pointer to hba context object.
6678 * @buff: Buffer containing the FCoE parameter data structure.
6680 * This function update driver data structure with config
6681 * parameters read from config region 23.
6684 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
6687 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
6688 struct lpfc_fcoe_params
*fcoe_param
;
6690 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
6692 fcoe_param
= (struct lpfc_fcoe_params
*)
6693 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
6695 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
6696 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
6699 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
6700 phba
->valid_vlan
= 1;
6701 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
6705 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
6706 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
6707 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
6712 * lpfc_get_rec_conf23 - Get a record type in config region data.
6713 * @buff: Buffer containing config region 23 data.
6714 * @size: Size of the data buffer.
6715 * @rec_type: Record type to be searched.
6717 * This function searches config region data to find the beginning
6718 * of the record specified by record_type. If record found, this
6719 * function return pointer to the record else return NULL.
6722 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
6724 uint32_t offset
= 0, rec_length
;
6726 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
6727 (size
< sizeof(uint32_t)))
6730 rec_length
= buff
[offset
+ 1];
6733 * One TLV record has one word header and number of data words
6734 * specified in the rec_length field of the record header.
6736 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
6738 if (buff
[offset
] == rec_type
)
6739 return &buff
[offset
];
6741 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
6744 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
6745 rec_length
= buff
[offset
+ 1];
6751 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6752 * @phba: Pointer to lpfc_hba data structure.
6753 * @buff: Buffer containing config region 23 data.
6754 * @size: Size of the data buffer.
6756 * This function parses the FCoE config parameters in config region 23 and
6757 * populate driver data structure with the parameters.
6760 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
6764 uint32_t offset
= 0;
6768 * If data size is less than 2 words signature and version cannot be
6771 if (size
< 2*sizeof(uint32_t))
6774 /* Check the region signature first */
6775 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
6776 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6777 "2567 Config region 23 has bad signature\n");
6783 /* Check the data structure version */
6784 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
6785 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
6786 "2568 Config region 23 has bad version\n");
6791 /* Read FCoE param record */
6792 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6793 size
- offset
, FCOE_PARAM_TYPE
);
6795 lpfc_read_fcoe_param(phba
, rec_ptr
);
6797 /* Read FCF connection table */
6798 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6799 size
- offset
, FCOE_CONN_TBL_TYPE
);
6801 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);