Projects
home:bitstreamout:Essentials
r8168
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 43
View file
r8168.changes
Changed
@@ -1,4 +1,14 @@ ------------------------------------------------------------------- +Thu Oct 15 13:31:06 UTC 2026 - Dr. Werner Fink <werner@suse.de> + +- Update to new version r8168-8.057.00 +- Port patches + * r8168-configuration.patch + * r8168-kernel_version.patch + * r8168-support-ethtool_keee.patch + * r8168-support-linux-L15.5.patch + +------------------------------------------------------------------- Mon Feb 10 09:07:28 UTC 2025 - Dr. Werner Fink <werner@suse.de> - Clean up spec file
View file
r8168.spec
Changed
@@ -18,13 +18,13 @@ #!BuildIgnore: enough-build-resources Name: r8168 -Version: 8.053.00 +Version: 8.057.00 Release: 0 Summary: Device driver for RealTek Gigabit Ethernet controllers License: GPL-2.0-or-later Group: System/Kernel URL: https://github.com/mtorromeo/r8168 -Source0: https://github.com/mtorromeo/r8168/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz +Source0: https://github.com/mtorromeo/r8168/archive/refs/tags/%{version}.tar.gz#/%{name}-%{version}.tar.gz Source1: preamble Source2: Module.supported Source3: https://github.com/mtorromeo/r8168/releases/download/%{version}/%{name}-%{version}.tar.gz.asc
View file
r8168-configuration.patch
Changed
@@ -4,7 +4,7 @@ --- src/Makefile +++ src/Makefile 2022-05-10 10:26:59.851240712 +0000 -@@ -52,6 +52,7 @@ CONFIG_CTAP_SHORT_OFF = n +@@ -53,6 +53,7 @@ CONFIG_CTAP_SHORT_OFF = n ifneq ($(KERNELRELEASE),) obj-m := r8168.o r8168-objs := r8168_n.o r8168_asf.o rtl_eeprom.o rtltool.o
View file
r8168-kernel_version.patch
Changed
@@ -5,7 +5,7 @@ --- src/r8168.h +++ src/r8168.h 2024-03-13 11:51:59.011947503 +0000 -@@ -196,6 +196,10 @@ do { \ +@@ -273,6 +273,10 @@ do { \ } while (0) #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) @@ -35,7 +35,7 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37) #include <linux/prefetch.h> #endif -@@ -586,8 +591,12 @@ static void rtl8168_set_rx_mode(struct n +@@ -614,8 +619,12 @@ static void rtl8168_set_rx_mode(struct n #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) static void rtl8168_tx_timeout(struct net_device *dev, unsigned int txqueue); #else @@ -48,7 +48,7 @@ static struct net_device_stats *rtl8168_get_stats(struct net_device *dev); static int rtl8168_rx_interrupt(struct net_device *, struct rtl8168_private *, struct rtl8168_rx_ring *, napi_budget); #ifdef CONFIG_R8168_NAPI -@@ -30897,8 +30906,12 @@ static void +@@ -31287,8 +31296,12 @@ static void rtl8168_tx_timeout(struct net_device *dev, unsigned int txqueue) #else static void @@ -61,7 +61,7 @@ { struct rtl8168_private *tp = netdev_priv(dev); -@@ -31636,7 +31649,7 @@ rtl8168_rx_interrupt(struct net_device * +@@ -32051,7 +32064,7 @@ rtl8168_rx_interrupt(struct net_device * if (rtl8168_rx_vlan_skb(tp, desc, skb) < 0) rtl8168_rx_skb(tp, skb, ring_index);
View file
r8168-support-ethtool_keee.patch
Changed
@@ -13,26 +13,24 @@ rtl_ethtool_get_eee(struct net_device *net, struct ethtool_keee *edata) rtl_ethtool_set_eee(struct net_device *net, struct ethtool_keee *edata) --- - src/r8168_n.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ + src/r8168_n.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) -diff --git a/src/r8168_n.c b/src/r8168_n.c -index ad63f42..3d67641 100755 --- a/src/r8168_n.c -+++ b/src/r8168_n.c -@@ -7941,7 +7941,11 @@ rtl8168_device_lpi_t_to_ethtool_lpi_t(struct rtl8168_private *tp , u32 lpi_timer ++++ b/src/r8168_n.c 2026-10-15 13:25:45.175908700 +0000 +@@ -8183,7 +8183,11 @@ rtl8168_adv_to_linkmode(unsigned long *m } static int +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0) -+rtl_ethtool_get_eee(struct net_device *net, struct ethtool_keee *edata) + 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) ++rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) +#endif { + __ETHTOOL_DECLARE_LINK_MODE_MASK(common); struct rtl8168_private *tp = netdev_priv(net); - struct ethtool_eee *eee = &tp->eee; -@@ -7975,9 +7979,15 @@ rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) +@@ -8311,9 +8315,15 @@ rtl_ethtool_get_eee(struct net_device *n edata->eee_enabled = !!val; edata->eee_active = !!(supported & adv & lp); @@ -48,7 +46,7 @@ edata->tx_lpi_enabled = edata->eee_enabled; edata->tx_lpi_timer = tx_lpi_timer; -@@ -7985,11 +7995,19 @@ rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) +@@ -8321,11 +8331,19 @@ rtl_ethtool_get_eee(struct net_device *n } static int @@ -68,7 +66,7 @@ int rc = 0; if (!rtl8168_support_eee(tp)) -@@ -8013,6 +8031,18 @@ rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *edata) +@@ -8349,6 +8367,18 @@ rtl_ethtool_set_eee(struct net_device *n } advertising = tp->advertising; @@ -87,7 +85,7 @@ if (!edata->advertised) { edata->advertised = advertising & eee->supported; } else if (edata->advertised & ~advertising) { -@@ -8021,15 +8051,29 @@ rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *edata) +@@ -8357,15 +8387,29 @@ rtl_ethtool_set_eee(struct net_device *n rc = -EINVAL; goto out; }
View file
r8168-support-linux-L15.5.patch
Changed
@@ -4,7 +4,7 @@ --- src/r8168_n.c +++ src/r8168_n.c 2024-03-13 12:10:07.947820999 +0000 -@@ -7234,7 +7234,7 @@ rtl8168_set_ring_size(struct rtl8168_pri +@@ -7437,7 +7437,7 @@ rtl8168_set_ring_size(struct rtl8168_pri } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) @@ -13,7 +13,7 @@ static void rtl8168_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, -@@ -7242,7 +7242,7 @@ static void rtl8168_get_ringparam(struct +@@ -7445,7 +7445,7 @@ static void rtl8168_get_ringparam(struct #else static void rtl8168_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) @@ -22,7 +22,7 @@ { struct rtl8168_private *tp = netdev_priv(dev); -@@ -7252,7 +7252,7 @@ static void rtl8168_get_ringparam(struct +@@ -7455,7 +7455,7 @@ static void rtl8168_get_ringparam(struct ring->tx_pending = tp->tx_ring0.num_tx_desc; } @@ -31,7 +31,7 @@ static int rtl8168_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring, struct kernel_ethtool_ringparam *kernel_ring, -@@ -7260,7 +7260,7 @@ static int rtl8168_set_ringparam(struct +@@ -7463,7 +7463,7 @@ static int rtl8168_set_ringparam(struct #else static int rtl8168_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) @@ -40,7 +40,7 @@ { struct rtl8168_private *tp = netdev_priv(dev); u32 new_rx_count, new_tx_count; -@@ -26737,11 +26737,11 @@ rtl8168_release_board(struct pci_dev *pd +@@ -27072,11 +27072,11 @@ rtl8168_release_board(struct pci_dev *pd static void rtl8168_hw_address_set(struct net_device *dev, u8 mac_addrMAC_ADDR_LEN) {
View file
r8168-8.053.00.tar.gz.asc
Deleted
@@ -1,7 +0,0 @@ ------BEGIN PGP SIGNATURE----- - -iHUEABYKAB0WIQQMrarPcPZMZU4TGzERZ1x0NCnd7wUCZiUOBgAKCRARZ1x0NCnd -7zwaAP9/wR9UAKCbpYCVY4a527hxVnKbIskev0+SNUa++NYyKAD+KCZaGOKSVUOF -AUqJsVPNzKZkPn162vhgkJH9EOfBmQ0= -=DNig ------END PGP SIGNATURE-----
View file
r8168-8.057.00.tar.gz.asc
Added
@@ -0,0 +1,8 @@ +-----BEGIN PGP SIGNATURE----- + +iJYEABYKAD4WIQQMrarPcPZMZU4TGzERZ1x0NCnd7wUCaqMzvCAcbWFzc2ltaWxp +YW5vLnRvcnJvbWVvQGdtYWlsLmNvbQAKCRARZ1x0NCnd78/jAQD0IFg1fvgn2WKc +/TYcRNDoNtpe1V8zaPMIa1TNFmAG+AD+LaOdByqpWCTK6BJCX3Iy0YGOZo2RwjWu +6zIZAwmzCw4= +=gLfi +-----END PGP SIGNATURE-----
View file
r8168-8.053.00.tar.gz/Makefile -> r8168-8.057.00.tar.gz/Makefile
Changed
@@ -4,7 +4,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2026 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free
View file
r8168-8.053.00.tar.gz/autorun.sh -> r8168-8.057.00.tar.gz/autorun.sh
Changed
@@ -15,14 +15,14 @@ echo "Check old driver and unload it." check=`lsmod | grep r8169` if "$check" != "" ; then - echo "rmmod r8169" - /sbin/rmmod r8169 + echo "rmmod r8169" + /sbin/rmmod r8169 fi check=`lsmod | grep r8168` if "$check" != "" ; then - echo "rmmod r8168" - /sbin/rmmod r8168 + echo "rmmod r8168" + /sbin/rmmod r8168 fi echo "Build the module and install" @@ -52,6 +52,21 @@ mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak fi fi + if test -e $TARGET_PATH/r8169.ko.zst ; then + echo "Backup r8169.ko.zst" + if test -e $TARGET_PATH/r8169.zst.bak ; then + i=0 + while test -e $TARGET_PATH/r8169.zst.bak$i + do + i=$(($i+1)) + done + echo "rename r8169.ko.zst to r8169.zst.bak$i" + mv $TARGET_PATH/r8169.ko.zst $TARGET_PATH/r8169.zst.bak$i + else + echo "rename r8169.ko.zst to r8169.zst.bak" + mv $TARGET_PATH/r8169.ko.zst $TARGET_PATH/r8169.zst.bak + fi + fi fi echo "DEPMOD $(uname -r)" @@ -84,4 +99,3 @@ echo "Completed." exit 0 -
View file
r8168-8.053.00.tar.gz/src/Makefile -> r8168-8.057.00.tar.gz/src/Makefile
Changed
@@ -4,7 +4,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -30,7 +30,7 @@ # US6,570,884, US6,115,776, and US6,327,625. ################################################################################ -CONFIG_SOC_LAN = n +CONFIG_SOC_LAN = y ENABLE_FIBER_SUPPORT = n ENABLE_REALWOW_SUPPORT = n ENABLE_DASH_SUPPORT = n @@ -48,6 +48,7 @@ ENABLE_RSS_SUPPORT = n ENABLE_LIB_SUPPORT = n DISABLE_WOL_SUPPORT = n +ENABLE_GIGA_LITE = y ifneq ($(KERNELRELEASE),) obj-m := r8168.o @@ -117,6 +118,12 @@ ifeq ($(DISABLE_WOL_SUPPORT), y) EXTRA_CFLAGS += -DDISABLE_WOL_SUPPORT endif + ifeq ($(ENABLE_GIGA_LITE), y) + EXTRA_CFLAGS += -DENABLE_GIGA_LITE + endif + + # Backward compatibility + ccflags-y += $(EXTRA_CFLAGS) else BASEDIR := /lib/modules/$(shell uname -r) KERNELDIR ?= $(BASEDIR)/build
View file
r8168-8.053.00.tar.gz/src/Makefile_linux24x -> r8168-8.057.00.tar.gz/src/Makefile_linux24x
Changed
@@ -4,7 +4,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free
View file
r8168-8.053.00.tar.gz/src/r8168.h -> r8168-8.057.00.tar.gz/src/r8168.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,6 +32,9 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ +#ifndef R8168_H +#define R8168_H + #include <linux/ethtool.h> #include <linux/interrupt.h> #include <linux/version.h> @@ -53,6 +56,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) @@ -103,6 +168,18 @@ static inline void netdev_tx_reset_queue(struct netdev_queue *q) {} #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) +static inline void fsleep(unsigned long usecs) +{ + if (usecs <= 10) + udelay(usecs); + else if (usecs <= 20000) + usleep_range(usecs, 2 * usecs); + else + msleep(DIV_ROUND_UP(usecs, 1000)); +} +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) #define netdev_xmit_more() (0) #endif @@ -238,7 +315,7 @@ #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 @@ -274,6 +351,13 @@ #if !defined(HAVE_FREE_NETDEV) && (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)) #define free_netdev(x) kfree(x) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#define RTL_NAPI_DEL(priv) +#else +#define RTL_NAPI_DEL(priv) netif_napi_del(&priv->napi) +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#else +#define RTL_NAPI_DEL(priv) #endif #ifndef SET_NETDEV_DEV @@ -349,6 +433,13 @@ #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,12 +522,12 @@ #define RSS_SUFFIX "" #endif -#define RTL8168_VERSION "8.053.00" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX RSS_SUFFIX +#define RTL8168_VERSION "8.057.00" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX RSS_SUFFIX #define MODULENAME "r8168" #define PFX MODULENAME ": " #define GPL_CLAIM "\ -r8168 Copyright (C) 2024 Realtek NIC software team <nicfae@realtek.com> \n \ +r8168 Copyright (C) 2026 Realtek NIC software team <nicfae@realtek.com> \n \ This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>. \n \ This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>. \n" @@ -531,7 +622,7 @@ #define NUM_TX_DESC 1024 /* Number of Tx descriptor registers */ #define NUM_RX_DESC 1024 /* Number of Rx descriptor registers */ -#define RX_BUF_SIZE 0x05F2 /* 0x05F2 = 1522bye */ +#define RX_BUF_SIZE 0x05F2 /* 0x05F2 = 1522 bytes */ #define R8168_MAX_TX_QUEUES (2) #define R8168_MAX_RX_QUEUES (4) #define R8168_MAX_QUEUES R8168_MAX_RX_QUEUES @@ -613,6 +704,13 @@ #define ETH_MIN_MTU 68 #endif +#ifndef WRITE_ONCE +#define WRITE_ONCE(var, val) (*((volatile typeof(var) *)(&(var))) = (val)) +#endif +#ifndef READ_ONCE +#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#endif + /*****************************************************************************/ //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) @@ -697,12 +795,6 @@ #define RTL_NAPI_DISABLE(dev, napi) napi_disable(napi) #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) -#define RTL_NAPI_DEL(priv) -#else -#define RTL_NAPI_DEL(priv) netif_napi_del(&priv->napi) -#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) - /*****************************************************************************/ #ifdef CONFIG_R8168_NAPI #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0) @@ -1179,10 +1271,17 @@ 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, @@ -1658,7 +1757,7 @@ R8168_RCV_REQ_DASH_OK, R8168_SEND_REQ_HOST_OK, R8168_CMAC_RESET, - R8168_CMAC_DISALE_RX_FLAG_MAX, + R8168_CMAC_DISABLE_RX_FLAG_MAX, R8168_DASH_REQ_FLAG_MAX }; @@ -1668,6 +1767,8 @@ R8168_FLAG_TASK_ESD_CHECK_PENDING, R8168_FLAG_TASK_LINKCHG_CHECK_PENDING, R8168_FLAG_TASK_DASH_CHECK_PENDING, + R8168_FLAG_SHUTDOWN, + R8168_FLAG_SUSPEND, R8168_FLAG_MAX }; @@ -1689,7 +1790,7 @@ void* priv; struct net_device *netdev; u32 index; - u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ + u32 cur_tx; /* Index into the Tx descriptor buffer of next Tx pkt. */ u32 dirty_tx; u32 num_tx_desc; /* Number of Tx descriptor registers */ u32 tdu; /* Tx descriptor unavailable count */ @@ -1891,6 +1992,20 @@ 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 reserved2; +}; +#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 */ @@ -1971,6 +2086,23 @@ u16 cur_page; u32 bios_setting; + /* module_param per-instance storage */ + int use_dac; + int timer_count; + int dynamic_aspm_packet_threshold; + unsigned int speed_mode; + unsigned int duplex_mode; + unsigned int autoneg_mode; + unsigned int advertising_mode; + int aspm; + int dynamic_aspm; + int s5wol; + int s5_keep_curr_mac; + int s0_magic_packet; + int disable_wol_support; + int enable_giga_lite; + ulong hwoptimize; + int (*set_speed)(struct net_device *, u8 autoneg, u32 speed, u8 duplex, u32 adv); #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) void (*get_settings)(struct net_device *, struct ethtool_cmd *); @@ -2064,6 +2196,8 @@ u8 ring_lib_enabled; + u8 recheck_desc_ownbit; + const char *fw_name; struct rtl8168_fw *rtl_fw; u32 ocp_base; @@ -2073,6 +2207,7 @@ u8 DASH; u8 dash_printer_enabled; u8 HwPkgDet; + u8 HwSuppOcpChannelVer; void __iomem *cmac_ioaddr; /* cmac memory map physical address */ DECLARE_BITMAP(dash_req_flags, R8168_DASH_REQ_FLAG_MAX); @@ -2143,7 +2278,7 @@ //Realwow-------------- #endif //ENABLE_REALWOW_SUPPORT - struct ethtool_eee eee; + struct ethtool_keee eee; u32 dynamic_aspm_packet_count; @@ -2206,7 +2341,7 @@ rtl8168_lib_tx_ring_released(struct rtl8168_private *tp) { int i; - bool released = 0; + bool released = false; for (i = tp->num_tx_rings; i < tp->HwSuppNumTxQueues; i++) { struct rtl8168_ring *ring = &tp->lib_tx_ringi; @@ -2214,7 +2349,7 @@ goto exit; } - released = 1; + released = true; exit: return released; @@ -2224,7 +2359,7 @@ rtl8168_lib_rx_ring_released(struct rtl8168_private *tp) { int i; - bool released = 0; + bool released = false; for (i = 1; i < tp->HwSuppNumRxQueues; i++) { struct rtl8168_ring *ring = &tp->lib_rx_ringi; @@ -2232,7 +2367,7 @@ goto exit; } - released = 1; + released = true; exit: return released; @@ -2255,13 +2390,13 @@ static inline bool rtl8168_lib_tx_ring_released(struct rtl8168_private *tp) { - return 1; + return true; } static inline bool rtl8168_lib_rx_ring_released(struct rtl8168_private *tp) { - return 1; + return true; } #endif @@ -2449,9 +2584,8 @@ 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 +2594,8 @@ 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 @@ -2508,6 +2641,7 @@ void rtl8168_hw_reset(struct net_device *dev); void rtl8168_tx_clear(struct rtl8168_private *tp); void rtl8168_rx_clear(struct rtl8168_private *tp); +void rtl8168_desc_quirk(struct rtl8168_private *tp); int rtl8168_init_ring(struct net_device *dev); int rtl8168_dump_tally_counter(struct rtl8168_private *tp, dma_addr_t paddr); void rtl8168_enable_napi(struct rtl8168_private *tp); @@ -2529,4 +2663,6 @@ #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0) #define netdev_for_each_mc_addr(mclist, dev) \ for (mclist = dev->mc_list; mclist; mclist = mclist->next) -#endif +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) */ + +#endif /* R8168_H */
View file
r8168-8.053.00.tar.gz/src/r8168_asf.c -> r8168-8.057.00.tar.gz/src/r8168_asf.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -58,7 +58,7 @@ struct ifreq *ifr) { struct rtl8168_private *tp = netdev_priv(dev); - void *user_data = ifr->ifr_data; + void __user *user_data = ifr->ifr_data; struct asf_ioctl_struct asf_usrdata; if (tp->mcfg != CFG_METHOD_7 && tp->mcfg != CFG_METHOD_8) @@ -249,8 +249,10 @@ eeprom_off = 75; /* write the new IP address to EEPROM */ - rtl8168_eeprom_write_sc(tp, eeprom_off, (data1 << 8) | data0); - rtl8168_eeprom_write_sc(tp, eeprom_off + 1, (data3 << 8) | data2); + if (eeprom_off != 0) { + rtl8168_eeprom_write_sc(tp, eeprom_off, (data1 << 8) | data0); + rtl8168_eeprom_write_sc(tp, eeprom_off + 1, (data3 << 8) | data2); + } } }
View file
r8168-8.053.00.tar.gz/src/r8168_asf.h -> r8168-8.057.00.tar.gz/src/r8168_asf.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,6 +32,9 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ +#ifndef R8168_ASF_H +#define R8168_ASF_H + #define SIOCDEVPRIVATE_RTLASF SIOCDEVPRIVATE #define FUNCTION_ENABLE 1 @@ -280,16 +283,17 @@ int rtl8168_asf_ioctl(struct net_device *dev, struct ifreq *ifr); void rtl8168_asf_hbperiod(struct rtl8168_private *tp, int arg, unsigned int *data); void rtl8168_asf_wd16rst(struct rtl8168_private *tp, int arg, unsigned int *data); -void rtl8168_asf_console_mac(struct rtl8168_private *, int arg, unsigned int *data); -void rtl8168_asf_ip_address(struct rtl8168_private *, int arg, int offset, unsigned int *data); +void rtl8168_asf_console_mac(struct rtl8168_private *tp, int arg, unsigned int *data); +void rtl8168_asf_ip_address(struct rtl8168_private *tp, int arg, int offset, unsigned int *data); void rtl8168_asf_config_regs(struct rtl8168_private *tp, int arg, int offset, unsigned int *data); void rtl8168_asf_capability_masks(struct rtl8168_private *tp, int arg, int offset, unsigned int *data); void rtl8168_asf_community_string(struct rtl8168_private *tp, int arg, char *string); void rtl8168_asf_community_string_len(struct rtl8168_private *tp, int arg, unsigned int *data); -void rtl8168_asf_alert_resend_interval(struct rtl8168_private *tp, int arg, unsigned int *data); void rtl8168_asf_time_period(struct rtl8168_private *tp, int arg, int offset, unsigned int *data); -void rtl8168_asf_key_access(struct rtl8168_private *, int arg, int offset, unsigned int *data); +void rtl8168_asf_key_access(struct rtl8168_private *tp, int arg, int offset, unsigned int *data); void rtl8168_asf_rw_hexadecimal(struct rtl8168_private *tp, int arg, int offset, int len, unsigned int *data); void rtl8168_asf_rw_iana(struct rtl8168_private *tp, int arg, unsigned int *data); void rtl8168_asf_rw_uuid(struct rtl8168_private *tp, int arg, unsigned int *data); void rtl8168_asf_rw_systemid(struct rtl8168_private *tp, int arg, unsigned int *data); + +#endif /* R8168_ASF_H */
View file
r8168-8.053.00.tar.gz/src/r8168_dash.h -> r8168-8.057.00.tar.gz/src/r8168_dash.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,10 +32,10 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_R8168_DASH_H -#define _LINUX_R8168_DASH_H +#ifndef R8168_DASH_H +#define R8168_DASH_H -#define SIOCDEVPRIVATE_RTLDASH SIOCDEVPRIVATE+2 +#define SIOCDEVPRIVATE_RTLDASH (SIOCDEVPRIVATE+2) enum rtl_dash_cmd { RTL_DASH_ARP_NS_OFFLOAD = 0, @@ -60,7 +60,7 @@ RTL_FW_GET_WAKEUP_PATTERN, RTL_FW_DEL_WAKEUP_PATTERN, - RTLT_DASH_COMMAND_INVALID, + RTL_DASH_COMMAND_INVALID, }; struct rtl_dash_ip_mac { @@ -75,7 +75,7 @@ __u32 len; union { __u32 data; - void *data_buffer; + void __user *data_buffer; }; }; @@ -120,7 +120,7 @@ __le32 resv; __le64 BufferAddress; } -RX_DASH_FROM_FW_DESC, *PRX_DASH_FROM_FW_DESC; +__packed RX_DASH_FROM_FW_DESC, *PRX_DASH_FROM_FW_DESC; typedef struct _TX_DASH_SEND_FW_DESC { __le16 length; @@ -128,7 +128,7 @@ __le32 resv; __le64 BufferAddress; } -TX_DASH_SEND_FW_DESC, *PTX_DASH_SEND_FW_DESC; +__packed TX_DASH_SEND_FW_DESC, *PTX_DASH_SEND_FW_DESC; typedef struct _OSOOBHdr { __le32 len; @@ -137,13 +137,13 @@ u8 hostReqV; u8 res; } -OSOOBHdr, *POSOOBHdr; +__packed OSOOBHdr, *POSOOBHdr; typedef struct _RX_DASH_BUFFER_TYPE_2 { OSOOBHdr oobhdr; - u8 RxDataBuffer0; + u8 RxDataBuffer; } -RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2; +__packed RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2; #define ALIGN_8 (0x7) #define ALIGN_16 (0xf) @@ -160,7 +160,7 @@ #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 #define OCP_REG_CONFIG0_OOBRESET BIT_14 @@ -175,6 +175,9 @@ #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) @@ -202,7 +205,7 @@ #define SystemSlaveDescStartAddrLow (0xF8) #define SystemSlaveDescStartAddrHigh (0xFC) -//DASH Request Type +/* DASH Request Type */ #define WSMANREG 0x01 #define OSPUSHDATA 0x02 @@ -235,16 +238,16 @@ #define RTL8168FP_CMAC_IOBASE 0xBAF20000 #define RTL8168FP_KVM_BASE 0xBAF80400 #define CMAC_SYNC_REG 0x20 -#define CMAC_RXDESC_OFFSET 0x90 //RX: 0x90 - 0x98 -#define CMAC_TXDESC_OFFSET 0x98 //TX: 0x98 - 0x9F +#define CMAC_RXDESC_OFFSET 0x90 /* RX: 0x90 - 0x98 */ +#define CMAC_TXDESC_OFFSET 0x98 /* TX: 0x98 - 0x9F */ /* cmac write/read MMIO register */ -#define RTL_CMAC_W8(tp, reg, val8) writeb ((val8), tp->cmac_ioaddr + (reg)) -#define RTL_CMAC_W16(tp, reg, val16) writew ((val16), tp->cmac_ioaddr + (reg)) -#define RTL_CMAC_W32(tp, reg, val32) writel ((val32), tp->cmac_ioaddr + (reg)) -#define RTL_CMAC_R8(tp, reg) readb (tp->cmac_ioaddr + (reg)) -#define RTL_CMAC_R16(tp, reg) readw (tp->cmac_ioaddr + (reg)) -#define RTL_CMAC_R32(tp, reg) ((unsigned long) readl (tp->cmac_ioaddr + (reg))) +#define RTL_CMAC_W8(tp, reg, val8) writeb ((val8), (tp)->cmac_ioaddr + (reg)) +#define RTL_CMAC_W16(tp, reg, val16) writew ((val16), (tp)->cmac_ioaddr + (reg)) +#define RTL_CMAC_W32(tp, reg, val32) writel ((val32), (tp)->cmac_ioaddr + (reg)) +#define RTL_CMAC_R8(tp, reg) readb ((tp)->cmac_ioaddr + (reg)) +#define RTL_CMAC_R16(tp, reg) readw ((tp)->cmac_ioaddr + (reg)) +#define RTL_CMAC_R32(tp, reg) readl ((tp)->cmac_ioaddr + (reg)) int rtl8168_dash_ioctl(struct net_device *dev, struct ifreq *ifr); bool CheckDashInterrupt(struct net_device *dev, u16 status); @@ -252,6 +255,4 @@ int AllocateDashShareMemory(struct net_device *dev); void FreeAllocatedDashShareMemory(struct net_device *dev); void DashHwInit(struct net_device *dev); - - -#endif /* _LINUX_R8168_DASH_H */ +#endif /* R8168_DASH_H */
View file
r8168-8.053.00.tar.gz/src/r8168_fiber.h -> r8168-8.057.00.tar.gz/src/r8168_fiber.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,8 +32,8 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_R8168_FIBER_H -#define _LINUX_R8168_FIBER_H +#ifndef R8168_FIBER_H +#define R8168_FIBER_H enum { FIBER_MODE_NIC_ONLY = 0, @@ -72,4 +72,4 @@ void rtl8168_check_hw_fiber_mode_support(struct rtl8168_private *tp); void rtl8168_set_fiber_mode_software_variable(struct rtl8168_private *tp); -#endif /* _LINUX_R8168_FIBER_H */ +#endif /* R8168_FIBER_H */
View file
r8168-8.053.00.tar.gz/src/r8168_firmware.c -> r8168-8.057.00.tar.gz/src/r8168_firmware.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -139,7 +139,7 @@ break; case PHY_BJMPN: - if (regno > index) + if (regno >= index) goto out; break; case PHY_READCOUNT_EQ_SKIP:
View file
r8168-8.053.00.tar.gz/src/r8168_firmware.h -> r8168-8.057.00.tar.gz/src/r8168_firmware.h
Changed
@@ -5,7 +5,7 @@ # 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. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,8 +32,8 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_RTL8168_FIRMWARE_H -#define _LINUX_RTL8168_FIRMWARE_H +#ifndef R8168_FIRMWARE_H +#define R8168_FIRMWARE_H #include <linux/device.h> #include <linux/firmware.h> @@ -65,4 +65,4 @@ void rtl8168_fw_release_firmware(struct rtl8168_fw *rtl_fw); void rtl8168_fw_write_firmware(struct rtl8168_private *tp, struct rtl8168_fw *rtl_fw); -#endif /* _LINUX_RTL8168_FIRMWARE_H */ +#endif /* R8168_FIRMWARE_H */
View file
r8168-8.053.00.tar.gz/src/r8168_n.c -> r8168-8.057.00.tar.gz/src/r8168_n.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -478,8 +478,13 @@ #else static int disable_wol_support = 0; #endif +#ifdef ENABLE_GIGA_LITE +static int enable_giga_lite = 1; +#else +static int enable_giga_lite = 0; +#endif -MODULE_AUTHOR("Realtek and the Linux r8168 crew <netdev@vger.kernel.org>"); +MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); MODULE_DESCRIPTION("RealTek RTL-8168 Gigabit Ethernet driver"); module_param(speed_mode, uint, 0); @@ -498,7 +503,7 @@ MODULE_PARM_DESC(aspm, "Enable ASPM."); module_param(dynamic_aspm, int, 0); -MODULE_PARM_DESC(aspm, "Enable Software Dynamic ASPM."); +MODULE_PARM_DESC(dynamic_aspm, "Enable Software Dynamic ASPM."); module_param(s5wol, int, 0); MODULE_PARM_DESC(s5wol, "Enable Shutdown Wake On Lan."); @@ -527,11 +532,34 @@ module_param(disable_wol_support, int, 0); MODULE_PARM_DESC(disable_wol_support, "Disable PM support."); +module_param(enable_giga_lite, int, 0); +MODULE_PARM_DESC(enable_giga_lite, "Enable Giga Lite."); + #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) module_param_named(debug, debug.msg_enable, int, 0); MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); #endif//LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0) +static void rtl8168_init_module_params(struct rtl8168_private *tp) +{ + tp->use_dac = use_dac; + tp->timer_count = timer_count; + tp->dynamic_aspm_packet_threshold = dynamic_aspm_packet_threshold; + tp->speed_mode = speed_mode; + tp->duplex_mode = duplex_mode; + tp->autoneg_mode = autoneg_mode; + tp->advertising_mode = advertising_mode; + tp->aspm = aspm; + tp->dynamic_aspm = dynamic_aspm; + tp->s5wol = s5wol; + tp->s5_keep_curr_mac = s5_keep_curr_mac; + tp->s0_magic_packet = s0_magic_packet; + tp->disable_wol_support = disable_wol_support; + tp->enable_giga_lite = enable_giga_lite; + tp->hwoptimize = hwoptimize; + tp->eee.eee_enabled = eee_enable; +} + MODULE_LICENSE("GPL"); #ifdef ENABLE_USE_FIRMWARE_FILE MODULE_FIRMWARE(FIRMWARE_8168D_1); @@ -618,6 +646,9 @@ static int rtl8168_set_phy_mcu_patch_request(struct rtl8168_private *tp); static int rtl8168_clear_phy_mcu_patch_request(struct rtl8168_private *tp); +static u32 rtl8168_pci_config_read(struct rtl8168_private *tp, u32 addr); +static void rtl8168_pci_config_write(struct rtl8168_private *tp, u32 addr, u32 value); + #ifdef CONFIG_R8168_NAPI static int rtl8168_poll(napi_ptr napi, napi_budget budget); #endif @@ -992,7 +1023,7 @@ #endif } -static u32 rtl8168_convert_link_speed(u16 status) +static u32 rtl8168_convert_link_speed(struct rtl8168_private *tp, u16 status) { u32 speed = SPEED_UNKNOWN; @@ -1003,6 +1034,10 @@ speed = SPEED_100; else if (status & _10bps) speed = SPEED_10; + else { + if (tp->enable_giga_lite) + speed = SPEED_1000; + } } return speed; @@ -1038,7 +1073,7 @@ wait_cnt = 0; do { - mdelay(1); + fsleep(1000); val = rtl8168_mdio_read(tp, 0x11); wait_cnt++; } while (!(val & BIT_15) && (wait_cnt < 5000)); @@ -1280,18 +1315,19 @@ seq_printf(m, "DASH\t0x%x\n", tp->DASH); seq_printf(m, "dash_printer_enabled\t0x%x\n", tp->dash_printer_enabled); seq_printf(m, "HwSuppKCPOffloadVer\t0x%x\n", tp->HwSuppKCPOffloadVer); - seq_printf(m, "speed_mode\t0x%x\n", speed_mode); - seq_printf(m, "duplex_mode\t0x%x\n", duplex_mode); - seq_printf(m, "autoneg_mode\t0x%x\n", autoneg_mode); - seq_printf(m, "advertising_mode\t0x%x\n", advertising_mode); - seq_printf(m, "aspm\t0x%x\n", aspm); - seq_printf(m, "s5wol\t0x%x\n", s5wol); - seq_printf(m, "s5_keep_curr_mac\t0x%x\n", s5_keep_curr_mac); + seq_printf(m, "speed_mode\t0x%x\n", tp->speed_mode); + seq_printf(m, "duplex_mode\t0x%x\n", tp->duplex_mode); + seq_printf(m, "autoneg_mode\t0x%x\n", tp->autoneg_mode); + seq_printf(m, "advertising_mode\t0x%x\n", tp->advertising_mode); + seq_printf(m, "aspm\t0x%x\n", tp->aspm); + seq_printf(m, "s5wol\t0x%x\n", tp->s5wol); + seq_printf(m, "s5_keep_curr_mac\t0x%x\n", tp->s5_keep_curr_mac); seq_printf(m, "eee_enable\t0x%x\n", tp->eee.eee_enabled); - seq_printf(m, "hwoptimize\t0x%lx\n", hwoptimize); + seq_printf(m, "hwoptimize\t0x%lx\n", tp->hwoptimize); seq_printf(m, "proc_init_num\t0x%x\n", proc_init_num); - seq_printf(m, "s0_magic_packet\t0x%x\n", s0_magic_packet); - seq_printf(m, "disable_wol_support\t0x%x\n", disable_wol_support); + seq_printf(m, "s0_magic_packet\t0x%x\n", tp->s0_magic_packet); + seq_printf(m, "disable_wol_support\t0x%x\n", tp->disable_wol_support); + seq_printf(m, "enable_giga_lite\t0x%x\n", tp->enable_giga_lite); seq_printf(m, "HwSuppMagicPktVer\t0x%x\n", tp->HwSuppMagicPktVer); seq_printf(m, "HwSuppUpsVer\t0x%x\n", tp->HwSuppUpsVer); seq_printf(m, "HwSuppEsdVer\t0x%x\n", tp->HwSuppEsdVer); @@ -1503,16 +1539,16 @@ seq_printf(m, "\n0x%03x:\t", n); for (i = 0; i < 4 && n < max; i++, n+=4) { - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); seq_printf(m, "%08x ", dword_rd); } } n = 0x110; - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); seq_printf(m, "\n0x%03x:\t%08x ", n, dword_rd); n = 0x70c; - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); seq_printf(m, "\n0x%03x:\t%08x ", n, dword_rd); rtnl_unlock(); @@ -1560,7 +1596,7 @@ status = RTL_R8(tp, PHYstatus); if (status & LinkStatus) seq_printf(m, "\nlink speed:%d", - rtl8168_convert_link_speed(status)); + rtl8168_convert_link_speed(tp, status)); else seq_puts(m, "\nlink status:off"); @@ -1701,26 +1737,35 @@ rtnl_lock(); - for (i=0; i<tp->HwSuppNumTxQueues; i++) { - struct rtl8168_tx_ring *ring = &tp->tx_ringi; - if (!ring->TxDescArray) - continue; - seq_printf(m, "\ndump Q%d tx desc:%d\n", i, ring->num_tx_desc); +#ifdef ENABLE_LIB_SUPPORT + (void)i; + if (tp->tx_ring0.TxDescArray) { + struct rtl8168_tx_ring *ring = &tp->tx_ring0; + + 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); } -#ifdef ENABLE_LIB_SUPPORT - for (i=0; i<tp->HwSuppNumTxQueues; i++) { - struct rtl8168_ring *ring = &tp->lib_tx_ringi; - if (!ring->desc_addr) - continue; - seq_printf(m, "\ndump lib Q%d tx desc:%d\n", i, ring->ring_size); + if (tp->lib_tx_ring1.desc_addr) { + struct rtl8168_ring *ring = &tp->lib_tx_ring1; + + 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; i<tp->HwSuppNumTxQueues; i++) { + struct rtl8168_tx_ring *ring = &tp->tx_ringi; + if (!ring->TxDescArray) + continue; + seq_printf(m, "\ndump Q%d tx desc:%d\n", i, ring->num_tx_desc); + _proc_dump_tx_desc(m, ring->TxDescArray, + ring->TxDescAllocSize, + ring->num_tx_desc); + } #endif //ENABLE_LIB_SUPPORT rtnl_unlock(); @@ -1766,6 +1811,50 @@ seq_putc(m, '\n'); return 0; } + +static int proc_dump_mac_mcu_bp(struct seq_file *m, void *v) +{ + int i, j; + struct net_device *dev = m->private; + struct rtl8168_private *tp = netdev_priv(dev); + + switch (tp->mcfg) { + case CFG_METHOD_1 ... CFG_METHOD_20: + return -EOPNOTSUPP; + default: + break; + } + + rtnl_lock(); + + seq_printf(m, "\ndump MAC MCU BPs. \n"); + + switch (tp->mcfg) { + case CFG_METHOD_29: + case CFG_METHOD_30: + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + case CFG_METHOD_35: + case CFG_METHOD_36: + case CFG_METHOD_37: + seq_printf(m, "BP_EN 0x%04x \n", rtl8168_mac_ocp_read(tp, 0xFC38)); + break; + } + + seq_printf(m, "BP Base 0x%04x \n", rtl8168_mac_ocp_read(tp, 0xFC26)); + + for (i=0xFC28, j=0; i<0xFC38; i+=2, j++) { + seq_printf(m, "BP%02d(0x%04x) 0x%04x \n", j, i, + rtl8168_mac_ocp_read(tp, i)); + } + + rtnl_unlock(); + + seq_putc(m, '\n'); + return 0; +} #else static int proc_get_driver_variable(char *page, char **start, @@ -1810,7 +1899,7 @@ "tdu0\t0x%x\n" "cur_tx1\t0x%x\n" "dirty_tx1\t0x%x\n" - "tdu0\t1x%x\n" + "tdu1\t0x%x\n" "rx_buf_sz\t0x%x\n" "esd_flag\t0x%x\n" "pci_cfg_is_read\t0x%x\n" @@ -1872,6 +1961,7 @@ "proc_init_num\t0x%x\n" "s0_magic_packet\t0x%x\n" "disable_wol_support\t0x%x\n" + "enable_giga_lite\t0x%x\n" "HwSuppMagicPktVer\t0x%x\n" "HwSuppUpsVer\t0x%x\n" "HwSuppEsdVer\t0x%x\n" @@ -1883,7 +1973,6 @@ "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" @@ -1974,18 +2063,19 @@ tp->DASH, tp->dash_printer_enabled, tp->HwSuppKCPOffloadVer, - speed_mode, - duplex_mode, - autoneg_mode, - advertising_mode, - aspm, - s5wol, - s5_keep_curr_mac, + tp->speed_mode, + tp->duplex_mode, + tp->autoneg_mode, + tp->advertising_mode, + tp->aspm, + tp->s5wol, + tp->s5_keep_curr_mac, tp->eee.eee_enabled, - hwoptimize, + tp->hwoptimize, proc_init_num, - s0_magic_packet, - disable_wol_support, + tp->s0_magic_packet, + tp->disable_wol_support, + tp->enable_giga_lite, tp->HwSuppMagicPktVer, tp->HwSuppUpsVer, tp->HwSuppEsdVer, @@ -2029,8 +2119,6 @@ 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, @@ -2052,19 +2140,19 @@ "Statistics\tValue\n----------\t-----\n"); len += snprintf(page + len, count - len, - "tx_packets\t%lld\n" - "rx_packets\t%lld\n" - "tx_errors\t%lld\n" - "rx_errors\t%d\n" - "rx_missed\t%d\n" - "align_errors\t%d\n" - "tx_one_collision\t%d\n" - "tx_multi_collision\t%d\n" - "rx_unicast\t%lld\n" - "rx_broadcast\t%lld\n" - "rx_multicast\t%d\n" - "tx_aborted\t%d\n" - "tx_underrun\t%d\n", + "tx_packets\t%llu\n" + "rx_packets\t%llu\n" + "tx_errors\t%llu\n" + "rx_errors\t%u\n" + "rx_missed\t%u\n" + "align_errors\t%u\n" + "tx_one_collision\t%u\n" + "tx_multi_collision\t%u\n" + "rx_unicast\t%llu\n" + "rx_broadcast\t%llu\n" + "rx_multicast\t%u\n" + "tx_aborted\t%u\n" + "tx_underrun\t%u\n", le64_to_cpu(counters->tx_packets), le64_to_cpu(counters->rx_packets), le64_to_cpu(counters->tx_errors), @@ -2272,7 +2360,7 @@ n); for (i = 0; i < 4 && n < max; i++, n+=4) { - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); len += snprintf(page + len, count - len, "%08x ", dword_rd); @@ -2280,13 +2368,13 @@ } n = 0x110; - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); len += snprintf(page + len, count - len, "\n0x%03x:\t%08x ", n, dword_rd); n = 0x70c; - pci_read_config_dword(tp->pci_dev, n, &dword_rd); + dword_rd = rtl8168_pci_config_read(tp, n); len += snprintf(page + len, count - len, "\n0x%03x:\t%08x ", n, @@ -2334,7 +2422,7 @@ if (status & LinkStatus) len += snprintf(page + len, count - len, "\nlink speed:%d", - rtl8168_convert_link_speed(status)); + rtl8168_convert_link_speed(tp, status)); else len += snprintf(page + len, count - len, "\nlink status:off"); @@ -2499,7 +2587,7 @@ pdwordi); } - len += snprintf(page + len, count - len, "\n"); + len += snprintf(page + len, *count - len, "\n"); *page_len = len; return; @@ -2511,7 +2599,6 @@ { 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_ring0; @@ -2521,13 +2608,13 @@ rtnl_lock(); - for (i=0; i<tp->HwSuppNumTxQueues; i++) { - struct rtl8168_tx_ring *ring = &tp->tx_ringi; - if (!ring->TxDescArray) - continue; +#ifdef ENABLE_LIB_SUPPORT + (void)i; + if (tp->tx_ring0.TxDescArray) { + struct rtl8168_tx_ring *ring = &tp->tx_ring0; + 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 +2622,31 @@ ring->num_tx_desc); } -#ifdef ENABLE_LIB_SUPPORT - for (i=0; i<tp->HwSuppNumTxQueues; i++) { - struct rtl8168_ring *ring = &tp->lib_tx_ringi; - if (!ring->desc_addr) - continue; + if (tp->lib_tx_ring1.desc_addr) { + struct rtl8168_ring *ring = &tp->lib_tx_ring1; + 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; i<tp->HwSuppNumTxQueues; i++) { + struct rtl8168_tx_ring *ring = &tp->tx_ringi; + 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,12 +2658,14 @@ return len; } -static int proc_dump_tx_desc(char *page, char **start, - off_t offset, int count, - int *eof, void *data) +static int proc_dump_msix_tbl(char *page, char **start, + off_t offset, int count, + int *eof, void *data) { - int i; - struct net_device *dev = m->private; + int i, j; + int len = 0; + void __iomem *ioaddr; + struct net_device *dev = data; struct rtl8168_private *tp = netdev_priv(dev); switch (tp->mcfg) { @@ -2574,32 +2675,23 @@ break; } + /* ioremap MMIO region */ + ioaddr = ioremap(pci_resource_start(tp->pci_dev, 4), pci_resource_len(tp->pci_dev, 4)); + if (!ioaddr) + return -EFAULT; + rtnl_lock(); len += snprintf(page + len, count - len, "\ndump MSI-X Table. Total Entry %d. \n", - R8168_MAX_MSIX_VEC); + tp->hw_supp_irq_nvecs); - for (i=0; i<R8168_MAX_MSIX_VEC; i++) { - len += snprintf(page + len, count - len, - "\n%04x ", - i); - len += snprintf(page + len, count - len, - "%08x ", - rtl8168_eri_read(tp, i*0x10, 4, - ERIAR_MSIX)); - len += snprintf(page + len, count - len, - "%08x ", - rtl8168_eri_read(tp, i*0x10 + 4, 4, - ERIAR_MSIX)); - len += snprintf(page + len, count - len, - "%08x ", - rtl8168_eri_read(tp, i*0x10 + 8, 4, - ERIAR_MSIX)); + for (i=0; i<tp->hw_supp_irq_nvecs; i++) { len += snprintf(page + len, count - len, - "%08x ", - rtl8168_eri_read(tp, i*0x10 + 12, 4, - ERIAR_MSIX)); + "\n%04x ", i); + for (j=0; j<4; j++) + len += snprintf(page + len, count - len, "%08x ", + readl(ioaddr + i*0x10 + 4*j)); } rtnl_unlock(); @@ -2607,44 +2699,52 @@ len += snprintf(page + len, count - len, "\n"); *eof = 1; - - return len; + return 0; } -static int proc_dump_msix_tbl(char *page, char **start, - off_t offset, int count, - int *eof, void *data) +static int proc_dump_mac_mcu_bp(char *page, char **start, + off_t offset, int count, + int *eof, void *data) { int i, j; int len = 0; - void __iomem *ioaddr; struct net_device *dev = data; struct rtl8168_private *tp = netdev_priv(dev); switch (tp->mcfg) { - case CFG_METHOD_1 ... CFG_METHOD_8: + case CFG_METHOD_1 ... CFG_METHOD_20: return -EOPNOTSUPP; default: break; } - /* ioremap MMIO region */ - ioaddr = ioremap(pci_resource_start(tp->pci_dev, 4), pci_resource_len(tp->pci_dev, 4)); - if (!ioaddr) - return -EFAULT; - rtnl_lock(); len += snprintf(page + len, count - len, - "\ndump MSI-X Table. Total Entry %d. \n", - tp->hw_supp_irq_nvecs); + "\ndump MAC MCU BPs. \n"); - for (i=0; i<tp->hw_supp_irq_nvecs; i++) { + switch (tp->mcfg) { + case CFG_METHOD_29: + case CFG_METHOD_30: + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + case CFG_METHOD_35: + case CFG_METHOD_36: + case CFG_METHOD_37: + len += snprintf(page + len, count - len, "BP_EN 0x%04x \n", + rtl8168_mac_ocp_read(tp, 0xFC38)); + break; + } + + len += snprintf(page + len, count - len, "BP Base 0x%04x \n", + rtl8168_mac_ocp_read(tp, 0xFC26)); + + for (i=0xFC28, j=0; i<0xFC38; i+=2, j++) { len += snprintf(page + len, count - len, - "\n%04x ", i); - for (j=0; j<4; j++) - len += snprintf(page + len, count - len, "%08x ", - readl(ioaddr + i*0x10 + 4*j)); + "BP%02d(0x%04x) 0x%04x \n", j, i, + rtl8168_mac_ocp_read(tp, i)); } rtnl_unlock(); @@ -2726,6 +2826,7 @@ { "rx_desc", &proc_dump_rx_desc }, { "rx_desc_2", &proc_dump_rx_desc_2 }, { "msix_tbl", &proc_dump_msix_tbl }, + { "mac_mcu_bp", &proc_dump_mac_mcu_bp }, { "" } }; @@ -2898,9 +2999,11 @@ struct net_device *netdev = to_net_dev(dev); struct rtl8168_private *tp = netdev_priv(netdev); - sprintf(buf, "%u\n", tp->testmode); - - return strlen(buf); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,103) + return sprintf(buf, "%u\n", tp->testmode); +#else + return sysfs_emit(buf, "%u\n", tp->testmode); +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,4,103) */ } static ssize_t testmode_store(struct device *dev, @@ -3011,7 +3114,7 @@ RTL_W32(tp, PHYOCP, data32); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); if (!(RTL_R32(tp, PHYOCP) & OCPR_Flag)) break; @@ -3074,7 +3177,7 @@ RTL_W32(tp, EPHY_RXER_NUM, 0); for (i = 0; i < 100; i++) { - mdelay(1); + fsleep(1000); if (!(RTL_R32(tp, OCPAR) & OCPAR_Flag)) break; } @@ -3093,11 +3196,11 @@ (value & PHYAR_Data_Mask)); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed writing to the specified MII register */ if (!(RTL_R32(tp, PHYAR) & PHYAR_Flag)) { - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); break; } } @@ -3149,7 +3252,7 @@ RTL_W32(tp, PHYOCP, data32); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); if (RTL_R32(tp, PHYOCP) & OCPR_Flag) break; @@ -3206,17 +3309,17 @@ RTL_W32(tp, EPHY_RXER_NUM, 0); for (i = 0; i < 100; i++) { - mdelay(1); + fsleep(1000); if (!(RTL_R32(tp, OCPAR) & OCPAR_Flag)) break; } - mdelay(1); + fsleep(1000); RTL_W32(tp, OCPAR, OCPAR_GPHY_Read); RTL_W32(tp, EPHY_RXER_NUM, 0); for (i = 0; i < 100; i++) { - mdelay(1); + fsleep(1000); if (RTL_R32(tp, OCPAR) & OCPAR_Flag) break; } @@ -3233,12 +3336,12 @@ PHYAR_Read | (RegAddr & PHYAR_Reg_Mask) << PHYAR_Reg_shift); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed retrieving data from the specified MII register */ if (RTL_R32(tp, PHYAR) & PHYAR_Flag) { value = RTL_R32(tp, PHYAR) & PHYAR_Data_Mask; - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); break; } } @@ -3407,7 +3510,7 @@ RTL_W32(tp, OCPAR, (0x0F<<12) | (addr&0xFFF)); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); if (RTL_R32(tp, OCPAR) & OCPAR_Flag) break; } @@ -3429,7 +3532,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return value2; } @@ -3441,16 +3544,21 @@ u32 rtl8168_ocp_read(struct rtl8168_private *tp, u16 addr, u8 len) { - u32 value = 0; - - if (HW_DASH_SUPPORT_TYPE_2(tp)) - value = rtl8168_ocp_read_with_oob_base_address(tp, addr, len, NO_BASE_ADDRESS); - else if (HW_DASH_SUPPORT_TYPE_3(tp)) - value = rtl8168_ocp_read_with_oob_base_address(tp, addr, len, RTL8168FP_OOBMAC_BASE); - else - value = real_ocp_read(tp, addr, len); - - return value; + switch (tp->HwSuppOcpChannelVer) { + case 1: + return real_ocp_read(tp, addr, len); + case 2: + return rtl8168_ocp_read_with_oob_base_address(tp, addr, len, + NO_BASE_ADDRESS); + case 3: + return rtl8168_ocp_read_with_oob_base_address(tp, addr, len, + RTL8168FP_OOBMAC_BASE); + default: +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) + WARN_ON_ONCE(1); +#endif + return 0; + } } static int real_ocp_write(struct rtl8168_private *tp, u16 addr, u8 len, u32 value) @@ -3477,7 +3585,7 @@ RTL_W32(tp, OCPAR, OCPAR_Flag | (0x0F<<12) | (addr&0xFFF)); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed ERI write */ if (!(RTL_R32(tp, OCPAR) & OCPAR_Flag)) @@ -3493,7 +3601,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return 0; } @@ -3505,12 +3613,21 @@ void rtl8168_ocp_write(struct rtl8168_private *tp, u16 addr, u8 len, u32 value) { - if (HW_DASH_SUPPORT_TYPE_2(tp)) - rtl8168_ocp_write_with_oob_base_address(tp, addr, len, value, NO_BASE_ADDRESS); - else if (HW_DASH_SUPPORT_TYPE_3(tp)) - rtl8168_ocp_write_with_oob_base_address(tp, addr, len, value, RTL8168FP_OOBMAC_BASE); - else + switch (tp->HwSuppOcpChannelVer) { + case 1: real_ocp_write(tp, addr, len, value); + break; + case 2: + rtl8168_ocp_write_with_oob_base_address(tp, addr, len, value, + NO_BASE_ADDRESS); + break; + case 3: + rtl8168_ocp_write_with_oob_base_address(tp, addr, len, value, + RTL8168FP_OOBMAC_BASE); + break; + default: + break; + } } void rtl8168_oob_mutex_lock(struct rtl8168_private *tp) @@ -3625,7 +3742,20 @@ rtl8168_ocp_write(tp, 0x30, 1, 0x01); } -static int rtl8168_check_dash(struct rtl8168_private *tp) +static u32 rtl8168_get_dash_fw_ver(struct rtl8168_private *tp) +{ + u32 ver = 0xffffffff; + + if (!HW_DASH_SUPPORT_GET_FIRMWARE_VERSION(tp)) + goto exit; + + ver = rtl8168_ocp_read(tp, OCP_REG_FIRMWARE_MAJOR_VERSION, 4); + +exit: + return ver; +} + +static int _rtl8168_check_dash(struct rtl8168_private *tp) { if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) { if (rtl8168_ocp_read(tp, 0x128, 1) & BIT_0) @@ -3647,12 +3777,31 @@ } } +static int rtl8168_check_dash(struct rtl8168_private *tp) +{ + int dash_enabled; + u32 fw_ver; + + dash_enabled = _rtl8168_check_dash(tp); + if (!dash_enabled) + goto exit; + + if (!HW_DASH_SUPPORT_GET_FIRMWARE_VERSION(tp)) + goto exit; + + fw_ver = rtl8168_get_dash_fw_ver(tp); + if (fw_ver == 0 || fw_ver == 0xffffffff) + dash_enabled = 0; +exit: + return dash_enabled; +} + void rtl8168_dash2_disable_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)) { u16 WaitCnt; u8 TmpUchar; @@ -3668,7 +3817,7 @@ break; } - udelay(50); + fsleep(50); WaitCnt++; } while(WaitCnt < 2000); @@ -3682,7 +3831,7 @@ 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 +3840,7 @@ 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 +3849,7 @@ 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 +3857,7 @@ { 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); } @@ -3740,14 +3889,14 @@ (value & EPHYAR_Data_Mask)); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed EPHY write */ if (!(RTL_R32(tp, EPHYAR) & EPHYAR_Flag)) break; } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); } void rtl8168_ephy_write(struct rtl8168_private *tp, int addr, int value) @@ -3764,7 +3913,7 @@ EPHYAR_Read | (addr & EPHYAR_Reg_Mask) << EPHYAR_Reg_shift); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed EPHY read */ if (RTL_R32(tp, EPHYAR) & EPHYAR_Flag) { @@ -3773,7 +3922,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return value; } @@ -3836,7 +3985,7 @@ RTL_W32(tp, CSIAR, cmd); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed CSI read */ if (RTL_R32(tp, CSIAR) & CSIAR_Flag) { @@ -3845,7 +3994,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return value; } @@ -3876,14 +4025,14 @@ RTL_W32(tp, CSIAR, cmd); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed CSI write */ if (!(RTL_R32(tp, CSIAR) & CSIAR_Flag)) break; } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); } static u32 @@ -3947,7 +4096,7 @@ pci_read_config_byte(pdev, addr, &RetVal); } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return RetVal; } @@ -3976,7 +4125,7 @@ pci_write_config_byte(pdev, addr, value); } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); } static void @@ -4147,7 +4296,7 @@ RTL_W32(tp, ERIAR, eri_cmd); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed ERI read */ if (RTL_R32(tp, ERIAR) & ERIAR_Flag) @@ -4171,7 +4320,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return value2; } @@ -4221,7 +4370,7 @@ RTL_W32(tp, ERIAR, eri_cmd); for (i = 0; i < R8168_CHANNEL_WAIT_COUNT; i++) { - udelay(R8168_CHANNEL_WAIT_TIME); + fsleep(R8168_CHANNEL_WAIT_TIME); /* Check if the RTL8168 has completed ERI write */ if (!(RTL_R32(tp, ERIAR) & ERIAR_Flag)) @@ -4237,7 +4386,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return 0; } @@ -4247,6 +4396,34 @@ return rtl8168_eri_write_with_oob_base_address(tp, addr, len, value, type, NO_BASE_ADDRESS); } +static u32 +rtl8168_pci_config_read(struct rtl8168_private *tp, + u32 addr) +{ + struct pci_dev *pdev = tp->pci_dev; + u32 val; + + if (pdev->cfg_size > (addr + 3) && + pci_read_config_dword(pdev, addr, &val) == PCIBIOS_SUCCESSFUL) + return val; + else + return rtl8168_csi_read(tp, addr); +} + +static void +rtl8168_pci_config_write(struct rtl8168_private *tp, + u32 addr, + u32 value) +{ + struct pci_dev *pdev = tp->pci_dev; + + if (pdev->cfg_size > (addr + 3) && + pci_write_config_dword(pdev, addr, value) == PCIBIOS_SUCCESSFUL) + return; + else + rtl8168_csi_write(tp, addr, value); +} + static void rtl8168_enable_rxdvgate(struct net_device *dev) { @@ -4271,7 +4448,6 @@ case CFG_METHOD_36: case CFG_METHOD_37: RTL_W8(tp, 0xF2, RTL_R8(tp, 0xF2) | BIT_3); - mdelay(2); break; } } @@ -4300,7 +4476,6 @@ case CFG_METHOD_36: case CFG_METHOD_37: RTL_W8(tp, 0xF2, RTL_R8(tp, 0xF2) & ~BIT_3); - mdelay(2); break; } } @@ -4392,18 +4567,18 @@ case CFG_METHOD_36: case CFG_METHOD_37: for (i = 0; i < 10; i++) { - udelay(100); + fsleep(100); if (RTL_R32(tp, TxConfig) & BIT_11) break; } for (i = 0; i < 10; i++) { - udelay(100); + fsleep(100); if ((RTL_R8(tp, MCUCmd_reg) & (Txfifo_empty | Rxfifo_empty)) == (Txfifo_empty | Rxfifo_empty)) break; } - mdelay(1); + fsleep(2000); break; } } @@ -4422,7 +4597,7 @@ int timeout; for (timeout = 0; timeout < 10; timeout++) { - mdelay(10); + fsleep(10000); if (rtl8168_ocp_read(tp, 0x124, 1) & BIT_0) { rc = 1; goto out; @@ -4438,7 +4613,7 @@ reg = 0x10; for (timeout = 0; timeout < 10; timeout++) { - mdelay(10); + fsleep(10000); if (rtl8168_ocp_read(tp, reg, 2) & BIT_11) { rc = 1; goto out; @@ -4646,8 +4821,8 @@ rtl8168_switch_to_timer_interrupt(struct rtl8168_private *tp) { if (tp->use_timer_interrrupt) { - RTL_W32(tp, TimeInt0, timer_count); - RTL_W32(tp, TCTR, timer_count); + RTL_W32(tp, TimeInt0, tp->timer_count); + RTL_W32(tp, TCTR, tp->timer_count); RTL_W16(tp, tp->imr_reg0, tp->timer_intr_mask); #ifdef ENABLE_DASH_SUPPORT @@ -4670,9 +4845,8 @@ 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); @@ -4710,7 +4884,7 @@ case CFG_METHOD_1: case CFG_METHOD_2: case CFG_METHOD_3: - mdelay(10); + fsleep(10000); break; case CFG_METHOD_4: case CFG_METHOD_5: @@ -4722,7 +4896,7 @@ case CFG_METHOD_14: case CFG_METHOD_15: RTL_W8(tp, ChipCmd, StopReq | CmdRxEnb | CmdTxEnb); - udelay(100); + fsleep(100); break; case CFG_METHOD_11: case CFG_METHOD_12: @@ -4730,7 +4904,7 @@ for (i = 0; i < 2000; i++) { if (!(RTL_R8(tp, TxPoll) & NPQ)) break; - udelay(100); + fsleep(100); } break; case CFG_METHOD_21: @@ -4750,10 +4924,10 @@ case CFG_METHOD_35: case CFG_METHOD_36: case CFG_METHOD_37: - mdelay(2); + fsleep(2000); break; default: - mdelay(10); + fsleep(10000); break; } @@ -4764,7 +4938,7 @@ /* Check that the chip has finished the reset. */ for (i = 100; i > 0; i--) { - udelay(100); + fsleep(100); if ((RTL_R8(tp, ChipCmd) & CmdReset) == 0) break; } @@ -4778,7 +4952,7 @@ rtl8168_oob_notify(tp, OOB_CMD_RESET); for (i = 0; i < 10; i++) { - mdelay(10); + fsleep(10000); if (rtl8168_ocp_read(tp, 0x010, 2)&0x00004000) break; } @@ -4910,14 +5084,16 @@ tmpAddr = skb_put(skb, len - 14); mapping = dma_map_single(tp_to_dev(tp), skb->data, len, DMA_TO_DEVICE); - dma_sync_single_for_cpu(tp_to_dev(tp), le64_to_cpu(mapping), - len, DMA_TO_DEVICE); + if (dma_mapping_error(tp_to_dev(tp), mapping)) { + dev_kfree_skb(skb); + return; + } txd->addr = cpu_to_le64(mapping); txd->opts2 = 0; while (1) { memset(tmpAddr, pattern++, len - 14); dma_sync_single_for_device(&tp->pci_dev->dev, - le64_to_cpu(mapping), + mapping, len, DMA_TO_DEVICE); txd->opts1 = cpu_to_le32(DescOwn | FirstFrag | LastFrag | len); @@ -4927,7 +5103,7 @@ rtl8168_doorbell(tx_ring); /* set polling bit */ for (i = 0; i < 50; i++) { - udelay(200); + fsleep(200); rx_cmd = le32_to_cpu(rxd->opts1); if ((rx_cmd & DescOwn) == 0) break; @@ -4939,8 +5115,6 @@ rx_len -= 4; rxd->opts1 = cpu_to_le32(DescOwn | tp->rx_buf_sz); - dma_sync_single_for_cpu(tp_to_dev(tp), le64_to_cpu(mapping), len, DMA_TO_DEVICE); - if (rx_len == len) { dma_sync_single_for_cpu(tp_to_dev(tp), le64_to_cpu(rxd->addr), tp->rx_buf_sz, DMA_FROM_DEVICE); i = memcmp(skb->data, rx_skb->data, rx_len); @@ -5001,7 +5175,7 @@ if (!val) return 0; - mdelay(1); + fsleep(1000); } return -1; @@ -5196,7 +5370,7 @@ if (!tp->HwSuppAspmClkIntrLock) return; - if (enable && aspm) { + if (enable && tp->aspm) { RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); } else { @@ -5204,7 +5378,7 @@ RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); } - udelay(10); + fsleep(10); } #ifdef ENABLE_DASH_SUPPORT @@ -5215,7 +5389,7 @@ // // 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_reg0, (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET)); } else { @@ -5343,7 +5517,7 @@ rtl8168_init_ring(dev); - if (dynamic_aspm) { + if (tp->dynamic_aspm) { rtl8168_enable_cfg9346_write(tp); rtl8168_hw_aspm_clkreq_enable(tp, true); rtl8168_disable_cfg9346_write(tp); @@ -5424,9 +5598,9 @@ break; } } else { - if (dynamic_aspm) { + if (tp->dynamic_aspm) { bool enable_hw_aspm_clkreq = true; - if (tp->dynamic_aspm_packet_count > dynamic_aspm_packet_threshold) + if (tp->dynamic_aspm_packet_count > tp->dynamic_aspm_packet_threshold) enable_hw_aspm_clkreq = false; rtl8168_enable_cfg9346_write(tp); @@ -5438,33 +5612,30 @@ } static void -rtl8168_link_option(u8 *aut, - u32 *spd, - u8 *dup, - u32 *adv) -{ - if ((*spd != SPEED_1000) && (*spd != SPEED_100) && (*spd != SPEED_10)) - *spd = SPEED_1000; - - if ((*dup != DUPLEX_FULL) && (*dup != DUPLEX_HALF)) - *dup = DUPLEX_FULL; - - if ((*aut != AUTONEG_ENABLE) && (*aut != AUTONEG_DISABLE)) - *aut = AUTONEG_ENABLE; - - *adv &= (ADVERTISED_10baseT_Half | - ADVERTISED_10baseT_Full | - ADVERTISED_100baseT_Half | - ADVERTISED_100baseT_Full | - ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full); - if (*adv == 0) - *adv = (ADVERTISED_10baseT_Half | - ADVERTISED_10baseT_Full | - ADVERTISED_100baseT_Half | - ADVERTISED_100baseT_Full | - ADVERTISED_1000baseT_Half | - ADVERTISED_1000baseT_Full); +rtl8168_link_option(struct rtl8168_private *tp) +{ + if ((tp->speed_mode != SPEED_1000) && (tp->speed_mode != SPEED_100) && (tp->speed_mode != SPEED_10)) + tp->speed_mode = SPEED_1000; + + if ((tp->duplex_mode != DUPLEX_FULL) && (tp->duplex_mode != DUPLEX_HALF)) + tp->duplex_mode = DUPLEX_FULL; + + if ((tp->autoneg_mode != AUTONEG_ENABLE) && (tp->autoneg_mode != AUTONEG_DISABLE)) + tp->autoneg_mode = AUTONEG_ENABLE; + + tp->advertising_mode &= (ADVERTISED_10baseT_Half | + ADVERTISED_10baseT_Full | + ADVERTISED_100baseT_Half | + ADVERTISED_100baseT_Full | + ADVERTISED_1000baseT_Half | + ADVERTISED_1000baseT_Full); + if (tp->advertising_mode == 0) + tp->advertising_mode = (ADVERTISED_10baseT_Half | + ADVERTISED_10baseT_Full | + ADVERTISED_100baseT_Half | + ADVERTISED_100baseT_Full | + ADVERTISED_1000baseT_Half | + ADVERTISED_1000baseT_Full); } static void @@ -5520,7 +5691,7 @@ int i; for (i = 0; i < 10; i++) { - udelay(100); + fsleep(100); if (RTL_R16(tp, 0xD2) & BIT_9) break; } @@ -5872,7 +6043,7 @@ } static void -rtl8168_set_pci_99_180_exit_driver_para(struct net_device *dev) +rtl8168_set_pci_99_exit_driver_para(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); @@ -5895,26 +6066,9 @@ case CFG_METHOD_37: if (tp->org_pci_offset_99 & BIT_2) rtl8168_issue_offset_99_event(tp); - rtl8168_disable_pci_offset_99(tp); - break; - } - switch (tp->mcfg) { - case CFG_METHOD_24: - case CFG_METHOD_25: - case CFG_METHOD_26: - case CFG_METHOD_27: - case CFG_METHOD_28: - case CFG_METHOD_29: - case CFG_METHOD_30: - case CFG_METHOD_31: - case CFG_METHOD_32: - case CFG_METHOD_33: - case CFG_METHOD_34: - case CFG_METHOD_35: - case CFG_METHOD_36: - case CFG_METHOD_37: - rtl8168_disable_pci_offset_180(tp); + if (test_bit(R8168_FLAG_SUSPEND | R8168_FLAG_SHUTDOWN, tp->task_flags)) + rtl8168_disable_pci_offset_99(tp); break; } } @@ -6012,7 +6166,7 @@ gphy_val = rtl8168_mdio_read(tp, 0x06); gphy_val &= ~BIT_7; rtl8168_mdio_write(tp, 0x06, gphy_val); - mdelay(1); + fsleep(1000); rtl8168_mdio_write(tp, 0x1F, 0x0007); rtl8168_mdio_write(tp, 0x1E, 0x002C); gphy_val = rtl8168_mdio_read(tp, 0x16); @@ -6022,7 +6176,7 @@ } } - rtl8168_set_pci_99_180_exit_driver_para(dev); + rtl8168_set_pci_99_exit_driver_para(dev); switch (tp->mcfg) { case CFG_METHOD_35: @@ -6096,7 +6250,7 @@ u8 options; u32 csi_tmp; - if (disable_wol_support) + if (tp->disable_wol_support) goto out; tp->wol_opts = 0; @@ -6236,6 +6390,37 @@ } static void +rtl8168_enable_giga_lite(struct rtl8168_private *tp, u32 adv) +{ + switch (tp->mcfg) { + case CFG_METHOD_29 ... CFG_METHOD_36: + rtl8168_mdio_write(tp, 0x1F, 0x0A42); + if (adv & ADVERTISED_1000baseT_Full) + rtl8168_set_eth_phy_bit(tp, 0x14, BIT_9); + else + rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_9); + rtl8168_mdio_write(tp, 0x1F, 0x0000); + break; + default: + break; + } +} + +static void +rtl8168_disable_giga_lite(struct rtl8168_private *tp) +{ + switch (tp->mcfg) { + case CFG_METHOD_29 ... CFG_METHOD_36: + rtl8168_mdio_write(tp, 0x1F, 0x0A42); + rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_9); + rtl8168_mdio_write(tp, 0x1F, 0x0000); + break; + default: + break; + } +} + +static void rtl8168_set_wol_link_speed(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); @@ -6318,6 +6503,8 @@ rtl8168_mdio_write(tp, MII_ADVERTISE, auto_nego); rtl8168_mdio_write(tp, MII_CTRL1000, giga_ctrl); + rtl8168_disable_giga_lite(tp); + rtl8168_phy_restart_nway(dev); exit: @@ -6329,6 +6516,10 @@ { struct rtl8168_private *tp = netdev_priv(dev); + /* Reboot not set wol link speed */ + if (system_state == SYSTEM_RESTART) + return; + if (tp->wol_enabled == WOL_ENABLED || tp->DASH || tp->EnableKCPOffload) { rtl8168_set_hw_wol(dev, tp->wol_opts); @@ -6469,7 +6660,7 @@ wol->wolopts = wol->supported = 0; - if (disable_wol_support) + if (tp->disable_wol_support) return; wol->supported = WAKE_ANY; @@ -6487,7 +6678,7 @@ { struct rtl8168_private *tp = netdev_priv(dev); - if (disable_wol_support) + if (tp->disable_wol_support) return -EOPNOTSUPP; tp->wol_opts = wol->wolopts; @@ -6540,9 +6731,6 @@ tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 || tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 || tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36) { - //Disable Giga Lite - rtl8168_mdio_write(tp, 0x1F, 0x0A42); - rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_9); if (tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 || tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_7); @@ -6557,6 +6745,11 @@ duplex = DUPLEX_FULL; } + if (tp->enable_giga_lite && (autoneg == AUTONEG_ENABLE)) + rtl8168_enable_giga_lite(tp, adv); + else + rtl8168_disable_giga_lite(tp); + giga_ctrl = rtl8168_mdio_read(tp, MII_CTRL1000); giga_ctrl &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL); @@ -6599,7 +6792,6 @@ rtl8168_mdio_write(tp, MII_ADVERTISE, auto_nego); rtl8168_mdio_write(tp, MII_CTRL1000, giga_ctrl); rtl8168_phy_restart_nway(dev); - mdelay(20); } else { /*true force*/ if (speed == SPEED_10 || speed == SPEED_100) @@ -6680,7 +6872,6 @@ 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) @@ -6946,11 +7137,16 @@ ) { struct rtl8168_private *tp = netdev_priv(dev); - u8 status; + u16 aner = tp->phy_reg_aner; + u16 anlpar = tp->phy_reg_anlpar; + u16 gbsr = tp->phy_reg_gbsr; + u64 lpa_adv = 0; + u32 status; u8 autoneg, duplex; u32 speed = 0; - u16 bmcr, bmsr, anlpar, ctrl1000 = 0, stat1000 = 0; - u32 supported, advertising, lp_advertising; + u16 bmcr; + u64 supported, advertising; + u8 report_lpa = 0; supported = SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | @@ -6962,27 +7158,9 @@ SUPPORTED_Pause | SUPPORTED_Asym_Pause; - advertising = ADVERTISED_TP; - - rtl8168_mdio_write(tp, 0x1F, 0x0000); - bmcr = rtl8168_mdio_read(tp, MII_BMCR); - bmsr = rtl8168_mdio_read(tp, MII_BMSR); - anlpar = rtl8168_mdio_read(tp, MII_LPA); - ctrl1000 = rtl8168_mdio_read(tp, MII_CTRL1000); - stat1000 = rtl8168_mdio_read(tp, MII_STAT1000); - - if (bmcr & BMCR_ANENABLE) { - advertising |= ADVERTISED_Autoneg; - autoneg = AUTONEG_ENABLE; - - if (bmsr & BMSR_ANEGCOMPLETE) { - lp_advertising = mii_lpa_to_ethtool_lpa_t(anlpar); - lp_advertising |= - mii_stat1000_to_ethtool_lpa_t(stat1000); - } else { - lp_advertising = 0; - } - + advertising = tp->advertising; + if (tp->phy_auto_nego_reg || tp->phy_1000_ctrl_reg) { + advertising = 0; if (tp->phy_auto_nego_reg & ADVERTISE_10HALF) advertising |= ADVERTISED_10baseT_Half; if (tp->phy_auto_nego_reg & ADVERTISE_10FULL) @@ -6993,21 +7171,26 @@ advertising |= ADVERTISED_100baseT_Full; if (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL) advertising |= ADVERTISED_1000baseT_Full; + } + + rtl8168_mdio_write(tp, 0x1F, 0x0000); + bmcr = rtl8168_mdio_read(tp, MII_BMCR); + if (bmcr & BMCR_ANENABLE) { + autoneg = AUTONEG_ENABLE; + advertising |= ADVERTISED_Autoneg; } else { autoneg = AUTONEG_DISABLE; - lp_advertising = 0; } + advertising |= ADVERTISED_TP; + status = RTL_R8(tp, PHYstatus); + if (netif_running(dev) && (status & LinkStatus)) + report_lpa = 1; - if (status & LinkStatus) { + if (report_lpa) { /*link on*/ - if (status & _1000bpsF) - speed = SPEED_1000; - else if (status & _100bps) - speed = SPEED_100; - else if (status & _10bps) - speed = SPEED_10; + speed = rtl8168_convert_link_speed(tp, status); if (status & TxFlowCtrl) advertising |= ADVERTISED_Asym_Pause; @@ -7015,24 +7198,43 @@ if (status & RxFlowCtrl) advertising |= ADVERTISED_Pause; - duplex = ((status & _1000bpsF) || (status & FullDup)) ? + duplex = ((status & (_1000bpsF)) || (status & FullDup)) ? DUPLEX_FULL : DUPLEX_HALF; + + /*link partner*/ + if (aner & EXPANSION_NWAY) + lpa_adv |= ADVERTISED_Autoneg; + if (anlpar & LPA_10HALF) + lpa_adv |= ADVERTISED_10baseT_Half; + if (anlpar & LPA_10FULL) + lpa_adv |= ADVERTISED_10baseT_Full; + if (anlpar & LPA_100HALF) + lpa_adv |= ADVERTISED_100baseT_Half; + if (anlpar & LPA_100FULL) + lpa_adv |= ADVERTISED_100baseT_Full; + if (anlpar & LPA_PAUSE_CAP) + lpa_adv |= ADVERTISED_Pause; + if (anlpar & LPA_PAUSE_ASYM) + lpa_adv |= ADVERTISED_Asym_Pause; + if (gbsr & LPA_1000HALF) + lpa_adv |= ADVERTISED_1000baseT_Half; + if (gbsr & LPA_1000FULL) + lpa_adv |= ADVERTISED_1000baseT_Full; } else { /*link down*/ speed = SPEED_UNKNOWN; duplex = DUPLEX_UNKNOWN; + lpa_adv = 0; } #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) - cmd->supported = supported; - cmd->advertising = advertising; -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30) - cmd->lp_advertising = lp_advertising; -#endif + cmd->supported = (u32)supported; + cmd->advertising = (u32)advertising; cmd->autoneg = autoneg; cmd->speed = speed; cmd->duplex = duplex; cmd->port = PORT_TP; + cmd->lp_advertising = (u32)lpa_adv; cmd->eth_tp_mdix = rtl8168_get_mdi_status(tp); #else ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, @@ -7040,7 +7242,8 @@ ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, advertising); ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising, - lp_advertising); + lpa_adv); + cmd->base.autoneg = autoneg; cmd->base.speed = speed; cmd->base.duplex = duplex; @@ -7227,8 +7430,8 @@ { struct rtl8168_private *tp = netdev_priv(dev); - ring->rx_max_pending = MAX_NUM_TX_DESC; - ring->tx_max_pending = MAX_NUM_RX_DESC; + ring->rx_max_pending = MAX_NUM_RX_DESC; + ring->tx_max_pending = MAX_NUM_TX_DESC; ring->rx_pending = tp->num_rx_desc; ring->tx_pending = tp->tx_ring0.num_tx_desc; } @@ -7290,7 +7493,7 @@ counters = tp->tally_vaddr; paddr = tp->tally_paddr; - if (!counters) + if (!counters || test_bit(R8168_FLAG_SHUTDOWN, tp->task_flags)) return; rtl8168_dump_tally_counter(tp, paddr); @@ -7380,7 +7583,7 @@ pci_write_config_word(tp->pci_dev, VPD_addr, (u16)i*4); ret = -EFAULT; for (j = 0; j < 10; j++) { - udelay(400); + fsleep(400); pci_read_config_word(tp->pci_dev, VPD_addr, &tmp); if (tmp&0x8000) { ret = 0; @@ -7391,7 +7594,7 @@ if (ret) break; - pci_read_config_dword(tp->pci_dev, VPD_data, &eeprom_buffi-start_w); + eeprom_buffi-start_w = rtl8168_pci_config_read(tp, VPD_data); } rtl8168_disable_cfg9346_write(tp); @@ -7605,8 +7808,8 @@ 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 +7912,7 @@ 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 +8143,120 @@ 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); +} + +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); + + 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 +8356,10 @@ 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) @@ -8427,7 +8742,7 @@ cnt = 0; do { - udelay(100); + fsleep(100); temp = RTL_R32(tp, EFUSEAR); cnt++; } while (!(temp & EFUSE_READ_OK) && (cnt < EFUSE_Check_Cnt)); @@ -8444,7 +8759,7 @@ cnt = 0; do { - udelay(100); + fsleep(100); temp = RTL_R32(tp, EFUSEAR); cnt++; } while (!(temp & EFUSE_READ_OK) && (cnt < EFUSE_Check_Cnt)); @@ -8470,7 +8785,7 @@ cnt = 0; do { - udelay(100); + fsleep(100); temp = RTL_R32(tp, EFUSEAR); cnt++; } while ((temp & BIT_31) && (cnt < EFUSE_Check_Cnt)); @@ -8490,7 +8805,7 @@ } } - udelay(R8168_CHANNEL_EXIT_DELAY_TIME); + fsleep(R8168_CHANNEL_EXIT_DELAY_TIME); return efuse_data; } @@ -8541,9 +8856,8 @@ static bool -rtl8168_wait_phy_state_ready(struct rtl8168_private *tp, - u16 PhyState, - u32 MicroSecondTimeout +rtl8168_wait_phy_state_ready(struct rtl8168_private *tp, u16 PhyState, + u32 usec ) { u16 TmpPhyState; @@ -8554,12 +8868,13 @@ if (HW_SUPPORT_UPS_MODE(tp) == FALSE) goto exit; - WaitCount = MicroSecondTimeout / 1000; - if (WaitCount == 0) WaitCount = 100; + WaitCount = usec / 1000; + if (WaitCount < 100) + WaitCount = 100; do { TmpPhyState = rtl8168_get_phy_state(tp); - mdelay(1); + fsleep(1000); i++; } while ((i < WaitCount) && (TmpPhyState != PhyState)); @@ -8602,17 +8917,17 @@ rtl8168_mdio_write(tp, 0x1F, 0x0C41); rtl8168_set_eth_phy_bit(tp, 0x14, BIT_0); rtl8168_mdio_write(tp, 0x1F, 0x0000); - mdelay(24); //24ms + fsleep(24000); //24ms rtl8168_mdio_write(tp, 0x1F, 0x0C40); PhyRegValue = rtl8168_mdio_read(tp, 0x12); if ((PhyRegValue & 0x03) != 0x00) { u32 WaitCnt = 0; - while ((PhyRegValue & 0x03) != 0x00 && WaitCnt < 5) { + while ((PhyRegValue & 0x03) != 0x00 && WaitCnt < 50) { rtl8168_mdio_write(tp, 0x1F, 0x0C40); rtl8168_set_eth_phy_bit(tp, 0x11, (BIT_15 | BIT_14)); rtl8168_clear_eth_phy_bit(tp, 0x11, (BIT_15 | BIT_14)); - mdelay(100); + fsleep(100000); rtl8168_mdio_write(tp, 0x1F, 0x0C40); PhyRegValue = rtl8168_mdio_read(tp, 0x12); WaitCnt++; @@ -8631,7 +8946,7 @@ rtl8168_mdio_write(tp, 0x1F, 0x0A46); rtl8168_set_eth_phy_bit(tp, 0x14, BIT_0); rtl8168_mdio_write(tp, 0x1F, 0x0000); - rtl8168_wait_phy_state_ready(tp, HW_PHY_STATUS_LAN_ON, 500000); + rtl8168_wait_phy_state_ready(tp, HW_PHY_STATUS_LAN_ON, 100000); tp->HwHasWrRamCodeToMicroP = FALSE; @@ -8687,17 +9002,17 @@ rtl8168_mdio_write(tp, 0x1F, 0x0C41); rtl8168_set_eth_phy_bit(tp, 0x14, BIT_0); rtl8168_mdio_write(tp, 0x1F, 0x0000); - mdelay(24000); //24ms + fsleep(24000); //24ms rtl8168_mdio_write(tp, 0x1F, 0x0C40); PhyRegValue = rtl8168_mdio_read(tp, 0x12); if ((PhyRegValue & 0x03) != 0x00) { u32 WaitCnt = 0; - while ((PhyRegValue & 0x03) != 0x00 && WaitCnt < 5) { + while ((PhyRegValue & 0x03) != 0x00 && WaitCnt < 50) { rtl8168_mdio_write(tp, 0x1F, 0x0C40); rtl8168_set_eth_phy_bit(tp, 0x11, (BIT_15 | BIT_14)); rtl8168_clear_eth_phy_bit(tp, 0x11, (BIT_15 | BIT_14)); - mdelay(100000); + fsleep(100000); rtl8168_mdio_write(tp, 0x1F, 0x0C40); PhyRegValue = rtl8168_mdio_read(tp, 0x12); WaitCnt++; @@ -8718,7 +9033,7 @@ rtl8168_mdio_write(tp, 0x1F, 0x0A46); rtl8168_set_eth_phy_bit(tp, 0x14, BIT_0); rtl8168_mdio_write(tp, 0x1F, 0x0000); - rtl8168_wait_phy_state_ready(tp, HW_PHY_STATUS_LAN_ON, 500000); + rtl8168_wait_phy_state_ready(tp, HW_PHY_STATUS_LAN_ON, 100000); //record fail case rtl8168_mdio_write(tp, 0x1F, 0x0A43); @@ -8797,7 +9112,7 @@ do { TmpPhyState = rtl8168_mdio_read_phy_ocp(tp, 0x0A42, 0x10); TmpPhyState &= 0x7; - mdelay(1); + fsleep(100); i++; } while ((i < 100) && (TmpPhyState != PhyState)); @@ -8977,6 +9292,30 @@ { struct rtl8168_private *tp = netdev_priv(dev); + switch (tp->mcfg) { + case CFG_METHOD_21: + case CFG_METHOD_22: + case CFG_METHOD_23: + case CFG_METHOD_24: + case CFG_METHOD_25: + case CFG_METHOD_26: + case CFG_METHOD_27: + case CFG_METHOD_28: + case CFG_METHOD_29: + case CFG_METHOD_30: + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + case CFG_METHOD_35: + case CFG_METHOD_36: + case CFG_METHOD_37: + /* support mac mcu */ + break; + default: + return; + } + if (tp->HwSuppAspmClkIntrLock) { rtl8168_enable_cfg9346_write(tp); rtl8168_hw_aspm_clkreq_enable(tp, false); @@ -9023,7 +9362,7 @@ rtl8168_mac_ocp_write(tp, 0xFC32, 0x0000); rtl8168_mac_ocp_write(tp, 0xFC34, 0x0000); rtl8168_mac_ocp_write(tp, 0xFC36, 0x0000); - mdelay(3); + fsleep(3000); rtl8168_mac_ocp_write(tp, 0xFC26, 0x0000); break; } @@ -9041,8 +9380,6 @@ rtl8168_mac_ocp_write(tp, 0xE434, 0x0004); rtl8168_mac_ocp_write(tp, 0xE43C, 0x0004); - rtl8168_hw_disable_mac_mcu_bps(dev); - rtl8168_mac_ocp_write(tp, 0xF800, 0xE008); rtl8168_mac_ocp_write(tp, 0xF802, 0xE01B); rtl8168_mac_ocp_write(tp, 0xF804, 0xE022); @@ -9264,8 +9601,6 @@ { struct rtl8168_private *tp = netdev_priv(dev); - rtl8168_hw_disable_mac_mcu_bps(dev); - rtl8168_mac_ocp_write(tp, 0xF800, 0xE008); rtl8168_mac_ocp_write(tp, 0xF802, 0xE011); rtl8168_mac_ocp_write(tp, 0xF804, 0xE015); @@ -9394,8 +9729,6 @@ { struct rtl8168_private *tp = netdev_priv(dev); - rtl8168_hw_disable_mac_mcu_bps(dev); - rtl8168_mac_ocp_write(tp, 0xF800, 0xE008); rtl8168_mac_ocp_write(tp, 0xF802, 0xE00A); rtl8168_mac_ocp_write(tp, 0xF804, 0xE00D); @@ -9823,8 +10156,6 @@ { struct rtl8168_private *tp = netdev_priv(dev); - rtl8168_hw_disable_mac_mcu_bps(dev); - rtl8168_mac_ocp_write(tp, 0xF800, 0xE008); rtl8168_mac_ocp_write(tp, 0xF802, 0xE00A); rtl8168_mac_ocp_write(tp, 0xF804, 0xE00C); @@ -9983,8 +10314,6 @@ 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168ep_1); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168ep_1i); @@ -10025,8 +10354,6 @@ 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168ep_2); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168ep_2i); @@ -10039,12 +10366,6 @@ } static void -rtl8168_set_mac_mcu_8168h_1(struct net_device *dev) -{ - rtl8168_hw_disable_mac_mcu_bps(dev); -} - -static void rtl8168_set_mac_mcu_8168h_2(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); @@ -10067,8 +10388,6 @@ 0xC402, 0xBC00, 0x0578, 0xC602, 0xBE00, 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168h_1); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168h_1i); @@ -10150,8 +10469,6 @@ 0x0000, 0x0000, 0x0000, 0x0000, 0x6838, 0x0A17, 0x0613, 0x0D26 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168h_3); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168h_3i); @@ -10165,20 +10482,12 @@ } static void -rtl8168_set_mac_mcu_8168h_4(struct net_device *dev) -{ - rtl8168_hw_disable_mac_mcu_bps(dev); -} - -static void rtl8168_set_mac_mcu_8168fp_1(struct net_device *dev) { struct rtl8168_private *tp = netdev_priv(dev); u16 i; u16 breakPointEnabled = 0; - rtl8168_hw_disable_mac_mcu_bps(dev); - if(tp->HwPkgDet == 0x00 || tp->HwPkgDet == 0x0F) { static const u16 mcu_patch_code_8168fp_1_1 = { 0xE00A, 0xE0C1, 0xE104, 0xE108, 0xE10D, 0xE112, 0xE11C, 0xE121, 0xE000, @@ -10315,8 +10624,6 @@ 0xBE00, 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168fp_8116as_2); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168fp_8116as_2i); @@ -10350,8 +10657,6 @@ 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168fp_2); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168fp_2i); @@ -10400,8 +10705,6 @@ 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000 }; - rtl8168_hw_disable_mac_mcu_bps(dev); - for (i = 0; i < ARRAY_SIZE(mcu_patch_code_8168fp_3); i++) rtl8168_mac_ocp_write(tp, 0xF800 + i * 2, mcu_patch_code_8168fp_3i); @@ -10424,6 +10727,8 @@ if (tp->NotWrMcuPatchCode == TRUE) return; + rtl8168_hw_disable_mac_mcu_bps(dev); + switch (tp->mcfg) { case CFG_METHOD_21: rtl8168_set_mac_mcu_8168g_1(dev); @@ -10443,9 +10748,6 @@ case CFG_METHOD_28: rtl8168_set_mac_mcu_8168ep_2(dev); break; - case CFG_METHOD_29: - rtl8168_set_mac_mcu_8168h_1(dev); - break; case CFG_METHOD_30: case CFG_METHOD_37: rtl8168_set_mac_mcu_8168h_2(dev); @@ -10463,8 +10765,11 @@ case CFG_METHOD_35: rtl8168_set_mac_mcu_8168h_3(dev); break; + case CFG_METHOD_29: case CFG_METHOD_36: - rtl8168_set_mac_mcu_8168h_4(dev); + /* no mac mcu patch code */ + break; + default: break; } } @@ -10575,9 +10880,9 @@ rtl8168_disable_ocp_phy_power_saving(dev); //Set PCIE uncorrectable error status mask pcie 0x108 - csi_tmp = rtl8168_csi_read(tp, 0x108); + csi_tmp = rtl8168_pci_config_read(tp, 0x108); csi_tmp |= BIT_20; - rtl8168_csi_write(tp, 0x108, csi_tmp); + rtl8168_pci_config_write(tp, 0x108, csi_tmp); switch (tp->mcfg) { case CFG_METHOD_21: @@ -10592,7 +10897,7 @@ rtl8168_set_pci_pme(tp, 0); - if (s0_magic_packet == 1) + if (tp->s0_magic_packet == 1) rtl8168_enable_magic_packet(dev); else rtl8168_disable_magic_packet(dev); @@ -10987,7 +11292,7 @@ WaitCnt = 0; do { PhyRegValue = rtl8168_mdio_read(tp, 0x10); - udelay(100); + fsleep(100); WaitCnt++; } while (!(PhyRegValue & BIT_6) && (WaitCnt < 1000)); @@ -11017,7 +11322,7 @@ WaitCnt = 0; do { PhyRegValue = rtl8168_mdio_read(tp, 0x10); - udelay(100); + fsleep(100); WaitCnt++; } while ((PhyRegValue & BIT_6) && (WaitCnt < 1000)); @@ -11118,7 +11423,7 @@ break; } - mdelay(1); + fsleep(1000); dprintk("disable phy disable mode.\n"); } @@ -11274,7 +11579,7 @@ rtl8168_clear_phy_mcu_patch_request(tp); - mdelay(2); + fsleep(2000); break; default: break; @@ -11317,7 +11622,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x16, 0x4104); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1E); gphy_val &= 0x03FF; if (gphy_val == 0x000C) @@ -11325,7 +11630,7 @@ } rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x07); if ((gphy_val & BIT_5) == 0) break; @@ -12662,7 +12967,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -12702,7 +13007,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x16, 0x4104); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1E); gphy_val &= 0x03FF; if (gphy_val==0x000C) @@ -12710,7 +13015,7 @@ } rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x07); if ((gphy_val & BIT_5) == 0) break; @@ -14088,7 +14393,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -14129,7 +14434,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x16, 0x4104); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1E); gphy_val &= 0x03FF; if (gphy_val==0x000C) @@ -14137,7 +14442,7 @@ } rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x07); if ((gphy_val & BIT_5) == 0) break; @@ -15471,7 +15776,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -15498,7 +15803,7 @@ gphy_val = rtl8168_mdio_read(tp, 0x15); gphy_val &= ~(BIT_12); rtl8168_mdio_write(tp, 0x15, gphy_val); - mdelay(20); + fsleep(20000); rtl8168_mdio_write(tp, 0x1f, 0x0004); rtl8168_mdio_write(tp, 0x1f, 0x0007); rtl8168_mdio_write(tp, 0x1e, 0x0023); @@ -15507,7 +15812,7 @@ gphy_val |= BIT_0; rtl8168_mdio_write(tp, 0x17, gphy_val); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x17); if (gphy_val & BIT_11) break; @@ -15525,14 +15830,14 @@ rtl8168_mdio_write(tp, 0x1f, 0x0002); rtl8168_mdio_write(tp, 0x1f, 0x0000); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1E); if ((gphy_val & 0x03FF) == 0x0014) break; } rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x07); if ((gphy_val & BIT_5) == 0) break; @@ -18004,7 +18309,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -18036,7 +18341,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0007); rtl8168_mdio_write(tp, 0x1e, 0x002f); for (i = 0; i < 1000; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1c); if ((gphy_val & 0x0080) == 0x0080) break; @@ -18046,7 +18351,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0007); rtl8168_mdio_write(tp, 0x1e, 0x0023); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x17); if (!(gphy_val & 0x0001)) break; @@ -18968,7 +19273,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -19004,7 +19309,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x002f); for (i = 0; i < 1000; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1c); if (gphy_val & 0x0080) break; @@ -19014,7 +19319,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x0023); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x18); if (!(gphy_val & 0x0001)) break; @@ -19849,7 +20154,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp,0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -19889,7 +20194,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x002f); for (i = 0; i < 1000; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1c); if (gphy_val & 0x0080) break; @@ -19899,7 +20204,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x0023); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x18); if (!(gphy_val & 0x0001)) break; @@ -20211,7 +20516,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp,0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -20243,7 +20548,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x002f); for (i = 0; i < 1000; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x1c); if (gphy_val & 0x0080) break; @@ -20253,7 +20558,7 @@ rtl8168_mdio_write(tp,0x1f, 0x0007); rtl8168_mdio_write(tp,0x1e, 0x0023); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x18); if (!(gphy_val & 0x0001)) break; @@ -20775,7 +21080,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp,0x1f, 0x0005); for (i = 0; i < 200; i++) { - udelay(100); + fsleep(100); gphy_val = rtl8168_mdio_read(tp, 0x00); if (gphy_val & BIT_7) break; @@ -24391,7 +24696,7 @@ rtl8168_mdio_write(tp, 0x0B, 0x09D7); rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1f, 0x0000); rtl8168_mdio_write(tp, 0x15, 0x1006); @@ -24679,7 +24984,7 @@ rtl8168_mdio_write(tp, 0x06, rtl8168_mdio_read(tp, 0x06) & ~BIT_8); rtl8168_mdio_write(tp, 0x1f, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1f, 0x0000); gphy_val = rtl8168_mdio_read(tp, 0x15); @@ -24774,7 +25079,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); } - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1f, 0x0000); gphy_val = rtl8168_mdio_read(tp, 0x15); @@ -24840,7 +25145,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); } - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1f, 0x0000); gphy_val = rtl8168_mdio_read(tp, 0x15); @@ -24932,7 +25237,7 @@ rtl8168_mdio_write(tp, 0x1f, 0x0000); } - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1f, 0x0000); gphy_val = rtl8168_mdio_read(tp, 0x15); @@ -24994,7 +25299,7 @@ rtl8168_mdio_write(tp, 0x13, 0x8088); rtl8168_mdio_write(tp, 0x14, 0x9222); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_mdio_write(tp, 0x10, rtl8168_mdio_read(tp, 0x10) | BIT_2); @@ -25037,7 +25342,7 @@ BIT_14); rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_mdio_write(tp, 0x10, rtl8168_mdio_read(tp, 0x10) | BIT_2); @@ -25065,7 +25370,7 @@ gphy_val &= ~BIT_13; rtl8168_mdio_write(tp, 0x11, gphy_val); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_mdio_write(tp, 0x10, rtl8168_mdio_read(tp, 0x10) | BIT_2); @@ -25137,7 +25442,7 @@ rtl8168_mdio_write(tp, 0x13, 0x80D7); rtl8168_mdio_write(tp, 0x14, (rtl8168_mdio_read(tp, 0x14) & ~0xFF00) | 0x8400); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_mdio_write(tp, 0x10, rtl8168_mdio_read(tp, 0x10) | BIT_2); @@ -25209,7 +25514,7 @@ rtl8168_mdio_write(tp, 0x13, 0x80D7); rtl8168_mdio_write(tp, 0x14, (rtl8168_mdio_read(tp, 0x14) & ~0xFF00) | 0x8400); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_mdio_write(tp, 0x10, rtl8168_mdio_read(tp, 0x10) | BIT_2); @@ -25359,7 +25664,7 @@ rtl8168_clear_eth_phy_bit(tp, 0x14, (BIT_13 | BIT_12)); rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_set_eth_phy_bit(tp, 0x10, BIT_2); @@ -25445,7 +25750,7 @@ rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_set_eth_phy_bit(tp, 0x10, BIT_2); @@ -25578,7 +25883,7 @@ rtl8168_set_eth_phy_bit(tp, 0x14, BIT_10); rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (!HW_SUPP_SERDES_PHY(tp) && HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); @@ -25702,7 +26007,7 @@ 0x7C00); rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_set_eth_phy_bit(tp, 0x10, BIT_2); @@ -25720,7 +26025,7 @@ rtl8168_mdio_write(tp, 0x1F, 0x0000); - if (aspm) { + if (tp->aspm) { if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) { rtl8168_mdio_write(tp, 0x1F, 0x0A43); rtl8168_set_eth_phy_bit(tp, 0x10, BIT_2); @@ -25767,7 +26072,7 @@ tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 || tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 || tp->mcfg == CFG_METHOD_37) { - if (aspm) + if (tp->aspm) rtl8168_enable_ocp_phy_power_saving(dev); } @@ -25957,8 +26262,10 @@ tp->ring_lib_enabled = 1; #endif - if (tp->mcfg == CFG_METHOD_DEFAULT) - disable_wol_support = 1; + if (tp->mcfg == CFG_METHOD_DEFAULT) { + tp->disable_wol_support = 1; + tp->eee.eee_enabled = 0; + } switch (tp->mcfg) { case CFG_METHOD_11: @@ -25983,6 +26290,28 @@ } switch (tp->mcfg) { + case CFG_METHOD_11: + case CFG_METHOD_12: + case CFG_METHOD_13: + tp->HwSuppOcpChannelVer = 1; + break; + case CFG_METHOD_23: + case CFG_METHOD_27: + case CFG_METHOD_28: + tp->HwSuppOcpChannelVer = 2; + break; + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + tp->HwSuppOcpChannelVer = 3; + break; + default: + tp->HwSuppOcpChannelVer = 0; + break; + } + + switch (tp->mcfg) { case CFG_METHOD_31: case CFG_METHOD_32: case CFG_METHOD_33: @@ -25993,7 +26322,7 @@ } if (HW_SUPP_SERDES_PHY(tp)) - eee_enable = 0; + tp->eee.eee_enabled = 0; switch (tp->mcfg) { case CFG_METHOD_21: @@ -26096,8 +26425,8 @@ break; } - if (!aspm || !tp->HwSuppAspmClkIntrLock) - dynamic_aspm = 0; + if (!tp->aspm || !tp->HwSuppAspmClkIntrLock) + tp->dynamic_aspm = 0; #ifdef ENABLE_REALWOW_SUPPORT rtl8168_get_realwow_hw_version(dev); @@ -26151,7 +26480,7 @@ } } - eee_enable = 0; + tp->eee.eee_enabled = 0; } #ifdef ENABLE_DASH_SUPPORT @@ -26187,7 +26516,7 @@ #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 { @@ -26196,7 +26525,7 @@ } } #endif - if (aspm) { + if (tp->aspm) { switch (tp->mcfg) { case CFG_METHOD_21: case CFG_METHOD_22: @@ -26285,7 +26614,7 @@ break; } - if (timer_count == 0 || tp->mcfg == CFG_METHOD_DEFAULT || + if (tp->timer_count == 0 || tp->mcfg == CFG_METHOD_DEFAULT || (tp->features & RTL_FEATURE_MSIX)) tp->use_timer_interrrupt = FALSE; @@ -26381,7 +26710,7 @@ if (pdev->subsystem_device == 0xc098 || pdev->subsystem_device == 0xc0b1 || pdev->subsystem_device == 0xc0b8) - hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; + tp->hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; } switch (tp->mcfg) { @@ -26389,16 +26718,16 @@ case CFG_METHOD_19: if (pdev->subsystem_vendor == 0x13fe) { if (pdev->subsystem_device == 0x00ec) - hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; + tp->hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; } break; } #ifdef CONFIG_CTAP_SHORT_OFF - hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; + tp->hwoptimize |= HW_PATCH_SAMSUNG_LAN_DONGLE; #endif //CONFIG_CTAP_SHORT_OFF - if (hwoptimize & HW_PATCH_SAMSUNG_LAN_DONGLE) { + if (tp->hwoptimize & HW_PATCH_SAMSUNG_LAN_DONGLE) { switch (tp->mcfg) { case CFG_METHOD_14: case CFG_METHOD_15: @@ -26611,7 +26940,7 @@ #ifdef ENABLE_LIB_SUPPORT tp->EnableRss = 1; #else - u8 rss_queue_num = netif_get_num_default_rss_queues(); + u16 rss_queue_num = netif_get_num_default_rss_queues(); tp->num_rx_rings = (tp->HwSuppNumRxQueues > rss_queue_num)? rss_queue_num : tp->HwSuppNumRxQueues; if (tp->num_rx_rings >= 2) @@ -26644,12 +26973,12 @@ rtl8168_get_hw_wol(dev); - rtl8168_link_option((u8*)&autoneg_mode, (u32*)&speed_mode, (u8*)&duplex_mode, (u32*)&advertising_mode); + rtl8168_link_option(tp); - tp->autoneg = autoneg_mode; - tp->speed = speed_mode; - tp->duplex = duplex_mode; - tp->advertising = advertising_mode; + tp->autoneg = tp->autoneg_mode; + tp->speed = tp->speed_mode; + tp->duplex = tp->duplex_mode; + tp->advertising = tp->advertising_mode; tp->fcpause = rtl8168_fc_full; tp->max_jumbo_frame_size = rtl_chip_infotp->chipset.jumbo_frame_sz; @@ -26660,13 +26989,19 @@ #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); - eee->tx_lpi_enabled = eee_enable; +#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 = tp->eee.eee_enabled; eee->tx_lpi_timer = dev->mtu + ETH_HLEN + 0x20; } @@ -27545,6 +27880,7 @@ void __user *data, int cmd) { struct rtl8168_private *tp = netdev_priv(dev); + struct ifreq ifrdata = { .ifr_data = data }; int ret = 0; switch (cmd) { @@ -27554,7 +27890,7 @@ break; } - ret = rtl8168_asf_ioctl(dev, ifr); + ret = rtl8168_asf_ioctl(dev, &ifrdata); break; #ifdef ENABLE_DASH_SUPPORT @@ -27569,7 +27905,7 @@ break; } - ret = rtl8168_dash_ioctl(dev, ifr); + ret = rtl8168_dash_ioctl(dev, &ifrdata); break; #endif @@ -27585,7 +27921,7 @@ break; } - ret = rtl8168_realwow_ioctl(dev, ifr); + ret = rtl8168_realwow_ioctl(dev, &ifrdata); break; #endif @@ -27595,7 +27931,7 @@ break; } - ret = rtl8168_tool_ioctl(tp, ifr); + ret = rtl8168_tool_ioctl(tp, &ifrdata); break; default: @@ -27728,7 +28064,7 @@ case CFG_METHOD_23: case CFG_METHOD_27: case CFG_METHOD_28: - mdelay(10); + fsleep(10000); break; } @@ -27829,12 +28165,15 @@ tp->pci_dev = pdev; tp->msg_enable = netif_msg_init(debug.msg_enable, R8168_MSG_DEFAULT); - if (!aspm || tp->mcfg == CFG_METHOD_9) { + rtl8168_init_module_params(tp); + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) + if (tp->aspm && tp->mcfg != CFG_METHOD_9) + pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S); + else pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM); #endif - } /* enable device (incl. PCI PM wakeup and hotplug setup) */ rc = pci_enable_device(pdev); @@ -27899,7 +28238,7 @@ } if ((sizeof(dma_addr_t) > 4) && - use_dac && + tp->use_dac && !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { dev->features |= NETIF_F_HIGHDMA; @@ -28092,17 +28431,17 @@ } if (tp->HwPcieSNOffset > 0) { - pci_sn_l = rtl8168_csi_read(tp, tp->HwPcieSNOffset); + pci_sn_l = rtl8168_pci_config_read(tp, tp->HwPcieSNOffset); if (pci_sn_l != tp->pci_cfg_space.pci_sn_l) { printk(KERN_ERR "%s: pci_sn_l = 0x%08x, should be 0x%08x \n.", dev->name, pci_sn_l, tp->pci_cfg_space.pci_sn_l); - rtl8168_csi_write(tp, tp->HwPcieSNOffset, tp->pci_cfg_space.pci_sn_l); + rtl8168_pci_config_write(tp, tp->HwPcieSNOffset, tp->pci_cfg_space.pci_sn_l); tp->esd_flag |= BIT_13; } - pci_sn_h = rtl8168_csi_read(tp, tp->HwPcieSNOffset + 4); + pci_sn_h = rtl8168_pci_config_read(tp, tp->HwPcieSNOffset + 4); if (pci_sn_h != tp->pci_cfg_space.pci_sn_h) { printk(KERN_ERR "%s: pci_sn_h = 0x%08x, should be 0x%08x \n.", dev->name, pci_sn_h, tp->pci_cfg_space.pci_sn_h); - rtl8168_csi_write(tp, tp->HwPcieSNOffset + 4, tp->pci_cfg_space.pci_sn_h); + rtl8168_pci_config_write(tp, tp->HwPcieSNOffset + 4, tp->pci_cfg_space.pci_sn_h); tp->esd_flag |= BIT_14; } } @@ -28178,6 +28517,31 @@ */ #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; @@ -28301,12 +28665,46 @@ #endif } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) +static netdev_features_t rtl8168_features_check(struct sk_buff *skb, + struct net_device *dev, + netdev_features_t features) +{ + struct rtl8168_private *tp = netdev_priv(dev); + + switch (tp->mcfg) { + case CFG_METHOD_1: + case CFG_METHOD_2: + case CFG_METHOD_3: + return features; + default: + break; + } + + if (skb_is_gso(skb)) { + if (skb_transport_offset(skb) > GTTCPHO_MAX) + features &= ~NETIF_F_ALL_TSO; + } else if (skb->ip_summed == CHECKSUM_PARTIAL) { + if (skb_transport_offset(skb) > TCPHO_MAX) + features &= ~NETIF_F_CSUM_MASK; + } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) + features = vlan_features_check(skb, features); +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0) + + return features; +} +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) static const struct net_device_ops rtl8168_netdev_ops = { .ndo_open = rtl8168_open, .ndo_stop = rtl8168_close, .ndo_get_stats = rtl8168_get_stats, .ndo_start_xmit = rtl8168_start_xmit, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) + .ndo_features_check = rtl8168_features_check, +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) .ndo_tx_timeout = rtl8168_tx_timeout, .ndo_change_mtu = rtl8168_change_mtu, .ndo_set_mac_address = rtl8168_set_mac_address, @@ -28629,9 +29027,11 @@ netif_carrier_off(dev); +#ifdef ENABLE_R8168_SYSFS rtl8168_sysfs_init(dev); +#endif /* ENABLE_R8168_SYSFS */ - printk("%s", GPL_CLAIM); + printk(KERN_INFO "%s", GPL_CLAIM); out: return rc; @@ -28665,19 +29065,38 @@ set_bit(R8168_FLAG_DOWN, tp->task_flags); - rtl8168_cancel_all_schedule_work(tp); - -#ifdef CONFIG_R8168_NAPI - rtl8168_del_napi(tp); -#endif if (HW_DASH_SUPPORT_DASH(tp)) rtl8168_driver_stop(tp); + switch (tp->mcfg) { + case CFG_METHOD_24: + case CFG_METHOD_25: + case CFG_METHOD_26: + case CFG_METHOD_27: + case CFG_METHOD_28: + case CFG_METHOD_29: + case CFG_METHOD_30: + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + case CFG_METHOD_35: + case CFG_METHOD_36: + case CFG_METHOD_37: + rtl8168_disable_pci_offset_180(tp); + break; + } + #ifdef ENABLE_R8168_SYSFS rtl8168_sysfs_remove(dev); #endif //ENABLE_R8168_SYSFS unregister_netdev(dev); + + rtl8168_cancel_all_schedule_work(tp); +#ifdef CONFIG_R8168_NAPI + rtl8168_del_napi(tp); +#endif rtl8168_disable_msi(pdev, tp); #ifdef ENABLE_R8168_PROCFS rtl8168_proc_remove(dev); @@ -28995,7 +29414,7 @@ { struct rtl8168_private *tp = netdev_priv(dev); - if (!(tp->mcfg == CFG_METHOD_5) || (tp->mcfg == CFG_METHOD_6)) + if (tp->mcfg != CFG_METHOD_5 && tp->mcfg != CFG_METHOD_6) return; switch (dev_state) { @@ -29019,29 +29438,39 @@ } static void -set_offset70F(struct rtl8168_private *tp, u8 setting) +_rtl8168_set_l1_l0s_entry_latency(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; - rtl8168_csi_write(tp, 0x70c, csi_tmp | temp); + csi_tmp = rtl8168_pci_config_read(tp, 0x70c) & 0xc0ffffff; + rtl8168_pci_config_write(tp, 0x70c, csi_tmp | temp); } static void -set_offset79(struct rtl8168_private *tp, u8 setting) +rtl8168_set_l1_l0s_entry_latency(struct rtl8168_private *tp) { - //Set PCI configuration space offset 0x79 to setting + switch (tp->mcfg) { + case CFG_METHOD_1 ... CFG_METHOD_3: + /* nothing to do */ + break; + default: + _rtl8168_set_l1_l0s_entry_latency(tp, 0x27); + break; + } +} +static void +_rtl8168_set_mrrs(struct rtl8168_private *tp, u8 setting) +{ struct pci_dev *pdev = tp->pci_dev; u8 device_control; - if (hwoptimize & HW_PATCH_SOC_LAN) - return; - pci_read_config_byte(pdev, 0x79, &device_control); device_control &= ~0x70; device_control |= setting; @@ -29049,7 +29478,29 @@ } static void -set_offset711(struct rtl8168_private *tp, u8 setting) +rtl8168_set_mrrs(struct rtl8168_private *tp) +{ + if (tp->hwoptimize & HW_PATCH_SOC_LAN) + return; + + switch (tp->mcfg) { + case CFG_METHOD_1 ... CFG_METHOD_3: + /* nothing to do */ + break; + case CFG_METHOD_4 ... CFG_METHOD_10: + if (tp->dev->mtu > ETH_DATA_LEN) + _rtl8168_set_mrrs(tp, 0x20); + else + _rtl8168_set_mrrs(tp, 0x40); + break; + default: + _rtl8168_set_mrrs(tp, 0x40); + break; + } +} + +static void +_rtl8168_set_eios_opt(struct rtl8168_private *tp, u8 setting) { u32 csi_tmp; u32 temp = (u32)setting; @@ -29057,8 +29508,21 @@ temp = temp << 12; /*set PCI configuration space offset 0x711 to setting*/ - csi_tmp = rtl8168_csi_read(tp, 0x710) & 0xffff0fff; - rtl8168_csi_write(tp, 0x710, csi_tmp | temp); + csi_tmp = rtl8168_pci_config_read(tp, 0x710) & 0xffff0fff; + rtl8168_pci_config_write(tp, 0x710, csi_tmp | temp); +} + +static void +rtl8168_set_eios_opt(struct rtl8168_private *tp) +{ + switch (tp->mcfg) { + case CFG_METHOD_21: + case CFG_METHOD_22: + _rtl8168_set_eios_opt(tp, 0x04); + break; + default: + break; + } } static void @@ -29246,9 +29710,13 @@ RTL_W32(tp, TxConfig, (TX_DMA_BURST_unlimited << TxDMAShift) | (InterFrameGap << TxInterFrameGapShift)); - if (tp->mcfg == CFG_METHOD_4) { - set_offset70F(tp, 0x27); + rtl8168_set_l1_l0s_entry_latency(tp); + + rtl8168_set_mrrs(tp); + rtl8168_set_eios_opt(tp); + + if (tp->mcfg == CFG_METHOD_4) { RTL_W8(tp, DBG_reg, (0x0E << 4) | Fix_Nak_1 | Fix_Nak_2); RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); @@ -29259,13 +29727,9 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } //rx checksum offload enable @@ -29279,9 +29743,6 @@ Force_rxflow_en | Force_txflow_en | Cxpl_dbg_sel | ASF | PktCntrDisable | Macdbgo_sel); } else if (tp->mcfg == CFG_METHOD_5) { - - set_offset70F(tp, 0x27); - RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); //disable clock request. @@ -29290,13 +29751,9 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } //rx checksum offload enable @@ -29306,8 +29763,6 @@ dev->features |= NETIF_F_RXCSUM; #endif } else if (tp->mcfg == CFG_METHOD_6) { - set_offset70F(tp, 0x27); - RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); //disable clock request. @@ -29316,13 +29771,9 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } //rx checksum offload enable @@ -29332,8 +29783,6 @@ dev->features |= NETIF_F_RXCSUM; #endif } else if (tp->mcfg == CFG_METHOD_7) { - set_offset70F(tp, 0x27); - rtl8168_eri_write(tp, 0x1EC, 1, 0x07, ERIAR_ASF); //disable clock request. @@ -29344,19 +29793,11 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - - set_offset79(tp, 0x50); } } else if (tp->mcfg == CFG_METHOD_8) { - - set_offset70F(tp, 0x27); - rtl8168_eri_write(tp, 0x1EC, 1, 0x07, ERIAR_ASF); //disable clock request. @@ -29369,17 +29810,11 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } } else if (tp->mcfg == CFG_METHOD_9) { - set_offset70F(tp, 0x27); - /* disable clock request. */ pci_write_config_byte(pdev, 0x81, 0x00); @@ -29389,32 +29824,22 @@ if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } RTL_W8(tp, TDFNR, 0x8); } else if (tp->mcfg == CFG_METHOD_10) { - set_offset70F(tp, 0x27); - RTL_W8(tp, DBG_reg, RTL_R8(tp, DBG_reg) | BIT_7 | BIT_1); if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); - - set_offset79(tp, 0x20); } else { RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); - - set_offset79(tp, 0x50); } RTL_W8(tp, TDFNR, 0x8); @@ -29424,9 +29849,6 @@ /* disable clock request. */ pci_write_config_byte(pdev, 0x81, 0x00); } else if (tp->mcfg == CFG_METHOD_11 || tp->mcfg == CFG_METHOD_13) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - if (dev->mtu > ETH_DATA_LEN) RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); else @@ -29437,9 +29859,6 @@ RTL_W8(tp, Config1, RTL_R8(tp, Config1) | 0x10); } else if (tp->mcfg == CFG_METHOD_12) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - if (dev->mtu > ETH_DATA_LEN) RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); else @@ -29450,10 +29869,6 @@ RTL_W8(tp, Config1, RTL_R8(tp, Config1) | 0x10); } else if (tp->mcfg == CFG_METHOD_14 || tp->mcfg == CFG_METHOD_15) { - - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - if (dev->mtu > ETH_DATA_LEN) { RTL_W8(tp, MTPS, 0x24); RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); @@ -29475,7 +29890,7 @@ RTL_W8(tp, TDFNR, 0x8); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -29485,9 +29900,6 @@ RTL_W8(tp, Config1, RTL_R8(tp, Config1) & ~0x10); } else if (tp->mcfg == CFG_METHOD_16 || tp->mcfg == CFG_METHOD_17) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - rtl8168_eri_write(tp, 0xC0, 2, 0x0000, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xB8, 4, 0x00000000, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xC8, 4, 0x00100002, ERIAR_ExGMAC); @@ -29532,9 +29944,6 @@ pci_write_config_byte(pdev, 0x81, 0x00); } else if (tp->mcfg == CFG_METHOD_18 || tp->mcfg == CFG_METHOD_19) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - rtl8168_eri_write(tp, 0xC8, 4, 0x00100002, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC); RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | BIT_7); @@ -29546,7 +29955,7 @@ rtl8168_eri_write(tp, 0xDC, 1, csi_tmp, ERIAR_ExGMAC); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -29571,9 +29980,6 @@ rtl8168_eri_write(tp, 0xCC, 4, 0x00000050, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xd0, 4, 0x00000060, ERIAR_ExGMAC); } else if (tp->mcfg == CFG_METHOD_20) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - rtl8168_eri_write(tp, 0xC8, 4, 0x00100002, ERIAR_ExGMAC); rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC); RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | BIT_7); @@ -29585,7 +29991,7 @@ rtl8168_eri_write(tp, 0xDC, 1, csi_tmp, ERIAR_ExGMAC); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -29612,18 +30018,13 @@ tp->mcfg == CFG_METHOD_26 || tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 || tp->mcfg == CFG_METHOD_37) { - set_offset70F(tp, 0x27); - set_offset79(tp, 0x50); - if (tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22) - set_offset711(tp, 0x04); - 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); @@ -29691,7 +30092,7 @@ RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~PMSTS_En); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -29757,12 +30158,9 @@ } } else if (tp->mcfg == CFG_METHOD_23 || tp->mcfg == CFG_METHOD_27 || tp->mcfg == CFG_METHOD_28) { - set_offset70F(tp, 0x27); - 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); @@ -29787,7 +30185,7 @@ RTL_W8(tp, TDFNR, 0x4); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -29832,12 +30230,9 @@ } } else if (tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 || tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) { - set_offset70F(tp, 0x27); - 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); @@ -29887,7 +30282,7 @@ RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~PMSTS_En); /* - if (aspm) + if (tp->aspm) RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) | BIT_7); */ @@ -30086,13 +30481,13 @@ case CFG_METHOD_35: case CFG_METHOD_36: case CFG_METHOD_37: - rtl8168_disable_pci_offset_99(tp); - if (aspm) { - if (tp->org_pci_offset_99 & (BIT_2 | BIT_5 | BIT_6)) - rtl8168_init_pci_offset_99(tp); - } + if (tp->aspm && (tp->org_pci_offset_99 & (BIT_2 | BIT_5 | BIT_6))) + rtl8168_init_pci_offset_99(tp); + else + rtl8168_disable_pci_offset_99(tp); break; } + switch (tp->mcfg) { case CFG_METHOD_24: case CFG_METHOD_25: @@ -30108,11 +30503,10 @@ case CFG_METHOD_35: case CFG_METHOD_36: case CFG_METHOD_37: - rtl8168_disable_pci_offset_180(tp); - if (aspm) { - if (tp->org_pci_offset_180 & (BIT_0|BIT_1)) - rtl8168_init_pci_offset_180(tp); - } + if (tp->aspm && (tp->org_pci_offset_180 & (BIT_0|BIT_1))) + rtl8168_init_pci_offset_180(tp); + else + rtl8168_disable_pci_offset_180(tp); break; } @@ -30141,7 +30535,7 @@ for (timeout = 0; timeout < 10; timeout++) { if ((rtl8168_eri_read(tp, 0x1AE, 2, ERIAR_ExGMAC) & BIT_13)==0) break; - mdelay(1); + fsleep(1000); } } break; @@ -30170,8 +30564,8 @@ pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &tp->pci_cfg_space.resv_0x2c_l); pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID + 2, &tp->pci_cfg_space.resv_0x2c_h); if (tp->HwPcieSNOffset > 0) { - tp->pci_cfg_space.pci_sn_l = rtl8168_csi_read(tp, tp->HwPcieSNOffset); - tp->pci_cfg_space.pci_sn_h = rtl8168_csi_read(tp, tp->HwPcieSNOffset + 4); + tp->pci_cfg_space.pci_sn_l = rtl8168_pci_config_read(tp, tp->HwPcieSNOffset); + tp->pci_cfg_space.pci_sn_h = rtl8168_pci_config_read(tp, tp->HwPcieSNOffset + 4); } tp->pci_cfg_is_read = 1; @@ -30192,7 +30586,7 @@ rtl8168_disable_cfg9346_write(tp); - udelay(10); + fsleep(10); } void @@ -30741,10 +31135,6 @@ rtl8168_disable_napi(tp); #endif//CONFIG_R8168_NAPI -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,67) - /* Give a racing hard_start_xmit a few cycles to complete. */ - synchronize_net(); -#endif rtl8168_irq_mask_and_ack(tp); rtl8168_wait_for_irq_complete(tp); @@ -31146,9 +31536,9 @@ struct TxDesc *txd; dma_addr_t mapping; u32 len; - u32 opts2; + u32 opts2 = { 0 }; netdev_tx_t ret = NETDEV_TX_OK; - unsigned long large_send; + unsigned long large_send = 0; int frags; const u16 queue_mapping = skb_get_queue_mapping(skb); struct rtl8168_tx_ring *ring; @@ -31345,12 +31735,20 @@ ret = NETDEV_TX_OK; goto out; err_stop: - netif_tx_disable(dev); + netif_stop_subqueue(dev, queue_mapping); + smp_mb(); + if (rtl8168_tx_slots_avail(tp, ring)) + netif_start_subqueue(dev, queue_mapping); ret = NETDEV_TX_BUSY; - RTLDEV->stats.tx_dropped++; goto out; } +void +rtl8168_desc_quirk(struct rtl8168_private *tp) +{ + RTL_R8(tp, tp->imr_reg0); +} + static void rtl8168_tx_interrupt(struct rtl8168_tx_ring *ring, int budget) { @@ -31378,10 +31776,18 @@ struct ring_info *tx_skb = ring->tx_skb + entry; u32 status; - rmb(); - status = le32_to_cpu(ring->TxDescArrayentry.opts1); - if (status & DescOwn) - break; + status = le32_to_cpu(READ_ONCE(ring->TxDescArrayentry.opts1)); + if (status & DescOwn) { + if (!tp->recheck_desc_ownbit) + break; + + tp->recheck_desc_ownbit = FALSE; + + rtl8168_desc_quirk(tp); + status = le32_to_cpu(READ_ONCE(ring->TxDescArrayentry.opts1)); + if (status & DescOwn) + break; + } rtl8168_unmap_tx_skb(tp->pci_dev, tx_skb, @@ -31413,11 +31819,11 @@ WRITE_ONCE(ring->dirty_tx, dirty_tx); smp_wmb(); if (netif_queue_stopped(dev) && - (rtl8168_tx_slots_avail(tp, ring))) { + rtl8168_tx_slots_avail(tp, ring) && netif_carrier_ok(dev)) { netif_start_subqueue(dev, ring->index); } smp_rmb(); - if (ring->cur_tx != dirty_tx) + if (READ_ONCE(ring->cur_tx) != dirty_tx) rtl8168_doorbell(ring); } } @@ -31557,9 +31963,18 @@ entry = cur_rx % tp->num_rx_desc; desc = rtl8168_get_rxdesc(tp, tp->RxDescArray, entry, ring_index); - status = le32_to_cpu(desc->opts1); - if (status & DescOwn) - break; + status = le32_to_cpu(READ_ONCE(desc->opts1)); + if (status & DescOwn) { + if (!tp->recheck_desc_ownbit) + break; + + tp->recheck_desc_ownbit = FALSE; + + rtl8168_desc_quirk(tp); + status = le32_to_cpu(READ_ONCE(desc->opts1)); + if (status & DescOwn) + break; + } rmb(); @@ -31711,7 +32126,7 @@ if (unlikely(status & RxFIFOOver)) { if (tp->mcfg == CFG_METHOD_1) { netif_tx_disable(dev); - udelay(300); + fsleep(300); rtl8168_hw_reset(dev); rtl8168_tx_clear(tp); rtl8168_rx_clear(tp); @@ -31733,6 +32148,8 @@ rtl8168_schedule_dash_work(tp); #endif + tp->recheck_desc_ownbit = TRUE; + #ifdef CONFIG_R8168_NAPI if ((status & tp->intr_mask) || (other_q_status & other_q_intr_mask) || @@ -31818,19 +32235,18 @@ rtl8168_schedule_dash_work(tp); #endif + tp->recheck_desc_ownbit = TRUE; + + rtl8168_disable_interrupt_by_vector(tp, message_id); + + rtl8168_self_clear_isr_by_vector(tp, message_id); #ifdef CONFIG_R8168_NAPI - if (likely(RTL_NETIF_RX_SCHEDULE_PREP(dev, &r8168napi->napi))) { - rtl8168_disable_interrupt_by_vector(tp, message_id); + if (likely(RTL_NETIF_RX_SCHEDULE_PREP(dev, &r8168napi->napi))) __RTL_NETIF_RX_SCHEDULE(dev, &r8168napi->napi); - } else if (netif_msg_intr(tp)) + else if (netif_msg_intr(tp)) printk(KERN_INFO "%s: interrupt message id %d in poll_msix\n", dev->name, message_id); - rtl8168_self_clear_isr_by_vector(tp, message_id); #else - rtl8168_disable_interrupt_by_vector(tp, message_id); - - rtl8168_self_clear_isr_by_vector(tp, message_id); - if (message_id == 0) rtl8168_tx_all_interrupt(tp, budget); @@ -31867,9 +32283,11 @@ 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_ringi, budget); - else + else if (message_id < tp->num_rx_rings) work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_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 +32331,8 @@ unsigned int work_to_do = RTL_NAPI_QUOTA(budget, dev); unsigned int work_done = 0; - work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, budget); + if (message_id < tp->num_rx_rings) + work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, budget); RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget); @@ -32029,20 +32448,41 @@ struct net_device *dev = pci_get_drvdata(pdev); struct rtl8168_private *tp = netdev_priv(dev); + rtl8168_cancel_all_schedule_work(tp); + rtnl_lock(); if (HW_DASH_SUPPORT_DASH(tp)) rtl8168_driver_stop(tp); + switch (tp->mcfg) { + case CFG_METHOD_24: + case CFG_METHOD_25: + case CFG_METHOD_26: + case CFG_METHOD_27: + case CFG_METHOD_28: + case CFG_METHOD_29: + case CFG_METHOD_30: + case CFG_METHOD_31: + case CFG_METHOD_32: + case CFG_METHOD_33: + case CFG_METHOD_34: + case CFG_METHOD_35: + case CFG_METHOD_36: + case CFG_METHOD_37: + rtl8168_disable_pci_offset_180(tp); + break; + } + rtl8168_set_bios_setting(dev); - if (s5_keep_curr_mac == 0 && tp->random_mac == 0) + if (tp->s5_keep_curr_mac == 0 && tp->random_mac == 0) rtl8168_rar_set(tp, tp->org_mac_addr); #ifdef ENABLE_FIBER_SUPPORT rtl8168_hw_fiber_nic_d3_para(tp); #endif //ENABLE_FIBER_SUPPORT - if (s5wol == 0) + if (tp->s5wol == 0) tp->wol_enabled = WOL_DISABLED; rtl8168_close(dev); @@ -32095,16 +32535,12 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) u32 pci_pm_state = pci_choose_state(pdev, state); #endif - if (!netif_running(dev)) - goto out; - - //rtl8168_cancel_schedule_work(dev); - - //rtl8168_delete_esd_timer(dev, &tp->esd_timer); + rtnl_lock(); - //rtl8168_delete_link_timer(dev, &tp->link_timer); + set_bit(R8168_FLAG_SUSPEND, tp->task_flags); - rtnl_lock(); + if (!netif_running(dev)) + goto out; set_bit(R8168_FLAG_DOWN, tp->task_flags); @@ -32130,12 +32566,12 @@ rtl8168_sleep_rx_enable(dev); - rtnl_unlock(); - out: if (HW_DASH_SUPPORT_DASH(tp)) rtl8168_driver_stop(tp); + rtnl_unlock(); + pci_disable_device(pdev); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) @@ -32172,6 +32608,8 @@ rtnl_lock(); + set_bit(R8168_FLAG_SUSPEND, tp->task_flags); + err = pci_enable_device(pdev); if (err) { dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
View file
r8168-8.053.00.tar.gz/src/r8168_realwow.h -> r8168-8.057.00.tar.gz/src/r8168_realwow.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,10 +32,10 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_R8168_REALWOW_H -#define _LINUX_R8168_REALWOW_H +#ifndef R8168_REALWOW_H +#define R8168_REALWOW_H -#define SIOCDEVPRIVATE_RTLREALWOW SIOCDEVPRIVATE+3 +#define SIOCDEVPRIVATE_RTLREALWOW (SIOCDEVPRIVATE + 3) #define MAX_RealWoW_KCP_SIZE (100) #define MAX_RealWoW_Payload (64) @@ -43,12 +43,12 @@ #define KA_TX_PACKET_SIZE (100) #define KA_WAKEUP_PATTERN_SIZE (120) -//HwSuppKeepAliveOffloadVer +/* HwSuppKeepAliveOffloadVer */ #define HW_SUPPORT_KCP_OFFLOAD(_M) ((_M)->HwSuppKCPOffloadVer > 0) enum rtl_realwow_cmd { - RTL_REALWOW_SET_KCP_DISABLE=0, + RTL_REALWOW_SET_KCP_DISABLE = 0, RTL_REALWOW_SET_KCP_INFO, RTL_REALWOW_SET_KCP_CONTENT, @@ -56,7 +56,7 @@ RTL_REALWOW_SET_KCP_WPINFO, RTL_REALWOW_SET_KCPDHCP_TIMEOUT, - RTLT_REALWOW_COMMAND_INVALID + RTL_REALWOW_COMMAND_INVALID }; struct rtl_realwow_ioctl_struct { @@ -65,7 +65,7 @@ __u32 len; union { __u32 data; - void *data_buffer; + void __user *data_buffer; }; }; @@ -85,7 +85,7 @@ } MP_KCP_INFO, *PMP_KCP_INFO; typedef struct _KCPInfo { - u32 nId; // = id + u32 nId; /* = id */ u8 DIPv44; u8 MacID6; u16 UdpPort; @@ -93,26 +93,26 @@ } KCPInfo, *PKCPInfo; typedef struct _KCPContent { - u32 id; // = id - u32 mSec; // = msec - u32 size; // =size - u8 bPacketMAX_RealWoW_KCP_SIZE; // put packet here + u32 id; /* = id */ + u32 mSec; /* = msec */ + u32 size; /* = size */ + u8 bPacketMAX_RealWoW_KCP_SIZE; /* put packet here */ } KCPContent, *PKCPContent; typedef struct _RealWoWAckPktInfo { u16 ackLostCnt; - u16 patterntSize; + u16 patternSize; u8 patternMAX_RealWoW_Payload; -} RealWoWAckPktInfo,*PRealWoWAckPktInfo; +} RealWoWAckPktInfo, *PRealWoWAckPktInfo; typedef struct _RealWoWWPInfo { - u16 patterntSize; + u16 patternSize; u8 patternMAX_RealWoW_Payload; -} RealWoWWPInfo,*PRealWoWWPInfo; +} RealWoWWPInfo, *PRealWoWWPInfo; int rtl8168_realwow_ioctl(struct net_device *dev, struct ifreq *ifr); void rtl8168_realwow_hw_init(struct net_device *dev); void rtl8168_get_realwow_hw_version(struct net_device *dev); void rtl8168_set_realwow_d3_para(struct net_device *dev); -#endif /* _LINUX_R8168_REALWOW_H */ +#endif /* R8168_REALWOW_H */
View file
r8168-8.053.00.tar.gz/src/r8168_rss.c -> r8168-8.057.00.tar.gz/src/r8168_rss.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -80,8 +80,6 @@ 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; @@ -106,7 +104,7 @@ } #define RSS_MASK_BITS_OFFSET (8) -static int _rtl8168_set_rss_hash_opt(struct rtl8168_private *tp) +static void _rtl8168_set_rss_hash_opt(struct rtl8168_private *tp) { u32 hash_mask_len; u32 rss_ctrl; @@ -127,8 +125,6 @@ rss_ctrl |= hash_mask_len << RSS_MASK_BITS_OFFSET; rtl8168_eri_write(tp, RSS_CTRL_8168, 4, rss_ctrl, ERIAR_ExGMAC); - - return 0; } static int rtl8168_set_rss_hash_opt(struct rtl8168_private *tp, @@ -136,8 +132,6 @@ { 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 +199,6 @@ 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 +222,6 @@ { 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 +232,6 @@ { 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; @@ -301,11 +289,16 @@ { const u16 rss_key_reg = rtl8168_rss_key_reg(tp); u32 i, rss_key_size = _rtl8168_get_rxfh_key_size(tp); - u32 *rss_key = (u32*)tp->rss_key; - /* Write redirection table to HW */ - for (i = 0; i < rss_key_size; i+=4) - rtl8168_eri_write(tp, rss_key_reg + i, 4, *rss_key++, ERIAR_ExGMAC); + /* Write RSS hash key to HW */ + for (i = 0; i < rss_key_size; i += 4) { + u32 key_word = ((u32)tp->rss_keyi) | + ((u32)tp->rss_keyi + 1 << 8) | + ((u32)tp->rss_keyi + 2 << 16) | + ((u32)tp->rss_keyi + 3 << 24); + + rtl8168_eri_write(tp, rss_key_reg + i, 4, key_word, ERIAR_ExGMAC); + } } #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,8,0) @@ -313,8 +306,6 @@ { 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 +327,6 @@ 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 +362,6 @@ { 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 +384,6 @@ 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 */ @@ -434,7 +419,7 @@ struct RxDescV2 *desc) { if (!desc->RSSResult) - udelay(1); + fsleep(1); return le32_to_cpu(desc->RSSResult); }
View file
r8168-8.053.00.tar.gz/src/r8168_rss.h -> r8168-8.057.00.tar.gz/src/r8168_rss.h
Changed
@@ -2,10 +2,10 @@ /* ################################################################################ # -# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet +# r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,8 +32,8 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_RTL8168_RSS_H -#define _LINUX_RTL8168_RSS_H +#ifndef RTL8168_RSS_H +#define RTL8168_RSS_H #include <linux/netdevice.h> #include <linux/types.h> @@ -69,4 +69,4 @@ u32 rtl8168_rss_indir_tbl_entries(struct rtl8168_private *tp); void rtl8168_disable_rss(struct rtl8168_private *tp); -#endif /* _LINUX_RTL8168_RSS_H */ +#endif /* RTL8168_RSS_H */
View file
r8168-8.053.00.tar.gz/src/rtl_eeprom.c -> r8168-8.057.00.tar.gz/src/rtl_eeprom.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -46,10 +46,8 @@ //------------------------------------------------------------------- //rtl8168_eeprom_type(): -// tell the eeprom type -//return value: -// 0: the eeprom type is 93C46 -// 1: the eeprom type is 93C56 or 93C66 +// Probe and set the EEPROM type in tp->eeprom_type and tp->eeprom_len. +// Must be called before any EEPROM read/write operations. //------------------------------------------------------------------- void rtl8168_eeprom_type(struct rtl8168_private *tp) { @@ -58,12 +56,12 @@ if (tp->mcfg == CFG_METHOD_DEFAULT) goto out_no_eeprom; - if(RTL_R8(tp, 0xD2)&0x04) { + if (RTL_R8(tp, 0xD2) & 0x04) { //not support //tp->eeprom_type = EEPROM_TWSI; //tp->eeprom_len = 256; goto out_no_eeprom; - } else if(RTL_R32(tp, RxConfig) & RxCfg_9356SEL) { + } else if (RTL_R32(tp, RxConfig) & RxCfg_9356SEL) { tp->eeprom_type = EEPROM_TYPE_93C56; tp->eeprom_len = 256; } else { @@ -104,10 +102,10 @@ x = RTL_R8(tp, Cfg9346); if (x & Cfg9346_EEDO) { - udelay(RTL_CLOCK_RATE * 2 * 3); + fsleep(RTL_CLOCK_RATE * 2 * 3); return 0; } - udelay(1); + fsleep(1); } return -1; @@ -121,15 +119,15 @@ { int addr_sz = 6; u8 x; - u16 data; + u16 data = 0; - if(tp->eeprom_type == EEPROM_TYPE_NONE) { - return -1; + if (tp->eeprom_type == EEPROM_TYPE_NONE) { + return 0xFFFF; } - if (tp->eeprom_type==EEPROM_TYPE_93C46) + if (tp->eeprom_type == EEPROM_TYPE_93C46) addr_sz = 6; - else if (tp->eeprom_type==EEPROM_TYPE_93C56) + else if (tp->eeprom_type == EEPROM_TYPE_93C56) addr_sz = 8; x = Cfg9346_EEM1 | Cfg9346_EECS; @@ -157,13 +155,13 @@ int addr_sz = 6; int w_dummy_addr = 4; - if(tp->eeprom_type == EEPROM_TYPE_NONE) + if (tp->eeprom_type == EEPROM_TYPE_NONE) return; - if (tp->eeprom_type==EEPROM_TYPE_93C46) { + if (tp->eeprom_type == EEPROM_TYPE_93C46) { addr_sz = 6; w_dummy_addr = 4; - } else if (tp->eeprom_type==EEPROM_TYPE_93C56) { + } else if (tp->eeprom_type == EEPROM_TYPE_93C56) { addr_sz = 8; w_dummy_addr = 6; } @@ -178,19 +176,20 @@ rtl8168_shift_out_bits(tp, RTL_EEPROM_ERASE_OPCODE, 3); rtl8168_shift_out_bits(tp, reg, addr_sz); if (rtl8168_eeprom_cmd_done(tp) < 0) - return; + goto exit; rtl8168_stand_by(tp); rtl8168_shift_out_bits(tp, RTL_EEPROM_WRITE_OPCODE, 3); rtl8168_shift_out_bits(tp, reg, addr_sz); rtl8168_shift_out_bits(tp, data, 16); if (rtl8168_eeprom_cmd_done(tp) < 0) - return; + goto exit; rtl8168_stand_by(tp); rtl8168_shift_out_bits(tp, RTL_EEPROM_EWDS_OPCODE, 5); rtl8168_shift_out_bits(tp, reg, w_dummy_addr); +exit: rtl8168_eeprom_cleanup(tp); RTL_W8(tp, Cfg9346, 0); } @@ -199,23 +198,22 @@ { *x = *x | Cfg9346_EESK; RTL_W8(tp, Cfg9346, *x); - udelay(RTL_CLOCK_RATE); + fsleep(RTL_CLOCK_RATE); } void rtl8168_lower_clock(struct rtl8168_private *tp, u8 *x) { - *x = *x & ~Cfg9346_EESK; RTL_W8(tp, Cfg9346, *x); - udelay(RTL_CLOCK_RATE); + fsleep(RTL_CLOCK_RATE); } void rtl8168_shift_out_bits(struct rtl8168_private *tp, int data, int count) { u8 x; - int mask; + unsigned int mask; - mask = 0x01 << (count - 1); + mask = 0x01U << (count - 1); x = RTL_R8(tp, Cfg9346); x &= ~(Cfg9346_EEDI | Cfg9346_EEDO); @@ -226,11 +224,11 @@ x &= ~Cfg9346_EEDI; RTL_W8(tp, Cfg9346, x); - udelay(RTL_CLOCK_RATE); + fsleep(RTL_CLOCK_RATE); rtl8168_raise_clock(tp, &x); rtl8168_lower_clock(tp, &x); mask = mask >> 1; - } while(mask); + } while (mask); x &= ~Cfg9346_EEDI; RTL_W8(tp, Cfg9346, x); @@ -239,7 +237,8 @@ u16 rtl8168_shift_in_bits(struct rtl8168_private *tp) { u8 x; - u16 d, i; + u16 d; + int i; x = RTL_R8(tp, Cfg9346); x &= ~(Cfg9346_EEDI | Cfg9346_EEDO); @@ -269,7 +268,7 @@ x = RTL_R8(tp, Cfg9346); x &= ~(Cfg9346_EECS | Cfg9346_EESK); RTL_W8(tp, Cfg9346, x); - udelay(RTL_CLOCK_RATE); + fsleep(RTL_CLOCK_RATE); x |= Cfg9346_EECS; RTL_W8(tp, Cfg9346, x); @@ -280,7 +279,7 @@ RTL_W8(tp, Cfg9346, Cfg9346_EEM1); RTL_W8(tp, Cfg9346, Cfg9346_EEM1 | Cfg9346_EESK); - udelay(20); + fsleep(20); RTL_W8(tp, Cfg9346, Cfg9346_EEM1); }
View file
r8168-8.053.00.tar.gz/src/rtl_eeprom.h -> r8168-8.057.00.tar.gz/src/rtl_eeprom.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,10 +32,14 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -//EEPROM opcodes -#define RTL_EEPROM_READ_OPCODE 06 -#define RTL_EEPROM_WRITE_OPCODE 05 -#define RTL_EEPROM_ERASE_OPCODE 07 +#ifndef RTL_EEPROM_H +#define RTL_EEPROM_H + + +/* EEPROM opcodes */ +#define RTL_EEPROM_READ_OPCODE 6 +#define RTL_EEPROM_WRITE_OPCODE 5 +#define RTL_EEPROM_ERASE_OPCODE 7 #define RTL_EEPROM_EWEN_OPCODE 19 #define RTL_EEPROM_EWDS_OPCODE 16 @@ -52,5 +56,4 @@ void rtl8168_stand_by(struct rtl8168_private *tp); void rtl8168_set_eeprom_sel_low(struct rtl8168_private *tp); - - +#endif /* RTL_EEPROM_H */
View file
r8168-8.053.00.tar.gz/src/rtltool.c -> r8168-8.057.00.tar.gz/src/rtltool.c
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -55,6 +55,12 @@ ret = 0; switch (my_cmd.cmd) { case RTLTOOL_READ_MAC: + if (my_cmd.offset >= R8168_REGS_SIZE || + my_cmd.len > R8168_REGS_SIZE - my_cmd.offset) { + ret = -EINVAL; + break; + } + if (my_cmd.len==1) my_cmd.data = readb(tp->mmio_addr+my_cmd.offset); else if (my_cmd.len==2) @@ -72,6 +78,12 @@ } break; case RTLTOOL_WRITE_MAC: + if (my_cmd.offset >= R8168_REGS_SIZE || + my_cmd.len > R8168_REGS_SIZE - my_cmd.offset) { + ret = -EINVAL; + break; + } + if (my_cmd.len==1) writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset); else if (my_cmd.len==2) @@ -162,6 +174,11 @@ } break; case RTLTOOL_READ_EEPROM: + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } + my_cmd.data = rtl8168_eeprom_read_sc(tp, my_cmd.offset); if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) { ret = -EFAULT; @@ -169,9 +186,19 @@ } break; case RTLTOOL_WRITE_EEPROM: + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } + rtl8168_eeprom_write_sc(tp, my_cmd.offset, my_cmd.data); break; - case RTL_READ_OOB_MAC: + case RTLTOOL_READ_OOB_MAC: + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } + rtl8168_oob_mutex_lock(tp); my_cmd.data = rtl8168_ocp_read(tp, my_cmd.offset, 4); rtl8168_oob_mutex_unlock(tp); @@ -181,25 +208,39 @@ break; } break; - case RTL_WRITE_OOB_MAC: - if (my_cmd.len == 0 || my_cmd.len > 4) - return -EOPNOTSUPP; + case RTLTOOL_WRITE_OOB_MAC: + if (my_cmd.len == 0 || my_cmd.len > 4) { + ret = -EOPNOTSUPP; + break; + } + + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } rtl8168_oob_mutex_lock(tp); rtl8168_ocp_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data); rtl8168_oob_mutex_unlock(tp); break; - case RTL_ENABLE_PCI_DIAG: + case RTLTOOL_ENABLE_PCI_DIAG: tp->rtk_enable_diag = 1; dprintk("enable rtk diag\n"); break; - case RTL_DISABLE_PCI_DIAG: + case RTLTOOL_DISABLE_PCI_DIAG: tp->rtk_enable_diag = 0; dprintk("disable rtk diag\n"); break; - case RTL_READ_MAC_OCP: - if (my_cmd.offset % 2) - return -EOPNOTSUPP; + case RTLTOOL_READ_MAC_OCP: + if (my_cmd.offset % 2) { + ret = -EOPNOTSUPP; + break; + } + + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } my_cmd.data = rtl8168_mac_ocp_read(tp, my_cmd.offset); if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) { @@ -207,20 +248,27 @@ break; } break; - case RTL_WRITE_MAC_OCP: - if ((my_cmd.offset % 2) || (my_cmd.len != 2)) - return -EOPNOTSUPP; + case RTLTOOL_WRITE_MAC_OCP: + if ((my_cmd.offset % 2) || (my_cmd.len != 2)) { + ret = -EOPNOTSUPP; + break; + } + + if (my_cmd.offset > 0xFFFF) { + ret = -EINVAL; + break; + } rtl8168_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data); break; - case RTL_DIRECT_READ_PHY_OCP: + case RTLTOOL_DIRECT_READ_PHY_OCP: my_cmd.data = rtl8168_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset); if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) { ret = -EFAULT; break; } break; - case RTL_DIRECT_WRITE_PHY_OCP: + case RTLTOOL_DIRECT_WRITE_PHY_OCP: rtl8168_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data); break; default:
View file
r8168-8.053.00.tar.gz/src/rtltool.h -> r8168-8.057.00.tar.gz/src/rtltool.h
Changed
@@ -5,7 +5,7 @@ # r8168 is the Linux device driver released for Realtek Gigabit Ethernet # controllers with PCI-Express interface. # -# Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved. +# Copyright(c) 2025 Realtek Semiconductor Corp. All rights reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -32,13 +32,15 @@ * US6,570,884, US6,115,776, and US6,327,625. ***********************************************************************************/ -#ifndef _LINUX_RTLTOOL_H -#define _LINUX_RTLTOOL_H +#ifndef RTLTOOL_H +#define RTLTOOL_H -#define SIOCRTLTOOL SIOCDEVPRIVATE+1 +#include <linux/types.h> + +#define SIOCRTLTOOL (SIOCDEVPRIVATE + 1) enum rtl_cmd { - RTLTOOL_READ_MAC=0, + RTLTOOL_READ_MAC = 0, RTLTOOL_WRITE_MAC, RTLTOOL_READ_PHY, RTLTOOL_WRITE_PHY, @@ -51,17 +53,17 @@ RTLTOOL_READ_EEPROM, RTLTOOL_WRITE_EEPROM, - RTL_READ_OOB_MAC, - RTL_WRITE_OOB_MAC, + RTLTOOL_READ_OOB_MAC, + RTLTOOL_WRITE_OOB_MAC, - RTL_ENABLE_PCI_DIAG, - RTL_DISABLE_PCI_DIAG, + RTLTOOL_ENABLE_PCI_DIAG, + RTLTOOL_DISABLE_PCI_DIAG, - RTL_READ_MAC_OCP, - RTL_WRITE_MAC_OCP, + RTLTOOL_READ_MAC_OCP, + RTLTOOL_WRITE_MAC_OCP, - RTL_DIRECT_READ_PHY_OCP, - RTL_DIRECT_WRITE_PHY_OCP, + RTLTOOL_DIRECT_READ_PHY_OCP, + RTLTOOL_DIRECT_WRITE_PHY_OCP, RTLTOOL_INVALID }; @@ -73,14 +75,8 @@ __u32 data; }; -enum mode_access { - MODE_NONE=0, - MODE_READ, - MODE_WRITE -}; - #ifdef __KERNEL__ int rtl8168_tool_ioctl(struct rtl8168_private *tp, struct ifreq *ifr); #endif -#endif /* _LINUX_RTLTOOL_H */ +#endif /* RTLTOOL_H */
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.