Skip to content

Commit 8c40d99

Browse files
hkallweitkuba-moo
authored andcommitted
r8169: add helper rtl_csi_mod for accessing extended config space
Add a helper for the Realtek-specific mechanism for accessing extended config space if native access isn't possible. This avoids code duplication. Signed-off-by: Heiner Kallweit <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3b4f78f commit 8c40d99

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,10 +2852,23 @@ static u32 rtl_csi_read(struct rtl8169_private *tp, int addr)
28522852
RTL_R32(tp, CSIDR) : ~0;
28532853
}
28542854

2855+
static void rtl_csi_mod(struct rtl8169_private *tp, int addr,
2856+
u32 mask, u32 set)
2857+
{
2858+
u32 val;
2859+
2860+
WARN(addr % 4, "Invalid CSI address %#x\n", addr);
2861+
2862+
netdev_notice_once(tp->dev,
2863+
"No native access to PCI extended config space, falling back to CSI\n");
2864+
2865+
val = rtl_csi_read(tp, addr);
2866+
rtl_csi_write(tp, addr, (val & ~mask) | set);
2867+
}
2868+
28552869
static void rtl_disable_zrxdc_timeout(struct rtl8169_private *tp)
28562870
{
28572871
struct pci_dev *pdev = tp->pci_dev;
2858-
u32 csi;
28592872
int rc;
28602873
u8 val;
28612874

@@ -2872,16 +2885,12 @@ static void rtl_disable_zrxdc_timeout(struct rtl8169_private *tp)
28722885
}
28732886
}
28742887

2875-
netdev_notice_once(tp->dev,
2876-
"No native access to PCI extended config space, falling back to CSI\n");
2877-
csi = rtl_csi_read(tp, RTL_GEN3_RELATED_OFF);
2878-
rtl_csi_write(tp, RTL_GEN3_RELATED_OFF, csi & ~RTL_GEN3_ZRXDC_NONCOMPL);
2888+
rtl_csi_mod(tp, RTL_GEN3_RELATED_OFF, RTL_GEN3_ZRXDC_NONCOMPL, 0);
28792889
}
28802890

28812891
static void rtl_set_aspm_entry_latency(struct rtl8169_private *tp, u8 val)
28822892
{
28832893
struct pci_dev *pdev = tp->pci_dev;
2884-
u32 csi;
28852894

28862895
/* According to Realtek the value at config space address 0x070f
28872896
* controls the L0s/L1 entrance latency. We try standard ECAM access
@@ -2893,10 +2902,7 @@ static void rtl_set_aspm_entry_latency(struct rtl8169_private *tp, u8 val)
28932902
pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL)
28942903
return;
28952904

2896-
netdev_notice_once(tp->dev,
2897-
"No native access to PCI extended config space, falling back to CSI\n");
2898-
csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff;
2899-
rtl_csi_write(tp, 0x070c, csi | val << 24);
2905+
rtl_csi_mod(tp, 0x070c, 0xff000000, val << 24);
29002906
}
29012907

29022908
static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp)

0 commit comments

Comments
 (0)