[PATCH net-next] net: dlink: add Kconfig option for RMON registers

Moon Yeounsu posted 1 patch 7 months ago
drivers/net/ethernet/dlink/Kconfig | 18 ++++++++++++++++++
drivers/net/ethernet/dlink/dl2k.c  |  2 ++
drivers/net/ethernet/dlink/dl2k.h  |  4 ++++
3 files changed, 24 insertions(+)
[PATCH net-next] net: dlink: add Kconfig option for RMON registers
Posted by Moon Yeounsu 7 months ago
This patch adds a Kconfig option to enable MMIO for RMON registers.

To read RMON registers, the code `dw32(RmonStatMask, 0x0007ffff);`
must also be skipped, so this patch adds a preprocessor directive to
that line as well.

On the `D-Link DGE-550T Rev-A3`, RMON statistics registers can be read
correctly and statistic data can be collected. However, the behavior on
other hardware is uncertain, and there may be undiscovered issues even
on this device. Thus, the default setting is `no`, allowing users to
enable it manually if necessary.

Tested-on: D-Link DGE-550T Rev-A3
Signed-off-by: Moon Yeounsu <yyyynoom@gmail.com>
---
 drivers/net/ethernet/dlink/Kconfig | 18 ++++++++++++++++++
 drivers/net/ethernet/dlink/dl2k.c  |  2 ++
 drivers/net/ethernet/dlink/dl2k.h  |  4 ++++
 3 files changed, 24 insertions(+)

diff --git a/drivers/net/ethernet/dlink/Kconfig b/drivers/net/ethernet/dlink/Kconfig
index e9e13654812c..40c8c861c5a9 100644
--- a/drivers/net/ethernet/dlink/Kconfig
+++ b/drivers/net/ethernet/dlink/Kconfig
@@ -32,4 +32,22 @@ config DL2K
 	  To compile this driver as a module, choose M here: the
 	  module will be called dl2k.
 
+if DL2K
+
+config DL2K_MMIO
+	bool "RMON MMIO"
+	depends on DL2K
+	default n
+	help
+	  Enable memory-mapped I/O for RMON registers.
+
+	  Since this feature may have potential issues,
+	  it should default to 'no'.
+
+	  If unsure, say N.
+
+endif # DL2K
+
 endif # NET_VENDOR_DLINK
+
+
diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
index 232e839a9d07..197142aa63ff 100644
--- a/drivers/net/ethernet/dlink/dl2k.c
+++ b/drivers/net/ethernet/dlink/dl2k.c
@@ -576,7 +576,9 @@ static void rio_hw_init(struct net_device *dev)
 	dw8(TxDMAPollPeriod, 0xff);
 	dw8(RxDMABurstThresh, 0x30);
 	dw8(RxDMAUrgentThresh, 0x30);
+#ifndef MEM_MAPPING
 	dw32(RmonStatMask, 0x0007ffff);
+#endif
 	/* clear statistics */
 	clear_stats (dev);
 
diff --git a/drivers/net/ethernet/dlink/dl2k.h b/drivers/net/ethernet/dlink/dl2k.h
index 0e33e2eaae96..3a13068d89a2 100644
--- a/drivers/net/ethernet/dlink/dl2k.h
+++ b/drivers/net/ethernet/dlink/dl2k.h
@@ -38,6 +38,10 @@
 #define TX_TOTAL_SIZE	TX_RING_SIZE*sizeof(struct netdev_desc)
 #define RX_TOTAL_SIZE	RX_RING_SIZE*sizeof(struct netdev_desc)
 
+#ifdef CONFIG_DL2K_MMIO
+#define MEM_MAPPING
+#endif
+
 /* Offsets to the device registers.
    Unlike software-only systems, device drivers interact with complex hardware.
    It's not useful to define symbolic names for every register bit in the
-- 
2.49.0
Re: [PATCH net-next] net: dlink: add Kconfig option for RMON registers
Posted by Jakub Kicinski 7 months ago
On Tue, 20 May 2025 06:40:45 +0900 Moon Yeounsu wrote:
> This patch adds a Kconfig option to enable MMIO for RMON registers.
> 
> To read RMON registers, the code `dw32(RmonStatMask, 0x0007ffff);`
> must also be skipped, so this patch adds a preprocessor directive to
> that line as well.
> 
> On the `D-Link DGE-550T Rev-A3`, RMON statistics registers can be read
> correctly and statistic data can be collected. However, the behavior on
> other hardware is uncertain, and there may be undiscovered issues even
> on this device. Thus, the default setting is `no`, allowing users to
> enable it manually if necessary.

Kconfig is not a great choice for chip specific logic.
You should check some sort of chip ID register or PCI ID
to match the chip version at runtime. Most users don't compile
their own kernels.
-- 
pw-bot: cr
Re: [PATCH net-next] net: dlink: add Kconfig option for RMON registers
Posted by Moon Yeounsu 7 months ago
On Mon, May 19, 2025 at 04:57:58PM -0700, Jakub Kicinski wrote:
> On Tue, 20 May 2025 06:40:45 +0900 Moon Yeounsu wrote:
> Kconfig is not a great choice for chip specific logic.
> You should check some sort of chip ID register or PCI ID
> to match the chip version at runtime. Most users don't compile
> their own kernels.

Just to confirm. are you suggesting that RMON MMIO should be enabled
only on hardware known to support it correctly, instaed of exposing it
via Kconfig?

Then, I'll drop the Kconfig option and enable RMON MMIO only for
known-good devices via a runtime check. Currently, that's limited to
DGE-550T (`0x4000`) with revision A3 (`0x0c`).

The `dw32(RmonStatMask, 0x0007ffff);` line will also be skipped
accordingly.

Let me know if you have any concerns. Otherwise, I'll send a revisied
patch.

Thank you for reviewing,
Yeounsu
Re: [PATCH net-next] net: dlink: add Kconfig option for RMON registers
Posted by Jakub Kicinski 7 months ago
On Thu, 22 May 2025 15:20:55 +0900 Moon Yeounsu wrote:
> On Mon, May 19, 2025 at 04:57:58PM -0700, Jakub Kicinski wrote:
> > On Tue, 20 May 2025 06:40:45 +0900 Moon Yeounsu wrote:
> > Kconfig is not a great choice for chip specific logic.
> > You should check some sort of chip ID register or PCI ID
> > to match the chip version at runtime. Most users don't compile
> > their own kernels.  
> 
> Just to confirm. are you suggesting that RMON MMIO should be enabled
> only on hardware known to support it correctly, instaed of exposing it
> via Kconfig?
> 
> Then, I'll drop the Kconfig option and enable RMON MMIO only for
> known-good devices via a runtime check. Currently, that's limited to
> DGE-550T (`0x4000`) with revision A3 (`0x0c`).
> 
> The `dw32(RmonStatMask, 0x0007ffff);` line will also be skipped
> accordingly.

Yes, sounds like that's along the lines of my suggestion.