[openwrt/openwrt] kernel: r8101: print link status when link up

LEDE Commits lede-commits at lists.infradead.org
Mon Aug 19 03:46:49 PDT 2024


noltari pushed a commit to openwrt/openwrt.git, branch openwrt-23.05:
https://git.openwrt.org/fe8c1fdd242a1e3da995af888a9889211b75c32b

commit fe8c1fdd242a1e3da995af888a9889211b75c32b
Author: Álvaro Fernández Rojas <noltari at gmail.com>
AuthorDate: Sat Aug 17 21:30:35 2024 +0200

    kernel: r8101: print link status when link up
    
    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 at gmail.com>
    (cherry picked from fe0240f27e9df2d0b8c0981741360f2f87b09536)
---
 package/kernel/r8101/Makefile                      |   4 +-
 ...00-r8101-print-link-speed-and-duplex-mode.patch | 100 +++++++++++++++++++++
 2 files changed, 102 insertions(+), 2 deletions(-)

diff --git a/package/kernel/r8101/Makefile b/package/kernel/r8101/Makefile
index d385d8308c..2a09855c05 100644
--- a/package/kernel/r8101/Makefile
+++ b/package/kernel/r8101/Makefile
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=r8101
 PKG_VERSION:=1.039.00
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=https://github.com/openwrt/rtl8101/releases/download/$(PKG_VERSION)
@@ -18,7 +18,7 @@ include $(INCLUDE_DIR)/package.mk
 define KernelPackage/r8101
   SUBMENU:=Network Devices
   TITLE:=Realtek RTL8101 PCI Fast Ethernet driver
-  DEPENDS:=@PCI_SUPPORT
+  DEPENDS:=@PCI_SUPPORT +kmod-libphy
   FILES:=$(PKG_BUILD_DIR)/src/r8101.ko
   AUTOLOAD:=$(call AutoProbe,r8101)
   PROVIDES:=kmod-r8169
diff --git a/package/kernel/r8101/patches/200-r8101-print-link-speed-and-duplex-mode.patch b/package/kernel/r8101/patches/200-r8101-print-link-speed-and-duplex-mode.patch
new file mode 100644
index 0000000000..e112d14168
--- /dev/null
+++ b/package/kernel/r8101/patches/200-r8101-print-link-speed-and-duplex-mode.patch
@@ -0,0 +1,100 @@
+From ec0de750e20073b23c91b67f4bc3ab71c50f0eed Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari at gmail.com>
+Date: Sat, 17 Aug 2024 21:19:54 +0200
+Subject: [PATCH] r8101: 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: Álvaro Fernández Rojas <noltari at gmail.com>
+---
+ src/r8101.h   |  2 ++
+ src/r8101_n.c | 42 +++++++++++++++++++++++++++++++++++++++---
+ 2 files changed, 41 insertions(+), 3 deletions(-)
+
+--- a/src/r8101.h
++++ b/src/r8101.h
+@@ -1162,6 +1162,8 @@ enum RTL8101_register_content {
+         LinkStatus = 0x02,
+         FullDup = 0x01,
+ 
++#define RTL8101_FULL_DUPLEX_MASK (FullDup)
++
+         /* ResetCounterCommand */
+         CounterReset = 0x1,
+         /* DumpCounterCommand */
+--- a/src/r8101_n.c
++++ b/src/r8101_n.c
+@@ -39,6 +39,7 @@ This driver is modified from r8169.c in
+ #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>
+@@ -2838,6 +2839,34 @@ rtl8101_issue_offset_99_event(struct rtl
+         }
+ }
+ 
++static unsigned int rtl8101_phy_duplex(u8 status)
++{
++        unsigned int duplex = DUPLEX_UNKNOWN;
++
++        if (status & LinkStatus) {
++                if (status & RTL8101_FULL_DUPLEX_MASK)
++                        duplex = DUPLEX_FULL;
++                else
++                        duplex = DUPLEX_HALF;
++        }
++
++        return duplex;
++}
++
++static int rtl8101_phy_speed(u8 status)
++{
++        int speed = SPEED_UNKNOWN;
++
++        if (status & LinkStatus) {
++                if (status & _100bps)
++                        speed = SPEED_100;
++                else if (status & _10bps)
++                        speed = SPEED_10;
++        }
++
++        return speed;
++}
++
+ static void
+ rtl8101_check_link_status(struct net_device *dev)
+ {
+@@ -2913,8 +2942,15 @@ rtl8101_check_link_status(struct net_dev
+                         tp->phy_reg_aner = rtl8101_mdio_read(tp, MII_EXPANSION);
+                         tp->phy_reg_anlpar = rtl8101_mdio_read(tp, MII_LPA);
+ 
+-                        if (netif_msg_ifup(tp))
+-                                printk(KERN_INFO PFX "%s: link up\n", dev->name);
++                        if (netif_msg_ifup(tp)) {
++                                const u8 phy_status = RTL_R8(tp, PHYstatus);
++                                const unsigned int phy_duplex = rtl8101_phy_duplex(phy_status);
++                                const int phy_speed = rtl8101_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 (tp->mcfg == CFG_METHOD_11 || tp->mcfg == CFG_METHOD_12 ||
+                             tp->mcfg == CFG_METHOD_13) {
+@@ -2925,7 +2961,7 @@ rtl8101_check_link_status(struct net_dev
+                                 rtl8101_mdio_write(tp, 0x1F, 0x0000);
+                         }
+                         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);
+ 
+                         tp->phy_reg_aner = 0;
+                         tp->phy_reg_anlpar = 0;




More information about the lede-commits mailing list