1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include "cnxk_ethdev.h"
8 cnxk_nix_toggle_flag_link_cfg(struct cnxk_eth_dev *dev, bool set)
11 dev->flags |= CNXK_LINK_CFG_IN_PROGRESS_F;
13 dev->flags &= ~CNXK_LINK_CFG_IN_PROGRESS_F;
19 nix_wait_for_link_cfg(struct cnxk_eth_dev *dev)
24 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
25 if (!(dev->flags & CNXK_LINK_CFG_IN_PROGRESS_F))
35 nix_link_status_print(struct rte_eth_dev *eth_dev, struct rte_eth_link *link)
37 if (link && link->link_status)
38 plt_info("Port %d: Link Up - speed %u Mbps - %s",
39 (int)(eth_dev->data->port_id),
40 (uint32_t)link->link_speed,
41 link->link_duplex == ETH_LINK_FULL_DUPLEX
45 plt_info("Port %d: Link Down", (int)(eth_dev->data->port_id));
49 cnxk_eth_dev_link_status_cb(struct roc_nix *nix, struct roc_nix_link_info *link)
51 struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
52 struct rte_eth_link eth_link;
53 struct rte_eth_dev *eth_dev;
58 eth_dev = dev->eth_dev;
59 if (!eth_dev || !eth_dev->data->dev_conf.intr_conf.lsc)
62 if (nix_wait_for_link_cfg(dev)) {
63 plt_err("Timeout waiting for link_cfg to complete");
67 eth_link.link_status = link->status;
68 eth_link.link_speed = link->speed;
69 eth_link.link_autoneg = ETH_LINK_AUTONEG;
70 eth_link.link_duplex = link->full_duplex;
73 nix_link_status_print(eth_dev, ð_link);
75 /* Update link info */
76 rte_eth_linkstatus_set(eth_dev, ð_link);
78 /* Set the flag and execute application callbacks */
79 rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
83 cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
85 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
86 struct roc_nix_link_info info;
87 struct rte_eth_link link;
90 RTE_SET_USED(wait_to_complete);
91 memset(&link, 0, sizeof(struct rte_eth_link));
93 if (!eth_dev->data->dev_started || roc_nix_is_sdp(&dev->nix))
96 if (roc_nix_is_lbk(&dev->nix)) {
97 link.link_status = ETH_LINK_UP;
98 link.link_speed = ETH_SPEED_NUM_100G;
99 link.link_autoneg = ETH_LINK_FIXED;
100 link.link_duplex = ETH_LINK_FULL_DUPLEX;
102 rc = roc_nix_mac_link_info_get(&dev->nix, &info);
105 link.link_status = info.status;
106 link.link_speed = info.speed;
107 link.link_autoneg = ETH_LINK_AUTONEG;
108 if (info.full_duplex)
109 link.link_duplex = info.full_duplex;
112 return rte_eth_linkstatus_set(eth_dev, &link);