1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/kthread.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_disc.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 /* AlpaArray for assignment of scsid for scan-down and bind_method */
48 static uint8_t lpfcAlpaArray
[] = {
49 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
50 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
51 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
52 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
53 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
54 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
55 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
56 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
57 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
58 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
59 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
60 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
61 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
64 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
65 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
66 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
67 static int lpfc_fcf_inuse(struct lpfc_hba
*);
70 lpfc_terminate_rport_io(struct fc_rport
*rport
)
72 struct lpfc_rport_data
*rdata
;
73 struct lpfc_nodelist
* ndlp
;
74 struct lpfc_hba
*phba
;
76 rdata
= rport
->dd_data
;
79 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
80 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
81 printk(KERN_ERR
"Cannot find remote node"
82 " to terminate I/O Data x%x\n",
89 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
90 "rport terminate: sid:x%x did:x%x flg:x%x",
91 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
93 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
94 lpfc_sli_abort_iocb(ndlp
->vport
,
95 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
96 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
101 * This function will be called when dev_loss_tmo fire.
104 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
106 struct lpfc_rport_data
*rdata
;
107 struct lpfc_nodelist
* ndlp
;
108 struct lpfc_vport
*vport
;
109 struct lpfc_hba
*phba
;
110 struct lpfc_work_evt
*evtp
;
114 rdata
= rport
->dd_data
;
116 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
122 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
123 "rport devlosscb: sid:x%x did:x%x flg:x%x",
124 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
126 /* Don't defer this if we are in the process of deleting the vport
127 * or unloading the driver. The unload will cleanup the node
128 * appropriately we just need to cleanup the ndlp rport info here.
130 if (vport
->load_flag
& FC_UNLOADING
) {
131 put_node
= rdata
->pnode
!= NULL
;
132 put_rport
= ndlp
->rport
!= NULL
;
138 put_device(&rport
->dev
);
142 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
145 evtp
= &ndlp
->dev_loss_evt
;
147 if (!list_empty(&evtp
->evt_listp
))
150 spin_lock_irq(&phba
->hbalock
);
151 /* We need to hold the node by incrementing the reference
152 * count until this queued work is done
154 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
155 if (evtp
->evt_arg1
) {
156 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
157 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
158 lpfc_worker_wake_up(phba
);
160 spin_unlock_irq(&phba
->hbalock
);
166 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
167 * @ndlp: Pointer to remote node object.
169 * This function is called from the worker thread when devloss timeout timer
170 * expires. For SLI4 host, this routine shall return 1 when at lease one
171 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
172 * routine shall return 0 when there is no remote node is still in use of FCF
173 * when devloss timeout happened to this @ndlp.
176 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
178 struct lpfc_rport_data
*rdata
;
179 struct fc_rport
*rport
;
180 struct lpfc_vport
*vport
;
181 struct lpfc_hba
*phba
;
193 rdata
= rport
->dd_data
;
194 name
= (uint8_t *) &ndlp
->nlp_portname
;
198 if (phba
->sli_rev
== LPFC_SLI_REV4
)
199 fcf_inuse
= lpfc_fcf_inuse(phba
);
201 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
202 "rport devlosstmo:did:x%x type:x%x id:x%x",
203 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
205 /* Don't defer this if we are in the process of deleting the vport
206 * or unloading the driver. The unload will cleanup the node
207 * appropriately we just need to cleanup the ndlp rport info here.
209 if (vport
->load_flag
& FC_UNLOADING
) {
210 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
211 /* flush the target */
212 lpfc_sli_abort_iocb(vport
,
213 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
214 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
216 put_node
= rdata
->pnode
!= NULL
;
217 put_rport
= ndlp
->rport
!= NULL
;
223 put_device(&rport
->dev
);
227 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
228 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
229 "0284 Devloss timeout Ignored on "
230 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
232 *name
, *(name
+1), *(name
+2), *(name
+3),
233 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
238 if (ndlp
->nlp_type
& NLP_FABRIC
) {
239 /* We will clean up these Nodes in linkup */
240 put_node
= rdata
->pnode
!= NULL
;
241 put_rport
= ndlp
->rport
!= NULL
;
247 put_device(&rport
->dev
);
251 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
253 /* flush the target */
254 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
255 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
259 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
260 "0203 Devloss timeout on "
261 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
262 "NPort x%06x Data: x%x x%x x%x\n",
263 *name
, *(name
+1), *(name
+2), *(name
+3),
264 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
265 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
266 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
268 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
269 "0204 Devloss timeout on "
270 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
271 "NPort x%06x Data: x%x x%x x%x\n",
272 *name
, *(name
+1), *(name
+2), *(name
+3),
273 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
274 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
275 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
278 put_node
= rdata
->pnode
!= NULL
;
279 put_rport
= ndlp
->rport
!= NULL
;
285 put_device(&rport
->dev
);
287 if (!(vport
->load_flag
& FC_UNLOADING
) &&
288 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
289 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
290 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
291 (ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) &&
292 (ndlp
->nlp_state
!= NLP_STE_PRLI_ISSUE
))
293 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
299 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
300 * @phba: Pointer to hba context object.
301 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
302 * @nlp_did: remote node identifer with devloss timeout.
304 * This function is called from the worker thread after invoking devloss
305 * timeout handler and releasing the reference count for the ndlp with
306 * which the devloss timeout was handled for SLI4 host. For the devloss
307 * timeout of the last remote node which had been in use of FCF, when this
308 * routine is invoked, it shall be guaranteed that none of the remote are
309 * in-use of FCF. When devloss timeout to the last remote using the FCF,
310 * if the FIP engine is neither in FCF table scan process nor roundrobin
311 * failover process, the in-use FCF shall be unregistered. If the FIP
312 * engine is in FCF discovery process, the devloss timeout state shall
313 * be set for either the FCF table scan process or roundrobin failover
314 * process to unregister the in-use FCF.
317 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba
*phba
, int fcf_inuse
,
320 /* If devloss timeout happened to a remote node when FCF had no
321 * longer been in-use, do nothing.
326 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) && !lpfc_fcf_inuse(phba
)) {
327 spin_lock_irq(&phba
->hbalock
);
328 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
329 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
330 spin_unlock_irq(&phba
->hbalock
);
333 phba
->hba_flag
|= HBA_DEVLOSS_TMO
;
334 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
335 "2847 Last remote node (x%x) using "
336 "FCF devloss tmo\n", nlp_did
);
338 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PROG
) {
339 spin_unlock_irq(&phba
->hbalock
);
340 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
341 "2868 Devloss tmo to FCF rediscovery "
345 if (!(phba
->hba_flag
& (FCF_TS_INPROG
| FCF_RR_INPROG
))) {
346 spin_unlock_irq(&phba
->hbalock
);
347 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
348 "2869 Devloss tmo to idle FIP engine, "
349 "unreg in-use FCF and rescan.\n");
350 /* Unregister in-use FCF and rescan */
351 lpfc_unregister_fcf_rescan(phba
);
354 spin_unlock_irq(&phba
->hbalock
);
355 if (phba
->hba_flag
& FCF_TS_INPROG
)
356 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
357 "2870 FCF table scan in progress\n");
358 if (phba
->hba_flag
& FCF_RR_INPROG
)
359 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
360 "2871 FLOGI roundrobin FCF failover "
363 lpfc_unregister_unused_fcf(phba
);
367 * lpfc_alloc_fast_evt - Allocates data structure for posting event
368 * @phba: Pointer to hba context object.
370 * This function is called from the functions which need to post
371 * events from interrupt context. This function allocates data
372 * structure required for posting event. It also keeps track of
373 * number of events pending and prevent event storm when there are
376 struct lpfc_fast_path_event
*
377 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
378 struct lpfc_fast_path_event
*ret
;
380 /* If there are lot of fast event do not exhaust memory due to this */
381 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
384 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
387 atomic_inc(&phba
->fast_event_count
);
388 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
389 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
395 * lpfc_free_fast_evt - Frees event data structure
396 * @phba: Pointer to hba context object.
397 * @evt: Event object which need to be freed.
399 * This function frees the data structure required for posting
403 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
404 struct lpfc_fast_path_event
*evt
) {
406 atomic_dec(&phba
->fast_event_count
);
411 * lpfc_send_fastpath_evt - Posts events generated from fast path
412 * @phba: Pointer to hba context object.
413 * @evtp: Event data structure.
415 * This function is called from worker thread, when the interrupt
416 * context need to post an event. This function posts the event
417 * to fc transport netlink interface.
420 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
421 struct lpfc_work_evt
*evtp
)
423 unsigned long evt_category
, evt_sub_category
;
424 struct lpfc_fast_path_event
*fast_evt_data
;
426 uint32_t evt_data_size
;
427 struct Scsi_Host
*shost
;
429 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
432 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
433 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
434 fabric_evt
.subcategory
;
435 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
436 if (evt_category
== FC_REG_FABRIC_EVENT
) {
437 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
438 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
439 evt_data_size
= sizeof(fast_evt_data
->un
.
441 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
442 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
443 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
444 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
446 lpfc_free_fast_evt(phba
, fast_evt_data
);
449 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
450 switch (evt_sub_category
) {
451 case LPFC_EVENT_QFULL
:
452 case LPFC_EVENT_DEVBSY
:
453 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
454 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
456 case LPFC_EVENT_CHECK_COND
:
457 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
458 evt_data_size
= sizeof(fast_evt_data
->un
.
461 case LPFC_EVENT_VARQUEDEPTH
:
462 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
463 evt_data_size
= sizeof(fast_evt_data
->un
.
467 lpfc_free_fast_evt(phba
, fast_evt_data
);
471 lpfc_free_fast_evt(phba
, fast_evt_data
);
475 fc_host_post_vendor_event(shost
,
476 fc_get_event_number(),
481 lpfc_free_fast_evt(phba
, fast_evt_data
);
486 lpfc_work_list_done(struct lpfc_hba
*phba
)
488 struct lpfc_work_evt
*evtp
= NULL
;
489 struct lpfc_nodelist
*ndlp
;
494 spin_lock_irq(&phba
->hbalock
);
495 while (!list_empty(&phba
->work_list
)) {
496 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
498 spin_unlock_irq(&phba
->hbalock
);
501 case LPFC_EVT_ELS_RETRY
:
502 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
503 lpfc_els_retry_delay_handler(ndlp
);
504 free_evt
= 0; /* evt is part of ndlp */
505 /* decrement the node reference count held
506 * for this queued work
510 case LPFC_EVT_DEV_LOSS
:
511 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
512 fcf_inuse
= lpfc_dev_loss_tmo_handler(ndlp
);
514 /* decrement the node reference count held for
517 nlp_did
= ndlp
->nlp_DID
;
519 if (phba
->sli_rev
== LPFC_SLI_REV4
)
520 lpfc_sli4_post_dev_loss_tmo_handler(phba
,
524 case LPFC_EVT_ONLINE
:
525 if (phba
->link_state
< LPFC_LINK_DOWN
)
526 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
528 *(int *) (evtp
->evt_arg1
) = 0;
529 complete((struct completion
*)(evtp
->evt_arg2
));
531 case LPFC_EVT_OFFLINE_PREP
:
532 if (phba
->link_state
>= LPFC_LINK_DOWN
)
533 lpfc_offline_prep(phba
);
534 *(int *)(evtp
->evt_arg1
) = 0;
535 complete((struct completion
*)(evtp
->evt_arg2
));
537 case LPFC_EVT_OFFLINE
:
539 lpfc_sli_brdrestart(phba
);
540 *(int *)(evtp
->evt_arg1
) =
541 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
542 lpfc_unblock_mgmt_io(phba
);
543 complete((struct completion
*)(evtp
->evt_arg2
));
545 case LPFC_EVT_WARM_START
:
547 lpfc_reset_barrier(phba
);
548 lpfc_sli_brdreset(phba
);
549 lpfc_hba_down_post(phba
);
550 *(int *)(evtp
->evt_arg1
) =
551 lpfc_sli_brdready(phba
, HS_MBRDY
);
552 lpfc_unblock_mgmt_io(phba
);
553 complete((struct completion
*)(evtp
->evt_arg2
));
557 *(int *)(evtp
->evt_arg1
)
558 = (phba
->pport
->stopped
)
559 ? 0 : lpfc_sli_brdkill(phba
);
560 lpfc_unblock_mgmt_io(phba
);
561 complete((struct completion
*)(evtp
->evt_arg2
));
563 case LPFC_EVT_FASTPATH_MGMT_EVT
:
564 lpfc_send_fastpath_evt(phba
, evtp
);
567 case LPFC_EVT_RESET_HBA
:
568 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
569 lpfc_reset_hba(phba
);
574 spin_lock_irq(&phba
->hbalock
);
576 spin_unlock_irq(&phba
->hbalock
);
581 lpfc_work_done(struct lpfc_hba
*phba
)
583 struct lpfc_sli_ring
*pring
;
584 uint32_t ha_copy
, status
, control
, work_port_events
;
585 struct lpfc_vport
**vports
;
586 struct lpfc_vport
*vport
;
589 spin_lock_irq(&phba
->hbalock
);
590 ha_copy
= phba
->work_ha
;
592 spin_unlock_irq(&phba
->hbalock
);
594 /* First, try to post the next mailbox command to SLI4 device */
595 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
596 lpfc_sli4_post_async_mbox(phba
);
598 if (ha_copy
& HA_ERATT
)
599 /* Handle the error attention event */
600 lpfc_handle_eratt(phba
);
602 if (ha_copy
& HA_MBATT
)
603 lpfc_sli_handle_mb_event(phba
);
605 if (ha_copy
& HA_LATT
)
606 lpfc_handle_latt(phba
);
608 /* Process SLI4 events */
609 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
610 if (phba
->hba_flag
& FCP_XRI_ABORT_EVENT
)
611 lpfc_sli4_fcp_xri_abort_event_proc(phba
);
612 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
613 lpfc_sli4_els_xri_abort_event_proc(phba
);
614 if (phba
->hba_flag
& ASYNC_EVENT
)
615 lpfc_sli4_async_event_proc(phba
);
616 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
617 spin_lock_irq(&phba
->hbalock
);
618 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
619 spin_unlock_irq(&phba
->hbalock
);
620 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
622 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
)
623 lpfc_sli4_fcf_redisc_event_proc(phba
);
626 vports
= lpfc_create_vport_work_array(phba
);
628 for (i
= 0; i
<= phba
->max_vports
; i
++) {
630 * We could have no vports in array if unloading, so if
631 * this happens then just use the pport
633 if (vports
[i
] == NULL
&& i
== 0)
639 spin_lock_irq(&vport
->work_port_lock
);
640 work_port_events
= vport
->work_port_events
;
641 vport
->work_port_events
&= ~work_port_events
;
642 spin_unlock_irq(&vport
->work_port_lock
);
643 if (work_port_events
& WORKER_DISC_TMO
)
644 lpfc_disc_timeout_handler(vport
);
645 if (work_port_events
& WORKER_ELS_TMO
)
646 lpfc_els_timeout_handler(vport
);
647 if (work_port_events
& WORKER_HB_TMO
)
648 lpfc_hb_timeout_handler(phba
);
649 if (work_port_events
& WORKER_MBOX_TMO
)
650 lpfc_mbox_timeout_handler(phba
);
651 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
652 lpfc_unblock_fabric_iocbs(phba
);
653 if (work_port_events
& WORKER_FDMI_TMO
)
654 lpfc_fdmi_timeout_handler(vport
);
655 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
656 lpfc_ramp_down_queue_handler(phba
);
657 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
658 lpfc_ramp_up_queue_handler(phba
);
660 lpfc_destroy_vport_work_array(phba
, vports
);
662 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
663 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
664 status
>>= (4*LPFC_ELS_RING
);
665 if ((status
& HA_RXMASK
) ||
666 (pring
->flag
& LPFC_DEFERRED_RING_EVENT
) ||
667 (phba
->hba_flag
& HBA_SP_QUEUE_EVT
)) {
668 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
669 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
670 /* Set the lpfc data pending flag */
671 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
673 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
674 lpfc_sli_handle_slow_ring_event(phba
, pring
,
678 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && pring
->txq_cnt
)
679 lpfc_drain_txq(phba
);
681 * Turn on Ring interrupts
683 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
684 spin_lock_irq(&phba
->hbalock
);
685 control
= readl(phba
->HCregaddr
);
686 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
687 lpfc_debugfs_slow_ring_trc(phba
,
688 "WRK Enable ring: cntl:x%x hacopy:x%x",
689 control
, ha_copy
, 0);
691 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
692 writel(control
, phba
->HCregaddr
);
693 readl(phba
->HCregaddr
); /* flush */
695 lpfc_debugfs_slow_ring_trc(phba
,
696 "WRK Ring ok: cntl:x%x hacopy:x%x",
697 control
, ha_copy
, 0);
699 spin_unlock_irq(&phba
->hbalock
);
702 lpfc_work_list_done(phba
);
706 lpfc_do_work(void *p
)
708 struct lpfc_hba
*phba
= p
;
711 set_user_nice(current
, -20);
712 phba
->data_flags
= 0;
714 while (!kthread_should_stop()) {
715 /* wait and check worker queue activities */
716 rc
= wait_event_interruptible(phba
->work_waitq
,
717 (test_and_clear_bit(LPFC_DATA_READY
,
719 || kthread_should_stop()));
720 /* Signal wakeup shall terminate the worker thread */
722 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
723 "0433 Wakeup on signal: rc=x%x\n", rc
);
727 /* Attend pending lpfc data processing */
728 lpfc_work_done(phba
);
730 phba
->worker_thread
= NULL
;
731 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
732 "0432 Worker thread stopped.\n");
737 * This is only called to handle FC worker events. Since this a rare
738 * occurance, we allocate a struct lpfc_work_evt structure here instead of
739 * embedding it in the IOCB.
742 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
745 struct lpfc_work_evt
*evtp
;
749 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
750 * be queued to worker thread for processing
752 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
756 evtp
->evt_arg1
= arg1
;
757 evtp
->evt_arg2
= arg2
;
760 spin_lock_irqsave(&phba
->hbalock
, flags
);
761 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
762 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
764 lpfc_worker_wake_up(phba
);
770 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
772 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
773 struct lpfc_hba
*phba
= vport
->phba
;
774 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
777 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
778 if (!NLP_CHK_NODE_ACT(ndlp
))
780 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
782 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
783 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
784 (ndlp
->nlp_DID
== NameServer_DID
)))
785 lpfc_unreg_rpi(vport
, ndlp
);
787 /* Leave Fabric nodes alone on link down */
788 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
789 (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
))
791 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
794 : NLP_EVT_DEVICE_RECOVERY
);
796 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
797 if (phba
->sli_rev
== LPFC_SLI_REV4
)
798 lpfc_sli4_unreg_all_rpis(vport
);
799 lpfc_mbx_unreg_vpi(vport
);
800 spin_lock_irq(shost
->host_lock
);
801 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
802 spin_unlock_irq(shost
->host_lock
);
807 lpfc_port_link_failure(struct lpfc_vport
*vport
)
809 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
811 /* Cleanup any outstanding received buffers */
812 lpfc_cleanup_rcv_buffers(vport
);
814 /* Cleanup any outstanding RSCN activity */
815 lpfc_els_flush_rscn(vport
);
817 /* Cleanup any outstanding ELS commands */
818 lpfc_els_flush_cmd(vport
);
820 lpfc_cleanup_rpis(vport
, 0);
822 /* Turn off discovery timer if its running */
823 lpfc_can_disctmo(vport
);
827 lpfc_linkdown_port(struct lpfc_vport
*vport
)
829 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
831 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
833 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
834 "Link Down: state:x%x rtry:x%x flg:x%x",
835 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
837 lpfc_port_link_failure(vport
);
842 lpfc_linkdown(struct lpfc_hba
*phba
)
844 struct lpfc_vport
*vport
= phba
->pport
;
845 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
846 struct lpfc_vport
**vports
;
850 if (phba
->link_state
== LPFC_LINK_DOWN
)
853 /* Block all SCSI stack I/Os */
854 lpfc_scsi_dev_block(phba
);
856 spin_lock_irq(&phba
->hbalock
);
857 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
858 spin_unlock_irq(&phba
->hbalock
);
859 if (phba
->link_state
> LPFC_LINK_DOWN
) {
860 phba
->link_state
= LPFC_LINK_DOWN
;
861 spin_lock_irq(shost
->host_lock
);
862 phba
->pport
->fc_flag
&= ~FC_LBIT
;
863 spin_unlock_irq(shost
->host_lock
);
865 vports
= lpfc_create_vport_work_array(phba
);
867 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
868 /* Issue a LINK DOWN event to all nodes */
869 lpfc_linkdown_port(vports
[i
]);
871 lpfc_destroy_vport_work_array(phba
, vports
);
872 /* Clean up any firmware default rpi's */
873 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
875 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
877 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
878 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
879 == MBX_NOT_FINISHED
) {
880 mempool_free(mb
, phba
->mbox_mem_pool
);
884 /* Setup myDID for link up if we are in pt2pt mode */
885 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
886 phba
->pport
->fc_myDID
= 0;
887 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
889 lpfc_config_link(phba
, mb
);
890 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
892 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
893 == MBX_NOT_FINISHED
) {
894 mempool_free(mb
, phba
->mbox_mem_pool
);
897 spin_lock_irq(shost
->host_lock
);
898 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
899 spin_unlock_irq(shost
->host_lock
);
906 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
908 struct lpfc_nodelist
*ndlp
;
910 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
911 if (!NLP_CHK_NODE_ACT(ndlp
))
913 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
915 if (ndlp
->nlp_type
& NLP_FABRIC
) {
916 /* On Linkup its safe to clean up the ndlp
917 * from Fabric connections.
919 if (ndlp
->nlp_DID
!= Fabric_DID
)
920 lpfc_unreg_rpi(vport
, ndlp
);
921 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
922 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
923 /* Fail outstanding IO now since device is
926 lpfc_unreg_rpi(vport
, ndlp
);
932 lpfc_linkup_port(struct lpfc_vport
*vport
)
934 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
935 struct lpfc_hba
*phba
= vport
->phba
;
937 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
940 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
941 "Link Up: top:x%x speed:x%x flg:x%x",
942 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
944 /* If NPIV is not enabled, only bring the physical port up */
945 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
946 (vport
!= phba
->pport
))
949 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
951 spin_lock_irq(shost
->host_lock
);
952 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
953 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
954 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
955 vport
->fc_ns_retry
= 0;
956 spin_unlock_irq(shost
->host_lock
);
958 if (vport
->fc_flag
& FC_LBIT
)
959 lpfc_linkup_cleanup_nodes(vport
);
964 lpfc_linkup(struct lpfc_hba
*phba
)
966 struct lpfc_vport
**vports
;
969 phba
->link_state
= LPFC_LINK_UP
;
971 /* Unblock fabric iocbs if they are blocked */
972 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
973 del_timer_sync(&phba
->fabric_block_timer
);
975 vports
= lpfc_create_vport_work_array(phba
);
977 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
978 lpfc_linkup_port(vports
[i
]);
979 lpfc_destroy_vport_work_array(phba
, vports
);
980 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
981 (phba
->sli_rev
< LPFC_SLI_REV4
))
982 lpfc_issue_clear_la(phba
, phba
->pport
);
988 * This routine handles processing a CLEAR_LA mailbox
989 * command upon completion. It is setup in the LPFC_MBOXQ
990 * as the completion routine when the command is
991 * handed off to the SLI layer.
994 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
996 struct lpfc_vport
*vport
= pmb
->vport
;
997 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
998 struct lpfc_sli
*psli
= &phba
->sli
;
999 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1002 /* Since we don't do discovery right now, turn these off here */
1003 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1004 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1005 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1007 /* Check for error */
1008 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
1009 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1010 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1011 "0320 CLEAR_LA mbxStatus error x%x hba "
1013 mb
->mbxStatus
, vport
->port_state
);
1014 phba
->link_state
= LPFC_HBA_ERROR
;
1018 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1019 phba
->link_state
= LPFC_HBA_READY
;
1021 spin_lock_irq(&phba
->hbalock
);
1022 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1023 control
= readl(phba
->HCregaddr
);
1024 control
|= HC_LAINT_ENA
;
1025 writel(control
, phba
->HCregaddr
);
1026 readl(phba
->HCregaddr
); /* flush */
1027 spin_unlock_irq(&phba
->hbalock
);
1028 mempool_free(pmb
, phba
->mbox_mem_pool
);
1032 /* Device Discovery completes */
1033 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1034 "0225 Device Discovery completes\n");
1035 mempool_free(pmb
, phba
->mbox_mem_pool
);
1037 spin_lock_irq(shost
->host_lock
);
1038 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
1039 spin_unlock_irq(shost
->host_lock
);
1041 lpfc_can_disctmo(vport
);
1043 /* turn on Link Attention interrupts */
1045 spin_lock_irq(&phba
->hbalock
);
1046 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1047 control
= readl(phba
->HCregaddr
);
1048 control
|= HC_LAINT_ENA
;
1049 writel(control
, phba
->HCregaddr
);
1050 readl(phba
->HCregaddr
); /* flush */
1051 spin_unlock_irq(&phba
->hbalock
);
1058 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1060 struct lpfc_vport
*vport
= pmb
->vport
;
1062 if (pmb
->u
.mb
.mbxStatus
)
1065 mempool_free(pmb
, phba
->mbox_mem_pool
);
1067 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
&&
1068 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
1069 !(vport
->fc_flag
& FC_LBIT
)) {
1070 /* Need to wait for FAN - use discovery timer
1071 * for timeout. port_state is identically
1072 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1074 lpfc_set_disctmo(vport
);
1078 /* Start discovery by sending a FLOGI. port_state is identically
1079 * LPFC_FLOGI while waiting for FLOGI cmpl
1081 if (vport
->port_state
!= LPFC_FLOGI
)
1082 lpfc_initial_flogi(vport
);
1086 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1087 "0306 CONFIG_LINK mbxStatus error x%x "
1089 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
1090 mempool_free(pmb
, phba
->mbox_mem_pool
);
1092 lpfc_linkdown(phba
);
1094 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1095 "0200 CONFIG_LINK bad hba state x%x\n",
1098 lpfc_issue_clear_la(phba
, vport
);
1103 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1105 struct lpfc_vport
*vport
= mboxq
->vport
;
1107 if (mboxq
->u
.mb
.mbxStatus
) {
1108 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1109 "2017 REG_FCFI mbxStatus error x%x "
1111 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1115 /* Start FCoE discovery by sending a FLOGI. */
1116 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1117 /* Set the FCFI registered flag */
1118 spin_lock_irq(&phba
->hbalock
);
1119 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1120 spin_unlock_irq(&phba
->hbalock
);
1122 /* If there is a pending FCoE event, restart FCF table scan. */
1123 if (lpfc_check_pending_fcoe_event(phba
, LPFC_UNREG_FCF
))
1126 /* Mark successful completion of FCF table scan */
1127 spin_lock_irq(&phba
->hbalock
);
1128 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1129 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1130 if (vport
->port_state
!= LPFC_FLOGI
) {
1131 phba
->hba_flag
|= FCF_RR_INPROG
;
1132 spin_unlock_irq(&phba
->hbalock
);
1133 lpfc_issue_init_vfi(vport
);
1136 spin_unlock_irq(&phba
->hbalock
);
1140 spin_lock_irq(&phba
->hbalock
);
1141 phba
->hba_flag
&= ~FCF_RR_INPROG
;
1142 spin_unlock_irq(&phba
->hbalock
);
1144 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1148 * lpfc_fab_name_match - Check if the fcf fabric name match.
1149 * @fab_name: pointer to fabric name.
1150 * @new_fcf_record: pointer to fcf record.
1152 * This routine compare the fcf record's fabric name with provided
1153 * fabric name. If the fabric name are identical this function
1154 * returns 1 else return 0.
1157 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1159 if (fab_name
[0] != bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
))
1161 if (fab_name
[1] != bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
))
1163 if (fab_name
[2] != bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
))
1165 if (fab_name
[3] != bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
))
1167 if (fab_name
[4] != bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
))
1169 if (fab_name
[5] != bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
))
1171 if (fab_name
[6] != bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
))
1173 if (fab_name
[7] != bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
))
1179 * lpfc_sw_name_match - Check if the fcf switch name match.
1180 * @fab_name: pointer to fabric name.
1181 * @new_fcf_record: pointer to fcf record.
1183 * This routine compare the fcf record's switch name with provided
1184 * switch name. If the switch name are identical this function
1185 * returns 1 else return 0.
1188 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1190 if (sw_name
[0] != bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
))
1192 if (sw_name
[1] != bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
))
1194 if (sw_name
[2] != bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
))
1196 if (sw_name
[3] != bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
))
1198 if (sw_name
[4] != bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
))
1200 if (sw_name
[5] != bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
))
1202 if (sw_name
[6] != bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
))
1204 if (sw_name
[7] != bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
))
1210 * lpfc_mac_addr_match - Check if the fcf mac address match.
1211 * @mac_addr: pointer to mac address.
1212 * @new_fcf_record: pointer to fcf record.
1214 * This routine compare the fcf record's mac address with HBA's
1215 * FCF mac address. If the mac addresses are identical this function
1216 * returns 1 else return 0.
1219 lpfc_mac_addr_match(uint8_t *mac_addr
, struct fcf_record
*new_fcf_record
)
1221 if (mac_addr
[0] != bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
))
1223 if (mac_addr
[1] != bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
))
1225 if (mac_addr
[2] != bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
))
1227 if (mac_addr
[3] != bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
))
1229 if (mac_addr
[4] != bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
))
1231 if (mac_addr
[5] != bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
))
1237 lpfc_vlan_id_match(uint16_t curr_vlan_id
, uint16_t new_vlan_id
)
1239 return (curr_vlan_id
== new_vlan_id
);
1243 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1244 * @fcf: pointer to driver fcf record.
1245 * @new_fcf_record: pointer to fcf record.
1247 * This routine copies the FCF information from the FCF
1248 * record to lpfc_hba data structure.
1251 lpfc_copy_fcf_record(struct lpfc_fcf_rec
*fcf_rec
,
1252 struct fcf_record
*new_fcf_record
)
1255 fcf_rec
->fabric_name
[0] =
1256 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1257 fcf_rec
->fabric_name
[1] =
1258 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1259 fcf_rec
->fabric_name
[2] =
1260 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1261 fcf_rec
->fabric_name
[3] =
1262 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1263 fcf_rec
->fabric_name
[4] =
1264 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1265 fcf_rec
->fabric_name
[5] =
1266 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1267 fcf_rec
->fabric_name
[6] =
1268 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1269 fcf_rec
->fabric_name
[7] =
1270 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1272 fcf_rec
->mac_addr
[0] = bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1273 fcf_rec
->mac_addr
[1] = bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1274 fcf_rec
->mac_addr
[2] = bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1275 fcf_rec
->mac_addr
[3] = bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1276 fcf_rec
->mac_addr
[4] = bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1277 fcf_rec
->mac_addr
[5] = bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1278 /* FCF record index */
1279 fcf_rec
->fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1280 /* FCF record priority */
1281 fcf_rec
->priority
= new_fcf_record
->fip_priority
;
1283 fcf_rec
->switch_name
[0] =
1284 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1285 fcf_rec
->switch_name
[1] =
1286 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1287 fcf_rec
->switch_name
[2] =
1288 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1289 fcf_rec
->switch_name
[3] =
1290 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1291 fcf_rec
->switch_name
[4] =
1292 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1293 fcf_rec
->switch_name
[5] =
1294 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1295 fcf_rec
->switch_name
[6] =
1296 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1297 fcf_rec
->switch_name
[7] =
1298 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1302 * lpfc_update_fcf_record - Update driver fcf record
1303 * @phba: pointer to lpfc hba data structure.
1304 * @fcf_rec: pointer to driver fcf record.
1305 * @new_fcf_record: pointer to hba fcf record.
1306 * @addr_mode: address mode to be set to the driver fcf record.
1307 * @vlan_id: vlan tag to be set to the driver fcf record.
1308 * @flag: flag bits to be set to the driver fcf record.
1310 * This routine updates the driver FCF record from the new HBA FCF record
1311 * together with the address mode, vlan_id, and other informations. This
1312 * routine is called with the host lock held.
1315 __lpfc_update_fcf_record(struct lpfc_hba
*phba
, struct lpfc_fcf_rec
*fcf_rec
,
1316 struct fcf_record
*new_fcf_record
, uint32_t addr_mode
,
1317 uint16_t vlan_id
, uint32_t flag
)
1319 /* Copy the fields from the HBA's FCF record */
1320 lpfc_copy_fcf_record(fcf_rec
, new_fcf_record
);
1321 /* Update other fields of driver FCF record */
1322 fcf_rec
->addr_mode
= addr_mode
;
1323 fcf_rec
->vlan_id
= vlan_id
;
1324 fcf_rec
->flag
|= (flag
| RECORD_VALID
);
1328 * lpfc_register_fcf - Register the FCF with hba.
1329 * @phba: pointer to lpfc hba data structure.
1331 * This routine issues a register fcfi mailbox command to register
1335 lpfc_register_fcf(struct lpfc_hba
*phba
)
1337 LPFC_MBOXQ_t
*fcf_mbxq
;
1340 spin_lock_irq(&phba
->hbalock
);
1341 /* If the FCF is not availabe do nothing. */
1342 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1343 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1344 spin_unlock_irq(&phba
->hbalock
);
1348 /* The FCF is already registered, start discovery */
1349 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1350 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1351 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1352 if (phba
->pport
->port_state
!= LPFC_FLOGI
) {
1353 phba
->hba_flag
|= FCF_RR_INPROG
;
1354 spin_unlock_irq(&phba
->hbalock
);
1355 lpfc_issue_init_vfi(phba
->pport
);
1358 spin_unlock_irq(&phba
->hbalock
);
1361 spin_unlock_irq(&phba
->hbalock
);
1363 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1365 spin_lock_irq(&phba
->hbalock
);
1366 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1367 spin_unlock_irq(&phba
->hbalock
);
1371 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1372 fcf_mbxq
->vport
= phba
->pport
;
1373 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1374 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1375 if (rc
== MBX_NOT_FINISHED
) {
1376 spin_lock_irq(&phba
->hbalock
);
1377 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1378 spin_unlock_irq(&phba
->hbalock
);
1379 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1386 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1387 * @phba: pointer to lpfc hba data structure.
1388 * @new_fcf_record: pointer to fcf record.
1389 * @boot_flag: Indicates if this record used by boot bios.
1390 * @addr_mode: The address mode to be used by this FCF
1391 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1393 * This routine compare the fcf record with connect list obtained from the
1394 * config region to decide if this FCF can be used for SAN discovery. It returns
1395 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1396 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1397 * is used by boot bios and addr_mode will indicate the addressing mode to be
1398 * used for this FCF when the function returns.
1399 * If the FCF record need to be used with a particular vlan id, the vlan is
1400 * set in the vlan_id on return of the function. If not VLAN tagging need to
1401 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1404 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1405 struct fcf_record
*new_fcf_record
,
1406 uint32_t *boot_flag
, uint32_t *addr_mode
,
1409 struct lpfc_fcf_conn_entry
*conn_entry
;
1410 int i
, j
, fcf_vlan_id
= 0;
1412 /* Find the lowest VLAN id in the FCF record */
1413 for (i
= 0; i
< 512; i
++) {
1414 if (new_fcf_record
->vlan_bitmap
[i
]) {
1415 fcf_vlan_id
= i
* 8;
1417 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1425 /* If FCF not available return 0 */
1426 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1427 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
))
1430 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1432 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1434 if (phba
->valid_vlan
)
1435 *vlan_id
= phba
->vlan_id
;
1437 *vlan_id
= LPFC_FCOE_NULL_VID
;
1442 * If there are no FCF connection table entry, driver connect to all
1445 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1447 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1451 * When there are no FCF connect entries, use driver's default
1452 * addressing mode - FPMA.
1454 if (*addr_mode
& LPFC_FCF_FPMA
)
1455 *addr_mode
= LPFC_FCF_FPMA
;
1457 /* If FCF record report a vlan id use that vlan id */
1459 *vlan_id
= fcf_vlan_id
;
1461 *vlan_id
= LPFC_FCOE_NULL_VID
;
1465 list_for_each_entry(conn_entry
,
1466 &phba
->fcf_conn_rec_list
, list
) {
1467 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1470 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1471 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1474 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1475 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1478 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1480 * If the vlan bit map does not have the bit set for the
1481 * vlan id to be used, then it is not a match.
1483 if (!(new_fcf_record
->vlan_bitmap
1484 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1485 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1490 * If connection record does not support any addressing mode,
1491 * skip the FCF record.
1493 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1494 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1498 * Check if the connection record specifies a required
1501 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1502 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1505 * If SPMA required but FCF not support this continue.
1507 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1508 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1509 new_fcf_record
) & LPFC_FCF_SPMA
))
1513 * If FPMA required but FCF not support this continue.
1515 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1516 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1517 new_fcf_record
) & LPFC_FCF_FPMA
))
1522 * This fcf record matches filtering criteria.
1524 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1530 * If user did not specify any addressing mode, or if the
1531 * prefered addressing mode specified by user is not supported
1532 * by FCF, allow fabric to pick the addressing mode.
1534 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1537 * If the user specified a required address mode, assign that
1540 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1541 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1542 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1544 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1546 * If the user specified a prefered address mode, use the
1547 * addr mode only if FCF support the addr_mode.
1549 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1550 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1551 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1552 (*addr_mode
& LPFC_FCF_SPMA
))
1553 *addr_mode
= LPFC_FCF_SPMA
;
1554 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1555 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1556 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1557 (*addr_mode
& LPFC_FCF_FPMA
))
1558 *addr_mode
= LPFC_FCF_FPMA
;
1560 /* If matching connect list has a vlan id, use it */
1561 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1562 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1564 * If no vlan id is specified in connect list, use the vlan id
1567 else if (fcf_vlan_id
)
1568 *vlan_id
= fcf_vlan_id
;
1570 *vlan_id
= LPFC_FCOE_NULL_VID
;
1579 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1580 * @phba: pointer to lpfc hba data structure.
1581 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1583 * This function check if there is any fcoe event pending while driver
1584 * scan FCF entries. If there is any pending event, it will restart the
1585 * FCF saning and return 1 else return 0.
1588 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1591 * If the Link is up and no FCoE events while in the
1592 * FCF discovery, no need to restart FCF discovery.
1594 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1595 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1598 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1599 "2768 Pending link or FCF event during current "
1600 "handling of the previous event: link_state:x%x, "
1601 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1602 phba
->link_state
, phba
->fcoe_eventtag_at_fcf_scan
,
1603 phba
->fcoe_eventtag
);
1605 spin_lock_irq(&phba
->hbalock
);
1606 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1607 spin_unlock_irq(&phba
->hbalock
);
1609 if (phba
->link_state
>= LPFC_LINK_UP
) {
1610 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1611 "2780 Restart FCF table scan due to "
1612 "pending FCF event:evt_tag_at_scan:x%x, "
1613 "evt_tag_current:x%x\n",
1614 phba
->fcoe_eventtag_at_fcf_scan
,
1615 phba
->fcoe_eventtag
);
1616 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1619 * Do not continue FCF discovery and clear FCF_TS_INPROG
1622 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1623 "2833 Stop FCF discovery process due to link "
1624 "state change (x%x)\n", phba
->link_state
);
1625 spin_lock_irq(&phba
->hbalock
);
1626 phba
->hba_flag
&= ~(FCF_TS_INPROG
| FCF_RR_INPROG
);
1627 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
| FCF_DISCOVERY
);
1628 spin_unlock_irq(&phba
->hbalock
);
1631 /* Unregister the currently registered FCF if required */
1633 spin_lock_irq(&phba
->hbalock
);
1634 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1635 spin_unlock_irq(&phba
->hbalock
);
1636 lpfc_sli4_unregister_fcf(phba
);
1642 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1643 * @phba: pointer to lpfc hba data structure.
1644 * @fcf_cnt: number of eligible fcf record seen so far.
1646 * This function makes an running random selection decision on FCF record to
1647 * use through a sequence of @fcf_cnt eligible FCF records with equal
1648 * probability. To perform integer manunipulation of random numbers with
1649 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1650 * from random32() are taken as the random random number generated.
1652 * Returns true when outcome is for the newly read FCF record should be
1653 * chosen; otherwise, return false when outcome is for keeping the previously
1654 * chosen FCF record.
1657 lpfc_sli4_new_fcf_random_select(struct lpfc_hba
*phba
, uint32_t fcf_cnt
)
1661 /* Get 16-bit uniform random number */
1662 rand_num
= (0xFFFF & random32());
1664 /* Decision with probability 1/fcf_cnt */
1665 if ((fcf_cnt
* rand_num
) < 0xFFFF)
1672 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1673 * @phba: pointer to lpfc hba data structure.
1674 * @mboxq: pointer to mailbox object.
1675 * @next_fcf_index: pointer to holder of next fcf index.
1677 * This routine parses the non-embedded fcf mailbox command by performing the
1678 * necessarily error checking, non-embedded read FCF record mailbox command
1679 * SGE parsing, and endianness swapping.
1681 * Returns the pointer to the new FCF record in the non-embedded mailbox
1682 * command DMA memory if successfully, other NULL.
1684 static struct fcf_record
*
1685 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
1686 uint16_t *next_fcf_index
)
1689 dma_addr_t phys_addr
;
1690 struct lpfc_mbx_sge sge
;
1691 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1692 uint32_t shdr_status
, shdr_add_status
;
1693 union lpfc_sli4_cfg_shdr
*shdr
;
1694 struct fcf_record
*new_fcf_record
;
1696 /* Get the first SGE entry from the non-embedded DMA memory. This
1697 * routine only uses a single SGE.
1699 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1700 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1701 if (unlikely(!mboxq
->sge_array
)) {
1702 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1703 "2524 Failed to get the non-embedded SGE "
1704 "virtual address\n");
1707 virt_addr
= mboxq
->sge_array
->addr
[0];
1709 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1710 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1711 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
1712 if (shdr_status
|| shdr_add_status
) {
1713 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
)
1714 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1715 "2726 READ_FCF_RECORD Indicates empty "
1718 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1719 "2521 READ_FCF_RECORD mailbox failed "
1720 "with status x%x add_status x%x, "
1721 "mbx\n", shdr_status
, shdr_add_status
);
1725 /* Interpreting the returned information of the FCF record */
1726 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1727 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1728 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1729 *next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1730 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1731 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1732 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1733 offsetof(struct fcf_record
, vlan_bitmap
));
1734 new_fcf_record
->word137
= le32_to_cpu(new_fcf_record
->word137
);
1735 new_fcf_record
->word138
= le32_to_cpu(new_fcf_record
->word138
);
1737 return new_fcf_record
;
1741 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1742 * @phba: pointer to lpfc hba data structure.
1743 * @fcf_record: pointer to the fcf record.
1744 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1745 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1747 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1751 lpfc_sli4_log_fcf_record_info(struct lpfc_hba
*phba
,
1752 struct fcf_record
*fcf_record
,
1754 uint16_t next_fcf_index
)
1756 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1757 "2764 READ_FCF_RECORD:\n"
1758 "\tFCF_Index : x%x\n"
1759 "\tFCF_Avail : x%x\n"
1760 "\tFCF_Valid : x%x\n"
1761 "\tFIP_Priority : x%x\n"
1762 "\tMAC_Provider : x%x\n"
1763 "\tLowest VLANID : x%x\n"
1764 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1765 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1766 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1767 "\tNext_FCF_Index: x%x\n",
1768 bf_get(lpfc_fcf_record_fcf_index
, fcf_record
),
1769 bf_get(lpfc_fcf_record_fcf_avail
, fcf_record
),
1770 bf_get(lpfc_fcf_record_fcf_valid
, fcf_record
),
1771 fcf_record
->fip_priority
,
1772 bf_get(lpfc_fcf_record_mac_addr_prov
, fcf_record
),
1774 bf_get(lpfc_fcf_record_mac_0
, fcf_record
),
1775 bf_get(lpfc_fcf_record_mac_1
, fcf_record
),
1776 bf_get(lpfc_fcf_record_mac_2
, fcf_record
),
1777 bf_get(lpfc_fcf_record_mac_3
, fcf_record
),
1778 bf_get(lpfc_fcf_record_mac_4
, fcf_record
),
1779 bf_get(lpfc_fcf_record_mac_5
, fcf_record
),
1780 bf_get(lpfc_fcf_record_fab_name_0
, fcf_record
),
1781 bf_get(lpfc_fcf_record_fab_name_1
, fcf_record
),
1782 bf_get(lpfc_fcf_record_fab_name_2
, fcf_record
),
1783 bf_get(lpfc_fcf_record_fab_name_3
, fcf_record
),
1784 bf_get(lpfc_fcf_record_fab_name_4
, fcf_record
),
1785 bf_get(lpfc_fcf_record_fab_name_5
, fcf_record
),
1786 bf_get(lpfc_fcf_record_fab_name_6
, fcf_record
),
1787 bf_get(lpfc_fcf_record_fab_name_7
, fcf_record
),
1788 bf_get(lpfc_fcf_record_switch_name_0
, fcf_record
),
1789 bf_get(lpfc_fcf_record_switch_name_1
, fcf_record
),
1790 bf_get(lpfc_fcf_record_switch_name_2
, fcf_record
),
1791 bf_get(lpfc_fcf_record_switch_name_3
, fcf_record
),
1792 bf_get(lpfc_fcf_record_switch_name_4
, fcf_record
),
1793 bf_get(lpfc_fcf_record_switch_name_5
, fcf_record
),
1794 bf_get(lpfc_fcf_record_switch_name_6
, fcf_record
),
1795 bf_get(lpfc_fcf_record_switch_name_7
, fcf_record
),
1800 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1801 * @phba: pointer to lpfc hba data structure.
1802 * @fcf_rec: pointer to an existing FCF record.
1803 * @new_fcf_record: pointer to a new FCF record.
1804 * @new_vlan_id: vlan id from the new FCF record.
1806 * This function performs matching test of a new FCF record against an existing
1807 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1808 * will not be used as part of the FCF record matching criteria.
1810 * Returns true if all the fields matching, otherwise returns false.
1813 lpfc_sli4_fcf_record_match(struct lpfc_hba
*phba
,
1814 struct lpfc_fcf_rec
*fcf_rec
,
1815 struct fcf_record
*new_fcf_record
,
1816 uint16_t new_vlan_id
)
1818 if (new_vlan_id
!= LPFC_FCOE_IGNORE_VID
)
1819 if (!lpfc_vlan_id_match(fcf_rec
->vlan_id
, new_vlan_id
))
1821 if (!lpfc_mac_addr_match(fcf_rec
->mac_addr
, new_fcf_record
))
1823 if (!lpfc_sw_name_match(fcf_rec
->switch_name
, new_fcf_record
))
1825 if (!lpfc_fab_name_match(fcf_rec
->fabric_name
, new_fcf_record
))
1831 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1832 * @vport: Pointer to vport object.
1833 * @fcf_index: index to next fcf.
1835 * This function processing the roundrobin fcf failover to next fcf index.
1836 * When this function is invoked, there will be a current fcf registered
1838 * Return: 0 for continue retrying flogi on currently registered fcf;
1839 * 1 for stop flogi on currently registered fcf;
1841 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport
*vport
, uint16_t fcf_index
)
1843 struct lpfc_hba
*phba
= vport
->phba
;
1846 if (fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
) {
1847 spin_lock_irq(&phba
->hbalock
);
1848 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
1849 spin_unlock_irq(&phba
->hbalock
);
1850 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1851 "2872 Devloss tmo with no eligible "
1852 "FCF, unregister in-use FCF (x%x) "
1853 "and rescan FCF table\n",
1854 phba
->fcf
.current_rec
.fcf_indx
);
1855 lpfc_unregister_fcf_rescan(phba
);
1856 goto stop_flogi_current_fcf
;
1858 /* Mark the end to FLOGI roundrobin failover */
1859 phba
->hba_flag
&= ~FCF_RR_INPROG
;
1860 /* Allow action to new fcf asynchronous event */
1861 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
1862 spin_unlock_irq(&phba
->hbalock
);
1863 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1864 "2865 No FCF available, stop roundrobin FCF "
1865 "failover and change port state:x%x/x%x\n",
1866 phba
->pport
->port_state
, LPFC_VPORT_UNKNOWN
);
1867 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
1868 goto stop_flogi_current_fcf
;
1870 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_ELS
,
1871 "2794 Try FLOGI roundrobin FCF failover to "
1872 "(x%x)\n", fcf_index
);
1873 rc
= lpfc_sli4_fcf_rr_read_fcf_rec(phba
, fcf_index
);
1875 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
1876 "2761 FLOGI roundrobin FCF failover "
1877 "failed (rc:x%x) to read FCF (x%x)\n",
1878 rc
, phba
->fcf
.current_rec
.fcf_indx
);
1880 goto stop_flogi_current_fcf
;
1884 stop_flogi_current_fcf
:
1885 lpfc_can_disctmo(vport
);
1890 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1891 * @phba: pointer to lpfc hba data structure.
1892 * @mboxq: pointer to mailbox object.
1894 * This function iterates through all the fcf records available in
1895 * HBA and chooses the optimal FCF record for discovery. After finding
1896 * the FCF for discovery it registers the FCF record and kicks start
1898 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1899 * use an FCF record which matches fabric name and mac address of the
1900 * currently used FCF record.
1901 * If the driver supports only one FCF, it will try to use the FCF record
1902 * used by BOOT_BIOS.
1905 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1907 struct fcf_record
*new_fcf_record
;
1908 uint32_t boot_flag
, addr_mode
;
1909 uint16_t fcf_index
, next_fcf_index
;
1910 struct lpfc_fcf_rec
*fcf_rec
= NULL
;
1913 bool select_new_fcf
;
1916 /* If there is pending FCoE event restart FCF table scan */
1917 if (lpfc_check_pending_fcoe_event(phba
, LPFC_SKIP_UNREG_FCF
)) {
1918 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1922 /* Parse the FCF record from the non-embedded mailbox command */
1923 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
1925 if (!new_fcf_record
) {
1926 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1927 "2765 Mailbox command READ_FCF_RECORD "
1928 "failed to retrieve a FCF record.\n");
1929 /* Let next new FCF event trigger fast failover */
1930 spin_lock_irq(&phba
->hbalock
);
1931 phba
->hba_flag
&= ~FCF_TS_INPROG
;
1932 spin_unlock_irq(&phba
->hbalock
);
1933 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1937 /* Check the FCF record against the connection list */
1938 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
1939 &addr_mode
, &vlan_id
);
1941 /* Log the FCF record information if turned on */
1942 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
1946 * If the fcf record does not match with connect list entries
1947 * read the next entry; otherwise, this is an eligible FCF
1948 * record for roundrobin FCF failover.
1951 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
1952 "2781 FCF (x%x) failed connection "
1953 "list check: (x%x/x%x)\n",
1954 bf_get(lpfc_fcf_record_fcf_index
,
1956 bf_get(lpfc_fcf_record_fcf_avail
,
1958 bf_get(lpfc_fcf_record_fcf_valid
,
1960 if ((phba
->fcf
.fcf_flag
& FCF_IN_USE
) &&
1961 lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
1962 new_fcf_record
, LPFC_FCOE_IGNORE_VID
)) {
1963 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) !=
1964 phba
->fcf
.current_rec
.fcf_indx
) {
1965 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1966 "2862 FCF (x%x) matches property "
1967 "of in-use FCF (x%x)\n",
1968 bf_get(lpfc_fcf_record_fcf_index
,
1970 phba
->fcf
.current_rec
.fcf_indx
);
1974 * In case the current in-use FCF record becomes
1975 * invalid/unavailable during FCF discovery that
1976 * was not triggered by fast FCF failover process,
1977 * treat it as fast FCF failover.
1979 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
) &&
1980 !(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
1981 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
1982 "2835 Invalid in-use FCF "
1983 "(x%x), enter FCF failover "
1985 phba
->fcf
.current_rec
.fcf_indx
);
1986 spin_lock_irq(&phba
->hbalock
);
1987 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
1988 spin_unlock_irq(&phba
->hbalock
);
1989 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1990 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
1991 LPFC_FCOE_FCF_GET_FIRST
);
1997 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1998 rc
= lpfc_sli4_fcf_rr_index_set(phba
, fcf_index
);
2004 * If this is not the first FCF discovery of the HBA, use last
2005 * FCF record for the discovery. The condition that a rescan
2006 * matches the in-use FCF record: fabric name, switch name, mac
2007 * address, and vlan_id.
2009 spin_lock_irq(&phba
->hbalock
);
2010 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2011 if (lpfc_sli4_fcf_record_match(phba
, &phba
->fcf
.current_rec
,
2012 new_fcf_record
, vlan_id
)) {
2013 if (bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
) ==
2014 phba
->fcf
.current_rec
.fcf_indx
) {
2015 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2016 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)
2017 /* Stop FCF redisc wait timer */
2018 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2020 else if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2021 /* Fast failover, mark completed */
2022 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2023 spin_unlock_irq(&phba
->hbalock
);
2024 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2025 "2836 New FCF matches in-use "
2027 phba
->fcf
.current_rec
.fcf_indx
);
2030 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
2031 "2863 New FCF (x%x) matches "
2032 "property of in-use FCF (x%x)\n",
2033 bf_get(lpfc_fcf_record_fcf_index
,
2035 phba
->fcf
.current_rec
.fcf_indx
);
2038 * Read next FCF record from HBA searching for the matching
2039 * with in-use record only if not during the fast failover
2040 * period. In case of fast failover period, it shall try to
2041 * determine whether the FCF record just read should be the
2044 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
2045 spin_unlock_irq(&phba
->hbalock
);
2050 * Update on failover FCF record only if it's in FCF fast-failover
2051 * period; otherwise, update on current FCF record.
2053 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
2054 fcf_rec
= &phba
->fcf
.failover_rec
;
2056 fcf_rec
= &phba
->fcf
.current_rec
;
2058 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
2060 * If the driver FCF record does not have boot flag
2061 * set and new hba fcf record has boot flag set, use
2062 * the new hba fcf record.
2064 if (boot_flag
&& !(fcf_rec
->flag
& BOOT_ENABLE
)) {
2065 /* Choose this FCF record */
2066 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2067 "2837 Update current FCF record "
2068 "(x%x) with new FCF record (x%x)\n",
2070 bf_get(lpfc_fcf_record_fcf_index
,
2072 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2073 addr_mode
, vlan_id
, BOOT_ENABLE
);
2074 spin_unlock_irq(&phba
->hbalock
);
2078 * If the driver FCF record has boot flag set and the
2079 * new hba FCF record does not have boot flag, read
2080 * the next FCF record.
2082 if (!boot_flag
&& (fcf_rec
->flag
& BOOT_ENABLE
)) {
2083 spin_unlock_irq(&phba
->hbalock
);
2087 * If the new hba FCF record has lower priority value
2088 * than the driver FCF record, use the new record.
2090 if (new_fcf_record
->fip_priority
< fcf_rec
->priority
) {
2091 /* Choose the new FCF record with lower priority */
2092 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2093 "2838 Update current FCF record "
2094 "(x%x) with new FCF record (x%x)\n",
2096 bf_get(lpfc_fcf_record_fcf_index
,
2098 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2099 addr_mode
, vlan_id
, 0);
2100 /* Reset running random FCF selection count */
2101 phba
->fcf
.eligible_fcf_cnt
= 1;
2102 } else if (new_fcf_record
->fip_priority
== fcf_rec
->priority
) {
2103 /* Update running random FCF selection count */
2104 phba
->fcf
.eligible_fcf_cnt
++;
2105 select_new_fcf
= lpfc_sli4_new_fcf_random_select(phba
,
2106 phba
->fcf
.eligible_fcf_cnt
);
2107 if (select_new_fcf
) {
2108 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2109 "2839 Update current FCF record "
2110 "(x%x) with new FCF record (x%x)\n",
2112 bf_get(lpfc_fcf_record_fcf_index
,
2114 /* Choose the new FCF by random selection */
2115 __lpfc_update_fcf_record(phba
, fcf_rec
,
2117 addr_mode
, vlan_id
, 0);
2120 spin_unlock_irq(&phba
->hbalock
);
2124 * This is the first suitable FCF record, choose this record for
2125 * initial best-fit FCF.
2128 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2129 "2840 Update initial FCF candidate "
2131 bf_get(lpfc_fcf_record_fcf_index
,
2133 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
2134 addr_mode
, vlan_id
, (boot_flag
?
2136 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
2137 /* Setup initial running random FCF selection count */
2138 phba
->fcf
.eligible_fcf_cnt
= 1;
2139 /* Seeding the random number generator for random selection */
2140 seed
= (uint32_t)(0xFFFFFFFF & jiffies
);
2143 spin_unlock_irq(&phba
->hbalock
);
2147 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2148 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0) {
2149 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
) {
2151 * Case of FCF fast failover scan
2155 * It has not found any suitable FCF record, cancel
2156 * FCF scan inprogress, and do nothing
2158 if (!(phba
->fcf
.failover_rec
.flag
& RECORD_VALID
)) {
2159 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2160 "2782 No suitable FCF found: "
2162 phba
->fcoe_eventtag_at_fcf_scan
,
2163 bf_get(lpfc_fcf_record_fcf_index
,
2165 spin_lock_irq(&phba
->hbalock
);
2166 if (phba
->hba_flag
& HBA_DEVLOSS_TMO
) {
2167 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2168 spin_unlock_irq(&phba
->hbalock
);
2169 /* Unregister in-use FCF and rescan */
2170 lpfc_printf_log(phba
, KERN_INFO
,
2172 "2864 On devloss tmo "
2173 "unreg in-use FCF and "
2174 "rescan FCF table\n");
2175 lpfc_unregister_fcf_rescan(phba
);
2179 * Let next new FCF event trigger fast failover
2181 phba
->hba_flag
&= ~FCF_TS_INPROG
;
2182 spin_unlock_irq(&phba
->hbalock
);
2186 * It has found a suitable FCF record that is not
2187 * the same as in-use FCF record, unregister the
2188 * in-use FCF record, replace the in-use FCF record
2189 * with the new FCF record, mark FCF fast failover
2190 * completed, and then start register the new FCF
2194 /* Unregister the current in-use FCF record */
2195 lpfc_unregister_fcf(phba
);
2197 /* Replace in-use record with the new record */
2198 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2199 "2842 Replace in-use FCF (x%x) "
2200 "with failover FCF (x%x)\n",
2201 phba
->fcf
.current_rec
.fcf_indx
,
2202 phba
->fcf
.failover_rec
.fcf_indx
);
2203 memcpy(&phba
->fcf
.current_rec
,
2204 &phba
->fcf
.failover_rec
,
2205 sizeof(struct lpfc_fcf_rec
));
2207 * Mark the fast FCF failover rediscovery completed
2208 * and the start of the first round of the roundrobin
2211 spin_lock_irq(&phba
->hbalock
);
2212 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
2213 spin_unlock_irq(&phba
->hbalock
);
2214 /* Register to the new FCF record */
2215 lpfc_register_fcf(phba
);
2218 * In case of transaction period to fast FCF failover,
2219 * do nothing when search to the end of the FCF table.
2221 if ((phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) ||
2222 (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
))
2225 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
2227 * In case the current in-use FCF record no
2228 * longer existed during FCF discovery that
2229 * was not triggered by fast FCF failover
2230 * process, treat it as fast FCF failover.
2232 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2233 "2841 In-use FCF record (x%x) "
2234 "not reported, entering fast "
2235 "FCF failover mode scanning.\n",
2236 phba
->fcf
.current_rec
.fcf_indx
);
2237 spin_lock_irq(&phba
->hbalock
);
2238 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
2239 spin_unlock_irq(&phba
->hbalock
);
2240 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2241 lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2242 LPFC_FCOE_FCF_GET_FIRST
);
2245 /* Register to the new FCF record */
2246 lpfc_register_fcf(phba
);
2249 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, next_fcf_index
);
2253 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2254 lpfc_register_fcf(phba
);
2260 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2261 * @phba: pointer to lpfc hba data structure.
2262 * @mboxq: pointer to mailbox object.
2264 * This is the callback function for FLOGI failure roundrobin FCF failover
2265 * read FCF record mailbox command from the eligible FCF record bmask for
2266 * performing the failover. If the FCF read back is not valid/available, it
2267 * fails through to retrying FLOGI to the currently registered FCF again.
2268 * Otherwise, if the FCF read back is valid and available, it will set the
2269 * newly read FCF record to the failover FCF record, unregister currently
2270 * registered FCF record, copy the failover FCF record to the current
2271 * FCF record, and then register the current FCF record before proceeding
2272 * to trying FLOGI on the new failover FCF.
2275 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2277 struct fcf_record
*new_fcf_record
;
2278 uint32_t boot_flag
, addr_mode
;
2279 uint16_t next_fcf_index
, fcf_index
;
2280 uint16_t current_fcf_index
;
2284 /* If link state is not up, stop the roundrobin failover process */
2285 if (phba
->link_state
< LPFC_LINK_UP
) {
2286 spin_lock_irq(&phba
->hbalock
);
2287 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
2288 phba
->hba_flag
&= ~FCF_RR_INPROG
;
2289 spin_unlock_irq(&phba
->hbalock
);
2293 /* Parse the FCF record from the non-embedded mailbox command */
2294 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2296 if (!new_fcf_record
) {
2297 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2298 "2766 Mailbox command READ_FCF_RECORD "
2299 "failed to retrieve a FCF record.\n");
2303 /* Get the needed parameters from FCF record */
2304 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2305 &addr_mode
, &vlan_id
);
2307 /* Log the FCF record information if turned on */
2308 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2311 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2313 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2314 "2848 Remove ineligible FCF (x%x) from "
2315 "from roundrobin bmask\n", fcf_index
);
2316 /* Clear roundrobin bmask bit for ineligible FCF */
2317 lpfc_sli4_fcf_rr_index_clear(phba
, fcf_index
);
2318 /* Perform next round of roundrobin FCF failover */
2319 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
2320 rc
= lpfc_sli4_fcf_rr_next_proc(phba
->pport
, fcf_index
);
2326 if (fcf_index
== phba
->fcf
.current_rec
.fcf_indx
) {
2327 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2328 "2760 Perform FLOGI roundrobin FCF failover: "
2329 "FCF (x%x) back to FCF (x%x)\n",
2330 phba
->fcf
.current_rec
.fcf_indx
, fcf_index
);
2331 /* Wait 500 ms before retrying FLOGI to current FCF */
2333 lpfc_issue_init_vfi(phba
->pport
);
2337 /* Upload new FCF record to the failover FCF record */
2338 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2339 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2340 phba
->fcf
.failover_rec
.fcf_indx
, fcf_index
);
2341 spin_lock_irq(&phba
->hbalock
);
2342 __lpfc_update_fcf_record(phba
, &phba
->fcf
.failover_rec
,
2343 new_fcf_record
, addr_mode
, vlan_id
,
2344 (boot_flag
? BOOT_ENABLE
: 0));
2345 spin_unlock_irq(&phba
->hbalock
);
2347 current_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
2349 /* Unregister the current in-use FCF record */
2350 lpfc_unregister_fcf(phba
);
2352 /* Replace in-use record with the new record */
2353 memcpy(&phba
->fcf
.current_rec
, &phba
->fcf
.failover_rec
,
2354 sizeof(struct lpfc_fcf_rec
));
2356 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2357 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2358 "(x%x) to FCF (x%x)\n", current_fcf_index
, fcf_index
);
2361 lpfc_register_fcf(phba
);
2363 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2367 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2368 * @phba: pointer to lpfc hba data structure.
2369 * @mboxq: pointer to mailbox object.
2371 * This is the callback function of read FCF record mailbox command for
2372 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2373 * failover when a new FCF event happened. If the FCF read back is
2374 * valid/available and it passes the connection list check, it updates
2375 * the bmask for the eligible FCF record for roundrobin failover.
2378 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2380 struct fcf_record
*new_fcf_record
;
2381 uint32_t boot_flag
, addr_mode
;
2382 uint16_t fcf_index
, next_fcf_index
;
2386 /* If link state is not up, no need to proceed */
2387 if (phba
->link_state
< LPFC_LINK_UP
)
2390 /* If FCF discovery period is over, no need to proceed */
2391 if (!(phba
->fcf
.fcf_flag
& FCF_DISCOVERY
))
2394 /* Parse the FCF record from the non-embedded mailbox command */
2395 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2397 if (!new_fcf_record
) {
2398 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2399 "2767 Mailbox command READ_FCF_RECORD "
2400 "failed to retrieve a FCF record.\n");
2404 /* Check the connection list for eligibility */
2405 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2406 &addr_mode
, &vlan_id
);
2408 /* Log the FCF record information if turned on */
2409 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2415 /* Update the eligible FCF record index bmask */
2416 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2417 rc
= lpfc_sli4_fcf_rr_index_set(phba
, fcf_index
);
2420 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2424 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2425 * @phba: pointer to lpfc hba data structure.
2426 * @mboxq: pointer to mailbox data structure.
2428 * This function handles completion of init vfi mailbox command.
2431 lpfc_init_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2433 struct lpfc_vport
*vport
= mboxq
->vport
;
2435 if (mboxq
->u
.mb
.mbxStatus
&& (mboxq
->u
.mb
.mbxStatus
!= 0x4002)) {
2436 lpfc_printf_vlog(vport
, KERN_ERR
,
2438 "2891 Init VFI mailbox failed 0x%x\n",
2439 mboxq
->u
.mb
.mbxStatus
);
2440 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2441 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2444 lpfc_initial_flogi(vport
);
2445 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2450 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2451 * @vport: pointer to lpfc_vport data structure.
2453 * This function issue a init_vfi mailbox command to initialize the VFI and
2454 * VPI for the physical port.
2457 lpfc_issue_init_vfi(struct lpfc_vport
*vport
)
2459 LPFC_MBOXQ_t
*mboxq
;
2461 struct lpfc_hba
*phba
= vport
->phba
;
2463 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2465 lpfc_printf_vlog(vport
, KERN_ERR
,
2466 LOG_MBOX
, "2892 Failed to allocate "
2467 "init_vfi mailbox\n");
2470 lpfc_init_vfi(mboxq
, vport
);
2471 mboxq
->mbox_cmpl
= lpfc_init_vfi_cmpl
;
2472 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
2473 if (rc
== MBX_NOT_FINISHED
) {
2474 lpfc_printf_vlog(vport
, KERN_ERR
,
2475 LOG_MBOX
, "2893 Failed to issue init_vfi mailbox\n");
2476 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2481 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2482 * @phba: pointer to lpfc hba data structure.
2483 * @mboxq: pointer to mailbox data structure.
2485 * This function handles completion of init vpi mailbox command.
2488 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2490 struct lpfc_vport
*vport
= mboxq
->vport
;
2491 struct lpfc_nodelist
*ndlp
;
2492 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2494 if (mboxq
->u
.mb
.mbxStatus
) {
2495 lpfc_printf_vlog(vport
, KERN_ERR
,
2497 "2609 Init VPI mailbox failed 0x%x\n",
2498 mboxq
->u
.mb
.mbxStatus
);
2499 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2500 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2503 spin_lock_irq(shost
->host_lock
);
2504 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2505 spin_unlock_irq(shost
->host_lock
);
2507 /* If this port is physical port or FDISC is done, do reg_vpi */
2508 if ((phba
->pport
== vport
) || (vport
->port_state
== LPFC_FDISC
)) {
2509 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
2511 lpfc_printf_vlog(vport
, KERN_ERR
,
2513 "2731 Cannot find fabric "
2514 "controller node\n");
2516 lpfc_register_new_vport(phba
, vport
, ndlp
);
2517 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2521 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2522 lpfc_initial_fdisc(vport
);
2524 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
2525 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2526 "2606 No NPIV Fabric support\n");
2528 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2533 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2534 * @vport: pointer to lpfc_vport data structure.
2536 * This function issue a init_vpi mailbox command to initialize
2537 * VPI for the vport.
2540 lpfc_issue_init_vpi(struct lpfc_vport
*vport
)
2542 LPFC_MBOXQ_t
*mboxq
;
2545 mboxq
= mempool_alloc(vport
->phba
->mbox_mem_pool
, GFP_KERNEL
);
2547 lpfc_printf_vlog(vport
, KERN_ERR
,
2548 LOG_MBOX
, "2607 Failed to allocate "
2549 "init_vpi mailbox\n");
2552 lpfc_init_vpi(vport
->phba
, mboxq
, vport
->vpi
);
2553 mboxq
->vport
= vport
;
2554 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
2555 rc
= lpfc_sli_issue_mbox(vport
->phba
, mboxq
, MBX_NOWAIT
);
2556 if (rc
== MBX_NOT_FINISHED
) {
2557 lpfc_printf_vlog(vport
, KERN_ERR
,
2558 LOG_MBOX
, "2608 Failed to issue init_vpi mailbox\n");
2559 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2564 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2565 * @phba: pointer to lpfc hba data structure.
2567 * This function loops through the list of vports on the @phba and issues an
2568 * FDISC if possible.
2571 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
2573 struct lpfc_vport
**vports
;
2576 vports
= lpfc_create_vport_work_array(phba
);
2577 if (vports
!= NULL
) {
2578 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2579 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
2581 /* There are no vpi for this vport */
2582 if (vports
[i
]->vpi
> phba
->max_vpi
) {
2583 lpfc_vport_set_state(vports
[i
],
2587 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2588 lpfc_vport_set_state(vports
[i
],
2592 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
2593 lpfc_issue_init_vpi(vports
[i
]);
2596 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2597 lpfc_initial_fdisc(vports
[i
]);
2599 lpfc_vport_set_state(vports
[i
],
2600 FC_VPORT_NO_FABRIC_SUPP
);
2601 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
2604 "Fabric support\n");
2608 lpfc_destroy_vport_work_array(phba
, vports
);
2612 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2614 struct lpfc_dmabuf
*dmabuf
= mboxq
->context1
;
2615 struct lpfc_vport
*vport
= mboxq
->vport
;
2616 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2618 if (mboxq
->u
.mb
.mbxStatus
) {
2619 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2620 "2018 REG_VFI mbxStatus error x%x "
2622 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
2623 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2624 /* FLOGI failed, use loop map to make discovery list */
2625 lpfc_disc_list_loopmap(vport
);
2626 /* Start discovery */
2627 lpfc_disc_start(vport
);
2630 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2633 /* The VPI is implicitly registered when the VFI is registered */
2634 spin_lock_irq(shost
->host_lock
);
2635 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2636 vport
->fc_flag
|= FC_VFI_REGISTERED
;
2637 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2638 spin_unlock_irq(shost
->host_lock
);
2640 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
2641 /* For private loop just start discovery and we are done. */
2642 if ((phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) &&
2643 (phba
->alpa_map
[0] == 0) &&
2644 !(vport
->fc_flag
& FC_PUBLIC_LOOP
)) {
2645 /* Use loop map to make discovery list */
2646 lpfc_disc_list_loopmap(vport
);
2647 /* Start discovery */
2648 lpfc_disc_start(vport
);
2650 lpfc_start_fdiscs(phba
);
2651 lpfc_do_scr_ns_plogi(phba
, vport
);
2656 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2657 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2663 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2665 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2666 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
2667 struct lpfc_vport
*vport
= pmb
->vport
;
2670 /* Check for error */
2671 if (mb
->mbxStatus
) {
2672 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
2673 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2674 "0319 READ_SPARAM mbxStatus error x%x "
2676 mb
->mbxStatus
, vport
->port_state
);
2677 lpfc_linkdown(phba
);
2681 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
2682 sizeof (struct serv_parm
));
2683 if (phba
->cfg_soft_wwnn
)
2684 u64_to_wwn(phba
->cfg_soft_wwnn
,
2685 vport
->fc_sparam
.nodeName
.u
.wwn
);
2686 if (phba
->cfg_soft_wwpn
)
2687 u64_to_wwn(phba
->cfg_soft_wwpn
,
2688 vport
->fc_sparam
.portName
.u
.wwn
);
2689 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
2690 sizeof(vport
->fc_nodename
));
2691 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
2692 sizeof(vport
->fc_portname
));
2693 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
2694 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
2695 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
2698 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2700 mempool_free(pmb
, phba
->mbox_mem_pool
);
2704 pmb
->context1
= NULL
;
2705 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2707 lpfc_issue_clear_la(phba
, vport
);
2708 mempool_free(pmb
, phba
->mbox_mem_pool
);
2713 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, struct lpfc_mbx_read_top
*la
)
2715 struct lpfc_vport
*vport
= phba
->pport
;
2716 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
2718 struct lpfc_dmabuf
*mp
;
2720 struct fcf_record
*fcf_record
;
2722 spin_lock_irq(&phba
->hbalock
);
2723 switch (bf_get(lpfc_mbx_read_top_link_spd
, la
)) {
2724 case LPFC_LINK_SPEED_1GHZ
:
2725 case LPFC_LINK_SPEED_2GHZ
:
2726 case LPFC_LINK_SPEED_4GHZ
:
2727 case LPFC_LINK_SPEED_8GHZ
:
2728 case LPFC_LINK_SPEED_10GHZ
:
2729 case LPFC_LINK_SPEED_16GHZ
:
2730 phba
->fc_linkspeed
= bf_get(lpfc_mbx_read_top_link_spd
, la
);
2733 phba
->fc_linkspeed
= LPFC_LINK_SPEED_UNKNOWN
;
2737 phba
->fc_topology
= bf_get(lpfc_mbx_read_top_topology
, la
);
2738 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
2740 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2741 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
2743 /* if npiv is enabled and this adapter supports npiv log
2744 * a message that npiv is not supported in this topology
2746 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
2747 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2748 "1309 Link Up Event npiv not supported in loop "
2750 /* Get Loop Map information */
2751 if (bf_get(lpfc_mbx_read_top_il
, la
))
2752 vport
->fc_flag
|= FC_LBIT
;
2754 vport
->fc_myDID
= bf_get(lpfc_mbx_read_top_alpa_granted
, la
);
2755 i
= la
->lilpBde64
.tus
.f
.bdeSize
;
2758 phba
->alpa_map
[0] = 0;
2760 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
2771 numalpa
= phba
->alpa_map
[0];
2773 while (j
< numalpa
) {
2774 memset(un
.pamap
, 0, 16);
2775 for (k
= 1; j
< numalpa
; k
++) {
2777 phba
->alpa_map
[j
+ 1];
2782 /* Link Up Event ALPA map */
2783 lpfc_printf_log(phba
,
2786 "1304 Link Up Event "
2787 "ALPA map Data: x%x "
2789 un
.pa
.wd1
, un
.pa
.wd2
,
2790 un
.pa
.wd3
, un
.pa
.wd4
);
2795 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
2796 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
2797 (phba
->sli_rev
== 3))
2798 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
2800 vport
->fc_myDID
= phba
->fc_pref_DID
;
2801 vport
->fc_flag
|= FC_LBIT
;
2803 spin_unlock_irq(&phba
->hbalock
);
2806 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2810 rc
= lpfc_read_sparam(phba
, sparam_mbox
, 0);
2812 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
2815 sparam_mbox
->vport
= vport
;
2816 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
2817 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
2818 if (rc
== MBX_NOT_FINISHED
) {
2819 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
2820 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2822 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
2826 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
2827 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2830 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
2831 lpfc_config_link(phba
, cfglink_mbox
);
2832 cfglink_mbox
->vport
= vport
;
2833 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
2834 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
2835 if (rc
== MBX_NOT_FINISHED
) {
2836 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
2840 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
2842 * Add the driver's default FCF record at FCF index 0 now. This
2843 * is phase 1 implementation that support FCF index 0 and driver
2846 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
2847 fcf_record
= kzalloc(sizeof(struct fcf_record
),
2849 if (unlikely(!fcf_record
)) {
2850 lpfc_printf_log(phba
, KERN_ERR
,
2852 "2554 Could not allocate memmory for "
2858 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
2859 LPFC_FCOE_FCF_DEF_INDEX
);
2860 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
2862 lpfc_printf_log(phba
, KERN_ERR
,
2864 "2013 Could not manually add FCF "
2865 "record 0, status %d\n", rc
);
2873 * The driver is expected to do FIP/FCF. Call the port
2874 * and get the FCF Table.
2876 spin_lock_irq(&phba
->hbalock
);
2877 if (phba
->hba_flag
& FCF_TS_INPROG
) {
2878 spin_unlock_irq(&phba
->hbalock
);
2881 /* This is the initial FCF discovery scan */
2882 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
2883 spin_unlock_irq(&phba
->hbalock
);
2884 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
2885 "2778 Start FCF table scan at linkup\n");
2886 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2887 LPFC_FCOE_FCF_GET_FIRST
);
2889 spin_lock_irq(&phba
->hbalock
);
2890 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
2891 spin_unlock_irq(&phba
->hbalock
);
2894 /* Reset FCF roundrobin bmask for new discovery */
2895 memset(phba
->fcf
.fcf_rr_bmask
, 0,
2896 sizeof(*phba
->fcf
.fcf_rr_bmask
));
2901 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2902 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2903 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2904 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
2905 lpfc_issue_clear_la(phba
, vport
);
2910 lpfc_enable_la(struct lpfc_hba
*phba
)
2913 struct lpfc_sli
*psli
= &phba
->sli
;
2914 spin_lock_irq(&phba
->hbalock
);
2915 psli
->sli_flag
|= LPFC_PROCESS_LA
;
2916 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
2917 control
= readl(phba
->HCregaddr
);
2918 control
|= HC_LAINT_ENA
;
2919 writel(control
, phba
->HCregaddr
);
2920 readl(phba
->HCregaddr
); /* flush */
2922 spin_unlock_irq(&phba
->hbalock
);
2926 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
2928 lpfc_linkdown(phba
);
2929 lpfc_enable_la(phba
);
2930 lpfc_unregister_unused_fcf(phba
);
2931 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2936 * This routine handles processing a READ_TOPOLOGY mailbox
2937 * command upon completion. It is setup in the LPFC_MBOXQ
2938 * as the completion routine when the command is
2939 * handed off to the SLI layer.
2942 lpfc_mbx_cmpl_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2944 struct lpfc_vport
*vport
= pmb
->vport
;
2945 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2946 struct lpfc_mbx_read_top
*la
;
2947 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2948 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2950 /* Unblock ELS traffic */
2951 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2952 /* Check for error */
2953 if (mb
->mbxStatus
) {
2954 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2955 "1307 READ_LA mbox error x%x state x%x\n",
2956 mb
->mbxStatus
, vport
->port_state
);
2957 lpfc_mbx_issue_link_down(phba
);
2958 phba
->link_state
= LPFC_HBA_ERROR
;
2959 goto lpfc_mbx_cmpl_read_topology_free_mbuf
;
2962 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
2964 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
2966 spin_lock_irq(shost
->host_lock
);
2967 if (bf_get(lpfc_mbx_read_top_pb
, la
))
2968 vport
->fc_flag
|= FC_BYPASSED_MODE
;
2970 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
2971 spin_unlock_irq(shost
->host_lock
);
2973 if ((phba
->fc_eventTag
< la
->eventTag
) ||
2974 (phba
->fc_eventTag
== la
->eventTag
)) {
2975 phba
->fc_stat
.LinkMultiEvent
++;
2976 if (bf_get(lpfc_mbx_read_top_att_type
, la
) == LPFC_ATT_LINK_UP
)
2977 if (phba
->fc_eventTag
!= 0)
2978 lpfc_linkdown(phba
);
2981 phba
->fc_eventTag
= la
->eventTag
;
2982 spin_lock_irq(&phba
->hbalock
);
2983 if (bf_get(lpfc_mbx_read_top_mm
, la
))
2984 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
2986 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
2987 spin_unlock_irq(&phba
->hbalock
);
2989 phba
->link_events
++;
2990 if ((bf_get(lpfc_mbx_read_top_att_type
, la
) == LPFC_ATT_LINK_UP
) &&
2991 (!bf_get(lpfc_mbx_read_top_mm
, la
))) {
2992 phba
->fc_stat
.LinkUp
++;
2993 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2994 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2995 "1306 Link Up Event in loop back mode "
2996 "x%x received Data: x%x x%x x%x x%x\n",
2997 la
->eventTag
, phba
->fc_eventTag
,
2998 bf_get(lpfc_mbx_read_top_alpa_granted
,
3000 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3003 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3004 "1303 Link Up Event x%x received "
3005 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3006 la
->eventTag
, phba
->fc_eventTag
,
3007 bf_get(lpfc_mbx_read_top_alpa_granted
,
3009 bf_get(lpfc_mbx_read_top_link_spd
, la
),
3011 bf_get(lpfc_mbx_read_top_mm
, la
),
3012 bf_get(lpfc_mbx_read_top_fa
, la
),
3013 phba
->wait_4_mlo_maint_flg
);
3015 lpfc_mbx_process_link_up(phba
, la
);
3016 } else if (bf_get(lpfc_mbx_read_top_att_type
, la
) ==
3017 LPFC_ATT_LINK_DOWN
) {
3018 phba
->fc_stat
.LinkDown
++;
3019 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
3020 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3021 "1308 Link Down Event in loop back mode "
3023 "Data: x%x x%x x%x\n",
3024 la
->eventTag
, phba
->fc_eventTag
,
3025 phba
->pport
->port_state
, vport
->fc_flag
);
3028 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3029 "1305 Link Down Event x%x received "
3030 "Data: x%x x%x x%x x%x x%x\n",
3031 la
->eventTag
, phba
->fc_eventTag
,
3032 phba
->pport
->port_state
, vport
->fc_flag
,
3033 bf_get(lpfc_mbx_read_top_mm
, la
),
3034 bf_get(lpfc_mbx_read_top_fa
, la
));
3036 lpfc_mbx_issue_link_down(phba
);
3038 if ((bf_get(lpfc_mbx_read_top_mm
, la
)) &&
3039 (bf_get(lpfc_mbx_read_top_att_type
, la
) == LPFC_ATT_LINK_UP
)) {
3040 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
3041 phba
->fc_stat
.LinkDown
++;
3042 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3043 "1312 Link Down Event x%x received "
3044 "Data: x%x x%x x%x\n",
3045 la
->eventTag
, phba
->fc_eventTag
,
3046 phba
->pport
->port_state
, vport
->fc_flag
);
3047 lpfc_mbx_issue_link_down(phba
);
3049 lpfc_enable_la(phba
);
3051 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
3052 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3053 "Data: x%x x%x x%x\n",
3054 la
->eventTag
, phba
->fc_eventTag
,
3055 phba
->pport
->port_state
, vport
->fc_flag
);
3057 * The cmnd that triggered this will be waiting for this
3060 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3061 if (phba
->wait_4_mlo_maint_flg
) {
3062 phba
->wait_4_mlo_maint_flg
= 0;
3063 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
3067 if (bf_get(lpfc_mbx_read_top_fa
, la
)) {
3068 if (bf_get(lpfc_mbx_read_top_mm
, la
))
3069 lpfc_issue_clear_la(phba
, vport
);
3070 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
3072 bf_get(lpfc_mbx_read_top_fa
, la
));
3075 lpfc_mbx_cmpl_read_topology_free_mbuf
:
3076 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3078 mempool_free(pmb
, phba
->mbox_mem_pool
);
3083 * This routine handles processing a REG_LOGIN mailbox
3084 * command upon completion. It is setup in the LPFC_MBOXQ
3085 * as the completion routine when the command is
3086 * handed off to the SLI layer.
3089 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3091 struct lpfc_vport
*vport
= pmb
->vport
;
3092 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3093 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3094 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3096 pmb
->context1
= NULL
;
3097 pmb
->context2
= NULL
;
3099 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
3100 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3102 if (ndlp
->nlp_flag
& NLP_IGNR_REG_CMPL
||
3103 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) {
3104 /* We rcvd a rscn after issuing this
3105 * mbox reg login, we may have cycled
3106 * back through the state and be
3107 * back at reg login state so this
3108 * mbox needs to be ignored becase
3109 * there is another reg login in
3112 spin_lock_irq(shost
->host_lock
);
3113 ndlp
->nlp_flag
&= ~NLP_IGNR_REG_CMPL
;
3114 spin_unlock_irq(shost
->host_lock
);
3115 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3116 lpfc_sli4_free_rpi(phba
,
3117 pmb
->u
.mb
.un
.varRegLogin
.rpi
);
3120 /* Good status, call state machine */
3121 lpfc_disc_state_machine(vport
, ndlp
, pmb
,
3122 NLP_EVT_CMPL_REG_LOGIN
);
3124 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3126 mempool_free(pmb
, phba
->mbox_mem_pool
);
3127 /* decrement the node reference count held for this callback
3136 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3138 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3139 struct lpfc_vport
*vport
= pmb
->vport
;
3140 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3142 switch (mb
->mbxStatus
) {
3145 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3146 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3149 /* If VPI is busy, reset the HBA */
3151 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3152 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3153 vport
->vpi
, mb
->mbxStatus
);
3154 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
3155 lpfc_workq_post_event(phba
, NULL
, NULL
,
3156 LPFC_EVT_RESET_HBA
);
3158 spin_lock_irq(shost
->host_lock
);
3159 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
3160 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3161 spin_unlock_irq(shost
->host_lock
);
3162 vport
->unreg_vpi_cmpl
= VPORT_OK
;
3163 mempool_free(pmb
, phba
->mbox_mem_pool
);
3165 * This shost reference might have been taken at the beginning of
3166 * lpfc_vport_delete()
3168 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
3169 scsi_host_put(shost
);
3173 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
3175 struct lpfc_hba
*phba
= vport
->phba
;
3179 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3183 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
3184 mbox
->vport
= vport
;
3185 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
3186 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3187 if (rc
== MBX_NOT_FINISHED
) {
3188 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3189 "1800 Could not issue unreg_vpi\n");
3190 mempool_free(mbox
, phba
->mbox_mem_pool
);
3191 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
3198 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3200 struct lpfc_vport
*vport
= pmb
->vport
;
3201 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3202 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3204 switch (mb
->mbxStatus
) {
3208 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3209 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3211 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3212 spin_lock_irq(shost
->host_lock
);
3213 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3214 spin_unlock_irq(shost
->host_lock
);
3215 vport
->fc_myDID
= 0;
3219 spin_lock_irq(shost
->host_lock
);
3220 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
3221 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
3222 spin_unlock_irq(shost
->host_lock
);
3223 vport
->num_disc_nodes
= 0;
3224 /* go thru NPR list and issue ELS PLOGIs */
3225 if (vport
->fc_npr_cnt
)
3226 lpfc_els_disc_plogi(vport
);
3228 if (!vport
->num_disc_nodes
) {
3229 spin_lock_irq(shost
->host_lock
);
3230 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3231 spin_unlock_irq(shost
->host_lock
);
3232 lpfc_can_disctmo(vport
);
3234 vport
->port_state
= LPFC_VPORT_READY
;
3237 mempool_free(pmb
, phba
->mbox_mem_pool
);
3242 * lpfc_create_static_vport - Read HBA config region to create static vports.
3243 * @phba: pointer to lpfc hba data structure.
3245 * This routine issue a DUMP mailbox command for config region 22 to get
3246 * the list of static vports to be created. The function create vports
3247 * based on the information returned from the HBA.
3250 lpfc_create_static_vport(struct lpfc_hba
*phba
)
3252 LPFC_MBOXQ_t
*pmb
= NULL
;
3254 struct static_vport_info
*vport_info
;
3256 struct fc_vport_identifiers vport_id
;
3257 struct fc_vport
*new_fc_vport
;
3258 struct Scsi_Host
*shost
;
3259 struct lpfc_vport
*vport
;
3260 uint16_t offset
= 0;
3261 uint8_t *vport_buff
;
3262 struct lpfc_dmabuf
*mp
;
3263 uint32_t byte_count
= 0;
3265 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3267 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3268 "0542 lpfc_create_static_vport failed to"
3269 " allocate mailbox memory\n");
3275 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
3277 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3278 "0543 lpfc_create_static_vport failed to"
3279 " allocate vport_info\n");
3280 mempool_free(pmb
, phba
->mbox_mem_pool
);
3284 vport_buff
= (uint8_t *) vport_info
;
3286 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
3289 pmb
->vport
= phba
->pport
;
3290 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, LPFC_MBOX_TMO
);
3292 if ((rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
3293 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3294 "0544 lpfc_create_static_vport failed to"
3295 " issue dump mailbox command ret 0x%x "
3301 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3302 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
3303 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
3304 if (byte_count
> sizeof(struct static_vport_info
) -
3306 byte_count
= sizeof(struct static_vport_info
)
3308 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
3309 offset
+= byte_count
;
3311 if (mb
->un
.varDmp
.word_cnt
>
3312 sizeof(struct static_vport_info
) - offset
)
3313 mb
->un
.varDmp
.word_cnt
=
3314 sizeof(struct static_vport_info
)
3316 byte_count
= mb
->un
.varDmp
.word_cnt
;
3317 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
3318 vport_buff
+ offset
,
3321 offset
+= byte_count
;
3324 } while (byte_count
&&
3325 offset
< sizeof(struct static_vport_info
));
3328 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
3329 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
3330 != VPORT_INFO_REV
)) {
3331 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3332 "0545 lpfc_create_static_vport bad"
3333 " information header 0x%x 0x%x\n",
3334 le32_to_cpu(vport_info
->signature
),
3335 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
3340 shost
= lpfc_shost_from_vport(phba
->pport
);
3342 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
3343 memset(&vport_id
, 0, sizeof(vport_id
));
3344 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
3345 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
3346 if (!vport_id
.port_name
|| !vport_id
.node_name
)
3349 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
3350 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
3351 vport_id
.disable
= false;
3352 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
3354 if (!new_fc_vport
) {
3355 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
3356 "0546 lpfc_create_static_vport failed to"
3361 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
3362 vport
->vport_flag
|= STATIC_VPORT
;
3367 if (rc
!= MBX_TIMEOUT
) {
3368 if (pmb
->context2
) {
3369 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
3370 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3373 mempool_free(pmb
, phba
->mbox_mem_pool
);
3380 * This routine handles processing a Fabric REG_LOGIN mailbox
3381 * command upon completion. It is setup in the LPFC_MBOXQ
3382 * as the completion routine when the command is
3383 * handed off to the SLI layer.
3386 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3388 struct lpfc_vport
*vport
= pmb
->vport
;
3389 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3390 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3391 struct lpfc_nodelist
*ndlp
;
3393 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3394 pmb
->context1
= NULL
;
3395 pmb
->context2
= NULL
;
3397 if (mb
->mbxStatus
) {
3398 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
3399 "0258 Register Fabric login error: 0x%x\n",
3401 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3403 mempool_free(pmb
, phba
->mbox_mem_pool
);
3405 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3406 /* FLOGI failed, use loop map to make discovery list */
3407 lpfc_disc_list_loopmap(vport
);
3409 /* Start discovery */
3410 lpfc_disc_start(vport
);
3411 /* Decrement the reference count to ndlp after the
3412 * reference to the ndlp are done.
3418 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3419 /* Decrement the reference count to ndlp after the reference
3420 * to the ndlp are done.
3426 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3427 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
3428 ndlp
->nlp_type
|= NLP_FABRIC
;
3429 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3431 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3432 /* when physical port receive logo donot start
3433 * vport discovery */
3434 if (!(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
3435 lpfc_start_fdiscs(phba
);
3437 vport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
3438 lpfc_do_scr_ns_plogi(phba
, vport
);
3441 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3443 mempool_free(pmb
, phba
->mbox_mem_pool
);
3445 /* Drop the reference count from the mbox at the end after
3446 * all the current reference to the ndlp have been done.
3453 * This routine handles processing a NameServer REG_LOGIN mailbox
3454 * command upon completion. It is setup in the LPFC_MBOXQ
3455 * as the completion routine when the command is
3456 * handed off to the SLI layer.
3459 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3461 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3462 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3463 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3464 struct lpfc_vport
*vport
= pmb
->vport
;
3466 pmb
->context1
= NULL
;
3467 pmb
->context2
= NULL
;
3469 if (mb
->mbxStatus
) {
3471 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3472 "0260 Register NameServer error: 0x%x\n",
3474 /* decrement the node reference count held for this
3475 * callback function.
3478 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3480 mempool_free(pmb
, phba
->mbox_mem_pool
);
3482 /* If no other thread is using the ndlp, free it */
3483 lpfc_nlp_not_used(ndlp
);
3485 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
3487 * RegLogin failed, use loop map to make discovery
3490 lpfc_disc_list_loopmap(vport
);
3492 /* Start discovery */
3493 lpfc_disc_start(vport
);
3496 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3500 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3501 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
3502 ndlp
->nlp_type
|= NLP_FABRIC
;
3503 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3505 if (vport
->port_state
< LPFC_VPORT_READY
) {
3506 /* Link up discovery requires Fabric registration. */
3507 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
3508 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
3509 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
3510 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
3511 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
3513 /* Issue SCR just before NameServer GID_FT Query */
3514 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
3517 vport
->fc_ns_retry
= 0;
3518 /* Good status, issue CT Request to NameServer */
3519 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
3520 /* Cannot issue NameServer Query, so finish up discovery */
3524 /* decrement the node reference count held for this
3525 * callback function.
3528 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3530 mempool_free(pmb
, phba
->mbox_mem_pool
);
3536 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3538 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3539 struct fc_rport
*rport
;
3540 struct lpfc_rport_data
*rdata
;
3541 struct fc_rport_identifiers rport_ids
;
3542 struct lpfc_hba
*phba
= vport
->phba
;
3544 /* Remote port has reappeared. Re-register w/ FC transport */
3545 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
3546 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
3547 rport_ids
.port_id
= ndlp
->nlp_DID
;
3548 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
3551 * We leave our node pointer in rport->dd_data when we unregister a
3552 * FCP target port. But fc_remote_port_add zeros the space to which
3553 * rport->dd_data points. So, if we're reusing a previously
3554 * registered port, drop the reference that we took the last time we
3555 * registered the port.
3557 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
3558 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
3561 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
3562 "rport add: did:x%x flg:x%x type x%x",
3563 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3565 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
3566 if (!rport
|| !get_device(&rport
->dev
)) {
3567 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
3568 "Warning: fc_remote_port_add failed\n");
3572 /* initialize static port data */
3573 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
3574 rport
->supported_classes
= ndlp
->nlp_class_sup
;
3575 rdata
= rport
->dd_data
;
3576 rdata
->pnode
= lpfc_nlp_get(ndlp
);
3578 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
3579 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
3580 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
3581 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
3584 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
3585 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
3587 if ((rport
->scsi_target_id
!= -1) &&
3588 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
3589 ndlp
->nlp_sid
= rport
->scsi_target_id
;
3595 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
3597 struct fc_rport
*rport
= ndlp
->rport
;
3599 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
3600 "rport delete: did:x%x flg:x%x type x%x",
3601 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3603 fc_remote_port_delete(rport
);
3609 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
3611 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3613 spin_lock_irq(shost
->host_lock
);
3615 case NLP_STE_UNUSED_NODE
:
3616 vport
->fc_unused_cnt
+= count
;
3618 case NLP_STE_PLOGI_ISSUE
:
3619 vport
->fc_plogi_cnt
+= count
;
3621 case NLP_STE_ADISC_ISSUE
:
3622 vport
->fc_adisc_cnt
+= count
;
3624 case NLP_STE_REG_LOGIN_ISSUE
:
3625 vport
->fc_reglogin_cnt
+= count
;
3627 case NLP_STE_PRLI_ISSUE
:
3628 vport
->fc_prli_cnt
+= count
;
3630 case NLP_STE_UNMAPPED_NODE
:
3631 vport
->fc_unmap_cnt
+= count
;
3633 case NLP_STE_MAPPED_NODE
:
3634 vport
->fc_map_cnt
+= count
;
3636 case NLP_STE_NPR_NODE
:
3637 vport
->fc_npr_cnt
+= count
;
3640 spin_unlock_irq(shost
->host_lock
);
3644 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3645 int old_state
, int new_state
)
3647 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3649 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
3650 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
3651 ndlp
->nlp_type
|= NLP_FC_NODE
;
3653 if (new_state
== NLP_STE_MAPPED_NODE
)
3654 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
3655 if (new_state
== NLP_STE_NPR_NODE
)
3656 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
3658 /* Transport interface */
3659 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
3660 old_state
== NLP_STE_UNMAPPED_NODE
)) {
3661 vport
->phba
->nport_event_cnt
++;
3662 lpfc_unregister_remote_port(ndlp
);
3665 if (new_state
== NLP_STE_MAPPED_NODE
||
3666 new_state
== NLP_STE_UNMAPPED_NODE
) {
3667 vport
->phba
->nport_event_cnt
++;
3669 * Tell the fc transport about the port, if we haven't
3670 * already. If we have, and it's a scsi entity, be
3671 * sure to unblock any attached scsi devices
3673 lpfc_register_remote_port(vport
, ndlp
);
3675 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
3676 (vport
->stat_data_enabled
)) {
3678 * A new target is discovered, if there is no buffer for
3679 * statistical data collection allocate buffer.
3681 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
3682 sizeof(struct lpfc_scsicmd_bkt
),
3685 if (!ndlp
->lat_data
)
3686 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3687 "0286 lpfc_nlp_state_cleanup failed to "
3688 "allocate statistical data buffer DID "
3689 "0x%x\n", ndlp
->nlp_DID
);
3692 * if we added to Mapped list, but the remote port
3693 * registration failed or assigned a target id outside
3694 * our presentable range - move the node to the
3697 if (new_state
== NLP_STE_MAPPED_NODE
&&
3699 ndlp
->rport
->scsi_target_id
== -1 ||
3700 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
3701 spin_lock_irq(shost
->host_lock
);
3702 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
3703 spin_unlock_irq(shost
->host_lock
);
3704 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3709 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
3711 static char *states
[] = {
3712 [NLP_STE_UNUSED_NODE
] = "UNUSED",
3713 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
3714 [NLP_STE_ADISC_ISSUE
] = "ADISC",
3715 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
3716 [NLP_STE_PRLI_ISSUE
] = "PRLI",
3717 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
3718 [NLP_STE_MAPPED_NODE
] = "MAPPED",
3719 [NLP_STE_NPR_NODE
] = "NPR",
3722 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
3723 strlcpy(buffer
, states
[state
], size
);
3725 snprintf(buffer
, size
, "unknown (%d)", state
);
3730 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3733 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3734 int old_state
= ndlp
->nlp_state
;
3735 char name1
[16], name2
[16];
3737 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3738 "0904 NPort state transition x%06x, %s -> %s\n",
3740 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
3741 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
3743 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3744 "node statechg did:x%x old:%d ste:%d",
3745 ndlp
->nlp_DID
, old_state
, state
);
3747 if (old_state
== NLP_STE_NPR_NODE
&&
3748 state
!= NLP_STE_NPR_NODE
)
3749 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3750 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
3751 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
3752 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
3755 if (list_empty(&ndlp
->nlp_listp
)) {
3756 spin_lock_irq(shost
->host_lock
);
3757 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
3758 spin_unlock_irq(shost
->host_lock
);
3759 } else if (old_state
)
3760 lpfc_nlp_counters(vport
, old_state
, -1);
3762 ndlp
->nlp_state
= state
;
3763 lpfc_nlp_counters(vport
, state
, 1);
3764 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
3768 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3770 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3772 if (list_empty(&ndlp
->nlp_listp
)) {
3773 spin_lock_irq(shost
->host_lock
);
3774 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
3775 spin_unlock_irq(shost
->host_lock
);
3780 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3782 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3784 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3785 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
3786 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
3787 spin_lock_irq(shost
->host_lock
);
3788 list_del_init(&ndlp
->nlp_listp
);
3789 spin_unlock_irq(shost
->host_lock
);
3790 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
3791 NLP_STE_UNUSED_NODE
);
3795 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3797 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3798 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
3799 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
3800 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
3801 NLP_STE_UNUSED_NODE
);
3804 * lpfc_initialize_node - Initialize all fields of node object
3805 * @vport: Pointer to Virtual Port object.
3806 * @ndlp: Pointer to FC node object.
3807 * @did: FC_ID of the node.
3809 * This function is always called when node object need to be initialized.
3810 * It initializes all the fields of the node object. Although the reference
3811 * to phba from @ndlp can be obtained indirectly through it's reference to
3812 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3813 * to the life-span of the @ndlp might go beyond the existence of @vport as
3814 * the final release of ndlp is determined by its reference count. And, the
3815 * operation on @ndlp needs the reference to phba.
3818 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3821 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
3822 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
3823 init_timer(&ndlp
->nlp_delayfunc
);
3824 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
3825 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
3826 ndlp
->nlp_DID
= did
;
3827 ndlp
->vport
= vport
;
3828 ndlp
->phba
= vport
->phba
;
3829 ndlp
->nlp_sid
= NLP_NO_SID
;
3830 kref_init(&ndlp
->kref
);
3831 NLP_INT_NODE_ACT(ndlp
);
3832 atomic_set(&ndlp
->cmd_pending
, 0);
3833 ndlp
->cmd_qdepth
= vport
->cfg_tgt_queue_depth
;
3836 struct lpfc_nodelist
*
3837 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3840 struct lpfc_hba
*phba
= vport
->phba
;
3842 unsigned long flags
;
3847 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3848 /* The ndlp should not be in memory free mode */
3849 if (NLP_CHK_FREE_REQ(ndlp
)) {
3850 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3851 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3852 "0277 lpfc_enable_node: ndlp:x%p "
3853 "usgmap:x%x refcnt:%d\n",
3854 (void *)ndlp
, ndlp
->nlp_usg_map
,
3855 atomic_read(&ndlp
->kref
.refcount
));
3858 /* The ndlp should not already be in active mode */
3859 if (NLP_CHK_NODE_ACT(ndlp
)) {
3860 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3861 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3862 "0278 lpfc_enable_node: ndlp:x%p "
3863 "usgmap:x%x refcnt:%d\n",
3864 (void *)ndlp
, ndlp
->nlp_usg_map
,
3865 atomic_read(&ndlp
->kref
.refcount
));
3869 /* Keep the original DID */
3870 did
= ndlp
->nlp_DID
;
3872 /* re-initialize ndlp except of ndlp linked list pointer */
3873 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
3874 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
3875 lpfc_initialize_node(vport
, ndlp
, did
);
3877 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3879 if (state
!= NLP_STE_UNUSED_NODE
)
3880 lpfc_nlp_set_state(vport
, ndlp
, state
);
3882 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3883 "node enable: did:x%x",
3884 ndlp
->nlp_DID
, 0, 0);
3889 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3892 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
3893 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
3894 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3895 * until ALL other outstanding threads have completed. We check
3896 * that the ndlp not already in the UNUSED state before we proceed.
3898 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3900 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3906 * Start / ReStart rescue timer for Discovery / RSCN handling
3909 lpfc_set_disctmo(struct lpfc_vport
*vport
)
3911 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3912 struct lpfc_hba
*phba
= vport
->phba
;
3915 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3916 /* For FAN, timeout should be greater than edtov */
3917 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
3919 /* Normal discovery timeout should be > than ELS/CT timeout
3920 * FC spec states we need 3 * ratov for CT requests
3922 tmo
= ((phba
->fc_ratov
* 3) + 3);
3926 if (!timer_pending(&vport
->fc_disctmo
)) {
3927 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3928 "set disc timer: tmo:x%x state:x%x flg:x%x",
3929 tmo
, vport
->port_state
, vport
->fc_flag
);
3932 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
3933 spin_lock_irq(shost
->host_lock
);
3934 vport
->fc_flag
|= FC_DISC_TMO
;
3935 spin_unlock_irq(shost
->host_lock
);
3937 /* Start Discovery Timer state <hba_state> */
3938 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3939 "0247 Start Discovery Timer state x%x "
3940 "Data: x%x x%lx x%x x%x\n",
3941 vport
->port_state
, tmo
,
3942 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
3943 vport
->fc_adisc_cnt
);
3949 * Cancel rescue timer for Discovery / RSCN handling
3952 lpfc_can_disctmo(struct lpfc_vport
*vport
)
3954 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3955 unsigned long iflags
;
3957 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3958 "can disc timer: state:x%x rtry:x%x flg:x%x",
3959 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3961 /* Turn off discovery timer if its running */
3962 if (vport
->fc_flag
& FC_DISC_TMO
) {
3963 spin_lock_irqsave(shost
->host_lock
, iflags
);
3964 vport
->fc_flag
&= ~FC_DISC_TMO
;
3965 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3966 del_timer_sync(&vport
->fc_disctmo
);
3967 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
3968 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
3969 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
3972 /* Cancel Discovery Timer state <hba_state> */
3973 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3974 "0248 Cancel Discovery Timer state x%x "
3975 "Data: x%x x%x x%x\n",
3976 vport
->port_state
, vport
->fc_flag
,
3977 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
3982 * Check specified ring for outstanding IOCB on the SLI queue
3983 * Return true if iocb matches the specified nport
3986 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
3987 struct lpfc_sli_ring
*pring
,
3988 struct lpfc_iocbq
*iocb
,
3989 struct lpfc_nodelist
*ndlp
)
3991 struct lpfc_sli
*psli
= &phba
->sli
;
3992 IOCB_t
*icmd
= &iocb
->iocb
;
3993 struct lpfc_vport
*vport
= ndlp
->vport
;
3995 if (iocb
->vport
!= vport
)
3998 if (pring
->ringno
== LPFC_ELS_RING
) {
3999 switch (icmd
->ulpCommand
) {
4000 case CMD_GEN_REQUEST64_CR
:
4001 if (iocb
->context_un
.ndlp
== ndlp
)
4003 case CMD_ELS_REQUEST64_CR
:
4004 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
4006 case CMD_XMIT_ELS_RSP64_CX
:
4007 if (iocb
->context1
== (uint8_t *) ndlp
)
4010 } else if (pring
->ringno
== psli
->extra_ring
) {
4012 } else if (pring
->ringno
== psli
->fcp_ring
) {
4013 /* Skip match check if waiting to relogin to FCP target */
4014 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4015 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
4018 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
4021 } else if (pring
->ringno
== psli
->next_ring
) {
4028 * Free resources / clean up outstanding I/Os
4029 * associated with nlp_rpi in the LPFC_NODELIST entry.
4032 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4034 LIST_HEAD(completions
);
4035 struct lpfc_sli
*psli
;
4036 struct lpfc_sli_ring
*pring
;
4037 struct lpfc_iocbq
*iocb
, *next_iocb
;
4040 lpfc_fabric_abort_nport(ndlp
);
4043 * Everything that matches on txcmplq will be returned
4044 * by firmware with a no rpi error.
4047 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
4048 /* Now process each ring */
4049 for (i
= 0; i
< psli
->num_rings
; i
++) {
4050 pring
= &psli
->ring
[i
];
4052 spin_lock_irq(&phba
->hbalock
);
4053 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
4056 * Check to see if iocb matches the nport we are
4059 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
4061 /* It matches, so deque and call compl
4063 list_move_tail(&iocb
->list
,
4068 spin_unlock_irq(&phba
->hbalock
);
4072 /* Cancel all the IOCBs from the completions list */
4073 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4080 * Free rpi associated with LPFC_NODELIST entry.
4081 * This routine is called from lpfc_freenode(), when we are removing
4082 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4083 * LOGO that completes successfully, and we are waiting to PLOGI back
4084 * to the remote NPort. In addition, it is called after we receive
4085 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4086 * we are waiting to PLOGI back to the remote NPort.
4089 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4091 struct lpfc_hba
*phba
= vport
->phba
;
4095 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
4096 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4098 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
4099 mbox
->vport
= vport
;
4100 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4101 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4102 if (rc
== MBX_NOT_FINISHED
)
4103 mempool_free(mbox
, phba
->mbox_mem_pool
);
4105 lpfc_no_rpi(phba
, ndlp
);
4108 ndlp
->nlp_flag
&= ~NLP_RPI_VALID
;
4109 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4116 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4117 * @phba: pointer to lpfc hba data structure.
4119 * This routine is invoked to unregister all the currently registered RPIs
4123 lpfc_unreg_hba_rpis(struct lpfc_hba
*phba
)
4125 struct lpfc_vport
**vports
;
4126 struct lpfc_nodelist
*ndlp
;
4127 struct Scsi_Host
*shost
;
4130 vports
= lpfc_create_vport_work_array(phba
);
4132 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
4133 "2884 Vport array allocation failed \n");
4136 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4137 shost
= lpfc_shost_from_vport(vports
[i
]);
4138 spin_lock_irq(shost
->host_lock
);
4139 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4140 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
4141 /* The mempool_alloc might sleep */
4142 spin_unlock_irq(shost
->host_lock
);
4143 lpfc_unreg_rpi(vports
[i
], ndlp
);
4144 spin_lock_irq(shost
->host_lock
);
4147 spin_unlock_irq(shost
->host_lock
);
4149 lpfc_destroy_vport_work_array(phba
, vports
);
4153 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
4155 struct lpfc_hba
*phba
= vport
->phba
;
4159 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4160 lpfc_sli4_unreg_all_rpis(vport
);
4164 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4166 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
4167 mbox
->vport
= vport
;
4168 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4169 mbox
->context1
= NULL
;
4170 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4171 if (rc
!= MBX_TIMEOUT
)
4172 mempool_free(mbox
, phba
->mbox_mem_pool
);
4174 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
4175 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
4176 "1836 Could not issue "
4177 "unreg_login(all_rpis) status %d\n", rc
);
4182 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
4184 struct lpfc_hba
*phba
= vport
->phba
;
4188 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4190 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
4191 mbox
->vport
= vport
;
4192 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4193 mbox
->context1
= NULL
;
4194 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
4195 if (rc
!= MBX_TIMEOUT
)
4196 mempool_free(mbox
, phba
->mbox_mem_pool
);
4198 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
4199 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
4200 "1815 Could not issue "
4201 "unreg_did (default rpis) status %d\n",
4207 * Free resources associated with LPFC_NODELIST entry
4208 * so it can be freed.
4211 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4213 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4214 struct lpfc_hba
*phba
= vport
->phba
;
4215 LPFC_MBOXQ_t
*mb
, *nextmb
;
4216 struct lpfc_dmabuf
*mp
;
4218 /* Cleanup node for NPort <nlp_DID> */
4219 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4220 "0900 Cleanup node for NPort x%x "
4221 "Data: x%x x%x x%x\n",
4222 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4223 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
4224 if (NLP_CHK_FREE_REQ(ndlp
)) {
4225 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4226 "0280 lpfc_cleanup_node: ndlp:x%p "
4227 "usgmap:x%x refcnt:%d\n",
4228 (void *)ndlp
, ndlp
->nlp_usg_map
,
4229 atomic_read(&ndlp
->kref
.refcount
));
4230 lpfc_dequeue_node(vport
, ndlp
);
4232 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
4233 "0281 lpfc_cleanup_node: ndlp:x%p "
4234 "usgmap:x%x refcnt:%d\n",
4235 (void *)ndlp
, ndlp
->nlp_usg_map
,
4236 atomic_read(&ndlp
->kref
.refcount
));
4237 lpfc_disable_node(vport
, ndlp
);
4240 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4241 if ((mb
= phba
->sli
.mbox_active
)) {
4242 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
4243 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
4244 mb
->context2
= NULL
;
4245 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4249 spin_lock_irq(&phba
->hbalock
);
4250 /* Cleanup REG_LOGIN completions which are not yet processed */
4251 list_for_each_entry(mb
, &phba
->sli
.mboxq_cmpl
, list
) {
4252 if ((mb
->u
.mb
.mbxCommand
!= MBX_REG_LOGIN64
) ||
4253 (ndlp
!= (struct lpfc_nodelist
*) mb
->context2
))
4256 mb
->context2
= NULL
;
4257 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4260 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
4261 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
4262 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
4263 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
4265 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4268 list_del(&mb
->list
);
4269 if (phba
->sli_rev
== LPFC_SLI_REV4
)
4270 lpfc_sli4_free_rpi(phba
,
4271 mb
->u
.mb
.un
.varRegLogin
.rpi
);
4272 mempool_free(mb
, phba
->mbox_mem_pool
);
4273 /* We shall not invoke the lpfc_nlp_put to decrement
4274 * the ndlp reference count as we are in the process
4275 * of lpfc_nlp_release.
4279 spin_unlock_irq(&phba
->hbalock
);
4281 lpfc_els_abort(phba
, ndlp
);
4283 spin_lock_irq(shost
->host_lock
);
4284 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
4285 spin_unlock_irq(shost
->host_lock
);
4287 ndlp
->nlp_last_elscmd
= 0;
4288 del_timer_sync(&ndlp
->nlp_delayfunc
);
4290 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
4291 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
4293 lpfc_unreg_rpi(vport
, ndlp
);
4299 * Check to see if we can free the nlp back to the freelist.
4300 * If we are in the middle of using the nlp in the discovery state
4301 * machine, defer the free till we reach the end of the state machine.
4304 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4306 struct lpfc_hba
*phba
= vport
->phba
;
4307 struct lpfc_rport_data
*rdata
;
4311 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4312 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
4313 !(ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
) &&
4314 !(ndlp
->nlp_flag
& NLP_RPI_VALID
)) {
4315 /* For this case we need to cleanup the default rpi
4316 * allocated by the firmware.
4318 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
4320 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
4321 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
4323 mempool_free(mbox
, phba
->mbox_mem_pool
);
4326 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
4327 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
4328 mbox
->vport
= vport
;
4329 mbox
->context2
= NULL
;
4330 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4331 if (rc
== MBX_NOT_FINISHED
) {
4332 mempool_free(mbox
, phba
->mbox_mem_pool
);
4337 lpfc_cleanup_node(vport
, ndlp
);
4340 * We can get here with a non-NULL ndlp->rport because when we
4341 * unregister a rport we don't break the rport/node linkage. So if we
4342 * do, make sure we don't leaving any dangling pointers behind.
4345 rdata
= ndlp
->rport
->dd_data
;
4346 rdata
->pnode
= NULL
;
4352 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4355 D_ID mydid
, ndlpdid
, matchdid
;
4357 if (did
== Bcast_DID
)
4360 /* First check for Direct match */
4361 if (ndlp
->nlp_DID
== did
)
4364 /* Next check for area/domain identically equals 0 match */
4365 mydid
.un
.word
= vport
->fc_myDID
;
4366 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
4370 matchdid
.un
.word
= did
;
4371 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
4372 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
4373 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
4374 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
4375 if ((ndlpdid
.un
.b
.domain
== 0) &&
4376 (ndlpdid
.un
.b
.area
== 0)) {
4377 if (ndlpdid
.un
.b
.id
)
4383 matchdid
.un
.word
= ndlp
->nlp_DID
;
4384 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
4385 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
4386 if ((matchdid
.un
.b
.domain
== 0) &&
4387 (matchdid
.un
.b
.area
== 0)) {
4388 if (matchdid
.un
.b
.id
)
4396 /* Search for a nodelist entry */
4397 static struct lpfc_nodelist
*
4398 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
4400 struct lpfc_nodelist
*ndlp
;
4403 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4404 if (lpfc_matchdid(vport
, ndlp
, did
)) {
4405 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
4406 ((uint32_t) ndlp
->nlp_xri
<< 16) |
4407 ((uint32_t) ndlp
->nlp_type
<< 8) |
4408 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
4409 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4410 "0929 FIND node DID "
4411 "Data: x%p x%x x%x x%x\n",
4412 ndlp
, ndlp
->nlp_DID
,
4413 ndlp
->nlp_flag
, data1
);
4418 /* FIND node did <did> NOT FOUND */
4419 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
4420 "0932 FIND node did x%x NOT FOUND.\n", did
);
4424 struct lpfc_nodelist
*
4425 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
4427 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4428 struct lpfc_nodelist
*ndlp
;
4430 spin_lock_irq(shost
->host_lock
);
4431 ndlp
= __lpfc_findnode_did(vport
, did
);
4432 spin_unlock_irq(shost
->host_lock
);
4436 struct lpfc_nodelist
*
4437 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
4439 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4440 struct lpfc_nodelist
*ndlp
;
4442 ndlp
= lpfc_findnode_did(vport
, did
);
4444 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
4445 lpfc_rscn_payload_check(vport
, did
) == 0)
4447 ndlp
= (struct lpfc_nodelist
*)
4448 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
4451 lpfc_nlp_init(vport
, ndlp
, did
);
4452 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4453 spin_lock_irq(shost
->host_lock
);
4454 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4455 spin_unlock_irq(shost
->host_lock
);
4457 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4458 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
4461 spin_lock_irq(shost
->host_lock
);
4462 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4463 spin_unlock_irq(shost
->host_lock
);
4467 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
4468 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
4469 if (lpfc_rscn_payload_check(vport
, did
)) {
4470 /* If we've already recieved a PLOGI from this NPort
4471 * we don't need to try to discover it again.
4473 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
4476 /* Since this node is marked for discovery,
4477 * delay timeout is not needed.
4479 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4480 spin_lock_irq(shost
->host_lock
);
4481 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4482 spin_unlock_irq(shost
->host_lock
);
4486 /* If we've already recieved a PLOGI from this NPort,
4487 * or we are already in the process of discovery on it,
4488 * we don't need to try to discover it again.
4490 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
4491 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
4492 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
4494 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4495 spin_lock_irq(shost
->host_lock
);
4496 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4497 spin_unlock_irq(shost
->host_lock
);
4502 /* Build a list of nodes to discover based on the loopmap */
4504 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
4506 struct lpfc_hba
*phba
= vport
->phba
;
4508 uint32_t alpa
, index
;
4510 if (!lpfc_is_link_up(phba
))
4513 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
4516 /* Check for loop map present or not */
4517 if (phba
->alpa_map
[0]) {
4518 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
4519 alpa
= phba
->alpa_map
[j
];
4520 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
4522 lpfc_setup_disc_node(vport
, alpa
);
4525 /* No alpamap, so try all alpa's */
4526 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
4527 /* If cfg_scan_down is set, start from highest
4528 * ALPA (0xef) to lowest (0x1).
4530 if (vport
->cfg_scan_down
)
4533 index
= FC_MAXLOOP
- j
- 1;
4534 alpa
= lpfcAlpaArray
[index
];
4535 if ((vport
->fc_myDID
& 0xff) == alpa
)
4537 lpfc_setup_disc_node(vport
, alpa
);
4544 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4547 struct lpfc_sli
*psli
= &phba
->sli
;
4548 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
4549 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
4550 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
4554 * if it's not a physical port or if we already send
4555 * clear_la then don't send it.
4557 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
4558 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
4559 (phba
->sli_rev
== LPFC_SLI_REV4
))
4562 /* Link up discovery */
4563 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
4564 phba
->link_state
= LPFC_CLEAR_LA
;
4565 lpfc_clear_la(phba
, mbox
);
4566 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
4567 mbox
->vport
= vport
;
4568 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4569 if (rc
== MBX_NOT_FINISHED
) {
4570 mempool_free(mbox
, phba
->mbox_mem_pool
);
4571 lpfc_disc_flush_list(vport
);
4572 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4573 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4574 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4575 phba
->link_state
= LPFC_HBA_ERROR
;
4580 /* Reg_vpi to tell firmware to resume normal operations */
4582 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4584 LPFC_MBOXQ_t
*regvpimbox
;
4586 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4588 lpfc_reg_vpi(vport
, regvpimbox
);
4589 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
4590 regvpimbox
->vport
= vport
;
4591 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
4592 == MBX_NOT_FINISHED
) {
4593 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
4598 /* Start Link up / RSCN discovery on NPR nodes */
4600 lpfc_disc_start(struct lpfc_vport
*vport
)
4602 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4603 struct lpfc_hba
*phba
= vport
->phba
;
4605 uint32_t clear_la_pending
;
4608 if (!lpfc_is_link_up(phba
))
4611 if (phba
->link_state
== LPFC_CLEAR_LA
)
4612 clear_la_pending
= 1;
4614 clear_la_pending
= 0;
4616 if (vport
->port_state
< LPFC_VPORT_READY
)
4617 vport
->port_state
= LPFC_DISC_AUTH
;
4619 lpfc_set_disctmo(vport
);
4621 if (vport
->fc_prevDID
== vport
->fc_myDID
)
4626 vport
->fc_prevDID
= vport
->fc_myDID
;
4627 vport
->num_disc_nodes
= 0;
4629 /* Start Discovery state <hba_state> */
4630 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4631 "0202 Start Discovery hba state x%x "
4632 "Data: x%x x%x x%x\n",
4633 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
4634 vport
->fc_adisc_cnt
);
4636 /* First do ADISCs - if any */
4637 num_sent
= lpfc_els_disc_adisc(vport
);
4643 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4644 * continue discovery.
4646 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4647 !(vport
->fc_flag
& FC_PT2PT
) &&
4648 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
4649 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
4650 lpfc_issue_reg_vpi(phba
, vport
);
4655 * For SLI2, we need to set port_state to READY and continue
4658 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
4659 /* If we get here, there is nothing to ADISC */
4660 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
4661 lpfc_issue_clear_la(phba
, vport
);
4663 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
4664 vport
->num_disc_nodes
= 0;
4665 /* go thru NPR nodes and issue ELS PLOGIs */
4666 if (vport
->fc_npr_cnt
)
4667 lpfc_els_disc_plogi(vport
);
4669 if (!vport
->num_disc_nodes
) {
4670 spin_lock_irq(shost
->host_lock
);
4671 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
4672 spin_unlock_irq(shost
->host_lock
);
4673 lpfc_can_disctmo(vport
);
4676 vport
->port_state
= LPFC_VPORT_READY
;
4678 /* Next do PLOGIs - if any */
4679 num_sent
= lpfc_els_disc_plogi(vport
);
4684 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4685 /* Check to see if more RSCNs came in while we
4686 * were processing this one.
4688 if ((vport
->fc_rscn_id_cnt
== 0) &&
4689 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
4690 spin_lock_irq(shost
->host_lock
);
4691 vport
->fc_flag
&= ~FC_RSCN_MODE
;
4692 spin_unlock_irq(shost
->host_lock
);
4693 lpfc_can_disctmo(vport
);
4695 lpfc_els_handle_rscn(vport
);
4702 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4703 * ring the match the sppecified nodelist.
4706 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4708 LIST_HEAD(completions
);
4709 struct lpfc_sli
*psli
;
4711 struct lpfc_iocbq
*iocb
, *next_iocb
;
4712 struct lpfc_sli_ring
*pring
;
4715 pring
= &psli
->ring
[LPFC_ELS_RING
];
4717 /* Error matching iocb on txq or txcmplq
4718 * First check the txq.
4720 spin_lock_irq(&phba
->hbalock
);
4721 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
4722 if (iocb
->context1
!= ndlp
) {
4726 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
4727 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
4729 list_move_tail(&iocb
->list
, &completions
);
4734 /* Next check the txcmplq */
4735 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
4736 if (iocb
->context1
!= ndlp
) {
4740 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
4741 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
4742 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
4745 spin_unlock_irq(&phba
->hbalock
);
4747 /* Cancel all the IOCBs from the completions list */
4748 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4753 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
4755 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4756 struct lpfc_hba
*phba
= vport
->phba
;
4758 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
4759 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
4761 if (!NLP_CHK_NODE_ACT(ndlp
))
4763 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
4764 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
4765 lpfc_free_tx(phba
, ndlp
);
4772 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
4774 lpfc_els_flush_rscn(vport
);
4775 lpfc_els_flush_cmd(vport
);
4776 lpfc_disc_flush_list(vport
);
4779 /*****************************************************************************/
4781 * NAME: lpfc_disc_timeout
4783 * FUNCTION: Fibre Channel driver discovery timeout routine.
4785 * EXECUTION ENVIRONMENT: interrupt only
4793 /*****************************************************************************/
4795 lpfc_disc_timeout(unsigned long ptr
)
4797 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
4798 struct lpfc_hba
*phba
= vport
->phba
;
4799 uint32_t tmo_posted
;
4800 unsigned long flags
= 0;
4802 if (unlikely(!phba
))
4805 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
4806 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
4808 vport
->work_port_events
|= WORKER_DISC_TMO
;
4809 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
4812 lpfc_worker_wake_up(phba
);
4817 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
4819 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4820 struct lpfc_hba
*phba
= vport
->phba
;
4821 struct lpfc_sli
*psli
= &phba
->sli
;
4822 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4823 LPFC_MBOXQ_t
*initlinkmbox
;
4824 int rc
, clrlaerr
= 0;
4826 if (!(vport
->fc_flag
& FC_DISC_TMO
))
4829 spin_lock_irq(shost
->host_lock
);
4830 vport
->fc_flag
&= ~FC_DISC_TMO
;
4831 spin_unlock_irq(shost
->host_lock
);
4833 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4834 "disc timeout: state:x%x rtry:x%x flg:x%x",
4835 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
4837 switch (vport
->port_state
) {
4839 case LPFC_LOCAL_CFG_LINK
:
4840 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4844 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
4845 "0221 FAN timeout\n");
4846 /* Start discovery by sending FLOGI, clean up old rpis */
4847 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
4849 if (!NLP_CHK_NODE_ACT(ndlp
))
4851 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
4853 if (ndlp
->nlp_type
& NLP_FABRIC
) {
4854 /* Clean up the ndlp on Fabric connections */
4855 lpfc_drop_node(vport
, ndlp
);
4857 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
4858 /* Fail outstanding IO now since device
4859 * is marked for PLOGI.
4861 lpfc_unreg_rpi(vport
, ndlp
);
4864 if (vport
->port_state
!= LPFC_FLOGI
) {
4865 if (phba
->sli_rev
<= LPFC_SLI_REV3
)
4866 lpfc_initial_flogi(vport
);
4868 lpfc_issue_init_vfi(vport
);
4875 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
4876 /* Initial FLOGI timeout */
4877 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4878 "0222 Initial %s timeout\n",
4879 vport
->vpi
? "FDISC" : "FLOGI");
4881 /* Assume no Fabric and go on with discovery.
4882 * Check for outstanding ELS FLOGI to abort.
4885 /* FLOGI failed, so just use loop map to make discovery list */
4886 lpfc_disc_list_loopmap(vport
);
4888 /* Start discovery */
4889 lpfc_disc_start(vport
);
4892 case LPFC_FABRIC_CFG_LINK
:
4893 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4895 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4896 "0223 Timeout while waiting for "
4897 "NameServer login\n");
4898 /* Next look for NameServer ndlp */
4899 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4900 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4901 lpfc_els_abort(phba
, ndlp
);
4903 /* ReStart discovery */
4907 /* Check for wait for NameServer Rsp timeout */
4908 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4909 "0224 NameServer Query timeout "
4911 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4913 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
4914 /* Try it one more time */
4915 vport
->fc_ns_retry
++;
4916 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
4917 vport
->fc_ns_retry
, 0);
4921 vport
->fc_ns_retry
= 0;
4925 * Discovery is over.
4926 * set port_state to PORT_READY if SLI2.
4927 * cmpl_reg_vpi will set port_state to READY for SLI3.
4929 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4930 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4931 lpfc_issue_reg_vpi(phba
, vport
);
4932 else { /* NPIV Not enabled */
4933 lpfc_issue_clear_la(phba
, vport
);
4934 vport
->port_state
= LPFC_VPORT_READY
;
4938 /* Setup and issue mailbox INITIALIZE LINK command */
4939 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4940 if (!initlinkmbox
) {
4941 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4942 "0206 Device Discovery "
4943 "completion error\n");
4944 phba
->link_state
= LPFC_HBA_ERROR
;
4948 lpfc_linkdown(phba
);
4949 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
4950 phba
->cfg_link_speed
);
4951 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4952 initlinkmbox
->vport
= vport
;
4953 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4954 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
4955 lpfc_set_loopback_flag(phba
);
4956 if (rc
== MBX_NOT_FINISHED
)
4957 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
4961 case LPFC_DISC_AUTH
:
4962 /* Node Authentication timeout */
4963 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4964 "0227 Node Authentication timeout\n");
4965 lpfc_disc_flush_list(vport
);
4968 * set port_state to PORT_READY if SLI2.
4969 * cmpl_reg_vpi will set port_state to READY for SLI3.
4971 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4972 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4973 lpfc_issue_reg_vpi(phba
, vport
);
4974 else { /* NPIV Not enabled */
4975 lpfc_issue_clear_la(phba
, vport
);
4976 vport
->port_state
= LPFC_VPORT_READY
;
4981 case LPFC_VPORT_READY
:
4982 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4983 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4984 "0231 RSCN timeout Data: x%x "
4986 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4988 /* Cleanup any outstanding ELS commands */
4989 lpfc_els_flush_cmd(vport
);
4991 lpfc_els_flush_rscn(vport
);
4992 lpfc_disc_flush_list(vport
);
4997 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4998 "0273 Unexpected discovery timeout, "
4999 "vport State x%x\n", vport
->port_state
);
5003 switch (phba
->link_state
) {
5005 /* CLEAR LA timeout */
5006 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5007 "0228 CLEAR LA timeout\n");
5012 lpfc_issue_clear_la(phba
, vport
);
5014 case LPFC_LINK_UNKNOWN
:
5015 case LPFC_WARM_START
:
5016 case LPFC_INIT_START
:
5017 case LPFC_INIT_MBX_CMDS
:
5018 case LPFC_LINK_DOWN
:
5019 case LPFC_HBA_ERROR
:
5020 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
5021 "0230 Unexpected timeout, hba link "
5022 "state x%x\n", phba
->link_state
);
5026 case LPFC_HBA_READY
:
5031 lpfc_disc_flush_list(vport
);
5032 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
5033 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
5034 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
5035 vport
->port_state
= LPFC_VPORT_READY
;
5042 * This routine handles processing a NameServer REG_LOGIN mailbox
5043 * command upon completion. It is setup in the LPFC_MBOXQ
5044 * as the completion routine when the command is
5045 * handed off to the SLI layer.
5048 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5050 MAILBOX_t
*mb
= &pmb
->u
.mb
;
5051 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
5052 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5053 struct lpfc_vport
*vport
= pmb
->vport
;
5055 pmb
->context1
= NULL
;
5056 pmb
->context2
= NULL
;
5058 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
5059 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
5060 ndlp
->nlp_type
|= NLP_FABRIC
;
5061 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
5064 * Start issuing Fabric-Device Management Interface (FDMI) command to
5065 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5066 * fdmi-on=2 (supporting RPA/hostnmae)
5069 if (vport
->cfg_fdmi_on
== 1)
5070 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
5072 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
5074 /* decrement the node reference count held for this callback
5078 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
5080 mempool_free(pmb
, phba
->mbox_mem_pool
);
5086 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
5088 uint16_t *rpi
= param
;
5090 return ndlp
->nlp_rpi
== *rpi
;
5094 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
5096 return memcmp(&ndlp
->nlp_portname
, param
,
5097 sizeof(ndlp
->nlp_portname
)) == 0;
5100 static struct lpfc_nodelist
*
5101 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
5103 struct lpfc_nodelist
*ndlp
;
5105 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5106 if (filter(ndlp
, param
))
5113 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5114 * returns the node list element pointer else return NULL.
5116 struct lpfc_nodelist
*
5117 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
5119 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
5123 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5124 * returns the node element list pointer else return NULL.
5126 struct lpfc_nodelist
*
5127 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
5129 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5130 struct lpfc_nodelist
*ndlp
;
5132 spin_lock_irq(shost
->host_lock
);
5133 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
5134 spin_unlock_irq(shost
->host_lock
);
5139 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5142 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
5144 lpfc_initialize_node(vport
, ndlp
, did
);
5145 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
5147 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
5148 "node init: did:x%x",
5149 ndlp
->nlp_DID
, 0, 0);
5154 /* This routine releases all resources associated with a specifc NPort's ndlp
5155 * and mempool_free's the nodelist.
5158 lpfc_nlp_release(struct kref
*kref
)
5160 struct lpfc_hba
*phba
;
5161 unsigned long flags
;
5162 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
5165 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
5166 "node release: did:x%x flg:x%x type:x%x",
5167 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
5169 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
5170 "0279 lpfc_nlp_release: ndlp:x%p "
5171 "usgmap:x%x refcnt:%d\n",
5172 (void *)ndlp
, ndlp
->nlp_usg_map
,
5173 atomic_read(&ndlp
->kref
.refcount
));
5175 /* remove ndlp from action. */
5176 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
5178 /* clear the ndlp active flag for all release cases */
5180 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
5181 NLP_CLR_NODE_ACT(ndlp
);
5182 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5184 /* free ndlp memory for final ndlp release */
5185 if (NLP_CHK_FREE_REQ(ndlp
)) {
5186 kfree(ndlp
->lat_data
);
5187 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
5191 /* This routine bumps the reference count for a ndlp structure to ensure
5192 * that one discovery thread won't free a ndlp while another discovery thread
5195 struct lpfc_nodelist
*
5196 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
5198 struct lpfc_hba
*phba
;
5199 unsigned long flags
;
5202 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
5203 "node get: did:x%x flg:x%x refcnt:x%x",
5204 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5205 atomic_read(&ndlp
->kref
.refcount
));
5206 /* The check of ndlp usage to prevent incrementing the
5207 * ndlp reference count that is in the process of being
5211 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
5212 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
5213 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5214 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
5215 "0276 lpfc_nlp_get: ndlp:x%p "
5216 "usgmap:x%x refcnt:%d\n",
5217 (void *)ndlp
, ndlp
->nlp_usg_map
,
5218 atomic_read(&ndlp
->kref
.refcount
));
5221 kref_get(&ndlp
->kref
);
5222 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5227 /* This routine decrements the reference count for a ndlp structure. If the
5228 * count goes to 0, this indicates the the associated nodelist should be
5229 * freed. Returning 1 indicates the ndlp resource has been released; on the
5230 * other hand, returning 0 indicates the ndlp resource has not been released
5234 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
5236 struct lpfc_hba
*phba
;
5237 unsigned long flags
;
5242 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
5243 "node put: did:x%x flg:x%x refcnt:x%x",
5244 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5245 atomic_read(&ndlp
->kref
.refcount
));
5247 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
5248 /* Check the ndlp memory free acknowledge flag to avoid the
5249 * possible race condition that kref_put got invoked again
5250 * after previous one has done ndlp memory free.
5252 if (NLP_CHK_FREE_ACK(ndlp
)) {
5253 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5254 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
5255 "0274 lpfc_nlp_put: ndlp:x%p "
5256 "usgmap:x%x refcnt:%d\n",
5257 (void *)ndlp
, ndlp
->nlp_usg_map
,
5258 atomic_read(&ndlp
->kref
.refcount
));
5261 /* Check the ndlp inactivate log flag to avoid the possible
5262 * race condition that kref_put got invoked again after ndlp
5263 * is already in inactivating state.
5265 if (NLP_CHK_IACT_REQ(ndlp
)) {
5266 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5267 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
5268 "0275 lpfc_nlp_put: ndlp:x%p "
5269 "usgmap:x%x refcnt:%d\n",
5270 (void *)ndlp
, ndlp
->nlp_usg_map
,
5271 atomic_read(&ndlp
->kref
.refcount
));
5274 /* For last put, mark the ndlp usage flags to make sure no
5275 * other kref_get and kref_put on the same ndlp shall get
5276 * in between the process when the final kref_put has been
5277 * invoked on this ndlp.
5279 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
5280 /* Indicate ndlp is put to inactive state. */
5281 NLP_SET_IACT_REQ(ndlp
);
5282 /* Acknowledge ndlp memory free has been seen. */
5283 if (NLP_CHK_FREE_REQ(ndlp
))
5284 NLP_SET_FREE_ACK(ndlp
);
5286 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
5287 /* Note, the kref_put returns 1 when decrementing a reference
5288 * count that was 1, it invokes the release callback function,
5289 * but it still left the reference count as 1 (not actually
5290 * performs the last decrementation). Otherwise, it actually
5291 * decrements the reference count and returns 0.
5293 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
5296 /* This routine free's the specified nodelist if it is not in use
5297 * by any other discovery thread. This routine returns 1 if the
5298 * ndlp has been freed. A return value of 0 indicates the ndlp is
5299 * not yet been released.
5302 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
5304 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
5305 "node not used: did:x%x flg:x%x refcnt:x%x",
5306 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5307 atomic_read(&ndlp
->kref
.refcount
));
5308 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
5309 if (lpfc_nlp_put(ndlp
))
5315 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5316 * @phba: Pointer to hba context object.
5318 * This function iterate through all FC nodes associated
5319 * will all vports to check if there is any node with
5320 * fc_rports associated with it. If there is an fc_rport
5321 * associated with the node, then the node is either in
5322 * discovered state or its devloss_timer is pending.
5325 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
5327 struct lpfc_vport
**vports
;
5329 struct lpfc_nodelist
*ndlp
;
5330 struct Scsi_Host
*shost
;
5332 vports
= lpfc_create_vport_work_array(phba
);
5334 /* If driver cannot allocate memory, indicate fcf is in use */
5338 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
5339 shost
= lpfc_shost_from_vport(vports
[i
]);
5340 spin_lock_irq(shost
->host_lock
);
5341 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
5342 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
5343 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
5345 spin_unlock_irq(shost
->host_lock
);
5348 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
5349 "2624 RPI %x DID %x flg %x still "
5351 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
5353 if (ndlp
->nlp_flag
& NLP_RPI_VALID
)
5357 spin_unlock_irq(shost
->host_lock
);
5360 lpfc_destroy_vport_work_array(phba
, vports
);
5365 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5366 * @phba: Pointer to hba context object.
5367 * @mboxq: Pointer to mailbox object.
5369 * This function frees memory associated with the mailbox command.
5372 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5374 struct lpfc_vport
*vport
= mboxq
->vport
;
5375 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5377 if (mboxq
->u
.mb
.mbxStatus
) {
5378 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5379 "2555 UNREG_VFI mbxStatus error x%x "
5381 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
5383 spin_lock_irq(shost
->host_lock
);
5384 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
5385 spin_unlock_irq(shost
->host_lock
);
5386 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5391 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5392 * @phba: Pointer to hba context object.
5393 * @mboxq: Pointer to mailbox object.
5395 * This function frees memory associated with the mailbox command.
5398 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
5400 struct lpfc_vport
*vport
= mboxq
->vport
;
5402 if (mboxq
->u
.mb
.mbxStatus
) {
5403 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5404 "2550 UNREG_FCFI mbxStatus error x%x "
5406 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
5408 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5413 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
5414 * @phba: Pointer to hba context object.
5416 * This function prepare the HBA for unregistering the currently registered
5417 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5421 lpfc_unregister_fcf_prep(struct lpfc_hba
*phba
)
5424 struct lpfc_vport
**vports
;
5425 struct lpfc_nodelist
*ndlp
;
5426 struct Scsi_Host
*shost
;
5429 /* Unregister RPIs */
5430 if (lpfc_fcf_inuse(phba
))
5431 lpfc_unreg_hba_rpis(phba
);
5433 /* At this point, all discovery is aborted */
5434 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
5436 /* Unregister VPIs */
5437 vports
= lpfc_create_vport_work_array(phba
);
5438 if (vports
&& (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
5439 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
5440 /* Stop FLOGI/FDISC retries */
5441 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
5443 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
5444 lpfc_cleanup_pending_mbox(vports
[i
]);
5445 if (phba
->sli_rev
== LPFC_SLI_REV4
)
5446 lpfc_sli4_unreg_all_rpis(vports
[i
]);
5447 lpfc_mbx_unreg_vpi(vports
[i
]);
5448 shost
= lpfc_shost_from_vport(vports
[i
]);
5449 spin_lock_irq(shost
->host_lock
);
5450 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
5451 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
5452 spin_unlock_irq(shost
->host_lock
);
5454 lpfc_destroy_vport_work_array(phba
, vports
);
5456 /* Cleanup any outstanding ELS commands */
5457 lpfc_els_flush_all_cmd(phba
);
5459 /* Unregister VFI */
5460 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5462 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5463 "2556 UNREG_VFI mbox allocation failed"
5464 "HBA state x%x\n", phba
->pport
->port_state
);
5468 lpfc_unreg_vfi(mbox
, phba
->pport
);
5469 mbox
->vport
= phba
->pport
;
5470 mbox
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
5472 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5473 if (rc
== MBX_NOT_FINISHED
) {
5474 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5475 "2557 UNREG_VFI issue mbox failed rc x%x "
5477 rc
, phba
->pport
->port_state
);
5478 mempool_free(mbox
, phba
->mbox_mem_pool
);
5482 shost
= lpfc_shost_from_vport(phba
->pport
);
5483 spin_lock_irq(shost
->host_lock
);
5484 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
5485 spin_unlock_irq(shost
->host_lock
);
5491 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5492 * @phba: Pointer to hba context object.
5494 * This function issues synchronous unregister FCF mailbox command to HBA to
5495 * unregister the currently registered FCF record. The driver does not reset
5496 * the driver FCF usage state flags.
5498 * Return 0 if successfully issued, none-zero otherwise.
5501 lpfc_sli4_unregister_fcf(struct lpfc_hba
*phba
)
5506 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5508 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5509 "2551 UNREG_FCFI mbox allocation failed"
5510 "HBA state x%x\n", phba
->pport
->port_state
);
5513 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
5514 mbox
->vport
= phba
->pport
;
5515 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
5516 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5518 if (rc
== MBX_NOT_FINISHED
) {
5519 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5520 "2552 Unregister FCFI command failed rc x%x "
5522 rc
, phba
->pport
->port_state
);
5529 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5530 * @phba: Pointer to hba context object.
5532 * This function unregisters the currently reigstered FCF. This function
5533 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5536 lpfc_unregister_fcf_rescan(struct lpfc_hba
*phba
)
5540 /* Preparation for unregistering fcf */
5541 rc
= lpfc_unregister_fcf_prep(phba
);
5543 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
5544 "2748 Failed to prepare for unregistering "
5545 "HBA's FCF record: rc=%d\n", rc
);
5549 /* Now, unregister FCF record and reset HBA FCF state */
5550 rc
= lpfc_sli4_unregister_fcf(phba
);
5553 /* Reset HBA FCF states after successful unregister FCF */
5554 phba
->fcf
.fcf_flag
= 0;
5555 phba
->fcf
.current_rec
.flag
= 0;
5558 * If driver is not unloading, check if there is any other
5559 * FCF record that can be used for discovery.
5561 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
5562 (phba
->link_state
< LPFC_LINK_UP
))
5565 /* This is considered as the initial FCF discovery scan */
5566 spin_lock_irq(&phba
->hbalock
);
5567 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
5568 spin_unlock_irq(&phba
->hbalock
);
5570 /* Reset FCF roundrobin bmask for new discovery */
5571 memset(phba
->fcf
.fcf_rr_bmask
, 0, sizeof(*phba
->fcf
.fcf_rr_bmask
));
5573 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
5576 spin_lock_irq(&phba
->hbalock
);
5577 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
5578 spin_unlock_irq(&phba
->hbalock
);
5579 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5580 "2553 lpfc_unregister_unused_fcf failed "
5581 "to read FCF record HBA state x%x\n",
5582 phba
->pport
->port_state
);
5587 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5588 * @phba: Pointer to hba context object.
5590 * This function just unregisters the currently reigstered FCF. It does not
5591 * try to find another FCF for discovery.
5594 lpfc_unregister_fcf(struct lpfc_hba
*phba
)
5598 /* Preparation for unregistering fcf */
5599 rc
= lpfc_unregister_fcf_prep(phba
);
5601 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
5602 "2749 Failed to prepare for unregistering "
5603 "HBA's FCF record: rc=%d\n", rc
);
5607 /* Now, unregister FCF record and reset HBA FCF state */
5608 rc
= lpfc_sli4_unregister_fcf(phba
);
5611 /* Set proper HBA FCF states after successful unregister FCF */
5612 spin_lock_irq(&phba
->hbalock
);
5613 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
5614 spin_unlock_irq(&phba
->hbalock
);
5618 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5619 * @phba: Pointer to hba context object.
5621 * This function check if there are any connected remote port for the FCF and
5622 * if all the devices are disconnected, this function unregister FCFI.
5623 * This function also tries to use another FCF for discovery.
5626 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
5629 * If HBA is not running in FIP mode, if HBA does not support
5630 * FCoE, if FCF discovery is ongoing, or if FCF has not been
5631 * registered, do nothing.
5633 spin_lock_irq(&phba
->hbalock
);
5634 if (!(phba
->hba_flag
& HBA_FCOE_MODE
) ||
5635 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
5636 !(phba
->hba_flag
& HBA_FIP_SUPPORT
) ||
5637 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) ||
5638 (phba
->pport
->port_state
== LPFC_FLOGI
)) {
5639 spin_unlock_irq(&phba
->hbalock
);
5642 spin_unlock_irq(&phba
->hbalock
);
5644 if (lpfc_fcf_inuse(phba
))
5647 lpfc_unregister_fcf_rescan(phba
);
5651 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5652 * @phba: Pointer to hba context object.
5653 * @buff: Buffer containing the FCF connection table as in the config
5655 * This function create driver data structure for the FCF connection
5656 * record table read from config region 23.
5659 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
5662 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
5663 struct lpfc_fcf_conn_hdr
*conn_hdr
;
5664 struct lpfc_fcf_conn_rec
*conn_rec
;
5665 uint32_t record_count
;
5668 /* Free the current connect table */
5669 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
5670 &phba
->fcf_conn_rec_list
, list
) {
5671 list_del_init(&conn_entry
->list
);
5675 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
5676 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
5677 sizeof(struct lpfc_fcf_conn_rec
);
5679 conn_rec
= (struct lpfc_fcf_conn_rec
*)
5680 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
5682 for (i
= 0; i
< record_count
; i
++) {
5683 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
5685 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
5688 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5689 "2566 Failed to allocate connection"
5694 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
5695 sizeof(struct lpfc_fcf_conn_rec
));
5696 conn_entry
->conn_rec
.vlan_tag
=
5697 le16_to_cpu(conn_entry
->conn_rec
.vlan_tag
) & 0xFFF;
5698 conn_entry
->conn_rec
.flags
=
5699 le16_to_cpu(conn_entry
->conn_rec
.flags
);
5700 list_add_tail(&conn_entry
->list
,
5701 &phba
->fcf_conn_rec_list
);
5706 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5707 * @phba: Pointer to hba context object.
5708 * @buff: Buffer containing the FCoE parameter data structure.
5710 * This function update driver data structure with config
5711 * parameters read from config region 23.
5714 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
5717 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
5718 struct lpfc_fcoe_params
*fcoe_param
;
5720 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
5722 fcoe_param
= (struct lpfc_fcoe_params
*)
5723 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
5725 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
5726 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
5729 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
5730 phba
->valid_vlan
= 1;
5731 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
5735 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
5736 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
5737 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
5742 * lpfc_get_rec_conf23 - Get a record type in config region data.
5743 * @buff: Buffer containing config region 23 data.
5744 * @size: Size of the data buffer.
5745 * @rec_type: Record type to be searched.
5747 * This function searches config region data to find the begining
5748 * of the record specified by record_type. If record found, this
5749 * function return pointer to the record else return NULL.
5752 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
5754 uint32_t offset
= 0, rec_length
;
5756 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
5757 (size
< sizeof(uint32_t)))
5760 rec_length
= buff
[offset
+ 1];
5763 * One TLV record has one word header and number of data words
5764 * specified in the rec_length field of the record header.
5766 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
5768 if (buff
[offset
] == rec_type
)
5769 return &buff
[offset
];
5771 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
5774 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
5775 rec_length
= buff
[offset
+ 1];
5781 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5782 * @phba: Pointer to lpfc_hba data structure.
5783 * @buff: Buffer containing config region 23 data.
5784 * @size: Size of the data buffer.
5786 * This function parses the FCoE config parameters in config region 23 and
5787 * populate driver data structure with the parameters.
5790 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
5794 uint32_t offset
= 0, rec_length
;
5798 * If data size is less than 2 words signature and version cannot be
5801 if (size
< 2*sizeof(uint32_t))
5804 /* Check the region signature first */
5805 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
5806 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5807 "2567 Config region 23 has bad signature\n");
5813 /* Check the data structure version */
5814 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
5815 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5816 "2568 Config region 23 has bad version\n");
5821 rec_length
= buff
[offset
+ 1];
5823 /* Read FCoE param record */
5824 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
5825 size
- offset
, FCOE_PARAM_TYPE
);
5827 lpfc_read_fcoe_param(phba
, rec_ptr
);
5829 /* Read FCF connection table */
5830 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
5831 size
- offset
, FCOE_CONN_TBL_TYPE
);
5833 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);