diff mbox series

[v2,14/26] net/ngbe: add loopback mode

Message ID 20211021095023.18288-15-jiawenwu@trustnetic.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers show
Series net/ngbe: add many features | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jiawen Wu Oct. 21, 2021, 9:50 a.m. UTC
Support loopback operation mode.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 drivers/net/ngbe/ngbe_ethdev.c |  6 ++++++
 drivers/net/ngbe/ngbe_rxtx.c   | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 121e78973e..b91437840e 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -926,6 +926,10 @@  ngbe_dev_start(struct rte_eth_dev *dev)
 		goto error;
 	}
 
+	/* Skip link setup if loopback mode is enabled. */
+	if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
+		goto skip_link_setup;
+
 	err = hw->mac.check_link(hw, &speed, &link_up, 0);
 	if (err != 0)
 		goto error;
@@ -969,6 +973,8 @@  ngbe_dev_start(struct rte_eth_dev *dev)
 	if (err != 0)
 		goto error;
 
+skip_link_setup:
+
 	if (rte_intr_allow_others(intr_handle)) {
 		ngbe_dev_misc_interrupt_setup(dev);
 		/* check if lsc interrupt is enabled */
diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c
index 9bcd2612fc..f2bc90b7e7 100644
--- a/drivers/net/ngbe/ngbe_rxtx.c
+++ b/drivers/net/ngbe/ngbe_rxtx.c
@@ -2468,6 +2468,17 @@  ngbe_dev_rx_init(struct rte_eth_dev *dev)
 	wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
 		NGBE_FRMSZ_MAX(dev->data->mtu + NGBE_ETH_OVERHEAD));
 
+	/*
+	 * If loopback mode is configured, set LPBK bit.
+	 */
+	hlreg0 = rd32(hw, NGBE_PSRCTL);
+	if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
+		hlreg0 |= NGBE_PSRCTL_LBENA;
+	else
+		hlreg0 &= ~NGBE_PSRCTL_LBENA;
+
+	wr32(hw, NGBE_PSRCTL, hlreg0);
+
 	/*
 	 * Assume no header split and no VLAN strip support
 	 * on any Rx queue first .
@@ -2586,6 +2597,19 @@  ngbe_dev_tx_init(struct rte_eth_dev *dev)
 	}
 }
 
+/*
+ * Set up link loopback mode Tx->Rx.
+ */
+static inline void
+ngbe_setup_loopback_link(struct ngbe_hw *hw)
+{
+	PMD_INIT_FUNC_TRACE();
+
+	wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_LB, NGBE_MACRXCFG_LB);
+
+	msec_delay(50);
+}
+
 /*
  * Start Transmit and Receive Units.
  */
@@ -2640,6 +2664,10 @@  ngbe_dev_rxtx_start(struct rte_eth_dev *dev)
 	rxctrl |= NGBE_PBRXCTL_ENA;
 	hw->mac.enable_rx_dma(hw, rxctrl);
 
+	/* If loopback mode is enabled, set up the link accordingly */
+	if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
+		ngbe_setup_loopback_link(hw);
+
 	return 0;
 }