Skip to content

Commit

Permalink
Update Realtek r8152 driver to 2.18.1
Browse files Browse the repository at this point in the history
This closes PR #24
  • Loading branch information
wenzhuoz authored and awesometic committed Oct 1, 2024
1 parent 97c39ff commit 554d0aa
Show file tree
Hide file tree
Showing 6 changed files with 9,406 additions and 4,953 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ GPL-2 on Realtek driver and the debian packaing.

## References

- [Realtek r8152 driver release page](https://www.realtek.com/en/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-usb-3-0-software)
- [Realtek r8152 driver downloads](https://www.realtek.com/Download/List?cate_id=585)
3 changes: 3 additions & 0 deletions REALTEK_README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
2.5G for kernel v4.10 and later
# ethtool -s eth0 autoneg on advertise 0x80000000002f

5G for kernel v4.10 and later (Couldn't be supported before kernel v4.10)
# ethtool -s eth0 autoneg on advertise 0x180000000002f

# ethtool -s eth0 autoneg on advertise 0x002f (1G)
# ethtool -s eth0 autoneg on advertise 0x000f (100M full)
# ethtool -s eth0 autoneg on advertise 0x0003 (10M full)
Expand Down
8 changes: 8 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ ifneq ($(KERNELRELEASE),)
obj-m := r8152.o
# EXTRA_CFLAGS += -DRTL8152_S5_WOL
# EXTRA_CFLAGS += -DRTL8152_DEBUG

ifneq (,$(filter OFF off, $(CONFIG_CTAP_SHORT)))
EXTRA_CFLAGS += -DCONFIG_CTAP_SHORT_OFF
endif

ifeq (TRUE, $(shell test $(VERSION) -lt 5 && echo "TRUE" || \
test $(VERSION) -eq 5 && test $(PATCHLEVEL) -lt 12 && echo "TRUE"))
EXTRA_CFLAGS += -DLINUX_VERSION_MAJOR=$(VERSION)
EXTRA_CFLAGS += -DLINUX_VERSION_PATCHLEVEL=$(PATCHLEVEL)
EXTRA_CFLAGS += -DLINUX_VERSION_SUBLEVEL=$(SUBLEVEL)
endif
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
Expand Down
55 changes: 37 additions & 18 deletions src/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#define TSO_LEGACY_MAX_SIZE 65536
#define netif_napi_add_weight netif_napi_add
#define netif_set_tso_max_size netif_set_gso_max_size
#define netif_set_tso_max_segs netif_set_gso_max_segs
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0)
#define PHY_MAC_INTERRUPT PHY_IGNORE_INTERRUPT
Expand Down Expand Up @@ -65,15 +67,19 @@
# define fallthrough do {} while (0) /* fallthrough */
#endif

#define MDIO_EEE_2_5GT 0x0001 /* 2.5GT EEE cap */
#define MDIO_EEE_2_5GT 0x0001 /* 2.5GT EEE cap */
#define MDIO_EEE_5GT 0x0002 /* 5GT EEE cap */
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0)
#define MDIO_AN_10GBT_CTRL_ADV2_5G 0x0080 /* Advertise 2.5GBASE-T */
#define MDIO_AN_10GBT_STAT_LP2_5G 0x0020 /* LP is 2.5GBT capable */
#define MDIO_AN_10GBT_CTRL_ADV2_5G 0x0080 /* Advertise 2.5GBASE-T */
#define MDIO_AN_10GBT_CTRL_ADV5G 0x0100 /* Advertise 5GBASE-T */
#define MDIO_AN_10GBT_STAT_LP2_5G 0x0020 /* LP is 2.5GBT capable */
#define MDIO_AN_10GBT_STAT_LP5G 0x0040 /* LP is 5GBT capable */
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0)
#define SPEED_2500 2500
#define SPEED_5000 5000
#define SPEED_25000 25000
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
#ifndef ETHTOOL_LINK_MODE_2500baseT_Full_BIT
Expand Down Expand Up @@ -357,7 +363,7 @@
static inline void netif_napi_del(struct napi_struct *napi)
{
#ifdef CONFIG_NETPOLL
list_del(&napi->dev_list);
list_del(&napi->dev_list);
#endif
}
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) */
Expand Down Expand Up @@ -473,21 +479,21 @@
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) */
static inline __be16 vlan_get_protocol(const struct sk_buff *skb)
{
__be16 protocol = 0;

if (vlan_tx_tag_present(skb) ||
skb->protocol != cpu_to_be16(ETH_P_8021Q))
protocol = skb->protocol;
else {
__be16 proto, *protop;
protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr,
h_vlan_encapsulated_proto),
sizeof(proto), &proto);
if (likely(protop))
protocol = *protop;
}
__be16 protocol = 0;

if (vlan_tx_tag_present(skb) ||
skb->protocol != cpu_to_be16(ETH_P_8021Q))
protocol = skb->protocol;
else {
__be16 proto, *protop;
protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr,
h_vlan_encapsulated_proto),
sizeof(proto), &proto);
if (likely(protop))
protocol = *protop;
}

return protocol;
return protocol;
}
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) */
Expand Down Expand Up @@ -620,11 +626,24 @@
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0) */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,10,188) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0)
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0)
#if LINUX_VERSION_MAJOR != 4 || LINUX_VERSION_PATCHLEVEL != 19 || LINUX_VERSION_SUBLEVEL < 291
static inline void eth_hw_addr_set(struct net_device *dev, const u8 *addr)
{
memcpy(dev->dev_addr, addr, 6);
}
#endif /* LINUX_VERSION_MAJOR != 4 || LINUX_VERSION_PATCHLEVEL != 19 || LINUX_VERSION_SUBLEVEL < 291 */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) */
#endif /*LINUX_VERSION_CODE < KERNEL_VERSION(5,10,188) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) */
static inline void netif_set_gso_max_segs(struct net_device *dev,
unsigned int segs)
{
/* dev->gso_max_segs is read locklessly from sk_setup_caps() */
WRITE_ONCE(dev->gso_max_segs, segs);
}
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0) */
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0) */

#ifndef FALSE
Expand Down
Loading

0 comments on commit 554d0aa

Please sign in to comment.