├── 50-usb-realtek-net.rules ├── Makefile ├── ReadMe.txt ├── compatibility.h └── r8152.c /50-usb-realtek-net.rules: -------------------------------------------------------------------------------- 1 | # This is used to change the default configuration of Realtek USB ethernet adapters 2 | 3 | ACTION!="add", GOTO="usb_realtek_net_end" 4 | SUBSYSTEM!="usb", GOTO="usb_realtek_net_end" 5 | ENV{DEVTYPE}!="usb_device", GOTO="usb_realtek_net_end" 6 | 7 | # Modify this to change the default value 8 | ENV{REALTEK_MODE1}="1" 9 | ENV{REALTEK_MODE2}="3" 10 | 11 | # Realtek 12 | ATTR{idVendor}=="0bda", ATTR{idProduct}=="815[2,3,5,6,7,a]", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 13 | ATTR{idVendor}=="0bda", ATTR{idProduct}=="8053", ATTR{bcdDevice}=="e???", ATTR{bConfigurationValue}!="$env{REALTEK_MODE2}", ATTR{bConfigurationValue}="$env{REALTEK_MODE2}" 14 | 15 | # Samsung 16 | ATTR{idVendor}=="04e8", ATTR{idProduct}=="a101", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 17 | 18 | # Lenovo 19 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="304f", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 20 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3052", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 21 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3054", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 22 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3057", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 23 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3062", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 24 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3069", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 25 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3082", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 26 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="3098", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 27 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="7205", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 28 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="720a", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 29 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="720b", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 30 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="720c", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 31 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="7214", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 32 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="721e", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 33 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="8153", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 34 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="a359", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 35 | ATTR{idVendor}=="17ef", ATTR{idProduct}=="a387", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 36 | 37 | # TP-LINK 38 | ATTR{idVendor}=="2357", ATTR{idProduct}=="0601", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 39 | 40 | # Nvidia 41 | ATTR{idVendor}=="0955", ATTR{idProduct}=="09ff", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 42 | 43 | # LINKSYS 44 | ATTR{idVendor}=="13b1", ATTR{idProduct}=="0041", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 45 | 46 | # ASUS 47 | ATTR{idVendor}=="0b05", ATTR{idProduct}=="1976", ATTR{bConfigurationValue}!="$env{REALTEK_MODE1}", ATTR{bConfigurationValue}="$env{REALTEK_MODE1}" 48 | 49 | LABEL="usb_realtek_net_end" 50 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # 4 | 5 | CONFIG_CTAP_SHORT = ON 6 | 7 | ifneq ($(KERNELRELEASE),) 8 | obj-m := r8152.o 9 | # ccflags-y += -DRTL8152_S5_WOL 10 | # ccflags-y += -DRTL8152_DEBUG 11 | 12 | ifneq (,$(filter OFF off, $(CONFIG_CTAP_SHORT))) 13 | ccflags-y += -DCONFIG_CTAP_SHORT_OFF 14 | endif 15 | 16 | ifeq (TRUE, $(shell test $(VERSION) -lt 5 && echo "TRUE" || \ 17 | test $(VERSION) -eq 5 && test $(PATCHLEVEL) -lt 12 && echo "TRUE")) 18 | ccflags-y += -DLINUX_VERSION_MAJOR=$(VERSION) 19 | ccflags-y += -DLINUX_VERSION_PATCHLEVEL=$(PATCHLEVEL) 20 | ccflags-y += -DLINUX_VERSION_SUBLEVEL=$(SUBLEVEL) 21 | endif 22 | else 23 | KERNELDIR ?= /lib/modules/$(shell uname -r)/build 24 | PWD :=$(shell pwd) 25 | TARGET_PATH := kernel/drivers/net/usb 26 | INBOXDRIVER := $(shell find $(subst build,$(TARGET_PATH),$(KERNELDIR)) -name r8152.ko.* -type f) 27 | RULEFILE = 50-usb-realtek-net.rules 28 | RULEDIR = /etc/udev/rules.d/ 29 | 30 | .PHONY: modules 31 | modules: 32 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules 33 | 34 | .PHONY: all 35 | all: clean modules install 36 | 37 | .PHONY: clean 38 | clean: 39 | $(MAKE) -C $(KERNELDIR) M=$(PWD) clean 40 | 41 | .PHONY: install 42 | install: 43 | ifneq ($(shell lsmod | grep r8153_ecm),) 44 | rmmod r8153_ecm 45 | endif 46 | ifneq ($(shell lsmod | grep r8152),) 47 | rmmod r8152 48 | endif 49 | ifneq ($(INBOXDRIVER),) 50 | rm -f $(INBOXDRIVER) 51 | endif 52 | $(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(TARGET_PATH) modules_install 53 | modprobe r8152 54 | 55 | .PHONY: install_rules 56 | install_rules: 57 | install --group=root --owner=root --mode=0644 $(RULEFILE) $(RULEDIR) 58 | 59 | endif 60 | 61 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | - If you want to support S5 WOL, you have to find 2 | 3 | EXTRA_CFLAGS += -DRTL8152_S5_WOL 4 | 5 | in the Makefile. Then, remove the first character '#", if it exists. 6 | 7 | 8 | - For Fedora, you may have to run the following command after installing the 9 | driver. 10 | 11 | # dracut -f 12 | 13 | - For Ubuntu, you may have to run the following command after installing the 14 | driver. 15 | 16 | # sudo depmod -a 17 | # sudo update-initramfs -u 18 | 19 | - Example of setting speed 20 | 21 | 2.5G before kernel v4.10 22 | # ethtool -s eth0 autoneg on advertise 0x802f 23 | 24 | 2.5G for kernel v4.10 and later 25 | # ethtool -s eth0 autoneg on advertise 0x80000000002f 26 | 27 | 5G for kernel v4.10 and later (Couldn't be supported before kernel v4.10) 28 | # ethtool -s eth0 autoneg on advertise 0x180000000002f 29 | 30 | 10G for kernel v4.10 and later (Couldn't be supported before kernel v4.10) 31 | # ethtool -s eth0 autoneg on advertise 0x180000000102f 32 | 33 | # ethtool -s eth0 autoneg on advertise 0x002f (1G) 34 | # ethtool -s eth0 autoneg on advertise 0x000f (100M full) 35 | # ethtool -s eth0 autoneg on advertise 0x0003 (10M full) 36 | 37 | - Disable center tap short 38 | 39 | # make CONFIG_CTAP_SHORT=OFF modules 40 | 41 | - Ring parameter 42 | 43 | Show Ring parameter 44 | # ethtool -g eth0 45 | 46 | Changes the number of ring entries for the Rx ring. 47 | # ethtool -G eth0 rx 100 48 | 49 | - Tunable parameters 50 | 51 | Get the current rx copybreak value in bytes. 52 | # ethtool --get-tunable eth0 rx-copybreak 53 | 54 | Set the rx copybreak value in bytes. 55 | # ethtool --set-tunable eth0 rx-copybreak 256 56 | 57 | - Flow control 58 | 59 | Queries the specified Ethernet device for pause parameter information. 60 | # ethtool -a eth0 61 | 62 | Changes the pause parameters of the specified Ethernet device. 63 | # ethtool -A eth0 rx off tx off (Disable flow control) 64 | # ethtool -A eth0 rx on tx off (Enable flow control) 65 | -------------------------------------------------------------------------------- /compatibility.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_COMPATIBILITY_H 2 | #define LINUX_COMPATIBILITY_H 3 | 4 | /* 5 | * Definition and macro 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #if defined(RTL8152_S5_WOL) && defined(CONFIG_PM) 14 | #include 15 | #endif /* defined(RTL8152_S5_WOL) && defined(CONFIG_PM) */ 16 | 17 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) 18 | #include 19 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) 20 | #include 21 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) */ 22 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) */ 23 | 24 | #if LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) 25 | #define ethtool_keee ethtool_eee 26 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0) 27 | #define TSO_LEGACY_MAX_SIZE 65536 28 | #define netif_napi_add_weight netif_napi_add 29 | #define netif_set_tso_max_size netif_set_gso_max_size 30 | #define netif_set_tso_max_segs netif_set_gso_max_segs 31 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0) 32 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) 33 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0) 34 | #define PHY_MAC_INTERRUPT PHY_IGNORE_INTERRUPT 35 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0) 36 | #ifdef CONFIG_PM 37 | #define pm_ptr(_ptr) (_ptr) 38 | #else 39 | #define pm_ptr(_ptr) NULL 40 | #endif 41 | 42 | #define from_tasklet(var, callback_tasklet, tasklet_fieldname) \ 43 | container_of((struct tasklet_struct *)callback_tasklet, typeof(*var), tasklet_fieldname) 44 | 45 | #define tasklet_setup(t, fun) tasklet_init(t, fun, (unsigned long)t) 46 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) 47 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,7,0) 48 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) 49 | /* Iterate through singly-linked GSO fragments of an skb. */ 50 | #define skb_list_walk_safe(first, skb, next_skb) \ 51 | for ((skb) = (first), (next_skb) = (skb) ? (skb)->next : NULL; (skb); \ 52 | (skb) = (next_skb), (next_skb) = (skb) ? (skb)->next : NULL) 53 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) 54 | #ifndef __has_attribute 55 | # define __has_attribute(x) 0 56 | #endif 57 | 58 | #if __has_attribute(__fallthrough__) 59 | # define fallthrough __attribute__((__fallthrough__)) 60 | #else 61 | # define fallthrough do {} while (0) /* fallthrough */ 62 | #endif 63 | 64 | #define MDIO_EEE_2_5GT 0x0001 /* 2.5GT EEE cap */ 65 | #define MDIO_EEE_5GT 0x0002 /* 5GT EEE cap */ 66 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) 67 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0) 68 | #define MDIO_AN_10GBT_CTRL_ADV2_5G 0x0080 /* Advertise 2.5GBASE-T */ 69 | #define MDIO_AN_10GBT_CTRL_ADV5G 0x0100 /* Advertise 5GBASE-T */ 70 | #define MDIO_AN_10GBT_STAT_LP2_5G 0x0020 /* LP is 2.5GBT capable */ 71 | #define MDIO_AN_10GBT_STAT_LP5G 0x0040 /* LP is 5GBT capable */ 72 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0) 73 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0) 74 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0) 75 | #define SPEED_2500 2500 76 | #define SPEED_5000 5000 77 | #define SPEED_25000 25000 78 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) 79 | #ifndef ETHTOOL_LINK_MODE_2500baseT_Full_BIT 80 | #define ETHTOOL_LINK_MODE_2500baseT_Full_BIT ETHTOOL_LINK_MODE_2500baseX_Full_BIT 81 | #endif 82 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,9,0) 83 | #define BMCR_SPEED10 0x0000 84 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) 85 | #define NETIF_F_CSUM_MASK NETIF_F_ALL_CSUM 86 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0) 87 | #define IS_REACHABLE(option) (defined(option) || \ 88 | (defined(option##_MODULE) && defined(MODULE))) 89 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) 90 | #define skb_vlan_tag_present(__skb) vlan_tx_tag_present(__skb) 91 | #define skb_vlan_tag_get(__skb) vlan_tx_tag_get(__skb) 92 | #define skb_vlan_tag_get_id(__skb) vlan_tx_tag_get_id(__skb) 93 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0) 94 | #define napi_alloc_skb(napi, length) netdev_alloc_skb_ip_align(netdev,length) 95 | #define napi_complete_done(n, d) napi_complete(n) 96 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0) 97 | #ifndef smp_mb__before_atomic 98 | #define smp_mb__before_atomic() smp_mb() 99 | #endif 100 | 101 | #ifndef smp_mb__after_atomic 102 | #define smp_mb__after_atomic() smp_mb() 103 | #endif 104 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) 105 | #define IS_ERR_OR_NULL(ptr) (!ptr) 106 | 107 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) 108 | #define ether_addr_copy(dst, src) memcpy(dst, src, ETH_ALEN) 109 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0) 110 | #define BIT(nr) (1UL << (nr)) 111 | #define BIT_ULL(nr) (1ULL << (nr)) 112 | #define BITS_PER_BYTE 8 113 | #define reinit_completion(x) ((x)->done = 0) 114 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0) 115 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0) 116 | #define DEVICE_ATTR_RW(_name) \ 117 | struct device_attribute dev_attr_##_name = __ATTR(_name, 0644, _name##_show, _name##_store) 118 | #define DEVICE_ATTR_RO(_name) \ 119 | struct device_attribute dev_attr_##_name = __ATTR_RO(_name) 120 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) 121 | #define NETIF_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_RX 122 | #define NETIF_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_TX 123 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) 124 | #define USB_DEVICE_INTERFACE_CLASS(vend, prod, cl) \ 125 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 126 | USB_DEVICE_ID_MATCH_INT_CLASS, \ 127 | .idVendor = (vend), \ 128 | .idProduct = (prod), \ 129 | .bInterfaceClass = (cl) 130 | 131 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) 132 | #ifndef SPEED_UNKNOWN 133 | #define SPEED_UNKNOWN 0 134 | #endif 135 | 136 | #ifndef DUPLEX_UNKNOWN 137 | #define DUPLEX_UNKNOWN 0xff 138 | #endif 139 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) 140 | #define eth_random_addr(addr) random_ether_addr(addr) 141 | #define usb_enable_lpm(udev) 142 | #define MDIO_EEE_100TX MDIO_AN_EEE_ADV_100TX /* 100TX EEE cap */ 143 | #define MDIO_EEE_1000T MDIO_AN_EEE_ADV_1000T /* 1000T EEE cap */ 144 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) 145 | #define ETH_MDIO_SUPPORTS_C22 MDIO_SUPPORTS_C22 146 | 147 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) 148 | #define module_usb_driver(__driver) \ 149 | static int __init __driver##_init(void) \ 150 | { \ 151 | return usb_register(&(__driver)); \ 152 | } \ 153 | module_init(__driver##_init); \ 154 | static void __exit __driver##_exit(void) \ 155 | { \ 156 | usb_deregister(&(__driver)); \ 157 | } \ 158 | module_exit(__driver##_exit); 159 | 160 | #define netdev_features_t u32 161 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) 162 | #define PMSG_IS_AUTO(msg) (((msg).event & PM_EVENT_AUTO) != 0) 163 | 164 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) 165 | #define ndo_set_rx_mode ndo_set_multicast_list 166 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) 167 | #define NETIF_F_RXCSUM (1 << 29) /* Receive checksumming offload */ 168 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) 169 | #define MDIO_AN_EEE_ADV 60 /* EEE advertisement */ 170 | #define MDIO_AN_EEE_ADV_100TX 0x0002 /* Advertise 100TX EEE cap */ 171 | #define MDIO_AN_EEE_ADV_1000T 0x0004 /* Advertise 1000T EEE cap */ 172 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) 173 | #define skb_checksum_none_assert(skb_ptr) (skb_ptr)->ip_summed = CHECKSUM_NONE 174 | 175 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) 176 | #define skb_tx_timestamp(skb) 177 | 178 | #define queue_delayed_work(long_wq, work, delay) schedule_delayed_work(work, delay) 179 | 180 | #define work_busy(x) 0 181 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) 182 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) 183 | #define netdev_mc_count(netdev) ((netdev)->mc_count) 184 | #define netdev_mc_empty(netdev) (netdev_mc_count(netdev) == 0) 185 | 186 | #define netif_printk(priv, type, level, netdev, fmt, args...) \ 187 | do { \ 188 | if (netif_msg_##type(priv)) \ 189 | printk(level "%s: " fmt,(netdev)->name , ##args); \ 190 | } while (0) 191 | 192 | #define netif_emerg(priv, type, netdev, fmt, args...) \ 193 | netif_printk(priv, type, KERN_EMERG, netdev, fmt, ##args) 194 | #define netif_alert(priv, type, netdev, fmt, args...) \ 195 | netif_printk(priv, type, KERN_ALERT, netdev, fmt, ##args) 196 | #define netif_crit(priv, type, netdev, fmt, args...) \ 197 | netif_printk(priv, type, KERN_CRIT, netdev, fmt, ##args) 198 | #define netif_err(priv, type, netdev, fmt, args...) \ 199 | netif_printk(priv, type, KERN_ERR, netdev, fmt, ##args) 200 | #define netif_warn(priv, type, netdev, fmt, args...) \ 201 | netif_printk(priv, type, KERN_WARNING, netdev, fmt, ##args) 202 | #define netif_notice(priv, type, netdev, fmt, args...) \ 203 | netif_printk(priv, type, KERN_NOTICE, netdev, fmt, ##args) 204 | #define netif_info(priv, type, netdev, fmt, args...) \ 205 | netif_printk(priv, type, KERN_INFO, (netdev), fmt, ##args) 206 | 207 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) 208 | #define get_sset_count get_stats_count 209 | 210 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) 211 | #define pm_request_resume(para) 212 | #define pm_runtime_set_suspended(para) 213 | #define pm_schedule_suspend(para1, para2) 214 | #define pm_runtime_get_sync(para) 215 | #define pm_runtime_put_sync(para) 216 | #define pm_runtime_put_noidle(para) 217 | #define pm_runtime_idle(para) 218 | #define pm_runtime_set_active(para) 219 | #define pm_runtime_enable(para) 220 | #define pm_runtime_disable(para) 221 | typedef int netdev_tx_t; 222 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) 223 | #define USB_SPEED_SUPER (USB_SPEED_VARIABLE + 1) 224 | #define MDIO_MMD_AN 7 /* Auto-Negotiation */ 225 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) 226 | #define napi_gro_receive(napi, skb) netif_receive_skb(skb) 227 | #define vlan_gro_receive(napi, grp, vlan_tci, skb) \ 228 | vlan_hwaccel_receive_skb(skb, grp, vlan_tci) 229 | 230 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) 231 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) 232 | #define PM_EVENT_AUTO 0x0400 233 | 234 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 235 | struct napi_struct { 236 | struct list_head poll_list; 237 | unsigned long state; 238 | int weight; 239 | int (*poll)(struct napi_struct *, int); 240 | #ifdef CONFIG_NETPOLL 241 | spinlock_t poll_lock; 242 | int poll_owner; 243 | struct net_device *dev; 244 | struct list_head dev_list; 245 | #endif 246 | }; 247 | 248 | #define napi_enable(napi_ptr) netif_poll_enable(container_of(napi_ptr, struct r8152, napi)->netdev) 249 | #define napi_disable(napi_ptr) netif_poll_disable(container_of(napi_ptr, struct r8152, napi)->netdev) 250 | #define napi_schedule(napi_ptr) netif_rx_schedule(container_of(napi_ptr, struct r8152, napi)->netdev) 251 | #define napi_complete(napi_ptr) netif_rx_complete(container_of(napi_ptr, struct r8152, napi)->netdev) 252 | #define netif_napi_add(ndev, napi_ptr, function, weight_t) \ 253 | ndev->poll = function; \ 254 | ndev->weight = weight_t; 255 | typedef unsigned long uintptr_t; 256 | #define DMA_BIT_MASK(value) \ 257 | (value < 64 ? ((1ULL << value) - 1) : 0xFFFFFFFFFFFFFFFFULL) 258 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) 259 | #define NETIF_F_IPV6_CSUM 16 260 | #define cancel_delayed_work_sync cancel_delayed_work 261 | 262 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) 263 | #define ip_hdr(skb_ptr) (skb_ptr)->nh.iph 264 | #define ipv6hdr(skb_ptr) (skb_ptr)->nh.ipv6h 265 | 266 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) 267 | #define vlan_group_set_device(vlgrp, vid, value) \ 268 | if (vlgrp) \ 269 | (vlgrp)->vlan_devices[vid] = value; 270 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) 271 | #define delayed_work work_struct 272 | #define INIT_DELAYED_WORK(a,b) INIT_WORK(a,b,tp) 273 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) 274 | #define CHECKSUM_PARTIAL CHECKSUM_HW 275 | 276 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 277 | #define skb_is_gso(skb_ptr) skb_shinfo(skb_ptr)->tso_size 278 | #define netdev_alloc_skb(dev, len) dev_alloc_skb(len) 279 | #define IRQF_SHARED SA_SHIRQ 280 | 281 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) 282 | #ifndef __LINUX_MUTEX_H 283 | #define mutex semaphore 284 | #define mutex_lock down 285 | #define mutex_unlock up 286 | #define mutex_trylock down_trylock 287 | #define mutex_lock_interruptible down_interruptible 288 | #define mutex_init init_MUTEX 289 | #endif 290 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) 291 | #define ADVERTISED_Pause (1 << 13) 292 | #define ADVERTISED_Asym_Pause (1 << 14) 293 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) 294 | #define skb_header_cloned(skb) skb_cloned(skb) 295 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) */ 296 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) */ 297 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) */ 298 | static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features) 299 | { 300 | return NULL; 301 | } 302 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) */ 303 | static inline void *kmemdup(const void *src, size_t len, gfp_t gfp) 304 | { 305 | void *p; 306 | 307 | p = kmalloc_track_caller(len, gfp); 308 | if (p) 309 | memcpy(p, src, len); 310 | return p; 311 | } 312 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) */ 313 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) */ 314 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) */ 315 | static inline void skb_copy_from_linear_data(const struct sk_buff *skb, 316 | void *to, 317 | const unsigned int len) 318 | { 319 | memcpy(to, skb->data, len); 320 | } 321 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) */ 322 | static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom) 323 | { 324 | int delta = 0; 325 | 326 | if (headroom > skb_headroom(skb)) 327 | delta = headroom - skb_headroom(skb); 328 | 329 | if (delta || skb_header_cloned(skb)) 330 | return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 331 | 0, GFP_ATOMIC); 332 | return 0; 333 | } 334 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) */ 335 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) */ 336 | static inline void __list_splice2(const struct list_head *list, 337 | struct list_head *prev, 338 | struct list_head *next) 339 | { 340 | struct list_head *first = list->next; 341 | struct list_head *last = list->prev; 342 | 343 | first->prev = prev; 344 | prev->next = first; 345 | 346 | last->next = next; 347 | next->prev = last; 348 | } 349 | 350 | static inline void list_splice_tail(struct list_head *list, 351 | struct list_head *head) 352 | { 353 | if (!list_empty(list)) 354 | __list_splice2(list, head->prev, head); 355 | } 356 | 357 | static inline void netif_napi_del(struct napi_struct *napi) 358 | { 359 | #ifdef CONFIG_NETPOLL 360 | list_del(&napi->dev_list); 361 | #endif 362 | } 363 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) */ 364 | static inline void __skb_queue_splice(const struct sk_buff_head *list, 365 | struct sk_buff *prev, 366 | struct sk_buff *next) 367 | { 368 | struct sk_buff *first = list->next; 369 | struct sk_buff *last = list->prev; 370 | 371 | first->prev = prev; 372 | prev->next = first; 373 | 374 | last->next = next; 375 | next->prev = last; 376 | } 377 | 378 | static inline void skb_queue_splice(const struct sk_buff_head *list, 379 | struct sk_buff_head *head) 380 | { 381 | if (!skb_queue_empty(list)) { 382 | __skb_queue_splice(list, (struct sk_buff *) head, head->next); 383 | head->qlen += list->qlen; 384 | } 385 | } 386 | 387 | static inline void __skb_queue_head_init(struct sk_buff_head *list) 388 | { 389 | list->prev = list->next = (struct sk_buff *)list; 390 | list->qlen = 0; 391 | } 392 | 393 | static inline void skb_queue_splice_init(struct sk_buff_head *list, 394 | struct sk_buff_head *head) 395 | { 396 | if (!skb_queue_empty(list)) { 397 | __skb_queue_splice(list, (struct sk_buff *) head, head->next); 398 | head->qlen += list->qlen; 399 | __skb_queue_head_init(list); 400 | } 401 | } 402 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) */ 403 | static inline void usb_autopm_put_interface_async(struct usb_interface *intf) 404 | { 405 | struct usb_device *udev = interface_to_usbdev(intf); 406 | int status = 0; 407 | 408 | if (intf->condition == USB_INTERFACE_UNBOUND) { 409 | status = -ENODEV; 410 | } else { 411 | udev->last_busy = jiffies; 412 | --intf->pm_usage_cnt; 413 | if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) 414 | status = -EPERM; 415 | } 416 | } 417 | 418 | static inline int usb_autopm_get_interface_async(struct usb_interface *intf) 419 | { 420 | struct usb_device *udev = interface_to_usbdev(intf); 421 | int status = 0; 422 | 423 | if (intf->condition == USB_INTERFACE_UNBOUND) 424 | status = -ENODEV; 425 | else if (udev->autoresume_disabled) 426 | status = -EPERM; 427 | else 428 | ++intf->pm_usage_cnt; 429 | return status; 430 | } 431 | 432 | static inline int eth_change_mtu(struct net_device *dev, int new_mtu) 433 | { 434 | if (new_mtu < 68 || new_mtu > ETH_DATA_LEN) 435 | return -EINVAL; 436 | dev->mtu = new_mtu; 437 | return 0; 438 | } 439 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */ 440 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) */ 441 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) */ 442 | static inline 443 | struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, 444 | unsigned int length) 445 | { 446 | struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); 447 | 448 | if (NET_IP_ALIGN && skb) 449 | skb_reserve(skb, NET_IP_ALIGN); 450 | return skb; 451 | } 452 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) */ 453 | static inline int usb_enable_autosuspend(struct usb_device *udev) 454 | { return 0; } 455 | static inline int usb_disable_autosuspend(struct usb_device *udev) 456 | { return 0; } 457 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) */ 458 | static inline bool pci_dev_run_wake(struct pci_dev *dev) 459 | { 460 | return 1; 461 | } 462 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) */ 463 | static inline void usleep_range(unsigned long min, unsigned long max) 464 | { 465 | unsigned long ms = min / 1000; 466 | 467 | if (ms) 468 | mdelay(ms); 469 | 470 | udelay(min % 1000); 471 | } 472 | 473 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) */ 474 | static inline __be16 vlan_get_protocol(const struct sk_buff *skb) 475 | { 476 | __be16 protocol = 0; 477 | 478 | if (vlan_tx_tag_present(skb) || 479 | skb->protocol != cpu_to_be16(ETH_P_8021Q)) 480 | protocol = skb->protocol; 481 | else { 482 | __be16 proto, *protop; 483 | protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr, 484 | h_vlan_encapsulated_proto), 485 | sizeof(proto), &proto); 486 | if (likely(protop)) 487 | protocol = *protop; 488 | } 489 | 490 | return protocol; 491 | } 492 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) */ 493 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) */ 494 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) */ 495 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) */ 496 | static inline struct page *skb_frag_page(const skb_frag_t *frag) 497 | { 498 | return frag->page; 499 | } 500 | 501 | static inline void *skb_frag_address(const skb_frag_t *frag) 502 | { 503 | return page_address(skb_frag_page(frag)) + frag->page_offset; 504 | } 505 | 506 | static inline unsigned int skb_frag_size(const skb_frag_t *frag) 507 | { 508 | return frag->size; 509 | } 510 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) */ 511 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) */ 512 | static inline void eth_hw_addr_random(struct net_device *dev) 513 | { 514 | random_ether_addr(dev->dev_addr); 515 | } 516 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) */ 517 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) */ 518 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) */ 519 | static inline __sum16 tcp_v6_check(int len, 520 | const struct in6_addr *saddr, 521 | const struct in6_addr *daddr, 522 | __wsum base) 523 | { 524 | return csum_ipv6_magic(saddr, daddr, len, IPPROTO_TCP, base); 525 | } 526 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */ 527 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */ 528 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0) */ 529 | static inline bool usb_device_no_sg_constraint(struct usb_device *udev) 530 | { 531 | return 0; 532 | } 533 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,12,0) */ 534 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0) */ 535 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) */ 536 | static inline int skb_to_sgvec_nomark(struct sk_buff *skb, 537 | struct scatterlist *sg, 538 | int offset, int len) 539 | { 540 | int nsg = skb_to_sgvec(skb, sg, offset, len); 541 | 542 | if (nsg <= 0) 543 | return nsg; 544 | 545 | sg_unmark_end(&sg[nsg - 1]); 546 | 547 | return nsg; 548 | } 549 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) */ 550 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0) */ 551 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0) */ 552 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0) */ 553 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0) */ 554 | static inline int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr) 555 | { 556 | return -EOPNOTSUPP; 557 | } 558 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) */ 559 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,9,0) */ 560 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) */ 561 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0) */ 562 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,19,10) && \ 563 | !(LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,217) && LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)) 564 | static inline void skb_mark_not_on_list(struct sk_buff *skb) 565 | { 566 | skb->next = NULL; 567 | } 568 | #endif 569 | static inline void linkmode_set_bit(int nr, volatile unsigned long *addr) 570 | { 571 | __set_bit(nr, addr); 572 | } 573 | 574 | static inline void linkmode_clear_bit(int nr, volatile unsigned long *addr) 575 | { 576 | __clear_bit(nr, addr); 577 | } 578 | 579 | static inline int linkmode_test_bit(int nr, volatile unsigned long *addr) 580 | { 581 | return test_bit(nr, addr); 582 | } 583 | 584 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0) */ 585 | static inline void linkmode_mod_bit(int nr, volatile unsigned long *addr, 586 | int set) 587 | { 588 | if (set) 589 | linkmode_set_bit(nr, addr); 590 | else 591 | linkmode_clear_bit(nr, addr); 592 | } 593 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0) */ 594 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,1,0) */ 595 | // static inline u16 pci_dev_id(struct pci_dev *dev) 596 | // { 597 | // return PCI_DEVID(dev->bus->number, dev->devfn); 598 | // } 599 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) */ 600 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,4,0) */ 601 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0) */ 602 | static inline void tcp_v6_gso_csum_prep(struct sk_buff *skb) 603 | { 604 | struct ipv6hdr *ipv6h = ipv6_hdr(skb); 605 | struct tcphdr *th = tcp_hdr(skb); 606 | 607 | ipv6h->payload_len = 0; 608 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); 609 | } 610 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,7,0) */ 611 | static inline void fsleep(unsigned long usecs) 612 | { 613 | if (usecs <= 10) 614 | udelay(usecs); 615 | else if (usecs <= 20000) 616 | usleep_range(usecs, 2 * usecs); 617 | else 618 | msleep(DIV_ROUND_UP(usecs, 1000)); 619 | } 620 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) */ 621 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0) */ 622 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0) */ 623 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,10,188) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) 624 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) 625 | #if LINUX_VERSION_MAJOR != 4 || LINUX_VERSION_PATCHLEVEL != 19 || LINUX_VERSION_SUBLEVEL < 291 626 | static inline void eth_hw_addr_set(struct net_device *dev, const u8 *addr) 627 | { 628 | memcpy(dev->dev_addr, addr, 6); 629 | } 630 | #endif /* LINUX_VERSION_MAJOR != 4 || LINUX_VERSION_PATCHLEVEL != 19 || LINUX_VERSION_SUBLEVEL < 291 */ 631 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,4,251) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) */ 632 | #endif /*LINUX_VERSION_CODE < KERNEL_VERSION(5,10,188) || LINUX_VERSION_CODE >= KERNEL_VERSION(5,11,0) */ 633 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0) */ 634 | static inline void netif_set_gso_max_segs(struct net_device *dev, 635 | unsigned int segs) 636 | { 637 | /* dev->gso_max_segs is read locklessly from sk_setup_caps() */ 638 | WRITE_ONCE(dev->gso_max_segs, segs); 639 | } 640 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0) */ 641 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0) */ 642 | #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(6,9,0) */ 643 | 644 | #ifndef FALSE 645 | #define TRUE 1 646 | #define FALSE 0 647 | #endif 648 | 649 | enum rtl_cmd { 650 | RTLTOOL_PLA_OCP_READ_DWORD = 0, 651 | RTLTOOL_PLA_OCP_WRITE_DWORD, 652 | RTLTOOL_USB_OCP_READ_DWORD, 653 | RTLTOOL_USB_OCP_WRITE_DWORD, 654 | RTLTOOL_PLA_OCP_READ, 655 | RTLTOOL_PLA_OCP_WRITE, 656 | RTLTOOL_USB_OCP_READ, 657 | RTLTOOL_USB_OCP_WRITE, 658 | RTLTOOL_USB_INFO, 659 | RTL_ENABLE_USB_DIAG, 660 | RTL_DISABLE_USB_DIAG, 661 | 662 | RTLTOOL_INVALID 663 | }; 664 | 665 | struct usb_device_info { 666 | __u16 idVendor; 667 | __u16 idProduct; 668 | __u16 bcdDevice; 669 | __u8 dev_addr[8]; 670 | char devpath[16]; 671 | }; 672 | 673 | struct rtltool_cmd { 674 | __u32 cmd; 675 | __u32 offset; 676 | __u32 byteen; 677 | __u32 data; 678 | void *buf; 679 | struct usb_device_info nic_info; 680 | struct sockaddr ifru_addr; 681 | struct sockaddr ifru_netmask; 682 | struct sockaddr ifru_hwaddr; 683 | }; 684 | 685 | #endif /* LINUX_COMPATIBILITY_H */ 686 | --------------------------------------------------------------------------------