1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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>
32 #include <scsi/scsi.h>
33 #include <scsi/scsi_device.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
38 #include <linux/nvme-fc-driver.h>
43 #include "lpfc_disc.h"
45 #include "lpfc_sli4.h"
47 #include "lpfc_scsi.h"
48 #include "lpfc_nvme.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_crtn.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_debugfs.h"
54 /* AlpaArray for assignment of scsid for scan-down and bind_method */
55 static uint8_t lpfcAlpaArray
[] = {
56 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
57 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
58 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
59 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
60 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
61 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
62 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
63 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
64 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
65 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
66 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
67 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
68 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
71 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
72 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
73 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
74 static int lpfc_fcf_inuse(struct lpfc_hba
*);
77 lpfc_terminate_rport_io(struct fc_rport
*rport
)
79 struct lpfc_rport_data
*rdata
;
80 struct lpfc_nodelist
* ndlp
;
81 struct lpfc_hba
*phba
;
83 rdata
= rport
->dd_data
;
86 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
87 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
88 printk(KERN_ERR
"Cannot find remote node"
89 " to terminate I/O Data x%x\n",
96 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
97 "rport terminate: sid:x%x did:x%x flg:x%x",
98 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
100 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
101 lpfc_sli_abort_iocb(ndlp
->vport
,
102 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
103 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
108 * This function will be called when dev_loss_tmo fire.
111 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
113 struct lpfc_rport_data
*rdata
;
114 struct lpfc_nodelist
* ndlp
;
115 struct lpfc_vport
*vport
;
116 struct Scsi_Host
*shost
;
117 struct lpfc_hba
*phba
;
118 struct lpfc_work_evt
*evtp
;
122 rdata
= rport
->dd_data
;
124 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
130 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
131 "rport devlosscb: sid:x%x did:x%x flg:x%x",
132 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
134 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
135 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
136 ndlp
->nlp_DID
, ndlp
->rport
, ndlp
->nlp_flag
);
138 /* Don't defer this if we are in the process of deleting the vport
139 * or unloading the driver. The unload will cleanup the node
140 * appropriately we just need to cleanup the ndlp rport info here.
142 if (vport
->load_flag
& FC_UNLOADING
) {
143 put_node
= rdata
->pnode
!= NULL
;
144 put_rport
= ndlp
->rport
!= NULL
;
150 put_device(&rport
->dev
);
154 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
157 if (rport
->port_name
!= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
))
158 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
159 "6789 rport name %llx != node port name %llx",
161 wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
));
163 evtp
= &ndlp
->dev_loss_evt
;
165 if (!list_empty(&evtp
->evt_listp
)) {
166 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
167 "6790 rport name %llx dev_loss_evt pending",
172 shost
= lpfc_shost_from_vport(vport
);
173 spin_lock_irq(shost
->host_lock
);
174 ndlp
->nlp_flag
|= NLP_IN_DEV_LOSS
;
175 spin_unlock_irq(shost
->host_lock
);
177 /* We need to hold the node by incrementing the reference
178 * count until this queued work is done
180 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
182 spin_lock_irq(&phba
->hbalock
);
183 if (evtp
->evt_arg1
) {
184 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
185 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
186 lpfc_worker_wake_up(phba
);
188 spin_unlock_irq(&phba
->hbalock
);
194 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
195 * @ndlp: Pointer to remote node object.
197 * This function is called from the worker thread when devloss timeout timer
198 * expires. For SLI4 host, this routine shall return 1 when at lease one
199 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
200 * routine shall return 0 when there is no remote node is still in use of FCF
201 * when devloss timeout happened to this @ndlp.
204 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
206 struct lpfc_rport_data
*rdata
;
207 struct fc_rport
*rport
;
208 struct lpfc_vport
*vport
;
209 struct lpfc_hba
*phba
;
210 struct Scsi_Host
*shost
;
218 shost
= lpfc_shost_from_vport(vport
);
220 spin_lock_irq(shost
->host_lock
);
221 ndlp
->nlp_flag
&= ~NLP_IN_DEV_LOSS
;
222 spin_unlock_irq(shost
->host_lock
);
227 name
= (uint8_t *) &ndlp
->nlp_portname
;
230 if (phba
->sli_rev
== LPFC_SLI_REV4
)
231 fcf_inuse
= lpfc_fcf_inuse(phba
);
233 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
234 "rport devlosstmo:did:x%x type:x%x id:x%x",
235 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
237 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
238 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
239 ndlp
->nlp_DID
, ndlp
->rport
, ndlp
->nlp_flag
);
242 * lpfc_nlp_remove if reached with dangling rport drops the
243 * reference. To make sure that does not happen clear rport
244 * pointer in ndlp before lpfc_nlp_put.
246 rdata
= rport
->dd_data
;
248 /* Don't defer this if we are in the process of deleting the vport
249 * or unloading the driver. The unload will cleanup the node
250 * appropriately we just need to cleanup the ndlp rport info here.
252 if (vport
->load_flag
& FC_UNLOADING
) {
253 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
254 /* flush the target */
255 lpfc_sli_abort_iocb(vport
,
256 &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
257 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
259 put_node
= rdata
->pnode
!= NULL
;
264 put_device(&rport
->dev
);
269 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
270 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
271 "0284 Devloss timeout Ignored on "
272 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
274 *name
, *(name
+1), *(name
+2), *(name
+3),
275 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
280 put_node
= rdata
->pnode
!= NULL
;
285 put_device(&rport
->dev
);
287 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_DISCOVERY
,
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_DISCOVERY
,
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
->nlp_flag
& NLP_DELAY_TMO
) &&
317 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
318 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
319 (ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) &&
320 (ndlp
->nlp_state
!= NLP_STE_PRLI_ISSUE
))
321 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
327 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
328 * @phba: Pointer to hba context object.
329 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
330 * @nlp_did: remote node identifer with devloss timeout.
332 * This function is called from the worker thread after invoking devloss
333 * timeout handler and releasing the reference count for the ndlp with
334 * which the devloss timeout was handled for SLI4 host. For the devloss
335 * timeout of the last remote node which had been in use of FCF, when this
336 * routine is invoked, it shall be guaranteed that none of the remote are
337 * in-use of FCF. When devloss timeout to the last remote using the FCF,
338 * if the FIP engine is neither in FCF table scan process nor roundrobin
339 * failover process, the in-use FCF shall be unregistered. If the FIP
340 * engine is in FCF discovery process, the devloss timeout state shall
341 * be set for either the FCF table scan process or roundrobin failover
342 * process to unregister the in-use FCF.
345 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba
*phba
, int fcf_inuse
,
348 /* If devloss timeout happened to a remote node when FCF had no
349 * longer been in-use, do nothing.
354 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) && !lpfc_fcf_inuse(phba
)) {
355 spin_lock_irq(&phba
->hbalock
);
356 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
357 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
358 spin_unlock_irq(&phba
->hbalock
);
361 phba
->hba_flag
|= HBA_DEVLOSS_TMO
;
362 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
363 "2847 Last remote node (x%x) using "
364 "FCF devloss tmo\n", nlp_did
);
366 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PROG
) {
367 spin_unlock_irq(&phba
->hbalock
);
368 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
369 "2868 Devloss tmo to FCF rediscovery "
373 if (!(phba
->hba_flag
& (FCF_TS_INPROG
| FCF_RR_INPROG
))) {
374 spin_unlock_irq(&phba
->hbalock
);
375 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
376 "2869 Devloss tmo to idle FIP engine, "
377 "unreg in-use FCF and rescan.\n");
378 /* Unregister in-use FCF and rescan */
379 lpfc_unregister_fcf_rescan(phba
);
382 spin_unlock_irq(&phba
->hbalock
);
383 if (phba
->hba_flag
& FCF_TS_INPROG
)
384 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
385 "2870 FCF table scan in progress\n");
386 if (phba
->hba_flag
& FCF_RR_INPROG
)
387 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
388 "2871 FLOGI roundrobin FCF failover "
391 lpfc_unregister_unused_fcf(phba
);
395 * lpfc_alloc_fast_evt - Allocates data structure for posting event
396 * @phba: Pointer to hba context object.
398 * This function is called from the functions which need to post
399 * events from interrupt context. This function allocates data
400 * structure required for posting event. It also keeps track of
401 * number of events pending and prevent event storm when there are
404 struct lpfc_fast_path_event
*
405 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
406 struct lpfc_fast_path_event
*ret
;
408 /* If there are lot of fast event do not exhaust memory due to this */
409 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
412 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
415 atomic_inc(&phba
->fast_event_count
);
416 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
417 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
423 * lpfc_free_fast_evt - Frees event data structure
424 * @phba: Pointer to hba context object.
425 * @evt: Event object which need to be freed.
427 * This function frees the data structure required for posting
431 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
432 struct lpfc_fast_path_event
*evt
) {
434 atomic_dec(&phba
->fast_event_count
);
439 * lpfc_send_fastpath_evt - Posts events generated from fast path
440 * @phba: Pointer to hba context object.
441 * @evtp: Event data structure.
443 * This function is called from worker thread, when the interrupt
444 * context need to post an event. This function posts the event
445 * to fc transport netlink interface.
448 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
449 struct lpfc_work_evt
*evtp
)
451 unsigned long evt_category
, evt_sub_category
;
452 struct lpfc_fast_path_event
*fast_evt_data
;
454 uint32_t evt_data_size
;
455 struct Scsi_Host
*shost
;
457 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
460 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
461 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
462 fabric_evt
.subcategory
;
463 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
464 if (evt_category
== FC_REG_FABRIC_EVENT
) {
465 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
466 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
467 evt_data_size
= sizeof(fast_evt_data
->un
.
469 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
470 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
471 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
472 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
474 lpfc_free_fast_evt(phba
, fast_evt_data
);
477 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
478 switch (evt_sub_category
) {
479 case LPFC_EVENT_QFULL
:
480 case LPFC_EVENT_DEVBSY
:
481 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
482 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
484 case LPFC_EVENT_CHECK_COND
:
485 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
486 evt_data_size
= sizeof(fast_evt_data
->un
.
489 case LPFC_EVENT_VARQUEDEPTH
:
490 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
491 evt_data_size
= sizeof(fast_evt_data
->un
.
495 lpfc_free_fast_evt(phba
, fast_evt_data
);
499 lpfc_free_fast_evt(phba
, fast_evt_data
);
503 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
504 fc_host_post_vendor_event(shost
,
505 fc_get_event_number(),
510 lpfc_free_fast_evt(phba
, fast_evt_data
);
515 lpfc_work_list_done(struct lpfc_hba
*phba
)
517 struct lpfc_work_evt
*evtp
= NULL
;
518 struct lpfc_nodelist
*ndlp
;
523 spin_lock_irq(&phba
->hbalock
);
524 while (!list_empty(&phba
->work_list
)) {
525 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
527 spin_unlock_irq(&phba
->hbalock
);
530 case LPFC_EVT_ELS_RETRY
:
531 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
532 lpfc_els_retry_delay_handler(ndlp
);
533 free_evt
= 0; /* evt is part of ndlp */
534 /* decrement the node reference count held
535 * for this queued work
539 case LPFC_EVT_DEV_LOSS
:
540 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
541 fcf_inuse
= lpfc_dev_loss_tmo_handler(ndlp
);
543 /* decrement the node reference count held for
546 nlp_did
= ndlp
->nlp_DID
;
548 if (phba
->sli_rev
== LPFC_SLI_REV4
)
549 lpfc_sli4_post_dev_loss_tmo_handler(phba
,
553 case LPFC_EVT_ONLINE
:
554 if (phba
->link_state
< LPFC_LINK_DOWN
)
555 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
557 *(int *) (evtp
->evt_arg1
) = 0;
558 complete((struct completion
*)(evtp
->evt_arg2
));
560 case LPFC_EVT_OFFLINE_PREP
:
561 if (phba
->link_state
>= LPFC_LINK_DOWN
)
562 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
563 *(int *)(evtp
->evt_arg1
) = 0;
564 complete((struct completion
*)(evtp
->evt_arg2
));
566 case LPFC_EVT_OFFLINE
:
568 lpfc_sli_brdrestart(phba
);
569 *(int *)(evtp
->evt_arg1
) =
570 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
571 lpfc_unblock_mgmt_io(phba
);
572 complete((struct completion
*)(evtp
->evt_arg2
));
574 case LPFC_EVT_WARM_START
:
576 lpfc_reset_barrier(phba
);
577 lpfc_sli_brdreset(phba
);
578 lpfc_hba_down_post(phba
);
579 *(int *)(evtp
->evt_arg1
) =
580 lpfc_sli_brdready(phba
, HS_MBRDY
);
581 lpfc_unblock_mgmt_io(phba
);
582 complete((struct completion
*)(evtp
->evt_arg2
));
586 *(int *)(evtp
->evt_arg1
)
587 = (phba
->pport
->stopped
)
588 ? 0 : lpfc_sli_brdkill(phba
);
589 lpfc_unblock_mgmt_io(phba
);
590 complete((struct completion
*)(evtp
->evt_arg2
));
592 case LPFC_EVT_FASTPATH_MGMT_EVT
:
593 lpfc_send_fastpath_evt(phba
, evtp
);
596 case LPFC_EVT_RESET_HBA
:
597 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
598 lpfc_reset_hba(phba
);
603 spin_lock_irq(&phba
->hbalock
);
605 spin_unlock_irq(&phba
->hbalock
);
610 lpfc_work_done(struct lpfc_hba
*phba
)
612 struct lpfc_sli_ring
*pring
;
613 uint32_t ha_copy
, status
, control
, work_port_events
;
614 struct lpfc_vport
**vports
;
615 struct lpfc_vport
*vport
;
618 spin_lock_irq(&phba
->hbalock
);
619 ha_copy
= phba
->work_ha
;
621 spin_unlock_irq(&phba
->hbalock
);
623 /* First, try to post the next mailbox command to SLI4 device */
624 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
625 lpfc_sli4_post_async_mbox(phba
);
627 if (ha_copy
& HA_ERATT
)
628 /* Handle the error attention event */
629 lpfc_handle_eratt(phba
);
631 if (ha_copy
& HA_MBATT
)
632 lpfc_sli_handle_mb_event(phba
);
634 if (ha_copy
& HA_LATT
)
635 lpfc_handle_latt(phba
);
637 /* Process SLI4 events */
638 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
639 if (phba
->hba_flag
& HBA_RRQ_ACTIVE
)
640 lpfc_handle_rrq_active(phba
);
641 if (phba
->hba_flag
& FCP_XRI_ABORT_EVENT
)
642 lpfc_sli4_fcp_xri_abort_event_proc(phba
);
643 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
644 lpfc_sli4_els_xri_abort_event_proc(phba
);
645 if (phba
->hba_flag
& ASYNC_EVENT
)
646 lpfc_sli4_async_event_proc(phba
);
647 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
648 spin_lock_irq(&phba
->hbalock
);
649 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
650 spin_unlock_irq(&phba
->hbalock
);
651 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
653 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
)
654 lpfc_sli4_fcf_redisc_event_proc(phba
);
657 vports
= lpfc_create_vport_work_array(phba
);
659 for (i
= 0; i
<= phba
->max_vports
; i
++) {
661 * We could have no vports in array if unloading, so if
662 * this happens then just use the pport
664 if (vports
[i
] == NULL
&& i
== 0)
670 spin_lock_irq(&vport
->work_port_lock
);
671 work_port_events
= vport
->work_port_events
;
672 vport
->work_port_events
&= ~work_port_events
;
673 spin_unlock_irq(&vport
->work_port_lock
);
674 if (work_port_events
& WORKER_DISC_TMO
)
675 lpfc_disc_timeout_handler(vport
);
676 if (work_port_events
& WORKER_ELS_TMO
)
677 lpfc_els_timeout_handler(vport
);
678 if (work_port_events
& WORKER_HB_TMO
)
679 lpfc_hb_timeout_handler(phba
);
680 if (work_port_events
& WORKER_MBOX_TMO
)
681 lpfc_mbox_timeout_handler(phba
);
682 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
683 lpfc_unblock_fabric_iocbs(phba
);
684 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
685 lpfc_ramp_down_queue_handler(phba
);
686 if (work_port_events
& WORKER_DELAYED_DISC_TMO
)
687 lpfc_delayed_disc_timeout_handler(vport
);
689 lpfc_destroy_vport_work_array(phba
, vports
);
691 pring
= lpfc_phba_elsring(phba
);
692 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
693 status
>>= (4*LPFC_ELS_RING
);
694 if (pring
&& (status
& HA_RXMASK
||
695 pring
->flag
& LPFC_DEFERRED_RING_EVENT
||
696 phba
->hba_flag
& HBA_SP_QUEUE_EVT
)) {
697 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
698 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
699 /* Preserve legacy behavior. */
700 if (!(phba
->hba_flag
& HBA_SP_QUEUE_EVT
))
701 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
703 if (phba
->link_state
>= LPFC_LINK_UP
||
704 phba
->link_flag
& LS_MDS_LOOPBACK
) {
705 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
706 lpfc_sli_handle_slow_ring_event(phba
, pring
,
711 if (phba
->sli_rev
== LPFC_SLI_REV4
)
712 lpfc_drain_txq(phba
);
714 * Turn on Ring interrupts
716 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
717 spin_lock_irq(&phba
->hbalock
);
718 control
= readl(phba
->HCregaddr
);
719 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
720 lpfc_debugfs_slow_ring_trc(phba
,
721 "WRK Enable ring: cntl:x%x hacopy:x%x",
722 control
, ha_copy
, 0);
724 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
725 writel(control
, phba
->HCregaddr
);
726 readl(phba
->HCregaddr
); /* flush */
728 lpfc_debugfs_slow_ring_trc(phba
,
729 "WRK Ring ok: cntl:x%x hacopy:x%x",
730 control
, ha_copy
, 0);
732 spin_unlock_irq(&phba
->hbalock
);
735 lpfc_work_list_done(phba
);
739 lpfc_do_work(void *p
)
741 struct lpfc_hba
*phba
= p
;
744 set_user_nice(current
, MIN_NICE
);
745 current
->flags
|= PF_NOFREEZE
;
746 phba
->data_flags
= 0;
748 while (!kthread_should_stop()) {
749 /* wait and check worker queue activities */
750 rc
= wait_event_interruptible(phba
->work_waitq
,
751 (test_and_clear_bit(LPFC_DATA_READY
,
753 || kthread_should_stop()));
754 /* Signal wakeup shall terminate the worker thread */
756 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
757 "0433 Wakeup on signal: rc=x%x\n", rc
);
761 /* Attend pending lpfc data processing */
762 lpfc_work_done(phba
);
764 phba
->worker_thread
= NULL
;
765 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
766 "0432 Worker thread stopped.\n");
771 * This is only called to handle FC worker events. Since this a rare
772 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
773 * embedding it in the IOCB.
776 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
779 struct lpfc_work_evt
*evtp
;
783 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
784 * be queued to worker thread for processing
786 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
790 evtp
->evt_arg1
= arg1
;
791 evtp
->evt_arg2
= arg2
;
794 spin_lock_irqsave(&phba
->hbalock
, flags
);
795 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
796 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
798 lpfc_worker_wake_up(phba
);
804 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
806 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
807 struct lpfc_hba
*phba
= vport
->phba
;
808 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
810 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
811 if (!NLP_CHK_NODE_ACT(ndlp
))
813 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
815 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
816 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
817 (ndlp
->nlp_DID
== NameServer_DID
)))
818 lpfc_unreg_rpi(vport
, ndlp
);
820 /* Leave Fabric nodes alone on link down */
821 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
822 (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
))
824 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
827 : NLP_EVT_DEVICE_RECOVERY
);
829 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
830 if (phba
->sli_rev
== LPFC_SLI_REV4
)
831 lpfc_sli4_unreg_all_rpis(vport
);
832 lpfc_mbx_unreg_vpi(vport
);
833 spin_lock_irq(shost
->host_lock
);
834 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
835 spin_unlock_irq(shost
->host_lock
);
840 lpfc_port_link_failure(struct lpfc_vport
*vport
)
842 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
844 /* Cleanup any outstanding received buffers */
845 lpfc_cleanup_rcv_buffers(vport
);
847 /* Cleanup any outstanding RSCN activity */
848 lpfc_els_flush_rscn(vport
);
850 /* Cleanup any outstanding ELS commands */
851 lpfc_els_flush_cmd(vport
);
853 lpfc_cleanup_rpis(vport
, 0);
855 /* Turn off discovery timer if its running */
856 lpfc_can_disctmo(vport
);
860 lpfc_linkdown_port(struct lpfc_vport
*vport
)
862 struct lpfc_hba
*phba
= vport
->phba
;
863 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
865 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
866 fc_host_post_event(shost
, fc_get_event_number(),
867 FCH_EVT_LINKDOWN
, 0);
869 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
870 "Link Down: state:x%x rtry:x%x flg:x%x",
871 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
873 lpfc_port_link_failure(vport
);
875 /* Stop delayed Nport discovery */
876 spin_lock_irq(shost
->host_lock
);
877 vport
->fc_flag
&= ~FC_DISC_DELAYED
;
878 spin_unlock_irq(shost
->host_lock
);
879 del_timer_sync(&vport
->delayed_disc_tmo
);
883 lpfc_linkdown(struct lpfc_hba
*phba
)
885 struct lpfc_vport
*vport
= phba
->pport
;
886 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
887 struct lpfc_vport
**vports
;
891 if (phba
->link_state
== LPFC_LINK_DOWN
) {
892 if (phba
->sli4_hba
.conf_trunk
) {
893 phba
->trunk_link
.link0
.state
= 0;
894 phba
->trunk_link
.link1
.state
= 0;
895 phba
->trunk_link
.link2
.state
= 0;
896 phba
->trunk_link
.link3
.state
= 0;
900 /* Block all SCSI stack I/Os */
901 lpfc_scsi_dev_block(phba
);
903 phba
->defer_flogi_acc_flag
= false;
905 spin_lock_irq(&phba
->hbalock
);
906 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
907 spin_unlock_irq(&phba
->hbalock
);
908 if (phba
->link_state
> LPFC_LINK_DOWN
) {
909 phba
->link_state
= LPFC_LINK_DOWN
;
910 if (phba
->sli4_hba
.conf_trunk
) {
911 phba
->trunk_link
.link0
.state
= 0;
912 phba
->trunk_link
.link1
.state
= 0;
913 phba
->trunk_link
.link2
.state
= 0;
914 phba
->trunk_link
.link3
.state
= 0;
916 spin_lock_irq(shost
->host_lock
);
917 phba
->pport
->fc_flag
&= ~FC_LBIT
;
918 spin_unlock_irq(shost
->host_lock
);
920 vports
= lpfc_create_vport_work_array(phba
);
921 if (vports
!= NULL
) {
922 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
923 /* Issue a LINK DOWN event to all nodes */
924 lpfc_linkdown_port(vports
[i
]);
926 vports
[i
]->fc_myDID
= 0;
928 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
929 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
930 if (phba
->nvmet_support
)
931 lpfc_nvmet_update_targetport(phba
);
933 lpfc_nvme_update_localport(vports
[i
]);
937 lpfc_destroy_vport_work_array(phba
, vports
);
938 /* Clean up any firmware default rpi's */
939 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
941 lpfc_unreg_did(phba
, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS
, mb
);
943 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
944 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
945 == MBX_NOT_FINISHED
) {
946 mempool_free(mb
, phba
->mbox_mem_pool
);
950 /* Setup myDID for link up if we are in pt2pt mode */
951 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
952 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
954 lpfc_config_link(phba
, mb
);
955 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
957 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
958 == MBX_NOT_FINISHED
) {
959 mempool_free(mb
, phba
->mbox_mem_pool
);
962 spin_lock_irq(shost
->host_lock
);
963 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
964 phba
->pport
->rcv_flogi_cnt
= 0;
965 spin_unlock_irq(shost
->host_lock
);
971 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
973 struct lpfc_nodelist
*ndlp
;
975 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
976 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
977 if (!NLP_CHK_NODE_ACT(ndlp
))
979 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
981 if (ndlp
->nlp_type
& NLP_FABRIC
) {
982 /* On Linkup its safe to clean up the ndlp
983 * from Fabric connections.
985 if (ndlp
->nlp_DID
!= Fabric_DID
)
986 lpfc_unreg_rpi(vport
, ndlp
);
987 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
988 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
989 /* Fail outstanding IO now since device is
992 lpfc_unreg_rpi(vport
, ndlp
);
998 lpfc_linkup_port(struct lpfc_vport
*vport
)
1000 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1001 struct lpfc_hba
*phba
= vport
->phba
;
1003 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
1006 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1007 "Link Up: top:x%x speed:x%x flg:x%x",
1008 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
1010 /* If NPIV is not enabled, only bring the physical port up */
1011 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1012 (vport
!= phba
->pport
))
1015 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
1016 fc_host_post_event(shost
, fc_get_event_number(),
1019 spin_lock_irq(shost
->host_lock
);
1020 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
1021 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
1022 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
1023 vport
->fc_ns_retry
= 0;
1024 spin_unlock_irq(shost
->host_lock
);
1026 if (vport
->fc_flag
& FC_LBIT
)
1027 lpfc_linkup_cleanup_nodes(vport
);
1032 lpfc_linkup(struct lpfc_hba
*phba
)
1034 struct lpfc_vport
**vports
;
1036 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
1038 phba
->link_state
= LPFC_LINK_UP
;
1040 /* Unblock fabric iocbs if they are blocked */
1041 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
1042 del_timer_sync(&phba
->fabric_block_timer
);
1044 vports
= lpfc_create_vport_work_array(phba
);
1046 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1047 lpfc_linkup_port(vports
[i
]);
1048 lpfc_destroy_vport_work_array(phba
, vports
);
1050 /* Clear the pport flogi counter in case the link down was
1051 * absorbed without an ACQE. No lock here - in worker thread
1052 * and discovery is synchronized.
1054 spin_lock_irq(shost
->host_lock
);
1055 phba
->pport
->rcv_flogi_cnt
= 0;
1056 spin_unlock_irq(shost
->host_lock
);
1058 /* reinitialize initial FLOGI flag */
1059 phba
->hba_flag
&= ~(HBA_FLOGI_ISSUED
);
1060 phba
->defer_flogi_acc_flag
= false;
1066 * This routine handles processing a CLEAR_LA mailbox
1067 * command upon completion. It is setup in the LPFC_MBOXQ
1068 * as the completion routine when the command is
1069 * handed off to the SLI layer. SLI3 only.
1072 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1074 struct lpfc_vport
*vport
= pmb
->vport
;
1075 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1076 struct lpfc_sli
*psli
= &phba
->sli
;
1077 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1080 /* Since we don't do discovery right now, turn these off here */
1081 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1082 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1084 /* Check for error */
1085 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
1086 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1087 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1088 "0320 CLEAR_LA mbxStatus error x%x hba "
1090 mb
->mbxStatus
, vport
->port_state
);
1091 phba
->link_state
= LPFC_HBA_ERROR
;
1095 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1096 phba
->link_state
= LPFC_HBA_READY
;
1098 spin_lock_irq(&phba
->hbalock
);
1099 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1100 control
= readl(phba
->HCregaddr
);
1101 control
|= HC_LAINT_ENA
;
1102 writel(control
, phba
->HCregaddr
);
1103 readl(phba
->HCregaddr
); /* flush */
1104 spin_unlock_irq(&phba
->hbalock
);
1105 mempool_free(pmb
, phba
->mbox_mem_pool
);
1109 /* Device Discovery completes */
1110 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1111 "0225 Device Discovery completes\n");
1112 mempool_free(pmb
, phba
->mbox_mem_pool
);
1114 spin_lock_irq(shost
->host_lock
);
1115 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
1116 spin_unlock_irq(shost
->host_lock
);
1118 lpfc_can_disctmo(vport
);
1120 /* turn on Link Attention interrupts */
1122 spin_lock_irq(&phba
->hbalock
);
1123 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1124 control
= readl(phba
->HCregaddr
);
1125 control
|= HC_LAINT_ENA
;
1126 writel(control
, phba
->HCregaddr
);
1127 readl(phba
->HCregaddr
); /* flush */
1128 spin_unlock_irq(&phba
->hbalock
);
1135 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1137 struct lpfc_vport
*vport
= pmb
->vport
;
1140 if (pmb
->u
.mb
.mbxStatus
)
1143 mempool_free(pmb
, phba
->mbox_mem_pool
);
1145 /* don't perform discovery for SLI4 loopback diagnostic test */
1146 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1147 !(phba
->hba_flag
& HBA_FCOE_MODE
) &&
1148 (phba
->link_flag
& LS_LOOPBACK_MODE
))
1151 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
&&
1152 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
1153 !(vport
->fc_flag
& FC_LBIT
)) {
1154 /* Need to wait for FAN - use discovery timer
1155 * for timeout. port_state is identically
1156 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1158 lpfc_set_disctmo(vport
);
1162 /* Start discovery by sending a FLOGI. port_state is identically
1163 * LPFC_FLOGI while waiting for FLOGI cmpl
1165 if (vport
->port_state
!= LPFC_FLOGI
) {
1166 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
) {
1167 bbscn
= bf_get(lpfc_bbscn_def
,
1168 &phba
->sli4_hba
.bbscn_params
);
1169 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
&= 0xf;
1170 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
|= (bbscn
<< 4);
1172 lpfc_initial_flogi(vport
);
1173 } else if (vport
->fc_flag
& FC_PT2PT
) {
1174 lpfc_disc_start(vport
);
1179 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1180 "0306 CONFIG_LINK mbxStatus error x%x "
1182 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
1183 mempool_free(pmb
, phba
->mbox_mem_pool
);
1185 lpfc_linkdown(phba
);
1187 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1188 "0200 CONFIG_LINK bad hba state x%x\n",
1191 lpfc_issue_clear_la(phba
, vport
);
1196 * lpfc_sli4_clear_fcf_rr_bmask
1197 * @phba pointer to the struct lpfc_hba for this port.
1198 * This fucnction resets the round robin bit mask and clears the
1199 * fcf priority list. The list deletions are done while holding the
1200 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1201 * from the lpfc_fcf_pri record.
1204 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba
*phba
)
1206 struct lpfc_fcf_pri
*fcf_pri
;
1207 struct lpfc_fcf_pri
*next_fcf_pri
;
1208 memset(phba
->fcf
.fcf_rr_bmask
, 0, sizeof(*phba
->fcf
.fcf_rr_bmask
));
1209 spin_lock_irq(&phba
->hbalock
);
1210 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
1211 &phba
->fcf
.fcf_pri_list
, list
) {
1212 list_del_init(&fcf_pri
->list
);
1213 fcf_pri
->fcf_rec
.flag
= 0;
1215 spin_unlock_irq(&phba
->hbalock
);
1218 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1220 struct lpfc_vport
*vport
= mboxq
->vport
;
1222 if (mboxq
->u
.mb
.mbxStatus
) {
1223 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1224 "2017 REG_FCFI mbxStatus error x%x "
1226 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1230 /* Start FCoE discovery by sending a FLOGI. */
1231 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1232 /* Set the FCFI registered flag */
1233 spin_lock_irq(&phba
->hbalock
);
1234 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1235 spin_unlock_irq(&phba
->hbalock
);
1237 /* If there is a pending FCoE event, restart FCF table scan. */
1238 if ((!(phba
->hba_flag
& FCF_RR_INPROG
)) &&
1239 lpfc_check_pending_fcoe_event(phba
, LPFC_UNREG_FCF
))
1242 /* Mark successful completion of FCF table scan */
1243 spin_lock_irq(&phba
->hbalock
);
1244 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1245 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1246 if (vport
->port_state
!= LPFC_FLOGI
) {
1247 phba
->hba_flag
|= FCF_RR_INPROG
;
1248 spin_unlock_irq(&phba
->hbalock
);
1249 lpfc_issue_init_vfi(vport
);
1252 spin_unlock_irq(&phba
->hbalock
);
1256 spin_lock_irq(&phba
->hbalock
);
1257 phba
->hba_flag
&= ~FCF_RR_INPROG
;
1258 spin_unlock_irq(&phba
->hbalock
);
1260 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1264 * lpfc_fab_name_match - Check if the fcf fabric name match.
1265 * @fab_name: pointer to fabric name.
1266 * @new_fcf_record: pointer to fcf record.
1268 * This routine compare the fcf record's fabric name with provided
1269 * fabric name. If the fabric name are identical this function
1270 * returns 1 else return 0.
1273 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1275 if (fab_name
[0] != bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
))
1277 if (fab_name
[1] != bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
))
1279 if (fab_name
[2] != bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
))
1281 if (fab_name
[3] != bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
))
1283 if (fab_name
[4] != bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
))
1285 if (fab_name
[5] != bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
))
1287 if (fab_name
[6] != bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
))
1289 if (fab_name
[7] != bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
))
1295 * lpfc_sw_name_match - Check if the fcf switch name match.
1296 * @fab_name: pointer to fabric name.
1297 * @new_fcf_record: pointer to fcf record.
1299 * This routine compare the fcf record's switch name with provided
1300 * switch name. If the switch name are identical this function
1301 * returns 1 else return 0.
1304 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1306 if (sw_name
[0] != bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
))
1308 if (sw_name
[1] != bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
))
1310 if (sw_name
[2] != bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
))
1312 if (sw_name
[3] != bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
))
1314 if (sw_name
[4] != bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
))
1316 if (sw_name
[5] != bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
))
1318 if (sw_name
[6] != bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
))
1320 if (sw_name
[7] != bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
))
1326 * lpfc_mac_addr_match - Check if the fcf mac address match.
1327 * @mac_addr: pointer to mac address.
1328 * @new_fcf_record: pointer to fcf record.
1330 * This routine compare the fcf record's mac address with HBA's
1331 * FCF mac address. If the mac addresses are identical this function
1332 * returns 1 else return 0.
1335 lpfc_mac_addr_match(uint8_t *mac_addr
, struct fcf_record
*new_fcf_record
)
1337 if (mac_addr
[0] != bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
))
1339 if (mac_addr
[1] != bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
))
1341 if (mac_addr
[2] != bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
))
1343 if (mac_addr
[3] != bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
))
1345 if (mac_addr
[4] != bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
))
1347 if (mac_addr
[5] != bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
))
1353 lpfc_vlan_id_match(uint16_t curr_vlan_id
, uint16_t new_vlan_id
)
1355 return (curr_vlan_id
== new_vlan_id
);
1359 * lpfc_update_fcf_record - Update driver fcf record
1360 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1361 * @phba: pointer to lpfc hba data structure.
1362 * @fcf_index: Index for the lpfc_fcf_record.
1363 * @new_fcf_record: pointer to hba fcf record.
1365 * This routine updates the driver FCF priority record from the new HBA FCF
1366 * record. This routine is called with the host lock held.
1369 __lpfc_update_fcf_record_pri(struct lpfc_hba
*phba
, uint16_t fcf_index
,
1370 struct fcf_record
*new_fcf_record
1373 struct lpfc_fcf_pri
*fcf_pri
;
1375 lockdep_assert_held(&phba
->hbalock
);
1377 fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
1378 fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
1379 /* FCF record priority */
1380 fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
1385 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1386 * @fcf: pointer to driver fcf record.
1387 * @new_fcf_record: pointer to fcf record.
1389 * This routine copies the FCF information from the FCF
1390 * record to lpfc_hba data structure.
1393 lpfc_copy_fcf_record(struct lpfc_fcf_rec
*fcf_rec
,
1394 struct fcf_record
*new_fcf_record
)
1397 fcf_rec
->fabric_name
[0] =
1398 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1399 fcf_rec
->fabric_name
[1] =
1400 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1401 fcf_rec
->fabric_name
[2] =
1402 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1403 fcf_rec
->fabric_name
[3] =
1404 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1405 fcf_rec
->fabric_name
[4] =
1406 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1407 fcf_rec
->fabric_name
[5] =
1408 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1409 fcf_rec
->fabric_name
[6] =
1410 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1411 fcf_rec
->fabric_name
[7] =
1412 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1414 fcf_rec
->mac_addr
[0] = bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1415 fcf_rec
->mac_addr
[1] = bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1416 fcf_rec
->mac_addr
[2] = bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1417 fcf_rec
->mac_addr
[3] = bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1418 fcf_rec
->mac_addr
[4] = bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1419 fcf_rec
->mac_addr
[5] = bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1420 /* FCF record index */
1421 fcf_rec
->fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1422 /* FCF record priority */
1423 fcf_rec
->priority
= new_fcf_record
->fip_priority
;
1425 fcf_rec
->switch_name
[0] =
1426 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1427 fcf_rec
->switch_name
[1] =
1428 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1429 fcf_rec
->switch_name
[2] =
1430 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1431 fcf_rec
->switch_name
[3] =
1432 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1433 fcf_rec
->switch_name
[4] =
1434 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1435 fcf_rec
->switch_name
[5] =
1436 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1437 fcf_rec
->switch_name
[6] =
1438 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1439 fcf_rec
->switch_name
[7] =
1440 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1444 * lpfc_update_fcf_record - Update driver fcf record
1445 * @phba: pointer to lpfc hba data structure.
1446 * @fcf_rec: pointer to driver fcf record.
1447 * @new_fcf_record: pointer to hba fcf record.
1448 * @addr_mode: address mode to be set to the driver fcf record.
1449 * @vlan_id: vlan tag to be set to the driver fcf record.
1450 * @flag: flag bits to be set to the driver fcf record.
1452 * This routine updates the driver FCF record from the new HBA FCF record
1453 * together with the address mode, vlan_id, and other informations. This
1454 * routine is called with the host lock held.
1457 __lpfc_update_fcf_record(struct lpfc_hba
*phba
, struct lpfc_fcf_rec
*fcf_rec
,
1458 struct fcf_record
*new_fcf_record
, uint32_t addr_mode
,
1459 uint16_t vlan_id
, uint32_t flag
)
1461 lockdep_assert_held(&phba
->hbalock
);
1463 /* Copy the fields from the HBA's FCF record */
1464 lpfc_copy_fcf_record(fcf_rec
, new_fcf_record
);
1465 /* Update other fields of driver FCF record */
1466 fcf_rec
->addr_mode
= addr_mode
;
1467 fcf_rec
->vlan_id
= vlan_id
;
1468 fcf_rec
->flag
|= (flag
| RECORD_VALID
);
1469 __lpfc_update_fcf_record_pri(phba
,
1470 bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
),
1475 * lpfc_register_fcf - Register the FCF with hba.
1476 * @phba: pointer to lpfc hba data structure.
1478 * This routine issues a register fcfi mailbox command to register
1482 lpfc_register_fcf(struct lpfc_hba
*phba
)
1484 LPFC_MBOXQ_t
*fcf_mbxq
;
1487 spin_lock_irq(&phba
->hbalock
);
1488 /* If the FCF is not available do nothing. */
1489 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1490 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1491 spin_unlock_irq(&phba
->hbalock
);
1495 /* The FCF is already registered, start discovery */
1496 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1497 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1498 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1499 if (phba
->pport
->port_state
!= LPFC_FLOGI
&&
1500 phba
->pport
->fc_flag
& FC_FABRIC
) {
1501 phba
->hba_flag
|= FCF_RR_INPROG
;
1502 spin_unlock_irq(&phba
->hbalock
);
1503 lpfc_initial_flogi(phba
->pport
);
1506 spin_unlock_irq(&phba
->hbalock
);
1509 spin_unlock_irq(&phba
->hbalock
);
1511 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1513 spin_lock_irq(&phba
->hbalock
);
1514 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1515 spin_unlock_irq(&phba
->hbalock
);
1519 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1520 fcf_mbxq
->vport
= phba
->pport
;
1521 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1522 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1523 if (rc
== MBX_NOT_FINISHED
) {
1524 spin_lock_irq(&phba
->hbalock
);
1525 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1526 spin_unlock_irq(&phba
->hbalock
);
1527 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1534 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1535 * @phba: pointer to lpfc hba data structure.
1536 * @new_fcf_record: pointer to fcf record.
1537 * @boot_flag: Indicates if this record used by boot bios.
1538 * @addr_mode: The address mode to be used by this FCF
1539 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1541 * This routine compare the fcf record with connect list obtained from the
1542 * config region to decide if this FCF can be used for SAN discovery. It returns
1543 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1544 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1545 * is used by boot bios and addr_mode will indicate the addressing mode to be
1546 * used for this FCF when the function returns.
1547 * If the FCF record need to be used with a particular vlan id, the vlan is
1548 * set in the vlan_id on return of the function. If not VLAN tagging need to
1549 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1552 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1553 struct fcf_record
*new_fcf_record
,
1554 uint32_t *boot_flag
, uint32_t *addr_mode
,
1557 struct lpfc_fcf_conn_entry
*conn_entry
;
1558 int i
, j
, fcf_vlan_id
= 0;
1560 /* Find the lowest VLAN id in the FCF record */
1561 for (i
= 0; i
< 512; i
++) {
1562 if (new_fcf_record
->vlan_bitmap
[i
]) {
1563 fcf_vlan_id
= i
* 8;
1565 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1573 /* FCF not valid/available or solicitation in progress */
1574 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1575 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
) ||
1576 bf_get(lpfc_fcf_record_fcf_sol
, new_fcf_record
))
1579 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1581 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1583 if (phba
->valid_vlan
)
1584 *vlan_id
= phba
->vlan_id
;
1586 *vlan_id
= LPFC_FCOE_NULL_VID
;
1591 * If there are no FCF connection table entry, driver connect to all
1594 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1596 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1600 * When there are no FCF connect entries, use driver's default
1601 * addressing mode - FPMA.
1603 if (*addr_mode
& LPFC_FCF_FPMA
)
1604 *addr_mode
= LPFC_FCF_FPMA
;
1606 /* If FCF record report a vlan id use that vlan id */
1608 *vlan_id
= fcf_vlan_id
;
1610 *vlan_id
= LPFC_FCOE_NULL_VID
;
1614 list_for_each_entry(conn_entry
,
1615 &phba
->fcf_conn_rec_list
, list
) {
1616 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1619 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1620 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1623 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1624 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1627 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1629 * If the vlan bit map does not have the bit set for the
1630 * vlan id to be used, then it is not a match.
1632 if (!(new_fcf_record
->vlan_bitmap
1633 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1634 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1639 * If connection record does not support any addressing mode,
1640 * skip the FCF record.
1642 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1643 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1647 * Check if the connection record specifies a required
1650 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1651 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1654 * If SPMA required but FCF not support this continue.
1656 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1657 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1658 new_fcf_record
) & LPFC_FCF_SPMA
))
1662 * If FPMA required but FCF not support this continue.
1664 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1665 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1666 new_fcf_record
) & LPFC_FCF_FPMA
))
1671 * This fcf record matches filtering criteria.
1673 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1679 * If user did not specify any addressing mode, or if the
1680 * preferred addressing mode specified by user is not supported
1681 * by FCF, allow fabric to pick the addressing mode.
1683 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1686 * If the user specified a required address mode, assign that
1689 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1690 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1691 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1693 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1695 * If the user specified a preferred address mode, use the
1696 * addr mode only if FCF support the addr_mode.
1698 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1699 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1700 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1701 (*addr_mode
& LPFC_FCF_SPMA
))
1702 *addr_mode
= LPFC_FCF_SPMA
;
1703 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1704 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1705 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1706 (*addr_mode
& LPFC_FCF_FPMA
))
1707 *addr_mode
= LPFC_FCF_FPMA
;
1709 /* If matching connect list has a vlan id, use it */
1710 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1711 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1713 * If no vlan id is specified in connect list, use the vlan id
1716 else if (fcf_vlan_id
)
1717 *vlan_id
= fcf_vlan_id
;
1719 *vlan_id
= LPFC_FCOE_NULL_VID
;
1728 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1729 * @phba: pointer to lpfc hba data structure.
1730 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1732 * This function check if there is any fcoe event pending while driver
1733 * scan FCF entries. If there is any pending event, it will restart the
1734 * FCF saning and return 1 else return 0.
1737 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1740 * If the Link is up and no FCoE events while in the
1741 * FCF discovery, no need to restart FCF discovery.
1743 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1744 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1747 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1748 "2768 Pending link or FCF event during current "
1749 "handling of the previous event: link_state:x%x, "
1750 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1751 phba
->link_state
, phba
->fcoe_eventtag_at_fcf_scan
,
1752 phba
->fcoe_eventtag
);
1754 spin_lock_irq(&phba
->hbalock
);
1755 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1756 spin_unlock_irq(&phba
->hbalock
);
1758 if (phba
->link_state
>= LPFC_LINK_UP
) {
1759 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1760 "2780 Restart FCF table scan due to "
1761 "pending FCF event:evt_tag_at_scan:x%x, "
1762 "evt_tag_current:x%x\n",
1763 phba
->fcoe_eventtag_at_fcf_scan
,
1764 phba
->fcoe_eventtag
);
1765 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1768 * Do not continue FCF discovery and clear FCF_TS_INPROG
1771 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1772 "2833 Stop FCF discovery process due to link "
1773 "state change (x%x)\n", phba
->link_state
);
1774 spin_lock_irq(&phba
->hbalock
);
1775 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1776 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
| FCF_DISCOVERY
);
1777 spin_unlock_irq(&phba
->hbalock
);
1780 /* Unregister the currently registered FCF if required */
1782 spin_lock_irq(&phba
->hbalock
);
1783 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1784 spin_unlock_irq(&phba
->hbalock
);
1785 lpfc_sli4_unregister_fcf(phba
);
1791 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1792 * @phba: pointer to lpfc hba data structure.
1793 * @fcf_cnt: number of eligible fcf record seen so far.
1795 * This function makes an running random selection decision on FCF record to
1796 * use through a sequence of @fcf_cnt eligible FCF records with equal
1797 * probability. To perform integer manunipulation of random numbers with
1798 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1799 * from prandom_u32() are taken as the random random number generated.
1801 * Returns true when outcome is for the newly read FCF record should be
1802 * chosen; otherwise, return false when outcome is for keeping the previously
1803 * chosen FCF record.
1806 lpfc_sli4_new_fcf_random_select(struct lpfc_hba
*phba
, uint32_t fcf_cnt
)
1810 /* Get 16-bit uniform random number */
1811 rand_num
= 0xFFFF & prandom_u32();
1813 /* Decision with probability 1/fcf_cnt */
1814 if ((fcf_cnt
* rand_num
) < 0xFFFF)
1821 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1822 * @phba: pointer to lpfc hba data structure.
1823 * @mboxq: pointer to mailbox object.
1824 * @next_fcf_index: pointer to holder of next fcf index.
1826 * This routine parses the non-embedded fcf mailbox command by performing the
1827 * necessarily error checking, non-embedded read FCF record mailbox command
1828 * SGE parsing, and endianness swapping.
1830 * Returns the pointer to the new FCF record in the non-embedded mailbox
1831 * command DMA memory if successfully, other NULL.
1833 static struct fcf_record
*
1834 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
1835 uint16_t *next_fcf_index
)
1838 struct lpfc_mbx_sge sge
;
1839 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1840 uint32_t shdr_status
, shdr_add_status
, if_type
;
1841 union lpfc_sli4_cfg_shdr
*shdr
;
1842 struct fcf_record
*new_fcf_record
;
1844 /* Get the first SGE entry from the non-embedded DMA memory. This
1845 * routine only uses a single SGE.
1847 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1848 if (unlikely(!mboxq
->sge_array
)) {
1849 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1850 "2524 Failed to get the non-embedded SGE "
1851 "virtual address\n");
1854 virt_addr
= mboxq
->sge_array
->addr
[0];
1856 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1857 lpfc_sli_pcimem_bcopy(shdr
, shdr
,
1858 sizeof(union lpfc_sli4_cfg_shdr
));
1859 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1860 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1861 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
1862 if (shdr_status
|| shdr_add_status
) {
1863 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
||
1864 if_type
== LPFC_SLI_INTF_IF_TYPE_2
)
1865 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1866 "2726 READ_FCF_RECORD Indicates empty "
1869 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1870 "2521 READ_FCF_RECORD mailbox failed "
1871 "with status x%x add_status x%x, "
1872 "mbx\n", shdr_status
, shdr_add_status
);
1876 /* Interpreting the returned information of the FCF record */
1877 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1878 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1879 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1880 *next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1881 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1882 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1883 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1884 offsetof(struct fcf_record
, vlan_bitmap
));
1885 new_fcf_record
->word137
= le32_to_cpu(new_fcf_record
->word137
);
1886 new_fcf_record
->word138
= le32_to_cpu(new_fcf_record
->word138
);
1888 return new_fcf_record
;
1892 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1893 * @phba: pointer to lpfc hba data structure.
1894 * @fcf_record: pointer to the fcf record.
1895 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1896 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1898 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1902 lpfc_sli4_log_fcf_record_info(struct lpfc_hba
*phba
,
1903 struct fcf_record
*fcf_record
,
1905 uint16_t next_fcf_index
)
1907 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1908 "2764 READ_FCF_RECORD:\n"
1909 "\tFCF_Index : x%x\n"
1910 "\tFCF_Avail : x%x\n"
1911 "\tFCF_Valid : x%x\n"
1913 "\tFIP_Priority : x%x\n"
1914 "\tMAC_Provider : x%x\n"
1915 "\tLowest VLANID : x%x\n"
1916 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1917 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1918 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1919 "\tNext_FCF_Index: x%x\n",
1920 bf_get(lpfc_fcf_record_fcf_index
, fcf_record
),
1921 bf_get(lpfc_fcf_record_fcf_avail
, fcf_record
),
1922 bf_get(lpfc_fcf_record_fcf_valid
, fcf_record
),
1923 bf_get(lpfc_fcf_record_fcf_sol
, fcf_record
),
1924 fcf_record
->fip_priority
,
1925 bf_get(lpfc_fcf_record_mac_addr_prov
, fcf_record
),
1927 bf_get(lpfc_fcf_record_mac_0
, fcf_record
),
1928 bf_get(lpfc_fcf_record_mac_1
, fcf_record
),
1929 bf_get(lpfc_fcf_record_mac_2
, fcf_record
),
1930 bf_get(lpfc_fcf_record_mac_3
, fcf_record
),
1931 bf_get(lpfc_fcf_record_mac_4
, fcf_record
),
1932 bf_get(lpfc_fcf_record_mac_5
, fcf_record
),
1933 bf_get(lpfc_fcf_record_fab_name_0
, fcf_record
),
1934 bf_get(lpfc_fcf_record_fab_name_1
, fcf_record
),
1935 bf_get(lpfc_fcf_record_fab_name_2
, fcf_record
),
1936 bf_get(lpfc_fcf_record_fab_name_3
, fcf_record
),
1937 bf_get(lpfc_fcf_record_fab_name_4
, fcf_record
),
1938 bf_get(lpfc_fcf_record_fab_name_5
, fcf_record
),
1939 bf_get(lpfc_fcf_record_fab_name_6
, fcf_record
),
1940 bf_get(lpfc_fcf_record_fab_name_7
, fcf_record
),
1941 bf_get(lpfc_fcf_record_switch_name_0
, fcf_record
),
1942 bf_get(lpfc_fcf_record_switch_name_1
, fcf_record
),
1943 bf_get(lpfc_fcf_record_switch_name_2
, fcf_record
),
1944 bf_get(lpfc_fcf_record_switch_name_3
, fcf_record
),
1945 bf_get(lpfc_fcf_record_switch_name_4
, fcf_record
),
1946 bf_get(lpfc_fcf_record_switch_name_5
, fcf_record
),
1947 bf_get(lpfc_fcf_record_switch_name_6
, fcf_record
),
1948 bf_get(lpfc_fcf_record_switch_name_7
, fcf_record
),
1953 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1954 * @phba: pointer to lpfc hba data structure.
1955 * @fcf_rec: pointer to an existing FCF record.
1956 * @new_fcf_record: pointer to a new FCF record.
1957 * @new_vlan_id: vlan id from the new FCF record.
1959 * This function performs matching test of a new FCF record against an existing
1960 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1961 * will not be used as part of the FCF record matching criteria.
1963 * Returns true if all the fields matching, otherwise returns false.
1966 lpfc_sli4_fcf_record_match(struct lpfc_hba
*phba
,
1967 struct lpfc_fcf_rec
*fcf_rec
,
1968 struct fcf_record
*new_fcf_record
,
1969 uint16_t new_vlan_id
)
1971 if (new_vlan_id
!= LPFC_FCOE_IGNORE_VID
)
1972 if (!lpfc_vlan_id_match(fcf_rec
->vlan_id
, new_vlan_id
))
1974 if (!lpfc_mac_addr_match(fcf_rec
->mac_addr
, new_fcf_record
))
1976 if (!lpfc_sw_name_match(fcf_rec
->switch_name
, new_fcf_record
))
1978 if (!lpfc_fab_name_match(fcf_rec
->fabric_name
, new_fcf_record
))
1980 if (fcf_rec
->priority
!= new_fcf_record
->fip_priority
)
1986 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1987 * @vport: Pointer to vport object.
1988 * @fcf_index: index to next fcf.
1990 * This function processing the roundrobin fcf failover to next fcf index.
1991 * When this function is invoked, there will be a current fcf registered
1993 * Return: 0 for continue retrying flogi on currently registered fcf;
1994 * 1 for stop flogi on currently registered fcf;
1996 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport
*vport
, uint16_t fcf_index
)
1998 struct lpfc_hba
*phba
= vport
->phba
;
2001 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
2002 spin_lock_irq(&phba
->hbalock
);
2003 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2004 spin_unlock_irq(&phba
->hbalock
);
2005 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2006 "2872 Devloss tmo with no eligible "
2007 "FCF, unregister in-use FCF (x%x) "
2008 "and rescan FCF table\n",
2009 phba
->fcf
.current_rec
.fcf_indx
);
2010 lpfc_unregister_fcf_rescan(phba
);
2011 goto stop_flogi_current_fcf
;
2013 /* Mark the end to FLOGI roundrobin failover */
2014 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2015 /* Allow action to new fcf asynchronous event */
2016 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
2017 spin_unlock_irq(&phba
->hbalock
);
2018 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2019 "2865 No FCF available, stop roundrobin FCF "
2020 "failover and change port state:x%x/x%x\n",
2021 phba
->pport
->port_state
, LPFC_VPORT_UNKNOWN
);
2022 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2024 if (!phba
->fcf
.fcf_redisc_attempted
) {
2025 lpfc_unregister_fcf(phba
);
2027 rc
= lpfc_sli4_redisc_fcf_table(phba
);
2029 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2030 "3195 Rediscover FCF table\n");
2031 phba
->fcf
.fcf_redisc_attempted
= 1;
2032 lpfc_sli4_clear_fcf_rr_bmask(phba
);
2034 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2035 "3196 Rediscover FCF table "
2036 "failed. Status:x%x\n", rc
);
2039 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2040 "3197 Already rediscover FCF table "
2041 "attempted. No more retry\n");
2043 goto stop_flogi_current_fcf
;
2045 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_ELS
,
2046 "2794 Try FLOGI roundrobin FCF failover to "
2047 "(x%x)\n", fcf_index
);
2048 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
, fcf_index
);
2050 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
2051 "2761 FLOGI roundrobin FCF failover "
2052 "failed (rc:x%x) to read FCF (x%x)\n",
2053 rc
, phba
->fcf
.current_rec
.fcf_indx
);
2055 goto stop_flogi_current_fcf
;
2059 stop_flogi_current_fcf
:
2060 lpfc_can_disctmo(vport
);
2065 * lpfc_sli4_fcf_pri_list_del
2066 * @phba: pointer to lpfc hba data structure.
2067 * @fcf_index the index of the fcf record to delete
2068 * This routine checks the on list flag of the fcf_index to be deleted.
2069 * If it is one the list then it is removed from the list, and the flag
2070 * is cleared. This routine grab the hbalock before removing the fcf
2071 * record from the list.
2073 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba
*phba
,
2076 struct lpfc_fcf_pri
*new_fcf_pri
;
2078 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2079 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2080 "3058 deleting idx x%x pri x%x flg x%x\n",
2081 fcf_index
, new_fcf_pri
->fcf_rec
.priority
,
2082 new_fcf_pri
->fcf_rec
.flag
);
2083 spin_lock_irq(&phba
->hbalock
);
2084 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
) {
2085 if (phba
->fcf
.current_rec
.priority
==
2086 new_fcf_pri
->fcf_rec
.priority
)
2087 phba
->fcf
.eligible_fcf_cnt
--;
2088 list_del_init(&new_fcf_pri
->list
);
2089 new_fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_ON_PRI_LIST
;
2091 spin_unlock_irq(&phba
->hbalock
);
2095 * lpfc_sli4_set_fcf_flogi_fail
2096 * @phba: pointer to lpfc hba data structure.
2097 * @fcf_index the index of the fcf record to update
2098 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2099 * flag so the the round robin slection for the particular priority level
2100 * will try a different fcf record that does not have this bit set.
2101 * If the fcf record is re-read for any reason this flag is cleared brfore
2102 * adding it to the priority list.
2105 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba
*phba
, uint16_t fcf_index
)
2107 struct lpfc_fcf_pri
*new_fcf_pri
;
2108 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2109 spin_lock_irq(&phba
->hbalock
);
2110 new_fcf_pri
->fcf_rec
.flag
|= LPFC_FCF_FLOGI_FAILED
;
2111 spin_unlock_irq(&phba
->hbalock
);
2115 * lpfc_sli4_fcf_pri_list_add
2116 * @phba: pointer to lpfc hba data structure.
2117 * @fcf_index the index of the fcf record to add
2118 * This routine checks the priority of the fcf_index to be added.
2119 * If it is a lower priority than the current head of the fcf_pri list
2120 * then it is added to the list in the right order.
2121 * If it is the same priority as the current head of the list then it
2122 * is added to the head of the list and its bit in the rr_bmask is set.
2123 * If the fcf_index to be added is of a higher priority than the current
2124 * head of the list then the rr_bmask is cleared, its bit is set in the
2125 * rr_bmask and it is added to the head of the list.
2127 * 0=success 1=failure
2129 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba
*phba
,
2131 struct fcf_record
*new_fcf_record
)
2133 uint16_t current_fcf_pri
;
2134 uint16_t last_index
;
2135 struct lpfc_fcf_pri
*fcf_pri
;
2136 struct lpfc_fcf_pri
*next_fcf_pri
;
2137 struct lpfc_fcf_pri
*new_fcf_pri
;
2140 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2141 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2142 "3059 adding idx x%x pri x%x flg x%x\n",
2143 fcf_index
, new_fcf_record
->fip_priority
,
2144 new_fcf_pri
->fcf_rec
.flag
);
2145 spin_lock_irq(&phba
->hbalock
);
2146 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
)
2147 list_del_init(&new_fcf_pri
->list
);
2148 new_fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
2149 new_fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
2150 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
2151 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2152 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2153 new_fcf_pri
->fcf_rec
.fcf_index
);
2157 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
2158 LPFC_SLI4_FCF_TBL_INDX_MAX
);
2159 if (last_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
2160 ret
= 0; /* Empty rr list */
2163 current_fcf_pri
= phba
->fcf
.fcf_pri
[last_index
].fcf_rec
.priority
;
2164 if (new_fcf_pri
->fcf_rec
.priority
<= current_fcf_pri
) {
2165 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2166 if (new_fcf_pri
->fcf_rec
.priority
< current_fcf_pri
) {
2167 memset(phba
->fcf
.fcf_rr_bmask
, 0,
2168 sizeof(*phba
->fcf
.fcf_rr_bmask
));
2169 /* fcfs_at_this_priority_level = 1; */
2170 phba
->fcf
.eligible_fcf_cnt
= 1;
2172 /* fcfs_at_this_priority_level++; */
2173 phba
->fcf
.eligible_fcf_cnt
++;
2174 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2175 new_fcf_pri
->fcf_rec
.fcf_index
);
2179 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
2180 &phba
->fcf
.fcf_pri_list
, list
) {
2181 if (new_fcf_pri
->fcf_rec
.priority
<=
2182 fcf_pri
->fcf_rec
.priority
) {
2183 if (fcf_pri
->list
.prev
== &phba
->fcf
.fcf_pri_list
)
2184 list_add(&new_fcf_pri
->list
,
2185 &phba
->fcf
.fcf_pri_list
);
2187 list_add(&new_fcf_pri
->list
,
2188 &((struct lpfc_fcf_pri
*)
2189 fcf_pri
->list
.prev
)->list
);
2192 } else if (fcf_pri
->list
.next
== &phba
->fcf
.fcf_pri_list
2193 || new_fcf_pri
->fcf_rec
.priority
<
2194 next_fcf_pri
->fcf_rec
.priority
) {
2195 list_add(&new_fcf_pri
->list
, &fcf_pri
->list
);
2199 if (new_fcf_pri
->fcf_rec
.priority
> fcf_pri
->fcf_rec
.priority
)
2205 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2206 new_fcf_pri
->fcf_rec
.flag
= LPFC_FCF_ON_PRI_LIST
;
2207 spin_unlock_irq(&phba
->hbalock
);
2212 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2213 * @phba: pointer to lpfc hba data structure.
2214 * @mboxq: pointer to mailbox object.
2216 * This function iterates through all the fcf records available in
2217 * HBA and chooses the optimal FCF record for discovery. After finding
2218 * the FCF for discovery it registers the FCF record and kicks start
2220 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2221 * use an FCF record which matches fabric name and mac address of the
2222 * currently used FCF record.
2223 * If the driver supports only one FCF, it will try to use the FCF record
2224 * used by BOOT_BIOS.
2227 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2229 struct fcf_record
*new_fcf_record
;
2230 uint32_t boot_flag
, addr_mode
;
2231 uint16_t fcf_index
, next_fcf_index
;
2232 struct lpfc_fcf_rec
*fcf_rec
= NULL
;
2233 uint16_t vlan_id
= LPFC_FCOE_NULL_VID
;
2234 bool select_new_fcf
;
2237 /* If there is pending FCoE event restart FCF table scan */
2238 if (lpfc_check_pending_fcoe_event(phba
, LPFC_SKIP_UNREG_FCF
)) {
2239 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2243 /* Parse the FCF record from the non-embedded mailbox command */
2244 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2246 if (!new_fcf_record
) {
2247 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2248 "2765 Mailbox command READ_FCF_RECORD "
2249 "failed to retrieve a FCF record.\n");
2250 /* Let next new FCF event trigger fast failover */
2251 spin_lock_irq(&phba
->hbalock
);
2252 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2253 spin_unlock_irq(&phba
->hbalock
);
2254 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2258 /* Check the FCF record against the connection list */
2259 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2260 &addr_mode
, &vlan_id
);
2262 /* Log the FCF record information if turned on */
2263 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2267 * If the fcf record does not match with connect list entries
2268 * read the next entry; otherwise, this is an eligible FCF
2269 * record for roundrobin FCF failover.
2272 lpfc_sli4_fcf_pri_list_del(phba
,
2273 bf_get(lpfc_fcf_record_fcf_index
,
2275 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2276 "2781 FCF (x%x) failed connection "
2277 "list check: (x%x/x%x/%x)\n",
2278 bf_get(lpfc_fcf_record_fcf_index
,
2280 bf_get(lpfc_fcf_record_fcf_avail
,
2282 bf_get(lpfc_fcf_record_fcf_valid
,
2284 bf_get(lpfc_fcf_record_fcf_sol
,
2286 if ((phba
->fcf
.fcf_flag
& FCF_IN_USE
) &&
2287 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2288 new_fcf_record
, LPFC_FCOE_IGNORE_VID
)) {
2289 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) !=
2290 phba
->fcf
.current_rec
.fcf_indx
) {
2291 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2292 "2862 FCF (x%x) matches property "
2293 "of in-use FCF (x%x)\n",
2294 bf_get(lpfc_fcf_record_fcf_index
,
2296 phba
->fcf
.current_rec
.fcf_indx
);
2300 * In case the current in-use FCF record becomes
2301 * invalid/unavailable during FCF discovery that
2302 * was not triggered by fast FCF failover process,
2303 * treat it as fast FCF failover.
2305 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
) &&
2306 !(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2307 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2308 "2835 Invalid in-use FCF "
2309 "(x%x), enter FCF failover "
2311 phba
->fcf
.current_rec
.fcf_indx
);
2312 spin_lock_irq(&phba
->hbalock
);
2313 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2314 spin_unlock_irq(&phba
->hbalock
);
2315 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2316 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2317 LPFC_FCOE_FCF_GET_FIRST
);
2323 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2324 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
,
2331 * If this is not the first FCF discovery of the HBA, use last
2332 * FCF record for the discovery. The condition that a rescan
2333 * matches the in-use FCF record: fabric name, switch name, mac
2334 * address, and vlan_id.
2336 spin_lock_irq(&phba
->hbalock
);
2337 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2338 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2339 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2340 new_fcf_record
, vlan_id
)) {
2341 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) ==
2342 phba
->fcf
.current_rec
.fcf_indx
) {
2343 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2344 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)
2345 /* Stop FCF redisc wait timer */
2346 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2348 else if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2349 /* Fast failover, mark completed */
2350 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2351 spin_unlock_irq(&phba
->hbalock
);
2352 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2353 "2836 New FCF matches in-use "
2354 "FCF (x%x), port_state:x%x, "
2356 phba
->fcf
.current_rec
.fcf_indx
,
2357 phba
->pport
->port_state
,
2358 phba
->pport
->fc_flag
);
2361 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2362 "2863 New FCF (x%x) matches "
2363 "property of in-use FCF (x%x)\n",
2364 bf_get(lpfc_fcf_record_fcf_index
,
2366 phba
->fcf
.current_rec
.fcf_indx
);
2369 * Read next FCF record from HBA searching for the matching
2370 * with in-use record only if not during the fast failover
2371 * period. In case of fast failover period, it shall try to
2372 * determine whether the FCF record just read should be the
2375 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2376 spin_unlock_irq(&phba
->hbalock
);
2381 * Update on failover FCF record only if it's in FCF fast-failover
2382 * period; otherwise, update on current FCF record.
2384 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2385 fcf_rec
= &phba
->fcf
.failover_rec
;
2387 fcf_rec
= &phba
->fcf
.current_rec
;
2389 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
2391 * If the driver FCF record does not have boot flag
2392 * set and new hba fcf record has boot flag set, use
2393 * the new hba fcf record.
2395 if (boot_flag
&& !(fcf_rec
->flag
& BOOT_ENABLE
)) {
2396 /* Choose this FCF record */
2397 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2398 "2837 Update current FCF record "
2399 "(x%x) with new FCF record (x%x)\n",
2401 bf_get(lpfc_fcf_record_fcf_index
,
2403 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2404 addr_mode
, vlan_id
, BOOT_ENABLE
);
2405 spin_unlock_irq(&phba
->hbalock
);
2409 * If the driver FCF record has boot flag set and the
2410 * new hba FCF record does not have boot flag, read
2411 * the next FCF record.
2413 if (!boot_flag
&& (fcf_rec
->flag
& BOOT_ENABLE
)) {
2414 spin_unlock_irq(&phba
->hbalock
);
2418 * If the new hba FCF record has lower priority value
2419 * than the driver FCF record, use the new record.
2421 if (new_fcf_record
->fip_priority
< fcf_rec
->priority
) {
2422 /* Choose the new FCF record with lower priority */
2423 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2424 "2838 Update current FCF record "
2425 "(x%x) with new FCF record (x%x)\n",
2427 bf_get(lpfc_fcf_record_fcf_index
,
2429 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2430 addr_mode
, vlan_id
, 0);
2431 /* Reset running random FCF selection count */
2432 phba
->fcf
.eligible_fcf_cnt
= 1;
2433 } else if (new_fcf_record
->fip_priority
== fcf_rec
->priority
) {
2434 /* Update running random FCF selection count */
2435 phba
->fcf
.eligible_fcf_cnt
++;
2436 select_new_fcf
= lpfc_sli4_new_fcf_random_select(phba
,
2437 phba
->fcf
.eligible_fcf_cnt
);
2438 if (select_new_fcf
) {
2439 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2440 "2839 Update current FCF record "
2441 "(x%x) with new FCF record (x%x)\n",
2443 bf_get(lpfc_fcf_record_fcf_index
,
2445 /* Choose the new FCF by random selection */
2446 __lpfc_update_fcf_record(phba
, fcf_rec
,
2448 addr_mode
, vlan_id
, 0);
2451 spin_unlock_irq(&phba
->hbalock
);
2455 * This is the first suitable FCF record, choose this record for
2456 * initial best-fit FCF.
2459 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2460 "2840 Update initial FCF candidate "
2462 bf_get(lpfc_fcf_record_fcf_index
,
2464 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2465 addr_mode
, vlan_id
, (boot_flag
?
2467 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2468 /* Setup initial running random FCF selection count */
2469 phba
->fcf
.eligible_fcf_cnt
= 1;
2471 spin_unlock_irq(&phba
->hbalock
);
2475 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2476 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0) {
2477 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
) {
2479 * Case of FCF fast failover scan
2483 * It has not found any suitable FCF record, cancel
2484 * FCF scan inprogress, and do nothing
2486 if (!(phba
->fcf
.failover_rec
.flag
& RECORD_VALID
)) {
2487 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2488 "2782 No suitable FCF found: "
2490 phba
->fcoe_eventtag_at_fcf_scan
,
2491 bf_get(lpfc_fcf_record_fcf_index
,
2493 spin_lock_irq(&phba
->hbalock
);
2494 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2495 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2496 spin_unlock_irq(&phba
->hbalock
);
2497 /* Unregister in-use FCF and rescan */
2498 lpfc_printf_log(phba
, KERN_INFO
,
2500 "2864 On devloss tmo "
2501 "unreg in-use FCF and "
2502 "rescan FCF table\n");
2503 lpfc_unregister_fcf_rescan(phba
);
2507 * Let next new FCF event trigger fast failover
2509 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2510 spin_unlock_irq(&phba
->hbalock
);
2514 * It has found a suitable FCF record that is not
2515 * the same as in-use FCF record, unregister the
2516 * in-use FCF record, replace the in-use FCF record
2517 * with the new FCF record, mark FCF fast failover
2518 * completed, and then start register the new FCF
2522 /* Unregister the current in-use FCF record */
2523 lpfc_unregister_fcf(phba
);
2525 /* Replace in-use record with the new record */
2526 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2527 "2842 Replace in-use FCF (x%x) "
2528 "with failover FCF (x%x)\n",
2529 phba
->fcf
.current_rec
.fcf_indx
,
2530 phba
->fcf
.failover_rec
.fcf_indx
);
2531 memcpy(&phba
->fcf
.current_rec
,
2532 &phba
->fcf
.failover_rec
,
2533 sizeof(struct lpfc_fcf_rec
));
2535 * Mark the fast FCF failover rediscovery completed
2536 * and the start of the first round of the roundrobin
2539 spin_lock_irq(&phba
->hbalock
);
2540 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2541 spin_unlock_irq(&phba
->hbalock
);
2542 /* Register to the new FCF record */
2543 lpfc_register_fcf(phba
);
2546 * In case of transaction period to fast FCF failover,
2547 * do nothing when search to the end of the FCF table.
2549 if ((phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) ||
2550 (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
))
2553 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2554 phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2556 * In case the current in-use FCF record no
2557 * longer existed during FCF discovery that
2558 * was not triggered by fast FCF failover
2559 * process, treat it as fast FCF failover.
2561 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2562 "2841 In-use FCF record (x%x) "
2563 "not reported, entering fast "
2564 "FCF failover mode scanning.\n",
2565 phba
->fcf
.current_rec
.fcf_indx
);
2566 spin_lock_irq(&phba
->hbalock
);
2567 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2568 spin_unlock_irq(&phba
->hbalock
);
2569 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2570 LPFC_FCOE_FCF_GET_FIRST
);
2573 /* Register to the new FCF record */
2574 lpfc_register_fcf(phba
);
2577 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, next_fcf_index
);
2581 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2582 lpfc_register_fcf(phba
);
2588 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2589 * @phba: pointer to lpfc hba data structure.
2590 * @mboxq: pointer to mailbox object.
2592 * This is the callback function for FLOGI failure roundrobin FCF failover
2593 * read FCF record mailbox command from the eligible FCF record bmask for
2594 * performing the failover. If the FCF read back is not valid/available, it
2595 * fails through to retrying FLOGI to the currently registered FCF again.
2596 * Otherwise, if the FCF read back is valid and available, it will set the
2597 * newly read FCF record to the failover FCF record, unregister currently
2598 * registered FCF record, copy the failover FCF record to the current
2599 * FCF record, and then register the current FCF record before proceeding
2600 * to trying FLOGI on the new failover FCF.
2603 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2605 struct fcf_record
*new_fcf_record
;
2606 uint32_t boot_flag
, addr_mode
;
2607 uint16_t next_fcf_index
, fcf_index
;
2608 uint16_t current_fcf_index
;
2612 /* If link state is not up, stop the roundrobin failover process */
2613 if (phba
->link_state
< LPFC_LINK_UP
) {
2614 spin_lock_irq(&phba
->hbalock
);
2615 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
2616 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2617 spin_unlock_irq(&phba
->hbalock
);
2621 /* Parse the FCF record from the non-embedded mailbox command */
2622 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2624 if (!new_fcf_record
) {
2625 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2626 "2766 Mailbox command READ_FCF_RECORD "
2627 "failed to retrieve a FCF record. "
2628 "hba_flg x%x fcf_flg x%x\n", phba
->hba_flag
,
2629 phba
->fcf
.fcf_flag
);
2630 lpfc_unregister_fcf_rescan(phba
);
2634 /* Get the needed parameters from FCF record */
2635 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2636 &addr_mode
, &vlan_id
);
2638 /* Log the FCF record information if turned on */
2639 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2642 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2644 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2645 "2848 Remove ineligible FCF (x%x) from "
2646 "from roundrobin bmask\n", fcf_index
);
2647 /* Clear roundrobin bmask bit for ineligible FCF */
2648 lpfc_sli4_fcf_rr_index_clear(phba
, fcf_index
);
2649 /* Perform next round of roundrobin FCF failover */
2650 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
2651 rc
= lpfc_sli4_fcf_rr_next_proc(phba
->pport
, fcf_index
);
2657 if (fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
2658 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2659 "2760 Perform FLOGI roundrobin FCF failover: "
2660 "FCF (x%x) back to FCF (x%x)\n",
2661 phba
->fcf
.current_rec
.fcf_indx
, fcf_index
);
2662 /* Wait 500 ms before retrying FLOGI to current FCF */
2664 lpfc_issue_init_vfi(phba
->pport
);
2668 /* Upload new FCF record to the failover FCF record */
2669 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2670 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2671 phba
->fcf
.failover_rec
.fcf_indx
, fcf_index
);
2672 spin_lock_irq(&phba
->hbalock
);
2673 __lpfc_update_fcf_record(phba
, &phba
->fcf
.failover_rec
,
2674 new_fcf_record
, addr_mode
, vlan_id
,
2675 (boot_flag
? BOOT_ENABLE
: 0));
2676 spin_unlock_irq(&phba
->hbalock
);
2678 current_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
2680 /* Unregister the current in-use FCF record */
2681 lpfc_unregister_fcf(phba
);
2683 /* Replace in-use record with the new record */
2684 memcpy(&phba
->fcf
.current_rec
, &phba
->fcf
.failover_rec
,
2685 sizeof(struct lpfc_fcf_rec
));
2687 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2688 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2689 "(x%x) to FCF (x%x)\n", current_fcf_index
, fcf_index
);
2692 lpfc_register_fcf(phba
);
2694 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2698 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2699 * @phba: pointer to lpfc hba data structure.
2700 * @mboxq: pointer to mailbox object.
2702 * This is the callback function of read FCF record mailbox command for
2703 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2704 * failover when a new FCF event happened. If the FCF read back is
2705 * valid/available and it passes the connection list check, it updates
2706 * the bmask for the eligible FCF record for roundrobin failover.
2709 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2711 struct fcf_record
*new_fcf_record
;
2712 uint32_t boot_flag
, addr_mode
;
2713 uint16_t fcf_index
, next_fcf_index
;
2717 /* If link state is not up, no need to proceed */
2718 if (phba
->link_state
< LPFC_LINK_UP
)
2721 /* If FCF discovery period is over, no need to proceed */
2722 if (!(phba
->fcf
.fcf_flag
& FCF_DISCOVERY
))
2725 /* Parse the FCF record from the non-embedded mailbox command */
2726 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2728 if (!new_fcf_record
) {
2729 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2730 "2767 Mailbox command READ_FCF_RECORD "
2731 "failed to retrieve a FCF record.\n");
2735 /* Check the connection list for eligibility */
2736 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2737 &addr_mode
, &vlan_id
);
2739 /* Log the FCF record information if turned on */
2740 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2746 /* Update the eligible FCF record index bmask */
2747 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2749 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
, new_fcf_record
);
2752 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2756 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2757 * @phba: pointer to lpfc hba data structure.
2758 * @mboxq: pointer to mailbox data structure.
2760 * This function handles completion of init vfi mailbox command.
2763 lpfc_init_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2765 struct lpfc_vport
*vport
= mboxq
->vport
;
2768 * VFI not supported on interface type 0, just do the flogi
2769 * Also continue if the VFI is in use - just use the same one.
2771 if (mboxq
->u
.mb
.mbxStatus
&&
2772 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2773 LPFC_SLI_INTF_IF_TYPE_0
) &&
2774 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
2775 lpfc_printf_vlog(vport
, KERN_ERR
,
2777 "2891 Init VFI mailbox failed 0x%x\n",
2778 mboxq
->u
.mb
.mbxStatus
);
2779 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2780 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2784 lpfc_initial_flogi(vport
);
2785 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2790 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2791 * @vport: pointer to lpfc_vport data structure.
2793 * This function issue a init_vfi mailbox command to initialize the VFI and
2794 * VPI for the physical port.
2797 lpfc_issue_init_vfi(struct lpfc_vport
*vport
)
2799 LPFC_MBOXQ_t
*mboxq
;
2801 struct lpfc_hba
*phba
= vport
->phba
;
2803 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2805 lpfc_printf_vlog(vport
, KERN_ERR
,
2806 LOG_MBOX
, "2892 Failed to allocate "
2807 "init_vfi mailbox\n");
2810 lpfc_init_vfi(mboxq
, vport
);
2811 mboxq
->mbox_cmpl
= lpfc_init_vfi_cmpl
;
2812 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
2813 if (rc
== MBX_NOT_FINISHED
) {
2814 lpfc_printf_vlog(vport
, KERN_ERR
,
2815 LOG_MBOX
, "2893 Failed to issue init_vfi mailbox\n");
2816 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2821 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2822 * @phba: pointer to lpfc hba data structure.
2823 * @mboxq: pointer to mailbox data structure.
2825 * This function handles completion of init vpi mailbox command.
2828 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2830 struct lpfc_vport
*vport
= mboxq
->vport
;
2831 struct lpfc_nodelist
*ndlp
;
2832 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2834 if (mboxq
->u
.mb
.mbxStatus
) {
2835 lpfc_printf_vlog(vport
, KERN_ERR
,
2837 "2609 Init VPI mailbox failed 0x%x\n",
2838 mboxq
->u
.mb
.mbxStatus
);
2839 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2840 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2843 spin_lock_irq(shost
->host_lock
);
2844 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2845 spin_unlock_irq(shost
->host_lock
);
2847 /* If this port is physical port or FDISC is done, do reg_vpi */
2848 if ((phba
->pport
== vport
) || (vport
->port_state
== LPFC_FDISC
)) {
2849 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
2851 lpfc_printf_vlog(vport
, KERN_ERR
,
2853 "2731 Cannot find fabric "
2854 "controller node\n");
2856 lpfc_register_new_vport(phba
, vport
, ndlp
);
2857 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2861 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2862 lpfc_initial_fdisc(vport
);
2864 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
2865 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2866 "2606 No NPIV Fabric support\n");
2868 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2873 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2874 * @vport: pointer to lpfc_vport data structure.
2876 * This function issue a init_vpi mailbox command to initialize
2877 * VPI for the vport.
2880 lpfc_issue_init_vpi(struct lpfc_vport
*vport
)
2882 LPFC_MBOXQ_t
*mboxq
;
2885 if ((vport
->port_type
!= LPFC_PHYSICAL_PORT
) && (!vport
->vpi
)) {
2886 vpi
= lpfc_alloc_vpi(vport
->phba
);
2888 lpfc_printf_vlog(vport
, KERN_ERR
,
2890 "3303 Failed to obtain vport vpi\n");
2891 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2897 mboxq
= mempool_alloc(vport
->phba
->mbox_mem_pool
, GFP_KERNEL
);
2899 lpfc_printf_vlog(vport
, KERN_ERR
,
2900 LOG_MBOX
, "2607 Failed to allocate "
2901 "init_vpi mailbox\n");
2904 lpfc_init_vpi(vport
->phba
, mboxq
, vport
->vpi
);
2905 mboxq
->vport
= vport
;
2906 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
2907 rc
= lpfc_sli_issue_mbox(vport
->phba
, mboxq
, MBX_NOWAIT
);
2908 if (rc
== MBX_NOT_FINISHED
) {
2909 lpfc_printf_vlog(vport
, KERN_ERR
,
2910 LOG_MBOX
, "2608 Failed to issue init_vpi mailbox\n");
2911 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2916 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2917 * @phba: pointer to lpfc hba data structure.
2919 * This function loops through the list of vports on the @phba and issues an
2920 * FDISC if possible.
2923 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
2925 struct lpfc_vport
**vports
;
2928 vports
= lpfc_create_vport_work_array(phba
);
2929 if (vports
!= NULL
) {
2930 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2931 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
2933 /* There are no vpi for this vport */
2934 if (vports
[i
]->vpi
> phba
->max_vpi
) {
2935 lpfc_vport_set_state(vports
[i
],
2939 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2940 lpfc_vport_set_state(vports
[i
],
2944 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
2945 lpfc_issue_init_vpi(vports
[i
]);
2948 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2949 lpfc_initial_fdisc(vports
[i
]);
2951 lpfc_vport_set_state(vports
[i
],
2952 FC_VPORT_NO_FABRIC_SUPP
);
2953 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
2956 "Fabric support\n");
2960 lpfc_destroy_vport_work_array(phba
, vports
);
2964 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2966 struct lpfc_dmabuf
*dmabuf
= mboxq
->ctx_buf
;
2967 struct lpfc_vport
*vport
= mboxq
->vport
;
2968 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2971 * VFI not supported for interface type 0, so ignore any mailbox
2972 * error (except VFI in use) and continue with the discovery.
2974 if (mboxq
->u
.mb
.mbxStatus
&&
2975 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2976 LPFC_SLI_INTF_IF_TYPE_0
) &&
2977 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
2978 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2979 "2018 REG_VFI mbxStatus error x%x "
2981 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
2982 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2983 /* FLOGI failed, use loop map to make discovery list */
2984 lpfc_disc_list_loopmap(vport
);
2985 /* Start discovery */
2986 lpfc_disc_start(vport
);
2989 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2993 /* If the VFI is already registered, there is nothing else to do
2994 * Unless this was a VFI update and we are in PT2PT mode, then
2995 * we should drop through to set the port state to ready.
2997 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
2998 if (!(phba
->sli_rev
== LPFC_SLI_REV4
&&
2999 vport
->fc_flag
& FC_PT2PT
))
3002 /* The VPI is implicitly registered when the VFI is registered */
3003 spin_lock_irq(shost
->host_lock
);
3004 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3005 vport
->fc_flag
|= FC_VFI_REGISTERED
;
3006 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3007 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
3008 spin_unlock_irq(shost
->host_lock
);
3010 /* In case SLI4 FC loopback test, we are ready */
3011 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
3012 (phba
->link_flag
& LS_LOOPBACK_MODE
)) {
3013 phba
->link_state
= LPFC_HBA_READY
;
3017 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3018 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3019 "alpacnt:%d LinkState:%x topology:%x\n",
3020 vport
->port_state
, vport
->fc_flag
, vport
->fc_myDID
,
3021 vport
->phba
->alpa_map
[0],
3022 phba
->link_state
, phba
->fc_topology
);
3024 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3026 * For private loop or for NPort pt2pt,
3027 * just start discovery and we are done.
3029 if ((vport
->fc_flag
& FC_PT2PT
) ||
3030 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
3031 !(vport
->fc_flag
& FC_PUBLIC_LOOP
))) {
3033 /* Use loop map to make discovery list */
3034 lpfc_disc_list_loopmap(vport
);
3035 /* Start discovery */
3036 if (vport
->fc_flag
& FC_PT2PT
)
3037 vport
->port_state
= LPFC_VPORT_READY
;
3039 lpfc_disc_start(vport
);
3041 lpfc_start_fdiscs(phba
);
3042 lpfc_do_scr_ns_plogi(phba
, vport
);
3047 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3049 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
3056 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3058 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3059 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3060 struct lpfc_vport
*vport
= pmb
->vport
;
3061 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3062 struct serv_parm
*sp
= &vport
->fc_sparam
;
3065 /* Check for error */
3066 if (mb
->mbxStatus
) {
3067 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3068 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3069 "0319 READ_SPARAM mbxStatus error x%x "
3071 mb
->mbxStatus
, vport
->port_state
);
3072 lpfc_linkdown(phba
);
3076 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
3077 sizeof (struct serv_parm
));
3079 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
3080 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
3081 ed_tov
= (ed_tov
+ 999999) / 1000000;
3083 phba
->fc_edtov
= ed_tov
;
3084 phba
->fc_ratov
= (2 * ed_tov
) / 1000;
3085 if (phba
->fc_ratov
< FF_DEF_RATOV
) {
3086 /* RA_TOV should be atleast 10sec for initial flogi */
3087 phba
->fc_ratov
= FF_DEF_RATOV
;
3090 lpfc_update_vport_wwn(vport
);
3091 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3092 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
3093 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
3094 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
3097 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3099 mempool_free(pmb
, phba
->mbox_mem_pool
);
3103 pmb
->ctx_buf
= NULL
;
3104 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3106 lpfc_issue_clear_la(phba
, vport
);
3107 mempool_free(pmb
, phba
->mbox_mem_pool
);
3112 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, struct lpfc_mbx_read_top
*la
)
3114 struct lpfc_vport
*vport
= phba
->pport
;
3115 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
3116 struct Scsi_Host
*shost
;
3118 struct lpfc_dmabuf
*mp
;
3120 struct fcf_record
*fcf_record
;
3121 uint32_t fc_flags
= 0;
3123 spin_lock_irq(&phba
->hbalock
);
3124 phba
->fc_linkspeed
= bf_get(lpfc_mbx_read_top_link_spd
, la
);
3126 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3127 switch (bf_get(lpfc_mbx_read_top_link_spd
, la
)) {
3128 case LPFC_LINK_SPEED_1GHZ
:
3129 case LPFC_LINK_SPEED_2GHZ
:
3130 case LPFC_LINK_SPEED_4GHZ
:
3131 case LPFC_LINK_SPEED_8GHZ
:
3132 case LPFC_LINK_SPEED_10GHZ
:
3133 case LPFC_LINK_SPEED_16GHZ
:
3134 case LPFC_LINK_SPEED_32GHZ
:
3135 case LPFC_LINK_SPEED_64GHZ
:
3136 case LPFC_LINK_SPEED_128GHZ
:
3139 phba
->fc_linkspeed
= LPFC_LINK_SPEED_UNKNOWN
;
3144 if (phba
->fc_topology
&&
3145 phba
->fc_topology
!= bf_get(lpfc_mbx_read_top_topology
, la
)) {
3146 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3147 "3314 Toplogy changed was 0x%x is 0x%x\n",
3149 bf_get(lpfc_mbx_read_top_topology
, la
));
3150 phba
->fc_topology_changed
= 1;
3153 phba
->fc_topology
= bf_get(lpfc_mbx_read_top_topology
, la
);
3154 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
3156 shost
= lpfc_shost_from_vport(vport
);
3157 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3158 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
3160 /* if npiv is enabled and this adapter supports npiv log
3161 * a message that npiv is not supported in this topology
3163 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
3164 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3165 "1309 Link Up Event npiv not supported in loop "
3167 /* Get Loop Map information */
3168 if (bf_get(lpfc_mbx_read_top_il
, la
))
3169 fc_flags
|= FC_LBIT
;
3171 vport
->fc_myDID
= bf_get(lpfc_mbx_read_top_alpa_granted
, la
);
3172 i
= la
->lilpBde64
.tus
.f
.bdeSize
;
3175 phba
->alpa_map
[0] = 0;
3177 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
3188 numalpa
= phba
->alpa_map
[0];
3190 while (j
< numalpa
) {
3191 memset(un
.pamap
, 0, 16);
3192 for (k
= 1; j
< numalpa
; k
++) {
3194 phba
->alpa_map
[j
+ 1];
3199 /* Link Up Event ALPA map */
3200 lpfc_printf_log(phba
,
3203 "1304 Link Up Event "
3204 "ALPA map Data: x%x "
3206 un
.pa
.wd1
, un
.pa
.wd2
,
3207 un
.pa
.wd3
, un
.pa
.wd4
);
3212 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
3213 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
3214 (phba
->sli_rev
>= LPFC_SLI_REV3
))
3215 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3217 vport
->fc_myDID
= phba
->fc_pref_DID
;
3218 fc_flags
|= FC_LBIT
;
3220 spin_unlock_irq(&phba
->hbalock
);
3223 spin_lock_irq(shost
->host_lock
);
3224 vport
->fc_flag
|= fc_flags
;
3225 spin_unlock_irq(shost
->host_lock
);
3229 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3233 rc
= lpfc_read_sparam(phba
, sparam_mbox
, 0);
3235 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3238 sparam_mbox
->vport
= vport
;
3239 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
3240 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
3241 if (rc
== MBX_NOT_FINISHED
) {
3242 mp
= (struct lpfc_dmabuf
*)sparam_mbox
->ctx_buf
;
3243 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3245 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3249 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3250 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3253 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
3254 lpfc_config_link(phba
, cfglink_mbox
);
3255 cfglink_mbox
->vport
= vport
;
3256 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
3257 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
3258 if (rc
== MBX_NOT_FINISHED
) {
3259 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
3263 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
3265 * Add the driver's default FCF record at FCF index 0 now. This
3266 * is phase 1 implementation that support FCF index 0 and driver
3269 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
3270 fcf_record
= kzalloc(sizeof(struct fcf_record
),
3272 if (unlikely(!fcf_record
)) {
3273 lpfc_printf_log(phba
, KERN_ERR
,
3275 "2554 Could not allocate memory for "
3281 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
3282 LPFC_FCOE_FCF_DEF_INDEX
);
3283 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
3285 lpfc_printf_log(phba
, KERN_ERR
,
3287 "2013 Could not manually add FCF "
3288 "record 0, status %d\n", rc
);
3296 * The driver is expected to do FIP/FCF. Call the port
3297 * and get the FCF Table.
3299 spin_lock_irq(&phba
->hbalock
);
3300 if (phba
->hba_flag
& FCF_TS_INPROG
) {
3301 spin_unlock_irq(&phba
->hbalock
);
3304 /* This is the initial FCF discovery scan */
3305 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
3306 spin_unlock_irq(&phba
->hbalock
);
3307 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3308 "2778 Start FCF table scan at linkup\n");
3309 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3310 LPFC_FCOE_FCF_GET_FIRST
);
3312 spin_lock_irq(&phba
->hbalock
);
3313 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
3314 spin_unlock_irq(&phba
->hbalock
);
3317 /* Reset FCF roundrobin bmask for new discovery */
3318 lpfc_sli4_clear_fcf_rr_bmask(phba
);
3323 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3324 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3325 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3326 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
3327 lpfc_issue_clear_la(phba
, vport
);
3332 lpfc_enable_la(struct lpfc_hba
*phba
)
3335 struct lpfc_sli
*psli
= &phba
->sli
;
3336 spin_lock_irq(&phba
->hbalock
);
3337 psli
->sli_flag
|= LPFC_PROCESS_LA
;
3338 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
3339 control
= readl(phba
->HCregaddr
);
3340 control
|= HC_LAINT_ENA
;
3341 writel(control
, phba
->HCregaddr
);
3342 readl(phba
->HCregaddr
); /* flush */
3344 spin_unlock_irq(&phba
->hbalock
);
3348 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
3350 lpfc_linkdown(phba
);
3351 lpfc_enable_la(phba
);
3352 lpfc_unregister_unused_fcf(phba
);
3353 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3358 * This routine handles processing a READ_TOPOLOGY mailbox
3359 * command upon completion. It is setup in the LPFC_MBOXQ
3360 * as the completion routine when the command is
3361 * handed off to the SLI layer. SLI4 only.
3364 lpfc_mbx_cmpl_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3366 struct lpfc_vport
*vport
= pmb
->vport
;
3367 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3368 struct lpfc_mbx_read_top
*la
;
3369 struct lpfc_sli_ring
*pring
;
3370 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3371 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3374 /* Unblock ELS traffic */
3375 pring
= lpfc_phba_elsring(phba
);
3377 pring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3379 /* Check for error */
3380 if (mb
->mbxStatus
) {
3381 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3382 "1307 READ_LA mbox error x%x state x%x\n",
3383 mb
->mbxStatus
, vport
->port_state
);
3384 lpfc_mbx_issue_link_down(phba
);
3385 phba
->link_state
= LPFC_HBA_ERROR
;
3386 goto lpfc_mbx_cmpl_read_topology_free_mbuf
;
3389 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3390 attn_type
= bf_get(lpfc_mbx_read_top_att_type
, la
);
3392 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
3394 spin_lock_irq(shost
->host_lock
);
3395 if (bf_get(lpfc_mbx_read_top_pb
, la
))
3396 vport
->fc_flag
|= FC_BYPASSED_MODE
;
3398 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
3399 spin_unlock_irq(shost
->host_lock
);
3401 if (phba
->fc_eventTag
<= la
->eventTag
) {
3402 phba
->fc_stat
.LinkMultiEvent
++;
3403 if (attn_type
== LPFC_ATT_LINK_UP
)
3404 if (phba
->fc_eventTag
!= 0)
3405 lpfc_linkdown(phba
);
3408 phba
->fc_eventTag
= la
->eventTag
;
3409 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3410 spin_lock_irq(&phba
->hbalock
);
3411 if (bf_get(lpfc_mbx_read_top_mm
, la
))
3412 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
3414 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
3415 spin_unlock_irq(&phba
->hbalock
);
3418 phba
->link_events
++;
3419 if ((attn_type
== LPFC_ATT_LINK_UP
) &&
3420 !(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)) {
3421 phba
->fc_stat
.LinkUp
++;
3422 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
3423 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3424 "1306 Link Up Event in loop back mode "
3425 "x%x received Data: x%x x%x x%x x%x\n",
3426 la
->eventTag
, phba
->fc_eventTag
,
3427 bf_get(lpfc_mbx_read_top_alpa_granted
,
3429 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3432 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3433 "1303 Link Up Event x%x received "
3434 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3435 la
->eventTag
, phba
->fc_eventTag
,
3436 bf_get(lpfc_mbx_read_top_alpa_granted
,
3438 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3440 bf_get(lpfc_mbx_read_top_mm
, la
),
3441 bf_get(lpfc_mbx_read_top_fa
, la
),
3442 phba
->wait_4_mlo_maint_flg
);
3444 lpfc_mbx_process_link_up(phba
, la
);
3445 } else if (attn_type
== LPFC_ATT_LINK_DOWN
||
3446 attn_type
== LPFC_ATT_UNEXP_WWPN
) {
3447 phba
->fc_stat
.LinkDown
++;
3448 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
3449 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3450 "1308 Link Down Event in loop back mode "
3452 "Data: x%x x%x x%x\n",
3453 la
->eventTag
, phba
->fc_eventTag
,
3454 phba
->pport
->port_state
, vport
->fc_flag
);
3455 else if (attn_type
== LPFC_ATT_UNEXP_WWPN
)
3456 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3457 "1313 Link Down UNEXP WWPN Event x%x received "
3458 "Data: x%x x%x x%x x%x x%x\n",
3459 la
->eventTag
, phba
->fc_eventTag
,
3460 phba
->pport
->port_state
, vport
->fc_flag
,
3461 bf_get(lpfc_mbx_read_top_mm
, la
),
3462 bf_get(lpfc_mbx_read_top_fa
, la
));
3464 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3465 "1305 Link Down Event x%x received "
3466 "Data: x%x x%x x%x x%x x%x\n",
3467 la
->eventTag
, phba
->fc_eventTag
,
3468 phba
->pport
->port_state
, vport
->fc_flag
,
3469 bf_get(lpfc_mbx_read_top_mm
, la
),
3470 bf_get(lpfc_mbx_read_top_fa
, la
));
3471 lpfc_mbx_issue_link_down(phba
);
3473 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
&&
3474 attn_type
== LPFC_ATT_LINK_UP
) {
3475 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
3476 phba
->fc_stat
.LinkDown
++;
3477 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3478 "1312 Link Down Event x%x received "
3479 "Data: x%x x%x x%x\n",
3480 la
->eventTag
, phba
->fc_eventTag
,
3481 phba
->pport
->port_state
, vport
->fc_flag
);
3482 lpfc_mbx_issue_link_down(phba
);
3484 lpfc_enable_la(phba
);
3486 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3487 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3488 "Data: x%x x%x x%x\n",
3489 la
->eventTag
, phba
->fc_eventTag
,
3490 phba
->pport
->port_state
, vport
->fc_flag
);
3492 * The cmnd that triggered this will be waiting for this
3495 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3496 if (phba
->wait_4_mlo_maint_flg
) {
3497 phba
->wait_4_mlo_maint_flg
= 0;
3498 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
3502 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3503 bf_get(lpfc_mbx_read_top_fa
, la
)) {
3504 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
3505 lpfc_issue_clear_la(phba
, vport
);
3506 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3508 bf_get(lpfc_mbx_read_top_fa
, la
));
3511 lpfc_mbx_cmpl_read_topology_free_mbuf
:
3512 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3514 mempool_free(pmb
, phba
->mbox_mem_pool
);
3519 * This routine handles processing a REG_LOGIN mailbox
3520 * command upon completion. It is setup in the LPFC_MBOXQ
3521 * as the completion routine when the command is
3522 * handed off to the SLI layer.
3525 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3527 struct lpfc_vport
*vport
= pmb
->vport
;
3528 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3529 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
3530 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3532 pmb
->ctx_buf
= NULL
;
3533 pmb
->ctx_ndlp
= NULL
;
3535 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3536 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3537 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3538 kref_read(&ndlp
->kref
),
3539 ndlp
->nlp_usg_map
, ndlp
);
3540 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
3541 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3543 if (ndlp
->nlp_flag
& NLP_IGNR_REG_CMPL
||
3544 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) {
3545 /* We rcvd a rscn after issuing this
3546 * mbox reg login, we may have cycled
3547 * back through the state and be
3548 * back at reg login state so this
3549 * mbox needs to be ignored becase
3550 * there is another reg login in
3553 spin_lock_irq(shost
->host_lock
);
3554 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
3555 spin_unlock_irq(shost
->host_lock
);
3558 * We cannot leave the RPI registered because
3559 * if we go thru discovery again for this ndlp
3560 * a subsequent REG_RPI will fail.
3562 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3563 lpfc_unreg_rpi(vport
, ndlp
);
3566 /* Call state machine */
3567 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
3569 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3571 mempool_free(pmb
, phba
->mbox_mem_pool
);
3572 /* decrement the node reference count held for this callback
3581 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3583 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3584 struct lpfc_vport
*vport
= pmb
->vport
;
3585 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3587 switch (mb
->mbxStatus
) {
3590 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3591 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3594 /* If VPI is busy, reset the HBA */
3596 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3597 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3598 vport
->vpi
, mb
->mbxStatus
);
3599 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
3600 lpfc_workq_post_event(phba
, NULL
, NULL
,
3601 LPFC_EVT_RESET_HBA
);
3603 spin_lock_irq(shost
->host_lock
);
3604 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3605 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3606 spin_unlock_irq(shost
->host_lock
);
3607 vport
->unreg_vpi_cmpl
= VPORT_OK
;
3608 mempool_free(pmb
, phba
->mbox_mem_pool
);
3609 lpfc_cleanup_vports_rrqs(vport
, NULL
);
3611 * This shost reference might have been taken at the beginning of
3612 * lpfc_vport_delete()
3614 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
3615 scsi_host_put(shost
);
3619 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
3621 struct lpfc_hba
*phba
= vport
->phba
;
3625 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3629 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
3630 mbox
->vport
= vport
;
3631 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
3632 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3633 if (rc
== MBX_NOT_FINISHED
) {
3634 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3635 "1800 Could not issue unreg_vpi\n");
3636 mempool_free(mbox
, phba
->mbox_mem_pool
);
3637 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
3644 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3646 struct lpfc_vport
*vport
= pmb
->vport
;
3647 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3648 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3650 switch (mb
->mbxStatus
) {
3654 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3655 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3657 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3658 spin_lock_irq(shost
->host_lock
);
3659 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3660 spin_unlock_irq(shost
->host_lock
);
3661 vport
->fc_myDID
= 0;
3663 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3664 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3665 if (phba
->nvmet_support
)
3666 lpfc_nvmet_update_targetport(phba
);
3668 lpfc_nvme_update_localport(vport
);
3673 spin_lock_irq(shost
->host_lock
);
3674 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3675 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3676 spin_unlock_irq(shost
->host_lock
);
3677 vport
->num_disc_nodes
= 0;
3678 /* go thru NPR list and issue ELS PLOGIs */
3679 if (vport
->fc_npr_cnt
)
3680 lpfc_els_disc_plogi(vport
);
3682 if (!vport
->num_disc_nodes
) {
3683 spin_lock_irq(shost
->host_lock
);
3684 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3685 spin_unlock_irq(shost
->host_lock
);
3686 lpfc_can_disctmo(vport
);
3688 vport
->port_state
= LPFC_VPORT_READY
;
3691 mempool_free(pmb
, phba
->mbox_mem_pool
);
3696 * lpfc_create_static_vport - Read HBA config region to create static vports.
3697 * @phba: pointer to lpfc hba data structure.
3699 * This routine issue a DUMP mailbox command for config region 22 to get
3700 * the list of static vports to be created. The function create vports
3701 * based on the information returned from the HBA.
3704 lpfc_create_static_vport(struct lpfc_hba
*phba
)
3706 LPFC_MBOXQ_t
*pmb
= NULL
;
3708 struct static_vport_info
*vport_info
;
3709 int mbx_wait_rc
= 0, i
;
3710 struct fc_vport_identifiers vport_id
;
3711 struct fc_vport
*new_fc_vport
;
3712 struct Scsi_Host
*shost
;
3713 struct lpfc_vport
*vport
;
3714 uint16_t offset
= 0;
3715 uint8_t *vport_buff
;
3716 struct lpfc_dmabuf
*mp
;
3717 uint32_t byte_count
= 0;
3719 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3721 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3722 "0542 lpfc_create_static_vport failed to"
3723 " allocate mailbox memory\n");
3726 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
3729 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
3731 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3732 "0543 lpfc_create_static_vport failed to"
3733 " allocate vport_info\n");
3734 mempool_free(pmb
, phba
->mbox_mem_pool
);
3738 vport_buff
= (uint8_t *) vport_info
;
3740 /* free dma buffer from previous round */
3742 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3743 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3746 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
3749 pmb
->vport
= phba
->pport
;
3750 mbx_wait_rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
,
3753 if ((mbx_wait_rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
3754 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3755 "0544 lpfc_create_static_vport failed to"
3756 " issue dump mailbox command ret 0x%x "
3758 mbx_wait_rc
, mb
->mbxStatus
);
3762 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3763 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
3764 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3765 if (byte_count
> sizeof(struct static_vport_info
) -
3767 byte_count
= sizeof(struct static_vport_info
)
3769 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
3770 offset
+= byte_count
;
3772 if (mb
->un
.varDmp
.word_cnt
>
3773 sizeof(struct static_vport_info
) - offset
)
3774 mb
->un
.varDmp
.word_cnt
=
3775 sizeof(struct static_vport_info
)
3777 byte_count
= mb
->un
.varDmp
.word_cnt
;
3778 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
3779 vport_buff
+ offset
,
3782 offset
+= byte_count
;
3785 } while (byte_count
&&
3786 offset
< sizeof(struct static_vport_info
));
3789 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
3790 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
3791 != VPORT_INFO_REV
)) {
3792 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3793 "0545 lpfc_create_static_vport bad"
3794 " information header 0x%x 0x%x\n",
3795 le32_to_cpu(vport_info
->signature
),
3796 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
3801 shost
= lpfc_shost_from_vport(phba
->pport
);
3803 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
3804 memset(&vport_id
, 0, sizeof(vport_id
));
3805 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
3806 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
3807 if (!vport_id
.port_name
|| !vport_id
.node_name
)
3810 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
3811 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
3812 vport_id
.disable
= false;
3813 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
3815 if (!new_fc_vport
) {
3816 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3817 "0546 lpfc_create_static_vport failed to"
3822 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
3823 vport
->vport_flag
|= STATIC_VPORT
;
3828 if (mbx_wait_rc
!= MBX_TIMEOUT
) {
3830 mp
= (struct lpfc_dmabuf
*)pmb
->ctx_buf
;
3831 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3834 mempool_free(pmb
, phba
->mbox_mem_pool
);
3841 * This routine handles processing a Fabric REG_LOGIN mailbox
3842 * command upon completion. It is setup in the LPFC_MBOXQ
3843 * as the completion routine when the command is
3844 * handed off to the SLI layer.
3847 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3849 struct lpfc_vport
*vport
= pmb
->vport
;
3850 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3851 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
3852 struct lpfc_nodelist
*ndlp
;
3853 struct Scsi_Host
*shost
;
3855 ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
3856 pmb
->ctx_ndlp
= NULL
;
3857 pmb
->ctx_buf
= NULL
;
3859 if (mb
->mbxStatus
) {
3860 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3861 "0258 Register Fabric login error: 0x%x\n",
3863 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3865 mempool_free(pmb
, phba
->mbox_mem_pool
);
3867 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3868 /* FLOGI failed, use loop map to make discovery list */
3869 lpfc_disc_list_loopmap(vport
);
3871 /* Start discovery */
3872 lpfc_disc_start(vport
);
3873 /* Decrement the reference count to ndlp after the
3874 * reference to the ndlp are done.
3880 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3881 /* Decrement the reference count to ndlp after the reference
3882 * to the ndlp are done.
3888 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3889 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3890 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3891 ndlp
->nlp_type
|= NLP_FABRIC
;
3892 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3894 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3895 /* when physical port receive logo donot start
3896 * vport discovery */
3897 if (!(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
3898 lpfc_start_fdiscs(phba
);
3900 shost
= lpfc_shost_from_vport(vport
);
3901 spin_lock_irq(shost
->host_lock
);
3902 vport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
3903 spin_unlock_irq(shost
->host_lock
);
3905 lpfc_do_scr_ns_plogi(phba
, vport
);
3908 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3910 mempool_free(pmb
, phba
->mbox_mem_pool
);
3912 /* Drop the reference count from the mbox at the end after
3913 * all the current reference to the ndlp have been done.
3920 * This routine will issue a GID_FT for each FC4 Type supported
3921 * by the driver. ALL GID_FTs must complete before discovery is started.
3924 lpfc_issue_gidft(struct lpfc_vport
*vport
)
3926 struct lpfc_hba
*phba
= vport
->phba
;
3928 /* Good status, issue CT Request to NameServer */
3929 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3930 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
)) {
3931 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_FCP
)) {
3932 /* Cannot issue NameServer FCP Query, so finish up
3935 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
3936 "0604 %s FC TYPE %x %s\n",
3937 "Failed to issue GID_FT to ",
3939 "Finishing discovery.");
3945 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3946 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3947 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_NVME
)) {
3948 /* Cannot issue NameServer NVME Query, so finish up
3951 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
3952 "0605 %s FC_TYPE %x %s %d\n",
3953 "Failed to issue GID_FT to ",
3955 "Finishing discovery: gidftinp ",
3957 if (vport
->gidft_inp
== 0)
3962 return vport
->gidft_inp
;
3966 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
3967 * @vport: The virtual port for which this call is being executed.
3969 * This routine will issue a GID_PT to get a list of all N_Ports
3972 * 0 - Failure to issue a GID_PT
3976 lpfc_issue_gidpt(struct lpfc_vport
*vport
)
3978 /* Good status, issue CT Request to NameServer */
3979 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_PT
, 0, GID_PT_N_PORT
)) {
3980 /* Cannot issue NameServer FCP Query, so finish up
3983 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
3984 "0606 %s Port TYPE %x %s\n",
3985 "Failed to issue GID_PT to ",
3987 "Finishing discovery.");
3995 * This routine handles processing a NameServer REG_LOGIN mailbox
3996 * command upon completion. It is setup in the LPFC_MBOXQ
3997 * as the completion routine when the command is
3998 * handed off to the SLI layer.
4001 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4003 MAILBOX_t
*mb
= &pmb
->u
.mb
;
4004 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
4005 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
4006 struct lpfc_vport
*vport
= pmb
->vport
;
4008 pmb
->ctx_buf
= NULL
;
4009 pmb
->ctx_ndlp
= NULL
;
4010 vport
->gidft_inp
= 0;
4012 if (mb
->mbxStatus
) {
4013 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4014 "0260 Register NameServer error: 0x%x\n",
4018 /* decrement the node reference count held for this
4019 * callback function.
4022 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4024 mempool_free(pmb
, phba
->mbox_mem_pool
);
4026 /* If no other thread is using the ndlp, free it */
4027 lpfc_nlp_not_used(ndlp
);
4029 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4031 * RegLogin failed, use loop map to make discovery
4034 lpfc_disc_list_loopmap(vport
);
4036 /* Start discovery */
4037 lpfc_disc_start(vport
);
4040 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4044 if (phba
->sli_rev
< LPFC_SLI_REV4
)
4045 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4046 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
4047 ndlp
->nlp_type
|= NLP_FABRIC
;
4048 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4049 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
4050 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
4051 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4052 kref_read(&ndlp
->kref
),
4053 ndlp
->nlp_usg_map
, ndlp
);
4055 if (vport
->port_state
< LPFC_VPORT_READY
) {
4056 /* Link up discovery requires Fabric registration. */
4057 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
4058 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
4059 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
4060 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
4062 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4063 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
))
4064 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, FC_TYPE_FCP
);
4066 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4067 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
))
4068 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0,
4071 /* Issue SCR just before NameServer GID_FT Query */
4072 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
4075 vport
->fc_ns_retry
= 0;
4076 if (lpfc_issue_gidft(vport
) == 0)
4080 * At this point in time we may need to wait for multiple
4081 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4083 * decrement the node reference count held for this
4084 * callback function.
4087 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4089 mempool_free(pmb
, phba
->mbox_mem_pool
);
4095 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4097 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4098 struct fc_rport
*rport
;
4099 struct lpfc_rport_data
*rdata
;
4100 struct fc_rport_identifiers rport_ids
;
4101 struct lpfc_hba
*phba
= vport
->phba
;
4103 if (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4106 /* Remote port has reappeared. Re-register w/ FC transport */
4107 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
4108 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
4109 rport_ids
.port_id
= ndlp
->nlp_DID
;
4110 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
4113 * We leave our node pointer in rport->dd_data when we unregister a
4114 * FCP target port. But fc_remote_port_add zeros the space to which
4115 * rport->dd_data points. So, if we're reusing a previously
4116 * registered port, drop the reference that we took the last time we
4117 * registered the port.
4119 rport
= ndlp
->rport
;
4121 rdata
= rport
->dd_data
;
4122 /* break the link before dropping the ref */
4125 if (rdata
->pnode
== ndlp
)
4127 rdata
->pnode
= NULL
;
4129 /* drop reference for earlier registeration */
4130 put_device(&rport
->dev
);
4133 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4134 "rport add: did:x%x flg:x%x type x%x",
4135 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4137 /* Don't add the remote port if unloading. */
4138 if (vport
->load_flag
& FC_UNLOADING
)
4141 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
4142 if (!rport
|| !get_device(&rport
->dev
)) {
4143 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
4144 "Warning: fc_remote_port_add failed\n");
4148 /* initialize static port data */
4149 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
4150 rport
->supported_classes
= ndlp
->nlp_class_sup
;
4151 rdata
= rport
->dd_data
;
4152 rdata
->pnode
= lpfc_nlp_get(ndlp
);
4154 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
4155 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
4156 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
4157 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
4159 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
4160 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
4162 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4163 "3183 rport register x%06x, rport %p role x%x\n",
4164 ndlp
->nlp_DID
, rport
, rport_ids
.roles
);
4166 if ((rport
->scsi_target_id
!= -1) &&
4167 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
4168 ndlp
->nlp_sid
= rport
->scsi_target_id
;
4174 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
4176 struct fc_rport
*rport
= ndlp
->rport
;
4177 struct lpfc_vport
*vport
= ndlp
->vport
;
4178 struct lpfc_hba
*phba
= vport
->phba
;
4180 if (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4183 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4184 "rport delete: did:x%x flg:x%x type x%x",
4185 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4187 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4188 "3184 rport unregister x%06x, rport %p\n",
4189 ndlp
->nlp_DID
, rport
);
4191 fc_remote_port_delete(rport
);
4197 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
4199 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4201 spin_lock_irq(shost
->host_lock
);
4203 case NLP_STE_UNUSED_NODE
:
4204 vport
->fc_unused_cnt
+= count
;
4206 case NLP_STE_PLOGI_ISSUE
:
4207 vport
->fc_plogi_cnt
+= count
;
4209 case NLP_STE_ADISC_ISSUE
:
4210 vport
->fc_adisc_cnt
+= count
;
4212 case NLP_STE_REG_LOGIN_ISSUE
:
4213 vport
->fc_reglogin_cnt
+= count
;
4215 case NLP_STE_PRLI_ISSUE
:
4216 vport
->fc_prli_cnt
+= count
;
4218 case NLP_STE_UNMAPPED_NODE
:
4219 vport
->fc_unmap_cnt
+= count
;
4221 case NLP_STE_MAPPED_NODE
:
4222 vport
->fc_map_cnt
+= count
;
4224 case NLP_STE_NPR_NODE
:
4225 if (vport
->fc_npr_cnt
== 0 && count
== -1)
4226 vport
->fc_npr_cnt
= 0;
4228 vport
->fc_npr_cnt
+= count
;
4231 spin_unlock_irq(shost
->host_lock
);
4235 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4236 int old_state
, int new_state
)
4238 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4240 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
4241 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4242 ndlp
->nlp_type
|= NLP_FC_NODE
;
4244 if (new_state
== NLP_STE_MAPPED_NODE
)
4245 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4246 if (new_state
== NLP_STE_NPR_NODE
)
4247 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
4249 /* FCP and NVME Transport interface */
4250 if ((old_state
== NLP_STE_MAPPED_NODE
||
4251 old_state
== NLP_STE_UNMAPPED_NODE
)) {
4253 vport
->phba
->nport_event_cnt
++;
4254 lpfc_unregister_remote_port(ndlp
);
4257 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4258 vport
->phba
->nport_event_cnt
++;
4259 if (vport
->phba
->nvmet_support
== 0) {
4260 /* Start devloss if target. */
4261 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
4262 lpfc_nvme_unregister_port(vport
, ndlp
);
4264 /* NVMET has no upcall. */
4270 /* FCP and NVME Transport interfaces */
4272 if (new_state
== NLP_STE_MAPPED_NODE
||
4273 new_state
== NLP_STE_UNMAPPED_NODE
) {
4274 if (ndlp
->nlp_fc4_type
||
4275 ndlp
->nlp_DID
== Fabric_DID
||
4276 ndlp
->nlp_DID
== NameServer_DID
||
4277 ndlp
->nlp_DID
== FDMI_DID
) {
4278 vport
->phba
->nport_event_cnt
++;
4280 * Tell the fc transport about the port, if we haven't
4281 * already. If we have, and it's a scsi entity, be
4283 lpfc_register_remote_port(vport
, ndlp
);
4285 /* Notify the NVME transport of this new rport. */
4286 if (vport
->phba
->sli_rev
>= LPFC_SLI_REV4
&&
4287 ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4288 if (vport
->phba
->nvmet_support
== 0) {
4289 /* Register this rport with the transport.
4290 * Only NVME Target Rports are registered with
4293 if (ndlp
->nlp_type
& NLP_NVME_TARGET
) {
4294 vport
->phba
->nport_event_cnt
++;
4295 lpfc_nvme_register_port(vport
, ndlp
);
4298 /* Just take an NDLP ref count since the
4299 * target does not register rports.
4306 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4307 (vport
->stat_data_enabled
)) {
4309 * A new target is discovered, if there is no buffer for
4310 * statistical data collection allocate buffer.
4312 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
4313 sizeof(struct lpfc_scsicmd_bkt
),
4316 if (!ndlp
->lat_data
)
4317 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
4318 "0286 lpfc_nlp_state_cleanup failed to "
4319 "allocate statistical data buffer DID "
4320 "0x%x\n", ndlp
->nlp_DID
);
4323 * If the node just added to Mapped list was an FCP target,
4324 * but the remote port registration failed or assigned a target
4325 * id outside the presentable range - move the node to the
4328 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4329 (ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4331 ndlp
->rport
->scsi_target_id
== -1 ||
4332 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
4333 spin_lock_irq(shost
->host_lock
);
4334 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
4335 spin_unlock_irq(shost
->host_lock
);
4336 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4341 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
4343 static char *states
[] = {
4344 [NLP_STE_UNUSED_NODE
] = "UNUSED",
4345 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
4346 [NLP_STE_ADISC_ISSUE
] = "ADISC",
4347 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
4348 [NLP_STE_PRLI_ISSUE
] = "PRLI",
4349 [NLP_STE_LOGO_ISSUE
] = "LOGO",
4350 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
4351 [NLP_STE_MAPPED_NODE
] = "MAPPED",
4352 [NLP_STE_NPR_NODE
] = "NPR",
4355 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
4356 strlcpy(buffer
, states
[state
], size
);
4358 snprintf(buffer
, size
, "unknown (%d)", state
);
4363 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4366 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4367 int old_state
= ndlp
->nlp_state
;
4368 char name1
[16], name2
[16];
4370 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4371 "0904 NPort state transition x%06x, %s -> %s\n",
4373 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
4374 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
4376 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4377 "node statechg did:x%x old:%d ste:%d",
4378 ndlp
->nlp_DID
, old_state
, state
);
4380 if (old_state
== NLP_STE_NPR_NODE
&&
4381 state
!= NLP_STE_NPR_NODE
)
4382 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4383 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
4384 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
4385 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
4388 if (list_empty(&ndlp
->nlp_listp
)) {
4389 spin_lock_irq(shost
->host_lock
);
4390 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4391 spin_unlock_irq(shost
->host_lock
);
4392 } else if (old_state
)
4393 lpfc_nlp_counters(vport
, old_state
, -1);
4395 ndlp
->nlp_state
= state
;
4396 lpfc_nlp_counters(vport
, state
, 1);
4397 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
4401 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4403 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4405 if (list_empty(&ndlp
->nlp_listp
)) {
4406 spin_lock_irq(shost
->host_lock
);
4407 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4408 spin_unlock_irq(shost
->host_lock
);
4413 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4415 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4417 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4418 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
4419 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
4420 spin_lock_irq(shost
->host_lock
);
4421 list_del_init(&ndlp
->nlp_listp
);
4422 spin_unlock_irq(shost
->host_lock
);
4423 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
4424 NLP_STE_UNUSED_NODE
);
4428 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4430 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4431 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
4432 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
4433 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
4434 NLP_STE_UNUSED_NODE
);
4437 * lpfc_initialize_node - Initialize all fields of node object
4438 * @vport: Pointer to Virtual Port object.
4439 * @ndlp: Pointer to FC node object.
4440 * @did: FC_ID of the node.
4442 * This function is always called when node object need to be initialized.
4443 * It initializes all the fields of the node object. Although the reference
4444 * to phba from @ndlp can be obtained indirectly through it's reference to
4445 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4446 * to the life-span of the @ndlp might go beyond the existence of @vport as
4447 * the final release of ndlp is determined by its reference count. And, the
4448 * operation on @ndlp needs the reference to phba.
4451 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4454 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
4455 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
4456 timer_setup(&ndlp
->nlp_delayfunc
, lpfc_els_retry_delay
, 0);
4457 ndlp
->nlp_DID
= did
;
4458 ndlp
->vport
= vport
;
4459 ndlp
->phba
= vport
->phba
;
4460 ndlp
->nlp_sid
= NLP_NO_SID
;
4461 ndlp
->nlp_fc4_type
= NLP_FC4_NONE
;
4462 kref_init(&ndlp
->kref
);
4463 NLP_INT_NODE_ACT(ndlp
);
4464 atomic_set(&ndlp
->cmd_pending
, 0);
4465 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
4466 ndlp
->nlp_defer_did
= NLP_EVT_NOTHING_PENDING
;
4469 struct lpfc_nodelist
*
4470 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4473 struct lpfc_hba
*phba
= vport
->phba
;
4475 unsigned long flags
;
4476 unsigned long *active_rrqs_xri_bitmap
= NULL
;
4477 int rpi
= LPFC_RPI_ALLOC_ERROR
;
4478 uint32_t defer_did
= 0;
4483 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4484 rpi
= lpfc_sli4_alloc_rpi(vport
->phba
);
4485 if (rpi
== LPFC_RPI_ALLOC_ERROR
)
4489 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4490 /* The ndlp should not be in memory free mode */
4491 if (NLP_CHK_FREE_REQ(ndlp
)) {
4492 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4493 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4494 "0277 lpfc_enable_node: ndlp:x%p "
4495 "usgmap:x%x refcnt:%d\n",
4496 (void *)ndlp
, ndlp
->nlp_usg_map
,
4497 kref_read(&ndlp
->kref
));
4500 /* The ndlp should not already be in active mode */
4501 if (NLP_CHK_NODE_ACT(ndlp
)) {
4502 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4503 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4504 "0278 lpfc_enable_node: ndlp:x%p "
4505 "usgmap:x%x refcnt:%d\n",
4506 (void *)ndlp
, ndlp
->nlp_usg_map
,
4507 kref_read(&ndlp
->kref
));
4511 /* First preserve the orginal DID, xri_bitmap and some flags */
4512 did
= ndlp
->nlp_DID
;
4513 flag
= (ndlp
->nlp_flag
& NLP_UNREG_INP
);
4514 if (flag
& NLP_UNREG_INP
)
4515 defer_did
= ndlp
->nlp_defer_did
;
4516 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4517 active_rrqs_xri_bitmap
= ndlp
->active_rrqs_xri_bitmap
;
4519 /* Zero ndlp except of ndlp linked list pointer */
4520 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
4521 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
4523 /* Next reinitialize and restore saved objects */
4524 lpfc_initialize_node(vport
, ndlp
, did
);
4525 ndlp
->nlp_flag
|= flag
;
4526 if (flag
& NLP_UNREG_INP
)
4527 ndlp
->nlp_defer_did
= defer_did
;
4528 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4529 ndlp
->active_rrqs_xri_bitmap
= active_rrqs_xri_bitmap
;
4531 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4532 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4533 ndlp
->nlp_rpi
= rpi
;
4534 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4535 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4536 "map:%x %p\n", ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4538 kref_read(&ndlp
->kref
),
4539 ndlp
->nlp_usg_map
, ndlp
);
4543 if (state
!= NLP_STE_UNUSED_NODE
)
4544 lpfc_nlp_set_state(vport
, ndlp
, state
);
4546 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4547 "node enable: did:x%x",
4548 ndlp
->nlp_DID
, 0, 0);
4552 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4553 lpfc_sli4_free_rpi(vport
->phba
, rpi
);
4558 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4561 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4562 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4563 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4564 * until ALL other outstanding threads have completed. We check
4565 * that the ndlp not already in the UNUSED state before we proceed.
4567 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
4569 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4570 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4571 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
4572 lpfc_unreg_rpi(vport
, ndlp
);
4580 * Start / ReStart rescue timer for Discovery / RSCN handling
4583 lpfc_set_disctmo(struct lpfc_vport
*vport
)
4585 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4586 struct lpfc_hba
*phba
= vport
->phba
;
4589 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
4590 /* For FAN, timeout should be greater than edtov */
4591 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
4593 /* Normal discovery timeout should be > than ELS/CT timeout
4594 * FC spec states we need 3 * ratov for CT requests
4596 tmo
= ((phba
->fc_ratov
* 3) + 3);
4600 if (!timer_pending(&vport
->fc_disctmo
)) {
4601 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4602 "set disc timer: tmo:x%x state:x%x flg:x%x",
4603 tmo
, vport
->port_state
, vport
->fc_flag
);
4606 mod_timer(&vport
->fc_disctmo
, jiffies
+ msecs_to_jiffies(1000 * tmo
));
4607 spin_lock_irq(shost
->host_lock
);
4608 vport
->fc_flag
|= FC_DISC_TMO
;
4609 spin_unlock_irq(shost
->host_lock
);
4611 /* Start Discovery Timer state <hba_state> */
4612 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4613 "0247 Start Discovery Timer state x%x "
4614 "Data: x%x x%lx x%x x%x\n",
4615 vport
->port_state
, tmo
,
4616 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
4617 vport
->fc_adisc_cnt
);
4623 * Cancel rescue timer for Discovery / RSCN handling
4626 lpfc_can_disctmo(struct lpfc_vport
*vport
)
4628 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4629 unsigned long iflags
;
4631 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4632 "can disc timer: state:x%x rtry:x%x flg:x%x",
4633 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
4635 /* Turn off discovery timer if its running */
4636 if (vport
->fc_flag
& FC_DISC_TMO
) {
4637 spin_lock_irqsave(shost
->host_lock
, iflags
);
4638 vport
->fc_flag
&= ~FC_DISC_TMO
;
4639 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
4640 del_timer_sync(&vport
->fc_disctmo
);
4641 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
4642 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
4643 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
4646 /* Cancel Discovery Timer state <hba_state> */
4647 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4648 "0248 Cancel Discovery Timer state x%x "
4649 "Data: x%x x%x x%x\n",
4650 vport
->port_state
, vport
->fc_flag
,
4651 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
4656 * Check specified ring for outstanding IOCB on the SLI queue
4657 * Return true if iocb matches the specified nport
4660 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
4661 struct lpfc_sli_ring
*pring
,
4662 struct lpfc_iocbq
*iocb
,
4663 struct lpfc_nodelist
*ndlp
)
4665 IOCB_t
*icmd
= &iocb
->iocb
;
4666 struct lpfc_vport
*vport
= ndlp
->vport
;
4668 if (iocb
->vport
!= vport
)
4671 if (pring
->ringno
== LPFC_ELS_RING
) {
4672 switch (icmd
->ulpCommand
) {
4673 case CMD_GEN_REQUEST64_CR
:
4674 if (iocb
->context_un
.ndlp
== ndlp
)
4676 case CMD_ELS_REQUEST64_CR
:
4677 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
4679 case CMD_XMIT_ELS_RSP64_CX
:
4680 if (iocb
->context1
== (uint8_t *) ndlp
)
4683 } else if (pring
->ringno
== LPFC_FCP_RING
) {
4684 /* Skip match check if waiting to relogin to FCP target */
4685 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4686 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
4689 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
4697 __lpfc_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4698 struct lpfc_nodelist
*ndlp
, struct lpfc_sli_ring
*pring
,
4699 struct list_head
*dequeue_list
)
4701 struct lpfc_iocbq
*iocb
, *next_iocb
;
4703 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
4704 /* Check to see if iocb matches the nport */
4705 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
4706 /* match, dequeue */
4707 list_move_tail(&iocb
->list
, dequeue_list
);
4712 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4713 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4715 struct lpfc_sli
*psli
= &phba
->sli
;
4718 spin_lock_irq(&phba
->hbalock
);
4719 for (i
= 0; i
< psli
->num_rings
; i
++)
4720 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, &psli
->sli3_ring
[i
],
4722 spin_unlock_irq(&phba
->hbalock
);
4726 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4727 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4729 struct lpfc_sli_ring
*pring
;
4730 struct lpfc_queue
*qp
= NULL
;
4732 spin_lock_irq(&phba
->hbalock
);
4733 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
4737 spin_lock(&pring
->ring_lock
);
4738 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, pring
, dequeue_list
);
4739 spin_unlock(&pring
->ring_lock
);
4741 spin_unlock_irq(&phba
->hbalock
);
4745 * Free resources / clean up outstanding I/Os
4746 * associated with nlp_rpi in the LPFC_NODELIST entry.
4749 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4751 LIST_HEAD(completions
);
4753 lpfc_fabric_abort_nport(ndlp
);
4756 * Everything that matches on txcmplq will be returned
4757 * by firmware with a no rpi error.
4759 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4760 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4761 lpfc_sli3_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4763 lpfc_sli4_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4766 /* Cancel all the IOCBs from the completions list */
4767 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4774 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4775 * @phba: Pointer to HBA context object.
4776 * @pmb: Pointer to mailbox object.
4778 * This function will issue an ELS LOGO command after completing
4782 lpfc_nlp_logo_unreg(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4784 struct lpfc_vport
*vport
= pmb
->vport
;
4785 struct lpfc_nodelist
*ndlp
;
4787 ndlp
= (struct lpfc_nodelist
*)(pmb
->ctx_ndlp
);
4790 lpfc_issue_els_logo(vport
, ndlp
, 0);
4791 mempool_free(pmb
, phba
->mbox_mem_pool
);
4793 /* Check to see if there are any deferred events to process */
4794 if ((ndlp
->nlp_flag
& NLP_UNREG_INP
) &&
4795 (ndlp
->nlp_defer_did
!= NLP_EVT_NOTHING_PENDING
)) {
4796 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4797 "1434 UNREG cmpl deferred logo x%x "
4798 "on NPort x%x Data: x%x %p\n",
4799 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4800 ndlp
->nlp_defer_did
, ndlp
);
4802 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
4803 ndlp
->nlp_defer_did
= NLP_EVT_NOTHING_PENDING
;
4804 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4806 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
4811 * Free rpi associated with LPFC_NODELIST entry.
4812 * This routine is called from lpfc_freenode(), when we are removing
4813 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4814 * LOGO that completes successfully, and we are waiting to PLOGI back
4815 * to the remote NPort. In addition, it is called after we receive
4816 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4817 * we are waiting to PLOGI back to the remote NPort.
4820 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4822 struct lpfc_hba
*phba
= vport
->phba
;
4824 int rc
, acc_plogi
= 1;
4827 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4828 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) {
4829 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
4830 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
4831 "3366 RPI x%x needs to be "
4832 "unregistered nlp_flag x%x "
4834 ndlp
->nlp_rpi
, ndlp
->nlp_flag
,
4837 /* If there is already an UNREG in progress for this ndlp,
4838 * no need to queue up another one.
4840 if (ndlp
->nlp_flag
& NLP_UNREG_INP
) {
4841 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4842 "1436 unreg_rpi SKIP UNREG x%x on "
4843 "NPort x%x deferred x%x flg x%x "
4845 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4846 ndlp
->nlp_defer_did
,
4847 ndlp
->nlp_flag
, ndlp
);
4851 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4853 /* SLI4 ports require the physical rpi value. */
4854 rpi
= ndlp
->nlp_rpi
;
4855 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4856 rpi
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4858 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, mbox
);
4859 mbox
->vport
= vport
;
4860 if (ndlp
->nlp_flag
& NLP_ISSUE_LOGO
) {
4861 mbox
->ctx_ndlp
= ndlp
;
4862 mbox
->mbox_cmpl
= lpfc_nlp_logo_unreg
;
4864 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
4865 (!(vport
->load_flag
& FC_UNLOADING
)) &&
4866 (bf_get(lpfc_sli_intf_if_type
,
4867 &phba
->sli4_hba
.sli_intf
) >=
4868 LPFC_SLI_INTF_IF_TYPE_2
) &&
4869 (kref_read(&ndlp
->kref
) > 0)) {
4870 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
4872 lpfc_sli4_unreg_rpi_cmpl_clr
;
4874 * accept PLOGIs after unreg_rpi_cmpl
4878 mbox
->ctx_ndlp
= ndlp
;
4880 lpfc_sli_def_mbox_cmpl
;
4883 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) !=
4885 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
4886 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
4888 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4889 "1433 unreg_rpi UNREG x%x on "
4890 "NPort x%x deferred flg x%x Data:%p\n",
4891 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4892 ndlp
->nlp_flag
, ndlp
);
4894 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4895 if (rc
== MBX_NOT_FINISHED
) {
4896 mempool_free(mbox
, phba
->mbox_mem_pool
);
4900 lpfc_no_rpi(phba
, ndlp
);
4902 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4904 ndlp
->nlp_flag
&= ~NLP_RPI_REGISTERED
;
4905 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4907 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4910 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4915 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4916 * @phba: pointer to lpfc hba data structure.
4918 * This routine is invoked to unregister all the currently registered RPIs
4922 lpfc_unreg_hba_rpis(struct lpfc_hba
*phba
)
4924 struct lpfc_vport
**vports
;
4925 struct lpfc_nodelist
*ndlp
;
4926 struct Scsi_Host
*shost
;
4929 vports
= lpfc_create_vport_work_array(phba
);
4931 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
4932 "2884 Vport array allocation failed \n");
4935 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4936 shost
= lpfc_shost_from_vport(vports
[i
]);
4937 spin_lock_irq(shost
->host_lock
);
4938 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4939 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4940 /* The mempool_alloc might sleep */
4941 spin_unlock_irq(shost
->host_lock
);
4942 lpfc_unreg_rpi(vports
[i
], ndlp
);
4943 spin_lock_irq(shost
->host_lock
);
4946 spin_unlock_irq(shost
->host_lock
);
4948 lpfc_destroy_vport_work_array(phba
, vports
);
4952 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
4954 struct lpfc_hba
*phba
= vport
->phba
;
4958 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4959 lpfc_sli4_unreg_all_rpis(vport
);
4963 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4965 lpfc_unreg_login(phba
, vport
->vpi
, LPFC_UNREG_ALL_RPIS_VPORT
,
4967 mbox
->vport
= vport
;
4968 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4969 mbox
->ctx_ndlp
= NULL
;
4970 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4971 if (rc
!= MBX_TIMEOUT
)
4972 mempool_free(mbox
, phba
->mbox_mem_pool
);
4974 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
4975 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
4976 "1836 Could not issue "
4977 "unreg_login(all_rpis) status %d\n", rc
);
4982 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
4984 struct lpfc_hba
*phba
= vport
->phba
;
4988 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4990 lpfc_unreg_did(phba
, vport
->vpi
, LPFC_UNREG_ALL_DFLT_RPIS
,
4992 mbox
->vport
= vport
;
4993 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4994 mbox
->ctx_ndlp
= NULL
;
4995 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4996 if (rc
!= MBX_TIMEOUT
)
4997 mempool_free(mbox
, phba
->mbox_mem_pool
);
4999 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
5000 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
5001 "1815 Could not issue "
5002 "unreg_did (default rpis) status %d\n",
5008 * Free resources associated with LPFC_NODELIST entry
5009 * so it can be freed.
5012 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
5014 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5015 struct lpfc_hba
*phba
= vport
->phba
;
5016 LPFC_MBOXQ_t
*mb
, *nextmb
;
5017 struct lpfc_dmabuf
*mp
;
5019 /* Cleanup node for NPort <nlp_DID> */
5020 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5021 "0900 Cleanup node for NPort x%x "
5022 "Data: x%x x%x x%x\n",
5023 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5024 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
5025 if (NLP_CHK_FREE_REQ(ndlp
)) {
5026 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
5027 "0280 lpfc_cleanup_node: ndlp:x%p "
5028 "usgmap:x%x refcnt:%d\n",
5029 (void *)ndlp
, ndlp
->nlp_usg_map
,
5030 kref_read(&ndlp
->kref
));
5031 lpfc_dequeue_node(vport
, ndlp
);
5033 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
5034 "0281 lpfc_cleanup_node: ndlp:x%p "
5035 "usgmap:x%x refcnt:%d\n",
5036 (void *)ndlp
, ndlp
->nlp_usg_map
,
5037 kref_read(&ndlp
->kref
));
5038 lpfc_disable_node(vport
, ndlp
);
5042 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5044 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5045 if ((mb
= phba
->sli
.mbox_active
)) {
5046 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
5047 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
5048 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
5049 mb
->ctx_ndlp
= NULL
;
5050 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5054 spin_lock_irq(&phba
->hbalock
);
5055 /* Cleanup REG_LOGIN completions which are not yet processed */
5056 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
5057 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) ||
5058 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) ||
5059 (ndlp
!= (struct lpfc_nodelist
*)mb
->ctx_ndlp
))
5062 mb
->ctx_ndlp
= NULL
;
5063 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5066 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
5067 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
5068 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
5069 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
5070 mp
= (struct lpfc_dmabuf
*)(mb
->ctx_buf
);
5072 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5075 list_del(&mb
->list
);
5076 mempool_free(mb
, phba
->mbox_mem_pool
);
5077 /* We shall not invoke the lpfc_nlp_put to decrement
5078 * the ndlp reference count as we are in the process
5079 * of lpfc_nlp_release.
5083 spin_unlock_irq(&phba
->hbalock
);
5085 lpfc_els_abort(phba
, ndlp
);
5087 spin_lock_irq(shost
->host_lock
);
5088 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
5089 spin_unlock_irq(shost
->host_lock
);
5091 ndlp
->nlp_last_elscmd
= 0;
5092 del_timer_sync(&ndlp
->nlp_delayfunc
);
5094 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
5095 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
5096 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
5097 lpfc_unreg_rpi(vport
, ndlp
);
5103 * Check to see if we can free the nlp back to the freelist.
5104 * If we are in the middle of using the nlp in the discovery state
5105 * machine, defer the free till we reach the end of the state machine.
5108 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
5110 struct lpfc_hba
*phba
= vport
->phba
;
5111 struct lpfc_rport_data
*rdata
;
5112 struct fc_rport
*rport
;
5116 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5117 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
5118 !(ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) &&
5119 !(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) &&
5120 phba
->sli_rev
!= LPFC_SLI_REV4
) {
5121 /* For this case we need to cleanup the default rpi
5122 * allocated by the firmware.
5124 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5125 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5126 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5127 kref_read(&ndlp
->kref
),
5128 ndlp
->nlp_usg_map
, ndlp
);
5129 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
5131 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
5132 (uint8_t *) &vport
->fc_sparam
, mbox
, ndlp
->nlp_rpi
);
5134 mempool_free(mbox
, phba
->mbox_mem_pool
);
5137 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
5138 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
5139 mbox
->vport
= vport
;
5140 mbox
->ctx_ndlp
= ndlp
;
5141 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5142 if (rc
== MBX_NOT_FINISHED
) {
5143 mempool_free(mbox
, phba
->mbox_mem_pool
);
5148 lpfc_cleanup_node(vport
, ndlp
);
5151 * ndlp->rport must be set to NULL before it reaches here
5152 * i.e. break rport/node link before doing lpfc_nlp_put for
5153 * registered rport and then drop the reference of rport.
5157 * extra lpfc_nlp_put dropped the reference of ndlp
5158 * for registered rport so need to cleanup rport
5160 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
5161 "0940 removed node x%p DID x%x "
5162 " rport not null %p\n",
5163 ndlp
, ndlp
->nlp_DID
, ndlp
->rport
);
5164 rport
= ndlp
->rport
;
5165 rdata
= rport
->dd_data
;
5166 rdata
->pnode
= NULL
;
5168 put_device(&rport
->dev
);
5173 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5176 D_ID mydid
, ndlpdid
, matchdid
;
5178 if (did
== Bcast_DID
)
5181 /* First check for Direct match */
5182 if (ndlp
->nlp_DID
== did
)
5185 /* Next check for area/domain identically equals 0 match */
5186 mydid
.un
.word
= vport
->fc_myDID
;
5187 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
5191 matchdid
.un
.word
= did
;
5192 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
5193 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
5194 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
5195 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
5196 /* This code is supposed to match the ID
5197 * for a private loop device that is
5198 * connect to fl_port. But we need to
5199 * check that the port did not just go
5200 * from pt2pt to fabric or we could end
5201 * up matching ndlp->nlp_DID 000001 to
5202 * fabric DID 0x20101
5204 if ((ndlpdid
.un
.b
.domain
== 0) &&
5205 (ndlpdid
.un
.b
.area
== 0)) {
5206 if (ndlpdid
.un
.b
.id
&&
5207 vport
->phba
->fc_topology
==
5214 matchdid
.un
.word
= ndlp
->nlp_DID
;
5215 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
5216 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
5217 if ((matchdid
.un
.b
.domain
== 0) &&
5218 (matchdid
.un
.b
.area
== 0)) {
5219 if (matchdid
.un
.b
.id
)
5227 /* Search for a nodelist entry */
5228 static struct lpfc_nodelist
*
5229 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5231 struct lpfc_nodelist
*ndlp
;
5234 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5235 if (lpfc_matchdid(vport
, ndlp
, did
)) {
5236 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
5237 ((uint32_t) ndlp
->nlp_xri
<< 16) |
5238 ((uint32_t) ndlp
->nlp_type
<< 8) |
5239 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
5240 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5241 "0929 FIND node DID "
5242 "Data: x%p x%x x%x x%x %p\n",
5243 ndlp
, ndlp
->nlp_DID
,
5244 ndlp
->nlp_flag
, data1
,
5245 ndlp
->active_rrqs_xri_bitmap
);
5250 /* FIND node did <did> NOT FOUND */
5251 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5252 "0932 FIND node did x%x NOT FOUND.\n", did
);
5256 struct lpfc_nodelist
*
5257 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5259 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5260 struct lpfc_nodelist
*ndlp
;
5261 unsigned long iflags
;
5263 spin_lock_irqsave(shost
->host_lock
, iflags
);
5264 ndlp
= __lpfc_findnode_did(vport
, did
);
5265 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
5269 struct lpfc_nodelist
*
5270 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
5272 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5273 struct lpfc_nodelist
*ndlp
;
5275 ndlp
= lpfc_findnode_did(vport
, did
);
5277 if (vport
->phba
->nvmet_support
)
5279 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
5280 lpfc_rscn_payload_check(vport
, did
) == 0)
5282 ndlp
= lpfc_nlp_init(vport
, did
);
5285 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5286 spin_lock_irq(shost
->host_lock
);
5287 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5288 spin_unlock_irq(shost
->host_lock
);
5290 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5291 if (vport
->phba
->nvmet_support
)
5293 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
5296 spin_lock_irq(shost
->host_lock
);
5297 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5298 spin_unlock_irq(shost
->host_lock
);
5302 /* The NVME Target does not want to actively manage an rport.
5303 * The goal is to allow the target to reset its state and clear
5304 * pending IO in preparation for the initiator to recover.
5306 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
5307 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
5308 if (lpfc_rscn_payload_check(vport
, did
)) {
5310 /* Since this node is marked for discovery,
5311 * delay timeout is not needed.
5313 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5315 /* NVME Target mode waits until rport is known to be
5316 * impacted by the RSCN before it transitions. No
5317 * active management - just go to NPR provided the
5318 * node had a valid login.
5320 if (vport
->phba
->nvmet_support
)
5323 /* If we've already received a PLOGI from this NPort
5324 * we don't need to try to discover it again.
5326 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
5329 spin_lock_irq(shost
->host_lock
);
5330 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5331 spin_unlock_irq(shost
->host_lock
);
5335 /* If the initiator received a PLOGI from this NPort or if the
5336 * initiator is already in the process of discovery on it,
5337 * there's no need to try to discover it again.
5339 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
5340 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5341 (!vport
->phba
->nvmet_support
&&
5342 ndlp
->nlp_flag
& NLP_RCV_PLOGI
))
5345 if (vport
->phba
->nvmet_support
)
5348 /* Moving to NPR state clears unsolicited flags and
5349 * allows for rediscovery
5351 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5353 spin_lock_irq(shost
->host_lock
);
5354 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5355 spin_unlock_irq(shost
->host_lock
);
5360 /* Build a list of nodes to discover based on the loopmap */
5362 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
5364 struct lpfc_hba
*phba
= vport
->phba
;
5366 uint32_t alpa
, index
;
5368 if (!lpfc_is_link_up(phba
))
5371 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5374 /* Check for loop map present or not */
5375 if (phba
->alpa_map
[0]) {
5376 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
5377 alpa
= phba
->alpa_map
[j
];
5378 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
5380 lpfc_setup_disc_node(vport
, alpa
);
5383 /* No alpamap, so try all alpa's */
5384 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
5385 /* If cfg_scan_down is set, start from highest
5386 * ALPA (0xef) to lowest (0x1).
5388 if (vport
->cfg_scan_down
)
5391 index
= FC_MAXLOOP
- j
- 1;
5392 alpa
= lpfcAlpaArray
[index
];
5393 if ((vport
->fc_myDID
& 0xff) == alpa
)
5395 lpfc_setup_disc_node(vport
, alpa
);
5403 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5406 struct lpfc_sli
*psli
= &phba
->sli
;
5407 struct lpfc_sli_ring
*extra_ring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
5408 struct lpfc_sli_ring
*fcp_ring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
5412 * if it's not a physical port or if we already send
5413 * clear_la then don't send it.
5415 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
5416 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
5417 (phba
->sli_rev
== LPFC_SLI_REV4
))
5420 /* Link up discovery */
5421 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
5422 phba
->link_state
= LPFC_CLEAR_LA
;
5423 lpfc_clear_la(phba
, mbox
);
5424 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
5425 mbox
->vport
= vport
;
5426 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5427 if (rc
== MBX_NOT_FINISHED
) {
5428 mempool_free(mbox
, phba
->mbox_mem_pool
);
5429 lpfc_disc_flush_list(vport
);
5430 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5431 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5432 phba
->link_state
= LPFC_HBA_ERROR
;
5437 /* Reg_vpi to tell firmware to resume normal operations */
5439 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5441 LPFC_MBOXQ_t
*regvpimbox
;
5443 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5445 lpfc_reg_vpi(vport
, regvpimbox
);
5446 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
5447 regvpimbox
->vport
= vport
;
5448 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
5449 == MBX_NOT_FINISHED
) {
5450 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
5455 /* Start Link up / RSCN discovery on NPR nodes */
5457 lpfc_disc_start(struct lpfc_vport
*vport
)
5459 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5460 struct lpfc_hba
*phba
= vport
->phba
;
5462 uint32_t clear_la_pending
;
5464 if (!lpfc_is_link_up(phba
)) {
5465 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
5466 "3315 Link is not up %x\n",
5471 if (phba
->link_state
== LPFC_CLEAR_LA
)
5472 clear_la_pending
= 1;
5474 clear_la_pending
= 0;
5476 if (vport
->port_state
< LPFC_VPORT_READY
)
5477 vport
->port_state
= LPFC_DISC_AUTH
;
5479 lpfc_set_disctmo(vport
);
5481 vport
->fc_prevDID
= vport
->fc_myDID
;
5482 vport
->num_disc_nodes
= 0;
5484 /* Start Discovery state <hba_state> */
5485 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5486 "0202 Start Discovery hba state x%x "
5487 "Data: x%x x%x x%x\n",
5488 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
5489 vport
->fc_adisc_cnt
);
5491 /* First do ADISCs - if any */
5492 num_sent
= lpfc_els_disc_adisc(vport
);
5497 /* Register the VPI for SLI3, NPIV only. */
5498 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5499 !(vport
->fc_flag
& FC_PT2PT
) &&
5500 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
5501 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
5502 lpfc_issue_clear_la(phba
, vport
);
5503 lpfc_issue_reg_vpi(phba
, vport
);
5508 * For SLI2, we need to set port_state to READY and continue
5511 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
5512 /* If we get here, there is nothing to ADISC */
5513 lpfc_issue_clear_la(phba
, vport
);
5515 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
5516 vport
->num_disc_nodes
= 0;
5517 /* go thru NPR nodes and issue ELS PLOGIs */
5518 if (vport
->fc_npr_cnt
)
5519 lpfc_els_disc_plogi(vport
);
5521 if (!vport
->num_disc_nodes
) {
5522 spin_lock_irq(shost
->host_lock
);
5523 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
5524 spin_unlock_irq(shost
->host_lock
);
5525 lpfc_can_disctmo(vport
);
5528 vport
->port_state
= LPFC_VPORT_READY
;
5530 /* Next do PLOGIs - if any */
5531 num_sent
= lpfc_els_disc_plogi(vport
);
5536 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5537 /* Check to see if more RSCNs came in while we
5538 * were processing this one.
5540 if ((vport
->fc_rscn_id_cnt
== 0) &&
5541 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
5542 spin_lock_irq(shost
->host_lock
);
5543 vport
->fc_flag
&= ~FC_RSCN_MODE
;
5544 spin_unlock_irq(shost
->host_lock
);
5545 lpfc_can_disctmo(vport
);
5547 lpfc_els_handle_rscn(vport
);
5554 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5555 * ring the match the sppecified nodelist.
5558 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
5560 LIST_HEAD(completions
);
5562 struct lpfc_iocbq
*iocb
, *next_iocb
;
5563 struct lpfc_sli_ring
*pring
;
5565 pring
= lpfc_phba_elsring(phba
);
5566 if (unlikely(!pring
))
5569 /* Error matching iocb on txq or txcmplq
5570 * First check the txq.
5572 spin_lock_irq(&phba
->hbalock
);
5573 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
5574 if (iocb
->context1
!= ndlp
) {
5578 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
5579 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
5581 list_move_tail(&iocb
->list
, &completions
);
5585 /* Next check the txcmplq */
5586 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
5587 if (iocb
->context1
!= ndlp
) {
5591 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
5592 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
5593 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
5596 spin_unlock_irq(&phba
->hbalock
);
5598 /* Cancel all the IOCBs from the completions list */
5599 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5604 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
5606 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5607 struct lpfc_hba
*phba
= vport
->phba
;
5609 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
5610 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5612 if (!NLP_CHK_NODE_ACT(ndlp
))
5614 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5615 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
5616 lpfc_free_tx(phba
, ndlp
);
5623 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
5625 lpfc_els_flush_rscn(vport
);
5626 lpfc_els_flush_cmd(vport
);
5627 lpfc_disc_flush_list(vport
);
5630 /*****************************************************************************/
5632 * NAME: lpfc_disc_timeout
5634 * FUNCTION: Fibre Channel driver discovery timeout routine.
5636 * EXECUTION ENVIRONMENT: interrupt only
5644 /*****************************************************************************/
5646 lpfc_disc_timeout(struct timer_list
*t
)
5648 struct lpfc_vport
*vport
= from_timer(vport
, t
, fc_disctmo
);
5649 struct lpfc_hba
*phba
= vport
->phba
;
5650 uint32_t tmo_posted
;
5651 unsigned long flags
= 0;
5653 if (unlikely(!phba
))
5656 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
5657 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
5659 vport
->work_port_events
|= WORKER_DISC_TMO
;
5660 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
5663 lpfc_worker_wake_up(phba
);
5668 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
5670 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5671 struct lpfc_hba
*phba
= vport
->phba
;
5672 struct lpfc_sli
*psli
= &phba
->sli
;
5673 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5674 LPFC_MBOXQ_t
*initlinkmbox
;
5675 int rc
, clrlaerr
= 0;
5677 if (!(vport
->fc_flag
& FC_DISC_TMO
))
5680 spin_lock_irq(shost
->host_lock
);
5681 vport
->fc_flag
&= ~FC_DISC_TMO
;
5682 spin_unlock_irq(shost
->host_lock
);
5684 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5685 "disc timeout: state:x%x rtry:x%x flg:x%x",
5686 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
5688 switch (vport
->port_state
) {
5690 case LPFC_LOCAL_CFG_LINK
:
5692 * port_state is identically LPFC_LOCAL_CFG_LINK while
5693 * waiting for FAN timeout
5695 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
5696 "0221 FAN timeout\n");
5698 /* Start discovery by sending FLOGI, clean up old rpis */
5699 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5701 if (!NLP_CHK_NODE_ACT(ndlp
))
5703 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
5705 if (ndlp
->nlp_type
& NLP_FABRIC
) {
5706 /* Clean up the ndlp on Fabric connections */
5707 lpfc_drop_node(vport
, ndlp
);
5709 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
5710 /* Fail outstanding IO now since device
5711 * is marked for PLOGI.
5713 lpfc_unreg_rpi(vport
, ndlp
);
5716 if (vport
->port_state
!= LPFC_FLOGI
) {
5717 if (phba
->sli_rev
<= LPFC_SLI_REV3
)
5718 lpfc_initial_flogi(vport
);
5720 lpfc_issue_init_vfi(vport
);
5727 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5728 /* Initial FLOGI timeout */
5729 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5730 "0222 Initial %s timeout\n",
5731 vport
->vpi
? "FDISC" : "FLOGI");
5733 /* Assume no Fabric and go on with discovery.
5734 * Check for outstanding ELS FLOGI to abort.
5737 /* FLOGI failed, so just use loop map to make discovery list */
5738 lpfc_disc_list_loopmap(vport
);
5740 /* Start discovery */
5741 lpfc_disc_start(vport
);
5744 case LPFC_FABRIC_CFG_LINK
:
5745 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5747 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5748 "0223 Timeout while waiting for "
5749 "NameServer login\n");
5750 /* Next look for NameServer ndlp */
5751 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5752 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5753 lpfc_els_abort(phba
, ndlp
);
5755 /* ReStart discovery */
5759 /* Check for wait for NameServer Rsp timeout */
5760 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5761 "0224 NameServer Query timeout "
5763 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5765 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
5766 /* Try it one more time */
5767 vport
->fc_ns_retry
++;
5768 vport
->gidft_inp
= 0;
5769 rc
= lpfc_issue_gidft(vport
);
5773 vport
->fc_ns_retry
= 0;
5777 * Discovery is over.
5778 * set port_state to PORT_READY if SLI2.
5779 * cmpl_reg_vpi will set port_state to READY for SLI3.
5781 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5782 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5783 lpfc_issue_reg_vpi(phba
, vport
);
5785 lpfc_issue_clear_la(phba
, vport
);
5786 vport
->port_state
= LPFC_VPORT_READY
;
5790 /* Setup and issue mailbox INITIALIZE LINK command */
5791 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5792 if (!initlinkmbox
) {
5793 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5794 "0206 Device Discovery "
5795 "completion error\n");
5796 phba
->link_state
= LPFC_HBA_ERROR
;
5800 lpfc_linkdown(phba
);
5801 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
5802 phba
->cfg_link_speed
);
5803 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
5804 initlinkmbox
->vport
= vport
;
5805 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5806 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
5807 lpfc_set_loopback_flag(phba
);
5808 if (rc
== MBX_NOT_FINISHED
)
5809 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
5813 case LPFC_DISC_AUTH
:
5814 /* Node Authentication timeout */
5815 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5816 "0227 Node Authentication timeout\n");
5817 lpfc_disc_flush_list(vport
);
5820 * set port_state to PORT_READY if SLI2.
5821 * cmpl_reg_vpi will set port_state to READY for SLI3.
5823 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5824 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5825 lpfc_issue_reg_vpi(phba
, vport
);
5826 else { /* NPIV Not enabled */
5827 lpfc_issue_clear_la(phba
, vport
);
5828 vport
->port_state
= LPFC_VPORT_READY
;
5833 case LPFC_VPORT_READY
:
5834 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5835 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5836 "0231 RSCN timeout Data: x%x "
5838 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5840 /* Cleanup any outstanding ELS commands */
5841 lpfc_els_flush_cmd(vport
);
5843 lpfc_els_flush_rscn(vport
);
5844 lpfc_disc_flush_list(vport
);
5849 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5850 "0273 Unexpected discovery timeout, "
5851 "vport State x%x\n", vport
->port_state
);
5855 switch (phba
->link_state
) {
5857 /* CLEAR LA timeout */
5858 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5859 "0228 CLEAR LA timeout\n");
5864 lpfc_issue_clear_la(phba
, vport
);
5866 case LPFC_LINK_UNKNOWN
:
5867 case LPFC_WARM_START
:
5868 case LPFC_INIT_START
:
5869 case LPFC_INIT_MBX_CMDS
:
5870 case LPFC_LINK_DOWN
:
5871 case LPFC_HBA_ERROR
:
5872 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5873 "0230 Unexpected timeout, hba link "
5874 "state x%x\n", phba
->link_state
);
5878 case LPFC_HBA_READY
:
5883 lpfc_disc_flush_list(vport
);
5884 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5885 psli
->sli3_ring
[(LPFC_EXTRA_RING
)].flag
&=
5886 ~LPFC_STOP_IOCB_EVENT
;
5887 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&=
5888 ~LPFC_STOP_IOCB_EVENT
;
5890 vport
->port_state
= LPFC_VPORT_READY
;
5896 * This routine handles processing a NameServer REG_LOGIN mailbox
5897 * command upon completion. It is setup in the LPFC_MBOXQ
5898 * as the completion routine when the command is
5899 * handed off to the SLI layer.
5902 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5904 MAILBOX_t
*mb
= &pmb
->u
.mb
;
5905 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*)(pmb
->ctx_buf
);
5906 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*)pmb
->ctx_ndlp
;
5907 struct lpfc_vport
*vport
= pmb
->vport
;
5909 pmb
->ctx_buf
= NULL
;
5910 pmb
->ctx_ndlp
= NULL
;
5912 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5913 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
5914 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
5915 ndlp
->nlp_type
|= NLP_FABRIC
;
5916 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
5917 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
5918 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5919 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5920 kref_read(&ndlp
->kref
),
5921 ndlp
->nlp_usg_map
, ndlp
);
5923 * Start issuing Fabric-Device Management Interface (FDMI) command to
5924 * 0xfffffa (FDMI well known port).
5925 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5926 * DPRT -> RPRT (vports)
5928 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
5929 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
, 0);
5931 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DPRT
, 0);
5934 /* decrement the node reference count held for this callback
5938 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5940 mempool_free(pmb
, phba
->mbox_mem_pool
);
5946 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
5948 uint16_t *rpi
= param
;
5950 /* check for active node */
5951 if (!NLP_CHK_NODE_ACT(ndlp
))
5954 return ndlp
->nlp_rpi
== *rpi
;
5958 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
5960 return memcmp(&ndlp
->nlp_portname
, param
,
5961 sizeof(ndlp
->nlp_portname
)) == 0;
5964 static struct lpfc_nodelist
*
5965 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
5967 struct lpfc_nodelist
*ndlp
;
5969 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5970 if (filter(ndlp
, param
)) {
5971 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5972 "3185 FIND node filter %p DID "
5973 "ndlp %p did x%x flg x%x st x%x "
5974 "xri x%x type x%x rpi x%x\n",
5975 filter
, ndlp
, ndlp
->nlp_DID
,
5976 ndlp
->nlp_flag
, ndlp
->nlp_state
,
5977 ndlp
->nlp_xri
, ndlp
->nlp_type
,
5982 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5983 "3186 FIND node filter %p NOT FOUND.\n", filter
);
5988 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5989 * returns the node list element pointer else return NULL.
5991 struct lpfc_nodelist
*
5992 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
5994 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
5998 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5999 * returns the node element list pointer else return NULL.
6001 struct lpfc_nodelist
*
6002 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
6004 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6005 struct lpfc_nodelist
*ndlp
;
6007 spin_lock_irq(shost
->host_lock
);
6008 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
6009 spin_unlock_irq(shost
->host_lock
);
6014 * This routine looks up the ndlp lists for the given RPI. If the rpi
6015 * is found, the routine returns the node element list pointer else
6018 struct lpfc_nodelist
*
6019 lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
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_findnode_rpi(vport
, rpi
);
6026 spin_unlock_irq(shost
->host_lock
);
6031 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6032 * @phba: pointer to lpfc hba data structure.
6033 * @vpi: the physical host virtual N_Port identifier.
6035 * This routine finds a vport on a HBA (referred by @phba) through a
6036 * @vpi. The function walks the HBA's vport list and returns the address
6037 * of the vport with the matching @vpi.
6040 * NULL - No vport with the matching @vpi found
6041 * Otherwise - Address to the vport with the matching @vpi.
6044 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
6046 struct lpfc_vport
*vport
;
6047 unsigned long flags
;
6050 /* The physical ports are always vpi 0 - translate is unnecessary. */
6053 * Translate the physical vpi to the logical vpi. The
6054 * vport stores the logical vpi.
6056 for (i
= 0; i
< phba
->max_vpi
; i
++) {
6057 if (vpi
== phba
->vpi_ids
[i
])
6061 if (i
>= phba
->max_vpi
) {
6062 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
6063 "2936 Could not find Vport mapped "
6064 "to vpi %d\n", vpi
);
6069 spin_lock_irqsave(&phba
->port_list_lock
, flags
);
6070 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
6071 if (vport
->vpi
== i
) {
6072 spin_unlock_irqrestore(&phba
->port_list_lock
, flags
);
6076 spin_unlock_irqrestore(&phba
->port_list_lock
, flags
);
6080 struct lpfc_nodelist
*
6081 lpfc_nlp_init(struct lpfc_vport
*vport
, uint32_t did
)
6083 struct lpfc_nodelist
*ndlp
;
6084 int rpi
= LPFC_RPI_ALLOC_ERROR
;
6086 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6087 rpi
= lpfc_sli4_alloc_rpi(vport
->phba
);
6088 if (rpi
== LPFC_RPI_ALLOC_ERROR
)
6092 ndlp
= mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
6094 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6095 lpfc_sli4_free_rpi(vport
->phba
, rpi
);
6099 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
6101 lpfc_initialize_node(vport
, ndlp
, did
);
6102 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
6103 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6104 ndlp
->nlp_rpi
= rpi
;
6105 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
6106 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
6107 "map:%x %p\n", ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6109 kref_read(&ndlp
->kref
),
6110 ndlp
->nlp_usg_map
, ndlp
);
6112 ndlp
->active_rrqs_xri_bitmap
=
6113 mempool_alloc(vport
->phba
->active_rrq_pool
,
6115 if (ndlp
->active_rrqs_xri_bitmap
)
6116 memset(ndlp
->active_rrqs_xri_bitmap
, 0,
6117 ndlp
->phba
->cfg_rrq_xri_bitmap_sz
);
6122 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
6123 "node init: did:x%x",
6124 ndlp
->nlp_DID
, 0, 0);
6129 /* This routine releases all resources associated with a specifc NPort's ndlp
6130 * and mempool_free's the nodelist.
6133 lpfc_nlp_release(struct kref
*kref
)
6135 struct lpfc_hba
*phba
;
6136 unsigned long flags
;
6137 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
6140 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6141 "node release: did:x%x flg:x%x type:x%x",
6142 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
6144 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
6145 "0279 lpfc_nlp_release: ndlp:x%p did %x "
6146 "usgmap:x%x refcnt:%d rpi:%x\n",
6147 (void *)ndlp
, ndlp
->nlp_DID
, ndlp
->nlp_usg_map
,
6148 kref_read(&ndlp
->kref
), ndlp
->nlp_rpi
);
6150 /* remove ndlp from action. */
6151 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
6153 /* clear the ndlp active flag for all release cases */
6155 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6156 NLP_CLR_NODE_ACT(ndlp
);
6157 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6158 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6159 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
6161 /* free ndlp memory for final ndlp release */
6162 if (NLP_CHK_FREE_REQ(ndlp
)) {
6163 kfree(ndlp
->lat_data
);
6164 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6165 mempool_free(ndlp
->active_rrqs_xri_bitmap
,
6166 ndlp
->phba
->active_rrq_pool
);
6167 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
6171 /* This routine bumps the reference count for a ndlp structure to ensure
6172 * that one discovery thread won't free a ndlp while another discovery thread
6175 struct lpfc_nodelist
*
6176 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
6178 struct lpfc_hba
*phba
;
6179 unsigned long flags
;
6182 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6183 "node get: did:x%x flg:x%x refcnt:x%x",
6184 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6185 kref_read(&ndlp
->kref
));
6186 /* The check of ndlp usage to prevent incrementing the
6187 * ndlp reference count that is in the process of being
6191 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6192 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
6193 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6194 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6195 "0276 lpfc_nlp_get: ndlp:x%p "
6196 "usgmap:x%x refcnt:%d\n",
6197 (void *)ndlp
, ndlp
->nlp_usg_map
,
6198 kref_read(&ndlp
->kref
));
6201 kref_get(&ndlp
->kref
);
6202 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6207 /* This routine decrements the reference count for a ndlp structure. If the
6208 * count goes to 0, this indicates the the associated nodelist should be
6209 * freed. Returning 1 indicates the ndlp resource has been released; on the
6210 * other hand, returning 0 indicates the ndlp resource has not been released
6214 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
6216 struct lpfc_hba
*phba
;
6217 unsigned long flags
;
6222 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6223 "node put: did:x%x flg:x%x refcnt:x%x",
6224 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6225 kref_read(&ndlp
->kref
));
6227 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6228 /* Check the ndlp memory free acknowledge flag to avoid the
6229 * possible race condition that kref_put got invoked again
6230 * after previous one has done ndlp memory free.
6232 if (NLP_CHK_FREE_ACK(ndlp
)) {
6233 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6234 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6235 "0274 lpfc_nlp_put: ndlp:x%p "
6236 "usgmap:x%x refcnt:%d\n",
6237 (void *)ndlp
, ndlp
->nlp_usg_map
,
6238 kref_read(&ndlp
->kref
));
6241 /* Check the ndlp inactivate log flag to avoid the possible
6242 * race condition that kref_put got invoked again after ndlp
6243 * is already in inactivating state.
6245 if (NLP_CHK_IACT_REQ(ndlp
)) {
6246 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6247 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6248 "0275 lpfc_nlp_put: ndlp:x%p "
6249 "usgmap:x%x refcnt:%d\n",
6250 (void *)ndlp
, ndlp
->nlp_usg_map
,
6251 kref_read(&ndlp
->kref
));
6254 /* For last put, mark the ndlp usage flags to make sure no
6255 * other kref_get and kref_put on the same ndlp shall get
6256 * in between the process when the final kref_put has been
6257 * invoked on this ndlp.
6259 if (kref_read(&ndlp
->kref
) == 1) {
6260 /* Indicate ndlp is put to inactive state. */
6261 NLP_SET_IACT_REQ(ndlp
);
6262 /* Acknowledge ndlp memory free has been seen. */
6263 if (NLP_CHK_FREE_REQ(ndlp
))
6264 NLP_SET_FREE_ACK(ndlp
);
6266 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6267 /* Note, the kref_put returns 1 when decrementing a reference
6268 * count that was 1, it invokes the release callback function,
6269 * but it still left the reference count as 1 (not actually
6270 * performs the last decrementation). Otherwise, it actually
6271 * decrements the reference count and returns 0.
6273 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
6276 /* This routine free's the specified nodelist if it is not in use
6277 * by any other discovery thread. This routine returns 1 if the
6278 * ndlp has been freed. A return value of 0 indicates the ndlp is
6279 * not yet been released.
6282 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
6284 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6285 "node not used: did:x%x flg:x%x refcnt:x%x",
6286 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6287 kref_read(&ndlp
->kref
));
6288 if (kref_read(&ndlp
->kref
) == 1)
6289 if (lpfc_nlp_put(ndlp
))
6295 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6296 * @phba: Pointer to hba context object.
6298 * This function iterate through all FC nodes associated
6299 * will all vports to check if there is any node with
6300 * fc_rports associated with it. If there is an fc_rport
6301 * associated with the node, then the node is either in
6302 * discovered state or its devloss_timer is pending.
6305 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
6307 struct lpfc_vport
**vports
;
6309 struct lpfc_nodelist
*ndlp
;
6310 struct Scsi_Host
*shost
;
6312 vports
= lpfc_create_vport_work_array(phba
);
6314 /* If driver cannot allocate memory, indicate fcf is in use */
6318 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6319 shost
= lpfc_shost_from_vport(vports
[i
]);
6320 spin_lock_irq(shost
->host_lock
);
6322 * IF the CVL_RCVD bit is not set then we have sent the
6324 * If dev_loss fires while we are waiting we do not want to
6327 if (!(vports
[i
]->fc_flag
& FC_VPORT_CVL_RCVD
)) {
6328 spin_unlock_irq(shost
->host_lock
);
6332 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
6333 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
6334 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
6336 spin_unlock_irq(shost
->host_lock
);
6338 } else if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
6340 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
6341 "2624 RPI %x DID %x flag %x "
6342 "still logged in\n",
6343 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6347 spin_unlock_irq(shost
->host_lock
);
6350 lpfc_destroy_vport_work_array(phba
, vports
);
6355 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6356 * @phba: Pointer to hba context object.
6357 * @mboxq: Pointer to mailbox object.
6359 * This function frees memory associated with the mailbox command.
6362 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6364 struct lpfc_vport
*vport
= mboxq
->vport
;
6365 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6367 if (mboxq
->u
.mb
.mbxStatus
) {
6368 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6369 "2555 UNREG_VFI mbxStatus error x%x "
6371 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6373 spin_lock_irq(shost
->host_lock
);
6374 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
6375 spin_unlock_irq(shost
->host_lock
);
6376 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6381 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6382 * @phba: Pointer to hba context object.
6383 * @mboxq: Pointer to mailbox object.
6385 * This function frees memory associated with the mailbox command.
6388 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6390 struct lpfc_vport
*vport
= mboxq
->vport
;
6392 if (mboxq
->u
.mb
.mbxStatus
) {
6393 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6394 "2550 UNREG_FCFI mbxStatus error x%x "
6396 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6398 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6403 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6404 * @phba: Pointer to hba context object.
6406 * This function prepare the HBA for unregistering the currently registered
6407 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6411 lpfc_unregister_fcf_prep(struct lpfc_hba
*phba
)
6413 struct lpfc_vport
**vports
;
6414 struct lpfc_nodelist
*ndlp
;
6415 struct Scsi_Host
*shost
;
6418 /* Unregister RPIs */
6419 if (lpfc_fcf_inuse(phba
))
6420 lpfc_unreg_hba_rpis(phba
);
6422 /* At this point, all discovery is aborted */
6423 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
6425 /* Unregister VPIs */
6426 vports
= lpfc_create_vport_work_array(phba
);
6427 if (vports
&& (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
6428 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6429 /* Stop FLOGI/FDISC retries */
6430 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6432 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6433 lpfc_cleanup_pending_mbox(vports
[i
]);
6434 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6435 lpfc_sli4_unreg_all_rpis(vports
[i
]);
6436 lpfc_mbx_unreg_vpi(vports
[i
]);
6437 shost
= lpfc_shost_from_vport(vports
[i
]);
6438 spin_lock_irq(shost
->host_lock
);
6439 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6440 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6441 spin_unlock_irq(shost
->host_lock
);
6443 lpfc_destroy_vport_work_array(phba
, vports
);
6444 if (i
== 0 && (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))) {
6445 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6447 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
6448 lpfc_cleanup_pending_mbox(phba
->pport
);
6449 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6450 lpfc_sli4_unreg_all_rpis(phba
->pport
);
6451 lpfc_mbx_unreg_vpi(phba
->pport
);
6452 shost
= lpfc_shost_from_vport(phba
->pport
);
6453 spin_lock_irq(shost
->host_lock
);
6454 phba
->pport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6455 phba
->pport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6456 spin_unlock_irq(shost
->host_lock
);
6459 /* Cleanup any outstanding ELS commands */
6460 lpfc_els_flush_all_cmd(phba
);
6462 /* Unregister the physical port VFI */
6463 rc
= lpfc_issue_unreg_vfi(phba
->pport
);
6468 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6469 * @phba: Pointer to hba context object.
6471 * This function issues synchronous unregister FCF mailbox command to HBA to
6472 * unregister the currently registered FCF record. The driver does not reset
6473 * the driver FCF usage state flags.
6475 * Return 0 if successfully issued, none-zero otherwise.
6478 lpfc_sli4_unregister_fcf(struct lpfc_hba
*phba
)
6483 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6485 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6486 "2551 UNREG_FCFI mbox allocation failed"
6487 "HBA state x%x\n", phba
->pport
->port_state
);
6490 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
6491 mbox
->vport
= phba
->pport
;
6492 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
6493 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
6495 if (rc
== MBX_NOT_FINISHED
) {
6496 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6497 "2552 Unregister FCFI command failed rc x%x "
6499 rc
, phba
->pport
->port_state
);
6506 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6507 * @phba: Pointer to hba context object.
6509 * This function unregisters the currently reigstered FCF. This function
6510 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6513 lpfc_unregister_fcf_rescan(struct lpfc_hba
*phba
)
6517 /* Preparation for unregistering fcf */
6518 rc
= lpfc_unregister_fcf_prep(phba
);
6520 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
6521 "2748 Failed to prepare for unregistering "
6522 "HBA's FCF record: rc=%d\n", rc
);
6526 /* Now, unregister FCF record and reset HBA FCF state */
6527 rc
= lpfc_sli4_unregister_fcf(phba
);
6530 /* Reset HBA FCF states after successful unregister FCF */
6531 phba
->fcf
.fcf_flag
= 0;
6532 phba
->fcf
.current_rec
.flag
= 0;
6535 * If driver is not unloading, check if there is any other
6536 * FCF record that can be used for discovery.
6538 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
6539 (phba
->link_state
< LPFC_LINK_UP
))
6542 /* This is considered as the initial FCF discovery scan */
6543 spin_lock_irq(&phba
->hbalock
);
6544 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
6545 spin_unlock_irq(&phba
->hbalock
);
6547 /* Reset FCF roundrobin bmask for new discovery */
6548 lpfc_sli4_clear_fcf_rr_bmask(phba
);
6550 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
6553 spin_lock_irq(&phba
->hbalock
);
6554 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
6555 spin_unlock_irq(&phba
->hbalock
);
6556 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6557 "2553 lpfc_unregister_unused_fcf failed "
6558 "to read FCF record HBA state x%x\n",
6559 phba
->pport
->port_state
);
6564 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6565 * @phba: Pointer to hba context object.
6567 * This function just unregisters the currently reigstered FCF. It does not
6568 * try to find another FCF for discovery.
6571 lpfc_unregister_fcf(struct lpfc_hba
*phba
)
6575 /* Preparation for unregistering fcf */
6576 rc
= lpfc_unregister_fcf_prep(phba
);
6578 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
6579 "2749 Failed to prepare for unregistering "
6580 "HBA's FCF record: rc=%d\n", rc
);
6584 /* Now, unregister FCF record and reset HBA FCF state */
6585 rc
= lpfc_sli4_unregister_fcf(phba
);
6588 /* Set proper HBA FCF states after successful unregister FCF */
6589 spin_lock_irq(&phba
->hbalock
);
6590 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
6591 spin_unlock_irq(&phba
->hbalock
);
6595 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6596 * @phba: Pointer to hba context object.
6598 * This function check if there are any connected remote port for the FCF and
6599 * if all the devices are disconnected, this function unregister FCFI.
6600 * This function also tries to use another FCF for discovery.
6603 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
6606 * If HBA is not running in FIP mode, if HBA does not support
6607 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6608 * registered, do nothing.
6610 spin_lock_irq(&phba
->hbalock
);
6611 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) ||
6612 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
6613 !(phba
->hba_flag
& HBA_FIP_SUPPORT
) ||
6614 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) ||
6615 (phba
->pport
->port_state
== LPFC_FLOGI
)) {
6616 spin_unlock_irq(&phba
->hbalock
);
6619 spin_unlock_irq(&phba
->hbalock
);
6621 if (lpfc_fcf_inuse(phba
))
6624 lpfc_unregister_fcf_rescan(phba
);
6628 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6629 * @phba: Pointer to hba context object.
6630 * @buff: Buffer containing the FCF connection table as in the config
6632 * This function create driver data structure for the FCF connection
6633 * record table read from config region 23.
6636 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
6639 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
6640 struct lpfc_fcf_conn_hdr
*conn_hdr
;
6641 struct lpfc_fcf_conn_rec
*conn_rec
;
6642 uint32_t record_count
;
6645 /* Free the current connect table */
6646 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
6647 &phba
->fcf_conn_rec_list
, list
) {
6648 list_del_init(&conn_entry
->list
);
6652 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
6653 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
6654 sizeof(struct lpfc_fcf_conn_rec
);
6656 conn_rec
= (struct lpfc_fcf_conn_rec
*)
6657 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
6659 for (i
= 0; i
< record_count
; i
++) {
6660 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
6662 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
6665 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6666 "2566 Failed to allocate connection"
6671 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
6672 sizeof(struct lpfc_fcf_conn_rec
));
6673 list_add_tail(&conn_entry
->list
,
6674 &phba
->fcf_conn_rec_list
);
6677 if (!list_empty(&phba
->fcf_conn_rec_list
)) {
6679 list_for_each_entry(conn_entry
, &phba
->fcf_conn_rec_list
,
6681 conn_rec
= &conn_entry
->conn_rec
;
6682 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6683 "3345 FCF connection list rec[%02d]: "
6684 "flags:x%04x, vtag:x%04x, "
6685 "fabric_name:x%02x:%02x:%02x:%02x:"
6686 "%02x:%02x:%02x:%02x, "
6687 "switch_name:x%02x:%02x:%02x:%02x:"
6688 "%02x:%02x:%02x:%02x\n", i
++,
6689 conn_rec
->flags
, conn_rec
->vlan_tag
,
6690 conn_rec
->fabric_name
[0],
6691 conn_rec
->fabric_name
[1],
6692 conn_rec
->fabric_name
[2],
6693 conn_rec
->fabric_name
[3],
6694 conn_rec
->fabric_name
[4],
6695 conn_rec
->fabric_name
[5],
6696 conn_rec
->fabric_name
[6],
6697 conn_rec
->fabric_name
[7],
6698 conn_rec
->switch_name
[0],
6699 conn_rec
->switch_name
[1],
6700 conn_rec
->switch_name
[2],
6701 conn_rec
->switch_name
[3],
6702 conn_rec
->switch_name
[4],
6703 conn_rec
->switch_name
[5],
6704 conn_rec
->switch_name
[6],
6705 conn_rec
->switch_name
[7]);
6711 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6712 * @phba: Pointer to hba context object.
6713 * @buff: Buffer containing the FCoE parameter data structure.
6715 * This function update driver data structure with config
6716 * parameters read from config region 23.
6719 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
6722 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
6723 struct lpfc_fcoe_params
*fcoe_param
;
6725 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
6727 fcoe_param
= (struct lpfc_fcoe_params
*)
6728 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
6730 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
6731 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
6734 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
6735 phba
->valid_vlan
= 1;
6736 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
6740 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
6741 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
6742 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
6747 * lpfc_get_rec_conf23 - Get a record type in config region data.
6748 * @buff: Buffer containing config region 23 data.
6749 * @size: Size of the data buffer.
6750 * @rec_type: Record type to be searched.
6752 * This function searches config region data to find the beginning
6753 * of the record specified by record_type. If record found, this
6754 * function return pointer to the record else return NULL.
6757 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
6759 uint32_t offset
= 0, rec_length
;
6761 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
6762 (size
< sizeof(uint32_t)))
6765 rec_length
= buff
[offset
+ 1];
6768 * One TLV record has one word header and number of data words
6769 * specified in the rec_length field of the record header.
6771 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
6773 if (buff
[offset
] == rec_type
)
6774 return &buff
[offset
];
6776 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
6779 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
6780 rec_length
= buff
[offset
+ 1];
6786 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6787 * @phba: Pointer to lpfc_hba data structure.
6788 * @buff: Buffer containing config region 23 data.
6789 * @size: Size of the data buffer.
6791 * This function parses the FCoE config parameters in config region 23 and
6792 * populate driver data structure with the parameters.
6795 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
6799 uint32_t offset
= 0;
6803 * If data size is less than 2 words signature and version cannot be
6806 if (size
< 2*sizeof(uint32_t))
6809 /* Check the region signature first */
6810 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
6811 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6812 "2567 Config region 23 has bad signature\n");
6818 /* Check the data structure version */
6819 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
6820 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6821 "2568 Config region 23 has bad version\n");
6826 /* Read FCoE param record */
6827 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6828 size
- offset
, FCOE_PARAM_TYPE
);
6830 lpfc_read_fcoe_param(phba
, rec_ptr
);
6832 /* Read FCF connection table */
6833 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6834 size
- offset
, FCOE_CONN_TBL_TYPE
);
6836 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);