Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: phy: micrel: Add Fast link failure support for lan8842

Add support for fast link failure for lan8842, when this is enabled the
PHY will detect link down immediately (~1ms). The disadvantage of this
is that also small instability might be reported as link down.
Therefore add this feature as a tunable configuration and the user will
know when to enable or not. By default it is not enabled.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20250917104630.3931969-1-horatiu.vultur@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Horatiu Vultur and committed by
Jakub Kicinski
5a26346e 38c5b9c3

+77 -2
+77 -2
drivers/net/phy/micrel.c
··· 107 107 #define LAN8814_INTC 0x18 108 108 #define LAN8814_INTS 0x1B 109 109 110 + #define LAN8814_INT_FLF BIT(15) 110 111 #define LAN8814_INT_LINK_DOWN BIT(2) 111 112 #define LAN8814_INT_LINK_UP BIT(0) 112 113 #define LAN8814_INT_LINK (LAN8814_INT_LINK_UP |\ ··· 2805 2804 2806 2805 return ret; 2807 2806 } 2807 + 2808 + /** 2809 + * LAN8814_PAGE_PCS - Selects Extended Page 0. 2810 + * 2811 + * This page contains timers used for auto-negotiation, debug registers and 2812 + * register to configure fast link failure. 2813 + */ 2814 + #define LAN8814_PAGE_PCS 0 2808 2815 2809 2816 /** 2810 2817 * LAN8814_PAGE_AFE_PMA - Selects Extended Page 1. ··· 5919 5910 if (err) 5920 5911 return err; 5921 5912 5922 - err = phy_write(phydev, LAN8814_INTC, LAN8814_INT_LINK); 5913 + err = phy_write(phydev, LAN8814_INTC, 5914 + LAN8814_INT_LINK | LAN8814_INT_FLF); 5923 5915 } else { 5924 5916 err = phy_write(phydev, LAN8814_INTC, 0); 5925 5917 if (err) ··· 5996 5986 return IRQ_NONE; 5997 5987 } 5998 5988 5999 - if (irq_status & LAN8814_INT_LINK) { 5989 + if (irq_status & (LAN8814_INT_LINK | LAN8814_INT_FLF)) { 6000 5990 phy_trigger_machine(phydev); 6001 5991 ret = IRQ_HANDLED; 6002 5992 } ··· 6063 6053 tx_errors_regs); 6064 6054 6065 6055 return 0; 6056 + } 6057 + 6058 + #define LAN8842_FLF 15 /* 0x0e */ 6059 + #define LAN8842_FLF_ENA BIT(1) 6060 + #define LAN8842_FLF_ENA_LINK_DOWN BIT(0) 6061 + 6062 + static int lan8842_get_fast_down(struct phy_device *phydev, u8 *msecs) 6063 + { 6064 + int ret; 6065 + 6066 + ret = lanphy_read_page_reg(phydev, LAN8814_PAGE_PCS, LAN8842_FLF); 6067 + if (ret < 0) 6068 + return ret; 6069 + 6070 + if (ret & LAN8842_FLF_ENA) 6071 + *msecs = ETHTOOL_PHY_FAST_LINK_DOWN_ON; 6072 + else 6073 + *msecs = ETHTOOL_PHY_FAST_LINK_DOWN_OFF; 6074 + 6075 + return 0; 6076 + } 6077 + 6078 + static int lan8842_set_fast_down(struct phy_device *phydev, const u8 *msecs) 6079 + { 6080 + u16 flf; 6081 + 6082 + switch (*msecs) { 6083 + case ETHTOOL_PHY_FAST_LINK_DOWN_OFF: 6084 + flf = 0; 6085 + break; 6086 + case ETHTOOL_PHY_FAST_LINK_DOWN_ON: 6087 + flf = LAN8842_FLF_ENA | LAN8842_FLF_ENA_LINK_DOWN; 6088 + break; 6089 + default: 6090 + return -EINVAL; 6091 + } 6092 + 6093 + return lanphy_modify_page_reg(phydev, LAN8814_PAGE_PCS, 6094 + LAN8842_FLF, 6095 + LAN8842_FLF_ENA | 6096 + LAN8842_FLF_ENA_LINK_DOWN, flf); 6097 + } 6098 + 6099 + static int lan8842_get_tunable(struct phy_device *phydev, 6100 + struct ethtool_tunable *tuna, void *data) 6101 + { 6102 + switch (tuna->id) { 6103 + case ETHTOOL_PHY_FAST_LINK_DOWN: 6104 + return lan8842_get_fast_down(phydev, data); 6105 + default: 6106 + return -EOPNOTSUPP; 6107 + } 6108 + } 6109 + 6110 + static int lan8842_set_tunable(struct phy_device *phydev, 6111 + struct ethtool_tunable *tuna, const void *data) 6112 + { 6113 + switch (tuna->id) { 6114 + case ETHTOOL_PHY_FAST_LINK_DOWN: 6115 + return lan8842_set_fast_down(phydev, data); 6116 + default: 6117 + return -EOPNOTSUPP; 6118 + } 6066 6119 } 6067 6120 6068 6121 static void lan8842_get_phy_stats(struct phy_device *phydev, ··· 6372 6299 .handle_interrupt = lan8842_handle_interrupt, 6373 6300 .get_phy_stats = lan8842_get_phy_stats, 6374 6301 .update_stats = lan8842_update_stats, 6302 + .get_tunable = lan8842_get_tunable, 6303 + .set_tunable = lan8842_set_tunable, 6375 6304 .cable_test_start = lan8814_cable_test_start, 6376 6305 .cable_test_get_status = ksz886x_cable_test_get_status, 6377 6306 }, {