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 == RTE_ETH_LINK_FULL_DUPLEX
45 plt_info("Port %d: Link Down", (int)(eth_dev->data->port_id));
49 cnxk_eth_dev_link_status_get_cb(struct roc_nix *nix,
50 struct roc_nix_link_info *link)
52 struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
53 struct rte_eth_link eth_link;
54 struct rte_eth_dev *eth_dev;
59 eth_dev = dev->eth_dev;
63 rte_eth_linkstatus_get(eth_dev, ð_link);
65 link->status = eth_link.link_status;
66 link->speed = eth_link.link_speed;
67 link->autoneg = eth_link.link_autoneg;
68 link->full_duplex = eth_link.link_duplex;
72 cnxk_eth_dev_link_status_cb(struct roc_nix *nix, struct roc_nix_link_info *link)
74 struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
75 struct rte_eth_link eth_link;
76 struct rte_eth_dev *eth_dev;
81 eth_dev = dev->eth_dev;
82 if (!eth_dev || !eth_dev->data->dev_conf.intr_conf.lsc)
85 if (nix_wait_for_link_cfg(dev)) {
86 plt_err("Timeout waiting for link_cfg to complete");
90 eth_link.link_status = link->status;
91 eth_link.link_speed = link->speed;
92 eth_link.link_autoneg = RTE_ETH_LINK_AUTONEG;
93 eth_link.link_duplex = link->full_duplex;
96 nix_link_status_print(eth_dev, ð_link);
98 /* Update link info */
99 rte_eth_linkstatus_set(eth_dev, ð_link);
101 /* Set the flag and execute application callbacks */
102 rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
106 cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
108 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
109 struct roc_nix_link_info info;
110 struct rte_eth_link link;
113 RTE_SET_USED(wait_to_complete);
114 memset(&link, 0, sizeof(struct rte_eth_link));
116 if (!eth_dev->data->dev_started || roc_nix_is_sdp(&dev->nix))
119 if (roc_nix_is_lbk(&dev->nix)) {
120 link.link_status = RTE_ETH_LINK_UP;
121 link.link_speed = RTE_ETH_SPEED_NUM_100G;
122 link.link_autoneg = RTE_ETH_LINK_FIXED;
123 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
125 rc = roc_nix_mac_link_info_get(&dev->nix, &info);
128 link.link_status = info.status;
129 link.link_speed = info.speed;
130 link.link_autoneg = RTE_ETH_LINK_AUTONEG;
131 if (info.full_duplex)
132 link.link_duplex = info.full_duplex;
135 return rte_eth_linkstatus_set(eth_dev, &link);