Add support to set device link down/up. Signed-off-by: Jiawen Wu <jiawe...@trustnetic.com> --- doc/guides/rel_notes/release_22_11.rst | 4 ++++ drivers/net/ngbe/base/ngbe_phy.c | 1 + drivers/net/ngbe/base/ngbe_phy_rtl.c | 13 ++++++++++++ drivers/net/ngbe/base/ngbe_phy_rtl.h | 2 ++ drivers/net/ngbe/ngbe_ethdev.c | 28 ++++++++++++++++++++++++++ 5 files changed, 48 insertions(+)
diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index 8c021cf050..843501c7c2 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -84,6 +84,10 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* **Updated Wangxun ngbe driver.** + + * Added support to set device link down/up. + ABI Changes ----------- diff --git a/drivers/net/ngbe/base/ngbe_phy.c b/drivers/net/ngbe/base/ngbe_phy.c index 06562b594f..acff7bfebf 100644 --- a/drivers/net/ngbe/base/ngbe_phy.c +++ b/drivers/net/ngbe/base/ngbe_phy.c @@ -400,6 +400,7 @@ s32 ngbe_init_phy(struct ngbe_hw *hw) hw->phy.init_hw = ngbe_init_phy_rtl; hw->phy.check_link = ngbe_check_phy_link_rtl; hw->phy.setup_link = ngbe_setup_phy_link_rtl; + hw->phy.set_phy_power = ngbe_set_phy_power_rtl; hw->phy.get_adv_pause = ngbe_get_phy_advertised_pause_rtl; hw->phy.get_lp_adv_pause = ngbe_get_phy_lp_advertised_pause_rtl; hw->phy.set_pause_adv = ngbe_set_phy_pause_adv_rtl; diff --git a/drivers/net/ngbe/base/ngbe_phy_rtl.c b/drivers/net/ngbe/base/ngbe_phy_rtl.c index 33c5e79e87..9b323624ec 100644 --- a/drivers/net/ngbe/base/ngbe_phy_rtl.c +++ b/drivers/net/ngbe/base/ngbe_phy_rtl.c @@ -393,3 +393,16 @@ s32 ngbe_check_phy_link_rtl(struct ngbe_hw *hw, u32 *speed, bool *link_up) return status; } +s32 ngbe_set_phy_power_rtl(struct ngbe_hw *hw, bool on) +{ + u16 value = 0; + + hw->phy.read_reg(hw, RTL_BMCR, 0, &value); + if (on) + value &= ~RTL_BMCR_PWDN; + else + value |= RTL_BMCR_PWDN; + hw->phy.write_reg(hw, RTL_BMCR, 0, value); + + return 0; +} diff --git a/drivers/net/ngbe/base/ngbe_phy_rtl.h b/drivers/net/ngbe/base/ngbe_phy_rtl.h index d717a1915c..b2fbc4f74d 100644 --- a/drivers/net/ngbe/base/ngbe_phy_rtl.h +++ b/drivers/net/ngbe/base/ngbe_phy_rtl.h @@ -15,6 +15,7 @@ #define RTL_BMCR_RESET MS16(15, 0x1) #define RTL_BMCR_SPEED_SELECT0 MS16(13, 0x1) #define RTL_BMCR_ANE MS16(12, 0x1) +#define RTL_BMCR_PWDN MS16(11, 0x1) #define RTL_BMCR_RESTART_AN MS16(9, 0x1) #define RTL_BMCR_DUPLEX MS16(8, 0x1) #define RTL_BMCR_SPEED_SELECT1 MS16(6, 0x1) @@ -88,5 +89,6 @@ s32 ngbe_get_phy_lp_advertised_pause_rtl(struct ngbe_hw *hw, u8 *pause_bit); s32 ngbe_set_phy_pause_adv_rtl(struct ngbe_hw *hw, u16 pause_bit); s32 ngbe_check_phy_link_rtl(struct ngbe_hw *hw, u32 *speed, bool *link_up); +s32 ngbe_set_phy_power_rtl(struct ngbe_hw *hw, bool on); #endif /* _NGBE_PHY_RTL_H_ */ diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c index 1090ba9a11..afdb3ad41f 100644 --- a/drivers/net/ngbe/ngbe_ethdev.c +++ b/drivers/net/ngbe/ngbe_ethdev.c @@ -1219,6 +1219,32 @@ ngbe_dev_stop(struct rte_eth_dev *dev) return 0; } +/* + * Set device link up: power on. + */ +static int +ngbe_dev_set_link_up(struct rte_eth_dev *dev) +{ + struct ngbe_hw *hw = ngbe_dev_hw(dev); + + hw->phy.set_phy_power(hw, true); + + return 0; +} + +/* + * Set device link down: power off. + */ +static int +ngbe_dev_set_link_down(struct rte_eth_dev *dev) +{ + struct ngbe_hw *hw = ngbe_dev_hw(dev); + + hw->phy.set_phy_power(hw, false); + + return 0; +} + /* * Reset and stop device. */ @@ -3030,6 +3056,8 @@ static const struct eth_dev_ops ngbe_eth_dev_ops = { .dev_infos_get = ngbe_dev_info_get, .dev_start = ngbe_dev_start, .dev_stop = ngbe_dev_stop, + .dev_set_link_up = ngbe_dev_set_link_up, + .dev_set_link_down = ngbe_dev_set_link_down, .dev_close = ngbe_dev_close, .dev_reset = ngbe_dev_reset, .promiscuous_enable = ngbe_dev_promiscuous_enable, -- 2.27.0