diff mbox series

[2/3,V2,SRU,OEM-6.0/OEM-5.17] UBUNTU: SAUCE: r8169: Use mutex to guard config register locking

Message ID 20221011020411.1228490-3-koba.ko@canonical.com
State New
Headers show
Series UBUNTU: SAUCE: Can only reach PC3 when ethernet is plugged r8169 | expand

Commit Message

Koba Ko Oct. 11, 2022, 2:04 a.m. UTC
From: Kai-Heng Feng <kai.heng.feng@canonical.com>

BugLink: https://bugs.launchpad.net/bugs/1946433 

Right now r8169 doesn't have parallel access to its config register, but
the next patch will access config register at anytime.

So add a mutex to prevent the race.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
(cherry picked from https://patchwork.kernel.org/project/netdevbpf/patch/20211016075442.650311-5-kai.heng.feng@canonical.com/)
Signed-off-by: Koba Ko <koba.ko@canonical.com>
---
 drivers/net/ethernet/realtek/r8169_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index fd0fbb90f52e8..0fab9a6f6aecd 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -623,6 +623,8 @@  struct rtl8169_private {
 		struct work_struct work;
 	} wk;
 
+	struct mutex config_lock;
+
 	unsigned supports_gmii:1;
 	dma_addr_t counters_phys_addr;
 	struct rtl8169_counters *counters;
@@ -672,12 +674,14 @@  static inline struct device *tp_to_dev(struct rtl8169_private *tp)
 
 static void rtl_lock_config_regs(struct rtl8169_private *tp)
 {
+	mutex_lock(&tp->config_lock);
 	RTL_W8(tp, Cfg9346, Cfg9346_Lock);
 }
 
 static void rtl_unlock_config_regs(struct rtl8169_private *tp)
 {
 	RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
+	mutex_unlock(&tp->config_lock);
 }
 
 static void rtl_pci_commit(struct rtl8169_private *tp)
@@ -5363,6 +5367,8 @@  static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		return rc;
 	}
 
+	mutex_init(&tp->config_lock);
+
 	tp->mmio_addr = pcim_iomap_table(pdev)[region];
 
 	xid = (RTL_R32(tp, TxConfig) >> 20) & 0xfcf;