kernel: r8126: print link status when link up
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Sat, 17 Aug 2024 19:55:42 +0000 (21:55 +0200)
committerÁlvaro Fernández Rojas <noltari@gmail.com>
Sun, 18 Aug 2024 17:57:47 +0000 (19:57 +0200)
Like other Ethernet drivers, print link speed and duplex mode
when the interface is up. Formatting output at the same time.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
package/kernel/r8126/Makefile
package/kernel/r8126/patches/200-r8126-print-link-speed-and-duplex-mode.patch [new file with mode: 0644]

index 88d45ff6b0e535f9bad38329799f78354e086637..3cd77294b1485b4d30c84b5994098f40d5a30e0a 100644 (file)
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=r8126
 PKG_VERSION:=10.013.00
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=https://github.com/openwrt/rtl8126/releases/download/$(PKG_VERSION)
@@ -18,7 +18,7 @@ include $(INCLUDE_DIR)/package.mk
 define KernelPackage/r8126
   SUBMENU:=Network Devices
   TITLE:=Realtek RTL8126 PCI 5 Gigabit Ethernet driver
-  DEPENDS:=@PCI_SUPPORT
+  DEPENDS:=@PCI_SUPPORT +kmod-libphy
   FILES:=$(PKG_BUILD_DIR)/src/r8126.ko
   AUTOLOAD:=$(call AutoProbe,r8126)
   PROVIDES:=kmod-r8169
diff --git a/package/kernel/r8126/patches/200-r8126-print-link-speed-and-duplex-mode.patch b/package/kernel/r8126/patches/200-r8126-print-link-speed-and-duplex-mode.patch
new file mode 100644 (file)
index 0000000..308d249
--- /dev/null
@@ -0,0 +1,102 @@
+From 5ca1d47e065c0318774a946ffdf76010c78cc164 Mon Sep 17 00:00:00 2001
+From: Chukun Pan <amadeus@jmu.edu.cn>
+Date: Sat, 10 Aug 2024 20:16:32 +0800
+Subject: [PATCH] r8126: print link speed and duplex mode
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Like other Ethernet drivers, print link speed and duplex mode
+when the interface is up. Formatting output at the same time.
+
+Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
+Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
+---
+ src/r8126.h   |  2 ++
+ src/r8126_n.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
+ 2 files changed, 47 insertions(+), 3 deletions(-)
+
+--- a/src/r8126.h
++++ b/src/r8126.h
+@@ -1561,6 +1561,8 @@ enum RTL8126_register_content {
+         LinkStatus = 0x02,
+         FullDup = 0x01,
++#define RTL8126_FULL_DUPLEX_MASK (_5000bpsF | _2500bpsF | _1000bpsF | FullDup)
++
+         /* DBG_reg */
+         Fix_Nak_1 = (1 << 4),
+         Fix_Nak_2 = (1 << 3),
+--- a/src/r8126_n.c
++++ b/src/r8126_n.c
+@@ -39,6 +39,7 @@
+ #include <linux/module.h>
+ #include <linux/version.h>
+ #include <linux/pci.h>
++#include <linux/phy.h>
+ #include <linux/netdevice.h>
+ #include <linux/etherdevice.h>
+ #include <linux/delay.h>
+@@ -4740,6 +4741,40 @@ rtl8126_link_down_patch(struct net_devic
+ #endif
+ }
++static unsigned int rtl8126_phy_duplex(u16 status)
++{
++        unsigned int duplex = DUPLEX_UNKNOWN;
++
++        if (status & LinkStatus) {
++                if (status & RTL8126_FULL_DUPLEX_MASK)
++                        duplex = DUPLEX_FULL;
++                else
++                        duplex = DUPLEX_HALF;
++        }
++
++        return duplex;
++}
++
++static int rtl8126_phy_speed(u16 status)
++{
++        int speed = SPEED_UNKNOWN;
++
++        if (status & LinkStatus) {
++                if (status & _5000bpsF)
++                        speed = SPEED_5000;
++                else if (status & _2500bpsF)
++                        speed = SPEED_2500;
++                else if (status & _1000bpsF)
++                        speed = SPEED_1000;
++                else if (status & _100bps)
++                        speed = SPEED_100;
++                else if (status & _10bps)
++                        speed = SPEED_10;
++        }
++
++        return speed;
++}
++
+ static void
+ _rtl8126_check_link_status(struct net_device *dev)
+ {
+@@ -4748,11 +4783,18 @@ _rtl8126_check_link_status(struct net_de
+         if (tp->link_ok(dev)) {
+                 rtl8126_link_on_patch(dev);
+-                if (netif_msg_ifup(tp))
+-                        printk(KERN_INFO PFX "%s: link up\n", dev->name);
++                if (netif_msg_ifup(tp)) {
++                        const u16 phy_status = RTL_R16(tp, PHYstatus);
++                        const unsigned int phy_duplex = rtl8126_phy_duplex(phy_status);
++                        const int phy_speed = rtl8126_phy_speed(phy_status);
++                        printk(KERN_INFO PFX "%s: Link is Up - %s/%s\n",
++                                dev->name,
++                                phy_speed_to_str(phy_speed),
++                                phy_duplex_to_str(phy_duplex));
++                }
+         } else {
+                 if (netif_msg_ifdown(tp))
+-                        printk(KERN_INFO PFX "%s: link down\n", dev->name);
++                        printk(KERN_INFO PFX "%s: Link is Down\n", dev->name);
+                 rtl8126_link_down_patch(dev);
+         }