1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 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 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
127 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
128 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
130 /* Don't defer this if we are in the process of deleting the vport
131 * or unloading the driver. The unload will cleanup the node
132 * appropriately we just need to cleanup the ndlp rport info here.
134 if (vport->load_flag & FC_UNLOADING) {
135 put_node = rdata->pnode != NULL;
136 put_rport = ndlp->rport != NULL;
142 put_device(&rport->dev);
146 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
149 if (ndlp->nlp_type & NLP_FABRIC) {
151 /* If the WWPN of the rport and ndlp don't match, ignore it */
152 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) {
153 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
154 "6789 rport name %lx != node port name %lx",
155 (unsigned long)rport->port_name,
156 (unsigned long)wwn_to_u64(
157 ndlp->nlp_portname.u.wwn));
158 put_node = rdata->pnode != NULL;
159 put_rport = ndlp->rport != NULL;
165 put_device(&rport->dev);
169 put_node = rdata->pnode != NULL;
170 put_rport = ndlp->rport != NULL;
176 put_device(&rport->dev);
180 evtp = &ndlp->dev_loss_evt;
182 if (!list_empty(&evtp->evt_listp))
185 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
186 ndlp->nlp_add_flag |= NLP_IN_DEV_LOSS;
188 spin_lock_irq(&phba->hbalock);
189 /* We need to hold the node by incrementing the reference
190 * count until this queued work is done
192 if (evtp->evt_arg1) {
193 evtp->evt = LPFC_EVT_DEV_LOSS;
194 list_add_tail(&evtp->evt_listp, &phba->work_list);
195 lpfc_worker_wake_up(phba);
197 spin_unlock_irq(&phba->hbalock);
203 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
204 * @ndlp: Pointer to remote node object.
206 * This function is called from the worker thread when devloss timeout timer
207 * expires. For SLI4 host, this routine shall return 1 when at lease one
208 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
209 * routine shall return 0 when there is no remote node is still in use of FCF
210 * when devloss timeout happened to this @ndlp.
213 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
215 struct lpfc_rport_data *rdata;
216 struct fc_rport *rport;
217 struct lpfc_vport *vport;
218 struct lpfc_hba *phba;
228 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
232 rdata = rport->dd_data;
233 name = (uint8_t *) &ndlp->nlp_portname;
237 if (phba->sli_rev == LPFC_SLI_REV4)
238 fcf_inuse = lpfc_fcf_inuse(phba);
240 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
241 "rport devlosstmo:did:x%x type:x%x id:x%x",
242 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
244 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
245 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
246 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
248 /* Don't defer this if we are in the process of deleting the vport
249 * or unloading the driver. The unload will cleanup the node
250 * appropriately we just need to cleanup the ndlp rport info here.
252 if (vport->load_flag & FC_UNLOADING) {
253 if (ndlp->nlp_sid != NLP_NO_SID) {
254 /* flush the target */
255 lpfc_sli_abort_iocb(vport,
256 &phba->sli.ring[phba->sli.fcp_ring],
257 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
259 put_node = rdata->pnode != NULL;
260 put_rport = ndlp->rport != NULL;
263 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
267 put_device(&rport->dev);
271 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
272 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
273 "0284 Devloss timeout Ignored on "
274 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
276 *name, *(name+1), *(name+2), *(name+3),
277 *(name+4), *(name+5), *(name+6), *(name+7),
279 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
283 if (ndlp->nlp_type & NLP_FABRIC) {
284 /* We will clean up these Nodes in linkup */
285 put_node = rdata->pnode != NULL;
286 put_rport = ndlp->rport != NULL;
289 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
293 put_device(&rport->dev);
297 if (ndlp->nlp_sid != NLP_NO_SID) {
299 /* flush the target */
300 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
301 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
302 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
306 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
307 "0203 Devloss timeout on "
308 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
309 "NPort x%06x Data: x%x x%x x%x\n",
310 *name, *(name+1), *(name+2), *(name+3),
311 *(name+4), *(name+5), *(name+6), *(name+7),
312 ndlp->nlp_DID, ndlp->nlp_flag,
313 ndlp->nlp_state, ndlp->nlp_rpi);
315 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
316 "0204 Devloss timeout on "
317 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
318 "NPort x%06x Data: x%x x%x x%x\n",
319 *name, *(name+1), *(name+2), *(name+3),
320 *(name+4), *(name+5), *(name+6), *(name+7),
321 ndlp->nlp_DID, ndlp->nlp_flag,
322 ndlp->nlp_state, ndlp->nlp_rpi);
325 put_node = rdata->pnode != NULL;
326 put_rport = ndlp->rport != NULL;
329 ndlp->nlp_add_flag &= ~NLP_IN_DEV_LOSS;
333 put_device(&rport->dev);
335 if (!(vport->load_flag & FC_UNLOADING) &&
336 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
337 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
338 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
339 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
340 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
341 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
347 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
348 * @phba: Pointer to hba context object.
349 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
350 * @nlp_did: remote node identifer with devloss timeout.
352 * This function is called from the worker thread after invoking devloss
353 * timeout handler and releasing the reference count for the ndlp with
354 * which the devloss timeout was handled for SLI4 host. For the devloss
355 * timeout of the last remote node which had been in use of FCF, when this
356 * routine is invoked, it shall be guaranteed that none of the remote are
357 * in-use of FCF. When devloss timeout to the last remote using the FCF,
358 * if the FIP engine is neither in FCF table scan process nor roundrobin
359 * failover process, the in-use FCF shall be unregistered. If the FIP
360 * engine is in FCF discovery process, the devloss timeout state shall
361 * be set for either the FCF table scan process or roundrobin failover
362 * process to unregister the in-use FCF.
365 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
368 /* If devloss timeout happened to a remote node when FCF had no
369 * longer been in-use, do nothing.
374 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
375 spin_lock_irq(&phba->hbalock);
376 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
377 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
378 spin_unlock_irq(&phba->hbalock);
381 phba->hba_flag |= HBA_DEVLOSS_TMO;
382 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
383 "2847 Last remote node (x%x) using "
384 "FCF devloss tmo\n", nlp_did);
386 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
387 spin_unlock_irq(&phba->hbalock);
388 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
389 "2868 Devloss tmo to FCF rediscovery "
393 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
394 spin_unlock_irq(&phba->hbalock);
395 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
396 "2869 Devloss tmo to idle FIP engine, "
397 "unreg in-use FCF and rescan.\n");
398 /* Unregister in-use FCF and rescan */
399 lpfc_unregister_fcf_rescan(phba);
402 spin_unlock_irq(&phba->hbalock);
403 if (phba->hba_flag & FCF_TS_INPROG)
404 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
405 "2870 FCF table scan in progress\n");
406 if (phba->hba_flag & FCF_RR_INPROG)
407 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
408 "2871 FLOGI roundrobin FCF failover "
411 lpfc_unregister_unused_fcf(phba);
415 * lpfc_alloc_fast_evt - Allocates data structure for posting event
416 * @phba: Pointer to hba context object.
418 * This function is called from the functions which need to post
419 * events from interrupt context. This function allocates data
420 * structure required for posting event. It also keeps track of
421 * number of events pending and prevent event storm when there are
424 struct lpfc_fast_path_event *
425 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
426 struct lpfc_fast_path_event *ret;
428 /* If there are lot of fast event do not exhaust memory due to this */
429 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
432 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
435 atomic_inc(&phba->fast_event_count);
436 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
437 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
443 * lpfc_free_fast_evt - Frees event data structure
444 * @phba: Pointer to hba context object.
445 * @evt: Event object which need to be freed.
447 * This function frees the data structure required for posting
451 lpfc_free_fast_evt(struct lpfc_hba *phba,
452 struct lpfc_fast_path_event *evt) {
454 atomic_dec(&phba->fast_event_count);
459 * lpfc_send_fastpath_evt - Posts events generated from fast path
460 * @phba: Pointer to hba context object.
461 * @evtp: Event data structure.
463 * This function is called from worker thread, when the interrupt
464 * context need to post an event. This function posts the event
465 * to fc transport netlink interface.
468 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
469 struct lpfc_work_evt *evtp)
471 unsigned long evt_category, evt_sub_category;
472 struct lpfc_fast_path_event *fast_evt_data;
474 uint32_t evt_data_size;
475 struct Scsi_Host *shost;
477 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
480 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
481 evt_sub_category = (unsigned long) fast_evt_data->un.
482 fabric_evt.subcategory;
483 shost = lpfc_shost_from_vport(fast_evt_data->vport);
484 if (evt_category == FC_REG_FABRIC_EVENT) {
485 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
486 evt_data = (char *) &fast_evt_data->un.read_check_error;
487 evt_data_size = sizeof(fast_evt_data->un.
489 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
490 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
491 evt_data = (char *) &fast_evt_data->un.fabric_evt;
492 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
494 lpfc_free_fast_evt(phba, fast_evt_data);
497 } else if (evt_category == FC_REG_SCSI_EVENT) {
498 switch (evt_sub_category) {
499 case LPFC_EVENT_QFULL:
500 case LPFC_EVENT_DEVBSY:
501 evt_data = (char *) &fast_evt_data->un.scsi_evt;
502 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
504 case LPFC_EVENT_CHECK_COND:
505 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
506 evt_data_size = sizeof(fast_evt_data->un.
509 case LPFC_EVENT_VARQUEDEPTH:
510 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
511 evt_data_size = sizeof(fast_evt_data->un.
515 lpfc_free_fast_evt(phba, fast_evt_data);
519 lpfc_free_fast_evt(phba, fast_evt_data);
523 fc_host_post_vendor_event(shost,
524 fc_get_event_number(),
529 lpfc_free_fast_evt(phba, fast_evt_data);
534 lpfc_work_list_done(struct lpfc_hba *phba)
536 struct lpfc_work_evt *evtp = NULL;
537 struct lpfc_nodelist *ndlp;
542 spin_lock_irq(&phba->hbalock);
543 while (!list_empty(&phba->work_list)) {
544 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
546 spin_unlock_irq(&phba->hbalock);
549 case LPFC_EVT_ELS_RETRY:
550 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
551 lpfc_els_retry_delay_handler(ndlp);
552 free_evt = 0; /* evt is part of ndlp */
553 /* decrement the node reference count held
554 * for this queued work
558 case LPFC_EVT_DEV_LOSS:
559 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
560 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
562 /* decrement the node reference count held for
565 nlp_did = ndlp->nlp_DID;
567 if (phba->sli_rev == LPFC_SLI_REV4)
568 lpfc_sli4_post_dev_loss_tmo_handler(phba,
572 case LPFC_EVT_ONLINE:
573 if (phba->link_state < LPFC_LINK_DOWN)
574 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
576 *(int *) (evtp->evt_arg1) = 0;
577 complete((struct completion *)(evtp->evt_arg2));
579 case LPFC_EVT_OFFLINE_PREP:
580 if (phba->link_state >= LPFC_LINK_DOWN)
581 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
582 *(int *)(evtp->evt_arg1) = 0;
583 complete((struct completion *)(evtp->evt_arg2));
585 case LPFC_EVT_OFFLINE:
587 lpfc_sli_brdrestart(phba);
588 *(int *)(evtp->evt_arg1) =
589 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
590 lpfc_unblock_mgmt_io(phba);
591 complete((struct completion *)(evtp->evt_arg2));
593 case LPFC_EVT_WARM_START:
595 lpfc_reset_barrier(phba);
596 lpfc_sli_brdreset(phba);
597 lpfc_hba_down_post(phba);
598 *(int *)(evtp->evt_arg1) =
599 lpfc_sli_brdready(phba, HS_MBRDY);
600 lpfc_unblock_mgmt_io(phba);
601 complete((struct completion *)(evtp->evt_arg2));
605 *(int *)(evtp->evt_arg1)
606 = (phba->pport->stopped)
607 ? 0 : lpfc_sli_brdkill(phba);
608 lpfc_unblock_mgmt_io(phba);
609 complete((struct completion *)(evtp->evt_arg2));
611 case LPFC_EVT_FASTPATH_MGMT_EVT:
612 lpfc_send_fastpath_evt(phba, evtp);
615 case LPFC_EVT_RESET_HBA:
616 if (!(phba->pport->load_flag & FC_UNLOADING))
617 lpfc_reset_hba(phba);
622 spin_lock_irq(&phba->hbalock);
624 spin_unlock_irq(&phba->hbalock);
629 lpfc_work_done(struct lpfc_hba *phba)
631 struct lpfc_sli_ring *pring;
632 uint32_t ha_copy, status, control, work_port_events;
633 struct lpfc_vport **vports;
634 struct lpfc_vport *vport;
637 spin_lock_irq(&phba->hbalock);
638 ha_copy = phba->work_ha;
640 spin_unlock_irq(&phba->hbalock);
642 /* First, try to post the next mailbox command to SLI4 device */
643 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
644 lpfc_sli4_post_async_mbox(phba);
646 if (ha_copy & HA_ERATT)
647 /* Handle the error attention event */
648 lpfc_handle_eratt(phba);
650 if (ha_copy & HA_MBATT)
651 lpfc_sli_handle_mb_event(phba);
653 if (ha_copy & HA_LATT)
654 lpfc_handle_latt(phba);
656 /* Process SLI4 events */
657 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
658 if (phba->hba_flag & HBA_RRQ_ACTIVE)
659 lpfc_handle_rrq_active(phba);
660 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
661 lpfc_sli4_fcp_xri_abort_event_proc(phba);
662 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
663 lpfc_sli4_els_xri_abort_event_proc(phba);
664 if (phba->hba_flag & ASYNC_EVENT)
665 lpfc_sli4_async_event_proc(phba);
666 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
667 spin_lock_irq(&phba->hbalock);
668 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
669 spin_unlock_irq(&phba->hbalock);
670 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
672 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
673 lpfc_sli4_fcf_redisc_event_proc(phba);
676 vports = lpfc_create_vport_work_array(phba);
678 for (i = 0; i <= phba->max_vports; i++) {
680 * We could have no vports in array if unloading, so if
681 * this happens then just use the pport
683 if (vports[i] == NULL && i == 0)
689 spin_lock_irq(&vport->work_port_lock);
690 work_port_events = vport->work_port_events;
691 vport->work_port_events &= ~work_port_events;
692 spin_unlock_irq(&vport->work_port_lock);
693 if (work_port_events & WORKER_DISC_TMO)
694 lpfc_disc_timeout_handler(vport);
695 if (work_port_events & WORKER_ELS_TMO)
696 lpfc_els_timeout_handler(vport);
697 if (work_port_events & WORKER_HB_TMO)
698 lpfc_hb_timeout_handler(phba);
699 if (work_port_events & WORKER_MBOX_TMO)
700 lpfc_mbox_timeout_handler(phba);
701 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
702 lpfc_unblock_fabric_iocbs(phba);
703 if (work_port_events & WORKER_FDMI_TMO)
704 lpfc_fdmi_timeout_handler(vport);
705 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
706 lpfc_ramp_down_queue_handler(phba);
707 if (work_port_events & WORKER_DELAYED_DISC_TMO)
708 lpfc_delayed_disc_timeout_handler(vport);
710 lpfc_destroy_vport_work_array(phba, vports);
712 pring = &phba->sli.ring[LPFC_ELS_RING];
713 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
714 status >>= (4*LPFC_ELS_RING);
715 if ((status & HA_RXMASK) ||
716 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
717 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
718 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
719 pring->flag |= LPFC_DEFERRED_RING_EVENT;
720 /* Set the lpfc data pending flag */
721 set_bit(LPFC_DATA_READY, &phba->data_flags);
723 if (phba->link_state >= LPFC_LINK_UP) {
724 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
725 lpfc_sli_handle_slow_ring_event(phba, pring,
730 if ((phba->sli_rev == LPFC_SLI_REV4) &
731 (!list_empty(&pring->txq)))
732 lpfc_drain_txq(phba);
734 * Turn on Ring interrupts
736 if (phba->sli_rev <= LPFC_SLI_REV3) {
737 spin_lock_irq(&phba->hbalock);
738 control = readl(phba->HCregaddr);
739 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
740 lpfc_debugfs_slow_ring_trc(phba,
741 "WRK Enable ring: cntl:x%x hacopy:x%x",
742 control, ha_copy, 0);
744 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
745 writel(control, phba->HCregaddr);
746 readl(phba->HCregaddr); /* flush */
748 lpfc_debugfs_slow_ring_trc(phba,
749 "WRK Ring ok: cntl:x%x hacopy:x%x",
750 control, ha_copy, 0);
752 spin_unlock_irq(&phba->hbalock);
755 lpfc_work_list_done(phba);
759 lpfc_do_work(void *p)
761 struct lpfc_hba *phba = p;
764 set_user_nice(current, MIN_NICE);
765 current->flags |= PF_NOFREEZE;
766 phba->data_flags = 0;
768 while (!kthread_should_stop()) {
769 /* wait and check worker queue activities */
770 rc = wait_event_interruptible(phba->work_waitq,
771 (test_and_clear_bit(LPFC_DATA_READY,
773 || kthread_should_stop()));
774 /* Signal wakeup shall terminate the worker thread */
776 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
777 "0433 Wakeup on signal: rc=x%x\n", rc);
781 /* Attend pending lpfc data processing */
782 lpfc_work_done(phba);
784 phba->worker_thread = NULL;
785 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
786 "0432 Worker thread stopped.\n");
791 * This is only called to handle FC worker events. Since this a rare
792 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
793 * embedding it in the IOCB.
796 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
799 struct lpfc_work_evt *evtp;
803 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
804 * be queued to worker thread for processing
806 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
810 evtp->evt_arg1 = arg1;
811 evtp->evt_arg2 = arg2;
814 spin_lock_irqsave(&phba->hbalock, flags);
815 list_add_tail(&evtp->evt_listp, &phba->work_list);
816 spin_unlock_irqrestore(&phba->hbalock, flags);
818 lpfc_worker_wake_up(phba);
824 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
826 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
827 struct lpfc_hba *phba = vport->phba;
828 struct lpfc_nodelist *ndlp, *next_ndlp;
831 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
832 if (!NLP_CHK_NODE_ACT(ndlp))
834 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
836 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
837 ((vport->port_type == LPFC_NPIV_PORT) &&
838 (ndlp->nlp_DID == NameServer_DID)))
839 lpfc_unreg_rpi(vport, ndlp);
841 /* Leave Fabric nodes alone on link down */
842 if ((phba->sli_rev < LPFC_SLI_REV4) &&
843 (!remove && ndlp->nlp_type & NLP_FABRIC))
845 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
848 : NLP_EVT_DEVICE_RECOVERY);
850 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
851 if (phba->sli_rev == LPFC_SLI_REV4)
852 lpfc_sli4_unreg_all_rpis(vport);
853 lpfc_mbx_unreg_vpi(vport);
854 spin_lock_irq(shost->host_lock);
855 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
856 spin_unlock_irq(shost->host_lock);
861 lpfc_port_link_failure(struct lpfc_vport *vport)
863 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
865 /* Cleanup any outstanding received buffers */
866 lpfc_cleanup_rcv_buffers(vport);
868 /* Cleanup any outstanding RSCN activity */
869 lpfc_els_flush_rscn(vport);
871 /* Cleanup any outstanding ELS commands */
872 lpfc_els_flush_cmd(vport);
874 lpfc_cleanup_rpis(vport, 0);
876 /* Turn off discovery timer if its running */
877 lpfc_can_disctmo(vport);
881 lpfc_linkdown_port(struct lpfc_vport *vport)
883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
885 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
888 "Link Down: state:x%x rtry:x%x flg:x%x",
889 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
891 lpfc_port_link_failure(vport);
893 /* Stop delayed Nport discovery */
894 spin_lock_irq(shost->host_lock);
895 vport->fc_flag &= ~FC_DISC_DELAYED;
896 spin_unlock_irq(shost->host_lock);
897 del_timer_sync(&vport->delayed_disc_tmo);
901 lpfc_linkdown(struct lpfc_hba *phba)
903 struct lpfc_vport *vport = phba->pport;
904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
905 struct lpfc_vport **vports;
909 if (phba->link_state == LPFC_LINK_DOWN)
912 /* Block all SCSI stack I/Os */
913 lpfc_scsi_dev_block(phba);
915 spin_lock_irq(&phba->hbalock);
916 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
917 spin_unlock_irq(&phba->hbalock);
918 if (phba->link_state > LPFC_LINK_DOWN) {
919 phba->link_state = LPFC_LINK_DOWN;
920 spin_lock_irq(shost->host_lock);
921 phba->pport->fc_flag &= ~FC_LBIT;
922 spin_unlock_irq(shost->host_lock);
924 vports = lpfc_create_vport_work_array(phba);
926 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
927 /* Issue a LINK DOWN event to all nodes */
928 lpfc_linkdown_port(vports[i]);
930 lpfc_destroy_vport_work_array(phba, vports);
931 /* Clean up any firmware default rpi's */
932 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
934 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
936 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
937 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
938 == MBX_NOT_FINISHED) {
939 mempool_free(mb, phba->mbox_mem_pool);
943 /* Setup myDID for link up if we are in pt2pt mode */
944 if (phba->pport->fc_flag & FC_PT2PT) {
945 phba->pport->fc_myDID = 0;
946 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
948 lpfc_config_link(phba, mb);
949 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
951 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
952 == MBX_NOT_FINISHED) {
953 mempool_free(mb, phba->mbox_mem_pool);
956 spin_lock_irq(shost->host_lock);
957 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
958 spin_unlock_irq(shost->host_lock);
965 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
967 struct lpfc_nodelist *ndlp;
969 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
970 if (!NLP_CHK_NODE_ACT(ndlp))
972 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
974 if (ndlp->nlp_type & NLP_FABRIC) {
975 /* On Linkup its safe to clean up the ndlp
976 * from Fabric connections.
978 if (ndlp->nlp_DID != Fabric_DID)
979 lpfc_unreg_rpi(vport, ndlp);
980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
981 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
982 /* Fail outstanding IO now since device is
985 lpfc_unreg_rpi(vport, ndlp);
991 lpfc_linkup_port(struct lpfc_vport *vport)
993 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
994 struct lpfc_hba *phba = vport->phba;
996 if ((vport->load_flag & FC_UNLOADING) != 0)
999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "Link Up: top:x%x speed:x%x flg:x%x",
1001 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1003 /* If NPIV is not enabled, only bring the physical port up */
1004 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1005 (vport != phba->pport))
1008 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
1010 spin_lock_irq(shost->host_lock);
1011 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1012 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1013 vport->fc_flag |= FC_NDISC_ACTIVE;
1014 vport->fc_ns_retry = 0;
1015 spin_unlock_irq(shost->host_lock);
1017 if (vport->fc_flag & FC_LBIT)
1018 lpfc_linkup_cleanup_nodes(vport);
1023 lpfc_linkup(struct lpfc_hba *phba)
1025 struct lpfc_vport **vports;
1028 phba->link_state = LPFC_LINK_UP;
1030 /* Unblock fabric iocbs if they are blocked */
1031 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1032 del_timer_sync(&phba->fabric_block_timer);
1034 vports = lpfc_create_vport_work_array(phba);
1036 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1037 lpfc_linkup_port(vports[i]);
1038 lpfc_destroy_vport_work_array(phba, vports);
1044 * This routine handles processing a CLEAR_LA mailbox
1045 * command upon completion. It is setup in the LPFC_MBOXQ
1046 * as the completion routine when the command is
1047 * handed off to the SLI layer.
1050 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1052 struct lpfc_vport *vport = pmb->vport;
1053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1054 struct lpfc_sli *psli = &phba->sli;
1055 MAILBOX_t *mb = &pmb->u.mb;
1058 /* Since we don't do discovery right now, turn these off here */
1059 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1060 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1061 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1063 /* Check for error */
1064 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1065 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1066 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1067 "0320 CLEAR_LA mbxStatus error x%x hba "
1069 mb->mbxStatus, vport->port_state);
1070 phba->link_state = LPFC_HBA_ERROR;
1074 if (vport->port_type == LPFC_PHYSICAL_PORT)
1075 phba->link_state = LPFC_HBA_READY;
1077 spin_lock_irq(&phba->hbalock);
1078 psli->sli_flag |= LPFC_PROCESS_LA;
1079 control = readl(phba->HCregaddr);
1080 control |= HC_LAINT_ENA;
1081 writel(control, phba->HCregaddr);
1082 readl(phba->HCregaddr); /* flush */
1083 spin_unlock_irq(&phba->hbalock);
1084 mempool_free(pmb, phba->mbox_mem_pool);
1088 /* Device Discovery completes */
1089 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1090 "0225 Device Discovery completes\n");
1091 mempool_free(pmb, phba->mbox_mem_pool);
1093 spin_lock_irq(shost->host_lock);
1094 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1095 spin_unlock_irq(shost->host_lock);
1097 lpfc_can_disctmo(vport);
1099 /* turn on Link Attention interrupts */
1101 spin_lock_irq(&phba->hbalock);
1102 psli->sli_flag |= LPFC_PROCESS_LA;
1103 control = readl(phba->HCregaddr);
1104 control |= HC_LAINT_ENA;
1105 writel(control, phba->HCregaddr);
1106 readl(phba->HCregaddr); /* flush */
1107 spin_unlock_irq(&phba->hbalock);
1114 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1116 struct lpfc_vport *vport = pmb->vport;
1118 if (pmb->u.mb.mbxStatus)
1121 mempool_free(pmb, phba->mbox_mem_pool);
1123 /* don't perform discovery for SLI4 loopback diagnostic test */
1124 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1125 !(phba->hba_flag & HBA_FCOE_MODE) &&
1126 (phba->link_flag & LS_LOOPBACK_MODE))
1129 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1130 vport->fc_flag & FC_PUBLIC_LOOP &&
1131 !(vport->fc_flag & FC_LBIT)) {
1132 /* Need to wait for FAN - use discovery timer
1133 * for timeout. port_state is identically
1134 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1136 lpfc_set_disctmo(vport);
1140 /* Start discovery by sending a FLOGI. port_state is identically
1141 * LPFC_FLOGI while waiting for FLOGI cmpl
1143 if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI)
1144 lpfc_initial_flogi(vport);
1148 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1149 "0306 CONFIG_LINK mbxStatus error x%x "
1151 pmb->u.mb.mbxStatus, vport->port_state);
1152 mempool_free(pmb, phba->mbox_mem_pool);
1154 lpfc_linkdown(phba);
1156 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1157 "0200 CONFIG_LINK bad hba state x%x\n",
1160 lpfc_issue_clear_la(phba, vport);
1165 * lpfc_sli4_clear_fcf_rr_bmask
1166 * @phba pointer to the struct lpfc_hba for this port.
1167 * This fucnction resets the round robin bit mask and clears the
1168 * fcf priority list. The list deletions are done while holding the
1169 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1170 * from the lpfc_fcf_pri record.
1173 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1175 struct lpfc_fcf_pri *fcf_pri;
1176 struct lpfc_fcf_pri *next_fcf_pri;
1177 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1178 spin_lock_irq(&phba->hbalock);
1179 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1180 &phba->fcf.fcf_pri_list, list) {
1181 list_del_init(&fcf_pri->list);
1182 fcf_pri->fcf_rec.flag = 0;
1184 spin_unlock_irq(&phba->hbalock);
1187 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1189 struct lpfc_vport *vport = mboxq->vport;
1191 if (mboxq->u.mb.mbxStatus) {
1192 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1193 "2017 REG_FCFI mbxStatus error x%x "
1195 mboxq->u.mb.mbxStatus, vport->port_state);
1199 /* Start FCoE discovery by sending a FLOGI. */
1200 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1201 /* Set the FCFI registered flag */
1202 spin_lock_irq(&phba->hbalock);
1203 phba->fcf.fcf_flag |= FCF_REGISTERED;
1204 spin_unlock_irq(&phba->hbalock);
1206 /* If there is a pending FCoE event, restart FCF table scan. */
1207 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1208 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1211 /* Mark successful completion of FCF table scan */
1212 spin_lock_irq(&phba->hbalock);
1213 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1214 phba->hba_flag &= ~FCF_TS_INPROG;
1215 if (vport->port_state != LPFC_FLOGI) {
1216 phba->hba_flag |= FCF_RR_INPROG;
1217 spin_unlock_irq(&phba->hbalock);
1218 lpfc_issue_init_vfi(vport);
1221 spin_unlock_irq(&phba->hbalock);
1225 spin_lock_irq(&phba->hbalock);
1226 phba->hba_flag &= ~FCF_RR_INPROG;
1227 spin_unlock_irq(&phba->hbalock);
1229 mempool_free(mboxq, phba->mbox_mem_pool);
1233 * lpfc_fab_name_match - Check if the fcf fabric name match.
1234 * @fab_name: pointer to fabric name.
1235 * @new_fcf_record: pointer to fcf record.
1237 * This routine compare the fcf record's fabric name with provided
1238 * fabric name. If the fabric name are identical this function
1239 * returns 1 else return 0.
1242 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1244 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1246 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1248 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1250 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1252 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1254 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1256 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1258 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1264 * lpfc_sw_name_match - Check if the fcf switch name match.
1265 * @fab_name: pointer to fabric name.
1266 * @new_fcf_record: pointer to fcf record.
1268 * This routine compare the fcf record's switch name with provided
1269 * switch name. If the switch name are identical this function
1270 * returns 1 else return 0.
1273 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1275 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1277 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1279 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1281 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1283 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1285 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1287 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1289 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1295 * lpfc_mac_addr_match - Check if the fcf mac address match.
1296 * @mac_addr: pointer to mac address.
1297 * @new_fcf_record: pointer to fcf record.
1299 * This routine compare the fcf record's mac address with HBA's
1300 * FCF mac address. If the mac addresses are identical this function
1301 * returns 1 else return 0.
1304 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1306 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1308 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1310 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1312 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1314 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1316 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1322 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1324 return (curr_vlan_id == new_vlan_id);
1328 * lpfc_update_fcf_record - Update driver fcf record
1329 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1330 * @phba: pointer to lpfc hba data structure.
1331 * @fcf_index: Index for the lpfc_fcf_record.
1332 * @new_fcf_record: pointer to hba fcf record.
1334 * This routine updates the driver FCF priority record from the new HBA FCF
1335 * record. This routine is called with the host lock held.
1338 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1339 struct fcf_record *new_fcf_record
1342 struct lpfc_fcf_pri *fcf_pri;
1344 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1345 fcf_pri->fcf_rec.fcf_index = fcf_index;
1346 /* FCF record priority */
1347 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1352 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1353 * @fcf: pointer to driver fcf record.
1354 * @new_fcf_record: pointer to fcf record.
1356 * This routine copies the FCF information from the FCF
1357 * record to lpfc_hba data structure.
1360 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1361 struct fcf_record *new_fcf_record)
1364 fcf_rec->fabric_name[0] =
1365 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1366 fcf_rec->fabric_name[1] =
1367 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1368 fcf_rec->fabric_name[2] =
1369 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1370 fcf_rec->fabric_name[3] =
1371 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1372 fcf_rec->fabric_name[4] =
1373 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1374 fcf_rec->fabric_name[5] =
1375 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1376 fcf_rec->fabric_name[6] =
1377 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1378 fcf_rec->fabric_name[7] =
1379 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1381 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1382 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1383 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1384 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1385 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1386 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1387 /* FCF record index */
1388 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1389 /* FCF record priority */
1390 fcf_rec->priority = new_fcf_record->fip_priority;
1392 fcf_rec->switch_name[0] =
1393 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1394 fcf_rec->switch_name[1] =
1395 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1396 fcf_rec->switch_name[2] =
1397 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1398 fcf_rec->switch_name[3] =
1399 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1400 fcf_rec->switch_name[4] =
1401 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1402 fcf_rec->switch_name[5] =
1403 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1404 fcf_rec->switch_name[6] =
1405 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1406 fcf_rec->switch_name[7] =
1407 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1411 * lpfc_update_fcf_record - Update driver fcf record
1412 * @phba: pointer to lpfc hba data structure.
1413 * @fcf_rec: pointer to driver fcf record.
1414 * @new_fcf_record: pointer to hba fcf record.
1415 * @addr_mode: address mode to be set to the driver fcf record.
1416 * @vlan_id: vlan tag to be set to the driver fcf record.
1417 * @flag: flag bits to be set to the driver fcf record.
1419 * This routine updates the driver FCF record from the new HBA FCF record
1420 * together with the address mode, vlan_id, and other informations. This
1421 * routine is called with the host lock held.
1424 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1425 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1426 uint16_t vlan_id, uint32_t flag)
1428 /* Copy the fields from the HBA's FCF record */
1429 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1430 /* Update other fields of driver FCF record */
1431 fcf_rec->addr_mode = addr_mode;
1432 fcf_rec->vlan_id = vlan_id;
1433 fcf_rec->flag |= (flag | RECORD_VALID);
1434 __lpfc_update_fcf_record_pri(phba,
1435 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1440 * lpfc_register_fcf - Register the FCF with hba.
1441 * @phba: pointer to lpfc hba data structure.
1443 * This routine issues a register fcfi mailbox command to register
1447 lpfc_register_fcf(struct lpfc_hba *phba)
1449 LPFC_MBOXQ_t *fcf_mbxq;
1452 spin_lock_irq(&phba->hbalock);
1453 /* If the FCF is not available do nothing. */
1454 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1455 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1456 spin_unlock_irq(&phba->hbalock);
1460 /* The FCF is already registered, start discovery */
1461 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1462 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1463 phba->hba_flag &= ~FCF_TS_INPROG;
1464 if (phba->pport->port_state != LPFC_FLOGI &&
1465 phba->pport->fc_flag & FC_FABRIC) {
1466 phba->hba_flag |= FCF_RR_INPROG;
1467 spin_unlock_irq(&phba->hbalock);
1468 lpfc_initial_flogi(phba->pport);
1471 spin_unlock_irq(&phba->hbalock);
1474 spin_unlock_irq(&phba->hbalock);
1476 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1478 spin_lock_irq(&phba->hbalock);
1479 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1480 spin_unlock_irq(&phba->hbalock);
1484 lpfc_reg_fcfi(phba, fcf_mbxq);
1485 fcf_mbxq->vport = phba->pport;
1486 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1487 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1488 if (rc == MBX_NOT_FINISHED) {
1489 spin_lock_irq(&phba->hbalock);
1490 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1491 spin_unlock_irq(&phba->hbalock);
1492 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1499 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1500 * @phba: pointer to lpfc hba data structure.
1501 * @new_fcf_record: pointer to fcf record.
1502 * @boot_flag: Indicates if this record used by boot bios.
1503 * @addr_mode: The address mode to be used by this FCF
1504 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1506 * This routine compare the fcf record with connect list obtained from the
1507 * config region to decide if this FCF can be used for SAN discovery. It returns
1508 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1509 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1510 * is used by boot bios and addr_mode will indicate the addressing mode to be
1511 * used for this FCF when the function returns.
1512 * If the FCF record need to be used with a particular vlan id, the vlan is
1513 * set in the vlan_id on return of the function. If not VLAN tagging need to
1514 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1517 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1518 struct fcf_record *new_fcf_record,
1519 uint32_t *boot_flag, uint32_t *addr_mode,
1522 struct lpfc_fcf_conn_entry *conn_entry;
1523 int i, j, fcf_vlan_id = 0;
1525 /* Find the lowest VLAN id in the FCF record */
1526 for (i = 0; i < 512; i++) {
1527 if (new_fcf_record->vlan_bitmap[i]) {
1528 fcf_vlan_id = i * 8;
1530 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1538 /* FCF not valid/available or solicitation in progress */
1539 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1540 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1541 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1544 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1546 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1548 if (phba->valid_vlan)
1549 *vlan_id = phba->vlan_id;
1551 *vlan_id = LPFC_FCOE_NULL_VID;
1556 * If there are no FCF connection table entry, driver connect to all
1559 if (list_empty(&phba->fcf_conn_rec_list)) {
1561 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1565 * When there are no FCF connect entries, use driver's default
1566 * addressing mode - FPMA.
1568 if (*addr_mode & LPFC_FCF_FPMA)
1569 *addr_mode = LPFC_FCF_FPMA;
1571 /* If FCF record report a vlan id use that vlan id */
1573 *vlan_id = fcf_vlan_id;
1575 *vlan_id = LPFC_FCOE_NULL_VID;
1579 list_for_each_entry(conn_entry,
1580 &phba->fcf_conn_rec_list, list) {
1581 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1584 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1585 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1588 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1589 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1592 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1594 * If the vlan bit map does not have the bit set for the
1595 * vlan id to be used, then it is not a match.
1597 if (!(new_fcf_record->vlan_bitmap
1598 [conn_entry->conn_rec.vlan_tag / 8] &
1599 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1604 * If connection record does not support any addressing mode,
1605 * skip the FCF record.
1607 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1608 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1612 * Check if the connection record specifies a required
1615 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1616 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1619 * If SPMA required but FCF not support this continue.
1621 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1622 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1623 new_fcf_record) & LPFC_FCF_SPMA))
1627 * If FPMA required but FCF not support this continue.
1629 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1630 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1631 new_fcf_record) & LPFC_FCF_FPMA))
1636 * This fcf record matches filtering criteria.
1638 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1644 * If user did not specify any addressing mode, or if the
1645 * preferred addressing mode specified by user is not supported
1646 * by FCF, allow fabric to pick the addressing mode.
1648 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1651 * If the user specified a required address mode, assign that
1654 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1655 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1656 *addr_mode = (conn_entry->conn_rec.flags &
1658 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1660 * If the user specified a preferred address mode, use the
1661 * addr mode only if FCF support the addr_mode.
1663 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1664 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1665 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1666 (*addr_mode & LPFC_FCF_SPMA))
1667 *addr_mode = LPFC_FCF_SPMA;
1668 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1669 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1670 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1671 (*addr_mode & LPFC_FCF_FPMA))
1672 *addr_mode = LPFC_FCF_FPMA;
1674 /* If matching connect list has a vlan id, use it */
1675 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1676 *vlan_id = conn_entry->conn_rec.vlan_tag;
1678 * If no vlan id is specified in connect list, use the vlan id
1681 else if (fcf_vlan_id)
1682 *vlan_id = fcf_vlan_id;
1684 *vlan_id = LPFC_FCOE_NULL_VID;
1693 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1694 * @phba: pointer to lpfc hba data structure.
1695 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1697 * This function check if there is any fcoe event pending while driver
1698 * scan FCF entries. If there is any pending event, it will restart the
1699 * FCF saning and return 1 else return 0.
1702 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1705 * If the Link is up and no FCoE events while in the
1706 * FCF discovery, no need to restart FCF discovery.
1708 if ((phba->link_state >= LPFC_LINK_UP) &&
1709 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1712 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1713 "2768 Pending link or FCF event during current "
1714 "handling of the previous event: link_state:x%x, "
1715 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1716 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1717 phba->fcoe_eventtag);
1719 spin_lock_irq(&phba->hbalock);
1720 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1721 spin_unlock_irq(&phba->hbalock);
1723 if (phba->link_state >= LPFC_LINK_UP) {
1724 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1725 "2780 Restart FCF table scan due to "
1726 "pending FCF event:evt_tag_at_scan:x%x, "
1727 "evt_tag_current:x%x\n",
1728 phba->fcoe_eventtag_at_fcf_scan,
1729 phba->fcoe_eventtag);
1730 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1733 * Do not continue FCF discovery and clear FCF_TS_INPROG
1736 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1737 "2833 Stop FCF discovery process due to link "
1738 "state change (x%x)\n", phba->link_state);
1739 spin_lock_irq(&phba->hbalock);
1740 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1741 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1742 spin_unlock_irq(&phba->hbalock);
1745 /* Unregister the currently registered FCF if required */
1747 spin_lock_irq(&phba->hbalock);
1748 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1749 spin_unlock_irq(&phba->hbalock);
1750 lpfc_sli4_unregister_fcf(phba);
1756 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1757 * @phba: pointer to lpfc hba data structure.
1758 * @fcf_cnt: number of eligible fcf record seen so far.
1760 * This function makes an running random selection decision on FCF record to
1761 * use through a sequence of @fcf_cnt eligible FCF records with equal
1762 * probability. To perform integer manunipulation of random numbers with
1763 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1764 * from prandom_u32() are taken as the random random number generated.
1766 * Returns true when outcome is for the newly read FCF record should be
1767 * chosen; otherwise, return false when outcome is for keeping the previously
1768 * chosen FCF record.
1771 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1775 /* Get 16-bit uniform random number */
1776 rand_num = 0xFFFF & prandom_u32();
1778 /* Decision with probability 1/fcf_cnt */
1779 if ((fcf_cnt * rand_num) < 0xFFFF)
1786 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1787 * @phba: pointer to lpfc hba data structure.
1788 * @mboxq: pointer to mailbox object.
1789 * @next_fcf_index: pointer to holder of next fcf index.
1791 * This routine parses the non-embedded fcf mailbox command by performing the
1792 * necessarily error checking, non-embedded read FCF record mailbox command
1793 * SGE parsing, and endianness swapping.
1795 * Returns the pointer to the new FCF record in the non-embedded mailbox
1796 * command DMA memory if successfully, other NULL.
1798 static struct fcf_record *
1799 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1800 uint16_t *next_fcf_index)
1803 dma_addr_t phys_addr;
1804 struct lpfc_mbx_sge sge;
1805 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1806 uint32_t shdr_status, shdr_add_status;
1807 union lpfc_sli4_cfg_shdr *shdr;
1808 struct fcf_record *new_fcf_record;
1810 /* Get the first SGE entry from the non-embedded DMA memory. This
1811 * routine only uses a single SGE.
1813 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1814 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1815 if (unlikely(!mboxq->sge_array)) {
1816 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1817 "2524 Failed to get the non-embedded SGE "
1818 "virtual address\n");
1821 virt_addr = mboxq->sge_array->addr[0];
1823 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1824 lpfc_sli_pcimem_bcopy(shdr, shdr,
1825 sizeof(union lpfc_sli4_cfg_shdr));
1826 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1827 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1828 if (shdr_status || shdr_add_status) {
1829 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1830 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1831 "2726 READ_FCF_RECORD Indicates empty "
1834 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1835 "2521 READ_FCF_RECORD mailbox failed "
1836 "with status x%x add_status x%x, "
1837 "mbx\n", shdr_status, shdr_add_status);
1841 /* Interpreting the returned information of the FCF record */
1842 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1843 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1844 sizeof(struct lpfc_mbx_read_fcf_tbl));
1845 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1846 new_fcf_record = (struct fcf_record *)(virt_addr +
1847 sizeof(struct lpfc_mbx_read_fcf_tbl));
1848 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1849 offsetof(struct fcf_record, vlan_bitmap));
1850 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1851 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1853 return new_fcf_record;
1857 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1858 * @phba: pointer to lpfc hba data structure.
1859 * @fcf_record: pointer to the fcf record.
1860 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1861 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1863 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1867 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1868 struct fcf_record *fcf_record,
1870 uint16_t next_fcf_index)
1872 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1873 "2764 READ_FCF_RECORD:\n"
1874 "\tFCF_Index : x%x\n"
1875 "\tFCF_Avail : x%x\n"
1876 "\tFCF_Valid : x%x\n"
1878 "\tFIP_Priority : x%x\n"
1879 "\tMAC_Provider : x%x\n"
1880 "\tLowest VLANID : x%x\n"
1881 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1882 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1883 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1884 "\tNext_FCF_Index: x%x\n",
1885 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1886 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1887 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1888 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1889 fcf_record->fip_priority,
1890 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1892 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1893 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1894 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1895 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1896 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1897 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1898 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1899 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1900 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1901 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1902 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1903 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1904 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1905 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1906 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1907 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1908 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1909 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1910 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1911 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1912 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1913 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1918 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1919 * @phba: pointer to lpfc hba data structure.
1920 * @fcf_rec: pointer to an existing FCF record.
1921 * @new_fcf_record: pointer to a new FCF record.
1922 * @new_vlan_id: vlan id from the new FCF record.
1924 * This function performs matching test of a new FCF record against an existing
1925 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1926 * will not be used as part of the FCF record matching criteria.
1928 * Returns true if all the fields matching, otherwise returns false.
1931 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1932 struct lpfc_fcf_rec *fcf_rec,
1933 struct fcf_record *new_fcf_record,
1934 uint16_t new_vlan_id)
1936 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1937 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1939 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1941 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1943 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1945 if (fcf_rec->priority != new_fcf_record->fip_priority)
1951 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1952 * @vport: Pointer to vport object.
1953 * @fcf_index: index to next fcf.
1955 * This function processing the roundrobin fcf failover to next fcf index.
1956 * When this function is invoked, there will be a current fcf registered
1958 * Return: 0 for continue retrying flogi on currently registered fcf;
1959 * 1 for stop flogi on currently registered fcf;
1961 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1963 struct lpfc_hba *phba = vport->phba;
1966 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1967 spin_lock_irq(&phba->hbalock);
1968 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1969 spin_unlock_irq(&phba->hbalock);
1970 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1971 "2872 Devloss tmo with no eligible "
1972 "FCF, unregister in-use FCF (x%x) "
1973 "and rescan FCF table\n",
1974 phba->fcf.current_rec.fcf_indx);
1975 lpfc_unregister_fcf_rescan(phba);
1976 goto stop_flogi_current_fcf;
1978 /* Mark the end to FLOGI roundrobin failover */
1979 phba->hba_flag &= ~FCF_RR_INPROG;
1980 /* Allow action to new fcf asynchronous event */
1981 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1982 spin_unlock_irq(&phba->hbalock);
1983 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1984 "2865 No FCF available, stop roundrobin FCF "
1985 "failover and change port state:x%x/x%x\n",
1986 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1987 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1988 goto stop_flogi_current_fcf;
1990 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1991 "2794 Try FLOGI roundrobin FCF failover to "
1992 "(x%x)\n", fcf_index);
1993 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1995 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1996 "2761 FLOGI roundrobin FCF failover "
1997 "failed (rc:x%x) to read FCF (x%x)\n",
1998 rc, phba->fcf.current_rec.fcf_indx);
2000 goto stop_flogi_current_fcf;
2004 stop_flogi_current_fcf:
2005 lpfc_can_disctmo(vport);
2010 * lpfc_sli4_fcf_pri_list_del
2011 * @phba: pointer to lpfc hba data structure.
2012 * @fcf_index the index of the fcf record to delete
2013 * This routine checks the on list flag of the fcf_index to be deleted.
2014 * If it is one the list then it is removed from the list, and the flag
2015 * is cleared. This routine grab the hbalock before removing the fcf
2016 * record from the list.
2018 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2021 struct lpfc_fcf_pri *new_fcf_pri;
2023 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2024 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2025 "3058 deleting idx x%x pri x%x flg x%x\n",
2026 fcf_index, new_fcf_pri->fcf_rec.priority,
2027 new_fcf_pri->fcf_rec.flag);
2028 spin_lock_irq(&phba->hbalock);
2029 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2030 if (phba->fcf.current_rec.priority ==
2031 new_fcf_pri->fcf_rec.priority)
2032 phba->fcf.eligible_fcf_cnt--;
2033 list_del_init(&new_fcf_pri->list);
2034 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2036 spin_unlock_irq(&phba->hbalock);
2040 * lpfc_sli4_set_fcf_flogi_fail
2041 * @phba: pointer to lpfc hba data structure.
2042 * @fcf_index the index of the fcf record to update
2043 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2044 * flag so the the round robin slection for the particular priority level
2045 * will try a different fcf record that does not have this bit set.
2046 * If the fcf record is re-read for any reason this flag is cleared brfore
2047 * adding it to the priority list.
2050 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2052 struct lpfc_fcf_pri *new_fcf_pri;
2053 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2054 spin_lock_irq(&phba->hbalock);
2055 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2056 spin_unlock_irq(&phba->hbalock);
2060 * lpfc_sli4_fcf_pri_list_add
2061 * @phba: pointer to lpfc hba data structure.
2062 * @fcf_index the index of the fcf record to add
2063 * This routine checks the priority of the fcf_index to be added.
2064 * If it is a lower priority than the current head of the fcf_pri list
2065 * then it is added to the list in the right order.
2066 * If it is the same priority as the current head of the list then it
2067 * is added to the head of the list and its bit in the rr_bmask is set.
2068 * If the fcf_index to be added is of a higher priority than the current
2069 * head of the list then the rr_bmask is cleared, its bit is set in the
2070 * rr_bmask and it is added to the head of the list.
2072 * 0=success 1=failure
2074 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2076 struct fcf_record *new_fcf_record)
2078 uint16_t current_fcf_pri;
2079 uint16_t last_index;
2080 struct lpfc_fcf_pri *fcf_pri;
2081 struct lpfc_fcf_pri *next_fcf_pri;
2082 struct lpfc_fcf_pri *new_fcf_pri;
2085 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2086 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2087 "3059 adding idx x%x pri x%x flg x%x\n",
2088 fcf_index, new_fcf_record->fip_priority,
2089 new_fcf_pri->fcf_rec.flag);
2090 spin_lock_irq(&phba->hbalock);
2091 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2092 list_del_init(&new_fcf_pri->list);
2093 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2094 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2095 if (list_empty(&phba->fcf.fcf_pri_list)) {
2096 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2097 ret = lpfc_sli4_fcf_rr_index_set(phba,
2098 new_fcf_pri->fcf_rec.fcf_index);
2102 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2103 LPFC_SLI4_FCF_TBL_INDX_MAX);
2104 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2105 ret = 0; /* Empty rr list */
2108 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2109 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2110 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2111 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2112 memset(phba->fcf.fcf_rr_bmask, 0,
2113 sizeof(*phba->fcf.fcf_rr_bmask));
2114 /* fcfs_at_this_priority_level = 1; */
2115 phba->fcf.eligible_fcf_cnt = 1;
2117 /* fcfs_at_this_priority_level++; */
2118 phba->fcf.eligible_fcf_cnt++;
2119 ret = lpfc_sli4_fcf_rr_index_set(phba,
2120 new_fcf_pri->fcf_rec.fcf_index);
2124 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2125 &phba->fcf.fcf_pri_list, list) {
2126 if (new_fcf_pri->fcf_rec.priority <=
2127 fcf_pri->fcf_rec.priority) {
2128 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2129 list_add(&new_fcf_pri->list,
2130 &phba->fcf.fcf_pri_list);
2132 list_add(&new_fcf_pri->list,
2133 &((struct lpfc_fcf_pri *)
2134 fcf_pri->list.prev)->list);
2137 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2138 || new_fcf_pri->fcf_rec.priority <
2139 next_fcf_pri->fcf_rec.priority) {
2140 list_add(&new_fcf_pri->list, &fcf_pri->list);
2144 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2150 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2151 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2152 spin_unlock_irq(&phba->hbalock);
2157 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2158 * @phba: pointer to lpfc hba data structure.
2159 * @mboxq: pointer to mailbox object.
2161 * This function iterates through all the fcf records available in
2162 * HBA and chooses the optimal FCF record for discovery. After finding
2163 * the FCF for discovery it registers the FCF record and kicks start
2165 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2166 * use an FCF record which matches fabric name and mac address of the
2167 * currently used FCF record.
2168 * If the driver supports only one FCF, it will try to use the FCF record
2169 * used by BOOT_BIOS.
2172 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2174 struct fcf_record *new_fcf_record;
2175 uint32_t boot_flag, addr_mode;
2176 uint16_t fcf_index, next_fcf_index;
2177 struct lpfc_fcf_rec *fcf_rec = NULL;
2179 bool select_new_fcf;
2182 /* If there is pending FCoE event restart FCF table scan */
2183 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2184 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2188 /* Parse the FCF record from the non-embedded mailbox command */
2189 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2191 if (!new_fcf_record) {
2192 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2193 "2765 Mailbox command READ_FCF_RECORD "
2194 "failed to retrieve a FCF record.\n");
2195 /* Let next new FCF event trigger fast failover */
2196 spin_lock_irq(&phba->hbalock);
2197 phba->hba_flag &= ~FCF_TS_INPROG;
2198 spin_unlock_irq(&phba->hbalock);
2199 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2203 /* Check the FCF record against the connection list */
2204 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2205 &addr_mode, &vlan_id);
2207 /* Log the FCF record information if turned on */
2208 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2212 * If the fcf record does not match with connect list entries
2213 * read the next entry; otherwise, this is an eligible FCF
2214 * record for roundrobin FCF failover.
2217 lpfc_sli4_fcf_pri_list_del(phba,
2218 bf_get(lpfc_fcf_record_fcf_index,
2220 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2221 "2781 FCF (x%x) failed connection "
2222 "list check: (x%x/x%x/%x)\n",
2223 bf_get(lpfc_fcf_record_fcf_index,
2225 bf_get(lpfc_fcf_record_fcf_avail,
2227 bf_get(lpfc_fcf_record_fcf_valid,
2229 bf_get(lpfc_fcf_record_fcf_sol,
2231 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2232 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2233 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2234 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2235 phba->fcf.current_rec.fcf_indx) {
2236 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2237 "2862 FCF (x%x) matches property "
2238 "of in-use FCF (x%x)\n",
2239 bf_get(lpfc_fcf_record_fcf_index,
2241 phba->fcf.current_rec.fcf_indx);
2245 * In case the current in-use FCF record becomes
2246 * invalid/unavailable during FCF discovery that
2247 * was not triggered by fast FCF failover process,
2248 * treat it as fast FCF failover.
2250 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2251 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2252 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2253 "2835 Invalid in-use FCF "
2254 "(x%x), enter FCF failover "
2256 phba->fcf.current_rec.fcf_indx);
2257 spin_lock_irq(&phba->hbalock);
2258 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2259 spin_unlock_irq(&phba->hbalock);
2260 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2261 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2262 LPFC_FCOE_FCF_GET_FIRST);
2268 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2269 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2276 * If this is not the first FCF discovery of the HBA, use last
2277 * FCF record for the discovery. The condition that a rescan
2278 * matches the in-use FCF record: fabric name, switch name, mac
2279 * address, and vlan_id.
2281 spin_lock_irq(&phba->hbalock);
2282 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2283 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2284 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2285 new_fcf_record, vlan_id)) {
2286 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2287 phba->fcf.current_rec.fcf_indx) {
2288 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2289 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2290 /* Stop FCF redisc wait timer */
2291 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2293 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2294 /* Fast failover, mark completed */
2295 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2296 spin_unlock_irq(&phba->hbalock);
2297 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2298 "2836 New FCF matches in-use "
2299 "FCF (x%x), port_state:x%x, "
2301 phba->fcf.current_rec.fcf_indx,
2302 phba->pport->port_state,
2303 phba->pport->fc_flag);
2306 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2307 "2863 New FCF (x%x) matches "
2308 "property of in-use FCF (x%x)\n",
2309 bf_get(lpfc_fcf_record_fcf_index,
2311 phba->fcf.current_rec.fcf_indx);
2314 * Read next FCF record from HBA searching for the matching
2315 * with in-use record only if not during the fast failover
2316 * period. In case of fast failover period, it shall try to
2317 * determine whether the FCF record just read should be the
2320 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2321 spin_unlock_irq(&phba->hbalock);
2326 * Update on failover FCF record only if it's in FCF fast-failover
2327 * period; otherwise, update on current FCF record.
2329 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2330 fcf_rec = &phba->fcf.failover_rec;
2332 fcf_rec = &phba->fcf.current_rec;
2334 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2336 * If the driver FCF record does not have boot flag
2337 * set and new hba fcf record has boot flag set, use
2338 * the new hba fcf record.
2340 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2341 /* Choose this FCF record */
2342 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2343 "2837 Update current FCF record "
2344 "(x%x) with new FCF record (x%x)\n",
2346 bf_get(lpfc_fcf_record_fcf_index,
2348 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2349 addr_mode, vlan_id, BOOT_ENABLE);
2350 spin_unlock_irq(&phba->hbalock);
2354 * If the driver FCF record has boot flag set and the
2355 * new hba FCF record does not have boot flag, read
2356 * the next FCF record.
2358 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2359 spin_unlock_irq(&phba->hbalock);
2363 * If the new hba FCF record has lower priority value
2364 * than the driver FCF record, use the new record.
2366 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2367 /* Choose the new FCF record with lower priority */
2368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2369 "2838 Update current FCF record "
2370 "(x%x) with new FCF record (x%x)\n",
2372 bf_get(lpfc_fcf_record_fcf_index,
2374 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2375 addr_mode, vlan_id, 0);
2376 /* Reset running random FCF selection count */
2377 phba->fcf.eligible_fcf_cnt = 1;
2378 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2379 /* Update running random FCF selection count */
2380 phba->fcf.eligible_fcf_cnt++;
2381 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2382 phba->fcf.eligible_fcf_cnt);
2383 if (select_new_fcf) {
2384 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2385 "2839 Update current FCF record "
2386 "(x%x) with new FCF record (x%x)\n",
2388 bf_get(lpfc_fcf_record_fcf_index,
2390 /* Choose the new FCF by random selection */
2391 __lpfc_update_fcf_record(phba, fcf_rec,
2393 addr_mode, vlan_id, 0);
2396 spin_unlock_irq(&phba->hbalock);
2400 * This is the first suitable FCF record, choose this record for
2401 * initial best-fit FCF.
2404 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2405 "2840 Update initial FCF candidate "
2407 bf_get(lpfc_fcf_record_fcf_index,
2409 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2410 addr_mode, vlan_id, (boot_flag ?
2412 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2413 /* Setup initial running random FCF selection count */
2414 phba->fcf.eligible_fcf_cnt = 1;
2416 spin_unlock_irq(&phba->hbalock);
2420 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2421 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2422 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2424 * Case of FCF fast failover scan
2428 * It has not found any suitable FCF record, cancel
2429 * FCF scan inprogress, and do nothing
2431 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2432 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2433 "2782 No suitable FCF found: "
2435 phba->fcoe_eventtag_at_fcf_scan,
2436 bf_get(lpfc_fcf_record_fcf_index,
2438 spin_lock_irq(&phba->hbalock);
2439 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2440 phba->hba_flag &= ~FCF_TS_INPROG;
2441 spin_unlock_irq(&phba->hbalock);
2442 /* Unregister in-use FCF and rescan */
2443 lpfc_printf_log(phba, KERN_INFO,
2445 "2864 On devloss tmo "
2446 "unreg in-use FCF and "
2447 "rescan FCF table\n");
2448 lpfc_unregister_fcf_rescan(phba);
2452 * Let next new FCF event trigger fast failover
2454 phba->hba_flag &= ~FCF_TS_INPROG;
2455 spin_unlock_irq(&phba->hbalock);
2459 * It has found a suitable FCF record that is not
2460 * the same as in-use FCF record, unregister the
2461 * in-use FCF record, replace the in-use FCF record
2462 * with the new FCF record, mark FCF fast failover
2463 * completed, and then start register the new FCF
2467 /* Unregister the current in-use FCF record */
2468 lpfc_unregister_fcf(phba);
2470 /* Replace in-use record with the new record */
2471 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2472 "2842 Replace in-use FCF (x%x) "
2473 "with failover FCF (x%x)\n",
2474 phba->fcf.current_rec.fcf_indx,
2475 phba->fcf.failover_rec.fcf_indx);
2476 memcpy(&phba->fcf.current_rec,
2477 &phba->fcf.failover_rec,
2478 sizeof(struct lpfc_fcf_rec));
2480 * Mark the fast FCF failover rediscovery completed
2481 * and the start of the first round of the roundrobin
2484 spin_lock_irq(&phba->hbalock);
2485 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2486 spin_unlock_irq(&phba->hbalock);
2487 /* Register to the new FCF record */
2488 lpfc_register_fcf(phba);
2491 * In case of transaction period to fast FCF failover,
2492 * do nothing when search to the end of the FCF table.
2494 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2495 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2498 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2499 phba->fcf.fcf_flag & FCF_IN_USE) {
2501 * In case the current in-use FCF record no
2502 * longer existed during FCF discovery that
2503 * was not triggered by fast FCF failover
2504 * process, treat it as fast FCF failover.
2506 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2507 "2841 In-use FCF record (x%x) "
2508 "not reported, entering fast "
2509 "FCF failover mode scanning.\n",
2510 phba->fcf.current_rec.fcf_indx);
2511 spin_lock_irq(&phba->hbalock);
2512 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2513 spin_unlock_irq(&phba->hbalock);
2514 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2515 LPFC_FCOE_FCF_GET_FIRST);
2518 /* Register to the new FCF record */
2519 lpfc_register_fcf(phba);
2522 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2526 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2527 lpfc_register_fcf(phba);
2533 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2534 * @phba: pointer to lpfc hba data structure.
2535 * @mboxq: pointer to mailbox object.
2537 * This is the callback function for FLOGI failure roundrobin FCF failover
2538 * read FCF record mailbox command from the eligible FCF record bmask for
2539 * performing the failover. If the FCF read back is not valid/available, it
2540 * fails through to retrying FLOGI to the currently registered FCF again.
2541 * Otherwise, if the FCF read back is valid and available, it will set the
2542 * newly read FCF record to the failover FCF record, unregister currently
2543 * registered FCF record, copy the failover FCF record to the current
2544 * FCF record, and then register the current FCF record before proceeding
2545 * to trying FLOGI on the new failover FCF.
2548 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2550 struct fcf_record *new_fcf_record;
2551 uint32_t boot_flag, addr_mode;
2552 uint16_t next_fcf_index, fcf_index;
2553 uint16_t current_fcf_index;
2557 /* If link state is not up, stop the roundrobin failover process */
2558 if (phba->link_state < LPFC_LINK_UP) {
2559 spin_lock_irq(&phba->hbalock);
2560 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2561 phba->hba_flag &= ~FCF_RR_INPROG;
2562 spin_unlock_irq(&phba->hbalock);
2566 /* Parse the FCF record from the non-embedded mailbox command */
2567 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2569 if (!new_fcf_record) {
2570 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2571 "2766 Mailbox command READ_FCF_RECORD "
2572 "failed to retrieve a FCF record. "
2573 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2574 phba->fcf.fcf_flag);
2575 lpfc_unregister_fcf_rescan(phba);
2579 /* Get the needed parameters from FCF record */
2580 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2581 &addr_mode, &vlan_id);
2583 /* Log the FCF record information if turned on */
2584 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2587 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2589 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2590 "2848 Remove ineligible FCF (x%x) from "
2591 "from roundrobin bmask\n", fcf_index);
2592 /* Clear roundrobin bmask bit for ineligible FCF */
2593 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2594 /* Perform next round of roundrobin FCF failover */
2595 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2596 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2602 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2603 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2604 "2760 Perform FLOGI roundrobin FCF failover: "
2605 "FCF (x%x) back to FCF (x%x)\n",
2606 phba->fcf.current_rec.fcf_indx, fcf_index);
2607 /* Wait 500 ms before retrying FLOGI to current FCF */
2609 lpfc_issue_init_vfi(phba->pport);
2613 /* Upload new FCF record to the failover FCF record */
2614 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2615 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2616 phba->fcf.failover_rec.fcf_indx, fcf_index);
2617 spin_lock_irq(&phba->hbalock);
2618 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2619 new_fcf_record, addr_mode, vlan_id,
2620 (boot_flag ? BOOT_ENABLE : 0));
2621 spin_unlock_irq(&phba->hbalock);
2623 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2625 /* Unregister the current in-use FCF record */
2626 lpfc_unregister_fcf(phba);
2628 /* Replace in-use record with the new record */
2629 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2630 sizeof(struct lpfc_fcf_rec));
2632 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2633 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2634 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2637 lpfc_register_fcf(phba);
2639 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2643 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2644 * @phba: pointer to lpfc hba data structure.
2645 * @mboxq: pointer to mailbox object.
2647 * This is the callback function of read FCF record mailbox command for
2648 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2649 * failover when a new FCF event happened. If the FCF read back is
2650 * valid/available and it passes the connection list check, it updates
2651 * the bmask for the eligible FCF record for roundrobin failover.
2654 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2656 struct fcf_record *new_fcf_record;
2657 uint32_t boot_flag, addr_mode;
2658 uint16_t fcf_index, next_fcf_index;
2662 /* If link state is not up, no need to proceed */
2663 if (phba->link_state < LPFC_LINK_UP)
2666 /* If FCF discovery period is over, no need to proceed */
2667 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2670 /* Parse the FCF record from the non-embedded mailbox command */
2671 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2673 if (!new_fcf_record) {
2674 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2675 "2767 Mailbox command READ_FCF_RECORD "
2676 "failed to retrieve a FCF record.\n");
2680 /* Check the connection list for eligibility */
2681 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2682 &addr_mode, &vlan_id);
2684 /* Log the FCF record information if turned on */
2685 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2691 /* Update the eligible FCF record index bmask */
2692 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2694 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2697 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2701 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2702 * @phba: pointer to lpfc hba data structure.
2703 * @mboxq: pointer to mailbox data structure.
2705 * This function handles completion of init vfi mailbox command.
2708 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2710 struct lpfc_vport *vport = mboxq->vport;
2713 * VFI not supported on interface type 0, just do the flogi
2714 * Also continue if the VFI is in use - just use the same one.
2716 if (mboxq->u.mb.mbxStatus &&
2717 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2718 LPFC_SLI_INTF_IF_TYPE_0) &&
2719 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2720 lpfc_printf_vlog(vport, KERN_ERR,
2722 "2891 Init VFI mailbox failed 0x%x\n",
2723 mboxq->u.mb.mbxStatus);
2724 mempool_free(mboxq, phba->mbox_mem_pool);
2725 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2729 lpfc_initial_flogi(vport);
2730 mempool_free(mboxq, phba->mbox_mem_pool);
2735 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2736 * @vport: pointer to lpfc_vport data structure.
2738 * This function issue a init_vfi mailbox command to initialize the VFI and
2739 * VPI for the physical port.
2742 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2744 LPFC_MBOXQ_t *mboxq;
2746 struct lpfc_hba *phba = vport->phba;
2748 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2750 lpfc_printf_vlog(vport, KERN_ERR,
2751 LOG_MBOX, "2892 Failed to allocate "
2752 "init_vfi mailbox\n");
2755 lpfc_init_vfi(mboxq, vport);
2756 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2757 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2758 if (rc == MBX_NOT_FINISHED) {
2759 lpfc_printf_vlog(vport, KERN_ERR,
2760 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2761 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2766 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2767 * @phba: pointer to lpfc hba data structure.
2768 * @mboxq: pointer to mailbox data structure.
2770 * This function handles completion of init vpi mailbox command.
2773 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2775 struct lpfc_vport *vport = mboxq->vport;
2776 struct lpfc_nodelist *ndlp;
2777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2779 if (mboxq->u.mb.mbxStatus) {
2780 lpfc_printf_vlog(vport, KERN_ERR,
2782 "2609 Init VPI mailbox failed 0x%x\n",
2783 mboxq->u.mb.mbxStatus);
2784 mempool_free(mboxq, phba->mbox_mem_pool);
2785 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2788 spin_lock_irq(shost->host_lock);
2789 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2790 spin_unlock_irq(shost->host_lock);
2792 /* If this port is physical port or FDISC is done, do reg_vpi */
2793 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2794 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2796 lpfc_printf_vlog(vport, KERN_ERR,
2798 "2731 Cannot find fabric "
2799 "controller node\n");
2801 lpfc_register_new_vport(phba, vport, ndlp);
2802 mempool_free(mboxq, phba->mbox_mem_pool);
2806 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2807 lpfc_initial_fdisc(vport);
2809 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2811 "2606 No NPIV Fabric support\n");
2813 mempool_free(mboxq, phba->mbox_mem_pool);
2818 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2819 * @vport: pointer to lpfc_vport data structure.
2821 * This function issue a init_vpi mailbox command to initialize
2822 * VPI for the vport.
2825 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2827 LPFC_MBOXQ_t *mboxq;
2830 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2831 vpi = lpfc_alloc_vpi(vport->phba);
2833 lpfc_printf_vlog(vport, KERN_ERR,
2835 "3303 Failed to obtain vport vpi\n");
2836 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2842 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2844 lpfc_printf_vlog(vport, KERN_ERR,
2845 LOG_MBOX, "2607 Failed to allocate "
2846 "init_vpi mailbox\n");
2849 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2850 mboxq->vport = vport;
2851 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2852 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2853 if (rc == MBX_NOT_FINISHED) {
2854 lpfc_printf_vlog(vport, KERN_ERR,
2855 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2856 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2861 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2862 * @phba: pointer to lpfc hba data structure.
2864 * This function loops through the list of vports on the @phba and issues an
2865 * FDISC if possible.
2868 lpfc_start_fdiscs(struct lpfc_hba *phba)
2870 struct lpfc_vport **vports;
2873 vports = lpfc_create_vport_work_array(phba);
2874 if (vports != NULL) {
2875 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2876 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2878 /* There are no vpi for this vport */
2879 if (vports[i]->vpi > phba->max_vpi) {
2880 lpfc_vport_set_state(vports[i],
2884 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2885 lpfc_vport_set_state(vports[i],
2889 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2890 lpfc_issue_init_vpi(vports[i]);
2893 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2894 lpfc_initial_fdisc(vports[i]);
2896 lpfc_vport_set_state(vports[i],
2897 FC_VPORT_NO_FABRIC_SUPP);
2898 lpfc_printf_vlog(vports[i], KERN_ERR,
2901 "Fabric support\n");
2905 lpfc_destroy_vport_work_array(phba, vports);
2909 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2911 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2912 struct lpfc_vport *vport = mboxq->vport;
2913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2916 * VFI not supported for interface type 0, so ignore any mailbox
2917 * error (except VFI in use) and continue with the discovery.
2919 if (mboxq->u.mb.mbxStatus &&
2920 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2921 LPFC_SLI_INTF_IF_TYPE_0) &&
2922 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2923 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2924 "2018 REG_VFI mbxStatus error x%x "
2926 mboxq->u.mb.mbxStatus, vport->port_state);
2927 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2928 /* FLOGI failed, use loop map to make discovery list */
2929 lpfc_disc_list_loopmap(vport);
2930 /* Start discovery */
2931 lpfc_disc_start(vport);
2934 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2938 /* If the VFI is already registered, there is nothing else to do
2939 * Unless this was a VFI update and we are in PT2PT mode, then
2940 * we should drop through to set the port state to ready.
2942 if (vport->fc_flag & FC_VFI_REGISTERED)
2943 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2944 vport->fc_flag & FC_PT2PT))
2947 /* The VPI is implicitly registered when the VFI is registered */
2948 spin_lock_irq(shost->host_lock);
2949 vport->vpi_state |= LPFC_VPI_REGISTERED;
2950 vport->fc_flag |= FC_VFI_REGISTERED;
2951 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2952 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2953 spin_unlock_irq(shost->host_lock);
2955 /* In case SLI4 FC loopback test, we are ready */
2956 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2957 (phba->link_flag & LS_LOOPBACK_MODE)) {
2958 phba->link_state = LPFC_HBA_READY;
2962 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2963 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
2964 "alpacnt:%d LinkState:%x topology:%x\n",
2965 vport->port_state, vport->fc_flag, vport->fc_myDID,
2966 vport->phba->alpa_map[0],
2967 phba->link_state, phba->fc_topology);
2969 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2971 * For private loop or for NPort pt2pt,
2972 * just start discovery and we are done.
2974 if ((vport->fc_flag & FC_PT2PT) ||
2975 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2976 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2978 /* Use loop map to make discovery list */
2979 lpfc_disc_list_loopmap(vport);
2980 /* Start discovery */
2981 if (vport->fc_flag & FC_PT2PT)
2982 vport->port_state = LPFC_VPORT_READY;
2984 lpfc_disc_start(vport);
2986 lpfc_start_fdiscs(phba);
2987 lpfc_do_scr_ns_plogi(phba, vport);
2992 mempool_free(mboxq, phba->mbox_mem_pool);
2993 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2999 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3001 MAILBOX_t *mb = &pmb->u.mb;
3002 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
3003 struct lpfc_vport *vport = pmb->vport;
3006 /* Check for error */
3007 if (mb->mbxStatus) {
3008 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3009 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3010 "0319 READ_SPARAM mbxStatus error x%x "
3012 mb->mbxStatus, vport->port_state);
3013 lpfc_linkdown(phba);
3017 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3018 sizeof (struct serv_parm));
3019 lpfc_update_vport_wwn(vport);
3020 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3021 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3022 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3025 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3027 mempool_free(pmb, phba->mbox_mem_pool);
3031 pmb->context1 = NULL;
3032 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3034 lpfc_issue_clear_la(phba, vport);
3035 mempool_free(pmb, phba->mbox_mem_pool);
3040 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3042 struct lpfc_vport *vport = phba->pport;
3043 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3044 struct Scsi_Host *shost;
3046 struct lpfc_dmabuf *mp;
3048 struct fcf_record *fcf_record;
3049 uint32_t fc_flags = 0;
3051 spin_lock_irq(&phba->hbalock);
3052 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3053 case LPFC_LINK_SPEED_1GHZ:
3054 case LPFC_LINK_SPEED_2GHZ:
3055 case LPFC_LINK_SPEED_4GHZ:
3056 case LPFC_LINK_SPEED_8GHZ:
3057 case LPFC_LINK_SPEED_10GHZ:
3058 case LPFC_LINK_SPEED_16GHZ:
3059 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3062 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3066 if (phba->fc_topology &&
3067 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3068 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3069 "3314 Toplogy changed was 0x%x is 0x%x\n",
3071 bf_get(lpfc_mbx_read_top_topology, la));
3072 phba->fc_topology_changed = 1;
3075 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3076 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3078 shost = lpfc_shost_from_vport(vport);
3079 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3080 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3082 /* if npiv is enabled and this adapter supports npiv log
3083 * a message that npiv is not supported in this topology
3085 if (phba->cfg_enable_npiv && phba->max_vpi)
3086 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3087 "1309 Link Up Event npiv not supported in loop "
3089 /* Get Loop Map information */
3090 if (bf_get(lpfc_mbx_read_top_il, la))
3091 fc_flags |= FC_LBIT;
3093 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3094 i = la->lilpBde64.tus.f.bdeSize;
3097 phba->alpa_map[0] = 0;
3099 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3110 numalpa = phba->alpa_map[0];
3112 while (j < numalpa) {
3113 memset(un.pamap, 0, 16);
3114 for (k = 1; j < numalpa; k++) {
3116 phba->alpa_map[j + 1];
3121 /* Link Up Event ALPA map */
3122 lpfc_printf_log(phba,
3125 "1304 Link Up Event "
3126 "ALPA map Data: x%x "
3128 un.pa.wd1, un.pa.wd2,
3129 un.pa.wd3, un.pa.wd4);
3134 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3135 if (phba->max_vpi && phba->cfg_enable_npiv &&
3136 (phba->sli_rev >= LPFC_SLI_REV3))
3137 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3139 vport->fc_myDID = phba->fc_pref_DID;
3140 fc_flags |= FC_LBIT;
3142 spin_unlock_irq(&phba->hbalock);
3145 spin_lock_irq(shost->host_lock);
3146 vport->fc_flag |= fc_flags;
3147 spin_unlock_irq(shost->host_lock);
3151 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3155 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3157 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3160 sparam_mbox->vport = vport;
3161 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3162 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3163 if (rc == MBX_NOT_FINISHED) {
3164 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3165 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3167 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3171 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3172 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3175 vport->port_state = LPFC_LOCAL_CFG_LINK;
3176 lpfc_config_link(phba, cfglink_mbox);
3177 cfglink_mbox->vport = vport;
3178 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3179 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3180 if (rc == MBX_NOT_FINISHED) {
3181 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3185 vport->port_state = LPFC_VPORT_UNKNOWN;
3187 * Add the driver's default FCF record at FCF index 0 now. This
3188 * is phase 1 implementation that support FCF index 0 and driver
3191 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3192 fcf_record = kzalloc(sizeof(struct fcf_record),
3194 if (unlikely(!fcf_record)) {
3195 lpfc_printf_log(phba, KERN_ERR,
3197 "2554 Could not allocate memory for "
3203 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3204 LPFC_FCOE_FCF_DEF_INDEX);
3205 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3207 lpfc_printf_log(phba, KERN_ERR,
3209 "2013 Could not manually add FCF "
3210 "record 0, status %d\n", rc);
3218 * The driver is expected to do FIP/FCF. Call the port
3219 * and get the FCF Table.
3221 spin_lock_irq(&phba->hbalock);
3222 if (phba->hba_flag & FCF_TS_INPROG) {
3223 spin_unlock_irq(&phba->hbalock);
3226 /* This is the initial FCF discovery scan */
3227 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3228 spin_unlock_irq(&phba->hbalock);
3229 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3230 "2778 Start FCF table scan at linkup\n");
3231 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3232 LPFC_FCOE_FCF_GET_FIRST);
3234 spin_lock_irq(&phba->hbalock);
3235 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3236 spin_unlock_irq(&phba->hbalock);
3239 /* Reset FCF roundrobin bmask for new discovery */
3240 lpfc_sli4_clear_fcf_rr_bmask(phba);
3245 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3246 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3247 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3248 vport->port_state, sparam_mbox, cfglink_mbox);
3249 lpfc_issue_clear_la(phba, vport);
3254 lpfc_enable_la(struct lpfc_hba *phba)
3257 struct lpfc_sli *psli = &phba->sli;
3258 spin_lock_irq(&phba->hbalock);
3259 psli->sli_flag |= LPFC_PROCESS_LA;
3260 if (phba->sli_rev <= LPFC_SLI_REV3) {
3261 control = readl(phba->HCregaddr);
3262 control |= HC_LAINT_ENA;
3263 writel(control, phba->HCregaddr);
3264 readl(phba->HCregaddr); /* flush */
3266 spin_unlock_irq(&phba->hbalock);
3270 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3272 lpfc_linkdown(phba);
3273 lpfc_enable_la(phba);
3274 lpfc_unregister_unused_fcf(phba);
3275 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3280 * This routine handles processing a READ_TOPOLOGY mailbox
3281 * command upon completion. It is setup in the LPFC_MBOXQ
3282 * as the completion routine when the command is
3283 * handed off to the SLI layer.
3286 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3288 struct lpfc_vport *vport = pmb->vport;
3289 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3290 struct lpfc_mbx_read_top *la;
3291 MAILBOX_t *mb = &pmb->u.mb;
3292 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3294 /* Unblock ELS traffic */
3295 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
3296 /* Check for error */
3297 if (mb->mbxStatus) {
3298 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3299 "1307 READ_LA mbox error x%x state x%x\n",
3300 mb->mbxStatus, vport->port_state);
3301 lpfc_mbx_issue_link_down(phba);
3302 phba->link_state = LPFC_HBA_ERROR;
3303 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3306 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3308 memcpy(&phba->alpa_map[0], mp->virt, 128);
3310 spin_lock_irq(shost->host_lock);
3311 if (bf_get(lpfc_mbx_read_top_pb, la))
3312 vport->fc_flag |= FC_BYPASSED_MODE;
3314 vport->fc_flag &= ~FC_BYPASSED_MODE;
3315 spin_unlock_irq(shost->host_lock);
3317 if (phba->fc_eventTag <= la->eventTag) {
3318 phba->fc_stat.LinkMultiEvent++;
3319 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
3320 if (phba->fc_eventTag != 0)
3321 lpfc_linkdown(phba);
3324 phba->fc_eventTag = la->eventTag;
3325 if (phba->sli_rev < LPFC_SLI_REV4) {
3326 spin_lock_irq(&phba->hbalock);
3327 if (bf_get(lpfc_mbx_read_top_mm, la))
3328 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3330 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3331 spin_unlock_irq(&phba->hbalock);
3334 phba->link_events++;
3335 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
3336 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3337 phba->fc_stat.LinkUp++;
3338 if (phba->link_flag & LS_LOOPBACK_MODE) {
3339 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3340 "1306 Link Up Event in loop back mode "
3341 "x%x received Data: x%x x%x x%x x%x\n",
3342 la->eventTag, phba->fc_eventTag,
3343 bf_get(lpfc_mbx_read_top_alpa_granted,
3345 bf_get(lpfc_mbx_read_top_link_spd, la),
3348 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3349 "1303 Link Up Event x%x received "
3350 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3351 la->eventTag, phba->fc_eventTag,
3352 bf_get(lpfc_mbx_read_top_alpa_granted,
3354 bf_get(lpfc_mbx_read_top_link_spd, la),
3356 bf_get(lpfc_mbx_read_top_mm, la),
3357 bf_get(lpfc_mbx_read_top_fa, la),
3358 phba->wait_4_mlo_maint_flg);
3360 lpfc_mbx_process_link_up(phba, la);
3361 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3362 LPFC_ATT_LINK_DOWN) {
3363 phba->fc_stat.LinkDown++;
3364 if (phba->link_flag & LS_LOOPBACK_MODE)
3365 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3366 "1308 Link Down Event in loop back mode "
3368 "Data: x%x x%x x%x\n",
3369 la->eventTag, phba->fc_eventTag,
3370 phba->pport->port_state, vport->fc_flag);
3372 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3373 "1305 Link Down Event x%x received "
3374 "Data: x%x x%x x%x x%x x%x\n",
3375 la->eventTag, phba->fc_eventTag,
3376 phba->pport->port_state, vport->fc_flag,
3377 bf_get(lpfc_mbx_read_top_mm, la),
3378 bf_get(lpfc_mbx_read_top_fa, la));
3379 lpfc_mbx_issue_link_down(phba);
3381 if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) &&
3382 ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) {
3383 if (phba->link_state != LPFC_LINK_DOWN) {
3384 phba->fc_stat.LinkDown++;
3385 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3386 "1312 Link Down Event x%x received "
3387 "Data: x%x x%x x%x\n",
3388 la->eventTag, phba->fc_eventTag,
3389 phba->pport->port_state, vport->fc_flag);
3390 lpfc_mbx_issue_link_down(phba);
3392 lpfc_enable_la(phba);
3394 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3395 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3396 "Data: x%x x%x x%x\n",
3397 la->eventTag, phba->fc_eventTag,
3398 phba->pport->port_state, vport->fc_flag);
3400 * The cmnd that triggered this will be waiting for this
3403 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3404 if (phba->wait_4_mlo_maint_flg) {
3405 phba->wait_4_mlo_maint_flg = 0;
3406 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3410 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3411 bf_get(lpfc_mbx_read_top_fa, la)) {
3412 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3413 lpfc_issue_clear_la(phba, vport);
3414 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3416 bf_get(lpfc_mbx_read_top_fa, la));
3419 lpfc_mbx_cmpl_read_topology_free_mbuf:
3420 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3422 mempool_free(pmb, phba->mbox_mem_pool);
3427 * This routine handles processing a REG_LOGIN mailbox
3428 * command upon completion. It is setup in the LPFC_MBOXQ
3429 * as the completion routine when the command is
3430 * handed off to the SLI layer.
3433 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3435 struct lpfc_vport *vport = pmb->vport;
3436 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3437 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3438 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3440 pmb->context1 = NULL;
3441 pmb->context2 = NULL;
3443 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3444 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3445 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3446 atomic_read(&ndlp->kref.refcount),
3447 ndlp->nlp_usg_map, ndlp);
3448 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3449 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3451 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3452 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3453 /* We rcvd a rscn after issuing this
3454 * mbox reg login, we may have cycled
3455 * back through the state and be
3456 * back at reg login state so this
3457 * mbox needs to be ignored becase
3458 * there is another reg login in
3461 spin_lock_irq(shost->host_lock);
3462 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3463 spin_unlock_irq(shost->host_lock);
3465 /* Good status, call state machine */
3466 lpfc_disc_state_machine(vport, ndlp, pmb,
3467 NLP_EVT_CMPL_REG_LOGIN);
3469 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3471 mempool_free(pmb, phba->mbox_mem_pool);
3472 /* decrement the node reference count held for this callback
3481 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3483 MAILBOX_t *mb = &pmb->u.mb;
3484 struct lpfc_vport *vport = pmb->vport;
3485 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3487 switch (mb->mbxStatus) {
3490 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3491 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3494 /* If VPI is busy, reset the HBA */
3496 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3497 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3498 vport->vpi, mb->mbxStatus);
3499 if (!(phba->pport->load_flag & FC_UNLOADING))
3500 lpfc_workq_post_event(phba, NULL, NULL,
3501 LPFC_EVT_RESET_HBA);
3503 spin_lock_irq(shost->host_lock);
3504 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3505 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3506 spin_unlock_irq(shost->host_lock);
3507 vport->unreg_vpi_cmpl = VPORT_OK;
3508 mempool_free(pmb, phba->mbox_mem_pool);
3509 lpfc_cleanup_vports_rrqs(vport, NULL);
3511 * This shost reference might have been taken at the beginning of
3512 * lpfc_vport_delete()
3514 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3515 scsi_host_put(shost);
3519 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3521 struct lpfc_hba *phba = vport->phba;
3525 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3529 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3530 mbox->vport = vport;
3531 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3532 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3533 if (rc == MBX_NOT_FINISHED) {
3534 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3535 "1800 Could not issue unreg_vpi\n");
3536 mempool_free(mbox, phba->mbox_mem_pool);
3537 vport->unreg_vpi_cmpl = VPORT_ERROR;
3544 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3546 struct lpfc_vport *vport = pmb->vport;
3547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3548 MAILBOX_t *mb = &pmb->u.mb;
3550 switch (mb->mbxStatus) {
3554 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3555 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3557 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3558 spin_lock_irq(shost->host_lock);
3559 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3560 spin_unlock_irq(shost->host_lock);
3561 vport->fc_myDID = 0;
3565 spin_lock_irq(shost->host_lock);
3566 vport->vpi_state |= LPFC_VPI_REGISTERED;
3567 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3568 spin_unlock_irq(shost->host_lock);
3569 vport->num_disc_nodes = 0;
3570 /* go thru NPR list and issue ELS PLOGIs */
3571 if (vport->fc_npr_cnt)
3572 lpfc_els_disc_plogi(vport);
3574 if (!vport->num_disc_nodes) {
3575 spin_lock_irq(shost->host_lock);
3576 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3577 spin_unlock_irq(shost->host_lock);
3578 lpfc_can_disctmo(vport);
3580 vport->port_state = LPFC_VPORT_READY;
3583 mempool_free(pmb, phba->mbox_mem_pool);
3588 * lpfc_create_static_vport - Read HBA config region to create static vports.
3589 * @phba: pointer to lpfc hba data structure.
3591 * This routine issue a DUMP mailbox command for config region 22 to get
3592 * the list of static vports to be created. The function create vports
3593 * based on the information returned from the HBA.
3596 lpfc_create_static_vport(struct lpfc_hba *phba)
3598 LPFC_MBOXQ_t *pmb = NULL;
3600 struct static_vport_info *vport_info;
3601 int mbx_wait_rc = 0, i;
3602 struct fc_vport_identifiers vport_id;
3603 struct fc_vport *new_fc_vport;
3604 struct Scsi_Host *shost;
3605 struct lpfc_vport *vport;
3606 uint16_t offset = 0;
3607 uint8_t *vport_buff;
3608 struct lpfc_dmabuf *mp;
3609 uint32_t byte_count = 0;
3611 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3613 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3614 "0542 lpfc_create_static_vport failed to"
3615 " allocate mailbox memory\n");
3618 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3621 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3623 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3624 "0543 lpfc_create_static_vport failed to"
3625 " allocate vport_info\n");
3626 mempool_free(pmb, phba->mbox_mem_pool);
3630 vport_buff = (uint8_t *) vport_info;
3632 /* free dma buffer from previous round */
3633 if (pmb->context1) {
3634 mp = (struct lpfc_dmabuf *)pmb->context1;
3635 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3638 if (lpfc_dump_static_vport(phba, pmb, offset))
3641 pmb->vport = phba->pport;
3642 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3645 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3646 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3647 "0544 lpfc_create_static_vport failed to"
3648 " issue dump mailbox command ret 0x%x "
3650 mbx_wait_rc, mb->mbxStatus);
3654 if (phba->sli_rev == LPFC_SLI_REV4) {
3655 byte_count = pmb->u.mqe.un.mb_words[5];
3656 mp = (struct lpfc_dmabuf *)pmb->context1;
3657 if (byte_count > sizeof(struct static_vport_info) -
3659 byte_count = sizeof(struct static_vport_info)
3661 memcpy(vport_buff + offset, mp->virt, byte_count);
3662 offset += byte_count;
3664 if (mb->un.varDmp.word_cnt >
3665 sizeof(struct static_vport_info) - offset)
3666 mb->un.varDmp.word_cnt =
3667 sizeof(struct static_vport_info)
3669 byte_count = mb->un.varDmp.word_cnt;
3670 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3671 vport_buff + offset,
3674 offset += byte_count;
3677 } while (byte_count &&
3678 offset < sizeof(struct static_vport_info));
3681 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3682 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3683 != VPORT_INFO_REV)) {
3684 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3685 "0545 lpfc_create_static_vport bad"
3686 " information header 0x%x 0x%x\n",
3687 le32_to_cpu(vport_info->signature),
3688 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3693 shost = lpfc_shost_from_vport(phba->pport);
3695 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3696 memset(&vport_id, 0, sizeof(vport_id));
3697 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3698 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3699 if (!vport_id.port_name || !vport_id.node_name)
3702 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3703 vport_id.vport_type = FC_PORTTYPE_NPIV;
3704 vport_id.disable = false;
3705 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3707 if (!new_fc_vport) {
3708 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3709 "0546 lpfc_create_static_vport failed to"
3714 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3715 vport->vport_flag |= STATIC_VPORT;
3720 if (mbx_wait_rc != MBX_TIMEOUT) {
3721 if (pmb->context1) {
3722 mp = (struct lpfc_dmabuf *)pmb->context1;
3723 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3726 mempool_free(pmb, phba->mbox_mem_pool);
3733 * This routine handles processing a Fabric REG_LOGIN mailbox
3734 * command upon completion. It is setup in the LPFC_MBOXQ
3735 * as the completion routine when the command is
3736 * handed off to the SLI layer.
3739 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3741 struct lpfc_vport *vport = pmb->vport;
3742 MAILBOX_t *mb = &pmb->u.mb;
3743 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3744 struct lpfc_nodelist *ndlp;
3745 struct Scsi_Host *shost;
3747 ndlp = (struct lpfc_nodelist *) pmb->context2;
3748 pmb->context1 = NULL;
3749 pmb->context2 = NULL;
3751 if (mb->mbxStatus) {
3752 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3753 "0258 Register Fabric login error: 0x%x\n",
3755 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3757 mempool_free(pmb, phba->mbox_mem_pool);
3759 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3760 /* FLOGI failed, use loop map to make discovery list */
3761 lpfc_disc_list_loopmap(vport);
3763 /* Start discovery */
3764 lpfc_disc_start(vport);
3765 /* Decrement the reference count to ndlp after the
3766 * reference to the ndlp are done.
3772 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3773 /* Decrement the reference count to ndlp after the reference
3774 * to the ndlp are done.
3780 if (phba->sli_rev < LPFC_SLI_REV4)
3781 ndlp->nlp_rpi = mb->un.varWords[0];
3782 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3783 ndlp->nlp_type |= NLP_FABRIC;
3784 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3786 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3787 /* when physical port receive logo donot start
3788 * vport discovery */
3789 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3790 lpfc_start_fdiscs(phba);
3792 shost = lpfc_shost_from_vport(vport);
3793 spin_lock_irq(shost->host_lock);
3794 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3795 spin_unlock_irq(shost->host_lock);
3797 lpfc_do_scr_ns_plogi(phba, vport);
3800 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3802 mempool_free(pmb, phba->mbox_mem_pool);
3804 /* Drop the reference count from the mbox at the end after
3805 * all the current reference to the ndlp have been done.
3812 * This routine handles processing a NameServer REG_LOGIN mailbox
3813 * command upon completion. It is setup in the LPFC_MBOXQ
3814 * as the completion routine when the command is
3815 * handed off to the SLI layer.
3818 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3820 MAILBOX_t *mb = &pmb->u.mb;
3821 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3822 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3823 struct lpfc_vport *vport = pmb->vport;
3825 pmb->context1 = NULL;
3826 pmb->context2 = NULL;
3828 if (mb->mbxStatus) {
3830 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3831 "0260 Register NameServer error: 0x%x\n",
3833 /* decrement the node reference count held for this
3834 * callback function.
3837 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3839 mempool_free(pmb, phba->mbox_mem_pool);
3841 /* If no other thread is using the ndlp, free it */
3842 lpfc_nlp_not_used(ndlp);
3844 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3846 * RegLogin failed, use loop map to make discovery
3849 lpfc_disc_list_loopmap(vport);
3851 /* Start discovery */
3852 lpfc_disc_start(vport);
3855 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3859 if (phba->sli_rev < LPFC_SLI_REV4)
3860 ndlp->nlp_rpi = mb->un.varWords[0];
3861 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3862 ndlp->nlp_type |= NLP_FABRIC;
3863 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3864 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3865 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
3866 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3867 atomic_read(&ndlp->kref.refcount),
3868 ndlp->nlp_usg_map, ndlp);
3870 if (vport->port_state < LPFC_VPORT_READY) {
3871 /* Link up discovery requires Fabric registration. */
3872 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3873 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3874 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3875 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3876 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0);
3878 /* Issue SCR just before NameServer GID_FT Query */
3879 lpfc_issue_els_scr(vport, SCR_DID, 0);
3882 vport->fc_ns_retry = 0;
3883 /* Good status, issue CT Request to NameServer */
3884 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
3885 /* Cannot issue NameServer Query, so finish up discovery */
3889 /* decrement the node reference count held for this
3890 * callback function.
3893 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3895 mempool_free(pmb, phba->mbox_mem_pool);
3901 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3904 struct fc_rport *rport;
3905 struct lpfc_rport_data *rdata;
3906 struct fc_rport_identifiers rport_ids;
3907 struct lpfc_hba *phba = vport->phba;
3909 /* Remote port has reappeared. Re-register w/ FC transport */
3910 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3911 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
3912 rport_ids.port_id = ndlp->nlp_DID;
3913 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3916 * We leave our node pointer in rport->dd_data when we unregister a
3917 * FCP target port. But fc_remote_port_add zeros the space to which
3918 * rport->dd_data points. So, if we're reusing a previously
3919 * registered port, drop the reference that we took the last time we
3920 * registered the port.
3922 if (ndlp->rport && ndlp->rport->dd_data &&
3923 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
3926 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3927 "rport add: did:x%x flg:x%x type x%x",
3928 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3930 /* Don't add the remote port if unloading. */
3931 if (vport->load_flag & FC_UNLOADING)
3934 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
3935 if (!rport || !get_device(&rport->dev)) {
3936 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3937 "Warning: fc_remote_port_add failed\n");
3941 /* initialize static port data */
3942 rport->maxframe_size = ndlp->nlp_maxframe;
3943 rport->supported_classes = ndlp->nlp_class_sup;
3944 rdata = rport->dd_data;
3945 rdata->pnode = lpfc_nlp_get(ndlp);
3947 if (ndlp->nlp_type & NLP_FCP_TARGET)
3948 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3949 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3950 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3952 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3953 fc_remote_port_rolechg(rport, rport_ids.roles);
3955 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3956 "3183 rport register x%06x, rport %p role x%x\n",
3957 ndlp->nlp_DID, rport, rport_ids.roles);
3959 if ((rport->scsi_target_id != -1) &&
3960 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
3961 ndlp->nlp_sid = rport->scsi_target_id;
3967 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
3969 struct fc_rport *rport = ndlp->rport;
3971 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3972 "rport delete: did:x%x flg:x%x type x%x",
3973 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3975 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3976 "3184 rport unregister x%06x, rport %p\n",
3977 ndlp->nlp_DID, rport);
3979 fc_remote_port_delete(rport);
3985 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
3987 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3989 spin_lock_irq(shost->host_lock);
3991 case NLP_STE_UNUSED_NODE:
3992 vport->fc_unused_cnt += count;
3994 case NLP_STE_PLOGI_ISSUE:
3995 vport->fc_plogi_cnt += count;
3997 case NLP_STE_ADISC_ISSUE:
3998 vport->fc_adisc_cnt += count;
4000 case NLP_STE_REG_LOGIN_ISSUE:
4001 vport->fc_reglogin_cnt += count;
4003 case NLP_STE_PRLI_ISSUE:
4004 vport->fc_prli_cnt += count;
4006 case NLP_STE_UNMAPPED_NODE:
4007 vport->fc_unmap_cnt += count;
4009 case NLP_STE_MAPPED_NODE:
4010 vport->fc_map_cnt += count;
4012 case NLP_STE_NPR_NODE:
4013 if (vport->fc_npr_cnt == 0 && count == -1)
4014 vport->fc_npr_cnt = 0;
4016 vport->fc_npr_cnt += count;
4019 spin_unlock_irq(shost->host_lock);
4023 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4024 int old_state, int new_state)
4026 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4028 if (new_state == NLP_STE_UNMAPPED_NODE) {
4029 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4030 ndlp->nlp_type |= NLP_FC_NODE;
4032 if (new_state == NLP_STE_MAPPED_NODE)
4033 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4034 if (new_state == NLP_STE_NPR_NODE)
4035 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4037 /* Transport interface */
4038 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
4039 old_state == NLP_STE_UNMAPPED_NODE)) {
4040 vport->phba->nport_event_cnt++;
4041 lpfc_unregister_remote_port(ndlp);
4044 if (new_state == NLP_STE_MAPPED_NODE ||
4045 new_state == NLP_STE_UNMAPPED_NODE) {
4046 vport->phba->nport_event_cnt++;
4048 * Tell the fc transport about the port, if we haven't
4049 * already. If we have, and it's a scsi entity, be
4050 * sure to unblock any attached scsi devices
4052 lpfc_register_remote_port(vport, ndlp);
4054 if ((new_state == NLP_STE_MAPPED_NODE) &&
4055 (vport->stat_data_enabled)) {
4057 * A new target is discovered, if there is no buffer for
4058 * statistical data collection allocate buffer.
4060 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4061 sizeof(struct lpfc_scsicmd_bkt),
4064 if (!ndlp->lat_data)
4065 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4066 "0286 lpfc_nlp_state_cleanup failed to "
4067 "allocate statistical data buffer DID "
4068 "0x%x\n", ndlp->nlp_DID);
4071 * if we added to Mapped list, but the remote port
4072 * registration failed or assigned a target id outside
4073 * our presentable range - move the node to the
4076 if (new_state == NLP_STE_MAPPED_NODE &&
4078 ndlp->rport->scsi_target_id == -1 ||
4079 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4080 spin_lock_irq(shost->host_lock);
4081 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4082 spin_unlock_irq(shost->host_lock);
4083 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4088 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4090 static char *states[] = {
4091 [NLP_STE_UNUSED_NODE] = "UNUSED",
4092 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4093 [NLP_STE_ADISC_ISSUE] = "ADISC",
4094 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4095 [NLP_STE_PRLI_ISSUE] = "PRLI",
4096 [NLP_STE_LOGO_ISSUE] = "LOGO",
4097 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4098 [NLP_STE_MAPPED_NODE] = "MAPPED",
4099 [NLP_STE_NPR_NODE] = "NPR",
4102 if (state < NLP_STE_MAX_STATE && states[state])
4103 strlcpy(buffer, states[state], size);
4105 snprintf(buffer, size, "unknown (%d)", state);
4110 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4114 int old_state = ndlp->nlp_state;
4115 char name1[16], name2[16];
4117 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4118 "0904 NPort state transition x%06x, %s -> %s\n",
4120 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4121 lpfc_nlp_state_name(name2, sizeof(name2), state));
4123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4124 "node statechg did:x%x old:%d ste:%d",
4125 ndlp->nlp_DID, old_state, state);
4127 if (old_state == NLP_STE_NPR_NODE &&
4128 state != NLP_STE_NPR_NODE)
4129 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4130 if (old_state == NLP_STE_UNMAPPED_NODE) {
4131 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4132 ndlp->nlp_type &= ~NLP_FC_NODE;
4135 if (list_empty(&ndlp->nlp_listp)) {
4136 spin_lock_irq(shost->host_lock);
4137 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4138 spin_unlock_irq(shost->host_lock);
4139 } else if (old_state)
4140 lpfc_nlp_counters(vport, old_state, -1);
4142 ndlp->nlp_state = state;
4143 lpfc_nlp_counters(vport, state, 1);
4144 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4148 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4150 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4152 if (list_empty(&ndlp->nlp_listp)) {
4153 spin_lock_irq(shost->host_lock);
4154 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4155 spin_unlock_irq(shost->host_lock);
4160 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4162 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4164 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4165 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4166 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4167 spin_lock_irq(shost->host_lock);
4168 list_del_init(&ndlp->nlp_listp);
4169 spin_unlock_irq(shost->host_lock);
4170 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4171 NLP_STE_UNUSED_NODE);
4175 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4177 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4178 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4179 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4180 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4181 NLP_STE_UNUSED_NODE);
4184 * lpfc_initialize_node - Initialize all fields of node object
4185 * @vport: Pointer to Virtual Port object.
4186 * @ndlp: Pointer to FC node object.
4187 * @did: FC_ID of the node.
4189 * This function is always called when node object need to be initialized.
4190 * It initializes all the fields of the node object. Although the reference
4191 * to phba from @ndlp can be obtained indirectly through it's reference to
4192 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4193 * to the life-span of the @ndlp might go beyond the existence of @vport as
4194 * the final release of ndlp is determined by its reference count. And, the
4195 * operation on @ndlp needs the reference to phba.
4198 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4201 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4202 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4203 init_timer(&ndlp->nlp_delayfunc);
4204 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4205 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4206 ndlp->nlp_DID = did;
4207 ndlp->vport = vport;
4208 ndlp->phba = vport->phba;
4209 ndlp->nlp_sid = NLP_NO_SID;
4210 kref_init(&ndlp->kref);
4211 NLP_INT_NODE_ACT(ndlp);
4212 atomic_set(&ndlp->cmd_pending, 0);
4213 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4216 struct lpfc_nodelist *
4217 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4220 struct lpfc_hba *phba = vport->phba;
4222 unsigned long flags;
4223 unsigned long *active_rrqs_xri_bitmap = NULL;
4228 spin_lock_irqsave(&phba->ndlp_lock, flags);
4229 /* The ndlp should not be in memory free mode */
4230 if (NLP_CHK_FREE_REQ(ndlp)) {
4231 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4232 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4233 "0277 lpfc_enable_node: ndlp:x%p "
4234 "usgmap:x%x refcnt:%d\n",
4235 (void *)ndlp, ndlp->nlp_usg_map,
4236 atomic_read(&ndlp->kref.refcount));
4239 /* The ndlp should not already be in active mode */
4240 if (NLP_CHK_NODE_ACT(ndlp)) {
4241 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4242 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4243 "0278 lpfc_enable_node: ndlp:x%p "
4244 "usgmap:x%x refcnt:%d\n",
4245 (void *)ndlp, ndlp->nlp_usg_map,
4246 atomic_read(&ndlp->kref.refcount));
4250 /* Keep the original DID */
4251 did = ndlp->nlp_DID;
4252 if (phba->sli_rev == LPFC_SLI_REV4)
4253 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
4255 /* re-initialize ndlp except of ndlp linked list pointer */
4256 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4257 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4258 lpfc_initialize_node(vport, ndlp, did);
4260 if (phba->sli_rev == LPFC_SLI_REV4)
4261 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4263 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4264 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4265 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
4266 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4267 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4268 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4270 atomic_read(&ndlp->kref.refcount),
4271 ndlp->nlp_usg_map, ndlp);
4275 if (state != NLP_STE_UNUSED_NODE)
4276 lpfc_nlp_set_state(vport, ndlp, state);
4278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4279 "node enable: did:x%x",
4280 ndlp->nlp_DID, 0, 0);
4285 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4288 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4289 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4290 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4291 * until ALL other outstanding threads have completed. We check
4292 * that the ndlp not already in the UNUSED state before we proceed.
4294 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4296 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4297 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4298 lpfc_cleanup_vports_rrqs(vport, ndlp);
4299 lpfc_unreg_rpi(vport, ndlp);
4307 * Start / ReStart rescue timer for Discovery / RSCN handling
4310 lpfc_set_disctmo(struct lpfc_vport *vport)
4312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4313 struct lpfc_hba *phba = vport->phba;
4316 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4317 /* For FAN, timeout should be greater than edtov */
4318 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4320 /* Normal discovery timeout should be > than ELS/CT timeout
4321 * FC spec states we need 3 * ratov for CT requests
4323 tmo = ((phba->fc_ratov * 3) + 3);
4327 if (!timer_pending(&vport->fc_disctmo)) {
4328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4329 "set disc timer: tmo:x%x state:x%x flg:x%x",
4330 tmo, vport->port_state, vport->fc_flag);
4333 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4334 spin_lock_irq(shost->host_lock);
4335 vport->fc_flag |= FC_DISC_TMO;
4336 spin_unlock_irq(shost->host_lock);
4338 /* Start Discovery Timer state <hba_state> */
4339 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4340 "0247 Start Discovery Timer state x%x "
4341 "Data: x%x x%lx x%x x%x\n",
4342 vport->port_state, tmo,
4343 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4344 vport->fc_adisc_cnt);
4350 * Cancel rescue timer for Discovery / RSCN handling
4353 lpfc_can_disctmo(struct lpfc_vport *vport)
4355 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4356 unsigned long iflags;
4358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4359 "can disc timer: state:x%x rtry:x%x flg:x%x",
4360 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4362 /* Turn off discovery timer if its running */
4363 if (vport->fc_flag & FC_DISC_TMO) {
4364 spin_lock_irqsave(shost->host_lock, iflags);
4365 vport->fc_flag &= ~FC_DISC_TMO;
4366 spin_unlock_irqrestore(shost->host_lock, iflags);
4367 del_timer_sync(&vport->fc_disctmo);
4368 spin_lock_irqsave(&vport->work_port_lock, iflags);
4369 vport->work_port_events &= ~WORKER_DISC_TMO;
4370 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4373 /* Cancel Discovery Timer state <hba_state> */
4374 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4375 "0248 Cancel Discovery Timer state x%x "
4376 "Data: x%x x%x x%x\n",
4377 vport->port_state, vport->fc_flag,
4378 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4383 * Check specified ring for outstanding IOCB on the SLI queue
4384 * Return true if iocb matches the specified nport
4387 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4388 struct lpfc_sli_ring *pring,
4389 struct lpfc_iocbq *iocb,
4390 struct lpfc_nodelist *ndlp)
4392 struct lpfc_sli *psli = &phba->sli;
4393 IOCB_t *icmd = &iocb->iocb;
4394 struct lpfc_vport *vport = ndlp->vport;
4396 if (iocb->vport != vport)
4399 if (pring->ringno == LPFC_ELS_RING) {
4400 switch (icmd->ulpCommand) {
4401 case CMD_GEN_REQUEST64_CR:
4402 if (iocb->context_un.ndlp == ndlp)
4404 case CMD_ELS_REQUEST64_CR:
4405 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4407 case CMD_XMIT_ELS_RSP64_CX:
4408 if (iocb->context1 == (uint8_t *) ndlp)
4411 } else if (pring->ringno == psli->extra_ring) {
4413 } else if (pring->ringno == psli->fcp_ring) {
4414 /* Skip match check if waiting to relogin to FCP target */
4415 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4416 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4419 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4422 } else if (pring->ringno == psli->next_ring) {
4429 * Free resources / clean up outstanding I/Os
4430 * associated with nlp_rpi in the LPFC_NODELIST entry.
4433 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4435 LIST_HEAD(completions);
4436 struct lpfc_sli *psli;
4437 struct lpfc_sli_ring *pring;
4438 struct lpfc_iocbq *iocb, *next_iocb;
4441 lpfc_fabric_abort_nport(ndlp);
4444 * Everything that matches on txcmplq will be returned
4445 * by firmware with a no rpi error.
4448 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4449 /* Now process each ring */
4450 for (i = 0; i < psli->num_rings; i++) {
4451 pring = &psli->ring[i];
4453 spin_lock_irq(&phba->hbalock);
4454 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
4457 * Check to see if iocb matches the nport we are
4460 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4462 /* It matches, so deque and call compl
4464 list_move_tail(&iocb->list,
4468 spin_unlock_irq(&phba->hbalock);
4472 /* Cancel all the IOCBs from the completions list */
4473 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4480 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4481 * @phba: Pointer to HBA context object.
4482 * @pmb: Pointer to mailbox object.
4484 * This function will issue an ELS LOGO command after completing
4488 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4490 struct lpfc_vport *vport = pmb->vport;
4491 struct lpfc_nodelist *ndlp;
4493 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4496 lpfc_issue_els_logo(vport, ndlp, 0);
4497 mempool_free(pmb, phba->mbox_mem_pool);
4501 * Free rpi associated with LPFC_NODELIST entry.
4502 * This routine is called from lpfc_freenode(), when we are removing
4503 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4504 * LOGO that completes successfully, and we are waiting to PLOGI back
4505 * to the remote NPort. In addition, it is called after we receive
4506 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4507 * we are waiting to PLOGI back to the remote NPort.
4510 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4512 struct lpfc_hba *phba = vport->phba;
4517 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4518 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4519 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4520 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4521 "3366 RPI x%x needs to be "
4522 "unregistered nlp_flag x%x "
4524 ndlp->nlp_rpi, ndlp->nlp_flag,
4526 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4528 /* SLI4 ports require the physical rpi value. */
4529 rpi = ndlp->nlp_rpi;
4530 if (phba->sli_rev == LPFC_SLI_REV4)
4531 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4533 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4534 mbox->vport = vport;
4535 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4536 mbox->context1 = ndlp;
4537 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4539 if (phba->sli_rev == LPFC_SLI_REV4 &&
4540 (!(vport->load_flag & FC_UNLOADING)) &&
4541 (bf_get(lpfc_sli_intf_if_type,
4542 &phba->sli4_hba.sli_intf) ==
4543 LPFC_SLI_INTF_IF_TYPE_2)) {
4544 mbox->context1 = lpfc_nlp_get(ndlp);
4546 lpfc_sli4_unreg_rpi_cmpl_clr;
4549 lpfc_sli_def_mbox_cmpl;
4552 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4553 if (rc == MBX_NOT_FINISHED)
4554 mempool_free(mbox, phba->mbox_mem_pool);
4556 lpfc_no_rpi(phba, ndlp);
4558 if (phba->sli_rev != LPFC_SLI_REV4)
4560 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4561 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4568 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4569 * @phba: pointer to lpfc hba data structure.
4571 * This routine is invoked to unregister all the currently registered RPIs
4575 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4577 struct lpfc_vport **vports;
4578 struct lpfc_nodelist *ndlp;
4579 struct Scsi_Host *shost;
4582 vports = lpfc_create_vport_work_array(phba);
4584 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4585 "2884 Vport array allocation failed \n");
4588 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4589 shost = lpfc_shost_from_vport(vports[i]);
4590 spin_lock_irq(shost->host_lock);
4591 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4592 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4593 /* The mempool_alloc might sleep */
4594 spin_unlock_irq(shost->host_lock);
4595 lpfc_unreg_rpi(vports[i], ndlp);
4596 spin_lock_irq(shost->host_lock);
4599 spin_unlock_irq(shost->host_lock);
4601 lpfc_destroy_vport_work_array(phba, vports);
4605 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4607 struct lpfc_hba *phba = vport->phba;
4611 if (phba->sli_rev == LPFC_SLI_REV4) {
4612 lpfc_sli4_unreg_all_rpis(vport);
4616 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4618 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4620 mbox->vport = vport;
4621 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4622 mbox->context1 = NULL;
4623 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4624 if (rc != MBX_TIMEOUT)
4625 mempool_free(mbox, phba->mbox_mem_pool);
4627 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4628 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4629 "1836 Could not issue "
4630 "unreg_login(all_rpis) status %d\n", rc);
4635 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4637 struct lpfc_hba *phba = vport->phba;
4641 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4643 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4645 mbox->vport = vport;
4646 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4647 mbox->context1 = NULL;
4648 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4649 if (rc != MBX_TIMEOUT)
4650 mempool_free(mbox, phba->mbox_mem_pool);
4652 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4653 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4654 "1815 Could not issue "
4655 "unreg_did (default rpis) status %d\n",
4661 * Free resources associated with LPFC_NODELIST entry
4662 * so it can be freed.
4665 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4667 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4668 struct lpfc_hba *phba = vport->phba;
4669 LPFC_MBOXQ_t *mb, *nextmb;
4670 struct lpfc_dmabuf *mp;
4672 /* Cleanup node for NPort <nlp_DID> */
4673 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4674 "0900 Cleanup node for NPort x%x "
4675 "Data: x%x x%x x%x\n",
4676 ndlp->nlp_DID, ndlp->nlp_flag,
4677 ndlp->nlp_state, ndlp->nlp_rpi);
4678 if (NLP_CHK_FREE_REQ(ndlp)) {
4679 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4680 "0280 lpfc_cleanup_node: ndlp:x%p "
4681 "usgmap:x%x refcnt:%d\n",
4682 (void *)ndlp, ndlp->nlp_usg_map,
4683 atomic_read(&ndlp->kref.refcount));
4684 lpfc_dequeue_node(vport, ndlp);
4686 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4687 "0281 lpfc_cleanup_node: ndlp:x%p "
4688 "usgmap:x%x refcnt:%d\n",
4689 (void *)ndlp, ndlp->nlp_usg_map,
4690 atomic_read(&ndlp->kref.refcount));
4691 lpfc_disable_node(vport, ndlp);
4695 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4697 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4698 if ((mb = phba->sli.mbox_active)) {
4699 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4700 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4701 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4702 mb->context2 = NULL;
4703 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4707 spin_lock_irq(&phba->hbalock);
4708 /* Cleanup REG_LOGIN completions which are not yet processed */
4709 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4710 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4711 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
4712 (ndlp != (struct lpfc_nodelist *) mb->context2))
4715 mb->context2 = NULL;
4716 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4719 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
4720 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4721 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4722 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4723 mp = (struct lpfc_dmabuf *) (mb->context1);
4725 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
4728 list_del(&mb->list);
4729 mempool_free(mb, phba->mbox_mem_pool);
4730 /* We shall not invoke the lpfc_nlp_put to decrement
4731 * the ndlp reference count as we are in the process
4732 * of lpfc_nlp_release.
4736 spin_unlock_irq(&phba->hbalock);
4738 lpfc_els_abort(phba, ndlp);
4740 spin_lock_irq(shost->host_lock);
4741 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4742 spin_unlock_irq(shost->host_lock);
4744 ndlp->nlp_last_elscmd = 0;
4745 del_timer_sync(&ndlp->nlp_delayfunc);
4747 list_del_init(&ndlp->els_retry_evt.evt_listp);
4748 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4749 lpfc_cleanup_vports_rrqs(vport, ndlp);
4750 lpfc_unreg_rpi(vport, ndlp);
4756 * Check to see if we can free the nlp back to the freelist.
4757 * If we are in the middle of using the nlp in the discovery state
4758 * machine, defer the free till we reach the end of the state machine.
4761 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4763 struct lpfc_hba *phba = vport->phba;
4764 struct lpfc_rport_data *rdata;
4768 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4769 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
4770 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4771 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
4772 /* For this case we need to cleanup the default rpi
4773 * allocated by the firmware.
4775 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4776 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
4777 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4778 atomic_read(&ndlp->kref.refcount),
4779 ndlp->nlp_usg_map, ndlp);
4780 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4782 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
4783 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
4785 mempool_free(mbox, phba->mbox_mem_pool);
4788 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4789 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4790 mbox->vport = vport;
4791 mbox->context2 = ndlp;
4792 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4793 if (rc == MBX_NOT_FINISHED) {
4794 mempool_free(mbox, phba->mbox_mem_pool);
4799 lpfc_cleanup_node(vport, ndlp);
4802 * We can get here with a non-NULL ndlp->rport because when we
4803 * unregister a rport we don't break the rport/node linkage. So if we
4804 * do, make sure we don't leaving any dangling pointers behind.
4807 rdata = ndlp->rport->dd_data;
4808 rdata->pnode = NULL;
4814 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4817 D_ID mydid, ndlpdid, matchdid;
4819 if (did == Bcast_DID)
4822 /* First check for Direct match */
4823 if (ndlp->nlp_DID == did)
4826 /* Next check for area/domain identically equals 0 match */
4827 mydid.un.word = vport->fc_myDID;
4828 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
4832 matchdid.un.word = did;
4833 ndlpdid.un.word = ndlp->nlp_DID;
4834 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4835 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4836 (mydid.un.b.area == matchdid.un.b.area)) {
4837 /* This code is supposed to match the ID
4838 * for a private loop device that is
4839 * connect to fl_port. But we need to
4840 * check that the port did not just go
4841 * from pt2pt to fabric or we could end
4842 * up matching ndlp->nlp_DID 000001 to
4843 * fabric DID 0x20101
4845 if ((ndlpdid.un.b.domain == 0) &&
4846 (ndlpdid.un.b.area == 0)) {
4847 if (ndlpdid.un.b.id &&
4848 vport->phba->fc_topology ==
4855 matchdid.un.word = ndlp->nlp_DID;
4856 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4857 (mydid.un.b.area == ndlpdid.un.b.area)) {
4858 if ((matchdid.un.b.domain == 0) &&
4859 (matchdid.un.b.area == 0)) {
4860 if (matchdid.un.b.id)
4868 /* Search for a nodelist entry */
4869 static struct lpfc_nodelist *
4870 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4872 struct lpfc_nodelist *ndlp;
4875 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4876 if (lpfc_matchdid(vport, ndlp, did)) {
4877 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4878 ((uint32_t) ndlp->nlp_xri << 16) |
4879 ((uint32_t) ndlp->nlp_type << 8) |
4880 ((uint32_t) ndlp->nlp_rpi & 0xff));
4881 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4882 "0929 FIND node DID "
4883 "Data: x%p x%x x%x x%x %p\n",
4884 ndlp, ndlp->nlp_DID,
4885 ndlp->nlp_flag, data1,
4886 ndlp->active_rrqs_xri_bitmap);
4891 /* FIND node did <did> NOT FOUND */
4892 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4893 "0932 FIND node did x%x NOT FOUND.\n", did);
4897 struct lpfc_nodelist *
4898 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4901 struct lpfc_nodelist *ndlp;
4902 unsigned long iflags;
4904 spin_lock_irqsave(shost->host_lock, iflags);
4905 ndlp = __lpfc_findnode_did(vport, did);
4906 spin_unlock_irqrestore(shost->host_lock, iflags);
4910 struct lpfc_nodelist *
4911 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4914 struct lpfc_nodelist *ndlp;
4916 ndlp = lpfc_findnode_did(vport, did);
4918 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4919 lpfc_rscn_payload_check(vport, did) == 0)
4921 ndlp = (struct lpfc_nodelist *)
4922 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
4925 lpfc_nlp_init(vport, ndlp, did);
4926 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4927 spin_lock_irq(shost->host_lock);
4928 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4929 spin_unlock_irq(shost->host_lock);
4931 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4932 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4935 spin_lock_irq(shost->host_lock);
4936 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4937 spin_unlock_irq(shost->host_lock);
4941 if ((vport->fc_flag & FC_RSCN_MODE) &&
4942 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
4943 if (lpfc_rscn_payload_check(vport, did)) {
4944 /* If we've already received a PLOGI from this NPort
4945 * we don't need to try to discover it again.
4947 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4950 /* Since this node is marked for discovery,
4951 * delay timeout is not needed.
4953 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4954 spin_lock_irq(shost->host_lock);
4955 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4956 spin_unlock_irq(shost->host_lock);
4960 /* If we've already received a PLOGI from this NPort,
4961 * or we are already in the process of discovery on it,
4962 * we don't need to try to discover it again.
4964 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
4965 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4966 ndlp->nlp_flag & NLP_RCV_PLOGI)
4968 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4969 spin_lock_irq(shost->host_lock);
4970 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4971 spin_unlock_irq(shost->host_lock);
4976 /* Build a list of nodes to discover based on the loopmap */
4978 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
4980 struct lpfc_hba *phba = vport->phba;
4982 uint32_t alpa, index;
4984 if (!lpfc_is_link_up(phba))
4987 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
4990 /* Check for loop map present or not */
4991 if (phba->alpa_map[0]) {
4992 for (j = 1; j <= phba->alpa_map[0]; j++) {
4993 alpa = phba->alpa_map[j];
4994 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
4996 lpfc_setup_disc_node(vport, alpa);
4999 /* No alpamap, so try all alpa's */
5000 for (j = 0; j < FC_MAXLOOP; j++) {
5001 /* If cfg_scan_down is set, start from highest
5002 * ALPA (0xef) to lowest (0x1).
5004 if (vport->cfg_scan_down)
5007 index = FC_MAXLOOP - j - 1;
5008 alpa = lpfcAlpaArray[index];
5009 if ((vport->fc_myDID & 0xff) == alpa)
5011 lpfc_setup_disc_node(vport, alpa);
5018 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5021 struct lpfc_sli *psli = &phba->sli;
5022 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
5023 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
5024 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
5028 * if it's not a physical port or if we already send
5029 * clear_la then don't send it.
5031 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5032 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5033 (phba->sli_rev == LPFC_SLI_REV4))
5036 /* Link up discovery */
5037 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5038 phba->link_state = LPFC_CLEAR_LA;
5039 lpfc_clear_la(phba, mbox);
5040 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5041 mbox->vport = vport;
5042 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5043 if (rc == MBX_NOT_FINISHED) {
5044 mempool_free(mbox, phba->mbox_mem_pool);
5045 lpfc_disc_flush_list(vport);
5046 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5047 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5048 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5049 phba->link_state = LPFC_HBA_ERROR;
5054 /* Reg_vpi to tell firmware to resume normal operations */
5056 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5058 LPFC_MBOXQ_t *regvpimbox;
5060 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5062 lpfc_reg_vpi(vport, regvpimbox);
5063 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5064 regvpimbox->vport = vport;
5065 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5066 == MBX_NOT_FINISHED) {
5067 mempool_free(regvpimbox, phba->mbox_mem_pool);
5072 /* Start Link up / RSCN discovery on NPR nodes */
5074 lpfc_disc_start(struct lpfc_vport *vport)
5076 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5077 struct lpfc_hba *phba = vport->phba;
5079 uint32_t clear_la_pending;
5081 if (!lpfc_is_link_up(phba)) {
5082 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5083 "3315 Link is not up %x\n",
5088 if (phba->link_state == LPFC_CLEAR_LA)
5089 clear_la_pending = 1;
5091 clear_la_pending = 0;
5093 if (vport->port_state < LPFC_VPORT_READY)
5094 vport->port_state = LPFC_DISC_AUTH;
5096 lpfc_set_disctmo(vport);
5098 vport->fc_prevDID = vport->fc_myDID;
5099 vport->num_disc_nodes = 0;
5101 /* Start Discovery state <hba_state> */
5102 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5103 "0202 Start Discovery hba state x%x "
5104 "Data: x%x x%x x%x\n",
5105 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5106 vport->fc_adisc_cnt);
5108 /* First do ADISCs - if any */
5109 num_sent = lpfc_els_disc_adisc(vport);
5114 /* Register the VPI for SLI3, NPIV only. */
5115 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5116 !(vport->fc_flag & FC_PT2PT) &&
5117 !(vport->fc_flag & FC_RSCN_MODE) &&
5118 (phba->sli_rev < LPFC_SLI_REV4)) {
5119 lpfc_issue_clear_la(phba, vport);
5120 lpfc_issue_reg_vpi(phba, vport);
5125 * For SLI2, we need to set port_state to READY and continue
5128 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5129 /* If we get here, there is nothing to ADISC */
5130 lpfc_issue_clear_la(phba, vport);
5132 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5133 vport->num_disc_nodes = 0;
5134 /* go thru NPR nodes and issue ELS PLOGIs */
5135 if (vport->fc_npr_cnt)
5136 lpfc_els_disc_plogi(vport);
5138 if (!vport->num_disc_nodes) {
5139 spin_lock_irq(shost->host_lock);
5140 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5141 spin_unlock_irq(shost->host_lock);
5142 lpfc_can_disctmo(vport);
5145 vport->port_state = LPFC_VPORT_READY;
5147 /* Next do PLOGIs - if any */
5148 num_sent = lpfc_els_disc_plogi(vport);
5153 if (vport->fc_flag & FC_RSCN_MODE) {
5154 /* Check to see if more RSCNs came in while we
5155 * were processing this one.
5157 if ((vport->fc_rscn_id_cnt == 0) &&
5158 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5159 spin_lock_irq(shost->host_lock);
5160 vport->fc_flag &= ~FC_RSCN_MODE;
5161 spin_unlock_irq(shost->host_lock);
5162 lpfc_can_disctmo(vport);
5164 lpfc_els_handle_rscn(vport);
5171 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5172 * ring the match the sppecified nodelist.
5175 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5177 LIST_HEAD(completions);
5178 struct lpfc_sli *psli;
5180 struct lpfc_iocbq *iocb, *next_iocb;
5181 struct lpfc_sli_ring *pring;
5184 pring = &psli->ring[LPFC_ELS_RING];
5186 /* Error matching iocb on txq or txcmplq
5187 * First check the txq.
5189 spin_lock_irq(&phba->hbalock);
5190 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5191 if (iocb->context1 != ndlp) {
5195 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5196 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5198 list_move_tail(&iocb->list, &completions);
5202 /* Next check the txcmplq */
5203 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5204 if (iocb->context1 != ndlp) {
5208 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5209 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5210 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5213 spin_unlock_irq(&phba->hbalock);
5215 /* Cancel all the IOCBs from the completions list */
5216 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5221 lpfc_disc_flush_list(struct lpfc_vport *vport)
5223 struct lpfc_nodelist *ndlp, *next_ndlp;
5224 struct lpfc_hba *phba = vport->phba;
5226 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5227 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5229 if (!NLP_CHK_NODE_ACT(ndlp))
5231 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5232 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5233 lpfc_free_tx(phba, ndlp);
5240 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5242 lpfc_els_flush_rscn(vport);
5243 lpfc_els_flush_cmd(vport);
5244 lpfc_disc_flush_list(vport);
5247 /*****************************************************************************/
5249 * NAME: lpfc_disc_timeout
5251 * FUNCTION: Fibre Channel driver discovery timeout routine.
5253 * EXECUTION ENVIRONMENT: interrupt only
5261 /*****************************************************************************/
5263 lpfc_disc_timeout(unsigned long ptr)
5265 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5266 struct lpfc_hba *phba = vport->phba;
5267 uint32_t tmo_posted;
5268 unsigned long flags = 0;
5270 if (unlikely(!phba))
5273 spin_lock_irqsave(&vport->work_port_lock, flags);
5274 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5276 vport->work_port_events |= WORKER_DISC_TMO;
5277 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5280 lpfc_worker_wake_up(phba);
5285 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5288 struct lpfc_hba *phba = vport->phba;
5289 struct lpfc_sli *psli = &phba->sli;
5290 struct lpfc_nodelist *ndlp, *next_ndlp;
5291 LPFC_MBOXQ_t *initlinkmbox;
5292 int rc, clrlaerr = 0;
5294 if (!(vport->fc_flag & FC_DISC_TMO))
5297 spin_lock_irq(shost->host_lock);
5298 vport->fc_flag &= ~FC_DISC_TMO;
5299 spin_unlock_irq(shost->host_lock);
5301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5302 "disc timeout: state:x%x rtry:x%x flg:x%x",
5303 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5305 switch (vport->port_state) {
5307 case LPFC_LOCAL_CFG_LINK:
5308 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
5312 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5313 "0221 FAN timeout\n");
5314 /* Start discovery by sending FLOGI, clean up old rpis */
5315 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5317 if (!NLP_CHK_NODE_ACT(ndlp))
5319 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5321 if (ndlp->nlp_type & NLP_FABRIC) {
5322 /* Clean up the ndlp on Fabric connections */
5323 lpfc_drop_node(vport, ndlp);
5325 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5326 /* Fail outstanding IO now since device
5327 * is marked for PLOGI.
5329 lpfc_unreg_rpi(vport, ndlp);
5332 if (vport->port_state != LPFC_FLOGI) {
5333 if (phba->sli_rev <= LPFC_SLI_REV3)
5334 lpfc_initial_flogi(vport);
5336 lpfc_issue_init_vfi(vport);
5343 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5344 /* Initial FLOGI timeout */
5345 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5346 "0222 Initial %s timeout\n",
5347 vport->vpi ? "FDISC" : "FLOGI");
5349 /* Assume no Fabric and go on with discovery.
5350 * Check for outstanding ELS FLOGI to abort.
5353 /* FLOGI failed, so just use loop map to make discovery list */
5354 lpfc_disc_list_loopmap(vport);
5356 /* Start discovery */
5357 lpfc_disc_start(vport);
5360 case LPFC_FABRIC_CFG_LINK:
5361 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5363 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5364 "0223 Timeout while waiting for "
5365 "NameServer login\n");
5366 /* Next look for NameServer ndlp */
5367 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5368 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5369 lpfc_els_abort(phba, ndlp);
5371 /* ReStart discovery */
5375 /* Check for wait for NameServer Rsp timeout */
5376 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5377 "0224 NameServer Query timeout "
5379 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5381 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5382 /* Try it one more time */
5383 vport->fc_ns_retry++;
5384 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
5385 vport->fc_ns_retry, 0);
5389 vport->fc_ns_retry = 0;
5393 * Discovery is over.
5394 * set port_state to PORT_READY if SLI2.
5395 * cmpl_reg_vpi will set port_state to READY for SLI3.
5397 if (phba->sli_rev < LPFC_SLI_REV4) {
5398 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5399 lpfc_issue_reg_vpi(phba, vport);
5401 lpfc_issue_clear_la(phba, vport);
5402 vport->port_state = LPFC_VPORT_READY;
5406 /* Setup and issue mailbox INITIALIZE LINK command */
5407 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5408 if (!initlinkmbox) {
5409 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5410 "0206 Device Discovery "
5411 "completion error\n");
5412 phba->link_state = LPFC_HBA_ERROR;
5416 lpfc_linkdown(phba);
5417 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5418 phba->cfg_link_speed);
5419 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5420 initlinkmbox->vport = vport;
5421 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5422 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5423 lpfc_set_loopback_flag(phba);
5424 if (rc == MBX_NOT_FINISHED)
5425 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5429 case LPFC_DISC_AUTH:
5430 /* Node Authentication timeout */
5431 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5432 "0227 Node Authentication timeout\n");
5433 lpfc_disc_flush_list(vport);
5436 * set port_state to PORT_READY if SLI2.
5437 * cmpl_reg_vpi will set port_state to READY for SLI3.
5439 if (phba->sli_rev < LPFC_SLI_REV4) {
5440 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5441 lpfc_issue_reg_vpi(phba, vport);
5442 else { /* NPIV Not enabled */
5443 lpfc_issue_clear_la(phba, vport);
5444 vport->port_state = LPFC_VPORT_READY;
5449 case LPFC_VPORT_READY:
5450 if (vport->fc_flag & FC_RSCN_MODE) {
5451 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5452 "0231 RSCN timeout Data: x%x "
5454 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5456 /* Cleanup any outstanding ELS commands */
5457 lpfc_els_flush_cmd(vport);
5459 lpfc_els_flush_rscn(vport);
5460 lpfc_disc_flush_list(vport);
5465 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5466 "0273 Unexpected discovery timeout, "
5467 "vport State x%x\n", vport->port_state);
5471 switch (phba->link_state) {
5473 /* CLEAR LA timeout */
5474 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5475 "0228 CLEAR LA timeout\n");
5480 lpfc_issue_clear_la(phba, vport);
5482 case LPFC_LINK_UNKNOWN:
5483 case LPFC_WARM_START:
5484 case LPFC_INIT_START:
5485 case LPFC_INIT_MBX_CMDS:
5486 case LPFC_LINK_DOWN:
5487 case LPFC_HBA_ERROR:
5488 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5489 "0230 Unexpected timeout, hba link "
5490 "state x%x\n", phba->link_state);
5494 case LPFC_HBA_READY:
5499 lpfc_disc_flush_list(vport);
5500 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5501 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5502 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5503 vport->port_state = LPFC_VPORT_READY;
5510 * This routine handles processing a NameServer REG_LOGIN mailbox
5511 * command upon completion. It is setup in the LPFC_MBOXQ
5512 * as the completion routine when the command is
5513 * handed off to the SLI layer.
5516 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5518 MAILBOX_t *mb = &pmb->u.mb;
5519 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5520 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5521 struct lpfc_vport *vport = pmb->vport;
5523 pmb->context1 = NULL;
5524 pmb->context2 = NULL;
5526 if (phba->sli_rev < LPFC_SLI_REV4)
5527 ndlp->nlp_rpi = mb->un.varWords[0];
5528 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
5529 ndlp->nlp_type |= NLP_FABRIC;
5530 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
5531 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5532 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5533 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5534 atomic_read(&ndlp->kref.refcount),
5535 ndlp->nlp_usg_map, ndlp);
5537 * Start issuing Fabric-Device Management Interface (FDMI) command to
5538 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5539 * fdmi-on=2 (supporting RPA/hostnmae)
5542 if (vport->cfg_fdmi_on & LPFC_FDMI_REG_DELAY)
5543 mod_timer(&vport->fc_fdmitmo,
5544 jiffies + msecs_to_jiffies(1000 * 60));
5546 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5548 /* decrement the node reference count held for this callback
5552 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5554 mempool_free(pmb, phba->mbox_mem_pool);
5560 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5562 uint16_t *rpi = param;
5564 /* check for active node */
5565 if (!NLP_CHK_NODE_ACT(ndlp))
5568 return ndlp->nlp_rpi == *rpi;
5572 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5574 return memcmp(&ndlp->nlp_portname, param,
5575 sizeof(ndlp->nlp_portname)) == 0;
5578 static struct lpfc_nodelist *
5579 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5581 struct lpfc_nodelist *ndlp;
5583 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5584 if (filter(ndlp, param)) {
5585 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5586 "3185 FIND node filter %p DID "
5587 "Data: x%p x%x x%x\n",
5588 filter, ndlp, ndlp->nlp_DID,
5593 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5594 "3186 FIND node filter %p NOT FOUND.\n", filter);
5599 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5600 * returns the node list element pointer else return NULL.
5602 struct lpfc_nodelist *
5603 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5605 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
5609 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5610 * returns the node element list pointer else return NULL.
5612 struct lpfc_nodelist *
5613 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
5615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5616 struct lpfc_nodelist *ndlp;
5618 spin_lock_irq(shost->host_lock);
5619 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5620 spin_unlock_irq(shost->host_lock);
5625 * This routine looks up the ndlp lists for the given RPI. If the rpi
5626 * is found, the routine returns the node element list pointer else
5629 struct lpfc_nodelist *
5630 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5632 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5633 struct lpfc_nodelist *ndlp;
5635 spin_lock_irq(shost->host_lock);
5636 ndlp = __lpfc_findnode_rpi(vport, rpi);
5637 spin_unlock_irq(shost->host_lock);
5642 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5643 * @phba: pointer to lpfc hba data structure.
5644 * @vpi: the physical host virtual N_Port identifier.
5646 * This routine finds a vport on a HBA (referred by @phba) through a
5647 * @vpi. The function walks the HBA's vport list and returns the address
5648 * of the vport with the matching @vpi.
5651 * NULL - No vport with the matching @vpi found
5652 * Otherwise - Address to the vport with the matching @vpi.
5655 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5657 struct lpfc_vport *vport;
5658 unsigned long flags;
5661 /* The physical ports are always vpi 0 - translate is unnecessary. */
5664 * Translate the physical vpi to the logical vpi. The
5665 * vport stores the logical vpi.
5667 for (i = 0; i < phba->max_vpi; i++) {
5668 if (vpi == phba->vpi_ids[i])
5672 if (i >= phba->max_vpi) {
5673 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5674 "2936 Could not find Vport mapped "
5675 "to vpi %d\n", vpi);
5680 spin_lock_irqsave(&phba->hbalock, flags);
5681 list_for_each_entry(vport, &phba->port_list, listentry) {
5682 if (vport->vpi == i) {
5683 spin_unlock_irqrestore(&phba->hbalock, flags);
5687 spin_unlock_irqrestore(&phba->hbalock, flags);
5692 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5695 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
5697 lpfc_initialize_node(vport, ndlp, did);
5698 INIT_LIST_HEAD(&ndlp->nlp_listp);
5699 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
5700 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
5701 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5702 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
5703 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
5705 atomic_read(&ndlp->kref.refcount),
5706 ndlp->nlp_usg_map, ndlp);
5708 ndlp->active_rrqs_xri_bitmap =
5709 mempool_alloc(vport->phba->active_rrq_pool,
5711 if (ndlp->active_rrqs_xri_bitmap)
5712 memset(ndlp->active_rrqs_xri_bitmap, 0,
5713 ndlp->phba->cfg_rrq_xri_bitmap_sz);
5718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5719 "node init: did:x%x",
5720 ndlp->nlp_DID, 0, 0);
5725 /* This routine releases all resources associated with a specifc NPort's ndlp
5726 * and mempool_free's the nodelist.
5729 lpfc_nlp_release(struct kref *kref)
5731 struct lpfc_hba *phba;
5732 unsigned long flags;
5733 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5736 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5737 "node release: did:x%x flg:x%x type:x%x",
5738 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5740 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5741 "0279 lpfc_nlp_release: ndlp:x%p did %x "
5742 "usgmap:x%x refcnt:%d rpi:%x\n",
5743 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
5744 atomic_read(&ndlp->kref.refcount), ndlp->nlp_rpi);
5746 /* remove ndlp from action. */
5747 lpfc_nlp_remove(ndlp->vport, ndlp);
5749 /* clear the ndlp active flag for all release cases */
5751 spin_lock_irqsave(&phba->ndlp_lock, flags);
5752 NLP_CLR_NODE_ACT(ndlp);
5753 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5754 if (phba->sli_rev == LPFC_SLI_REV4)
5755 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5757 /* free ndlp memory for final ndlp release */
5758 if (NLP_CHK_FREE_REQ(ndlp)) {
5759 kfree(ndlp->lat_data);
5760 if (phba->sli_rev == LPFC_SLI_REV4)
5761 mempool_free(ndlp->active_rrqs_xri_bitmap,
5762 ndlp->phba->active_rrq_pool);
5763 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
5767 /* This routine bumps the reference count for a ndlp structure to ensure
5768 * that one discovery thread won't free a ndlp while another discovery thread
5771 struct lpfc_nodelist *
5772 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5774 struct lpfc_hba *phba;
5775 unsigned long flags;
5778 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5779 "node get: did:x%x flg:x%x refcnt:x%x",
5780 ndlp->nlp_DID, ndlp->nlp_flag,
5781 atomic_read(&ndlp->kref.refcount));
5782 /* The check of ndlp usage to prevent incrementing the
5783 * ndlp reference count that is in the process of being
5787 spin_lock_irqsave(&phba->ndlp_lock, flags);
5788 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5789 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5790 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5791 "0276 lpfc_nlp_get: ndlp:x%p "
5792 "usgmap:x%x refcnt:%d\n",
5793 (void *)ndlp, ndlp->nlp_usg_map,
5794 atomic_read(&ndlp->kref.refcount));
5797 kref_get(&ndlp->kref);
5798 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5803 /* This routine decrements the reference count for a ndlp structure. If the
5804 * count goes to 0, this indicates the the associated nodelist should be
5805 * freed. Returning 1 indicates the ndlp resource has been released; on the
5806 * other hand, returning 0 indicates the ndlp resource has not been released
5810 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5812 struct lpfc_hba *phba;
5813 unsigned long flags;
5818 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5819 "node put: did:x%x flg:x%x refcnt:x%x",
5820 ndlp->nlp_DID, ndlp->nlp_flag,
5821 atomic_read(&ndlp->kref.refcount));
5823 spin_lock_irqsave(&phba->ndlp_lock, flags);
5824 /* Check the ndlp memory free acknowledge flag to avoid the
5825 * possible race condition that kref_put got invoked again
5826 * after previous one has done ndlp memory free.
5828 if (NLP_CHK_FREE_ACK(ndlp)) {
5829 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5830 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5831 "0274 lpfc_nlp_put: ndlp:x%p "
5832 "usgmap:x%x refcnt:%d\n",
5833 (void *)ndlp, ndlp->nlp_usg_map,
5834 atomic_read(&ndlp->kref.refcount));
5837 /* Check the ndlp inactivate log flag to avoid the possible
5838 * race condition that kref_put got invoked again after ndlp
5839 * is already in inactivating state.
5841 if (NLP_CHK_IACT_REQ(ndlp)) {
5842 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5843 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5844 "0275 lpfc_nlp_put: ndlp:x%p "
5845 "usgmap:x%x refcnt:%d\n",
5846 (void *)ndlp, ndlp->nlp_usg_map,
5847 atomic_read(&ndlp->kref.refcount));
5850 /* For last put, mark the ndlp usage flags to make sure no
5851 * other kref_get and kref_put on the same ndlp shall get
5852 * in between the process when the final kref_put has been
5853 * invoked on this ndlp.
5855 if (atomic_read(&ndlp->kref.refcount) == 1) {
5856 /* Indicate ndlp is put to inactive state. */
5857 NLP_SET_IACT_REQ(ndlp);
5858 /* Acknowledge ndlp memory free has been seen. */
5859 if (NLP_CHK_FREE_REQ(ndlp))
5860 NLP_SET_FREE_ACK(ndlp);
5862 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5863 /* Note, the kref_put returns 1 when decrementing a reference
5864 * count that was 1, it invokes the release callback function,
5865 * but it still left the reference count as 1 (not actually
5866 * performs the last decrementation). Otherwise, it actually
5867 * decrements the reference count and returns 0.
5869 return kref_put(&ndlp->kref, lpfc_nlp_release);
5872 /* This routine free's the specified nodelist if it is not in use
5873 * by any other discovery thread. This routine returns 1 if the
5874 * ndlp has been freed. A return value of 0 indicates the ndlp is
5875 * not yet been released.
5878 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5880 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5881 "node not used: did:x%x flg:x%x refcnt:x%x",
5882 ndlp->nlp_DID, ndlp->nlp_flag,
5883 atomic_read(&ndlp->kref.refcount));
5884 if (atomic_read(&ndlp->kref.refcount) == 1)
5885 if (lpfc_nlp_put(ndlp))
5891 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5892 * @phba: Pointer to hba context object.
5894 * This function iterate through all FC nodes associated
5895 * will all vports to check if there is any node with
5896 * fc_rports associated with it. If there is an fc_rport
5897 * associated with the node, then the node is either in
5898 * discovered state or its devloss_timer is pending.
5901 lpfc_fcf_inuse(struct lpfc_hba *phba)
5903 struct lpfc_vport **vports;
5905 struct lpfc_nodelist *ndlp;
5906 struct Scsi_Host *shost;
5908 vports = lpfc_create_vport_work_array(phba);
5910 /* If driver cannot allocate memory, indicate fcf is in use */
5914 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5915 shost = lpfc_shost_from_vport(vports[i]);
5916 spin_lock_irq(shost->host_lock);
5918 * IF the CVL_RCVD bit is not set then we have sent the
5920 * If dev_loss fires while we are waiting we do not want to
5923 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
5924 spin_unlock_irq(shost->host_lock);
5928 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5929 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5930 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5932 spin_unlock_irq(shost->host_lock);
5934 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5936 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5937 "2624 RPI %x DID %x flag %x "
5938 "still logged in\n",
5939 ndlp->nlp_rpi, ndlp->nlp_DID,
5943 spin_unlock_irq(shost->host_lock);
5946 lpfc_destroy_vport_work_array(phba, vports);
5951 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5952 * @phba: Pointer to hba context object.
5953 * @mboxq: Pointer to mailbox object.
5955 * This function frees memory associated with the mailbox command.
5958 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5960 struct lpfc_vport *vport = mboxq->vport;
5961 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5963 if (mboxq->u.mb.mbxStatus) {
5964 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5965 "2555 UNREG_VFI mbxStatus error x%x "
5967 mboxq->u.mb.mbxStatus, vport->port_state);
5969 spin_lock_irq(shost->host_lock);
5970 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5971 spin_unlock_irq(shost->host_lock);
5972 mempool_free(mboxq, phba->mbox_mem_pool);
5977 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5978 * @phba: Pointer to hba context object.
5979 * @mboxq: Pointer to mailbox object.
5981 * This function frees memory associated with the mailbox command.
5984 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5986 struct lpfc_vport *vport = mboxq->vport;
5988 if (mboxq->u.mb.mbxStatus) {
5989 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5990 "2550 UNREG_FCFI mbxStatus error x%x "
5992 mboxq->u.mb.mbxStatus, vport->port_state);
5994 mempool_free(mboxq, phba->mbox_mem_pool);
5999 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6000 * @phba: Pointer to hba context object.
6002 * This function prepare the HBA for unregistering the currently registered
6003 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6007 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6009 struct lpfc_vport **vports;
6010 struct lpfc_nodelist *ndlp;
6011 struct Scsi_Host *shost;
6014 /* Unregister RPIs */
6015 if (lpfc_fcf_inuse(phba))
6016 lpfc_unreg_hba_rpis(phba);
6018 /* At this point, all discovery is aborted */
6019 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6021 /* Unregister VPIs */
6022 vports = lpfc_create_vport_work_array(phba);
6023 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6024 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6025 /* Stop FLOGI/FDISC retries */
6026 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6028 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6029 lpfc_cleanup_pending_mbox(vports[i]);
6030 if (phba->sli_rev == LPFC_SLI_REV4)
6031 lpfc_sli4_unreg_all_rpis(vports[i]);
6032 lpfc_mbx_unreg_vpi(vports[i]);
6033 shost = lpfc_shost_from_vport(vports[i]);
6034 spin_lock_irq(shost->host_lock);
6035 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6036 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6037 spin_unlock_irq(shost->host_lock);
6039 lpfc_destroy_vport_work_array(phba, vports);
6040 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6041 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6043 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6044 lpfc_cleanup_pending_mbox(phba->pport);
6045 if (phba->sli_rev == LPFC_SLI_REV4)
6046 lpfc_sli4_unreg_all_rpis(phba->pport);
6047 lpfc_mbx_unreg_vpi(phba->pport);
6048 shost = lpfc_shost_from_vport(phba->pport);
6049 spin_lock_irq(shost->host_lock);
6050 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6051 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6052 spin_unlock_irq(shost->host_lock);
6055 /* Cleanup any outstanding ELS commands */
6056 lpfc_els_flush_all_cmd(phba);
6058 /* Unregister the physical port VFI */
6059 rc = lpfc_issue_unreg_vfi(phba->pport);
6064 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6065 * @phba: Pointer to hba context object.
6067 * This function issues synchronous unregister FCF mailbox command to HBA to
6068 * unregister the currently registered FCF record. The driver does not reset
6069 * the driver FCF usage state flags.
6071 * Return 0 if successfully issued, none-zero otherwise.
6074 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6079 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6081 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6082 "2551 UNREG_FCFI mbox allocation failed"
6083 "HBA state x%x\n", phba->pport->port_state);
6086 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6087 mbox->vport = phba->pport;
6088 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6089 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6091 if (rc == MBX_NOT_FINISHED) {
6092 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6093 "2552 Unregister FCFI command failed rc x%x "
6095 rc, phba->pport->port_state);
6102 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6103 * @phba: Pointer to hba context object.
6105 * This function unregisters the currently reigstered FCF. This function
6106 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6109 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6113 /* Preparation for unregistering fcf */
6114 rc = lpfc_unregister_fcf_prep(phba);
6116 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6117 "2748 Failed to prepare for unregistering "
6118 "HBA's FCF record: rc=%d\n", rc);
6122 /* Now, unregister FCF record and reset HBA FCF state */
6123 rc = lpfc_sli4_unregister_fcf(phba);
6126 /* Reset HBA FCF states after successful unregister FCF */
6127 phba->fcf.fcf_flag = 0;
6128 phba->fcf.current_rec.flag = 0;
6131 * If driver is not unloading, check if there is any other
6132 * FCF record that can be used for discovery.
6134 if ((phba->pport->load_flag & FC_UNLOADING) ||
6135 (phba->link_state < LPFC_LINK_UP))
6138 /* This is considered as the initial FCF discovery scan */
6139 spin_lock_irq(&phba->hbalock);
6140 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6141 spin_unlock_irq(&phba->hbalock);
6143 /* Reset FCF roundrobin bmask for new discovery */
6144 lpfc_sli4_clear_fcf_rr_bmask(phba);
6146 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6149 spin_lock_irq(&phba->hbalock);
6150 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6151 spin_unlock_irq(&phba->hbalock);
6152 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6153 "2553 lpfc_unregister_unused_fcf failed "
6154 "to read FCF record HBA state x%x\n",
6155 phba->pport->port_state);
6160 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6161 * @phba: Pointer to hba context object.
6163 * This function just unregisters the currently reigstered FCF. It does not
6164 * try to find another FCF for discovery.
6167 lpfc_unregister_fcf(struct lpfc_hba *phba)
6171 /* Preparation for unregistering fcf */
6172 rc = lpfc_unregister_fcf_prep(phba);
6174 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6175 "2749 Failed to prepare for unregistering "
6176 "HBA's FCF record: rc=%d\n", rc);
6180 /* Now, unregister FCF record and reset HBA FCF state */
6181 rc = lpfc_sli4_unregister_fcf(phba);
6184 /* Set proper HBA FCF states after successful unregister FCF */
6185 spin_lock_irq(&phba->hbalock);
6186 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6187 spin_unlock_irq(&phba->hbalock);
6191 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6192 * @phba: Pointer to hba context object.
6194 * This function check if there are any connected remote port for the FCF and
6195 * if all the devices are disconnected, this function unregister FCFI.
6196 * This function also tries to use another FCF for discovery.
6199 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6202 * If HBA is not running in FIP mode, if HBA does not support
6203 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6204 * registered, do nothing.
6206 spin_lock_irq(&phba->hbalock);
6207 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6208 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6209 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6210 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6211 (phba->pport->port_state == LPFC_FLOGI)) {
6212 spin_unlock_irq(&phba->hbalock);
6215 spin_unlock_irq(&phba->hbalock);
6217 if (lpfc_fcf_inuse(phba))
6220 lpfc_unregister_fcf_rescan(phba);
6224 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6225 * @phba: Pointer to hba context object.
6226 * @buff: Buffer containing the FCF connection table as in the config
6228 * This function create driver data structure for the FCF connection
6229 * record table read from config region 23.
6232 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6235 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6236 struct lpfc_fcf_conn_hdr *conn_hdr;
6237 struct lpfc_fcf_conn_rec *conn_rec;
6238 uint32_t record_count;
6241 /* Free the current connect table */
6242 list_for_each_entry_safe(conn_entry, next_conn_entry,
6243 &phba->fcf_conn_rec_list, list) {
6244 list_del_init(&conn_entry->list);
6248 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6249 record_count = conn_hdr->length * sizeof(uint32_t)/
6250 sizeof(struct lpfc_fcf_conn_rec);
6252 conn_rec = (struct lpfc_fcf_conn_rec *)
6253 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6255 for (i = 0; i < record_count; i++) {
6256 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6258 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6262 "2566 Failed to allocate connection"
6267 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6268 sizeof(struct lpfc_fcf_conn_rec));
6269 list_add_tail(&conn_entry->list,
6270 &phba->fcf_conn_rec_list);
6273 if (!list_empty(&phba->fcf_conn_rec_list)) {
6275 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6277 conn_rec = &conn_entry->conn_rec;
6278 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6279 "3345 FCF connection list rec[%02d]: "
6280 "flags:x%04x, vtag:x%04x, "
6281 "fabric_name:x%02x:%02x:%02x:%02x:"
6282 "%02x:%02x:%02x:%02x, "
6283 "switch_name:x%02x:%02x:%02x:%02x:"
6284 "%02x:%02x:%02x:%02x\n", i++,
6285 conn_rec->flags, conn_rec->vlan_tag,
6286 conn_rec->fabric_name[0],
6287 conn_rec->fabric_name[1],
6288 conn_rec->fabric_name[2],
6289 conn_rec->fabric_name[3],
6290 conn_rec->fabric_name[4],
6291 conn_rec->fabric_name[5],
6292 conn_rec->fabric_name[6],
6293 conn_rec->fabric_name[7],
6294 conn_rec->switch_name[0],
6295 conn_rec->switch_name[1],
6296 conn_rec->switch_name[2],
6297 conn_rec->switch_name[3],
6298 conn_rec->switch_name[4],
6299 conn_rec->switch_name[5],
6300 conn_rec->switch_name[6],
6301 conn_rec->switch_name[7]);
6307 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6308 * @phba: Pointer to hba context object.
6309 * @buff: Buffer containing the FCoE parameter data structure.
6311 * This function update driver data structure with config
6312 * parameters read from config region 23.
6315 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6318 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6319 struct lpfc_fcoe_params *fcoe_param;
6321 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6323 fcoe_param = (struct lpfc_fcoe_params *)
6324 (buff + sizeof(struct lpfc_fip_param_hdr));
6326 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6327 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6330 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6331 phba->valid_vlan = 1;
6332 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6336 phba->fc_map[0] = fcoe_param->fc_map[0];
6337 phba->fc_map[1] = fcoe_param->fc_map[1];
6338 phba->fc_map[2] = fcoe_param->fc_map[2];
6343 * lpfc_get_rec_conf23 - Get a record type in config region data.
6344 * @buff: Buffer containing config region 23 data.
6345 * @size: Size of the data buffer.
6346 * @rec_type: Record type to be searched.
6348 * This function searches config region data to find the beginning
6349 * of the record specified by record_type. If record found, this
6350 * function return pointer to the record else return NULL.
6353 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6355 uint32_t offset = 0, rec_length;
6357 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6358 (size < sizeof(uint32_t)))
6361 rec_length = buff[offset + 1];
6364 * One TLV record has one word header and number of data words
6365 * specified in the rec_length field of the record header.
6367 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6369 if (buff[offset] == rec_type)
6370 return &buff[offset];
6372 if (buff[offset] == LPFC_REGION23_LAST_REC)
6375 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6376 rec_length = buff[offset + 1];
6382 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6383 * @phba: Pointer to lpfc_hba data structure.
6384 * @buff: Buffer containing config region 23 data.
6385 * @size: Size of the data buffer.
6387 * This function parses the FCoE config parameters in config region 23 and
6388 * populate driver data structure with the parameters.
6391 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6395 uint32_t offset = 0;
6399 * If data size is less than 2 words signature and version cannot be
6402 if (size < 2*sizeof(uint32_t))
6405 /* Check the region signature first */
6406 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6407 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6408 "2567 Config region 23 has bad signature\n");
6414 /* Check the data structure version */
6415 if (buff[offset] != LPFC_REGION23_VERSION) {
6416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6417 "2568 Config region 23 has bad version\n");
6422 /* Read FCoE param record */
6423 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6424 size - offset, FCOE_PARAM_TYPE);
6426 lpfc_read_fcoe_param(phba, rec_ptr);
6428 /* Read FCF connection table */
6429 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6430 size - offset, FCOE_CONN_TBL_TYPE);
6432 lpfc_read_fcf_conn_tbl(phba, rec_ptr);