From 5f8e52f3991c794be69af13170e5c54e5afe0674 Mon Sep 17 00:00:00 2001
From: Chukun Pan <amadeus@jmu.edu.cn>
Date: Sun, 5 Jan 2025 18:08:29 +0800
Subject: [PATCH] r8169: LED uses original network port name

Most Linux distributions use Predictable Network Interface Names
to name PCIe network interfaces (systemd-udevd renames them).
Since OpenWrt doesn't use this, let's use the original network
port name in the driver to match the LED.

Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
---

--- a/drivers/net/ethernet/realtek/r8169.h
+++ b/drivers/net/ethernet/realtek/r8169.h
@@ -84,8 +84,6 @@ u8 rtl8168d_efuse_read(struct rtl8169_pr
 void r8169_hw_phy_config(struct rtl8169_private *tp, struct phy_device *phydev,
 			 enum mac_version ver);
 
-void r8169_get_led_name(struct rtl8169_private *tp, int idx,
-			char *buf, int buf_len);
 int rtl8168_get_led_mode(struct rtl8169_private *tp);
 int rtl8168_led_mod_ctrl(struct rtl8169_private *tp, u16 mask, u16 val);
 struct r8169_led_classdev *rtl8168_init_leds(struct net_device *ndev);
--- a/drivers/net/ethernet/realtek/r8169_leds.c
+++ b/drivers/net/ethernet/realtek/r8169_leds.c
@@ -129,14 +129,13 @@ static struct device *
 static void rtl8168_setup_ldev(struct r8169_led_classdev *ldev,
 			       struct net_device *ndev, int index)
 {
-	struct rtl8169_private *tp = netdev_priv(ndev);
 	struct led_classdev *led_cdev = &ldev->led;
 	char led_name[LED_MAX_NAME_SIZE];
 
 	ldev->ndev = ndev;
 	ldev->index = index;
 
-	r8169_get_led_name(tp, index, led_name, LED_MAX_NAME_SIZE);
+	snprintf(led_name, sizeof(led_name), "%s-%d::lan", ndev->name, index);
 	led_cdev->name = led_name;
 	led_cdev->hw_control_trigger = "netdev";
 	led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN;
@@ -228,14 +227,13 @@ static int rtl8125_led_hw_control_get(st
 static void rtl8125_setup_led_ldev(struct r8169_led_classdev *ldev,
 				   struct net_device *ndev, int index)
 {
-	struct rtl8169_private *tp = netdev_priv(ndev);
 	struct led_classdev *led_cdev = &ldev->led;
 	char led_name[LED_MAX_NAME_SIZE];
 
 	ldev->ndev = ndev;
 	ldev->index = index;
 
-	r8169_get_led_name(tp, index, led_name, LED_MAX_NAME_SIZE);
+	snprintf(led_name, sizeof(led_name), "%s-%d::lan", ndev->name, index);
 	led_cdev->name = led_name;
 	led_cdev->hw_control_trigger = "netdev";
 	led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN;
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -980,28 +980,6 @@ int rtl8125_get_led_mode(struct rtl8169_
 	return ret;
 }
 
-void r8169_get_led_name(struct rtl8169_private *tp, int idx,
-			char *buf, int buf_len)
-{
-	struct pci_dev *pdev = tp->pci_dev;
-	char pdom[8], pfun[8];
-	int domain;
-
-	domain = pci_domain_nr(pdev->bus);
-	if (domain)
-		snprintf(pdom, sizeof(pdom), "P%d", domain);
-	else
-		pdom[0] = '\0';
-
-	if (pdev->multifunction)
-		snprintf(pfun, sizeof(pfun), "f%d", PCI_FUNC(pdev->devfn));
-	else
-		pfun[0] = '\0';
-
-	snprintf(buf, buf_len, "en%sp%ds%d%s-%d::lan", pdom, pdev->bus->number,
-		 PCI_SLOT(pdev->devfn), pfun, idx);
-}
-
 static void r8168fp_adjust_ocp_cmd(struct rtl8169_private *tp, u32 *cmd, int type)
 {
 	/* based on RTL8168FP_OOBMAC_BASE in vendor driver */
