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
)
894 /* Block all SCSI stack I/Os */
895 lpfc_scsi_dev_block(phba
);
897 spin_lock_irq(&phba
->hbalock
);
898 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
899 spin_unlock_irq(&phba
->hbalock
);
900 if (phba
->link_state
> LPFC_LINK_DOWN
) {
901 phba
->link_state
= LPFC_LINK_DOWN
;
902 spin_lock_irq(shost
->host_lock
);
903 phba
->pport
->fc_flag
&= ~FC_LBIT
;
904 spin_unlock_irq(shost
->host_lock
);
906 vports
= lpfc_create_vport_work_array(phba
);
907 if (vports
!= NULL
) {
908 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
909 /* Issue a LINK DOWN event to all nodes */
910 lpfc_linkdown_port(vports
[i
]);
912 vports
[i
]->fc_myDID
= 0;
914 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
915 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
916 if (phba
->nvmet_support
)
917 lpfc_nvmet_update_targetport(phba
);
919 lpfc_nvme_update_localport(vports
[i
]);
923 lpfc_destroy_vport_work_array(phba
, vports
);
925 /* Clean up any SLI3 firmware default rpi's */
926 if (phba
->sli_rev
> LPFC_SLI_REV3
)
929 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
931 lpfc_unreg_did(phba
, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS
, mb
);
933 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
934 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
935 == MBX_NOT_FINISHED
) {
936 mempool_free(mb
, phba
->mbox_mem_pool
);
941 /* Setup myDID for link up if we are in pt2pt mode */
942 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
943 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
945 lpfc_config_link(phba
, mb
);
946 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
948 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
949 == MBX_NOT_FINISHED
) {
950 mempool_free(mb
, phba
->mbox_mem_pool
);
953 spin_lock_irq(shost
->host_lock
);
954 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
955 phba
->pport
->rcv_flogi_cnt
= 0;
956 spin_unlock_irq(shost
->host_lock
);
962 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
964 struct lpfc_nodelist
*ndlp
;
966 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
967 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
968 if (!NLP_CHK_NODE_ACT(ndlp
))
970 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
972 if (ndlp
->nlp_type
& NLP_FABRIC
) {
973 /* On Linkup its safe to clean up the ndlp
974 * from Fabric connections.
976 if (ndlp
->nlp_DID
!= Fabric_DID
)
977 lpfc_unreg_rpi(vport
, ndlp
);
978 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
979 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
980 /* Fail outstanding IO now since device is
983 lpfc_unreg_rpi(vport
, ndlp
);
989 lpfc_linkup_port(struct lpfc_vport
*vport
)
991 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
992 struct lpfc_hba
*phba
= vport
->phba
;
994 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
997 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
998 "Link Up: top:x%x speed:x%x flg:x%x",
999 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
1001 /* If NPIV is not enabled, only bring the physical port up */
1002 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1003 (vport
!= phba
->pport
))
1006 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
1007 fc_host_post_event(shost
, fc_get_event_number(),
1010 spin_lock_irq(shost
->host_lock
);
1011 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
1012 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
1013 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
1014 vport
->fc_ns_retry
= 0;
1015 spin_unlock_irq(shost
->host_lock
);
1017 if (vport
->fc_flag
& FC_LBIT
)
1018 lpfc_linkup_cleanup_nodes(vport
);
1023 lpfc_linkup(struct lpfc_hba
*phba
)
1025 struct lpfc_vport
**vports
;
1027 struct Scsi_Host
*shost
= lpfc_shost_from_vport(phba
->pport
);
1029 phba
->link_state
= LPFC_LINK_UP
;
1031 /* Unblock fabric iocbs if they are blocked */
1032 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
1033 del_timer_sync(&phba
->fabric_block_timer
);
1035 vports
= lpfc_create_vport_work_array(phba
);
1037 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1038 lpfc_linkup_port(vports
[i
]);
1039 lpfc_destroy_vport_work_array(phba
, vports
);
1041 /* Clear the pport flogi counter in case the link down was
1042 * absorbed without an ACQE. No lock here - in worker thread
1043 * and discovery is synchronized.
1045 spin_lock_irq(shost
->host_lock
);
1046 phba
->pport
->rcv_flogi_cnt
= 0;
1047 spin_unlock_irq(shost
->host_lock
);
1052 * This routine handles processing a CLEAR_LA mailbox
1053 * command upon completion. It is setup in the LPFC_MBOXQ
1054 * as the completion routine when the command is
1055 * handed off to the SLI layer. SLI3 only.
1058 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1060 struct lpfc_vport
*vport
= pmb
->vport
;
1061 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1062 struct lpfc_sli
*psli
= &phba
->sli
;
1063 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1066 /* Since we don't do discovery right now, turn these off here */
1067 psli
->sli3_ring
[LPFC_EXTRA_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1068 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1070 /* Check for error */
1071 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
1072 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1073 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1074 "0320 CLEAR_LA mbxStatus error x%x hba "
1076 mb
->mbxStatus
, vport
->port_state
);
1077 phba
->link_state
= LPFC_HBA_ERROR
;
1081 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1082 phba
->link_state
= LPFC_HBA_READY
;
1084 spin_lock_irq(&phba
->hbalock
);
1085 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1086 control
= readl(phba
->HCregaddr
);
1087 control
|= HC_LAINT_ENA
;
1088 writel(control
, phba
->HCregaddr
);
1089 readl(phba
->HCregaddr
); /* flush */
1090 spin_unlock_irq(&phba
->hbalock
);
1091 mempool_free(pmb
, phba
->mbox_mem_pool
);
1095 /* Device Discovery completes */
1096 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1097 "0225 Device Discovery completes\n");
1098 mempool_free(pmb
, phba
->mbox_mem_pool
);
1100 spin_lock_irq(shost
->host_lock
);
1101 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
1102 spin_unlock_irq(shost
->host_lock
);
1104 lpfc_can_disctmo(vport
);
1106 /* turn on Link Attention interrupts */
1108 spin_lock_irq(&phba
->hbalock
);
1109 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1110 control
= readl(phba
->HCregaddr
);
1111 control
|= HC_LAINT_ENA
;
1112 writel(control
, phba
->HCregaddr
);
1113 readl(phba
->HCregaddr
); /* flush */
1114 spin_unlock_irq(&phba
->hbalock
);
1121 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1123 struct lpfc_vport
*vport
= pmb
->vport
;
1126 if (pmb
->u
.mb
.mbxStatus
)
1129 mempool_free(pmb
, phba
->mbox_mem_pool
);
1131 /* don't perform discovery for SLI4 loopback diagnostic test */
1132 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1133 !(phba
->hba_flag
& HBA_FCOE_MODE
) &&
1134 (phba
->link_flag
& LS_LOOPBACK_MODE
))
1137 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
&&
1138 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
1139 !(vport
->fc_flag
& FC_LBIT
)) {
1140 /* Need to wait for FAN - use discovery timer
1141 * for timeout. port_state is identically
1142 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1144 lpfc_set_disctmo(vport
);
1148 /* Start discovery by sending a FLOGI. port_state is identically
1149 * LPFC_FLOGI while waiting for FLOGI cmpl
1151 if (vport
->port_state
!= LPFC_FLOGI
) {
1152 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
) {
1153 bbscn
= bf_get(lpfc_bbscn_def
,
1154 &phba
->sli4_hba
.bbscn_params
);
1155 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
&= 0xf;
1156 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
|= (bbscn
<< 4);
1158 lpfc_initial_flogi(vport
);
1159 } else if (vport
->fc_flag
& FC_PT2PT
) {
1160 lpfc_disc_start(vport
);
1165 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1166 "0306 CONFIG_LINK mbxStatus error x%x "
1168 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
1169 mempool_free(pmb
, phba
->mbox_mem_pool
);
1171 lpfc_linkdown(phba
);
1173 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1174 "0200 CONFIG_LINK bad hba state x%x\n",
1177 lpfc_issue_clear_la(phba
, vport
);
1182 * lpfc_sli4_clear_fcf_rr_bmask
1183 * @phba pointer to the struct lpfc_hba for this port.
1184 * This fucnction resets the round robin bit mask and clears the
1185 * fcf priority list. The list deletions are done while holding the
1186 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1187 * from the lpfc_fcf_pri record.
1190 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba
*phba
)
1192 struct lpfc_fcf_pri
*fcf_pri
;
1193 struct lpfc_fcf_pri
*next_fcf_pri
;
1194 memset(phba
->fcf
.fcf_rr_bmask
, 0, sizeof(*phba
->fcf
.fcf_rr_bmask
));
1195 spin_lock_irq(&phba
->hbalock
);
1196 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
1197 &phba
->fcf
.fcf_pri_list
, list
) {
1198 list_del_init(&fcf_pri
->list
);
1199 fcf_pri
->fcf_rec
.flag
= 0;
1201 spin_unlock_irq(&phba
->hbalock
);
1204 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1206 struct lpfc_vport
*vport
= mboxq
->vport
;
1208 if (mboxq
->u
.mb
.mbxStatus
) {
1209 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1210 "2017 REG_FCFI mbxStatus error x%x "
1212 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1216 /* Start FCoE discovery by sending a FLOGI. */
1217 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1218 /* Set the FCFI registered flag */
1219 spin_lock_irq(&phba
->hbalock
);
1220 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1221 spin_unlock_irq(&phba
->hbalock
);
1223 /* If there is a pending FCoE event, restart FCF table scan. */
1224 if ((!(phba
->hba_flag
& FCF_RR_INPROG
)) &&
1225 lpfc_check_pending_fcoe_event(phba
, LPFC_UNREG_FCF
))
1228 /* Mark successful completion of FCF table scan */
1229 spin_lock_irq(&phba
->hbalock
);
1230 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1231 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1232 if (vport
->port_state
!= LPFC_FLOGI
) {
1233 phba
->hba_flag
|= FCF_RR_INPROG
;
1234 spin_unlock_irq(&phba
->hbalock
);
1235 lpfc_issue_init_vfi(vport
);
1238 spin_unlock_irq(&phba
->hbalock
);
1242 spin_lock_irq(&phba
->hbalock
);
1243 phba
->hba_flag
&= ~FCF_RR_INPROG
;
1244 spin_unlock_irq(&phba
->hbalock
);
1246 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1250 * lpfc_fab_name_match - Check if the fcf fabric name match.
1251 * @fab_name: pointer to fabric name.
1252 * @new_fcf_record: pointer to fcf record.
1254 * This routine compare the fcf record's fabric name with provided
1255 * fabric name. If the fabric name are identical this function
1256 * returns 1 else return 0.
1259 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1261 if (fab_name
[0] != bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
))
1263 if (fab_name
[1] != bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
))
1265 if (fab_name
[2] != bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
))
1267 if (fab_name
[3] != bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
))
1269 if (fab_name
[4] != bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
))
1271 if (fab_name
[5] != bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
))
1273 if (fab_name
[6] != bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
))
1275 if (fab_name
[7] != bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
))
1281 * lpfc_sw_name_match - Check if the fcf switch name match.
1282 * @fab_name: pointer to fabric name.
1283 * @new_fcf_record: pointer to fcf record.
1285 * This routine compare the fcf record's switch name with provided
1286 * switch name. If the switch name are identical this function
1287 * returns 1 else return 0.
1290 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1292 if (sw_name
[0] != bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
))
1294 if (sw_name
[1] != bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
))
1296 if (sw_name
[2] != bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
))
1298 if (sw_name
[3] != bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
))
1300 if (sw_name
[4] != bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
))
1302 if (sw_name
[5] != bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
))
1304 if (sw_name
[6] != bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
))
1306 if (sw_name
[7] != bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
))
1312 * lpfc_mac_addr_match - Check if the fcf mac address match.
1313 * @mac_addr: pointer to mac address.
1314 * @new_fcf_record: pointer to fcf record.
1316 * This routine compare the fcf record's mac address with HBA's
1317 * FCF mac address. If the mac addresses are identical this function
1318 * returns 1 else return 0.
1321 lpfc_mac_addr_match(uint8_t *mac_addr
, struct fcf_record
*new_fcf_record
)
1323 if (mac_addr
[0] != bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
))
1325 if (mac_addr
[1] != bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
))
1327 if (mac_addr
[2] != bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
))
1329 if (mac_addr
[3] != bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
))
1331 if (mac_addr
[4] != bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
))
1333 if (mac_addr
[5] != bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
))
1339 lpfc_vlan_id_match(uint16_t curr_vlan_id
, uint16_t new_vlan_id
)
1341 return (curr_vlan_id
== new_vlan_id
);
1345 * lpfc_update_fcf_record - Update driver fcf record
1346 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1347 * @phba: pointer to lpfc hba data structure.
1348 * @fcf_index: Index for the lpfc_fcf_record.
1349 * @new_fcf_record: pointer to hba fcf record.
1351 * This routine updates the driver FCF priority record from the new HBA FCF
1352 * record. This routine is called with the host lock held.
1355 __lpfc_update_fcf_record_pri(struct lpfc_hba
*phba
, uint16_t fcf_index
,
1356 struct fcf_record
*new_fcf_record
1359 struct lpfc_fcf_pri
*fcf_pri
;
1361 lockdep_assert_held(&phba
->hbalock
);
1363 fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
1364 fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
1365 /* FCF record priority */
1366 fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
1371 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1372 * @fcf: pointer to driver fcf record.
1373 * @new_fcf_record: pointer to fcf record.
1375 * This routine copies the FCF information from the FCF
1376 * record to lpfc_hba data structure.
1379 lpfc_copy_fcf_record(struct lpfc_fcf_rec
*fcf_rec
,
1380 struct fcf_record
*new_fcf_record
)
1383 fcf_rec
->fabric_name
[0] =
1384 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1385 fcf_rec
->fabric_name
[1] =
1386 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1387 fcf_rec
->fabric_name
[2] =
1388 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1389 fcf_rec
->fabric_name
[3] =
1390 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1391 fcf_rec
->fabric_name
[4] =
1392 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1393 fcf_rec
->fabric_name
[5] =
1394 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1395 fcf_rec
->fabric_name
[6] =
1396 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1397 fcf_rec
->fabric_name
[7] =
1398 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1400 fcf_rec
->mac_addr
[0] = bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1401 fcf_rec
->mac_addr
[1] = bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1402 fcf_rec
->mac_addr
[2] = bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1403 fcf_rec
->mac_addr
[3] = bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1404 fcf_rec
->mac_addr
[4] = bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1405 fcf_rec
->mac_addr
[5] = bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1406 /* FCF record index */
1407 fcf_rec
->fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1408 /* FCF record priority */
1409 fcf_rec
->priority
= new_fcf_record
->fip_priority
;
1411 fcf_rec
->switch_name
[0] =
1412 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1413 fcf_rec
->switch_name
[1] =
1414 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1415 fcf_rec
->switch_name
[2] =
1416 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1417 fcf_rec
->switch_name
[3] =
1418 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1419 fcf_rec
->switch_name
[4] =
1420 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1421 fcf_rec
->switch_name
[5] =
1422 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1423 fcf_rec
->switch_name
[6] =
1424 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1425 fcf_rec
->switch_name
[7] =
1426 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1430 * lpfc_update_fcf_record - Update driver fcf record
1431 * @phba: pointer to lpfc hba data structure.
1432 * @fcf_rec: pointer to driver fcf record.
1433 * @new_fcf_record: pointer to hba fcf record.
1434 * @addr_mode: address mode to be set to the driver fcf record.
1435 * @vlan_id: vlan tag to be set to the driver fcf record.
1436 * @flag: flag bits to be set to the driver fcf record.
1438 * This routine updates the driver FCF record from the new HBA FCF record
1439 * together with the address mode, vlan_id, and other informations. This
1440 * routine is called with the host lock held.
1443 __lpfc_update_fcf_record(struct lpfc_hba
*phba
, struct lpfc_fcf_rec
*fcf_rec
,
1444 struct fcf_record
*new_fcf_record
, uint32_t addr_mode
,
1445 uint16_t vlan_id
, uint32_t flag
)
1447 lockdep_assert_held(&phba
->hbalock
);
1449 /* Copy the fields from the HBA's FCF record */
1450 lpfc_copy_fcf_record(fcf_rec
, new_fcf_record
);
1451 /* Update other fields of driver FCF record */
1452 fcf_rec
->addr_mode
= addr_mode
;
1453 fcf_rec
->vlan_id
= vlan_id
;
1454 fcf_rec
->flag
|= (flag
| RECORD_VALID
);
1455 __lpfc_update_fcf_record_pri(phba
,
1456 bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
),
1461 * lpfc_register_fcf - Register the FCF with hba.
1462 * @phba: pointer to lpfc hba data structure.
1464 * This routine issues a register fcfi mailbox command to register
1468 lpfc_register_fcf(struct lpfc_hba
*phba
)
1470 LPFC_MBOXQ_t
*fcf_mbxq
;
1473 spin_lock_irq(&phba
->hbalock
);
1474 /* If the FCF is not available do nothing. */
1475 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1476 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1477 spin_unlock_irq(&phba
->hbalock
);
1481 /* The FCF is already registered, start discovery */
1482 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1483 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1484 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1485 if (phba
->pport
->port_state
!= LPFC_FLOGI
&&
1486 phba
->pport
->fc_flag
& FC_FABRIC
) {
1487 phba
->hba_flag
|= FCF_RR_INPROG
;
1488 spin_unlock_irq(&phba
->hbalock
);
1489 lpfc_initial_flogi(phba
->pport
);
1492 spin_unlock_irq(&phba
->hbalock
);
1495 spin_unlock_irq(&phba
->hbalock
);
1497 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1499 spin_lock_irq(&phba
->hbalock
);
1500 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1501 spin_unlock_irq(&phba
->hbalock
);
1505 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1506 fcf_mbxq
->vport
= phba
->pport
;
1507 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1508 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1509 if (rc
== MBX_NOT_FINISHED
) {
1510 spin_lock_irq(&phba
->hbalock
);
1511 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1512 spin_unlock_irq(&phba
->hbalock
);
1513 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1520 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1521 * @phba: pointer to lpfc hba data structure.
1522 * @new_fcf_record: pointer to fcf record.
1523 * @boot_flag: Indicates if this record used by boot bios.
1524 * @addr_mode: The address mode to be used by this FCF
1525 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1527 * This routine compare the fcf record with connect list obtained from the
1528 * config region to decide if this FCF can be used for SAN discovery. It returns
1529 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1530 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1531 * is used by boot bios and addr_mode will indicate the addressing mode to be
1532 * used for this FCF when the function returns.
1533 * If the FCF record need to be used with a particular vlan id, the vlan is
1534 * set in the vlan_id on return of the function. If not VLAN tagging need to
1535 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1538 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1539 struct fcf_record
*new_fcf_record
,
1540 uint32_t *boot_flag
, uint32_t *addr_mode
,
1543 struct lpfc_fcf_conn_entry
*conn_entry
;
1544 int i
, j
, fcf_vlan_id
= 0;
1546 /* Find the lowest VLAN id in the FCF record */
1547 for (i
= 0; i
< 512; i
++) {
1548 if (new_fcf_record
->vlan_bitmap
[i
]) {
1549 fcf_vlan_id
= i
* 8;
1551 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1559 /* FCF not valid/available or solicitation in progress */
1560 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1561 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
) ||
1562 bf_get(lpfc_fcf_record_fcf_sol
, new_fcf_record
))
1565 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1567 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1569 if (phba
->valid_vlan
)
1570 *vlan_id
= phba
->vlan_id
;
1572 *vlan_id
= LPFC_FCOE_NULL_VID
;
1577 * If there are no FCF connection table entry, driver connect to all
1580 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1582 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1586 * When there are no FCF connect entries, use driver's default
1587 * addressing mode - FPMA.
1589 if (*addr_mode
& LPFC_FCF_FPMA
)
1590 *addr_mode
= LPFC_FCF_FPMA
;
1592 /* If FCF record report a vlan id use that vlan id */
1594 *vlan_id
= fcf_vlan_id
;
1596 *vlan_id
= LPFC_FCOE_NULL_VID
;
1600 list_for_each_entry(conn_entry
,
1601 &phba
->fcf_conn_rec_list
, list
) {
1602 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1605 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1606 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1609 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1610 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1613 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1615 * If the vlan bit map does not have the bit set for the
1616 * vlan id to be used, then it is not a match.
1618 if (!(new_fcf_record
->vlan_bitmap
1619 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1620 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1625 * If connection record does not support any addressing mode,
1626 * skip the FCF record.
1628 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1629 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1633 * Check if the connection record specifies a required
1636 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1637 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1640 * If SPMA required but FCF not support this continue.
1642 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1643 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1644 new_fcf_record
) & LPFC_FCF_SPMA
))
1648 * If FPMA required but FCF not support this continue.
1650 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1651 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1652 new_fcf_record
) & LPFC_FCF_FPMA
))
1657 * This fcf record matches filtering criteria.
1659 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1665 * If user did not specify any addressing mode, or if the
1666 * preferred addressing mode specified by user is not supported
1667 * by FCF, allow fabric to pick the addressing mode.
1669 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1672 * If the user specified a required address mode, assign that
1675 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1676 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1677 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1679 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1681 * If the user specified a preferred address mode, use the
1682 * addr mode only if FCF support the addr_mode.
1684 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1685 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1686 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1687 (*addr_mode
& LPFC_FCF_SPMA
))
1688 *addr_mode
= LPFC_FCF_SPMA
;
1689 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1690 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1691 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1692 (*addr_mode
& LPFC_FCF_FPMA
))
1693 *addr_mode
= LPFC_FCF_FPMA
;
1695 /* If matching connect list has a vlan id, use it */
1696 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1697 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1699 * If no vlan id is specified in connect list, use the vlan id
1702 else if (fcf_vlan_id
)
1703 *vlan_id
= fcf_vlan_id
;
1705 *vlan_id
= LPFC_FCOE_NULL_VID
;
1714 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1715 * @phba: pointer to lpfc hba data structure.
1716 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1718 * This function check if there is any fcoe event pending while driver
1719 * scan FCF entries. If there is any pending event, it will restart the
1720 * FCF saning and return 1 else return 0.
1723 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1726 * If the Link is up and no FCoE events while in the
1727 * FCF discovery, no need to restart FCF discovery.
1729 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1730 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1733 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1734 "2768 Pending link or FCF event during current "
1735 "handling of the previous event: link_state:x%x, "
1736 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1737 phba
->link_state
, phba
->fcoe_eventtag_at_fcf_scan
,
1738 phba
->fcoe_eventtag
);
1740 spin_lock_irq(&phba
->hbalock
);
1741 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1742 spin_unlock_irq(&phba
->hbalock
);
1744 if (phba
->link_state
>= LPFC_LINK_UP
) {
1745 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1746 "2780 Restart FCF table scan due to "
1747 "pending FCF event:evt_tag_at_scan:x%x, "
1748 "evt_tag_current:x%x\n",
1749 phba
->fcoe_eventtag_at_fcf_scan
,
1750 phba
->fcoe_eventtag
);
1751 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1754 * Do not continue FCF discovery and clear FCF_TS_INPROG
1757 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1758 "2833 Stop FCF discovery process due to link "
1759 "state change (x%x)\n", phba
->link_state
);
1760 spin_lock_irq(&phba
->hbalock
);
1761 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1762 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
| FCF_DISCOVERY
);
1763 spin_unlock_irq(&phba
->hbalock
);
1766 /* Unregister the currently registered FCF if required */
1768 spin_lock_irq(&phba
->hbalock
);
1769 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1770 spin_unlock_irq(&phba
->hbalock
);
1771 lpfc_sli4_unregister_fcf(phba
);
1777 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1778 * @phba: pointer to lpfc hba data structure.
1779 * @fcf_cnt: number of eligible fcf record seen so far.
1781 * This function makes an running random selection decision on FCF record to
1782 * use through a sequence of @fcf_cnt eligible FCF records with equal
1783 * probability. To perform integer manunipulation of random numbers with
1784 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1785 * from prandom_u32() are taken as the random random number generated.
1787 * Returns true when outcome is for the newly read FCF record should be
1788 * chosen; otherwise, return false when outcome is for keeping the previously
1789 * chosen FCF record.
1792 lpfc_sli4_new_fcf_random_select(struct lpfc_hba
*phba
, uint32_t fcf_cnt
)
1796 /* Get 16-bit uniform random number */
1797 rand_num
= 0xFFFF & prandom_u32();
1799 /* Decision with probability 1/fcf_cnt */
1800 if ((fcf_cnt
* rand_num
) < 0xFFFF)
1807 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1808 * @phba: pointer to lpfc hba data structure.
1809 * @mboxq: pointer to mailbox object.
1810 * @next_fcf_index: pointer to holder of next fcf index.
1812 * This routine parses the non-embedded fcf mailbox command by performing the
1813 * necessarily error checking, non-embedded read FCF record mailbox command
1814 * SGE parsing, and endianness swapping.
1816 * Returns the pointer to the new FCF record in the non-embedded mailbox
1817 * command DMA memory if successfully, other NULL.
1819 static struct fcf_record
*
1820 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
1821 uint16_t *next_fcf_index
)
1824 struct lpfc_mbx_sge sge
;
1825 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1826 uint32_t shdr_status
, shdr_add_status
, if_type
;
1827 union lpfc_sli4_cfg_shdr
*shdr
;
1828 struct fcf_record
*new_fcf_record
;
1830 /* Get the first SGE entry from the non-embedded DMA memory. This
1831 * routine only uses a single SGE.
1833 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1834 if (unlikely(!mboxq
->sge_array
)) {
1835 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1836 "2524 Failed to get the non-embedded SGE "
1837 "virtual address\n");
1840 virt_addr
= mboxq
->sge_array
->addr
[0];
1842 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1843 lpfc_sli_pcimem_bcopy(shdr
, shdr
,
1844 sizeof(union lpfc_sli4_cfg_shdr
));
1845 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1846 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1847 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
1848 if (shdr_status
|| shdr_add_status
) {
1849 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
||
1850 if_type
== LPFC_SLI_INTF_IF_TYPE_2
)
1851 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1852 "2726 READ_FCF_RECORD Indicates empty "
1855 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1856 "2521 READ_FCF_RECORD mailbox failed "
1857 "with status x%x add_status x%x, "
1858 "mbx\n", shdr_status
, shdr_add_status
);
1862 /* Interpreting the returned information of the FCF record */
1863 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1864 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1865 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1866 *next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1867 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1868 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1869 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1870 offsetof(struct fcf_record
, vlan_bitmap
));
1871 new_fcf_record
->word137
= le32_to_cpu(new_fcf_record
->word137
);
1872 new_fcf_record
->word138
= le32_to_cpu(new_fcf_record
->word138
);
1874 return new_fcf_record
;
1878 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1879 * @phba: pointer to lpfc hba data structure.
1880 * @fcf_record: pointer to the fcf record.
1881 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1882 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1884 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1888 lpfc_sli4_log_fcf_record_info(struct lpfc_hba
*phba
,
1889 struct fcf_record
*fcf_record
,
1891 uint16_t next_fcf_index
)
1893 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1894 "2764 READ_FCF_RECORD:\n"
1895 "\tFCF_Index : x%x\n"
1896 "\tFCF_Avail : x%x\n"
1897 "\tFCF_Valid : x%x\n"
1899 "\tFIP_Priority : x%x\n"
1900 "\tMAC_Provider : x%x\n"
1901 "\tLowest VLANID : x%x\n"
1902 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1903 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1904 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1905 "\tNext_FCF_Index: x%x\n",
1906 bf_get(lpfc_fcf_record_fcf_index
, fcf_record
),
1907 bf_get(lpfc_fcf_record_fcf_avail
, fcf_record
),
1908 bf_get(lpfc_fcf_record_fcf_valid
, fcf_record
),
1909 bf_get(lpfc_fcf_record_fcf_sol
, fcf_record
),
1910 fcf_record
->fip_priority
,
1911 bf_get(lpfc_fcf_record_mac_addr_prov
, fcf_record
),
1913 bf_get(lpfc_fcf_record_mac_0
, fcf_record
),
1914 bf_get(lpfc_fcf_record_mac_1
, fcf_record
),
1915 bf_get(lpfc_fcf_record_mac_2
, fcf_record
),
1916 bf_get(lpfc_fcf_record_mac_3
, fcf_record
),
1917 bf_get(lpfc_fcf_record_mac_4
, fcf_record
),
1918 bf_get(lpfc_fcf_record_mac_5
, fcf_record
),
1919 bf_get(lpfc_fcf_record_fab_name_0
, fcf_record
),
1920 bf_get(lpfc_fcf_record_fab_name_1
, fcf_record
),
1921 bf_get(lpfc_fcf_record_fab_name_2
, fcf_record
),
1922 bf_get(lpfc_fcf_record_fab_name_3
, fcf_record
),
1923 bf_get(lpfc_fcf_record_fab_name_4
, fcf_record
),
1924 bf_get(lpfc_fcf_record_fab_name_5
, fcf_record
),
1925 bf_get(lpfc_fcf_record_fab_name_6
, fcf_record
),
1926 bf_get(lpfc_fcf_record_fab_name_7
, fcf_record
),
1927 bf_get(lpfc_fcf_record_switch_name_0
, fcf_record
),
1928 bf_get(lpfc_fcf_record_switch_name_1
, fcf_record
),
1929 bf_get(lpfc_fcf_record_switch_name_2
, fcf_record
),
1930 bf_get(lpfc_fcf_record_switch_name_3
, fcf_record
),
1931 bf_get(lpfc_fcf_record_switch_name_4
, fcf_record
),
1932 bf_get(lpfc_fcf_record_switch_name_5
, fcf_record
),
1933 bf_get(lpfc_fcf_record_switch_name_6
, fcf_record
),
1934 bf_get(lpfc_fcf_record_switch_name_7
, fcf_record
),
1939 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1940 * @phba: pointer to lpfc hba data structure.
1941 * @fcf_rec: pointer to an existing FCF record.
1942 * @new_fcf_record: pointer to a new FCF record.
1943 * @new_vlan_id: vlan id from the new FCF record.
1945 * This function performs matching test of a new FCF record against an existing
1946 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1947 * will not be used as part of the FCF record matching criteria.
1949 * Returns true if all the fields matching, otherwise returns false.
1952 lpfc_sli4_fcf_record_match(struct lpfc_hba
*phba
,
1953 struct lpfc_fcf_rec
*fcf_rec
,
1954 struct fcf_record
*new_fcf_record
,
1955 uint16_t new_vlan_id
)
1957 if (new_vlan_id
!= LPFC_FCOE_IGNORE_VID
)
1958 if (!lpfc_vlan_id_match(fcf_rec
->vlan_id
, new_vlan_id
))
1960 if (!lpfc_mac_addr_match(fcf_rec
->mac_addr
, new_fcf_record
))
1962 if (!lpfc_sw_name_match(fcf_rec
->switch_name
, new_fcf_record
))
1964 if (!lpfc_fab_name_match(fcf_rec
->fabric_name
, new_fcf_record
))
1966 if (fcf_rec
->priority
!= new_fcf_record
->fip_priority
)
1972 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1973 * @vport: Pointer to vport object.
1974 * @fcf_index: index to next fcf.
1976 * This function processing the roundrobin fcf failover to next fcf index.
1977 * When this function is invoked, there will be a current fcf registered
1979 * Return: 0 for continue retrying flogi on currently registered fcf;
1980 * 1 for stop flogi on currently registered fcf;
1982 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport
*vport
, uint16_t fcf_index
)
1984 struct lpfc_hba
*phba
= vport
->phba
;
1987 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
1988 spin_lock_irq(&phba
->hbalock
);
1989 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
1990 spin_unlock_irq(&phba
->hbalock
);
1991 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1992 "2872 Devloss tmo with no eligible "
1993 "FCF, unregister in-use FCF (x%x) "
1994 "and rescan FCF table\n",
1995 phba
->fcf
.current_rec
.fcf_indx
);
1996 lpfc_unregister_fcf_rescan(phba
);
1997 goto stop_flogi_current_fcf
;
1999 /* Mark the end to FLOGI roundrobin failover */
2000 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2001 /* Allow action to new fcf asynchronous event */
2002 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
2003 spin_unlock_irq(&phba
->hbalock
);
2004 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2005 "2865 No FCF available, stop roundrobin FCF "
2006 "failover and change port state:x%x/x%x\n",
2007 phba
->pport
->port_state
, LPFC_VPORT_UNKNOWN
);
2008 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
2010 if (!phba
->fcf
.fcf_redisc_attempted
) {
2011 lpfc_unregister_fcf(phba
);
2013 rc
= lpfc_sli4_redisc_fcf_table(phba
);
2015 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2016 "3195 Rediscover FCF table\n");
2017 phba
->fcf
.fcf_redisc_attempted
= 1;
2018 lpfc_sli4_clear_fcf_rr_bmask(phba
);
2020 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2021 "3196 Rediscover FCF table "
2022 "failed. Status:x%x\n", rc
);
2025 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2026 "3197 Already rediscover FCF table "
2027 "attempted. No more retry\n");
2029 goto stop_flogi_current_fcf
;
2031 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_ELS
,
2032 "2794 Try FLOGI roundrobin FCF failover to "
2033 "(x%x)\n", fcf_index
);
2034 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
, fcf_index
);
2036 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
2037 "2761 FLOGI roundrobin FCF failover "
2038 "failed (rc:x%x) to read FCF (x%x)\n",
2039 rc
, phba
->fcf
.current_rec
.fcf_indx
);
2041 goto stop_flogi_current_fcf
;
2045 stop_flogi_current_fcf
:
2046 lpfc_can_disctmo(vport
);
2051 * lpfc_sli4_fcf_pri_list_del
2052 * @phba: pointer to lpfc hba data structure.
2053 * @fcf_index the index of the fcf record to delete
2054 * This routine checks the on list flag of the fcf_index to be deleted.
2055 * If it is one the list then it is removed from the list, and the flag
2056 * is cleared. This routine grab the hbalock before removing the fcf
2057 * record from the list.
2059 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba
*phba
,
2062 struct lpfc_fcf_pri
*new_fcf_pri
;
2064 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2065 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2066 "3058 deleting idx x%x pri x%x flg x%x\n",
2067 fcf_index
, new_fcf_pri
->fcf_rec
.priority
,
2068 new_fcf_pri
->fcf_rec
.flag
);
2069 spin_lock_irq(&phba
->hbalock
);
2070 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
) {
2071 if (phba
->fcf
.current_rec
.priority
==
2072 new_fcf_pri
->fcf_rec
.priority
)
2073 phba
->fcf
.eligible_fcf_cnt
--;
2074 list_del_init(&new_fcf_pri
->list
);
2075 new_fcf_pri
->fcf_rec
.flag
&= ~LPFC_FCF_ON_PRI_LIST
;
2077 spin_unlock_irq(&phba
->hbalock
);
2081 * lpfc_sli4_set_fcf_flogi_fail
2082 * @phba: pointer to lpfc hba data structure.
2083 * @fcf_index the index of the fcf record to update
2084 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2085 * flag so the the round robin slection for the particular priority level
2086 * will try a different fcf record that does not have this bit set.
2087 * If the fcf record is re-read for any reason this flag is cleared brfore
2088 * adding it to the priority list.
2091 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba
*phba
, uint16_t fcf_index
)
2093 struct lpfc_fcf_pri
*new_fcf_pri
;
2094 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2095 spin_lock_irq(&phba
->hbalock
);
2096 new_fcf_pri
->fcf_rec
.flag
|= LPFC_FCF_FLOGI_FAILED
;
2097 spin_unlock_irq(&phba
->hbalock
);
2101 * lpfc_sli4_fcf_pri_list_add
2102 * @phba: pointer to lpfc hba data structure.
2103 * @fcf_index the index of the fcf record to add
2104 * This routine checks the priority of the fcf_index to be added.
2105 * If it is a lower priority than the current head of the fcf_pri list
2106 * then it is added to the list in the right order.
2107 * If it is the same priority as the current head of the list then it
2108 * is added to the head of the list and its bit in the rr_bmask is set.
2109 * If the fcf_index to be added is of a higher priority than the current
2110 * head of the list then the rr_bmask is cleared, its bit is set in the
2111 * rr_bmask and it is added to the head of the list.
2113 * 0=success 1=failure
2115 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba
*phba
,
2117 struct fcf_record
*new_fcf_record
)
2119 uint16_t current_fcf_pri
;
2120 uint16_t last_index
;
2121 struct lpfc_fcf_pri
*fcf_pri
;
2122 struct lpfc_fcf_pri
*next_fcf_pri
;
2123 struct lpfc_fcf_pri
*new_fcf_pri
;
2126 new_fcf_pri
= &phba
->fcf
.fcf_pri
[fcf_index
];
2127 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2128 "3059 adding idx x%x pri x%x flg x%x\n",
2129 fcf_index
, new_fcf_record
->fip_priority
,
2130 new_fcf_pri
->fcf_rec
.flag
);
2131 spin_lock_irq(&phba
->hbalock
);
2132 if (new_fcf_pri
->fcf_rec
.flag
& LPFC_FCF_ON_PRI_LIST
)
2133 list_del_init(&new_fcf_pri
->list
);
2134 new_fcf_pri
->fcf_rec
.fcf_index
= fcf_index
;
2135 new_fcf_pri
->fcf_rec
.priority
= new_fcf_record
->fip_priority
;
2136 if (list_empty(&phba
->fcf
.fcf_pri_list
)) {
2137 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2138 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2139 new_fcf_pri
->fcf_rec
.fcf_index
);
2143 last_index
= find_first_bit(phba
->fcf
.fcf_rr_bmask
,
2144 LPFC_SLI4_FCF_TBL_INDX_MAX
);
2145 if (last_index
>= LPFC_SLI4_FCF_TBL_INDX_MAX
) {
2146 ret
= 0; /* Empty rr list */
2149 current_fcf_pri
= phba
->fcf
.fcf_pri
[last_index
].fcf_rec
.priority
;
2150 if (new_fcf_pri
->fcf_rec
.priority
<= current_fcf_pri
) {
2151 list_add(&new_fcf_pri
->list
, &phba
->fcf
.fcf_pri_list
);
2152 if (new_fcf_pri
->fcf_rec
.priority
< current_fcf_pri
) {
2153 memset(phba
->fcf
.fcf_rr_bmask
, 0,
2154 sizeof(*phba
->fcf
.fcf_rr_bmask
));
2155 /* fcfs_at_this_priority_level = 1; */
2156 phba
->fcf
.eligible_fcf_cnt
= 1;
2158 /* fcfs_at_this_priority_level++; */
2159 phba
->fcf
.eligible_fcf_cnt
++;
2160 ret
= lpfc_sli4_fcf_rr_index_set(phba
,
2161 new_fcf_pri
->fcf_rec
.fcf_index
);
2165 list_for_each_entry_safe(fcf_pri
, next_fcf_pri
,
2166 &phba
->fcf
.fcf_pri_list
, list
) {
2167 if (new_fcf_pri
->fcf_rec
.priority
<=
2168 fcf_pri
->fcf_rec
.priority
) {
2169 if (fcf_pri
->list
.prev
== &phba
->fcf
.fcf_pri_list
)
2170 list_add(&new_fcf_pri
->list
,
2171 &phba
->fcf
.fcf_pri_list
);
2173 list_add(&new_fcf_pri
->list
,
2174 &((struct lpfc_fcf_pri
*)
2175 fcf_pri
->list
.prev
)->list
);
2178 } else if (fcf_pri
->list
.next
== &phba
->fcf
.fcf_pri_list
2179 || new_fcf_pri
->fcf_rec
.priority
<
2180 next_fcf_pri
->fcf_rec
.priority
) {
2181 list_add(&new_fcf_pri
->list
, &fcf_pri
->list
);
2185 if (new_fcf_pri
->fcf_rec
.priority
> fcf_pri
->fcf_rec
.priority
)
2191 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2192 new_fcf_pri
->fcf_rec
.flag
= LPFC_FCF_ON_PRI_LIST
;
2193 spin_unlock_irq(&phba
->hbalock
);
2198 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2199 * @phba: pointer to lpfc hba data structure.
2200 * @mboxq: pointer to mailbox object.
2202 * This function iterates through all the fcf records available in
2203 * HBA and chooses the optimal FCF record for discovery. After finding
2204 * the FCF for discovery it registers the FCF record and kicks start
2206 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2207 * use an FCF record which matches fabric name and mac address of the
2208 * currently used FCF record.
2209 * If the driver supports only one FCF, it will try to use the FCF record
2210 * used by BOOT_BIOS.
2213 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2215 struct fcf_record
*new_fcf_record
;
2216 uint32_t boot_flag
, addr_mode
;
2217 uint16_t fcf_index
, next_fcf_index
;
2218 struct lpfc_fcf_rec
*fcf_rec
= NULL
;
2219 uint16_t vlan_id
= LPFC_FCOE_NULL_VID
;
2220 bool select_new_fcf
;
2223 /* If there is pending FCoE event restart FCF table scan */
2224 if (lpfc_check_pending_fcoe_event(phba
, LPFC_SKIP_UNREG_FCF
)) {
2225 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2229 /* Parse the FCF record from the non-embedded mailbox command */
2230 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2232 if (!new_fcf_record
) {
2233 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2234 "2765 Mailbox command READ_FCF_RECORD "
2235 "failed to retrieve a FCF record.\n");
2236 /* Let next new FCF event trigger fast failover */
2237 spin_lock_irq(&phba
->hbalock
);
2238 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2239 spin_unlock_irq(&phba
->hbalock
);
2240 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2244 /* Check the FCF record against the connection list */
2245 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2246 &addr_mode
, &vlan_id
);
2248 /* Log the FCF record information if turned on */
2249 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2253 * If the fcf record does not match with connect list entries
2254 * read the next entry; otherwise, this is an eligible FCF
2255 * record for roundrobin FCF failover.
2258 lpfc_sli4_fcf_pri_list_del(phba
,
2259 bf_get(lpfc_fcf_record_fcf_index
,
2261 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2262 "2781 FCF (x%x) failed connection "
2263 "list check: (x%x/x%x/%x)\n",
2264 bf_get(lpfc_fcf_record_fcf_index
,
2266 bf_get(lpfc_fcf_record_fcf_avail
,
2268 bf_get(lpfc_fcf_record_fcf_valid
,
2270 bf_get(lpfc_fcf_record_fcf_sol
,
2272 if ((phba
->fcf
.fcf_flag
& FCF_IN_USE
) &&
2273 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2274 new_fcf_record
, LPFC_FCOE_IGNORE_VID
)) {
2275 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) !=
2276 phba
->fcf
.current_rec
.fcf_indx
) {
2277 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2278 "2862 FCF (x%x) matches property "
2279 "of in-use FCF (x%x)\n",
2280 bf_get(lpfc_fcf_record_fcf_index
,
2282 phba
->fcf
.current_rec
.fcf_indx
);
2286 * In case the current in-use FCF record becomes
2287 * invalid/unavailable during FCF discovery that
2288 * was not triggered by fast FCF failover process,
2289 * treat it as fast FCF failover.
2291 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
) &&
2292 !(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2293 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2294 "2835 Invalid in-use FCF "
2295 "(x%x), enter FCF failover "
2297 phba
->fcf
.current_rec
.fcf_indx
);
2298 spin_lock_irq(&phba
->hbalock
);
2299 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2300 spin_unlock_irq(&phba
->hbalock
);
2301 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2302 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2303 LPFC_FCOE_FCF_GET_FIRST
);
2309 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2310 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
,
2317 * If this is not the first FCF discovery of the HBA, use last
2318 * FCF record for the discovery. The condition that a rescan
2319 * matches the in-use FCF record: fabric name, switch name, mac
2320 * address, and vlan_id.
2322 spin_lock_irq(&phba
->hbalock
);
2323 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2324 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2325 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2326 new_fcf_record
, vlan_id
)) {
2327 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) ==
2328 phba
->fcf
.current_rec
.fcf_indx
) {
2329 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2330 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)
2331 /* Stop FCF redisc wait timer */
2332 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2334 else if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2335 /* Fast failover, mark completed */
2336 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2337 spin_unlock_irq(&phba
->hbalock
);
2338 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2339 "2836 New FCF matches in-use "
2340 "FCF (x%x), port_state:x%x, "
2342 phba
->fcf
.current_rec
.fcf_indx
,
2343 phba
->pport
->port_state
,
2344 phba
->pport
->fc_flag
);
2347 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2348 "2863 New FCF (x%x) matches "
2349 "property of in-use FCF (x%x)\n",
2350 bf_get(lpfc_fcf_record_fcf_index
,
2352 phba
->fcf
.current_rec
.fcf_indx
);
2355 * Read next FCF record from HBA searching for the matching
2356 * with in-use record only if not during the fast failover
2357 * period. In case of fast failover period, it shall try to
2358 * determine whether the FCF record just read should be the
2361 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2362 spin_unlock_irq(&phba
->hbalock
);
2367 * Update on failover FCF record only if it's in FCF fast-failover
2368 * period; otherwise, update on current FCF record.
2370 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2371 fcf_rec
= &phba
->fcf
.failover_rec
;
2373 fcf_rec
= &phba
->fcf
.current_rec
;
2375 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
2377 * If the driver FCF record does not have boot flag
2378 * set and new hba fcf record has boot flag set, use
2379 * the new hba fcf record.
2381 if (boot_flag
&& !(fcf_rec
->flag
& BOOT_ENABLE
)) {
2382 /* Choose this FCF record */
2383 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2384 "2837 Update current FCF record "
2385 "(x%x) with new FCF record (x%x)\n",
2387 bf_get(lpfc_fcf_record_fcf_index
,
2389 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2390 addr_mode
, vlan_id
, BOOT_ENABLE
);
2391 spin_unlock_irq(&phba
->hbalock
);
2395 * If the driver FCF record has boot flag set and the
2396 * new hba FCF record does not have boot flag, read
2397 * the next FCF record.
2399 if (!boot_flag
&& (fcf_rec
->flag
& BOOT_ENABLE
)) {
2400 spin_unlock_irq(&phba
->hbalock
);
2404 * If the new hba FCF record has lower priority value
2405 * than the driver FCF record, use the new record.
2407 if (new_fcf_record
->fip_priority
< fcf_rec
->priority
) {
2408 /* Choose the new FCF record with lower priority */
2409 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2410 "2838 Update current FCF record "
2411 "(x%x) with new FCF record (x%x)\n",
2413 bf_get(lpfc_fcf_record_fcf_index
,
2415 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2416 addr_mode
, vlan_id
, 0);
2417 /* Reset running random FCF selection count */
2418 phba
->fcf
.eligible_fcf_cnt
= 1;
2419 } else if (new_fcf_record
->fip_priority
== fcf_rec
->priority
) {
2420 /* Update running random FCF selection count */
2421 phba
->fcf
.eligible_fcf_cnt
++;
2422 select_new_fcf
= lpfc_sli4_new_fcf_random_select(phba
,
2423 phba
->fcf
.eligible_fcf_cnt
);
2424 if (select_new_fcf
) {
2425 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2426 "2839 Update current FCF record "
2427 "(x%x) with new FCF record (x%x)\n",
2429 bf_get(lpfc_fcf_record_fcf_index
,
2431 /* Choose the new FCF by random selection */
2432 __lpfc_update_fcf_record(phba
, fcf_rec
,
2434 addr_mode
, vlan_id
, 0);
2437 spin_unlock_irq(&phba
->hbalock
);
2441 * This is the first suitable FCF record, choose this record for
2442 * initial best-fit FCF.
2445 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2446 "2840 Update initial FCF candidate "
2448 bf_get(lpfc_fcf_record_fcf_index
,
2450 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2451 addr_mode
, vlan_id
, (boot_flag
?
2453 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2454 /* Setup initial running random FCF selection count */
2455 phba
->fcf
.eligible_fcf_cnt
= 1;
2457 spin_unlock_irq(&phba
->hbalock
);
2461 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2462 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0) {
2463 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
) {
2465 * Case of FCF fast failover scan
2469 * It has not found any suitable FCF record, cancel
2470 * FCF scan inprogress, and do nothing
2472 if (!(phba
->fcf
.failover_rec
.flag
& RECORD_VALID
)) {
2473 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2474 "2782 No suitable FCF found: "
2476 phba
->fcoe_eventtag_at_fcf_scan
,
2477 bf_get(lpfc_fcf_record_fcf_index
,
2479 spin_lock_irq(&phba
->hbalock
);
2480 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2481 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2482 spin_unlock_irq(&phba
->hbalock
);
2483 /* Unregister in-use FCF and rescan */
2484 lpfc_printf_log(phba
, KERN_INFO
,
2486 "2864 On devloss tmo "
2487 "unreg in-use FCF and "
2488 "rescan FCF table\n");
2489 lpfc_unregister_fcf_rescan(phba
);
2493 * Let next new FCF event trigger fast failover
2495 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2496 spin_unlock_irq(&phba
->hbalock
);
2500 * It has found a suitable FCF record that is not
2501 * the same as in-use FCF record, unregister the
2502 * in-use FCF record, replace the in-use FCF record
2503 * with the new FCF record, mark FCF fast failover
2504 * completed, and then start register the new FCF
2508 /* Unregister the current in-use FCF record */
2509 lpfc_unregister_fcf(phba
);
2511 /* Replace in-use record with the new record */
2512 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2513 "2842 Replace in-use FCF (x%x) "
2514 "with failover FCF (x%x)\n",
2515 phba
->fcf
.current_rec
.fcf_indx
,
2516 phba
->fcf
.failover_rec
.fcf_indx
);
2517 memcpy(&phba
->fcf
.current_rec
,
2518 &phba
->fcf
.failover_rec
,
2519 sizeof(struct lpfc_fcf_rec
));
2521 * Mark the fast FCF failover rediscovery completed
2522 * and the start of the first round of the roundrobin
2525 spin_lock_irq(&phba
->hbalock
);
2526 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2527 spin_unlock_irq(&phba
->hbalock
);
2528 /* Register to the new FCF record */
2529 lpfc_register_fcf(phba
);
2532 * In case of transaction period to fast FCF failover,
2533 * do nothing when search to the end of the FCF table.
2535 if ((phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) ||
2536 (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
))
2539 if (phba
->cfg_fcf_failover_policy
== LPFC_FCF_FOV
&&
2540 phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2542 * In case the current in-use FCF record no
2543 * longer existed during FCF discovery that
2544 * was not triggered by fast FCF failover
2545 * process, treat it as fast FCF failover.
2547 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2548 "2841 In-use FCF record (x%x) "
2549 "not reported, entering fast "
2550 "FCF failover mode scanning.\n",
2551 phba
->fcf
.current_rec
.fcf_indx
);
2552 spin_lock_irq(&phba
->hbalock
);
2553 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2554 spin_unlock_irq(&phba
->hbalock
);
2555 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2556 LPFC_FCOE_FCF_GET_FIRST
);
2559 /* Register to the new FCF record */
2560 lpfc_register_fcf(phba
);
2563 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, next_fcf_index
);
2567 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2568 lpfc_register_fcf(phba
);
2574 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2575 * @phba: pointer to lpfc hba data structure.
2576 * @mboxq: pointer to mailbox object.
2578 * This is the callback function for FLOGI failure roundrobin FCF failover
2579 * read FCF record mailbox command from the eligible FCF record bmask for
2580 * performing the failover. If the FCF read back is not valid/available, it
2581 * fails through to retrying FLOGI to the currently registered FCF again.
2582 * Otherwise, if the FCF read back is valid and available, it will set the
2583 * newly read FCF record to the failover FCF record, unregister currently
2584 * registered FCF record, copy the failover FCF record to the current
2585 * FCF record, and then register the current FCF record before proceeding
2586 * to trying FLOGI on the new failover FCF.
2589 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2591 struct fcf_record
*new_fcf_record
;
2592 uint32_t boot_flag
, addr_mode
;
2593 uint16_t next_fcf_index
, fcf_index
;
2594 uint16_t current_fcf_index
;
2598 /* If link state is not up, stop the roundrobin failover process */
2599 if (phba
->link_state
< LPFC_LINK_UP
) {
2600 spin_lock_irq(&phba
->hbalock
);
2601 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
2602 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2603 spin_unlock_irq(&phba
->hbalock
);
2607 /* Parse the FCF record from the non-embedded mailbox command */
2608 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2610 if (!new_fcf_record
) {
2611 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2612 "2766 Mailbox command READ_FCF_RECORD "
2613 "failed to retrieve a FCF record. "
2614 "hba_flg x%x fcf_flg x%x\n", phba
->hba_flag
,
2615 phba
->fcf
.fcf_flag
);
2616 lpfc_unregister_fcf_rescan(phba
);
2620 /* Get the needed parameters from FCF record */
2621 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2622 &addr_mode
, &vlan_id
);
2624 /* Log the FCF record information if turned on */
2625 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2628 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2630 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2631 "2848 Remove ineligible FCF (x%x) from "
2632 "from roundrobin bmask\n", fcf_index
);
2633 /* Clear roundrobin bmask bit for ineligible FCF */
2634 lpfc_sli4_fcf_rr_index_clear(phba
, fcf_index
);
2635 /* Perform next round of roundrobin FCF failover */
2636 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
2637 rc
= lpfc_sli4_fcf_rr_next_proc(phba
->pport
, fcf_index
);
2643 if (fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
2644 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2645 "2760 Perform FLOGI roundrobin FCF failover: "
2646 "FCF (x%x) back to FCF (x%x)\n",
2647 phba
->fcf
.current_rec
.fcf_indx
, fcf_index
);
2648 /* Wait 500 ms before retrying FLOGI to current FCF */
2650 lpfc_issue_init_vfi(phba
->pport
);
2654 /* Upload new FCF record to the failover FCF record */
2655 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2656 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2657 phba
->fcf
.failover_rec
.fcf_indx
, fcf_index
);
2658 spin_lock_irq(&phba
->hbalock
);
2659 __lpfc_update_fcf_record(phba
, &phba
->fcf
.failover_rec
,
2660 new_fcf_record
, addr_mode
, vlan_id
,
2661 (boot_flag
? BOOT_ENABLE
: 0));
2662 spin_unlock_irq(&phba
->hbalock
);
2664 current_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
2666 /* Unregister the current in-use FCF record */
2667 lpfc_unregister_fcf(phba
);
2669 /* Replace in-use record with the new record */
2670 memcpy(&phba
->fcf
.current_rec
, &phba
->fcf
.failover_rec
,
2671 sizeof(struct lpfc_fcf_rec
));
2673 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2674 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2675 "(x%x) to FCF (x%x)\n", current_fcf_index
, fcf_index
);
2678 lpfc_register_fcf(phba
);
2680 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2684 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2685 * @phba: pointer to lpfc hba data structure.
2686 * @mboxq: pointer to mailbox object.
2688 * This is the callback function of read FCF record mailbox command for
2689 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2690 * failover when a new FCF event happened. If the FCF read back is
2691 * valid/available and it passes the connection list check, it updates
2692 * the bmask for the eligible FCF record for roundrobin failover.
2695 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2697 struct fcf_record
*new_fcf_record
;
2698 uint32_t boot_flag
, addr_mode
;
2699 uint16_t fcf_index
, next_fcf_index
;
2703 /* If link state is not up, no need to proceed */
2704 if (phba
->link_state
< LPFC_LINK_UP
)
2707 /* If FCF discovery period is over, no need to proceed */
2708 if (!(phba
->fcf
.fcf_flag
& FCF_DISCOVERY
))
2711 /* Parse the FCF record from the non-embedded mailbox command */
2712 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2714 if (!new_fcf_record
) {
2715 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2716 "2767 Mailbox command READ_FCF_RECORD "
2717 "failed to retrieve a FCF record.\n");
2721 /* Check the connection list for eligibility */
2722 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2723 &addr_mode
, &vlan_id
);
2725 /* Log the FCF record information if turned on */
2726 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2732 /* Update the eligible FCF record index bmask */
2733 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2735 rc
= lpfc_sli4_fcf_pri_list_add(phba
, fcf_index
, new_fcf_record
);
2738 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2742 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2743 * @phba: pointer to lpfc hba data structure.
2744 * @mboxq: pointer to mailbox data structure.
2746 * This function handles completion of init vfi mailbox command.
2749 lpfc_init_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2751 struct lpfc_vport
*vport
= mboxq
->vport
;
2754 * VFI not supported on interface type 0, just do the flogi
2755 * Also continue if the VFI is in use - just use the same one.
2757 if (mboxq
->u
.mb
.mbxStatus
&&
2758 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2759 LPFC_SLI_INTF_IF_TYPE_0
) &&
2760 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
2761 lpfc_printf_vlog(vport
, KERN_ERR
,
2763 "2891 Init VFI mailbox failed 0x%x\n",
2764 mboxq
->u
.mb
.mbxStatus
);
2765 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2766 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2770 lpfc_initial_flogi(vport
);
2771 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2776 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2777 * @vport: pointer to lpfc_vport data structure.
2779 * This function issue a init_vfi mailbox command to initialize the VFI and
2780 * VPI for the physical port.
2783 lpfc_issue_init_vfi(struct lpfc_vport
*vport
)
2785 LPFC_MBOXQ_t
*mboxq
;
2787 struct lpfc_hba
*phba
= vport
->phba
;
2789 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2791 lpfc_printf_vlog(vport
, KERN_ERR
,
2792 LOG_MBOX
, "2892 Failed to allocate "
2793 "init_vfi mailbox\n");
2796 lpfc_init_vfi(mboxq
, vport
);
2797 mboxq
->mbox_cmpl
= lpfc_init_vfi_cmpl
;
2798 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
2799 if (rc
== MBX_NOT_FINISHED
) {
2800 lpfc_printf_vlog(vport
, KERN_ERR
,
2801 LOG_MBOX
, "2893 Failed to issue init_vfi mailbox\n");
2802 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2807 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2808 * @phba: pointer to lpfc hba data structure.
2809 * @mboxq: pointer to mailbox data structure.
2811 * This function handles completion of init vpi mailbox command.
2814 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2816 struct lpfc_vport
*vport
= mboxq
->vport
;
2817 struct lpfc_nodelist
*ndlp
;
2818 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2820 if (mboxq
->u
.mb
.mbxStatus
) {
2821 lpfc_printf_vlog(vport
, KERN_ERR
,
2823 "2609 Init VPI mailbox failed 0x%x\n",
2824 mboxq
->u
.mb
.mbxStatus
);
2825 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2826 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2829 spin_lock_irq(shost
->host_lock
);
2830 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2831 spin_unlock_irq(shost
->host_lock
);
2833 /* If this port is physical port or FDISC is done, do reg_vpi */
2834 if ((phba
->pport
== vport
) || (vport
->port_state
== LPFC_FDISC
)) {
2835 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
2837 lpfc_printf_vlog(vport
, KERN_ERR
,
2839 "2731 Cannot find fabric "
2840 "controller node\n");
2842 lpfc_register_new_vport(phba
, vport
, ndlp
);
2843 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2847 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2848 lpfc_initial_fdisc(vport
);
2850 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
2851 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2852 "2606 No NPIV Fabric support\n");
2854 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2859 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2860 * @vport: pointer to lpfc_vport data structure.
2862 * This function issue a init_vpi mailbox command to initialize
2863 * VPI for the vport.
2866 lpfc_issue_init_vpi(struct lpfc_vport
*vport
)
2868 LPFC_MBOXQ_t
*mboxq
;
2871 if ((vport
->port_type
!= LPFC_PHYSICAL_PORT
) && (!vport
->vpi
)) {
2872 vpi
= lpfc_alloc_vpi(vport
->phba
);
2874 lpfc_printf_vlog(vport
, KERN_ERR
,
2876 "3303 Failed to obtain vport vpi\n");
2877 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2883 mboxq
= mempool_alloc(vport
->phba
->mbox_mem_pool
, GFP_KERNEL
);
2885 lpfc_printf_vlog(vport
, KERN_ERR
,
2886 LOG_MBOX
, "2607 Failed to allocate "
2887 "init_vpi mailbox\n");
2890 lpfc_init_vpi(vport
->phba
, mboxq
, vport
->vpi
);
2891 mboxq
->vport
= vport
;
2892 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
2893 rc
= lpfc_sli_issue_mbox(vport
->phba
, mboxq
, MBX_NOWAIT
);
2894 if (rc
== MBX_NOT_FINISHED
) {
2895 lpfc_printf_vlog(vport
, KERN_ERR
,
2896 LOG_MBOX
, "2608 Failed to issue init_vpi mailbox\n");
2897 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2902 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2903 * @phba: pointer to lpfc hba data structure.
2905 * This function loops through the list of vports on the @phba and issues an
2906 * FDISC if possible.
2909 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
2911 struct lpfc_vport
**vports
;
2914 vports
= lpfc_create_vport_work_array(phba
);
2915 if (vports
!= NULL
) {
2916 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2917 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
2919 /* There are no vpi for this vport */
2920 if (vports
[i
]->vpi
> phba
->max_vpi
) {
2921 lpfc_vport_set_state(vports
[i
],
2925 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2926 lpfc_vport_set_state(vports
[i
],
2930 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
2931 lpfc_issue_init_vpi(vports
[i
]);
2934 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2935 lpfc_initial_fdisc(vports
[i
]);
2937 lpfc_vport_set_state(vports
[i
],
2938 FC_VPORT_NO_FABRIC_SUPP
);
2939 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
2942 "Fabric support\n");
2946 lpfc_destroy_vport_work_array(phba
, vports
);
2950 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2952 struct lpfc_dmabuf
*dmabuf
= mboxq
->context1
;
2953 struct lpfc_vport
*vport
= mboxq
->vport
;
2954 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2957 * VFI not supported for interface type 0, so ignore any mailbox
2958 * error (except VFI in use) and continue with the discovery.
2960 if (mboxq
->u
.mb
.mbxStatus
&&
2961 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
2962 LPFC_SLI_INTF_IF_TYPE_0
) &&
2963 mboxq
->u
.mb
.mbxStatus
!= MBX_VFI_IN_USE
) {
2964 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2965 "2018 REG_VFI mbxStatus error x%x "
2967 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
2968 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2969 /* FLOGI failed, use loop map to make discovery list */
2970 lpfc_disc_list_loopmap(vport
);
2971 /* Start discovery */
2972 lpfc_disc_start(vport
);
2975 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2979 /* If the VFI is already registered, there is nothing else to do
2980 * Unless this was a VFI update and we are in PT2PT mode, then
2981 * we should drop through to set the port state to ready.
2983 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
2984 if (!(phba
->sli_rev
== LPFC_SLI_REV4
&&
2985 vport
->fc_flag
& FC_PT2PT
))
2988 /* The VPI is implicitly registered when the VFI is registered */
2989 spin_lock_irq(shost
->host_lock
);
2990 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2991 vport
->fc_flag
|= FC_VFI_REGISTERED
;
2992 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2993 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2994 spin_unlock_irq(shost
->host_lock
);
2996 /* In case SLI4 FC loopback test, we are ready */
2997 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
2998 (phba
->link_flag
& LS_LOOPBACK_MODE
)) {
2999 phba
->link_state
= LPFC_HBA_READY
;
3003 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3004 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3005 "alpacnt:%d LinkState:%x topology:%x\n",
3006 vport
->port_state
, vport
->fc_flag
, vport
->fc_myDID
,
3007 vport
->phba
->alpa_map
[0],
3008 phba
->link_state
, phba
->fc_topology
);
3010 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3012 * For private loop or for NPort pt2pt,
3013 * just start discovery and we are done.
3015 if ((vport
->fc_flag
& FC_PT2PT
) ||
3016 ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
3017 !(vport
->fc_flag
& FC_PUBLIC_LOOP
))) {
3019 /* Use loop map to make discovery list */
3020 lpfc_disc_list_loopmap(vport
);
3021 /* Start discovery */
3022 if (vport
->fc_flag
& FC_PT2PT
)
3023 vport
->port_state
= LPFC_VPORT_READY
;
3025 lpfc_disc_start(vport
);
3027 lpfc_start_fdiscs(phba
);
3028 lpfc_do_scr_ns_plogi(phba
, vport
);
3033 mempool_free(mboxq
, phba
->mbox_mem_pool
);
3035 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
3042 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3044 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3045 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
3046 struct lpfc_vport
*vport
= pmb
->vport
;
3047 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3048 struct serv_parm
*sp
= &vport
->fc_sparam
;
3051 /* Check for error */
3052 if (mb
->mbxStatus
) {
3053 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3054 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3055 "0319 READ_SPARAM mbxStatus error x%x "
3057 mb
->mbxStatus
, vport
->port_state
);
3058 lpfc_linkdown(phba
);
3062 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
3063 sizeof (struct serv_parm
));
3065 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
3066 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
3067 ed_tov
= (ed_tov
+ 999999) / 1000000;
3069 phba
->fc_edtov
= ed_tov
;
3070 phba
->fc_ratov
= (2 * ed_tov
) / 1000;
3071 if (phba
->fc_ratov
< FF_DEF_RATOV
) {
3072 /* RA_TOV should be atleast 10sec for initial flogi */
3073 phba
->fc_ratov
= FF_DEF_RATOV
;
3076 lpfc_update_vport_wwn(vport
);
3077 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3078 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
3079 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
3080 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
3083 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3085 mempool_free(pmb
, phba
->mbox_mem_pool
);
3089 pmb
->context1
= NULL
;
3090 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3092 lpfc_issue_clear_la(phba
, vport
);
3093 mempool_free(pmb
, phba
->mbox_mem_pool
);
3098 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, struct lpfc_mbx_read_top
*la
)
3100 struct lpfc_vport
*vport
= phba
->pport
;
3101 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
3102 struct Scsi_Host
*shost
;
3104 struct lpfc_dmabuf
*mp
;
3106 struct fcf_record
*fcf_record
;
3107 uint32_t fc_flags
= 0;
3109 spin_lock_irq(&phba
->hbalock
);
3110 phba
->fc_linkspeed
= bf_get(lpfc_mbx_read_top_link_spd
, la
);
3112 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3113 switch (bf_get(lpfc_mbx_read_top_link_spd
, la
)) {
3114 case LPFC_LINK_SPEED_1GHZ
:
3115 case LPFC_LINK_SPEED_2GHZ
:
3116 case LPFC_LINK_SPEED_4GHZ
:
3117 case LPFC_LINK_SPEED_8GHZ
:
3118 case LPFC_LINK_SPEED_10GHZ
:
3119 case LPFC_LINK_SPEED_16GHZ
:
3120 case LPFC_LINK_SPEED_32GHZ
:
3121 case LPFC_LINK_SPEED_64GHZ
:
3124 phba
->fc_linkspeed
= LPFC_LINK_SPEED_UNKNOWN
;
3129 if (phba
->fc_topology
&&
3130 phba
->fc_topology
!= bf_get(lpfc_mbx_read_top_topology
, la
)) {
3131 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
3132 "3314 Toplogy changed was 0x%x is 0x%x\n",
3134 bf_get(lpfc_mbx_read_top_topology
, la
));
3135 phba
->fc_topology_changed
= 1;
3138 phba
->fc_topology
= bf_get(lpfc_mbx_read_top_topology
, la
);
3139 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
3141 shost
= lpfc_shost_from_vport(vport
);
3142 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3143 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
3145 /* if npiv is enabled and this adapter supports npiv log
3146 * a message that npiv is not supported in this topology
3148 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
3149 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3150 "1309 Link Up Event npiv not supported in loop "
3152 /* Get Loop Map information */
3153 if (bf_get(lpfc_mbx_read_top_il
, la
))
3154 fc_flags
|= FC_LBIT
;
3156 vport
->fc_myDID
= bf_get(lpfc_mbx_read_top_alpa_granted
, la
);
3157 i
= la
->lilpBde64
.tus
.f
.bdeSize
;
3160 phba
->alpa_map
[0] = 0;
3162 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
3173 numalpa
= phba
->alpa_map
[0];
3175 while (j
< numalpa
) {
3176 memset(un
.pamap
, 0, 16);
3177 for (k
= 1; j
< numalpa
; k
++) {
3179 phba
->alpa_map
[j
+ 1];
3184 /* Link Up Event ALPA map */
3185 lpfc_printf_log(phba
,
3188 "1304 Link Up Event "
3189 "ALPA map Data: x%x "
3191 un
.pa
.wd1
, un
.pa
.wd2
,
3192 un
.pa
.wd3
, un
.pa
.wd4
);
3197 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
3198 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
3199 (phba
->sli_rev
>= LPFC_SLI_REV3
))
3200 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
3202 vport
->fc_myDID
= phba
->fc_pref_DID
;
3203 fc_flags
|= FC_LBIT
;
3205 spin_unlock_irq(&phba
->hbalock
);
3208 spin_lock_irq(shost
->host_lock
);
3209 vport
->fc_flag
|= fc_flags
;
3210 spin_unlock_irq(shost
->host_lock
);
3214 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3218 rc
= lpfc_read_sparam(phba
, sparam_mbox
, 0);
3220 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3223 sparam_mbox
->vport
= vport
;
3224 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
3225 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
3226 if (rc
== MBX_NOT_FINISHED
) {
3227 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
3228 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3230 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
3234 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3235 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3238 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
3239 lpfc_config_link(phba
, cfglink_mbox
);
3240 cfglink_mbox
->vport
= vport
;
3241 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
3242 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
3243 if (rc
== MBX_NOT_FINISHED
) {
3244 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
3248 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
3250 * Add the driver's default FCF record at FCF index 0 now. This
3251 * is phase 1 implementation that support FCF index 0 and driver
3254 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
3255 fcf_record
= kzalloc(sizeof(struct fcf_record
),
3257 if (unlikely(!fcf_record
)) {
3258 lpfc_printf_log(phba
, KERN_ERR
,
3260 "2554 Could not allocate memory for "
3266 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
3267 LPFC_FCOE_FCF_DEF_INDEX
);
3268 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
3270 lpfc_printf_log(phba
, KERN_ERR
,
3272 "2013 Could not manually add FCF "
3273 "record 0, status %d\n", rc
);
3281 * The driver is expected to do FIP/FCF. Call the port
3282 * and get the FCF Table.
3284 spin_lock_irq(&phba
->hbalock
);
3285 if (phba
->hba_flag
& FCF_TS_INPROG
) {
3286 spin_unlock_irq(&phba
->hbalock
);
3289 /* This is the initial FCF discovery scan */
3290 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
3291 spin_unlock_irq(&phba
->hbalock
);
3292 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3293 "2778 Start FCF table scan at linkup\n");
3294 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3295 LPFC_FCOE_FCF_GET_FIRST
);
3297 spin_lock_irq(&phba
->hbalock
);
3298 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
3299 spin_unlock_irq(&phba
->hbalock
);
3302 /* Reset FCF roundrobin bmask for new discovery */
3303 lpfc_sli4_clear_fcf_rr_bmask(phba
);
3308 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3309 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3310 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3311 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
3312 lpfc_issue_clear_la(phba
, vport
);
3317 lpfc_enable_la(struct lpfc_hba
*phba
)
3320 struct lpfc_sli
*psli
= &phba
->sli
;
3321 spin_lock_irq(&phba
->hbalock
);
3322 psli
->sli_flag
|= LPFC_PROCESS_LA
;
3323 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
3324 control
= readl(phba
->HCregaddr
);
3325 control
|= HC_LAINT_ENA
;
3326 writel(control
, phba
->HCregaddr
);
3327 readl(phba
->HCregaddr
); /* flush */
3329 spin_unlock_irq(&phba
->hbalock
);
3333 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
3335 lpfc_linkdown(phba
);
3336 lpfc_enable_la(phba
);
3337 lpfc_unregister_unused_fcf(phba
);
3338 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3343 * This routine handles processing a READ_TOPOLOGY mailbox
3344 * command upon completion. It is setup in the LPFC_MBOXQ
3345 * as the completion routine when the command is
3346 * handed off to the SLI layer. SLI4 only.
3349 lpfc_mbx_cmpl_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3351 struct lpfc_vport
*vport
= pmb
->vport
;
3352 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3353 struct lpfc_mbx_read_top
*la
;
3354 struct lpfc_sli_ring
*pring
;
3355 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3356 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3359 /* Unblock ELS traffic */
3360 pring
= lpfc_phba_elsring(phba
);
3362 pring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3364 /* Check for error */
3365 if (mb
->mbxStatus
) {
3366 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3367 "1307 READ_LA mbox error x%x state x%x\n",
3368 mb
->mbxStatus
, vport
->port_state
);
3369 lpfc_mbx_issue_link_down(phba
);
3370 phba
->link_state
= LPFC_HBA_ERROR
;
3371 goto lpfc_mbx_cmpl_read_topology_free_mbuf
;
3374 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3375 attn_type
= bf_get(lpfc_mbx_read_top_att_type
, la
);
3377 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
3379 spin_lock_irq(shost
->host_lock
);
3380 if (bf_get(lpfc_mbx_read_top_pb
, la
))
3381 vport
->fc_flag
|= FC_BYPASSED_MODE
;
3383 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
3384 spin_unlock_irq(shost
->host_lock
);
3386 if (phba
->fc_eventTag
<= la
->eventTag
) {
3387 phba
->fc_stat
.LinkMultiEvent
++;
3388 if (attn_type
== LPFC_ATT_LINK_UP
)
3389 if (phba
->fc_eventTag
!= 0)
3390 lpfc_linkdown(phba
);
3393 phba
->fc_eventTag
= la
->eventTag
;
3394 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3395 spin_lock_irq(&phba
->hbalock
);
3396 if (bf_get(lpfc_mbx_read_top_mm
, la
))
3397 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
3399 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
3400 spin_unlock_irq(&phba
->hbalock
);
3403 phba
->link_events
++;
3404 if ((attn_type
== LPFC_ATT_LINK_UP
) &&
3405 !(phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)) {
3406 phba
->fc_stat
.LinkUp
++;
3407 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
3408 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3409 "1306 Link Up Event in loop back mode "
3410 "x%x received Data: x%x x%x x%x x%x\n",
3411 la
->eventTag
, phba
->fc_eventTag
,
3412 bf_get(lpfc_mbx_read_top_alpa_granted
,
3414 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3417 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3418 "1303 Link Up Event x%x received "
3419 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3420 la
->eventTag
, phba
->fc_eventTag
,
3421 bf_get(lpfc_mbx_read_top_alpa_granted
,
3423 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3425 bf_get(lpfc_mbx_read_top_mm
, la
),
3426 bf_get(lpfc_mbx_read_top_fa
, la
),
3427 phba
->wait_4_mlo_maint_flg
);
3429 lpfc_mbx_process_link_up(phba
, la
);
3430 } else if (attn_type
== LPFC_ATT_LINK_DOWN
||
3431 attn_type
== LPFC_ATT_UNEXP_WWPN
) {
3432 phba
->fc_stat
.LinkDown
++;
3433 if (phba
->link_flag
& LS_LOOPBACK_MODE
)
3434 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3435 "1308 Link Down Event in loop back mode "
3437 "Data: x%x x%x x%x\n",
3438 la
->eventTag
, phba
->fc_eventTag
,
3439 phba
->pport
->port_state
, vport
->fc_flag
);
3440 else if (attn_type
== LPFC_ATT_UNEXP_WWPN
)
3441 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3442 "1313 Link Down UNEXP WWPN Event x%x received "
3443 "Data: x%x x%x x%x x%x x%x\n",
3444 la
->eventTag
, phba
->fc_eventTag
,
3445 phba
->pport
->port_state
, vport
->fc_flag
,
3446 bf_get(lpfc_mbx_read_top_mm
, la
),
3447 bf_get(lpfc_mbx_read_top_fa
, la
));
3449 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3450 "1305 Link Down Event x%x received "
3451 "Data: x%x x%x x%x x%x x%x\n",
3452 la
->eventTag
, phba
->fc_eventTag
,
3453 phba
->pport
->port_state
, vport
->fc_flag
,
3454 bf_get(lpfc_mbx_read_top_mm
, la
),
3455 bf_get(lpfc_mbx_read_top_fa
, la
));
3456 lpfc_mbx_issue_link_down(phba
);
3458 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
&&
3459 attn_type
== LPFC_ATT_LINK_UP
) {
3460 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
3461 phba
->fc_stat
.LinkDown
++;
3462 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3463 "1312 Link Down Event x%x received "
3464 "Data: x%x x%x x%x\n",
3465 la
->eventTag
, phba
->fc_eventTag
,
3466 phba
->pport
->port_state
, vport
->fc_flag
);
3467 lpfc_mbx_issue_link_down(phba
);
3469 lpfc_enable_la(phba
);
3471 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3472 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3473 "Data: x%x x%x x%x\n",
3474 la
->eventTag
, phba
->fc_eventTag
,
3475 phba
->pport
->port_state
, vport
->fc_flag
);
3477 * The cmnd that triggered this will be waiting for this
3480 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3481 if (phba
->wait_4_mlo_maint_flg
) {
3482 phba
->wait_4_mlo_maint_flg
= 0;
3483 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
3487 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
3488 bf_get(lpfc_mbx_read_top_fa
, la
)) {
3489 if (phba
->sli
.sli_flag
& LPFC_MENLO_MAINT
)
3490 lpfc_issue_clear_la(phba
, vport
);
3491 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3493 bf_get(lpfc_mbx_read_top_fa
, la
));
3496 lpfc_mbx_cmpl_read_topology_free_mbuf
:
3497 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3499 mempool_free(pmb
, phba
->mbox_mem_pool
);
3504 * This routine handles processing a REG_LOGIN mailbox
3505 * command upon completion. It is setup in the LPFC_MBOXQ
3506 * as the completion routine when the command is
3507 * handed off to the SLI layer.
3510 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3512 struct lpfc_vport
*vport
= pmb
->vport
;
3513 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3514 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3515 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3517 pmb
->context1
= NULL
;
3518 pmb
->context2
= NULL
;
3520 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
3521 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3522 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3523 kref_read(&ndlp
->kref
),
3524 ndlp
->nlp_usg_map
, ndlp
);
3525 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
3526 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3528 if (ndlp
->nlp_flag
& NLP_IGNR_REG_CMPL
||
3529 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) {
3530 /* We rcvd a rscn after issuing this
3531 * mbox reg login, we may have cycled
3532 * back through the state and be
3533 * back at reg login state so this
3534 * mbox needs to be ignored becase
3535 * there is another reg login in
3538 spin_lock_irq(shost
->host_lock
);
3539 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
3540 spin_unlock_irq(shost
->host_lock
);
3543 * We cannot leave the RPI registered because
3544 * if we go thru discovery again for this ndlp
3545 * a subsequent REG_RPI will fail.
3547 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3548 lpfc_unreg_rpi(vport
, ndlp
);
3551 /* Call state machine */
3552 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
3554 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3556 mempool_free(pmb
, phba
->mbox_mem_pool
);
3557 /* decrement the node reference count held for this callback
3566 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3568 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3569 struct lpfc_vport
*vport
= pmb
->vport
;
3570 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3572 switch (mb
->mbxStatus
) {
3575 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3576 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3579 /* If VPI is busy, reset the HBA */
3581 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3582 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3583 vport
->vpi
, mb
->mbxStatus
);
3584 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
3585 lpfc_workq_post_event(phba
, NULL
, NULL
,
3586 LPFC_EVT_RESET_HBA
);
3588 spin_lock_irq(shost
->host_lock
);
3589 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3590 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3591 spin_unlock_irq(shost
->host_lock
);
3592 vport
->unreg_vpi_cmpl
= VPORT_OK
;
3593 mempool_free(pmb
, phba
->mbox_mem_pool
);
3594 lpfc_cleanup_vports_rrqs(vport
, NULL
);
3596 * This shost reference might have been taken at the beginning of
3597 * lpfc_vport_delete()
3599 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
3600 scsi_host_put(shost
);
3604 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
3606 struct lpfc_hba
*phba
= vport
->phba
;
3610 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3614 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
3615 mbox
->vport
= vport
;
3616 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
3617 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3618 if (rc
== MBX_NOT_FINISHED
) {
3619 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3620 "1800 Could not issue unreg_vpi\n");
3621 mempool_free(mbox
, phba
->mbox_mem_pool
);
3622 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
3629 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3631 struct lpfc_vport
*vport
= pmb
->vport
;
3632 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3633 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3635 switch (mb
->mbxStatus
) {
3639 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3640 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3642 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3643 spin_lock_irq(shost
->host_lock
);
3644 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3645 spin_unlock_irq(shost
->host_lock
);
3646 vport
->fc_myDID
= 0;
3648 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3649 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3650 if (phba
->nvmet_support
)
3651 lpfc_nvmet_update_targetport(phba
);
3653 lpfc_nvme_update_localport(vport
);
3658 spin_lock_irq(shost
->host_lock
);
3659 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3660 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3661 spin_unlock_irq(shost
->host_lock
);
3662 vport
->num_disc_nodes
= 0;
3663 /* go thru NPR list and issue ELS PLOGIs */
3664 if (vport
->fc_npr_cnt
)
3665 lpfc_els_disc_plogi(vport
);
3667 if (!vport
->num_disc_nodes
) {
3668 spin_lock_irq(shost
->host_lock
);
3669 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3670 spin_unlock_irq(shost
->host_lock
);
3671 lpfc_can_disctmo(vport
);
3673 vport
->port_state
= LPFC_VPORT_READY
;
3676 mempool_free(pmb
, phba
->mbox_mem_pool
);
3681 * lpfc_create_static_vport - Read HBA config region to create static vports.
3682 * @phba: pointer to lpfc hba data structure.
3684 * This routine issue a DUMP mailbox command for config region 22 to get
3685 * the list of static vports to be created. The function create vports
3686 * based on the information returned from the HBA.
3689 lpfc_create_static_vport(struct lpfc_hba
*phba
)
3691 LPFC_MBOXQ_t
*pmb
= NULL
;
3693 struct static_vport_info
*vport_info
;
3694 int mbx_wait_rc
= 0, i
;
3695 struct fc_vport_identifiers vport_id
;
3696 struct fc_vport
*new_fc_vport
;
3697 struct Scsi_Host
*shost
;
3698 struct lpfc_vport
*vport
;
3699 uint16_t offset
= 0;
3700 uint8_t *vport_buff
;
3701 struct lpfc_dmabuf
*mp
;
3702 uint32_t byte_count
= 0;
3704 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3706 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3707 "0542 lpfc_create_static_vport failed to"
3708 " allocate mailbox memory\n");
3711 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
3714 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
3716 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3717 "0543 lpfc_create_static_vport failed to"
3718 " allocate vport_info\n");
3719 mempool_free(pmb
, phba
->mbox_mem_pool
);
3723 vport_buff
= (uint8_t *) vport_info
;
3725 /* free dma buffer from previous round */
3726 if (pmb
->context1
) {
3727 mp
= (struct lpfc_dmabuf
*)pmb
->context1
;
3728 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3731 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
3734 pmb
->vport
= phba
->pport
;
3735 mbx_wait_rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
,
3738 if ((mbx_wait_rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
3739 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3740 "0544 lpfc_create_static_vport failed to"
3741 " issue dump mailbox command ret 0x%x "
3743 mbx_wait_rc
, mb
->mbxStatus
);
3747 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3748 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
3749 mp
= (struct lpfc_dmabuf
*)pmb
->context1
;
3750 if (byte_count
> sizeof(struct static_vport_info
) -
3752 byte_count
= sizeof(struct static_vport_info
)
3754 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
3755 offset
+= byte_count
;
3757 if (mb
->un
.varDmp
.word_cnt
>
3758 sizeof(struct static_vport_info
) - offset
)
3759 mb
->un
.varDmp
.word_cnt
=
3760 sizeof(struct static_vport_info
)
3762 byte_count
= mb
->un
.varDmp
.word_cnt
;
3763 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
3764 vport_buff
+ offset
,
3767 offset
+= byte_count
;
3770 } while (byte_count
&&
3771 offset
< sizeof(struct static_vport_info
));
3774 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
3775 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
3776 != VPORT_INFO_REV
)) {
3777 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3778 "0545 lpfc_create_static_vport bad"
3779 " information header 0x%x 0x%x\n",
3780 le32_to_cpu(vport_info
->signature
),
3781 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
3786 shost
= lpfc_shost_from_vport(phba
->pport
);
3788 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
3789 memset(&vport_id
, 0, sizeof(vport_id
));
3790 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
3791 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
3792 if (!vport_id
.port_name
|| !vport_id
.node_name
)
3795 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
3796 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
3797 vport_id
.disable
= false;
3798 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
3800 if (!new_fc_vport
) {
3801 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3802 "0546 lpfc_create_static_vport failed to"
3807 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
3808 vport
->vport_flag
|= STATIC_VPORT
;
3813 if (mbx_wait_rc
!= MBX_TIMEOUT
) {
3814 if (pmb
->context1
) {
3815 mp
= (struct lpfc_dmabuf
*)pmb
->context1
;
3816 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3819 mempool_free(pmb
, phba
->mbox_mem_pool
);
3826 * This routine handles processing a Fabric REG_LOGIN mailbox
3827 * command upon completion. It is setup in the LPFC_MBOXQ
3828 * as the completion routine when the command is
3829 * handed off to the SLI layer.
3832 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3834 struct lpfc_vport
*vport
= pmb
->vport
;
3835 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3836 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3837 struct lpfc_nodelist
*ndlp
;
3838 struct Scsi_Host
*shost
;
3840 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3841 pmb
->context1
= NULL
;
3842 pmb
->context2
= NULL
;
3844 if (mb
->mbxStatus
) {
3845 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3846 "0258 Register Fabric login error: 0x%x\n",
3848 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3850 mempool_free(pmb
, phba
->mbox_mem_pool
);
3852 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3853 /* FLOGI failed, use loop map to make discovery list */
3854 lpfc_disc_list_loopmap(vport
);
3856 /* Start discovery */
3857 lpfc_disc_start(vport
);
3858 /* Decrement the reference count to ndlp after the
3859 * reference to the ndlp are done.
3865 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3866 /* Decrement the reference count to ndlp after the reference
3867 * to the ndlp are done.
3873 if (phba
->sli_rev
< LPFC_SLI_REV4
)
3874 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3875 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
3876 ndlp
->nlp_type
|= NLP_FABRIC
;
3877 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3879 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3880 /* when physical port receive logo donot start
3881 * vport discovery */
3882 if (!(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
3883 lpfc_start_fdiscs(phba
);
3885 shost
= lpfc_shost_from_vport(vport
);
3886 spin_lock_irq(shost
->host_lock
);
3887 vport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
3888 spin_unlock_irq(shost
->host_lock
);
3890 lpfc_do_scr_ns_plogi(phba
, vport
);
3893 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3895 mempool_free(pmb
, phba
->mbox_mem_pool
);
3897 /* Drop the reference count from the mbox at the end after
3898 * all the current reference to the ndlp have been done.
3905 * This routine will issue a GID_FT for each FC4 Type supported
3906 * by the driver. ALL GID_FTs must complete before discovery is started.
3909 lpfc_issue_gidft(struct lpfc_vport
*vport
)
3911 struct lpfc_hba
*phba
= vport
->phba
;
3913 /* Good status, issue CT Request to NameServer */
3914 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3915 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
)) {
3916 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_FCP
)) {
3917 /* Cannot issue NameServer FCP Query, so finish up
3920 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
3921 "0604 %s FC TYPE %x %s\n",
3922 "Failed to issue GID_FT to ",
3924 "Finishing discovery.");
3930 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
3931 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
3932 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, SLI_CTPT_NVME
)) {
3933 /* Cannot issue NameServer NVME Query, so finish up
3936 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
3937 "0605 %s FC_TYPE %x %s %d\n",
3938 "Failed to issue GID_FT to ",
3940 "Finishing discovery: gidftinp ",
3942 if (vport
->gidft_inp
== 0)
3947 return vport
->gidft_inp
;
3951 * This routine handles processing a NameServer REG_LOGIN mailbox
3952 * command upon completion. It is setup in the LPFC_MBOXQ
3953 * as the completion routine when the command is
3954 * handed off to the SLI layer.
3957 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3959 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3960 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3961 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3962 struct lpfc_vport
*vport
= pmb
->vport
;
3964 pmb
->context1
= NULL
;
3965 pmb
->context2
= NULL
;
3966 vport
->gidft_inp
= 0;
3968 if (mb
->mbxStatus
) {
3969 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3970 "0260 Register NameServer error: 0x%x\n",
3974 /* decrement the node reference count held for this
3975 * callback function.
3978 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3980 mempool_free(pmb
, phba
->mbox_mem_pool
);
3982 /* If no other thread is using the ndlp, free it */
3983 lpfc_nlp_not_used(ndlp
);
3985 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3987 * RegLogin failed, use loop map to make discovery
3990 lpfc_disc_list_loopmap(vport
);
3992 /* Start discovery */
3993 lpfc_disc_start(vport
);
3996 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4000 if (phba
->sli_rev
< LPFC_SLI_REV4
)
4001 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4002 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
4003 ndlp
->nlp_type
|= NLP_FABRIC
;
4004 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4005 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
4006 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
4007 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4008 kref_read(&ndlp
->kref
),
4009 ndlp
->nlp_usg_map
, ndlp
);
4011 if (vport
->port_state
< LPFC_VPORT_READY
) {
4012 /* Link up discovery requires Fabric registration. */
4013 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
4014 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
4015 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
4016 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
4018 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4019 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_FCP
))
4020 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, FC_TYPE_FCP
);
4022 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
4023 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
))
4024 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0,
4027 /* Issue SCR just before NameServer GID_FT Query */
4028 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
4031 vport
->fc_ns_retry
= 0;
4032 if (lpfc_issue_gidft(vport
) == 0)
4036 * At this point in time we may need to wait for multiple
4037 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4039 * decrement the node reference count held for this
4040 * callback function.
4043 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4045 mempool_free(pmb
, phba
->mbox_mem_pool
);
4051 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4053 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4054 struct fc_rport
*rport
;
4055 struct lpfc_rport_data
*rdata
;
4056 struct fc_rport_identifiers rport_ids
;
4057 struct lpfc_hba
*phba
= vport
->phba
;
4059 if (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4062 /* Remote port has reappeared. Re-register w/ FC transport */
4063 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
4064 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
4065 rport_ids
.port_id
= ndlp
->nlp_DID
;
4066 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
4069 * We leave our node pointer in rport->dd_data when we unregister a
4070 * FCP target port. But fc_remote_port_add zeros the space to which
4071 * rport->dd_data points. So, if we're reusing a previously
4072 * registered port, drop the reference that we took the last time we
4073 * registered the port.
4075 rport
= ndlp
->rport
;
4077 rdata
= rport
->dd_data
;
4078 /* break the link before dropping the ref */
4081 if (rdata
->pnode
== ndlp
)
4083 rdata
->pnode
= NULL
;
4085 /* drop reference for earlier registeration */
4086 put_device(&rport
->dev
);
4089 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4090 "rport add: did:x%x flg:x%x type x%x",
4091 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4093 /* Don't add the remote port if unloading. */
4094 if (vport
->load_flag
& FC_UNLOADING
)
4097 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
4098 if (!rport
|| !get_device(&rport
->dev
)) {
4099 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
4100 "Warning: fc_remote_port_add failed\n");
4104 /* initialize static port data */
4105 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
4106 rport
->supported_classes
= ndlp
->nlp_class_sup
;
4107 rdata
= rport
->dd_data
;
4108 rdata
->pnode
= lpfc_nlp_get(ndlp
);
4110 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
4111 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
4112 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
4113 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
4115 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
4116 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
4118 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4119 "3183 rport register x%06x, rport %p role x%x\n",
4120 ndlp
->nlp_DID
, rport
, rport_ids
.roles
);
4122 if ((rport
->scsi_target_id
!= -1) &&
4123 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
4124 ndlp
->nlp_sid
= rport
->scsi_target_id
;
4130 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
4132 struct fc_rport
*rport
= ndlp
->rport
;
4133 struct lpfc_vport
*vport
= ndlp
->vport
;
4134 struct lpfc_hba
*phba
= vport
->phba
;
4136 if (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)
4139 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
4140 "rport delete: did:x%x flg:x%x type x%x",
4141 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4143 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4144 "3184 rport unregister x%06x, rport %p\n",
4145 ndlp
->nlp_DID
, rport
);
4147 fc_remote_port_delete(rport
);
4153 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
4155 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4157 spin_lock_irq(shost
->host_lock
);
4159 case NLP_STE_UNUSED_NODE
:
4160 vport
->fc_unused_cnt
+= count
;
4162 case NLP_STE_PLOGI_ISSUE
:
4163 vport
->fc_plogi_cnt
+= count
;
4165 case NLP_STE_ADISC_ISSUE
:
4166 vport
->fc_adisc_cnt
+= count
;
4168 case NLP_STE_REG_LOGIN_ISSUE
:
4169 vport
->fc_reglogin_cnt
+= count
;
4171 case NLP_STE_PRLI_ISSUE
:
4172 vport
->fc_prli_cnt
+= count
;
4174 case NLP_STE_UNMAPPED_NODE
:
4175 vport
->fc_unmap_cnt
+= count
;
4177 case NLP_STE_MAPPED_NODE
:
4178 vport
->fc_map_cnt
+= count
;
4180 case NLP_STE_NPR_NODE
:
4181 if (vport
->fc_npr_cnt
== 0 && count
== -1)
4182 vport
->fc_npr_cnt
= 0;
4184 vport
->fc_npr_cnt
+= count
;
4187 spin_unlock_irq(shost
->host_lock
);
4191 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4192 int old_state
, int new_state
)
4194 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4196 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
4197 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4198 ndlp
->nlp_type
|= NLP_FC_NODE
;
4200 if (new_state
== NLP_STE_MAPPED_NODE
)
4201 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
4202 if (new_state
== NLP_STE_NPR_NODE
)
4203 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
4205 /* FCP and NVME Transport interface */
4206 if ((old_state
== NLP_STE_MAPPED_NODE
||
4207 old_state
== NLP_STE_UNMAPPED_NODE
)) {
4209 vport
->phba
->nport_event_cnt
++;
4210 lpfc_unregister_remote_port(ndlp
);
4213 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4214 vport
->phba
->nport_event_cnt
++;
4215 if (vport
->phba
->nvmet_support
== 0) {
4216 /* Start devloss if target. */
4217 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
4218 lpfc_nvme_unregister_port(vport
, ndlp
);
4220 /* NVMET has no upcall. */
4226 /* FCP and NVME Transport interfaces */
4228 if (new_state
== NLP_STE_MAPPED_NODE
||
4229 new_state
== NLP_STE_UNMAPPED_NODE
) {
4230 if (ndlp
->nlp_fc4_type
||
4231 ndlp
->nlp_DID
== Fabric_DID
||
4232 ndlp
->nlp_DID
== NameServer_DID
||
4233 ndlp
->nlp_DID
== FDMI_DID
) {
4234 vport
->phba
->nport_event_cnt
++;
4236 * Tell the fc transport about the port, if we haven't
4237 * already. If we have, and it's a scsi entity, be
4239 lpfc_register_remote_port(vport
, ndlp
);
4241 /* Notify the NVME transport of this new rport. */
4242 if (vport
->phba
->sli_rev
>= LPFC_SLI_REV4
&&
4243 ndlp
->nlp_fc4_type
& NLP_FC4_NVME
) {
4244 if (vport
->phba
->nvmet_support
== 0) {
4245 /* Register this rport with the transport.
4246 * Only NVME Target Rports are registered with
4249 if (ndlp
->nlp_type
& NLP_NVME_TARGET
) {
4250 vport
->phba
->nport_event_cnt
++;
4251 lpfc_nvme_register_port(vport
, ndlp
);
4254 /* Just take an NDLP ref count since the
4255 * target does not register rports.
4262 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4263 (vport
->stat_data_enabled
)) {
4265 * A new target is discovered, if there is no buffer for
4266 * statistical data collection allocate buffer.
4268 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
4269 sizeof(struct lpfc_scsicmd_bkt
),
4272 if (!ndlp
->lat_data
)
4273 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
4274 "0286 lpfc_nlp_state_cleanup failed to "
4275 "allocate statistical data buffer DID "
4276 "0x%x\n", ndlp
->nlp_DID
);
4279 * If the node just added to Mapped list was an FCP target,
4280 * but the remote port registration failed or assigned a target
4281 * id outside the presentable range - move the node to the
4284 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
4285 (ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4287 ndlp
->rport
->scsi_target_id
== -1 ||
4288 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
4289 spin_lock_irq(shost
->host_lock
);
4290 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
4291 spin_unlock_irq(shost
->host_lock
);
4292 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4297 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
4299 static char *states
[] = {
4300 [NLP_STE_UNUSED_NODE
] = "UNUSED",
4301 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
4302 [NLP_STE_ADISC_ISSUE
] = "ADISC",
4303 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
4304 [NLP_STE_PRLI_ISSUE
] = "PRLI",
4305 [NLP_STE_LOGO_ISSUE
] = "LOGO",
4306 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
4307 [NLP_STE_MAPPED_NODE
] = "MAPPED",
4308 [NLP_STE_NPR_NODE
] = "NPR",
4311 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
4312 strlcpy(buffer
, states
[state
], size
);
4314 snprintf(buffer
, size
, "unknown (%d)", state
);
4319 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4322 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4323 int old_state
= ndlp
->nlp_state
;
4324 char name1
[16], name2
[16];
4326 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4327 "0904 NPort state transition x%06x, %s -> %s\n",
4329 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
4330 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
4332 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4333 "node statechg did:x%x old:%d ste:%d",
4334 ndlp
->nlp_DID
, old_state
, state
);
4336 if (old_state
== NLP_STE_NPR_NODE
&&
4337 state
!= NLP_STE_NPR_NODE
)
4338 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4339 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
4340 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
4341 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
4344 if (list_empty(&ndlp
->nlp_listp
)) {
4345 spin_lock_irq(shost
->host_lock
);
4346 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4347 spin_unlock_irq(shost
->host_lock
);
4348 } else if (old_state
)
4349 lpfc_nlp_counters(vport
, old_state
, -1);
4351 ndlp
->nlp_state
= state
;
4352 lpfc_nlp_counters(vport
, state
, 1);
4353 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
4357 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4359 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4361 if (list_empty(&ndlp
->nlp_listp
)) {
4362 spin_lock_irq(shost
->host_lock
);
4363 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
4364 spin_unlock_irq(shost
->host_lock
);
4369 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4371 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4373 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4374 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
4375 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
4376 spin_lock_irq(shost
->host_lock
);
4377 list_del_init(&ndlp
->nlp_listp
);
4378 spin_unlock_irq(shost
->host_lock
);
4379 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
4380 NLP_STE_UNUSED_NODE
);
4384 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4386 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4387 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
4388 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
4389 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
4390 NLP_STE_UNUSED_NODE
);
4393 * lpfc_initialize_node - Initialize all fields of node object
4394 * @vport: Pointer to Virtual Port object.
4395 * @ndlp: Pointer to FC node object.
4396 * @did: FC_ID of the node.
4398 * This function is always called when node object need to be initialized.
4399 * It initializes all the fields of the node object. Although the reference
4400 * to phba from @ndlp can be obtained indirectly through it's reference to
4401 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4402 * to the life-span of the @ndlp might go beyond the existence of @vport as
4403 * the final release of ndlp is determined by its reference count. And, the
4404 * operation on @ndlp needs the reference to phba.
4407 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4410 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
4411 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
4412 timer_setup(&ndlp
->nlp_delayfunc
, lpfc_els_retry_delay
, 0);
4413 ndlp
->nlp_DID
= did
;
4414 ndlp
->vport
= vport
;
4415 ndlp
->phba
= vport
->phba
;
4416 ndlp
->nlp_sid
= NLP_NO_SID
;
4417 ndlp
->nlp_fc4_type
= NLP_FC4_NONE
;
4418 kref_init(&ndlp
->kref
);
4419 NLP_INT_NODE_ACT(ndlp
);
4420 atomic_set(&ndlp
->cmd_pending
, 0);
4421 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
4424 struct lpfc_nodelist
*
4425 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4428 struct lpfc_hba
*phba
= vport
->phba
;
4430 unsigned long flags
;
4431 unsigned long *active_rrqs_xri_bitmap
= NULL
;
4432 int rpi
= LPFC_RPI_ALLOC_ERROR
;
4437 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4438 rpi
= lpfc_sli4_alloc_rpi(vport
->phba
);
4439 if (rpi
== LPFC_RPI_ALLOC_ERROR
)
4443 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4444 /* The ndlp should not be in memory free mode */
4445 if (NLP_CHK_FREE_REQ(ndlp
)) {
4446 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4447 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4448 "0277 lpfc_enable_node: ndlp:x%p "
4449 "usgmap:x%x refcnt:%d\n",
4450 (void *)ndlp
, ndlp
->nlp_usg_map
,
4451 kref_read(&ndlp
->kref
));
4454 /* The ndlp should not already be in active mode */
4455 if (NLP_CHK_NODE_ACT(ndlp
)) {
4456 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4457 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4458 "0278 lpfc_enable_node: ndlp:x%p "
4459 "usgmap:x%x refcnt:%d\n",
4460 (void *)ndlp
, ndlp
->nlp_usg_map
,
4461 kref_read(&ndlp
->kref
));
4465 /* Keep the original DID */
4466 did
= ndlp
->nlp_DID
;
4467 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4468 active_rrqs_xri_bitmap
= ndlp
->active_rrqs_xri_bitmap
;
4470 /* re-initialize ndlp except of ndlp linked list pointer */
4471 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
4472 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
4473 lpfc_initialize_node(vport
, ndlp
, did
);
4475 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4476 ndlp
->active_rrqs_xri_bitmap
= active_rrqs_xri_bitmap
;
4478 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4479 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4480 ndlp
->nlp_rpi
= rpi
;
4481 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4482 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4483 "map:%x %p\n", ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4485 kref_read(&ndlp
->kref
),
4486 ndlp
->nlp_usg_map
, ndlp
);
4490 if (state
!= NLP_STE_UNUSED_NODE
)
4491 lpfc_nlp_set_state(vport
, ndlp
, state
);
4493 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4494 "node enable: did:x%x",
4495 ndlp
->nlp_DID
, 0, 0);
4499 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4500 lpfc_sli4_free_rpi(vport
->phba
, rpi
);
4505 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4508 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4509 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4510 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4511 * until ALL other outstanding threads have completed. We check
4512 * that the ndlp not already in the UNUSED state before we proceed.
4514 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
4516 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4517 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
4518 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
4519 lpfc_unreg_rpi(vport
, ndlp
);
4527 * Start / ReStart rescue timer for Discovery / RSCN handling
4530 lpfc_set_disctmo(struct lpfc_vport
*vport
)
4532 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4533 struct lpfc_hba
*phba
= vport
->phba
;
4536 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
4537 /* For FAN, timeout should be greater than edtov */
4538 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
4540 /* Normal discovery timeout should be > than ELS/CT timeout
4541 * FC spec states we need 3 * ratov for CT requests
4543 tmo
= ((phba
->fc_ratov
* 3) + 3);
4547 if (!timer_pending(&vport
->fc_disctmo
)) {
4548 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4549 "set disc timer: tmo:x%x state:x%x flg:x%x",
4550 tmo
, vport
->port_state
, vport
->fc_flag
);
4553 mod_timer(&vport
->fc_disctmo
, jiffies
+ msecs_to_jiffies(1000 * tmo
));
4554 spin_lock_irq(shost
->host_lock
);
4555 vport
->fc_flag
|= FC_DISC_TMO
;
4556 spin_unlock_irq(shost
->host_lock
);
4558 /* Start Discovery Timer state <hba_state> */
4559 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4560 "0247 Start Discovery Timer state x%x "
4561 "Data: x%x x%lx x%x x%x\n",
4562 vport
->port_state
, tmo
,
4563 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
4564 vport
->fc_adisc_cnt
);
4570 * Cancel rescue timer for Discovery / RSCN handling
4573 lpfc_can_disctmo(struct lpfc_vport
*vport
)
4575 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4576 unsigned long iflags
;
4578 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4579 "can disc timer: state:x%x rtry:x%x flg:x%x",
4580 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
4582 /* Turn off discovery timer if its running */
4583 if (vport
->fc_flag
& FC_DISC_TMO
) {
4584 spin_lock_irqsave(shost
->host_lock
, iflags
);
4585 vport
->fc_flag
&= ~FC_DISC_TMO
;
4586 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
4587 del_timer_sync(&vport
->fc_disctmo
);
4588 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
4589 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
4590 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
4593 /* Cancel Discovery Timer state <hba_state> */
4594 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4595 "0248 Cancel Discovery Timer state x%x "
4596 "Data: x%x x%x x%x\n",
4597 vport
->port_state
, vport
->fc_flag
,
4598 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
4603 * Check specified ring for outstanding IOCB on the SLI queue
4604 * Return true if iocb matches the specified nport
4607 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
4608 struct lpfc_sli_ring
*pring
,
4609 struct lpfc_iocbq
*iocb
,
4610 struct lpfc_nodelist
*ndlp
)
4612 IOCB_t
*icmd
= &iocb
->iocb
;
4613 struct lpfc_vport
*vport
= ndlp
->vport
;
4615 if (iocb
->vport
!= vport
)
4618 if (pring
->ringno
== LPFC_ELS_RING
) {
4619 switch (icmd
->ulpCommand
) {
4620 case CMD_GEN_REQUEST64_CR
:
4621 if (iocb
->context_un
.ndlp
== ndlp
)
4623 case CMD_ELS_REQUEST64_CR
:
4624 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
4626 case CMD_XMIT_ELS_RSP64_CX
:
4627 if (iocb
->context1
== (uint8_t *) ndlp
)
4630 } else if (pring
->ringno
== LPFC_FCP_RING
) {
4631 /* Skip match check if waiting to relogin to FCP target */
4632 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4633 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
4636 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
4644 __lpfc_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4645 struct lpfc_nodelist
*ndlp
, struct lpfc_sli_ring
*pring
,
4646 struct list_head
*dequeue_list
)
4648 struct lpfc_iocbq
*iocb
, *next_iocb
;
4650 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
4651 /* Check to see if iocb matches the nport */
4652 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
4653 /* match, dequeue */
4654 list_move_tail(&iocb
->list
, dequeue_list
);
4659 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4660 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4662 struct lpfc_sli
*psli
= &phba
->sli
;
4665 spin_lock_irq(&phba
->hbalock
);
4666 for (i
= 0; i
< psli
->num_rings
; i
++)
4667 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, &psli
->sli3_ring
[i
],
4669 spin_unlock_irq(&phba
->hbalock
);
4673 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba
*phba
,
4674 struct lpfc_nodelist
*ndlp
, struct list_head
*dequeue_list
)
4676 struct lpfc_sli_ring
*pring
;
4677 struct lpfc_queue
*qp
= NULL
;
4679 spin_lock_irq(&phba
->hbalock
);
4680 list_for_each_entry(qp
, &phba
->sli4_hba
.lpfc_wq_list
, wq_list
) {
4684 spin_lock(&pring
->ring_lock
);
4685 __lpfc_dequeue_nport_iocbs(phba
, ndlp
, pring
, dequeue_list
);
4686 spin_unlock(&pring
->ring_lock
);
4688 spin_unlock_irq(&phba
->hbalock
);
4692 * Free resources / clean up outstanding I/Os
4693 * associated with nlp_rpi in the LPFC_NODELIST entry.
4696 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4698 LIST_HEAD(completions
);
4700 lpfc_fabric_abort_nport(ndlp
);
4703 * Everything that matches on txcmplq will be returned
4704 * by firmware with a no rpi error.
4706 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4707 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4708 lpfc_sli3_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4710 lpfc_sli4_dequeue_nport_iocbs(phba
, ndlp
, &completions
);
4713 /* Cancel all the IOCBs from the completions list */
4714 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4721 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4722 * @phba: Pointer to HBA context object.
4723 * @pmb: Pointer to mailbox object.
4725 * This function will issue an ELS LOGO command after completing
4729 lpfc_nlp_logo_unreg(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4731 struct lpfc_vport
*vport
= pmb
->vport
;
4732 struct lpfc_nodelist
*ndlp
;
4734 ndlp
= (struct lpfc_nodelist
*)(pmb
->context1
);
4737 lpfc_issue_els_logo(vport
, ndlp
, 0);
4738 mempool_free(pmb
, phba
->mbox_mem_pool
);
4742 * Free rpi associated with LPFC_NODELIST entry.
4743 * This routine is called from lpfc_freenode(), when we are removing
4744 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4745 * LOGO that completes successfully, and we are waiting to PLOGI back
4746 * to the remote NPort. In addition, it is called after we receive
4747 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4748 * we are waiting to PLOGI back to the remote NPort.
4751 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4753 struct lpfc_hba
*phba
= vport
->phba
;
4755 int rc
, acc_plogi
= 1;
4758 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4759 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) {
4760 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
4761 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
4762 "3366 RPI x%x needs to be "
4763 "unregistered nlp_flag x%x "
4765 ndlp
->nlp_rpi
, ndlp
->nlp_flag
,
4767 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4769 /* SLI4 ports require the physical rpi value. */
4770 rpi
= ndlp
->nlp_rpi
;
4771 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4772 rpi
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
4774 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, mbox
);
4775 mbox
->vport
= vport
;
4776 if (ndlp
->nlp_flag
& NLP_ISSUE_LOGO
) {
4777 mbox
->context1
= ndlp
;
4778 mbox
->mbox_cmpl
= lpfc_nlp_logo_unreg
;
4780 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
4781 (!(vport
->load_flag
& FC_UNLOADING
)) &&
4782 (bf_get(lpfc_sli_intf_if_type
,
4783 &phba
->sli4_hba
.sli_intf
) >=
4784 LPFC_SLI_INTF_IF_TYPE_2
) &&
4785 (kref_read(&ndlp
->kref
) > 0)) {
4786 mbox
->context1
= lpfc_nlp_get(ndlp
);
4788 lpfc_sli4_unreg_rpi_cmpl_clr
;
4790 * accept PLOGIs after unreg_rpi_cmpl
4795 lpfc_sli_def_mbox_cmpl
;
4798 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4799 if (rc
== MBX_NOT_FINISHED
) {
4800 mempool_free(mbox
, phba
->mbox_mem_pool
);
4804 lpfc_no_rpi(phba
, ndlp
);
4806 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4808 ndlp
->nlp_flag
&= ~NLP_RPI_REGISTERED
;
4809 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4811 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4814 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4819 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4820 * @phba: pointer to lpfc hba data structure.
4822 * This routine is invoked to unregister all the currently registered RPIs
4826 lpfc_unreg_hba_rpis(struct lpfc_hba
*phba
)
4828 struct lpfc_vport
**vports
;
4829 struct lpfc_nodelist
*ndlp
;
4830 struct Scsi_Host
*shost
;
4833 vports
= lpfc_create_vport_work_array(phba
);
4835 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
4836 "2884 Vport array allocation failed \n");
4839 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4840 shost
= lpfc_shost_from_vport(vports
[i
]);
4841 spin_lock_irq(shost
->host_lock
);
4842 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4843 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
4844 /* The mempool_alloc might sleep */
4845 spin_unlock_irq(shost
->host_lock
);
4846 lpfc_unreg_rpi(vports
[i
], ndlp
);
4847 spin_lock_irq(shost
->host_lock
);
4850 spin_unlock_irq(shost
->host_lock
);
4852 lpfc_destroy_vport_work_array(phba
, vports
);
4856 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
4858 struct lpfc_hba
*phba
= vport
->phba
;
4862 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4863 lpfc_sli4_unreg_all_rpis(vport
);
4867 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4869 lpfc_unreg_login(phba
, vport
->vpi
, LPFC_UNREG_ALL_RPIS_VPORT
,
4871 mbox
->vport
= vport
;
4872 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4873 mbox
->context1
= NULL
;
4874 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4875 if (rc
!= MBX_TIMEOUT
)
4876 mempool_free(mbox
, phba
->mbox_mem_pool
);
4878 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
4879 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
4880 "1836 Could not issue "
4881 "unreg_login(all_rpis) status %d\n", rc
);
4886 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
4888 struct lpfc_hba
*phba
= vport
->phba
;
4892 /* Unreg DID is an SLI3 operation. */
4893 if (phba
->sli_rev
> LPFC_SLI_REV3
)
4896 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4898 lpfc_unreg_did(phba
, vport
->vpi
, LPFC_UNREG_ALL_DFLT_RPIS
,
4900 mbox
->vport
= vport
;
4901 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4902 mbox
->context1
= NULL
;
4903 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4904 if (rc
!= MBX_TIMEOUT
)
4905 mempool_free(mbox
, phba
->mbox_mem_pool
);
4907 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
4908 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
4909 "1815 Could not issue "
4910 "unreg_did (default rpis) status %d\n",
4916 * Free resources associated with LPFC_NODELIST entry
4917 * so it can be freed.
4920 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4922 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4923 struct lpfc_hba
*phba
= vport
->phba
;
4924 LPFC_MBOXQ_t
*mb
, *nextmb
;
4925 struct lpfc_dmabuf
*mp
;
4927 /* Cleanup node for NPort <nlp_DID> */
4928 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4929 "0900 Cleanup node for NPort x%x "
4930 "Data: x%x x%x x%x\n",
4931 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4932 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
4933 if (NLP_CHK_FREE_REQ(ndlp
)) {
4934 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4935 "0280 lpfc_cleanup_node: ndlp:x%p "
4936 "usgmap:x%x refcnt:%d\n",
4937 (void *)ndlp
, ndlp
->nlp_usg_map
,
4938 kref_read(&ndlp
->kref
));
4939 lpfc_dequeue_node(vport
, ndlp
);
4941 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4942 "0281 lpfc_cleanup_node: ndlp:x%p "
4943 "usgmap:x%x refcnt:%d\n",
4944 (void *)ndlp
, ndlp
->nlp_usg_map
,
4945 kref_read(&ndlp
->kref
));
4946 lpfc_disable_node(vport
, ndlp
);
4950 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4952 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4953 if ((mb
= phba
->sli
.mbox_active
)) {
4954 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
4955 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
4956 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
4957 mb
->context2
= NULL
;
4958 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4962 spin_lock_irq(&phba
->hbalock
);
4963 /* Cleanup REG_LOGIN completions which are not yet processed */
4964 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
4965 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) ||
4966 (mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) ||
4967 (ndlp
!= (struct lpfc_nodelist
*) mb
->context2
))
4970 mb
->context2
= NULL
;
4971 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4974 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
4975 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
4976 !(mb
->mbox_flag
& LPFC_MBX_IMED_UNREG
) &&
4977 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
4978 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
4980 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4983 list_del(&mb
->list
);
4984 mempool_free(mb
, phba
->mbox_mem_pool
);
4985 /* We shall not invoke the lpfc_nlp_put to decrement
4986 * the ndlp reference count as we are in the process
4987 * of lpfc_nlp_release.
4991 spin_unlock_irq(&phba
->hbalock
);
4993 lpfc_els_abort(phba
, ndlp
);
4995 spin_lock_irq(shost
->host_lock
);
4996 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
4997 spin_unlock_irq(shost
->host_lock
);
4999 ndlp
->nlp_last_elscmd
= 0;
5000 del_timer_sync(&ndlp
->nlp_delayfunc
);
5002 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
5003 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
5004 lpfc_cleanup_vports_rrqs(vport
, ndlp
);
5005 lpfc_unreg_rpi(vport
, ndlp
);
5011 * Check to see if we can free the nlp back to the freelist.
5012 * If we are in the middle of using the nlp in the discovery state
5013 * machine, defer the free till we reach the end of the state machine.
5016 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
5018 struct lpfc_hba
*phba
= vport
->phba
;
5019 struct lpfc_rport_data
*rdata
;
5020 struct fc_rport
*rport
;
5024 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5025 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
5026 !(ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) &&
5027 !(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) &&
5028 phba
->sli_rev
!= LPFC_SLI_REV4
) {
5029 /* For this case we need to cleanup the default rpi
5030 * allocated by the firmware.
5032 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5033 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5034 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5035 kref_read(&ndlp
->kref
),
5036 ndlp
->nlp_usg_map
, ndlp
);
5037 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
5039 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
5040 (uint8_t *) &vport
->fc_sparam
, mbox
, ndlp
->nlp_rpi
);
5042 mempool_free(mbox
, phba
->mbox_mem_pool
);
5045 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
5046 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
5047 mbox
->vport
= vport
;
5048 mbox
->context2
= ndlp
;
5049 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5050 if (rc
== MBX_NOT_FINISHED
) {
5051 mempool_free(mbox
, phba
->mbox_mem_pool
);
5056 lpfc_cleanup_node(vport
, ndlp
);
5059 * ndlp->rport must be set to NULL before it reaches here
5060 * i.e. break rport/node link before doing lpfc_nlp_put for
5061 * registered rport and then drop the reference of rport.
5065 * extra lpfc_nlp_put dropped the reference of ndlp
5066 * for registered rport so need to cleanup rport
5068 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
5069 "0940 removed node x%p DID x%x "
5070 " rport not null %p\n",
5071 ndlp
, ndlp
->nlp_DID
, ndlp
->rport
);
5072 rport
= ndlp
->rport
;
5073 rdata
= rport
->dd_data
;
5074 rdata
->pnode
= NULL
;
5076 put_device(&rport
->dev
);
5081 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5084 D_ID mydid
, ndlpdid
, matchdid
;
5086 if (did
== Bcast_DID
)
5089 /* First check for Direct match */
5090 if (ndlp
->nlp_DID
== did
)
5093 /* Next check for area/domain identically equals 0 match */
5094 mydid
.un
.word
= vport
->fc_myDID
;
5095 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
5099 matchdid
.un
.word
= did
;
5100 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
5101 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
5102 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
5103 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
5104 /* This code is supposed to match the ID
5105 * for a private loop device that is
5106 * connect to fl_port. But we need to
5107 * check that the port did not just go
5108 * from pt2pt to fabric or we could end
5109 * up matching ndlp->nlp_DID 000001 to
5110 * fabric DID 0x20101
5112 if ((ndlpdid
.un
.b
.domain
== 0) &&
5113 (ndlpdid
.un
.b
.area
== 0)) {
5114 if (ndlpdid
.un
.b
.id
&&
5115 vport
->phba
->fc_topology
==
5122 matchdid
.un
.word
= ndlp
->nlp_DID
;
5123 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
5124 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
5125 if ((matchdid
.un
.b
.domain
== 0) &&
5126 (matchdid
.un
.b
.area
== 0)) {
5127 if (matchdid
.un
.b
.id
)
5135 /* Search for a nodelist entry */
5136 static struct lpfc_nodelist
*
5137 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5139 struct lpfc_nodelist
*ndlp
;
5142 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5143 if (lpfc_matchdid(vport
, ndlp
, did
)) {
5144 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
5145 ((uint32_t) ndlp
->nlp_xri
<< 16) |
5146 ((uint32_t) ndlp
->nlp_type
<< 8) |
5147 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
5148 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5149 "0929 FIND node DID "
5150 "Data: x%p x%x x%x x%x %p\n",
5151 ndlp
, ndlp
->nlp_DID
,
5152 ndlp
->nlp_flag
, data1
,
5153 ndlp
->active_rrqs_xri_bitmap
);
5158 /* FIND node did <did> NOT FOUND */
5159 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5160 "0932 FIND node did x%x NOT FOUND.\n", did
);
5164 struct lpfc_nodelist
*
5165 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
5167 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5168 struct lpfc_nodelist
*ndlp
;
5169 unsigned long iflags
;
5171 spin_lock_irqsave(shost
->host_lock
, iflags
);
5172 ndlp
= __lpfc_findnode_did(vport
, did
);
5173 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
5177 struct lpfc_nodelist
*
5178 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
5180 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5181 struct lpfc_nodelist
*ndlp
;
5183 ndlp
= lpfc_findnode_did(vport
, did
);
5185 if (vport
->phba
->nvmet_support
)
5187 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
5188 lpfc_rscn_payload_check(vport
, did
) == 0)
5190 ndlp
= lpfc_nlp_init(vport
, did
);
5193 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5194 spin_lock_irq(shost
->host_lock
);
5195 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5196 spin_unlock_irq(shost
->host_lock
);
5198 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
5199 if (vport
->phba
->nvmet_support
)
5201 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
5204 spin_lock_irq(shost
->host_lock
);
5205 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5206 spin_unlock_irq(shost
->host_lock
);
5210 /* The NVME Target does not want to actively manage an rport.
5211 * The goal is to allow the target to reset its state and clear
5212 * pending IO in preparation for the initiator to recover.
5214 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
5215 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
5216 if (lpfc_rscn_payload_check(vport
, did
)) {
5218 /* Since this node is marked for discovery,
5219 * delay timeout is not needed.
5221 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5223 /* NVME Target mode waits until rport is known to be
5224 * impacted by the RSCN before it transitions. No
5225 * active management - just go to NPR provided the
5226 * node had a valid login.
5228 if (vport
->phba
->nvmet_support
)
5231 /* If we've already received a PLOGI from this NPort
5232 * we don't need to try to discover it again.
5234 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
&&
5236 (NLP_FCP_TARGET
| NLP_NVME_TARGET
)))
5239 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5240 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5242 spin_lock_irq(shost
->host_lock
);
5243 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5244 spin_unlock_irq(shost
->host_lock
);
5248 /* If the initiator received a PLOGI from this NPort or if the
5249 * initiator is already in the process of discovery on it,
5250 * there's no need to try to discover it again.
5252 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
5253 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5254 (!vport
->phba
->nvmet_support
&&
5255 ndlp
->nlp_flag
& NLP_RCV_PLOGI
))
5258 if (vport
->phba
->nvmet_support
)
5261 /* Moving to NPR state clears unsolicited flags and
5262 * allows for rediscovery
5264 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
5266 spin_lock_irq(shost
->host_lock
);
5267 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5268 spin_unlock_irq(shost
->host_lock
);
5273 /* Build a list of nodes to discover based on the loopmap */
5275 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
5277 struct lpfc_hba
*phba
= vport
->phba
;
5279 uint32_t alpa
, index
;
5281 if (!lpfc_is_link_up(phba
))
5284 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5287 /* Check for loop map present or not */
5288 if (phba
->alpa_map
[0]) {
5289 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
5290 alpa
= phba
->alpa_map
[j
];
5291 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
5293 lpfc_setup_disc_node(vport
, alpa
);
5296 /* No alpamap, so try all alpa's */
5297 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
5298 /* If cfg_scan_down is set, start from highest
5299 * ALPA (0xef) to lowest (0x1).
5301 if (vport
->cfg_scan_down
)
5304 index
= FC_MAXLOOP
- j
- 1;
5305 alpa
= lpfcAlpaArray
[index
];
5306 if ((vport
->fc_myDID
& 0xff) == alpa
)
5308 lpfc_setup_disc_node(vport
, alpa
);
5316 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5319 struct lpfc_sli
*psli
= &phba
->sli
;
5320 struct lpfc_sli_ring
*extra_ring
= &psli
->sli3_ring
[LPFC_EXTRA_RING
];
5321 struct lpfc_sli_ring
*fcp_ring
= &psli
->sli3_ring
[LPFC_FCP_RING
];
5325 * if it's not a physical port or if we already send
5326 * clear_la then don't send it.
5328 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
5329 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
5330 (phba
->sli_rev
== LPFC_SLI_REV4
))
5333 /* Link up discovery */
5334 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
5335 phba
->link_state
= LPFC_CLEAR_LA
;
5336 lpfc_clear_la(phba
, mbox
);
5337 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
5338 mbox
->vport
= vport
;
5339 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5340 if (rc
== MBX_NOT_FINISHED
) {
5341 mempool_free(mbox
, phba
->mbox_mem_pool
);
5342 lpfc_disc_flush_list(vport
);
5343 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5344 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
5345 phba
->link_state
= LPFC_HBA_ERROR
;
5350 /* Reg_vpi to tell firmware to resume normal operations */
5352 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
5354 LPFC_MBOXQ_t
*regvpimbox
;
5356 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5358 lpfc_reg_vpi(vport
, regvpimbox
);
5359 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
5360 regvpimbox
->vport
= vport
;
5361 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
5362 == MBX_NOT_FINISHED
) {
5363 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
5368 /* Start Link up / RSCN discovery on NPR nodes */
5370 lpfc_disc_start(struct lpfc_vport
*vport
)
5372 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5373 struct lpfc_hba
*phba
= vport
->phba
;
5375 uint32_t clear_la_pending
;
5377 if (!lpfc_is_link_up(phba
)) {
5378 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
5379 "3315 Link is not up %x\n",
5384 if (phba
->link_state
== LPFC_CLEAR_LA
)
5385 clear_la_pending
= 1;
5387 clear_la_pending
= 0;
5389 if (vport
->port_state
< LPFC_VPORT_READY
)
5390 vport
->port_state
= LPFC_DISC_AUTH
;
5392 lpfc_set_disctmo(vport
);
5394 vport
->fc_prevDID
= vport
->fc_myDID
;
5395 vport
->num_disc_nodes
= 0;
5397 /* Start Discovery state <hba_state> */
5398 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5399 "0202 Start Discovery hba state x%x "
5400 "Data: x%x x%x x%x\n",
5401 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
5402 vport
->fc_adisc_cnt
);
5404 /* First do ADISCs - if any */
5405 num_sent
= lpfc_els_disc_adisc(vport
);
5410 /* Register the VPI for SLI3, NPIV only. */
5411 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5412 !(vport
->fc_flag
& FC_PT2PT
) &&
5413 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
5414 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
5415 lpfc_issue_clear_la(phba
, vport
);
5416 lpfc_issue_reg_vpi(phba
, vport
);
5421 * For SLI2, we need to set port_state to READY and continue
5424 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
5425 /* If we get here, there is nothing to ADISC */
5426 lpfc_issue_clear_la(phba
, vport
);
5428 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
5429 vport
->num_disc_nodes
= 0;
5430 /* go thru NPR nodes and issue ELS PLOGIs */
5431 if (vport
->fc_npr_cnt
)
5432 lpfc_els_disc_plogi(vport
);
5434 if (!vport
->num_disc_nodes
) {
5435 spin_lock_irq(shost
->host_lock
);
5436 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
5437 spin_unlock_irq(shost
->host_lock
);
5438 lpfc_can_disctmo(vport
);
5441 vport
->port_state
= LPFC_VPORT_READY
;
5443 /* Next do PLOGIs - if any */
5444 num_sent
= lpfc_els_disc_plogi(vport
);
5449 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5450 /* Check to see if more RSCNs came in while we
5451 * were processing this one.
5453 if ((vport
->fc_rscn_id_cnt
== 0) &&
5454 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
5455 spin_lock_irq(shost
->host_lock
);
5456 vport
->fc_flag
&= ~FC_RSCN_MODE
;
5457 spin_unlock_irq(shost
->host_lock
);
5458 lpfc_can_disctmo(vport
);
5460 lpfc_els_handle_rscn(vport
);
5467 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5468 * ring the match the sppecified nodelist.
5471 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
5473 LIST_HEAD(completions
);
5474 struct lpfc_sli
*psli
;
5476 struct lpfc_iocbq
*iocb
, *next_iocb
;
5477 struct lpfc_sli_ring
*pring
;
5480 pring
= lpfc_phba_elsring(phba
);
5481 if (unlikely(!pring
))
5484 /* Error matching iocb on txq or txcmplq
5485 * First check the txq.
5487 spin_lock_irq(&phba
->hbalock
);
5488 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
5489 if (iocb
->context1
!= ndlp
) {
5493 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
5494 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
5496 list_move_tail(&iocb
->list
, &completions
);
5500 /* Next check the txcmplq */
5501 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
5502 if (iocb
->context1
!= ndlp
) {
5506 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
5507 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
5508 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
5511 spin_unlock_irq(&phba
->hbalock
);
5513 /* Cancel all the IOCBs from the completions list */
5514 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
5519 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
5521 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5522 struct lpfc_hba
*phba
= vport
->phba
;
5524 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
5525 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5527 if (!NLP_CHK_NODE_ACT(ndlp
))
5529 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5530 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
5531 lpfc_free_tx(phba
, ndlp
);
5538 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
5540 lpfc_els_flush_rscn(vport
);
5541 lpfc_els_flush_cmd(vport
);
5542 lpfc_disc_flush_list(vport
);
5545 /*****************************************************************************/
5547 * NAME: lpfc_disc_timeout
5549 * FUNCTION: Fibre Channel driver discovery timeout routine.
5551 * EXECUTION ENVIRONMENT: interrupt only
5559 /*****************************************************************************/
5561 lpfc_disc_timeout(struct timer_list
*t
)
5563 struct lpfc_vport
*vport
= from_timer(vport
, t
, fc_disctmo
);
5564 struct lpfc_hba
*phba
= vport
->phba
;
5565 uint32_t tmo_posted
;
5566 unsigned long flags
= 0;
5568 if (unlikely(!phba
))
5571 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
5572 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
5574 vport
->work_port_events
|= WORKER_DISC_TMO
;
5575 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
5578 lpfc_worker_wake_up(phba
);
5583 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
5585 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5586 struct lpfc_hba
*phba
= vport
->phba
;
5587 struct lpfc_sli
*psli
= &phba
->sli
;
5588 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
5589 LPFC_MBOXQ_t
*initlinkmbox
;
5590 int rc
, clrlaerr
= 0;
5592 if (!(vport
->fc_flag
& FC_DISC_TMO
))
5595 spin_lock_irq(shost
->host_lock
);
5596 vport
->fc_flag
&= ~FC_DISC_TMO
;
5597 spin_unlock_irq(shost
->host_lock
);
5599 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5600 "disc timeout: state:x%x rtry:x%x flg:x%x",
5601 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
5603 switch (vport
->port_state
) {
5605 case LPFC_LOCAL_CFG_LINK
:
5607 * port_state is identically LPFC_LOCAL_CFG_LINK while
5608 * waiting for FAN timeout
5610 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
5611 "0221 FAN timeout\n");
5613 /* Start discovery by sending FLOGI, clean up old rpis */
5614 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
5616 if (!NLP_CHK_NODE_ACT(ndlp
))
5618 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
5620 if (ndlp
->nlp_type
& NLP_FABRIC
) {
5621 /* Clean up the ndlp on Fabric connections */
5622 lpfc_drop_node(vport
, ndlp
);
5624 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
5625 /* Fail outstanding IO now since device
5626 * is marked for PLOGI.
5628 lpfc_unreg_rpi(vport
, ndlp
);
5631 if (vport
->port_state
!= LPFC_FLOGI
) {
5632 if (phba
->sli_rev
<= LPFC_SLI_REV3
)
5633 lpfc_initial_flogi(vport
);
5635 lpfc_issue_init_vfi(vport
);
5642 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5643 /* Initial FLOGI timeout */
5644 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5645 "0222 Initial %s timeout\n",
5646 vport
->vpi
? "FDISC" : "FLOGI");
5648 /* Assume no Fabric and go on with discovery.
5649 * Check for outstanding ELS FLOGI to abort.
5652 /* FLOGI failed, so just use loop map to make discovery list */
5653 lpfc_disc_list_loopmap(vport
);
5655 /* Start discovery */
5656 lpfc_disc_start(vport
);
5659 case LPFC_FABRIC_CFG_LINK
:
5660 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5662 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5663 "0223 Timeout while waiting for "
5664 "NameServer login\n");
5665 /* Next look for NameServer ndlp */
5666 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5667 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5668 lpfc_els_abort(phba
, ndlp
);
5670 /* ReStart discovery */
5674 /* Check for wait for NameServer Rsp timeout */
5675 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5676 "0224 NameServer Query timeout "
5678 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5680 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
5681 /* Try it one more time */
5682 vport
->fc_ns_retry
++;
5683 vport
->gidft_inp
= 0;
5684 rc
= lpfc_issue_gidft(vport
);
5688 vport
->fc_ns_retry
= 0;
5692 * Discovery is over.
5693 * set port_state to PORT_READY if SLI2.
5694 * cmpl_reg_vpi will set port_state to READY for SLI3.
5696 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5697 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5698 lpfc_issue_reg_vpi(phba
, vport
);
5700 lpfc_issue_clear_la(phba
, vport
);
5701 vport
->port_state
= LPFC_VPORT_READY
;
5705 /* Setup and issue mailbox INITIALIZE LINK command */
5706 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5707 if (!initlinkmbox
) {
5708 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5709 "0206 Device Discovery "
5710 "completion error\n");
5711 phba
->link_state
= LPFC_HBA_ERROR
;
5715 lpfc_linkdown(phba
);
5716 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
5717 phba
->cfg_link_speed
);
5718 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
5719 initlinkmbox
->vport
= vport
;
5720 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5721 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
5722 lpfc_set_loopback_flag(phba
);
5723 if (rc
== MBX_NOT_FINISHED
)
5724 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
5728 case LPFC_DISC_AUTH
:
5729 /* Node Authentication timeout */
5730 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5731 "0227 Node Authentication timeout\n");
5732 lpfc_disc_flush_list(vport
);
5735 * set port_state to PORT_READY if SLI2.
5736 * cmpl_reg_vpi will set port_state to READY for SLI3.
5738 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5739 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
5740 lpfc_issue_reg_vpi(phba
, vport
);
5741 else { /* NPIV Not enabled */
5742 lpfc_issue_clear_la(phba
, vport
);
5743 vport
->port_state
= LPFC_VPORT_READY
;
5748 case LPFC_VPORT_READY
:
5749 if (vport
->fc_flag
& FC_RSCN_MODE
) {
5750 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5751 "0231 RSCN timeout Data: x%x "
5753 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
5755 /* Cleanup any outstanding ELS commands */
5756 lpfc_els_flush_cmd(vport
);
5758 lpfc_els_flush_rscn(vport
);
5759 lpfc_disc_flush_list(vport
);
5764 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5765 "0273 Unexpected discovery timeout, "
5766 "vport State x%x\n", vport
->port_state
);
5770 switch (phba
->link_state
) {
5772 /* CLEAR LA timeout */
5773 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5774 "0228 CLEAR LA timeout\n");
5779 lpfc_issue_clear_la(phba
, vport
);
5781 case LPFC_LINK_UNKNOWN
:
5782 case LPFC_WARM_START
:
5783 case LPFC_INIT_START
:
5784 case LPFC_INIT_MBX_CMDS
:
5785 case LPFC_LINK_DOWN
:
5786 case LPFC_HBA_ERROR
:
5787 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5788 "0230 Unexpected timeout, hba link "
5789 "state x%x\n", phba
->link_state
);
5793 case LPFC_HBA_READY
:
5798 lpfc_disc_flush_list(vport
);
5799 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
5800 psli
->sli3_ring
[(LPFC_EXTRA_RING
)].flag
&=
5801 ~LPFC_STOP_IOCB_EVENT
;
5802 psli
->sli3_ring
[LPFC_FCP_RING
].flag
&=
5803 ~LPFC_STOP_IOCB_EVENT
;
5805 vport
->port_state
= LPFC_VPORT_READY
;
5811 * This routine handles processing a NameServer REG_LOGIN mailbox
5812 * command upon completion. It is setup in the LPFC_MBOXQ
5813 * as the completion routine when the command is
5814 * handed off to the SLI layer.
5817 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5819 MAILBOX_t
*mb
= &pmb
->u
.mb
;
5820 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
5821 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5822 struct lpfc_vport
*vport
= pmb
->vport
;
5824 pmb
->context1
= NULL
;
5825 pmb
->context2
= NULL
;
5827 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5828 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
5829 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
5830 ndlp
->nlp_type
|= NLP_FABRIC
;
5831 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
5832 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_SLI
,
5833 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5834 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5835 kref_read(&ndlp
->kref
),
5836 ndlp
->nlp_usg_map
, ndlp
);
5838 * Start issuing Fabric-Device Management Interface (FDMI) command to
5839 * 0xfffffa (FDMI well known port).
5840 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5841 * DPRT -> RPRT (vports)
5843 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
5844 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
, 0);
5846 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DPRT
, 0);
5849 /* decrement the node reference count held for this callback
5853 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5855 mempool_free(pmb
, phba
->mbox_mem_pool
);
5861 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
5863 uint16_t *rpi
= param
;
5865 /* check for active node */
5866 if (!NLP_CHK_NODE_ACT(ndlp
))
5869 return ndlp
->nlp_rpi
== *rpi
;
5873 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
5875 return memcmp(&ndlp
->nlp_portname
, param
,
5876 sizeof(ndlp
->nlp_portname
)) == 0;
5879 static struct lpfc_nodelist
*
5880 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
5882 struct lpfc_nodelist
*ndlp
;
5884 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5885 if (filter(ndlp
, param
)) {
5886 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5887 "3185 FIND node filter %p DID "
5888 "ndlp %p did x%x flg x%x st x%x "
5889 "xri x%x type x%x rpi x%x\n",
5890 filter
, ndlp
, ndlp
->nlp_DID
,
5891 ndlp
->nlp_flag
, ndlp
->nlp_state
,
5892 ndlp
->nlp_xri
, ndlp
->nlp_type
,
5897 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
5898 "3186 FIND node filter %p NOT FOUND.\n", filter
);
5903 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5904 * returns the node list element pointer else return NULL.
5906 struct lpfc_nodelist
*
5907 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
5909 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
5913 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5914 * returns the node element list pointer else return NULL.
5916 struct lpfc_nodelist
*
5917 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
5919 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5920 struct lpfc_nodelist
*ndlp
;
5922 spin_lock_irq(shost
->host_lock
);
5923 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
5924 spin_unlock_irq(shost
->host_lock
);
5929 * This routine looks up the ndlp lists for the given RPI. If the rpi
5930 * is found, the routine returns the node element list pointer else
5933 struct lpfc_nodelist
*
5934 lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
5936 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5937 struct lpfc_nodelist
*ndlp
;
5939 spin_lock_irq(shost
->host_lock
);
5940 ndlp
= __lpfc_findnode_rpi(vport
, rpi
);
5941 spin_unlock_irq(shost
->host_lock
);
5946 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5947 * @phba: pointer to lpfc hba data structure.
5948 * @vpi: the physical host virtual N_Port identifier.
5950 * This routine finds a vport on a HBA (referred by @phba) through a
5951 * @vpi. The function walks the HBA's vport list and returns the address
5952 * of the vport with the matching @vpi.
5955 * NULL - No vport with the matching @vpi found
5956 * Otherwise - Address to the vport with the matching @vpi.
5959 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
5961 struct lpfc_vport
*vport
;
5962 unsigned long flags
;
5965 /* The physical ports are always vpi 0 - translate is unnecessary. */
5968 * Translate the physical vpi to the logical vpi. The
5969 * vport stores the logical vpi.
5971 for (i
= 0; i
< phba
->max_vpi
; i
++) {
5972 if (vpi
== phba
->vpi_ids
[i
])
5976 if (i
>= phba
->max_vpi
) {
5977 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
5978 "2936 Could not find Vport mapped "
5979 "to vpi %d\n", vpi
);
5984 spin_lock_irqsave(&phba
->hbalock
, flags
);
5985 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
5986 if (vport
->vpi
== i
) {
5987 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5991 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
5995 struct lpfc_nodelist
*
5996 lpfc_nlp_init(struct lpfc_vport
*vport
, uint32_t did
)
5998 struct lpfc_nodelist
*ndlp
;
5999 int rpi
= LPFC_RPI_ALLOC_ERROR
;
6001 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6002 rpi
= lpfc_sli4_alloc_rpi(vport
->phba
);
6003 if (rpi
== LPFC_RPI_ALLOC_ERROR
)
6007 ndlp
= mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
6009 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6010 lpfc_sli4_free_rpi(vport
->phba
, rpi
);
6014 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
6016 lpfc_initialize_node(vport
, ndlp
, did
);
6017 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
6018 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
6019 ndlp
->nlp_rpi
= rpi
;
6020 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
6021 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
6022 "map:%x %p\n", ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6024 kref_read(&ndlp
->kref
),
6025 ndlp
->nlp_usg_map
, ndlp
);
6027 ndlp
->active_rrqs_xri_bitmap
=
6028 mempool_alloc(vport
->phba
->active_rrq_pool
,
6030 if (ndlp
->active_rrqs_xri_bitmap
)
6031 memset(ndlp
->active_rrqs_xri_bitmap
, 0,
6032 ndlp
->phba
->cfg_rrq_xri_bitmap_sz
);
6037 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
6038 "node init: did:x%x",
6039 ndlp
->nlp_DID
, 0, 0);
6044 /* This routine releases all resources associated with a specifc NPort's ndlp
6045 * and mempool_free's the nodelist.
6048 lpfc_nlp_release(struct kref
*kref
)
6050 struct lpfc_hba
*phba
;
6051 unsigned long flags
;
6052 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
6055 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6056 "node release: did:x%x flg:x%x type:x%x",
6057 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
6059 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
6060 "0279 lpfc_nlp_release: ndlp:x%p did %x "
6061 "usgmap:x%x refcnt:%d rpi:%x\n",
6062 (void *)ndlp
, ndlp
->nlp_DID
, ndlp
->nlp_usg_map
,
6063 kref_read(&ndlp
->kref
), ndlp
->nlp_rpi
);
6065 /* remove ndlp from action. */
6066 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
6068 /* clear the ndlp active flag for all release cases */
6070 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6071 NLP_CLR_NODE_ACT(ndlp
);
6072 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6073 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6074 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
6076 /* free ndlp memory for final ndlp release */
6077 if (NLP_CHK_FREE_REQ(ndlp
)) {
6078 kfree(ndlp
->lat_data
);
6079 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6080 mempool_free(ndlp
->active_rrqs_xri_bitmap
,
6081 ndlp
->phba
->active_rrq_pool
);
6082 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
6086 /* This routine bumps the reference count for a ndlp structure to ensure
6087 * that one discovery thread won't free a ndlp while another discovery thread
6090 struct lpfc_nodelist
*
6091 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
6093 struct lpfc_hba
*phba
;
6094 unsigned long flags
;
6097 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6098 "node get: did:x%x flg:x%x refcnt:x%x",
6099 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6100 kref_read(&ndlp
->kref
));
6101 /* The check of ndlp usage to prevent incrementing the
6102 * ndlp reference count that is in the process of being
6106 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6107 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
6108 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6109 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6110 "0276 lpfc_nlp_get: ndlp:x%p "
6111 "usgmap:x%x refcnt:%d\n",
6112 (void *)ndlp
, ndlp
->nlp_usg_map
,
6113 kref_read(&ndlp
->kref
));
6116 kref_get(&ndlp
->kref
);
6117 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6122 /* This routine decrements the reference count for a ndlp structure. If the
6123 * count goes to 0, this indicates the the associated nodelist should be
6124 * freed. Returning 1 indicates the ndlp resource has been released; on the
6125 * other hand, returning 0 indicates the ndlp resource has not been released
6129 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
6131 struct lpfc_hba
*phba
;
6132 unsigned long flags
;
6137 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6138 "node put: did:x%x flg:x%x refcnt:x%x",
6139 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6140 kref_read(&ndlp
->kref
));
6142 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
6143 /* Check the ndlp memory free acknowledge flag to avoid the
6144 * possible race condition that kref_put got invoked again
6145 * after previous one has done ndlp memory free.
6147 if (NLP_CHK_FREE_ACK(ndlp
)) {
6148 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6149 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6150 "0274 lpfc_nlp_put: ndlp:x%p "
6151 "usgmap:x%x refcnt:%d\n",
6152 (void *)ndlp
, ndlp
->nlp_usg_map
,
6153 kref_read(&ndlp
->kref
));
6156 /* Check the ndlp inactivate log flag to avoid the possible
6157 * race condition that kref_put got invoked again after ndlp
6158 * is already in inactivating state.
6160 if (NLP_CHK_IACT_REQ(ndlp
)) {
6161 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6162 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
6163 "0275 lpfc_nlp_put: ndlp:x%p "
6164 "usgmap:x%x refcnt:%d\n",
6165 (void *)ndlp
, ndlp
->nlp_usg_map
,
6166 kref_read(&ndlp
->kref
));
6169 /* For last put, mark the ndlp usage flags to make sure no
6170 * other kref_get and kref_put on the same ndlp shall get
6171 * in between the process when the final kref_put has been
6172 * invoked on this ndlp.
6174 if (kref_read(&ndlp
->kref
) == 1) {
6175 /* Indicate ndlp is put to inactive state. */
6176 NLP_SET_IACT_REQ(ndlp
);
6177 /* Acknowledge ndlp memory free has been seen. */
6178 if (NLP_CHK_FREE_REQ(ndlp
))
6179 NLP_SET_FREE_ACK(ndlp
);
6181 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
6182 /* Note, the kref_put returns 1 when decrementing a reference
6183 * count that was 1, it invokes the release callback function,
6184 * but it still left the reference count as 1 (not actually
6185 * performs the last decrementation). Otherwise, it actually
6186 * decrements the reference count and returns 0.
6188 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
6191 /* This routine free's the specified nodelist if it is not in use
6192 * by any other discovery thread. This routine returns 1 if the
6193 * ndlp has been freed. A return value of 0 indicates the ndlp is
6194 * not yet been released.
6197 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
6199 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
6200 "node not used: did:x%x flg:x%x refcnt:x%x",
6201 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
6202 kref_read(&ndlp
->kref
));
6203 if (kref_read(&ndlp
->kref
) == 1)
6204 if (lpfc_nlp_put(ndlp
))
6210 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6211 * @phba: Pointer to hba context object.
6213 * This function iterate through all FC nodes associated
6214 * will all vports to check if there is any node with
6215 * fc_rports associated with it. If there is an fc_rport
6216 * associated with the node, then the node is either in
6217 * discovered state or its devloss_timer is pending.
6220 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
6222 struct lpfc_vport
**vports
;
6224 struct lpfc_nodelist
*ndlp
;
6225 struct Scsi_Host
*shost
;
6227 vports
= lpfc_create_vport_work_array(phba
);
6229 /* If driver cannot allocate memory, indicate fcf is in use */
6233 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6234 shost
= lpfc_shost_from_vport(vports
[i
]);
6235 spin_lock_irq(shost
->host_lock
);
6237 * IF the CVL_RCVD bit is not set then we have sent the
6239 * If dev_loss fires while we are waiting we do not want to
6242 if (!(vports
[i
]->fc_flag
& FC_VPORT_CVL_RCVD
)) {
6243 spin_unlock_irq(shost
->host_lock
);
6247 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
6248 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
6249 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
6251 spin_unlock_irq(shost
->host_lock
);
6253 } else if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
6255 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
6256 "2624 RPI %x DID %x flag %x "
6257 "still logged in\n",
6258 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
6262 spin_unlock_irq(shost
->host_lock
);
6265 lpfc_destroy_vport_work_array(phba
, vports
);
6270 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6271 * @phba: Pointer to hba context object.
6272 * @mboxq: Pointer to mailbox object.
6274 * This function frees memory associated with the mailbox command.
6277 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6279 struct lpfc_vport
*vport
= mboxq
->vport
;
6280 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6282 if (mboxq
->u
.mb
.mbxStatus
) {
6283 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6284 "2555 UNREG_VFI mbxStatus error x%x "
6286 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6288 spin_lock_irq(shost
->host_lock
);
6289 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
6290 spin_unlock_irq(shost
->host_lock
);
6291 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6296 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6297 * @phba: Pointer to hba context object.
6298 * @mboxq: Pointer to mailbox object.
6300 * This function frees memory associated with the mailbox command.
6303 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
6305 struct lpfc_vport
*vport
= mboxq
->vport
;
6307 if (mboxq
->u
.mb
.mbxStatus
) {
6308 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6309 "2550 UNREG_FCFI mbxStatus error x%x "
6311 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
6313 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6318 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6319 * @phba: Pointer to hba context object.
6321 * This function prepare the HBA for unregistering the currently registered
6322 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6326 lpfc_unregister_fcf_prep(struct lpfc_hba
*phba
)
6328 struct lpfc_vport
**vports
;
6329 struct lpfc_nodelist
*ndlp
;
6330 struct Scsi_Host
*shost
;
6333 /* Unregister RPIs */
6334 if (lpfc_fcf_inuse(phba
))
6335 lpfc_unreg_hba_rpis(phba
);
6337 /* At this point, all discovery is aborted */
6338 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
6340 /* Unregister VPIs */
6341 vports
= lpfc_create_vport_work_array(phba
);
6342 if (vports
&& (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
6343 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6344 /* Stop FLOGI/FDISC retries */
6345 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6347 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6348 lpfc_cleanup_pending_mbox(vports
[i
]);
6349 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6350 lpfc_sli4_unreg_all_rpis(vports
[i
]);
6351 lpfc_mbx_unreg_vpi(vports
[i
]);
6352 shost
= lpfc_shost_from_vport(vports
[i
]);
6353 spin_lock_irq(shost
->host_lock
);
6354 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6355 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6356 spin_unlock_irq(shost
->host_lock
);
6358 lpfc_destroy_vport_work_array(phba
, vports
);
6359 if (i
== 0 && (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))) {
6360 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6362 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
6363 lpfc_cleanup_pending_mbox(phba
->pport
);
6364 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6365 lpfc_sli4_unreg_all_rpis(phba
->pport
);
6366 lpfc_mbx_unreg_vpi(phba
->pport
);
6367 shost
= lpfc_shost_from_vport(phba
->pport
);
6368 spin_lock_irq(shost
->host_lock
);
6369 phba
->pport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
6370 phba
->pport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
6371 spin_unlock_irq(shost
->host_lock
);
6374 /* Cleanup any outstanding ELS commands */
6375 lpfc_els_flush_all_cmd(phba
);
6377 /* Unregister the physical port VFI */
6378 rc
= lpfc_issue_unreg_vfi(phba
->pport
);
6383 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6384 * @phba: Pointer to hba context object.
6386 * This function issues synchronous unregister FCF mailbox command to HBA to
6387 * unregister the currently registered FCF record. The driver does not reset
6388 * the driver FCF usage state flags.
6390 * Return 0 if successfully issued, none-zero otherwise.
6393 lpfc_sli4_unregister_fcf(struct lpfc_hba
*phba
)
6398 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6400 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6401 "2551 UNREG_FCFI mbox allocation failed"
6402 "HBA state x%x\n", phba
->pport
->port_state
);
6405 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
6406 mbox
->vport
= phba
->pport
;
6407 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
6408 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
6410 if (rc
== MBX_NOT_FINISHED
) {
6411 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6412 "2552 Unregister FCFI command failed rc x%x "
6414 rc
, phba
->pport
->port_state
);
6421 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6422 * @phba: Pointer to hba context object.
6424 * This function unregisters the currently reigstered FCF. This function
6425 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6428 lpfc_unregister_fcf_rescan(struct lpfc_hba
*phba
)
6432 /* Preparation for unregistering fcf */
6433 rc
= lpfc_unregister_fcf_prep(phba
);
6435 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
6436 "2748 Failed to prepare for unregistering "
6437 "HBA's FCF record: rc=%d\n", rc
);
6441 /* Now, unregister FCF record and reset HBA FCF state */
6442 rc
= lpfc_sli4_unregister_fcf(phba
);
6445 /* Reset HBA FCF states after successful unregister FCF */
6446 phba
->fcf
.fcf_flag
= 0;
6447 phba
->fcf
.current_rec
.flag
= 0;
6450 * If driver is not unloading, check if there is any other
6451 * FCF record that can be used for discovery.
6453 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
6454 (phba
->link_state
< LPFC_LINK_UP
))
6457 /* This is considered as the initial FCF discovery scan */
6458 spin_lock_irq(&phba
->hbalock
);
6459 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
6460 spin_unlock_irq(&phba
->hbalock
);
6462 /* Reset FCF roundrobin bmask for new discovery */
6463 lpfc_sli4_clear_fcf_rr_bmask(phba
);
6465 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
6468 spin_lock_irq(&phba
->hbalock
);
6469 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
6470 spin_unlock_irq(&phba
->hbalock
);
6471 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
6472 "2553 lpfc_unregister_unused_fcf failed "
6473 "to read FCF record HBA state x%x\n",
6474 phba
->pport
->port_state
);
6479 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6480 * @phba: Pointer to hba context object.
6482 * This function just unregisters the currently reigstered FCF. It does not
6483 * try to find another FCF for discovery.
6486 lpfc_unregister_fcf(struct lpfc_hba
*phba
)
6490 /* Preparation for unregistering fcf */
6491 rc
= lpfc_unregister_fcf_prep(phba
);
6493 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
6494 "2749 Failed to prepare for unregistering "
6495 "HBA's FCF record: rc=%d\n", rc
);
6499 /* Now, unregister FCF record and reset HBA FCF state */
6500 rc
= lpfc_sli4_unregister_fcf(phba
);
6503 /* Set proper HBA FCF states after successful unregister FCF */
6504 spin_lock_irq(&phba
->hbalock
);
6505 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
6506 spin_unlock_irq(&phba
->hbalock
);
6510 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6511 * @phba: Pointer to hba context object.
6513 * This function check if there are any connected remote port for the FCF and
6514 * if all the devices are disconnected, this function unregister FCFI.
6515 * This function also tries to use another FCF for discovery.
6518 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
6521 * If HBA is not running in FIP mode, if HBA does not support
6522 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6523 * registered, do nothing.
6525 spin_lock_irq(&phba
->hbalock
);
6526 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) ||
6527 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
6528 !(phba
->hba_flag
& HBA_FIP_SUPPORT
) ||
6529 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) ||
6530 (phba
->pport
->port_state
== LPFC_FLOGI
)) {
6531 spin_unlock_irq(&phba
->hbalock
);
6534 spin_unlock_irq(&phba
->hbalock
);
6536 if (lpfc_fcf_inuse(phba
))
6539 lpfc_unregister_fcf_rescan(phba
);
6543 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6544 * @phba: Pointer to hba context object.
6545 * @buff: Buffer containing the FCF connection table as in the config
6547 * This function create driver data structure for the FCF connection
6548 * record table read from config region 23.
6551 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
6554 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
6555 struct lpfc_fcf_conn_hdr
*conn_hdr
;
6556 struct lpfc_fcf_conn_rec
*conn_rec
;
6557 uint32_t record_count
;
6560 /* Free the current connect table */
6561 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
6562 &phba
->fcf_conn_rec_list
, list
) {
6563 list_del_init(&conn_entry
->list
);
6567 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
6568 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
6569 sizeof(struct lpfc_fcf_conn_rec
);
6571 conn_rec
= (struct lpfc_fcf_conn_rec
*)
6572 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
6574 for (i
= 0; i
< record_count
; i
++) {
6575 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
6577 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
6580 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6581 "2566 Failed to allocate connection"
6586 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
6587 sizeof(struct lpfc_fcf_conn_rec
));
6588 list_add_tail(&conn_entry
->list
,
6589 &phba
->fcf_conn_rec_list
);
6592 if (!list_empty(&phba
->fcf_conn_rec_list
)) {
6594 list_for_each_entry(conn_entry
, &phba
->fcf_conn_rec_list
,
6596 conn_rec
= &conn_entry
->conn_rec
;
6597 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6598 "3345 FCF connection list rec[%02d]: "
6599 "flags:x%04x, vtag:x%04x, "
6600 "fabric_name:x%02x:%02x:%02x:%02x:"
6601 "%02x:%02x:%02x:%02x, "
6602 "switch_name:x%02x:%02x:%02x:%02x:"
6603 "%02x:%02x:%02x:%02x\n", i
++,
6604 conn_rec
->flags
, conn_rec
->vlan_tag
,
6605 conn_rec
->fabric_name
[0],
6606 conn_rec
->fabric_name
[1],
6607 conn_rec
->fabric_name
[2],
6608 conn_rec
->fabric_name
[3],
6609 conn_rec
->fabric_name
[4],
6610 conn_rec
->fabric_name
[5],
6611 conn_rec
->fabric_name
[6],
6612 conn_rec
->fabric_name
[7],
6613 conn_rec
->switch_name
[0],
6614 conn_rec
->switch_name
[1],
6615 conn_rec
->switch_name
[2],
6616 conn_rec
->switch_name
[3],
6617 conn_rec
->switch_name
[4],
6618 conn_rec
->switch_name
[5],
6619 conn_rec
->switch_name
[6],
6620 conn_rec
->switch_name
[7]);
6626 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6627 * @phba: Pointer to hba context object.
6628 * @buff: Buffer containing the FCoE parameter data structure.
6630 * This function update driver data structure with config
6631 * parameters read from config region 23.
6634 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
6637 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
6638 struct lpfc_fcoe_params
*fcoe_param
;
6640 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
6642 fcoe_param
= (struct lpfc_fcoe_params
*)
6643 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
6645 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
6646 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
6649 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
6650 phba
->valid_vlan
= 1;
6651 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
6655 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
6656 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
6657 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
6662 * lpfc_get_rec_conf23 - Get a record type in config region data.
6663 * @buff: Buffer containing config region 23 data.
6664 * @size: Size of the data buffer.
6665 * @rec_type: Record type to be searched.
6667 * This function searches config region data to find the beginning
6668 * of the record specified by record_type. If record found, this
6669 * function return pointer to the record else return NULL.
6672 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
6674 uint32_t offset
= 0, rec_length
;
6676 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
6677 (size
< sizeof(uint32_t)))
6680 rec_length
= buff
[offset
+ 1];
6683 * One TLV record has one word header and number of data words
6684 * specified in the rec_length field of the record header.
6686 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
6688 if (buff
[offset
] == rec_type
)
6689 return &buff
[offset
];
6691 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
6694 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
6695 rec_length
= buff
[offset
+ 1];
6701 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6702 * @phba: Pointer to lpfc_hba data structure.
6703 * @buff: Buffer containing config region 23 data.
6704 * @size: Size of the data buffer.
6706 * This function parses the FCoE config parameters in config region 23 and
6707 * populate driver data structure with the parameters.
6710 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
6714 uint32_t offset
= 0;
6718 * If data size is less than 2 words signature and version cannot be
6721 if (size
< 2*sizeof(uint32_t))
6724 /* Check the region signature first */
6725 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
6726 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6727 "2567 Config region 23 has bad signature\n");
6733 /* Check the data structure version */
6734 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
6735 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6736 "2568 Config region 23 has bad version\n");
6741 /* Read FCoE param record */
6742 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6743 size
- offset
, FCOE_PARAM_TYPE
);
6745 lpfc_read_fcoe_param(phba
, rec_ptr
);
6747 /* Read FCF connection table */
6748 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
6749 size
- offset
, FCOE_CONN_TBL_TYPE
);
6751 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);