r8126: add Realtek 5GbE PCIe Network Adapter support

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
(cherry picked from commit c582674b44)
This commit is contained in:
Tianling Shen
2024-07-17 15:28:23 +08:00
parent 1e6d2fcc57
commit 79e9020dbe
3 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2024 ImmortalWrt.org
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=r8126
PKG_VERSION:=10.013.00
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=@IMMORTALWRT
PKG_HASH:=b41bda6ff3bbb7d9bc5b81c5c21355f031587d3a3a5862abcd4d766e942272e7
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
PKG_LICENSE:=GPL-2.0-only
PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
define KernelPackage/r8126
TITLE:=Driver for Realtek r8126 chipsets
SUBMENU:=Network Devices
DEPENDS:=@PCI_SUPPORT
FILES:= $(PKG_BUILD_DIR)/src/r8126.ko
AUTOLOAD:=$(call AutoProbe,r8126)
endef
define KernelPackage/r8126/description
This package contains a driver for Realtek r8126 chipsets.
endef
define Build/Compile
+$(KERNEL_MAKE) $(PKG_JOBS) \
M=$(PKG_BUILD_DIR)/src \
CONFIG_ASPM=n \
ENABLE_RSS_SUPPORT=y \
modules
endef
$(eval $(call KernelPackage,r8126))

View File

@@ -0,0 +1,45 @@
--- a/src/r8126_n.c
+++ b/src/r8126_n.c
@@ -43,6 +43,7 @@
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/mii.h>
+#include <linux/of.h>
#include <linux/if_vlan.h>
#include <linux/crc32.h>
#include <linux/interrupt.h>
@@ -11610,6 +11611,25 @@ rtl8126_setup_mqs_reg(struct rtl8126_pri
}
}
+static int
+rtl8126_led_configuration(struct rtl8126_private *tp)
+{
+ const int led_regs[] = { 0x18, 0x86, 0x84, 0x96 }; /* LEDSEL 0-3 */
+ u32 led_data[4];
+ int ret, i;
+
+ ret = of_property_read_u32_array(tp->pci_dev->dev.of_node,
+ "realtek,led-data", led_data, 4);
+
+ if (ret)
+ return ret;
+
+ for (i = 0; i < 4; i++)
+ RTL_W16(tp, led_regs[i], led_data[i]);
+
+ return 0;
+}
+
static void
rtl8126_init_software_variable(struct net_device *dev)
{
@@ -11982,6 +12002,8 @@ rtl8126_init_software_variable(struct ne
if (tp->InitRxDescType == RX_DESC_RING_TYPE_3)
tp->rtl8126_rx_config |= EnableRxDescV3;
+ rtl8126_led_configuration(tp);
+
tp->NicCustLedValue = RTL_R16(tp, CustomLED);
tp->wol_opts = rtl8126_get_hw_wol(tp);

View File

@@ -0,0 +1,20 @@
--- a/src/r8126_n.c
+++ b/src/r8126_n.c
@@ -13016,6 +13016,7 @@ rtl8126_init_board(struct pci_dev *pdev,
void __iomem *ioaddr;
struct net_device *dev;
struct rtl8126_private *tp;
+ const char *devname = of_get_property(pdev->dev.of_node, "label", NULL);
int rc = -ENOMEM, i, pm_cap;
assert(ioaddr_out != NULL);
@@ -13030,6 +13031,9 @@ rtl8126_init_board(struct pci_dev *pdev,
goto err_out;
}
+ if (devname)
+ strscpy(dev->name, devname, IFNAMSIZ);
+
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
tp = netdev_priv(dev);