From eebb76bced066ebbb8be7e65f307a136ab0d818d Mon Sep 17 00:00:00 2001 From: sbwml Date: Thu, 17 Oct 2024 17:18:18 +0800 Subject: [PATCH] r8168: bump to 8.054.00 Signed-off-by: sbwml --- Makefile | 2 +- ...-r8168-add-LED-configuration-from-OF.patch | 4 +- patches/100-fix-build-with-linux-6.9.patch | 99 ----- src/r8168.h | 109 ++++- src/r8168_dash.h | 4 + src/r8168_n.c | 379 ++++++++++++------ src/r8168_rss.c | 18 - src/r8168_rss.h | 2 +- 8 files changed, 376 insertions(+), 241 deletions(-) delete mode 100644 patches/100-fix-build-with-linux-6.9.patch diff --git a/Makefile b/Makefile index b02d7a9..a57c9a5 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=r8168 -PKG_VERSION:=8.053.00 +PKG_VERSION:=8.054.00 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) diff --git a/patches/001-r8168-add-LED-configuration-from-OF.patch b/patches/001-r8168-add-LED-configuration-from-OF.patch index 2795175..4cac002 100644 --- a/patches/001-r8168-add-LED-configuration-from-OF.patch +++ b/patches/001-r8168-add-LED-configuration-from-OF.patch @@ -8,7 +8,7 @@ #include #include #include -@@ -25945,6 +25946,22 @@ rtl8168_setup_mqs_reg(struct rtl8168_pri +@@ -26059,6 +26060,22 @@ rtl8168_setup_mqs_reg(struct rtl8168_pri tp->imr_reg[3] = IntrMask3; } @@ -31,7 +31,7 @@ static void rtl8168_init_software_variable(struct net_device *dev) { -@@ -26640,6 +26657,8 @@ err1: +@@ -26754,6 +26771,8 @@ err1: if (tp->InitRxDescType == RX_DESC_RING_TYPE_2) tp->RxDescLength = RX_DESC_LEN_TYPE_2; diff --git a/patches/100-fix-build-with-linux-6.9.patch b/patches/100-fix-build-with-linux-6.9.patch deleted file mode 100644 index 817ccf0..0000000 --- a/patches/100-fix-build-with-linux-6.9.patch +++ /dev/null @@ -1,99 +0,0 @@ ---- a/r8168_n.c -+++ b/r8168_n.c -@@ -7942,7 +7942,11 @@ rtl8168_device_lpi_t_to_ethtool_lpi_t(st - } - - static int -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+rtl_ethtool_get_eee(struct net_device *net, struct ethtool_keee *edata) -+#else - rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) -+#endif - { - struct rtl8168_private *tp = netdev_priv(net); - struct ethtool_eee *eee = &tp->eee; -@@ -7976,9 +7980,15 @@ rtl_ethtool_get_eee(struct net_device *n - - edata->eee_enabled = !!val; - edata->eee_active = !!(supported & adv & lp); -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+ ethtool_convert_legacy_u32_to_link_mode(edata->supported, supported); -+ ethtool_convert_legacy_u32_to_link_mode(edata->advertised, adv); -+ ethtool_convert_legacy_u32_to_link_mode(edata->lp_advertised, lp); -+#else - edata->supported = supported; - edata->advertised = adv; - edata->lp_advertised = lp; -+#endif - edata->tx_lpi_enabled = edata->eee_enabled; - edata->tx_lpi_timer = tx_lpi_timer; - -@@ -7986,11 +7996,19 @@ rtl_ethtool_get_eee(struct net_device *n - } - - static int -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+rtl_ethtool_set_eee(struct net_device *net, struct ethtool_keee *edata) -+#else - rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *edata) -+#endif - { - struct rtl8168_private *tp = netdev_priv(net); - struct ethtool_eee *eee = &tp->eee; -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+ u32 advertising, adv; -+#else - u32 advertising; -+#endif - int rc = 0; - - if (!rtl8168_support_eee(tp)) -@@ -8014,6 +8032,18 @@ rtl_ethtool_set_eee(struct net_device *n - } - - advertising = tp->advertising; -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+ ethtool_convert_link_mode_to_legacy_u32(&adv, edata->advertised); -+ if (linkmode_empty(edata->advertised)) { -+ adv = advertising & eee->supported; -+ ethtool_convert_legacy_u32_to_link_mode(edata->advertised, adv); -+ } else if (!linkmode_empty(edata->advertised) & ~advertising) { -+ dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised %x must be a subset of autoneg advertised speeds %x\n", -+ adv, advertising); -+ rc = -EINVAL; -+ goto out; -+ } -+#else - if (!edata->advertised) { - edata->advertised = advertising & eee->supported; - } else if (edata->advertised & ~advertising) { -@@ -8022,15 +8052,29 @@ rtl_ethtool_set_eee(struct net_device *n - rc = -EINVAL; - goto out; - } -+#endif - -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+ if (!linkmode_empty(edata->advertised) & ~eee->supported) { -+ dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised %x must be a subset of support %x\n", -+ adv, eee->supported); -+ rc = -EINVAL; -+ goto out; -+ } -+#else - if (edata->advertised & ~eee->supported) { - dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised %x must be a subset of support %x\n", - edata->advertised, eee->supported); - rc = -EINVAL; - goto out; - } -+#endif - -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+ ethtool_convert_link_mode_to_legacy_u32(&eee->advertised, edata->advertised); -+#else - eee->advertised = edata->advertised; -+#endif - eee->eee_enabled = edata->eee_enabled; - - if (eee->eee_enabled) diff --git a/src/r8168.h b/src/r8168.h index a56399f..bfb0e5a 100644 --- a/src/r8168.h +++ b/src/r8168.h @@ -53,6 +53,68 @@ #define fallthrough #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#define netif_xmit_stopped netif_tx_queue_stopped +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +#ifndef MDIO_AN_EEE_ADV_100TX +#define MDIO_AN_EEE_ADV_100TX 0x0002 /* Advertise 100TX EEE cap */ +#endif +#ifndef MDIO_AN_EEE_ADV_1000T +#define MDIO_AN_EEE_ADV_1000T 0x0004 /* Advertise 1000T EEE cap */ +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +#define MDIO_EEE_100TX MDIO_AN_EEE_ADV_100TX /* 100TX EEE cap */ +#define MDIO_EEE_1000T MDIO_AN_EEE_ADV_1000T /* 1000T EEE cap */ +#define MDIO_EEE_10GT 0x0008 /* 10GT EEE cap */ +#define MDIO_EEE_1000KX 0x0010 /* 1000KX EEE cap */ +#define MDIO_EEE_10GKX4 0x0020 /* 10G KX4 EEE cap */ +#define MDIO_EEE_10GKR 0x0040 /* 10G KR EEE cap */ +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) */ + +static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv) +{ + u32 adv = 0; + + if (eee_adv & MDIO_EEE_100TX) + adv |= ADVERTISED_100baseT_Full; + if (eee_adv & MDIO_EEE_1000T) + adv |= ADVERTISED_1000baseT_Full; + if (eee_adv & MDIO_EEE_10GT) + adv |= ADVERTISED_10000baseT_Full; + if (eee_adv & MDIO_EEE_1000KX) + adv |= ADVERTISED_1000baseKX_Full; + if (eee_adv & MDIO_EEE_10GKX4) + adv |= ADVERTISED_10000baseKX4_Full; + if (eee_adv & MDIO_EEE_10GKR) + adv |= ADVERTISED_10000baseKR_Full; + + return adv; +} + +static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv) +{ + u16 reg = 0; + + if (adv & ADVERTISED_100baseT_Full) + reg |= MDIO_EEE_100TX; + if (adv & ADVERTISED_1000baseT_Full) + reg |= MDIO_EEE_1000T; + if (adv & ADVERTISED_10000baseT_Full) + reg |= MDIO_EEE_10GT; + if (adv & ADVERTISED_1000baseKX_Full) + reg |= MDIO_EEE_1000KX; + if (adv & ADVERTISED_10000baseKX4_Full) + reg |= MDIO_EEE_10GKX4; + if (adv & ADVERTISED_10000baseKR_Full) + reg |= MDIO_EEE_10GKR; + + return reg; +} +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4,3,0) static inline ssize_t strscpy(char *dest, const char *src, size_t count) @@ -238,7 +300,7 @@ do { \ #define ENABLE_R8168_PROCFS #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0) #define ENABLE_R8168_SYSFS #endif @@ -349,6 +411,13 @@ do { \ #define MDIO_EEE_1000T 0x0004 #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) +#define ethtool_keee ethtool_eee +#define rtl8168_ethtool_adv_to_mmd_eee_adv_cap1_t ethtool_adv_to_mmd_eee_adv_t +#else +#define rtl8168_ethtool_adv_to_mmd_eee_adv_cap1_t linkmode_to_mii_eee_cap1_t +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) #ifdef CONFIG_NET_POLL_CONTROLLER #define RTL_NET_POLL_CONTROLLER dev->poll_controller=rtl8168_netpoll @@ -431,7 +500,7 @@ do { \ #define RSS_SUFFIX "" #endif -#define RTL8168_VERSION "8.053.00" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX RSS_SUFFIX +#define RTL8168_VERSION "8.054.00" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX RSS_SUFFIX #define MODULENAME "r8168" #define PFX MODULENAME ": " @@ -613,6 +682,13 @@ This is free software, and you are welcome to redistribute it under certain cond #define ETH_MIN_MTU 68 #endif +#ifndef WRITE_ONCE +#define WRITE_ONCE(var, val) (*((volatile typeof(val) *)(&(var))) = (val)) +#endif +#ifndef READ_ONCE +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#endif + /*****************************************************************************/ //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) @@ -1179,10 +1255,17 @@ enum RTL8168_registers { CounterAddrLow = 0x10, CounterAddrHigh = 0x14, CustomLED = 0x18, +#ifdef ENABLE_LIB_SUPPORT + TxDescStartAddrLow = 0x28, + TxDescStartAddrHigh = 0x2c, + TxHDescStartAddrLow = 0x20, + TxHDescStartAddrHigh = 0x24, +#else TxDescStartAddrLow = 0x20, TxDescStartAddrHigh = 0x24, TxHDescStartAddrLow = 0x28, TxHDescStartAddrHigh = 0x2c, +#endif /* ENABLE_LIB_SUPPORT */ FLASH = 0x30, ERSR = 0x36, ChipCmd = 0x37, @@ -1891,6 +1974,20 @@ struct rtl8168_counters { u16 tx_underrun; }; +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +struct ethtool_eee { + __u32 cmd; + __u32 supported; + __u32 advertised; + __u32 lp_advertised; + __u32 eee_active; + __u32 eee_enabled; + __u32 tx_lpi_enabled; + __u32 tx_lpi_timer; + __u32 reserved[2]; +}; +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) */ + struct rtl8168_private { void __iomem *mmio_addr; /* memory map physical address */ struct pci_dev *pci_dev; /* Index of PCI device */ @@ -2143,7 +2240,7 @@ struct rtl8168_private { //Realwow-------------- #endif //ENABLE_REALWOW_SUPPORT - struct ethtool_eee eee; + struct ethtool_keee eee; u32 dynamic_aspm_packet_count; @@ -2449,9 +2546,8 @@ rtl8168_enable_dash2_interrupt(struct rtl8168_private *tp) if (!tp->DASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBIMR0, (ISRIMR_DASH_TYPE2_ROK | ISRIMR_DASH_TYPE2_TOK | ISRIMR_DASH_TYPE2_TDU | ISRIMR_DASH_TYPE2_RDU | ISRIMR_DASH_TYPE2_RX_DISABLE_IDLE)); - } } static inline void @@ -2460,9 +2556,8 @@ rtl8168_disable_dash2_interrupt(struct rtl8168_private *tp) if (!tp->DASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBIMR0, 0); - } } #endif diff --git a/src/r8168_dash.h b/src/r8168_dash.h index 2c2174e..f9703f3 100644 --- a/src/r8168_dash.h +++ b/src/r8168_dash.h @@ -160,6 +160,7 @@ RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2; #define OCP_REG_CR (0x36) #define OCP_REG_DMEMSTA (0x38) #define OCP_REG_GPHYAR (0x60) +#define OCP_REG_FIRMWARE_MAJOR_VERSION (0x120) #define OCP_REG_CONFIG0_DASHEN BIT_15 @@ -175,6 +176,9 @@ RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2; #define HW_DASH_SUPPORT_TYPE_1(_M) ((_M)->HwSuppDashVer == 1) #define HW_DASH_SUPPORT_TYPE_2(_M) ((_M)->HwSuppDashVer == 2) #define HW_DASH_SUPPORT_TYPE_3(_M) ((_M)->HwSuppDashVer == 3) +#define HW_DASH_SUPPORT_CMAC(_M) (HW_DASH_SUPPORT_TYPE_2(_M) || HW_DASH_SUPPORT_TYPE_3(_M)) +#define HW_DASH_SUPPORT_GET_FIRMWARE_VERSION(_M) (HW_DASH_SUPPORT_TYPE_2(_M) || \ + HW_DASH_SUPPORT_TYPE_3(_M)) #define RECV_FROM_FW_BUF_SIZE (2048) #define SEND_TO_FW_BUF_SIZE (2048) diff --git a/src/r8168_n.c b/src/r8168_n.c index ad63f42..600ac50 100644 --- a/src/r8168_n.c +++ b/src/r8168_n.c @@ -1701,6 +1701,26 @@ static int proc_dump_tx_desc(struct seq_file *m, void *v) rtnl_lock(); +#ifdef ENABLE_LIB_SUPPORT + (void)i; + if (tp->tx_ring[0].TxDescArray) { + struct rtl8168_tx_ring *ring = &tp->tx_ring[0]; + + seq_printf(m, "\ndump rtk tx desc:%d\n", ring->num_tx_desc); + _proc_dump_tx_desc(m, ring->TxDescArray, + ring->TxDescAllocSize, + ring->num_tx_desc); + } + + if (tp->lib_tx_ring[1].desc_addr) { + struct rtl8168_ring *ring = &tp->lib_tx_ring[1]; + + seq_printf(m, "\ndump lib tx desc:%d\n", ring->ring_size); + _proc_dump_tx_desc(m, ring->desc_addr, + ring->desc_size, + ring->ring_size); + } +#else for (i=0; iHwSuppNumTxQueues; i++) { struct rtl8168_tx_ring *ring = &tp->tx_ring[i]; if (!ring->TxDescArray) @@ -1710,17 +1730,6 @@ static int proc_dump_tx_desc(struct seq_file *m, void *v) ring->TxDescAllocSize, ring->num_tx_desc); } - -#ifdef ENABLE_LIB_SUPPORT - for (i=0; iHwSuppNumTxQueues; i++) { - struct rtl8168_ring *ring = &tp->lib_tx_ring[i]; - if (!ring->desc_addr) - continue; - seq_printf(m, "\ndump lib Q%d tx desc:%d\n", i, ring->ring_size); - _proc_dump_tx_desc(m, ring->desc_addr, - ring->desc_size, - ring->ring_size); - } #endif //ENABLE_LIB_SUPPORT rtnl_unlock(); @@ -1883,7 +1892,6 @@ static int proc_get_driver_variable(char *page, char **start, "num_tx_rings\t0x%x\n" "tot_rx_rings\t0x%x\n" "tot_tx_rings\t0x%x\n" - "tot_rx_desc_rings\t0x%x\n" "HwSuppNumTxQueues\t0x%x\n" "HwSuppNumRxQueues\t0x%x\n" "num_hw_tot_en_rx_rings\t0x%x\n" @@ -2029,8 +2037,6 @@ static int proc_get_tally_counter(char *page, char **start, struct rtl8168_private *tp = netdev_priv(dev); struct rtl8168_counters *counters; dma_addr_t paddr; - u32 cmd; - u32 WaitCnt; int len = 0; len += snprintf(page + len, count - len, @@ -2499,7 +2505,7 @@ void _proc_dump_tx_desc(char *page, int *page_len, int *count, pdword[i]); } - len += snprintf(page + len, count - len, "\n"); + len += snprintf(page + len, *count - len, "\n"); *page_len = len; return; @@ -2511,7 +2517,6 @@ static int proc_dump_tx_desc(char *page, char **start, { int i; int len = 0; - u32 *pdword; struct net_device *dev = data; struct rtl8168_private *tp = netdev_priv(dev); struct rtl8168_tx_ring *ring = &tp->tx_ring[0]; @@ -2521,13 +2526,13 @@ static int proc_dump_tx_desc(char *page, char **start, rtnl_lock(); - for (i=0; iHwSuppNumTxQueues; i++) { - struct rtl8168_tx_ring *ring = &tp->tx_ring[i]; - if (!ring->TxDescArray) - continue; +#ifdef ENABLE_LIB_SUPPORT + (void)i; + if (tp->tx_ring[0].TxDescArray) { + struct rtl8168_tx_ring *ring = &tp->tx_ring[0]; + len += snprintf(page + len, count - len, - "\ndump Q%d tx desc:%d", - i, + "\ndump rtk tx desc:%d\n", ring->num_tx_desc); _proc_dump_tx_desc(page, &len, &count, ring->TxDescArray, @@ -2535,19 +2540,31 @@ static int proc_dump_tx_desc(char *page, char **start, ring->num_tx_desc); } -#ifdef ENABLE_LIB_SUPPORT - for (i=0; iHwSuppNumTxQueues; i++) { - struct rtl8168_ring *ring = &tp->lib_tx_ring[i]; - if (!ring->desc_addr) - continue; + if (tp->lib_tx_ring[1].desc_addr) { + struct rtl8168_ring *ring = &tp->lib_tx_ring[1]; + len += snprintf(page + len, count - len, - "\ndump lib Q%d tx desc:%d", - i, + "\ndump lib tx desc:%d\n", ring->ring_size); - _proc_dump_tx_desc(page, &len, ring->desc_addr, + _proc_dump_tx_desc(page, &len, &count, + ring->desc_addr, ring->desc_size, ring->ring_size); } +#else + for (i=0; iHwSuppNumTxQueues; i++) { + struct rtl8168_tx_ring *ring = &tp->tx_ring[i]; + if (!ring->TxDescArray) + continue; + len += snprintf(page + len, count - len, + "\ndump Q%d tx desc:%d\n", + i, + ring->num_tx_desc); + _proc_dump_tx_desc(page, &len, &count, + ring->TxDescArray, + ring->TxDescAllocSize, + ring->num_tx_desc); + } #endif //ENABLE_LIB_SUPPORT rtnl_unlock(); @@ -2559,58 +2576,6 @@ static int proc_dump_tx_desc(char *page, char **start, return len; } -static int proc_dump_tx_desc(char *page, char **start, - off_t offset, int count, - int *eof, void *data) -{ - int i; - struct net_device *dev = m->private; - struct rtl8168_private *tp = netdev_priv(dev); - - switch (tp->mcfg) { - case CFG_METHOD_1 ... CFG_METHOD_8: - return -EOPNOTSUPP; - default: - break; - } - - rtnl_lock(); - - len += snprintf(page + len, count - len, - "\ndump MSI-X Table. Total Entry %d. \n", - R8168_MAX_MSIX_VEC); - - for (i=0; iDASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) { u16 WaitCnt; u8 TmpUchar; @@ -3682,7 +3679,7 @@ void rtl8168_dash2_enable_tx(struct rtl8168_private *tp) if (!tp->DASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBCR2, RTL_CMAC_R8(tp, CMAC_IBCR2) | BIT_0); } @@ -3691,7 +3688,7 @@ void rtl8168_dash2_disable_rx(struct rtl8168_private *tp) if (!tp->DASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBCR0, RTL_CMAC_R8(tp, CMAC_IBCR0) & ~(BIT_0)); } @@ -3700,7 +3697,7 @@ void rtl8168_dash2_enable_rx(struct rtl8168_private *tp) if (!tp->DASH) return; - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBCR0, RTL_CMAC_R8(tp, CMAC_IBCR0) | BIT_0); } @@ -3708,7 +3705,7 @@ static void rtl8168_dash2_disable_txrx(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) { rtl8168_dash2_disable_tx(tp); rtl8168_dash2_disable_rx(tp); } @@ -4670,9 +4667,8 @@ rtl8168_irq_mask_and_ack(struct rtl8168_private *tp) rtl8168_get_isr_by_vector(tp, 0) & ~(ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET)); } else { - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) RTL_CMAC_W8(tp, CMAC_IBISR0, RTL_CMAC_R8(tp, CMAC_IBISR0)); - } } } else { rtl8168_self_clear_isr_by_vector(tp, 0); @@ -5215,7 +5211,7 @@ NICChkTypeEnableDashInterrupt(struct rtl8168_private *tp) // // even disconnected, enable 3 dash interrupt mask bits for in-band/out-band communication // - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) { rtl8168_enable_dash2_interrupt(tp); RTL_W16(tp, tp->imr_reg[0], (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET)); } else { @@ -6680,7 +6676,6 @@ rtl8168_set_settings(struct net_device *dev, static u32 rtl8168_get_tx_csum(struct net_device *dev) { - struct rtl8168_private *tp = netdev_priv(dev); u32 ret; #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) @@ -7605,8 +7600,8 @@ static int rtl8168_enable_eee(struct rtl8168_private *tp) int ret; u16 data; u32 csi_tmp; - struct ethtool_eee *eee = &tp->eee; - u16 eee_adv_t = ethtool_adv_to_mmd_eee_adv_t(eee->advertised); + struct ethtool_keee *eee = &tp->eee; + u16 eee_adv_cap1_t = rtl8168_ethtool_adv_to_mmd_eee_adv_cap1_t(eee->advertised); ret = 0; switch (tp->mcfg) { @@ -7709,7 +7704,7 @@ static int rtl8168_enable_eee(struct rtl8168_private *tp) data = rtl8168_mdio_read(tp, 0x11); rtl8168_mdio_write(tp, 0x11, data | BIT_4); rtl8168_mdio_write(tp, 0x1F, 0x0A5D); - rtl8168_mdio_write(tp, 0x10, eee_adv_t); + rtl8168_mdio_write(tp, 0x10, eee_adv_cap1_t); rtl8168_mdio_write(tp, 0x1F, 0x0000); break; @@ -7940,6 +7935,127 @@ rtl8168_device_lpi_t_to_ethtool_lpi_t(struct rtl8168_private *tp , u32 lpi_timer return to_us; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) +static void +rtl8168_adv_to_linkmode(unsigned long *mode, u64 adv) +{ + linkmode_zero(mode); + + if (adv & ADVERTISED_10baseT_Half) + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, mode); + if (adv & ADVERTISED_10baseT_Full) + linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, mode); + if (adv & ADVERTISED_100baseT_Half) + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, mode); + if (adv & ADVERTISED_100baseT_Full) + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, mode); + if (adv & ADVERTISED_1000baseT_Half) + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, mode); + if (adv & ADVERTISED_1000baseT_Full) + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, mode); + if (adv & ADVERTISED_2500baseX_Full) + linkmode_set_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, mode); +} + +static int +rtl_ethtool_get_eee(struct net_device *net, struct ethtool_keee *edata) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(common); + struct rtl8168_private *tp = netdev_priv(net); + struct ethtool_keee *eee = &tp->eee; + u32 tx_lpi_timer; + u16 val; + + if (!rtl8168_support_eee(tp)) + return -EOPNOTSUPP; + + if (unlikely(tp->rtk_enable_diag)) + return -EBUSY; + + /* Get LP advertisement EEE */ + rtl8168_mdio_write(tp, 0x1F, 0x0A5D); + val = rtl8168_mdio_read(tp, 0x11); + mii_eee_cap1_mod_linkmode_t(edata->lp_advertised, val);; + + /* Get EEE Tx LPI timer*/ + tx_lpi_timer = rtl8168_device_lpi_t_to_ethtool_lpi_t(tp, eee->tx_lpi_timer); + + val = rtl8168_eri_read(tp, 0x1B0, 2, ERIAR_ExGMAC); + val &= BIT_1 | BIT_0; + + rtl8168_mdio_write(tp, 0x1F, 0x0000); + + edata->eee_enabled = !!val; + linkmode_copy(edata->supported, eee->supported); + linkmode_copy(edata->advertised, eee->advertised); + edata->tx_lpi_enabled = edata->eee_enabled; + edata->tx_lpi_timer = tx_lpi_timer; + linkmode_and(common, edata->advertised, edata->lp_advertised); + edata->eee_active = !linkmode_empty(common); + + return 0; +} + +static int +rtl_ethtool_set_eee(struct net_device *net, struct ethtool_keee *edata) +{ + __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); + __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp); + struct rtl8168_private *tp = netdev_priv(net); + struct ethtool_keee *eee = &tp->eee; + int rc = 0; + + if (!rtl8168_support_eee(tp)) + return -EOPNOTSUPP; + + if (HW_SUPP_SERDES_PHY(tp) || + !HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp) || + tp->DASH) + return -EOPNOTSUPP; + + if (unlikely(tp->rtk_enable_diag)) { + dev_printk(KERN_WARNING, tp_to_dev(tp), "Diag Enabled\n"); + rc = -EBUSY; + goto out; + } + + if (tp->autoneg != AUTONEG_ENABLE) { + dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE requires autoneg\n"); + rc = -EINVAL; + goto out; + } + + rtl8168_adv_to_linkmode(advertising, tp->advertising); + if (linkmode_empty(edata->advertised)) { + linkmode_and(edata->advertised, advertising, eee->supported); + } else if (linkmode_andnot(tmp, edata->advertised, advertising)) { + dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised must be a subset of autoneg advertised speeds\n"); + rc = -EINVAL; + goto out; + } + + if (linkmode_andnot(tmp, edata->advertised, eee->supported)) { + dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised must be a subset of support \n"); + rc = -EINVAL; + goto out; + } + + linkmode_copy(eee->advertised, edata->advertised); + eee->tx_lpi_enabled = edata->tx_lpi_enabled; + eee->tx_lpi_timer = edata->tx_lpi_timer; + eee->eee_enabled = edata->eee_enabled; + + if (eee->eee_enabled) + rtl8168_enable_eee(tp); + else + rtl8168_disable_eee(tp); + + rtl_nway_reset(net); + +out: + return rc; +} +#else static int rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) { @@ -8039,12 +8155,10 @@ rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *edata) rtl_nway_reset(net); - return rc; - out: - return rc; } +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) */ #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) @@ -26187,7 +26301,7 @@ err1: #ifdef ENABLE_DASH_SUPPORT if (tp->DASH) { - if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { + if (HW_DASH_SUPPORT_CMAC(tp)) { tp->timer_intr_mask |= (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET); tp->intr_mask |= (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET); } else { @@ -26660,12 +26774,19 @@ err1: #endif //LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0) if (rtl8168_support_eee(tp)) { - struct ethtool_eee *eee = &tp->eee; + struct ethtool_keee *eee = &tp->eee; eee->eee_enabled = eee_enable; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) eee->supported = SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Full; eee->advertised = mmd_eee_adv_to_ethtool_adv_t(MDIO_EEE_1000T | MDIO_EEE_100TX); +#else + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, eee->supported); + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, eee->supported); + linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, eee->advertised); + linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, eee->advertised); +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) */ eee->tx_lpi_enabled = eee_enable; eee->tx_lpi_timer = dev->mtu + ETH_HLEN + 0x20; } @@ -28178,6 +28299,31 @@ rtl8168_link_timer(struct timer_list *t) */ #ifndef ENABLE_RSS_SUPPORT +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) +static int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, + int minvec, int maxvec) +{ + int nvec = maxvec; + int rc; + + if (maxvec < minvec) + return -ERANGE; + + do { + rc = pci_enable_msix(dev, entries, nvec); + if (rc < 0) { + return rc; + } else if (rc > 0) { + if (rc < minvec) + return -ENOSPC; + nvec = rc; + } + } while (rc); + + return nvec; +} +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) */ + static int rtl8168_enable_msix(struct rtl8168_private *tp) { int i, nvecs = 0; @@ -28629,7 +28775,9 @@ rtl8168_init_one(struct pci_dev *pdev, netif_carrier_off(dev); +#ifdef ENABLE_R8168_SYSFS rtl8168_sysfs_init(dev); +#endif /* ENABLE_R8168_SYSFS */ printk("%s", GPL_CLAIM); @@ -29022,12 +29170,14 @@ static void set_offset70F(struct rtl8168_private *tp, u8 setting) { u32 csi_tmp; - u32 temp = (u32)setting; - temp = temp << 24; + u32 temp; + + temp = setting & 0x3f; + temp <<= 24; /*set PCI configuration space offset 0x70F to setting*/ /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/ - csi_tmp = rtl8168_csi_read(tp, 0x70c) & 0x00ffffff; + csi_tmp = rtl8168_csi_read(tp, 0x70c) & 0xc0ffffff; rtl8168_csi_write(tp, 0x70c, csi_tmp | temp); } @@ -29619,11 +29769,11 @@ rtl8168_hw_config(struct net_device *dev) rtl8168_eri_write(tp, 0xC8, 4, 0x00080002, ERIAR_ExGMAC); #ifdef ENABLE_LIB_SUPPORT - rtl8168_eri_write(tp, 0xCC, 1, 0x60, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xD0, 1, 0x70, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xCC, 2, 0x60, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xD0, 2, 0x70, ERIAR_ExGMAC); #else - rtl8168_eri_write(tp, 0xCC, 1, 0x38, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xD0, 1, 0x48, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xCC, 2, 0x38, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xD0, 2, 0x48, ERIAR_ExGMAC); #endif //ENABLE_LIB_SUPPORT rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC); @@ -29761,8 +29911,8 @@ rtl8168_hw_config(struct net_device *dev) set_offset79(tp, 0x50); rtl8168_eri_write(tp, 0xC8, 4, 0x00080002, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xCC, 1, 0x2F, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xD0, 1, 0x5F, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xCC, 2, 0x2F, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xD0, 2, 0x5F, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC); RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | BIT_7); @@ -29836,8 +29986,8 @@ rtl8168_hw_config(struct net_device *dev) set_offset79(tp, 0x50); rtl8168_eri_write(tp, 0xC8, 4, 0x00080002, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xCC, 1, 0x2F, ERIAR_ExGMAC); - rtl8168_eri_write(tp, 0xD0, 1, 0x5F, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xCC, 2, 0x2F, ERIAR_ExGMAC); + rtl8168_eri_write(tp, 0xD0, 2, 0x5F, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC); RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | BIT_7); @@ -31867,9 +32017,11 @@ static int rtl8168_poll_vector(napi_ptr napi, napi_budget budget, bool all_rx_q) if (all_rx_q) for (i = 0; i < tp->num_hw_tot_en_rx_rings; i++) work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ring[i], budget); - else + else if (message_id < tp->num_rx_rings) work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ring[message_id], budget); + work_done = min(work_done, work_to_do); + RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget); if (work_done < work_to_do) { @@ -31913,7 +32065,8 @@ static int rtl8168_poll_msix_rx(napi_ptr napi, napi_budget budget) unsigned int work_to_do = RTL_NAPI_QUOTA(budget, dev); unsigned int work_done = 0; - work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ring[message_id], budget); + if (message_id < tp->num_rx_rings) + work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ring[message_id], budget); RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget); diff --git a/src/r8168_rss.c b/src/r8168_rss.c index 3119f1f..c7ca990 100644 --- a/src/r8168_rss.c +++ b/src/r8168_rss.c @@ -80,8 +80,6 @@ int rtl8168_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, struct rtl8168_private *tp = netdev_priv(dev); int ret = -EOPNOTSUPP; - netif_info(tp, drv, tp->dev, "rss get rxnfc\n"); - if (!(dev->features & NETIF_F_RXHASH)) return ret; @@ -136,8 +134,6 @@ static int rtl8168_set_rss_hash_opt(struct rtl8168_private *tp, { u32 rss_flags = tp->rss_flags; - netif_info(tp, drv, tp->dev, "rss set hash\n"); - /* * RSS does not support anything other than hashing * to queues on src and dst IPs and ports @@ -205,8 +201,6 @@ int rtl8168_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) struct rtl8168_private *tp = netdev_priv(dev); int ret = -EOPNOTSUPP; - netif_info(tp, drv, tp->dev, "rss set rxnfc\n"); - if (!(dev->features & NETIF_F_RXHASH)) return ret; @@ -230,8 +224,6 @@ u32 rtl8168_get_rxfh_key_size(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); - netif_info(tp, drv, tp->dev, "rss get key size\n"); - if (!(dev->features & NETIF_F_RXHASH)) return 0; @@ -242,8 +234,6 @@ u32 rtl8168_rss_indir_size(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); - netif_info(tp, drv, tp->dev, "rss get indir tbl size\n"); - if (!(dev->features & NETIF_F_RXHASH)) return 0; @@ -313,8 +303,6 @@ int rtl8168_get_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh) { struct rtl8168_private *tp = netdev_priv(dev); - netif_info(tp, drv, tp->dev, "rss get rxfh\n"); - if (!(dev->features & NETIF_F_RXHASH)) return -EOPNOTSUPP; @@ -336,8 +324,6 @@ int rtl8168_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh, u32 reta_entries = rtl8168_rss_indir_tbl_entries(tp); int i; - netif_info(tp, drv, tp->dev, "rss set rxfh\n"); - /* We require at least one supported parameter to be changed and no * change in any of the unsupported parameters */ @@ -373,8 +359,6 @@ int rtl8168_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, { struct rtl8168_private *tp = netdev_priv(dev); - netif_info(tp, drv, tp->dev, "rss get rxfh\n"); - if (!(dev->features & NETIF_F_RXHASH)) return -EOPNOTSUPP; @@ -397,8 +381,6 @@ int rtl8168_set_rxfh(struct net_device *dev, const u32 *indir, u32 reta_entries = rtl8168_rss_indir_tbl_entries(tp); int i; - netif_info(tp, drv, tp->dev, "rss set rxfh\n"); - /* We require at least one supported parameter to be changed and no * change in any of the unsupported parameters */ diff --git a/src/r8168_rss.h b/src/r8168_rss.h index 1bef737..f273d23 100644 --- a/src/r8168_rss.h +++ b/src/r8168_rss.h @@ -2,7 +2,7 @@ /* ################################################################################ # -# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet +# r8168 is the Linux device driver released for Realtek 2.5Gigabit Ethernet # controllers with PCI-Express interface. # # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.