There was a bug that RX will lose the first packet when down/up port.

When PHY is configured, mac error code is reported to the MAC layer,
and MAC locked this status without unlocking. As a result, when the
first packet is reveived, MAC reports this error code and RDB dismissed
this packet.

Do MAC reset can clean MAC error code so we can fix this bug.

Signed-off-by: Zaiyu Wang <zaiyuw...@trustnetic.com>
---
 drivers/net/txgbe/base/txgbe_hw.c   | 37 +++++++++++++++++++++++++++++
 drivers/net/txgbe/base/txgbe_hw.h   |  1 +
 drivers/net/txgbe/base/txgbe_regs.h |  2 ++
 drivers/net/txgbe/txgbe_ethdev.c    |  1 +
 4 files changed, 41 insertions(+)

diff --git a/drivers/net/txgbe/base/txgbe_hw.c 
b/drivers/net/txgbe/base/txgbe_hw.c
index 86963fd078..8eae816164 100644
--- a/drivers/net/txgbe/base/txgbe_hw.c
+++ b/drivers/net/txgbe/base/txgbe_hw.c
@@ -3497,6 +3497,43 @@ txgbe_check_flash_load(struct txgbe_hw *hw, u32 
check_bit)
        return err;
 }
 
+int txgbe_reconfig_mac(struct txgbe_hw *hw)
+{
+       u32 mac_wdg_timeout;
+       u32 mac_flow_ctrl;
+
+       mac_wdg_timeout = rd32(hw, TXGBE_MAC_WDG_TIMEOUT);
+       mac_flow_ctrl = rd32(hw, TXGBE_RXFCCFG);
+
+       if (hw->bus.lan_id == 0)
+               wr32(hw, TXGBE_RST, TXGBE_RST_MAC_LAN_0);
+       else if (hw->bus.lan_id == 1)
+               wr32(hw, TXGBE_RST, TXGBE_RST_MAC_LAN_1);
+
+       /* wait for mac reset complete */
+       usec_delay(1500);
+       wr32m(hw, TXGBE_MAC_MISC_CTL, TXGBE_MAC_MISC_LINK_STS_MOD,
+               TXGBE_LINK_BOTH_PCS_MAC);
+
+       /* receive packets that size > 2048 */
+       wr32m(hw, TXGBE_MACRXCFG,
+               TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
+
+       /* clear counters on read */
+       wr32m(hw, TXGBE_MACCNTCTL,
+               TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
+
+       wr32m(hw, TXGBE_RXFCCFG,
+               TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
+
+       wr32(hw, TXGBE_MACRXFLT, TXGBE_MACRXFLT_PROMISC);
+
+       wr32(hw, TXGBE_MAC_WDG_TIMEOUT, mac_wdg_timeout);
+       wr32(hw, TXGBE_RXFCCFG, mac_flow_ctrl);
+
+       return 0;
+}
+
 static void
 txgbe_reset_misc(struct txgbe_hw *hw)
 {
diff --git a/drivers/net/txgbe/base/txgbe_hw.h 
b/drivers/net/txgbe/base/txgbe_hw.h
index a7e9547430..1356878575 100644
--- a/drivers/net/txgbe/base/txgbe_hw.h
+++ b/drivers/net/txgbe/base/txgbe_hw.h
@@ -107,6 +107,7 @@ s32 txgbe_setup_mac_link(struct txgbe_hw *hw, u32 speed,
                               bool autoneg_wait_to_complete);
 s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw);
 void txgbe_init_mac_link_ops_sp(struct txgbe_hw *hw);
+int txgbe_reconfig_mac(struct txgbe_hw *hw);
 s32 txgbe_reset_hw(struct txgbe_hw *hw);
 s32 txgbe_start_hw_raptor(struct txgbe_hw *hw);
 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw);
diff --git a/drivers/net/txgbe/base/txgbe_regs.h 
b/drivers/net/txgbe/base/txgbe_regs.h
index e24bd1eb03..7ee7712e53 100644
--- a/drivers/net/txgbe/base/txgbe_regs.h
+++ b/drivers/net/txgbe/base/txgbe_regs.h
@@ -158,6 +158,8 @@
 #define   TXGBE_RST_SW             MS(0, 0x1)
 #define   TXGBE_RST_LAN(i)         MS(((i) + 1), 0x1)
 #define   TXGBE_RST_FW             MS(3, 0x1)
+#define   TXGBE_RST_MAC_LAN_1      MS(17, 0x1)
+#define   TXGBE_RST_MAC_LAN_0      MS(20, 0x1)
 #define   TXGBE_RST_ETH(i)         MS(((i) + 29), 0x1)
 #define   TXGBE_RST_GLB            MS(31, 0x1)
 #define   TXGBE_RST_DEFAULT        (TXGBE_RST_SW | \
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index cba1e8f2a7..a854b40b9f 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -3081,6 +3081,7 @@ txgbe_dev_link_update_share(struct rte_eth_dev *dev,
 
        /* enable mac receiver */
        if (hw->mac.type == txgbe_mac_aml || hw->mac.type == txgbe_mac_aml40) {
+               txgbe_reconfig_mac(hw);
                wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 
TXGBE_MACRXCFG_ENA);
        }
 
-- 
2.21.0.windows.1

Reply via email to