r8169: add support for RTL8125
Heiner Kallweit
maintainercover r8169: add support for RTL8125
This series adds support for the 2.5Gbps chip RTl8125. It can be found on PCIe network cards, and on an increasing number of consumer gaming mainboards. Series is partially based on the r8125 vendor driver. Tested with a Delock 89531 PCIe card against a Netgear GS110MX Multi-Gig switch.
Firmware isn't strictly needed, but on some systems there may be compatibility issues w/o firmware. Firmware has been submitted to linux-firmware.
Heiner Kallweit (4):
r8169: prepare for adding RTL8125 support
r8169: add support for RTL8125
r8169: add RTL8125 PHY initialization
r8169: add support for EEE on RTL8125
drivers/net/ethernet/realtek/Kconfig | 9 +- drivers/net/ethernet/realtek/r8169_main.c | 464 ++++++++++++++++++++-- 2 files changed, 443 insertions(+), 30 deletions(-)
Signature · 1 line
2.23.0
Heiner Kallweit
maintainerPATCH 1/4 r8169: prepare for adding RTL8125 support
This patch prepares the driver for adding RTL8125 support:
- change type of interrupt mask to u32
- restrict rtl_is_8168evl_up to RTL8168 chip versions
- factor out reading MAC address from registers
- re-add function rtl_get_events
- move disabling interrupt coalescing to RTL8169/RTL8168 init
- read different register for PCI commit
- don't use bit LastFrag in tx descriptor after send, RTL8125 clears it
No functional change intended.
--- drivers/net/ethernet/realtek/r8169_main.c | 44 ++++++++++++++++------- 1 file changed, 31 insertions(+), 13 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +31 -13
@@ -645,7 +645,7 @@ struct rtl8169_private {struct page *Rx_databuff[NUM_RX_DESC ];/* Rx data buffers */ struct ring_info tx_skb[NUM_TX_DESC ];/* Tx data buffers */ u16 cp_cmd; -u16 irq_mask; +u32 irq_mask;struct clk *clk;struct {
@@ -730,7 +730,8 @@ static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force)static bool rtl_is_8168evl_up (struct rtl8169_private *tp) {return tp->mac_version >=RTL_GIGA_MAC_VER_34 && - tp->mac_version !=RTL_GIGA_MAC_VER_39 ; + tp->mac_version !=RTL_GIGA_MAC_VER_39 && + tp->mac_version <=RTL_GIGA_MAC_VER_51 ; }static bool rtl_supports_eee (struct rtl8169_private *tp)
@@ -740,6 +741,14 @@ static bool rtl_supports_eee(struct rtl8169_private *tp) tp->mac_version !=RTL_GIGA_MAC_VER_39 ; } +static void rtl_read_mac_from_reg (struct rtl8169_private *tp,u8 *mac,int reg) +{ +int i; + +for (i =0 ; i <ETH_ALEN ; i++) + mac[i] =RTL_R8 (tp, reg + i); +} +struct rtl_cond {bool (*check)(struct rtl8169_private *);const char *msg;
@@ -1313,7 +1322,12 @@ static u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr) RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; } -static void rtl_ack_events (struct rtl8169_private *tp,u16 bits) +static u32 rtl_get_events (struct rtl8169_private *tp) +{ +return RTL_R16 (tp, IntrStatus); +} + +static void rtl_ack_events (struct rtl8169_private *tp,u32 bits) {RTL_W16 (tp, IntrStatus, bits); }
@@ -1337,7 +1351,7 @@ static void rtl_irq_enable(struct rtl8169_private *tp)static void rtl8169_irq_mask_and_ack (struct rtl8169_private *tp) {rtl_irq_disable (tp); -rtl_ack_events (tp,0xffff ); +rtl_ack_events (tp,0xffffffff );/* PCI commit */ RTL_R8 (tp, ChipCmd); }
@@ -5073,6 +5087,9 @@ static void rtl_hw_start_8168(struct rtl8169_private *tp)RTL_W8 (tp, MaxTxPacketSize, TxPacketMax);rtl_hw_config (tp); + +/* disable interrupt coalescing */ +RTL_W16 (tp, IntrMitigate,0x0000 ); }static void rtl_hw_start_8169 (struct rtl8169_private *tp)
@@ -5096,6 +5113,9 @@ static void rtl_hw_start_8169(struct rtl8169_private *tp)rtl8169_set_magic_reg (tp, tp->mac_version);RTL_W32 (tp, RxMissed,0 ); + +/* disable interrupt coalescing */ +RTL_W16 (tp, IntrMitigate,0x0000 ); }static void rtl_hw_start (struct rtl8169_private *tp)
@@ -5114,10 +5134,8 @@ static void rtl_hw_start(struct rtl8169_private *tp)rtl_set_rx_tx_desc_registers (tp);rtl_lock_config_regs (tp); -/* disable interrupt coalescing */ -RTL_W16 (tp, IntrMitigate,0x0000 );/* Initially a 10 us delay. Turned it into a PCI commit. - FR */ -RTL_R8 (tp, IntrMask); +RTL_R8 (tp, ChipCmd);RTL_W8 (tp, ChipCmd, CmdTxEnb | CmdRxEnb);rtl_init_rxcfg (tp);rtl_set_tx_config_registers (tp);
@@ -5695,7 +5713,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp,rtl8169_unmap_tx_skb (tp_to_dev (tp), tx_skb, tp->TxDescArray + entry); -if (status & LastFrag) { +if (tx_skb->skb) { pkts_compl++; bytes_compl += tx_skb->skb->len;napi_consume_skb (tx_skb->skb, budget);
@@ -5854,9 +5872,10 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budgetstatic irqreturn_t rtl8169_interrupt (int irq,void *dev_instance) {struct rtl8169_private *tp = dev_instance; -u16 status =RTL_R16 (tp, IntrStatus); +u32 status =rtl_get_events (tp); -if (!tp->irq_enabled || status ==0xffff || !(status & tp->irq_mask)) +if (!tp->irq_enabled || (status &0xffff ) ==0xffff || + !(status & tp->irq_mask))return IRQ_NONE ;if (unlikely (status & SYSErr)) {
@@ -6623,7 +6642,7 @@ static void rtl_init_mac_address(struct rtl8169_private *tp) {struct net_device *dev = tp->dev;u8 *mac_addr = dev->dev_addr; -int rc, i; +int rc; rc =eth_platform_get_mac_address (tp_to_dev (tp), mac_addr);if (!rc)
@@ -6633,8 +6652,7 @@ static void rtl_init_mac_address(struct rtl8169_private *tp)if (is_valid_ether_addr (mac_addr)) goto done; -for (i =0 ; i <ETH_ALEN ; i++) - mac_addr[i] =RTL_R8 (tp,MAC0 + i); +rtl_read_mac_from_reg (tp, mac_addr,MAC0 );if (is_valid_ether_addr (mac_addr)) goto done;
Signature · 1 line
2.23.0
Re: [PATCH net-next 1/4] r8169: prepare for adding RTL8125 support
Quoted 8 lines · Heiner Kallweit
This patch prepares the driver for adding RTL8125 support:
- change type of interrupt mask to u32
- restrictrtl_is_8168evl_upto RTL8168 chip versions
- factor out reading MAC address from registers
- re-add functionrtl_get_events
- move disabling interrupt coalescing to RTL8169/RTL8168 init
- read different register for PCI commit
- don't use bit LastFrag in tx descriptor after send, RTL8125 clears it
Hi Heiner
That is a lot of changes in one patch. Although there is no planned functional change, r8169 has a habit of breaking. Having lots of small changes would help tracking down which change caused a breakage, via a git bisect.
So you might want to consider splitting this up into a number of small patches.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next 1/4] r8169: prepare for adding RTL8125 support
Quoted 17 lines · Andrew Lunn
Quoted 8 lines · Heiner Kallweit
This patch prepares the driver for adding RTL8125 support:
- change type of interrupt mask to u32
- restrictrtl_is_8168evl_upto RTL8168 chip versions
- factor out reading MAC address from registers
- re-add functionrtl_get_events
- move disabling interrupt coalescing to RTL8169/RTL8168 init
- read different register for PCI commit
- don't use bit LastFrag in tx descriptor after send, RTL8125 clears itHi Heiner
That is a lot of changes in one patch. Although there is no planned functional change, r8169 has a habit of breaking. Having lots of small changes would help tracking down which change caused a breakage, via a git bisect.
Quoted 5 lines
So you might want to consider splitting this up into a number of small patches.
Andrew
Hi Andrew,
most of the changes are trivial, but you're right. I'll split this patch.
Heiner
Heiner Kallweit
maintainerPATCH 2/4 r8169: add support for RTL8125
In reply to Heiner KallweitThis adds support for 2.5Gbps chip RTL8125, it's partially based on the r8125 vendor driver. Tested with a Delock 89531 PCIe card against a Netgear GS110MX Multi-Gig switch. Firmware isn't strictly needed, but on some systems there may be compatibility issues w/o firmware. Firmware has been submitted to linux-firmware.
--- drivers/net/ethernet/realtek/Kconfig | 9 +- drivers/net/ethernet/realtek/r8169_main.c | 274 ++++++++++++++++++++-- 2 files changed, 265 insertions(+), 18 deletions(-)
drivers/net/ethernet/realtek/Kconfig +7 -2
@@ -96,14 +96,19 @@ config 8139_OLD_RX_RESET old RX-reset behavior. If unsure, say N. config R8169 - tristate "Realtek 8169 gigabit ethernet support" + tristate "Realtek 8169/8168/8101/8125 ethernet support" depends on PCI select FW_LOADER select CRC32 select PHYLIB select REALTEK_PHY ---help--- - Say Y here if you have a Realtek 8169 PCI Gigabit Ethernet adapter. + Say Y here if you have a Realtek Ethernet adapter belonging to + the following families: + RTL8169 Gigabit Ethernet + RTL8168 Gigabit Ethernet + RTL8101 Fast Ethernet + RTL8125 2.5GBit Ethernet To compile this driver as a module, choose M here: the module will be called r8169. This is recommended.
drivers/net/ethernet/realtek/r8169_main.c +258 -16
473 lines not on this page · raw message
Signature · 1 line
2.23.0
Heiner Kallweit
maintainerPATCH 3/4 r8169: add RTL8125 PHY initialization
In reply to Heiner KallweitThis patch adds PHY initialization magic copied from the r8125 vendor driver. In addition it supports loading the firmware for chip version RTL_GIGA_MAC_VER_61.
--- drivers/net/ethernet/realtek/r8169_main.c | 130 +++++++++++++++++++++- 1 file changed, 127 insertions(+), 3 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +127 -3
@@ -55,6 +55,7 @@#define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw"#define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw"#define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" +#define FIRMWARE_8125A_3 "rtl_nic/rtl8125a-3.fw"#define R8169_MSG_DEFAULT \ (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
@@ -203,7 +204,7 @@ static const struct { [RTL_GIGA_MAC_VER_50] = {"RTL8168ep/8111ep" }, [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" }, [RTL_GIGA_MAC_VER_60] = {"RTL8125" }, - [RTL_GIGA_MAC_VER_61] = {"RTL8125" }, + [RTL_GIGA_MAC_VER_61] = {"RTL8125", FIRMWARE_8125A_3}, };static const struct pci_device_id rtl8169_pci_tbl[] = {
@@ -714,6 +715,7 @@ MODULE_FIRMWARE(FIRMWARE_8168H_1);MODULE_FIRMWARE (FIRMWARE_8168H_2 );MODULE_FIRMWARE (FIRMWARE_8107E_1 );MODULE_FIRMWARE (FIRMWARE_8107E_2 ); +MODULE_FIRMWARE (FIRMWARE_8125A_3 );static inline struct device *tp_to_dev (struct rtl8169_private *tp) {
@@ -3619,6 +3621,128 @@ static void rtl8106e_hw_phy_config(struct rtl8169_private *tp)rtl_eri_write (tp,0x1d0 ,ERIAR_MASK_0011 ,0x0000 ); } +static void rtl8125_1_hw_phy_config (struct rtl8169_private *tp) +{ +struct phy_device *phydev = tp->phydev; + +phy_modify_paged (phydev,0xad4 ,0x10 ,0x03ff ,0x0084 ); +phy_modify_paged (phydev,0xad4 ,0x17 ,0x0000 ,0x0010 ); +phy_modify_paged (phydev,0xad1 ,0x13 ,0x03ff ,0x0006 ); +phy_modify_paged (phydev,0xad3 ,0x11 ,0x003f ,0x0006 ); +phy_modify_paged (phydev,0xac0 ,0x14 ,0x0000 ,0x1100 ); +phy_modify_paged (phydev,0xac8 ,0x15 ,0xf000 ,0x7000 ); +phy_modify_paged (phydev,0xad1 ,0x14 ,0x0000 ,0x0400 ); +phy_modify_paged (phydev,0xad1 ,0x15 ,0x0000 ,0x03ff ); +phy_modify_paged (phydev,0xad1 ,0x16 ,0x0000 ,0x03ff ); + +phy_write (phydev,0x1f ,0x0a43 ); +phy_write (phydev,0x13 ,0x80ea ); +phy_modify (phydev,0x14 ,0xff00 ,0xc400 ); +phy_write (phydev,0x13 ,0x80eb ); +phy_modify (phydev,0x14 ,0x0700 ,0x0300 ); +phy_write (phydev,0x13 ,0x80f8 ); +phy_modify (phydev,0x14 ,0xff00 ,0x1c00 ); +phy_write (phydev,0x13 ,0x80f1 ); +phy_modify (phydev,0x14 ,0xff00 ,0x3000 ); +phy_write (phydev,0x13 ,0x80fe ); +phy_modify (phydev,0x14 ,0xff00 ,0xa500 ); +phy_write (phydev,0x13 ,0x8102 ); +phy_modify (phydev,0x14 ,0xff00 ,0x5000 ); +phy_write (phydev,0x13 ,0x8105 ); +phy_modify (phydev,0x14 ,0xff00 ,0x3300 ); +phy_write (phydev,0x13 ,0x8100 ); +phy_modify (phydev,0x14 ,0xff00 ,0x7000 ); +phy_write (phydev,0x13 ,0x8104 ); +phy_modify (phydev,0x14 ,0xff00 ,0xf000 ); +phy_write (phydev,0x13 ,0x8106 ); +phy_modify (phydev,0x14 ,0xff00 ,0x6500 ); +phy_write (phydev,0x13 ,0x80dc ); +phy_modify (phydev,0x14 ,0xff00 ,0xed00 ); +phy_write (phydev,0x13 ,0x80df ); +phy_set_bits (phydev,0x14 ,BIT (8 )); +phy_write (phydev,0x13 ,0x80e1 ); +phy_clear_bits (phydev,0x14 ,BIT (8 )); +phy_write (phydev,0x1f ,0x0000 ); + +phy_modify_paged (phydev,0xbf0 ,0x13 ,0x003f ,0x0038 ); +phy_write_paged (phydev,0xa43 ,0x13 ,0x819f ); +phy_write_paged (phydev,0xa43 ,0x14 ,0xd0b6 ); + +phy_write_paged (phydev,0xbc3 ,0x12 ,0x5555 ); +phy_modify_paged (phydev,0xbf0 ,0x15 ,0x0e00 ,0x0a00 ); +phy_modify_paged (phydev,0xa5c ,0x10 ,0x0400 ,0x0000 ); +phy_modify_paged (phydev,0xa44 ,0x11 ,0x0000 ,0x0800 ); +} + +static void rtl8125_2_hw_phy_config (struct rtl8169_private *tp) +{ +struct phy_device *phydev = tp->phydev; +int i; + +phy_modify_paged (phydev,0xad4 ,0x17 ,0x0000 ,0x0010 ); +phy_modify_paged (phydev,0xad1 ,0x13 ,0x03ff ,0x03ff ); +phy_modify_paged (phydev,0xad3 ,0x11 ,0x003f ,0x0006 ); +phy_modify_paged (phydev,0xac0 ,0x14 ,0x1100 ,0x0000 ); +phy_modify_paged (phydev,0xacc ,0x10 ,0x0003 ,0x0002 ); +phy_modify_paged (phydev,0xad4 ,0x10 ,0x00e7 ,0x0044 ); +phy_modify_paged (phydev,0xac1 ,0x12 ,0x0080 ,0x0000 ); +phy_modify_paged (phydev,0xac8 ,0x10 ,0x0300 ,0x0000 ); +phy_modify_paged (phydev,0xac5 ,0x17 ,0x0007 ,0x0002 ); +phy_write_paged (phydev,0xad4 ,0x16 ,0x00a8 ); +phy_write_paged (phydev,0xac5 ,0x16 ,0x01ff ); +phy_modify_paged (phydev,0xac8 ,0x15 ,0x00f0 ,0x0030 ); + +phy_write (phydev,0x1f ,0x0b87 ); +phy_write (phydev,0x16 ,0x80a2 ); +phy_write (phydev,0x17 ,0x0153 ); +phy_write (phydev,0x16 ,0x809c ); +phy_write (phydev,0x17 ,0x0153 ); +phy_write (phydev,0x1f ,0x0000 ); + +phy_write (phydev,0x1f ,0x0a43 ); +phy_write (phydev,0x13 ,0x81B3 ); +phy_write (phydev,0x14 ,0x0043 ); +phy_write (phydev,0x14 ,0x00A7 ); +phy_write (phydev,0x14 ,0x00D6 ); +phy_write (phydev,0x14 ,0x00EC ); +phy_write (phydev,0x14 ,0x00F6 ); +phy_write (phydev,0x14 ,0x00FB ); +phy_write (phydev,0x14 ,0x00FD ); +phy_write (phydev,0x14 ,0x00FF ); +phy_write (phydev,0x14 ,0x00BB ); +phy_write (phydev,0x14 ,0x0058 ); +phy_write (phydev,0x14 ,0x0029 ); +phy_write (phydev,0x14 ,0x0013 ); +phy_write (phydev,0x14 ,0x0009 ); +phy_write (phydev,0x14 ,0x0004 ); +phy_write (phydev,0x14 ,0x0002 ); +for (i =0 ; i <25 ; i++) +phy_write (phydev,0x14 ,0x0000 ); + +phy_write (phydev,0x13 ,0x8257 ); +phy_write (phydev,0x14 ,0x020F ); + +phy_write (phydev,0x13 ,0x80EA ); +phy_write (phydev,0x14 ,0x7843 ); +phy_write (phydev,0x1f ,0x0000 ); + +rtl_apply_firmware (tp); + +phy_modify_paged (phydev,0xd06 ,0x14 ,0x0000 ,0x2000 ); + +phy_write (phydev,0x1f ,0x0a43 ); +phy_write (phydev,0x13 ,0x81a2 ); +phy_set_bits (phydev,0x14 ,BIT (8 )); +phy_write (phydev,0x1f ,0x0000 ); + +phy_modify_paged (phydev,0xb54 ,0x16 ,0xff00 ,0xdb00 ); +phy_modify_paged (phydev,0xa45 ,0x12 ,0x0001 ,0x0000 ); +phy_modify_paged (phydev,0xa5d ,0x12 ,0x0000 ,0x0020 ); +phy_modify_paged (phydev,0xad4 ,0x17 ,0x0010 ,0x0000 ); +phy_modify_paged (phydev,0xa86 ,0x15 ,0x0001 ,0x0000 ); +phy_modify_paged (phydev,0xa44 ,0x11 ,0x0000 ,0x0800 ); +} +static void rtl_hw_phy_config (struct net_device *dev) {static const rtl_generic_fct phy_configs[] = {
@@ -3674,8 +3798,8 @@ static void rtl_hw_phy_config(struct net_device *dev) [RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config, [RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config, [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config, - [RTL_GIGA_MAC_VER_60] = NULL, - [RTL_GIGA_MAC_VER_61] = NULL, + [RTL_GIGA_MAC_VER_60] = rtl8125_1_hw_phy_config, + [RTL_GIGA_MAC_VER_61] = rtl8125_2_hw_phy_config, };struct rtl8169_private *tp =netdev_priv (dev);
Signature · 1 line
2.23.0
Heiner Kallweit
maintainerPATCH 4/4 r8169: add support for EEE on RTL8125
In reply to Heiner KallweitThis adds EEE support for RTL8125 based on the vendor driver. Supported is EEE for 100Mbps and 1Gbps. Realtek recommended to not yet enable EEE for 2.5Gbps due to potential compatibility issues. Also ethtool doesn't support yet controlling EEE for 2.5Gbps and 5Gbps.
--- drivers/net/ethernet/realtek/r8169_main.c | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/net/ethernet/realtek/r8169_main.c +24 -0
@@ -2271,6 +2271,12 @@ static void rtl8168_config_eee_mac(struct rtl8169_private *tp)rtl_eri_set_bits (tp,0x1b0 ,ERIAR_MASK_1111 ,0x0003 ); } +static void rtl8125_config_eee_mac (struct rtl8169_private *tp) +{ +r8168_mac_ocp_modify (tp,0xe040 ,0 ,BIT (1 ) |BIT (0 )); +r8168_mac_ocp_modify (tp,0xeb62 ,0 ,BIT (2 ) |BIT (1 )); +} +static void rtl8168f_config_eee_phy (struct rtl8169_private *tp) {struct phy_device *phydev = tp->phydev;
@@ -2301,6 +2307,16 @@ static void rtl8168h_config_eee_phy(struct rtl8169_private *tp)phy_modify_paged (phydev,0xa42 ,0x14 ,0x0000 ,0x0080 ); } +static void rtl8125_config_eee_phy (struct rtl8169_private *tp) +{ +struct phy_device *phydev = tp->phydev; + +rtl8168h_config_eee_phy (tp); + +phy_modify_paged (phydev,0xa6d ,0x12 ,0x0001 ,0x0000 ); +phy_modify_paged (phydev,0xa6d ,0x14 ,0x0010 ,0x0000 ); +} +static void rtl8169s_hw_phy_config (struct rtl8169_private *tp) {static const struct phy_reg phy_reg_init[] = {
@@ -3672,6 +3688,9 @@ static void rtl8125_1_hw_phy_config(struct rtl8169_private *tp)phy_modify_paged (phydev,0xbf0 ,0x15 ,0x0e00 ,0x0a00 );phy_modify_paged (phydev,0xa5c ,0x10 ,0x0400 ,0x0000 );phy_modify_paged (phydev,0xa44 ,0x11 ,0x0000 ,0x0800 ); + +rtl8125_config_eee_phy (tp); +rtl_enable_eee (tp); }static void rtl8125_2_hw_phy_config (struct rtl8169_private *tp)
@@ -3741,6 +3760,9 @@ static void rtl8125_2_hw_phy_config(struct rtl8169_private *tp)phy_modify_paged (phydev,0xad4 ,0x17 ,0x0010 ,0x0000 );phy_modify_paged (phydev,0xa86 ,0x15 ,0x0001 ,0x0000 );phy_modify_paged (phydev,0xa44 ,0x11 ,0x0000 ,0x0800 ); + +rtl8125_config_eee_phy (tp); +rtl_enable_eee (tp); }static void rtl_hw_phy_config (struct net_device *dev)
@@ -5263,6 +5285,8 @@ static void rtl_hw_start_8125_common(struct rtl8169_private *tp)rtl_udelay_loop_wait_low (tp, &rtl_mac_ocp_e00e_cond,1000 ,10 ); +rtl8125_config_eee_mac (tp); +RTL_W32 (tp,MISC ,RTL_R32 (tp,MISC ) & ~RXDV_GATED_EN );udelay (10 ); }
Signature · 1 line
2.23.0