本帖最后由 威廉第三 于 2023-3-23 22:46 编辑
其实从高版本驱动借鉴几处修改,可以继续在PVE 6.2内核上编译9.007版本的驱动,开启4Rx 2Tx队列
- diff --git a/src/r8125.h b/src/r8125.h
- index 8b4085c..723c6f1 100755
- --- a/src/r8125.h
- +++ b/src/r8125.h
- @@ -616,7 +616,11 @@ typedef int *napi_budget;
- typedef struct napi_struct *napi_ptr;
- typedef int napi_budget;
-
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
- #define RTL_NAPI_CONFIG(ndev, priv, function, weight) netif_napi_add(ndev, &priv->napi, function, weight)
- +#else
- +#define RTL_NAPI_CONFIG(ndev, priv, function, weight) netif_napi_add_weight(ndev, &priv->napi, function, weight)
- +#endif
- #define RTL_NAPI_QUOTA(budget, ndev) min(budget, budget)
- #define RTL_GET_PRIV(stuct_ptr, priv_struct) container_of(stuct_ptr, priv_struct, stuct_ptr)
- #define RTL_GET_NETDEV(priv_ptr) struct net_device *dev = priv_ptr->dev;
- diff --git a/src/r8125_n.c b/src/r8125_n.c
- index ec117a7..5c29a4b 100755
- --- a/src/r8125_n.c
- +++ b/src/r8125_n.c
- @@ -348,7 +348,7 @@ static int rtl8125_change_mtu(struct net_device *dev, int new_mtu);
- static void rtl8125_down(struct net_device *dev);
-
- static int rtl8125_set_mac_address(struct net_device *dev, void *p);
- -static void rtl8125_rar_set(struct rtl8125_private *tp, uint8_t *addr);
- +static void rtl8125_rar_set(struct rtl8125_private *tp, const u8 *addr);
- static void rtl8125_desc_addr_fill(struct rtl8125_private *);
- static void rtl8125_tx_desc_init(struct rtl8125_private *tp);
- static void rtl8125_rx_desc_init(struct rtl8125_private *tp);
- @@ -1746,7 +1746,11 @@ static void rtl8125_proc_module_init(void)
- static int rtl8125_proc_open(struct inode *inode, struct file *file)
- {
- struct net_device *dev = proc_get_parent_data(inode);
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
- + int (*show)(struct seq_file *, void *) = pde_data(inode);
- +#else
- int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
- +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
-
- return single_open(file, show, dev);
- }
- @@ -10720,6 +10724,16 @@ rtl8125_release_board(struct pci_dev *pdev,
- free_netdev(dev);
- }
-
- +static void
- +rtl8125_hw_address_set(struct net_device *dev, u8 mac_addr[MAC_ADDR_LEN])
- +{
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
- + eth_hw_addr_set(dev, mac_addr);
- +#else
- + memcpy(dev->dev_addr, mac_addr, MAC_ADDR_LEN);
- +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(5,17,0)
- +}
- +
- static int
- rtl8125_get_mac_address(struct net_device *dev)
- {
- @@ -10743,24 +10757,21 @@ rtl8125_get_mac_address(struct net_device *dev)
- if (!is_valid_ether_addr(mac_addr)) {
- netif_err(tp, probe, dev, "Invalid ether addr %pM\n",
- mac_addr);
- - eth_hw_addr_random(dev);
- - ether_addr_copy(mac_addr, dev->dev_addr);
- + eth_random_addr(mac_addr);
- + dev->addr_assign_type = NET_ADDR_RANDOM;
- netif_info(tp, probe, dev, "Random ether addr %pM\n",
- mac_addr);
- tp->random_mac = 1;
- }
-
- + rtl8125_hw_address_set(dev, mac_addr);
- rtl8125_rar_set(tp, mac_addr);
-
- - for (i = 0; i < MAC_ADDR_LEN; i++) {
- - dev->dev_addr[i] = RTL_R8(tp, MAC0 + i);
- - tp->org_mac_addr[i] = dev->dev_addr[i]; /* keep the original MAC address */
- - }
- + /* keep the original MAC address */
- + memcpy(tp->org_mac_addr, dev->dev_addr, MAC_ADDR_LEN);
- #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)
- memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
- #endif
- -// memcpy(dev->dev_addr, dev->dev_addr, dev->addr_len);
- -
- return 0;
- }
-
- @@ -10781,7 +10792,7 @@ rtl8125_set_mac_address(struct net_device *dev,
- if (!is_valid_ether_addr(addr->sa_data))
- return -EADDRNOTAVAIL;
-
- - memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
- + rtl8125_hw_address_set(dev, addr->sa_data);
-
- rtl8125_rar_set(tp, dev->dev_addr);
-
- @@ -10796,7 +10807,7 @@ rtl8125_set_mac_address(struct net_device *dev,
- *****************************************************************************/
- void
- rtl8125_rar_set(struct rtl8125_private *tp,
- - uint8_t *addr)
- + const u8 *addr)
- {
- uint32_t rar_low = 0;
- uint32_t rar_high = 0;
- @@ -11476,6 +11487,57 @@ static int ethtool_ioctl(struct ifreq *ifr)
- }
- #endif //ETHTOOL_OPS_COMPAT
-
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0)
- +static int rtl8125_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
- + void __user *data, int cmd)
- +{
- + struct rtl8125_private *tp = netdev_priv(dev);
- + int ret = 0;
- +
- + switch (cmd) {
- +#ifdef ENABLE_DASH_SUPPORT
- + case SIOCDEVPRIVATE_RTLDASH:
- + if (!netif_running(dev)) {
- + ret = -ENODEV;
- + break;
- + }
- + if (!capable(CAP_NET_ADMIN)) {
- + ret = -EPERM;
- + break;
- + }
- +
- + ret = rtl8125_dash_ioctl(dev, ifr);
- + break;
- +#endif
- +
- +#ifdef ENABLE_REALWOW_SUPPORT
- + case SIOCDEVPRIVATE_RTLREALWOW:
- + if (!netif_running(dev)) {
- + ret = -ENODEV;
- + break;
- + }
- +
- + ret = rtl8125_realwow_ioctl(dev, ifr);
- + break;
- +#endif
- +
- + case SIOCRTLTOOL:
- + if (!capable(CAP_NET_ADMIN)) {
- + ret = -EPERM;
- + break;
- + }
- +
- + ret = rtl8125_tool_ioctl(tp, ifr);
- + break;
- +
- + default:
- + ret = -EOPNOTSUPP;
- + }
- +
- + return ret;
- +}
- +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0)
- +
- static int
- rtl8125_do_ioctl(struct net_device *dev,
- struct ifreq *ifr,
- @@ -11483,9 +11545,8 @@ rtl8125_do_ioctl(struct net_device *dev,
- {
- struct rtl8125_private *tp = netdev_priv(dev);
- struct mii_ioctl_data *data = if_mii(ifr);
- - int ret;
- + int ret = 0;
-
- - ret = 0;
- switch (cmd) {
- case SIOCGMIIPHY:
- data->phy_id = 32; /* Internal PHY */
- @@ -11509,6 +11570,16 @@ rtl8125_do_ioctl(struct net_device *dev,
- break;
- #endif
-
- +#ifdef ENABLE_PTP_SUPPORT
- + case SIOCSHWTSTAMP:
- + case SIOCGHWTSTAMP:
- + if (tp->EnablePtp)
- + ret = rtl8125_ptp_ioctl(dev, ifr, cmd);
- + else
- + ret = -EOPNOTSUPP;
- + break;
- +#endif
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
- #ifdef ENABLE_DASH_SUPPORT
- case SIOCDEVPRIVATE_RTLDASH:
- if (!netif_running(dev)) {
- @@ -11531,22 +11602,24 @@ rtl8125_do_ioctl(struct net_device *dev,
- break;
- }
-
- + if (!capable(CAP_NET_ADMIN)) {
- + ret = -EPERM;
- + break;
- + }
- +
- ret = rtl8125_realwow_ioctl(dev, ifr);
- break;
- #endif
-
- -#ifdef ENABLE_PTP_SUPPORT
- - case SIOCSHWTSTAMP:
- - case SIOCGHWTSTAMP:
- - if (tp->EnablePtp)
- - ret = rtl8125_ptp_ioctl(dev, ifr, cmd);
- - else
- - ret = -EOPNOTSUPP;
- - break;
- -#endif
- case SIOCRTLTOOL:
- + if (!capable(CAP_NET_ADMIN)) {
- + ret = -EPERM;
- + break;
- + }
- +
- ret = rtl8125_tool_ioctl(tp, ifr);
- break;
- +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
-
- default:
- ret = -EOPNOTSUPP;
- @@ -11689,11 +11762,11 @@ rtl8125_init_board(struct pci_dev *pdev,
-
- if ((sizeof(dma_addr_t) > 4) &&
- use_dac &&
- - !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
- - !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
- + !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
- + !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
- dev->features |= NETIF_F_HIGHDMA;
- } else {
- - rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
- + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
- if (rc < 0) {
- #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
- if (netif_msg_probe(tp))
- @@ -11778,6 +11851,9 @@ rtl8125_esd_checker(struct rtl8125_private *tp)
- u32 pci_sn_l;
- u32 pci_sn_h;
-
- + if (unlikely(tp->rtk_enable_diag))
- + goto exit;
- +
- tp->esd_flag = 0;
-
- pci_read_config_byte(pdev, PCI_COMMAND, &cmd);
- @@ -12081,7 +12157,12 @@ static const struct net_device_ops rtl8125_netdev_ops = {
- .ndo_tx_timeout = rtl8125_tx_timeout,
- .ndo_change_mtu = rtl8125_change_mtu,
- .ndo_set_mac_address = rtl8125_set_mac_address,
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
- .ndo_do_ioctl = rtl8125_do_ioctl,
- +#else
- + .ndo_siocdevprivate = rtl8125_siocdevprivate,
- + .ndo_eth_ioctl = rtl8125_do_ioctl,
- +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0)
- #if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)
- .ndo_set_multicast_list = rtl8125_set_rx_mode,
- #else
- @@ -12444,6 +12525,10 @@ rtl8125_init_one(struct pci_dev *pdev,
- #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
- dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
- dev->features |= NETIF_F_IPV6_CSUM;
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)
- + netif_set_tso_max_size(dev, LSO_64K);
- + netif_set_tso_max_segs(dev, NIC_MAX_PHYS_BUF_COUNT_LSO2);
- +#else //LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)
- netif_set_gso_max_size(dev, LSO_64K);
- #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0)
- dev->gso_max_segs = NIC_MAX_PHYS_BUF_COUNT_LSO2;
- @@ -12451,6 +12536,7 @@ rtl8125_init_one(struct pci_dev *pdev,
- dev->gso_min_segs = NIC_MIN_PHYS_BUF_COUNT;
- #endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
- #endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0)
- +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(5,19,0)
-
- #endif //LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
- #endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
复制代码
|