Overview

Request 6032 (accepted)

- Update to new version r8168-8.052.01
- Remove patches now upstream
* skb_gso_segment.patch
* r8168-support-linux-6.1.0.patch
- Port patches
* r8168-configuration.patch
* r8168-kernel_version.patch
* r8168-support-dev0x8136.patch
* r8168-support-linux-5.19.patch
* r8168-support-linux-L15.5.patch
- Add r8168.keyring and signature of tar ball to check tar ball
- Add patch r8168-gcc14.patch
* Avoid gcc14 trouble
* Switch from deprecated strlcpy() to strscpy()

- Use %patch -P N instead of deprecated %patchN.

Submit package home:bitstreamout:Essentials / r8168 to package Essentials / r8168

r8168.changes Changed
x
 
1
@@ -1,4 +1,27 @@
2
 -------------------------------------------------------------------
3
+Wed Mar 13 12:12:43 UTC 2024 - Dr. Werner Fink <werner@suse.de>
4
+
5
+- Update to new version r8168-8.052.01
6
+- Remove patches now upstream
7
+  * skb_gso_segment.patch
8
+  * r8168-support-linux-6.1.0.patch
9
+- Port patches
10
+  * r8168-configuration.patch
11
+  * r8168-kernel_version.patch
12
+  * r8168-support-dev0x8136.patch
13
+  * r8168-support-linux-5.19.patch
14
+  * r8168-support-linux-L15.5.patch
15
+- Add r8168.keyring and signature of tar ball to check tar ball
16
+- Add patch r8168-gcc14.patch
17
+  * Avoid gcc14 trouble
18
+  * Switch from deprecated strlcpy() to strscpy()
19
+
20
+-------------------------------------------------------------------
21
+Wed Mar 13 11:26:04 UTC 2024 - Dr. Werner Fink <werner@suse.de>
22
+
23
+- Use %patch -P N instead of deprecated %patchN. 
24
+
25
+-------------------------------------------------------------------
26
 Thu Oct 19 08:29:04 UTC 2023 - Dr. Werner Fink <werner@suse.de>
27
 
28
 - Dynamic adaption of patch skb_gso_segment.patch means if net/gso.h
29
r8168.spec Changed
60
 
1
@@ -18,7 +18,7 @@
2
 
3
 #!BuildIgnore: enough-build-resources
4
 Name:           r8168
5
-Version:        8.051.02
6
+Version:        8.052.01
7
 Release:        0
8
 Summary:        Device driver for RealTek Gigabit Ethernet controllers
9
 License:        GPL-2.0-or-later
10
@@ -27,13 +27,14 @@
11
 Source0:        https://github.com/mtorromeo/r8168/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
12
 Source1:        preamble
13
 Source2:        Module.supported
14
+Source3:        https://github.com/mtorromeo/r8168/releases/download/%{version}/%{name}-%{version}.tar.gz.asc
15
+Source4:        r8168.keyring
16
 Patch0:         r8168-kernel_version.patch
17
 Patch1:         r8168-configuration.patch
18
 Patch2:         r8168-support-linux-5.19.patch
19
-Patch3:         r8168-support-linux-6.1.0.patch
20
+Patch3:         r8168-gcc14.patch
21
 Patch4:         r8168-support-dev0x8136.patch
22
 Patch5:         r8168-support-linux-L15.5.patch
23
-Patch6:         skb_gso_segment.patch
24
 BuildRequires:  kernel-source
25
 BuildRequires:  kernel-syms
26
 BuildRequires:  libelf-devel
27
@@ -61,25 +62,24 @@
28
 
29
 %prep
30
 %setup -q
31
-%patch0 -b .p0
32
-%patch1 -b .p1
33
-%patch2 -p1 -b .p2
34
-%patch3 -p1 -b .p3
35
-%patch4 -p1 -b .p4
36
+%patch -P 0 -b .p0
37
+%patch -P 1 -b .p1
38
+%patch -P 2 -p1 -b .p2
39
+%patch -P 3 -b .p3
40
+%patch -P 4 -p1 -b .p4
41
 if test -e /usr/src/linux/include/linux/ethtool.h
42
 then
43
     argc=$(sed -rn '/\*get_ringparam/,/;$/p' /usr/src/linux/include/linux/ethtool.h | wc -l)
44
     if test -n "$argc" -a "$argc" -eq 4
45
     then
46
-%patch5 -b .p5
47
+%patch -P 5 -b .p5
48
     fi
49
 fi
50
 if test -e /usr/src/linux/include/net/gso.h
51
 then
52
     version=$(uname -r|sed -r 's/-.*//;s/\./,/g')
53
-    sed -ri "/KERNEL_VERSION/{s/\(6,4,10\)/(${version})/}" %{PATCH6}
54
+    sed -ri "/KERNEL_VERSION/{s/\(6,4,10\)/(${version})/}" src/r8168_n.c
55
 fi
56
-%patch6 -p1 -b .p6
57
 cp %{S:1} .
58
 cp %{S:2} .
59
 
60
r8168-configuration.patch Changed
10
 
1
@@ -4,7 +4,7 @@
2
 
3
 --- src/Makefile
4
 +++ src/Makefile   2022-05-10 10:26:59.851240712 +0000
5
-@@ -48,6 +48,7 @@ CONFIG_CTAP_SHORT_OFF = n
6
+@@ -52,6 +52,7 @@ CONFIG_CTAP_SHORT_OFF = n
7
  ifneq ($(KERNELRELEASE),)
8
    obj-m := r8168.o
9
    r8168-objs := r8168_n.o r8168_asf.o rtl_eeprom.o rtltool.o
10
r8168-gcc14.patch Added
27
 
1
@@ -0,0 +1,25 @@
2
+---
3
+ src/r8168_n.c |    5 +++--
4
+ 1 file changed, 3 insertions(+), 2 deletions(-)
5
+
6
+--- src/r8168_n.c
7
++++ src/r8168_n.c  2024-03-13 12:25:52.886342182 +0000
8
+@@ -6312,7 +6312,7 @@ rtl8168_get_drvinfo(struct net_device *d
9
+         info->eedump_len = tp->eeprom_len;
10
+         BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version));
11
+         if (rtl_fw)
12
+-                strlcpy(info->fw_version, rtl_fw->version,
13
++                strscpy(info->fw_version, rtl_fw->version,
14
+                         sizeof(info->fw_version));
15
+ }
16
+ 
17
+@@ -28103,7 +28103,8 @@ rtl8168_link_timer(struct timer_list *t)
18
+ }
19
+ */
20
+ 
21
+-int rtl8168_enable_msix(struct rtl8168_private *tp)
22
++static int
23
++rtl8168_enable_msix(struct rtl8168_private *tp)
24
+ {
25
+         int i, nvecs = 0;
26
+         struct msix_entry msix_entR8168_MAX_MSIX_VEC;
27
r8168-kernel_version.patch Changed
63
 
1
@@ -4,8 +4,8 @@
2
  2 files changed, 18 insertions(+), 1 deletion(-)
3
 
4
 --- src/r8168.h
5
-+++ src/r8168.h    2022-05-10 10:26:28.831787721 +0000
6
-@@ -121,6 +121,10 @@ do { \
7
++++ src/r8168.h    2024-03-13 11:51:59.011947503 +0000
8
+@@ -133,6 +133,10 @@ do { \
9
  } while (0)
10
  #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
11
  
12
@@ -17,7 +17,7 @@
13
  #if defined(skb_vlan_tag_present) && !defined(vlan_tx_tag_present)
14
  #define vlan_tx_tag_present skb_vlan_tag_present
15
 --- src/r8168_n.c
16
-+++ src/r8168_n.c  2022-05-10 10:26:28.871787016 +0000
17
++++ src/r8168_n.c  2024-03-13 11:57:02.890342590 +0000
18
 @@ -61,11 +61,16 @@
19
  #include <linux/rtnetlink.h>
20
  #include <linux/completion.h>
21
@@ -35,7 +35,7 @@
22
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37)
23
  #include <linux/prefetch.h>
24
  #endif
25
-@@ -571,8 +576,12 @@ static void rtl8168_set_rx_mode(struct n
26
+@@ -590,8 +595,12 @@ static void rtl8168_set_rx_mode(struct n
27
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
28
  static void rtl8168_tx_timeout(struct net_device *dev, unsigned int txqueue);
29
  #else
30
@@ -46,9 +46,9 @@
31
  #endif
32
 +#endif
33
  static struct net_device_stats *rtl8168_get_stats(struct net_device *dev);
34
- static int rtl8168_rx_interrupt(struct net_device *, struct rtl8168_private *, napi_budget);
35
- static int rtl8168_change_mtu(struct net_device *dev, int new_mtu);
36
-@@ -28985,8 +28994,12 @@ static void
37
+ static int rtl8168_rx_interrupt(struct net_device *, struct rtl8168_private *, struct rtl8168_rx_ring *, napi_budget);
38
+ #ifdef CONFIG_R8168_NAPI
39
+@@ -30765,8 +30774,12 @@ static void
40
  rtl8168_tx_timeout(struct net_device *dev, unsigned int txqueue)
41
  #else
42
  static void
43
@@ -60,13 +60,13 @@
44
 +#endif
45
  {
46
          struct rtl8168_private *tp = netdev_priv(dev);
47
-         unsigned long flags;
48
-@@ -29672,7 +29685,7 @@ process_pkt:
49
  
50
-                         if (rtl8168_rx_vlan_skb(tp, desc, skb) < 0)
51
-                                 rtl8168_rx_skb(tp, skb);
52
+@@ -31502,7 +31515,7 @@ rtl8168_rx_interrupt(struct net_device *
53
+ 
54
+                 if (rtl8168_rx_vlan_skb(tp, desc, skb) < 0)
55
+                         rtl8168_rx_skb(tp, skb, ring_index);
56
 -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
57
 +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0)
58
-                         dev->last_rx = jiffies;
59
+                 dev->last_rx = jiffies;
60
  #endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
61
-                         RTLDEV->stats.rx_bytes += pkt_size;
62
+                 RTLDEV->stats.rx_bytes += pkt_size;
63
r8168-support-dev0x8136.patch Changed
10
 
1
@@ -12,7 +12,7 @@
2
 index 28d7636..cbf43d1 100755
3
 --- a/src/r8168_n.c
4
 +++ b/src/r8168_n.c
5
-@@ -411,6 +411,7 @@ static const struct {
6
+@@ -430,6 +430,7 @@ static const struct {
7
  
8
  static struct pci_device_id rtl8168_pci_tbl = {
9
          { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), },
10
r8168-support-linux-5.19.patch Changed
9
 
1
@@ -1,6 +1,6 @@
2
 --- r8168-8.050.03/src/r8168_n.c
3
 +++ r8168-8.050.03/src/r8168_n.c
4
-@@ -121,6 +121,15 @@
5
+@@ -126,6 +126,15 @@
6
  #define FIRMWARE_8168FP_3   "rtl_nic/rtl8168fp-3.fw"
7
  #define FIRMWARE_8168FP_4   "rtl_nic/rtl8168fp-4.fw"
8
  
9
r8168-support-linux-6.1.0.patch Deleted
27
 
1
@@ -1,25 +0,0 @@
2
-From 39dd0fd2e5dc45cd63113f33a9890e36c304916d Mon Sep 17 00:00:00 2001
3
-From: zu1k <i@zu1k.com>
4
-Date: Sat, 29 Oct 2022 21:57:39 +0800
5
-Subject: PATCH Adapted for Linux 6.1
6
-
7
----
8
- src/r8168.h | 4 ++++
9
- 1 file changed, 4 insertions(+)
10
-
11
-diff --git a/src/r8168.h b/src/r8168.h
12
-index 662974a..baf48c6 100755
13
---- a/src/r8168.h
14
-+++ b/src/r8168.h
15
-@@ -570,7 +570,11 @@ typedef int *napi_budget;
16
- typedef struct napi_struct *napi_ptr;
17
- typedef int napi_budget;
18
- 
19
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
20
-+#define RTL_NAPI_CONFIG(ndev, priv, function, weight)   netif_napi_add(ndev, &priv->napi, function)
21
-+#else
22
- #define RTL_NAPI_CONFIG(ndev, priv, function, weight)   netif_napi_add(ndev, &priv->napi, function, weight)
23
-+#endif
24
- #define RTL_NAPI_QUOTA(budget, ndev)            min(budget, budget)
25
- #define RTL_GET_PRIV(stuct_ptr, priv_struct)        container_of(stuct_ptr, priv_struct, stuct_ptr)
26
- #define RTL_GET_NETDEV(priv_ptr)            struct net_device *dev = priv_ptr->dev;
27
r8168-support-linux-L15.5.patch Changed
50
 
1
@@ -3,8 +3,8 @@
2
  1 file changed, 6 insertions(+), 6 deletions(-)
3
 
4
 --- src/r8168_n.c
5
-+++ src/r8168_n.c  2023-05-10 10:40:25.454736974 +0000
6
-@@ -5964,7 +5964,7 @@ rtl8168_wait_for_quiescence(struct net_d
7
++++ src/r8168_n.c  2024-03-13 12:10:07.947820999 +0000
8
+@@ -6986,7 +6986,7 @@ rtl8168_set_ring_size(struct rtl8168_pri
9
  }
10
  
11
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
12
@@ -13,7 +13,7 @@
13
  static void rtl8168_get_ringparam(struct net_device *dev,
14
                                    struct ethtool_ringparam *ring,
15
                                    struct kernel_ethtool_ringparam *kernel_ring,
16
-@@ -5972,7 +5972,7 @@ static void rtl8168_get_ringparam(struct
17
+@@ -6994,7 +6994,7 @@ static void rtl8168_get_ringparam(struct
18
  #else
19
  static void rtl8168_get_ringparam(struct net_device *dev,
20
                                    struct ethtool_ringparam *ring)
21
@@ -22,8 +22,8 @@
22
  {
23
          struct rtl8168_private *tp = netdev_priv(dev);
24
  
25
-@@ -5982,7 +5982,7 @@ static void rtl8168_get_ringparam(struct
26
-         ring->tx_pending = tp->num_tx_desc;
27
+@@ -7004,7 +7004,7 @@ static void rtl8168_get_ringparam(struct
28
+         ring->tx_pending = tp->tx_ring0.num_tx_desc;
29
  }
30
  
31
 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
32
@@ -31,7 +31,7 @@
33
  static int rtl8168_set_ringparam(struct net_device *dev,
34
                                   struct ethtool_ringparam *ring,
35
                                   struct kernel_ethtool_ringparam *kernel_ring,
36
-@@ -5990,7 +5990,7 @@ static int rtl8168_set_ringparam(struct
37
+@@ -7012,7 +7012,7 @@ static int rtl8168_set_ringparam(struct
38
  #else
39
  static int rtl8168_set_ringparam(struct net_device *dev,
40
                                   struct ethtool_ringparam *ring)
41
@@ -40,7 +40,7 @@
42
  {
43
          struct rtl8168_private *tp = netdev_priv(dev);
44
          u32 new_rx_count, new_tx_count;
45
-@@ -25420,11 +25420,11 @@ rtl8168_release_board(struct pci_dev *pd
46
+@@ -26644,11 +26644,11 @@ rtl8168_release_board(struct pci_dev *pd
47
  static void
48
  rtl8168_hw_address_set(struct net_device *dev, u8 mac_addrMAC_ADDR_LEN)
49
  {
50
skb_gso_segment.patch Deleted
27
 
1
@@ -1,25 +0,0 @@
2
-From fc2e0d28c79d3f6ef052d85a7cb146610554ff22 Mon Sep 17 00:00:00 2001
3
-From: safocl <safocl88@gmail.com>
4
-Date: Sun, 13 Aug 2023 04:23:03 +0400
5
-Subject: PATCH Fix missing skb_gso_segment function declaration This
6
- motivation from this issue(https://github.com/mtorromeo/r8168/issues/54)
7
-
8
----
9
- src/r8168_n.c | 4 ++++
10
- 1 file changed, 4 insertions(+)
11
-
12
-diff --git a/src/r8168_n.c b/src/r8168_n.c
13
-index 7e9e2ea..3855910 100755
14
---- a/src/r8168_n.c
15
-+++ b/src/r8168_n.c
16
-@@ -86,6 +86,10 @@
17
- #include <linux/mdio.h>
18
- #endif
19
- 
20
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,10)
21
-+#include <net/gso.h>
22
-+#endif
23
-+
24
- #include <asm/io.h>
25
- #include <asm/irq.h>
26
- 
27
r8168-8.052.01.tar.gz.asc Added
9
 
1
@@ -0,0 +1,7 @@
2
+-----BEGIN PGP SIGNATURE-----
3
+
4
+iHUEABYIAB0WIQQMrarPcPZMZU4TGzERZ1x0NCnd7wUCZRk1EAAKCRARZ1x0NCnd
5
+761TAPsHdh+FI5/eoR1/vSKJ8nCBXVmP6xR9q5bHvknbyzcGJAD/Zq5BWgkYnfBR
6
+M3Ow6FM7EZ7+iAlkIRAavYHASGXERQ4=
7
+=QvU5
8
+-----END PGP SIGNATURE-----
9
r8168-8.051.02.tar.gz/Makefile -> r8168-8.052.01.tar.gz/Makefile Changed
10
 
1
@@ -4,7 +4,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/Makefile -> r8168-8.052.01.tar.gz/src/Makefile Changed
53
 
1
@@ -4,7 +4,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
@@ -44,6 +44,10 @@
11
 CONFIG_DYNAMIC_ASPM = y
12
 ENABLE_USE_FIRMWARE_FILE = n
13
 CONFIG_CTAP_SHORT_OFF = n
14
+ENABLE_MULTIPLE_TX_QUEUE = n
15
+ENABLE_RSS_SUPPORT = n
16
+ENABLE_LIB_SUPPORT = n
17
+DISABLE_WOL_SUPPORT = n
18
 
19
 ifneq ($(KERNELRELEASE),)
20
    obj-m := r8168.o
21
@@ -67,7 +71,9 @@
22
        r8168-objs += r8168_dash.o
23
        EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT -DENABLE_DASH_PRINTER_SUPPORT
24
    endif
25
-   EXTRA_CFLAGS += -DCONFIG_R8168_NAPI
26
+   ifneq ($(ENABLE_RSS_SUPPORT), y)
27
+       EXTRA_CFLAGS += -DCONFIG_R8168_NAPI
28
+   endif
29
    EXTRA_CFLAGS += -DCONFIG_R8168_VLAN
30
    ifeq ($(CONFIG_DOWN_SPEED_100), y)
31
        EXTRA_CFLAGS += -DCONFIG_DOWN_SPEED_100
32
@@ -97,6 +103,20 @@
33
    ifeq ($(CONFIG_CTAP_SHORT_OFF), y)
34
        EXTRA_CFLAGS += -DCONFIG_CTAP_SHORT_OFF
35
    endif
36
+   ifeq ($(ENABLE_MULTIPLE_TX_QUEUE), y)
37
+       EXTRA_CFLAGS += -DENABLE_MULTIPLE_TX_QUEUE
38
+   endif
39
+   ifeq ($(ENABLE_RSS_SUPPORT), y)
40
+       r8168-objs += r8168_rss.o
41
+       EXTRA_CFLAGS += -DENABLE_RSS_SUPPORT
42
+   endif
43
+   ifeq ($(ENABLE_LIB_SUPPORT), y)
44
+       r8168-objs += r8168_lib.o
45
+       EXTRA_CFLAGS += -DENABLE_LIB_SUPPORT
46
+   endif
47
+   ifeq ($(DISABLE_WOL_SUPPORT), y)
48
+       EXTRA_CFLAGS += -DDISABLE_WOL_SUPPORT
49
+   endif
50
 else
51
    BASEDIR := /lib/modules/$(shell uname -r)
52
    KERNELDIR ?= $(BASEDIR)/build
53
r8168-8.051.02.tar.gz/src/Makefile_linux24x -> r8168-8.052.01.tar.gz/src/Makefile_linux24x Changed
10
 
1
@@ -4,7 +4,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168.h -> r8168-8.052.01.tar.gz/src/r8168.h Changed
815
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
@@ -33,9 +33,21 @@
11
  ***********************************************************************************/
12
 
13
 #include <linux/ethtool.h>
14
+#include <linux/interrupt.h>
15
+#include <linux/version.h>
16
 #include "r8168_dash.h"
17
 #include "r8168_realwow.h"
18
 #include "r8168_fiber.h"
19
+#include "r8168_rss.h"
20
+#ifdef ENABLE_LIB_SUPPORT
21
+#include "r8168_lib.h"
22
+#endif
23
+
24
+/*
25
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)&& !defined(ENABLE_LIB_SUPPORT)
26
+#define RTL_USE_NEW_INTR_API
27
+#endif
28
+*/
29
 
30
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
31
 typedef int netdev_tx_t;
32
@@ -130,11 +142,14 @@
33
 #endif
34
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
35
 
36
-#define RTL_ALLOC_SKB_INTR(tp, length) dev_alloc_skb(length)
37
+#define RTL_ALLOC_SKB_INTR(napi, length) dev_alloc_skb(length)
38
+#define R8168_USE_NAPI_ALLOC_SKB 0
39
 #ifdef CONFIG_R8168_NAPI
40
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0)
41
 #undef RTL_ALLOC_SKB_INTR
42
-#define RTL_ALLOC_SKB_INTR(tp, length) napi_alloc_skb(&tp->napi, length)
43
+#define RTL_ALLOC_SKB_INTR(napi, length) napi_alloc_skb(napi, length)
44
+#undef R8168_USE_NAPI_ALLOC_SKB
45
+#define R8168_USE_NAPI_ALLOC_SKB 1
46
 #endif
47
 #endif
48
 
49
@@ -319,7 +334,7 @@
50
 #ifndef NET_IP_ALIGN
51
 #define NET_IP_ALIGN        2
52
 #endif
53
-#define RTK_RX_ALIGN        8
54
+#define RTK_RX_ALIGN        NET_IP_ALIGN
55
 
56
 #ifdef CONFIG_R8168_NAPI
57
 #define NAPI_SUFFIX "-NAPI"
58
@@ -343,13 +358,18 @@
59
 #else
60
 #define DASH_SUFFIX ""
61
 #endif
62
+#if defined(ENABLE_RSS_SUPPORT)
63
+#define RSS_SUFFIX "-RSS"
64
+#else
65
+#define RSS_SUFFIX ""
66
+#endif
67
 
68
-#define RTL8168_VERSION "8.051.02" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX
69
+#define RTL8168_VERSION "8.052.01" NAPI_SUFFIX FIBER_SUFFIX REALWOW_SUFFIX DASH_SUFFIX RSS_SUFFIX
70
 #define MODULENAME "r8168"
71
 #define PFX MODULENAME ": "
72
 
73
 #define GPL_CLAIM "\
74
-r8168  Copyright (C) 2022 Realtek NIC software team <nicfae@realtek.com> \n \
75
+r8168  Copyright (C) 2023 Realtek NIC software team <nicfae@realtek.com> \n \
76
 This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>. \n \
77
 This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>. \n"
78
 
79
@@ -428,6 +448,8 @@
80
 #define R8168_PCI_REGS_SIZE    (0x100)
81
 #define R8168_NAPI_WEIGHT   64
82
 
83
+#define R8168_MAX_MSIX_VEC   4
84
+
85
 #define RTL8168_TX_TIMEOUT  (6 * HZ)
86
 #define RTL8168_LINK_TIMEOUT    (1 * HZ)
87
 #define RTL8168_ESD_TIMEOUT (2 * HZ)
88
@@ -438,10 +460,17 @@
89
 #define MIN_NUM_TX_DESC 32    /* Minimum number of Tx descriptor registers */
90
 #define MIN_NUM_RX_DESC 32    /* Minimum number of Rx descriptor registers */
91
 
92
-#define NUM_TX_DESC 256    /* Number of Tx descriptor registers */
93
-#define NUM_RX_DESC 256    /* Number of Rx descriptor registers */
94
+#define NUM_TX_DESC 1024    /* Number of Tx descriptor registers */
95
+#define NUM_RX_DESC 1024    /* Number of Rx descriptor registers */
96
 
97
-#define RX_BUF_SIZE 0x05F3  /* 0x05F3 = 1522bye + 1 */
98
+#define RX_BUF_SIZE 0x05F2  /* 0x05F2 = 1522bye */
99
+#define R8168_MAX_TX_QUEUES (2)
100
+#define R8168_MAX_RX_QUEUES (4)
101
+#define R8168_MAX_QUEUES R8168_MAX_RX_QUEUES
102
+#define R8168_MULTI_TX_Q(tp) (rtl8168_tot_tx_rings(tp) > 1)
103
+#define R8168_MULTI_RX_Q(tp) (rtl8168_tot_rx_rings(tp) > 1)
104
+#define R8168_MULTI_RX_4Q(tp) (rtl8168_tot_rx_rings(tp) > 3)
105
+#define R8168_MULTI_RSS_4Q(tp) (tp->num_hw_tot_en_rx_rings > 3)
106
 
107
 #define OCP_STD_PHY_BASE   0xa400
108
 
109
@@ -566,7 +595,11 @@
110
 typedef struct napi_struct *napi_ptr;
111
 typedef int napi_budget;
112
 
113
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0)
114
+#define RTL_NAPI_CONFIG(ndev, priv, function, weight)   netif_napi_add_weight(ndev, &priv->napi, function, weight)
115
+#else
116
 #define RTL_NAPI_CONFIG(ndev, priv, function, weight)   netif_napi_add(ndev, &priv->napi, function, weight)
117
+#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0)
118
 #define RTL_NAPI_QUOTA(budget, ndev)            min(budget, budget)
119
 #define RTL_GET_PRIV(stuct_ptr, priv_struct)        container_of(stuct_ptr, priv_struct, stuct_ptr)
120
 #define RTL_GET_NETDEV(priv_ptr)            struct net_device *dev = priv_ptr->dev;
121
@@ -1095,13 +1128,20 @@
122
         ERIAR           = 0x74,
123
         EPHY_RXER_NUM   = 0x7C,
124
         EPHYAR          = 0x80,
125
+        IntrMask1       = 0x84,
126
+        IntrMask2       = 0x85,
127
+        IntrStatus1     = 0x86,
128
+        IntrStatus2     = 0x87,
129
         TimeInt2        = 0x8C,
130
+        Rss_indir_tbl   = 0x90,
131
         OCPDR           = 0xB0,
132
         MACOCP          = 0xB0,
133
         OCPAR           = 0xB4,
134
         SecMAC0         = 0xB4,
135
         SecMAC4         = 0xB8,
136
         PHYOCP          = 0xB8,
137
+        IntrMask3       = 0xC0,
138
+        IntrStatus3     = 0xC1,
139
         DBG_reg         = 0xD1,
140
         TwiCmdReg       = 0xD2,
141
         MCUCmd_reg      = 0xD3,
142
@@ -1122,6 +1162,14 @@
143
         CMAC_IBIMR0     = 0xFA,
144
         CMAC_IBISR0     = 0xFB,
145
         FuncForceEvent  = 0xFC,
146
+
147
+        /* ERI */
148
+        RSS_KEY_8168    = 0x90,
149
+        RSS_CTRL_8168   = 0xB8,
150
+        Q_NUM_CTRL_8168 = 0xC0,
151
+
152
+        /* MAC OCP */
153
+        EEE_TXIDLE_TIMER_8168   = 0xe048,
154
 };
155
 
156
 enum RTL8168_register_content {
157
@@ -1137,6 +1185,8 @@
158
         TxOK        = 0x0004,
159
         RxErr       = 0x0002,
160
         RxOK        = 0x0001,
161
+        RxDU1       = 0x0002,
162
+        RxOK1       = 0x0001,
163
 
164
         /* RxStatusDesc */
165
         RxRWT = (1 << 22),
166
@@ -1181,6 +1231,7 @@
167
         RxCfg_fet_multi_en = (1 << 14),
168
         RxCfg_half_refetch = (1 << 13),
169
         RxCfg_9356SEL = (1 << 6),
170
+        RxCfg_rx_desc_v2_en = (1 << 24),
171
 
172
         /* TxConfigBits */
173
         TxInterFrameGapShift = 24,
174
@@ -1435,6 +1486,17 @@
175
         BIT_31 = (1 << 31)
176
 };
177
 
178
+#define RTL8168_CP_NUM 4
179
+#define RTL8168_MAX_SUPPORT_cp_len 110
180
+
181
+enum rtl8168_cp_status {
182
+        rtl8168_cp_normal = 0,
183
+        rtl8168_cp_short,
184
+        rtl8168_cp_open,
185
+        rtl8168_cp_mismatch,
186
+        rtl8168_cp_unknown
187
+};
188
+
189
 enum effuse {
190
         EFUSE_NOT_SUPPORT = 0,
191
         EFUSE_SUPPORT_V1,
192
@@ -1455,6 +1517,29 @@
193
         u64 addr;
194
 };
195
 
196
+struct RxDescV2 {
197
+        u32 opts1;
198
+        u32 opts2;
199
+        u64 addr;
200
+        u32 rsvd1;
201
+        u32 RSSResult;
202
+        u64 rsvd2;
203
+};
204
+
205
+//Rx Desc Type
206
+enum rx_desc_ring_type {
207
+        RX_DESC_RING_TYPE_UNKNOWN=0,
208
+        RX_DESC_RING_TYPE_1,
209
+        RX_DESC_RING_TYPE_2,
210
+        RX_DESC_RING_TYPE_3,
211
+        RX_DESC_RING_TYPE_MAX
212
+};
213
+
214
+enum rx_desc_len {
215
+        RX_DESC_LEN_TYPE_1 = (sizeof(struct RxDesc)),
216
+        RX_DESC_LEN_TYPE_2 = (sizeof(struct RxDescV2))
217
+};
218
+
219
 struct ring_info {
220
         struct sk_buff  *skb;
221
         u32     len;
222
@@ -1481,6 +1566,14 @@
223
         u32 pci_sn_h;
224
 };
225
 
226
+enum r8168_flag {
227
+        R8168_FLAG_DOWN = 0,
228
+        R8168_FLAG_TASK_RESET_PENDING,
229
+        R8168_FLAG_TASK_ESD_CHECK_PENDING,
230
+        R8168_FLAG_TASK_LINKCHG_CHECK_PENDING,
231
+        R8168_FLAG_MAX
232
+};
233
+
234
 /* Flow Control Settings */
235
 enum rtl8168_fc_mode {
236
         rtl8168_fc_none = 0,
237
@@ -1490,17 +1583,222 @@
238
         rtl8168_fc_default
239
 };
240
 
241
-struct rtl8168_private {
242
-        void __iomem *mmio_addr;    /* memory map physical address */
243
-        struct pci_dev *pci_dev;    /* Index of PCI device */
244
-        struct net_device *dev;
245
+struct rtl8168_tx_ring {
246
+        void* priv;
247
+        u32 index;
248
+        u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
249
+        u32 dirty_tx;
250
+        u32 num_tx_desc; /* Number of Tx descriptor registers */
251
+        u32 tdu; /* Tx descriptor unavailable count */
252
+        struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
253
+        dma_addr_t TxPhyAddr;
254
+        u32 TxDescAllocSize;
255
+        struct ring_info tx_skbNUM_TX_DESC; /* Tx data buffers */
256
+
257
+        u16 tdsar_reg; /* Transmit Descriptor Start Address */
258
+};
259
+
260
+struct rtl8168_rx_ring {
261
+        void* priv;
262
+        u32 index;
263
+        u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
264
+        u32 dirty_rx;
265
+        u32 rdu; /* Rx descriptor unavailable count */
266
+        //struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
267
+        //u32 RxDescAllocSize;
268
+        u64 RxDescPhyAddrMAX_NUM_RX_DESC; /* Rx desc physical address*/
269
+        //dma_addr_t RxPhyAddr;
270
+        struct sk_buff *Rx_skbuffMAX_NUM_RX_DESC; /* Rx data buffers */
271
+
272
+        //u16 rdsar_reg; /* Receive Descriptor Start Address */
273
+};
274
+
275
+struct r8168_napi {
276
 #ifdef CONFIG_R8168_NAPI
277
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
278
         struct napi_struct napi;
279
 #endif
280
 #endif
281
+        void* priv;
282
+        int index;
283
+};
284
+
285
+struct r8168_irq {
286
+        irq_handler_t  handler;
287
+        unsigned int   vector;
288
+        u8     requested;
289
+        char       nameIFNAMSIZ + 10;
290
+};
291
+
292
+#pragma pack(1)
293
+struct rtl8168_regs {
294
+        //00
295
+        u8 mac_id6;
296
+        u16 reg_06;
297
+        u8 mar8;
298
+        //10
299
+        u64 dtccr;
300
+        u16 ledsel0;
301
+        u16 legreg;
302
+        u32 tctr3;
303
+        //20
304
+        u32 txq0_dsc_st_addr_0;
305
+        u32 txq0_dsc_st_addr_2;
306
+        u64 reg_28;
307
+        //30
308
+        u16 rit;
309
+        u16 ritc;
310
+        u16 reg_34;
311
+        u8 reg_36;
312
+        u8 command;
313
+        u32 imr0;
314
+        u32 isr0;
315
+        //40
316
+        u32 tcr;
317
+        u32 rcr;
318
+        u32 tctr0;
319
+        u32 tctr1;
320
+        //50
321
+        u8 cr93c46;
322
+        u8 config0;
323
+        u8 config1;
324
+        u8 config2;
325
+        u8 config3;
326
+        u8 config4;
327
+        u8 config5;
328
+        u8 tdfnr;
329
+        u32 timer_int0;
330
+        u32 timer_int1;
331
+        //60
332
+        u32 gphy_mdcmdio;
333
+        u32 csidr;
334
+        u32 csiar;
335
+        u16 phy_status;
336
+        u8 config6;
337
+        u8 pmch;
338
+        //70
339
+        u32 eridr;
340
+        u32 eriar;
341
+        u16 config7;
342
+        u16 reg_7a;
343
+        u32 ephy_rxerr_cnt;
344
+        //80
345
+        u32 ephy_mdcmdio;
346
+        u16 ledsel2;
347
+        u16 ledsel1;
348
+        u32 tctr2;
349
+        u32 timer_int2;
350
+        //90
351
+        u8 tppoll0;
352
+        u8 reg_91;
353
+        u16 reg_92;
354
+        u16 led_feature;
355
+        u16 ledsel3;
356
+        u16 eee_led_config;
357
+        u16 reg_9a;
358
+        u32 reg_9c;
359
+        //a0
360
+        u32 reg_a0;
361
+        u32 reg_a4;
362
+        u32 reg_a8;
363
+        u32 reg_ac;
364
+        //b0
365
+        u32 patch_dbg;
366
+        u32 reg_b4;
367
+        u32 gphy_ocp;
368
+        u32 reg_bc;
369
+        //c0
370
+        u32 reg_c0;
371
+        u32 reg_c4;
372
+        u32 reg_c8;
373
+        u16 otp_cmd;
374
+        u16 otp_pg_config;
375
+        //d0
376
+        u16 phy_pwr;
377
+        u8 twsi_ctrl;
378
+        u8 oob_ctrl;
379
+        u16 mac_dbgo;
380
+        u16 mac_dbg;
381
+        u16 reg_d8;
382
+        u16 rms;
383
+        u32 efuse_data;
384
+        //e0
385
+        u16 cplus_cmd;
386
+        u16 reg_e2;
387
+        u32 rxq0_dsc_st_addr_0;
388
+        u32 rxq0_dsc_st_addr_2;
389
+        u16 reg_ec;
390
+        u16 tx10midle_cnt;
391
+        //f0
392
+        u16 misc0;
393
+        u16 misc1;
394
+        u32 timer_int3;
395
+        u32 cmac_ib;
396
+        u16 reg_fc;
397
+        u16 sw_rst;
398
+};
399
+#pragma pack()
400
+
401
+struct rtl8168_regs_save {
402
+        union {
403
+                u8 mac_ioR8168_MAC_REGS_SIZE;
404
+
405
+                struct rtl8168_regs mac_reg;
406
+        };
407
+        u16 pcie_phyR8168_EPHY_REGS_SIZE/2;
408
+        u16 eth_phyR8168_PHY_REGS_SIZE/2;
409
+        u32 eri_regR8168_ERI_REGS_SIZE/4;
410
+        u32 pci_regR8168_PCI_REGS_SIZE/4;
411
+
412
+        //ktime_t begin_ktime;
413
+        //ktime_t end_ktime;
414
+        //u64 duration_ns;
415
+
416
+
417
+        u16 int_miti_rxq0;
418
+
419
+        u8 int_config;
420
+        u32 imr_new;
421
+        u32 isr_new;
422
+
423
+        u8 tdu_status;
424
+        u16 rdu_status;
425
+
426
+        u32 rss_ctrl;
427
+        u8 rss_keyRTL8168_RSS_KEY_SIZE;
428
+        u8 rss_i_tableRTL8168_MAX_INDIRECTION_TABLE_ENTRIES;
429
+        u16 rss_queue_num_sel_r;
430
+};
431
+
432
+struct rtl8168_counters {
433
+        /* legacy */
434
+        u64 tx_packets;
435
+        u64 rx_packets;
436
+        u64 tx_errors;
437
+        u32 rx_errors;
438
+        u16 rx_missed;
439
+        u16 align_errors;
440
+        u32 tx_one_collision;
441
+        u32 tx_multi_collision;
442
+        u64 rx_unicast;
443
+        u64 rx_broadcast;
444
+        u32 rx_multicast;
445
+        u16 tx_aborted;
446
+        u16 tx_underrun;
447
+};
448
+
449
+struct rtl8168_private {
450
+        void __iomem *mmio_addr;    /* memory map physical address */
451
+        struct pci_dev *pci_dev;    /* Index of PCI device */
452
+        struct pci_dev *pdev_cmac;  /* Index of PCI device */
453
+        struct net_device *dev;
454
+        struct r8168_napi r8168napiR8168_MAX_MSIX_VEC;
455
+        struct r8168_irq irq_tblR8168_MAX_MSIX_VEC;
456
+        unsigned int irq_nvecs;
457
+        unsigned int max_irq_nvecs;
458
+        unsigned int min_irq_nvecs;
459
+        unsigned int hw_supp_irq_nvecs;
460
         struct net_device_stats stats;  /* statistics of net device */
461
-        spinlock_t lock;        /* spin lock flag */
462
         u32 msg_enable;
463
         u32 tx_tcp_csum_cmd;
464
         u32 tx_udp_csum_cmd;
465
@@ -1509,23 +1807,35 @@
466
         int max_jumbo_frame_size;
467
         int chipset;
468
         u32 mcfg;
469
-        u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
470
-        u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
471
-        u32 dirty_rx;
472
-        u32 dirty_tx;
473
+        //u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
474
+        // u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
475
+        //u32 dirty_rx;
476
+        //u32 dirty_tx;
477
         u32 num_rx_desc; /* Number of Rx descriptor registers */
478
-        u32 num_tx_desc; /* Number of Tx descriptor registers */
479
-        struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
480
+        //u32 num_tx_desc; /* Number of Tx descriptor registers */
481
+        //struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
482
         struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
483
-        dma_addr_t TxPhyAddr;
484
+        //dma_addr_t TxPhyAddr;
485
         dma_addr_t RxPhyAddr;
486
-        u32 TxDescAllocSize;
487
+        //u32 TxDescAllocSize;
488
         u32 RxDescAllocSize;
489
-        struct sk_buff *Rx_skbuffMAX_NUM_RX_DESC; /* Rx data buffers */
490
-        struct ring_info tx_skbMAX_NUM_TX_DESC;   /* Tx data buffers */
491
+        //struct sk_buff *Rx_skbuffMAX_NUM_RX_DESC; /* Rx data buffers */
492
+        //struct ring_info tx_skbMAX_NUM_TX_DESC;   /* Tx data buffers */
493
         unsigned rx_buf_sz;
494
-        struct timer_list esd_timer;
495
-        struct timer_list link_timer;
496
+        u16 HwSuppNumTxQueues; // Number of tx ring that hardware can support
497
+        u16 HwSuppNumRxQueues; // Number of rx ring that hardware can support
498
+        unsigned int num_tx_rings; // Number of tx ring that non-ring-lib driver used
499
+        unsigned int num_rx_rings; // Number of rx ring that non-ring-lib driver used
500
+        struct rtl8168_tx_ring tx_ringR8168_MAX_TX_QUEUES; // non-ring-lib tx ring
501
+        struct rtl8168_rx_ring rx_ringR8168_MAX_RX_QUEUES; // non-ring-lib rx ring
502
+#ifdef ENABLE_LIB_SUPPORT
503
+        struct blocking_notifier_head lib_nh;
504
+        struct rtl8168_ring lib_tx_ringR8168_MAX_TX_QUEUES; // ring-lib tx ring
505
+        struct rtl8168_ring lib_rx_ringR8168_MAX_RX_QUEUES; // ring-lib rx ring
506
+#endif
507
+        u16 num_hw_tot_en_rx_rings; // Number of rx ring that hardware enabled
508
+        //struct timer_list esd_timer;
509
+        //struct timer_list link_timer;
510
         struct pci_resource pci_cfg_space;
511
         unsigned int esd_flag;
512
         unsigned int pci_cfg_is_read;
513
@@ -1533,7 +1843,8 @@
514
         u16 cp_cmd;
515
         u16 intr_mask;
516
         u16 timer_intr_mask;
517
-        int irq;
518
+        u16 isr_regR8168_MAX_MSIX_VEC;
519
+        u16 imr_regR8168_MAX_MSIX_VEC;
520
         int phy_auto_nego_reg;
521
         int phy_1000_ctrl_reg;
522
         u8 org_mac_addrNODE_ADDRESS_SIZE;
523
@@ -1566,10 +1877,15 @@
524
         unsigned int (*phy_reset_pending)(struct net_device *);
525
         unsigned int (*link_ok)(struct net_device *);
526
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
527
-        struct work_struct task;
528
+        struct work_struct reset_task;
529
+        struct work_struct esd_task;
530
+        struct work_struct linkchg_task;
531
 #else
532
-        struct delayed_work task;
533
+        struct delayed_work reset_task;
534
+        struct delayed_work esd_task;
535
+        struct delayed_work linkchg_task;
536
 #endif
537
+        DECLARE_BITMAP(task_flags, R8168_FLAG_MAX);
538
         unsigned features;
539
 
540
         u8 org_pci_offset_99;
541
@@ -1640,6 +1956,8 @@
542
         u16 BackupPhyFuseDout_47_32;
543
         u16 BackupPhyFuseDout_63_48;
544
 
545
+        u8 ring_lib_enabled;
546
+
547
         const char *fw_name;
548
         struct rtl8168_fw *rtl_fw;
549
         u32 ocp_base;
550
@@ -1649,7 +1967,6 @@
551
         u8 DASH;
552
         u8 dash_printer_enabled;
553
         u8 HwPkgDet;
554
-        void __iomem *mapped_cmac_ioaddr; /* mapped cmac memory map physical address */
555
         void __iomem *cmac_ioaddr; /* cmac memory map physical address */
556
 
557
 #ifdef ENABLE_DASH_SUPPORT
558
@@ -1725,8 +2042,7 @@
559
         //Realwow--------------
560
 #endif //ENABLE_REALWOW_SUPPORT
561
 
562
-        u32 eee_adv_t;
563
-        u8 eee_enabled;
564
+        struct ethtool_eee eee;
565
 
566
         u32 dynamic_aspm_packet_count;
567
 
568
@@ -1734,8 +2050,132 @@
569
         //Procfs support
570
         struct proc_dir_entry *proc_dir;
571
 #endif
572
+        u8 HwSuppRxDescType;
573
+        u8 InitRxDescType;
574
+        u16 RxDescLength; //V1 16 Byte V2 32 Bytes
575
+
576
+        u8 HwSuppRssVer;
577
+        u8 EnableRss;
578
+        u16 HwSuppIndirTblEntries;
579
+#ifdef ENABLE_RSS_SUPPORT
580
+        u32 rss_flags;
581
+        /* Receive Side Scaling settings */
582
+#define RTL8168_RSS_KEY_SIZE     40  /* size of RSS Hash Key in bytes */
583
+        u8 rss_keyRTL8168_RSS_KEY_SIZE;
584
+#define RTL8168_MAX_INDIRECTION_TABLE_ENTRIES 128
585
+        u8 rss_indir_tblRTL8168_MAX_INDIRECTION_TABLE_ENTRIES;
586
+        u32 rss_options;
587
+#endif
588
+        u32 rx_fifo_of; /* Rx fifo overflow count */
589
 };
590
 
591
+#ifdef ENABLE_LIB_SUPPORT
592
+static inline unsigned int
593
+rtl8168_num_lib_tx_rings(struct rtl8168_private *tp)
594
+{
595
+        int count, i;
596
+
597
+        for (count = 0, i = tp->num_tx_rings; i < tp->HwSuppNumTxQueues; i++)
598
+                if(tp->lib_tx_ringi.enabled)
599
+                        count++;
600
+
601
+        return count;
602
+}
603
+
604
+static inline unsigned int
605
+rtl8168_num_lib_rx_rings(struct rtl8168_private *tp)
606
+{
607
+        int count, i;
608
+
609
+        for (count = 0, i = tp->num_rx_rings; i < tp->HwSuppNumRxQueues; i++)
610
+                if(tp->lib_rx_ringi.enabled)
611
+                        count++;
612
+
613
+        return count;
614
+}
615
+
616
+static inline bool
617
+rtl8168_lib_tx_ring_released(struct rtl8168_private *tp)
618
+{
619
+        int i;
620
+        bool released = 0;
621
+
622
+        for (i = tp->num_tx_rings; i < tp->HwSuppNumTxQueues; i++) {
623
+                struct rtl8168_ring *ring = &tp->lib_tx_ringi;
624
+                if (ring->allocated)
625
+                        goto exit;
626
+        }
627
+
628
+        released = 1;
629
+
630
+exit:
631
+        return released;
632
+}
633
+
634
+static inline bool
635
+rtl8168_lib_rx_ring_released(struct rtl8168_private *tp)
636
+{
637
+        int i;
638
+        bool released = 0;
639
+
640
+        for (i = tp->num_rx_rings; i < tp->HwSuppNumRxQueues; i++) {
641
+                struct rtl8168_ring *ring = &tp->lib_rx_ringi;
642
+                if (ring->allocated)
643
+                        goto exit;
644
+        }
645
+
646
+        released = 1;
647
+
648
+exit:
649
+        return released;
650
+}
651
+
652
+#else
653
+
654
+static inline unsigned int
655
+rtl8168_num_lib_tx_rings(struct rtl8168_private *tp)
656
+{
657
+        return 0;
658
+}
659
+
660
+static inline unsigned int
661
+rtl8168_num_lib_rx_rings(struct rtl8168_private *tp)
662
+{
663
+        return 0;
664
+}
665
+
666
+static inline bool
667
+rtl8168_lib_tx_ring_released(struct rtl8168_private *tp)
668
+{
669
+        return 1;
670
+}
671
+
672
+static inline bool
673
+rtl8168_lib_rx_ring_released(struct rtl8168_private *tp)
674
+{
675
+        return 1;
676
+}
677
+#endif
678
+
679
+static inline unsigned int
680
+rtl8168_tot_tx_rings(struct rtl8168_private *tp)
681
+{
682
+        return tp->num_tx_rings + rtl8168_num_lib_tx_rings(tp);
683
+}
684
+
685
+static inline unsigned int
686
+rtl8168_tot_rx_rings(struct rtl8168_private *tp)
687
+{
688
+        return tp->num_rx_rings + rtl8168_num_lib_rx_rings(tp);
689
+}
690
+
691
+static inline bool
692
+rtl8168_lib_all_ring_released(struct rtl8168_private *tp)
693
+{
694
+        return (rtl8168_lib_tx_ring_released(tp) &&
695
+                rtl8168_lib_rx_ring_released(tp));
696
+}
697
+
698
 enum eetype {
699
         EEPROM_TYPE_NONE=0,
700
         EEPROM_TYPE_93C46,
701
@@ -1779,6 +2219,8 @@
702
         CFG_METHOD_33,
703
         CFG_METHOD_34,
704
         CFG_METHOD_35,
705
+        CFG_METHOD_36,
706
+        CFG_METHOD_37,
707
         CFG_METHOD_MAX,
708
         CFG_METHOD_DEFAULT = 0xFF
709
 };
710
@@ -1817,14 +2259,17 @@
711
 #define NIC_RAMCODE_VERSION_CFG_METHOD_23 (0x0015)
712
 #define NIC_RAMCODE_VERSION_CFG_METHOD_26 (0x0012)
713
 #define NIC_RAMCODE_VERSION_CFG_METHOD_28 (0x0019)
714
-#define NIC_RAMCODE_VERSION_CFG_METHOD_29 (0x0055)
715
+#define NIC_RAMCODE_VERSION_CFG_METHOD_29 (0x0083)
716
 #define NIC_RAMCODE_VERSION_CFG_METHOD_31 (0x0003)
717
-#define NIC_RAMCODE_VERSION_CFG_METHOD_35 (0x0019)
718
+#define NIC_RAMCODE_VERSION_CFG_METHOD_35 (0x0027)
719
+#define NIC_RAMCODE_VERSION_CFG_METHOD_36 (0x0000)
720
 
721
 //hwoptimize
722
 #define HW_PATCH_SOC_LAN (BIT_0)
723
 #define HW_PATCH_SAMSUNG_LAN_DONGLE (BIT_2)
724
 
725
+static const u8 other_q_intr_mask = (RxOK1 | RxDU1);
726
+
727
 #define HW_PHY_STATUS_INI       1
728
 #define HW_PHY_STATUS_EXT_INI   2
729
 #define HW_PHY_STATUS_LAN_ON    3
730
@@ -1862,11 +2307,84 @@
731
 void rtl8168_dash2_disable_rx(struct rtl8168_private *tp);
732
 void rtl8168_dash2_enable_rx(struct rtl8168_private *tp);
733
 void rtl8168_hw_disable_mac_mcu_bps(struct net_device *dev);
734
+void rtl8168_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz);
735
+
736
+static inline struct RxDesc*
737
+rtl8168_get_rxdesc(struct rtl8168_private *tp, struct RxDesc *RxDescBase, u32 const cur_rx, u32 const q_num)
738
+{
739
+        u8 *desc = (u8*)RxDescBase;
740
+        u32 offset;
741
+
742
+        WARN_ON_ONCE(q_num >= tp->num_hw_tot_en_rx_rings);
743
+
744
+        if (tp->InitRxDescType == RX_DESC_RING_TYPE_2)
745
+                offset = (cur_rx * tp->num_hw_tot_en_rx_rings) + q_num;
746
+        else
747
+                offset = cur_rx;
748
+
749
+        offset *= tp->RxDescLength;
750
+        desc += offset;
751
+
752
+        return (struct RxDesc*)desc;
753
+}
754
+
755
+static inline void
756
+rtl8168_disable_interrupt_by_vector(struct rtl8168_private *tp,
757
+                                    u32 message_id)
758
+{
759
+        if (message_id >= R8168_MAX_MSIX_VEC)
760
+                return;
761
+
762
+        if (message_id == 0) {
763
+                RTL_W16(tp, tp->imr_reg0, 0x0000);
764
+#ifdef ENABLE_DASH_SUPPORT
765
+                if (tp->DASH)
766
+                        rtl8168_disable_dash2_interrupt(tp);
767
+#endif
768
+        } else
769
+                RTL_W8(tp, tp->imr_regmessage_id, 0x00);
770
+}
771
+
772
+static inline void
773
+rtl8168_enable_interrupt_by_vector(struct rtl8168_private *tp,
774
+                                   u32 message_id)
775
+{
776
+        if (message_id >= R8168_MAX_MSIX_VEC)
777
+                return;
778
+
779
+        if (message_id == 0) {
780
+                RTL_W16(tp, tp->imr_reg0, tp->intr_mask);
781
+#ifdef ENABLE_DASH_SUPPORT
782
+                if (tp->DASH)
783
+                        rtl8168_enable_dash2_interrupt(tp);
784
+#endif
785
+        } else {
786
+                RTL_W8(tp, tp->imr_regmessage_id, other_q_intr_mask);
787
+        }
788
+}
789
+
790
+int rtl8168_open(struct net_device *dev);
791
+int rtl8168_close(struct net_device *dev);
792
+void rtl8168_hw_config(struct net_device *dev);
793
+void rtl8168_hw_start(struct net_device *dev);
794
+void rtl8168_hw_reset(struct net_device *dev);
795
+void rtl8168_tx_clear(struct rtl8168_private *tp);
796
+void rtl8168_rx_clear(struct rtl8168_private *tp);
797
+int rtl8168_init_ring(struct net_device *dev);
798
+int rtl8168_dump_tally_counter(struct rtl8168_private *tp, dma_addr_t paddr);
799
+void rtl8168_enable_napi(struct rtl8168_private *tp);
800
+void _rtl8168_wait_for_quiescence(struct net_device *dev);
801
+
802
+#ifndef ENABLE_LIB_SUPPORT
803
+static inline void rtl8168_lib_reset_prepare(struct rtl8168_private *tp) { }
804
+static inline void rtl8168_lib_reset_complete(struct rtl8168_private *tp) { }
805
+#endif
806
 
807
 #define HW_SUPPORT_CHECK_PHY_DISABLE_MODE(_M)        ((_M)->HwSuppCheckPhyDisableModeVer > 0 )
808
 #define HW_SUPP_SERDES_PHY(_M)        ((_M)->HwSuppSerDesPhyVer > 0)
809
 #define HW_HAS_WRITE_PHY_MCU_RAM_CODE(_M)        (((_M)->HwHasWrRamCodeToMicroP == TRUE) ? 1 : 0)
810
 #define HW_SUPPORT_UPS_MODE(_M)        ((_M)->HwSuppUpsVer > 0)
811
+#define HW_RSS_SUPPORT_RSS(_M)        ((_M)->HwSuppRssVer > 0)
812
 
813
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
814
 #define netdev_mc_count(dev) ((dev)->mc_count)
815
r8168-8.051.02.tar.gz/src/r8168_asf.c -> r8168-8.052.01.tar.gz/src/r8168_asf.c Changed
40
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
@@ -60,7 +60,6 @@
11
         struct rtl8168_private *tp = netdev_priv(dev);
12
         void *user_data = ifr->ifr_data;
13
         struct asf_ioctl_struct asf_usrdata;
14
-        unsigned long flags;
15
 
16
         if (tp->mcfg != CFG_METHOD_7 && tp->mcfg != CFG_METHOD_8)
17
                 return -EOPNOTSUPP;
18
@@ -68,8 +67,6 @@
19
         if (copy_from_user(&asf_usrdata, user_data, sizeof(struct asf_ioctl_struct)))
20
                 return -EFAULT;
21
 
22
-        spin_lock_irqsave(&tp->lock, flags);
23
-
24
         switch (asf_usrdata.offset) {
25
         case HBPeriod:
26
                 rtl8168_asf_hbperiod(tp, asf_usrdata.arg, asf_usrdata.u.data);
27
@@ -192,12 +189,9 @@
28
                 rtl8168_asf_key_access(tp, asf_usrdata.arg, KR, asf_usrdata.u.data);
29
                 break;
30
         default:
31
-                spin_unlock_irqrestore(&tp->lock, flags);
32
                 return -EOPNOTSUPP;
33
         }
34
 
35
-        spin_unlock_irqrestore(&tp->lock, flags);
36
-
37
         if (copy_to_user(user_data, &asf_usrdata, sizeof(struct asf_ioctl_struct)))
38
                 return -EFAULT;
39
 
40
r8168-8.051.02.tar.gz/src/r8168_asf.h -> r8168-8.052.01.tar.gz/src/r8168_asf.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168_dash.h -> r8168-8.052.01.tar.gz/src/r8168_dash.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168_fiber.h -> r8168-8.052.01.tar.gz/src/r8168_fiber.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168_firmware.c -> r8168-8.052.01.tar.gz/src/r8168_firmware.c Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168_firmware.h -> r8168-8.052.01.tar.gz/src/r8168_firmware.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/r8168_n.c -> r8168-8.052.01.tar.gz/src/r8168_n.c Changed
7932
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
@@ -81,6 +81,10 @@
11
 #include <linux/mdio.h>
12
 #endif
13
 
14
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,10)
15
+#include <net/gso.h>
16
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,4,10) */
17
+
18
 #include <asm/io.h>
19
 #include <asm/irq.h>
20
 
21
@@ -113,6 +117,7 @@
22
 #define FIRMWARE_8168H_1    "rtl_nic/rtl8168h-1.fw"
23
 #define FIRMWARE_8168H_2    "rtl_nic/rtl8168h-2.fw"
24
 #define FIRMWARE_8168H_3    "rtl_nic/rtl8168h-3.fw"
25
+#define FIRMWARE_8168H_4    "rtl_nic/rtl8168h-4.fw"
26
 #define FIRMWARE_8168FP_3   "rtl_nic/rtl8168fp-3.fw"
27
 #define FIRMWARE_8168FP_4   "rtl_nic/rtl8168fp-4.fw"
28
 
29
@@ -160,6 +165,8 @@
30
         CFG_METHOD_33 = {"RTL8168FP/8111FP",      FIRMWARE_8168FP_4},
31
         CFG_METHOD_34 = {"RTL8168FP/8111FP",      FIRMWARE_8168FP_4},
32
         CFG_METHOD_35 = {"RTL8168H/8111H",        FIRMWARE_8168H_3},
33
+        CFG_METHOD_36 = {"RTL8168H/8111H",        FIRMWARE_8168H_4},
34
+        CFG_METHOD_37 = {"RTL8168M/8111M",        FIRMWARE_8168H_2},
35
         CFG_METHOD_DEFAULT = {"Unknown",          },
36
 };
37
 
38
@@ -295,91 +302,103 @@
39
 
40
         _R("RTL8168G/8111G",
41
         CFG_METHOD_21,
42
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
43
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
44
         0xff7e5880,
45
         Jumbo_Frame_9k),
46
 
47
         _R("RTL8168G/8111G",
48
         CFG_METHOD_22,
49
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
50
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
51
         0xff7e5880,
52
         Jumbo_Frame_9k),
53
 
54
         _R("RTL8168EP/8111EP",
55
         CFG_METHOD_23,
56
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
57
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
58
         0xff7e5880,
59
         Jumbo_Frame_9k),
60
 
61
         _R("RTL8168GU/8111GU",
62
         CFG_METHOD_24,
63
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
64
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
65
         0xff7e5880,
66
         Jumbo_Frame_9k),
67
 
68
         _R("RTL8168GU/8111GU",
69
         CFG_METHOD_25,
70
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
71
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
72
         0xff7e5880,
73
         Jumbo_Frame_9k),
74
 
75
         _R("8411B",
76
         CFG_METHOD_26,
77
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
78
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
79
         0xff7e5880,
80
         Jumbo_Frame_9k),
81
 
82
         _R("RTL8168EP/8111EP",
83
         CFG_METHOD_27,
84
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
85
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
86
         0xff7e5880,
87
         Jumbo_Frame_9k),
88
 
89
         _R("RTL8168EP/8111EP",
90
         CFG_METHOD_28,
91
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
92
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
93
         0xff7e5880,
94
         Jumbo_Frame_9k),
95
 
96
         _R("RTL8168H/8111H",
97
         CFG_METHOD_29,
98
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
99
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
100
         0xff7e5880,
101
         Jumbo_Frame_9k),
102
 
103
         _R("RTL8168H/8111H",
104
         CFG_METHOD_30,
105
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
106
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
107
         0xff7e5880,
108
         Jumbo_Frame_9k),
109
 
110
         _R("RTL8168FP/8111FP",
111
         CFG_METHOD_31,
112
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
113
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
114
         0xff7e5880,
115
         Jumbo_Frame_9k),
116
 
117
         _R("RTL8168FP/8111FP",
118
         CFG_METHOD_32,
119
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
120
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
121
         0xff7e5880,
122
         Jumbo_Frame_9k),
123
 
124
         _R("RTL8168FP/8111FP",
125
         CFG_METHOD_33,
126
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
127
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
128
         0xff7e5880,
129
         Jumbo_Frame_9k),
130
 
131
         _R("RTL8168FP/8111FP",
132
         CFG_METHOD_34,
133
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
134
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
135
         0xff7e5880,
136
         Jumbo_Frame_9k),
137
 
138
         _R("RTL8168H/8111H",
139
         CFG_METHOD_35,
140
-        RxCfg_128_int_en | RxEarly_off_V2 | Rx_Single_fetch_V2 | (RX_DMA_BURST << RxCfgDMAShift),
141
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
142
+        0xff7e5880,
143
+        Jumbo_Frame_9k),
144
+
145
+        _R("RTL8168H/8111H",
146
+        CFG_METHOD_36,
147
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
148
+        0xff7e5880,
149
+        Jumbo_Frame_9k),
150
+
151
+        _R("RTL8168M/8111M",
152
+        CFG_METHOD_37,
153
+        RxCfg_128_int_en | RxEarly_off_V2 | (RX_DMA_BURST << RxCfgDMAShift),
154
         0xff7e5880,
155
         Jumbo_Frame_9k),
156
 
157
@@ -406,7 +425,6 @@
158
 
159
 MODULE_DEVICE_TABLE(pci, rtl8168_pci_tbl);
160
 
161
-static int rx_copybreak = 0;
162
 static int use_dac = 1;
163
 static int timer_count = 0x2600;
164
 static int dynamic_aspm_packet_threshold = 10;
165
@@ -459,6 +477,11 @@
166
 #else
167
 static int s0_magic_packet = 0;
168
 #endif
169
+#ifdef DISABLE_WOL_SUPPORT
170
+static int disable_wol_support = 1;
171
+#else
172
+static int disable_wol_support = 0;
173
+#endif
174
 
175
 MODULE_AUTHOR("Realtek and the Linux r8168 crew <netdev@vger.kernel.org>");
176
 MODULE_DESCRIPTION("RealTek RTL-8168 Gigabit Ethernet driver");
177
@@ -487,9 +510,6 @@
178
 module_param(s5_keep_curr_mac, int, 0);
179
 MODULE_PARM_DESC(s5_keep_curr_mac, "Enable Shutdown Keep Current MAC Address.");
180
 
181
-module_param(rx_copybreak, int, 0);
182
-MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames");
183
-
184
 module_param(use_dac, int, 0);
185
 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
186
 
187
@@ -508,6 +528,9 @@
188
 module_param(dynamic_aspm_packet_threshold, int, 0);
189
 MODULE_PARM_DESC(dynamic_aspm_packet_threshold, "Dynamic ASPM packet threshold.");
190
 
191
+module_param(disable_wol_support, int, 0);
192
+MODULE_PARM_DESC(disable_wol_support, "Disable PM support.");
193
+
194
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
195
 module_param_named(debug, debug.msg_enable, int, 0);
196
 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
197
@@ -533,6 +556,7 @@
198
 MODULE_FIRMWARE(FIRMWARE_8168H_1);
199
 MODULE_FIRMWARE(FIRMWARE_8168H_2);
200
 MODULE_FIRMWARE(FIRMWARE_8168H_3);
201
+MODULE_FIRMWARE(FIRMWARE_8168H_4);
202
 MODULE_FIRMWARE(FIRMWARE_8168FP_3);
203
 MODULE_FIRMWARE(FIRMWARE_8168FP_4);
204
 #endif
205
@@ -542,6 +566,7 @@
206
 static void rtl8168_sleep_rx_enable(struct net_device *dev);
207
 static void rtl8168_dsm(struct net_device *dev, int dev_state);
208
 
209
+/*
210
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
211
 static void rtl8168_esd_timer(unsigned long __opaque);
212
 #else
213
@@ -552,10 +577,8 @@
214
 #else
215
 static void rtl8168_link_timer(struct timer_list *t);
216
 #endif
217
-static void rtl8168_tx_clear(struct rtl8168_private *tp);
218
-static void rtl8168_rx_clear(struct rtl8168_private *tp);
219
+*/
220
 
221
-static int rtl8168_open(struct net_device *dev);
222
 static netdev_tx_t rtl8168_start_xmit(struct sk_buff *skb, struct net_device *dev);
223
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
224
 static irqreturn_t rtl8168_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
225
@@ -563,10 +586,6 @@
226
 static irqreturn_t rtl8168_interrupt(int irq, void *dev_instance);
227
 #endif
228
 static void rtl8168_rx_desc_offset0_init(struct rtl8168_private *, int);
229
-static int rtl8168_init_ring(struct net_device *dev);
230
-static void rtl8168_hw_config(struct net_device *dev);
231
-static void rtl8168_hw_start(struct net_device *dev);
232
-static int rtl8168_close(struct net_device *dev);
233
 static void rtl8168_set_rx_mode(struct net_device *dev);
234
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
235
 static void rtl8168_tx_timeout(struct net_device *dev, unsigned int txqueue);
236
@@ -574,7 +593,17 @@
237
 static void rtl8168_tx_timeout(struct net_device *dev);
238
 #endif
239
 static struct net_device_stats *rtl8168_get_stats(struct net_device *dev);
240
-static int rtl8168_rx_interrupt(struct net_device *, struct rtl8168_private *, napi_budget);
241
+static int rtl8168_rx_interrupt(struct net_device *, struct rtl8168_private *, struct rtl8168_rx_ring *, napi_budget);
242
+#ifdef CONFIG_R8168_NAPI
243
+static int rtl8168_poll_msix_ring(napi_ptr napi, napi_budget budget);
244
+static int rtl8168_poll_msix_rx(napi_ptr napi, napi_budget budget);
245
+#endif
246
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
247
+static irqreturn_t rtl8168_interrupt_msix(int irq, void *dev_instance, struct pt_regs *regs);
248
+#else
249
+static irqreturn_t rtl8168_interrupt_msix(int irq, void *dev_instance);
250
+#endif
251
+static void rtl8168_wait_for_quiescence(struct net_device *dev);
252
 static int rtl8168_change_mtu(struct net_device *dev, int new_mtu);
253
 static void rtl8168_down(struct net_device *dev);
254
 
255
@@ -586,8 +615,6 @@
256
 
257
 static u16 rtl8168_get_hw_phy_mcu_code_ver(struct rtl8168_private *tp);
258
 
259
-static void rtl8168_hw_reset(struct net_device *dev);
260
-
261
 static void rtl8168_phy_power_up(struct net_device *dev);
262
 static void rtl8168_phy_power_down(struct net_device *dev);
263
 static int rtl8168_set_speed(struct net_device *dev, u8 autoneg, u32 speed, u8 duplex, u32 adv);
264
@@ -601,9 +628,18 @@
265
 
266
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
267
 static void rtl8168_reset_task(void *_data);
268
+static void rtl8168_esd_task(void *_data);
269
+static void rtl8168_linkchg_task(void *_data);
270
 #else
271
 static void rtl8168_reset_task(struct work_struct *work);
272
+static void rtl8168_esd_task(struct work_struct *work);
273
+static void rtl8168_linkchg_task(struct work_struct *work);
274
 #endif
275
+static void rtl8168_schedule_reset_work(struct rtl8168_private *tp);
276
+static void rtl8168_schedule_esd_work(struct rtl8168_private *tp);
277
+static void rtl8168_schedule_linkchg_work(struct rtl8168_private *tp);
278
+static void rtl8168_init_all_schedule_work(struct rtl8168_private *tp);
279
+static void rtl8168_cancel_all_schedule_work(struct rtl8168_private *tp);
280
 
281
 static inline struct device *tp_to_dev(struct rtl8168_private *tp)
282
 {
283
@@ -921,21 +957,206 @@
284
 }
285
 #endif  //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7)
286
 
287
-struct rtl8168_counters {
288
-        u64 tx_packets;
289
-        u64 rx_packets;
290
-        u64 tx_errors;
291
-        u32 rx_errors;
292
-        u16 rx_missed;
293
-        u16 align_errors;
294
-        u32 tx_one_collision;
295
-        u32 tx_multi_collision;
296
-        u64 rx_unicast;
297
-        u64 rx_broadcast;
298
-        u32 rx_multicast;
299
-        u16 tx_aborted;
300
-        u16 tx_underrun;
301
-};
302
+int rtl8168_dump_tally_counter(struct rtl8168_private *tp, dma_addr_t paddr)
303
+{
304
+        u32 cmd;
305
+        u32 WaitCnt;
306
+        int retval = -1;
307
+
308
+        RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
309
+        cmd = (u64)paddr & DMA_BIT_MASK(32);
310
+        RTL_W32(tp, CounterAddrLow, cmd);
311
+        RTL_W32(tp, CounterAddrLow, cmd | CounterDump);
312
+
313
+        WaitCnt = 0;
314
+        while (RTL_R32(tp, CounterAddrLow) & CounterDump) {
315
+                udelay(10);
316
+
317
+                WaitCnt++;
318
+                if (WaitCnt > 20)
319
+                        break;
320
+        }
321
+
322
+        if (WaitCnt <= 20)
323
+                retval = 0;
324
+
325
+        return retval;
326
+}
327
+
328
+static u32 rtl8168_convert_link_speed(u16 status)
329
+{
330
+        u32 speed = SPEED_UNKNOWN;
331
+
332
+        if (status & LinkStatus) {
333
+                if (status & _1000bpsF)
334
+                        speed = SPEED_1000;
335
+                else if (status & _100bps)
336
+                        speed = SPEED_100;
337
+                else if (status & _10bps)
338
+                        speed = SPEED_10;
339
+        }
340
+
341
+        return speed;
342
+}
343
+
344
+static int rtl8168_vcd_test(struct rtl8168_private *tp)
345
+{
346
+        u16 val;
347
+        u32 wait_cnt;
348
+        int ret = -1;
349
+
350
+        rtl8168_mdio_write(tp, 0x1f, 0x0a43);
351
+        rtl8168_mdio_write(tp, 0x13, 0x8169);
352
+        rtl8168_mdio_write(tp, 0x14, 0x18c1);
353
+        rtl8168_mdio_write(tp, 0x13, 0x816b);
354
+        rtl8168_mdio_write(tp, 0x14, 0xc7b0);
355
+        rtl8168_mdio_write(tp, 0x13, 0x816d);
356
+        rtl8168_mdio_write(tp, 0x14, 0x5933);
357
+        rtl8168_mdio_write(tp, 0x13, 0x816f);
358
+        rtl8168_mdio_write(tp, 0x14, 0xb920);
359
+        rtl8168_mdio_write(tp, 0x13, 0x8171);
360
+        rtl8168_mdio_write(tp, 0x14, 0xee07);
361
+        rtl8168_mdio_write(tp, 0x13, 0x8162);
362
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
363
+        rtl8168_mdio_write(tp, 0x13, 0x8173);
364
+        rtl8168_mdio_write(tp, 0x14, 0x0304);
365
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
366
+
367
+        rtl8168_mdio_write(tp, 0x1f, 0x0a42);
368
+        rtl8168_clear_eth_phy_bit(tp, 0x11, BIT(0));
369
+        rtl8168_set_eth_phy_bit(tp, 0x11, 0x00f0);
370
+        rtl8168_set_eth_phy_bit(tp, 0x11, BIT(0));
371
+
372
+        wait_cnt = 0;
373
+        do {
374
+                mdelay(1);
375
+                val = rtl8168_mdio_read(tp, 0x11);
376
+                wait_cnt++;
377
+        } while (!(val & BIT_15) && (wait_cnt < 5000));
378
+
379
+        if (wait_cnt == 5000)
380
+                goto exit;
381
+
382
+        ret = 0;
383
+
384
+exit:
385
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
386
+
387
+        return ret;
388
+}
389
+
390
+static void rtl8168_get_cp_len(struct rtl8168_private *tp,
391
+                               u16 cp_lenRTL8168_CP_NUM)
392
+{
393
+        int i;
394
+        u16 status;
395
+        u16 tmp_cp_len = 0;
396
+
397
+        status = RTL_R8(tp, PHYstatus);
398
+        if (status & LinkStatus) {
399
+                if (status & _10bps) {
400
+                        tmp_cp_len = 0;
401
+                } else if (status & _1000bpsF) {
402
+                        rtl8168_mdio_write(tp, 0x1f, 0x0a88);
403
+                        tmp_cp_len = rtl8168_mdio_read(tp, 0x10);
404
+                } else
405
+                        goto exit;
406
+        } else
407
+                goto exit;
408
+
409
+        tmp_cp_len &= 0xff;
410
+        for (i=0; i<RTL8168_CP_NUM; i++)
411
+                cp_leni = tmp_cp_len;
412
+
413
+exit:
414
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
415
+
416
+        for (i=0; i<RTL8168_CP_NUM; i++)
417
+                if (cp_leni > RTL8168_MAX_SUPPORT_cp_len)
418
+                        cp_leni = RTL8168_MAX_SUPPORT_cp_len;
419
+
420
+        return;
421
+}
422
+
423
+static int __rtl8168_get_cp_status(u16 val)
424
+{
425
+        switch (val) {
426
+        case 0x0060:
427
+                return rtl8168_cp_normal;
428
+        case 0x0048:
429
+                return rtl8168_cp_open;
430
+        case 0x0050:
431
+                return rtl8168_cp_short;
432
+        case 0x0042:
433
+        case 0x0044:
434
+                return rtl8168_cp_mismatch;
435
+        default:
436
+                return rtl8168_cp_normal;
437
+        }
438
+}
439
+
440
+static int _rtl8168_get_cp_status(struct rtl8168_private *tp, u8 pair_num)
441
+{
442
+        u16 val;
443
+        int cp_status = rtl8168_cp_unknown;
444
+
445
+        if (pair_num > 3)
446
+                goto exit;
447
+
448
+        rtl8168_mdio_write(tp, 0x1f, 0x0a43);
449
+        rtl8168_mdio_write(tp, 0x13, 0x802b + 4 * pair_num);
450
+        val = rtl8168_mdio_read(tp, 0x14);
451
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
452
+
453
+        cp_status = __rtl8168_get_cp_status(val);
454
+
455
+exit:
456
+        return cp_status;
457
+}
458
+
459
+static const char * rtl8168_get_cp_status_string(int cp_status)
460
+{
461
+        switch(cp_status) {
462
+        case rtl8168_cp_normal:
463
+                return "normal  ";
464
+        case rtl8168_cp_short:
465
+                return "short   ";
466
+        case rtl8168_cp_open:
467
+                return "open    ";
468
+        case rtl8168_cp_mismatch:
469
+                return "mismatch";
470
+        default:
471
+                return "unknown ";
472
+        }
473
+}
474
+
475
+static u16 rtl8168_get_cp_pp(struct rtl8168_private *tp, u8 pair_num)
476
+{
477
+        u16 pp = 0;
478
+
479
+        if (pair_num > 3)
480
+                goto exit;
481
+
482
+        rtl8168_mdio_write(tp, 0x1f, 0x0a43);
483
+        rtl8168_mdio_write(tp, 0x13, 0x802d + 4 * pair_num);
484
+        pp = rtl8168_mdio_read(tp, 0x14);
485
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
486
+
487
+        pp &= 0x3fff;
488
+        pp /= 80;
489
+
490
+exit:
491
+        return pp;
492
+}
493
+
494
+static void rtl8168_get_cp_status(struct rtl8168_private *tp,
495
+                                  int cp_statusRTL8168_CP_NUM)
496
+{
497
+        int i;
498
+
499
+        for (i =0; i<RTL8168_CP_NUM; i++)
500
+                cp_statusi = _rtl8168_get_cp_status(tp, i);
501
+}
502
 
503
 #ifdef ENABLE_R8168_PROCFS
504
 /****************************************************************************
505
@@ -951,23 +1172,38 @@
506
 {
507
         struct net_device *dev = m->private;
508
         struct rtl8168_private *tp = netdev_priv(dev);
509
-        unsigned long flags;
510
 
511
         seq_puts(m, "\nDump Driver Variable\n");
512
 
513
-        spin_lock_irqsave(&tp->lock, flags);
514
+        rtnl_lock();
515
+
516
         seq_puts(m, "Variable\tValue\n----------\t-----\n");
517
         seq_printf(m, "MODULENAME\t%s\n", MODULENAME);
518
         seq_printf(m, "driver version\t%s\n", RTL8168_VERSION);
519
         seq_printf(m, "chipset\t%d\n", tp->chipset);
520
         seq_printf(m, "chipset_name\t%s\n", rtl_chip_infotp->chipset.name);
521
         seq_printf(m, "mtu\t%d\n", dev->mtu);
522
-        seq_printf(m, "NUM_RX_DESC\t0x%x\n", tp->num_rx_desc);
523
-        seq_printf(m, "cur_rx\t0x%x\n", tp->cur_rx);
524
-        seq_printf(m, "dirty_rx\t0x%x\n", tp->dirty_rx);
525
-        seq_printf(m, "NUM_TX_DESC\t0x%x\n", tp->num_tx_desc);
526
-        seq_printf(m, "cur_tx\t0x%x\n", tp->cur_tx);
527
-        seq_printf(m, "dirty_tx\t0x%x\n", tp->dirty_tx);
528
+        seq_printf(m, "num_rx_desc\t0x%x\n", tp->num_rx_desc);
529
+        seq_printf(m, "cur_rx0\t0x%x\n", tp->rx_ring0.cur_rx);
530
+        seq_printf(m, "dirty_rx0\t0x%x\n", tp->rx_ring0.dirty_rx);
531
+        seq_printf(m, "rdu0\t0x%x\n", tp->rx_ring0.rdu);
532
+        seq_printf(m, "cur_rx1\t0x%x\n", tp->rx_ring1.cur_rx);
533
+        seq_printf(m, "dirty_rx1\t0x%x\n", tp->rx_ring1.dirty_rx);
534
+        seq_printf(m, "rdu1\t0x%x\n", tp->rx_ring1.rdu);
535
+        seq_printf(m, "cur_rx2\t0x%x\n", tp->rx_ring2.cur_rx);
536
+        seq_printf(m, "dirty_rx2\t0x%x\n", tp->rx_ring2.dirty_rx);
537
+        seq_printf(m, "rdu2\t0x%x\n", tp->rx_ring2.rdu);
538
+        seq_printf(m, "cur_rx3\t0x%x\n", tp->rx_ring3.cur_rx);
539
+        seq_printf(m, "dirty_rx3\t0x%x\n", tp->rx_ring3.dirty_rx);
540
+        seq_printf(m, "rdu3\t0x%x\n", tp->rx_ring3.rdu);
541
+        seq_printf(m, "rx_fifo_of\t0x%x\n", tp->rx_fifo_of);
542
+        seq_printf(m, "num_tx_desc\t0x%x\n", tp->tx_ring0.num_tx_desc);
543
+        seq_printf(m, "cur_tx0\t0x%x\n", tp->tx_ring0.cur_tx);
544
+        seq_printf(m, "dirty_tx0\t0x%x\n", tp->tx_ring0.dirty_tx);
545
+        seq_printf(m, "tdu0\t0x%x\n", tp->tx_ring0.tdu);
546
+        seq_printf(m, "cur_tx1\t0x%x\n", tp->tx_ring1.cur_tx);
547
+        seq_printf(m, "dirty_tx1\t0x%x\n", tp->tx_ring1.dirty_tx);
548
+        seq_printf(m, "tdu1\t0x%x\n", tp->tx_ring1.tdu);
549
         seq_printf(m, "rx_buf_sz\t0x%x\n", tp->rx_buf_sz);
550
         seq_printf(m, "esd_flag\t0x%x\n", tp->esd_flag);
551
         seq_printf(m, "pci_cfg_is_read\t0x%x\n", tp->pci_cfg_is_read);
552
@@ -1024,22 +1260,39 @@
553
         seq_printf(m, "aspm\t0x%x\n", aspm);
554
         seq_printf(m, "s5wol\t0x%x\n", s5wol);
555
         seq_printf(m, "s5_keep_curr_mac\t0x%x\n", s5_keep_curr_mac);
556
-        seq_printf(m, "eee_enable\t0x%x\n", tp->eee_enabled);
557
+        seq_printf(m, "eee_enable\t0x%x\n", tp->eee.eee_enabled);
558
         seq_printf(m, "hwoptimize\t0x%lx\n", hwoptimize);
559
         seq_printf(m, "proc_init_num\t0x%x\n", proc_init_num);
560
         seq_printf(m, "s0_magic_packet\t0x%x\n", s0_magic_packet);
561
+        seq_printf(m, "disable_wol_support\t0x%x\n", disable_wol_support);
562
         seq_printf(m, "HwSuppMagicPktVer\t0x%x\n", tp->HwSuppMagicPktVer);
563
         seq_printf(m, "HwSuppUpsVer\t0x%x\n", tp->HwSuppUpsVer);
564
         seq_printf(m, "HwSuppEsdVer\t0x%x\n", tp->HwSuppEsdVer);
565
         seq_printf(m, "HwSuppCheckPhyDisableModeVer\t0x%x\n", tp->HwSuppCheckPhyDisableModeVer);
566
         seq_printf(m, "HwPkgDet\t0x%x\n", tp->HwPkgDet);
567
+        seq_printf(m, "InitRxDescType\t0x%x\n", tp->InitRxDescType);
568
+        seq_printf(m, "RxDescLength\t0x%x\n", tp->RxDescLength);
569
+        seq_printf(m, "num_rx_rings\t0x%x\n", tp->num_rx_rings);
570
+        seq_printf(m, "num_tx_rings\t0x%x\n", tp->num_tx_rings);
571
+        seq_printf(m, "tot_rx_rings\t0x%x\n", rtl8168_tot_rx_rings(tp));
572
+        seq_printf(m, "tot_tx_rings\t0x%x\n", rtl8168_tot_tx_rings(tp));
573
+        seq_printf(m, "HwSuppNumTxQueues\t0x%x\n", tp->HwSuppNumTxQueues);
574
+        seq_printf(m, "HwSuppNumRxQueues\t0x%x\n", tp->HwSuppNumRxQueues);
575
+        seq_printf(m, "num_hw_tot_en_rx_rings\t0x%x\n", tp->num_hw_tot_en_rx_rings);
576
+        seq_printf(m, "EnableRss\t0x%x\n", tp->EnableRss);
577
+        seq_printf(m, "min_irq_nvecs\t0x%x\n", tp->min_irq_nvecs);
578
+        seq_printf(m, "max_irq_nvecs\t0x%x\n", tp->max_irq_nvecs);
579
+        seq_printf(m, "irq_nvecs\t0x%x\n", tp->irq_nvecs);
580
+        seq_printf(m, "hw_supp_irq_nvecs\t0x%x\n", tp->hw_supp_irq_nvecs);
581
+        seq_printf(m, "ring_lib_enabled\t0x%x\n", tp->ring_lib_enabled);
582
         seq_printf(m, "random_mac\t0x%x\n", tp->random_mac);
583
         seq_printf(m, "org_mac_addr\t%pM\n", tp->org_mac_addr);
584
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
585
         seq_printf(m, "perm_addr\t%pM\n", dev->perm_addr);
586
 #endif
587
         seq_printf(m, "dev_addr\t%pM\n", dev->dev_addr);
588
-        spin_unlock_irqrestore(&tp->lock, flags);
589
+
590
+        rtnl_unlock();
591
 
592
         seq_putc(m, '\n');
593
         return 0;
594
@@ -1051,36 +1304,19 @@
595
         struct rtl8168_private *tp = netdev_priv(dev);
596
         struct rtl8168_counters *counters;
597
         dma_addr_t paddr;
598
-        u32 cmd;
599
-        u32 WaitCnt;
600
-        unsigned long flags;
601
 
602
         seq_puts(m, "\nDump Tally Counter\n");
603
 
604
-        //ASSERT_RTNL();
605
+        rtnl_lock();
606
 
607
         counters = tp->tally_vaddr;
608
         paddr = tp->tally_paddr;
609
         if (!counters) {
610
                 seq_puts(m, "\nDump Tally Counter Fail\n");
611
-                return 0;
612
+                goto out_unlock;
613
         }
614
 
615
-        spin_lock_irqsave(&tp->lock, flags);
616
-        RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
617
-        cmd = (u64)paddr & DMA_BIT_MASK(32);
618
-        RTL_W32(tp, CounterAddrLow, cmd);
619
-        RTL_W32(tp, CounterAddrLow, cmd | CounterDump);
620
-
621
-        WaitCnt = 0;
622
-        while (RTL_R32(tp, CounterAddrLow) & CounterDump) {
623
-                udelay(10);
624
-
625
-                WaitCnt++;
626
-                if (WaitCnt > 20)
627
-                        break;
628
-        }
629
-        spin_unlock_irqrestore(&tp->lock, flags);
630
+        rtl8168_dump_tally_counter(tp, paddr);
631
 
632
         seq_puts(m, "Statistics\tValue\n----------\t-----\n");
633
         seq_printf(m, "tx_packets\t%lld\n", le64_to_cpu(counters->tx_packets));
634
@@ -1097,6 +1333,9 @@
635
         seq_printf(m, "tx_aborted\t%d\n", le16_to_cpu(counters->tx_aborted));
636
         seq_printf(m, "tx_underrun\t%d\n", le16_to_cpu(counters->tx_underrun));
637
 
638
+out_unlock:
639
+        rtnl_unlock();
640
+
641
         seq_putc(m, '\n');
642
         return 0;
643
 }
644
@@ -1108,12 +1347,12 @@
645
         u8 byte_rd;
646
         struct rtl8168_private *tp = netdev_priv(dev);
647
         void __iomem *ioaddr = tp->mmio_addr;
648
-        unsigned long flags;
649
 
650
         seq_puts(m, "\nDump MAC Registers\n");
651
         seq_puts(m, "Offset\tValue\n------\t-----\n");
652
 
653
-        spin_lock_irqsave(&tp->lock, flags);
654
+        rtnl_lock();
655
+
656
         for (n = 0; n < max;) {
657
                 seq_printf(m, "\n0x%02x:\t", n);
658
 
659
@@ -1122,7 +1361,8 @@
660
                         seq_printf(m, "%02x ", byte_rd);
661
                 }
662
         }
663
-        spin_unlock_irqrestore(&tp->lock, flags);
664
+
665
+        rtnl_unlock();
666
 
667
         seq_putc(m, '\n');
668
         return 0;
669
@@ -1134,12 +1374,12 @@
670
         int i, n, max = R8168_EPHY_REGS_SIZE/2;
671
         u16 word_rd;
672
         struct rtl8168_private *tp = netdev_priv(dev);
673
-        unsigned long flags;
674
 
675
         seq_puts(m, "\nDump PCIE PHY\n");
676
         seq_puts(m, "\nOffset\tValue\n------\t-----\n ");
677
 
678
-        spin_lock_irqsave(&tp->lock, flags);
679
+        rtnl_lock();
680
+
681
         for (n = 0; n < max;) {
682
                 seq_printf(m, "\n0x%02x:\t", n);
683
 
684
@@ -1148,7 +1388,8 @@
685
                         seq_printf(m, "%04x ", word_rd);
686
                 }
687
         }
688
-        spin_unlock_irqrestore(&tp->lock, flags);
689
+
690
+        rtnl_unlock();
691
 
692
         seq_putc(m, '\n');
693
         return 0;
694
@@ -1160,12 +1401,12 @@
695
         int i, n, max = R8168_PHY_REGS_SIZE/2;
696
         u16 word_rd;
697
         struct rtl8168_private *tp = netdev_priv(dev);
698
-        unsigned long flags;
699
 
700
         seq_puts(m, "\nDump Ethernet PHY\n");
701
         seq_puts(m, "\nOffset\tValue\n------\t-----\n ");
702
 
703
-        spin_lock_irqsave(&tp->lock, flags);
704
+        rtnl_lock();
705
+
706
         seq_puts(m, "\n####################page 0##################\n ");
707
         rtl8168_mdio_write(tp, 0x1f, 0x0000);
708
         for (n = 0; n < max;) {
709
@@ -1176,7 +1417,8 @@
710
                         seq_printf(m, "%04x ", word_rd);
711
                 }
712
         }
713
-        spin_unlock_irqrestore(&tp->lock, flags);
714
+
715
+        rtnl_unlock();
716
 
717
         seq_putc(m, '\n');
718
         return 0;
719
@@ -1188,7 +1430,6 @@
720
         int i, n, max = R8168_ERI_REGS_SIZE;
721
         u32 dword_rd;
722
         struct rtl8168_private *tp = netdev_priv(dev);
723
-        unsigned long flags;
724
 
725
         switch (tp->mcfg) {
726
         case CFG_METHOD_1:
727
@@ -1202,7 +1443,8 @@
728
         seq_puts(m, "\nDump Extended Registers\n");
729
         seq_puts(m, "\nOffset\tValue\n------\t-----\n ");
730
 
731
-        spin_lock_irqsave(&tp->lock, flags);
732
+        rtnl_lock();
733
+
734
         for (n = 0; n < max;) {
735
                 seq_printf(m, "\n0x%02x:\t", n);
736
 
737
@@ -1211,7 +1453,8 @@
738
                         seq_printf(m, "%08x ", dword_rd);
739
                 }
740
         }
741
-        spin_unlock_irqrestore(&tp->lock, flags);
742
+
743
+        rtnl_unlock();
744
 
745
         seq_putc(m, '\n');
746
         return 0;
747
@@ -1223,12 +1466,12 @@
748
         int i, n, max = R8168_PCI_REGS_SIZE;
749
         u32 dword_rd;
750
         struct rtl8168_private *tp = netdev_priv(dev);
751
-        unsigned long flags;
752
 
753
         seq_puts(m, "\nDump PCI Registers\n");
754
         seq_puts(m, "\nOffset\tValue\n------\t-----\n ");
755
 
756
-        spin_lock_irqsave(&tp->lock, flags);
757
+        rtnl_lock();
758
+
759
         for (n = 0; n < max;) {
760
                 seq_printf(m, "\n0x%03x:\t", n);
761
 
762
@@ -1245,7 +1488,225 @@
763
         pci_read_config_dword(tp->pci_dev, n, &dword_rd);
764
         seq_printf(m, "\n0x%03x:\t%08x ", n, dword_rd);
765
 
766
-        spin_unlock_irqrestore(&tp->lock, flags);
767
+        rtnl_unlock();
768
+
769
+        seq_putc(m, '\n');
770
+        return 0;
771
+}
772
+
773
+static int proc_get_cable_info(struct seq_file *m, void *v)
774
+{
775
+        int i;
776
+        u16 status;
777
+        int cp_statusRTL8168_CP_NUM = {0};
778
+        u16 cp_lenRTL8168_CP_NUM = {0};
779
+        struct net_device *dev = m->private;
780
+        struct rtl8168_private *tp = netdev_priv(dev);
781
+        const char *pair_strRTL8168_CP_NUM = {"1-2", "3-6", "4-5", "7-8"};
782
+
783
+        switch (tp->mcfg) {
784
+        case CFG_METHOD_30:
785
+        case CFG_METHOD_35:
786
+        case CFG_METHOD_36:
787
+        case CFG_METHOD_37:
788
+                /* support */
789
+                break;
790
+        default:
791
+                return -EOPNOTSUPP;
792
+        }
793
+
794
+        rtnl_lock();
795
+
796
+        rtl8168_mdio_write(tp, 0x1f, 0x0000);
797
+        if (rtl8168_mdio_read(tp, MII_BMCR) & BMCR_PDOWN) {
798
+                rtnl_unlock();
799
+                return -EIO;
800
+        }
801
+
802
+        status = RTL_R8(tp, PHYstatus);
803
+        if (status & LinkStatus)
804
+                seq_printf(m, "\nlink speed:%d",
805
+                           rtl8168_convert_link_speed(status));
806
+        else
807
+                seq_puts(m, "\nlink status:off");
808
+
809
+        rtl8168_get_cp_len(tp, cp_len);
810
+
811
+        rtl8168_vcd_test(tp);
812
+
813
+        rtl8168_get_cp_status(tp, cp_status);
814
+
815
+        seq_puts(m, "\npair\tlength\tstatus   \tpp\n");
816
+
817
+        for (i =0; i<RTL8168_CP_NUM; i++) {
818
+                seq_printf(m, "%s\t%d\t%s\t",
819
+                           pair_stri, cp_leni,
820
+                           rtl8168_get_cp_status_string(cp_statusi));
821
+                if (cp_statusi == rtl8168_cp_normal)
822
+                        seq_printf(m, "none\n");
823
+                else
824
+                        seq_printf(m, "%dm\n", rtl8168_get_cp_pp(tp, i));
825
+        }
826
+
827
+        tp->phy_reset_enable(dev);
828
+
829
+        rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
830
+
831
+        rtnl_unlock();
832
+
833
+        seq_putc(m, '\n');
834
+        return 0;
835
+}
836
+
837
+static int proc_dump_rx_desc(struct seq_file *m, void *v)
838
+{
839
+        int i;
840
+        u32 *pdword;
841
+        struct net_device *dev = m->private;
842
+        struct rtl8168_private *tp = netdev_priv(dev);
843
+
844
+        if (!tp->RxDescArray)
845
+                return -EOPNOTSUPP;
846
+
847
+        rtnl_lock();
848
+
849
+        seq_printf(m, "\ndump rx desc:%d\n", tp->num_rx_desc);
850
+
851
+        pdword = (u32*)tp->RxDescArray;
852
+        for (i=0; i<(tp->RxDescAllocSize/4); i++) {
853
+                if (!(i % 4))
854
+                        seq_printf(m, "\n%04x ", i);
855
+                seq_printf(m, "%08x ", pdwordi);
856
+        }
857
+
858
+        rtnl_unlock();
859
+
860
+        seq_putc(m, '\n');
861
+        return 0;
862
+}
863
+
864
+static int proc_dump_rx_desc_2(struct seq_file *m, void *v)
865
+{
866
+        int i, j, k;
867
+        u32 *pdword;
868
+        struct net_device *dev = m->private;
869
+        struct rtl8168_private *tp = netdev_priv(dev);
870
+
871
+        if (!tp->RxDescArray)
872
+                return -EOPNOTSUPP;
873
+
874
+        rtnl_lock();
875
+
876
+        for (k=0; k<tp->num_hw_tot_en_rx_rings; k++) {
877
+                seq_printf(m, "\ndump Q%d rx desc:%d\n", k, tp->num_rx_desc);
878
+                for (j=0; j<tp->num_rx_desc; j++) {
879
+                        pdword = (u32*)rtl8168_get_rxdesc(tp,
880
+                                                          tp->RxDescArray,
881
+                                                          j, k);
882
+                        for (i=0; i<(tp->RxDescLength/4); i++) {
883
+                                if (!(i % 4))
884
+                                        seq_printf(m, "\n%04llx ",
885
+                                                   ((u64)pdword + (i * 4) -
886
+                                                    (u64)tp->RxDescArray));
887
+                                seq_printf(m, "%08x ", pdwordi);
888
+                        }
889
+                }
890
+
891
+                seq_putc(m, '\n');
892
+        }
893
+
894
+        rtnl_unlock();
895
+
896
+        seq_putc(m, '\n');
897
+        return 0;
898
+}
899
+
900
+void _proc_dump_tx_desc(struct seq_file *m, struct TxDesc *desc_base,
901
+                        u32 alloc_size, u32 num_desc)
902
+{
903
+        int i;
904
+        u32 *pdword;
905
+
906
+        if (desc_base == NULL ||
907
+            alloc_size == 0 ||
908
+            num_desc == 0)
909
+                return;
910
+
911
+        pdword = (u32*)desc_base;
912
+        for (i=0; i<(alloc_size/4); i++) {
913
+                if (!(i % 4))
914
+                        seq_printf(m, "\n%04x ", i);
915
+                seq_printf(m, "%08x ", pdwordi);
916
+        }
917
+
918
+        seq_putc(m, '\n');
919
+        return;
920
+}
921
+
922
+static int proc_dump_tx_desc(struct seq_file *m, void *v)
923
+{
924
+        int i;
925
+        struct net_device *dev = m->private;
926
+        struct rtl8168_private *tp = netdev_priv(dev);
927
+
928
+        rtnl_lock();
929
+
930
+        for (i=0; i<tp->HwSuppNumTxQueues; i++) {
931
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
932
+                if (!ring->TxDescArray)
933
+                        continue;
934
+                seq_printf(m, "\ndump Q%d tx desc:%d\n", i, ring->num_tx_desc);
935
+                _proc_dump_tx_desc(m, ring->TxDescArray,
936
+                                   ring->TxDescAllocSize,
937
+                                   ring->num_tx_desc);
938
+        }
939
+
940
+#ifdef ENABLE_LIB_SUPPORT
941
+        for (i=0; i<tp->HwSuppNumTxQueues; i++) {
942
+                struct rtl8168_ring *ring = &tp->lib_tx_ringi;
943
+                if (!ring->desc_addr)
944
+                        continue;
945
+                seq_printf(m, "\ndump lib Q%d tx desc:%d\n", i, ring->ring_size);
946
+                _proc_dump_tx_desc(m, ring->desc_addr,
947
+                                   ring->desc_size,
948
+                                   ring->ring_size);
949
+        }
950
+#endif //ENABLE_LIB_SUPPORT
951
+
952
+        rtnl_unlock();
953
+
954
+        seq_putc(m, '\n');
955
+        return 0;
956
+}
957
+
958
+static int proc_dump_msix_tbl(struct seq_file *m, void *v)
959
+{
960
+        int i, j;
961
+        struct net_device *dev = m->private;
962
+        struct rtl8168_private *tp = netdev_priv(dev);
963
+
964
+        switch (tp->mcfg) {
965
+        case CFG_METHOD_1 ... CFG_METHOD_8:
966
+                return -EOPNOTSUPP;
967
+        default:
968
+                break;
969
+        }
970
+
971
+        rtnl_lock();
972
+
973
+        seq_printf(m, "\ndump MSI-X Table. Total Entry %d. \n",
974
+                   tp->hw_supp_irq_nvecs);
975
+
976
+        for (i=0; i<tp->hw_supp_irq_nvecs; i++) {
977
+                seq_printf(m, "\n%04x ", i);
978
+                for (j=0; j<4; j++)
979
+                        seq_printf(m, "%08x ",
980
+                                   rtl8168_eri_read(
981
+                                           tp, i*0x10 + 4 * j, 4,
982
+                                           ERIAR_MSIX));
983
+        }
984
+
985
+        rtnl_unlock();
986
 
987
         seq_putc(m, '\n');
988
         return 0;
989
@@ -1258,13 +1719,13 @@
990
 {
991
         struct net_device *dev = data;
992
         struct rtl8168_private *tp = netdev_priv(dev);
993
-        unsigned long flags;
994
         int len = 0;
995
 
996
         len += snprintf(page + len, count - len,
997
                         "\nDump Driver Driver\n");
998
 
999
-        spin_lock_irqsave(&tp->lock, flags);
1000
+        rtnl_lock();
1001
+
1002
         len += snprintf(page + len, count - len,
1003
                         "Variable\tValue\n----------\t-----\n");
1004
 
1005
@@ -1274,12 +1735,27 @@
1006
                         "chipset\t%d\n"
1007
                         "chipset_name\t%s\n"
1008
                         "mtu\t%d\n"
1009
-                        "NUM_RX_DESC\t0x%x\n"
1010
-                        "cur_rx\t0x%x\n"
1011
-                        "dirty_rx\t0x%x\n"
1012
-                        "NUM_TX_DESC\t0x%x\n"
1013
-                        "cur_tx\t0x%x\n"
1014
-                        "dirty_tx\t0x%x\n"
1015
+                        "num_rx_desc\t0x%x\n"
1016
+                        "cur_rx0\t0x%x\n"
1017
+                        "dirty_rx0\t0x%x\n"
1018
+                        "rdu0\t0x%x\n"
1019
+                        "cur_rx1\t0x%x\n"
1020
+                        "dirty_rx1\t0x%x\n"
1021
+                        "rdu1\t0x%x\n"
1022
+                        "cur_rx2\t0x%x\n"
1023
+                        "dirty_rx2\t0x%x\n"
1024
+                        "rdu2\t0x%x\n"
1025
+                        "cur_rx3\t0x%x\n"
1026
+                        "dirty_rx3\t0x%x\n"
1027
+                        "rdu3\t0x%x\n"
1028
+                        "rx_fifo_of\t0x%x\n"
1029
+                        "num_tx_desc\t0x%x\n"
1030
+                        "cur_tx0\t0x%x\n"
1031
+                        "dirty_tx0\t0x%x\n"
1032
+                        "tdu0\t0x%x\n"
1033
+                        "cur_tx1\t0x%x\n"
1034
+                        "dirty_tx1\t0x%x\n"
1035
+                        "tdu0\t1x%x\n"
1036
                         "rx_buf_sz\t0x%x\n"
1037
                         "esd_flag\t0x%x\n"
1038
                         "pci_cfg_is_read\t0x%x\n"
1039
@@ -1340,11 +1816,28 @@
1040
                         "hwoptimize\t0x%lx\n"
1041
                         "proc_init_num\t0x%x\n"
1042
                         "s0_magic_packet\t0x%x\n"
1043
+                        "disable_wol_support\t0x%x\n"
1044
                         "HwSuppMagicPktVer\t0x%x\n"
1045
                         "HwSuppUpsVer\t0x%x\n"
1046
                         "HwSuppEsdVer\t0x%x\n"
1047
                         "HwSuppCheckPhyDisableModeVer\t0x%x\n"
1048
                         "HwPkgDet\t0x%x\n"
1049
+                        "InitRxDescType\t0x%x\n"
1050
+                        "RxDescLength\t0x%x\n"
1051
+                        "num_rx_rings\t0x%x\n"
1052
+                        "num_tx_rings\t0x%x\n"
1053
+                        "tot_rx_rings\t0x%x\n"
1054
+                        "tot_tx_rings\t0x%x\n"
1055
+                        "tot_rx_desc_rings\t0x%x\n"
1056
+                        "HwSuppNumTxQueues\t0x%x\n"
1057
+                        "HwSuppNumRxQueues\t0x%x\n"
1058
+                        "num_hw_tot_en_rx_rings\t0x%x\n"
1059
+                        "EnableRss\t0x%x\n"
1060
+                        "min_irq_nvecs\t0x%x\n"
1061
+                        "max_irq_nvecs\t0x%x\n"
1062
+                        "irq_nvecs\t0x%x\n"
1063
+                        "hw_supp_irq_nvecs\t0x%x\n"
1064
+                        "ring_lib_enabled\t0x%x\n"
1065
                         "random_mac\t0x%x\n"
1066
                         "org_mac_addr\t%pM\n"
1067
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
1068
@@ -1357,11 +1850,26 @@
1069
                         rtl_chip_infotp->chipset.name,
1070
                         dev->mtu,
1071
                         tp->num_rx_desc,
1072
-                        tp->cur_rx,
1073
-                        tp->dirty_rx,
1074
-                        tp->num_tx_desc,
1075
-                        tp->cur_tx,
1076
-                        tp->dirty_tx,
1077
+                        tp->rx_ring0.cur_rx,
1078
+                        tp->rx_ring0.dirty_rx,
1079
+                        tp->rx_ring0.rdu,
1080
+                        tp->rx_ring1.cur_rx,
1081
+                        tp->rx_ring1.dirty_rx,
1082
+                        tp->rx_ring1.rdu,
1083
+                        tp->rx_ring2.cur_rx,
1084
+                        tp->rx_ring2.dirty_rx,
1085
+                        tp->rx_ring2.rdu,
1086
+                        tp->rx_ring3.cur_rx,
1087
+                        tp->rx_ring3.dirty_rx,
1088
+                        tp->rx_ring3.rdu,
1089
+                        tp->rx_fifo_of,
1090
+                        tp->tx_ring0.num_tx_desc,
1091
+                        tp->tx_ring0.cur_tx,
1092
+                        tp->tx_ring0.dirty_tx,
1093
+                        tp->tx_ring0.tdu,
1094
+                        tp->tx_ring1.cur_tx,
1095
+                        tp->tx_ring1.dirty_tx,
1096
+                        tp->tx_ring1.tdu,
1097
                         tp->rx_buf_sz,
1098
                         tp->esd_flag,
1099
                         tp->pci_cfg_is_read,
1100
@@ -1418,15 +1926,31 @@
1101
                         aspm,
1102
                         s5wol,
1103
                         s5_keep_curr_mac,
1104
-                        tp->eee_enabled,
1105
+                        tp->eee.eee_enabled,
1106
                         hwoptimize,
1107
                         proc_init_num,
1108
                         s0_magic_packet,
1109
+                        disable_wol_support,
1110
                         tp->HwSuppMagicPktVer,
1111
                         tp->HwSuppUpsVer,
1112
                         tp->HwSuppEsdVer,
1113
                         tp->HwSuppCheckPhyDisableModeVer,
1114
                         tp->HwPkgDet,
1115
+                        tp->InitRxDescType,
1116
+                        tp->RxDescLength,
1117
+                        tp->num_rx_rings,
1118
+                        tp->num_tx_rings,
1119
+                        rtl8168_tot_rx_rings(tp),
1120
+                        rtl8168_tot_tx_rings(tp),
1121
+                        tp->HwSuppNumTxQueues,
1122
+                        tp->HwSuppNumRxQueues,
1123
+                        tp->num_hw_tot_en_rx_rings,
1124
+                        tp->EnableRss,
1125
+                        tp->min_irq_nvecs,
1126
+                        tp->max_irq_nvecs,
1127
+                        tp->irq_nvecs,
1128
+                        tp->hw_supp_irq_nvecs,
1129
+                        tp->ring_lib_enabled,
1130
                         tp->random_mac,
1131
                         tp->org_mac_addr,
1132
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
1133
@@ -1434,7 +1958,8 @@
1134
 #endif
1135
                         dev->dev_addr
1136
                        );
1137
-        spin_unlock_irqrestore(&tp->lock, flags);
1138
+
1139
+        rtnl_unlock();
1140
 
1141
         len += snprintf(page + len, count - len, "\n");
1142
 
1143
@@ -1452,37 +1977,22 @@
1144
         dma_addr_t paddr;
1145
         u32 cmd;
1146
         u32 WaitCnt;
1147
-        unsigned long flags;
1148
         int len = 0;
1149
 
1150
         len += snprintf(page + len, count - len,
1151
                         "\nDump Tally Counter\n");
1152
 
1153
-        //ASSERT_RTNL();
1154
+        rtnl_lock();
1155
 
1156
         counters = tp->tally_vaddr;
1157
         paddr = tp->tally_paddr;
1158
         if (!counters) {
1159
                 len += snprintf(page + len, count - len,
1160
                                 "\nDump Tally Counter Fail\n");
1161
-                goto out;
1162
+                goto out_unlock;
1163
         }
1164
 
1165
-        spin_lock_irqsave(&tp->lock, flags);
1166
-        RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
1167
-        cmd = (u64)paddr & DMA_BIT_MASK(32);
1168
-        RTL_W32(tp, CounterAddrLow, cmd);
1169
-        RTL_W32(tp, CounterAddrLow, cmd | CounterDump);
1170
-
1171
-        WaitCnt = 0;
1172
-        while (RTL_R32(tp, CounterAddrLow) & CounterDump) {
1173
-                udelay(10);
1174
-
1175
-                WaitCnt++;
1176
-                if (WaitCnt > 20)
1177
-                        break;
1178
-        }
1179
-        spin_unlock_irqrestore(&tp->lock, flags);
1180
+        rtl8168_dump_tally_counter(tp, paddr);
1181
 
1182
         len += snprintf(page + len, count - len,
1183
                         "Statistics\tValue\n----------\t-----\n");
1184
@@ -1517,7 +2027,9 @@
1185
                        );
1186
 
1187
         len += snprintf(page + len, count - len, "\n");
1188
-out:
1189
+out_unlock:
1190
+        rtnl_unlock();
1191
+
1192
         *eof = 1;
1193
         return len;
1194
 }
1195
@@ -1531,14 +2043,14 @@
1196
         u8 byte_rd;
1197
         struct rtl8168_private *tp = netdev_priv(dev);
1198
         void __iomem *ioaddr = tp->mmio_addr;
1199
-        unsigned long flags;
1200
         int len = 0;
1201
 
1202
         len += snprintf(page + len, count - len,
1203
                         "\nDump MAC Registers\n"
1204
                         "Offset\tValue\n------\t-----\n");
1205
 
1206
-        spin_lock_irqsave(&tp->lock, flags);
1207
+        rtnl_lock();
1208
+
1209
         for (n = 0; n < max;) {
1210
                 len += snprintf(page + len, count - len,
1211
                                 "\n0x%02x:\t",
1212
@@ -1551,7 +2063,8 @@
1213
                                         byte_rd);
1214
                 }
1215
         }
1216
-        spin_unlock_irqrestore(&tp->lock, flags);
1217
+
1218
+        rtnl_unlock();
1219
 
1220
         len += snprintf(page + len, count - len, "\n");
1221
 
1222
@@ -1567,14 +2080,14 @@
1223
         int i, n, max = R8168_EPHY_REGS_SIZE/2;
1224
         u16 word_rd;
1225
         struct rtl8168_private *tp = netdev_priv(dev);
1226
-        unsigned long flags;
1227
         int len = 0;
1228
 
1229
         len += snprintf(page + len, count - len,
1230
                         "\nDump PCIE PHY\n"
1231
                         "Offset\tValue\n------\t-----\n");
1232
 
1233
-        spin_lock_irqsave(&tp->lock, flags);
1234
+        rtnl_lock();
1235
+
1236
         for (n = 0; n < max;) {
1237
                 len += snprintf(page + len, count - len,
1238
                                 "\n0x%02x:\t",
1239
@@ -1587,7 +2100,8 @@
1240
                                         word_rd);
1241
                 }
1242
         }
1243
-        spin_unlock_irqrestore(&tp->lock, flags);
1244
+
1245
+        rtnl_unlock();
1246
 
1247
         len += snprintf(page + len, count - len, "\n");
1248
 
1249
@@ -1603,14 +2117,14 @@
1250
         int i, n, max = R8168_PHY_REGS_SIZE/2;
1251
         u16 word_rd;
1252
         struct rtl8168_private *tp = netdev_priv(dev);
1253
-        unsigned long flags;
1254
         int len = 0;
1255
 
1256
         len += snprintf(page + len, count - len,
1257
                         "\nDump Ethernet PHY\n"
1258
                         "Offset\tValue\n------\t-----\n");
1259
 
1260
-        spin_lock_irqsave(&tp->lock, flags);
1261
+        rtnl_lock();
1262
+
1263
         len += snprintf(page + len, count - len,
1264
                         "\n####################page 0##################\n");
1265
         rtl8168_mdio_write(tp, 0x1f, 0x0000);
1266
@@ -1626,7 +2140,8 @@
1267
                                         word_rd);
1268
                 }
1269
         }
1270
-        spin_unlock_irqrestore(&tp->lock, flags);
1271
+
1272
+        rtnl_unlock();
1273
 
1274
         len += snprintf(page + len, count - len, "\n");
1275
 
1276
@@ -1642,7 +2157,6 @@
1277
         int i, n, max = R8168_ERI_REGS_SIZE;
1278
         u32 dword_rd;
1279
         struct rtl8168_private *tp = netdev_priv(dev);
1280
-        unsigned long flags;
1281
         int len = 0;
1282
 
1283
         switch (tp->mcfg) {
1284
@@ -1660,7 +2174,8 @@
1285
                         "\nDump Extended Registers\n"
1286
                         "Offset\tValue\n------\t-----\n");
1287
 
1288
-        spin_lock_irqsave(&tp->lock, flags);
1289
+        rtnl_lock();
1290
+
1291
         for (n = 0; n < max;) {
1292
                 len += snprintf(page + len, count - len,
1293
                                 "\n0x%02x:\t",
1294
@@ -1673,7 +2188,8 @@
1295
                                         dword_rd);
1296
                 }
1297
         }
1298
-        spin_unlock_irqrestore(&tp->lock, flags);
1299
+
1300
+        rtnl_unlock();
1301
 
1302
         len += snprintf(page + len, count - len, "\n");
1303
 out:
1304
@@ -1689,14 +2205,14 @@
1305
         int i, n, max = R8168_PCI_REGS_SIZE;
1306
         u32 dword_rd;
1307
         struct rtl8168_private *tp = netdev_priv(dev);
1308
-        unsigned long flags;
1309
         int len = 0;
1310
 
1311
         len += snprintf(page + len, count - len,
1312
                         "\nDump PCI Registers\n"
1313
                         "Offset\tValue\n------\t-----\n");
1314
 
1315
-        spin_lock_irqsave(&tp->lock, flags);
1316
+        rtnl_lock();
1317
+
1318
         for (n = 0; n < max;) {
1319
                 len += snprintf(page + len, count - len,
1320
                                 "\n0x%03x:\t",
1321
@@ -1722,14 +2238,332 @@
1322
                         "\n0x%03x:\t%08x ",
1323
                         n,
1324
                         dword_rd);
1325
-        spin_unlock_irqrestore(&tp->lock, flags);
1326
+
1327
+        rtnl_unlock();
1328
 
1329
         len += snprintf(page + len, count - len, "\n");
1330
 
1331
         *eof = 1;
1332
         return len;
1333
 }
1334
-#endif
1335
+
1336
+static int proc_get_cable_info(char *page, char **start,
1337
+                               off_t offset, int count,
1338
+                               int *eof, void *data)
1339
+{
1340
+        int i;
1341
+        u16 status;
1342
+        int len = 0;
1343
+        struct net_device *dev = data;
1344
+        int cp_statusRTL8168_CP_NUM = {0};
1345
+        u16 cp_lenRTL8168_CP_NUM = {0};
1346
+        struct rtl8168_private *tp = netdev_priv(dev);
1347
+        const char *pair_strRTL8168_CP_NUM = {"1-2", "3-6", "4-5", "7-8"};
1348
+
1349
+        switch (tp->mcfg) {
1350
+        case CFG_METHOD_30:
1351
+        case CFG_METHOD_35:
1352
+        case CFG_METHOD_36:
1353
+        case CFG_METHOD_37:
1354
+                /* support */
1355
+                break;
1356
+        default:
1357
+                return -EOPNOTSUPP;
1358
+        }
1359
+
1360
+        rtnl_lock();
1361
+
1362
+        status = RTL_R8(tp, PHYstatus);
1363
+        if (status & LinkStatus)
1364
+                len += snprintf(page + len, count - len,
1365
+                                "\nlink speed:%d",
1366
+                                rtl8168_convert_link_speed(status));
1367
+        else
1368
+                len += snprintf(page + len, count - len,
1369
+                                "\nlink status:off");
1370
+
1371
+        rtl8168_get_cp(tp, cp_len, cp_status);
1372
+
1373
+        len += snprintf(page + len, count - len,
1374
+                        "\npair\tlength\tstatus   \tpp\n");
1375
+
1376
+        for (i =0; i<RTL8168_CP_NUM; i++) {
1377
+                len += snprintf(page + len, count - len,
1378
+                                "%s\t%d\t%s\t",
1379
+                                pair_stri, cp_leni,
1380
+                                rtl8168_get_cp_status_string(cp_statusi));
1381
+                if (cp_statusi == rtl8168_cp_normal)
1382
+                        len += snprintf(page + len, count - len, "none\n");
1383
+                else
1384
+                        len += snprintf(page + len, count - len, "%dm\n",
1385
+                                        rtl8168_get_cp_pp(tp, i));
1386
+        }
1387
+
1388
+        rtnl_unlock();
1389
+
1390
+        len += snprintf(page + len, count - len, "\n");
1391
+
1392
+        *eof = 1;
1393
+        return len;
1394
+}
1395
+
1396
+static int proc_dump_rx_desc(char *page, char **start,
1397
+                             off_t offset, int count,
1398
+                             int *eof, void *data)
1399
+{
1400
+        int i;
1401
+        int len = 0;
1402
+        u32 *pdword;
1403
+        struct net_device *dev = data;
1404
+        struct rtl8168_private *tp = netdev_priv(dev);
1405
+
1406
+        if (!tp->RxDescArray)
1407
+                return -EOPNOTSUPP;
1408
+
1409
+        rtnl_lock();
1410
+
1411
+        len += snprintf(page + len, count - len,
1412
+                        "\ndump rx desc:%d",
1413
+                        tp->num_rx_desc);
1414
+
1415
+        pdword = (u32*)tp->RxDescArray;
1416
+        for (i=0; i<(tp->RxDescAllocSize/4); i++) {
1417
+                if (!(i % 4))
1418
+                        len += snprintf(page + len, count - len,
1419
+                                        "\n%04x ",
1420
+                                        i);
1421
+                len += snprintf(page + len, count - len,
1422
+                                "%08x ",
1423
+                                pdwordi);
1424
+        }
1425
+
1426
+        rtnl_unlock();
1427
+
1428
+        len += snprintf(page + len, count - len, "\n");
1429
+
1430
+        *eof = 1;
1431
+
1432
+        return len;
1433
+}
1434
+
1435
+static int proc_dump_rx_desc_2(char *page, char **start,
1436
+                               off_t offset, int count,
1437
+                               int *eof, void *data)
1438
+{
1439
+        int i, j, k;
1440
+        int len = 0;
1441
+        u32 *pdword;
1442
+        struct net_device *dev = data;
1443
+        struct rtl8168_private *tp = netdev_priv(dev);
1444
+
1445
+        if (!tp->RxDescArray)
1446
+                return -EOPNOTSUPP;
1447
+
1448
+        rtnl_lock();
1449
+
1450
+        for (k=0; k<tp->num_hw_tot_en_rx_rings; k++) {
1451
+                len += snprintf(page + len, count - len,
1452
+                                "\ndump Q%d rx desc:%d",
1453
+                                k,
1454
+                                tp->num_rx_desc);
1455
+                for (j=0; j<tp->num_rx_desc; j++) {
1456
+                        pdword = (u32*)rtl8168_get_rxdesc(tp,
1457
+                                                          tp->RxDescArray,
1458
+                                                          j, k);
1459
+                        for (i=0; i<(tp->RxDescLength/4); i++) {
1460
+                                if (!(i % 4))
1461
+                                        len += snprintf(page + len, count - len,
1462
+                                                        "\n%04llx ",
1463
+                                                        ((u64)pdword + (i * 4) -
1464
+                                                         (u64)tp->RxDescArray));
1465
+                                len += snprintf(page + len, count - len,
1466
+                                                "%08x ",
1467
+                                                pdwordi);
1468
+                        }
1469
+                }
1470
+
1471
+                len += snprintf(page + len, count - len, "\n");
1472
+        }
1473
+
1474
+        rtnl_unlock();
1475
+
1476
+        len += snprintf(page + len, count - len, "\n");
1477
+
1478
+        *eof = 1;
1479
+
1480
+        return len;
1481
+}
1482
+
1483
+void _proc_dump_tx_desc(char *page, int *page_len, int *count,
1484
+                        struct TxDesc *desc_base,
1485
+                        u32 alloc_size, u32 num_desc)
1486
+{
1487
+        int i;
1488
+        int len = 0;
1489
+        u32 *pdword;
1490
+
1491
+        if (desc_base == NULL ||
1492
+            alloc_size == 0 ||
1493
+            num_desc == 0)
1494
+                return;
1495
+
1496
+        len = *page_len;
1497
+        pdword = (u32*)desc_base;
1498
+        for (i=0; i<(alloc_size/4); i++) {
1499
+                if (!(i % 4))
1500
+                        len += snprintf(page + len, *count - len,
1501
+                                        "\n%04x ",
1502
+                                        i);
1503
+                len += snprintf(page + len, *count - len,
1504
+                                "%08x ",
1505
+                                pdwordi);
1506
+        }
1507
+
1508
+        len += snprintf(page + len, count - len, "\n");
1509
+
1510
+        *page_len = len;
1511
+        return;
1512
+}
1513
+
1514
+static int proc_dump_tx_desc(char *page, char **start,
1515
+                             off_t offset, int count,
1516
+                             int *eof, void *data)
1517
+{
1518
+        int i;
1519
+        int len = 0;
1520
+        u32 *pdword;
1521
+        struct net_device *dev = data;
1522
+        struct rtl8168_private *tp = netdev_priv(dev);
1523
+        struct rtl8168_tx_ring *ring = &tp->tx_ring0;
1524
+
1525
+        if (!ring->TxDescArray)
1526
+                return -EOPNOTSUPP;
1527
+
1528
+        rtnl_lock();
1529
+
1530
+        for (i=0; i<tp->HwSuppNumTxQueues; i++) {
1531
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
1532
+                if (!ring->TxDescArray)
1533
+                        continue;
1534
+                len += snprintf(page + len, count - len,
1535
+                                "\ndump Q%d tx desc:%d",
1536
+                                i,
1537
+                                ring->num_tx_desc);
1538
+                _proc_dump_tx_desc(page, &len, &count,
1539
+                                   ring->TxDescArray,
1540
+                                   ring->TxDescAllocSize,
1541
+                                   ring->num_tx_desc);
1542
+        }
1543
+
1544
+#ifdef ENABLE_LIB_SUPPORT
1545
+        for (i=0; i<tp->HwSuppNumTxQueues; i++) {
1546
+                struct rtl8168_ring *ring = &tp->lib_tx_ringi;
1547
+                if (!ring->desc_addr)
1548
+                        continue;
1549
+                len += snprintf(page + len, count - len,
1550
+                                "\ndump lib Q%d tx desc:%d",
1551
+                                i,
1552
+                                ring->ring_size);
1553
+                _proc_dump_tx_desc(page, &len, ring->desc_addr,
1554
+                                   ring->desc_size,
1555
+                                   ring->ring_size);
1556
+        }
1557
+#endif //ENABLE_LIB_SUPPORT
1558
+
1559
+        rtnl_unlock();
1560
+
1561
+        len += snprintf(page + len, count - len, "\n");
1562
+
1563
+        *eof = 1;
1564
+
1565
+        return len;
1566
+}
1567
+
1568
+static int proc_dump_tx_desc(char *page, char **start,
1569
+                             off_t offset, int count,
1570
+                             int *eof, void *data)
1571
+{
1572
+        int i;
1573
+        struct net_device *dev = m->private;
1574
+        struct rtl8168_private *tp = netdev_priv(dev);
1575
+
1576
+        switch (tp->mcfg) {
1577
+        case CFG_METHOD_1 ... CFG_METHOD_8:
1578
+                return -EOPNOTSUPP;
1579
+        default:
1580
+                break;
1581
+        }
1582
+
1583
+        rtnl_lock();
1584
+
1585
+        len += snprintf(page + len, count - len,
1586
+                        "\ndump MSI-X Table. Total Entry %d. \n",
1587
+                        R8168_MAX_MSIX_VEC);
1588
+
1589
+        for (i=0; i<R8168_MAX_MSIX_VEC; i++) {
1590
+                len += snprintf(page + len, count - len,
1591
+                                "\n%04x ",
1592
+                                i);
1593
+                len += snprintf(page + len, count - len,
1594
+                                "%08x ",
1595
+                                rtl8168_eri_read(tp, i*0x10, 4,
1596
+                                                 ERIAR_MSIX));
1597
+                len += snprintf(page + len, count - len,
1598
+                                "%08x ",
1599
+                                rtl8168_eri_read(tp, i*0x10 + 4, 4,
1600
+                                                 ERIAR_MSIX));
1601
+                len += snprintf(page + len, count - len,
1602
+                                "%08x ",
1603
+                                rtl8168_eri_read(tp, i*0x10 + 8, 4,
1604
+                                                 ERIAR_MSIX));
1605
+                len += snprintf(page + len, count - len,
1606
+                                "%08x ",
1607
+                                rtl8168_eri_read(tp, i*0x10 + 12, 4,
1608
+                                                 ERIAR_MSIX));
1609
+        }
1610
+
1611
+        rtnl_unlock();
1612
+
1613
+        len += snprintf(page + len, count - len, "\n");
1614
+
1615
+        *eof = 1;
1616
+
1617
+        return len;
1618
+}
1619
+
1620
+static int proc_dump_msix_tbl(char *page, char **start,
1621
+                              off_t offset, int count,
1622
+                              int *eof, void *data)
1623
+{
1624
+        int i, j;
1625
+        int len = 0;
1626
+        struct net_device *dev = data;
1627
+        struct rtl8168_private *tp = netdev_priv(dev);
1628
+
1629
+        rtnl_lock();
1630
+
1631
+        len += snprintf(page + len, count - len,
1632
+                        "\ndump MSI-X Table. Total Entry %d. \n",
1633
+                        tp->hw_supp_irq_nvecs);
1634
+
1635
+        for (i=0; i<tp->hw_supp_irq_nvecs; i++) {
1636
+                len += snprintf(page + len, count - len,
1637
+                                "\n%04x ", i);
1638
+                for (j=0; j<4; j++)
1639
+                        len += snprintf(page + len, count - len, "%08x ",
1640
+                                        rtl8168_eri_read(tp, i*0x10 + 4*j, 4,
1641
+                                                         ERIAR_MSIX));
1642
+        }
1643
+
1644
+        rtnl_unlock();
1645
+
1646
+        len += snprintf(page + len, count - len, "\n");
1647
+
1648
+        *eof = 1;
1649
+        return 0;
1650
+}
1651
+#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
1652
+
1653
 static void rtl8168_proc_module_init(void)
1654
 {
1655
         //create /proc/net/r8168
1656
@@ -1796,6 +2630,11 @@
1657
         { "eth_phy", &proc_get_eth_phy },
1658
         { "ext_regs", &proc_get_extended_registers },
1659
         { "pci_regs", &proc_get_pci_registers },
1660
+        { "cdt", &proc_get_cable_info },
1661
+        { "tx_desc", &proc_dump_tx_desc },
1662
+        { "rx_desc", &proc_dump_rx_desc },
1663
+        { "rx_desc_2", &proc_dump_rx_desc_2 },
1664
+        { "msix_tbl", &proc_dump_msix_tbl },
1665
         { "" }
1666
 };
1667
 
1668
@@ -2205,7 +3044,7 @@
1669
                             );
1670
 }
1671
 
1672
-void rtl8168_set_eth_phy_bit(struct rtl8168_private *tp,  u8  addr, u16  mask)
1673
+void rtl8168_set_eth_phy_bit(struct rtl8168_private *tp, u8  addr, u16  mask)
1674
 {
1675
         ClearAndSetEthPhyBit(tp,
1676
                              addr,
1677
@@ -2636,7 +3475,8 @@
1678
 
1679
 static u8 rtl8168_check_ephy_addr(struct rtl8168_private *tp, int addr)
1680
 {
1681
-        if ( tp->mcfg != CFG_METHOD_35) goto exit;
1682
+        if (tp->mcfg != CFG_METHOD_35 && tp->mcfg != CFG_METHOD_36)
1683
+                goto exit;
1684
 
1685
         if (addr & (BIT_6 | BIT_5))
1686
                 rtl8168_clear_and_set_mcu_ocp_bit(tp, 0xDE28,
1687
@@ -3192,6 +4032,8 @@
1688
         case CFG_METHOD_33:
1689
         case CFG_METHOD_34:
1690
         case CFG_METHOD_35:
1691
+        case CFG_METHOD_36:
1692
+        case CFG_METHOD_37:
1693
                 RTL_W8(tp, 0xF2, RTL_R8(tp, 0xF2) | BIT_3);
1694
                 mdelay(2);
1695
                 break;
1696
@@ -3219,6 +4061,8 @@
1697
         case CFG_METHOD_33:
1698
         case CFG_METHOD_34:
1699
         case CFG_METHOD_35:
1700
+        case CFG_METHOD_36:
1701
+        case CFG_METHOD_37:
1702
                 RTL_W8(tp, 0xF2, RTL_R8(tp, 0xF2) & ~BIT_3);
1703
                 mdelay(2);
1704
                 break;
1705
@@ -3309,6 +4153,8 @@
1706
         case CFG_METHOD_33:
1707
         case CFG_METHOD_34:
1708
         case CFG_METHOD_35:
1709
+        case CFG_METHOD_36:
1710
+        case CFG_METHOD_37:
1711
                 for (i = 0; i < 10; i++) {
1712
                         udelay(100);
1713
                         if (RTL_R32(tp, TxConfig) & BIT_11)
1714
@@ -3326,6 +4172,50 @@
1715
         }
1716
 }
1717
 
1718
+static int rtl8168_wait_dash_fw_ready(struct rtl8168_private *tp)
1719
+{
1720
+        int rc = -1;
1721
+
1722
+        if (!HW_DASH_SUPPORT_DASH(tp))
1723
+                goto out;
1724
+
1725
+        if (!tp->DASH)
1726
+                goto out;
1727
+
1728
+        if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) {
1729
+                int timeout;
1730
+
1731
+                for (timeout = 0; timeout < 10; timeout++) {
1732
+                        mdelay(10);
1733
+                        if (rtl8168_ocp_read(tp, 0x124, 1) & BIT_0) {
1734
+                                rc = 1;
1735
+                                goto out;
1736
+                        }
1737
+                }
1738
+        } else {
1739
+                u32 reg;
1740
+                int timeout;
1741
+
1742
+                if (tp->mcfg == CFG_METHOD_13)
1743
+                        reg = 0xB8;
1744
+                else
1745
+                        reg = 0x10;
1746
+
1747
+                for (timeout = 0; timeout < 10; timeout++) {
1748
+                        mdelay(10);
1749
+                        if (rtl8168_ocp_read(tp, reg, 2) & BIT_11) {
1750
+                                rc = 1;
1751
+                                goto out;
1752
+                        }
1753
+                }
1754
+        }
1755
+
1756
+        rc = 0;
1757
+
1758
+out:
1759
+        return rc;
1760
+}
1761
+
1762
 static void rtl8168_driver_start(struct rtl8168_private *tp)
1763
 {
1764
         //change other device state to D0.
1765
@@ -3345,11 +4235,7 @@
1766
                 break;
1767
         }
1768
 
1769
-        if (!tp->DASH)
1770
-                return;
1771
-
1772
         if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) {
1773
-                int timeout;
1774
                 u32 tmp_value;
1775
 
1776
                 rtl8168_ocp_write(tp, 0x180, 1, OOB_CMD_DRIVER_START);
1777
@@ -3357,42 +4243,22 @@
1778
                 tmp_value |= BIT_0;
1779
                 rtl8168_ocp_write(tp, 0x30, 1, tmp_value);
1780
 
1781
-                for (timeout = 0; timeout < 10; timeout++) {
1782
-                        mdelay(10);
1783
-                        if (rtl8168_ocp_read(tp, 0x124, 1) & BIT_0)
1784
-                                break;
1785
-                }
1786
+                rtl8168_wait_dash_fw_ready(tp);
1787
         } else {
1788
-                int timeout;
1789
-                u32 reg;
1790
 
1791
-                if (tp->mcfg == CFG_METHOD_13) {
1792
+                if (tp->mcfg == CFG_METHOD_13)
1793
                         RTL_W8(tp, TwiCmdReg, RTL_R8(tp, TwiCmdReg) | ( BIT_7 ));
1794
-                }
1795
 
1796
                 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START);
1797
 
1798
-                if (tp->mcfg == CFG_METHOD_13)
1799
-                        reg = 0xB8;
1800
-                else
1801
-                        reg = 0x10;
1802
-
1803
-                for (timeout = 0; timeout < 10; timeout++) {
1804
-                        mdelay(10);
1805
-                        if (rtl8168_ocp_read(tp, reg, 2) & BIT_11)
1806
-                                break;
1807
-                }
1808
+                rtl8168_wait_dash_fw_ready(tp);
1809
         }
1810
 }
1811
 
1812
 static void rtl8168_driver_stop(struct rtl8168_private *tp)
1813
 {
1814
-        if (!tp->DASH)
1815
-                goto update_device_state;
1816
-
1817
         if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) {
1818
                 struct net_device *dev = tp->dev;
1819
-                int timeout;
1820
                 u32 tmp_value;
1821
 
1822
                 rtl8168_dash2_disable_txrx(dev);
1823
@@ -3402,34 +4268,16 @@
1824
                 tmp_value |= BIT_0;
1825
                 rtl8168_ocp_write(tp, 0x30, 1, tmp_value);
1826
 
1827
-                for (timeout = 0; timeout < 10; timeout++) {
1828
-                        mdelay(10);
1829
-                        if (!(rtl8168_ocp_read(tp, 0x124, 1) & BIT_0))
1830
-                                break;
1831
-                }
1832
+                rtl8168_wait_dash_fw_ready(tp);
1833
         } else {
1834
-                int timeout;
1835
-                u32 reg;
1836
-
1837
                 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP);
1838
 
1839
-                if (tp->mcfg == CFG_METHOD_13)
1840
-                        reg = 0xB8;
1841
-                else
1842
-                        reg = 0x10;
1843
-
1844
-                for (timeout = 0; timeout < 10; timeout++) {
1845
-                        mdelay(10);
1846
-                        if ((rtl8168_ocp_read(tp, reg, 2) & BIT_11) == 0)
1847
-                                break;
1848
-                }
1849
+                rtl8168_wait_dash_fw_ready(tp);
1850
 
1851
-                if (tp->mcfg == CFG_METHOD_13) {
1852
+                if (tp->mcfg == CFG_METHOD_13)
1853
                         RTL_W8(tp, TwiCmdReg, RTL_R8(tp, TwiCmdReg) & ~( BIT_7 ));
1854
-                }
1855
         }
1856
 
1857
-update_device_state:
1858
         //change other device state to D3.
1859
         switch (tp->mcfg) {
1860
         case CFG_METHOD_23:
1861
@@ -3446,6 +4294,64 @@
1862
         }
1863
 }
1864
 
1865
+
1866
+static inline u16 rtl8168_get_isr_by_vector(struct rtl8168_private *tp,
1867
+                u32 message_id)
1868
+{
1869
+        if (message_id >= R8168_MAX_MSIX_VEC)
1870
+                return 0;
1871
+
1872
+        if (message_id == 0)
1873
+                return RTL_R16(tp, tp->isr_reg0);
1874
+        else
1875
+                return RTL_R8(tp, tp->isr_regmessage_id);
1876
+}
1877
+
1878
+static inline void rtl8168_clear_isr_by_vector(struct rtl8168_private *tp,
1879
+                u32 message_id, u16 val)
1880
+{
1881
+        if (message_id >= R8168_MAX_MSIX_VEC)
1882
+                return;
1883
+
1884
+        if (message_id == 0) {
1885
+                RTL_W16(tp, tp->isr_reg0, val);
1886
+
1887
+                if (val & RxDescUnavail)
1888
+                        tp->rx_ringmessage_id.rdu++;
1889
+                if (val & TxDescUnavail)
1890
+                        tp->tx_ringmessage_id.tdu++;
1891
+        } else {
1892
+                RTL_W8(tp, tp->isr_regmessage_id, val);
1893
+
1894
+                if (val & RxDU1)
1895
+                        tp->rx_ringmessage_id.rdu++;
1896
+        }
1897
+}
1898
+
1899
+static inline void rtl8168_self_clear_isr_by_vector(struct rtl8168_private *tp,
1900
+                u32 message_id)
1901
+{
1902
+        u16 val;
1903
+
1904
+        if (message_id >= R8168_MAX_MSIX_VEC)
1905
+                return;
1906
+
1907
+        val = rtl8168_get_isr_by_vector(tp, message_id);
1908
+        if ((message_id == 0) && (val & RxFIFOOver))
1909
+                tp->rx_fifo_of++;
1910
+
1911
+        switch (tp->mcfg) {
1912
+        case CFG_METHOD_9 ... CFG_METHOD_37:
1913
+                /* RX_OVERFLOW RE-START mechanism now HW handles it automatically*/
1914
+                if (message_id == 0)
1915
+                        val &= ~RxFIFOOver;
1916
+                break;
1917
+        default:
1918
+                break;
1919
+        }
1920
+        rtl8168_clear_isr_by_vector(tp, message_id, val);
1921
+}
1922
+
1923
 #ifdef ENABLE_DASH_SUPPORT
1924
 
1925
 inline void
1926
@@ -3472,34 +4378,57 @@
1927
 #endif
1928
 
1929
 static inline void
1930
-rtl8168_enable_hw_interrupt(struct rtl8168_private *tp)
1931
+rtl8168_enable_interrupt(struct rtl8168_private *tp)
1932
 {
1933
-        RTL_W16(tp, IntrMask, tp->intr_mask);
1934
+        int i;
1935
+        for (i=0; i<tp->num_rx_rings; i++)
1936
+                rtl8168_enable_interrupt_by_vector(tp, i);
1937
+}
1938
 
1939
-#ifdef ENABLE_DASH_SUPPORT
1940
-        if (tp->DASH)
1941
-                rtl8168_enable_dash2_interrupt(tp);
1942
-#endif
1943
+static inline void
1944
+rtl8168_enable_lib_interrupt(struct rtl8168_private *tp)
1945
+{
1946
+        int i;
1947
+
1948
+        for (i=1; i<rtl8168_tot_rx_rings(tp); i++)
1949
+                rtl8168_enable_interrupt_by_vector(tp, i);
1950
 }
1951
 
1952
 static inline void
1953
-rtl8168_disable_hw_interrupt(struct rtl8168_private *tp)
1954
+rtl8168_disable_interrupt(struct rtl8168_private *tp)
1955
 {
1956
-        RTL_W16(tp, IntrMask, 0x0000);
1957
+        int i;
1958
 
1959
-#ifdef ENABLE_DASH_SUPPORT
1960
-        if (tp->DASH)
1961
-                rtl8168_disable_dash2_interrupt(tp);
1962
-#endif
1963
+        for (i=0; i<tp->num_rx_rings; i++)
1964
+                rtl8168_disable_interrupt_by_vector(tp, i);
1965
 }
1966
 
1967
+static inline void
1968
+rtl8168_disable_lib_interrupt(struct rtl8168_private *tp)
1969
+{
1970
+        int i;
1971
+
1972
+        for (i=1; i<rtl8168_tot_rx_rings(tp); i++)
1973
+                rtl8168_disable_interrupt_by_vector(tp, i);
1974
+}
1975
+
1976
+static inline void
1977
+rtl8168_disable_all_interrupt(struct rtl8168_private *tp)
1978
+{
1979
+        int i;
1980
+
1981
+        for (i=0; i<tp->hw_supp_irq_nvecs; i++)
1982
+                rtl8168_disable_interrupt_by_vector(tp, i);
1983
+}
1984
 
1985
 static inline void
1986
 rtl8168_switch_to_hw_interrupt(struct rtl8168_private *tp)
1987
 {
1988
         RTL_W32(tp, TimeInt0, 0x0000);
1989
 
1990
-        rtl8168_enable_hw_interrupt(tp);
1991
+        rtl8168_enable_interrupt(tp);
1992
+
1993
+        rtl8168_enable_lib_interrupt(tp);
1994
 }
1995
 
1996
 static inline void
1997
@@ -3508,7 +4437,7 @@
1998
         if (tp->use_timer_interrrupt) {
1999
                 RTL_W32(tp, TimeInt0, timer_count);
2000
                 RTL_W32(tp, TCTR, timer_count);
2001
-                RTL_W16(tp, IntrMask, tp->timer_intr_mask);
2002
+                RTL_W16(tp, tp->imr_reg0, tp->timer_intr_mask);
2003
 
2004
 #ifdef ENABLE_DASH_SUPPORT
2005
                 if (tp->DASH)
2006
@@ -3522,23 +4451,38 @@
2007
 static void
2008
 rtl8168_irq_mask_and_ack(struct rtl8168_private *tp)
2009
 {
2010
-        rtl8168_disable_hw_interrupt(tp);
2011
+        rtl8168_disable_all_interrupt(tp);
2012
 #ifdef ENABLE_DASH_SUPPORT
2013
         if (tp->DASH) {
2014
                 if (tp->dash_printer_enabled) {
2015
-                        RTL_W16(tp, IntrStatus, RTL_R16(tp, IntrStatus) &
2016
-                                ~(ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET));
2017
+                        rtl8168_clear_isr_by_vector(tp, 0,
2018
+                                                    rtl8168_get_hw_isr_by_vector(tp, 0) &
2019
+                                                    ~(ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET));
2020
                 } else {
2021
                         if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) {
2022
                                 RTL_CMAC_W8(tp, CMAC_IBISR0, RTL_CMAC_R8(tp, CMAC_IBISR0));
2023
                         }
2024
                 }
2025
         } else {
2026
-                RTL_W16(tp, IntrStatus, RTL_R16(tp, IntrStatus));
2027
+                rtl8168_self_clear_isr_by_vector(tp, 0);
2028
         }
2029
 #else
2030
-        RTL_W16(tp, IntrStatus, RTL_R16(tp, IntrStatus));
2031
+        rtl8168_self_clear_isr_by_vector(tp, 0);
2032
 #endif
2033
+        if (tp->hw_supp_irq_nvecs > 1) {
2034
+                int i;
2035
+                for (i=1; i<tp->hw_supp_irq_nvecs; i++)
2036
+                        rtl8168_self_clear_isr_by_vector(tp, i);
2037
+        }
2038
+}
2039
+
2040
+static void
2041
+rtl8168_disable_rx_packet_filter(struct rtl8168_private *tp)
2042
+{
2043
+
2044
+        RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) &
2045
+                ~(AcceptErr | AcceptRunt |AcceptBroadcast | AcceptMulticast |
2046
+                  AcceptMyPhys |  AcceptAllPhys));
2047
 }
2048
 
2049
 static void
2050
@@ -3547,7 +4491,7 @@
2051
         struct rtl8168_private *tp = netdev_priv(dev);
2052
         int i;
2053
 
2054
-        RTL_W32(tp, RxConfig, (RX_DMA_BURST << RxCfgDMAShift));
2055
+        rtl8168_disable_rx_packet_filter(tp);
2056
 
2057
         rtl8168_enable_rxdvgate(dev);
2058
 
2059
@@ -3592,6 +4536,8 @@
2060
         case CFG_METHOD_33:
2061
         case CFG_METHOD_34:
2062
         case CFG_METHOD_35:
2063
+        case CFG_METHOD_36:
2064
+        case CFG_METHOD_37:
2065
                 mdelay(2);
2066
                 break;
2067
         default:
2068
@@ -3675,6 +4621,8 @@
2069
         case CFG_METHOD_33:
2070
         case CFG_METHOD_34:
2071
         case CFG_METHOD_35:
2072
+        case CFG_METHOD_36:
2073
+        case CFG_METHOD_37:
2074
                 RTL_W32(tp, TimeInt1, 0x0000);
2075
                 RTL_W32(tp, TimeInt2, 0x0000);
2076
                 RTL_W32(tp, TimeInt3, 0x0000);
2077
@@ -3682,11 +4630,13 @@
2078
         }
2079
 }
2080
 
2081
-static void
2082
+void
2083
 rtl8168_hw_reset(struct net_device *dev)
2084
 {
2085
         struct rtl8168_private *tp = netdev_priv(dev);
2086
 
2087
+        rtl8168_lib_reset_prepare(tp);
2088
+
2089
         /* Disable interrupts */
2090
         rtl8168_irq_mask_and_ack(tp);
2091
 
2092
@@ -3695,8 +4645,20 @@
2093
         rtl8168_nic_reset(dev);
2094
 }
2095
 
2096
+static void rtl8168_doorbell(struct rtl8168_tx_ring *ring)
2097
+{
2098
+        struct rtl8168_private *tp = ring->priv;
2099
+
2100
+        if (ring->index > 0)
2101
+                RTL_W8(tp, TxPoll, HPQ);
2102
+        else
2103
+                RTL_W8(tp, TxPoll, NPQ);
2104
+}
2105
+
2106
 static void rtl8168_mac_loopback_test(struct rtl8168_private *tp)
2107
 {
2108
+        struct rtl8168_tx_ring *tx_ring = &tp->tx_ring0;
2109
+        struct rtl8168_rx_ring *rx_ring = &tp->rx_ring0;
2110
         struct pci_dev *pdev = tp->pci_dev;
2111
         struct net_device *dev = tp->dev;
2112
         struct sk_buff *skb, *rx_skb;
2113
@@ -3715,9 +4677,9 @@
2114
         pattern = 0x5A;
2115
         len = 60;
2116
         type = htons(ETH_P_IP);
2117
-        txd = tp->TxDescArray;
2118
-        rxd = tp->RxDescArray;
2119
-        rx_skb = tp->Rx_skbuff0;
2120
+        txd = tx_ring->TxDescArray;
2121
+        rxd = rtl8168_get_rxdesc(tp, tp->RxDescArray, 0, rx_ring->index);
2122
+        rx_skb = rx_ring->Rx_skbuff0;
2123
         RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) & ~0x00060000) | 0x00020000);
2124
 
2125
         do {
2126
@@ -3747,7 +4709,7 @@
2127
                 RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig)  | AcceptMyPhys);
2128
 
2129
                 smp_wmb();
2130
-                RTL_W8(tp, TxPoll, NPQ);    /* set polling bit */
2131
+                rtl8168_doorbell(tx_ring);    /* set polling bit */
2132
 
2133
                 for (i = 0; i < 50; i++) {
2134
                         udelay(200);
2135
@@ -3778,15 +4740,15 @@
2136
                 rtl8168_disable_rxdvgate(dev);
2137
                 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
2138
         }
2139
-        tp->dirty_tx++;
2140
-        tp->dirty_rx++;
2141
-        tp->cur_tx++;
2142
-        tp->cur_rx++;
2143
+        tx_ring->dirty_tx++;
2144
+        rx_ring->dirty_rx++;
2145
+        tx_ring->cur_tx++;
2146
+        rx_ring->cur_rx++;
2147
         dma_unmap_single(&pdev->dev, le64_to_cpu(mapping),
2148
                          len, DMA_TO_DEVICE);
2149
         RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) & ~0x00060000);
2150
         dev_kfree_skb_any(skb);
2151
-        RTL_W16(tp, IntrStatus, 0xFFBF);
2152
+        rtl8168_clear_isr_by_vector(tp, 0, 0xFFBF);
2153
 }
2154
 
2155
 static unsigned int
2156
@@ -3805,11 +4767,13 @@
2157
 rtl8168_xmii_link_ok(struct net_device *dev)
2158
 {
2159
         struct rtl8168_private *tp = netdev_priv(dev);
2160
-        unsigned int retval;
2161
+        u8 status;
2162
 
2163
-        retval = (RTL_R8(tp, PHYstatus) & LinkStatus) ? 1 : 0;
2164
+        status = RTL_R8(tp, PHYstatus);
2165
+        if (status == 0xff)
2166
+                return 0;
2167
 
2168
-        return retval;
2169
+        return (status & LinkStatus) ? 1 : 0;
2170
 }
2171
 
2172
 static int
2173
@@ -3868,10 +4832,37 @@
2174
 
2175
 void rtl8168_init_ring_indexes(struct rtl8168_private *tp)
2176
 {
2177
-        tp->dirty_tx = 0;
2178
-        tp->dirty_rx = 0;
2179
-        tp->cur_tx = 0;
2180
-        tp->cur_rx = 0;
2181
+        int i;
2182
+
2183
+        for (i = 0; i < tp->HwSuppNumTxQueues; i++) {
2184
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
2185
+                ring->dirty_tx = ring->cur_tx = 0;
2186
+                ring->index = i;
2187
+                ring->priv = tp;
2188
+        }
2189
+
2190
+        for (i = 0; i < tp->HwSuppNumRxQueues; i++) {
2191
+                struct rtl8168_rx_ring *ring = &tp->rx_ringi;
2192
+                ring->dirty_rx = ring->cur_rx = 0;
2193
+                ring->index = i;
2194
+                ring->priv = tp;
2195
+        }
2196
+
2197
+#ifdef ENABLE_LIB_SUPPORT
2198
+        for (i = 0; i < tp->HwSuppNumTxQueues; i++) {
2199
+                struct rtl8168_ring *ring = &tp->lib_tx_ringi;
2200
+                ring->direction = RTL8168_CH_DIR_TX;
2201
+                ring->queue_num = i;
2202
+                ring->private = tp;
2203
+        }
2204
+
2205
+        for (i = 0; i < tp->HwSuppNumRxQueues; i++) {
2206
+                struct rtl8168_ring *ring = &tp->lib_rx_ringi;
2207
+                ring->direction = RTL8168_CH_DIR_RX;
2208
+                ring->queue_num = i;
2209
+                ring->private = tp;
2210
+        }
2211
+#endif
2212
 }
2213
 
2214
 static void
2215
@@ -3904,6 +4895,8 @@
2216
         case CFG_METHOD_33:
2217
         case CFG_METHOD_34:
2218
         case CFG_METHOD_35:
2219
+        case CFG_METHOD_36:
2220
+        case CFG_METHOD_37:
2221
                 csi_tmp = rtl8168_eri_read(tp, 0x1EA, 1, ERIAR_ExGMAC);
2222
                 csi_tmp |= BIT_0;
2223
                 rtl8168_eri_write(tp, 0x1EA, 1, csi_tmp, ERIAR_ExGMAC);
2224
@@ -3942,7 +4935,7 @@
2225
                 csi_tmp |= (BIT_10 | BIT_11);
2226
                 rtl8168_eri_write(tp, 0xD4, 4, csi_tmp, ERIAR_ExGMAC);
2227
                 break;
2228
-        case CFG_METHOD_21 ... CFG_METHOD_35:
2229
+        case CFG_METHOD_21 ... CFG_METHOD_37:
2230
                 csi_tmp = rtl8168_eri_read(tp, 0xD4, 4, ERIAR_ExGMAC);
2231
                 csi_tmp |= (BIT_7 | BIT_8 | BIT_9 | BIT_10 | BIT_11 | BIT_12);
2232
                 rtl8168_eri_write(tp, 0xD4, 4, csi_tmp, ERIAR_ExGMAC);
2233
@@ -3969,7 +4962,7 @@
2234
                 csi_tmp &= ~(BIT_10 | BIT_11);
2235
                 rtl8168_eri_write(tp, 0xD4, 4, csi_tmp, ERIAR_ExGMAC);
2236
                 break;
2237
-        case CFG_METHOD_21 ... CFG_METHOD_35:
2238
+        case CFG_METHOD_21 ... CFG_METHOD_37:
2239
                 csi_tmp = rtl8168_eri_read(tp, 0xD4, 4, ERIAR_ExGMAC);
2240
                 csi_tmp &= ~(BIT_7 | BIT_8 | BIT_9 | BIT_10 | BIT_11 | BIT_12);
2241
                 rtl8168_eri_write(tp, 0xD4, 4, csi_tmp, ERIAR_ExGMAC);
2242
@@ -4004,174 +4997,188 @@
2243
                 //
2244
                 if (HW_DASH_SUPPORT_TYPE_2(tp) || HW_DASH_SUPPORT_TYPE_3(tp)) {
2245
                         rtl8168_enable_dash2_interrupt(tp);
2246
-                        RTL_W16(tp, IntrMask, (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET));
2247
+                        RTL_W16(tp, tp->imr_reg0, (ISRIMR_DASH_INTR_EN | ISRIMR_DASH_INTR_CMAC_RESET));
2248
                 } else {
2249
-                        RTL_W16(tp, IntrMask, (ISRIMR_DP_DASH_OK | ISRIMR_DP_HOST_OK | ISRIMR_DP_REQSYS_OK));
2250
+                        RTL_W16(tp, tp->imr_reg0, (ISRIMR_DP_DASH_OK | ISRIMR_DP_HOST_OK | ISRIMR_DP_REQSYS_OK));
2251
                 }
2252
         }
2253
 }
2254
 #endif
2255
 
2256
 static void
2257
-rtl8168_check_link_status(struct net_device *dev)
2258
+rtl8168_link_on_patch(struct net_device *dev)
2259
 {
2260
         struct rtl8168_private *tp = netdev_priv(dev);
2261
-        int link_status_on;
2262
-
2263
-#ifdef ENABLE_FIBER_SUPPORT
2264
-        rtl8168_check_fiber_link_status(tp);
2265
-#endif //ENABLE_FIBER_SUPPORT
2266
-
2267
-        link_status_on = tp->link_ok(dev);
2268
 
2269
-        if (tp->mcfg == CFG_METHOD_11)
2270
-                rtl8168dp_10mbps_gphy_para(dev);
2271
-
2272
-        if (netif_carrier_ok(dev) != link_status_on) {
2273
-                if (link_status_on) {
2274
-                        rtl8168_hw_config(dev);
2275
+        rtl8168_hw_config(dev);
2276
 
2277
-                        if (tp->mcfg == CFG_METHOD_18 || tp->mcfg == CFG_METHOD_19 || tp->mcfg == CFG_METHOD_20) {
2278
-                                if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
2279
-                                        rtl8168_eri_write(tp, 0x1bc, 4, 0x00000011, ERIAR_ExGMAC);
2280
-                                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000001f, ERIAR_ExGMAC);
2281
-                                } else if (RTL_R8(tp, PHYstatus) & _100bps) {
2282
-                                        rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2283
-                                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000001f, ERIAR_ExGMAC);
2284
-                                } else {
2285
-                                        rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2286
-                                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000002d, ERIAR_ExGMAC);
2287
-                                }
2288
-                        } else if ((tp->mcfg == CFG_METHOD_16 || tp->mcfg == CFG_METHOD_17) && netif_running(dev)) {
2289
-                                if (tp->mcfg == CFG_METHOD_16 && (RTL_R8(tp, PHYstatus) & _10bps)) {
2290
-                                        RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | AcceptAllPhys);
2291
-                                } else if (tp->mcfg == CFG_METHOD_17) {
2292
-                                        if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
2293
-                                                rtl8168_eri_write(tp, 0x1bc, 4, 0x00000011, ERIAR_ExGMAC);
2294
-                                                rtl8168_eri_write(tp, 0x1dc, 4, 0x00000005, ERIAR_ExGMAC);
2295
-                                        } else if (RTL_R8(tp, PHYstatus) & _100bps) {
2296
-                                                rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2297
-                                                rtl8168_eri_write(tp, 0x1dc, 4, 0x00000005, ERIAR_ExGMAC);
2298
-                                        } else {
2299
-                                                rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2300
-                                                rtl8168_eri_write(tp, 0x1dc, 4, 0x0000003f, ERIAR_ExGMAC);
2301
-                                        }
2302
-                                }
2303
-                        } else if ((tp->mcfg == CFG_METHOD_14 || tp->mcfg == CFG_METHOD_15) && tp->eee_enabled == 1) {
2304
-                                /*Full -Duplex  mode*/
2305
-                                if (RTL_R8(tp, PHYstatus)&FullDup) {
2306
-                                        rtl8168_mdio_write(tp, 0x1F, 0x0006);
2307
-                                        rtl8168_mdio_write(tp, 0x00, 0x5a30);
2308
-                                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2309
-                                        if (RTL_R8(tp, PHYstatus) & (_10bps | _100bps))
2310
-                                                RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) & ~BIT_19) | BIT_25);
2311
-
2312
-                                } else {
2313
-                                        rtl8168_mdio_write(tp, 0x1F, 0x0006);
2314
-                                        rtl8168_mdio_write(tp, 0x00, 0x5a00);
2315
-                                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2316
-                                        if (RTL_R8(tp, PHYstatus) & (_10bps | _100bps))
2317
-                                                RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) & ~BIT_19) | (InterFrameGap << TxInterFrameGapShift));
2318
-                                }
2319
-                        } else if ((tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
2320
-                                    tp->mcfg == CFG_METHOD_23 || tp->mcfg == CFG_METHOD_24 ||
2321
-                                    tp->mcfg == CFG_METHOD_25 || tp->mcfg == CFG_METHOD_26 ||
2322
-                                    tp->mcfg == CFG_METHOD_27 || tp->mcfg == CFG_METHOD_28 ||
2323
-                                    tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2324
-                                    tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2325
-                                    tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2326
-                                    tp->mcfg == CFG_METHOD_35) &&
2327
-                                   netif_running(dev)) {
2328
-                                if (RTL_R8(tp, PHYstatus)&FullDup)
2329
-                                        RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) | (BIT_24 | BIT_25)) & ~BIT_19);
2330
-                                else
2331
-                                        RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) | BIT_25) & ~(BIT_19 | BIT_24));
2332
+        if (tp->mcfg == CFG_METHOD_18 || tp->mcfg == CFG_METHOD_19 || tp->mcfg == CFG_METHOD_20) {
2333
+                if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
2334
+                        rtl8168_eri_write(tp, 0x1bc, 4, 0x00000011, ERIAR_ExGMAC);
2335
+                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000001f, ERIAR_ExGMAC);
2336
+                } else if (RTL_R8(tp, PHYstatus) & _100bps) {
2337
+                        rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2338
+                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000001f, ERIAR_ExGMAC);
2339
+                } else {
2340
+                        rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2341
+                        rtl8168_eri_write(tp, 0x1dc, 4, 0x0000002d, ERIAR_ExGMAC);
2342
+                }
2343
+        } else if ((tp->mcfg == CFG_METHOD_16 || tp->mcfg == CFG_METHOD_17) && netif_running(dev)) {
2344
+                if (tp->mcfg == CFG_METHOD_16 && (RTL_R8(tp, PHYstatus) & _10bps)) {
2345
+                        RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | AcceptAllPhys);
2346
+                } else if (tp->mcfg == CFG_METHOD_17) {
2347
+                        if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
2348
+                                rtl8168_eri_write(tp, 0x1bc, 4, 0x00000011, ERIAR_ExGMAC);
2349
+                                rtl8168_eri_write(tp, 0x1dc, 4, 0x00000005, ERIAR_ExGMAC);
2350
+                        } else if (RTL_R8(tp, PHYstatus) & _100bps) {
2351
+                                rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2352
+                                rtl8168_eri_write(tp, 0x1dc, 4, 0x00000005, ERIAR_ExGMAC);
2353
+                        } else {
2354
+                                rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2355
+                                rtl8168_eri_write(tp, 0x1dc, 4, 0x0000003f, ERIAR_ExGMAC);
2356
                         }
2357
+                }
2358
+        } else if ((tp->mcfg == CFG_METHOD_14 || tp->mcfg == CFG_METHOD_15) && tp->eee.eee_enabled == 1) {
2359
+                /*Full -Duplex  mode*/
2360
+                if (RTL_R8(tp, PHYstatus)&FullDup) {
2361
+                        rtl8168_mdio_write(tp, 0x1F, 0x0006);
2362
+                        rtl8168_mdio_write(tp, 0x00, 0x5a30);
2363
+                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2364
+                        if (RTL_R8(tp, PHYstatus) & (_10bps | _100bps))
2365
+                                RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) & ~BIT_19) | BIT_25);
2366
 
2367
-                        if (tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
2368
-                            tp->mcfg == CFG_METHOD_27 || tp->mcfg == CFG_METHOD_28 ||
2369
-                            tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2370
-                            tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) {
2371
-                                /*half mode*/
2372
-                                if (!(RTL_R8(tp, PHYstatus)&FullDup)) {
2373
-                                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2374
-                                        rtl8168_mdio_write(tp, MII_ADVERTISE, rtl8168_mdio_read(tp, MII_ADVERTISE)&~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM));
2375
-                                }
2376
-                        }
2377
+                } else {
2378
+                        rtl8168_mdio_write(tp, 0x1F, 0x0006);
2379
+                        rtl8168_mdio_write(tp, 0x00, 0x5a00);
2380
+                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2381
+                        if (RTL_R8(tp, PHYstatus) & (_10bps | _100bps))
2382
+                                RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) & ~BIT_19) | (InterFrameGap << TxInterFrameGapShift));
2383
+                }
2384
+        } else if ((tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
2385
+                    tp->mcfg == CFG_METHOD_23 || tp->mcfg == CFG_METHOD_24 ||
2386
+                    tp->mcfg == CFG_METHOD_25 || tp->mcfg == CFG_METHOD_26 ||
2387
+                    tp->mcfg == CFG_METHOD_27 || tp->mcfg == CFG_METHOD_28 ||
2388
+                    tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2389
+                    tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2390
+                    tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2391
+                    tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
2392
+                    tp->mcfg == CFG_METHOD_37) && netif_running(dev)) {
2393
+                if (RTL_R8(tp, PHYstatus)&FullDup)
2394
+                        RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) | (BIT_24 | BIT_25)) & ~BIT_19);
2395
+                else
2396
+                        RTL_W32(tp, TxConfig, (RTL_R32(tp, TxConfig) | BIT_25) & ~(BIT_19 | BIT_24));
2397
+        }
2398
 
2399
-                        if ((tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2400
-                             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) &&
2401
-                            (RTL_R8(tp, PHYstatus) & _10bps)) {
2402
-                                u32 csi_tmp;
2403
-
2404
-                                csi_tmp = rtl8168_eri_read(tp, 0x1D0, 1, ERIAR_ExGMAC);
2405
-                                csi_tmp |= BIT_1;
2406
-                                rtl8168_eri_write(tp, 0x1D0, 1, csi_tmp, ERIAR_ExGMAC);
2407
-                        }
2408
+        if (tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
2409
+            tp->mcfg == CFG_METHOD_27 || tp->mcfg == CFG_METHOD_28 ||
2410
+            tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2411
+            tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) {
2412
+                /*half mode*/
2413
+                if (!(RTL_R8(tp, PHYstatus)&FullDup)) {
2414
+                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2415
+                        rtl8168_mdio_write(tp, MII_ADVERTISE, rtl8168_mdio_read(tp, MII_ADVERTISE)&~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM));
2416
+                }
2417
+        }
2418
+
2419
+        if ((tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2420
+             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34) &&
2421
+            (RTL_R8(tp, PHYstatus) & _10bps)) {
2422
+                u32 csi_tmp;
2423
 
2424
-                        rtl8168_hw_start(dev);
2425
+                csi_tmp = rtl8168_eri_read(tp, 0x1D0, 1, ERIAR_ExGMAC);
2426
+                csi_tmp |= BIT_1;
2427
+                rtl8168_eri_write(tp, 0x1D0, 1, csi_tmp, ERIAR_ExGMAC);
2428
+        }
2429
 
2430
-                        netif_carrier_on(dev);
2431
+        rtl8168_hw_start(dev);
2432
 
2433
-                        netif_wake_queue(dev);
2434
+        netif_carrier_on(dev);
2435
 
2436
-                        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2437
-                        tp->phy_reg_aner = rtl8168_mdio_read(tp, MII_EXPANSION);
2438
-                        tp->phy_reg_anlpar = rtl8168_mdio_read(tp, MII_LPA);
2439
-                        tp->phy_reg_gbsr = rtl8168_mdio_read(tp, MII_STAT1000);
2440
+        netif_tx_wake_all_queues(dev);
2441
 
2442
-                        if (netif_msg_ifup(tp))
2443
-                                printk(KERN_INFO PFX "%s: link up\n", dev->name);
2444
-                } else {
2445
-                        if (netif_msg_ifdown(tp))
2446
-                                printk(KERN_INFO PFX "%s: link down\n", dev->name);
2447
+        rtl8168_mdio_write(tp, 0x1F, 0x0000);
2448
+        tp->phy_reg_aner = rtl8168_mdio_read(tp, MII_EXPANSION);
2449
+        tp->phy_reg_anlpar = rtl8168_mdio_read(tp, MII_LPA);
2450
+        tp->phy_reg_gbsr = rtl8168_mdio_read(tp, MII_STAT1000);
2451
+}
2452
 
2453
-                        tp->phy_reg_aner = 0;
2454
-                        tp->phy_reg_anlpar = 0;
2455
-                        tp->phy_reg_gbsr = 0;
2456
+static void
2457
+rtl8168_link_down_patch(struct net_device *dev)
2458
+{
2459
+        struct rtl8168_private *tp = netdev_priv(dev);
2460
 
2461
-                        netif_stop_queue(dev);
2462
+        tp->phy_reg_aner = 0;
2463
+        tp->phy_reg_anlpar = 0;
2464
+        tp->phy_reg_gbsr = 0;
2465
 
2466
-                        netif_carrier_off(dev);
2467
+        netif_carrier_off(dev);
2468
 
2469
-                        rtl8168_hw_reset(dev);
2470
+        netif_tx_disable(dev);
2471
 
2472
-                        rtl8168_tx_clear(tp);
2473
+        rtl8168_hw_reset(dev);
2474
 
2475
-                        rtl8168_rx_clear(tp);
2476
+        rtl8168_tx_clear(tp);
2477
 
2478
-                        rtl8168_init_ring(dev);
2479
+        rtl8168_rx_clear(tp);
2480
 
2481
-                        if (dynamic_aspm) {
2482
-                                rtl8168_enable_cfg9346_write(tp);
2483
-                                rtl8168_hw_aspm_clkreq_enable(tp, true);
2484
-                                rtl8168_disable_cfg9346_write(tp);
2485
-                        }
2486
+        rtl8168_init_ring(dev);
2487
 
2488
-                        rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
2489
+        if (dynamic_aspm) {
2490
+                rtl8168_enable_cfg9346_write(tp);
2491
+                rtl8168_hw_aspm_clkreq_enable(tp, true);
2492
+                rtl8168_disable_cfg9346_write(tp);
2493
+        }
2494
 
2495
-                        switch (tp->mcfg) {
2496
-                        case CFG_METHOD_21:
2497
-                        case CFG_METHOD_22:
2498
-                        case CFG_METHOD_23:
2499
-                        case CFG_METHOD_24:
2500
-                        case CFG_METHOD_25:
2501
-                        case CFG_METHOD_27:
2502
-                        case CFG_METHOD_28:
2503
-                        case CFG_METHOD_31:
2504
-                        case CFG_METHOD_32:
2505
-                        case CFG_METHOD_33:
2506
-                        case CFG_METHOD_34:
2507
-                                if (tp->org_pci_offset_99 & BIT_2)
2508
-                                        tp->issue_offset_99_event = TRUE;
2509
-                                break;
2510
-                        }
2511
+        switch (tp->mcfg) {
2512
+        case CFG_METHOD_21:
2513
+        case CFG_METHOD_22:
2514
+        case CFG_METHOD_23:
2515
+        case CFG_METHOD_24:
2516
+        case CFG_METHOD_25:
2517
+        case CFG_METHOD_27:
2518
+        case CFG_METHOD_28:
2519
+        case CFG_METHOD_31:
2520
+        case CFG_METHOD_32:
2521
+        case CFG_METHOD_33:
2522
+        case CFG_METHOD_34:
2523
+                if (tp->org_pci_offset_99 & BIT_2)
2524
+                        tp->issue_offset_99_event = TRUE;
2525
+                break;
2526
+        }
2527
 
2528
 #ifdef ENABLE_DASH_SUPPORT
2529
-                        if (tp->DASH) {
2530
-                                NICChkTypeEnableDashInterrupt(tp);
2531
-                        }
2532
+        if (tp->DASH) {
2533
+                NICChkTypeEnableDashInterrupt(tp);
2534
+        }
2535
 #endif
2536
+}
2537
+
2538
+static void
2539
+rtl8168_check_link_status(struct net_device *dev)
2540
+{
2541
+        struct rtl8168_private *tp = netdev_priv(dev);
2542
+        int link_status_on;
2543
+
2544
+#ifdef ENABLE_FIBER_SUPPORT
2545
+        rtl8168_check_fiber_link_status(tp);
2546
+#endif //ENABLE_FIBER_SUPPORT
2547
+
2548
+        link_status_on = tp->link_ok(dev);
2549
+
2550
+        if (tp->mcfg == CFG_METHOD_11)
2551
+                rtl8168dp_10mbps_gphy_para(dev);
2552
+
2553
+        if (netif_carrier_ok(dev) != link_status_on) {
2554
+                if (link_status_on) {
2555
+                        rtl8168_link_on_patch(dev);
2556
+
2557
+                        if (netif_msg_ifup(tp))
2558
+                                printk(KERN_INFO PFX "%s: link up\n", dev->name);
2559
+                } else {
2560
+                        if (netif_msg_ifdown(tp))
2561
+                                printk(KERN_INFO PFX "%s: link down\n", dev->name);
2562
+
2563
+                        rtl8168_link_down_patch(dev);
2564
                 }
2565
         }
2566
 
2567
@@ -4251,7 +5258,8 @@
2568
             tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2569
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2570
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2571
-            tp->mcfg == CFG_METHOD_35) {
2572
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
2573
+            tp->mcfg == CFG_METHOD_37) {
2574
                 val = rtl8168_mdio_read_phy_ocp(tp, 0x0C41, 0x13);
2575
                 if (val != 0x0050) {
2576
                         rtl8168_set_phy_mcu_patch_request(tp);
2577
@@ -4273,7 +5281,8 @@
2578
             tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2579
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2580
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2581
-            tp->mcfg == CFG_METHOD_35) {
2582
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
2583
+            tp->mcfg == CFG_METHOD_37) {
2584
                 val = rtl8168_mdio_read_phy_ocp(tp, 0x0C41, 0x13);
2585
                 if (val != 0x0500) {
2586
                         rtl8168_set_phy_mcu_patch_request(tp);
2587
@@ -4318,6 +5327,8 @@
2588
         case CFG_METHOD_33:
2589
         case CFG_METHOD_34:
2590
         case CFG_METHOD_35:
2591
+        case CFG_METHOD_36:
2592
+        case CFG_METHOD_37:
2593
                 csi_tmp = rtl8168_eri_read(tp, 0x3F2, 2, ERIAR_ExGMAC);
2594
                 csi_tmp &= ~(BIT_0 | BIT_1);
2595
                 rtl8168_eri_write(tp, 0x3F2, 2, csi_tmp, ERIAR_ExGMAC);
2596
@@ -4335,6 +5346,8 @@
2597
         case CFG_METHOD_33:
2598
         case CFG_METHOD_34:
2599
         case CFG_METHOD_35:
2600
+        case CFG_METHOD_36:
2601
+        case CFG_METHOD_37:
2602
                 rtl8168_csi_fun0_write_byte(tp, 0x99, 0x00);
2603
                 break;
2604
         }
2605
@@ -4356,6 +5369,8 @@
2606
         case CFG_METHOD_33:
2607
         case CFG_METHOD_34:
2608
         case CFG_METHOD_35:
2609
+        case CFG_METHOD_36:
2610
+        case CFG_METHOD_37:
2611
                 rtl8168_csi_fun0_write_byte(tp, 0x99, tp->org_pci_offset_99);
2612
                 break;
2613
         }
2614
@@ -4376,6 +5391,8 @@
2615
         case CFG_METHOD_33:
2616
         case CFG_METHOD_34:
2617
         case CFG_METHOD_35:
2618
+        case CFG_METHOD_36:
2619
+        case CFG_METHOD_37:
2620
                 csi_tmp = rtl8168_eri_read(tp, 0x3F2, 2, ERIAR_ExGMAC);
2621
                 csi_tmp &= ~(BIT_0 | BIT_1);
2622
                 if (tp->org_pci_offset_99 & (BIT_5 | BIT_6))
2623
@@ -4418,6 +5435,8 @@
2624
         case CFG_METHOD_33:
2625
         case CFG_METHOD_34:
2626
         case CFG_METHOD_35:
2627
+        case CFG_METHOD_36:
2628
+        case CFG_METHOD_37:
2629
                 csi_tmp = rtl8168_eri_read(tp, 0x3F2, 2, ERIAR_ExGMAC);
2630
                 csi_tmp &= ~( BIT_8 | BIT_9  | BIT_10 | BIT_11  | BIT_12  | BIT_13  | BIT_14 | BIT_15 );
2631
                 csi_tmp |= ( BIT_9 | BIT_10 | BIT_13  | BIT_14 | BIT_15 );
2632
@@ -4451,8 +5470,10 @@
2633
         case CFG_METHOD_33:
2634
         case CFG_METHOD_34:
2635
         case CFG_METHOD_35:
2636
+        case CFG_METHOD_36:
2637
+        case CFG_METHOD_37:
2638
                 if (tp->org_pci_offset_99 & BIT_2)
2639
-                        rtl8168_mac_ocp_write(tp, 0xE0A2,  rtl8168_mac_ocp_read(tp, 0xE0A2) | BIT_0);
2640
+                        rtl8168_mac_ocp_write(tp, 0xE0A2, rtl8168_mac_ocp_read(tp, 0xE0A2) | BIT_0);
2641
                 break;
2642
         }
2643
 
2644
@@ -4479,6 +5500,8 @@
2645
         case CFG_METHOD_33:
2646
         case CFG_METHOD_34:
2647
         case CFG_METHOD_35:
2648
+        case CFG_METHOD_36:
2649
+        case CFG_METHOD_37:
2650
                 rtl8168_eri_write(tp, 0x2E8, 2, 0x9003, ERIAR_ExGMAC);
2651
                 rtl8168_eri_write(tp, 0x2EA, 2, 0x9003, ERIAR_ExGMAC);
2652
                 rtl8168_eri_write(tp, 0x2EC, 2, 0x9003, ERIAR_ExGMAC);
2653
@@ -4507,6 +5530,8 @@
2654
         case CFG_METHOD_29:
2655
         case CFG_METHOD_30:
2656
         case CFG_METHOD_35:
2657
+        case CFG_METHOD_36:
2658
+        case CFG_METHOD_37:
2659
                 if (tp->org_pci_offset_99 & BIT_2)
2660
                         RTL_W8(tp, 0xB6, RTL_R8(tp, 0xB6) | BIT_0);
2661
                 break;
2662
@@ -4533,6 +5558,8 @@
2663
         case CFG_METHOD_33:
2664
         case CFG_METHOD_34:
2665
         case CFG_METHOD_35:
2666
+        case CFG_METHOD_36:
2667
+        case CFG_METHOD_37:
2668
                 csi_tmp = rtl8168_eri_read(tp, 0x1E2, 1, ERIAR_ExGMAC);
2669
                 csi_tmp &= ~BIT_2;
2670
                 rtl8168_eri_write(tp, 0x1E2, 1, csi_tmp, ERIAR_ExGMAC);
2671
@@ -4580,6 +5607,7 @@
2672
 
2673
         switch (tp->mcfg) {
2674
         case CFG_METHOD_35:
2675
+        case CFG_METHOD_36:
2676
                 csi_tmp = rtl8168_eri_read(tp, 0x1E8, 2, ERIAR_ExGMAC);
2677
                 csi_tmp &= ~(0xFFF0);
2678
                 csi_tmp |= 0x0640;
2679
@@ -4600,6 +5628,8 @@
2680
         case CFG_METHOD_29:
2681
         case CFG_METHOD_30:
2682
         case CFG_METHOD_35:
2683
+        case CFG_METHOD_36:
2684
+        case CFG_METHOD_37:
2685
                 csi_tmp = rtl8168_eri_read(tp, 0x1E2, 1, ERIAR_ExGMAC);
2686
                 csi_tmp |= BIT_2;
2687
                 rtl8168_eri_write(tp, 0x1E2, 1, csi_tmp, ERIAR_ExGMAC);
2688
@@ -4641,6 +5671,8 @@
2689
         case CFG_METHOD_33:
2690
         case CFG_METHOD_34:
2691
         case CFG_METHOD_35:
2692
+        case CFG_METHOD_36:
2693
+        case CFG_METHOD_37:
2694
                 if (tp->org_pci_offset_99 & BIT_2)
2695
                         rtl8168_issue_offset_99_event(tp);
2696
                 rtl8168_disable_pci_offset_99(tp);
2697
@@ -4660,17 +5692,63 @@
2698
         case CFG_METHOD_33:
2699
         case CFG_METHOD_34:
2700
         case CFG_METHOD_35:
2701
+        case CFG_METHOD_36:
2702
+        case CFG_METHOD_37:
2703
                 rtl8168_disable_pci_offset_180(tp);
2704
                 break;
2705
         }
2706
 }
2707
 
2708
 static void
2709
+rtl8168_set_rx_q_num(struct rtl8168_private *tp,
2710
+                     unsigned int num_rx_queues)
2711
+{
2712
+        u16 q_ctrl;
2713
+        u16 rx_q_num;
2714
+
2715
+        if (tp->HwSuppRxDescType != RX_DESC_RING_TYPE_2)
2716
+                return;
2717
+
2718
+        if (num_rx_queues > tp->HwSuppNumRxQueues ||
2719
+            num_rx_queues < 1)
2720
+                num_rx_queues = 1;
2721
+
2722
+        rx_q_num = (u16)ilog2(num_rx_queues);
2723
+        rx_q_num &= (BIT_0 | BIT_1 | BIT_2);
2724
+        rx_q_num <<= 2;
2725
+        q_ctrl = rtl8168_eri_read(tp, Q_NUM_CTRL_8168, 2, ERIAR_ExGMAC);
2726
+        q_ctrl &= ~(BIT_2 | BIT_3 | BIT_4);
2727
+        q_ctrl |= rx_q_num;
2728
+        rtl8168_eri_write(tp, Q_NUM_CTRL_8168, 2, q_ctrl, ERIAR_ExGMAC);
2729
+}
2730
+
2731
+void
2732
+rtl8168_set_rx_vlan_filter(struct rtl8168_private *tp)
2733
+{
2734
+        int i;
2735
+
2736
+        if (tp->HwSuppRxDescType != RX_DESC_RING_TYPE_2)
2737
+                return;
2738
+
2739
+        for (i = 1; i < 16; i++) {
2740
+                rtl8168_eri_write(tp, 0xf0 + 8*i, 4, 0xffff0000, ERIAR_ExGMAC);
2741
+                rtl8168_eri_write(tp, 0xf4 + 8*i, 4, 0xffffffff, ERIAR_ExGMAC);
2742
+        }
2743
+}
2744
+
2745
+static void
2746
 rtl8168_hw_d3_para(struct net_device *dev)
2747
 {
2748
         struct rtl8168_private *tp = netdev_priv(dev);
2749
 
2750
-        RTL_W16(tp, RxMaxSize, RX_BUF_SIZE);
2751
+        switch (tp->mcfg) {
2752
+        case CFG_METHOD_1 ... CFG_METHOD_26:
2753
+                RTL_W16(tp, RxMaxSize, RX_BUF_SIZE + 1);
2754
+                break;
2755
+        default:
2756
+                RTL_W16(tp, RxMaxSize, RX_BUF_SIZE);
2757
+                break;
2758
+        }
2759
 
2760
         if (tp->HwSuppAspmClkIntrLock) {
2761
                 RTL_W8(tp, 0xF1, RTL_R8(tp, 0xF1) & ~BIT_7);
2762
@@ -4684,6 +5762,7 @@
2763
 #ifdef ENABLE_REALWOW_SUPPORT
2764
         rtl8168_set_realwow_d3_para(dev);
2765
 #endif
2766
+        rtl8168_set_rx_q_num(tp, 1);
2767
 
2768
         if (tp->mcfg == CFG_METHOD_18 || tp->mcfg == CFG_METHOD_19 || tp->mcfg == CFG_METHOD_20) {
2769
                 rtl8168_eri_write(tp, 0x1bc, 4, 0x0000001f, ERIAR_ExGMAC);
2770
@@ -4727,8 +5806,9 @@
2771
 
2772
         switch (tp->mcfg) {
2773
         case CFG_METHOD_35:
2774
+        case CFG_METHOD_36:
2775
                 rtl8168_set_mcu_ocp_bit(tp, 0xD438, BIT_3);
2776
-                rtl8168_set_mcu_ocp_bit(tp, 0xDE38, BIT_2);
2777
+                rtl8168_set_mcu_ocp_bit(tp, 0xD438, BIT_2);
2778
                 rtl8168_clear_mcu_ocp_bit(tp, 0xDE28, (BIT_1 | BIT_0));
2779
                 rtl8168_set_mcu_ocp_bit(tp, 0xD438, (BIT_1 | BIT_0));
2780
                 break;
2781
@@ -4740,7 +5820,8 @@
2782
             tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2783
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2784
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2785
-            tp->mcfg == CFG_METHOD_35)
2786
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
2787
+            tp->mcfg == CFG_METHOD_37)
2788
                 if (!tp->dash_printer_enabled)
2789
                         rtl8168_disable_ocp_phy_power_saving(dev);
2790
 
2791
@@ -4794,15 +5875,14 @@
2792
         struct rtl8168_private *tp = netdev_priv(dev);
2793
         u8 options;
2794
         u32 csi_tmp;
2795
-        unsigned long flags;
2796
-
2797
 
2798
-        spin_lock_irqsave(&tp->lock, flags);
2799
+        if (disable_wol_support)
2800
+                goto out;
2801
 
2802
         tp->wol_opts = 0;
2803
         options = RTL_R8(tp, Config1);
2804
         if (!(options & PMEnable))
2805
-                goto out_unlock;
2806
+                goto out;
2807
 
2808
         options = RTL_R8(tp, Config3);
2809
         if (options & LinkUp)
2810
@@ -4828,10 +5908,8 @@
2811
         if (options & MWF)
2812
                 tp->wol_opts |= WAKE_MCAST;
2813
 
2814
-out_unlock:
2815
+out:
2816
         tp->wol_enabled = (tp->wol_opts || tp->dash_printer_enabled) ? WOL_ENABLED : WOL_DISABLED;
2817
-
2818
-        spin_unlock_irqrestore(&tp->lock, flags);
2819
 }
2820
 
2821
 static void
2822
@@ -5042,7 +6120,7 @@
2823
                     tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2824
                     tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2825
                     tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2826
-                    tp->mcfg == CFG_METHOD_35) {
2827
+                    tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36) {
2828
                         rtl8168_enable_cfg9346_write(tp);
2829
                         RTL_W8(tp, Config2, RTL_R8(tp, Config2) | PMSTS_En);
2830
                         rtl8168_disable_cfg9346_write(tp);
2831
@@ -5107,6 +6185,7 @@
2832
                 case CFG_METHOD_33:
2833
                 case CFG_METHOD_34:
2834
                 case CFG_METHOD_35:
2835
+                case CFG_METHOD_36:
2836
                         RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~BIT_7);
2837
                         break;
2838
                 }
2839
@@ -5116,7 +6195,7 @@
2840
         case CFG_METHOD_14 ... CFG_METHOD_15:
2841
                 RTL_W8(tp, 0xD0, RTL_R8(tp, 0xD0) & ~BIT_6);
2842
                 break;
2843
-        case CFG_METHOD_16 ... CFG_METHOD_35:
2844
+        case CFG_METHOD_16 ... CFG_METHOD_36:
2845
                 RTL_W8(tp, 0xD0, RTL_R8(tp, 0xD0) & ~BIT_6);
2846
                 RTL_W8(tp, 0xF2, RTL_R8(tp, 0xF2) & ~BIT_6);
2847
                 break;
2848
@@ -5152,6 +6231,7 @@
2849
         case CFG_METHOD_33:
2850
         case CFG_METHOD_34:
2851
         case CFG_METHOD_35:
2852
+        case CFG_METHOD_36:
2853
                 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | BIT_7 | BIT_6);
2854
                 break;
2855
         }
2856
@@ -5166,27 +6246,19 @@
2857
 {
2858
         struct rtl8168_private *tp = netdev_priv(dev);
2859
         u8 options;
2860
-        unsigned long flags;
2861
 
2862
-        wol->wolopts = 0;
2863
+        wol->wolopts = wol->supported = 0;
2864
 
2865
-        if (tp->mcfg == CFG_METHOD_DEFAULT) {
2866
-                wol->supported = 0;
2867
+        if (disable_wol_support)
2868
                 return;
2869
-        } else {
2870
-                wol->supported = WAKE_ANY;
2871
-        }
2872
 
2873
-        spin_lock_irqsave(&tp->lock, flags);
2874
+        wol->supported = WAKE_ANY;
2875
 
2876
         options = RTL_R8(tp, Config1);
2877
         if (!(options & PMEnable))
2878
-                goto out_unlock;
2879
+                return;
2880
 
2881
         wol->wolopts = tp->wol_opts;
2882
-
2883
-out_unlock:
2884
-        spin_unlock_irqrestore(&tp->lock, flags);
2885
 }
2886
 
2887
 static int
2888
@@ -5194,19 +6266,14 @@
2889
                 struct ethtool_wolinfo *wol)
2890
 {
2891
         struct rtl8168_private *tp = netdev_priv(dev);
2892
-        unsigned long flags;
2893
 
2894
-        if (tp->mcfg == CFG_METHOD_DEFAULT)
2895
+        if (disable_wol_support)
2896
                 return -EOPNOTSUPP;
2897
 
2898
-        spin_lock_irqsave(&tp->lock, flags);
2899
-
2900
         tp->wol_opts = wol->wolopts;
2901
 
2902
         tp->wol_enabled = (tp->wol_opts || tp->dash_printer_enabled) ? WOL_ENABLED : WOL_DISABLED;
2903
 
2904
-        spin_unlock_irqrestore(&tp->lock, flags);
2905
-
2906
         device_set_wakeup_enable(tp_to_dev(tp), tp->wol_enabled);
2907
 
2908
         return 0;
2909
@@ -5221,7 +6288,7 @@
2910
 
2911
         strcpy(info->driver, MODULENAME);
2912
         strcpy(info->version, RTL8168_VERSION);
2913
-        strcpy(info->bus_info, pci_name(tp->pci_dev));
2914
+        strncpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info) - 1);
2915
         info->regdump_len = R8168_REGS_DUMP_SIZE;
2916
         info->eedump_len = tp->eeprom_len;
2917
         BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version));
2918
@@ -5252,7 +6319,7 @@
2919
         if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
2920
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
2921
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
2922
-            tp->mcfg == CFG_METHOD_35) {
2923
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36) {
2924
                 //Disable Giga Lite
2925
                 rtl8168_mdio_write(tp, 0x1F, 0x0A42);
2926
                 rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_9);
2927
@@ -5294,8 +6361,16 @@
2928
                         giga_ctrl |= ADVERTISE_1000FULL;
2929
 
2930
                 //flow control
2931
-                if (dev->mtu <= ETH_DATA_LEN && tp->fcpause == rtl8168_fc_full)
2932
-                        auto_nego |= ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM;
2933
+                switch (tp->mcfg) {
2934
+                case CFG_METHOD_1 ... CFG_METHOD_20:
2935
+                        if (dev->mtu <= ETH_DATA_LEN && tp->fcpause == rtl8168_fc_full)
2936
+                                auto_nego |= ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM;
2937
+                        break;
2938
+                default:
2939
+                        if (tp->fcpause == rtl8168_fc_full)
2940
+                                auto_nego |= ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM;
2941
+                        break;
2942
+                }
2943
 
2944
                 tp->phy_auto_nego_reg = auto_nego;
2945
                 tp->phy_1000_ctrl_reg = giga_ctrl;
2946
@@ -5351,9 +6426,7 @@
2947
 #endif
2948
                     )
2949
 {
2950
-        struct rtl8168_private *tp = netdev_priv(dev);
2951
         int ret;
2952
-        unsigned long flags;
2953
         u8 autoneg;
2954
         u32 speed;
2955
         u8 duplex;
2956
@@ -5378,9 +6451,7 @@
2957
         if (advertising & ~supported)
2958
                 return -EINVAL;
2959
 
2960
-        spin_lock_irqsave(&tp->lock, flags);
2961
         ret = rtl8168_set_speed(dev, autoneg, speed, duplex, advertising);
2962
-        spin_unlock_irqrestore(&tp->lock, flags);
2963
 
2964
         return ret;
2965
 }
2966
@@ -5391,15 +6462,12 @@
2967
 {
2968
         struct rtl8168_private *tp = netdev_priv(dev);
2969
         u32 ret;
2970
-        unsigned long flags;
2971
 
2972
-        spin_lock_irqsave(&tp->lock, flags);
2973
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
2974
         ret = ((dev->features & NETIF_F_IP_CSUM) != 0);
2975
 #else
2976
         ret = ((dev->features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) != 0);
2977
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
2978
-        spin_unlock_irqrestore(&tp->lock, flags);
2979
 
2980
         return ret;
2981
 }
2982
@@ -5409,11 +6477,8 @@
2983
 {
2984
         struct rtl8168_private *tp = netdev_priv(dev);
2985
         u32 ret;
2986
-        unsigned long flags;
2987
 
2988
-        spin_lock_irqsave(&tp->lock, flags);
2989
         ret = tp->cp_cmd & RxChkSum;
2990
-        spin_unlock_irqrestore(&tp->lock, flags);
2991
 
2992
         return ret;
2993
 }
2994
@@ -5423,13 +6488,10 @@
2995
                     u32 data)
2996
 {
2997
         struct rtl8168_private *tp = netdev_priv(dev);
2998
-        unsigned long flags;
2999
 
3000
         if (tp->mcfg == CFG_METHOD_DEFAULT)
3001
                 return -EOPNOTSUPP;
3002
 
3003
-        spin_lock_irqsave(&tp->lock, flags);
3004
-
3005
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
3006
         if (data)
3007
                 dev->features |= NETIF_F_IP_CSUM;
3008
@@ -5445,8 +6507,6 @@
3009
                 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
3010
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
3011
 
3012
-        spin_unlock_irqrestore(&tp->lock, flags);
3013
-
3014
         return 0;
3015
 }
3016
 
3017
@@ -5455,13 +6515,10 @@
3018
                     u32 data)
3019
 {
3020
         struct rtl8168_private *tp = netdev_priv(dev);
3021
-        unsigned long flags;
3022
 
3023
         if (tp->mcfg == CFG_METHOD_DEFAULT)
3024
                 return -EOPNOTSUPP;
3025
 
3026
-        spin_lock_irqsave(&tp->lock, flags);
3027
-
3028
         if (data)
3029
                 tp->cp_cmd |= RxChkSum;
3030
         else
3031
@@ -5469,8 +6526,6 @@
3032
 
3033
         RTL_W16(tp, CPlusCmd, tp->cp_cmd);
3034
 
3035
-        spin_unlock_irqrestore(&tp->lock, flags);
3036
-
3037
         return 0;
3038
 }
3039
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
3040
@@ -5505,9 +6560,7 @@
3041
                          struct vlan_group *grp)
3042
 {
3043
         struct rtl8168_private *tp = netdev_priv(dev);
3044
-        unsigned long flags;
3045
 
3046
-        spin_lock_irqsave(&tp->lock, flags);
3047
         tp->vlgrp = grp;
3048
         if (tp->vlgrp)
3049
                 tp->cp_cmd |= RxVlan;
3050
@@ -5515,7 +6568,6 @@
3051
                 tp->cp_cmd &= ~RxVlan;
3052
         RTL_W16(tp, CPlusCmd, tp->cp_cmd);
3053
         RTL_R16(tp, CPlusCmd);
3054
-        spin_unlock_irqrestore(&tp->lock, flags);
3055
 }
3056
 
3057
 #endif
3058
@@ -5526,16 +6578,13 @@
3059
                          unsigned short vid)
3060
 {
3061
         struct rtl8168_private *tp = netdev_priv(dev);
3062
-        unsigned long flags;
3063
 
3064
-        spin_lock_irqsave(&tp->lock, flags);
3065
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
3066
         if (tp->vlgrp)
3067
                 tp->vlgrp->vlan_devicesvid = NULL;
3068
 #else
3069
         vlan_group_set_device(tp->vlgrp, vid, NULL);
3070
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
3071
-        spin_unlock_irqrestore(&tp->lock, flags);
3072
 }
3073
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
3074
 
3075
@@ -5589,17 +6638,12 @@
3076
 static netdev_features_t rtl8168_fix_features(struct net_device *dev,
3077
                 netdev_features_t features)
3078
 {
3079
-        struct rtl8168_private *tp = netdev_priv(dev);
3080
-        unsigned long flags;
3081
-
3082
-        spin_lock_irqsave(&tp->lock, flags);
3083
         if (dev->mtu > MSS_MAX)
3084
                 features &= ~NETIF_F_ALL_TSO;
3085
         if (dev->mtu > ETH_DATA_LEN) {
3086
                 features &= ~NETIF_F_ALL_TSO;
3087
                 features &= ~NETIF_F_ALL_CSUM;
3088
         }
3089
-        spin_unlock_irqrestore(&tp->lock, flags);
3090
 
3091
         return features;
3092
 }
3093
@@ -5623,7 +6667,7 @@
3094
         else
3095
                 tp->cp_cmd &= ~RxChkSum;
3096
 
3097
-        if (dev->features & NETIF_F_HW_VLAN_RX)
3098
+        if (features & NETIF_F_HW_VLAN_RX)
3099
                 tp->cp_cmd |= RxVlan;
3100
         else
3101
                 tp->cp_cmd &= ~RxVlan;
3102
@@ -5637,15 +6681,10 @@
3103
 static int rtl8168_set_features(struct net_device *dev,
3104
                                 netdev_features_t features)
3105
 {
3106
-        struct rtl8168_private *tp = netdev_priv(dev);
3107
-        unsigned long flags;
3108
-
3109
         features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX;
3110
 
3111
-        spin_lock_irqsave(&tp->lock, flags);
3112
         if (features ^ dev->features)
3113
                 rtl8168_hw_set_features(dev, features);
3114
-        spin_unlock_irqrestore(&tp->lock, flags);
3115
 
3116
         return 0;
3117
 }
3118
@@ -5666,7 +6705,6 @@
3119
         u32 speed = 0;
3120
         u16 bmcr, bmsr, anlpar, ctrl1000 = 0, stat1000 = 0;
3121
         u32 supported, advertising, lp_advertising;
3122
-        unsigned long flags;
3123
 
3124
         supported = SUPPORTED_10baseT_Half |
3125
                     SUPPORTED_10baseT_Full |
3126
@@ -5680,14 +6718,12 @@
3127
 
3128
         advertising = ADVERTISED_TP;
3129
 
3130
-        spin_lock_irqsave(&tp->lock, flags);
3131
         rtl8168_mdio_write(tp, 0x1F, 0x0000);
3132
         bmcr = rtl8168_mdio_read(tp, MII_BMCR);
3133
         bmsr = rtl8168_mdio_read(tp, MII_BMSR);
3134
         anlpar = rtl8168_mdio_read(tp, MII_LPA);
3135
         ctrl1000 = rtl8168_mdio_read(tp, MII_CTRL1000);
3136
         stat1000 = rtl8168_mdio_read(tp, MII_STAT1000);
3137
-        spin_unlock_irqrestore(&tp->lock, flags);
3138
 
3139
         if (bmcr & BMCR_ANENABLE) {
3140
                 advertising |= ADVERTISED_Autoneg;
3141
@@ -5789,14 +6825,12 @@
3142
         void __iomem *ioaddr = tp->mmio_addr;
3143
         unsigned int i;
3144
         u8 *data = p;
3145
-        unsigned long flags;
3146
 
3147
         if (regs->len < R8168_REGS_DUMP_SIZE)
3148
                 return /* -EINVAL */;
3149
 
3150
         memset(p, 0, regs->len);
3151
 
3152
-        spin_lock_irqsave(&tp->lock, flags);
3153
         for (i = 0; i < R8168_MAC_REGS_SIZE; i++)
3154
                 *data++ = readb(ioaddr + i);
3155
         data = (u8*)p + 256;
3156
@@ -5827,7 +6861,6 @@
3157
                 }
3158
                 break;
3159
         }
3160
-        spin_unlock_irqrestore(&tp->lock, flags);
3161
 }
3162
 
3163
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3164
@@ -5923,26 +6956,14 @@
3165
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
3166
 
3167
 static void
3168
-rtl8168_wait_for_quiescence(struct net_device *dev)
3169
+rtl8168_set_ring_size(struct rtl8168_private *tp, u32 rx, u32 tx)
3170
 {
3171
-        struct rtl8168_private *tp = netdev_priv(dev);
3172
-
3173
-        synchronize_irq(tp->irq);
3174
-
3175
-        /* Wait for any pending NAPI task to complete */
3176
-#ifdef CONFIG_R8168_NAPI
3177
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
3178
-        RTL_NAPI_DISABLE(dev, &tp->napi);
3179
-#endif
3180
-#endif //CONFIG_R8168_NAPI
3181
+        int i;
3182
 
3183
-        rtl8168_irq_mask_and_ack(tp);
3184
+        tp->num_rx_desc = rx;
3185
 
3186
-#ifdef CONFIG_R8168_NAPI
3187
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
3188
-        RTL_NAPI_ENABLE(dev, &tp->napi);
3189
-#endif
3190
-#endif //CONFIG_R8168_NAPI
3191
+        for (i = 0; i < tp->num_tx_rings; i++)
3192
+                tp->tx_ringi.num_tx_desc = tx;
3193
 }
3194
 
3195
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
3196
@@ -5961,7 +6982,7 @@
3197
         ring->rx_max_pending = MAX_NUM_TX_DESC;
3198
         ring->tx_max_pending = MAX_NUM_RX_DESC;
3199
         ring->rx_pending = tp->num_rx_desc;
3200
-        ring->tx_pending = tp->num_tx_desc;
3201
+        ring->tx_pending = tp->tx_ring0.num_tx_desc;
3202
 }
3203
 
3204
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
3205
@@ -5988,7 +7009,7 @@
3206
                                MIN_NUM_RX_DESC, MAX_NUM_RX_DESC);
3207
 
3208
         if ((new_rx_count == tp->num_rx_desc) &&
3209
-            (new_tx_count == tp->num_tx_desc)) {
3210
+            (new_tx_count == tp->tx_ring0.num_tx_desc)) {
3211
                 /* nothing to do */
3212
                 return 0;
3213
         }
3214
@@ -5998,8 +7019,7 @@
3215
                 rtl8168_close(dev);
3216
         }
3217
 
3218
-        tp->num_rx_desc = new_rx_count;
3219
-        tp->num_tx_desc = new_tx_count;
3220
+        rtl8168_set_ring_size(tp, new_rx_count, new_tx_count);
3221
 
3222
         if (netif_running(dev))
3223
                 rc = rtl8168_open(dev);
3224
@@ -6017,9 +7037,6 @@
3225
         struct rtl8168_private *tp = netdev_priv(dev);
3226
         struct rtl8168_counters *counters;
3227
         dma_addr_t paddr;
3228
-        u32 cmd;
3229
-        u32 WaitCnt;
3230
-        unsigned long flags;
3231
 
3232
         ASSERT_RTNL();
3233
 
3234
@@ -6028,21 +7045,7 @@
3235
         if (!counters)
3236
                 return;
3237
 
3238
-        spin_lock_irqsave(&tp->lock, flags);
3239
-        RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
3240
-        cmd = (u64)paddr & DMA_BIT_MASK(32);
3241
-        RTL_W32(tp, CounterAddrLow, cmd);
3242
-        RTL_W32(tp, CounterAddrLow, cmd | CounterDump);
3243
-
3244
-        WaitCnt = 0;
3245
-        while (RTL_R32(tp, CounterAddrLow) & CounterDump) {
3246
-                udelay(10);
3247
-
3248
-                WaitCnt++;
3249
-                if (WaitCnt > 20)
3250
-                        break;
3251
-        }
3252
-        spin_unlock_irqrestore(&tp->lock, flags);
3253
+        rtl8168_dump_tally_counter(tp, paddr);
3254
 
3255
         data0 = le64_to_cpu(counters->tx_packets);
3256
         data1 = le64_to_cpu(counters->rx_packets);
3257
@@ -6191,11 +7194,33 @@
3258
 }
3259
 #endif
3260
 
3261
-static int rtl8168_enable_EEE(struct rtl8168_private *tp)
3262
+static void
3263
+rtl8168_set_eee_lpi_timer(struct rtl8168_private *tp)
3264
+{
3265
+        u16 dev_lpi_timer;
3266
+
3267
+        dev_lpi_timer = tp->eee.tx_lpi_timer;
3268
+
3269
+        switch (tp->mcfg) {
3270
+        case CFG_METHOD_29:
3271
+        case CFG_METHOD_30:
3272
+        case CFG_METHOD_35:
3273
+        case CFG_METHOD_36:
3274
+        case CFG_METHOD_37:
3275
+                rtl8168_mac_ocp_write(tp, EEE_TXIDLE_TIMER_8168, dev_lpi_timer);
3276
+                break;
3277
+        default:
3278
+                break;
3279
+        }
3280
+}
3281
+
3282
+static int rtl8168_enable_eee(struct rtl8168_private *tp)
3283
 {
3284
         int ret;
3285
         u16 data;
3286
         u32 csi_tmp;
3287
+        struct ethtool_eee *eee = &tp->eee;
3288
+        u16 eee_adv_t = ethtool_adv_to_mmd_eee_adv_t(eee->advertised);
3289
 
3290
         ret = 0;
3291
         switch (tp->mcfg) {
3292
@@ -6290,6 +7315,7 @@
3293
         case CFG_METHOD_33:
3294
         case CFG_METHOD_34:
3295
         case CFG_METHOD_35:
3296
+        case CFG_METHOD_36:
3297
                 csi_tmp = rtl8168_eri_read(tp, 0x1B0, 4, ERIAR_ExGMAC);
3298
                 csi_tmp |= BIT_1 | BIT_0;
3299
                 rtl8168_eri_write(tp, 0x1B0, 4, csi_tmp, ERIAR_ExGMAC);
3300
@@ -6297,7 +7323,7 @@
3301
                 data = rtl8168_mdio_read(tp, 0x11);
3302
                 rtl8168_mdio_write(tp, 0x11, data | BIT_4);
3303
                 rtl8168_mdio_write(tp, 0x1F, 0x0A5D);
3304
-                rtl8168_mdio_write(tp, 0x10, tp->eee_adv_t);
3305
+                rtl8168_mdio_write(tp, 0x10, eee_adv_t);
3306
                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
3307
                 break;
3308
 
3309
@@ -6315,6 +7341,7 @@
3310
         case CFG_METHOD_33:
3311
         case CFG_METHOD_34:
3312
         case CFG_METHOD_35:
3313
+        case CFG_METHOD_36:
3314
                 rtl8168_mdio_write(tp, 0x1F, 0x0A4A);
3315
                 rtl8168_set_eth_phy_bit(tp, 0x11, BIT_9);
3316
                 rtl8168_mdio_write(tp, 0x1F, 0x0A42);
3317
@@ -6347,6 +7374,7 @@
3318
         case CFG_METHOD_33:
3319
         case CFG_METHOD_34:
3320
         case CFG_METHOD_35:
3321
+        case CFG_METHOD_36:
3322
                 rtl8168_set_phy_mcu_patch_request(tp);
3323
                 break;
3324
         }
3325
@@ -6407,6 +7435,7 @@
3326
         case CFG_METHOD_29:
3327
         case CFG_METHOD_30:
3328
         case CFG_METHOD_35:
3329
+        case CFG_METHOD_36:
3330
                 data = rtl8168_mac_ocp_read(tp, 0xE052);
3331
                 data &= ~(BIT_0);
3332
                 rtl8168_mac_ocp_write(tp, 0xE052, data);
3333
@@ -6454,6 +7483,7 @@
3334
         case CFG_METHOD_33:
3335
         case CFG_METHOD_34:
3336
         case CFG_METHOD_35:
3337
+        case CFG_METHOD_36:
3338
                 rtl8168_clear_phy_mcu_patch_request(tp);
3339
                 break;
3340
         }
3341
@@ -6473,7 +7503,7 @@
3342
         return ret;
3343
 }
3344
 
3345
-static int rtl8168_disable_EEE(struct rtl8168_private *tp)
3346
+static int rtl8168_disable_eee(struct rtl8168_private *tp)
3347
 {
3348
         int ret;
3349
         u16 data;
3350
@@ -6573,12 +7603,16 @@
3351
         case CFG_METHOD_33:
3352
         case CFG_METHOD_34:
3353
         case CFG_METHOD_35:
3354
+        case CFG_METHOD_36:
3355
                 csi_tmp = rtl8168_eri_read(tp, 0x1B0, 4, ERIAR_ExGMAC);
3356
                 csi_tmp &= ~(BIT_1 | BIT_0);
3357
                 rtl8168_eri_write(tp, 0x1B0, 4, csi_tmp, ERIAR_ExGMAC);
3358
                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3359
                 data = rtl8168_mdio_read(tp, 0x11);
3360
-                rtl8168_mdio_write(tp, 0x11, data & ~BIT_4);
3361
+                if (tp->mcfg == CFG_METHOD_36)
3362
+                        rtl8168_mdio_write(tp, 0x11, data | BIT_4);
3363
+                else
3364
+                        rtl8168_mdio_write(tp, 0x11, data & ~BIT_4);
3365
                 rtl8168_mdio_write(tp, 0x1F, 0x0A5D);
3366
                 rtl8168_mdio_write(tp, 0x10, 0x0000);
3367
                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
3368
@@ -6594,6 +7628,7 @@
3369
         case CFG_METHOD_29:
3370
         case CFG_METHOD_30:
3371
         case CFG_METHOD_35:
3372
+        case CFG_METHOD_36:
3373
                 rtl8168_mdio_write(tp, 0x1F, 0x0A42);
3374
                 rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_7);
3375
                 rtl8168_mdio_write(tp, 0x1F, 0x0A4A);
3376
@@ -6626,6 +7661,7 @@
3377
         case CFG_METHOD_33:
3378
         case CFG_METHOD_34:
3379
         case CFG_METHOD_35:
3380
+        case CFG_METHOD_36:
3381
                 rtl8168_set_phy_mcu_patch_request(tp);
3382
                 break;
3383
         }
3384
@@ -6664,6 +7700,7 @@
3385
         case CFG_METHOD_33:
3386
         case CFG_METHOD_34:
3387
         case CFG_METHOD_35:
3388
+        case CFG_METHOD_36:
3389
                 data = rtl8168_mac_ocp_read(tp, 0xE052);
3390
                 data &= ~(BIT_0);
3391
                 rtl8168_mac_ocp_write(tp, 0xE052, data);
3392
@@ -6690,6 +7727,7 @@
3393
         case CFG_METHOD_33:
3394
         case CFG_METHOD_34:
3395
         case CFG_METHOD_35:
3396
+        case CFG_METHOD_36:
3397
                 rtl8168_clear_phy_mcu_patch_request(tp);
3398
                 break;
3399
         }
3400
@@ -6712,15 +7750,10 @@
3401
 static int rtl_nway_reset(struct net_device *dev)
3402
 {
3403
         struct rtl8168_private *tp = netdev_priv(dev);
3404
-        unsigned long flags;
3405
         int ret, bmcr;
3406
 
3407
-        spin_lock_irqsave(&tp->lock, flags);
3408
-
3409
-        if (unlikely(tp->rtk_enable_diag)) {
3410
-                spin_unlock_irqrestore(&tp->lock, flags);
3411
+        if (unlikely(tp->rtk_enable_diag))
3412
                 return -EBUSY;
3413
-        }
3414
 
3415
         /* if autoneg is off, it's an error */
3416
         rtl8168_mdio_write(tp, 0x1F, 0x0000);
3417
@@ -6734,99 +7767,148 @@
3418
                 ret = -EINVAL;
3419
         }
3420
 
3421
-        spin_unlock_irqrestore(&tp->lock, flags);
3422
-
3423
         return ret;
3424
 }
3425
+static bool
3426
+rtl8168_support_eee(struct rtl8168_private *tp)
3427
+{
3428
+        switch (tp->mcfg) {
3429
+        case CFG_METHOD_21 ... CFG_METHOD_36:
3430
+                return 1;
3431
+        default:
3432
+                return 0;
3433
+        }
3434
+}
3435
 
3436
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)
3437
+static u32
3438
+rtl8168_device_lpi_t_to_ethtool_lpi_t(struct rtl8168_private *tp , u32 lpi_timer)
3439
+{
3440
+        u32 to_us;
3441
+        u8 status;
3442
+
3443
+        //Giga: lpi_timer * 8ns
3444
+        //100M : lpi_timer * 80ns
3445
+        to_us = 0;
3446
+        status = RTL_R8(tp, PHYstatus);
3447
+        if (status & LinkStatus) {
3448
+                /*link on*/
3449
+                if (status & _1000bpsF)
3450
+                        to_us = lpi_timer * 8;
3451
+                else if (status & _100bps)
3452
+                        to_us = lpi_timer * 80;
3453
+        }
3454
+
3455
+        //ns to us
3456
+        to_us /= 1000;
3457
+
3458
+        return to_us;
3459
+}
3460
+
3461
 static int
3462
-rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *eee)
3463
+rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata)
3464
 {
3465
         struct rtl8168_private *tp = netdev_priv(net);
3466
-        u32 lp, adv, supported = 0;
3467
-        unsigned long flags;
3468
+        struct ethtool_eee *eee = &tp->eee;
3469
+        u32 lp, adv, tx_lpi_timer, supported = 0;
3470
         u16 val;
3471
 
3472
-        switch (tp->mcfg) {
3473
-        case CFG_METHOD_21 ... CFG_METHOD_35:
3474
-                break;
3475
-        default:
3476
+        if (!rtl8168_support_eee(tp))
3477
                 return -EOPNOTSUPP;
3478
-        }
3479
 
3480
-        spin_lock_irqsave(&tp->lock, flags);
3481
-
3482
-        if (unlikely(tp->rtk_enable_diag)) {
3483
-                spin_unlock_irqrestore(&tp->lock, flags);
3484
+        if (unlikely(tp->rtk_enable_diag))
3485
                 return -EBUSY;
3486
-        }
3487
 
3488
-        rtl8168_mdio_write(tp, 0x1F, 0x0A5C);
3489
-        val = rtl8168_mdio_read(tp, 0x12);
3490
-        supported = mmd_eee_cap_to_ethtool_sup_t(val);
3491
+        /* Get Supported EEE */
3492
+        supported = eee->supported;
3493
 
3494
-        rtl8168_mdio_write(tp, 0x1F, 0x0A5D);
3495
-        val = rtl8168_mdio_read(tp, 0x10);
3496
-        adv = mmd_eee_adv_to_ethtool_adv_t(val);
3497
+        /* Get advertisement EEE */
3498
+        adv = eee->advertised;
3499
 
3500
+        /* Get LP advertisement EEE */
3501
+        rtl8168_mdio_write(tp, 0x1F, 0x0A5D);
3502
         val = rtl8168_mdio_read(tp, 0x11);
3503
         lp = mmd_eee_adv_to_ethtool_adv_t(val);
3504
 
3505
+        /* Get EEE Tx LPI timer*/
3506
+        tx_lpi_timer = rtl8168_device_lpi_t_to_ethtool_lpi_t(tp, eee->tx_lpi_timer);
3507
+
3508
         val = rtl8168_eri_read(tp, 0x1B0, 2, ERIAR_ExGMAC);
3509
         val &= BIT_1 | BIT_0;
3510
 
3511
         rtl8168_mdio_write(tp, 0x1F, 0x0000);
3512
 
3513
-        spin_unlock_irqrestore(&tp->lock, flags);
3514
-
3515
-        eee->eee_enabled = !!val;
3516
-        eee->eee_active = !!(supported & adv & lp);
3517
-        eee->supported = supported;
3518
-        eee->advertised = adv;
3519
-        eee->lp_advertised = lp;
3520
+        edata->eee_enabled = !!val;
3521
+        edata->eee_active = !!(supported & adv & lp);
3522
+        edata->supported = supported;
3523
+        edata->advertised = adv;
3524
+        edata->lp_advertised = lp;
3525
+        edata->tx_lpi_enabled = edata->eee_enabled;
3526
+        edata->tx_lpi_timer = tx_lpi_timer;
3527
 
3528
         return 0;
3529
 }
3530
 
3531
 static int
3532
-rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *eee)
3533
+rtl_ethtool_set_eee(struct net_device *net, struct ethtool_eee *edata)
3534
 {
3535
         struct rtl8168_private *tp = netdev_priv(net);
3536
-        unsigned long flags;
3537
+        struct ethtool_eee *eee = &tp->eee;
3538
+        u32 advertising;
3539
+        int rc = 0;
3540
 
3541
-        switch (tp->mcfg) {
3542
-        case CFG_METHOD_21 ... CFG_METHOD_35:
3543
-                break;
3544
-        default:
3545
+        if (!rtl8168_support_eee(tp))
3546
                 return -EOPNOTSUPP;
3547
-        }
3548
 
3549
         if (HW_SUPP_SERDES_PHY(tp) ||
3550
             !HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp) ||
3551
             tp->DASH)
3552
                 return -EOPNOTSUPP;
3553
 
3554
-        spin_lock_irqsave(&tp->lock, flags);
3555
-
3556
         if (unlikely(tp->rtk_enable_diag)) {
3557
-                spin_unlock_irqrestore(&tp->lock, flags);
3558
-                return -EBUSY;
3559
+                dev_printk(KERN_WARNING, tp_to_dev(tp), "Diag Enabled\n");
3560
+                rc = -EBUSY;
3561
+                goto out;
3562
         }
3563
 
3564
-        tp->eee_enabled = eee->eee_enabled;
3565
-        tp->eee_adv_t = ethtool_adv_to_mmd_eee_adv_t(eee->advertised);
3566
+        if (tp->autoneg != AUTONEG_ENABLE) {
3567
+                dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE requires autoneg\n");
3568
+                rc = -EINVAL;
3569
+                goto out;
3570
+        }
3571
 
3572
-        if (tp->eee_enabled)
3573
-                rtl8168_enable_EEE(tp);
3574
-        else
3575
-                rtl8168_disable_EEE(tp);
3576
+        advertising = tp->advertising;
3577
+        if (!edata->advertised) {
3578
+                edata->advertised = advertising & eee->supported;
3579
+        } else if (edata->advertised & ~advertising) {
3580
+                dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
3581
+                           edata->advertised, advertising);
3582
+                rc = -EINVAL;
3583
+                goto out;
3584
+        }
3585
 
3586
-        spin_unlock_irqrestore(&tp->lock, flags);
3587
+        if (edata->advertised & ~eee->supported) {
3588
+                dev_printk(KERN_WARNING, tp_to_dev(tp), "EEE advertised %x must be a subset of support %x\n",
3589
+                           edata->advertised, eee->supported);
3590
+                rc = -EINVAL;
3591
+                goto out;
3592
+        }
3593
+
3594
+        eee->advertised = edata->advertised;
3595
+        eee->eee_enabled = edata->eee_enabled;
3596
+
3597
+        if (eee->eee_enabled)
3598
+                rtl8168_enable_eee(tp);
3599
+        else
3600
+                rtl8168_disable_eee(tp);
3601
 
3602
         rtl_nway_reset(net);
3603
 
3604
-        return 0;
3605
+        return rc;
3606
+
3607
+out:
3608
+
3609
+        return rc;
3610
 }
3611
 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */
3612
 
3613
@@ -6881,6 +7963,14 @@
3614
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
3615
         .get_eeprom     = rtl_get_eeprom,
3616
         .get_eeprom_len     = rtl_get_eeprom_len,
3617
+#ifdef ENABLE_RSS_SUPPORT
3618
+        .get_rxnfc     = rtl8168_get_rxnfc,
3619
+        .set_rxnfc     = rtl8168_set_rxnfc,
3620
+        .get_rxfh_indir_size   = rtl8168_rss_indir_size,
3621
+        .get_rxfh_key_size = rtl8168_get_rxfh_key_size,
3622
+        .get_rxfh      = rtl8168_get_rxfh,
3623
+        .set_rxfh      = rtl8168_set_rxfh,
3624
+#endif
3625
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
3626
         .get_ts_info        = ethtool_op_get_ts_info,
3627
 #endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
3628
@@ -6892,171 +7982,6 @@
3629
 };
3630
 #endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22)
3631
 
3632
-#if 0
3633
-
3634
-static int rtl8168_enable_green_feature(struct rtl8168_private *tp)
3635
-{
3636
-        u16 gphy_val;
3637
-        unsigned long flags;
3638
-
3639
-        switch (tp->mcfg) {
3640
-        case CFG_METHOD_14:
3641
-        case CFG_METHOD_15:
3642
-                rtl8168_mdio_write(tp, 0x1F, 0x0003);
3643
-                gphy_val = rtl8168_mdio_read(tp, 0x10) | 0x0400;
3644
-                rtl8168_mdio_write(tp, 0x10, gphy_val);
3645
-                gphy_val = rtl8168_mdio_read(tp, 0x19) | 0x0001;
3646
-                rtl8168_mdio_write(tp, 0x19, gphy_val);
3647
-                rtl8168_mdio_write(tp, 0x1F, 0x0005);
3648
-                gphy_val = rtl8168_mdio_read(tp, 0x01) & ~0x0100;
3649
-                rtl8168_mdio_write(tp, 0x01, gphy_val);
3650
-                rtl8168_mdio_write(tp, 0x1F, 0x0000);
3651
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3652
-                mdelay(20);
3653
-                break;
3654
-
3655
-        case CFG_METHOD_17:
3656
-        case CFG_METHOD_18:
3657
-        case CFG_METHOD_19:
3658
-        case CFG_METHOD_20:
3659
-                rtl8168_mdio_write(tp, 0x1f, 0x0003);
3660
-                gphy_val = rtl8168_mdio_read(tp, 0x10);
3661
-                gphy_val |= BIT_10;
3662
-                rtl8168_mdio_write(tp, 0x10, gphy_val);
3663
-                gphy_val = rtl8168_mdio_read(tp, 0x19);
3664
-                gphy_val |= BIT_0;
3665
-                rtl8168_mdio_write(tp, 0x19, gphy_val);
3666
-                rtl8168_mdio_write(tp, 0x1F, 0x0005);
3667
-                gphy_val = rtl8168_mdio_read(tp, 0x01);
3668
-                gphy_val |= BIT_8;
3669
-                rtl8168_mdio_write(tp, 0x01, gphy_val);
3670
-                rtl8168_mdio_write(tp, 0x1f, 0x0000);
3671
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3672
-                break;
3673
-        case CFG_METHOD_21:
3674
-        case CFG_METHOD_23:
3675
-        case CFG_METHOD_24:
3676
-        case CFG_METHOD_25:
3677
-        case CFG_METHOD_26:
3678
-        case CFG_METHOD_27:
3679
-        case CFG_METHOD_28:
3680
-                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3681
-                rtl8168_mdio_write(tp, 0x13, 0x8011);
3682
-                rtl8168_set_eth_phy_bit( tp, 0x14, BIT_14 );
3683
-                rtl8168_mdio_write(tp, 0x1F, 0x0A40);
3684
-                rtl8168_mdio_write(tp, 0x1F, 0x0000);
3685
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3686
-                break;
3687
-        case CFG_METHOD_29:
3688
-        case CFG_METHOD_30:
3689
-        case CFG_METHOD_31:
3690
-        case CFG_METHOD_32:
3691
-        case CFG_METHOD_33:
3692
-        case CFG_METHOD_34:
3693
-        case CFG_METHOD_35:
3694
-                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3695
-                rtl8168_mdio_write(tp, 0x13, 0x8045);
3696
-                rtl8168_mdio_write(tp, 0x14, 0x0000);
3697
-                rtl8168_mdio_write(tp, 0x13, 0x804d);
3698
-                rtl8168_mdio_write(tp, 0x14, 0x1222);
3699
-                rtl8168_mdio_write(tp, 0x13, 0x805d);
3700
-                rtl8168_mdio_write(tp, 0x14, 0x0022);
3701
-                rtl8168_mdio_write(tp, 0x13, 0x8011);
3702
-                rtl8168_set_eth_phy_bit( tp, 0x14, BIT_15 );
3703
-                rtl8168_mdio_write(tp, 0x1F, 0x0A40);
3704
-                rtl8168_mdio_write(tp, 0x1F, 0x0000);
3705
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3706
-                break;
3707
-        default:
3708
-                dev_printk(KERN_DEBUG, tp_to_dev(tp), "Not Support Green Feature\n");
3709
-                break;
3710
-        }
3711
-
3712
-        return 0;
3713
-}
3714
-
3715
-static int rtl8168_disable_green_feature(struct rtl8168_private *tp)
3716
-{
3717
-        u16 gphy_val;
3718
-        unsigned long flags;
3719
-
3720
-        switch (tp->mcfg) {
3721
-        case CFG_METHOD_14:
3722
-        case CFG_METHOD_15:
3723
-                rtl8168_mdio_write(tp, 0x1F, 0x0005);
3724
-                gphy_val = rtl8168_mdio_read(tp, 0x01) | 0x0100;
3725
-                rtl8168_mdio_write(tp, 0x01, gphy_val);
3726
-                rtl8168_mdio_write(tp, 0x1F, 0x0003);
3727
-                gphy_val = rtl8168_mdio_read(tp, 0x10) & ~0x0400;
3728
-                rtl8168_mdio_write(tp, 0x10, gphy_val);
3729
-                gphy_val = rtl8168_mdio_read(tp, 0x19) & ~0x0001;
3730
-                rtl8168_mdio_write(tp, 0x19, gphy_val);
3731
-                rtl8168_mdio_write(tp, 0x1F, 0x0002);
3732
-                gphy_val = rtl8168_mdio_read(tp, 0x06) & ~0x7000;
3733
-                gphy_val |= 0x3000;
3734
-                rtl8168_mdio_write(tp, 0x06, gphy_val);
3735
-                gphy_val = rtl8168_mdio_read(tp, 0x0D) & 0x0700;
3736
-                gphy_val |= 0x0500;
3737
-                rtl8168_mdio_write(tp, 0x0D, gphy_val);
3738
-                rtl8168_mdio_write(tp, 0x1F, 0x0000);
3739
-                break;
3740
-
3741
-        case CFG_METHOD_17:
3742
-        case CFG_METHOD_18:
3743
-        case CFG_METHOD_19:
3744
-        case CFG_METHOD_20:
3745
-                rtl8168_mdio_write(tp, 0x1f, 0x0003);
3746
-                gphy_val = rtl8168_mdio_read(tp, 0x19);
3747
-                gphy_val &= ~BIT_0;
3748
-                rtl8168_mdio_write(tp, 0x19, gphy_val);
3749
-                gphy_val = rtl8168_mdio_read(tp, 0x10);
3750
-                gphy_val &= ~BIT_10;
3751
-                rtl8168_mdio_write(tp, 0x10, gphy_val);
3752
-                rtl8168_mdio_write(tp, 0x1f, 0x0000);
3753
-                break;
3754
-        case CFG_METHOD_21:
3755
-        case CFG_METHOD_23:
3756
-        case CFG_METHOD_24:
3757
-        case CFG_METHOD_25:
3758
-        case CFG_METHOD_26:
3759
-        case CFG_METHOD_27:
3760
-        case CFG_METHOD_28:
3761
-                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3762
-                rtl8168_mdio_write(tp, 0x13, 0x8011);
3763
-                rtl8168_clear_eth_phy_bit( tp, 0x14, BIT_14 );
3764
-                rtl8168_mdio_write(tp, 0x1F, 0x0A40);
3765
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3766
-                break;
3767
-        case CFG_METHOD_29:
3768
-        case CFG_METHOD_30:
3769
-        case CFG_METHOD_31:
3770
-        case CFG_METHOD_32:
3771
-        case CFG_METHOD_33:
3772
-        case CFG_METHOD_34:
3773
-        case CFG_METHOD_35:
3774
-                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3775
-                rtl8168_mdio_write(tp, 0x13, 0x8045);
3776
-                rtl8168_mdio_write(tp, 0x14, 0x2444);
3777
-                rtl8168_mdio_write(tp, 0x13, 0x804d);
3778
-                rtl8168_mdio_write(tp, 0x14, 0x2444);
3779
-                rtl8168_mdio_write(tp, 0x13, 0x805d);
3780
-                rtl8168_mdio_write(tp, 0x14, 0x2444);
3781
-                rtl8168_mdio_write(tp, 0x13, 0x8011);
3782
-                rtl8168_set_eth_phy_bit( tp, 0x14, BIT_15 );
3783
-                rtl8168_mdio_write(tp, 0x1F, 0x0A40);
3784
-                rtl8168_mdio_write(tp, 0x1F, 0x0000);
3785
-                rtl8168_mdio_write(tp, 0x00, 0x9200);
3786
-                break;
3787
-        default:
3788
-                dev_printk(KERN_DEBUG, tp_to_dev(tp), "Not Support Green Feature\n");
3789
-                break;
3790
-        }
3791
-
3792
-        return 0;
3793
-}
3794
-
3795
-#endif
3796
-
3797
 static void rtl8168_get_mac_version(struct rtl8168_private *tp)
3798
 {
3799
         u32 reg,val32;
3800
@@ -7229,9 +8154,24 @@
3801
                         tp->HwIcVerUnknown = TRUE;
3802
                 }
3803
 
3804
-                if (tp->mcfg == CFG_METHOD_30 &&
3805
-                    (rtl8168_mac_ocp_read(tp, 0xD006) & 0xFF00) == 0x0100)
3806
-                        tp->mcfg = CFG_METHOD_35;
3807
+                if (tp->mcfg == CFG_METHOD_30) {
3808
+                        if ((rtl8168_mac_ocp_read(tp, 0xD006) & 0xFF00) ==
3809
+                            0x0100)
3810
+                                tp->mcfg = CFG_METHOD_35;
3811
+                        else if ((rtl8168_mac_ocp_read(tp, 0xD006) & 0xFF00) ==
3812
+                                 0x0300)
3813
+                                tp->mcfg = CFG_METHOD_36;
3814
+                }
3815
+
3816
+                tp->efuse_ver = EFUSE_SUPPORT_V3;
3817
+                break;
3818
+        case 0x6C000000:
3819
+                if (ICVerID == 0x00000000) {
3820
+                        tp->mcfg = CFG_METHOD_37;
3821
+                } else {
3822
+                        tp->mcfg = CFG_METHOD_37;
3823
+                        tp->HwIcVerUnknown = TRUE;
3824
+                }
3825
 
3826
                 tp->efuse_ver = EFUSE_SUPPORT_V3;
3827
                 break;
3828
@@ -7298,10 +8238,9 @@
3829
 {
3830
         u16 reg = (u16)((DwCmd & 0x00FE0000) >> 17);
3831
         u32 DummyPos = rtl8168_calc_efuse_dummy_bit(reg);
3832
-        u32 DeCodeDwCmd = DwCmd;
3833
+        u32 DeCodeDwCmd;
3834
         u32 Dw17BitData;
3835
 
3836
-
3837
         if (tp->efuse_ver < 3) {
3838
                 DeCodeDwCmd = (DwCmd>>(DummyPos+1))<<DummyPos;
3839
                 if (DummyPos > 0) {
3840
@@ -7633,7 +8572,6 @@
3841
         //record fail case
3842
         rtl8168_mdio_write(tp, 0x1F, 0x0A43);
3843
         rtl8168_mdio_write(tp, 0x13, 0x801C);
3844
-        PhyRegValue = 0;
3845
         PhyRegValue = watch_dog & 0x03;
3846
         PhyRegValue <<= 14;
3847
         if (uc_response) PhyRegValue |= BIT_13;
3848
@@ -7755,7 +8693,7 @@
3849
         struct rtl8168_private *tp = netdev_priv(dev);
3850
         u16 data16;
3851
 
3852
-        RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~(AcceptErr | AcceptRunt | AcceptBroadcast | AcceptMulticast | AcceptMyPhys |  AcceptAllPhys));
3853
+        rtl8168_disable_rx_packet_filter(tp);
3854
 
3855
         if (HW_SUPP_SERDES_PHY(tp)) {
3856
                 if (tp->HwSuppSerDesPhyVer == 1) {
3857
@@ -7819,7 +8757,9 @@
3858
                 break;
3859
         case CFG_METHOD_29:
3860
         case CFG_METHOD_30:
3861
-        case CFG_METHOD_35:    {
3862
+        case CFG_METHOD_35:
3863
+        case CFG_METHOD_36:
3864
+        case CFG_METHOD_37: {
3865
                 u32 csi_tmp;
3866
                 csi_tmp = rtl8168_eri_read(tp, 0x174, 2, ERIAR_ExGMAC);
3867
                 csi_tmp &= ~(BIT_8);
3868
@@ -7857,6 +8797,8 @@
3869
         case CFG_METHOD_33:
3870
         case CFG_METHOD_34:
3871
         case CFG_METHOD_35:
3872
+        case CFG_METHOD_36:
3873
+        case CFG_METHOD_37:
3874
                 rtl8168_disable_now_is_oob(tp);
3875
 
3876
                 data16 = rtl8168_mac_ocp_read(tp, 0xE8DE) & ~BIT_14;
3877
@@ -7902,6 +8844,8 @@
3878
         case CFG_METHOD_33:
3879
         case CFG_METHOD_34:
3880
         case CFG_METHOD_35:
3881
+        case CFG_METHOD_36:
3882
+        case CFG_METHOD_37:
3883
                 rtl8168_mac_ocp_write(tp, 0xFC38, 0x0000);
3884
                 break;
3885
         }
3886
@@ -7922,6 +8866,8 @@
3887
         case CFG_METHOD_33:
3888
         case CFG_METHOD_34:
3889
         case CFG_METHOD_35:
3890
+        case CFG_METHOD_36:
3891
+        case CFG_METHOD_37:
3892
                 rtl8168_mac_ocp_write(tp, 0xFC28, 0x0000);
3893
                 rtl8168_mac_ocp_write(tp, 0xFC2A, 0x0000);
3894
                 rtl8168_mac_ocp_write(tp, 0xFC2C, 0x0000);
3895
@@ -9001,19 +9947,19 @@
3896
         struct rtl8168_private *tp = netdev_priv(dev);
3897
         u16 i;
3898
         static const u16 mcu_patch_code_8168h_3 = {
3899
-                0xE008, 0xE00A, 0xE00C, 0xE00E, 0xE010, 0xE039, 0xE03B, 0xE064, 0xC602,
3900
-                0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602,
3901
-                0xBE00, 0x0000, 0xC727, 0x76E2, 0x49EE, 0xF1FD, 0x1E00, 0x8EE0, 0x1E1C,
3902
-                0x8EE2, 0x76E2, 0x49EE, 0xF1FE, 0xC61D, 0x8EE0, 0x1E1D, 0x486F, 0x8EE2,
3903
-                0x76E2, 0x49EE, 0xF12C, 0xC716, 0x76E0, 0x48E8, 0x48E9, 0x48EA, 0x48EB,
3904
-                0x48EC, 0x9EE0, 0xC709, 0xC609, 0x9EF4, 0xC608, 0x9EF6, 0xB007, 0xC602,
3905
-                0xBE00, 0x0ACC, 0xE000, 0x03BF, 0x07FF, 0xDE24, 0x3200, 0xE096, 0xC602,
3906
-                0xBE00, 0x0000, 0x8EE6, 0xC726, 0x76E2, 0x49EE, 0xF1FD, 0x1E00, 0x8EE0,
3907
-                0x1E1C, 0x8EE2, 0x76E2, 0x49EE, 0xF1FE, 0xC61C, 0x8EE0, 0x1E1D, 0x486F,
3908
-                0x8EE2, 0x76E2, 0x49EE, 0xF1FE, 0xC715, 0x76E0, 0x48E8, 0x48E9, 0x48EA,
3909
-                0x48EB, 0x48EC, 0x9EE0, 0xC708, 0xC608, 0x9EF4, 0xC607, 0x9EF6, 0xC602,
3910
-                0xBE00, 0x0ABE, 0xE000, 0x03BF, 0x07FF, 0xDE24, 0x3200, 0xE096, 0xC602,
3911
-                0xBE00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3912
+                0xE008, 0xE00A, 0xE00C, 0xE00E, 0xE010, 0xE03E, 0xE040, 0xE069, 0xC602,
3913
+                0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC002, 0xB800, 0x0000, 0xC602,
3914
+                0xBE00, 0x0000, 0xC72B, 0x76E2, 0x49EE, 0xF1FD, 0x1E00, 0x9EE0, 0x1E1C,
3915
+                0x9EE2, 0x76E2, 0x49EE, 0xF1FE, 0xC621, 0x9EE0, 0x1E1D, 0x486F, 0x9EE2,
3916
+                0x76E2, 0x49EE, 0xF1FE, 0xC71A, 0x76E0, 0x48E8, 0x48E9, 0x48EA, 0x48EB,
3917
+                0x48EC, 0x9EE0, 0xC70D, 0xC60D, 0x9EF4, 0xC60C, 0x9EF6, 0xC70E, 0x76E0,
3918
+                0x4863, 0x9EE0, 0xB007, 0xC602, 0xBE00, 0x0ACC, 0xE000, 0x03BF, 0x07FF,
3919
+                0xDE24, 0x3200, 0xE096, 0xD438, 0xC602, 0xBE00, 0x0000, 0x8EE6, 0xC726,
3920
+                0x76E2, 0x49EE, 0xF1FD, 0x1E00, 0x8EE0, 0x1E1C, 0x8EE2, 0x76E2, 0x49EE,
3921
+                0xF1FE, 0xC61C, 0x8EE0, 0x1E1D, 0x486F, 0x8EE2, 0x76E2, 0x49EE, 0xF1FE,
3922
+                0xC715, 0x76E0, 0x48E8, 0x48E9, 0x48EA, 0x48EB, 0x48EC, 0x9EE0, 0xC708,
3923
+                0xC608, 0x9EF4, 0xC607, 0x9EF6, 0xC602, 0xBE00, 0x0ABE, 0xE000, 0x03BF,
3924
+                0x07FF, 0xDE24, 0x3200, 0xE096, 0xC602, 0xBE00, 0x0000, 0x0000, 0x0000,
3925
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3926
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3927
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3928
@@ -9057,7 +10003,7 @@
3929
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3930
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3931
                 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
3932
-                0x0000, 0x0000, 0x0000, 0x0000, 0x6838, 0x0A16, 0x0901, 0x101C
3933
+                0x0000, 0x0000, 0x0000, 0x0000, 0x6838, 0x0A17, 0x0613, 0x0D26
3934
         };
3935
 
3936
         rtl8168_hw_disable_mac_mcu_bps(dev);
3937
@@ -9076,6 +10022,12 @@
3938
 }
3939
 
3940
 static void
3941
+rtl8168_set_mac_mcu_8168h_4(struct net_device *dev)
3942
+{
3943
+        rtl8168_hw_disable_mac_mcu_bps(dev);
3944
+}
3945
+
3946
+static void
3947
 rtl8168_set_mac_mcu_8168fp_1(struct net_device *dev)
3948
 {
3949
         struct rtl8168_private *tp = netdev_priv(dev);
3950
@@ -9137,7 +10089,7 @@
3951
                 rtl8168_mac_ocp_write(tp, 0xFC34, 0x0A68);
3952
                 rtl8168_mac_ocp_write(tp, 0xFC36, 0x0A84);
3953
 
3954
-        } else if (tp->HwPkgDet == 0x6) {
3955
+        } else if (tp->HwPkgDet == 0x05 || tp->HwPkgDet == 0x06) {
3956
                 static const u16 mcu_patch_code_8168fp_1_2 = {
3957
                         0xE008, 0xE00A, 0xE031, 0xE033, 0xE035, 0xE144, 0xE166, 0xE168, 0xC502,
3958
                         0xBD00, 0x0000, 0xC725, 0x75E0, 0x48D0, 0x9DE0, 0xC722, 0x75E0, 0x1C78,
3959
@@ -9203,7 +10155,7 @@
3960
                 breakPointEnabled = 0x00FC;
3961
         else if (tp->HwPkgDet == 0x0F)
3962
                 breakPointEnabled = 0x00FF;
3963
-        else if (tp->HwPkgDet == 0x06)
3964
+        else if (tp->HwPkgDet == 0x05 || tp->HwPkgDet == 0x06)
3965
                 breakPointEnabled = 0x0022;
3966
 
3967
         rtl8168_mac_ocp_write(tp, 0xFC38, breakPointEnabled);
3968
@@ -9357,6 +10309,7 @@
3969
                 rtl8168_set_mac_mcu_8168h_1(dev);
3970
                 break;
3971
         case CFG_METHOD_30:
3972
+        case CFG_METHOD_37:
3973
                 rtl8168_set_mac_mcu_8168h_2(dev);
3974
                 break;
3975
         case CFG_METHOD_31:
3976
@@ -9372,6 +10325,9 @@
3977
         case CFG_METHOD_35:
3978
                 rtl8168_set_mac_mcu_8168h_3(dev);
3979
                 break;
3980
+        case CFG_METHOD_36:
3981
+                rtl8168_set_mac_mcu_8168h_4(dev);
3982
+                break;
3983
         }
3984
 }
3985
 #endif
3986
@@ -9433,6 +10389,8 @@
3987
         case CFG_METHOD_33:
3988
         case CFG_METHOD_34:
3989
         case CFG_METHOD_35:
3990
+        case CFG_METHOD_36:
3991
+        case CFG_METHOD_37:
3992
                 rtl8168_mac_ocp_write(tp, 0xE63E, rtl8168_mac_ocp_read( tp, 0xE63E) & ~(BIT_3 | BIT_2 | BIT_1));
3993
                 rtl8168_mac_ocp_write(tp, 0xE63E, rtl8168_mac_ocp_read( tp, 0xE63E) | (BIT_0));
3994
                 rtl8168_mac_ocp_write(tp, 0xE63E, rtl8168_mac_ocp_read( tp, 0xE63E) & ~(BIT_0));
3995
@@ -9459,31 +10417,6 @@
3996
                 break;
3997
         }
3998
 
3999
-        switch (tp->mcfg) {
4000
-        case CFG_METHOD_16:
4001
-        case CFG_METHOD_17:
4002
-        case CFG_METHOD_18:
4003
-        case CFG_METHOD_19:
4004
-        case CFG_METHOD_20:
4005
-                if (aspm) {
4006
-                        RTL_W8(tp, 0x6E, RTL_R8(tp, 0x6E) | BIT_6);
4007
-                        rtl8168_eri_write(tp, 0x1AE, 2, 0x0403, ERIAR_ExGMAC);
4008
-                }
4009
-                break;
4010
-        case CFG_METHOD_21:
4011
-        case CFG_METHOD_22:
4012
-        case CFG_METHOD_29:
4013
-        case CFG_METHOD_30:
4014
-        case CFG_METHOD_35:
4015
-                if (aspm) {
4016
-                        if ((rtl8168_mac_ocp_read(tp, 0xDC00) & BIT_3) || (RTL_R8(tp, Config0) & 0x07)) {
4017
-                                RTL_W8(tp, 0x6E, RTL_R8(tp, 0x6E) | BIT_6);
4018
-                                rtl8168_eri_write(tp, 0x1AE, 2, 0x0403, ERIAR_ExGMAC);
4019
-                        }
4020
-                }
4021
-                break;
4022
-        }
4023
-
4024
         if (tp->mcfg == CFG_METHOD_10 || tp->mcfg == CFG_METHOD_14 || tp->mcfg == CFG_METHOD_15)
4025
                 RTL_W8(tp, 0xF3, RTL_R8(tp, 0xF3) | BIT_2);
4026
 
4027
@@ -9498,7 +10431,8 @@
4028
             tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
4029
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
4030
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
4031
-            tp->mcfg == CFG_METHOD_35)
4032
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
4033
+            tp->mcfg == CFG_METHOD_37)
4034
                 if (!tp->dash_printer_enabled)
4035
                         rtl8168_disable_ocp_phy_power_saving(dev);
4036
 
4037
@@ -9853,6 +10787,7 @@
4038
                 break;
4039
         case CFG_METHOD_29:
4040
         case CFG_METHOD_30:
4041
+        case CFG_METHOD_37:
4042
                 ClearPCIePhyBit(tp, 0x1E, BIT_11);
4043
 
4044
                 SetPCIePhyBit(tp, 0x1E, BIT_0);
4045
@@ -9886,13 +10821,21 @@
4046
 
4047
                 break;
4048
         case CFG_METHOD_35:
4049
-                rtl8168_clear_mcu_ocp_bit(tp, 0xDE38, BIT_2);
4050
+                rtl8168_clear_mcu_ocp_bit(tp, 0xD438, BIT_2);
4051
 
4052
                 ClearPCIePhyBit(tp, 0x24, BIT_9);
4053
 
4054
                 rtl8168_clear_mcu_ocp_bit(tp, 0xDE28, (BIT_1 | BIT_0));
4055
 
4056
-                rtl8168_set_mcu_ocp_bit(tp, 0xDE38, BIT_2);
4057
+                rtl8168_set_mcu_ocp_bit(tp, 0xD438, BIT_2);
4058
+
4059
+                break;
4060
+        case CFG_METHOD_36:
4061
+                rtl8168_clear_mcu_ocp_bit(tp, 0xD438, BIT_2);
4062
+
4063
+                rtl8168_clear_mcu_ocp_bit(tp, 0xDE28, (BIT_1 | BIT_0));
4064
+
4065
+                rtl8168_set_mcu_ocp_bit(tp, 0xD438, BIT_2);
4066
 
4067
                 break;
4068
         }
4069
@@ -9906,7 +10849,7 @@
4070
         int retval = TRUE;
4071
 
4072
         switch (tp->mcfg) {
4073
-        case CFG_METHOD_21 ... CFG_METHOD_35:
4074
+        case CFG_METHOD_21 ... CFG_METHOD_37:
4075
                 rtl8168_mdio_write(tp,0x1f, 0x0B82);
4076
                 rtl8168_set_eth_phy_bit(tp, 0x10, BIT_4);
4077
 
4078
@@ -9936,7 +10879,7 @@
4079
         int retval = TRUE;
4080
 
4081
         switch (tp->mcfg) {
4082
-        case CFG_METHOD_21 ... CFG_METHOD_35:
4083
+        case CFG_METHOD_21 ... CFG_METHOD_37:
4084
                 rtl8168_mdio_write(tp, 0x1f, 0x0B82);
4085
                 rtl8168_clear_eth_phy_bit(tp, 0x10, BIT_4);
4086
 
4087
@@ -9996,6 +10939,8 @@
4088
         case CFG_METHOD_33:
4089
         case CFG_METHOD_34:
4090
         case CFG_METHOD_35:
4091
+        case CFG_METHOD_36:
4092
+        case CFG_METHOD_37:
4093
                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4094
                 rtl8168_mdio_write(tp, 0x13, 0x801E);
4095
                 hw_ram_code_ver = rtl8168_mdio_read(tp, 0x14);
4096
@@ -10104,6 +11049,8 @@
4097
         case CFG_METHOD_33:
4098
         case CFG_METHOD_34:
4099
         case CFG_METHOD_35:
4100
+        case CFG_METHOD_36:
4101
+        case CFG_METHOD_37:
4102
                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4103
                 rtl8168_mdio_write(tp, 0x13, 0x801E);
4104
                 rtl8168_mdio_write(tp, 0x14, tp->sw_ram_code_ver);
4105
@@ -10138,7 +11085,7 @@
4106
                 PhyRegValue &= ~(BIT_11);
4107
                 rtl8168_mdio_write(tp, 0x14, PhyRegValue);
4108
 
4109
-                retval = rtl8168_set_phy_mcu_patch_request(tp);
4110
+                rtl8168_set_phy_mcu_patch_request(tp);
4111
 
4112
                 rtl8168_mdio_write(tp, 0x1f, 0x0A40);
4113
                 rtl8168_mdio_write(tp, 0x10, 0x0140);
4114
@@ -10159,7 +11106,7 @@
4115
                 PhyRegValue |= (BIT_11|BIT_12);
4116
                 rtl8168_mdio_write(tp, 0x11, PhyRegValue);
4117
 
4118
-                retval = rtl8168_clear_phy_mcu_patch_request(tp);
4119
+                rtl8168_clear_phy_mcu_patch_request(tp);
4120
 
4121
                 rtl8168_mdio_write(tp, 0x1f, 0x0A40);
4122
                 rtl8168_mdio_write(tp, 0x10, 0x1040);
4123
@@ -10185,7 +11132,7 @@
4124
                 PhyRegValue |= (BIT_11);
4125
                 rtl8168_mdio_write(tp, 0x14, PhyRegValue);
4126
 
4127
-                retval = rtl8168_set_phy_mcu_patch_request(tp);
4128
+                rtl8168_set_phy_mcu_patch_request(tp);
4129
 
4130
                 rtl8168_mdio_write(tp, 0x1f, 0x0A20);
4131
                 PhyRegValue = rtl8168_mdio_read(tp, 0x13);
4132
@@ -10195,7 +11142,7 @@
4133
                         }
4134
                 }
4135
 
4136
-                retval = rtl8168_clear_phy_mcu_patch_request(tp);
4137
+                rtl8168_clear_phy_mcu_patch_request(tp);
4138
 
4139
                 mdelay(2);
4140
                 break;
4141
@@ -20999,7 +21946,7 @@
4142
         rtl8168_mdio_write(tp, 0x13, 0x0000);
4143
         rtl8168_mdio_write(tp, 0x14, 0x0000);
4144
         rtl8168_mdio_write(tp, 0x1f, 0x0B82);
4145
-        gphy_val = rtl8168_mdio_read(tp,  0x17);
4146
+        gphy_val = rtl8168_mdio_read(tp, 0x17);
4147
         gphy_val &= ~(BIT_0);
4148
         rtl8168_mdio_write(tp, 0x17, gphy_val);
4149
         rtl8168_mdio_write(tp, 0x1f, 0x0A43);
4150
@@ -21032,23 +21979,45 @@
4151
         rtl8168_mdio_write(tp, 0x13, 0xA014);
4152
         rtl8168_mdio_write(tp, 0x14, 0x2c04);
4153
         rtl8168_mdio_write(tp, 0x14, 0x2c09);
4154
-        rtl8168_mdio_write(tp, 0x14, 0x2c09);
4155
-        rtl8168_mdio_write(tp, 0x14, 0x2c09);
4156
+        rtl8168_mdio_write(tp, 0x14, 0x2c0d);
4157
+        rtl8168_mdio_write(tp, 0x14, 0x2c12);
4158
         rtl8168_mdio_write(tp, 0x14, 0xad01);
4159
         rtl8168_mdio_write(tp, 0x14, 0xad01);
4160
         rtl8168_mdio_write(tp, 0x14, 0xad01);
4161
         rtl8168_mdio_write(tp, 0x14, 0xad01);
4162
         rtl8168_mdio_write(tp, 0x14, 0x236c);
4163
+        rtl8168_mdio_write(tp, 0x14, 0xd03c);
4164
+        rtl8168_mdio_write(tp, 0x14, 0xd1aa);
4165
+        rtl8168_mdio_write(tp, 0x14, 0xc010);
4166
+        rtl8168_mdio_write(tp, 0x14, 0x2745);
4167
+        rtl8168_mdio_write(tp, 0x14, 0x33de);
4168
+        rtl8168_mdio_write(tp, 0x14, 0x16ba);
4169
+        rtl8168_mdio_write(tp, 0x14, 0x31ee);
4170
+        rtl8168_mdio_write(tp, 0x14, 0x2712);
4171
+        rtl8168_mdio_write(tp, 0x14, 0x274e);
4172
+        rtl8168_mdio_write(tp, 0x14, 0xc2bb);
4173
+        rtl8168_mdio_write(tp, 0x14, 0xd500);
4174
+        rtl8168_mdio_write(tp, 0x14, 0xc426);
4175
+        rtl8168_mdio_write(tp, 0x14, 0xd01d);
4176
+        rtl8168_mdio_write(tp, 0x14, 0xd1c3);
4177
+        rtl8168_mdio_write(tp, 0x14, 0x401c);
4178
+        rtl8168_mdio_write(tp, 0x14, 0xd501);
4179
+        rtl8168_mdio_write(tp, 0x14, 0xc2b3);
4180
+        rtl8168_mdio_write(tp, 0x14, 0xd500);
4181
+        rtl8168_mdio_write(tp, 0x14, 0xd00b);
4182
+        rtl8168_mdio_write(tp, 0x14, 0xd1c3);
4183
+        rtl8168_mdio_write(tp, 0x14, 0x401c);
4184
+        rtl8168_mdio_write(tp, 0x14, 0x241a);
4185
         rtl8168_mdio_write(tp, 0x13, 0xA01A);
4186
         rtl8168_mdio_write(tp, 0x14, 0x0000);
4187
         rtl8168_mdio_write(tp, 0x13, 0xA006);
4188
-        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4189
+        rtl8168_mdio_write(tp, 0x14, 0x0414);
4190
         rtl8168_mdio_write(tp, 0x13, 0xA004);
4191
-        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4192
+        rtl8168_mdio_write(tp, 0x14, 0x074c);
4193
         rtl8168_mdio_write(tp, 0x13, 0xA002);
4194
-        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4195
+        rtl8168_mdio_write(tp, 0x14, 0x0744);
4196
         rtl8168_mdio_write(tp, 0x13, 0xA000);
4197
-        rtl8168_mdio_write(tp, 0x14, 0x136b);
4198
+        rtl8168_mdio_write(tp, 0x14, 0xf36b);
4199
         rtl8168_mdio_write(tp, 0x13, 0xB820);
4200
         rtl8168_mdio_write(tp, 0x14, 0x0210);
4201
 
4202
@@ -21382,15 +22351,57 @@
4203
         rtl8168_mdio_write(tp, 0x14, 0x0000);
4204
         rtl8168_mdio_write(tp, 0x13, 0xA014);
4205
         rtl8168_mdio_write(tp, 0x14, 0x1800);
4206
-        rtl8168_mdio_write(tp, 0x14, 0x8002);
4207
+        rtl8168_mdio_write(tp, 0x14, 0x8010);
4208
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4209
+        rtl8168_mdio_write(tp, 0x14, 0x8014);
4210
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4211
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4212
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4213
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4214
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4215
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4216
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4217
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4218
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4219
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4220
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4221
+        rtl8168_mdio_write(tp, 0x14, 0x8022);
4222
         rtl8168_mdio_write(tp, 0x14, 0x2b5d);
4223
         rtl8168_mdio_write(tp, 0x14, 0x0c68);
4224
         rtl8168_mdio_write(tp, 0x14, 0x1800);
4225
         rtl8168_mdio_write(tp, 0x14, 0x0b3c);
4226
+        rtl8168_mdio_write(tp, 0x14, 0xc2bb);
4227
+        rtl8168_mdio_write(tp, 0x14, 0xd500);
4228
+        rtl8168_mdio_write(tp, 0x14, 0xc426);
4229
+        rtl8168_mdio_write(tp, 0x14, 0xd01d);
4230
+        rtl8168_mdio_write(tp, 0x14, 0xd1c3);
4231
+        rtl8168_mdio_write(tp, 0x14, 0x401c);
4232
+        rtl8168_mdio_write(tp, 0x14, 0xd501);
4233
+        rtl8168_mdio_write(tp, 0x14, 0xc2b3);
4234
+        rtl8168_mdio_write(tp, 0x14, 0xd500);
4235
+        rtl8168_mdio_write(tp, 0x14, 0xd00b);
4236
+        rtl8168_mdio_write(tp, 0x14, 0xd1c3);
4237
+        rtl8168_mdio_write(tp, 0x14, 0x401c);
4238
+        rtl8168_mdio_write(tp, 0x14, 0x1800);
4239
+        rtl8168_mdio_write(tp, 0x14, 0x0478);
4240
+        rtl8168_mdio_write(tp, 0x13, 0xA026);
4241
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4242
+        rtl8168_mdio_write(tp, 0x13, 0xA024);
4243
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4244
+        rtl8168_mdio_write(tp, 0x13, 0xA022);
4245
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4246
+        rtl8168_mdio_write(tp, 0x13, 0xA020);
4247
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4248
+        rtl8168_mdio_write(tp, 0x13, 0xA006);
4249
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4250
+        rtl8168_mdio_write(tp, 0x13, 0xA004);
4251
+        rtl8168_mdio_write(tp, 0x14, 0x0fff);
4252
+        rtl8168_mdio_write(tp, 0x13, 0xA002);
4253
+        rtl8168_mdio_write(tp, 0x14, 0x0472);
4254
         rtl8168_mdio_write(tp, 0x13, 0xA000);
4255
         rtl8168_mdio_write(tp, 0x14, 0x0b3a);
4256
         rtl8168_mdio_write(tp, 0x13, 0xA008);
4257
-        rtl8168_mdio_write(tp, 0x14, 0x0100);
4258
+        rtl8168_mdio_write(tp, 0x14, 0x0300);
4259
         rtl8168_mdio_write(tp, 0x13, 0xB820);
4260
         rtl8168_mdio_write(tp, 0x14, 0x0010);
4261
 
4262
@@ -21968,11 +22979,14 @@
4263
                 rtl8168_set_phy_mcu_8168h_1(dev);
4264
                 break;
4265
         case CFG_METHOD_30:
4266
+        case CFG_METHOD_37:
4267
                 rtl8168_set_phy_mcu_8168h_2(dev);
4268
                 break;
4269
         case CFG_METHOD_35:
4270
                 rtl8168_set_phy_mcu_8168h_3(dev);
4271
                 break;
4272
+        case CFG_METHOD_36:
4273
+                break;
4274
         }
4275
 
4276
         if (require_disable_phy_disable_mode)
4277
@@ -23682,6 +24696,13 @@
4278
                 rtl8168_mdio_write(tp, 0x06, rtl8168_mdio_read(tp, 0x06) & ~BIT_8);
4279
                 rtl8168_mdio_write(tp, 0x1f, 0x0000);
4280
 
4281
+
4282
+                rtl8168_mdio_write(tp, 0x1F, 0x0007);
4283
+                rtl8168_mdio_write(tp, 0x1E, 0x0023);
4284
+                rtl8168_clear_eth_phy_bit(tp, 0x17, BIT_1);
4285
+                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4286
+
4287
+
4288
                 if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) {
4289
                         rtl8168_mdio_write(tp, 0x1f, 0x0005);
4290
                         rtl8168_mdio_write(tp, 0x05, 0x8b85);
4291
@@ -24231,7 +25252,7 @@
4292
                                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
4293
                         }
4294
                 }
4295
-        } else if (tp->mcfg == CFG_METHOD_30) {
4296
+        } else if (tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_37) {
4297
                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4298
                 rtl8168_mdio_write(tp, 0x13, 0x808A);
4299
                 ClearAndSetEthPhyBit( tp,
4300
@@ -24299,6 +25320,17 @@
4301
                                 BIT_12);
4302
                 }
4303
 
4304
+
4305
+                rtl8168_mdio_write(tp, 0x1F, 0x0C41);
4306
+                rtl8168_clear_eth_phy_bit(tp, 0x15, BIT_1);
4307
+                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4308
+
4309
+
4310
+                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4311
+                rtl8168_set_eth_phy_bit(tp, 0x10, BIT_0);
4312
+                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4313
+
4314
+
4315
                 if (aspm) {
4316
                         if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) {
4317
                                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4318
@@ -24441,7 +25473,7 @@
4319
 
4320
                 rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4321
                 rtl8168_mdio_write(tp, 0x13, 0x8011);
4322
-                rtl8168_set_eth_phy_bit(tp, 0x14, BIT_11);
4323
+                rtl8168_clear_eth_phy_bit(tp, 0x14, BIT_11);
4324
                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
4325
 
4326
                 rtl8168_mdio_write(tp, 0x1F, 0x0A44);
4327
@@ -24584,6 +25616,24 @@
4328
                                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
4329
                         }
4330
                 }
4331
+        } else if (tp->mcfg == CFG_METHOD_36) {
4332
+                rtl8168_mdio_write(tp, 0x1F, 0x0A44);
4333
+                rtl8168_set_eth_phy_bit(tp, 0x11, BIT_11);
4334
+                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4335
+
4336
+
4337
+                rtl8168_mdio_write(tp, 0x1F, 0x0C41);
4338
+                rtl8168_clear_eth_phy_bit(tp, 0x15, BIT_1);
4339
+                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4340
+
4341
+
4342
+                if (aspm) {
4343
+                        if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) {
4344
+                                rtl8168_mdio_write(tp, 0x1F, 0x0A43);
4345
+                                rtl8168_set_eth_phy_bit( tp, 0x10, BIT_2 );
4346
+                                rtl8168_mdio_write(tp, 0x1F, 0x0000);
4347
+                        }
4348
+                }
4349
         }
4350
 
4351
 #ifdef ENABLE_FIBER_SUPPORT
4352
@@ -24609,7 +25659,7 @@
4353
         } else if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
4354
                    tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
4355
                    tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
4356
-                   tp->mcfg == CFG_METHOD_35) {
4357
+                   tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36) {
4358
                 //enable EthPhyPPSW
4359
                 rtl8168_mdio_write(tp, 0x1F, 0x0A44);
4360
                 rtl8168_set_eth_phy_bit( tp, 0x11, BIT_7 );
4361
@@ -24622,7 +25672,8 @@
4362
             tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
4363
             tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32 ||
4364
             tp->mcfg == CFG_METHOD_33 || tp->mcfg == CFG_METHOD_34 ||
4365
-            tp->mcfg == CFG_METHOD_35) {
4366
+            tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
4367
+            tp->mcfg == CFG_METHOD_37) {
4368
                 if (aspm)
4369
                         rtl8168_enable_ocp_phy_power_saving(dev);
4370
         }
4371
@@ -24630,13 +25681,14 @@
4372
         rtl8168_mdio_write(tp, 0x1F, 0x0000);
4373
 
4374
         if (HW_HAS_WRITE_PHY_MCU_RAM_CODE(tp)) {
4375
-                if (tp->eee_enabled)
4376
-                        rtl8168_enable_EEE(tp);
4377
+                if (tp->eee.eee_enabled)
4378
+                        rtl8168_enable_eee(tp);
4379
                 else
4380
-                        rtl8168_disable_EEE(tp);
4381
+                        rtl8168_disable_eee(tp);
4382
         }
4383
 }
4384
 
4385
+/*
4386
 static inline void rtl8168_delete_esd_timer(struct net_device *dev, struct timer_list *timer)
4387
 {
4388
         del_timer_sync(timer);
4389
@@ -24671,6 +25723,7 @@
4390
 #endif
4391
         mod_timer(timer, jiffies + RTL8168_LINK_TIMEOUT);
4392
 }
4393
+*/
4394
 
4395
 #ifdef CONFIG_NET_POLL_CONTROLLER
4396
 /*
4397
@@ -24682,16 +25735,24 @@
4398
 rtl8168_netpoll(struct net_device *dev)
4399
 {
4400
         struct rtl8168_private *tp = netdev_priv(dev);
4401
+        int i;
4402
+        for (i = 0; i < tp->irq_nvecs; i++) {
4403
+                struct r8168_irq *irq = &tp->irq_tbli;
4404
+                struct r8168_napi *r8168napi = &tp->r8168napii;
4405
 
4406
-        disable_irq(tp->irq);
4407
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
4408
-        rtl8168_interrupt(tp->irq, dev, NULL);
4409
+                disable_irq(irq->vector);
4410
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
4411
+                irq->handler(irq->vector, r8168napi);
4412
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
4413
+                irq->handler(irq->vector, r8168napi, NULL);
4414
 #else
4415
-        rtl8168_interrupt(tp->irq, dev);
4416
+                irq->handler(irq->vector, r8168napi);
4417
 #endif
4418
-        enable_irq(tp->irq);
4419
+                enable_irq(irq->vector);
4420
+        }
4421
 }
4422
-#endif
4423
+
4424
+#endif //CONFIG_NET_POLL_CONTROLLER
4425
 
4426
 static void
4427
 rtl8168_get_bios_setting(struct net_device *dev)
4428
@@ -24726,6 +25787,8 @@
4429
         case CFG_METHOD_33:
4430
         case CFG_METHOD_34:
4431
         case CFG_METHOD_35:
4432
+        case CFG_METHOD_36:
4433
+        case CFG_METHOD_37:
4434
                 tp->bios_setting = RTL_R32(tp, 0x8c);
4435
                 break;
4436
         }
4437
@@ -24764,12 +25827,32 @@
4438
         case CFG_METHOD_33:
4439
         case CFG_METHOD_34:
4440
         case CFG_METHOD_35:
4441
+        case CFG_METHOD_36:
4442
+        case CFG_METHOD_37:
4443
                 RTL_W32(tp, 0x8C, tp->bios_setting);
4444
                 break;
4445
         }
4446
 }
4447
 
4448
 static void
4449
+rtl8168_setup_mqs_reg(struct rtl8168_private *tp)
4450
+{
4451
+        //tx
4452
+        tp->tx_ring0.tdsar_reg = TxDescStartAddrLow;
4453
+        tp->tx_ring1.tdsar_reg = TxHDescStartAddrLow;
4454
+
4455
+        tp->isr_reg0 = IntrStatus;
4456
+        tp->isr_reg1 = IntrStatus1;
4457
+        tp->isr_reg2 = IntrStatus2;
4458
+        tp->isr_reg3 = IntrStatus3;
4459
+
4460
+        tp->imr_reg0 = IntrMask;
4461
+        tp->imr_reg1 = IntrMask1;
4462
+        tp->imr_reg2 = IntrMask2;
4463
+        tp->imr_reg3 = IntrMask3;
4464
+}
4465
+
4466
+static void
4467
 rtl8168_init_software_variable(struct net_device *dev)
4468
 {
4469
         struct rtl8168_private *tp = netdev_priv(dev);
4470
@@ -24777,8 +25860,12 @@
4471
 
4472
         rtl8168_get_bios_setting(dev);
4473
 
4474
-        tp->num_rx_desc = NUM_RX_DESC;
4475
-        tp->num_tx_desc = NUM_TX_DESC;
4476
+#ifdef ENABLE_LIB_SUPPORT
4477
+        tp->ring_lib_enabled = 1;
4478
+#endif
4479
+
4480
+        if (tp->mcfg == CFG_METHOD_DEFAULT)
4481
+                disable_wol_support = 1;
4482
 
4483
         switch (tp->mcfg) {
4484
         case CFG_METHOD_11:
4485
@@ -24831,6 +25918,8 @@
4486
         case CFG_METHOD_33:
4487
         case CFG_METHOD_34:
4488
         case CFG_METHOD_35:
4489
+        case CFG_METHOD_36:
4490
+        case CFG_METHOD_37:
4491
                 tp->HwSuppNowIsOobVer = 1;
4492
                 break;
4493
         }
4494
@@ -24851,6 +25940,8 @@
4495
         case CFG_METHOD_33:
4496
         case CFG_METHOD_34:
4497
         case CFG_METHOD_35:
4498
+        case CFG_METHOD_36:
4499
+        case CFG_METHOD_37:
4500
                 tp->HwSuppPhyOcpVer = 1;
4501
                 break;
4502
         }
4503
@@ -24863,6 +25954,7 @@
4504
         case CFG_METHOD_33:
4505
         case CFG_METHOD_34:
4506
         case CFG_METHOD_35:
4507
+        case CFG_METHOD_36:
4508
                 tp->HwSuppUpsVer = 1;
4509
                 break;
4510
         }
4511
@@ -24905,6 +25997,8 @@
4512
         case CFG_METHOD_33:
4513
         case CFG_METHOD_34:
4514
         case CFG_METHOD_35:
4515
+        case CFG_METHOD_36:
4516
+        case CFG_METHOD_37:
4517
                 tp->HwSuppAspmClkIntrLock = 1;
4518
                 break;
4519
         }
4520
@@ -24926,8 +26020,20 @@
4521
                         u64 CmacMemPhysAddress;
4522
                         void __iomem *cmac_ioaddr = NULL;
4523
                         struct pci_dev *pdev_cmac;
4524
+                        int ret;
4525
 
4526
                         pdev_cmac = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
4527
+                        ret = pci_enable_device(pdev_cmac);
4528
+                        if (ret < 0) {
4529
+                                dev_err(&pdev_cmac->dev, "eable device fail %d\n", ret);
4530
+                                goto err1;
4531
+                        }
4532
+
4533
+                        ret = pci_request_regions(pdev_cmac, MODULENAME);
4534
+                        if (ret < 0) {
4535
+                                dev_err(&pdev_cmac->dev, "could not request regions %d\n", ret);
4536
+                                goto err2;
4537
+                        }
4538
 
4539
                         //map CMAC IO space
4540
                         CmacMemPhysAddress = pci_resource_start(pdev_cmac, 2);
4541
@@ -24940,9 +26046,15 @@
4542
                                 if (netif_msg_probe(tp))
4543
                                         dev_err(&pdev->dev, "cannot remap CMAC MMIO, aborting\n");
4544
 #endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
4545
+                                pci_release_regions(pdev_cmac);
4546
+err2:
4547
+                                pci_disable_device(pdev_cmac);
4548
+err1:
4549
                                 tp->DASH = 0;
4550
                         } else {
4551
-                                tp->mapped_cmac_ioaddr = cmac_ioaddr;
4552
+                                pci_set_master(pdev_cmac);
4553
+                                tp->cmac_ioaddr = cmac_ioaddr;
4554
+                                tp->pdev_cmac = pdev_cmac;
4555
                         }
4556
                 }
4557
 
4558
@@ -24962,8 +26074,6 @@
4559
 
4560
         if (HW_DASH_SUPPORT_TYPE_2(tp))
4561
                 tp->cmac_ioaddr = tp->mmio_addr;
4562
-        else if (HW_DASH_SUPPORT_TYPE_3(tp))
4563
-                tp->cmac_ioaddr = tp->mapped_cmac_ioaddr;
4564
 
4565
         switch (tp->mcfg) {
4566
         case CFG_METHOD_1:
4567
@@ -25010,6 +26120,8 @@
4568
                 case CFG_METHOD_33:
4569
                 case CFG_METHOD_34:
4570
                 case CFG_METHOD_35:
4571
+                case CFG_METHOD_36:
4572
+                case CFG_METHOD_37:
4573
                         tp->org_pci_offset_99 = rtl8168_csi_fun0_read_byte(tp, 0x99);
4574
                         tp->org_pci_offset_99 &= ~(BIT_5|BIT_6);
4575
                         break;
4576
@@ -25023,6 +26135,8 @@
4577
                 case CFG_METHOD_29:
4578
                 case CFG_METHOD_30:
4579
                 case CFG_METHOD_35:
4580
+                case CFG_METHOD_36:
4581
+                case CFG_METHOD_37:
4582
                         tp->org_pci_offset_180 = rtl8168_csi_fun0_read_byte(tp, 0x180);
4583
                         break;
4584
                 case CFG_METHOD_31:
4585
@@ -25078,7 +26192,8 @@
4586
                 break;
4587
         }
4588
 
4589
-        if (timer_count == 0 || tp->mcfg == CFG_METHOD_DEFAULT)
4590
+        if (timer_count == 0 || tp->mcfg == CFG_METHOD_DEFAULT ||
4591
+            (tp->features & RTL_FEATURE_MSIX))
4592
                 tp->use_timer_interrrupt = FALSE;
4593
 
4594
         switch (tp->mcfg) {
4595
@@ -25095,7 +26210,8 @@
4596
         }
4597
 
4598
         switch (tp->mcfg) {
4599
-        case CFG_METHOD_30: {
4600
+        case CFG_METHOD_30:
4601
+        case CFG_METHOD_37: {
4602
                 u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0;
4603
                 u16 TmpUshort;
4604
 
4605
@@ -25130,7 +26246,9 @@
4606
         case CFG_METHOD_31:
4607
         case CFG_METHOD_32:
4608
         case CFG_METHOD_33:
4609
-        case CFG_METHOD_34: {
4610
+        case CFG_METHOD_34:
4611
+        case CFG_METHOD_36:
4612
+        case CFG_METHOD_37: {
4613
                 u16 rg_saw_cnt;
4614
 
4615
                 rtl8168_mdio_write(tp, 0x1F, 0x0C42);
4616
@@ -25197,6 +26315,7 @@
4617
                 case CFG_METHOD_19:
4618
                 case CFG_METHOD_20:
4619
                 case CFG_METHOD_30:
4620
+                case CFG_METHOD_37:
4621
                         tp->RequiredSecLanDonglePatch = TRUE;
4622
                         break;
4623
                 }
4624
@@ -25222,6 +26341,8 @@
4625
         case CFG_METHOD_33:
4626
         case CFG_METHOD_34:
4627
         case CFG_METHOD_35:
4628
+        case CFG_METHOD_36:
4629
+        case CFG_METHOD_37:
4630
                 tp->HwSuppMagicPktVer = WAKEUP_MAGIC_PACKET_V2;
4631
                 break;
4632
         case CFG_METHOD_DEFAULT:
4633
@@ -25276,6 +26397,8 @@
4634
         case CFG_METHOD_29:
4635
         case CFG_METHOD_30:
4636
         case CFG_METHOD_35:
4637
+        case CFG_METHOD_36:
4638
+        case CFG_METHOD_37:
4639
                 tp->HwSuppCheckPhyDisableModeVer = 2;
4640
                 break;
4641
         case CFG_METHOD_23:
4642
@@ -25325,6 +26448,7 @@
4643
                 break;
4644
         case CFG_METHOD_29:
4645
         case CFG_METHOD_30:
4646
+        case CFG_METHOD_37:
4647
                 tp->sw_ram_code_ver = NIC_RAMCODE_VERSION_CFG_METHOD_29;
4648
                 break;
4649
         case CFG_METHOD_31:
4650
@@ -25336,6 +26460,9 @@
4651
         case CFG_METHOD_35:
4652
                 tp->sw_ram_code_ver = NIC_RAMCODE_VERSION_CFG_METHOD_35;
4653
                 break;
4654
+        case CFG_METHOD_36:
4655
+                tp->sw_ram_code_ver = NIC_RAMCODE_VERSION_CFG_METHOD_36;
4656
+                break;
4657
         }
4658
 
4659
         if (tp->HwIcVerUnknown) {
4660
@@ -25343,6 +26470,83 @@
4661
                 tp->NotWrMcuPatchCode = TRUE;
4662
         }
4663
 
4664
+        switch (tp->mcfg) {
4665
+        case CFG_METHOD_16 ... CFG_METHOD_37:
4666
+                tp->HwSuppRxDescType = RX_DESC_RING_TYPE_2;
4667
+                break;
4668
+        default:
4669
+                tp->HwSuppRxDescType = RX_DESC_RING_TYPE_1;
4670
+                break;
4671
+        }
4672
+
4673
+        switch (tp->mcfg) {
4674
+        case CFG_METHOD_29:
4675
+        case CFG_METHOD_30:
4676
+        case CFG_METHOD_35:
4677
+        case CFG_METHOD_36:
4678
+        case CFG_METHOD_37:
4679
+                tp->HwSuppNumTxQueues = 2;
4680
+                tp->HwSuppNumRxQueues = 4;
4681
+                break;
4682
+        default:
4683
+                tp->HwSuppNumTxQueues = 1;
4684
+                tp->HwSuppNumRxQueues = 1;
4685
+                break;
4686
+        }
4687
+
4688
+        tp->num_tx_rings = 1;
4689
+#ifdef ENABLE_MULTIPLE_TX_QUEUE
4690
+#ifndef ENABLE_LIB_SUPPORT
4691
+        tp->num_tx_rings = tp->HwSuppNumTxQueues;
4692
+#endif
4693
+#endif
4694
+
4695
+        switch (tp->mcfg) {
4696
+        case CFG_METHOD_29:
4697
+        case CFG_METHOD_30:
4698
+        case CFG_METHOD_35:
4699
+        case CFG_METHOD_36:
4700
+        case CFG_METHOD_37:
4701
+                tp->HwSuppRssVer = 2;
4702
+                tp->HwSuppIndirTblEntries = RTL8168_MAX_INDIRECTION_TABLE_ENTRIES;
4703
+                break;
4704
+        }
4705
+
4706
+        tp->num_rx_rings = 1;
4707
+#ifdef ENABLE_RSS_SUPPORT
4708
+        if (HW_RSS_SUPPORT_RSS(tp)) {
4709
+#ifdef ENABLE_LIB_SUPPORT
4710
+                tp->EnableRss = 1;
4711
+#else
4712
+                u8 rss_queue_num = netif_get_num_default_rss_queues();
4713
+                tp->num_rx_rings = (tp->HwSuppNumRxQueues > rss_queue_num)?
4714
+                                   rss_queue_num : tp->HwSuppNumRxQueues;
4715
+                if (tp->num_rx_rings >= 2)
4716
+                        tp->EnableRss = 1;
4717
+#endif
4718
+        }
4719
+#endif
4720
+        if (!tp->EnableRss || tp->num_rx_rings < 1)
4721
+                tp->num_rx_rings = 1;
4722
+
4723
+#ifdef ENABLE_LIB_SUPPORT
4724
+        tp->num_hw_tot_en_rx_rings = 2;
4725
+#else
4726
+        tp->num_hw_tot_en_rx_rings = tp->num_rx_rings;
4727
+#endif //ENABLE_LIB_SUPPORT
4728
+
4729
+        rtl8168_setup_mqs_reg(tp);
4730
+
4731
+        rtl8168_set_ring_size(tp, NUM_RX_DESC, NUM_TX_DESC);
4732
+
4733
+        tp->InitRxDescType = RX_DESC_RING_TYPE_1;
4734
+        if (tp->EnableRss)
4735
+                tp->InitRxDescType = RX_DESC_RING_TYPE_2;
4736
+
4737
+        tp->RxDescLength = RX_DESC_LEN_TYPE_1;
4738
+        if (tp->InitRxDescType == RX_DESC_RING_TYPE_2)
4739
+                tp->RxDescLength = RX_DESC_LEN_TYPE_2;
4740
+
4741
         tp->NicCustLedValue = RTL_R16(tp, CustomLED);
4742
 
4743
         rtl8168_get_hw_wol(dev);
4744
@@ -25361,13 +26565,27 @@
4745
         dev->min_mtu = ETH_MIN_MTU;
4746
         dev->max_mtu = tp->max_jumbo_frame_size;
4747
 #endif //LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
4748
-        tp->eee_enabled = eee_enable;
4749
-        tp->eee_adv_t = MDIO_EEE_1000T | MDIO_EEE_100TX;
4750
+
4751
+        if (rtl8168_support_eee(tp)) {
4752
+                struct ethtool_eee *eee = &tp->eee;
4753
+
4754
+                eee->eee_enabled = eee_enable;
4755
+                eee->supported  = SUPPORTED_100baseT_Full |
4756
+                                  SUPPORTED_1000baseT_Full;
4757
+                eee->advertised = mmd_eee_adv_to_ethtool_adv_t(MDIO_EEE_1000T | MDIO_EEE_100TX);
4758
+                eee->tx_lpi_enabled = eee_enable;
4759
+                eee->tx_lpi_timer = dev->mtu + ETH_HLEN + 0x20;
4760
+        }
4761
 
4762
 #ifdef ENABLE_FIBER_SUPPORT
4763
         if (HW_FIBER_MODE_ENABLED(tp))
4764
                 rtl8168_set_fiber_mode_software_variable(tp);
4765
 #endif //ENABLE_FIBER_SUPPORT
4766
+
4767
+#ifdef ENABLE_RSS_SUPPORT
4768
+        if (tp->EnableRss)
4769
+                rtl8168_init_rss(tp);
4770
+#endif
4771
 }
4772
 
4773
 static void
4774
@@ -25389,8 +26607,13 @@
4775
                 FreeAllocatedDashShareMemory(dev);
4776
 #endif
4777
 
4778
-        if (tp->mapped_cmac_ioaddr != NULL)
4779
-                iounmap(tp->mapped_cmac_ioaddr);
4780
+        if (tp->pdev_cmac) {
4781
+                iounmap(tp->cmac_ioaddr);
4782
+                pci_clear_master(tp->pdev_cmac);
4783
+                pci_release_regions(tp->pdev_cmac);
4784
+                pci_disable_device(tp->pdev_cmac);
4785
+                tp->pdev_cmac = NULL;
4786
+        }
4787
 
4788
         iounmap(ioaddr);
4789
         pci_release_regions(pdev);
4790
@@ -25436,7 +26659,9 @@
4791
             tp->mcfg == CFG_METHOD_32 ||
4792
             tp->mcfg == CFG_METHOD_33 ||
4793
             tp->mcfg == CFG_METHOD_34 ||
4794
-            tp->mcfg == CFG_METHOD_35) {
4795
+            tp->mcfg == CFG_METHOD_35 ||
4796
+            tp->mcfg == CFG_METHOD_36 ||
4797
+            tp->mcfg == CFG_METHOD_37) {
4798
                 *(u32*)&mac_addr0 = rtl8168_eri_read(tp, 0xE0, 4, ERIAR_ExGMAC);
4799
                 *(u16*)&mac_addr4 = rtl8168_eri_read(tp, 0xE4, 2, ERIAR_ExGMAC);
4800
         } else {
4801
@@ -25462,7 +26687,9 @@
4802
                             tp->mcfg == CFG_METHOD_32 ||
4803
                             tp->mcfg == CFG_METHOD_33 ||
4804
                             tp->mcfg == CFG_METHOD_34 ||
4805
-                            tp->mcfg == CFG_METHOD_35) {
4806
+                            tp->mcfg == CFG_METHOD_35 ||
4807
+                            tp->mcfg == CFG_METHOD_36 ||
4808
+                            tp->mcfg == CFG_METHOD_37) {
4809
                                 *pUshort++ = rtl8168_eeprom_read_sc(tp, 1);
4810
                                 *pUshort++ = rtl8168_eeprom_read_sc(tp, 2);
4811
                                 *pUshort = rtl8168_eeprom_read_sc(tp, 3);
4812
@@ -25490,7 +26717,7 @@
4813
         /* keep the original MAC address */
4814
         memcpy(tp->org_mac_addr, dev->dev_addr, MAC_ADDR_LEN);
4815
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
4816
-        memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
4817
+        memcpy(dev->perm_addr, dev->dev_addr, MAC_ADDR_LEN);
4818
 #endif
4819
         return 0;
4820
 }
4821
@@ -25508,19 +26735,14 @@
4822
 {
4823
         struct rtl8168_private *tp = netdev_priv(dev);
4824
         struct sockaddr *addr = p;
4825
-        unsigned long flags;
4826
 
4827
         if (!is_valid_ether_addr(addr->sa_data))
4828
                 return -EADDRNOTAVAIL;
4829
 
4830
-        spin_lock_irqsave(&tp->lock, flags);
4831
-
4832
         rtl8168_hw_address_set(dev, addr->sa_data);
4833
 
4834
         rtl8168_rar_set(tp, dev->dev_addr);
4835
 
4836
-        spin_unlock_irqrestore(&tp->lock, flags);
4837
-
4838
         return 0;
4839
 }
4840
 
4841
@@ -26299,7 +27521,6 @@
4842
         struct rtl8168_private *tp = netdev_priv(dev);
4843
         struct mii_ioctl_data *data = if_mii(ifr);
4844
         int ret;
4845
-        unsigned long flags;
4846
 
4847
         ret = 0;
4848
         switch (cmd) {
4849
@@ -26308,19 +27529,15 @@
4850
                 break;
4851
 
4852
         case SIOCGMIIREG:
4853
-                spin_lock_irqsave(&tp->lock, flags);
4854
                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
4855
                 data->val_out = rtl8168_mdio_read(tp, data->reg_num);
4856
-                spin_unlock_irqrestore(&tp->lock, flags);
4857
                 break;
4858
 
4859
         case SIOCSMIIREG:
4860
                 if (!capable(CAP_NET_ADMIN))
4861
                         return -EPERM;
4862
-                spin_lock_irqsave(&tp->lock, flags);
4863
                 rtl8168_mdio_write(tp, 0x1F, 0x0000);
4864
                 rtl8168_mdio_write(tp, data->reg_num, data->val_in);
4865
-                spin_unlock_irqrestore(&tp->lock, flags);
4866
                 break;
4867
 
4868
 #ifdef ETHTOOL_OPS_COMPAT
4869
@@ -26472,6 +27689,8 @@
4870
         case CFG_METHOD_29:
4871
         case CFG_METHOD_30:
4872
         case CFG_METHOD_35:
4873
+        case CFG_METHOD_36:
4874
+        case CFG_METHOD_37:
4875
                 rtl8168_mdio_write(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN);
4876
                 break;
4877
         case CFG_METHOD_21:
4878
@@ -26501,7 +27720,7 @@
4879
         assert(ioaddr_out != NULL);
4880
 
4881
         /* dev zeroed in alloc_etherdev */
4882
-        dev = alloc_etherdev(sizeof (*tp));
4883
+        dev = alloc_etherdev_mq(sizeof (*tp), R8168_MAX_QUEUES);
4884
         if (dev == NULL) {
4885
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
4886
                 if (netif_msg_drv(&debug))
4887
@@ -26657,24 +27876,10 @@
4888
 }
4889
 
4890
 static void
4891
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
4892
-rtl8168_esd_timer(unsigned long __opaque)
4893
-#else
4894
-rtl8168_esd_timer(struct timer_list *t)
4895
-#endif
4896
+rtl8168_esd_checker(struct rtl8168_private *tp)
4897
 {
4898
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
4899
-        struct net_device *dev = (struct net_device *)__opaque;
4900
-        struct rtl8168_private *tp = netdev_priv(dev);
4901
-        struct timer_list *timer = &tp->esd_timer;
4902
-#else
4903
-        struct rtl8168_private *tp = from_timer(tp, t, esd_timer);
4904
         struct net_device *dev = tp->dev;
4905
-        struct timer_list *timer = t;
4906
-#endif
4907
         struct pci_dev *pdev = tp->pci_dev;
4908
-        unsigned long timeout = RTL8168_ESD_TIMEOUT;
4909
-        unsigned long flags;
4910
         u8 cmd;
4911
         u16 io_base_l;
4912
         u16 mem_base_l;
4913
@@ -26691,10 +27896,8 @@
4914
         u32 pci_sn_l;
4915
         u32 pci_sn_h;
4916
 
4917
-        spin_lock_irqsave(&tp->lock, flags);
4918
-
4919
         if (unlikely(tp->rtk_enable_diag))
4920
-                goto out_unlock;
4921
+                goto exit;
4922
 
4923
         tp->esd_flag = 0;
4924
 
4925
@@ -26707,7 +27910,7 @@
4926
                 pci_read_config_byte(pdev, PCI_COMMAND, &cmd);
4927
                 if (cmd == 0xff) {
4928
                         printk(KERN_ERR "%s: pci link is down \n.", dev->name);
4929
-                        goto out_unlock;
4930
+                        goto exit;
4931
                 }
4932
         }
4933
 
4934
@@ -26816,8 +28019,8 @@
4935
 
4936
         if (tp->esd_flag != 0) {
4937
                 printk(KERN_ERR "%s: esd_flag = 0x%04x\n.\n", dev->name, tp->esd_flag);
4938
-                netif_stop_queue(dev);
4939
                 netif_carrier_off(dev);
4940
+                netif_tx_disable(dev);
4941
                 rtl8168_hw_reset(dev);
4942
                 rtl8168_tx_clear(tp);
4943
                 rtl8168_rx_clear(tp);
4944
@@ -26831,12 +28034,34 @@
4945
                 tp->esd_flag = 0;
4946
         }
4947
 
4948
-out_unlock:
4949
-        spin_unlock_irqrestore(&tp->lock, flags);
4950
+exit:
4951
+        return;
4952
+}
4953
+
4954
+/*
4955
+static void
4956
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
4957
+rtl8168_esd_timer(unsigned long __opaque)
4958
+#else
4959
+rtl8168_esd_timer(struct timer_list *t)
4960
+#endif
4961
+{
4962
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
4963
+        struct net_device *dev = (struct net_device *)__opaque;
4964
+        struct rtl8168_private *tp = netdev_priv(dev);
4965
+        struct timer_list *timer = &tp->esd_timer;
4966
+#else
4967
+        struct rtl8168_private *tp = from_timer(tp, t, esd_timer);
4968
+        //struct net_device *dev = tp->dev;
4969
+        struct timer_list *timer = t;
4970
+#endif
4971
+        rtl8168_esd_checker(tp);
4972
 
4973
         mod_timer(timer, jiffies + timeout);
4974
 }
4975
+*/
4976
 
4977
+/*
4978
 static void
4979
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
4980
 rtl8168_link_timer(unsigned long __opaque)
4981
@@ -26853,36 +28078,71 @@
4982
         struct net_device *dev = tp->dev;
4983
         struct timer_list *timer = t;
4984
 #endif
4985
-        unsigned long flags;
4986
-
4987
-        spin_lock_irqsave(&tp->lock, flags);
4988
         rtl8168_check_link_status(dev);
4989
-        spin_unlock_irqrestore(&tp->lock, flags);
4990
 
4991
         mod_timer(timer, jiffies + RTL8168_LINK_TIMEOUT);
4992
 }
4993
+*/
4994
 
4995
-static int rtl8168_enable_msix(struct rtl8168_private *tp)
4996
+int rtl8168_enable_msix(struct rtl8168_private *tp)
4997
 {
4998
-        int nvecs = 0;
4999
-        struct msix_entry msix_ent1 = {0};
5000
+        int i, nvecs = 0;
5001
+        struct msix_entry msix_entR8168_MAX_MSIX_VEC;
5002
+        //struct net_device *dev = tp->dev;
5003
+        //const int len = sizeof(tp->irq_tbl0.name);
5004
+
5005
+        for (i = 0; i < R8168_MAX_MSIX_VEC; i++) {
5006
+                msix_enti.entry = i;
5007
+                msix_enti.vector = 0;
5008
+        }
5009
 
5010
         nvecs = pci_enable_msix_range(tp->pci_dev, msix_ent,
5011
-                                      1, 1);
5012
+                                      tp->min_irq_nvecs, tp->max_irq_nvecs);
5013
         if (nvecs < 0)
5014
                 goto out;
5015
 
5016
-        tp->irq = msix_ent0.vector;
5017
+        for (i = 0; i < nvecs; i++) {
5018
+                struct r8168_irq *irq = &tp->irq_tbli;
5019
+                irq->vector = msix_enti.vector;
5020
+                //snprintf(irq->name, len, "%s-%d", dev->name, i);
5021
+                //irq->handler = rtl8168_interrupt_msix;
5022
+        }
5023
+
5024
 out:
5025
         return nvecs;
5026
 }
5027
 
5028
 /* Cfg9346_Unlock assumed. */
5029
-static unsigned rtl8168_try_msi(struct pci_dev *pdev, struct rtl8168_private *tp)
5030
+static int rtl8168_try_msi(struct rtl8168_private *tp)
5031
 {
5032
+        struct pci_dev *pdev = tp->pci_dev;
5033
+        unsigned int hw_supp_irq_nvecs;
5034
         unsigned msi = 0;
5035
+        int nvecs = 1;
5036
 
5037
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
5038
+        switch (tp->mcfg) {
5039
+        case CFG_METHOD_4 ... CFG_METHOD_8:
5040
+                hw_supp_irq_nvecs = 2;
5041
+                break;
5042
+        case CFG_METHOD_9 ... CFG_METHOD_37:
5043
+                hw_supp_irq_nvecs = 4;
5044
+                break;
5045
+        default:
5046
+                hw_supp_irq_nvecs = 1;
5047
+                break;
5048
+        }
5049
+        tp->hw_supp_irq_nvecs = clamp_val(hw_supp_irq_nvecs, 1,
5050
+                                          R8168_MAX_MSIX_VEC);
5051
+
5052
+        tp->max_irq_nvecs = 1;
5053
+        tp->min_irq_nvecs = 1;
5054
+
5055
+#ifdef ENABLE_RSS_SUPPORT
5056
+        if (!pci_enable_msi(pdev))
5057
+                msi |= RTL_FEATURE_MSI;
5058
+        else
5059
+                dev_info(&pdev->dev, "Default use INTx.\n");
5060
+#else
5061
         switch (tp->mcfg) {
5062
         case CFG_METHOD_1:
5063
         case CFG_METHOD_2:
5064
@@ -26895,40 +28155,55 @@
5065
                 dev_info(&pdev->dev, "Default use INTx.\n");
5066
                 break;
5067
         default:
5068
-                if (rtl8168_enable_msix(tp) > 0)
5069
+#if defined(RTL_USE_NEW_INTR_API)
5070
+                if ((nvecs = pci_alloc_irq_vectors(pdev, tp->min_irq_nvecs, tp->max_irq_nvecs, PCI_IRQ_MSIX)) > 0)
5071
+                        msi |= RTL_FEATURE_MSIX;
5072
+                else if ((nvecs = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES)) > 0 &&
5073
+                         pci_dev_msi_enabled(pdev))
5074
+                        msi |= RTL_FEATURE_MSI;
5075
+#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
5076
+                if ((nvecs = rtl8168_enable_msix(tp)) > 0)
5077
                         msi |= RTL_FEATURE_MSIX;
5078
                 else if (!pci_enable_msi(pdev))
5079
                         msi |= RTL_FEATURE_MSI;
5080
-                else
5081
-                        dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
5082
+#endif
5083
                 break;
5084
         }
5085
-#endif
5086
+#endif //ENABLE_RSS_SUPPORT
5087
+        if (!(msi & (RTL_FEATURE_MSI | RTL_FEATURE_MSIX)))
5088
+                dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
5089
 
5090
-        if (msi & RTL_FEATURE_MSIX)
5091
-                goto out;
5092
+        if (!(msi & RTL_FEATURE_MSIX) || nvecs < 1)
5093
+                nvecs = 1;
5094
 
5095
-        tp->irq = pdev->irq;
5096
+        tp->irq_nvecs = nvecs;
5097
 
5098
-out:
5099
-        return msi;
5100
+        tp->features |= msi;
5101
+
5102
+        return nvecs;
5103
 }
5104
 
5105
 static void rtl8168_disable_msi(struct pci_dev *pdev, struct rtl8168_private *tp)
5106
 {
5107
-        if (tp->features & RTL_FEATURE_MSIX) {
5108
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
5109
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
5110
+        if (tp->features & (RTL_FEATURE_MSI | RTL_FEATURE_MSIX))
5111
+                pci_free_irq_vectors(pdev);
5112
+#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
5113
+        if (tp->features & (RTL_FEATURE_MSIX))
5114
                 pci_disable_msix(pdev);
5115
+        else if (tp->features & (RTL_FEATURE_MSI))
5116
+                pci_disable_msi(pdev);
5117
 #endif
5118
-                tp->features &= ~RTL_FEATURE_MSIX;
5119
-        }
5120
+        tp->features &= ~(RTL_FEATURE_MSI | RTL_FEATURE_MSIX);
5121
+}
5122
 
5123
-        if (tp->features & RTL_FEATURE_MSI) {
5124
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
5125
-                pci_disable_msi(pdev);
5126
+static int rtl8168_get_irq(struct pci_dev *pdev)
5127
+{
5128
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
5129
+        return pci_irq_vector(pdev, 0);
5130
+#else
5131
+        return pdev->irq;
5132
 #endif
5133
-                tp->features &= ~RTL_FEATURE_MSI;
5134
-        }
5135
 }
5136
 
5137
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
5138
@@ -26965,6 +28240,82 @@
5139
 };
5140
 #endif
5141
 
5142
+#ifdef  CONFIG_R8168_NAPI
5143
+
5144
+void rtl8168_enable_napi(struct rtl8168_private *tp)
5145
+{
5146
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
5147
+        int i;
5148
+
5149
+        for (i = 0; i < tp->irq_nvecs; i++)
5150
+                RTL_NAPI_ENABLE(tp->dev, &tp->r8168napii.napi);
5151
+#endif
5152
+}
5153
+
5154
+static void rtl8168_disable_napi(struct rtl8168_private *tp)
5155
+{
5156
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
5157
+        int i;
5158
+
5159
+        for (i = 0; i < tp->irq_nvecs; i++)
5160
+                RTL_NAPI_DISABLE(tp->dev, &tp->r8168napii.napi);
5161
+#endif
5162
+}
5163
+
5164
+static void rtl8168_del_napi(struct rtl8168_private *tp)
5165
+{
5166
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
5167
+        int i;
5168
+
5169
+        for (i = 0; i < tp->irq_nvecs; i++)
5170
+                RTL_NAPI_DEL((&tp->r8168napii));
5171
+#endif
5172
+}
5173
+#endif //CONFIG_R8168_NAPI
5174
+
5175
+static void rtl8168_init_napi(struct rtl8168_private *tp)
5176
+{
5177
+        int i;
5178
+
5179
+        for (i=0; i<tp->irq_nvecs; i++) {
5180
+                struct r8168_napi *r8168napi = &tp->r8168napii;
5181
+#ifdef CONFIG_R8168_NAPI
5182
+                int (*poll)(struct napi_struct *, int);
5183
+
5184
+                if (tp->features & RTL_FEATURE_MSIX) {
5185
+                        if (i == 0)
5186
+                                poll = rtl8168_poll_msix_ring;
5187
+                        else
5188
+                                poll = rtl8168_poll_msix_rx;
5189
+                } else {
5190
+                        poll = rtl8168_poll;
5191
+                }
5192
+
5193
+                RTL_NAPI_CONFIG(tp->dev, r8168napi, poll, R8168_NAPI_WEIGHT);
5194
+#endif
5195
+
5196
+                r8168napi->priv = tp;
5197
+                r8168napi->index = i;
5198
+        }
5199
+}
5200
+
5201
+static int
5202
+rtl8168_set_real_num_queue(struct rtl8168_private *tp)
5203
+{
5204
+        int retval = 0;
5205
+
5206
+        retval = netif_set_real_num_tx_queues(tp->dev, tp->num_tx_rings);
5207
+        if (retval < 0)
5208
+                goto exit;
5209
+
5210
+        retval = netif_set_real_num_rx_queues(tp->dev, tp->num_rx_rings);
5211
+        if (retval < 0)
5212
+                goto exit;
5213
+
5214
+exit:
5215
+        return retval;
5216
+}
5217
+
5218
 static int __devinit
5219
 rtl8168_init_one(struct pci_dev *pdev,
5220
                  const struct pci_device_id *ent)
5221
@@ -26998,7 +28349,13 @@
5222
         tp->phy_reset_pending = rtl8168_xmii_reset_pending;
5223
         tp->link_ok = rtl8168_xmii_link_ok;
5224
 
5225
-        tp->features |= rtl8168_try_msi(pdev, tp);
5226
+        rc = rtl8168_try_msi(tp);
5227
+        if (rc < 0) {
5228
+                dev_err(&pdev->dev, "Can't allocate interrupt\n");
5229
+                goto err_out_1;
5230
+        }
5231
+
5232
+        rtl8168_init_software_variable(dev);
5233
 
5234
         RTL_NET_DEVICE_OPS(rtl8168_netdev_ops);
5235
 
5236
@@ -27007,16 +28364,17 @@
5237
 #endif
5238
 
5239
         dev->watchdog_timeo = RTL8168_TX_TIMEOUT;
5240
-        dev->irq = tp->irq;
5241
+        dev->irq = rtl8168_get_irq(pdev);
5242
         dev->base_addr = (unsigned long) ioaddr;
5243
 
5244
-#ifdef CONFIG_R8168_NAPI
5245
-        RTL_NAPI_CONFIG(dev, tp, rtl8168_poll, R8168_NAPI_WEIGHT);
5246
-#endif
5247
+        rtl8168_init_napi(tp);
5248
 
5249
 #ifdef CONFIG_R8168_VLAN
5250
         if (tp->mcfg != CFG_METHOD_DEFAULT) {
5251
-                dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
5252
+                dev->features |= NETIF_F_HW_VLAN_TX;
5253
+#ifndef ENABLE_LIB_SUPPORT
5254
+                dev->features |= NETIF_F_HW_VLAN_RX;
5255
+#endif //!ENABLE_LIB_SUPPORT
5256
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
5257
                 dev->vlan_rx_kill_vid = rtl8168_vlan_rx_kill_vid;
5258
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
5259
@@ -27040,9 +28398,16 @@
5260
                 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM |
5261
                                      NETIF_F_HIGHDMA;
5262
                 if ((tp->mcfg != CFG_METHOD_16) && (tp->mcfg != CFG_METHOD_17)) {
5263
-                        //dev->features |= NETIF_F_TSO;
5264
                         dev->hw_features |= NETIF_F_TSO;
5265
                         dev->vlan_features |= NETIF_F_TSO;
5266
+                        switch (tp->mcfg) {
5267
+                        case CFG_METHOD_1 ... CFG_METHOD_26:
5268
+                                /* nothing to do */
5269
+                                break;
5270
+                        default:
5271
+                                dev->features |= NETIF_F_SG | NETIF_F_TSO;
5272
+                                break;
5273
+                        };
5274
                 }
5275
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)
5276
                 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
5277
@@ -27069,7 +28434,14 @@
5278
                         dev->features |=  NETIF_F_IPV6_CSUM;
5279
                         if ((tp->mcfg != CFG_METHOD_16) && (tp->mcfg != CFG_METHOD_17)) {
5280
                                 dev->hw_features |= NETIF_F_TSO6;
5281
-                                //dev->features |=  NETIF_F_TSO6;
5282
+                                switch (tp->mcfg) {
5283
+                                case CFG_METHOD_1 ... CFG_METHOD_26:
5284
+                                        /* nothing to do */
5285
+                                        break;
5286
+                                default:
5287
+                                        dev->features |=  NETIF_F_TSO6;
5288
+                                        break;
5289
+                                };
5290
                         }
5291
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)
5292
                         netif_set_tso_max_size(dev, LSO_64K);
5293
@@ -27088,15 +28460,27 @@
5294
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
5295
         }
5296
 
5297
-        spin_lock_init(&tp->lock);
5298
-
5299
-        rtl8168_init_software_variable(dev);
5300
+#ifdef ENABLE_RSS_SUPPORT
5301
+        if (tp->EnableRss) {
5302
+                dev->hw_features |= NETIF_F_RXHASH;
5303
+                dev->features |=  NETIF_F_RXHASH;
5304
+        }
5305
+#endif
5306
 
5307
 #ifdef ENABLE_DASH_SUPPORT
5308
         if (tp->DASH)
5309
                 AllocateDashShareMemory(dev);
5310
 #endif
5311
 
5312
+#ifdef ENABLE_LIB_SUPPORT
5313
+        BLOCKING_INIT_NOTIFIER_HEAD(&tp->lib_nh);
5314
+#endif
5315
+        rtl8168_init_all_schedule_work(tp);
5316
+
5317
+        rc = rtl8168_set_real_num_queue(tp);
5318
+        if (rc < 0)
5319
+                goto err_out;
5320
+
5321
         rtl8168_exit_oob(dev);
5322
 
5323
         rtl8168_hw_init(dev);
5324
@@ -27106,7 +28490,8 @@
5325
         /* Get production from EEPROM */
5326
         if (((tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
5327
               tp->mcfg == CFG_METHOD_25 || tp->mcfg == CFG_METHOD_29 ||
5328
-              tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_35) &&
5329
+              tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_35 ||
5330
+              tp->mcfg == CFG_METHOD_36 || tp->mcfg == CFG_METHOD_37) &&
5331
              (rtl8168_mac_ocp_read(tp, 0xDC00) & BIT_3)) ||
5332
             ((tp->mcfg == CFG_METHOD_26) && (rtl8168_mac_ocp_read(tp, 0xDC00) & BIT_4)))
5333
                 tp->eeprom_type = EEPROM_TYPE_NONE;
5334
@@ -27162,9 +28547,11 @@
5335
                 tp->tally_vaddr = NULL;
5336
         }
5337
 #ifdef  CONFIG_R8168_NAPI
5338
-        RTL_NAPI_DEL(tp);
5339
+        rtl8168_del_napi(tp);
5340
 #endif
5341
         rtl8168_disable_msi(pdev, tp);
5342
+
5343
+err_out_1:
5344
         rtl8168_release_board(pdev, dev);
5345
 
5346
         goto out;
5347
@@ -27179,8 +28566,12 @@
5348
         assert(dev != NULL);
5349
         assert(tp != NULL);
5350
 
5351
+        set_bit(R8168_FLAG_DOWN, tp->task_flags);
5352
+
5353
+        rtl8168_cancel_all_schedule_work(tp);
5354
+
5355
 #ifdef  CONFIG_R8168_NAPI
5356
-        RTL_NAPI_DEL(tp);
5357
+        rtl8168_del_napi(tp);
5358
 #endif
5359
         if (HW_DASH_SUPPORT_DASH(tp))
5360
                 rtl8168_driver_stop(tp);
5361
@@ -27204,13 +28595,180 @@
5362
         pci_set_drvdata(pdev, NULL);
5363
 }
5364
 
5365
+static void rtl8168_free_irq(struct rtl8168_private *tp)
5366
+{
5367
+        int i;
5368
+
5369
+        for (i=0; i<tp->irq_nvecs; i++) {
5370
+                struct r8168_irq *irq = &tp->irq_tbli;
5371
+                struct r8168_napi *r8168napi = &tp->r8168napii;
5372
+
5373
+                if (irq->requested) {
5374
+                        irq->requested = 0;
5375
+#if defined(RTL_USE_NEW_INTR_API)
5376
+                        pci_free_irq(tp->pci_dev, i, r8168napi);
5377
+#else
5378
+                        free_irq(irq->vector, r8168napi);
5379
+#endif
5380
+                }
5381
+        }
5382
+}
5383
+
5384
+static int rtl8168_alloc_irq(struct rtl8168_private *tp)
5385
+{
5386
+        struct net_device *dev = tp->dev;
5387
+        int rc = 0;
5388
+        struct r8168_irq *irq;
5389
+        struct r8168_napi *r8168napi;
5390
+        int i = 0;
5391
+        const int len = sizeof(tp->irq_tbl0.name);
5392
+
5393
+#if defined(RTL_USE_NEW_INTR_API)
5394
+        for (i=0; i<tp->irq_nvecs; i++) {
5395
+                irq = &tp->irq_tbli;
5396
+                if (tp->features & RTL_FEATURE_MSIX)
5397
+                        irq->handler = rtl8168_interrupt_msix;
5398
+                else
5399
+                        irq->handler = rtl8168_interrupt;
5400
+
5401
+                r8168napi = &tp->r8168napii;
5402
+                snprintf(irq->name, len, "%s-%d", dev->name, i);
5403
+                rc = pci_request_irq(tp->pci_dev, i, irq->handler, NULL, r8168napi,
5404
+                                     irq->name);
5405
+                if (rc)
5406
+                        break;
5407
+
5408
+                irq->vector = pci_irq_vector(tp->pci_dev, i);
5409
+                irq->requested = 1;
5410
+        }
5411
+#else
5412
+        unsigned long irq_flags = 0;
5413
+#ifdef ENABLE_LIB_SUPPORT
5414
+        if (tp->features & (RTL_FEATURE_MSI | RTL_FEATURE_MSIX))
5415
+                irq_flags |= IRQF_NO_SUSPEND;
5416
+#endif //ENABLE_LIB_SUPPORT
5417
+        if (tp->features & RTL_FEATURE_MSIX) {
5418
+                for (i=0; i<tp->irq_nvecs; i++) {
5419
+                        irq = &tp->irq_tbli;
5420
+                        irq->handler = rtl8168_interrupt_msix;
5421
+                        r8168napi = &tp->r8168napii;
5422
+                        snprintf(irq->name, len, "%s-%d", dev->name, i);
5423
+                        rc = request_irq(irq->vector, irq->handler, irq_flags, irq->name, r8168napi);
5424
+
5425
+                        if (rc)
5426
+                                break;
5427
+
5428
+                        irq->requested = 1;
5429
+                }
5430
+        } else {
5431
+                irq = &tp->irq_tbl0;
5432
+                irq->handler = rtl8168_interrupt;
5433
+                r8168napi = &tp->r8168napi0;
5434
+                snprintf(irq->name, len, "%s-0", dev->name);
5435
+                irq->vector = dev->irq;
5436
+                irq_flags |= (tp->features & (RTL_FEATURE_MSI | RTL_FEATURE_MSIX)) ? 0 : SA_SHIRQ;
5437
+                rc = request_irq(irq->vector, irq->handler, irq_flags, irq->name, r8168napi);
5438
+
5439
+                if (rc == 0)
5440
+                        irq->requested = 1;
5441
+        }
5442
+#endif
5443
+        if (rc)
5444
+                rtl8168_free_irq(tp);
5445
+
5446
+        return rc;
5447
+}
5448
+
5449
 static void
5450
 rtl8168_set_rxbufsize(struct rtl8168_private *tp,
5451
                       struct net_device *dev)
5452
 {
5453
         unsigned int mtu = dev->mtu;
5454
 
5455
-        tp->rx_buf_sz = (mtu > ETH_DATA_LEN) ? mtu + ETH_HLEN + 8 + 1 : RX_BUF_SIZE;
5456
+        tp->rx_buf_sz = (mtu > ETH_DATA_LEN) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE;
5457
+
5458
+        switch (tp->mcfg) {
5459
+        case CFG_METHOD_1 ... CFG_METHOD_26:
5460
+                tp->rx_buf_sz += 1;
5461
+                break;
5462
+        default:
5463
+                break;
5464
+        }
5465
+}
5466
+
5467
+static int rtl8168_alloc_tx_desc(struct rtl8168_private *tp)
5468
+{
5469
+        struct pci_dev *pdev = tp->pci_dev;
5470
+        struct rtl8168_tx_ring *ring;
5471
+        int i;
5472
+
5473
+        for (i = 0; i < tp->num_tx_rings; i++) {
5474
+                ring = &tp->tx_ringi;
5475
+                ring->TxDescAllocSize = (ring->num_tx_desc + 1) * sizeof(struct TxDesc);
5476
+                ring->TxDescArray = dma_alloc_coherent(&pdev->dev,
5477
+                                                       ring->TxDescAllocSize,
5478
+                                                       &ring->TxPhyAddr,
5479
+                                                       GFP_KERNEL);
5480
+
5481
+                if (!ring->TxDescArray)
5482
+                        return -1;
5483
+        }
5484
+
5485
+        return 0;
5486
+}
5487
+
5488
+static int rtl8168_alloc_rx_desc(struct rtl8168_private *tp)
5489
+{
5490
+        struct pci_dev *pdev = tp->pci_dev;
5491
+
5492
+        if (tp->InitRxDescType == RX_DESC_RING_TYPE_2)
5493
+                tp->RxDescAllocSize = ((tp->num_rx_desc + 1) * tp->num_hw_tot_en_rx_rings)
5494
+                                      * tp->RxDescLength;
5495
+        else
5496
+                tp->RxDescAllocSize = (tp->num_rx_desc + 1) * tp->RxDescLength;
5497
+
5498
+        tp->RxDescArray = dma_alloc_coherent(&pdev->dev, tp->RxDescAllocSize,
5499
+                                             &tp->RxPhyAddr, GFP_KERNEL);
5500
+        if (!tp->RxDescArray)
5501
+                return -1;
5502
+
5503
+        return 0;
5504
+}
5505
+
5506
+static void rtl8168_free_tx_desc(struct rtl8168_private *tp)
5507
+{
5508
+        struct rtl8168_tx_ring *ring;
5509
+        struct pci_dev *pdev = tp->pci_dev;
5510
+        int i;
5511
+
5512
+        for (i = 0; i < tp->num_tx_rings; i++) {
5513
+                ring = &tp->tx_ringi;
5514
+                if (ring->TxDescArray) {
5515
+                        dma_free_coherent(&pdev->dev,
5516
+                                          ring->TxDescAllocSize,
5517
+                                          ring->TxDescArray,
5518
+                                          ring->TxPhyAddr);
5519
+                        ring->TxDescArray = NULL;
5520
+                }
5521
+        }
5522
+}
5523
+
5524
+static void rtl8168_free_rx_desc(struct rtl8168_private *tp)
5525
+{
5526
+        struct pci_dev *pdev = tp->pci_dev;
5527
+
5528
+        if (tp->RxDescArray) {
5529
+                dma_free_coherent(&pdev->dev, tp->RxDescAllocSize, tp->RxDescArray,
5530
+                                  tp->RxPhyAddr);
5531
+                tp->RxDescArray = NULL;
5532
+        }
5533
+}
5534
+
5535
+static void rtl8168_free_alloc_resources(struct rtl8168_private *tp)
5536
+{
5537
+        rtl8168_free_rx_desc(tp);
5538
+
5539
+        rtl8168_free_tx_desc(tp);
5540
 }
5541
 
5542
 #ifdef ENABLE_USE_FIRMWARE_FILE
5543
@@ -27240,11 +28798,10 @@
5544
 }
5545
 #endif
5546
 
5547
-static int rtl8168_open(struct net_device *dev)
5548
+int rtl8168_open(struct net_device *dev)
5549
 {
5550
         struct rtl8168_private *tp = netdev_priv(dev);
5551
         struct pci_dev *pdev = tp->pci_dev;
5552
-        unsigned long flags;
5553
         int retval;
5554
 
5555
         retval = -ENOMEM;
5556
@@ -27257,27 +28814,14 @@
5557
         * Rx and Tx descriptors needs 256 bytes alignment.
5558
         * pci_alloc_consistent provides more.
5559
         */
5560
-        tp->TxDescAllocSize = (tp->num_tx_desc + 1) * sizeof(struct TxDesc);
5561
-        tp->TxDescArray = dma_alloc_coherent(&pdev->dev,
5562
-                                             tp->TxDescAllocSize,
5563
-                                             &tp->TxPhyAddr, GFP_KERNEL);
5564
-        if (!tp->TxDescArray)
5565
-                goto err_free_all_allocated_mem;
5566
-
5567
-        tp->RxDescAllocSize = (tp->num_rx_desc + 1) * sizeof(struct RxDesc);
5568
-        tp->RxDescArray = dma_alloc_coherent(&pdev->dev,
5569
-                                             tp->RxDescAllocSize,
5570
-                                             &tp->RxPhyAddr, GFP_KERNEL);
5571
-        if (!tp->RxDescArray)
5572
+        if (rtl8168_alloc_tx_desc(tp) < 0 || rtl8168_alloc_rx_desc(tp) < 0)
5573
                 goto err_free_all_allocated_mem;
5574
 
5575
         retval = rtl8168_init_ring(dev);
5576
         if (retval < 0)
5577
                 goto err_free_all_allocated_mem;
5578
 
5579
-        retval = request_irq(tp->irq, rtl8168_interrupt, (tp->features &
5580
-                             (RTL_FEATURE_MSI | RTL_FEATURE_MSIX)) ? 0 :
5581
-                             SA_SHIRQ, dev->name, dev);
5582
+        retval = rtl8168_alloc_irq(tp);
5583
         if (retval<0)
5584
                 goto err_free_all_allocated_mem;
5585
 
5586
@@ -27289,28 +28833,24 @@
5587
                        dev->base_addr,
5588
                        dev->dev_addr0, dev->dev_addr1,
5589
                        dev->dev_addr2, dev->dev_addr3,
5590
-                       dev->dev_addr4, dev->dev_addr5, tp->irq);
5591
+                       dev->dev_addr4, dev->dev_addr5, dev->irq);
5592
         }
5593
 
5594
 #ifdef ENABLE_USE_FIRMWARE_FILE
5595
         rtl8168_request_firmware(tp);
5596
 #endif
5597
-
5598
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
5599
-        INIT_WORK(&tp->task, rtl8168_reset_task, dev);
5600
-#else
5601
-        INIT_DELAYED_WORK(&tp->task, rtl8168_reset_task);
5602
-#endif
5603
-
5604
+        /*
5605
+        #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
5606
+                INIT_WORK(&tp->task, rtl8168_reset_task, dev);
5607
+        #else
5608
+                INIT_DELAYED_WORK(&tp->task, rtl8168_reset_task);
5609
+        #endif
5610
+        */
5611
         pci_set_master(pdev);
5612
 
5613
 #ifdef  CONFIG_R8168_NAPI
5614
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
5615
-        RTL_NAPI_ENABLE(dev, &tp->napi);
5616
+        rtl8168_enable_napi(tp);
5617
 #endif
5618
-#endif
5619
-        spin_lock_irqsave(&tp->lock, flags);
5620
-
5621
         rtl8168_exit_oob(dev);
5622
 
5623
         rtl8168_hw_init(dev);
5624
@@ -27327,35 +28867,24 @@
5625
 
5626
         rtl8168_dsm(dev, DSM_IF_UP);
5627
 
5628
-        rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
5629
+        clear_bit(R8168_FLAG_DOWN, tp->task_flags);
5630
 
5631
-        spin_unlock_irqrestore(&tp->lock, flags);
5632
+        rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
5633
 
5634
-        if (tp->esd_flag == 0)
5635
-                rtl8168_request_esd_timer(dev);
5636
+        if (tp->esd_flag == 0) {
5637
+                //rtl8168_request_esd_timer(dev);
5638
+                rtl8168_schedule_esd_work(tp);
5639
+        }
5640
 
5641
-        rtl8168_request_link_timer(dev);
5642
+        //rtl8168_request_link_timer(dev);
5643
+        rtl8168_schedule_linkchg_work(tp);
5644
 
5645
 out:
5646
 
5647
         return retval;
5648
 
5649
 err_free_all_allocated_mem:
5650
-        if (tp->RxDescArray != NULL) {
5651
-                dma_free_coherent(&pdev->dev,
5652
-                                  tp->RxDescAllocSize,
5653
-                                  tp->RxDescArray,
5654
-                                  tp->RxPhyAddr);
5655
-                tp->RxDescArray = NULL;
5656
-        }
5657
-
5658
-        if (tp->TxDescArray != NULL) {
5659
-                dma_free_coherent(&pdev->dev,
5660
-                                  tp->TxDescAllocSize,
5661
-                                  tp->TxDescArray,
5662
-                                  tp->TxPhyAddr);
5663
-                tp->TxDescArray = NULL;
5664
-        }
5665
+        rtl8168_free_alloc_resources(tp);
5666
 
5667
         goto out;
5668
 }
5669
@@ -27392,7 +28921,6 @@
5670
 
5671
                 break;
5672
         }
5673
-
5674
 }
5675
 
5676
 static void
5677
@@ -27495,6 +29023,18 @@
5678
         mc_filter1 = swab32(tmp);
5679
 
5680
         tp->rtl8168_rx_config = rtl_chip_infotp->chipset.RCR_Cfg;
5681
+        switch (tp->mcfg) {
5682
+        case CFG_METHOD_21 ... CFG_METHOD_35:
5683
+                if (tp->EnableRss)
5684
+                        tp->rtl8168_rx_config &= ~Rx_Single_fetch_V2;
5685
+                else
5686
+                        tp->rtl8168_rx_config |= Rx_Single_fetch_V2;
5687
+                break;
5688
+        default:
5689
+                break;
5690
+        }
5691
+        if (tp->InitRxDescType == RX_DESC_RING_TYPE_2)
5692
+                tp->rtl8168_rx_config |= RxCfg_rx_desc_v2_en;
5693
         tmp = tp->rtl8168_rx_config | rx_mode | (RTL_R32(tp, RxConfig) & rtl_chip_infotp->chipset.RxConfigMask);
5694
 
5695
         RTL_W32(tp, RxConfig, tmp);
5696
@@ -27505,17 +29045,10 @@
5697
 static void
5698
 rtl8168_set_rx_mode(struct net_device *dev)
5699
 {
5700
-        struct rtl8168_private *tp = netdev_priv(dev);
5701
-        unsigned long flags;
5702
-
5703
-        spin_lock_irqsave(&tp->lock, flags);
5704
-
5705
         rtl8168_hw_set_rx_packet_filter(dev);
5706
-
5707
-        spin_unlock_irqrestore(&tp->lock, flags);
5708
 }
5709
 
5710
-static void
5711
+void
5712
 rtl8168_hw_config(struct net_device *dev)
5713
 {
5714
         struct rtl8168_private *tp = netdev_priv(dev);
5715
@@ -27531,8 +29064,7 @@
5716
                 dev->features |= NETIF_F_IP_CSUM;
5717
         }
5718
 #endif
5719
-
5720
-        RTL_W32(tp, RxConfig, (RX_DMA_BURST << RxCfgDMAShift));
5721
+        rtl8168_disable_rx_packet_filter(tp);
5722
 
5723
         rtl8168_hw_reset(dev);
5724
 
5725
@@ -27542,6 +29074,8 @@
5726
                 rtl8168_hw_aspm_clkreq_enable(tp, false);
5727
         }
5728
 
5729
+        rtl8168_set_eee_lpi_timer(tp);
5730
+
5731
         //clear io_rdy_l23
5732
         switch (tp->mcfg) {
5733
         case CFG_METHOD_20:
5734
@@ -27560,6 +29094,8 @@
5735
         case CFG_METHOD_33:
5736
         case CFG_METHOD_34:
5737
         case CFG_METHOD_35:
5738
+        case CFG_METHOD_36:
5739
+        case CFG_METHOD_37:
5740
                 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~BIT_1);
5741
                 break;
5742
         }
5743
@@ -27586,6 +29122,8 @@
5744
         case CFG_METHOD_33:
5745
         case CFG_METHOD_34:
5746
         case CFG_METHOD_35:
5747
+        case CFG_METHOD_36:
5748
+        case CFG_METHOD_37:
5749
                 csi_tmp = rtl8168_eri_read(tp, 0xDE, 1, ERIAR_ExGMAC);
5750
                 csi_tmp &= BIT_0;
5751
                 rtl8168_eri_write(tp, 0xDE, 1, csi_tmp, ERIAR_ExGMAC);
5752
@@ -27978,15 +29516,21 @@
5753
         } else if (tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22 ||
5754
                    tp->mcfg == CFG_METHOD_24 || tp->mcfg == CFG_METHOD_25 ||
5755
                    tp->mcfg == CFG_METHOD_26 || tp->mcfg == CFG_METHOD_29 ||
5756
-                   tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_35) {
5757
+                   tp->mcfg == CFG_METHOD_30 || tp->mcfg == CFG_METHOD_35 ||
5758
+                   tp->mcfg == CFG_METHOD_36 || tp->mcfg == CFG_METHOD_37) {
5759
                 set_offset70F(tp, 0x27);
5760
                 set_offset79(tp, 0x50);
5761
                 if (tp->mcfg == CFG_METHOD_21 || tp->mcfg == CFG_METHOD_22)
5762
                         set_offset711(tp, 0x04);
5763
 
5764
                 rtl8168_eri_write(tp, 0xC8, 4, 0x00080002, ERIAR_ExGMAC);
5765
+#ifdef ENABLE_LIB_SUPPORT
5766
+                rtl8168_eri_write(tp, 0xCC, 1, 0x60, ERIAR_ExGMAC);
5767
+                rtl8168_eri_write(tp, 0xD0, 1, 0x70, ERIAR_ExGMAC);
5768
+#else
5769
                 rtl8168_eri_write(tp, 0xCC, 1, 0x38, ERIAR_ExGMAC);
5770
                 rtl8168_eri_write(tp, 0xD0, 1, 0x48, ERIAR_ExGMAC);
5771
+#endif //ENABLE_LIB_SUPPORT
5772
                 rtl8168_eri_write(tp, 0xE8, 4, 0x00100006, ERIAR_ExGMAC);
5773
 
5774
                 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | BIT_7);
5775
@@ -27997,7 +29541,7 @@
5776
                 csi_tmp |= BIT_0;
5777
                 rtl8168_eri_write(tp, 0xDC, 1, csi_tmp, ERIAR_ExGMAC);
5778
 
5779
-                if (tp->mcfg == CFG_METHOD_35)
5780
+                if (tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36)
5781
                         rtl8168_set_mcu_ocp_bit(tp, 0xD438, (BIT_1 | BIT_0));
5782
 
5783
                 if (tp->mcfg == CFG_METHOD_26) {
5784
@@ -28012,7 +29556,8 @@
5785
                         mac_ocp_data |= BIT_0;
5786
                         rtl8168_mac_ocp_write(tp, 0xD3C4, mac_ocp_data);
5787
                 } else if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
5788
-                           tp->mcfg == CFG_METHOD_35) {
5789
+                           tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
5790
+                           tp->mcfg == CFG_METHOD_37) {
5791
 
5792
                         if (tp->RequireAdjustUpsTxLinkPulseTiming) {
5793
                                 mac_ocp_data = rtl8168_mac_ocp_read(tp, 0xD412);
5794
@@ -28064,11 +29609,11 @@
5795
 
5796
                 RTL_W8(tp, 0xD0, RTL_R8(tp, 0xD0) | BIT_7);
5797
 
5798
-                rtl8168_eri_write(tp, 0xC0, 2, 0x0000, ERIAR_ExGMAC);
5799
-                rtl8168_eri_write(tp, 0xB8, 4, 0x00000000, ERIAR_ExGMAC);
5800
+                rtl8168_eri_write(tp, RSS_CTRL_8168, 4, 0x00000000, ERIAR_ExGMAC);
5801
 
5802
                 if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
5803
-                    tp->mcfg == CFG_METHOD_35) {
5804
+                    tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
5805
+                    tp->mcfg == CFG_METHOD_37) {
5806
                         rtl8168_mac_ocp_write(tp, 0xE054, 0x0000);
5807
 
5808
                         rtl8168_eri_write(tp, 0x5F0, 2, 0x4000, ERIAR_ExGMAC);
5809
@@ -28077,7 +29622,8 @@
5810
                 }
5811
 
5812
                 if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
5813
-                    tp->mcfg == CFG_METHOD_35) {
5814
+                    tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
5815
+                    tp->mcfg == CFG_METHOD_37) {
5816
                         csi_tmp = rtl8168_eri_read(tp, 0xDC, 4, ERIAR_ExGMAC);
5817
                         csi_tmp |= (BIT_2 | BIT_3 | BIT_4);
5818
                         rtl8168_eri_write(tp, 0xDC, 4, csi_tmp, ERIAR_ExGMAC);
5819
@@ -28087,7 +29633,8 @@
5820
                     tp->mcfg == CFG_METHOD_24 || tp->mcfg == CFG_METHOD_25) {
5821
                         rtl8168_mac_ocp_write(tp, 0xC140, 0xFFFF);
5822
                 } else if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
5823
-                           tp->mcfg == CFG_METHOD_35) {
5824
+                           tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
5825
+                           tp->mcfg == CFG_METHOD_37) {
5826
                         rtl8168_mac_ocp_write(tp, 0xC140, 0xFFFF);
5827
                         rtl8168_mac_ocp_write(tp, 0xC142, 0xFFFF);
5828
                 }
5829
@@ -28097,7 +29644,8 @@
5830
                 rtl8168_eri_write(tp, 0x1B0, 4, csi_tmp, ERIAR_ExGMAC);
5831
 
5832
                 if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
5833
-                    tp->mcfg == CFG_METHOD_35) {
5834
+                    tp->mcfg == CFG_METHOD_35 || tp->mcfg == CFG_METHOD_36 ||
5835
+                    tp->mcfg == CFG_METHOD_37) {
5836
                         csi_tmp = rtl8168_eri_read(tp, 0x2FC, 1, ERIAR_ExGMAC);
5837
                         csi_tmp &= ~(BIT_2);
5838
                         rtl8168_eri_write(tp, 0x2FC, 1, csi_tmp, ERIAR_ExGMAC);
5839
@@ -28108,9 +29656,11 @@
5840
                         rtl8168_eri_write(tp, 0x2FC, 1, csi_tmp, ERIAR_ExGMAC);
5841
                 }
5842
 
5843
-                csi_tmp = rtl8168_eri_read(tp, 0x1D0, 1, ERIAR_ExGMAC);
5844
-                csi_tmp |= BIT_1;
5845
-                rtl8168_eri_write(tp, 0x1D0, 1, csi_tmp, ERIAR_ExGMAC);
5846
+                if (tp->mcfg != CFG_METHOD_37) {
5847
+                        csi_tmp = rtl8168_eri_read(tp, 0x1D0, 1, ERIAR_ExGMAC);
5848
+                        csi_tmp |= BIT_1;
5849
+                        rtl8168_eri_write(tp, 0x1D0, 1, csi_tmp, ERIAR_ExGMAC);
5850
+                }
5851
         } else if (tp->mcfg == CFG_METHOD_23 || tp->mcfg == CFG_METHOD_27 ||
5852
                    tp->mcfg == CFG_METHOD_28) {
5853
                 set_offset70F(tp, 0x27);
5854
@@ -28270,6 +29820,10 @@
5855
                         rtl8168_eri_write(tp, 0x5F0, 2, 0x4000, ERIAR_ExGMAC);
5856
                 rtl8168_oob_mutex_unlock(tp);
5857
 
5858
+                csi_tmp = rtl8168_eri_read(tp, 0xDC, 4, ERIAR_ExGMAC);
5859
+                csi_tmp |= (BIT_2 | BIT_3);
5860
+                rtl8168_eri_write(tp, 0xDC, 4, csi_tmp, ERIAR_ExGMAC);
5861
+
5862
                 if (tp->mcfg == CFG_METHOD_32 || tp->mcfg == CFG_METHOD_33 ||
5863
                     tp->mcfg == CFG_METHOD_34) {
5864
                         csi_tmp = rtl8168_eri_read(tp, 0xD4, 4, ERIAR_ExGMAC);
5865
@@ -28385,6 +29939,17 @@
5866
                 }
5867
         }
5868
 
5869
+        rtl8168_set_rx_q_num(tp, tp->num_hw_tot_en_rx_rings);
5870
+
5871
+        rtl8168_set_rx_vlan_filter(tp);
5872
+#ifdef ENABLE_RSS_SUPPORT
5873
+#ifdef ENABLE_LIB_SUPPORT
5874
+        /* if lib queue not exist, default use rx queue 0 */
5875
+        if (rtl8168_num_lib_rx_rings(tp) == 0)
5876
+                memset(tp->rss_indir_tbl, 0x0, sizeof(tp->rss_indir_tbl));
5877
+#endif //ENABLE_LIB_SUPPORT
5878
+        rtl8168_config_rss(tp);
5879
+#endif //ENABLE_RSS_SUPPORT
5880
         rtl8168_hw_clear_timer_int(dev);
5881
 
5882
         rtl8168_enable_exit_l1_mask(tp);
5883
@@ -28397,6 +29962,8 @@
5884
         case CFG_METHOD_29:
5885
         case CFG_METHOD_30:
5886
         case CFG_METHOD_35:
5887
+        case CFG_METHOD_36:
5888
+        case CFG_METHOD_37:
5889
                 rtl8168_mac_ocp_write(tp, 0xE098, 0x0AA2);
5890
                 break;
5891
         case CFG_METHOD_31:
5892
@@ -28423,6 +29990,8 @@
5893
         case CFG_METHOD_33:
5894
         case CFG_METHOD_34:
5895
         case CFG_METHOD_35:
5896
+        case CFG_METHOD_36:
5897
+        case CFG_METHOD_37:
5898
                 rtl8168_disable_pci_offset_99(tp);
5899
                 if (aspm) {
5900
                         if (tp->org_pci_offset_99 & (BIT_2 | BIT_5 | BIT_6))
5901
@@ -28443,6 +30012,8 @@
5902
         case CFG_METHOD_33:
5903
         case CFG_METHOD_34:
5904
         case CFG_METHOD_35:
5905
+        case CFG_METHOD_36:
5906
+        case CFG_METHOD_37:
5907
                 rtl8168_disable_pci_offset_180(tp);
5908
                 if (aspm) {
5909
                         if (tp->org_pci_offset_180 & (BIT_0|BIT_1))
5910
@@ -28469,19 +30040,9 @@
5911
         case CFG_METHOD_20:
5912
         case CFG_METHOD_21:
5913
         case CFG_METHOD_22:
5914
-        case CFG_METHOD_23:
5915
         case CFG_METHOD_24:
5916
         case CFG_METHOD_25:
5917
-        case CFG_METHOD_26:
5918
-        case CFG_METHOD_27:
5919
-        case CFG_METHOD_28:
5920
-        case CFG_METHOD_29:
5921
-        case CFG_METHOD_30:
5922
-        case CFG_METHOD_31:
5923
-        case CFG_METHOD_32:
5924
-        case CFG_METHOD_33:
5925
-        case CFG_METHOD_34:
5926
-        case CFG_METHOD_35: {
5927
+        case CFG_METHOD_26: {
5928
                 int timeout;
5929
                 for (timeout = 0; timeout < 10; timeout++) {
5930
                         if ((rtl8168_eri_read(tp, 0x1AE, 2, ERIAR_ExGMAC) & BIT_13)==0)
5931
@@ -28540,14 +30101,20 @@
5932
         udelay(10);
5933
 }
5934
 
5935
-static void
5936
+void
5937
 rtl8168_hw_start(struct net_device *dev)
5938
 {
5939
         struct rtl8168_private *tp = netdev_priv(dev);
5940
 
5941
+#ifdef ENABLE_LIB_SUPPORT
5942
+        rtl8168_init_lib_ring(tp);
5943
+#endif
5944
+
5945
         RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
5946
 
5947
-        rtl8168_enable_hw_interrupt(tp);
5948
+        rtl8168_enable_interrupt(tp);
5949
+
5950
+        rtl8168_lib_reset_complete(tp);
5951
 }
5952
 
5953
 static int
5954
@@ -28556,7 +30123,6 @@
5955
 {
5956
         struct rtl8168_private *tp = netdev_priv(dev);
5957
         int ret = 0;
5958
-        unsigned long flags;
5959
 
5960
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
5961
         if (new_mtu < ETH_MIN_MTU)
5962
@@ -28565,42 +30131,33 @@
5963
                 new_mtu = tp->max_jumbo_frame_size;
5964
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
5965
 
5966
-        spin_lock_irqsave(&tp->lock, flags);
5967
         dev->mtu = new_mtu;
5968
-        spin_unlock_irqrestore(&tp->lock, flags);
5969
+
5970
+        tp->eee.tx_lpi_timer = dev->mtu + ETH_HLEN + 0x20;
5971
 
5972
         if (!netif_running(dev))
5973
                 goto out;
5974
 
5975
         rtl8168_down(dev);
5976
 
5977
-        spin_lock_irqsave(&tp->lock, flags);
5978
-
5979
         rtl8168_set_rxbufsize(tp, dev);
5980
 
5981
         ret = rtl8168_init_ring(dev);
5982
 
5983
-        if (ret < 0) {
5984
-                spin_unlock_irqrestore(&tp->lock, flags);
5985
+        if (ret < 0)
5986
                 goto err_out;
5987
-        }
5988
 
5989
 #ifdef CONFIG_R8168_NAPI
5990
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
5991
-        RTL_NAPI_ENABLE(dev, &tp->napi);
5992
-#endif
5993
+        rtl8168_enable_napi(tp);
5994
 #endif//CONFIG_R8168_NAPI
5995
 
5996
-        netif_stop_queue(dev);
5997
-        netif_carrier_off(dev);
5998
-        rtl8168_hw_config(dev);
5999
-
6000
-        rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
6001
-
6002
-        spin_unlock_irqrestore(&tp->lock, flags);
6003
+        if (tp->link_ok(dev))
6004
+                rtl8168_link_on_patch(dev);
6005
+        else
6006
+                rtl8168_link_down_patch(dev);
6007
 
6008
-        mod_timer(&tp->esd_timer, jiffies + RTL8168_ESD_TIMEOUT);
6009
-        mod_timer(&tp->link_timer, jiffies + RTL8168_LINK_TIMEOUT);
6010
+        //mod_timer(&tp->esd_timer, jiffies + RTL8168_ESD_TIMEOUT);
6011
+        //mod_timer(&tp->link_timer, jiffies + RTL8168_LINK_TIMEOUT);
6012
 out:
6013
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
6014
         netdev_update_features(dev);
6015
@@ -28619,32 +30176,37 @@
6016
 
6017
 static void
6018
 rtl8168_free_rx_skb(struct rtl8168_private *tp,
6019
+                    struct rtl8168_rx_ring *ring,
6020
                     struct sk_buff **sk_buff,
6021
-                    struct RxDesc *desc)
6022
+                    struct RxDesc *desc,
6023
+                    const u32 cur_rx)
6024
 {
6025
         struct pci_dev *pdev = tp->pci_dev;
6026
 
6027
-        dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
6028
+        dma_unmap_single(&pdev->dev, ring->RxDescPhyAddrcur_rx, tp->rx_buf_sz,
6029
                          DMA_FROM_DEVICE);
6030
         dev_kfree_skb(*sk_buff);
6031
         *sk_buff = NULL;
6032
         rtl8168_make_unusable_by_asic(desc);
6033
 }
6034
 
6035
-static inline void
6036
+void
6037
 rtl8168_mark_to_asic(struct RxDesc *desc,
6038
                      u32 rx_buf_sz)
6039
 {
6040
         u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
6041
 
6042
-        desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz);
6043
+        WRITE_ONCE(desc->opts1, cpu_to_le32(DescOwn | eor | rx_buf_sz));
6044
 }
6045
 
6046
 static inline void
6047
 rtl8168_map_to_asic(struct RxDesc *desc,
6048
+                    struct rtl8168_rx_ring *ring,
6049
                     dma_addr_t mapping,
6050
-                    u32 rx_buf_sz)
6051
+                    u32 rx_buf_sz,
6052
+                    const u32 cur_rx)
6053
 {
6054
+        ring->RxDescPhyAddrcur_rx = mapping;
6055
         desc->addr = cpu_to_le64(mapping);
6056
         wmb();
6057
         rtl8168_mark_to_asic(desc, rx_buf_sz);
6058
@@ -28652,9 +30214,11 @@
6059
 
6060
 static int
6061
 rtl8168_alloc_rx_skb(struct rtl8168_private *tp,
6062
+                     struct rtl8168_rx_ring *ring,
6063
                      struct sk_buff **sk_buff,
6064
                      struct RxDesc *desc,
6065
                      int rx_buf_sz,
6066
+                     const u32 cur_rx,
6067
                      u8 in_intr)
6068
 {
6069
         struct sk_buff *skb;
6070
@@ -28662,14 +30226,16 @@
6071
         int ret = 0;
6072
 
6073
         if (in_intr)
6074
-                skb = RTL_ALLOC_SKB_INTR(tp, rx_buf_sz + RTK_RX_ALIGN);
6075
+                skb = RTL_ALLOC_SKB_INTR(&tp->r8168napiring->index.napi,
6076
+                                         rx_buf_sz + RTK_RX_ALIGN);
6077
         else
6078
                 skb = dev_alloc_skb(rx_buf_sz + RTK_RX_ALIGN);
6079
 
6080
         if (unlikely(!skb))
6081
                 goto err_out;
6082
 
6083
-        skb_reserve(skb, RTK_RX_ALIGN);
6084
+        if (!in_intr || !R8168_USE_NAPI_ALLOC_SKB)
6085
+                skb_reserve(skb, RTK_RX_ALIGN);
6086
 
6087
         mapping = dma_map_single(tp_to_dev(tp), skb->data, rx_buf_sz,
6088
                                  DMA_FROM_DEVICE);
6089
@@ -28680,7 +30246,7 @@
6090
         }
6091
 
6092
         *sk_buff = skb;
6093
-        rtl8168_map_to_asic(desc, mapping, rx_buf_sz);
6094
+        rtl8168_map_to_asic(desc, ring, mapping, rx_buf_sz, cur_rx);
6095
 out:
6096
         return ret;
6097
 
6098
@@ -28693,19 +30259,37 @@
6099
 }
6100
 
6101
 static void
6102
-rtl8168_rx_clear(struct rtl8168_private *tp)
6103
+_rtl8168_rx_clear(struct rtl8168_private *tp, struct rtl8168_rx_ring *ring)
6104
 {
6105
         int i;
6106
 
6107
         for (i = 0; i < tp->num_rx_desc; i++) {
6108
-                if (tp->Rx_skbuffi)
6109
-                        rtl8168_free_rx_skb(tp, tp->Rx_skbuff + i,
6110
-                                            tp->RxDescArray + i);
6111
+                if (ring->Rx_skbuffi) {
6112
+                        rtl8168_free_rx_skb(tp,
6113
+                                            ring,
6114
+                                            ring->Rx_skbuff + i,
6115
+                                            rtl8168_get_rxdesc(tp,
6116
+                                                               tp->RxDescArray,
6117
+                                                               i,
6118
+                                                               ring->index),
6119
+                                            i);
6120
+                        ring->Rx_skbuffi = NULL;
6121
+                }
6122
         }
6123
 }
6124
 
6125
+void
6126
+rtl8168_rx_clear(struct rtl8168_private *tp)
6127
+{
6128
+        int i;
6129
+
6130
+        for (i = 0; i < tp->num_rx_rings; i++)
6131
+                _rtl8168_rx_clear(tp, &tp->rx_ringi);
6132
+}
6133
+
6134
 static u32
6135
 rtl8168_rx_fill(struct rtl8168_private *tp,
6136
+                struct rtl8168_rx_ring *ring,
6137
                 struct net_device *dev,
6138
                 u32 start,
6139
                 u32 end,
6140
@@ -28716,12 +30300,17 @@
6141
         for (cur = start; end - cur > 0; cur++) {
6142
                 int ret, i = cur % tp->num_rx_desc;
6143
 
6144
-                if (tp->Rx_skbuffi)
6145
+                if (ring->Rx_skbuffi)
6146
                         continue;
6147
 
6148
-                ret = rtl8168_alloc_rx_skb(tp, tp->Rx_skbuff + i,
6149
-                                           tp->RxDescArray + i,
6150
+                ret = rtl8168_alloc_rx_skb(tp,
6151
+                                           ring,
6152
+                                           ring->Rx_skbuff + i,
6153
+                                           rtl8168_get_rxdesc(tp,
6154
+                                                           tp->RxDescArray,
6155
+                                                           i, ring->index),
6156
                                            tp->rx_buf_sz,
6157
+                                           i,
6158
                                            in_intr);
6159
                 if (ret < 0)
6160
                         break;
6161
@@ -28738,33 +30327,54 @@
6162
 static void
6163
 rtl8168_desc_addr_fill(struct rtl8168_private *tp)
6164
 {
6165
-        if (!tp->TxPhyAddr || !tp->RxPhyAddr)
6166
-                return;
6167
+        int i;
6168
+
6169
+        for (i = 0; i < tp->num_tx_rings; i++) {
6170
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
6171
+                RTL_W32(tp, ring->tdsar_reg, ((u64)ring->TxPhyAddr & DMA_BIT_MASK(32)));
6172
+                RTL_W32(tp, ring->tdsar_reg + 4, ((u64)ring->TxPhyAddr >> 32));
6173
+        }
6174
+
6175
+#ifdef ENABLE_LIB_SUPPORT
6176
+        /*
6177
+         * The lib tx q1 polling may be set after tx is disabled. If lib tx q1
6178
+         * is released, after enable tx, device will try to access invalid tx q1
6179
+         * desc base address. Set tx q1 desc base address to tx q0 desc base
6180
+         * address to let device to access the valid address and clear tx q1
6181
+         * polling bit after enable tx.
6182
+         */
6183
+        if (rtl8168_lib_tx_ring_released(tp)) {
6184
+                struct rtl8168_tx_ring *ring = &tp->tx_ring0;
6185
+                u16 tdsar_reg = TxHDescStartAddrLow;
6186
+                RTL_W32(tp, tdsar_reg, ((u64)ring->TxPhyAddr & DMA_BIT_MASK(32)));
6187
+                RTL_W32(tp, tdsar_reg + 4, ((u64)ring->TxPhyAddr >> 32));
6188
+        }
6189
+#endif
6190
 
6191
-        RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr & DMA_BIT_MASK(32)));
6192
-        RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr >> 32));
6193
         RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr & DMA_BIT_MASK(32)));
6194
-        RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr >> 32));
6195
+        RTL_W32(tp, RxDescAddrLow + 4, ((u64) tp->RxPhyAddr >> 32));
6196
 }
6197
 
6198
 static void
6199
 rtl8168_tx_desc_init(struct rtl8168_private *tp)
6200
 {
6201
-        int i = 0;
6202
+        int i;
6203
 
6204
-        memset(tp->TxDescArray, 0x0, tp->TxDescAllocSize);
6205
+        for (i = 0; i < tp->num_tx_rings; i++) {
6206
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
6207
+                memset(ring->TxDescArray, 0x0, ring->TxDescAllocSize);
6208
 
6209
-        for (i = 0; i < tp->num_tx_desc; i++) {
6210
-                if (i == (tp->num_tx_desc - 1))
6211
-                        tp->TxDescArrayi.opts1 = cpu_to_le32(RingEnd);
6212
+                ring->TxDescArrayring->num_tx_desc - 1.opts1 = cpu_to_le32(RingEnd);
6213
         }
6214
 }
6215
 
6216
 static void
6217
 rtl8168_rx_desc_offset0_init(struct rtl8168_private *tp, int own)
6218
 {
6219
-        int i = 0;
6220
+        struct rtl8168_rx_ring *ring = &tp->rx_ring0;
6221
+        struct RxDesc *desc;
6222
         int ownbit = 0;
6223
+        int i;
6224
 
6225
         if (tp->RxDescArray == NULL)
6226
                 return;
6227
@@ -28773,36 +30383,56 @@
6228
                 ownbit = DescOwn;
6229
 
6230
         for (i = 0; i < tp->num_rx_desc; i++) {
6231
+                desc = rtl8168_get_rxdesc(tp, tp->RxDescArray, i,
6232
+                                          ring->index);
6233
                 if (i == (tp->num_rx_desc - 1))
6234
-                        tp->RxDescArrayi.opts1 = cpu_to_le32((ownbit | RingEnd) | (unsigned long)tp->rx_buf_sz);
6235
+                        desc->opts1 = cpu_to_le32((ownbit | RingEnd) | (unsigned long)tp->rx_buf_sz);
6236
                 else
6237
-                        tp->RxDescArrayi.opts1 = cpu_to_le32(ownbit | (unsigned long)tp->rx_buf_sz);
6238
+                        desc->opts1 = cpu_to_le32(ownbit | (unsigned long)tp->rx_buf_sz);
6239
         }
6240
 }
6241
 
6242
 static void
6243
 rtl8168_rx_desc_init(struct rtl8168_private *tp)
6244
 {
6245
+        if (!tp->RxDescArray)
6246
+                return;
6247
+
6248
+        if (rtl8168_num_lib_rx_rings(tp) > 0)
6249
+                return;
6250
+
6251
         memset(tp->RxDescArray, 0x0, tp->RxDescAllocSize);
6252
 }
6253
 
6254
-static int
6255
+int
6256
 rtl8168_init_ring(struct net_device *dev)
6257
 {
6258
         struct rtl8168_private *tp = netdev_priv(dev);
6259
+        int i;
6260
 
6261
         rtl8168_init_ring_indexes(tp);
6262
 
6263
-        memset(tp->tx_skb, 0x0, sizeof(tp->tx_skb));
6264
-        memset(tp->Rx_skbuff, 0x0, sizeof(tp->Rx_skbuff));
6265
-
6266
         rtl8168_tx_desc_init(tp);
6267
         rtl8168_rx_desc_init(tp);
6268
 
6269
-        if (rtl8168_rx_fill(tp, dev, 0, tp->num_rx_desc, 0) != tp->num_rx_desc)
6270
-                goto err_out;
6271
+        for (i = 0; i < tp->num_tx_rings; i++) {
6272
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
6273
+                memset(ring->tx_skb, 0x0, sizeof(ring->tx_skb));
6274
+        }
6275
+
6276
+        for (i = 0; i < tp->num_rx_rings; i++) {
6277
+                struct rtl8168_rx_ring *ring = &tp->rx_ringi;
6278
+
6279
+                memset(ring->Rx_skbuff, 0x0, sizeof(ring->Rx_skbuff));
6280
+                if (rtl8168_rx_fill(tp, ring, dev, 0, tp->num_rx_desc, 0) != tp->num_rx_desc)
6281
+                        goto err_out;
6282
+
6283
+                rtl8168_mark_as_last_descriptor(rtl8168_get_rxdesc(tp,
6284
+                                                tp->RxDescArray,
6285
+                                                tp->num_rx_desc - 1,
6286
+                                                ring->index));
6287
+        }
6288
 
6289
-        rtl8168_mark_as_last_descriptor(tp->RxDescArray + tp->num_rx_desc - 1);
6290
 
6291
         return 0;
6292
 
6293
@@ -28826,8 +30456,11 @@
6294
         tx_skb->len = 0;
6295
 }
6296
 
6297
-static void rtl8168_tx_clear_range(struct rtl8168_private *tp, u32 start,
6298
-                                   unsigned int n)
6299
+static void
6300
+rtl8168_tx_clear_range(struct rtl8168_private *tp,
6301
+                       struct rtl8168_tx_ring *ring,
6302
+                       u32 start,
6303
+                       unsigned int n)
6304
 {
6305
         unsigned int i;
6306
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
6307
@@ -28835,15 +30468,15 @@
6308
 #endif
6309
 
6310
         for (i = 0; i < n; i++) {
6311
-                unsigned int entry = (start + i) % tp->num_tx_desc;
6312
-                struct ring_info *tx_skb = tp->tx_skb + entry;
6313
+                unsigned int entry = (start + i) % ring->num_tx_desc;
6314
+                struct ring_info *tx_skb = ring->tx_skb + entry;
6315
                 unsigned int len = tx_skb->len;
6316
 
6317
                 if (len) {
6318
                         struct sk_buff *skb = tx_skb->skb;
6319
 
6320
                         rtl8168_unmap_tx_skb(tp->pci_dev, tx_skb,
6321
-                                             tp->TxDescArray + entry);
6322
+                                             ring->TxDescArray + entry);
6323
                         if (skb) {
6324
                                 RTLDEV->stats.tx_dropped++;
6325
                                 dev_kfree_skb_any(skb);
6326
@@ -28853,83 +30486,167 @@
6327
         }
6328
 }
6329
 
6330
-static void
6331
+void
6332
 rtl8168_tx_clear(struct rtl8168_private *tp)
6333
 {
6334
-        rtl8168_tx_clear_range(tp, tp->dirty_tx, tp->num_tx_desc);
6335
-        tp->cur_tx = tp->dirty_tx = 0;
6336
+        int i;
6337
+
6338
+        for (i = 0; i < tp->num_tx_rings; i++) {
6339
+                struct rtl8168_tx_ring *ring = &tp->tx_ringi;
6340
+                rtl8168_tx_clear_range(tp, ring, ring->dirty_tx, ring->num_tx_desc);
6341
+                ring->cur_tx = ring->dirty_tx = 0;
6342
+        }
6343
 }
6344
 
6345
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6346
-static void rtl8168_schedule_work(struct net_device *dev, void (*task)(void *))
6347
+static void rtl8168_schedule_reset_work(struct rtl8168_private *tp)
6348
 {
6349
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6350
-        struct rtl8168_private *tp = netdev_priv(dev);
6351
+        set_bit(R8168_FLAG_TASK_RESET_PENDING, tp->task_flags);
6352
+        schedule_delayed_work(&tp->reset_task, 4);
6353
+#endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6354
+}
6355
+
6356
+static void rtl8168_schedule_esd_work(struct rtl8168_private *tp)
6357
+{
6358
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6359
+        set_bit(R8168_FLAG_TASK_ESD_CHECK_PENDING, tp->task_flags);
6360
+        schedule_delayed_work(&tp->esd_task, RTL8168_ESD_TIMEOUT);
6361
+#endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6362
+}
6363
 
6364
-        INIT_WORK(&tp->task, task, dev);
6365
-        schedule_delayed_work(&tp->task, 4);
6366
+static void rtl8168_schedule_linkchg_work(struct rtl8168_private *tp)
6367
+{
6368
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6369
+        set_bit(R8168_FLAG_TASK_LINKCHG_CHECK_PENDING, tp->task_flags);
6370
+        schedule_delayed_work(&tp->linkchg_task, RTL8168_LINK_TIMEOUT);
6371
 #endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
6372
 }
6373
 
6374
-#define rtl8168_cancel_schedule_work(a)
6375
+#define rtl8168_cancel_schedule_reset_work(a)
6376
+#define rtl8168_cancel_schedule_esd_work(a)
6377
+#define rtl8168_cancel_schedule_linkchg_work(a)
6378
 
6379
 #else
6380
-static void rtl8168_schedule_work(struct net_device *dev, work_func_t task)
6381
+static void rtl8168_schedule_reset_work(struct rtl8168_private *tp)
6382
 {
6383
-        struct rtl8168_private *tp = netdev_priv(dev);
6384
+        set_bit(R8168_FLAG_TASK_RESET_PENDING, tp->task_flags);
6385
+        schedule_delayed_work(&tp->reset_task, 4);
6386
+}
6387
+
6388
+static void rtl8168_cancel_schedule_reset_work(struct rtl8168_private *tp)
6389
+{
6390
+        struct work_struct *work = &tp->reset_task.work;
6391
 
6392
-        INIT_DELAYED_WORK(&tp->task, task);
6393
-        schedule_delayed_work(&tp->task, 4);
6394
+        if (!work->func) return;
6395
+
6396
+        cancel_delayed_work_sync(&tp->reset_task);
6397
 }
6398
 
6399
-static void rtl8168_cancel_schedule_work(struct net_device *dev)
6400
+static void rtl8168_schedule_esd_work(struct rtl8168_private *tp)
6401
 {
6402
-        struct rtl8168_private *tp = netdev_priv(dev);
6403
-        struct work_struct *work = &tp->task.work;
6404
+        set_bit(R8168_FLAG_TASK_ESD_CHECK_PENDING, tp->task_flags);
6405
+        schedule_delayed_work(&tp->esd_task, RTL8168_ESD_TIMEOUT);
6406
+}
6407
 
6408
-        if (!work->func)
6409
-                return;
6410
+static void rtl8168_cancel_schedule_esd_work(struct rtl8168_private *tp)
6411
+{
6412
+        struct work_struct *work = &tp->esd_task.work;
6413
+
6414
+        if (!work->func) return;
6415
 
6416
-        cancel_delayed_work_sync(&tp->task);
6417
+        cancel_delayed_work_sync(&tp->esd_task);
6418
 }
6419
-#endif
6420
 
6421
-#if 0
6422
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6423
-static void rtl8168_reinit_task(void *_data)
6424
-#else
6425
-static void rtl8168_reinit_task(struct work_struct *work)
6426
+static void rtl8168_schedule_linkchg_work(struct rtl8168_private *tp)
6427
+{
6428
+        set_bit(R8168_FLAG_TASK_LINKCHG_CHECK_PENDING, tp->task_flags);
6429
+        schedule_delayed_work(&tp->linkchg_task, RTL8168_LINK_TIMEOUT);
6430
+}
6431
+
6432
+static void rtl8168_cancel_schedule_linkchg_work(struct rtl8168_private *tp)
6433
+{
6434
+        struct work_struct *work = &tp->linkchg_task.work;
6435
+
6436
+        if (!work->func) return;
6437
+
6438
+        cancel_delayed_work_sync(&tp->linkchg_task);
6439
+}
6440
 #endif
6441
+
6442
+static void rtl8168_init_all_schedule_work(struct rtl8168_private *tp)
6443
 {
6444
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6445
-        struct net_device *dev = _data;
6446
+        INIT_WORK(&tp->reset_task, rtl8168_reset_task, dev);
6447
+        INIT_WORK(&tp->esd_task, rtl8168_esd_task, dev);
6448
+        INIT_WORK(&tp->linkchg_task, rtl8168_linkchg_task, dev);
6449
 #else
6450
-        struct rtl8168_private *tp =
6451
-                container_of(work, struct rtl8168_private, task.work);
6452
-        struct net_device *dev = tp->dev;
6453
+        INIT_DELAYED_WORK(&tp->reset_task, rtl8168_reset_task);
6454
+        INIT_DELAYED_WORK(&tp->esd_task, rtl8168_esd_task);
6455
+        INIT_DELAYED_WORK(&tp->linkchg_task, rtl8168_linkchg_task);
6456
 #endif
6457
-        int ret;
6458
-
6459
-        if (netif_running(dev)) {
6460
-                rtl8168_wait_for_quiescence(dev);
6461
-                rtl8168_close(dev);
6462
-        }
6463
+}
6464
 
6465
-        ret = rtl8168_open(dev);
6466
-        if (unlikely(ret < 0)) {
6467
-                if (unlikely(net_ratelimit())) {
6468
-                        struct rtl8168_private *tp = netdev_priv(dev);
6469
+static void rtl8168_cancel_all_schedule_work(struct rtl8168_private *tp)
6470
+{
6471
+        rtl8168_cancel_schedule_reset_work(tp);
6472
+        rtl8168_cancel_schedule_esd_work(tp);
6473
+        rtl8168_cancel_schedule_linkchg_work(tp);
6474
+}
6475
 
6476
-                        if (netif_msg_drv(tp)) {
6477
-                                printk(PFX KERN_ERR
6478
-                                       "%s: reinit failure (status = %d)."
6479
-                                       " Rescheduling.\n", dev->name, ret);
6480
-                        }
6481
-                }
6482
-                rtl8168_schedule_work(dev, rtl8168_reinit_task);
6483
+static void
6484
+rtl8168_wait_for_irq_complete(struct rtl8168_private *tp)
6485
+{
6486
+        if (tp->features & RTL_FEATURE_MSIX) {
6487
+                int i;
6488
+                for (i = 0; i < tp->irq_nvecs; i++)
6489
+                        synchronize_irq(tp->irq_tbli.vector);
6490
+        } else {
6491
+                synchronize_irq(tp->dev->irq);
6492
         }
6493
 }
6494
+
6495
+void
6496
+_rtl8168_wait_for_quiescence(struct net_device *dev)
6497
+{
6498
+        struct rtl8168_private *tp = netdev_priv(dev);
6499
+
6500
+        /* Wait for any pending NAPI task to complete */
6501
+#ifdef CONFIG_R8168_NAPI
6502
+        rtl8168_disable_napi(tp);
6503
+#endif//CONFIG_R8168_NAPI
6504
+
6505
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,67)
6506
+        /* Give a racing hard_start_xmit a few cycles to complete. */
6507
+        synchronize_net();
6508
 #endif
6509
+        rtl8168_irq_mask_and_ack(tp);
6510
+
6511
+        rtl8168_wait_for_irq_complete(tp);
6512
+}
6513
+
6514
+static void
6515
+rtl8168_wait_for_quiescence(struct net_device *dev)
6516
+{
6517
+        struct rtl8168_private *tp = netdev_priv(dev);
6518
+
6519
+        //suppress unused variable
6520
+        (void)(tp);
6521
+
6522
+        _rtl8168_wait_for_quiescence(dev);
6523
+
6524
+#ifdef CONFIG_R8168_NAPI
6525
+        rtl8168_enable_napi(tp);
6526
+#endif //CONFIG_R8168_NAPI
6527
+}
6528
+
6529
+static int rtl8168_rx_nostuck(struct rtl8168_private *tp)
6530
+{
6531
+        int i, ret = 1;
6532
+        for (i = 0; i < tp->num_rx_rings; i++)
6533
+                ret &= (tp->rx_ringi.dirty_rx == tp->rx_ringi.cur_rx);
6534
+        return ret;
6535
+}
6536
 
6537
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6538
 static void rtl8168_reset_task(void *_data)
6539
@@ -28940,34 +30657,40 @@
6540
 static void rtl8168_reset_task(struct work_struct *work)
6541
 {
6542
         struct rtl8168_private *tp =
6543
-                container_of(work, struct rtl8168_private, task.work);
6544
+                container_of(work, struct rtl8168_private, reset_task.work);
6545
         struct net_device *dev = tp->dev;
6546
 #endif
6547
         u32 budget = ~(u32)0;
6548
-        unsigned long flags;
6549
+        int i;
6550
 
6551
-        if (!netif_running(dev))
6552
-                return;
6553
+        rtnl_lock();
6554
+
6555
+        if (!netif_running(dev) ||
6556
+            test_bit(R8168_FLAG_DOWN, tp->task_flags) ||
6557
+            !test_and_clear_bit(R8168_FLAG_TASK_RESET_PENDING, tp->task_flags))
6558
+                goto out_unlock;
6559
 
6560
         rtl8168_wait_for_quiescence(dev);
6561
 
6562
+        for (i = 0; i < tp->num_rx_rings; i++) {
6563
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
6564
-        rtl8168_rx_interrupt(dev, tp, &budget);
6565
+                rtl8168_rx_interrupt(dev, tp, &tp->rx_ringi, &budget);
6566
 #else
6567
-        rtl8168_rx_interrupt(dev, tp, budget);
6568
-#endif  //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
6569
+                rtl8168_rx_interrupt(dev, tp, &tp->rx_ringi, budget);
6570
+#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
6571
+        }
6572
 
6573
-        spin_lock_irqsave(&tp->lock, flags);
6574
+        netif_carrier_off(dev);
6575
+        netif_tx_disable(dev);
6576
+        rtl8168_hw_reset(dev);
6577
 
6578
         rtl8168_tx_clear(tp);
6579
 
6580
-        if (tp->dirty_rx == tp->cur_rx) {
6581
+        if (rtl8168_rx_nostuck(tp)) {
6582
                 rtl8168_rx_clear(tp);
6583
                 rtl8168_init_ring(dev);
6584
                 rtl8168_set_speed(dev, tp->autoneg, tp->speed, tp->duplex, tp->advertising);
6585
-                spin_unlock_irqrestore(&tp->lock, flags);
6586
         } else {
6587
-                spin_unlock_irqrestore(&tp->lock, flags);
6588
                 if (unlikely(net_ratelimit())) {
6589
                         struct rtl8168_private *tp = netdev_priv(dev);
6590
 
6591
@@ -28976,8 +30699,65 @@
6592
                                        "%s: Rx buffers shortage\n", dev->name);
6593
                         }
6594
                 }
6595
-                rtl8168_schedule_work(dev, rtl8168_reset_task);
6596
+                rtl8168_schedule_reset_work(tp);
6597
         }
6598
+
6599
+out_unlock:
6600
+        rtnl_unlock();
6601
+}
6602
+
6603
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6604
+static void rtl8168_esd_task(void *_data)
6605
+{
6606
+        struct net_device *dev = _data;
6607
+        struct rtl8168_private *tp = netdev_priv(dev);
6608
+#else
6609
+static void rtl8168_esd_task(struct work_struct *work)
6610
+{
6611
+        struct rtl8168_private *tp =
6612
+                container_of(work, struct rtl8168_private, esd_task.work);
6613
+        struct net_device *dev = tp->dev;
6614
+#endif
6615
+        rtnl_lock();
6616
+
6617
+        if (!netif_running(dev) ||
6618
+            test_bit(R8168_FLAG_DOWN, tp->task_flags) ||
6619
+            !test_and_clear_bit(R8168_FLAG_TASK_ESD_CHECK_PENDING, tp->task_flags))
6620
+                goto out_unlock;
6621
+
6622
+        rtl8168_esd_checker(tp);
6623
+
6624
+        rtl8168_schedule_esd_work(tp);
6625
+
6626
+out_unlock:
6627
+        rtnl_unlock();
6628
+}
6629
+
6630
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6631
+static void rtl8168_linkchg_task(void *_data)
6632
+{
6633
+        struct net_device *dev = _data;
6634
+        //struct rtl8168_private *tp = netdev_priv(dev);
6635
+#else
6636
+static void rtl8168_linkchg_task(struct work_struct *work)
6637
+{
6638
+        struct rtl8168_private *tp =
6639
+                container_of(work, struct rtl8168_private, linkchg_task.work);
6640
+        struct net_device *dev = tp->dev;
6641
+#endif
6642
+        rtnl_lock();
6643
+
6644
+        if (!netif_running(dev) ||
6645
+            test_bit(R8168_FLAG_DOWN, tp->task_flags) ||
6646
+            !test_and_clear_bit(R8168_FLAG_TASK_LINKCHG_CHECK_PENDING, tp->task_flags))
6647
+                goto out_unlock;
6648
+
6649
+        rtl8168_check_link_status(dev);
6650
+
6651
+        rtl8168_schedule_linkchg_work(tp);
6652
+
6653
+out_unlock:
6654
+        rtnl_unlock();
6655
 }
6656
 
6657
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
6658
@@ -28989,27 +30769,20 @@
6659
 #endif
6660
 {
6661
         struct rtl8168_private *tp = netdev_priv(dev);
6662
-        unsigned long flags;
6663
-
6664
-        spin_lock_irqsave(&tp->lock, flags);
6665
-        netif_stop_queue(dev);
6666
-        netif_carrier_off(dev);
6667
-        rtl8168_hw_reset(dev);
6668
-        spin_unlock_irqrestore(&tp->lock, flags);
6669
 
6670
         /* Let's wait a bit while any (async) irq lands on */
6671
-        rtl8168_schedule_work(dev, rtl8168_reset_task);
6672
+        rtl8168_schedule_reset_work(tp);
6673
 }
6674
 
6675
 static u32
6676
-rtl8168_get_txd_opts1(struct rtl8168_private *tp,
6677
+rtl8168_get_txd_opts1(struct rtl8168_tx_ring *ring,
6678
                       u32 opts1,
6679
                       u32 len,
6680
                       unsigned int entry)
6681
 {
6682
         u32 status = opts1 | len;
6683
 
6684
-        if (entry == tp->num_tx_desc - 1)
6685
+        if (entry == ring->num_tx_desc - 1)
6686
                 status |= RingEnd;
6687
 
6688
         return status;
6689
@@ -29017,6 +30790,7 @@
6690
 
6691
 static int
6692
 rtl8168_xmit_frags(struct rtl8168_private *tp,
6693
+                   struct rtl8168_tx_ring *ring,
6694
                    struct sk_buff *skb,
6695
                    const u32 *opts)
6696
 {
6697
@@ -29025,16 +30799,16 @@
6698
         struct TxDesc *txd = NULL;
6699
         const unsigned char nr_frags = info->nr_frags;
6700
 
6701
-        entry = tp->cur_tx;
6702
+        entry = ring->cur_tx;
6703
         for (cur_frag = 0; cur_frag < nr_frags; cur_frag++) {
6704
                 skb_frag_t *frag = info->frags + cur_frag;
6705
                 dma_addr_t mapping;
6706
                 u32 status, len;
6707
                 void *addr;
6708
 
6709
-                entry = (entry + 1) % tp->num_tx_desc;
6710
+                entry = (entry + 1) % ring->num_tx_desc;
6711
 
6712
-                txd = tp->TxDescArray + entry;
6713
+                txd = ring->TxDescArray + entry;
6714
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)
6715
                 len = frag->size;
6716
                 addr = ((void *) page_address(frag->page)) + frag->page_offset;
6717
@@ -29052,15 +30826,15 @@
6718
                 }
6719
 
6720
                 /* anti gcc 2.95.3 bugware (sic) */
6721
-                status = rtl8168_get_txd_opts1(tp, opts0, len, entry);
6722
+                status = rtl8168_get_txd_opts1(ring, opts0, len, entry);
6723
                 if (cur_frag == (nr_frags - 1)) {
6724
-                        tp->tx_skbentry.skb = skb;
6725
+                        ring->tx_skbentry.skb = skb;
6726
                         status |= LastFrag;
6727
                 }
6728
 
6729
                 txd->addr = cpu_to_le64(mapping);
6730
 
6731
-                tp->tx_skbentry.len = len;
6732
+                ring->tx_skbentry.len = len;
6733
 
6734
                 txd->opts2 = cpu_to_le32(opts1);
6735
                 wmb();
6736
@@ -29070,7 +30844,7 @@
6737
         return cur_frag;
6738
 
6739
 err_out:
6740
-        rtl8168_tx_clear_range(tp, tp->cur_tx + 1, cur_frag);
6741
+        rtl8168_tx_clear_range(tp, ring, ring->cur_tx + 1, cur_frag);
6742
         return -EIO;
6743
 }
6744
 
6745
@@ -29194,9 +30968,9 @@
6746
 
6747
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
6748
 /* r8169_csum_workaround()
6749
-  * The hw limits the value the transport offset. When the offset is out of the
6750
-  * range, calculate the checksum by sw.
6751
-  */
6752
+ * The hw limits the value the transport offset. When the offset is out of the
6753
+ * range, calculate the checksum by sw.
6754
+ */
6755
 static void r8168_csum_workaround(struct rtl8168_private *tp,
6756
                                   struct sk_buff *skb)
6757
 {
6758
@@ -29257,12 +31031,13 @@
6759
 #endif
6760
 
6761
 static bool rtl8168_tx_slots_avail(struct rtl8168_private *tp,
6762
-                                   unsigned int nr_frags)
6763
+                                   struct rtl8168_tx_ring *ring)
6764
 {
6765
-        unsigned int slots_avail = tp->dirty_tx + tp->num_tx_desc - tp->cur_tx;
6766
+        unsigned int slots_avail = READ_ONCE(ring->dirty_tx) + ring->num_tx_desc
6767
+                                   - READ_ONCE(ring->cur_tx);
6768
 
6769
         /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
6770
-        return slots_avail > nr_frags;
6771
+        return slots_avail > MAX_SKB_FRAGS;
6772
 }
6773
 
6774
 static netdev_tx_t
6775
@@ -29276,12 +31051,17 @@
6776
         u32 len;
6777
         u32 opts2;
6778
         netdev_tx_t ret = NETDEV_TX_OK;
6779
-        unsigned long flags, large_send;
6780
+        unsigned long large_send;
6781
         int frags;
6782
+        const u16 queue_mapping = skb_get_queue_mapping(skb);
6783
+        struct rtl8168_tx_ring *ring;
6784
+        bool stop_queue;
6785
 
6786
-        spin_lock_irqsave(&tp->lock, flags);
6787
+        assert(queue_mapping < tp->num_tx_rings);
6788
 
6789
-        if (unlikely(!rtl8168_tx_slots_avail(tp, skb_shinfo(skb)->nr_frags))) {
6790
+        ring = &tp->tx_ringqueue_mapping;
6791
+
6792
+        if (unlikely(!rtl8168_tx_slots_avail(tp, ring))) {
6793
                 if (netif_msg_drv(tp)) {
6794
                         printk(KERN_ERR
6795
                                "%s: BUG! Tx Ring full when queue awake!\n",
6796
@@ -29290,8 +31070,8 @@
6797
                 goto err_stop;
6798
         }
6799
 
6800
-        entry = tp->cur_tx % tp->num_tx_desc;
6801
-        txd = tp->TxDescArray + entry;
6802
+        entry = ring->cur_tx % ring->num_tx_desc;
6803
+        txd = ring->TxDescArray + entry;
6804
 
6805
         if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) {
6806
                 if (netif_msg_drv(tp)) {
6807
@@ -29334,7 +31114,6 @@
6808
                                 case __constant_htons(ETH_P_IPV6):
6809
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
6810
                                         if (msdn_giant_send_check(skb)) {
6811
-                                                spin_unlock_irqrestore(&tp->lock, flags);
6812
                                                 r8168_csum_workaround(tp, skb);
6813
                                                 goto out;
6814
                                         }
6815
@@ -29364,7 +31143,7 @@
6816
                         goto err_dma_0;
6817
         }
6818
 
6819
-        frags = rtl8168_xmit_frags(tp, skb, opts);
6820
+        frags = rtl8168_xmit_frags(tp, ring, skb, opts);
6821
         if (unlikely(frags < 0))
6822
                 goto err_dma_0;
6823
         if (frags) {
6824
@@ -29373,19 +31152,19 @@
6825
         } else {
6826
                 len = skb->len;
6827
 
6828
-                tp->tx_skbentry.skb = skb;
6829
+                ring->tx_skbentry.skb = skb;
6830
 
6831
                 opts0 |= FirstFrag | LastFrag;
6832
         }
6833
 
6834
-        opts0 = rtl8168_get_txd_opts1(tp, opts0, len, entry);
6835
+        opts0 = rtl8168_get_txd_opts1(ring, opts0, len, entry);
6836
         mapping = dma_map_single(tp_to_dev(tp), skb->data, len, DMA_TO_DEVICE);
6837
         if (unlikely(dma_mapping_error(tp_to_dev(tp), mapping))) {
6838
                 if (unlikely(net_ratelimit()))
6839
                         netif_err(tp, drv, dev, "Failed to map TX DMA!\n");
6840
                 goto err_dma_1;
6841
         }
6842
-        tp->tx_skbentry.len = len;
6843
+        ring->tx_skbentry.len = len;
6844
         txd->addr = cpu_to_le64(mapping);
6845
         txd->opts2 = cpu_to_le32(opts1);
6846
         wmb();
6847
@@ -29397,62 +31176,81 @@
6848
         skb_tx_timestamp(skb);
6849
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
6850
 
6851
-        tp->cur_tx += frags + 1;
6852
+        /* rtl_tx needs to see descriptor changes before updated ring->cur_tx */
6853
+        smp_wmb();
6854
 
6855
-        wmb();
6856
+        WRITE_ONCE(ring->cur_tx, ring->cur_tx + frags + 1);
6857
+
6858
+        stop_queue = !rtl8168_tx_slots_avail(tp, ring);
6859
+        if (unlikely(stop_queue)) {
6860
+                /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
6861
+                 * not miss a ring update when it notices a stopped queue.
6862
+                 */
6863
+                smp_wmb();
6864
+                netif_stop_subqueue(dev, queue_mapping);
6865
+        }
6866
 
6867
-        RTL_W8(tp, TxPoll, NPQ);    /* set polling bit */
6868
+        rtl8168_doorbell(ring);    /* set polling bit */
6869
 
6870
-        if (!rtl8168_tx_slots_avail(tp, MAX_SKB_FRAGS)) {
6871
-                netif_stop_queue(dev);
6872
-                smp_rmb();
6873
-                if (rtl8168_tx_slots_avail(tp, MAX_SKB_FRAGS))
6874
-                        netif_wake_queue(dev);
6875
+        if (unlikely(stop_queue)) {
6876
+                /* Sync with rtl_tx:
6877
+                 * - publish queue status and cur_tx ring index (write barrier)
6878
+                 * - refresh dirty_tx ring index (read barrier).
6879
+                 * May the current thread have a pessimistic view of the ring
6880
+                 * status and forget to wake up queue, a racing rtl_tx thread
6881
+                 * can't.
6882
+                 */
6883
+                smp_mb();
6884
+                if (rtl8168_tx_slots_avail(tp, ring))
6885
+                        netif_start_subqueue(dev, queue_mapping);
6886
         }
6887
 
6888
-        spin_unlock_irqrestore(&tp->lock, flags);
6889
 out:
6890
         return ret;
6891
 err_dma_1:
6892
-        tp->tx_skbentry.skb = NULL;
6893
-        rtl8168_tx_clear_range(tp, tp->cur_tx + 1, frags);
6894
+        ring->tx_skbentry.skb = NULL;
6895
+        rtl8168_tx_clear_range(tp, ring, ring->cur_tx + 1, frags);
6896
 err_dma_0:
6897
         RTLDEV->stats.tx_dropped++;
6898
-        spin_unlock_irqrestore(&tp->lock, flags);
6899
         dev_kfree_skb_any(skb);
6900
         ret = NETDEV_TX_OK;
6901
         goto out;
6902
 err_stop:
6903
-        netif_stop_queue(dev);
6904
+        netif_tx_disable(dev);
6905
         ret = NETDEV_TX_BUSY;
6906
         RTLDEV->stats.tx_dropped++;
6907
-
6908
-        spin_unlock_irqrestore(&tp->lock, flags);
6909
         goto out;
6910
 }
6911
 
6912
 static void
6913
-rtl8168_tx_interrupt(struct net_device *dev,
6914
-                     struct rtl8168_private *tp)
6915
+rtl8168_tx_interrupt(struct rtl8168_tx_ring *ring)
6916
 {
6917
+        struct rtl8168_private *tp = ring->priv;
6918
+        struct net_device *dev = tp->dev;
6919
         unsigned int dirty_tx, tx_left;
6920
 
6921
         assert(dev != NULL);
6922
         assert(tp != NULL);
6923
 
6924
-        dirty_tx = tp->dirty_tx;
6925
+#ifdef ENABLE_LIB_SUPPORT
6926
+        if (ring->index > 0) {
6927
+                rtl8168_lib_tx_interrupt(tp);
6928
+                return;
6929
+        }
6930
+#endif
6931
+        dirty_tx = ring->dirty_tx;
6932
         smp_rmb();
6933
-        tx_left = tp->cur_tx - dirty_tx;
6934
+        tx_left = READ_ONCE(ring->cur_tx) - dirty_tx;
6935
         tp->dynamic_aspm_packet_count += tx_left;
6936
 
6937
         while (tx_left > 0) {
6938
-                unsigned int entry = dirty_tx % tp->num_tx_desc;
6939
-                struct ring_info *tx_skb = tp->tx_skb + entry;
6940
+                unsigned int entry = dirty_tx % ring->num_tx_desc;
6941
+                struct ring_info *tx_skb = ring->tx_skb + entry;
6942
                 u32 len = tx_skb->len;
6943
                 u32 status;
6944
 
6945
                 rmb();
6946
-                status = le32_to_cpu(tp->TxDescArrayentry.opts1);
6947
+                status = le32_to_cpu(ring->TxDescArrayentry.opts1);
6948
                 if (status & DescOwn)
6949
                         break;
6950
 
6951
@@ -29461,7 +31259,7 @@
6952
 
6953
                 rtl8168_unmap_tx_skb(tp->pci_dev,
6954
                                      tx_skb,
6955
-                                     tp->TxDescArray + entry);
6956
+                                     ring->TxDescArray + entry);
6957
 
6958
                 if (tx_skb->skb!=NULL) {
6959
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
6960
@@ -29477,19 +31275,28 @@
6961
 
6962
         tp->dynamic_aspm_packet_count -= tx_left;
6963
 
6964
-        if (tp->dirty_tx != dirty_tx) {
6965
-                tp->dirty_tx = dirty_tx;
6966
+        if (ring->dirty_tx != dirty_tx) {
6967
+                WRITE_ONCE(ring->dirty_tx, dirty_tx);
6968
                 smp_wmb();
6969
                 if (netif_queue_stopped(dev) &&
6970
-                    (rtl8168_tx_slots_avail(tp, MAX_SKB_FRAGS))) {
6971
-                        netif_wake_queue(dev);
6972
+                    (rtl8168_tx_slots_avail(tp, ring))) {
6973
+                        netif_start_subqueue(dev, ring->index);
6974
                 }
6975
                 smp_rmb();
6976
-                if (tp->cur_tx != dirty_tx)
6977
-                        RTL_W8(tp, TxPoll, NPQ);
6978
+                if (ring->cur_tx != dirty_tx)
6979
+                        rtl8168_doorbell(ring);
6980
         }
6981
 }
6982
 
6983
+static void
6984
+rtl8168_tx_all_interrupt(struct rtl8168_private *tp)
6985
+{
6986
+        int i;
6987
+
6988
+        for (i = 0; i < rtl8168_tot_tx_rings(tp); i++)
6989
+                rtl8168_tx_interrupt(&tp->tx_ringi);
6990
+}
6991
+
6992
 static inline int
6993
 rtl8168_fragmented_frame(u32 status)
6994
 {
6995
@@ -29528,8 +31335,10 @@
6996
         }
6997
 }
6998
 
6999
+/*
7000
 static inline int
7001
 rtl8168_try_rx_copy(struct rtl8168_private *tp,
7002
+                    struct rtl8168_rx_ring *ring,
7003
                     struct sk_buff **sk_buff,
7004
                     int pkt_size,
7005
                     struct RxDesc *desc,
7006
@@ -29537,36 +31346,38 @@
7007
 {
7008
         int ret = -1;
7009
 
7010
-        if (pkt_size < rx_copybreak) {
7011
-                struct sk_buff *skb;
7012
+        struct sk_buff *skb;
7013
 
7014
-                skb = RTL_ALLOC_SKB_INTR(tp, pkt_size + RTK_RX_ALIGN);
7015
-                if (skb) {
7016
-                        u8 *data;
7017
+        skb = RTL_ALLOC_SKB_INTR(&tp->r8168napiring->index.napi,
7018
+                                 pkt_size + RTK_RX_ALIGN);
7019
+        if (skb) {
7020
+                u8 *data;
7021
 
7022
-                        data = sk_buff0->data;
7023
-                        skb_reserve(skb, RTK_RX_ALIGN);
7024
+                data = sk_buff0->data;
7025
+                skb_reserve(skb, RTK_RX_ALIGN);
7026
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37)
7027
-                        prefetch(data - RTK_RX_ALIGN);
7028
+                prefetch(data - RTK_RX_ALIGN);
7029
 #endif
7030
-                        eth_copy_and_sum(skb, data, pkt_size, 0);
7031
-                        *sk_buff = skb;
7032
-                        rtl8168_mark_to_asic(desc, rx_buf_sz);
7033
-                        ret = 0;
7034
-                }
7035
+                eth_copy_and_sum(skb, data, pkt_size, 0);
7036
+                *sk_buff = skb;
7037
+                rtl8168_mark_to_asic(desc, rx_buf_sz);
7038
+                ret = 0;
7039
         }
7040
+
7041
         return ret;
7042
 }
7043
+*/
7044
 
7045
 static inline void
7046
 rtl8168_rx_skb(struct rtl8168_private *tp,
7047
-               struct sk_buff *skb)
7048
+               struct sk_buff *skb,
7049
+               u32 ring_index)
7050
 {
7051
 #ifdef CONFIG_R8168_NAPI
7052
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
7053
         netif_receive_skb(skb);
7054
 #else
7055
-        napi_gro_receive(&tp->napi, skb);
7056
+        napi_gro_receive(&tp->r8168napiring_index.napi, skb);
7057
 #endif
7058
 #else
7059
         netif_rx(skb);
7060
@@ -29576,29 +31387,42 @@
7061
 static int
7062
 rtl8168_rx_interrupt(struct net_device *dev,
7063
                      struct rtl8168_private *tp,
7064
+                     struct rtl8168_rx_ring *ring,
7065
                      napi_budget budget)
7066
 {
7067
         unsigned int cur_rx, rx_left;
7068
-        unsigned int delta, count = 0;
7069
+        unsigned int count = 0;
7070
+        u32 ring_index = ring->index;
7071
         unsigned int entry;
7072
         struct RxDesc *desc;
7073
         u32 status;
7074
         u32 rx_quota;
7075
+        u64 rx_buf_phy_addr;
7076
 
7077
         assert(dev != NULL);
7078
         assert(tp != NULL);
7079
 
7080
-        if (tp->RxDescArray == NULL)
7081
+        if (!tp->RxDescArray)
7082
                 goto rx_out;
7083
 
7084
+#ifdef ENABLE_LIB_SUPPORT
7085
+        if (ring->index > 0) {
7086
+                rtl8168_lib_rx_interrupt(tp);
7087
+                goto rx_out;
7088
+        }
7089
+#endif
7090
         rx_quota = RTL_RX_QUOTA(budget);
7091
-        cur_rx = tp->cur_rx;
7092
-        entry = cur_rx % tp->num_rx_desc;
7093
-        desc = tp->RxDescArray + entry;
7094
-        rx_left = tp->num_rx_desc + tp->dirty_rx - cur_rx;
7095
+        cur_rx = ring->cur_rx;
7096
+        rx_left = tp->num_rx_desc + ring->dirty_rx - cur_rx;
7097
         rx_left = rtl8168_rx_quota(rx_left, (u32)rx_quota);
7098
 
7099
-        for (; rx_left > 0; rx_left--) {
7100
+        for (; rx_left > 0; rx_left--, cur_rx++) {
7101
+                int pkt_size;
7102
+                const void *rx_buf;
7103
+                struct sk_buff *skb;
7104
+
7105
+                entry = cur_rx % tp->num_rx_desc;
7106
+                desc = rtl8168_get_rxdesc(tp, tp->RxDescArray, entry, ring_index);
7107
                 status = le32_to_cpu(desc->opts1);
7108
                 if (status & DescOwn)
7109
                         break;
7110
@@ -29618,94 +31442,81 @@
7111
                                 RTLDEV->stats.rx_length_errors++;
7112
                         if (status & RxCRC)
7113
                                 RTLDEV->stats.rx_crc_errors++;
7114
-                        if (dev->features & NETIF_F_RXALL)
7115
-                                goto process_pkt;
7116
 
7117
-                        rtl8168_mark_to_asic(desc, tp->rx_buf_sz);
7118
-                } else {
7119
-                        struct sk_buff *skb;
7120
-                        int pkt_size;
7121
+                        if (!(dev->features & NETIF_F_RXALL))
7122
+                                goto release_descriptor;
7123
+                }
7124
 
7125
-process_pkt:
7126
-                        pkt_size = status & 0x00003fff;
7127
-                        if (likely(!(dev->features & NETIF_F_RXFCS)))
7128
-                                pkt_size -= ETH_FCS_LEN;
7129
-
7130
-                        /*
7131
-                         * The driver does not support incoming fragmented
7132
-                         * frames. They are seen as a symptom of over-mtu
7133
-                         * sized frames.
7134
-                         */
7135
-                        if (unlikely(rtl8168_fragmented_frame(status)) ||
7136
-                            unlikely(pkt_size > tp->rx_buf_sz)) {
7137
-                                RTLDEV->stats.rx_dropped++;
7138
-                                RTLDEV->stats.rx_length_errors++;
7139
-                                rtl8168_mark_to_asic(desc, tp->rx_buf_sz);
7140
-                                continue;
7141
-                        }
7142
+                pkt_size = status & 0x00003fff;
7143
+                if (likely(!(dev->features & NETIF_F_RXFCS)))
7144
+                        pkt_size -= ETH_FCS_LEN;
7145
 
7146
-                        skb = tp->Rx_skbuffentry;
7147
+                /*
7148
+                 * The driver does not support incoming fragmented
7149
+                 * frames. They are seen as a symptom of over-mtu
7150
+                 * sized frames.
7151
+                 */
7152
+                if (unlikely(rtl8168_fragmented_frame(status)) ||
7153
+                    unlikely(pkt_size > tp->rx_buf_sz)) {
7154
+                        RTLDEV->stats.rx_dropped++;
7155
+                        RTLDEV->stats.rx_length_errors++;
7156
+                        goto release_descriptor;
7157
+                }
7158
+
7159
+                skb = RTL_ALLOC_SKB_INTR(&tp->r8168napiring_index.napi, pkt_size + RTK_RX_ALIGN);
7160
+                if (!skb) {
7161
+                        RTLDEV->stats.rx_dropped++;
7162
+                        RTLDEV->stats.rx_length_errors++;
7163
+                        //netdev_err(tp->dev, "Failed to allocate RX skb!\n");
7164
+                        goto release_descriptor;
7165
+                }
7166
+
7167
+                rx_buf_phy_addr = ring->RxDescPhyAddrentry;
7168
+                dma_sync_single_for_cpu(tp_to_dev(tp),
7169
+                                        rx_buf_phy_addr, tp->rx_buf_sz,
7170
+                                        DMA_FROM_DEVICE);
7171
 
7172
-                        dma_sync_single_for_cpu(tp_to_dev(tp),
7173
-                                                le64_to_cpu(desc->addr), tp->rx_buf_sz,
7174
-                                                DMA_FROM_DEVICE);
7175
-
7176
-                        if (rtl8168_try_rx_copy(tp, &skb, pkt_size,
7177
-                                                desc, tp->rx_buf_sz)) {
7178
-                                tp->Rx_skbuffentry = NULL;
7179
-                                dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr),
7180
-                                                 tp->rx_buf_sz, DMA_FROM_DEVICE);
7181
-                        } else {
7182
-                                dma_sync_single_for_device(tp_to_dev(tp), le64_to_cpu(desc->addr),
7183
-                                                           tp->rx_buf_sz, DMA_FROM_DEVICE);
7184
-                        }
7185
+                rx_buf = ring->Rx_skbuffentry->data;
7186
+                if (!R8168_USE_NAPI_ALLOC_SKB)
7187
+                        skb_reserve(skb, RTK_RX_ALIGN);
7188
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37)
7189
+                prefetch(rx_buf);
7190
+#endif
7191
+                eth_copy_and_sum(skb, rx_buf, pkt_size, 0);
7192
 
7193
-                        if (tp->cp_cmd & RxChkSum)
7194
-                                rtl8168_rx_csum(tp, skb, desc);
7195
+                dma_sync_single_for_device(tp_to_dev(tp), rx_buf_phy_addr,
7196
+                                           tp->rx_buf_sz, DMA_FROM_DEVICE);
7197
 
7198
-                        skb->dev = dev;
7199
-                        skb_put(skb, pkt_size);
7200
-                        skb->protocol = eth_type_trans(skb, dev);
7201
+#ifdef ENABLE_RSS_SUPPORT
7202
+                rtl8168_rx_hash(tp, (struct RxDescV2 *)desc, skb);
7203
+#endif
7204
+                if (tp->cp_cmd & RxChkSum)
7205
+                        rtl8168_rx_csum(tp, skb, desc);
7206
+
7207
+                skb->dev = dev;
7208
+                skb_put(skb, pkt_size);
7209
+                skb->protocol = eth_type_trans(skb, dev);
7210
 
7211
-                        if (skb->pkt_type == PACKET_MULTICAST)
7212
-                                RTLDEV->stats.multicast++;
7213
+                if (skb->pkt_type == PACKET_MULTICAST)
7214
+                        RTLDEV->stats.multicast++;
7215
 
7216
-                        if (rtl8168_rx_vlan_skb(tp, desc, skb) < 0)
7217
-                                rtl8168_rx_skb(tp, skb);
7218
+                if (rtl8168_rx_vlan_skb(tp, desc, skb) < 0)
7219
+                        rtl8168_rx_skb(tp, skb, ring_index);
7220
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
7221
-                        dev->last_rx = jiffies;
7222
+                dev->last_rx = jiffies;
7223
 #endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,11,0)
7224
-                        RTLDEV->stats.rx_bytes += pkt_size;
7225
-                        RTLDEV->stats.rx_packets++;
7226
-                }
7227
+                RTLDEV->stats.rx_bytes += pkt_size;
7228
+                RTLDEV->stats.rx_packets++;
7229
 
7230
-                cur_rx++;
7231
-                entry = cur_rx % tp->num_rx_desc;
7232
-                desc = tp->RxDescArray + entry;
7233
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37)
7234
-                prefetch(desc);
7235
-#endif
7236
+release_descriptor:
7237
+                rtl8168_mark_to_asic(desc, tp->rx_buf_sz);
7238
         }
7239
 
7240
-        count = cur_rx - tp->cur_rx;
7241
-        tp->cur_rx = cur_rx;
7242
+        count = cur_rx - ring->cur_rx;
7243
+        ring->cur_rx = cur_rx;
7244
+        ring->dirty_rx += count;
7245
 
7246
-        delta = rtl8168_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx, 1);
7247
-        if (!delta && count && netif_msg_intr(tp))
7248
-                printk(KERN_INFO "%s: no Rx buffer allocated\n", dev->name);
7249
-        tp->dirty_rx += delta;
7250
-
7251
-        tp->dynamic_aspm_packet_count += delta;
7252
-
7253
-        /*
7254
-         * FIXME: until there is periodic timer to try and refill the ring,
7255
-         * a temporary shortage may definitely kill the Rx process.
7256
-         * - disable the asic to try and avoid an overflow and kick it again
7257
-         *   after refill ?
7258
-         * - how do others driver handle this condition (Uh oh...).
7259
-         */
7260
-        if ((tp->dirty_rx + tp->num_rx_desc == tp->cur_rx) && netif_msg_intr(tp))
7261
-                printk(KERN_EMERG "%s: Rx buffers exhausted\n", dev->name);
7262
+        tp->dynamic_aspm_packet_count += count;
7263
 
7264
 rx_out:
7265
         return count;
7266
@@ -29721,67 +31532,51 @@
7267
 static irqreturn_t rtl8168_interrupt(int irq, void *dev_instance)
7268
 #endif
7269
 {
7270
-        struct net_device *dev = (struct net_device *) dev_instance;
7271
-        struct rtl8168_private *tp = netdev_priv(dev);
7272
-        int status;
7273
+        struct r8168_napi *r8168napi = dev_instance;
7274
+        struct rtl8168_private *tp = r8168napi->priv;
7275
+        struct net_device *dev = tp->dev;
7276
+        u8 other_q_status = 0;
7277
         int handled = 0;
7278
+        int status;
7279
+        int i;
7280
 
7281
         do {
7282
-                status = RTL_R16(tp, IntrStatus);
7283
-
7284
+                status = RTL_R16(tp, tp->isr_reg0);
7285
+#ifdef ENABLE_RSS_SUPPORT
7286
+                if (R8168_MULTI_RX_Q(tp)) {
7287
+                        for (i=1; i<rtl8168_tot_rx_rings(tp); i++)
7288
+                                other_q_status |= RTL_R8(tp, tp->isr_regi);
7289
+                }
7290
+#endif
7291
                 if (!(tp->features & (RTL_FEATURE_MSI | RTL_FEATURE_MSIX))) {
7292
                         /* hotplug/major error/no more work/shared irq */
7293
-                        if ((status == 0xFFFF) || !status)
7294
+                        if ((status == 0xFFFF) || (!status && !other_q_status))
7295
                                 break;
7296
 
7297
-                        if (!(status & (tp->intr_mask | tp->timer_intr_mask)))
7298
+                        if (!(status & (tp->intr_mask | tp->timer_intr_mask)) &&
7299
+                            !(other_q_status & other_q_intr_mask))
7300
                                 break;
7301
                 }
7302
 
7303
                 handled = 1;
7304
 
7305
-                rtl8168_disable_hw_interrupt(tp);
7306
+                rtl8168_disable_interrupt(tp);
7307
+                rtl8168_disable_lib_interrupt(tp);
7308
 
7309
                 switch (tp->mcfg) {
7310
-                case CFG_METHOD_9:
7311
-                case CFG_METHOD_10:
7312
-                case CFG_METHOD_11:
7313
-                case CFG_METHOD_12:
7314
-                case CFG_METHOD_13:
7315
-                case CFG_METHOD_14:
7316
-                case CFG_METHOD_15:
7317
-                case CFG_METHOD_16:
7318
-                case CFG_METHOD_17:
7319
-                case CFG_METHOD_18:
7320
-                case CFG_METHOD_19:
7321
-                case CFG_METHOD_20:
7322
-                case CFG_METHOD_21:
7323
-                case CFG_METHOD_22:
7324
-                case CFG_METHOD_23:
7325
-                case CFG_METHOD_24:
7326
-                case CFG_METHOD_25:
7327
-                case CFG_METHOD_26:
7328
-                case CFG_METHOD_27:
7329
-                case CFG_METHOD_28:
7330
-                case CFG_METHOD_29:
7331
-                case CFG_METHOD_30:
7332
-                case CFG_METHOD_31:
7333
-                case CFG_METHOD_32:
7334
-                case CFG_METHOD_33:
7335
-                case CFG_METHOD_34:
7336
-                case CFG_METHOD_35:
7337
+                case CFG_METHOD_9 ... CFG_METHOD_37:
7338
                         /* RX_OVERFLOW RE-START mechanism now HW handles it automatically*/
7339
-                        RTL_W16(tp, IntrStatus, status&~RxFIFOOver);
7340
+                        rtl8168_clear_isr_by_vector(tp, 0, status&~RxFIFOOver);
7341
                         break;
7342
                 default:
7343
-                        RTL_W16(tp, IntrStatus, status);
7344
+                        rtl8168_clear_isr_by_vector(tp, 0, status);
7345
                         break;
7346
                 }
7347
 
7348
                 //Work around for rx fifo overflow
7349
                 if (unlikely(status & RxFIFOOver)) {
7350
                         if (tp->mcfg == CFG_METHOD_1) {
7351
-                                netif_stop_queue(dev);
7352
+                                netif_tx_disable(dev);
7353
                                 udelay(300);
7354
                                 rtl8168_hw_reset(dev);
7355
                                 rtl8168_tx_clear(tp);
7356
@@ -29789,8 +31584,14 @@
7357
                                 rtl8168_init_ring(dev);
7358
                                 rtl8168_hw_config(dev);
7359
                                 rtl8168_hw_start(dev);
7360
-                                netif_wake_queue(dev);
7361
+                                netif_tx_wake_all_queues(dev);
7362
                         }
7363
+                        tp->rx_fifo_of++;
7364
+                }
7365
+
7366
+                if (other_q_status) {
7367
+                        for (i=1; i<rtl8168_tot_rx_rings(tp); i++)
7368
+                                rtl8168_clear_isr_by_vector(tp, i, other_q_status);
7369
                 }
7370
 
7371
 #ifdef ENABLE_DASH_SUPPORT
7372
@@ -29828,12 +31629,15 @@
7373
 #endif
7374
 
7375
 #ifdef CONFIG_R8168_NAPI
7376
-                if (status & tp->intr_mask || tp->keep_intr_cnt-- > 0) {
7377
-                        if (status & tp->intr_mask)
7378
+                if ((status & tp->intr_mask) ||
7379
+                    (other_q_status & other_q_intr_mask) ||
7380
+                    tp->keep_intr_cnt-- > 0) {
7381
+                        if ((status & tp->intr_mask) ||
7382
+                            (other_q_status & other_q_intr_mask))
7383
                                 tp->keep_intr_cnt = RTK_KEEP_INTERRUPT_COUNT;
7384
 
7385
-                        if (likely(RTL_NETIF_RX_SCHEDULE_PREP(dev, &tp->napi)))
7386
-                                __RTL_NETIF_RX_SCHEDULE(dev, &tp->napi);
7387
+                        if (likely(RTL_NETIF_RX_SCHEDULE_PREP(dev, &tp->r8168napi0.napi)))
7388
+                                __RTL_NETIF_RX_SCHEDULE(dev, &tp->r8168napi0.napi);
7389
                         else if (netif_msg_intr(tp))
7390
                                 printk(KERN_INFO "%s: interrupt %04x in poll\n",
7391
                                        dev->name, status);
7392
@@ -29842,19 +31646,27 @@
7393
                         rtl8168_switch_to_hw_interrupt(tp);
7394
                 }
7395
 #else
7396
-                if (status & tp->intr_mask || tp->keep_intr_cnt-- > 0) {
7397
+                if ((status & tp->intr_mask) ||
7398
+                    (other_q_status & other_q_intr_mask) ||
7399
+                    tp->keep_intr_cnt-- > 0) {
7400
+                        u32 const max_rx_queue =
7401
+                                (other_q_status & other_q_intr_mask) > 0 ?
7402
+                                rtl8168_tot_rx_rings(tp) : 1;
7403
                         u32 budget = ~(u32)0;
7404
 
7405
-                        if (status & tp->intr_mask)
7406
+                        if ((status & tp->intr_mask) ||
7407
+                            (other_q_status & other_q_intr_mask))
7408
                                 tp->keep_intr_cnt = RTK_KEEP_INTERRUPT_COUNT;
7409
 
7410
-                        rtl8168_tx_interrupt(dev, tp);
7411
+                        rtl8168_tx_all_interrupt(tp);
7412
 
7413
+                        for (i = 0; i < max_rx_queue; i++) {
7414
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
7415
-                        rtl8168_rx_interrupt(dev, tp, &budget);
7416
+                                rtl8168_rx_interrupt(dev, tp, &tp->rx_ringi, &budget);
7417
 #else
7418
-                        rtl8168_rx_interrupt(dev, tp, budget);
7419
-#endif  //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
7420
+                                rtl8168_rx_interrupt(dev, tp, &tp->rx_ringi, budget);
7421
+#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
7422
+                        }
7423
 
7424
 #ifdef ENABLE_DASH_SUPPORT
7425
                         if ( tp->DASH ) {
7426
@@ -29876,31 +31688,91 @@
7427
         return IRQ_RETVAL(handled);
7428
 }
7429
 
7430
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
7431
+static irqreturn_t rtl8168_interrupt_msix(int irq, void *dev_instance, struct pt_regs *regs)
7432
+#else
7433
+static irqreturn_t rtl8168_interrupt_msix(int irq, void *dev_instance)
7434
+#endif
7435
+{
7436
+        struct r8168_napi *r8168napi = dev_instance;
7437
+        struct rtl8168_private *tp = r8168napi->priv;
7438
+        struct net_device *dev = tp->dev;
7439
+        int message_id = r8168napi->index;
7440
+#ifndef CONFIG_R8168_NAPI
7441
+        u32 budget = ~(u32)0;
7442
+#endif
7443
+
7444
+        do {
7445
+#if defined(RTL_USE_NEW_INTR_API)
7446
+                if (!tp->irq_tblmessage_id.requested)
7447
+                        break;
7448
+#endif
7449
+                /*
7450
+                 * Other rx queue may incur interrupt due to rdu.
7451
+                 * Skip its interrupt here or its queue will be initialized
7452
+                 * incorrectly.
7453
+                 */
7454
+                if (message_id >= tp->num_rx_rings)
7455
+                        break;
7456
+
7457
 #ifdef CONFIG_R8168_NAPI
7458
-static int rtl8168_poll(napi_ptr napi, napi_budget budget)
7459
+                if (likely(RTL_NETIF_RX_SCHEDULE_PREP(dev, &r8168napi->napi))) {
7460
+                        rtl8168_disable_interrupt_by_vector(tp, message_id);
7461
+                        __RTL_NETIF_RX_SCHEDULE(dev, &r8168napi->napi);
7462
+                } else if (netif_msg_intr(tp))
7463
+                        printk(KERN_INFO "%s: interrupt message id %d in poll_msix\n",
7464
+                               dev->name, message_id);
7465
+                rtl8168_self_clear_isr_by_vector(tp, message_id);
7466
+#else
7467
+                if (message_id == 0)
7468
+                        rtl8168_tx_all_interrupt(tp);
7469
+
7470
+                if (message_id < tp->num_rx_rings) {
7471
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
7472
+                        rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, &budget);
7473
+#else
7474
+                        rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, budget);
7475
+#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
7476
+                }
7477
+
7478
+                rtl8168_enable_interrupt_by_vector(tp, message_id);
7479
+#endif
7480
+
7481
+        } while (false);
7482
+
7483
+        return IRQ_HANDLED;
7484
+}
7485
+
7486
+#ifdef CONFIG_R8168_NAPI
7487
+static int rtl8168_poll_vector(napi_ptr napi, napi_budget budget, bool all_rx_q)
7488
 {
7489
-        struct rtl8168_private *tp = RTL_GET_PRIV(napi, struct rtl8168_private);
7490
+        struct r8168_napi *r8168napi = RTL_GET_PRIV(napi, struct r8168_napi);
7491
+        struct rtl8168_private *tp = r8168napi->priv;
7492
+        const int message_id = r8168napi->index;
7493
         RTL_GET_NETDEV(tp)
7494
         unsigned int work_to_do = RTL_NAPI_QUOTA(budget, dev);
7495
-        unsigned int work_done;
7496
-        unsigned long flags;
7497
+        unsigned int work_done = 0;
7498
+        int i;
7499
 
7500
-        spin_lock_irqsave(&tp->lock, flags);
7501
-        rtl8168_tx_interrupt(dev, tp);
7502
-        spin_unlock_irqrestore(&tp->lock, flags);
7503
+        if (message_id == 0)
7504
+                rtl8168_tx_all_interrupt(tp);
7505
 
7506
-        work_done = rtl8168_rx_interrupt(dev, tp, budget);
7507
+        if (all_rx_q)
7508
+                for (i = 0; i < tp->num_rx_rings; i++)
7509
+                        work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringi, budget);
7510
+        else
7511
+                work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, budget);
7512
 
7513
         RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget);
7514
 
7515
         if (work_done < work_to_do) {
7516
 #ifdef ENABLE_DASH_SUPPORT
7517
-                if ( tp->DASH ) {
7518
-                        struct net_device *dev = tp->dev;
7519
+                if (message_id == 0) {
7520
+                        if ( tp->DASH ) {
7521
+                                struct net_device *dev = tp->dev;
7522
 
7523
-                        spin_lock_irqsave(&tp->lock, flags);
7524
-                        HandleDashInterrupt(dev);
7525
-                        spin_unlock_irqrestore(&tp->lock, flags);
7526
+                                HandleDashInterrupt(dev);
7527
+                        }
7528
                 }
7529
 #endif
7530
 
7531
@@ -29917,8 +31789,55 @@
7532
                  * write is safe - FR
7533
                  */
7534
                 smp_wmb();
7535
+                //if (message_id == 0)
7536
+                //        rtl8168_switch_to_timer_interrupt(tp);
7537
+                //else
7538
+                rtl8168_enable_interrupt_by_vector(tp, message_id);
7539
+        }
7540
 
7541
-                rtl8168_switch_to_timer_interrupt(tp);
7542
+        return RTL_NAPI_RETURN_VALUE;
7543
+}
7544
+
7545
+static int rtl8168_poll(napi_ptr napi, napi_budget budget)
7546
+{
7547
+        return rtl8168_poll_vector(napi, budget, 1);
7548
+}
7549
+
7550
+static int rtl8168_poll_msix_ring(napi_ptr napi, napi_budget budget)
7551
+{
7552
+        return rtl8168_poll_vector(napi, budget, 0);
7553
+}
7554
+static int rtl8168_poll_msix_rx(napi_ptr napi, napi_budget budget)
7555
+{
7556
+        struct r8168_napi *r8168napi = RTL_GET_PRIV(napi, struct r8168_napi);
7557
+        struct rtl8168_private *tp = r8168napi->priv;
7558
+        const int message_id = r8168napi->index;
7559
+        RTL_GET_NETDEV(tp)
7560
+        unsigned int work_to_do = RTL_NAPI_QUOTA(budget, dev);
7561
+        unsigned int work_done = 0;
7562
+
7563
+        work_done += rtl8168_rx_interrupt(dev, tp, &tp->rx_ringmessage_id, budget);
7564
+
7565
+        RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget);
7566
+
7567
+        if (work_done < work_to_do) {
7568
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
7569
+                if (RTL_NETIF_RX_COMPLETE(dev, napi, work_done) == FALSE)
7570
+                        return RTL_NAPI_RETURN_VALUE;
7571
+#else
7572
+                RTL_NETIF_RX_COMPLETE(dev, napi, work_done);
7573
+#endif
7574
+                /*
7575
+                 * 20040426: the barrier is not strictly required but the
7576
+                 * behavior of the irq handler could be less predictable
7577
+                 * without it. Btw, the lack of flush for the posted pci
7578
+                 * write is safe - FR
7579
+                 */
7580
+                smp_wmb();
7581
+                //if (message_id == 0)
7582
+                //        rtl8168_switch_to_timer_interrupt(tp);
7583
+                //else
7584
+                rtl8168_enable_interrupt_by_vector(tp, message_id);
7585
         }
7586
 
7587
         return RTL_NAPI_RETURN_VALUE;
7588
@@ -29945,89 +31864,62 @@
7589
 static void rtl8168_down(struct net_device *dev)
7590
 {
7591
         struct rtl8168_private *tp = netdev_priv(dev);
7592
-        unsigned long flags;
7593
-
7594
-        rtl8168_delete_esd_timer(dev, &tp->esd_timer);
7595
-
7596
-        rtl8168_delete_link_timer(dev, &tp->link_timer);
7597
-
7598
-#ifdef CONFIG_R8168_NAPI
7599
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
7600
-        RTL_NAPI_DISABLE(dev, &tp->napi);
7601
-#endif
7602
-#endif//CONFIG_R8168_NAPI
7603
 
7604
-        netif_stop_queue(dev);
7605
+        //rtl8168_delete_esd_timer(dev, &tp->esd_timer);
7606
+        //rtl8168_delete_link_timer(dev, &tp->link_timer);
7607
 
7608
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
7609
-        /* Give a racing hard_start_xmit a few cycles to complete. */
7610
-        synchronize_rcu();  /* FIXME: should this be synchronize_irq()? */
7611
-#endif
7612
+        netif_carrier_off(dev);
7613
 
7614
-        spin_lock_irqsave(&tp->lock, flags);
7615
+        netif_tx_disable(dev);
7616
 
7617
-        netif_carrier_off(dev);
7618
+        _rtl8168_wait_for_quiescence(dev);
7619
 
7620
         rtl8168_dsm(dev, DSM_IF_DOWN);
7621
 
7622
         rtl8168_hw_reset(dev);
7623
 
7624
-        spin_unlock_irqrestore(&tp->lock, flags);
7625
+        rtl8168_tx_clear(tp);
7626
 
7627
-        synchronize_irq(tp->irq);
7628
+        rtl8168_rx_clear(tp);
7629
+}
7630
 
7631
-        spin_lock_irqsave(&tp->lock, flags);
7632
+static int rtl8168_resource_freed(struct rtl8168_private *tp)
7633
+{
7634
+        int i;
7635
 
7636
-        rtl8168_tx_clear(tp);
7637
+        for (i = 0; i < tp->num_tx_rings; i++)
7638
+                if (tp->tx_ringi.TxDescArray) return 0;
7639
 
7640
-        rtl8168_rx_clear(tp);
7641
+        if (tp->RxDescArray)
7642
+                return 0;
7643
 
7644
-        spin_unlock_irqrestore(&tp->lock, flags);
7645
+        return 1;
7646
 }
7647
 
7648
-static int rtl8168_close(struct net_device *dev)
7649
+int rtl8168_close(struct net_device *dev)
7650
 {
7651
         struct rtl8168_private *tp = netdev_priv(dev);
7652
-        struct pci_dev *pdev = tp->pci_dev;
7653
-        unsigned long flags;
7654
 
7655
-        if (tp->TxDescArray!=NULL && tp->RxDescArray!=NULL) {
7656
-                rtl8168_cancel_schedule_work(dev);
7657
+        if (!rtl8168_resource_freed(tp)) {
7658
+                set_bit(R8168_FLAG_DOWN, tp->task_flags);
7659
 
7660
                 rtl8168_down(dev);
7661
 
7662
                 pci_clear_master(tp->pci_dev);
7663
 
7664
-                spin_lock_irqsave(&tp->lock, flags);
7665
-
7666
                 rtl8168_hw_d3_para(dev);
7667
 
7668
                 rtl8168_powerdown_pll(dev);
7669
 
7670
                 rtl8168_sleep_rx_enable(dev);
7671
 
7672
-                spin_unlock_irqrestore(&tp->lock, flags);
7673
-
7674
-                free_irq(tp->irq, dev);
7675
+                rtl8168_free_irq(tp);
7676
 
7677
-                dma_free_coherent(&pdev->dev,
7678
-                                  tp->RxDescAllocSize,
7679
-                                  tp->RxDescArray,
7680
-                                  tp->RxPhyAddr);
7681
-                dma_free_coherent(&pdev->dev,
7682
-                                  tp->TxDescAllocSize,
7683
-                                  tp->TxDescArray,
7684
-                                  tp->TxPhyAddr);
7685
-                tp->TxDescArray = NULL;
7686
-                tp->RxDescArray = NULL;
7687
+                rtl8168_free_alloc_resources(tp);
7688
         } else {
7689
-                spin_lock_irqsave(&tp->lock, flags);
7690
-
7691
                 rtl8168_hw_d3_para(dev);
7692
 
7693
                 rtl8168_powerdown_pll(dev);
7694
-
7695
-                spin_unlock_irqrestore(&tp->lock, flags);
7696
         }
7697
 
7698
         return 0;
7699
@@ -30039,6 +31931,8 @@
7700
         struct net_device *dev = pci_get_drvdata(pdev);
7701
         struct rtl8168_private *tp = netdev_priv(dev);
7702
 
7703
+        rtnl_lock();
7704
+
7705
         if (HW_DASH_SUPPORT_DASH(tp))
7706
                 rtl8168_driver_stop(tp);
7707
 
7708
@@ -30056,6 +31950,8 @@
7709
         rtl8168_close(dev);
7710
         rtl8168_disable_msi(pdev, tp);
7711
 
7712
+        rtnl_unlock();
7713
+
7714
         if (system_state == SYSTEM_POWER_OFF) {
7715
                 pci_clear_master(tp->pci_dev);
7716
                 rtl8168_sleep_rx_enable(dev);
7717
@@ -30077,11 +31973,6 @@
7718
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
7719
         struct rtl8168_private *tp = netdev_priv(dev);
7720
 #endif
7721
-        if (netif_running(dev)) {
7722
-//      spin_lock_irqsave(&tp->lock, flags);
7723
-//      spin_unlock_irqrestore(&tp->lock, flags);
7724
-        }
7725
-
7726
         return &RTLDEV->stats;
7727
 }
7728
 
7729
@@ -30090,34 +31981,40 @@
7730
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
7731
 static int
7732
 rtl8168_suspend(struct pci_dev *pdev, u32 state)
7733
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
7734
+static int
7735
+rtl8168_suspend(struct device *device)
7736
 #else
7737
 static int
7738
 rtl8168_suspend(struct pci_dev *pdev, pm_message_t state)
7739
 #endif
7740
 {
7741
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
7742
+        struct pci_dev *pdev = to_pci_dev(device);
7743
+#endif
7744
         struct net_device *dev = pci_get_drvdata(pdev);
7745
         struct rtl8168_private *tp = netdev_priv(dev);
7746
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7747
         u32 pci_pm_state = pci_choose_state(pdev, state);
7748
 #endif
7749
-        unsigned long flags;
7750
-
7751
         if (!netif_running(dev))
7752
                 goto out;
7753
 
7754
-        rtl8168_cancel_schedule_work(dev);
7755
+        //rtl8168_cancel_schedule_work(dev);
7756
 
7757
-        rtl8168_delete_esd_timer(dev, &tp->esd_timer);
7758
+        //rtl8168_delete_esd_timer(dev, &tp->esd_timer);
7759
 
7760
-        rtl8168_delete_link_timer(dev, &tp->link_timer);
7761
+        //rtl8168_delete_link_timer(dev, &tp->link_timer);
7762
 
7763
-        netif_stop_queue(dev);
7764
+        rtnl_lock();
7765
+
7766
+        set_bit(R8168_FLAG_DOWN, tp->task_flags);
7767
 
7768
         netif_carrier_off(dev);
7769
 
7770
-        netif_device_detach(dev);
7771
+        netif_tx_disable(dev);
7772
 
7773
-        spin_lock_irqsave(&tp->lock, flags);
7774
+        netif_device_detach(dev);
7775
 
7776
         rtl8168_dsm(dev, DSM_NIC_GOTO_D3);
7777
 
7778
@@ -30135,37 +32032,53 @@
7779
 
7780
         rtl8168_sleep_rx_enable(dev);
7781
 
7782
-        spin_unlock_irqrestore(&tp->lock, flags);
7783
+        rtnl_unlock();
7784
 
7785
 out:
7786
-        if (HW_DASH_SUPPORT_DASH(tp)) {
7787
-                spin_lock_irqsave(&tp->lock, flags);
7788
+        if (HW_DASH_SUPPORT_DASH(tp))
7789
                 rtl8168_driver_stop(tp);
7790
-                spin_unlock_irqrestore(&tp->lock, flags);
7791
-        }
7792
+
7793
+        pci_disable_device(pdev);
7794
 
7795
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7796
         pci_save_state(pdev, &pci_pm_state);
7797
 #else
7798
         pci_save_state(pdev);
7799
 #endif
7800
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
7801
         pci_enable_wake(pdev, pci_choose_state(pdev, state), tp->wol_enabled);
7802
-//  pci_set_power_state(pdev, pci_choose_state(pdev, state));
7803
+#endif
7804
+
7805
+        pci_prepare_to_sleep(pdev);
7806
 
7807
         return 0;
7808
 }
7809
 
7810
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
7811
 static int
7812
 rtl8168_resume(struct pci_dev *pdev)
7813
+#else
7814
+static int
7815
+rtl8168_resume(struct device *device)
7816
+#endif
7817
 {
7818
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
7819
+        struct pci_dev *pdev = to_pci_dev(device);
7820
+#endif
7821
         struct net_device *dev = pci_get_drvdata(pdev);
7822
         struct rtl8168_private *tp = netdev_priv(dev);
7823
-        unsigned long flags;
7824
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7825
         u32 pci_pm_state = PCI_D0;
7826
 #endif
7827
+        int err;
7828
+
7829
+        rtnl_lock();
7830
 
7831
-        pci_set_power_state(pdev, PCI_D0);
7832
+        err = pci_enable_device(pdev);
7833
+        if (err) {
7834
+                dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
7835
+                goto out_unlock;
7836
+        }
7837
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7838
         pci_restore_state(pdev, &pci_pm_state);
7839
 #else
7840
@@ -30173,26 +32086,18 @@
7841
 #endif
7842
         pci_enable_wake(pdev, PCI_D0, 0);
7843
 
7844
-        spin_lock_irqsave(&tp->lock, flags);
7845
-
7846
         /* restore last modified mac address */
7847
         rtl8168_rar_set(tp, dev->dev_addr);
7848
 
7849
-        spin_unlock_irqrestore(&tp->lock, flags);
7850
-
7851
         if (!netif_running(dev)) {
7852
                 if (HW_DASH_SUPPORT_DASH(tp)) {
7853
-                        spin_lock_irqsave(&tp->lock, flags);
7854
                         rtl8168_driver_start(tp);
7855
-                        spin_unlock_irqrestore(&tp->lock, flags);
7856
                 }
7857
-                goto out;
7858
+                goto out_unlock;
7859
         }
7860
 
7861
         pci_set_master(pdev);
7862
 
7863
-        spin_lock_irqsave(&tp->lock, flags);
7864
-
7865
         rtl8168_exit_oob(dev);
7866
 
7867
         rtl8168_dsm(dev, DSM_NIC_RESUME_D3);
7868
@@ -30207,18 +32112,43 @@
7869
 
7870
         rtl8168_hw_config(dev);
7871
 
7872
-        spin_unlock_irqrestore(&tp->lock, flags);
7873
+        clear_bit(R8168_FLAG_DOWN, tp->task_flags);
7874
+
7875
+        rtl8168_schedule_reset_work(tp);
7876
+
7877
+        rtl8168_schedule_esd_work(tp);
7878
 
7879
-        rtl8168_schedule_work(dev, rtl8168_reset_task);
7880
+        rtl8168_schedule_linkchg_work(tp);
7881
 
7882
+        //mod_timer(&tp->esd_timer, jiffies + RTL8168_ESD_TIMEOUT);
7883
+        //mod_timer(&tp->link_timer, jiffies + RTL8168_LINK_TIMEOUT);
7884
+out_unlock:
7885
         netif_device_attach(dev);
7886
 
7887
-        mod_timer(&tp->esd_timer, jiffies + RTL8168_ESD_TIMEOUT);
7888
-        mod_timer(&tp->link_timer, jiffies + RTL8168_LINK_TIMEOUT);
7889
-out:
7890
-        return 0;
7891
+        rtnl_unlock();
7892
+
7893
+        return err;
7894
 }
7895
 
7896
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
7897
+
7898
+static struct dev_pm_ops rtl8168_pm_ops = {
7899
+        .suspend = rtl8168_suspend,
7900
+        .resume = rtl8168_resume,
7901
+        .freeze = rtl8168_suspend,
7902
+        .thaw = rtl8168_resume,
7903
+        .poweroff = rtl8168_suspend,
7904
+        .restore = rtl8168_resume,
7905
+};
7906
+
7907
+#define RTL8168_PM_OPS (&rtl8168_pm_ops)
7908
+
7909
+#endif
7910
+
7911
+#else /* !CONFIG_PM */
7912
+
7913
+#define RTL8168_PM_OPS NULL
7914
+
7915
 #endif /* CONFIG_PM */
7916
 
7917
 static struct pci_driver rtl8168_pci_driver = {
7918
@@ -30230,9 +32160,13 @@
7919
         .shutdown   = rtl8168_shutdown,
7920
 #endif
7921
 #ifdef CONFIG_PM
7922
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
7923
         .suspend    = rtl8168_suspend,
7924
         .resume     = rtl8168_resume,
7925
+#else /* CONFIG_PM */
7926
+        .driver.pm  = RTL8168_PM_OPS,
7927
 #endif
7928
+#endif /* CONFIG_PM */
7929
 };
7930
 
7931
 static int __init
7932
r8168-8.051.02.tar.gz/src/r8168_realwow.h -> r8168-8.052.01.tar.gz/src/r8168_realwow.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.052.01.tar.gz/src/r8168_rss.c Added
441
 
1
@@ -0,0 +1,439 @@
2
+// SPDX-License-Identifier: GPL-2.0-only
3
+/*
4
+################################################################################
5
+#
6
+# r8168 is the Linux device driver released for Realtek Gigabit Ethernet
7
+# controllers with PCI-Express interface.
8
+#
9
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
10
+#
11
+# This program is free software; you can redistribute it and/or modify it
12
+# under the terms of the GNU General Public License as published by the Free
13
+# Software Foundation; either version 2 of the License, or (at your option)
14
+# any later version.
15
+#
16
+# This program is distributed in the hope that it will be useful, but WITHOUT
17
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
+# more details.
20
+#
21
+# You should have received a copy of the GNU General Public License along with
22
+# this program; if not, see <http://www.gnu.org/licenses/>.
23
+#
24
+# Author:
25
+# Realtek NIC software team <nicfae@realtek.com>
26
+# No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
27
+#
28
+################################################################################
29
+*/
30
+
31
+/************************************************************************************
32
+ *  This product is covered by one or more of the following patents:
33
+ *  US6,570,884, US6,115,776, and US6,327,625.
34
+ ***********************************************************************************/
35
+
36
+#include <linux/version.h>
37
+#include "r8168.h"
38
+
39
+enum rtl8168_rss_register_content {
40
+        /* RSS */
41
+        RSS_CTRL_TCP_IPV4_SUPP = (1 << 0),
42
+        RSS_CTRL_IPV4_SUPP  = (1 << 1),
43
+        RSS_CTRL_TCP_IPV6_SUPP  = (1 << 2),
44
+        RSS_CTRL_IPV6_SUPP  = (1 << 3),
45
+        RSS_CTRL_IPV6_EXT_SUPP  = (1 << 4),
46
+        RSS_CTRL_TCP_IPV6_EXT_SUPP  = (1 << 5),
47
+        RSS_HALF_SUPP  = (1 << 7),
48
+        RSS_QUAD_CPU_EN  = (1 << 16),
49
+        RSS_HQ_Q_SUP_R  = (1 << 31),
50
+};
51
+
52
+static int rtl8168_get_rss_hash_opts(struct rtl8168_private *tp,
53
+                                     struct ethtool_rxnfc *cmd)
54
+{
55
+        cmd->data = 0;
56
+
57
+        /* Report default options for RSS */
58
+        switch (cmd->flow_type) {
59
+        case TCP_V4_FLOW:
60
+                cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
61
+        /* fallthrough */
62
+        case IPV4_FLOW:
63
+                cmd->data |= RXH_IP_SRC | RXH_IP_DST;
64
+                break;
65
+        case TCP_V6_FLOW:
66
+                cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
67
+        /* fallthrough */
68
+        case IPV6_FLOW:
69
+                cmd->data |= RXH_IP_SRC | RXH_IP_DST;
70
+                break;
71
+        default:
72
+                return -EINVAL;
73
+        }
74
+
75
+        return 0;
76
+}
77
+
78
+int rtl8168_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
79
+                      u32 *rule_locs)
80
+{
81
+        struct rtl8168_private *tp = netdev_priv(dev);
82
+        int ret = -EOPNOTSUPP;
83
+
84
+        netif_info(tp, drv, tp->dev, "rss get rxnfc\n");
85
+
86
+        if (!(dev->features & NETIF_F_RXHASH))
87
+                return ret;
88
+
89
+        switch (cmd->cmd) {
90
+        case ETHTOOL_GRXRINGS:
91
+                cmd->data = rtl8168_tot_rx_rings(tp);
92
+                ret = 0;
93
+                break;
94
+        case ETHTOOL_GRXFH:
95
+                ret = rtl8168_get_rss_hash_opts(tp, cmd);
96
+                break;
97
+        default:
98
+                break;
99
+        }
100
+
101
+        return ret;
102
+}
103
+
104
+u32 rtl8168_rss_indir_tbl_entries(struct rtl8168_private *tp)
105
+{
106
+        return tp->HwSuppIndirTblEntries;
107
+}
108
+
109
+#define RSS_MASK_BITS_OFFSET (8)
110
+static int _rtl8168_set_rss_hash_opt(struct rtl8168_private *tp)
111
+{
112
+        u32 hash_mask_len;
113
+        u32 rss_ctrl;
114
+
115
+        /* Perform hash on these packet types */
116
+        rss_ctrl = RSS_CTRL_TCP_IPV4_SUPP
117
+                   | RSS_CTRL_IPV4_SUPP
118
+                   | RSS_CTRL_IPV6_SUPP
119
+                   | RSS_CTRL_IPV6_EXT_SUPP
120
+                   | RSS_CTRL_TCP_IPV6_SUPP
121
+                   | RSS_CTRL_TCP_IPV6_EXT_SUPP;
122
+
123
+        if (R8168_MULTI_RSS_4Q(tp))
124
+                rss_ctrl |= RSS_QUAD_CPU_EN;
125
+
126
+        hash_mask_len = ilog2(rtl8168_rss_indir_tbl_entries(tp));
127
+        hash_mask_len &= (BIT_0 | BIT_1 | BIT_2);
128
+        rss_ctrl |= hash_mask_len << RSS_MASK_BITS_OFFSET;
129
+
130
+        rtl8168_eri_write(tp, RSS_CTRL_8168, 4, rss_ctrl, ERIAR_ExGMAC);
131
+
132
+        return 0;
133
+}
134
+
135
+static int rtl8168_set_rss_hash_opt(struct rtl8168_private *tp,
136
+                                    struct ethtool_rxnfc *nfc)
137
+{
138
+        u32 rss_flags = tp->rss_flags;
139
+
140
+        netif_info(tp, drv, tp->dev, "rss set hash\n");
141
+
142
+        /*
143
+         * RSS does not support anything other than hashing
144
+         * to queues on src and dst IPs and ports
145
+         */
146
+        if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
147
+                          RXH_L4_B_0_1 | RXH_L4_B_2_3))
148
+                return -EINVAL;
149
+
150
+        switch (nfc->flow_type) {
151
+        case TCP_V4_FLOW:
152
+        case TCP_V6_FLOW:
153
+                if (!(nfc->data & RXH_IP_SRC) ||
154
+                    !(nfc->data & RXH_IP_DST) ||
155
+                    !(nfc->data & RXH_L4_B_0_1) ||
156
+                    !(nfc->data & RXH_L4_B_2_3))
157
+                        return -EINVAL;
158
+                break;
159
+        case SCTP_V4_FLOW:
160
+        case AH_ESP_V4_FLOW:
161
+        case AH_V4_FLOW:
162
+        case ESP_V4_FLOW:
163
+        case SCTP_V6_FLOW:
164
+        case AH_ESP_V6_FLOW:
165
+        case AH_V6_FLOW:
166
+        case ESP_V6_FLOW:
167
+        case IP_USER_FLOW:
168
+        case ETHER_FLOW:
169
+                /* RSS is not supported for these protocols */
170
+                if (nfc->data) {
171
+                        netif_err(tp, drv, tp->dev, "Command parameters not supported\n");
172
+                        return -EINVAL;
173
+                }
174
+                return 0;
175
+        default:
176
+                return -EINVAL;
177
+        }
178
+
179
+        /* if we changed something we need to update flags */
180
+        if (rss_flags != tp->rss_flags) {
181
+                u32 rss_ctrl = rtl8168_eri_read(tp, RSS_CTRL_8168, 4, ERIAR_ExGMAC);
182
+
183
+                tp->rss_flags = rss_flags;
184
+
185
+                /* Perform hash on these packet types */
186
+                rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
187
+                            | RSS_CTRL_IPV4_SUPP
188
+                            | RSS_CTRL_IPV6_SUPP
189
+                            | RSS_CTRL_IPV6_EXT_SUPP
190
+                            | RSS_CTRL_TCP_IPV6_SUPP
191
+                            | RSS_CTRL_TCP_IPV6_EXT_SUPP;
192
+
193
+                if (R8168_MULTI_RSS_4Q(tp))
194
+                        rss_ctrl |= RSS_QUAD_CPU_EN;
195
+                else
196
+                        rss_ctrl &= ~RSS_QUAD_CPU_EN;
197
+
198
+                rtl8168_eri_write(tp, RSS_CTRL_8168, 4, rss_ctrl, ERIAR_ExGMAC);
199
+        }
200
+
201
+        return 0;
202
+}
203
+
204
+int rtl8168_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
205
+{
206
+        struct rtl8168_private *tp = netdev_priv(dev);
207
+        int ret = -EOPNOTSUPP;
208
+
209
+        netif_info(tp, drv, tp->dev, "rss set rxnfc\n");
210
+
211
+        if (!(dev->features & NETIF_F_RXHASH))
212
+                return ret;
213
+
214
+        switch (cmd->cmd) {
215
+        case ETHTOOL_SRXFH:
216
+                ret = rtl8168_set_rss_hash_opt(tp, cmd);
217
+                break;
218
+        default:
219
+                break;
220
+        }
221
+
222
+        return ret;
223
+}
224
+
225
+static u32 _rtl8168_get_rxfh_key_size(struct rtl8168_private *tp)
226
+{
227
+        return sizeof(tp->rss_key);
228
+}
229
+
230
+u32 rtl8168_get_rxfh_key_size(struct net_device *dev)
231
+{
232
+        struct rtl8168_private *tp = netdev_priv(dev);
233
+
234
+        netif_info(tp, drv, tp->dev, "rss get key size\n");
235
+
236
+        if (!(dev->features & NETIF_F_RXHASH))
237
+                return 0;
238
+
239
+        return _rtl8168_get_rxfh_key_size(tp);
240
+}
241
+
242
+u32 rtl8168_rss_indir_size(struct net_device *dev)
243
+{
244
+        struct rtl8168_private *tp = netdev_priv(dev);
245
+
246
+        netif_info(tp, drv, tp->dev, "rss get indir tbl size\n");
247
+
248
+        if (!(dev->features & NETIF_F_RXHASH))
249
+                return 0;
250
+
251
+        return rtl8168_rss_indir_tbl_entries(tp);
252
+}
253
+
254
+static void rtl8168_get_reta(struct rtl8168_private *tp, u32 *indir)
255
+{
256
+        int i, reta_size = rtl8168_rss_indir_tbl_entries(tp);
257
+
258
+        for (i = 0; i < reta_size; i++)
259
+                indiri = tp->rss_indir_tbli;
260
+}
261
+
262
+int rtl8168_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
263
+                     u8 *hfunc)
264
+{
265
+        struct rtl8168_private *tp = netdev_priv(dev);
266
+
267
+        netif_info(tp, drv, tp->dev, "rss get rxfh\n");
268
+
269
+        if (!(dev->features & NETIF_F_RXHASH))
270
+                return -EOPNOTSUPP;
271
+
272
+        if (hfunc)
273
+                *hfunc = ETH_RSS_HASH_TOP;
274
+
275
+        if (indir)
276
+                rtl8168_get_reta(tp, indir);
277
+
278
+        if (key)
279
+                memcpy(key, tp->rss_key, RTL8168_RSS_KEY_SIZE);
280
+
281
+        return 0;
282
+}
283
+
284
+static u32 rtl8168_rss_key_reg(struct rtl8168_private *tp)
285
+{
286
+        return RSS_KEY_8168;
287
+}
288
+
289
+static u32 rtl8168_rss_indir_tbl_reg(struct rtl8168_private *tp)
290
+{
291
+        return Rss_indir_tbl;
292
+}
293
+
294
+static void rtl8168_store_reta(struct rtl8168_private *tp)
295
+{
296
+        u32 reta_entries = rtl8168_rss_indir_tbl_entries(tp);
297
+        u16 indir_tbl_reg = rtl8168_rss_indir_tbl_reg(tp);
298
+        u32 hw_indirRTL8168_RSS_INDIR_TBL_SIZE = {0};
299
+        u8 *indir = tp->rss_indir_tbl;
300
+        u32 bit_on_cnt = 0x00000001;
301
+        u32 i, j;
302
+
303
+        /* Mapping redirection table to HW */
304
+        for (i = 0, j = 0; i < reta_entries; i++) {
305
+                if ((indiri & 2) && R8168_MULTI_RSS_4Q(tp))
306
+                        hw_indirj + 4 |= bit_on_cnt;
307
+                if (indiri & 1)
308
+                        hw_indirj |= bit_on_cnt;
309
+
310
+                if (bit_on_cnt == 0x80000000) {
311
+                        bit_on_cnt = 0x00000001;
312
+                        j++;
313
+                        continue;
314
+                }
315
+                bit_on_cnt <<= 1;
316
+        }
317
+
318
+        /* Write redirection table to HW */
319
+        for (i = 0; i < RTL8168_RSS_INDIR_TBL_SIZE; i++)
320
+                RTL_W32(tp, indir_tbl_reg + i*4, hw_indiri);
321
+}
322
+
323
+static void rtl8168_store_rss_key(struct rtl8168_private *tp)
324
+{
325
+        const u16 rss_key_reg = rtl8168_rss_key_reg(tp);
326
+        u32 i, rss_key_size = _rtl8168_get_rxfh_key_size(tp);
327
+        u32 *rss_key = (u32*)tp->rss_key;
328
+
329
+        /* Write redirection table to HW */
330
+        for (i = 0; i < rss_key_size; i+=4)
331
+                rtl8168_eri_write(tp, rss_key_reg + i, 4, *rss_key++, ERIAR_ExGMAC);
332
+}
333
+
334
+int rtl8168_set_rxfh(struct net_device *dev, const u32 *indir,
335
+                     const u8 *key, const u8 hfunc)
336
+{
337
+        struct rtl8168_private *tp = netdev_priv(dev);
338
+        u32 reta_entries = rtl8168_rss_indir_tbl_entries(tp);
339
+        int i;
340
+
341
+        netif_info(tp, drv, tp->dev, "rss set rxfh\n");
342
+
343
+        /* We require at least one supported parameter to be changed and no
344
+         * change in any of the unsupported parameters
345
+         */
346
+        if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
347
+                return -EOPNOTSUPP;
348
+
349
+        /* Fill out the redirection table */
350
+        if (indir) {
351
+                int max_queues = tp->num_rx_rings;
352
+
353
+                /* Verify user input. */
354
+                for (i = 0; i < reta_entries; i++)
355
+                        if (indiri >= max_queues)
356
+                                return -EINVAL;
357
+
358
+                for (i = 0; i < reta_entries; i++)
359
+                        tp->rss_indir_tbli = indiri;
360
+        }
361
+
362
+        /* Fill out the rss hash key */
363
+        if (key)
364
+                memcpy(tp->rss_key, key, RTL8168_RSS_KEY_SIZE);
365
+
366
+        rtl8168_store_reta(tp);
367
+
368
+        rtl8168_store_rss_key(tp);
369
+
370
+        return 0;
371
+}
372
+
373
+static u32 rtl8168_get_rx_desc_hash(struct rtl8168_private *tp,
374
+                                    struct RxDescV2 *desc)
375
+{
376
+        if (!desc->RSSResult)
377
+                udelay(1);
378
+        return le32_to_cpu(desc->RSSResult);
379
+}
380
+
381
+#define RXS_8168_RSS_IPV4 BIT(17)
382
+#define RXS_8168_RSS_IPV6 BIT(18)
383
+#define RXS_8168_RSS_TCP BIT(19)
384
+#define RTL8168_RXS_RSS_L3_TYPE_MASK (RXS_8168_RSS_IPV4 | RXS_8168_RSS_IPV6)
385
+#define RTL8168_RXS_RSS_L4_TYPE_MASK (RXS_8168_RSS_TCP)
386
+void rtl8168_rx_hash(struct rtl8168_private *tp,
387
+                     struct RxDescV2 *desc,
388
+                     struct sk_buff *skb)
389
+{
390
+        u32 rss_header_info;
391
+
392
+        if (!(tp->dev->features & NETIF_F_RXHASH))
393
+                return;
394
+
395
+        rss_header_info = le32_to_cpu(desc->opts2);
396
+
397
+        if (!(rss_header_info & RTL8168_RXS_RSS_L3_TYPE_MASK))
398
+                return;
399
+
400
+        skb_set_hash(skb, rtl8168_get_rx_desc_hash(tp, desc),
401
+                     (RTL8168_RXS_RSS_L4_TYPE_MASK & rss_header_info) ?
402
+                     PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
403
+}
404
+
405
+void rtl8168_disable_rss(struct rtl8168_private *tp)
406
+{
407
+        rtl8168_eri_write(tp, RSS_CTRL_8168, 4, 0x00000000, ERIAR_ExGMAC);
408
+}
409
+
410
+void _rtl8168_config_rss(struct rtl8168_private *tp)
411
+{
412
+        _rtl8168_set_rss_hash_opt(tp);
413
+
414
+        rtl8168_store_reta(tp);
415
+
416
+        rtl8168_store_rss_key(tp);
417
+}
418
+
419
+void rtl8168_config_rss(struct rtl8168_private *tp)
420
+{
421
+        if (!HW_RSS_SUPPORT_RSS(tp))
422
+                return;
423
+
424
+        if (!tp->EnableRss) {
425
+                rtl8168_disable_rss(tp);
426
+                return;
427
+        }
428
+
429
+        _rtl8168_config_rss(tp);
430
+}
431
+
432
+void rtl8168_init_rss(struct rtl8168_private *tp)
433
+{
434
+        int i;
435
+
436
+        for (i = 0; i < rtl8168_rss_indir_tbl_entries(tp); i++)
437
+                tp->rss_indir_tbli = ethtool_rxfh_indir_default(i, tp->num_rx_rings);
438
+
439
+        netdev_rss_key_fill(tp->rss_key, RTL8168_RSS_KEY_SIZE);
440
+}
441
r8168-8.052.01.tar.gz/src/r8168_rss.h Added
68
 
1
@@ -0,0 +1,66 @@
2
+/* SPDX-License-Identifier: GPL-2.0-only */
3
+/*
4
+################################################################################
5
+#
6
+# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
7
+# controllers with PCI-Express interface.
8
+#
9
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
10
+#
11
+# This program is free software; you can redistribute it and/or modify it
12
+# under the terms of the GNU General Public License as published by the Free
13
+# Software Foundation; either version 2 of the License, or (at your option)
14
+# any later version.
15
+#
16
+# This program is distributed in the hope that it will be useful, but WITHOUT
17
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
+# more details.
20
+#
21
+# You should have received a copy of the GNU General Public License along with
22
+# this program; if not, see <http://www.gnu.org/licenses/>.
23
+#
24
+# Author:
25
+# Realtek NIC software team <nicfae@realtek.com>
26
+# No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
27
+#
28
+################################################################################
29
+*/
30
+
31
+/************************************************************************************
32
+ *  This product is covered by one or more of the following patents:
33
+ *  US6,570,884, US6,115,776, and US6,327,625.
34
+ ***********************************************************************************/
35
+
36
+#ifndef _LINUX_RTL8168_RSS_H
37
+#define _LINUX_RTL8168_RSS_H
38
+
39
+#include <linux/netdevice.h>
40
+#include <linux/types.h>
41
+
42
+#define RTL8168_RSS_INDIR_TBL_SIZE 8
43
+#define RTL8168_RSS_KEY_SIZE     40  /* size of RSS Hash Key in bytes */
44
+#define RTL8168_MAX_INDIRECTION_TABLE_ENTRIES 128
45
+
46
+struct rtl8168_private;
47
+struct RxDescV2;
48
+
49
+int rtl8168_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
50
+                      u32 *rule_locs);
51
+int rtl8168_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
52
+u32 rtl8168_get_rxfh_key_size(struct net_device *netdev);
53
+u32 rtl8168_rss_indir_size(struct net_device *netdev);
54
+int rtl8168_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
55
+                     u8 *hfunc);
56
+int rtl8168_set_rxfh(struct net_device *netdev, const u32 *indir,
57
+                     const u8 *key, const u8 hfunc);
58
+void rtl8168_rx_hash(struct rtl8168_private *tp,
59
+                     struct RxDescV2 *desc,
60
+                     struct sk_buff *skb);
61
+void _rtl8168_config_rss(struct rtl8168_private *tp);
62
+void rtl8168_config_rss(struct rtl8168_private *tp);
63
+void rtl8168_init_rss(struct rtl8168_private *tp);
64
+u32 rtl8168_rss_indir_tbl_entries(struct rtl8168_private *tp);
65
+void rtl8168_disable_rss(struct rtl8168_private *tp);
66
+
67
+#endif /* _LINUX_RTL8168_RSS_H */
68
r8168-8.051.02.tar.gz/src/rtl_eeprom.c -> r8168-8.052.01.tar.gz/src/rtl_eeprom.c Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/rtl_eeprom.h -> r8168-8.052.01.tar.gz/src/rtl_eeprom.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168-8.051.02.tar.gz/src/rtltool.c -> r8168-8.052.01.tar.gz/src/rtltool.c Changed
216
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
@@ -47,7 +47,6 @@
11
 int rtl8168_tool_ioctl(struct rtl8168_private *tp, struct ifreq *ifr)
12
 {
13
         struct rtltool_cmd my_cmd;
14
-        unsigned long flags;
15
         int ret;
16
 
17
         if (copy_from_user(&my_cmd, ifr->ifr_data, sizeof(my_cmd)))
18
@@ -72,7 +71,6 @@
19
                         break;
20
                 }
21
                 break;
22
-
23
         case RTLTOOL_WRITE_MAC:
24
                 if (my_cmd.len==1)
25
                         writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
26
@@ -84,51 +82,31 @@
27
                         ret = -EOPNOTSUPP;
28
                         break;
29
                 }
30
-
31
                 break;
32
-
33
         case RTLTOOL_READ_PHY:
34
-                spin_lock_irqsave(&tp->lock, flags);
35
                 my_cmd.data = rtl8168_mdio_prot_read(tp, my_cmd.offset);
36
-                spin_unlock_irqrestore(&tp->lock, flags);
37
-
38
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
39
                         ret = -EFAULT;
40
                         break;
41
                 }
42
-
43
                 break;
44
-
45
         case RTLTOOL_WRITE_PHY:
46
-                spin_lock_irqsave(&tp->lock, flags);
47
                 rtl8168_mdio_prot_write(tp, my_cmd.offset, my_cmd.data);
48
-                spin_unlock_irqrestore(&tp->lock, flags);
49
                 break;
50
-
51
         case RTLTOOL_READ_EPHY:
52
-                spin_lock_irqsave(&tp->lock, flags);
53
                 my_cmd.data = rtl8168_ephy_read(tp, my_cmd.offset);
54
-                spin_unlock_irqrestore(&tp->lock, flags);
55
-
56
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
57
                         ret = -EFAULT;
58
                         break;
59
                 }
60
-
61
                 break;
62
-
63
         case RTLTOOL_WRITE_EPHY:
64
-                spin_lock_irqsave(&tp->lock, flags);
65
                 rtl8168_ephy_write(tp, my_cmd.offset, my_cmd.data);
66
-                spin_unlock_irqrestore(&tp->lock, flags);
67
                 break;
68
-
69
         case RTLTOOL_READ_ERI:
70
                 my_cmd.data = 0;
71
                 if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
72
-                        spin_lock_irqsave(&tp->lock, flags);
73
                         my_cmd.data = rtl8168_eri_read(tp, my_cmd.offset, my_cmd.len, ERIAR_ExGMAC);
74
-                        spin_unlock_irqrestore(&tp->lock, flags);
75
                 } else {
76
                         ret = -EOPNOTSUPP;
77
                         break;
78
@@ -138,20 +116,15 @@
79
                         ret = -EFAULT;
80
                         break;
81
                 }
82
-
83
                 break;
84
-
85
         case RTLTOOL_WRITE_ERI:
86
                 if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
87
-                        spin_lock_irqsave(&tp->lock, flags);
88
                         rtl8168_eri_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data, ERIAR_ExGMAC);
89
-                        spin_unlock_irqrestore(&tp->lock, flags);
90
                 } else {
91
                         ret = -EOPNOTSUPP;
92
                         break;
93
                 }
94
                 break;
95
-
96
         case RTLTOOL_READ_PCI:
97
                 my_cmd.data = 0;
98
                 if (my_cmd.len==1)
99
@@ -173,7 +146,6 @@
100
                         break;
101
                 }
102
                 break;
103
-
104
         case RTLTOOL_WRITE_PCI:
105
                 if (my_cmd.len==1)
106
                         pci_write_config_byte(tp->pci_dev, my_cmd.offset,
107
@@ -188,108 +160,69 @@
108
                         ret = -EOPNOTSUPP;
109
                         break;
110
                 }
111
-
112
                 break;
113
-
114
         case RTLTOOL_READ_EEPROM:
115
-                spin_lock_irqsave(&tp->lock, flags);
116
                 my_cmd.data = rtl8168_eeprom_read_sc(tp, my_cmd.offset);
117
-                spin_unlock_irqrestore(&tp->lock, flags);
118
-
119
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
120
                         ret = -EFAULT;
121
                         break;
122
                 }
123
-
124
                 break;
125
-
126
         case RTLTOOL_WRITE_EEPROM:
127
-                spin_lock_irqsave(&tp->lock, flags);
128
                 rtl8168_eeprom_write_sc(tp, my_cmd.offset, my_cmd.data);
129
-                spin_unlock_irqrestore(&tp->lock, flags);
130
                 break;
131
-
132
         case RTL_READ_OOB_MAC:
133
-                spin_lock_irqsave(&tp->lock, flags);
134
                 rtl8168_oob_mutex_lock(tp);
135
                 my_cmd.data = rtl8168_ocp_read(tp, my_cmd.offset, 4);
136
                 rtl8168_oob_mutex_unlock(tp);
137
-                spin_unlock_irqrestore(&tp->lock, flags);
138
 
139
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
140
                         ret = -EFAULT;
141
                         break;
142
                 }
143
                 break;
144
-
145
         case RTL_WRITE_OOB_MAC:
146
                 if (my_cmd.len == 0 || my_cmd.len > 4)
147
                         return -EOPNOTSUPP;
148
 
149
-                spin_lock_irqsave(&tp->lock, flags);
150
                 rtl8168_oob_mutex_lock(tp);
151
                 rtl8168_ocp_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data);
152
                 rtl8168_oob_mutex_unlock(tp);
153
-                spin_unlock_irqrestore(&tp->lock, flags);
154
                 break;
155
-
156
         case RTL_ENABLE_PCI_DIAG:
157
-                spin_lock_irqsave(&tp->lock, flags);
158
                 tp->rtk_enable_diag = 1;
159
-                spin_unlock_irqrestore(&tp->lock, flags);
160
-
161
                 dprintk("enable rtk diag\n");
162
                 break;
163
-
164
         case RTL_DISABLE_PCI_DIAG:
165
-                spin_lock_irqsave(&tp->lock, flags);
166
                 tp->rtk_enable_diag = 0;
167
-                spin_unlock_irqrestore(&tp->lock, flags);
168
-
169
                 dprintk("disable rtk diag\n");
170
                 break;
171
-
172
         case RTL_READ_MAC_OCP:
173
                 if (my_cmd.offset % 2)
174
                         return -EOPNOTSUPP;
175
 
176
-                spin_lock_irqsave(&tp->lock, flags);
177
                 my_cmd.data = rtl8168_mac_ocp_read(tp, my_cmd.offset);
178
-                spin_unlock_irqrestore(&tp->lock, flags);
179
-
180
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
181
                         ret = -EFAULT;
182
                         break;
183
                 }
184
                 break;
185
-
186
         case RTL_WRITE_MAC_OCP:
187
                 if ((my_cmd.offset % 2) || (my_cmd.len != 2))
188
                         return -EOPNOTSUPP;
189
 
190
-                spin_lock_irqsave(&tp->lock, flags);
191
                 rtl8168_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data);
192
-                spin_unlock_irqrestore(&tp->lock, flags);
193
                 break;
194
-
195
         case RTL_DIRECT_READ_PHY_OCP:
196
-                spin_lock_irqsave(&tp->lock, flags);
197
                 my_cmd.data = rtl8168_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset);
198
-                spin_unlock_irqrestore(&tp->lock, flags);
199
-
200
                 if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
201
                         ret = -EFAULT;
202
                         break;
203
                 }
204
-
205
                 break;
206
-
207
         case RTL_DIRECT_WRITE_PHY_OCP:
208
-                spin_lock_irqsave(&tp->lock, flags);
209
                 rtl8168_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data);
210
-                spin_unlock_irqrestore(&tp->lock, flags);
211
                 break;
212
-
213
         default:
214
                 ret = -EOPNOTSUPP;
215
                 break;
216
r8168-8.051.02.tar.gz/src/rtltool.h -> r8168-8.052.01.tar.gz/src/rtltool.h Changed
10
 
1
@@ -5,7 +5,7 @@
2
 # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
3
 # controllers with PCI-Express interface.
4
 #
5
-# Copyright(c) 2022 Realtek Semiconductor Corp. All rights reserved.
6
+# Copyright(c) 2023 Realtek Semiconductor Corp. All rights reserved.
7
 #
8
 # This program is free software; you can redistribute it and/or modify it
9
 # under the terms of the GNU General Public License as published by the Free
10
r8168.keyring Added
21
 
1
@@ -0,0 +1,19 @@
2
+-----BEGIN PGP PUBLIC KEY BLOCK-----
3
+
4
+mDMEWjorXBYJKwYBBAHaRw8BAQdAjGKRKfCsgqRDija1BdhFQyhl7v8ooFB9n0+B
5
+fFFwIUq0N01hc3NpbWlsaWFubyBUb3Jyb21lbyA8bWFzc2ltaWxpYW5vLnRvcnJv
6
+bWVvQGdtYWlsLmNvbT6I0AQTFggAeAIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIX
7
+gAUJEJ7XDhYhBAytqs9w9kxlThMbMRFnXHQ0Kd3vBQJjhKA5ORSAAAAAABAAIHBy
8
+b29mQGFyaWFkbmUuaWRodHRwczovL2Zvc3N0b2Rvbi5vcmcvQG10b3Jyb21lbwAK
9
+CRARZ1x0NCnd74sYAP9cd+GQFHYUdC8h5rinC8zlLfCSRmK4RmpynORvNUoHlwD/
10
+VHc1QKQygGJHkGUR/BzBwhvy9V8VFUXLHEkix/5EAgy4MwRaOiyTFgkrBgEEAdpH
11
+DwEBB0ALDo3UpmTEMnSfibzebWay/yHw5PQ3M6dikohuznLdD4h+BBgWCAAmAhsg
12
+FiEEDK2qz3D2TGVOExsxEWdcdDQp3e8FAmFzE3sFCRCe6GgACgkQEWdcdDQp3e+l
13
+MgEAqNJOWIvlmwvgDUnM49o9Xy+ev0ApfCcpd+M9Viv3HmwA/RFNVLW5Q3ClhUPd
14
+RHRSgOI/txQSMCX24h1R4g5Ck3kPuDgEWjorXBIKKwYBBAGXVQEFAQEHQG8U6zt8
15
+dY35U3jMoulSJrEfc2IawNGNum7hdNwGarUhAwEIB4h+BBgWCAAmAhsMFiEEDK2q
16
+z3D2TGVOExsxEWdcdDQp3e8FAmFzE3sFCRCe6Z8ACgkQEWdcdDQp3e/FnQD/ROjp
17
+SAtLo4A2PbQ9Awk4V/dW2iSGXT+c946xwd6v+toA/R3VhNaxQpVjqpwLYYhV2T+E
18
+8i1/tU0JWRZh4/DUvY0P
19
+=mnMt
20
+-----END PGP PUBLIC KEY BLOCK-----
21
Refresh
============================ rpmlint session starts ============================
rpmlint: 2.6.1
configuration:
/opt/testing/lib64/python3.13/rpmlint/configdefaults.toml
/opt/testing/share/rpmlint/cron-whitelist.toml
/opt/testing/share/rpmlint/dbus-services.toml
/opt/testing/share/rpmlint/device-files-whitelist.toml
/opt/testing/share/rpmlint/licenses.toml
/opt/testing/share/rpmlint/opensuse.toml
/opt/testing/share/rpmlint/pam-modules.toml
/opt/testing/share/rpmlint/permissions-whitelist.toml
/opt/testing/share/rpmlint/pie-executables.toml
/opt/testing/share/rpmlint/polkit-rules-whitelist.toml
/opt/testing/share/rpmlint/scoring.toml
/opt/testing/share/rpmlint/security.toml
/opt/testing/share/rpmlint/sudoers-whitelist.toml
/opt/testing/share/rpmlint/sysctl-whitelist.toml
/opt/testing/share/rpmlint/systemd-tmpfiles.toml
/opt/testing/share/rpmlint/users-groups.toml
/opt/testing/share/rpmlint/world-writable-whitelist.toml
/opt/testing/share/rpmlint/zypper-plugins.toml
checks: 41, packages: 3

r8168-kmp-default.x86_64: E: suse-zypp-packageand packageand(kernel-default:r8168)
The 'packageand(package1:package2)' syntax is obsolete, please use boolean
dependencies like: 'Supplements: (package1 and package2)'

r8168.spec: W: no-%check-section
The spec file does not contain an %check section. Please check if the package
has a testsuite and what it takes to enable the testsuite as part of the
package build. If it is not possible to run it in the build environment
(OBS/koji) or no testsuite exists, then please ignore this warning. You should
not insert an empty %check section.

Check time report (&gt;1% &amp; &gt;0.1s):
Check                            Duration (in s)   Fraction (in %)  Checked files
ExtractRpm                                   0.3              86.9
TOTAL                                        0.4             100.0

3 packages and 0 specfiles checked; 1 errors, 1 warnings, 15 filtered, 1 badness; has taken 0.4 s
Request History
bitstreamout's avatar

bitstreamout created request about 1 year ago

- Update to new version r8168-8.052.01
- Remove patches now upstream
* skb_gso_segment.patch
* r8168-support-linux-6.1.0.patch
- Port patches
* r8168-configuration.patch
* r8168-kernel_version.patch
* r8168-support-dev0x8136.patch
* r8168-support-linux-5.19.patch
* r8168-support-linux-L15.5.patch
- Add r8168.keyring and signature of tar ball to check tar ball
- Add patch r8168-gcc14.patch
* Avoid gcc14 trouble
* Switch from deprecated strlcpy() to strscpy()

- Use %patch -P N instead of deprecated %patchN.


bitstreamout's avatar

bitstreamout accepted request about 1 year ago

Fine