1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_common.h>
6 #include <rte_ethdev_pci.h>
8 #include "otx2_ethdev.h"
11 otx2_nix_toggle_flag_link_cfg(struct otx2_eth_dev *dev, bool set)
14 dev->flags |= OTX2_LINK_CFG_IN_PROGRESS_F;
16 dev->flags &= ~OTX2_LINK_CFG_IN_PROGRESS_F;
22 nix_wait_for_link_cfg(struct otx2_eth_dev *dev)
28 if (!(dev->flags & OTX2_LINK_CFG_IN_PROGRESS_F))
38 nix_link_status_print(struct rte_eth_dev *eth_dev, struct rte_eth_link *link)
40 if (link && link->link_status)
41 otx2_info("Port %d: Link Up - speed %u Mbps - %s",
42 (int)(eth_dev->data->port_id),
43 (uint32_t)link->link_speed,
44 link->link_duplex == ETH_LINK_FULL_DUPLEX ?
45 "full-duplex" : "half-duplex");
47 otx2_info("Port %d: Link Down", (int)(eth_dev->data->port_id));
51 otx2_eth_dev_link_status_update(struct otx2_dev *dev,
52 struct cgx_link_user_info *link)
54 struct otx2_eth_dev *otx2_dev = (struct otx2_eth_dev *)dev;
55 struct rte_eth_link eth_link;
56 struct rte_eth_dev *eth_dev;
61 eth_dev = otx2_dev->eth_dev;
62 if (!eth_dev || !eth_dev->data->dev_conf.intr_conf.lsc)
65 if (nix_wait_for_link_cfg(otx2_dev)) {
66 otx2_err("Timeout waiting for link_cfg to complete");
70 eth_link.link_status = link->link_up;
71 eth_link.link_speed = link->speed;
72 eth_link.link_autoneg = ETH_LINK_AUTONEG;
73 eth_link.link_duplex = link->full_duplex;
76 nix_link_status_print(eth_dev, ð_link);
78 /* Update link info */
79 rte_eth_linkstatus_set(eth_dev, ð_link);
81 /* Set the flag and execute application callbacks */
82 _rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
86 lbk_link_update(struct rte_eth_link *link)
88 link->link_status = ETH_LINK_UP;
89 link->link_speed = ETH_SPEED_NUM_100G;
90 link->link_autoneg = ETH_LINK_FIXED;
91 link->link_duplex = ETH_LINK_FULL_DUPLEX;
96 cgx_link_update(struct otx2_eth_dev *dev, struct rte_eth_link *link)
98 struct otx2_mbox *mbox = dev->mbox;
99 struct cgx_link_info_msg *rsp;
101 otx2_mbox_alloc_msg_cgx_get_linkinfo(mbox);
102 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
106 link->link_status = rsp->link_info.link_up;
107 link->link_speed = rsp->link_info.speed;
108 link->link_autoneg = ETH_LINK_AUTONEG;
110 if (rsp->link_info.full_duplex)
111 link->link_duplex = rsp->link_info.full_duplex;
116 otx2_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
118 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
119 struct rte_eth_link link;
122 RTE_SET_USED(wait_to_complete);
123 memset(&link, 0, sizeof(struct rte_eth_link));
125 if (otx2_dev_is_sdp(dev))
128 if (otx2_dev_is_lbk(dev))
129 rc = lbk_link_update(&link);
131 rc = cgx_link_update(dev, &link);
136 return rte_eth_linkstatus_set(eth_dev, &link);
140 nix_dev_set_link_state(struct rte_eth_dev *eth_dev, uint8_t enable)
142 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
143 struct otx2_mbox *mbox = dev->mbox;
144 struct cgx_set_link_state_msg *req;
146 req = otx2_mbox_alloc_msg_cgx_set_link_state(mbox);
147 req->enable = enable;
148 return otx2_mbox_process(mbox);
152 otx2_nix_dev_set_link_up(struct rte_eth_dev *eth_dev)
154 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
157 if (otx2_dev_is_vf_or_sdp(dev))
160 rc = nix_dev_set_link_state(eth_dev, 1);
164 /* Start tx queues */
165 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
166 otx2_nix_tx_queue_start(eth_dev, i);
173 otx2_nix_dev_set_link_down(struct rte_eth_dev *eth_dev)
175 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
178 if (otx2_dev_is_vf_or_sdp(dev))
182 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
183 otx2_nix_tx_queue_stop(eth_dev, i);
185 return nix_dev_set_link_state(eth_dev, 0);