1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73 static int lpfc_fcf_inuse(struct lpfc_hba *);
74 static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
75 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
76 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
79 lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
81 if (ndlp->nlp_fc4_type ||
82 ndlp->nlp_type & NLP_FABRIC)
86 /* The source of a terminate rport I/O is either a dev_loss_tmo
87 * event or a call to fc_remove_host. While the rport should be
88 * valid during these downcalls, the transport can call twice
89 * in a single event. This routine provides somoe protection
90 * as the NDLP isn't really free, just released to the pool.
93 lpfc_rport_invalid(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
103 rdata = rport->dd_data;
105 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
112 pr_err("**** %s: NULL ndlp on rport x%px SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
127 lpfc_terminate_rport_io(struct fc_rport *rport)
129 struct lpfc_rport_data *rdata;
130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
133 if (lpfc_rport_invalid(rport))
136 rdata = rport->dd_data;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
143 if (ndlp->nlp_sid != NLP_NO_SID)
144 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
148 * This function will be called when dev_loss_tmo fire.
151 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
153 struct lpfc_nodelist *ndlp;
154 struct lpfc_vport *vport;
155 struct lpfc_hba *phba;
156 struct lpfc_work_evt *evtp;
157 unsigned long iflags;
159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172 "load_flag x%x refcnt %d\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref));
176 /* Don't schedule a worker thread event if the vport is going down.
177 * The teardown process cleans up the node via lpfc_drop_node.
179 if (vport->load_flag & FC_UNLOADING) {
180 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
183 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
185 /* Remove the node reference from remote_port_add now.
186 * The driver will not call remote_port_delete.
192 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
195 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
196 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
197 "6789 rport name %llx != node port name %llx",
199 wwn_to_u64(ndlp->nlp_portname.u.wwn));
201 evtp = &ndlp->dev_loss_evt;
203 if (!list_empty(&evtp->evt_listp)) {
204 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
205 "6790 rport name %llx dev_loss_evt pending\n",
210 spin_lock_irqsave(&ndlp->lock, iflags);
211 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
212 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
215 * The backend does not expect any more calls associated with this
216 * rport. Remove the association between rport and ndlp.
218 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
219 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
221 spin_unlock_irqrestore(&ndlp->lock, iflags);
223 /* We need to hold the node by incrementing the reference
224 * count until this queued work is done
226 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
228 spin_lock_irqsave(&phba->hbalock, iflags);
229 if (evtp->evt_arg1) {
230 evtp->evt = LPFC_EVT_DEV_LOSS;
231 list_add_tail(&evtp->evt_listp, &phba->work_list);
232 lpfc_worker_wake_up(phba);
234 spin_unlock_irqrestore(&phba->hbalock, iflags);
240 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
241 * @vport: Pointer to vport context object.
243 * This function checks for idle VMID entries related to a particular vport. If
244 * found unused/idle, free them accordingly.
246 static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
249 u32 difftime = 0, r, bucket;
252 struct lpfc_vmid *vmp;
254 write_lock(&vport->vmid_lock);
256 if (!vport->cur_vmid_cnt)
259 /* iterate through the table */
260 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
262 if (vmp->flag & LPFC_VMID_REGISTERED) {
263 /* check if the particular VMID is in use */
264 /* for all available per cpu variable */
265 for_each_possible_cpu(cpu) {
266 /* if last access time is less than timeout */
267 lta = per_cpu_ptr(vmp->last_io_time, cpu);
270 difftime = (jiffies) - (*lta);
271 if ((vport->vmid_inactivity_timeout *
272 JIFFIES_PER_HR) > difftime) {
278 /* if none of the cpus have been used by the vm, */
279 /* remove the entry if already registered */
281 /* mark the entry for deregistration */
282 vmp->flag = LPFC_VMID_DE_REGISTER;
283 write_unlock(&vport->vmid_lock);
284 if (vport->vmid_priority_tagging)
285 r = lpfc_vmid_uvem(vport, vmp, false);
287 r = lpfc_vmid_cmd(vport,
291 /* decrement number of active vms and mark */
292 /* entry in slot as free */
293 write_lock(&vport->vmid_lock);
295 struct lpfc_vmid *ht = vmp;
297 vport->cur_vmid_cnt--;
298 ht->flag = LPFC_VMID_SLOT_FREE;
299 free_percpu(ht->last_io_time);
300 ht->last_io_time = NULL;
301 hash_del(&ht->hnode);
307 write_unlock(&vport->vmid_lock);
311 * lpfc_check_inactive_vmid - VMID inactivity checker
312 * @phba: Pointer to hba context object.
314 * This function is called from the worker thread to determine if an entry in
315 * the VMID table can be released since there was no I/O activity seen from that
316 * particular VM for the specified time. When this happens, the entry in the
317 * table is released and also the resources on the switch cleared.
320 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
322 struct lpfc_vport *vport;
323 struct lpfc_vport **vports;
326 vports = lpfc_create_vport_work_array(phba);
330 for (i = 0; i <= phba->max_vports; i++) {
331 if ((!vports[i]) && (i == 0))
338 lpfc_check_inactive_vmid_one(vport);
340 lpfc_destroy_vport_work_array(phba, vports);
344 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
345 * @ndlp: Pointer to remote node object.
347 * This function is called from the worker thread when devloss timeout timer
348 * expires. For SLI4 host, this routine shall return 1 when at lease one
349 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
350 * routine shall return 0 when there is no remote node is still in use of FCF
351 * when devloss timeout happened to this @ndlp.
354 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
356 struct lpfc_vport *vport;
357 struct lpfc_hba *phba;
361 unsigned long iflags;
364 name = (uint8_t *)&ndlp->nlp_portname;
367 spin_lock_irqsave(&ndlp->lock, iflags);
368 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
369 spin_unlock_irqrestore(&ndlp->lock, iflags);
371 if (phba->sli_rev == LPFC_SLI_REV4)
372 fcf_inuse = lpfc_fcf_inuse(phba);
374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
375 "rport devlosstmo:did:x%x type:x%x id:x%x",
376 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
378 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
379 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
380 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
381 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
383 /* If the driver is recovering the rport, ignore devloss. */
384 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
385 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
386 "0284 Devloss timeout Ignored on "
387 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
389 *name, *(name+1), *(name+2), *(name+3),
390 *(name+4), *(name+5), *(name+6), *(name+7),
395 /* Fabric nodes are done. */
396 if (ndlp->nlp_type & NLP_FABRIC) {
401 if (ndlp->nlp_sid != NLP_NO_SID) {
403 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
407 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
408 "0203 Devloss timeout on "
409 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
410 "NPort x%06x Data: x%x x%x x%x\n",
411 *name, *(name+1), *(name+2), *(name+3),
412 *(name+4), *(name+5), *(name+6), *(name+7),
413 ndlp->nlp_DID, ndlp->nlp_flag,
414 ndlp->nlp_state, ndlp->nlp_rpi);
416 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
417 "0204 Devloss timeout on "
418 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
419 "NPort x%06x Data: x%x x%x x%x\n",
420 *name, *(name+1), *(name+2), *(name+3),
421 *(name+4), *(name+5), *(name+6), *(name+7),
422 ndlp->nlp_DID, ndlp->nlp_flag,
423 ndlp->nlp_state, ndlp->nlp_rpi);
426 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
427 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
432 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
434 struct lpfc_vport *vport;
435 struct lpfc_vport **vports;
438 vports = lpfc_create_vport_work_array(phba);
442 for (i = 0; i <= phba->max_vports; i++) {
443 if ((!vports[i]) && (i == 0))
450 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
451 if (!lpfc_issue_els_qfpa(vport))
452 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
455 lpfc_destroy_vport_work_array(phba, vports);
459 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
460 * @phba: Pointer to hba context object.
461 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
462 * @nlp_did: remote node identifer with devloss timeout.
464 * This function is called from the worker thread after invoking devloss
465 * timeout handler and releasing the reference count for the ndlp with
466 * which the devloss timeout was handled for SLI4 host. For the devloss
467 * timeout of the last remote node which had been in use of FCF, when this
468 * routine is invoked, it shall be guaranteed that none of the remote are
469 * in-use of FCF. When devloss timeout to the last remote using the FCF,
470 * if the FIP engine is neither in FCF table scan process nor roundrobin
471 * failover process, the in-use FCF shall be unregistered. If the FIP
472 * engine is in FCF discovery process, the devloss timeout state shall
473 * be set for either the FCF table scan process or roundrobin failover
474 * process to unregister the in-use FCF.
477 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
480 /* If devloss timeout happened to a remote node when FCF had no
481 * longer been in-use, do nothing.
486 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
487 spin_lock_irq(&phba->hbalock);
488 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
489 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
490 spin_unlock_irq(&phba->hbalock);
493 phba->hba_flag |= HBA_DEVLOSS_TMO;
494 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
495 "2847 Last remote node (x%x) using "
496 "FCF devloss tmo\n", nlp_did);
498 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
499 spin_unlock_irq(&phba->hbalock);
500 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
501 "2868 Devloss tmo to FCF rediscovery "
505 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
506 spin_unlock_irq(&phba->hbalock);
507 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
508 "2869 Devloss tmo to idle FIP engine, "
509 "unreg in-use FCF and rescan.\n");
510 /* Unregister in-use FCF and rescan */
511 lpfc_unregister_fcf_rescan(phba);
514 spin_unlock_irq(&phba->hbalock);
515 if (phba->hba_flag & FCF_TS_INPROG)
516 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
517 "2870 FCF table scan in progress\n");
518 if (phba->hba_flag & FCF_RR_INPROG)
519 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
520 "2871 FLOGI roundrobin FCF failover "
523 lpfc_unregister_unused_fcf(phba);
527 * lpfc_alloc_fast_evt - Allocates data structure for posting event
528 * @phba: Pointer to hba context object.
530 * This function is called from the functions which need to post
531 * events from interrupt context. This function allocates data
532 * structure required for posting event. It also keeps track of
533 * number of events pending and prevent event storm when there are
536 struct lpfc_fast_path_event *
537 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
538 struct lpfc_fast_path_event *ret;
540 /* If there are lot of fast event do not exhaust memory due to this */
541 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
544 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
547 atomic_inc(&phba->fast_event_count);
548 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
549 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
555 * lpfc_free_fast_evt - Frees event data structure
556 * @phba: Pointer to hba context object.
557 * @evt: Event object which need to be freed.
559 * This function frees the data structure required for posting
563 lpfc_free_fast_evt(struct lpfc_hba *phba,
564 struct lpfc_fast_path_event *evt) {
566 atomic_dec(&phba->fast_event_count);
571 * lpfc_send_fastpath_evt - Posts events generated from fast path
572 * @phba: Pointer to hba context object.
573 * @evtp: Event data structure.
575 * This function is called from worker thread, when the interrupt
576 * context need to post an event. This function posts the event
577 * to fc transport netlink interface.
580 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
581 struct lpfc_work_evt *evtp)
583 unsigned long evt_category, evt_sub_category;
584 struct lpfc_fast_path_event *fast_evt_data;
586 uint32_t evt_data_size;
587 struct Scsi_Host *shost;
589 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
592 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
593 evt_sub_category = (unsigned long) fast_evt_data->un.
594 fabric_evt.subcategory;
595 shost = lpfc_shost_from_vport(fast_evt_data->vport);
596 if (evt_category == FC_REG_FABRIC_EVENT) {
597 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
598 evt_data = (char *) &fast_evt_data->un.read_check_error;
599 evt_data_size = sizeof(fast_evt_data->un.
601 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
602 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
603 evt_data = (char *) &fast_evt_data->un.fabric_evt;
604 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
606 lpfc_free_fast_evt(phba, fast_evt_data);
609 } else if (evt_category == FC_REG_SCSI_EVENT) {
610 switch (evt_sub_category) {
611 case LPFC_EVENT_QFULL:
612 case LPFC_EVENT_DEVBSY:
613 evt_data = (char *) &fast_evt_data->un.scsi_evt;
614 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
616 case LPFC_EVENT_CHECK_COND:
617 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
618 evt_data_size = sizeof(fast_evt_data->un.
621 case LPFC_EVENT_VARQUEDEPTH:
622 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
623 evt_data_size = sizeof(fast_evt_data->un.
627 lpfc_free_fast_evt(phba, fast_evt_data);
631 lpfc_free_fast_evt(phba, fast_evt_data);
635 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
636 fc_host_post_vendor_event(shost,
637 fc_get_event_number(),
642 lpfc_free_fast_evt(phba, fast_evt_data);
647 lpfc_work_list_done(struct lpfc_hba *phba)
649 struct lpfc_work_evt *evtp = NULL;
650 struct lpfc_nodelist *ndlp;
655 spin_lock_irq(&phba->hbalock);
656 while (!list_empty(&phba->work_list)) {
657 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
659 spin_unlock_irq(&phba->hbalock);
662 case LPFC_EVT_ELS_RETRY:
663 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
664 lpfc_els_retry_delay_handler(ndlp);
665 free_evt = 0; /* evt is part of ndlp */
666 /* decrement the node reference count held
667 * for this queued work
671 case LPFC_EVT_DEV_LOSS:
672 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
673 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
675 /* decrement the node reference count held for
678 nlp_did = ndlp->nlp_DID;
680 if (phba->sli_rev == LPFC_SLI_REV4)
681 lpfc_sli4_post_dev_loss_tmo_handler(phba,
685 case LPFC_EVT_RECOVER_PORT:
686 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
687 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
689 /* decrement the node reference count held for
694 case LPFC_EVT_ONLINE:
695 if (phba->link_state < LPFC_LINK_DOWN)
696 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
698 *(int *) (evtp->evt_arg1) = 0;
699 complete((struct completion *)(evtp->evt_arg2));
701 case LPFC_EVT_OFFLINE_PREP:
702 if (phba->link_state >= LPFC_LINK_DOWN)
703 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
704 *(int *)(evtp->evt_arg1) = 0;
705 complete((struct completion *)(evtp->evt_arg2));
707 case LPFC_EVT_OFFLINE:
709 lpfc_sli_brdrestart(phba);
710 *(int *)(evtp->evt_arg1) =
711 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
712 lpfc_unblock_mgmt_io(phba);
713 complete((struct completion *)(evtp->evt_arg2));
715 case LPFC_EVT_WARM_START:
717 lpfc_reset_barrier(phba);
718 lpfc_sli_brdreset(phba);
719 lpfc_hba_down_post(phba);
720 *(int *)(evtp->evt_arg1) =
721 lpfc_sli_brdready(phba, HS_MBRDY);
722 lpfc_unblock_mgmt_io(phba);
723 complete((struct completion *)(evtp->evt_arg2));
727 *(int *)(evtp->evt_arg1)
728 = (phba->pport->stopped)
729 ? 0 : lpfc_sli_brdkill(phba);
730 lpfc_unblock_mgmt_io(phba);
731 complete((struct completion *)(evtp->evt_arg2));
733 case LPFC_EVT_FASTPATH_MGMT_EVT:
734 lpfc_send_fastpath_evt(phba, evtp);
737 case LPFC_EVT_RESET_HBA:
738 if (!(phba->pport->load_flag & FC_UNLOADING))
739 lpfc_reset_hba(phba);
744 spin_lock_irq(&phba->hbalock);
746 spin_unlock_irq(&phba->hbalock);
751 lpfc_work_done(struct lpfc_hba *phba)
753 struct lpfc_sli_ring *pring;
754 uint32_t ha_copy, status, control, work_port_events;
755 struct lpfc_vport **vports;
756 struct lpfc_vport *vport;
759 spin_lock_irq(&phba->hbalock);
760 ha_copy = phba->work_ha;
762 spin_unlock_irq(&phba->hbalock);
764 /* First, try to post the next mailbox command to SLI4 device */
765 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
766 lpfc_sli4_post_async_mbox(phba);
768 if (ha_copy & HA_ERATT)
769 /* Handle the error attention event */
770 lpfc_handle_eratt(phba);
772 if (ha_copy & HA_MBATT)
773 lpfc_sli_handle_mb_event(phba);
775 if (ha_copy & HA_LATT)
776 lpfc_handle_latt(phba);
778 /* Handle VMID Events */
779 if (lpfc_is_vmid_enabled(phba)) {
780 if (phba->pport->work_port_events &
781 WORKER_CHECK_VMID_ISSUE_QFPA) {
782 lpfc_check_vmid_qfpa_issue(phba);
783 phba->pport->work_port_events &=
784 ~WORKER_CHECK_VMID_ISSUE_QFPA;
786 if (phba->pport->work_port_events &
787 WORKER_CHECK_INACTIVE_VMID) {
788 lpfc_check_inactive_vmid(phba);
789 phba->pport->work_port_events &=
790 ~WORKER_CHECK_INACTIVE_VMID;
794 /* Process SLI4 events */
795 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
796 if (phba->hba_flag & HBA_RRQ_ACTIVE)
797 lpfc_handle_rrq_active(phba);
798 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
799 lpfc_sli4_els_xri_abort_event_proc(phba);
800 if (phba->hba_flag & ASYNC_EVENT)
801 lpfc_sli4_async_event_proc(phba);
802 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
803 spin_lock_irq(&phba->hbalock);
804 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
805 spin_unlock_irq(&phba->hbalock);
806 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
808 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
809 lpfc_sli4_fcf_redisc_event_proc(phba);
812 vports = lpfc_create_vport_work_array(phba);
814 for (i = 0; i <= phba->max_vports; i++) {
816 * We could have no vports in array if unloading, so if
817 * this happens then just use the pport
819 if (vports[i] == NULL && i == 0)
825 spin_lock_irq(&vport->work_port_lock);
826 work_port_events = vport->work_port_events;
827 vport->work_port_events &= ~work_port_events;
828 spin_unlock_irq(&vport->work_port_lock);
829 if (work_port_events & WORKER_DISC_TMO)
830 lpfc_disc_timeout_handler(vport);
831 if (work_port_events & WORKER_ELS_TMO)
832 lpfc_els_timeout_handler(vport);
833 if (work_port_events & WORKER_HB_TMO)
834 lpfc_hb_timeout_handler(phba);
835 if (work_port_events & WORKER_MBOX_TMO)
836 lpfc_mbox_timeout_handler(phba);
837 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
838 lpfc_unblock_fabric_iocbs(phba);
839 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
840 lpfc_ramp_down_queue_handler(phba);
841 if (work_port_events & WORKER_DELAYED_DISC_TMO)
842 lpfc_delayed_disc_timeout_handler(vport);
844 lpfc_destroy_vport_work_array(phba, vports);
846 pring = lpfc_phba_elsring(phba);
847 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
848 status >>= (4*LPFC_ELS_RING);
849 if (pring && (status & HA_RXMASK ||
850 pring->flag & LPFC_DEFERRED_RING_EVENT ||
851 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
852 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
853 pring->flag |= LPFC_DEFERRED_RING_EVENT;
854 /* Preserve legacy behavior. */
855 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
856 set_bit(LPFC_DATA_READY, &phba->data_flags);
858 /* Driver could have abort request completed in queue
859 * when link goes down. Allow for this transition.
861 if (phba->link_state >= LPFC_LINK_DOWN ||
862 phba->link_flag & LS_MDS_LOOPBACK) {
863 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
864 lpfc_sli_handle_slow_ring_event(phba, pring,
869 if (phba->sli_rev == LPFC_SLI_REV4)
870 lpfc_drain_txq(phba);
872 * Turn on Ring interrupts
874 if (phba->sli_rev <= LPFC_SLI_REV3) {
875 spin_lock_irq(&phba->hbalock);
876 control = readl(phba->HCregaddr);
877 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
878 lpfc_debugfs_slow_ring_trc(phba,
879 "WRK Enable ring: cntl:x%x hacopy:x%x",
880 control, ha_copy, 0);
882 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
883 writel(control, phba->HCregaddr);
884 readl(phba->HCregaddr); /* flush */
886 lpfc_debugfs_slow_ring_trc(phba,
887 "WRK Ring ok: cntl:x%x hacopy:x%x",
888 control, ha_copy, 0);
890 spin_unlock_irq(&phba->hbalock);
893 lpfc_work_list_done(phba);
897 lpfc_do_work(void *p)
899 struct lpfc_hba *phba = p;
902 set_user_nice(current, MIN_NICE);
903 current->flags |= PF_NOFREEZE;
904 phba->data_flags = 0;
906 while (!kthread_should_stop()) {
907 /* wait and check worker queue activities */
908 rc = wait_event_interruptible(phba->work_waitq,
909 (test_and_clear_bit(LPFC_DATA_READY,
911 || kthread_should_stop()));
912 /* Signal wakeup shall terminate the worker thread */
914 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
915 "0433 Wakeup on signal: rc=x%x\n", rc);
919 /* Attend pending lpfc data processing */
920 lpfc_work_done(phba);
922 phba->worker_thread = NULL;
923 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
924 "0432 Worker thread stopped.\n");
929 * This is only called to handle FC worker events. Since this a rare
930 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
931 * embedding it in the IOCB.
934 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
937 struct lpfc_work_evt *evtp;
941 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
942 * be queued to worker thread for processing
944 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
948 evtp->evt_arg1 = arg1;
949 evtp->evt_arg2 = arg2;
952 spin_lock_irqsave(&phba->hbalock, flags);
953 list_add_tail(&evtp->evt_listp, &phba->work_list);
954 spin_unlock_irqrestore(&phba->hbalock, flags);
956 lpfc_worker_wake_up(phba);
962 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
965 struct lpfc_hba *phba = vport->phba;
966 struct lpfc_nodelist *ndlp, *next_ndlp;
968 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
969 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
972 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
973 ((vport->port_type == LPFC_NPIV_PORT) &&
974 ((ndlp->nlp_DID == NameServer_DID) ||
975 (ndlp->nlp_DID == FDMI_DID) ||
976 (ndlp->nlp_DID == Fabric_Cntl_DID))))
977 lpfc_unreg_rpi(vport, ndlp);
979 /* Leave Fabric nodes alone on link down */
980 if ((phba->sli_rev < LPFC_SLI_REV4) &&
981 (!remove && ndlp->nlp_type & NLP_FABRIC))
984 /* Notify transport of connectivity loss to trigger cleanup. */
985 if (phba->nvmet_support &&
986 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
987 lpfc_nvmet_invalidate_host(phba, ndlp);
989 lpfc_disc_state_machine(vport, ndlp, NULL,
992 : NLP_EVT_DEVICE_RECOVERY);
994 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
995 if (phba->sli_rev == LPFC_SLI_REV4)
996 lpfc_sli4_unreg_all_rpis(vport);
997 lpfc_mbx_unreg_vpi(vport);
998 spin_lock_irq(shost->host_lock);
999 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1000 spin_unlock_irq(shost->host_lock);
1005 lpfc_port_link_failure(struct lpfc_vport *vport)
1007 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1009 /* Cleanup any outstanding received buffers */
1010 lpfc_cleanup_rcv_buffers(vport);
1012 /* Cleanup any outstanding RSCN activity */
1013 lpfc_els_flush_rscn(vport);
1015 /* Cleanup any outstanding ELS commands */
1016 lpfc_els_flush_cmd(vport);
1018 lpfc_cleanup_rpis(vport, 0);
1020 /* Turn off discovery timer if its running */
1021 lpfc_can_disctmo(vport);
1025 lpfc_linkdown_port(struct lpfc_vport *vport)
1027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1030 fc_host_post_event(shost, fc_get_event_number(),
1031 FCH_EVT_LINKDOWN, 0);
1033 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1034 "Link Down: state:x%x rtry:x%x flg:x%x",
1035 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1037 lpfc_port_link_failure(vport);
1039 /* Stop delayed Nport discovery */
1040 spin_lock_irq(shost->host_lock);
1041 vport->fc_flag &= ~FC_DISC_DELAYED;
1042 spin_unlock_irq(shost->host_lock);
1043 del_timer_sync(&vport->delayed_disc_tmo);
1047 lpfc_linkdown(struct lpfc_hba *phba)
1049 struct lpfc_vport *vport = phba->pport;
1050 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1051 struct lpfc_vport **vports;
1055 if (phba->link_state == LPFC_LINK_DOWN)
1058 /* Block all SCSI stack I/Os */
1059 lpfc_scsi_dev_block(phba);
1061 phba->defer_flogi_acc_flag = false;
1063 spin_lock_irq(&phba->hbalock);
1064 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1065 spin_unlock_irq(&phba->hbalock);
1066 if (phba->link_state > LPFC_LINK_DOWN) {
1067 phba->link_state = LPFC_LINK_DOWN;
1068 if (phba->sli4_hba.conf_trunk) {
1069 phba->trunk_link.link0.state = 0;
1070 phba->trunk_link.link1.state = 0;
1071 phba->trunk_link.link2.state = 0;
1072 phba->trunk_link.link3.state = 0;
1073 phba->sli4_hba.link_state.logical_speed =
1074 LPFC_LINK_SPEED_UNKNOWN;
1076 spin_lock_irq(shost->host_lock);
1077 phba->pport->fc_flag &= ~FC_LBIT;
1078 spin_unlock_irq(shost->host_lock);
1080 vports = lpfc_create_vport_work_array(phba);
1081 if (vports != NULL) {
1082 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1083 /* Issue a LINK DOWN event to all nodes */
1084 lpfc_linkdown_port(vports[i]);
1086 vports[i]->fc_myDID = 0;
1088 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1089 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1090 if (phba->nvmet_support)
1091 lpfc_nvmet_update_targetport(phba);
1093 lpfc_nvme_update_localport(vports[i]);
1097 lpfc_destroy_vport_work_array(phba, vports);
1099 /* Clean up any SLI3 firmware default rpi's */
1100 if (phba->sli_rev > LPFC_SLI_REV3)
1101 goto skip_unreg_did;
1103 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1105 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1107 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1108 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1109 == MBX_NOT_FINISHED) {
1110 mempool_free(mb, phba->mbox_mem_pool);
1115 /* Setup myDID for link up if we are in pt2pt mode */
1116 if (phba->pport->fc_flag & FC_PT2PT) {
1117 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1119 lpfc_config_link(phba, mb);
1120 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1122 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1123 == MBX_NOT_FINISHED) {
1124 mempool_free(mb, phba->mbox_mem_pool);
1127 spin_lock_irq(shost->host_lock);
1128 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1129 phba->pport->rcv_flogi_cnt = 0;
1130 spin_unlock_irq(shost->host_lock);
1136 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1138 struct lpfc_nodelist *ndlp;
1140 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1141 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1143 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1145 if (ndlp->nlp_type & NLP_FABRIC) {
1146 /* On Linkup its safe to clean up the ndlp
1147 * from Fabric connections.
1149 if (ndlp->nlp_DID != Fabric_DID)
1150 lpfc_unreg_rpi(vport, ndlp);
1151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1152 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1153 /* Fail outstanding IO now since device is
1156 lpfc_unreg_rpi(vport, ndlp);
1162 lpfc_linkup_port(struct lpfc_vport *vport)
1164 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1165 struct lpfc_hba *phba = vport->phba;
1167 if ((vport->load_flag & FC_UNLOADING) != 0)
1170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1171 "Link Up: top:x%x speed:x%x flg:x%x",
1172 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1174 /* If NPIV is not enabled, only bring the physical port up */
1175 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1176 (vport != phba->pport))
1179 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1180 fc_host_post_event(shost, fc_get_event_number(),
1183 spin_lock_irq(shost->host_lock);
1184 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1185 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1186 vport->fc_flag |= FC_NDISC_ACTIVE;
1187 vport->fc_ns_retry = 0;
1188 spin_unlock_irq(shost->host_lock);
1190 lpfc_linkup_cleanup_nodes(vport);
1194 lpfc_linkup(struct lpfc_hba *phba)
1196 struct lpfc_vport **vports;
1198 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1200 phba->link_state = LPFC_LINK_UP;
1202 /* Unblock fabric iocbs if they are blocked */
1203 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1204 del_timer_sync(&phba->fabric_block_timer);
1206 vports = lpfc_create_vport_work_array(phba);
1208 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1209 lpfc_linkup_port(vports[i]);
1210 lpfc_destroy_vport_work_array(phba, vports);
1212 /* Clear the pport flogi counter in case the link down was
1213 * absorbed without an ACQE. No lock here - in worker thread
1214 * and discovery is synchronized.
1216 spin_lock_irq(shost->host_lock);
1217 phba->pport->rcv_flogi_cnt = 0;
1218 spin_unlock_irq(shost->host_lock);
1220 /* reinitialize initial FLOGI flag */
1221 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1222 phba->defer_flogi_acc_flag = false;
1228 * This routine handles processing a CLEAR_LA mailbox
1229 * command upon completion. It is setup in the LPFC_MBOXQ
1230 * as the completion routine when the command is
1231 * handed off to the SLI layer. SLI3 only.
1234 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1236 struct lpfc_vport *vport = pmb->vport;
1237 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1238 struct lpfc_sli *psli = &phba->sli;
1239 MAILBOX_t *mb = &pmb->u.mb;
1242 /* Since we don't do discovery right now, turn these off here */
1243 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1244 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1246 /* Check for error */
1247 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1248 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1249 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1250 "0320 CLEAR_LA mbxStatus error x%x hba "
1252 mb->mbxStatus, vport->port_state);
1253 phba->link_state = LPFC_HBA_ERROR;
1257 if (vport->port_type == LPFC_PHYSICAL_PORT)
1258 phba->link_state = LPFC_HBA_READY;
1260 spin_lock_irq(&phba->hbalock);
1261 psli->sli_flag |= LPFC_PROCESS_LA;
1262 control = readl(phba->HCregaddr);
1263 control |= HC_LAINT_ENA;
1264 writel(control, phba->HCregaddr);
1265 readl(phba->HCregaddr); /* flush */
1266 spin_unlock_irq(&phba->hbalock);
1267 mempool_free(pmb, phba->mbox_mem_pool);
1271 /* Device Discovery completes */
1272 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1273 "0225 Device Discovery completes\n");
1274 mempool_free(pmb, phba->mbox_mem_pool);
1276 spin_lock_irq(shost->host_lock);
1277 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1278 spin_unlock_irq(shost->host_lock);
1280 lpfc_can_disctmo(vport);
1282 /* turn on Link Attention interrupts */
1284 spin_lock_irq(&phba->hbalock);
1285 psli->sli_flag |= LPFC_PROCESS_LA;
1286 control = readl(phba->HCregaddr);
1287 control |= HC_LAINT_ENA;
1288 writel(control, phba->HCregaddr);
1289 readl(phba->HCregaddr); /* flush */
1290 spin_unlock_irq(&phba->hbalock);
1296 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1298 struct lpfc_vport *vport = pmb->vport;
1299 LPFC_MBOXQ_t *sparam_mb;
1300 struct lpfc_dmabuf *sparam_mp;
1301 u16 status = pmb->u.mb.mbxStatus;
1304 mempool_free(pmb, phba->mbox_mem_pool);
1309 /* don't perform discovery for SLI4 loopback diagnostic test */
1310 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1311 !(phba->hba_flag & HBA_FCOE_MODE) &&
1312 (phba->link_flag & LS_LOOPBACK_MODE))
1315 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1316 vport->fc_flag & FC_PUBLIC_LOOP &&
1317 !(vport->fc_flag & FC_LBIT)) {
1318 /* Need to wait for FAN - use discovery timer
1319 * for timeout. port_state is identically
1320 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1322 lpfc_set_disctmo(vport);
1326 /* Start discovery by sending a FLOGI. port_state is identically
1327 * LPFC_FLOGI while waiting for FLOGI cmpl.
1329 if (vport->port_state != LPFC_FLOGI) {
1330 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1331 * bb-credit recovery is in place.
1333 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1334 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1335 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1340 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1342 mempool_free(sparam_mb, phba->mbox_mem_pool);
1345 sparam_mb->vport = vport;
1346 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1347 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1348 if (rc == MBX_NOT_FINISHED) {
1349 sparam_mp = (struct lpfc_dmabuf *)
1351 lpfc_mbuf_free(phba, sparam_mp->virt,
1354 sparam_mb->ctx_buf = NULL;
1355 mempool_free(sparam_mb, phba->mbox_mem_pool);
1359 phba->hba_flag |= HBA_DEFER_FLOGI;
1361 lpfc_initial_flogi(vport);
1364 if (vport->fc_flag & FC_PT2PT)
1365 lpfc_disc_start(vport);
1370 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1371 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1372 status, vport->port_state);
1375 lpfc_linkdown(phba);
1377 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1378 "0200 CONFIG_LINK bad hba state x%x\n",
1381 lpfc_issue_clear_la(phba, vport);
1386 * lpfc_sli4_clear_fcf_rr_bmask
1387 * @phba: pointer to the struct lpfc_hba for this port.
1388 * This fucnction resets the round robin bit mask and clears the
1389 * fcf priority list. The list deletions are done while holding the
1390 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1391 * from the lpfc_fcf_pri record.
1394 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1396 struct lpfc_fcf_pri *fcf_pri;
1397 struct lpfc_fcf_pri *next_fcf_pri;
1398 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1399 spin_lock_irq(&phba->hbalock);
1400 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1401 &phba->fcf.fcf_pri_list, list) {
1402 list_del_init(&fcf_pri->list);
1403 fcf_pri->fcf_rec.flag = 0;
1405 spin_unlock_irq(&phba->hbalock);
1408 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1410 struct lpfc_vport *vport = mboxq->vport;
1412 if (mboxq->u.mb.mbxStatus) {
1413 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1414 "2017 REG_FCFI mbxStatus error x%x "
1415 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1420 /* Start FCoE discovery by sending a FLOGI. */
1421 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1422 /* Set the FCFI registered flag */
1423 spin_lock_irq(&phba->hbalock);
1424 phba->fcf.fcf_flag |= FCF_REGISTERED;
1425 spin_unlock_irq(&phba->hbalock);
1427 /* If there is a pending FCoE event, restart FCF table scan. */
1428 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1429 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1432 /* Mark successful completion of FCF table scan */
1433 spin_lock_irq(&phba->hbalock);
1434 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1435 phba->hba_flag &= ~FCF_TS_INPROG;
1436 if (vport->port_state != LPFC_FLOGI) {
1437 phba->hba_flag |= FCF_RR_INPROG;
1438 spin_unlock_irq(&phba->hbalock);
1439 lpfc_issue_init_vfi(vport);
1442 spin_unlock_irq(&phba->hbalock);
1446 spin_lock_irq(&phba->hbalock);
1447 phba->hba_flag &= ~FCF_RR_INPROG;
1448 spin_unlock_irq(&phba->hbalock);
1450 mempool_free(mboxq, phba->mbox_mem_pool);
1454 * lpfc_fab_name_match - Check if the fcf fabric name match.
1455 * @fab_name: pointer to fabric name.
1456 * @new_fcf_record: pointer to fcf record.
1458 * This routine compare the fcf record's fabric name with provided
1459 * fabric name. If the fabric name are identical this function
1460 * returns 1 else return 0.
1463 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1465 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1467 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1469 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1471 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1473 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1475 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1477 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1479 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1485 * lpfc_sw_name_match - Check if the fcf switch name match.
1486 * @sw_name: pointer to switch name.
1487 * @new_fcf_record: pointer to fcf record.
1489 * This routine compare the fcf record's switch name with provided
1490 * switch name. If the switch name are identical this function
1491 * returns 1 else return 0.
1494 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1496 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1498 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1500 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1502 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1504 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1506 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1508 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1510 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1516 * lpfc_mac_addr_match - Check if the fcf mac address match.
1517 * @mac_addr: pointer to mac address.
1518 * @new_fcf_record: pointer to fcf record.
1520 * This routine compare the fcf record's mac address with HBA's
1521 * FCF mac address. If the mac addresses are identical this function
1522 * returns 1 else return 0.
1525 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1527 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1529 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1531 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1533 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1535 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1537 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1543 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1545 return (curr_vlan_id == new_vlan_id);
1549 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1550 * @phba: pointer to lpfc hba data structure.
1551 * @fcf_index: Index for the lpfc_fcf_record.
1552 * @new_fcf_record: pointer to hba fcf record.
1554 * This routine updates the driver FCF priority record from the new HBA FCF
1555 * record. The hbalock is asserted held in the code path calling this
1559 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1560 struct fcf_record *new_fcf_record
1563 struct lpfc_fcf_pri *fcf_pri;
1565 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1566 fcf_pri->fcf_rec.fcf_index = fcf_index;
1567 /* FCF record priority */
1568 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1573 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1574 * @fcf_rec: pointer to driver fcf record.
1575 * @new_fcf_record: pointer to fcf record.
1577 * This routine copies the FCF information from the FCF
1578 * record to lpfc_hba data structure.
1581 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1582 struct fcf_record *new_fcf_record)
1585 fcf_rec->fabric_name[0] =
1586 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1587 fcf_rec->fabric_name[1] =
1588 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1589 fcf_rec->fabric_name[2] =
1590 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1591 fcf_rec->fabric_name[3] =
1592 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1593 fcf_rec->fabric_name[4] =
1594 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1595 fcf_rec->fabric_name[5] =
1596 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1597 fcf_rec->fabric_name[6] =
1598 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1599 fcf_rec->fabric_name[7] =
1600 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1602 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1603 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1604 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1605 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1606 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1607 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1608 /* FCF record index */
1609 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1610 /* FCF record priority */
1611 fcf_rec->priority = new_fcf_record->fip_priority;
1613 fcf_rec->switch_name[0] =
1614 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1615 fcf_rec->switch_name[1] =
1616 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1617 fcf_rec->switch_name[2] =
1618 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1619 fcf_rec->switch_name[3] =
1620 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1621 fcf_rec->switch_name[4] =
1622 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1623 fcf_rec->switch_name[5] =
1624 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1625 fcf_rec->switch_name[6] =
1626 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1627 fcf_rec->switch_name[7] =
1628 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1632 * __lpfc_update_fcf_record - Update driver fcf record
1633 * @phba: pointer to lpfc hba data structure.
1634 * @fcf_rec: pointer to driver fcf record.
1635 * @new_fcf_record: pointer to hba fcf record.
1636 * @addr_mode: address mode to be set to the driver fcf record.
1637 * @vlan_id: vlan tag to be set to the driver fcf record.
1638 * @flag: flag bits to be set to the driver fcf record.
1640 * This routine updates the driver FCF record from the new HBA FCF record
1641 * together with the address mode, vlan_id, and other informations. This
1642 * routine is called with the hbalock held.
1645 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1646 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1647 uint16_t vlan_id, uint32_t flag)
1649 lockdep_assert_held(&phba->hbalock);
1651 /* Copy the fields from the HBA's FCF record */
1652 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1653 /* Update other fields of driver FCF record */
1654 fcf_rec->addr_mode = addr_mode;
1655 fcf_rec->vlan_id = vlan_id;
1656 fcf_rec->flag |= (flag | RECORD_VALID);
1657 __lpfc_update_fcf_record_pri(phba,
1658 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1663 * lpfc_register_fcf - Register the FCF with hba.
1664 * @phba: pointer to lpfc hba data structure.
1666 * This routine issues a register fcfi mailbox command to register
1670 lpfc_register_fcf(struct lpfc_hba *phba)
1672 LPFC_MBOXQ_t *fcf_mbxq;
1675 spin_lock_irq(&phba->hbalock);
1676 /* If the FCF is not available do nothing. */
1677 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1678 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1679 spin_unlock_irq(&phba->hbalock);
1683 /* The FCF is already registered, start discovery */
1684 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1685 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1686 phba->hba_flag &= ~FCF_TS_INPROG;
1687 if (phba->pport->port_state != LPFC_FLOGI &&
1688 phba->pport->fc_flag & FC_FABRIC) {
1689 phba->hba_flag |= FCF_RR_INPROG;
1690 spin_unlock_irq(&phba->hbalock);
1691 lpfc_initial_flogi(phba->pport);
1694 spin_unlock_irq(&phba->hbalock);
1697 spin_unlock_irq(&phba->hbalock);
1699 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1701 spin_lock_irq(&phba->hbalock);
1702 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1703 spin_unlock_irq(&phba->hbalock);
1707 lpfc_reg_fcfi(phba, fcf_mbxq);
1708 fcf_mbxq->vport = phba->pport;
1709 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1710 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1711 if (rc == MBX_NOT_FINISHED) {
1712 spin_lock_irq(&phba->hbalock);
1713 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1714 spin_unlock_irq(&phba->hbalock);
1715 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1722 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1723 * @phba: pointer to lpfc hba data structure.
1724 * @new_fcf_record: pointer to fcf record.
1725 * @boot_flag: Indicates if this record used by boot bios.
1726 * @addr_mode: The address mode to be used by this FCF
1727 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1729 * This routine compare the fcf record with connect list obtained from the
1730 * config region to decide if this FCF can be used for SAN discovery. It returns
1731 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1732 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1733 * is used by boot bios and addr_mode will indicate the addressing mode to be
1734 * used for this FCF when the function returns.
1735 * If the FCF record need to be used with a particular vlan id, the vlan is
1736 * set in the vlan_id on return of the function. If not VLAN tagging need to
1737 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1740 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1741 struct fcf_record *new_fcf_record,
1742 uint32_t *boot_flag, uint32_t *addr_mode,
1745 struct lpfc_fcf_conn_entry *conn_entry;
1746 int i, j, fcf_vlan_id = 0;
1748 /* Find the lowest VLAN id in the FCF record */
1749 for (i = 0; i < 512; i++) {
1750 if (new_fcf_record->vlan_bitmap[i]) {
1751 fcf_vlan_id = i * 8;
1753 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1761 /* FCF not valid/available or solicitation in progress */
1762 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1763 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1764 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1767 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1769 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1771 if (phba->valid_vlan)
1772 *vlan_id = phba->vlan_id;
1774 *vlan_id = LPFC_FCOE_NULL_VID;
1779 * If there are no FCF connection table entry, driver connect to all
1782 if (list_empty(&phba->fcf_conn_rec_list)) {
1784 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1788 * When there are no FCF connect entries, use driver's default
1789 * addressing mode - FPMA.
1791 if (*addr_mode & LPFC_FCF_FPMA)
1792 *addr_mode = LPFC_FCF_FPMA;
1794 /* If FCF record report a vlan id use that vlan id */
1796 *vlan_id = fcf_vlan_id;
1798 *vlan_id = LPFC_FCOE_NULL_VID;
1802 list_for_each_entry(conn_entry,
1803 &phba->fcf_conn_rec_list, list) {
1804 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1807 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1808 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1811 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1812 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1815 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1817 * If the vlan bit map does not have the bit set for the
1818 * vlan id to be used, then it is not a match.
1820 if (!(new_fcf_record->vlan_bitmap
1821 [conn_entry->conn_rec.vlan_tag / 8] &
1822 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1827 * If connection record does not support any addressing mode,
1828 * skip the FCF record.
1830 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1831 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1835 * Check if the connection record specifies a required
1838 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1839 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1842 * If SPMA required but FCF not support this continue.
1844 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1845 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1846 new_fcf_record) & LPFC_FCF_SPMA))
1850 * If FPMA required but FCF not support this continue.
1852 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1853 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1854 new_fcf_record) & LPFC_FCF_FPMA))
1859 * This fcf record matches filtering criteria.
1861 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1867 * If user did not specify any addressing mode, or if the
1868 * preferred addressing mode specified by user is not supported
1869 * by FCF, allow fabric to pick the addressing mode.
1871 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1874 * If the user specified a required address mode, assign that
1877 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1878 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1879 *addr_mode = (conn_entry->conn_rec.flags &
1881 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1883 * If the user specified a preferred address mode, use the
1884 * addr mode only if FCF support the addr_mode.
1886 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1887 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1888 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1889 (*addr_mode & LPFC_FCF_SPMA))
1890 *addr_mode = LPFC_FCF_SPMA;
1891 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1892 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1893 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1894 (*addr_mode & LPFC_FCF_FPMA))
1895 *addr_mode = LPFC_FCF_FPMA;
1897 /* If matching connect list has a vlan id, use it */
1898 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1899 *vlan_id = conn_entry->conn_rec.vlan_tag;
1901 * If no vlan id is specified in connect list, use the vlan id
1904 else if (fcf_vlan_id)
1905 *vlan_id = fcf_vlan_id;
1907 *vlan_id = LPFC_FCOE_NULL_VID;
1916 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1917 * @phba: pointer to lpfc hba data structure.
1918 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1920 * This function check if there is any fcoe event pending while driver
1921 * scan FCF entries. If there is any pending event, it will restart the
1922 * FCF saning and return 1 else return 0.
1925 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1928 * If the Link is up and no FCoE events while in the
1929 * FCF discovery, no need to restart FCF discovery.
1931 if ((phba->link_state >= LPFC_LINK_UP) &&
1932 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1935 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1936 "2768 Pending link or FCF event during current "
1937 "handling of the previous event: link_state:x%x, "
1938 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1939 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1940 phba->fcoe_eventtag);
1942 spin_lock_irq(&phba->hbalock);
1943 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1944 spin_unlock_irq(&phba->hbalock);
1946 if (phba->link_state >= LPFC_LINK_UP) {
1947 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1948 "2780 Restart FCF table scan due to "
1949 "pending FCF event:evt_tag_at_scan:x%x, "
1950 "evt_tag_current:x%x\n",
1951 phba->fcoe_eventtag_at_fcf_scan,
1952 phba->fcoe_eventtag);
1953 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1956 * Do not continue FCF discovery and clear FCF_TS_INPROG
1959 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1960 "2833 Stop FCF discovery process due to link "
1961 "state change (x%x)\n", phba->link_state);
1962 spin_lock_irq(&phba->hbalock);
1963 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1964 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1965 spin_unlock_irq(&phba->hbalock);
1968 /* Unregister the currently registered FCF if required */
1970 spin_lock_irq(&phba->hbalock);
1971 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1972 spin_unlock_irq(&phba->hbalock);
1973 lpfc_sli4_unregister_fcf(phba);
1979 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1980 * @phba: pointer to lpfc hba data structure.
1981 * @fcf_cnt: number of eligible fcf record seen so far.
1983 * This function makes an running random selection decision on FCF record to
1984 * use through a sequence of @fcf_cnt eligible FCF records with equal
1985 * probability. To perform integer manunipulation of random numbers with
1986 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1987 * from prandom_u32() are taken as the random random number generated.
1989 * Returns true when outcome is for the newly read FCF record should be
1990 * chosen; otherwise, return false when outcome is for keeping the previously
1991 * chosen FCF record.
1994 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1998 /* Get 16-bit uniform random number */
1999 rand_num = 0xFFFF & prandom_u32();
2001 /* Decision with probability 1/fcf_cnt */
2002 if ((fcf_cnt * rand_num) < 0xFFFF)
2009 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2010 * @phba: pointer to lpfc hba data structure.
2011 * @mboxq: pointer to mailbox object.
2012 * @next_fcf_index: pointer to holder of next fcf index.
2014 * This routine parses the non-embedded fcf mailbox command by performing the
2015 * necessarily error checking, non-embedded read FCF record mailbox command
2016 * SGE parsing, and endianness swapping.
2018 * Returns the pointer to the new FCF record in the non-embedded mailbox
2019 * command DMA memory if successfully, other NULL.
2021 static struct fcf_record *
2022 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2023 uint16_t *next_fcf_index)
2026 struct lpfc_mbx_sge sge;
2027 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2028 uint32_t shdr_status, shdr_add_status, if_type;
2029 union lpfc_sli4_cfg_shdr *shdr;
2030 struct fcf_record *new_fcf_record;
2032 /* Get the first SGE entry from the non-embedded DMA memory. This
2033 * routine only uses a single SGE.
2035 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2036 if (unlikely(!mboxq->sge_array)) {
2037 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2038 "2524 Failed to get the non-embedded SGE "
2039 "virtual address\n");
2042 virt_addr = mboxq->sge_array->addr[0];
2044 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2045 lpfc_sli_pcimem_bcopy(shdr, shdr,
2046 sizeof(union lpfc_sli4_cfg_shdr));
2047 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2048 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2049 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2050 if (shdr_status || shdr_add_status) {
2051 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2052 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2053 lpfc_printf_log(phba, KERN_ERR,
2055 "2726 READ_FCF_RECORD Indicates empty "
2058 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2059 "2521 READ_FCF_RECORD mailbox failed "
2060 "with status x%x add_status x%x, "
2061 "mbx\n", shdr_status, shdr_add_status);
2065 /* Interpreting the returned information of the FCF record */
2066 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2067 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2068 sizeof(struct lpfc_mbx_read_fcf_tbl));
2069 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2070 new_fcf_record = (struct fcf_record *)(virt_addr +
2071 sizeof(struct lpfc_mbx_read_fcf_tbl));
2072 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2073 offsetof(struct fcf_record, vlan_bitmap));
2074 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2075 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2077 return new_fcf_record;
2081 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2082 * @phba: pointer to lpfc hba data structure.
2083 * @fcf_record: pointer to the fcf record.
2084 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2085 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2087 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2091 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2092 struct fcf_record *fcf_record,
2094 uint16_t next_fcf_index)
2096 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2097 "2764 READ_FCF_RECORD:\n"
2098 "\tFCF_Index : x%x\n"
2099 "\tFCF_Avail : x%x\n"
2100 "\tFCF_Valid : x%x\n"
2102 "\tFIP_Priority : x%x\n"
2103 "\tMAC_Provider : x%x\n"
2104 "\tLowest VLANID : x%x\n"
2105 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2106 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2107 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2108 "\tNext_FCF_Index: x%x\n",
2109 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2110 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2111 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2112 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2113 fcf_record->fip_priority,
2114 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2116 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2117 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2118 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2119 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2120 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2121 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2122 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2123 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2124 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2125 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2126 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2127 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2128 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2129 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2130 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2131 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2132 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2133 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2134 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2135 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2136 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2137 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2142 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2143 * @phba: pointer to lpfc hba data structure.
2144 * @fcf_rec: pointer to an existing FCF record.
2145 * @new_fcf_record: pointer to a new FCF record.
2146 * @new_vlan_id: vlan id from the new FCF record.
2148 * This function performs matching test of a new FCF record against an existing
2149 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2150 * will not be used as part of the FCF record matching criteria.
2152 * Returns true if all the fields matching, otherwise returns false.
2155 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2156 struct lpfc_fcf_rec *fcf_rec,
2157 struct fcf_record *new_fcf_record,
2158 uint16_t new_vlan_id)
2160 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2161 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2163 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2165 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2167 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2169 if (fcf_rec->priority != new_fcf_record->fip_priority)
2175 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2176 * @vport: Pointer to vport object.
2177 * @fcf_index: index to next fcf.
2179 * This function processing the roundrobin fcf failover to next fcf index.
2180 * When this function is invoked, there will be a current fcf registered
2182 * Return: 0 for continue retrying flogi on currently registered fcf;
2183 * 1 for stop flogi on currently registered fcf;
2185 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2187 struct lpfc_hba *phba = vport->phba;
2190 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2191 spin_lock_irq(&phba->hbalock);
2192 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2193 spin_unlock_irq(&phba->hbalock);
2194 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2195 "2872 Devloss tmo with no eligible "
2196 "FCF, unregister in-use FCF (x%x) "
2197 "and rescan FCF table\n",
2198 phba->fcf.current_rec.fcf_indx);
2199 lpfc_unregister_fcf_rescan(phba);
2200 goto stop_flogi_current_fcf;
2202 /* Mark the end to FLOGI roundrobin failover */
2203 phba->hba_flag &= ~FCF_RR_INPROG;
2204 /* Allow action to new fcf asynchronous event */
2205 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2206 spin_unlock_irq(&phba->hbalock);
2207 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2208 "2865 No FCF available, stop roundrobin FCF "
2209 "failover and change port state:x%x/x%x\n",
2210 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2211 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2213 if (!phba->fcf.fcf_redisc_attempted) {
2214 lpfc_unregister_fcf(phba);
2216 rc = lpfc_sli4_redisc_fcf_table(phba);
2218 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2219 "3195 Rediscover FCF table\n");
2220 phba->fcf.fcf_redisc_attempted = 1;
2221 lpfc_sli4_clear_fcf_rr_bmask(phba);
2223 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2224 "3196 Rediscover FCF table "
2225 "failed. Status:x%x\n", rc);
2228 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2229 "3197 Already rediscover FCF table "
2230 "attempted. No more retry\n");
2232 goto stop_flogi_current_fcf;
2234 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2235 "2794 Try FLOGI roundrobin FCF failover to "
2236 "(x%x)\n", fcf_index);
2237 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2239 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2240 "2761 FLOGI roundrobin FCF failover "
2241 "failed (rc:x%x) to read FCF (x%x)\n",
2242 rc, phba->fcf.current_rec.fcf_indx);
2244 goto stop_flogi_current_fcf;
2248 stop_flogi_current_fcf:
2249 lpfc_can_disctmo(vport);
2254 * lpfc_sli4_fcf_pri_list_del
2255 * @phba: pointer to lpfc hba data structure.
2256 * @fcf_index: the index of the fcf record to delete
2257 * This routine checks the on list flag of the fcf_index to be deleted.
2258 * If it is one the list then it is removed from the list, and the flag
2259 * is cleared. This routine grab the hbalock before removing the fcf
2260 * record from the list.
2262 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2265 struct lpfc_fcf_pri *new_fcf_pri;
2267 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2268 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2269 "3058 deleting idx x%x pri x%x flg x%x\n",
2270 fcf_index, new_fcf_pri->fcf_rec.priority,
2271 new_fcf_pri->fcf_rec.flag);
2272 spin_lock_irq(&phba->hbalock);
2273 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2274 if (phba->fcf.current_rec.priority ==
2275 new_fcf_pri->fcf_rec.priority)
2276 phba->fcf.eligible_fcf_cnt--;
2277 list_del_init(&new_fcf_pri->list);
2278 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2280 spin_unlock_irq(&phba->hbalock);
2284 * lpfc_sli4_set_fcf_flogi_fail
2285 * @phba: pointer to lpfc hba data structure.
2286 * @fcf_index: the index of the fcf record to update
2287 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2288 * flag so the the round robin slection for the particular priority level
2289 * will try a different fcf record that does not have this bit set.
2290 * If the fcf record is re-read for any reason this flag is cleared brfore
2291 * adding it to the priority list.
2294 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2296 struct lpfc_fcf_pri *new_fcf_pri;
2297 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2298 spin_lock_irq(&phba->hbalock);
2299 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2300 spin_unlock_irq(&phba->hbalock);
2304 * lpfc_sli4_fcf_pri_list_add
2305 * @phba: pointer to lpfc hba data structure.
2306 * @fcf_index: the index of the fcf record to add
2307 * @new_fcf_record: pointer to a new FCF record.
2308 * This routine checks the priority of the fcf_index to be added.
2309 * If it is a lower priority than the current head of the fcf_pri list
2310 * then it is added to the list in the right order.
2311 * If it is the same priority as the current head of the list then it
2312 * is added to the head of the list and its bit in the rr_bmask is set.
2313 * If the fcf_index to be added is of a higher priority than the current
2314 * head of the list then the rr_bmask is cleared, its bit is set in the
2315 * rr_bmask and it is added to the head of the list.
2317 * 0=success 1=failure
2319 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2321 struct fcf_record *new_fcf_record)
2323 uint16_t current_fcf_pri;
2324 uint16_t last_index;
2325 struct lpfc_fcf_pri *fcf_pri;
2326 struct lpfc_fcf_pri *next_fcf_pri;
2327 struct lpfc_fcf_pri *new_fcf_pri;
2330 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2331 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2332 "3059 adding idx x%x pri x%x flg x%x\n",
2333 fcf_index, new_fcf_record->fip_priority,
2334 new_fcf_pri->fcf_rec.flag);
2335 spin_lock_irq(&phba->hbalock);
2336 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2337 list_del_init(&new_fcf_pri->list);
2338 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2339 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2340 if (list_empty(&phba->fcf.fcf_pri_list)) {
2341 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2342 ret = lpfc_sli4_fcf_rr_index_set(phba,
2343 new_fcf_pri->fcf_rec.fcf_index);
2347 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2348 LPFC_SLI4_FCF_TBL_INDX_MAX);
2349 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2350 ret = 0; /* Empty rr list */
2353 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2354 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2355 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2356 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2357 memset(phba->fcf.fcf_rr_bmask, 0,
2358 sizeof(*phba->fcf.fcf_rr_bmask));
2359 /* fcfs_at_this_priority_level = 1; */
2360 phba->fcf.eligible_fcf_cnt = 1;
2362 /* fcfs_at_this_priority_level++; */
2363 phba->fcf.eligible_fcf_cnt++;
2364 ret = lpfc_sli4_fcf_rr_index_set(phba,
2365 new_fcf_pri->fcf_rec.fcf_index);
2369 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2370 &phba->fcf.fcf_pri_list, list) {
2371 if (new_fcf_pri->fcf_rec.priority <=
2372 fcf_pri->fcf_rec.priority) {
2373 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2374 list_add(&new_fcf_pri->list,
2375 &phba->fcf.fcf_pri_list);
2377 list_add(&new_fcf_pri->list,
2378 &((struct lpfc_fcf_pri *)
2379 fcf_pri->list.prev)->list);
2382 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2383 || new_fcf_pri->fcf_rec.priority <
2384 next_fcf_pri->fcf_rec.priority) {
2385 list_add(&new_fcf_pri->list, &fcf_pri->list);
2389 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2395 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2396 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2397 spin_unlock_irq(&phba->hbalock);
2402 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2403 * @phba: pointer to lpfc hba data structure.
2404 * @mboxq: pointer to mailbox object.
2406 * This function iterates through all the fcf records available in
2407 * HBA and chooses the optimal FCF record for discovery. After finding
2408 * the FCF for discovery it registers the FCF record and kicks start
2410 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2411 * use an FCF record which matches fabric name and mac address of the
2412 * currently used FCF record.
2413 * If the driver supports only one FCF, it will try to use the FCF record
2414 * used by BOOT_BIOS.
2417 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2419 struct fcf_record *new_fcf_record;
2420 uint32_t boot_flag, addr_mode;
2421 uint16_t fcf_index, next_fcf_index;
2422 struct lpfc_fcf_rec *fcf_rec = NULL;
2423 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2424 bool select_new_fcf;
2427 /* If there is pending FCoE event restart FCF table scan */
2428 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2429 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2433 /* Parse the FCF record from the non-embedded mailbox command */
2434 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2436 if (!new_fcf_record) {
2437 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2438 "2765 Mailbox command READ_FCF_RECORD "
2439 "failed to retrieve a FCF record.\n");
2440 /* Let next new FCF event trigger fast failover */
2441 spin_lock_irq(&phba->hbalock);
2442 phba->hba_flag &= ~FCF_TS_INPROG;
2443 spin_unlock_irq(&phba->hbalock);
2444 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2448 /* Check the FCF record against the connection list */
2449 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2450 &addr_mode, &vlan_id);
2452 /* Log the FCF record information if turned on */
2453 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2457 * If the fcf record does not match with connect list entries
2458 * read the next entry; otherwise, this is an eligible FCF
2459 * record for roundrobin FCF failover.
2462 lpfc_sli4_fcf_pri_list_del(phba,
2463 bf_get(lpfc_fcf_record_fcf_index,
2465 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2466 "2781 FCF (x%x) failed connection "
2467 "list check: (x%x/x%x/%x)\n",
2468 bf_get(lpfc_fcf_record_fcf_index,
2470 bf_get(lpfc_fcf_record_fcf_avail,
2472 bf_get(lpfc_fcf_record_fcf_valid,
2474 bf_get(lpfc_fcf_record_fcf_sol,
2476 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2477 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2478 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2479 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2480 phba->fcf.current_rec.fcf_indx) {
2481 lpfc_printf_log(phba, KERN_ERR,
2483 "2862 FCF (x%x) matches property "
2484 "of in-use FCF (x%x)\n",
2485 bf_get(lpfc_fcf_record_fcf_index,
2487 phba->fcf.current_rec.fcf_indx);
2491 * In case the current in-use FCF record becomes
2492 * invalid/unavailable during FCF discovery that
2493 * was not triggered by fast FCF failover process,
2494 * treat it as fast FCF failover.
2496 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2497 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2498 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2499 "2835 Invalid in-use FCF "
2500 "(x%x), enter FCF failover "
2502 phba->fcf.current_rec.fcf_indx);
2503 spin_lock_irq(&phba->hbalock);
2504 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2505 spin_unlock_irq(&phba->hbalock);
2506 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2507 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2508 LPFC_FCOE_FCF_GET_FIRST);
2514 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2515 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2522 * If this is not the first FCF discovery of the HBA, use last
2523 * FCF record for the discovery. The condition that a rescan
2524 * matches the in-use FCF record: fabric name, switch name, mac
2525 * address, and vlan_id.
2527 spin_lock_irq(&phba->hbalock);
2528 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2529 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2530 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2531 new_fcf_record, vlan_id)) {
2532 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2533 phba->fcf.current_rec.fcf_indx) {
2534 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2535 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2536 /* Stop FCF redisc wait timer */
2537 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2539 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2540 /* Fast failover, mark completed */
2541 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2542 spin_unlock_irq(&phba->hbalock);
2543 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2544 "2836 New FCF matches in-use "
2545 "FCF (x%x), port_state:x%x, "
2547 phba->fcf.current_rec.fcf_indx,
2548 phba->pport->port_state,
2549 phba->pport->fc_flag);
2552 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2553 "2863 New FCF (x%x) matches "
2554 "property of in-use FCF (x%x)\n",
2555 bf_get(lpfc_fcf_record_fcf_index,
2557 phba->fcf.current_rec.fcf_indx);
2560 * Read next FCF record from HBA searching for the matching
2561 * with in-use record only if not during the fast failover
2562 * period. In case of fast failover period, it shall try to
2563 * determine whether the FCF record just read should be the
2566 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2567 spin_unlock_irq(&phba->hbalock);
2572 * Update on failover FCF record only if it's in FCF fast-failover
2573 * period; otherwise, update on current FCF record.
2575 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2576 fcf_rec = &phba->fcf.failover_rec;
2578 fcf_rec = &phba->fcf.current_rec;
2580 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2582 * If the driver FCF record does not have boot flag
2583 * set and new hba fcf record has boot flag set, use
2584 * the new hba fcf record.
2586 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2587 /* Choose this FCF record */
2588 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2589 "2837 Update current FCF record "
2590 "(x%x) with new FCF record (x%x)\n",
2592 bf_get(lpfc_fcf_record_fcf_index,
2594 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2595 addr_mode, vlan_id, BOOT_ENABLE);
2596 spin_unlock_irq(&phba->hbalock);
2600 * If the driver FCF record has boot flag set and the
2601 * new hba FCF record does not have boot flag, read
2602 * the next FCF record.
2604 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2605 spin_unlock_irq(&phba->hbalock);
2609 * If the new hba FCF record has lower priority value
2610 * than the driver FCF record, use the new record.
2612 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2613 /* Choose the new FCF record with lower priority */
2614 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2615 "2838 Update current FCF record "
2616 "(x%x) with new FCF record (x%x)\n",
2618 bf_get(lpfc_fcf_record_fcf_index,
2620 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2621 addr_mode, vlan_id, 0);
2622 /* Reset running random FCF selection count */
2623 phba->fcf.eligible_fcf_cnt = 1;
2624 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2625 /* Update running random FCF selection count */
2626 phba->fcf.eligible_fcf_cnt++;
2627 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2628 phba->fcf.eligible_fcf_cnt);
2629 if (select_new_fcf) {
2630 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2631 "2839 Update current FCF record "
2632 "(x%x) with new FCF record (x%x)\n",
2634 bf_get(lpfc_fcf_record_fcf_index,
2636 /* Choose the new FCF by random selection */
2637 __lpfc_update_fcf_record(phba, fcf_rec,
2639 addr_mode, vlan_id, 0);
2642 spin_unlock_irq(&phba->hbalock);
2646 * This is the first suitable FCF record, choose this record for
2647 * initial best-fit FCF.
2650 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2651 "2840 Update initial FCF candidate "
2653 bf_get(lpfc_fcf_record_fcf_index,
2655 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2656 addr_mode, vlan_id, (boot_flag ?
2658 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2659 /* Setup initial running random FCF selection count */
2660 phba->fcf.eligible_fcf_cnt = 1;
2662 spin_unlock_irq(&phba->hbalock);
2666 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2667 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2668 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2670 * Case of FCF fast failover scan
2674 * It has not found any suitable FCF record, cancel
2675 * FCF scan inprogress, and do nothing
2677 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2678 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2679 "2782 No suitable FCF found: "
2681 phba->fcoe_eventtag_at_fcf_scan,
2682 bf_get(lpfc_fcf_record_fcf_index,
2684 spin_lock_irq(&phba->hbalock);
2685 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2686 phba->hba_flag &= ~FCF_TS_INPROG;
2687 spin_unlock_irq(&phba->hbalock);
2688 /* Unregister in-use FCF and rescan */
2689 lpfc_printf_log(phba, KERN_INFO,
2691 "2864 On devloss tmo "
2692 "unreg in-use FCF and "
2693 "rescan FCF table\n");
2694 lpfc_unregister_fcf_rescan(phba);
2698 * Let next new FCF event trigger fast failover
2700 phba->hba_flag &= ~FCF_TS_INPROG;
2701 spin_unlock_irq(&phba->hbalock);
2705 * It has found a suitable FCF record that is not
2706 * the same as in-use FCF record, unregister the
2707 * in-use FCF record, replace the in-use FCF record
2708 * with the new FCF record, mark FCF fast failover
2709 * completed, and then start register the new FCF
2713 /* Unregister the current in-use FCF record */
2714 lpfc_unregister_fcf(phba);
2716 /* Replace in-use record with the new record */
2717 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2718 "2842 Replace in-use FCF (x%x) "
2719 "with failover FCF (x%x)\n",
2720 phba->fcf.current_rec.fcf_indx,
2721 phba->fcf.failover_rec.fcf_indx);
2722 memcpy(&phba->fcf.current_rec,
2723 &phba->fcf.failover_rec,
2724 sizeof(struct lpfc_fcf_rec));
2726 * Mark the fast FCF failover rediscovery completed
2727 * and the start of the first round of the roundrobin
2730 spin_lock_irq(&phba->hbalock);
2731 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2732 spin_unlock_irq(&phba->hbalock);
2733 /* Register to the new FCF record */
2734 lpfc_register_fcf(phba);
2737 * In case of transaction period to fast FCF failover,
2738 * do nothing when search to the end of the FCF table.
2740 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2741 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2744 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2745 phba->fcf.fcf_flag & FCF_IN_USE) {
2747 * In case the current in-use FCF record no
2748 * longer existed during FCF discovery that
2749 * was not triggered by fast FCF failover
2750 * process, treat it as fast FCF failover.
2752 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2753 "2841 In-use FCF record (x%x) "
2754 "not reported, entering fast "
2755 "FCF failover mode scanning.\n",
2756 phba->fcf.current_rec.fcf_indx);
2757 spin_lock_irq(&phba->hbalock);
2758 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2759 spin_unlock_irq(&phba->hbalock);
2760 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2761 LPFC_FCOE_FCF_GET_FIRST);
2764 /* Register to the new FCF record */
2765 lpfc_register_fcf(phba);
2768 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2772 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2773 lpfc_register_fcf(phba);
2779 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2780 * @phba: pointer to lpfc hba data structure.
2781 * @mboxq: pointer to mailbox object.
2783 * This is the callback function for FLOGI failure roundrobin FCF failover
2784 * read FCF record mailbox command from the eligible FCF record bmask for
2785 * performing the failover. If the FCF read back is not valid/available, it
2786 * fails through to retrying FLOGI to the currently registered FCF again.
2787 * Otherwise, if the FCF read back is valid and available, it will set the
2788 * newly read FCF record to the failover FCF record, unregister currently
2789 * registered FCF record, copy the failover FCF record to the current
2790 * FCF record, and then register the current FCF record before proceeding
2791 * to trying FLOGI on the new failover FCF.
2794 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2796 struct fcf_record *new_fcf_record;
2797 uint32_t boot_flag, addr_mode;
2798 uint16_t next_fcf_index, fcf_index;
2799 uint16_t current_fcf_index;
2803 /* If link state is not up, stop the roundrobin failover process */
2804 if (phba->link_state < LPFC_LINK_UP) {
2805 spin_lock_irq(&phba->hbalock);
2806 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2807 phba->hba_flag &= ~FCF_RR_INPROG;
2808 spin_unlock_irq(&phba->hbalock);
2812 /* Parse the FCF record from the non-embedded mailbox command */
2813 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2815 if (!new_fcf_record) {
2816 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2817 "2766 Mailbox command READ_FCF_RECORD "
2818 "failed to retrieve a FCF record. "
2819 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2820 phba->fcf.fcf_flag);
2821 lpfc_unregister_fcf_rescan(phba);
2825 /* Get the needed parameters from FCF record */
2826 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2827 &addr_mode, &vlan_id);
2829 /* Log the FCF record information if turned on */
2830 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2833 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2835 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2836 "2848 Remove ineligible FCF (x%x) from "
2837 "from roundrobin bmask\n", fcf_index);
2838 /* Clear roundrobin bmask bit for ineligible FCF */
2839 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2840 /* Perform next round of roundrobin FCF failover */
2841 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2842 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2848 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2849 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2850 "2760 Perform FLOGI roundrobin FCF failover: "
2851 "FCF (x%x) back to FCF (x%x)\n",
2852 phba->fcf.current_rec.fcf_indx, fcf_index);
2853 /* Wait 500 ms before retrying FLOGI to current FCF */
2855 lpfc_issue_init_vfi(phba->pport);
2859 /* Upload new FCF record to the failover FCF record */
2860 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2861 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2862 phba->fcf.failover_rec.fcf_indx, fcf_index);
2863 spin_lock_irq(&phba->hbalock);
2864 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2865 new_fcf_record, addr_mode, vlan_id,
2866 (boot_flag ? BOOT_ENABLE : 0));
2867 spin_unlock_irq(&phba->hbalock);
2869 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2871 /* Unregister the current in-use FCF record */
2872 lpfc_unregister_fcf(phba);
2874 /* Replace in-use record with the new record */
2875 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2876 sizeof(struct lpfc_fcf_rec));
2878 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2879 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2880 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2883 lpfc_register_fcf(phba);
2885 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2889 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2890 * @phba: pointer to lpfc hba data structure.
2891 * @mboxq: pointer to mailbox object.
2893 * This is the callback function of read FCF record mailbox command for
2894 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2895 * failover when a new FCF event happened. If the FCF read back is
2896 * valid/available and it passes the connection list check, it updates
2897 * the bmask for the eligible FCF record for roundrobin failover.
2900 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2902 struct fcf_record *new_fcf_record;
2903 uint32_t boot_flag, addr_mode;
2904 uint16_t fcf_index, next_fcf_index;
2908 /* If link state is not up, no need to proceed */
2909 if (phba->link_state < LPFC_LINK_UP)
2912 /* If FCF discovery period is over, no need to proceed */
2913 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2916 /* Parse the FCF record from the non-embedded mailbox command */
2917 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2919 if (!new_fcf_record) {
2920 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2921 "2767 Mailbox command READ_FCF_RECORD "
2922 "failed to retrieve a FCF record.\n");
2926 /* Check the connection list for eligibility */
2927 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2928 &addr_mode, &vlan_id);
2930 /* Log the FCF record information if turned on */
2931 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2937 /* Update the eligible FCF record index bmask */
2938 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2940 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2943 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2947 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2948 * @phba: pointer to lpfc hba data structure.
2949 * @mboxq: pointer to mailbox data structure.
2951 * This function handles completion of init vfi mailbox command.
2954 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2956 struct lpfc_vport *vport = mboxq->vport;
2959 * VFI not supported on interface type 0, just do the flogi
2960 * Also continue if the VFI is in use - just use the same one.
2962 if (mboxq->u.mb.mbxStatus &&
2963 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2964 LPFC_SLI_INTF_IF_TYPE_0) &&
2965 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2966 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2967 "2891 Init VFI mailbox failed 0x%x\n",
2968 mboxq->u.mb.mbxStatus);
2969 mempool_free(mboxq, phba->mbox_mem_pool);
2970 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2974 lpfc_initial_flogi(vport);
2975 mempool_free(mboxq, phba->mbox_mem_pool);
2980 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2981 * @vport: pointer to lpfc_vport data structure.
2983 * This function issue a init_vfi mailbox command to initialize the VFI and
2984 * VPI for the physical port.
2987 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2989 LPFC_MBOXQ_t *mboxq;
2991 struct lpfc_hba *phba = vport->phba;
2993 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2995 lpfc_printf_vlog(vport, KERN_ERR,
2996 LOG_TRACE_EVENT, "2892 Failed to allocate "
2997 "init_vfi mailbox\n");
3000 lpfc_init_vfi(mboxq, vport);
3001 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3002 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3003 if (rc == MBX_NOT_FINISHED) {
3004 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3005 "2893 Failed to issue init_vfi mailbox\n");
3006 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3011 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3012 * @phba: pointer to lpfc hba data structure.
3013 * @mboxq: pointer to mailbox data structure.
3015 * This function handles completion of init vpi mailbox command.
3018 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3020 struct lpfc_vport *vport = mboxq->vport;
3021 struct lpfc_nodelist *ndlp;
3022 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3024 if (mboxq->u.mb.mbxStatus) {
3025 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3026 "2609 Init VPI mailbox failed 0x%x\n",
3027 mboxq->u.mb.mbxStatus);
3028 mempool_free(mboxq, phba->mbox_mem_pool);
3029 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3032 spin_lock_irq(shost->host_lock);
3033 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3034 spin_unlock_irq(shost->host_lock);
3036 /* If this port is physical port or FDISC is done, do reg_vpi */
3037 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3038 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3040 lpfc_printf_vlog(vport, KERN_ERR,
3042 "2731 Cannot find fabric "
3043 "controller node\n");
3045 lpfc_register_new_vport(phba, vport, ndlp);
3046 mempool_free(mboxq, phba->mbox_mem_pool);
3050 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3051 lpfc_initial_fdisc(vport);
3053 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3054 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3055 "2606 No NPIV Fabric support\n");
3057 mempool_free(mboxq, phba->mbox_mem_pool);
3062 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3063 * @vport: pointer to lpfc_vport data structure.
3065 * This function issue a init_vpi mailbox command to initialize
3066 * VPI for the vport.
3069 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3071 LPFC_MBOXQ_t *mboxq;
3074 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3075 vpi = lpfc_alloc_vpi(vport->phba);
3077 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3078 "3303 Failed to obtain vport vpi\n");
3079 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3085 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3087 lpfc_printf_vlog(vport, KERN_ERR,
3088 LOG_TRACE_EVENT, "2607 Failed to allocate "
3089 "init_vpi mailbox\n");
3092 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3093 mboxq->vport = vport;
3094 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3095 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3096 if (rc == MBX_NOT_FINISHED) {
3097 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3098 "2608 Failed to issue init_vpi mailbox\n");
3099 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3104 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3105 * @phba: pointer to lpfc hba data structure.
3107 * This function loops through the list of vports on the @phba and issues an
3108 * FDISC if possible.
3111 lpfc_start_fdiscs(struct lpfc_hba *phba)
3113 struct lpfc_vport **vports;
3116 vports = lpfc_create_vport_work_array(phba);
3117 if (vports != NULL) {
3118 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3119 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3121 /* There are no vpi for this vport */
3122 if (vports[i]->vpi > phba->max_vpi) {
3123 lpfc_vport_set_state(vports[i],
3127 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3128 lpfc_vport_set_state(vports[i],
3132 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3133 lpfc_issue_init_vpi(vports[i]);
3136 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3137 lpfc_initial_fdisc(vports[i]);
3139 lpfc_vport_set_state(vports[i],
3140 FC_VPORT_NO_FABRIC_SUPP);
3141 lpfc_printf_vlog(vports[i], KERN_ERR,
3144 "Fabric support\n");
3148 lpfc_destroy_vport_work_array(phba, vports);
3152 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3154 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
3155 struct lpfc_vport *vport = mboxq->vport;
3156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3159 * VFI not supported for interface type 0, so ignore any mailbox
3160 * error (except VFI in use) and continue with the discovery.
3162 if (mboxq->u.mb.mbxStatus &&
3163 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3164 LPFC_SLI_INTF_IF_TYPE_0) &&
3165 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3166 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3167 "2018 REG_VFI mbxStatus error x%x "
3169 mboxq->u.mb.mbxStatus, vport->port_state);
3170 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3171 /* FLOGI failed, use loop map to make discovery list */
3172 lpfc_disc_list_loopmap(vport);
3173 /* Start discovery */
3174 lpfc_disc_start(vport);
3177 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3181 /* If the VFI is already registered, there is nothing else to do
3182 * Unless this was a VFI update and we are in PT2PT mode, then
3183 * we should drop through to set the port state to ready.
3185 if (vport->fc_flag & FC_VFI_REGISTERED)
3186 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3187 vport->fc_flag & FC_PT2PT))
3190 /* The VPI is implicitly registered when the VFI is registered */
3191 spin_lock_irq(shost->host_lock);
3192 vport->vpi_state |= LPFC_VPI_REGISTERED;
3193 vport->fc_flag |= FC_VFI_REGISTERED;
3194 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3195 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3196 spin_unlock_irq(shost->host_lock);
3198 /* In case SLI4 FC loopback test, we are ready */
3199 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3200 (phba->link_flag & LS_LOOPBACK_MODE)) {
3201 phba->link_state = LPFC_HBA_READY;
3205 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3206 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3207 "alpacnt:%d LinkState:%x topology:%x\n",
3208 vport->port_state, vport->fc_flag, vport->fc_myDID,
3209 vport->phba->alpa_map[0],
3210 phba->link_state, phba->fc_topology);
3212 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3214 * For private loop or for NPort pt2pt,
3215 * just start discovery and we are done.
3217 if ((vport->fc_flag & FC_PT2PT) ||
3218 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3219 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3221 /* Use loop map to make discovery list */
3222 lpfc_disc_list_loopmap(vport);
3223 /* Start discovery */
3224 if (vport->fc_flag & FC_PT2PT)
3225 vport->port_state = LPFC_VPORT_READY;
3227 lpfc_disc_start(vport);
3229 lpfc_start_fdiscs(phba);
3230 lpfc_do_scr_ns_plogi(phba, vport);
3235 mempool_free(mboxq, phba->mbox_mem_pool);
3237 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3244 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3246 MAILBOX_t *mb = &pmb->u.mb;
3247 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3248 struct lpfc_vport *vport = pmb->vport;
3249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3250 struct serv_parm *sp = &vport->fc_sparam;
3253 /* Check for error */
3254 if (mb->mbxStatus) {
3255 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3256 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3257 "0319 READ_SPARAM mbxStatus error x%x "
3259 mb->mbxStatus, vport->port_state);
3260 lpfc_linkdown(phba);
3264 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3265 sizeof (struct serv_parm));
3267 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3268 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3269 ed_tov = (ed_tov + 999999) / 1000000;
3271 phba->fc_edtov = ed_tov;
3272 phba->fc_ratov = (2 * ed_tov) / 1000;
3273 if (phba->fc_ratov < FF_DEF_RATOV) {
3274 /* RA_TOV should be atleast 10sec for initial flogi */
3275 phba->fc_ratov = FF_DEF_RATOV;
3278 lpfc_update_vport_wwn(vport);
3279 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3280 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3281 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3282 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3285 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3287 mempool_free(pmb, phba->mbox_mem_pool);
3289 /* Check if sending the FLOGI is being deferred to after we get
3290 * up to date CSPs from MBX_READ_SPARAM.
3292 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3293 lpfc_initial_flogi(vport);
3294 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3299 pmb->ctx_buf = NULL;
3300 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3302 lpfc_issue_clear_la(phba, vport);
3303 mempool_free(pmb, phba->mbox_mem_pool);
3308 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3310 struct lpfc_vport *vport = phba->pport;
3311 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3312 struct Scsi_Host *shost;
3314 struct lpfc_dmabuf *mp;
3316 struct fcf_record *fcf_record;
3317 uint32_t fc_flags = 0;
3318 unsigned long iflags;
3320 spin_lock_irqsave(&phba->hbalock, iflags);
3321 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3323 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3324 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3325 case LPFC_LINK_SPEED_1GHZ:
3326 case LPFC_LINK_SPEED_2GHZ:
3327 case LPFC_LINK_SPEED_4GHZ:
3328 case LPFC_LINK_SPEED_8GHZ:
3329 case LPFC_LINK_SPEED_10GHZ:
3330 case LPFC_LINK_SPEED_16GHZ:
3331 case LPFC_LINK_SPEED_32GHZ:
3332 case LPFC_LINK_SPEED_64GHZ:
3333 case LPFC_LINK_SPEED_128GHZ:
3334 case LPFC_LINK_SPEED_256GHZ:
3337 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3342 if (phba->fc_topology &&
3343 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3344 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3345 "3314 Toplogy changed was 0x%x is 0x%x\n",
3347 bf_get(lpfc_mbx_read_top_topology, la));
3348 phba->fc_topology_changed = 1;
3351 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3352 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3354 shost = lpfc_shost_from_vport(vport);
3355 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3356 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3358 /* if npiv is enabled and this adapter supports npiv log
3359 * a message that npiv is not supported in this topology
3361 if (phba->cfg_enable_npiv && phba->max_vpi)
3362 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3363 "1309 Link Up Event npiv not supported in loop "
3365 /* Get Loop Map information */
3366 if (bf_get(lpfc_mbx_read_top_il, la))
3367 fc_flags |= FC_LBIT;
3369 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3370 i = la->lilpBde64.tus.f.bdeSize;
3373 phba->alpa_map[0] = 0;
3375 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3386 numalpa = phba->alpa_map[0];
3388 while (j < numalpa) {
3389 memset(un.pamap, 0, 16);
3390 for (k = 1; j < numalpa; k++) {
3392 phba->alpa_map[j + 1];
3397 /* Link Up Event ALPA map */
3398 lpfc_printf_log(phba,
3401 "1304 Link Up Event "
3402 "ALPA map Data: x%x "
3404 un.pa.wd1, un.pa.wd2,
3405 un.pa.wd3, un.pa.wd4);
3410 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3411 if (phba->max_vpi && phba->cfg_enable_npiv &&
3412 (phba->sli_rev >= LPFC_SLI_REV3))
3413 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3415 vport->fc_myDID = phba->fc_pref_DID;
3416 fc_flags |= FC_LBIT;
3418 spin_unlock_irqrestore(&phba->hbalock, iflags);
3421 spin_lock_irqsave(shost->host_lock, iflags);
3422 vport->fc_flag |= fc_flags;
3423 spin_unlock_irqrestore(shost->host_lock, iflags);
3429 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3433 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3435 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3438 sparam_mbox->vport = vport;
3439 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3440 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3441 if (rc == MBX_NOT_FINISHED) {
3442 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3445 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3449 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3450 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3453 vport->port_state = LPFC_LOCAL_CFG_LINK;
3454 lpfc_config_link(phba, cfglink_mbox);
3455 cfglink_mbox->vport = vport;
3456 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3457 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3458 if (rc == MBX_NOT_FINISHED) {
3459 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3463 vport->port_state = LPFC_VPORT_UNKNOWN;
3465 * Add the driver's default FCF record at FCF index 0 now. This
3466 * is phase 1 implementation that support FCF index 0 and driver
3469 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3470 fcf_record = kzalloc(sizeof(struct fcf_record),
3472 if (unlikely(!fcf_record)) {
3473 lpfc_printf_log(phba, KERN_ERR,
3475 "2554 Could not allocate memory for "
3481 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3482 LPFC_FCOE_FCF_DEF_INDEX);
3483 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3485 lpfc_printf_log(phba, KERN_ERR,
3487 "2013 Could not manually add FCF "
3488 "record 0, status %d\n", rc);
3496 * The driver is expected to do FIP/FCF. Call the port
3497 * and get the FCF Table.
3499 spin_lock_irqsave(&phba->hbalock, iflags);
3500 if (phba->hba_flag & FCF_TS_INPROG) {
3501 spin_unlock_irqrestore(&phba->hbalock, iflags);
3504 /* This is the initial FCF discovery scan */
3505 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3506 spin_unlock_irqrestore(&phba->hbalock, iflags);
3507 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3508 "2778 Start FCF table scan at linkup\n");
3509 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3510 LPFC_FCOE_FCF_GET_FIRST);
3512 spin_lock_irqsave(&phba->hbalock, iflags);
3513 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3514 spin_unlock_irqrestore(&phba->hbalock, iflags);
3517 /* Reset FCF roundrobin bmask for new discovery */
3518 lpfc_sli4_clear_fcf_rr_bmask(phba);
3521 /* Prepare for LINK up registrations */
3522 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3523 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3524 init_utsname()->nodename);
3527 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3528 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3529 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3530 vport->port_state, sparam_mbox, cfglink_mbox);
3531 lpfc_issue_clear_la(phba, vport);
3536 lpfc_enable_la(struct lpfc_hba *phba)
3539 struct lpfc_sli *psli = &phba->sli;
3540 spin_lock_irq(&phba->hbalock);
3541 psli->sli_flag |= LPFC_PROCESS_LA;
3542 if (phba->sli_rev <= LPFC_SLI_REV3) {
3543 control = readl(phba->HCregaddr);
3544 control |= HC_LAINT_ENA;
3545 writel(control, phba->HCregaddr);
3546 readl(phba->HCregaddr); /* flush */
3548 spin_unlock_irq(&phba->hbalock);
3552 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3554 lpfc_linkdown(phba);
3555 lpfc_enable_la(phba);
3556 lpfc_unregister_unused_fcf(phba);
3557 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3562 * This routine handles processing a READ_TOPOLOGY mailbox
3563 * command upon completion. It is setup in the LPFC_MBOXQ
3564 * as the completion routine when the command is
3565 * handed off to the SLI layer. SLI4 only.
3568 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3570 struct lpfc_vport *vport = pmb->vport;
3571 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3572 struct lpfc_mbx_read_top *la;
3573 struct lpfc_sli_ring *pring;
3574 MAILBOX_t *mb = &pmb->u.mb;
3575 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3577 unsigned long iflags;
3579 /* Unblock ELS traffic */
3580 pring = lpfc_phba_elsring(phba);
3582 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3584 /* Check for error */
3585 if (mb->mbxStatus) {
3586 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3587 "1307 READ_LA mbox error x%x state x%x\n",
3588 mb->mbxStatus, vport->port_state);
3589 lpfc_mbx_issue_link_down(phba);
3590 phba->link_state = LPFC_HBA_ERROR;
3591 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3594 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3595 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3597 memcpy(&phba->alpa_map[0], mp->virt, 128);
3599 spin_lock_irqsave(shost->host_lock, iflags);
3600 if (bf_get(lpfc_mbx_read_top_pb, la))
3601 vport->fc_flag |= FC_BYPASSED_MODE;
3603 vport->fc_flag &= ~FC_BYPASSED_MODE;
3604 spin_unlock_irqrestore(shost->host_lock, iflags);
3606 if (phba->fc_eventTag <= la->eventTag) {
3607 phba->fc_stat.LinkMultiEvent++;
3608 if (attn_type == LPFC_ATT_LINK_UP)
3609 if (phba->fc_eventTag != 0)
3610 lpfc_linkdown(phba);
3613 phba->fc_eventTag = la->eventTag;
3614 if (phba->sli_rev < LPFC_SLI_REV4) {
3615 spin_lock_irqsave(&phba->hbalock, iflags);
3616 if (bf_get(lpfc_mbx_read_top_mm, la))
3617 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3619 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3620 spin_unlock_irqrestore(&phba->hbalock, iflags);
3623 phba->link_events++;
3624 if ((attn_type == LPFC_ATT_LINK_UP) &&
3625 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3626 phba->fc_stat.LinkUp++;
3627 if (phba->link_flag & LS_LOOPBACK_MODE) {
3628 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3629 "1306 Link Up Event in loop back mode "
3630 "x%x received Data: x%x x%x x%x x%x\n",
3631 la->eventTag, phba->fc_eventTag,
3632 bf_get(lpfc_mbx_read_top_alpa_granted,
3634 bf_get(lpfc_mbx_read_top_link_spd, la),
3637 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3638 "1303 Link Up Event x%x received "
3639 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3640 la->eventTag, phba->fc_eventTag,
3641 bf_get(lpfc_mbx_read_top_alpa_granted,
3643 bf_get(lpfc_mbx_read_top_link_spd, la),
3645 bf_get(lpfc_mbx_read_top_mm, la),
3646 bf_get(lpfc_mbx_read_top_fa, la),
3647 phba->wait_4_mlo_maint_flg);
3649 lpfc_mbx_process_link_up(phba, la);
3651 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3652 lpfc_cmf_signal_init(phba);
3654 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3655 attn_type == LPFC_ATT_UNEXP_WWPN) {
3656 phba->fc_stat.LinkDown++;
3657 if (phba->link_flag & LS_LOOPBACK_MODE)
3658 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3659 "1308 Link Down Event in loop back mode "
3661 "Data: x%x x%x x%x\n",
3662 la->eventTag, phba->fc_eventTag,
3663 phba->pport->port_state, vport->fc_flag);
3664 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3665 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3666 "1313 Link Down Unexpected FA WWPN Event x%x "
3667 "received Data: x%x x%x x%x x%x x%x\n",
3668 la->eventTag, phba->fc_eventTag,
3669 phba->pport->port_state, vport->fc_flag,
3670 bf_get(lpfc_mbx_read_top_mm, la),
3671 bf_get(lpfc_mbx_read_top_fa, la));
3673 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3674 "1305 Link Down Event x%x received "
3675 "Data: x%x x%x x%x x%x x%x\n",
3676 la->eventTag, phba->fc_eventTag,
3677 phba->pport->port_state, vport->fc_flag,
3678 bf_get(lpfc_mbx_read_top_mm, la),
3679 bf_get(lpfc_mbx_read_top_fa, la));
3680 lpfc_mbx_issue_link_down(phba);
3682 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3683 attn_type == LPFC_ATT_LINK_UP) {
3684 if (phba->link_state != LPFC_LINK_DOWN) {
3685 phba->fc_stat.LinkDown++;
3686 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3687 "1312 Link Down Event x%x received "
3688 "Data: x%x x%x x%x\n",
3689 la->eventTag, phba->fc_eventTag,
3690 phba->pport->port_state, vport->fc_flag);
3691 lpfc_mbx_issue_link_down(phba);
3693 lpfc_enable_la(phba);
3695 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3696 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3697 "Data: x%x x%x x%x\n",
3698 la->eventTag, phba->fc_eventTag,
3699 phba->pport->port_state, vport->fc_flag);
3701 * The cmnd that triggered this will be waiting for this
3704 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3705 if (phba->wait_4_mlo_maint_flg) {
3706 phba->wait_4_mlo_maint_flg = 0;
3707 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3711 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3712 bf_get(lpfc_mbx_read_top_fa, la)) {
3713 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3714 lpfc_issue_clear_la(phba, vport);
3715 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3717 bf_get(lpfc_mbx_read_top_fa, la));
3720 lpfc_mbx_cmpl_read_topology_free_mbuf:
3721 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3723 mempool_free(pmb, phba->mbox_mem_pool);
3728 * This routine handles processing a REG_LOGIN mailbox
3729 * command upon completion. It is setup in the LPFC_MBOXQ
3730 * as the completion routine when the command is
3731 * handed off to the SLI layer.
3734 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3736 struct lpfc_vport *vport = pmb->vport;
3737 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3738 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3740 pmb->ctx_buf = NULL;
3741 pmb->ctx_ndlp = NULL;
3743 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3744 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3745 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3746 kref_read(&ndlp->kref),
3748 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3749 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3751 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3752 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3753 /* We rcvd a rscn after issuing this
3754 * mbox reg login, we may have cycled
3755 * back through the state and be
3756 * back at reg login state so this
3757 * mbox needs to be ignored becase
3758 * there is another reg login in
3761 spin_lock_irq(&ndlp->lock);
3762 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3763 spin_unlock_irq(&ndlp->lock);
3766 * We cannot leave the RPI registered because
3767 * if we go thru discovery again for this ndlp
3768 * a subsequent REG_RPI will fail.
3770 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3771 lpfc_unreg_rpi(vport, ndlp);
3774 /* Call state machine */
3775 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3777 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3779 mempool_free(pmb, phba->mbox_mem_pool);
3780 /* decrement the node reference count held for this callback
3789 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3791 MAILBOX_t *mb = &pmb->u.mb;
3792 struct lpfc_vport *vport = pmb->vport;
3793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3795 switch (mb->mbxStatus) {
3798 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3799 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3802 /* If VPI is busy, reset the HBA */
3804 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3805 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3806 vport->vpi, mb->mbxStatus);
3807 if (!(phba->pport->load_flag & FC_UNLOADING))
3808 lpfc_workq_post_event(phba, NULL, NULL,
3809 LPFC_EVT_RESET_HBA);
3811 spin_lock_irq(shost->host_lock);
3812 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3813 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3814 spin_unlock_irq(shost->host_lock);
3815 vport->unreg_vpi_cmpl = VPORT_OK;
3816 mempool_free(pmb, phba->mbox_mem_pool);
3817 lpfc_cleanup_vports_rrqs(vport, NULL);
3819 * This shost reference might have been taken at the beginning of
3820 * lpfc_vport_delete()
3822 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3823 scsi_host_put(shost);
3827 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3829 struct lpfc_hba *phba = vport->phba;
3833 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3837 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3838 mbox->vport = vport;
3839 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3840 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3841 if (rc == MBX_NOT_FINISHED) {
3842 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3843 "1800 Could not issue unreg_vpi\n");
3844 mempool_free(mbox, phba->mbox_mem_pool);
3845 vport->unreg_vpi_cmpl = VPORT_ERROR;
3852 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3854 struct lpfc_vport *vport = pmb->vport;
3855 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3856 MAILBOX_t *mb = &pmb->u.mb;
3858 switch (mb->mbxStatus) {
3862 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3863 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3865 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3866 spin_lock_irq(shost->host_lock);
3867 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3868 spin_unlock_irq(shost->host_lock);
3869 vport->fc_myDID = 0;
3871 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3872 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3873 if (phba->nvmet_support)
3874 lpfc_nvmet_update_targetport(phba);
3876 lpfc_nvme_update_localport(vport);
3881 spin_lock_irq(shost->host_lock);
3882 vport->vpi_state |= LPFC_VPI_REGISTERED;
3883 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3884 spin_unlock_irq(shost->host_lock);
3885 vport->num_disc_nodes = 0;
3886 /* go thru NPR list and issue ELS PLOGIs */
3887 if (vport->fc_npr_cnt)
3888 lpfc_els_disc_plogi(vport);
3890 if (!vport->num_disc_nodes) {
3891 spin_lock_irq(shost->host_lock);
3892 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3893 spin_unlock_irq(shost->host_lock);
3894 lpfc_can_disctmo(vport);
3896 vport->port_state = LPFC_VPORT_READY;
3899 mempool_free(pmb, phba->mbox_mem_pool);
3904 * lpfc_create_static_vport - Read HBA config region to create static vports.
3905 * @phba: pointer to lpfc hba data structure.
3907 * This routine issue a DUMP mailbox command for config region 22 to get
3908 * the list of static vports to be created. The function create vports
3909 * based on the information returned from the HBA.
3912 lpfc_create_static_vport(struct lpfc_hba *phba)
3914 LPFC_MBOXQ_t *pmb = NULL;
3916 struct static_vport_info *vport_info;
3917 int mbx_wait_rc = 0, i;
3918 struct fc_vport_identifiers vport_id;
3919 struct fc_vport *new_fc_vport;
3920 struct Scsi_Host *shost;
3921 struct lpfc_vport *vport;
3922 uint16_t offset = 0;
3923 uint8_t *vport_buff;
3924 struct lpfc_dmabuf *mp;
3925 uint32_t byte_count = 0;
3927 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3929 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3930 "0542 lpfc_create_static_vport failed to"
3931 " allocate mailbox memory\n");
3934 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3937 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3939 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3940 "0543 lpfc_create_static_vport failed to"
3941 " allocate vport_info\n");
3942 mempool_free(pmb, phba->mbox_mem_pool);
3946 vport_buff = (uint8_t *) vport_info;
3948 /* free dma buffer from previous round */
3950 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3951 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3954 if (lpfc_dump_static_vport(phba, pmb, offset))
3957 pmb->vport = phba->pport;
3958 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3961 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3962 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3963 "0544 lpfc_create_static_vport failed to"
3964 " issue dump mailbox command ret 0x%x "
3966 mbx_wait_rc, mb->mbxStatus);
3970 if (phba->sli_rev == LPFC_SLI_REV4) {
3971 byte_count = pmb->u.mqe.un.mb_words[5];
3972 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3973 if (byte_count > sizeof(struct static_vport_info) -
3975 byte_count = sizeof(struct static_vport_info)
3977 memcpy(vport_buff + offset, mp->virt, byte_count);
3978 offset += byte_count;
3980 if (mb->un.varDmp.word_cnt >
3981 sizeof(struct static_vport_info) - offset)
3982 mb->un.varDmp.word_cnt =
3983 sizeof(struct static_vport_info)
3985 byte_count = mb->un.varDmp.word_cnt;
3986 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3987 vport_buff + offset,
3990 offset += byte_count;
3993 } while (byte_count &&
3994 offset < sizeof(struct static_vport_info));
3997 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3998 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3999 != VPORT_INFO_REV)) {
4000 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4001 "0545 lpfc_create_static_vport bad"
4002 " information header 0x%x 0x%x\n",
4003 le32_to_cpu(vport_info->signature),
4004 le32_to_cpu(vport_info->rev) &
4005 VPORT_INFO_REV_MASK);
4010 shost = lpfc_shost_from_vport(phba->pport);
4012 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4013 memset(&vport_id, 0, sizeof(vport_id));
4014 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4015 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4016 if (!vport_id.port_name || !vport_id.node_name)
4019 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4020 vport_id.vport_type = FC_PORTTYPE_NPIV;
4021 vport_id.disable = false;
4022 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4024 if (!new_fc_vport) {
4025 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4026 "0546 lpfc_create_static_vport failed to"
4031 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4032 vport->vport_flag |= STATIC_VPORT;
4037 if (mbx_wait_rc != MBX_TIMEOUT) {
4039 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4040 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4043 mempool_free(pmb, phba->mbox_mem_pool);
4050 * This routine handles processing a Fabric REG_LOGIN mailbox
4051 * command upon completion. It is setup in the LPFC_MBOXQ
4052 * as the completion routine when the command is
4053 * handed off to the SLI layer.
4056 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4058 struct lpfc_vport *vport = pmb->vport;
4059 MAILBOX_t *mb = &pmb->u.mb;
4060 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4061 struct lpfc_nodelist *ndlp;
4062 struct Scsi_Host *shost;
4064 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4065 pmb->ctx_ndlp = NULL;
4066 pmb->ctx_buf = NULL;
4068 if (mb->mbxStatus) {
4069 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4070 "0258 Register Fabric login error: 0x%x\n",
4072 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4074 mempool_free(pmb, phba->mbox_mem_pool);
4076 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4077 /* FLOGI failed, use loop map to make discovery list */
4078 lpfc_disc_list_loopmap(vport);
4080 /* Start discovery */
4081 lpfc_disc_start(vport);
4082 /* Decrement the reference count to ndlp after the
4083 * reference to the ndlp are done.
4089 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4090 /* Decrement the reference count to ndlp after the reference
4091 * to the ndlp are done.
4097 if (phba->sli_rev < LPFC_SLI_REV4)
4098 ndlp->nlp_rpi = mb->un.varWords[0];
4099 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4100 ndlp->nlp_type |= NLP_FABRIC;
4101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4103 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4104 /* when physical port receive logo donot start
4105 * vport discovery */
4106 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4107 lpfc_start_fdiscs(phba);
4109 shost = lpfc_shost_from_vport(vport);
4110 spin_lock_irq(shost->host_lock);
4111 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4112 spin_unlock_irq(shost->host_lock);
4114 lpfc_do_scr_ns_plogi(phba, vport);
4117 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4119 mempool_free(pmb, phba->mbox_mem_pool);
4121 /* Drop the reference count from the mbox at the end after
4122 * all the current reference to the ndlp have been done.
4129 * This routine will issue a GID_FT for each FC4 Type supported
4130 * by the driver. ALL GID_FTs must complete before discovery is started.
4133 lpfc_issue_gidft(struct lpfc_vport *vport)
4135 /* Good status, issue CT Request to NameServer */
4136 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4137 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4138 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4139 /* Cannot issue NameServer FCP Query, so finish up
4142 lpfc_printf_vlog(vport, KERN_ERR,
4144 "0604 %s FC TYPE %x %s\n",
4145 "Failed to issue GID_FT to ",
4147 "Finishing discovery.");
4153 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4154 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4155 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4156 /* Cannot issue NameServer NVME Query, so finish up
4159 lpfc_printf_vlog(vport, KERN_ERR,
4161 "0605 %s FC_TYPE %x %s %d\n",
4162 "Failed to issue GID_FT to ",
4164 "Finishing discovery: gidftinp ",
4166 if (vport->gidft_inp == 0)
4171 return vport->gidft_inp;
4175 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4176 * @vport: The virtual port for which this call is being executed.
4178 * This routine will issue a GID_PT to get a list of all N_Ports
4181 * 0 - Failure to issue a GID_PT
4185 lpfc_issue_gidpt(struct lpfc_vport *vport)
4187 /* Good status, issue CT Request to NameServer */
4188 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4189 /* Cannot issue NameServer FCP Query, so finish up
4192 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4193 "0606 %s Port TYPE %x %s\n",
4194 "Failed to issue GID_PT to ",
4196 "Finishing discovery.");
4204 * This routine handles processing a NameServer REG_LOGIN mailbox
4205 * command upon completion. It is setup in the LPFC_MBOXQ
4206 * as the completion routine when the command is
4207 * handed off to the SLI layer.
4210 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4212 MAILBOX_t *mb = &pmb->u.mb;
4213 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4214 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4215 struct lpfc_vport *vport = pmb->vport;
4218 pmb->ctx_buf = NULL;
4219 pmb->ctx_ndlp = NULL;
4220 vport->gidft_inp = 0;
4222 if (mb->mbxStatus) {
4223 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4224 "0260 Register NameServer error: 0x%x\n",
4228 /* decrement the node reference count held for this
4229 * callback function.
4232 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4234 mempool_free(pmb, phba->mbox_mem_pool);
4236 /* If the node is not registered with the scsi or nvme
4237 * transport, remove the fabric node. The failed reg_login
4240 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4241 spin_lock_irq(&ndlp->lock);
4242 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4243 spin_unlock_irq(&ndlp->lock);
4244 lpfc_nlp_not_used(ndlp);
4247 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4249 * RegLogin failed, use loop map to make discovery
4252 lpfc_disc_list_loopmap(vport);
4254 /* Start discovery */
4255 lpfc_disc_start(vport);
4258 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4262 if (phba->sli_rev < LPFC_SLI_REV4)
4263 ndlp->nlp_rpi = mb->un.varWords[0];
4264 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4265 ndlp->nlp_type |= NLP_FABRIC;
4266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4267 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4268 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4269 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4270 kref_read(&ndlp->kref),
4273 if (vport->port_state < LPFC_VPORT_READY) {
4274 /* Link up discovery requires Fabric registration. */
4275 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4276 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4277 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4278 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4280 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4281 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4282 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4284 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4285 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4286 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4289 /* Issue SCR just before NameServer GID_FT Query */
4290 lpfc_issue_els_scr(vport, 0);
4292 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4293 * with initial FW values provided the congestion mode is
4294 * not off. Note that signals may or may not be supported
4295 * by the adapter but FPIN is provided by default for 1
4296 * or both missing signals support.
4298 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4299 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4300 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4301 rc = lpfc_issue_els_edc(vport, 0);
4302 lpfc_printf_log(phba, KERN_INFO,
4303 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4304 "4220 EDC issue error x%x, Data: x%x\n",
4305 rc, phba->cgn_init_reg_signal);
4307 lpfc_issue_els_rdf(vport, 0);
4311 vport->fc_ns_retry = 0;
4312 if (lpfc_issue_gidft(vport) == 0)
4316 * At this point in time we may need to wait for multiple
4317 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4319 * decrement the node reference count held for this
4320 * callback function.
4323 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4325 mempool_free(pmb, phba->mbox_mem_pool);
4331 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4332 * command upon completion. It is setup in the LPFC_MBOXQ
4333 * as the completion routine when the command is handed off to the SLI layer.
4336 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4338 struct lpfc_vport *vport = pmb->vport;
4339 MAILBOX_t *mb = &pmb->u.mb;
4340 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4341 struct lpfc_nodelist *ndlp;
4343 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4344 pmb->ctx_ndlp = NULL;
4345 pmb->ctx_buf = NULL;
4347 if (mb->mbxStatus) {
4348 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4349 "0933 %s: Register FC login error: 0x%x\n",
4350 __func__, mb->mbxStatus);
4354 if (phba->sli_rev < LPFC_SLI_REV4)
4355 ndlp->nlp_rpi = mb->un.varWords[0];
4357 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4358 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4359 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4362 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4363 ndlp->nlp_type |= NLP_FABRIC;
4364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4367 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4369 mempool_free(pmb, phba->mbox_mem_pool);
4371 /* Drop the reference count from the mbox at the end after
4372 * all the current reference to the ndlp have been done.
4378 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4381 struct fc_rport *rport;
4382 struct lpfc_rport_data *rdata;
4383 struct fc_rport_identifiers rport_ids;
4384 struct lpfc_hba *phba = vport->phba;
4385 unsigned long flags;
4387 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4390 /* Remote port has reappeared. Re-register w/ FC transport */
4391 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4392 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4393 rport_ids.port_id = ndlp->nlp_DID;
4394 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4397 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4398 "rport add: did:x%x flg:x%x type x%x",
4399 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4401 /* Don't add the remote port if unloading. */
4402 if (vport->load_flag & FC_UNLOADING)
4406 * Disassociate any older association between this ndlp and rport
4409 rdata = ndlp->rport->dd_data;
4410 rdata->pnode = NULL;
4413 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4415 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4416 "Warning: fc_remote_port_add failed\n");
4420 /* Successful port add. Complete initializing node data */
4421 rport->maxframe_size = ndlp->nlp_maxframe;
4422 rport->supported_classes = ndlp->nlp_class_sup;
4423 rdata = rport->dd_data;
4424 rdata->pnode = lpfc_nlp_get(ndlp);
4425 if (!rdata->pnode) {
4426 dev_warn(&phba->pcidev->dev,
4427 "Warning - node ref failed. Unreg rport\n");
4428 fc_remote_port_delete(rport);
4433 spin_lock_irqsave(&ndlp->lock, flags);
4434 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4435 spin_unlock_irqrestore(&ndlp->lock, flags);
4437 if (ndlp->nlp_type & NLP_FCP_TARGET)
4438 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4439 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4440 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4441 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4442 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4443 if (ndlp->nlp_type & NLP_NVME_TARGET)
4444 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4445 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4446 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4448 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4449 fc_remote_port_rolechg(rport, rport_ids.roles);
4451 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4452 "3183 %s rport x%px DID x%x, role x%x\n",
4453 __func__, rport, rport->port_id, rport->roles);
4455 if ((rport->scsi_target_id != -1) &&
4456 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4457 ndlp->nlp_sid = rport->scsi_target_id;
4464 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4466 struct fc_rport *rport = ndlp->rport;
4467 struct lpfc_vport *vport = ndlp->vport;
4469 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4472 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4473 "rport delete: did:x%x flg:x%x type x%x",
4474 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4476 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4477 "3184 rport unregister x%06x, rport x%px "
4479 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags);
4481 fc_remote_port_delete(rport);
4486 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4489 unsigned long iflags;
4491 spin_lock_irqsave(shost->host_lock, iflags);
4493 case NLP_STE_UNUSED_NODE:
4494 vport->fc_unused_cnt += count;
4496 case NLP_STE_PLOGI_ISSUE:
4497 vport->fc_plogi_cnt += count;
4499 case NLP_STE_ADISC_ISSUE:
4500 vport->fc_adisc_cnt += count;
4502 case NLP_STE_REG_LOGIN_ISSUE:
4503 vport->fc_reglogin_cnt += count;
4505 case NLP_STE_PRLI_ISSUE:
4506 vport->fc_prli_cnt += count;
4508 case NLP_STE_UNMAPPED_NODE:
4509 vport->fc_unmap_cnt += count;
4511 case NLP_STE_MAPPED_NODE:
4512 vport->fc_map_cnt += count;
4514 case NLP_STE_NPR_NODE:
4515 if (vport->fc_npr_cnt == 0 && count == -1)
4516 vport->fc_npr_cnt = 0;
4518 vport->fc_npr_cnt += count;
4521 spin_unlock_irqrestore(shost->host_lock, iflags);
4524 /* Register a node with backend if not already done */
4526 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4529 unsigned long iflags;
4531 spin_lock_irqsave(&ndlp->lock, iflags);
4532 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4533 /* Already registered with backend, trigger rescan */
4534 spin_unlock_irqrestore(&ndlp->lock, iflags);
4536 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4537 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4538 lpfc_nvme_rescan_port(vport, ndlp);
4543 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4544 spin_unlock_irqrestore(&ndlp->lock, iflags);
4546 if (lpfc_valid_xpt_node(ndlp)) {
4547 vport->phba->nport_event_cnt++;
4549 * Tell the fc transport about the port, if we haven't
4550 * already. If we have, and it's a scsi entity, be
4552 lpfc_register_remote_port(vport, ndlp);
4555 /* We are done if we do not have any NVME remote node */
4556 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4559 /* Notify the NVME transport of this new rport. */
4560 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4561 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4562 if (vport->phba->nvmet_support == 0) {
4563 /* Register this rport with the transport.
4564 * Only NVME Target Rports are registered with
4567 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4568 vport->phba->nport_event_cnt++;
4569 lpfc_nvme_register_port(vport, ndlp);
4572 /* Just take an NDLP ref count since the
4573 * target does not register rports.
4580 /* Unregister a node with backend if not already done */
4582 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4584 unsigned long iflags;
4586 spin_lock_irqsave(&ndlp->lock, iflags);
4587 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4588 spin_unlock_irqrestore(&ndlp->lock, iflags);
4592 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4593 spin_unlock_irqrestore(&ndlp->lock, iflags);
4596 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4597 vport->phba->nport_event_cnt++;
4598 lpfc_unregister_remote_port(ndlp);
4601 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4602 vport->phba->nport_event_cnt++;
4603 if (vport->phba->nvmet_support == 0) {
4604 /* Start devloss if target. */
4605 if (ndlp->nlp_type & NLP_NVME_TARGET)
4606 lpfc_nvme_unregister_port(vport, ndlp);
4608 /* NVMET has no upcall. */
4616 * Adisc state change handling
4619 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4622 switch (new_state) {
4624 * Any state to ADISC_ISSUE
4625 * Do nothing, adisc cmpl handling will trigger state changes
4627 case NLP_STE_ADISC_ISSUE:
4631 * ADISC_ISSUE to mapped states
4632 * Trigger a registration with backend, it will be nop if
4633 * already registered
4635 case NLP_STE_UNMAPPED_NODE:
4636 ndlp->nlp_type |= NLP_FC_NODE;
4638 case NLP_STE_MAPPED_NODE:
4639 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4640 lpfc_nlp_reg_node(vport, ndlp);
4644 * ADISC_ISSUE to non-mapped states
4645 * We are moving from ADISC_ISSUE to a non-mapped state because
4646 * ADISC failed, we would have skipped unregistering with
4647 * backend, attempt it now
4649 case NLP_STE_NPR_NODE:
4650 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4653 lpfc_nlp_unreg_node(vport, ndlp);
4660 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4661 int old_state, int new_state)
4663 /* Trap ADISC changes here */
4664 if (new_state == NLP_STE_ADISC_ISSUE ||
4665 old_state == NLP_STE_ADISC_ISSUE) {
4666 lpfc_handle_adisc_state(vport, ndlp, new_state);
4670 if (new_state == NLP_STE_UNMAPPED_NODE) {
4671 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4672 ndlp->nlp_type |= NLP_FC_NODE;
4674 if (new_state == NLP_STE_MAPPED_NODE)
4675 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4676 if (new_state == NLP_STE_NPR_NODE)
4677 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4679 /* Reg/Unreg for FCP and NVME Transport interface */
4680 if ((old_state == NLP_STE_MAPPED_NODE ||
4681 old_state == NLP_STE_UNMAPPED_NODE)) {
4682 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl */
4683 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
4684 lpfc_nlp_unreg_node(vport, ndlp);
4687 if (new_state == NLP_STE_MAPPED_NODE ||
4688 new_state == NLP_STE_UNMAPPED_NODE)
4689 lpfc_nlp_reg_node(vport, ndlp);
4691 if ((new_state == NLP_STE_MAPPED_NODE) &&
4692 (vport->stat_data_enabled)) {
4694 * A new target is discovered, if there is no buffer for
4695 * statistical data collection allocate buffer.
4697 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4698 sizeof(struct lpfc_scsicmd_bkt),
4701 if (!ndlp->lat_data)
4702 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4703 "0286 lpfc_nlp_state_cleanup failed to "
4704 "allocate statistical data buffer DID "
4705 "0x%x\n", ndlp->nlp_DID);
4708 * If the node just added to Mapped list was an FCP target,
4709 * but the remote port registration failed or assigned a target
4710 * id outside the presentable range - move the node to the
4713 if ((new_state == NLP_STE_MAPPED_NODE) &&
4714 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4716 ndlp->rport->scsi_target_id == -1 ||
4717 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4718 spin_lock_irq(&ndlp->lock);
4719 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4720 spin_unlock_irq(&ndlp->lock);
4721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4726 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4728 static char *states[] = {
4729 [NLP_STE_UNUSED_NODE] = "UNUSED",
4730 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4731 [NLP_STE_ADISC_ISSUE] = "ADISC",
4732 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4733 [NLP_STE_PRLI_ISSUE] = "PRLI",
4734 [NLP_STE_LOGO_ISSUE] = "LOGO",
4735 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4736 [NLP_STE_MAPPED_NODE] = "MAPPED",
4737 [NLP_STE_NPR_NODE] = "NPR",
4740 if (state < NLP_STE_MAX_STATE && states[state])
4741 strlcpy(buffer, states[state], size);
4743 snprintf(buffer, size, "unknown (%d)", state);
4748 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4752 int old_state = ndlp->nlp_state;
4753 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4754 char name1[16], name2[16];
4756 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4757 "0904 NPort state transition x%06x, %s -> %s\n",
4759 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4760 lpfc_nlp_state_name(name2, sizeof(name2), state));
4762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4763 "node statechg did:x%x old:%d ste:%d",
4764 ndlp->nlp_DID, old_state, state);
4766 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4767 state != NLP_STE_UNUSED_NODE) {
4768 ndlp->nlp_flag &= ~NLP_DROPPED;
4772 if (old_state == NLP_STE_NPR_NODE &&
4773 state != NLP_STE_NPR_NODE)
4774 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4775 if (old_state == NLP_STE_UNMAPPED_NODE) {
4776 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4777 ndlp->nlp_type &= ~NLP_FC_NODE;
4780 if (list_empty(&ndlp->nlp_listp)) {
4781 spin_lock_irq(shost->host_lock);
4782 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4783 spin_unlock_irq(shost->host_lock);
4784 } else if (old_state)
4785 lpfc_nlp_counters(vport, old_state, -1);
4787 ndlp->nlp_state = state;
4788 lpfc_nlp_counters(vport, state, 1);
4789 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4793 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4795 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4797 if (list_empty(&ndlp->nlp_listp)) {
4798 spin_lock_irq(shost->host_lock);
4799 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4800 spin_unlock_irq(shost->host_lock);
4805 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4809 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4810 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4811 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4812 spin_lock_irq(shost->host_lock);
4813 list_del_init(&ndlp->nlp_listp);
4814 spin_unlock_irq(shost->host_lock);
4815 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4816 NLP_STE_UNUSED_NODE);
4820 * lpfc_initialize_node - Initialize all fields of node object
4821 * @vport: Pointer to Virtual Port object.
4822 * @ndlp: Pointer to FC node object.
4823 * @did: FC_ID of the node.
4825 * This function is always called when node object need to be initialized.
4826 * It initializes all the fields of the node object. Although the reference
4827 * to phba from @ndlp can be obtained indirectly through it's reference to
4828 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4829 * to the life-span of the @ndlp might go beyond the existence of @vport as
4830 * the final release of ndlp is determined by its reference count. And, the
4831 * operation on @ndlp needs the reference to phba.
4834 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4837 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4838 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4839 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4840 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4842 ndlp->nlp_DID = did;
4843 ndlp->vport = vport;
4844 ndlp->phba = vport->phba;
4845 ndlp->nlp_sid = NLP_NO_SID;
4846 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4847 kref_init(&ndlp->kref);
4848 atomic_set(&ndlp->cmd_pending, 0);
4849 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4850 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4854 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4857 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4858 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4859 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4860 * until ALL other outstanding threads have completed. We check
4861 * that the ndlp not already in the UNUSED state before we proceed.
4863 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4865 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4866 ndlp->nlp_flag |= NLP_DROPPED;
4867 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4868 lpfc_cleanup_vports_rrqs(vport, ndlp);
4869 lpfc_unreg_rpi(vport, ndlp);
4877 * Start / ReStart rescue timer for Discovery / RSCN handling
4880 lpfc_set_disctmo(struct lpfc_vport *vport)
4882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4883 struct lpfc_hba *phba = vport->phba;
4886 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4887 /* For FAN, timeout should be greater than edtov */
4888 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4890 /* Normal discovery timeout should be > than ELS/CT timeout
4891 * FC spec states we need 3 * ratov for CT requests
4893 tmo = ((phba->fc_ratov * 3) + 3);
4897 if (!timer_pending(&vport->fc_disctmo)) {
4898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4899 "set disc timer: tmo:x%x state:x%x flg:x%x",
4900 tmo, vport->port_state, vport->fc_flag);
4903 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4904 spin_lock_irq(shost->host_lock);
4905 vport->fc_flag |= FC_DISC_TMO;
4906 spin_unlock_irq(shost->host_lock);
4908 /* Start Discovery Timer state <hba_state> */
4909 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4910 "0247 Start Discovery Timer state x%x "
4911 "Data: x%x x%lx x%x x%x\n",
4912 vport->port_state, tmo,
4913 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4914 vport->fc_adisc_cnt);
4920 * Cancel rescue timer for Discovery / RSCN handling
4923 lpfc_can_disctmo(struct lpfc_vport *vport)
4925 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4926 unsigned long iflags;
4928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4929 "can disc timer: state:x%x rtry:x%x flg:x%x",
4930 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4932 /* Turn off discovery timer if its running */
4933 if (vport->fc_flag & FC_DISC_TMO) {
4934 spin_lock_irqsave(shost->host_lock, iflags);
4935 vport->fc_flag &= ~FC_DISC_TMO;
4936 spin_unlock_irqrestore(shost->host_lock, iflags);
4937 del_timer_sync(&vport->fc_disctmo);
4938 spin_lock_irqsave(&vport->work_port_lock, iflags);
4939 vport->work_port_events &= ~WORKER_DISC_TMO;
4940 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4943 /* Cancel Discovery Timer state <hba_state> */
4944 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4945 "0248 Cancel Discovery Timer state x%x "
4946 "Data: x%x x%x x%x\n",
4947 vport->port_state, vport->fc_flag,
4948 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4953 * Check specified ring for outstanding IOCB on the SLI queue
4954 * Return true if iocb matches the specified nport
4957 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4958 struct lpfc_sli_ring *pring,
4959 struct lpfc_iocbq *iocb,
4960 struct lpfc_nodelist *ndlp)
4962 IOCB_t *icmd = &iocb->iocb;
4963 struct lpfc_vport *vport = ndlp->vport;
4965 if (iocb->vport != vport)
4968 if (pring->ringno == LPFC_ELS_RING) {
4969 switch (icmd->ulpCommand) {
4970 case CMD_GEN_REQUEST64_CR:
4971 if (iocb->context_un.ndlp == ndlp)
4974 case CMD_ELS_REQUEST64_CR:
4975 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4978 case CMD_XMIT_ELS_RSP64_CX:
4979 if (iocb->context1 == (uint8_t *) ndlp)
4982 } else if (pring->ringno == LPFC_FCP_RING) {
4983 /* Skip match check if waiting to relogin to FCP target */
4984 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4985 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4988 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4996 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
4997 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
4998 struct list_head *dequeue_list)
5000 struct lpfc_iocbq *iocb, *next_iocb;
5002 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5003 /* Check to see if iocb matches the nport */
5004 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5005 /* match, dequeue */
5006 list_move_tail(&iocb->list, dequeue_list);
5011 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5012 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5014 struct lpfc_sli *psli = &phba->sli;
5017 spin_lock_irq(&phba->hbalock);
5018 for (i = 0; i < psli->num_rings; i++)
5019 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5021 spin_unlock_irq(&phba->hbalock);
5025 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5026 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5028 struct lpfc_sli_ring *pring;
5029 struct lpfc_queue *qp = NULL;
5031 spin_lock_irq(&phba->hbalock);
5032 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5036 spin_lock(&pring->ring_lock);
5037 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5038 spin_unlock(&pring->ring_lock);
5040 spin_unlock_irq(&phba->hbalock);
5044 * Free resources / clean up outstanding I/Os
5045 * associated with nlp_rpi in the LPFC_NODELIST entry.
5048 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5050 LIST_HEAD(completions);
5052 lpfc_fabric_abort_nport(ndlp);
5055 * Everything that matches on txcmplq will be returned
5056 * by firmware with a no rpi error.
5058 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5059 if (phba->sli_rev != LPFC_SLI_REV4)
5060 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5062 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5065 /* Cancel all the IOCBs from the completions list */
5066 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5073 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5074 * @phba: Pointer to HBA context object.
5075 * @pmb: Pointer to mailbox object.
5077 * This function will issue an ELS LOGO command after completing
5081 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5083 struct lpfc_vport *vport = pmb->vport;
5084 struct lpfc_nodelist *ndlp;
5086 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5089 lpfc_issue_els_logo(vport, ndlp, 0);
5090 mempool_free(pmb, phba->mbox_mem_pool);
5092 /* Check to see if there are any deferred events to process */
5093 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5094 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5096 "1434 UNREG cmpl deferred logo x%x "
5097 "on NPort x%x Data: x%x x%px\n",
5098 ndlp->nlp_rpi, ndlp->nlp_DID,
5099 ndlp->nlp_defer_did, ndlp);
5101 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5102 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5103 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5105 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5106 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5107 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5108 spin_lock_irq(&ndlp->lock);
5109 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5110 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5111 spin_unlock_irq(&ndlp->lock);
5113 spin_lock_irq(&ndlp->lock);
5114 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5115 spin_unlock_irq(&ndlp->lock);
5120 * Sets the mailbox completion handler to be used for the
5121 * unreg_rpi command. The handler varies based on the state of
5122 * the port and what will be happening to the rpi next.
5125 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5126 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5128 unsigned long iflags;
5130 /* Driver always gets a reference on the mailbox job
5131 * in support of async jobs.
5133 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5134 if (!mbox->ctx_ndlp)
5137 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5138 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5140 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5141 (!(vport->load_flag & FC_UNLOADING)) &&
5142 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5143 LPFC_SLI_INTF_IF_TYPE_2) &&
5144 (kref_read(&ndlp->kref) > 0)) {
5145 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5147 if (vport->load_flag & FC_UNLOADING) {
5148 if (phba->sli_rev == LPFC_SLI_REV4) {
5149 spin_lock_irqsave(&ndlp->lock, iflags);
5150 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5151 spin_unlock_irqrestore(&ndlp->lock, iflags);
5154 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5159 * Free rpi associated with LPFC_NODELIST entry.
5160 * This routine is called from lpfc_freenode(), when we are removing
5161 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5162 * LOGO that completes successfully, and we are waiting to PLOGI back
5163 * to the remote NPort. In addition, it is called after we receive
5164 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5165 * we are waiting to PLOGI back to the remote NPort.
5168 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5170 struct lpfc_hba *phba = vport->phba;
5172 int rc, acc_plogi = 1;
5175 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5176 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5177 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5178 lpfc_printf_vlog(vport, KERN_INFO,
5179 LOG_NODE | LOG_DISCOVERY,
5180 "3366 RPI x%x needs to be "
5181 "unregistered nlp_flag x%x "
5183 ndlp->nlp_rpi, ndlp->nlp_flag,
5186 /* If there is already an UNREG in progress for this ndlp,
5187 * no need to queue up another one.
5189 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5190 lpfc_printf_vlog(vport, KERN_INFO,
5191 LOG_NODE | LOG_DISCOVERY,
5192 "1436 unreg_rpi SKIP UNREG x%x on "
5193 "NPort x%x deferred x%x flg x%x "
5195 ndlp->nlp_rpi, ndlp->nlp_DID,
5196 ndlp->nlp_defer_did,
5197 ndlp->nlp_flag, ndlp);
5201 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5203 /* SLI4 ports require the physical rpi value. */
5204 rpi = ndlp->nlp_rpi;
5205 if (phba->sli_rev == LPFC_SLI_REV4)
5206 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5208 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5209 mbox->vport = vport;
5210 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5211 if (!mbox->ctx_ndlp) {
5212 mempool_free(mbox, phba->mbox_mem_pool);
5216 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5218 * accept PLOGIs after unreg_rpi_cmpl
5221 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5223 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5224 ndlp->nlp_flag |= NLP_UNREG_INP;
5226 lpfc_printf_vlog(vport, KERN_INFO,
5227 LOG_NODE | LOG_DISCOVERY,
5228 "1433 unreg_rpi UNREG x%x on "
5229 "NPort x%x deferred flg x%x "
5231 ndlp->nlp_rpi, ndlp->nlp_DID,
5232 ndlp->nlp_flag, ndlp);
5234 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5235 if (rc == MBX_NOT_FINISHED) {
5236 mempool_free(mbox, phba->mbox_mem_pool);
5240 lpfc_printf_vlog(vport, KERN_INFO,
5241 LOG_NODE | LOG_DISCOVERY,
5242 "1444 Failed to allocate mempool "
5243 "unreg_rpi UNREG x%x, "
5244 "DID x%x, flag x%x, "
5246 ndlp->nlp_rpi, ndlp->nlp_DID,
5247 ndlp->nlp_flag, ndlp);
5249 /* Because mempool_alloc failed, we
5250 * will issue a LOGO here and keep the rpi alive if
5253 if (!(vport->load_flag & FC_UNLOADING)) {
5254 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5255 lpfc_issue_els_logo(vport, ndlp, 0);
5256 ndlp->nlp_prev_state = ndlp->nlp_state;
5257 lpfc_nlp_set_state(vport, ndlp,
5263 lpfc_no_rpi(phba, ndlp);
5265 if (phba->sli_rev != LPFC_SLI_REV4)
5267 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5268 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5270 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5273 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5278 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5279 * @phba: pointer to lpfc hba data structure.
5281 * This routine is invoked to unregister all the currently registered RPIs
5285 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5287 struct lpfc_vport **vports;
5288 struct lpfc_nodelist *ndlp;
5289 struct Scsi_Host *shost;
5292 vports = lpfc_create_vport_work_array(phba);
5294 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5295 "2884 Vport array allocation failed \n");
5298 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5299 shost = lpfc_shost_from_vport(vports[i]);
5300 spin_lock_irq(shost->host_lock);
5301 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5302 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5303 /* The mempool_alloc might sleep */
5304 spin_unlock_irq(shost->host_lock);
5305 lpfc_unreg_rpi(vports[i], ndlp);
5306 spin_lock_irq(shost->host_lock);
5309 spin_unlock_irq(shost->host_lock);
5311 lpfc_destroy_vport_work_array(phba, vports);
5315 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5317 struct lpfc_hba *phba = vport->phba;
5321 if (phba->sli_rev == LPFC_SLI_REV4) {
5322 lpfc_sli4_unreg_all_rpis(vport);
5326 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5328 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5330 mbox->vport = vport;
5331 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5332 mbox->ctx_ndlp = NULL;
5333 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5334 if (rc != MBX_TIMEOUT)
5335 mempool_free(mbox, phba->mbox_mem_pool);
5337 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5338 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5339 "1836 Could not issue "
5340 "unreg_login(all_rpis) status %d\n",
5346 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5348 struct lpfc_hba *phba = vport->phba;
5352 /* Unreg DID is an SLI3 operation. */
5353 if (phba->sli_rev > LPFC_SLI_REV3)
5356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5358 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5360 mbox->vport = vport;
5361 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5362 mbox->ctx_ndlp = NULL;
5363 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5364 if (rc != MBX_TIMEOUT)
5365 mempool_free(mbox, phba->mbox_mem_pool);
5367 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5368 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5369 "1815 Could not issue "
5370 "unreg_did (default rpis) status %d\n",
5376 * Free resources associated with LPFC_NODELIST entry
5377 * so it can be freed.
5380 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5382 struct lpfc_hba *phba = vport->phba;
5383 LPFC_MBOXQ_t *mb, *nextmb;
5384 struct lpfc_dmabuf *mp;
5386 /* Cleanup node for NPort <nlp_DID> */
5387 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5388 "0900 Cleanup node for NPort x%x "
5389 "Data: x%x x%x x%x\n",
5390 ndlp->nlp_DID, ndlp->nlp_flag,
5391 ndlp->nlp_state, ndlp->nlp_rpi);
5392 lpfc_dequeue_node(vport, ndlp);
5394 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5396 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5397 if ((mb = phba->sli.mbox_active)) {
5398 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5399 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5400 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5401 mb->ctx_ndlp = NULL;
5402 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5406 spin_lock_irq(&phba->hbalock);
5407 /* Cleanup REG_LOGIN completions which are not yet processed */
5408 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5409 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5410 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5411 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5414 mb->ctx_ndlp = NULL;
5415 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5418 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5419 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5420 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5421 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5422 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5424 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5427 list_del(&mb->list);
5428 mempool_free(mb, phba->mbox_mem_pool);
5429 /* We shall not invoke the lpfc_nlp_put to decrement
5430 * the ndlp reference count as we are in the process
5431 * of lpfc_nlp_release.
5435 spin_unlock_irq(&phba->hbalock);
5437 lpfc_els_abort(phba, ndlp);
5439 spin_lock_irq(&ndlp->lock);
5440 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5441 spin_unlock_irq(&ndlp->lock);
5443 ndlp->nlp_last_elscmd = 0;
5444 del_timer_sync(&ndlp->nlp_delayfunc);
5446 list_del_init(&ndlp->els_retry_evt.evt_listp);
5447 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5448 list_del_init(&ndlp->recovery_evt.evt_listp);
5449 lpfc_cleanup_vports_rrqs(vport, ndlp);
5451 if (phba->sli_rev == LPFC_SLI_REV4)
5452 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5458 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5461 D_ID mydid, ndlpdid, matchdid;
5463 if (did == Bcast_DID)
5466 /* First check for Direct match */
5467 if (ndlp->nlp_DID == did)
5470 /* Next check for area/domain identically equals 0 match */
5471 mydid.un.word = vport->fc_myDID;
5472 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5476 matchdid.un.word = did;
5477 ndlpdid.un.word = ndlp->nlp_DID;
5478 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5479 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5480 (mydid.un.b.area == matchdid.un.b.area)) {
5481 /* This code is supposed to match the ID
5482 * for a private loop device that is
5483 * connect to fl_port. But we need to
5484 * check that the port did not just go
5485 * from pt2pt to fabric or we could end
5486 * up matching ndlp->nlp_DID 000001 to
5487 * fabric DID 0x20101
5489 if ((ndlpdid.un.b.domain == 0) &&
5490 (ndlpdid.un.b.area == 0)) {
5491 if (ndlpdid.un.b.id &&
5492 vport->phba->fc_topology ==
5499 matchdid.un.word = ndlp->nlp_DID;
5500 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5501 (mydid.un.b.area == ndlpdid.un.b.area)) {
5502 if ((matchdid.un.b.domain == 0) &&
5503 (matchdid.un.b.area == 0)) {
5504 if (matchdid.un.b.id)
5512 /* Search for a nodelist entry */
5513 static struct lpfc_nodelist *
5514 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5516 struct lpfc_nodelist *ndlp;
5519 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5520 if (lpfc_matchdid(vport, ndlp, did)) {
5521 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5522 ((uint32_t)ndlp->nlp_xri << 16) |
5523 ((uint32_t)ndlp->nlp_type << 8)
5525 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5526 "0929 FIND node DID "
5527 "Data: x%px x%x x%x x%x x%x x%px\n",
5528 ndlp, ndlp->nlp_DID,
5529 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5530 ndlp->active_rrqs_xri_bitmap);
5535 /* FIND node did <did> NOT FOUND */
5536 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5537 "0932 FIND node did x%x NOT FOUND.\n", did);
5541 struct lpfc_nodelist *
5542 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5544 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5545 struct lpfc_nodelist *ndlp;
5546 unsigned long iflags;
5548 spin_lock_irqsave(shost->host_lock, iflags);
5549 ndlp = __lpfc_findnode_did(vport, did);
5550 spin_unlock_irqrestore(shost->host_lock, iflags);
5554 struct lpfc_nodelist *
5555 lpfc_findnode_mapped(struct lpfc_vport *vport)
5557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5558 struct lpfc_nodelist *ndlp;
5560 unsigned long iflags;
5562 spin_lock_irqsave(shost->host_lock, iflags);
5564 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5565 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5566 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5567 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5568 ((uint32_t)ndlp->nlp_xri << 16) |
5569 ((uint32_t)ndlp->nlp_type << 8) |
5570 ((uint32_t)ndlp->nlp_rpi & 0xff));
5571 spin_unlock_irqrestore(shost->host_lock, iflags);
5572 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5573 "2025 FIND node DID "
5574 "Data: x%px x%x x%x x%x x%px\n",
5575 ndlp, ndlp->nlp_DID,
5576 ndlp->nlp_flag, data1,
5577 ndlp->active_rrqs_xri_bitmap);
5581 spin_unlock_irqrestore(shost->host_lock, iflags);
5583 /* FIND node did <did> NOT FOUND */
5584 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5585 "2026 FIND mapped did NOT FOUND.\n");
5589 struct lpfc_nodelist *
5590 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5592 struct lpfc_nodelist *ndlp;
5594 ndlp = lpfc_findnode_did(vport, did);
5596 if (vport->phba->nvmet_support)
5598 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5599 lpfc_rscn_payload_check(vport, did) == 0)
5601 ndlp = lpfc_nlp_init(vport, did);
5604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5606 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5607 "6453 Setup New Node 2B_DISC x%x "
5608 "Data:x%x x%x x%x\n",
5609 ndlp->nlp_DID, ndlp->nlp_flag,
5610 ndlp->nlp_state, vport->fc_flag);
5612 spin_lock_irq(&ndlp->lock);
5613 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5614 spin_unlock_irq(&ndlp->lock);
5618 /* The NVME Target does not want to actively manage an rport.
5619 * The goal is to allow the target to reset its state and clear
5620 * pending IO in preparation for the initiator to recover.
5622 if ((vport->fc_flag & FC_RSCN_MODE) &&
5623 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5624 if (lpfc_rscn_payload_check(vport, did)) {
5626 /* Since this node is marked for discovery,
5627 * delay timeout is not needed.
5629 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5631 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5632 "6455 Setup RSCN Node 2B_DISC x%x "
5633 "Data:x%x x%x x%x\n",
5634 ndlp->nlp_DID, ndlp->nlp_flag,
5635 ndlp->nlp_state, vport->fc_flag);
5637 /* NVME Target mode waits until rport is known to be
5638 * impacted by the RSCN before it transitions. No
5639 * active management - just go to NPR provided the
5640 * node had a valid login.
5642 if (vport->phba->nvmet_support)
5645 /* If we've already received a PLOGI from this NPort
5646 * we don't need to try to discover it again.
5648 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5650 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5653 ndlp->nlp_prev_state = ndlp->nlp_state;
5654 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5656 spin_lock_irq(&ndlp->lock);
5657 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5658 spin_unlock_irq(&ndlp->lock);
5660 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5661 "6456 Skip Setup RSCN Node x%x "
5662 "Data:x%x x%x x%x\n",
5663 ndlp->nlp_DID, ndlp->nlp_flag,
5664 ndlp->nlp_state, vport->fc_flag);
5668 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5669 "6457 Setup Active Node 2B_DISC x%x "
5670 "Data:x%x x%x x%x\n",
5671 ndlp->nlp_DID, ndlp->nlp_flag,
5672 ndlp->nlp_state, vport->fc_flag);
5674 /* If the initiator received a PLOGI from this NPort or if the
5675 * initiator is already in the process of discovery on it,
5676 * there's no need to try to discover it again.
5678 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5679 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5680 (!vport->phba->nvmet_support &&
5681 ndlp->nlp_flag & NLP_RCV_PLOGI))
5684 if (vport->phba->nvmet_support)
5687 /* Moving to NPR state clears unsolicited flags and
5688 * allows for rediscovery
5690 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5692 spin_lock_irq(&ndlp->lock);
5693 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5694 spin_unlock_irq(&ndlp->lock);
5699 /* Build a list of nodes to discover based on the loopmap */
5701 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5703 struct lpfc_hba *phba = vport->phba;
5705 uint32_t alpa, index;
5707 if (!lpfc_is_link_up(phba))
5710 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5713 /* Check for loop map present or not */
5714 if (phba->alpa_map[0]) {
5715 for (j = 1; j <= phba->alpa_map[0]; j++) {
5716 alpa = phba->alpa_map[j];
5717 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5719 lpfc_setup_disc_node(vport, alpa);
5722 /* No alpamap, so try all alpa's */
5723 for (j = 0; j < FC_MAXLOOP; j++) {
5724 /* If cfg_scan_down is set, start from highest
5725 * ALPA (0xef) to lowest (0x1).
5727 if (vport->cfg_scan_down)
5730 index = FC_MAXLOOP - j - 1;
5731 alpa = lpfcAlpaArray[index];
5732 if ((vport->fc_myDID & 0xff) == alpa)
5734 lpfc_setup_disc_node(vport, alpa);
5742 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5745 struct lpfc_sli *psli = &phba->sli;
5746 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5747 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5751 * if it's not a physical port or if we already send
5752 * clear_la then don't send it.
5754 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5755 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5756 (phba->sli_rev == LPFC_SLI_REV4))
5759 /* Link up discovery */
5760 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5761 phba->link_state = LPFC_CLEAR_LA;
5762 lpfc_clear_la(phba, mbox);
5763 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5764 mbox->vport = vport;
5765 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5766 if (rc == MBX_NOT_FINISHED) {
5767 mempool_free(mbox, phba->mbox_mem_pool);
5768 lpfc_disc_flush_list(vport);
5769 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5770 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5771 phba->link_state = LPFC_HBA_ERROR;
5776 /* Reg_vpi to tell firmware to resume normal operations */
5778 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5780 LPFC_MBOXQ_t *regvpimbox;
5782 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5784 lpfc_reg_vpi(vport, regvpimbox);
5785 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5786 regvpimbox->vport = vport;
5787 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5788 == MBX_NOT_FINISHED) {
5789 mempool_free(regvpimbox, phba->mbox_mem_pool);
5794 /* Start Link up / RSCN discovery on NPR nodes */
5796 lpfc_disc_start(struct lpfc_vport *vport)
5798 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5799 struct lpfc_hba *phba = vport->phba;
5801 uint32_t clear_la_pending;
5803 if (!lpfc_is_link_up(phba)) {
5804 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5805 "3315 Link is not up %x\n",
5810 if (phba->link_state == LPFC_CLEAR_LA)
5811 clear_la_pending = 1;
5813 clear_la_pending = 0;
5815 if (vport->port_state < LPFC_VPORT_READY)
5816 vport->port_state = LPFC_DISC_AUTH;
5818 lpfc_set_disctmo(vport);
5820 vport->fc_prevDID = vport->fc_myDID;
5821 vport->num_disc_nodes = 0;
5823 /* Start Discovery state <hba_state> */
5824 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5825 "0202 Start Discovery port state x%x "
5826 "flg x%x Data: x%x x%x x%x\n",
5827 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5828 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5830 /* First do ADISCs - if any */
5831 num_sent = lpfc_els_disc_adisc(vport);
5836 /* Register the VPI for SLI3, NPIV only. */
5837 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5838 !(vport->fc_flag & FC_PT2PT) &&
5839 !(vport->fc_flag & FC_RSCN_MODE) &&
5840 (phba->sli_rev < LPFC_SLI_REV4)) {
5841 lpfc_issue_clear_la(phba, vport);
5842 lpfc_issue_reg_vpi(phba, vport);
5847 * For SLI2, we need to set port_state to READY and continue
5850 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5851 /* If we get here, there is nothing to ADISC */
5852 lpfc_issue_clear_la(phba, vport);
5854 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5855 vport->num_disc_nodes = 0;
5856 /* go thru NPR nodes and issue ELS PLOGIs */
5857 if (vport->fc_npr_cnt)
5858 lpfc_els_disc_plogi(vport);
5860 if (!vport->num_disc_nodes) {
5861 spin_lock_irq(shost->host_lock);
5862 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5863 spin_unlock_irq(shost->host_lock);
5864 lpfc_can_disctmo(vport);
5867 vport->port_state = LPFC_VPORT_READY;
5869 /* Next do PLOGIs - if any */
5870 num_sent = lpfc_els_disc_plogi(vport);
5875 if (vport->fc_flag & FC_RSCN_MODE) {
5876 /* Check to see if more RSCNs came in while we
5877 * were processing this one.
5879 if ((vport->fc_rscn_id_cnt == 0) &&
5880 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5881 spin_lock_irq(shost->host_lock);
5882 vport->fc_flag &= ~FC_RSCN_MODE;
5883 spin_unlock_irq(shost->host_lock);
5884 lpfc_can_disctmo(vport);
5886 lpfc_els_handle_rscn(vport);
5893 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5894 * ring the match the sppecified nodelist.
5897 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5899 LIST_HEAD(completions);
5901 struct lpfc_iocbq *iocb, *next_iocb;
5902 struct lpfc_sli_ring *pring;
5904 pring = lpfc_phba_elsring(phba);
5905 if (unlikely(!pring))
5908 /* Error matching iocb on txq or txcmplq
5909 * First check the txq.
5911 spin_lock_irq(&phba->hbalock);
5912 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5913 if (iocb->context1 != ndlp) {
5917 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5918 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5920 list_move_tail(&iocb->list, &completions);
5924 /* Next check the txcmplq */
5925 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5926 if (iocb->context1 != ndlp) {
5930 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5931 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5932 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
5935 spin_unlock_irq(&phba->hbalock);
5937 /* Make sure HBA is alive */
5938 lpfc_issue_hb_tmo(phba);
5940 /* Cancel all the IOCBs from the completions list */
5941 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5946 lpfc_disc_flush_list(struct lpfc_vport *vport)
5948 struct lpfc_nodelist *ndlp, *next_ndlp;
5949 struct lpfc_hba *phba = vport->phba;
5951 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5952 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5954 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5955 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5956 lpfc_free_tx(phba, ndlp);
5963 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5965 lpfc_els_flush_rscn(vport);
5966 lpfc_els_flush_cmd(vport);
5967 lpfc_disc_flush_list(vport);
5970 /*****************************************************************************/
5972 * NAME: lpfc_disc_timeout
5974 * FUNCTION: Fibre Channel driver discovery timeout routine.
5976 * EXECUTION ENVIRONMENT: interrupt only
5984 /*****************************************************************************/
5986 lpfc_disc_timeout(struct timer_list *t)
5988 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
5989 struct lpfc_hba *phba = vport->phba;
5990 uint32_t tmo_posted;
5991 unsigned long flags = 0;
5993 if (unlikely(!phba))
5996 spin_lock_irqsave(&vport->work_port_lock, flags);
5997 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5999 vport->work_port_events |= WORKER_DISC_TMO;
6000 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6003 lpfc_worker_wake_up(phba);
6008 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6011 struct lpfc_hba *phba = vport->phba;
6012 struct lpfc_sli *psli = &phba->sli;
6013 struct lpfc_nodelist *ndlp, *next_ndlp;
6014 LPFC_MBOXQ_t *initlinkmbox;
6015 int rc, clrlaerr = 0;
6017 if (!(vport->fc_flag & FC_DISC_TMO))
6020 spin_lock_irq(shost->host_lock);
6021 vport->fc_flag &= ~FC_DISC_TMO;
6022 spin_unlock_irq(shost->host_lock);
6024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6025 "disc timeout: state:x%x rtry:x%x flg:x%x",
6026 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6028 switch (vport->port_state) {
6030 case LPFC_LOCAL_CFG_LINK:
6032 * port_state is identically LPFC_LOCAL_CFG_LINK while
6033 * waiting for FAN timeout
6035 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6036 "0221 FAN timeout\n");
6038 /* Start discovery by sending FLOGI, clean up old rpis */
6039 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6041 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6043 if (ndlp->nlp_type & NLP_FABRIC) {
6044 /* Clean up the ndlp on Fabric connections */
6045 lpfc_drop_node(vport, ndlp);
6047 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6048 /* Fail outstanding IO now since device
6049 * is marked for PLOGI.
6051 lpfc_unreg_rpi(vport, ndlp);
6054 if (vport->port_state != LPFC_FLOGI) {
6055 if (phba->sli_rev <= LPFC_SLI_REV3)
6056 lpfc_initial_flogi(vport);
6058 lpfc_issue_init_vfi(vport);
6065 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6066 /* Initial FLOGI timeout */
6067 lpfc_printf_vlog(vport, KERN_ERR,
6069 "0222 Initial %s timeout\n",
6070 vport->vpi ? "FDISC" : "FLOGI");
6072 /* Assume no Fabric and go on with discovery.
6073 * Check for outstanding ELS FLOGI to abort.
6076 /* FLOGI failed, so just use loop map to make discovery list */
6077 lpfc_disc_list_loopmap(vport);
6079 /* Start discovery */
6080 lpfc_disc_start(vport);
6083 case LPFC_FABRIC_CFG_LINK:
6084 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6086 lpfc_printf_vlog(vport, KERN_ERR,
6088 "0223 Timeout while waiting for "
6089 "NameServer login\n");
6090 /* Next look for NameServer ndlp */
6091 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6093 lpfc_els_abort(phba, ndlp);
6095 /* ReStart discovery */
6099 /* Check for wait for NameServer Rsp timeout */
6100 lpfc_printf_vlog(vport, KERN_ERR,
6102 "0224 NameServer Query timeout "
6104 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6106 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6107 /* Try it one more time */
6108 vport->fc_ns_retry++;
6109 vport->gidft_inp = 0;
6110 rc = lpfc_issue_gidft(vport);
6114 vport->fc_ns_retry = 0;
6118 * Discovery is over.
6119 * set port_state to PORT_READY if SLI2.
6120 * cmpl_reg_vpi will set port_state to READY for SLI3.
6122 if (phba->sli_rev < LPFC_SLI_REV4) {
6123 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6124 lpfc_issue_reg_vpi(phba, vport);
6126 lpfc_issue_clear_la(phba, vport);
6127 vport->port_state = LPFC_VPORT_READY;
6131 /* Setup and issue mailbox INITIALIZE LINK command */
6132 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6133 if (!initlinkmbox) {
6134 lpfc_printf_vlog(vport, KERN_ERR,
6136 "0206 Device Discovery "
6137 "completion error\n");
6138 phba->link_state = LPFC_HBA_ERROR;
6142 lpfc_linkdown(phba);
6143 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6144 phba->cfg_link_speed);
6145 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6146 initlinkmbox->vport = vport;
6147 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6148 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6149 lpfc_set_loopback_flag(phba);
6150 if (rc == MBX_NOT_FINISHED)
6151 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6155 case LPFC_DISC_AUTH:
6156 /* Node Authentication timeout */
6157 lpfc_printf_vlog(vport, KERN_ERR,
6159 "0227 Node Authentication timeout\n");
6160 lpfc_disc_flush_list(vport);
6163 * set port_state to PORT_READY if SLI2.
6164 * cmpl_reg_vpi will set port_state to READY for SLI3.
6166 if (phba->sli_rev < LPFC_SLI_REV4) {
6167 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6168 lpfc_issue_reg_vpi(phba, vport);
6169 else { /* NPIV Not enabled */
6170 lpfc_issue_clear_la(phba, vport);
6171 vport->port_state = LPFC_VPORT_READY;
6176 case LPFC_VPORT_READY:
6177 if (vport->fc_flag & FC_RSCN_MODE) {
6178 lpfc_printf_vlog(vport, KERN_ERR,
6180 "0231 RSCN timeout Data: x%x "
6182 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6184 /* Cleanup any outstanding ELS commands */
6185 lpfc_els_flush_cmd(vport);
6187 lpfc_els_flush_rscn(vport);
6188 lpfc_disc_flush_list(vport);
6193 lpfc_printf_vlog(vport, KERN_ERR,
6195 "0273 Unexpected discovery timeout, "
6196 "vport State x%x\n", vport->port_state);
6200 switch (phba->link_state) {
6202 /* CLEAR LA timeout */
6203 lpfc_printf_vlog(vport, KERN_ERR,
6205 "0228 CLEAR LA timeout\n");
6210 lpfc_issue_clear_la(phba, vport);
6212 case LPFC_LINK_UNKNOWN:
6213 case LPFC_WARM_START:
6214 case LPFC_INIT_START:
6215 case LPFC_INIT_MBX_CMDS:
6216 case LPFC_LINK_DOWN:
6217 case LPFC_HBA_ERROR:
6218 lpfc_printf_vlog(vport, KERN_ERR,
6220 "0230 Unexpected timeout, hba link "
6221 "state x%x\n", phba->link_state);
6225 case LPFC_HBA_READY:
6230 lpfc_disc_flush_list(vport);
6231 if (phba->sli_rev != LPFC_SLI_REV4) {
6232 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6233 ~LPFC_STOP_IOCB_EVENT;
6234 psli->sli3_ring[LPFC_FCP_RING].flag &=
6235 ~LPFC_STOP_IOCB_EVENT;
6237 vport->port_state = LPFC_VPORT_READY;
6243 * This routine handles processing a NameServer REG_LOGIN mailbox
6244 * command upon completion. It is setup in the LPFC_MBOXQ
6245 * as the completion routine when the command is
6246 * handed off to the SLI layer.
6249 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6251 MAILBOX_t *mb = &pmb->u.mb;
6252 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6253 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6254 struct lpfc_vport *vport = pmb->vport;
6256 pmb->ctx_buf = NULL;
6257 pmb->ctx_ndlp = NULL;
6259 if (phba->sli_rev < LPFC_SLI_REV4)
6260 ndlp->nlp_rpi = mb->un.varWords[0];
6261 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6262 ndlp->nlp_type |= NLP_FABRIC;
6263 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6264 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6265 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6266 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6267 kref_read(&ndlp->kref),
6270 * Start issuing Fabric-Device Management Interface (FDMI) command to
6271 * 0xfffffa (FDMI well known port).
6272 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6273 * DPRT -> RPRT (vports)
6275 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6276 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6277 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6279 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6283 /* decrement the node reference count held for this callback
6287 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6289 mempool_free(pmb, phba->mbox_mem_pool);
6295 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6297 uint16_t *rpi = param;
6299 return ndlp->nlp_rpi == *rpi;
6303 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6305 return memcmp(&ndlp->nlp_portname, param,
6306 sizeof(ndlp->nlp_portname)) == 0;
6309 static struct lpfc_nodelist *
6310 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6312 struct lpfc_nodelist *ndlp;
6314 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6315 if (filter(ndlp, param)) {
6316 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6317 "3185 FIND node filter %ps DID "
6318 "ndlp x%px did x%x flg x%x st x%x "
6319 "xri x%x type x%x rpi x%x\n",
6320 filter, ndlp, ndlp->nlp_DID,
6321 ndlp->nlp_flag, ndlp->nlp_state,
6322 ndlp->nlp_xri, ndlp->nlp_type,
6327 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6328 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6333 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6334 * returns the node list element pointer else return NULL.
6336 struct lpfc_nodelist *
6337 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6339 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6343 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6344 * returns the node element list pointer else return NULL.
6346 struct lpfc_nodelist *
6347 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6350 struct lpfc_nodelist *ndlp;
6352 spin_lock_irq(shost->host_lock);
6353 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6354 spin_unlock_irq(shost->host_lock);
6359 * This routine looks up the ndlp lists for the given RPI. If the rpi
6360 * is found, the routine returns the node element list pointer else
6363 struct lpfc_nodelist *
6364 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6366 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6367 struct lpfc_nodelist *ndlp;
6368 unsigned long flags;
6370 spin_lock_irqsave(shost->host_lock, flags);
6371 ndlp = __lpfc_findnode_rpi(vport, rpi);
6372 spin_unlock_irqrestore(shost->host_lock, flags);
6377 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6378 * @phba: pointer to lpfc hba data structure.
6379 * @vpi: the physical host virtual N_Port identifier.
6381 * This routine finds a vport on a HBA (referred by @phba) through a
6382 * @vpi. The function walks the HBA's vport list and returns the address
6383 * of the vport with the matching @vpi.
6386 * NULL - No vport with the matching @vpi found
6387 * Otherwise - Address to the vport with the matching @vpi.
6390 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6392 struct lpfc_vport *vport;
6393 unsigned long flags;
6396 /* The physical ports are always vpi 0 - translate is unnecessary. */
6399 * Translate the physical vpi to the logical vpi. The
6400 * vport stores the logical vpi.
6402 for (i = 0; i <= phba->max_vpi; i++) {
6403 if (vpi == phba->vpi_ids[i])
6407 if (i > phba->max_vpi) {
6408 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6409 "2936 Could not find Vport mapped "
6410 "to vpi %d\n", vpi);
6415 spin_lock_irqsave(&phba->port_list_lock, flags);
6416 list_for_each_entry(vport, &phba->port_list, listentry) {
6417 if (vport->vpi == i) {
6418 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6422 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6426 struct lpfc_nodelist *
6427 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6429 struct lpfc_nodelist *ndlp;
6430 int rpi = LPFC_RPI_ALLOC_ERROR;
6432 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6433 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6434 if (rpi == LPFC_RPI_ALLOC_ERROR)
6438 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6440 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6441 lpfc_sli4_free_rpi(vport->phba, rpi);
6445 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6447 spin_lock_init(&ndlp->lock);
6449 lpfc_initialize_node(vport, ndlp, did);
6450 INIT_LIST_HEAD(&ndlp->nlp_listp);
6451 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6452 ndlp->nlp_rpi = rpi;
6453 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6454 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6455 "flg:x%x refcnt:%d\n",
6456 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6457 ndlp->nlp_flag, kref_read(&ndlp->kref));
6459 ndlp->active_rrqs_xri_bitmap =
6460 mempool_alloc(vport->phba->active_rrq_pool,
6462 if (ndlp->active_rrqs_xri_bitmap)
6463 memset(ndlp->active_rrqs_xri_bitmap, 0,
6464 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6470 "node init: did:x%x",
6471 ndlp->nlp_DID, 0, 0);
6476 /* This routine releases all resources associated with a specifc NPort's ndlp
6477 * and mempool_free's the nodelist.
6480 lpfc_nlp_release(struct kref *kref)
6482 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6484 struct lpfc_vport *vport = ndlp->vport;
6486 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6487 "node release: did:x%x flg:x%x type:x%x",
6488 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6490 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6491 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6492 __func__, ndlp, ndlp->nlp_DID,
6493 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6495 /* remove ndlp from action. */
6496 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6497 lpfc_cleanup_node(vport, ndlp);
6499 /* Not all ELS transactions have registered the RPI with the port.
6500 * In these cases the rpi usage is temporary and the node is
6501 * released when the WQE is completed. Catch this case to free the
6502 * RPI to the pool. Because this node is in the release path, a lock
6503 * is unnecessary. All references are gone and the node has been
6506 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6507 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6508 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6509 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6510 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6514 /* The node is not freed back to memory, it is released to a pool so
6515 * the node fields need to be cleaned up.
6518 ndlp->nlp_state = NLP_STE_FREED_NODE;
6520 ndlp->fc4_xpt_flags = 0;
6522 /* free ndlp memory for final ndlp release */
6523 kfree(ndlp->lat_data);
6524 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6525 mempool_free(ndlp->active_rrqs_xri_bitmap,
6526 ndlp->phba->active_rrq_pool);
6527 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6530 /* This routine bumps the reference count for a ndlp structure to ensure
6531 * that one discovery thread won't free a ndlp while another discovery thread
6534 struct lpfc_nodelist *
6535 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6537 unsigned long flags;
6540 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6541 "node get: did:x%x flg:x%x refcnt:x%x",
6542 ndlp->nlp_DID, ndlp->nlp_flag,
6543 kref_read(&ndlp->kref));
6545 /* The check of ndlp usage to prevent incrementing the
6546 * ndlp reference count that is in the process of being
6549 spin_lock_irqsave(&ndlp->lock, flags);
6550 if (!kref_get_unless_zero(&ndlp->kref)) {
6551 spin_unlock_irqrestore(&ndlp->lock, flags);
6552 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6553 "0276 %s: ndlp:x%px refcnt:%d\n",
6554 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6557 spin_unlock_irqrestore(&ndlp->lock, flags);
6559 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6565 /* This routine decrements the reference count for a ndlp structure. If the
6566 * count goes to 0, this indicates the associated nodelist should be freed.
6569 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6572 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6573 "node put: did:x%x flg:x%x refcnt:x%x",
6574 ndlp->nlp_DID, ndlp->nlp_flag,
6575 kref_read(&ndlp->kref));
6577 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6580 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6583 /* This routine free's the specified nodelist if it is not in use
6584 * by any other discovery thread. This routine returns 1 if the
6585 * ndlp has been freed. A return value of 0 indicates the ndlp is
6586 * not yet been released.
6589 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6591 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6592 "node not used: did:x%x flg:x%x refcnt:x%x",
6593 ndlp->nlp_DID, ndlp->nlp_flag,
6594 kref_read(&ndlp->kref));
6596 if (kref_read(&ndlp->kref) == 1)
6597 if (lpfc_nlp_put(ndlp))
6603 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6604 * @phba: Pointer to hba context object.
6606 * This function iterate through all FC nodes associated
6607 * will all vports to check if there is any node with
6608 * fc_rports associated with it. If there is an fc_rport
6609 * associated with the node, then the node is either in
6610 * discovered state or its devloss_timer is pending.
6613 lpfc_fcf_inuse(struct lpfc_hba *phba)
6615 struct lpfc_vport **vports;
6617 struct lpfc_nodelist *ndlp;
6618 struct Scsi_Host *shost;
6620 vports = lpfc_create_vport_work_array(phba);
6622 /* If driver cannot allocate memory, indicate fcf is in use */
6626 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6627 shost = lpfc_shost_from_vport(vports[i]);
6628 spin_lock_irq(shost->host_lock);
6630 * IF the CVL_RCVD bit is not set then we have sent the
6632 * If dev_loss fires while we are waiting we do not want to
6635 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6636 spin_unlock_irq(shost->host_lock);
6640 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6642 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6644 spin_unlock_irq(shost->host_lock);
6646 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6648 lpfc_printf_log(phba, KERN_INFO,
6649 LOG_NODE | LOG_DISCOVERY,
6650 "2624 RPI %x DID %x flag %x "
6651 "still logged in\n",
6652 ndlp->nlp_rpi, ndlp->nlp_DID,
6656 spin_unlock_irq(shost->host_lock);
6659 lpfc_destroy_vport_work_array(phba, vports);
6664 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6665 * @phba: Pointer to hba context object.
6666 * @mboxq: Pointer to mailbox object.
6668 * This function frees memory associated with the mailbox command.
6671 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6673 struct lpfc_vport *vport = mboxq->vport;
6674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6676 if (mboxq->u.mb.mbxStatus) {
6677 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6678 "2555 UNREG_VFI mbxStatus error x%x "
6680 mboxq->u.mb.mbxStatus, vport->port_state);
6682 spin_lock_irq(shost->host_lock);
6683 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6684 spin_unlock_irq(shost->host_lock);
6685 mempool_free(mboxq, phba->mbox_mem_pool);
6690 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6691 * @phba: Pointer to hba context object.
6692 * @mboxq: Pointer to mailbox object.
6694 * This function frees memory associated with the mailbox command.
6697 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6699 struct lpfc_vport *vport = mboxq->vport;
6701 if (mboxq->u.mb.mbxStatus) {
6702 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6703 "2550 UNREG_FCFI mbxStatus error x%x "
6705 mboxq->u.mb.mbxStatus, vport->port_state);
6707 mempool_free(mboxq, phba->mbox_mem_pool);
6712 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6713 * @phba: Pointer to hba context object.
6715 * This function prepare the HBA for unregistering the currently registered
6716 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6720 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6722 struct lpfc_vport **vports;
6723 struct lpfc_nodelist *ndlp;
6724 struct Scsi_Host *shost;
6727 /* Unregister RPIs */
6728 if (lpfc_fcf_inuse(phba))
6729 lpfc_unreg_hba_rpis(phba);
6731 /* At this point, all discovery is aborted */
6732 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6734 /* Unregister VPIs */
6735 vports = lpfc_create_vport_work_array(phba);
6736 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6737 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6738 /* Stop FLOGI/FDISC retries */
6739 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6741 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6742 lpfc_cleanup_pending_mbox(vports[i]);
6743 if (phba->sli_rev == LPFC_SLI_REV4)
6744 lpfc_sli4_unreg_all_rpis(vports[i]);
6745 lpfc_mbx_unreg_vpi(vports[i]);
6746 shost = lpfc_shost_from_vport(vports[i]);
6747 spin_lock_irq(shost->host_lock);
6748 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6749 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6750 spin_unlock_irq(shost->host_lock);
6752 lpfc_destroy_vport_work_array(phba, vports);
6753 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6754 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6756 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6757 lpfc_cleanup_pending_mbox(phba->pport);
6758 if (phba->sli_rev == LPFC_SLI_REV4)
6759 lpfc_sli4_unreg_all_rpis(phba->pport);
6760 lpfc_mbx_unreg_vpi(phba->pport);
6761 shost = lpfc_shost_from_vport(phba->pport);
6762 spin_lock_irq(shost->host_lock);
6763 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6764 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6765 spin_unlock_irq(shost->host_lock);
6768 /* Cleanup any outstanding ELS commands */
6769 lpfc_els_flush_all_cmd(phba);
6771 /* Unregister the physical port VFI */
6772 rc = lpfc_issue_unreg_vfi(phba->pport);
6777 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6778 * @phba: Pointer to hba context object.
6780 * This function issues synchronous unregister FCF mailbox command to HBA to
6781 * unregister the currently registered FCF record. The driver does not reset
6782 * the driver FCF usage state flags.
6784 * Return 0 if successfully issued, none-zero otherwise.
6787 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6792 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6794 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6795 "2551 UNREG_FCFI mbox allocation failed"
6796 "HBA state x%x\n", phba->pport->port_state);
6799 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6800 mbox->vport = phba->pport;
6801 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6802 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6804 if (rc == MBX_NOT_FINISHED) {
6805 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6806 "2552 Unregister FCFI command failed rc x%x "
6808 rc, phba->pport->port_state);
6815 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6816 * @phba: Pointer to hba context object.
6818 * This function unregisters the currently reigstered FCF. This function
6819 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6822 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6826 /* Preparation for unregistering fcf */
6827 rc = lpfc_unregister_fcf_prep(phba);
6829 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6830 "2748 Failed to prepare for unregistering "
6831 "HBA's FCF record: rc=%d\n", rc);
6835 /* Now, unregister FCF record and reset HBA FCF state */
6836 rc = lpfc_sli4_unregister_fcf(phba);
6839 /* Reset HBA FCF states after successful unregister FCF */
6840 phba->fcf.fcf_flag = 0;
6841 phba->fcf.current_rec.flag = 0;
6844 * If driver is not unloading, check if there is any other
6845 * FCF record that can be used for discovery.
6847 if ((phba->pport->load_flag & FC_UNLOADING) ||
6848 (phba->link_state < LPFC_LINK_UP))
6851 /* This is considered as the initial FCF discovery scan */
6852 spin_lock_irq(&phba->hbalock);
6853 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6854 spin_unlock_irq(&phba->hbalock);
6856 /* Reset FCF roundrobin bmask for new discovery */
6857 lpfc_sli4_clear_fcf_rr_bmask(phba);
6859 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6862 spin_lock_irq(&phba->hbalock);
6863 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6864 spin_unlock_irq(&phba->hbalock);
6865 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6866 "2553 lpfc_unregister_unused_fcf failed "
6867 "to read FCF record HBA state x%x\n",
6868 phba->pport->port_state);
6873 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6874 * @phba: Pointer to hba context object.
6876 * This function just unregisters the currently reigstered FCF. It does not
6877 * try to find another FCF for discovery.
6880 lpfc_unregister_fcf(struct lpfc_hba *phba)
6884 /* Preparation for unregistering fcf */
6885 rc = lpfc_unregister_fcf_prep(phba);
6887 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6888 "2749 Failed to prepare for unregistering "
6889 "HBA's FCF record: rc=%d\n", rc);
6893 /* Now, unregister FCF record and reset HBA FCF state */
6894 rc = lpfc_sli4_unregister_fcf(phba);
6897 /* Set proper HBA FCF states after successful unregister FCF */
6898 spin_lock_irq(&phba->hbalock);
6899 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6900 spin_unlock_irq(&phba->hbalock);
6904 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6905 * @phba: Pointer to hba context object.
6907 * This function check if there are any connected remote port for the FCF and
6908 * if all the devices are disconnected, this function unregister FCFI.
6909 * This function also tries to use another FCF for discovery.
6912 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6915 * If HBA is not running in FIP mode, if HBA does not support
6916 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6917 * registered, do nothing.
6919 spin_lock_irq(&phba->hbalock);
6920 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6921 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6922 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6923 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6924 (phba->pport->port_state == LPFC_FLOGI)) {
6925 spin_unlock_irq(&phba->hbalock);
6928 spin_unlock_irq(&phba->hbalock);
6930 if (lpfc_fcf_inuse(phba))
6933 lpfc_unregister_fcf_rescan(phba);
6937 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6938 * @phba: Pointer to hba context object.
6939 * @buff: Buffer containing the FCF connection table as in the config
6941 * This function create driver data structure for the FCF connection
6942 * record table read from config region 23.
6945 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6948 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6949 struct lpfc_fcf_conn_hdr *conn_hdr;
6950 struct lpfc_fcf_conn_rec *conn_rec;
6951 uint32_t record_count;
6954 /* Free the current connect table */
6955 list_for_each_entry_safe(conn_entry, next_conn_entry,
6956 &phba->fcf_conn_rec_list, list) {
6957 list_del_init(&conn_entry->list);
6961 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6962 record_count = conn_hdr->length * sizeof(uint32_t)/
6963 sizeof(struct lpfc_fcf_conn_rec);
6965 conn_rec = (struct lpfc_fcf_conn_rec *)
6966 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6968 for (i = 0; i < record_count; i++) {
6969 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6971 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6975 "2566 Failed to allocate connection"
6980 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6981 sizeof(struct lpfc_fcf_conn_rec));
6982 list_add_tail(&conn_entry->list,
6983 &phba->fcf_conn_rec_list);
6986 if (!list_empty(&phba->fcf_conn_rec_list)) {
6988 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6990 conn_rec = &conn_entry->conn_rec;
6991 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6992 "3345 FCF connection list rec[%02d]: "
6993 "flags:x%04x, vtag:x%04x, "
6994 "fabric_name:x%02x:%02x:%02x:%02x:"
6995 "%02x:%02x:%02x:%02x, "
6996 "switch_name:x%02x:%02x:%02x:%02x:"
6997 "%02x:%02x:%02x:%02x\n", i++,
6998 conn_rec->flags, conn_rec->vlan_tag,
6999 conn_rec->fabric_name[0],
7000 conn_rec->fabric_name[1],
7001 conn_rec->fabric_name[2],
7002 conn_rec->fabric_name[3],
7003 conn_rec->fabric_name[4],
7004 conn_rec->fabric_name[5],
7005 conn_rec->fabric_name[6],
7006 conn_rec->fabric_name[7],
7007 conn_rec->switch_name[0],
7008 conn_rec->switch_name[1],
7009 conn_rec->switch_name[2],
7010 conn_rec->switch_name[3],
7011 conn_rec->switch_name[4],
7012 conn_rec->switch_name[5],
7013 conn_rec->switch_name[6],
7014 conn_rec->switch_name[7]);
7020 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7021 * @phba: Pointer to hba context object.
7022 * @buff: Buffer containing the FCoE parameter data structure.
7024 * This function update driver data structure with config
7025 * parameters read from config region 23.
7028 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7031 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7032 struct lpfc_fcoe_params *fcoe_param;
7034 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7036 fcoe_param = (struct lpfc_fcoe_params *)
7037 (buff + sizeof(struct lpfc_fip_param_hdr));
7039 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7040 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7043 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7044 phba->valid_vlan = 1;
7045 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7049 phba->fc_map[0] = fcoe_param->fc_map[0];
7050 phba->fc_map[1] = fcoe_param->fc_map[1];
7051 phba->fc_map[2] = fcoe_param->fc_map[2];
7056 * lpfc_get_rec_conf23 - Get a record type in config region data.
7057 * @buff: Buffer containing config region 23 data.
7058 * @size: Size of the data buffer.
7059 * @rec_type: Record type to be searched.
7061 * This function searches config region data to find the beginning
7062 * of the record specified by record_type. If record found, this
7063 * function return pointer to the record else return NULL.
7066 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7068 uint32_t offset = 0, rec_length;
7070 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7071 (size < sizeof(uint32_t)))
7074 rec_length = buff[offset + 1];
7077 * One TLV record has one word header and number of data words
7078 * specified in the rec_length field of the record header.
7080 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7082 if (buff[offset] == rec_type)
7083 return &buff[offset];
7085 if (buff[offset] == LPFC_REGION23_LAST_REC)
7088 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7089 rec_length = buff[offset + 1];
7095 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7096 * @phba: Pointer to lpfc_hba data structure.
7097 * @buff: Buffer containing config region 23 data.
7098 * @size: Size of the data buffer.
7100 * This function parses the FCoE config parameters in config region 23 and
7101 * populate driver data structure with the parameters.
7104 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7108 uint32_t offset = 0;
7112 * If data size is less than 2 words signature and version cannot be
7115 if (size < 2*sizeof(uint32_t))
7118 /* Check the region signature first */
7119 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7120 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7121 "2567 Config region 23 has bad signature\n");
7127 /* Check the data structure version */
7128 if (buff[offset] != LPFC_REGION23_VERSION) {
7129 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7130 "2568 Config region 23 has bad version\n");
7135 /* Read FCoE param record */
7136 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7137 size - offset, FCOE_PARAM_TYPE);
7139 lpfc_read_fcoe_param(phba, rec_ptr);
7141 /* Read FCF connection table */
7142 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7143 size - offset, FCOE_CONN_TBL_TYPE);
7145 lpfc_read_fcf_conn_tbl(phba, rec_ptr);