Commit Graph

98 Commits

Author SHA1 Message Date
Thomas Martitz
c8c187f0f0 realtek: add support for RTL8218E
ZyXEL XGS1250-12 Rev.B1 has RTL8218E compared to RTL8218D in Rev.A1
but both of them seem very similar and pin compatible. Therefore
they can share the same phy_driver callbacks.

PHY identifier is set based on the datasheet from
  https://github.com/plappermaul/realtek-doc/blob/main/RTL8218E-CG_Datasheet.pdf

Before:

[    2.120161] rtl83xx-switch switch@1b000000 lan1 (uninitialized): PHY [mdio-bus:00] driver [Generic PHY] (irq=POLL)
[    2.134581] rtl83xx-switch switch@1b000000 lan2 (uninitialized): PHY [mdio-bus:01] driver [Generic PHY] (irq=POLL)
[    2.149043] rtl83xx-switch switch@1b000000 lan3 (uninitialized): PHY [mdio-bus:02] driver [Generic PHY] (irq=POLL)
[    2.163498] rtl83xx-switch switch@1b000000 lan4 (uninitialized): PHY [mdio-bus:03] driver [Generic PHY] (irq=POLL)
[    2.177963] rtl83xx-switch switch@1b000000 lan5 (uninitialized): PHY [mdio-bus:04] driver [Generic PHY] (irq=POLL)
[    2.192435] rtl83xx-switch switch@1b000000 lan6 (uninitialized): PHY [mdio-bus:05] driver [Generic PHY] (irq=POLL)
[    2.207009] rtl83xx-switch switch@1b000000 lan7 (uninitialized): PHY [mdio-bus:06] driver [Generic PHY] (irq=POLL)
[    2.221474] rtl83xx-switch switch@1b000000 lan8 (uninitialized): PHY [mdio-bus:07] driver [Generic PHY] (irq=POLL)

After:

[    2.119165] rtl83xx-switch switch@1b000000 lan1 (uninitialized): PHY [mdio-bus:00] driver [REALTEK RTL8218E] (irq=POLL)
[    2.132880] rtl83xx-switch switch@1b000000 lan2 (uninitialized): PHY [mdio-bus:01] driver [REALTEK RTL8218E] (irq=POLL)
[    2.146727] rtl83xx-switch switch@1b000000 lan3 (uninitialized): PHY [mdio-bus:02] driver [REALTEK RTL8218E] (irq=POLL)
[    2.160580] rtl83xx-switch switch@1b000000 lan4 (uninitialized): PHY [mdio-bus:03] driver [REALTEK RTL8218E] (irq=POLL)
[    2.174367] rtl83xx-switch switch@1b000000 lan5 (uninitialized): PHY [mdio-bus:04] driver [REALTEK RTL8218E] (irq=POLL)
[    2.188270] rtl83xx-switch switch@1b000000 lan6 (uninitialized): PHY [mdio-bus:05] driver [REALTEK RTL8218E] (irq=POLL)
[    2.202140] rtl83xx-switch switch@1b000000 lan7 (uninitialized): PHY [mdio-bus:06] driver [REALTEK RTL8218E] (irq=POLL)
[    2.216047] rtl83xx-switch switch@1b000000 lan8 (uninitialized): PHY [mdio-bus:07] driver [REALTEK RTL8218E] (irq=POLL)

Based-on-patch-by: Antanas Bruzas <antanas.bruzas@protonmail.com>
Signed-off-by: Thomas Martitz <thomas.martitz@mailbox.org>
Link: https://github.com/openwrt/openwrt/pull/20068
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-22 01:15:12 +02:00
Markus Stockhausen
fe27cce1ec realtek: add SerDes PCS driver
Until now the the SerDes configuration is realized with helper functions
scattered around the DSA and PHY driver. Give them a new home as a PCS
driver.

The target design is as follows:

- dsa driver manages switch
- pcs driver manages SerDes on high level (this commit)
- mdio driver manages SerDes on low level

This driver adds the high level SerDes access via PCS. It makes use of
the low level mdio SerDes driver to access the registers.

Remark: This initial version provides exactly all phylink_pcs_ops that
are currently part of the DSA driver. So this can be swapped in one of
the next commits as a drop in replacement. To make use of it something
like this is needed:

...
ports = of_get_child_by_name(node, "ethernet-ports");
if (!ports)
	return -EINVAL;

for_each_available_child_of_node(ports, port) {
	pcs_node = of_parse_phandle(port, "pcs-handle", 0);
	of_property_read_u32(port, "reg", &port_nr)) {

	priv->pcs[port_nr] = rtpcs_create(dev, pcs_node, port_nr);
}
...

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20075
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-20 12:51:23 +02:00
Markus Stockhausen
e2271a1dab realtek: mdio: register SerDes bus so it can be looked up
The upcoming PCS driver will lookup the SerDes mdio bus via
of_mdio_find_bus() and the devicetree. This is only possible
with proper registration via devm_of_mdiobus_register().

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20078
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-18 10:44:36 +02:00
Markus Stockhausen
bb783e8548 realtek: mdio: Simplify backing SerDes calculation
No need two write a dedicated 1:1 mapping function and link that
for all the targets except RTL931x. Combine everything into a generic
helper and reduce the configuration structure.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20078
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-18 10:44:35 +02:00
Markus Stockhausen
ab49297334 realtek: mdio: fix non-debug SerDes builds
The new SerDes mdio driver produces the following compilation
error in non-debug builds.

drivers/net/mdio/mdio-realtek-otto-serdes.c:72:12:
error: 'rtsds_sds_to_mmd' defined but not used [-Werror=unused-function]
   72 | static int rtsds_sds_to_mmd(int sds_page, int sds_regnum)
      |            ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Move the function into the debug section.

Fixes: 7a7ee72c4d ("realtek: mdio: add SerDes driver")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20078
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-18 10:44:35 +02:00
Markus Stockhausen
7a7ee72c4d realtek: mdio: add SerDes driver
Until now the SerDes access is realized with some helper functions
in the mdio bus. These were moved around a lot and had no real home.
End that temporary solution to move them where they belong.

The target design for the different Realtek drivers is as follows:

- dsa driver manages switch
- pcs driver manages SerDes on high level (to be developed)
- mdio driver manages SerDes on low level (this commit)

This driver adds the low level SerDes access via mdio. For debugging
purposes the user can interact with the SerDes in different ways.

First, there is a debug interface in
/sys/kernel/debug/realtek_otto_serdes/serdes.X/registers.
With that a dump of all registers can be shown.

> cat /sys/kernel/debug/realtek_otto_serdes/serdes.4/registers
Back SDS  4:   00   01   02   03   04   05   06   07   08
SDS        : 0C03 0F00 7060 7106 074D 0EBF 0F0F 0359 5248
SDS_EXT    : 0000 0000 85FA 8C6D 5CCC 0000 20D8 0003 79AA
...

Second, one can read/write registers via the mmd functions of the
mdio command line tool. Important to know: The registers are accessed
on the vendor specific MDIO_MMD_VEND1 device address (=30). Additionally
the SerDes page and register are concatenated into the the mmd register.
Top 8 bits are SerDes page and bottom 8 bits are SerDEs register.
E.g.

- mmd 0x0206 : SerDes page 0x02, SerDes register 0x06
- mmd 0x041f : SerDes page 0x04, SerDes register 0x1f

Read register 0x02 on page 0x03 of SerDes 0
> mdio realtek-serdes-mdio mmd 0:30 raw 0x0302

Write register 0x12 on page 0x02 of SerDes 1
> mdio realtek-serdes-mdio mmd 1:30 raw 0x0212 0x2222

For now this driver is only defined in the devicetree and activated
in the kernel build. There is no current consumer but at least
the debugging interface is available. Cleanup of the currently used
SerDes functions will come later.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20062
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-17 19:23:15 +02:00
Markus Stockhausen
60bdae3ab3 realtek: ethernet: drop open coding
There is some open coding in the ethernet driver. Drop
that and use kernel helpers instead.

- Use napi_gro_receive() instead of local skb list
- Use skb_put_data() instead of skb_put() plus memcpy()
- Use netdev_alloc_skb_ip_align() instead of manual alignment

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20030
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-17 19:22:37 +02:00
Markus Stockhausen
532c51c15a realtek: Increase verbosity in rtldsa_fib4_add()/rtldsa_fib4_del()
L3 routing in Realtek switches is some magic voodoo. Especially
the syslog messages are not helpful at all for error diagnosis. As
a first step refactor rtldsa_fib4_add() and rtldsa_fib4_del() to
get some idea what is going on. For this add a helper function
rtldsa_fib4_check() for basic sanity checks and logging.

Do not only increase verbosity but fix some coding as well.

- Drop leftover checks for subnet 192.168.100.x
- Better detection of broadcast routes
- clearer MAC/VLAN formatting
- sort variables descending
- rename 1 char variable "r" to "route"
- change log helpers from pr...() to dev_...()

Before:

[    5.640463] rtl83xx_fib_event_work_do: FIB4 default rule failed
[    5.647164] rtl83xx_fib_event_work_do: FIB4 default rule failed
[   13.975386] rtl83xx_fib_event_work_do: FIB4 failed
[   13.981456] rtl83xx_fib_event_work_do: FIB4 failed
[   13.986906] rtl83xx_fib_event_work_do: FIB4 failed
[   18.455777] rtl83xx_fib4_del: no such gateway: 0.0.0.0
[   18.470993] rtl83xx_fib4_del: no such gateway: 0.0.0.0
[   18.476839] rtl83xx_fib4_del: no such gateway: 0.0.0.0

After:

[   13.812501] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.1.1/32 (VLAN 0, MAC 80:00:37:74:80:00)
[   13.823501] rtl83xx-switch switch@1b000000: lower interface lan1 not found
[   13.831371] rtl83xx-switch switch@1b000000: fib_add() failed
[   13.848157] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.1.255/32 (VLAN 0, MAC 80:00:37:74:80:00)
[   13.859264] rtl83xx-switch switch@1b000000: skip loopback/broadcast address
[   13.883086] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.1.0/24 (VLAN 0, MAC 80:00:37:74:80:00)
[   13.894051] rtl83xx-switch switch@1b000000: lower interface lan1 not found
[   13.902009] rtl83xx-switch switch@1b000000: fib_add() failed
[   18.342938] rtl83xx-switch switch@1b000000: delete IPv4 route 192.168.1.0/24 (VLAN 0, MAC 80:00:37:74:80:00)
[   18.354162] rtl83xx-switch switch@1b000000: no such gateway: 0.0.0.0
[   18.361483] rtl83xx-switch switch@1b000000: fib_del() failed
[   18.378327] rtl83xx-switch switch@1b000000: delete IPv4 route 192.168.1.255/32 (VLAN 0, MAC 80:00:37:74:80:00)
[   18.389736] rtl83xx-switch switch@1b000000: skip loopback/broadcast address
[   18.419856] rtl83xx-switch switch@1b000000: delete IPv4 route 192.168.1.1/32 (VLAN 0, MAC 80:00:37:74:80:00)
[   18.431160] rtl83xx-switch switch@1b000000: no such gateway: 0.0.0.0
[   18.438452] rtl83xx-switch switch@1b000000: fib_del() failed
[   54.570217] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.2.71/32 (VLAN 1, MAC d8:ec:5e:5b:7d:a1)
[   54.581329] rtl83xx-switch switch@1b000000: route hashtable extended for gw 0.0.0.0
[   54.638792] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.2.255/32 (VLAN 1, MAC d8:ec:5e:5b:7d:a1)
[   54.649913] rtl83xx-switch switch@1b000000: skip loopback/broadcast address
[   54.780897] rtl83xx-switch switch@1b000000: add IPv4 route 192.168.2.0/24 (VLAN 1, MAC d8:ec:5e:5b:7d:a1)
[   54.791883] rtl83xx-switch switch@1b000000: route hashtable extended for gw 0.0.0.0

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20029
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-17 19:21:58 +02:00
Markus Stockhausen
d4893b816c realtek: rtl931x: rename SerDes read/write helpers
During SerDes rework the helper functions were temporarily
renamed to ..._new(). Fix the leftovers by

- giving the functions a new rtsds_ prefix nad
- dropping the _new appendix.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20034
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-14 11:10:07 +02:00
Markus Stockhausen
61b72cb736 realtek: drop usage of proprietary HSGMII mode
The only consumers of the Realtek HSGMII (2.5G SGMII) mode were
the RTL8226/RTL8221B PHYs. These have been converted to dynamic
SGMII/2500base-x mode switching. Drop the leftovers of the mode
implementation.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/20002
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-12 21:00:08 +02:00
Markus Stockhausen
57b2706845 realtek: dts: rearrange mdio-bus below mdio-controller
The mdio controller got its own dts node with a dedicated bus node.
Until now it still searches the phy nodes in the ethernet node.

Change the driver so it searches the nodes at the right location.
For this to work move the phy nodes in all dts/dtsi over to the new
bus node. Use the following replacement rule:

Replace old full declaration

&ethernet0 {
  mdio-bus {
    ...
  };
};

and old abbreviated declaration

&mdio {
  ...
};

simply with the new declaration

&mdio_bus0 {
  ...
};

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19986
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-12 20:58:17 +02:00
Markus Stockhausen
616559b6d3 realtek: mdio: convert mdio bus to new device nodes and compatibles
The mdio controller has now its own target specific device nodes. This
is much closer to upstream notation. Adapt the driver to make use of it.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19986
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-12 20:58:17 +02:00
Markus Stockhausen
69ce2eeb97 realtek: rtl931x: align SerDes access with other targets
While converting the RTL931x SerDes code to the new frontend
access methods, the target specific workarounds where left in
place. The old functions were kept and the phy/sds mapping
was unchanged too. It is time to clean this up

- drop the old functions
- reuse the existing read/write logic
- harden the new functions

For now keep the function naming rtmdio_...__new() as is. This
will be changed in a future commit.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19973
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-12 20:52:37 +02:00
Markus Stockhausen
fcd3ce6954 realtek: carve out mdio bus from ethernet driver
So much code was distributed between phy/ethernet/dsa drivers. A lot
was already cleand up before. With this step the mdio bus gets its
own space and is no longer hidden inside the ethernet driver.

This commit is mostly a copy/paste that includes only minor changes.

- define prefixes are renamed to RTMDIO
- The driver is totally self contained (does not rely on SoC include)
- The DTS structure (mdio node below ethernet node) was kept
- The driver is added to the kernel config of all subtargets.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19942
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-07 11:37:59 +02:00
Markus Stockhausen
3fae46d5cc realtek: early ethernet probe in dsa setup
The ethernet and mdio code will be splitted. The dsa driver depends
on proper loading of both, before switch setup can start. Sadly there
are severe cleanup issues in the probe() function if one of the
required devices is not available.

As a temporary workaround provide a dedicated check function that
verifies if the ethernet platform device driver is loaded and can
be used.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19942
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-07 11:37:59 +02:00
Markus Stockhausen
2420a77556 realtek: make NAPI polling thread safe
At the end of RX NAPI polling the counter and mask registers are
cleaned up. Although this might run in parallel there is no
synchronization and the register modifications are some wild mix.
RTL83xx enables only the interrupt of a single ring while RTL93xx
just reactivates all interrupts (even for other NAPI threads).
Make use of the driver lock and only modify the interrupt bits that
the current thread owns.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19960
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-07 11:36:01 +02:00
Markus Stockhausen
e3ccd1a287 realtek: RTL93xx: do not drop packets in software
Now that the counter registers work fine there is no need to
free buffers in software. Hardware will automatically block
input processing when software processing is too slow.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19960
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-07 11:36:00 +02:00
Markus Stockhausen
a93e725140 realtek: RTL93xx: Make use of correct ring size counters
The receive path of the RTL93xx SoCs is currently discarding packets
in software. Analysis gives the following explanation:

- RX ring size registers are setup with the full software ring size
- When packets are received the packet counter registers are increased
- After RX processing the counter registers are changed the wrong way
- From then SOC is allowed to receive more packets than software allows
- Overflow interrupts are fired
- As a reaction to that the software drops packets

Change the processing as follows:

- Setup ring size registers with a headroom of 2 buffers
- Decrease the counter registers with the real work done

With this change no more overflow interrupts occur because the SoC
disables the queues before they can overflow or hit a buffer that is
still owned by the CPU.

Benchmark from single stream iperf3 run, with server process running
on ZyXEL XGS1210 (RTL930x).

iperf3 run before

-----------------------------------------------------------
Server listening on 5201 (test #1)
-----------------------------------------------------------
Accepted connection from 192.168.2.86, port 54412
[  5] local 192.168.2.71 port 5201 connected to 192.168.2.86 port 54418
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec   384 KBytes  3.14 Mbits/sec
[  5]   1.00-2.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   2.00-3.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   3.00-4.01   sec  5.12 MBytes  42.8 Mbits/sec
[  5]   4.01-5.00   sec  11.4 MBytes  95.8 Mbits/sec
[  5]   5.00-6.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   6.00-7.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   7.00-8.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   8.00-9.00   sec  0.00 Bytes  0.00 bits/sec
[  5]   9.00-10.00  sec  0.00 Bytes  0.00 bits/sec

iperf3 run after

-----------------------------------------------------------
Server listening on 5201 (test #1)
-----------------------------------------------------------
Accepted connection from 192.168.2.86, port 55228
[  5] local 192.168.2.71 port 5201 connected to 192.168.2.86 port 55232
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  22.8 MBytes   191 Mbits/sec
[  5]   1.00-2.01   sec  25.4 MBytes   211 Mbits/sec
[  5]   2.01-3.00   sec  25.4 MBytes   215 Mbits/sec
[  5]   3.00-4.01   sec  26.5 MBytes   220 Mbits/sec
[  5]   4.01-5.00   sec  26.2 MBytes   222 Mbits/sec
[  5]   5.00-6.00   sec  26.9 MBytes   225 Mbits/sec
[  5]   6.00-7.00   sec  27.0 MBytes   226 Mbits/sec
[  5]   7.00-8.01   sec  26.9 MBytes   224 Mbits/sec
[  5]   8.01-9.00   sec  26.5 MBytes   223 Mbits/sec
[  5]   9.00-10.00  sec  26.8 MBytes   225 Mbits/sec
[  5]  10.00-10.02  sec   640 KBytes   224 Mbits/sec

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19960
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-07 11:36:00 +02:00
Markus Stockhausen
3d7b0bc5c1 realtek: drop RTL8226/RTL8221B downstream PHY driver
Since we are using upstream PHY drivers there is no more need
for the downstream version. Side effect is that the SoC dependent
polling functions are no longer needed. This was always wrong
in this driver.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19906
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-05 13:35:39 +02:00
Sven Eckelmann
d2beb6bdc4 realtek: rtl931x: Fix unsafe MAC_L2_GLOBAL_CTRL2 access
Registers must not be accessed in parallel by multiple drivers.
Read-modify-write operations are not atomic, and the result of parallel
access is undefined.

The MAC_L2_GLOBAL_CTRL2 register is essentially a pin configuration
register and is represented by a pinmux node in the devicetree.  Operations
on this register by the realtek,rtl838x-eth driver must therefore also be
reflected in the devicetree.

Since the MDIO sets used are board-specific, the pins must be enabled in
the board’s devicetree.  This can be achieved using the pinctrl properties
for the realtek,rtl83xx-switch.

    &switch0 {
    	pinctrl-names = "default";
    	pinctrl-0 = <&pinmux_enable_mdc_mdio_0>,
    		    <&pinmux_enable_mdc_mdio_1>;
    	....
    };

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Link: https://github.com/openwrt/openwrt/pull/19815
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-03 09:54:51 +02:00
Christian Marangi
08a616b216
generic: backport support for Aeonsemi AS21xxx PHY
Backport support for Aeonsemi AS121xxx PHY. The PHY require dedicated
firmware to be loaded to correctly work and support a big family of
Aeonsemi PHY that provide from 1G to 10G speed.

Automatically refresh all affected patch and file (rtl PHY).

Link: https://github.com/openwrt/openwrt/pull/19816
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2025-09-03 00:58:48 +02:00
Markus Stockhausen
a8e3bff523 realtek: convert access to RTL931x "even CMU" serdes pages
Currently the calculation for the CMU (even) SerDes works similar
to this pseudo code.

analog_backend_serdes = get_analog_serdes(frontend_serdes);
even_backend_serdes = analog_backend_serdes & ~1;
write_to(even_backend_serdes);

Because of the SerDes layout and frontend/backend mapping this can
be swapped to the following order with the same resulting Serdes.

even_frontend_serdes = frontend_serdes ~1;
analog_backend_serdes = get_analog_serdes(even_frontend_serdes);
write_to(analog_backed_serdes);

In the later example the frontend/backend mapping code is already
in our new functions. So swap the calculation logic and use the
new access functions. This allows to finally drop the old access
functions without mapping.

From now on all RTL931x SerDes functions will use a consistent
frontend view.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19873
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-02 00:51:43 +02:00
Markus Stockhausen
207ab9c36a realtek: convert access to RTL931x "digital 2" serdes pages
The RTL931x has 14 frontend and at least 26 backend serdes. Currently
the programming functions always need to determine the right backend
serdes from the given frontend serdes on their own. We plan to provide
a consistent serdes mapping to all callers.

As the third step make use of these new functions whenever we want to
access the "digital 2" pages. The pages are mapped starting at 0x200.
So the function conversion is as simple as this:

Old:
dsds = (sds - 1) * 2;
rtmdio_931x_read_sds_phy(dsds + 1, page, ...)

New:
rtmdio_931x_read_sds_phy_new(sds, page + 0x200, ...)

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19873
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-02 00:51:43 +02:00
Markus Stockhausen
6802cd7f15 realtek: adapt RTl931x "digital 2" serdes page calculation
The more we step down into the SerDes deeps the more confusing it
gets. Nevertheless it is not to late to fix a wrong assumption.
Until now it seemed as if the frontend/backend SerDes mapping is
totally without intersection. This is not true.

The backend SerDes mapping is also dependent on the mode. Especially
the proprietary Realtek XSGMII mode stands out from all other
mappings. So fix the descriptions and the calculation of the third
page package (digital 2 aka XSGMII 2).

As it was not yet used it had no impact.

Fixes: a4cbb44c1b ("realtek: convert access to RTL931x analog serdes pages")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19873
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-02 00:51:43 +02:00
Markus Stockhausen
4063d90400 realtek: convert access to RTL931x "digital 1" serdes pages
The RTL931x has 14 frontend and at least 26 backend serdes. Currently
the programming functions always need to determine the right backend
serdes from the given frontend serdes on their own. We plan to provide
a consistent serdes mapping to all callers.

As the second step make use of these new functions whenever we
want to access the digital 1 pages. The pages are mapped starting
at 0x100. So the function conversion is as simple as this:

Old:
dsds = (sds - 1) * 2;
rtmdio_931x_read_sds_phy(dsds, page, ...)

New:
rtmdio_931x_read_sds_phy_new(sds, page + 0x100, ...)

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19873
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-09-02 00:51:43 +02:00
Markus Stockhausen
0008b4ed07 realtek: RTL838x: remove artifical mdio delays
For some reason 3 of the 4 mdio access functions contain an
artifical delay of 10ms. While it might have been part of
older Realtek SDKs it can no longer be found in current ones.
Remove the delays.

While we are here remove the pre-access bus ready checks.
It is sufficient to run them after the command start. If
anything fails the caller will get an error. This is the
same behaviour as for the other targets.

Finally cleanup the error handling. Something like this makes
no sense at all.

  err = rtmdio_838x_smi_wait_op(100000);
  if (err)
    goto errout;
  err = 0;
errout:

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19901
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-09-01 10:48:09 +02:00
Damien Dejean
886382ba25 realtek: add 2500base-x patch sequence.
Adds the SerDes patch sequence for 2500base-x to improve the support of
devices with minimal bootloaders (like BootBase). The sequences were
imported from [1] for even lanes and [2] for odd lanes.

[1] https://github.com/ddejean/dms-1250-oss-release/blob/main/sdk/sdk_rtk_switch/rtk-sdk/src/dal/longan/dal_longan_construct.c#L641
[2] https://github.com/ddejean/dms-1250-oss-release/blob/main/sdk/sdk_rtk_switch/rtk-sdk/src/dal/longan/dal_longan_construct.c#L664

Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/19834
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 01:12:05 +02:00
Damien Dejean
6bb1b7cbbf realtek: allow different serdes patch sequences
Prepare the SerDes patch function to allow different patch sequences
depending on the phy mode. Patches are required to allow devices with a
lightweight bootloader (one that doesn't have a "rtk network init"
command) to use the serdes. Some modes required a different patch
sequence than the one currently used.

Signed-off-by: Damien Dejean <dam.dejean@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/19834
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 01:12:05 +02:00
Markus Stockhausen
d5ad59ffb1 realtek: phy: add RTL8214x/RTL8218x patch helper
The patching sequence of the RTL8214x/8218x is very similar.
Especially the preparation for readiness is always the same.
Provide a common helper to improve readability.

While we are here clean up the changed functions

- Sort variable definitions according to upstream
- simplify some messages

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19810
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 00:18:18 +02:00
Markus Stockhausen
6e416149d7 realtek: phy: drop use of mdio package functions
Our phy driver can handle some multiport phys (e.g. RTL8218B
or RTL8214FC). To access arbitrary ports some package access
functions have been defined. These were implemented in the
mdio bus with poor knowledge about the phy/mdio dependencies.
So they add unneeded complexity to the bus and the phy driver
must access these external functions directly.

Provide a new helper get_package_phy() that can derive any
phy device in a package from a given phy of that package.
Make use of this local helper and cut the mdio dependency.

While we refactor several firmware patching functions rename
the loop variables to "port" to better indicate what we are
working on.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19810
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 00:18:18 +02:00
Markus Stockhausen
fa1b362ae9 realtek: simplify RTL8214FC handling
Now that we have a get_base_phy() function a lot code of the RTL8214FC
handling can be cleaned up. To name a few:

- use phy_read/phy_write instead of mdiobus functions or the even worse
  phy_package_..._paged() helpers
- replace messages with phydev_info()
- remove if/else statements around copper/fibre handling

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19810
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 00:18:18 +02:00
Markus Stockhausen
a1043fda8b realtek: phy: late phy package patching
Currently phy packages (like RTL8214x/RTL8218x) are patched and
initialized as soon as the first phy of the package is found.
In this situation the shared structure is not finalized because
devm_phy_package_join() has only been called for the first phy.
This is no issue as the patching directly hammers the bus addresses
for the follow-up phys.

In the future we want to simplify the package handling and allow
to access all phy_device structures from only one phy_device of
the package. With this we can use normal phy_read/phy_write.

Switch the probing logic to "late patching". With this we will
initialize the firmware of the package when the last phy of the
package has been found and thus the shared structure is complete.

Provide get_base_phy() as the first package helper that allows
to determine the first phy of the package from any other phy.

While we are here drop the shared structure that only repeats the
phy name and has no other use.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19810
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-30 00:18:18 +02:00
Harshal Gohel
5880f345ba realtek: Fix nvmem support for ethernet device
The function of_get_mac_address is not taking care of evaluation the nvmem
address before trying to read out the mac-address properties. The driver
must check whether the return code is -EPROBE_DEFER and stop the probing
process in that case. If the nvmem-cell related driver code finished, the
probe can be redone ad the correct mac-address will appear for the device.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19362
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-28 21:07:57 +02:00
Harshal Gohel
18077d22e9 realtek: rtl93xx: Trap LLDP management frames
LLDP packets must be transmitted on a single port and trapped on a port of
a device which understands LLDP. It must not forward it to other ports to
avoid confusing neighbor information on connected devices.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19571
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-26 23:44:08 +02:00
Harshal Gohel
43dbc6d4d6 realtek: rtl931x: Register support for trapping management frames
Driver needs to configure management frame actions
To support LLDP, EAPOL or MSTP, which needs to be trapped to the CPU
instead of being forwarded.

The function to implement the various management frame actions was already
present but not yet registered correctly.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19571
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-26 23:44:08 +02:00
Harshal Gohel
75fe6b2d0b realtek: rtl930x: Add support for trapping management frames
Driver needs to configure management frame actions
To support LLDP, EAPOL or MSTP, which needs to be trapped to the CPU
instead of being forwarded

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19571
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-26 23:44:08 +02:00
Harshal Gohel
1b436585a2 realtek: dsa: Fix prefix for trapping functions
The functions to enable trapping of management frames are not RTL83xx
specific. It is more appropriate to use the more generic "rtldsa" prefix
for them.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19571
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-26 23:44:08 +02:00
Markus Stockhausen
a4cbb44c1b realtek: convert access to RTL931x analog serdes pages
The RTL931x has 14 frontend and at least 26 backend serdes. Currently
the programming functions always need to determine the right backend
serdes from the given frontend serdes on their own.

We plan to provide a consistent serdes mapping to all callers as follows

Frontend SerDes  |  0  1  2  3  4  5  6  7  8  9 10 11 12 13
-----------------+------------------------------------------
Backend SerDes 1 |  0  1  2  3  6  7 10 11 14 15 18 19 22 23
Backend SerDes 2 |  0  1  2  4  6  8 10 12 14 16 18 20 22 24
Backend SerDes 3 |  0  1  2  5  6  9 10 13 14 17 18 21 22 25

frontend page               "even" frontend SerDes     "odd" frontend SerDes
page 0x000-0x03f (analog):  page 0x000-0x03f back SDS  page 0x000-0x03f back SDS
page 0x100-0x13f (XSGMII1): page 0x000-0x03f back SDS  page 0x000-0x03f back SDS+1
page 0x200-0x23f (XSGMII2): page 0x000-0x03f back SDS  page 0x000-0x03f back SDS+2

As a first micro step provide some helpers that simply operate on
frontend serdes and will determine the backend serdes on their own.

So rtmdio_931x_read_sds_phy() and rtmdio_931x_write_sds_phy() operate
on backend serdes. While rtmdio_931x_read_sds_phy_**new**() and
rtmdio_931x_write_sds_phy_**new**() operate on frontend serdes.

This is only an intermediate naming convention and will be cleanup
afterwards.

In a first step make use of these new functions whenever we
want to access the analog page. As the pages stay unchanged
in the new functions conversion is as simple as this:

Old:
asds = rtl931x_get_analog_sds(...)
rtmdio_931x_read_sds_phy(asds, ...)

New:
rtmdio_931x_read_sds_phy_new(sds, ...)

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19818
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-25 13:44:43 +02:00
Issam Hamdi
8c42e63a69 realtek: rtl93xx: fix incorrect destination port selection
When testing LLDP and STP, we observed that locally generated multicast
packets (e.g. LLDP, STP) were not restricted to the designated output
port(s). For example, when transmitting on `lan1`, the same packet was also
forwarded to other ports such as `lan2`.

Steps to reproduce:

1. Configure lldpd to use `lan1` in UCI and restart the service
2. Connect devices to `lan1` and `lan2`
3. Observe that the device on `lan2` still receives LLDP packets

The issue was caused by an incorrect `FWD_TYPE` setting in the TX CPU TAG,
which failed to enforce the selected egress port(s).

Fix this by updating the TX CPU TAG to set `FWD_TYPE` correctly, ensuring
that locally generated packets are transmitted only on the intended
port(s).

Signed-off-by: Issam Hamdi <ih@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19802
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-24 00:01:18 +02:00
Bevan Weiss
00c16754cd realtek: RTL930x led_set count error message tidy up + dev_ print fixups
Whilst testing Hasivo s1100wp-8gt-se LED configuration, several error
messages were presented which didn't indicate which led_set they were
referencing, nor what the value was that caused the invalid configuration.

Migrate to use dev_ print messages for this function.
And tidy up both when the error message is reported (don't show it when
an led_set isn't in the DTS) and what details the message presents.

Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/19791
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-21 11:22:11 +02:00
Markus Stockhausen
070d8eb4d5 realtek: mdio: rtl931x: move functions over to bus
This commit repeats the mdio function relocation from the other targets.
In short that means:

- phy read/write functions are moved away from the phy driver
- SerDes read/write functions are moved away from the dsa driver
- All gets consolidated into the mdio driver (inside the ethernet driver)

This is mostly a copy/paste to keep the changes small. The SerDes phy mapping
and the simplification of the central bus functions will come later.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19743
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-19 20:06:08 +02:00
Markus Stockhausen
5dbf55bebb realtek: register ethernet device after NAPI context init
Booting Realtek switches via TFTP will have a chance of ~5% to
fail with the following dump on SMP devices. Sample taken from
RTL931x.

[    1.318320] rtl931x_chip_init: init ENCAP done
[    1.323360] rtl931x_chip_init: init MIB done
[    1.328337] rtl931x_chip_init: init ACL done
[    1.333219] rtl931x_chip_init: init ALE done
[    1.344307] CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 00000000, ra == 806c5c4c
[    1.356418] Oops[#1]:
[    1.359067] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.12.40 #0
[    1.366582] Hardware name: Linksys LGS352C
[    1.371226] $ 0   : 00000000 00000001 00000000 80b6cc44
[    1.377179] $ 4   : 836b0540 00000000 00000000 83011d38
[    1.383119] $ 8   : 00000000 ffffefff 00000001 80b08c08
[    1.389071] $12   : ffffffea 83011d34 00000072 00000558
[    1.395060] $16   : 836b0540 00000000 00000100 83011ebf
[    1.401003] $20   : 83011ec0 83011ec8 ffff8b3c 80b00000
[    1.406984] $24   : 00000000 80b08c38
[    1.412922] $28   : 83038000 83011e70 82fb37a0 806c5c4c
[    1.418888] Hi    : 0000014b
[    1.422201] Lo    : c74d8000
[    1.425490] epc   : 00000000 0x0
[    1.429191] ra    : 806c5c4c __napi_poll+0x4c/0x208
[    1.434728] Status: 11000403 KERNEL EXL IE
[    1.439497] Cause : 50800008 (ExcCode 02)
[    1.444040] BadVA : 00000000
[    1.447330] PrId  : 0001a120 (MIPS interAptiv (multi))
[    1.453157] Modules linked in:
[    1.456641] Process swapper/0 (pid: 1, threadinfo=(ptrval), task=(ptrval), tls=00000000)
[    1.465742] Stack : 82faf248 80a8d558 817ed500 ffff8b3a 836b0540 8066a348 82fb2bc0 836b0540
[    1.475209]         82fb3600 00000100 0000012c 806c6274 00000000 00000017 00000002 80196134
[    1.484701]         80b00000 83011ed0 83011eb8 83011e00 83011ec0 83011ec0 83011ec8 83011ec8
[    1.494233]         00000001 81920000 81920000 80aefe4c 836b0000 00000000 00000000 00000001
[    1.503686]         00000100 00000000 83011f20 80aefde0 00000000 8019ac14 80b01550 00000000
[    1.513144]         ...
[    1.515957] Call Trace:
[    1.515996]
[    1.520458] [<8066a348>] rtl93xx_net_irq+0x1a4/0x1ac
[    1.526116] [<806c6274>] net_rx_action+0x18c/0x360
[    1.531576] [<80196134>] __handle_irq_event_percpu+0x58/0x16c
[    1.538111] [<8019ac14>] handle_level_irq+0x1e0/0x1f4
[    1.543870] [<80133588>] handle_softirqs+0x14c/0x2ec
[    1.549488] [<801339e4>] irq_exit+0x84/0xb4
[    1.554183] [<805527dc>] plat_irq_dispatch+0x90/0xdc
[    1.559764] [<801019f0>] except_vec_vi_end+0xc4/0xd0
[    1.565337]

A network interrupt may be received before the device is setup
properly. In this case NAPI structures are missing and __napi_poll()
will find a NULL pointer in n->poll. Avoid this by registering the
device after initialization is complete.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19787
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-17 17:22:29 +02:00
Markus Stockhausen
0724412c58 realtek: RTL838x harden ethernet driver against fuzzying
While checking setup routines for stability and completeness,
random RTL838x SoC I/O areas were intentionally overwritten.
As soon as L2_CTRL_1->FAST_AGE_OUT is set to 1, the system
stalls during bootup. Analysis shows that it loops endlessly
in rtl838x_hw_stop()

/* Flush L2 address cache */
if (priv->family_id == RTL8380_FAMILY_ID) {
	for (int i = 0; i <= priv->cpu_port; i++) {
		sw_w32(1 << 26 | 1 << 23 | i << 5, priv->r->l2_tbl_flush_ctrl);
		do { } while (sw_r32(priv->r->l2_tbl_flush_ctrl) & (1 << 26));
	}

This is exactly the same logic as in the vendor GPL. There
are no hints about possible timeouts or issues. The reason is
still unclear. Nevertheless harden the function for further fuzzy
tests. Do this by resetting the configuration value to its SoC
default.

Additionally convert some shifts to BIT() for better readability.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19679
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-11 15:18:09 +02:00
Harshal Gohel
522294eeef realtek: rtl931x: Fix l2 fdb entry handling
Previous implementation was directly copied from rtl930x and was not
working. Table field offsets are different between rlt931x and rtl930x

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19580
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-10 21:59:02 +02:00
Harshal Gohel
a4b8d80050 realtek: rtl931x: Add missing rma_bpdu_fld_pmask
The .rma_bpdu_fld_pmask is not used anywhere in the code for RTL930x nor
RTL931x. But the RTL930x was still initializing this member. To avoid
problems in the future, simply initialize it also on RTL931x.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19569
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-10 14:35:40 +02:00
Harshal Gohel
743f2cd731 realtek: rtl931x: Don't use RTL8xx port flooding initialization
Neither the RTL930x not the RT931x use the BPDU flooding mechanism which
was used for other SoCs. At the same time, the RTL931x must use the same
debugfs initialization function as RTL930x.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19569
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-10 14:35:40 +02:00
Markus Stockhausen
07a04d8485 realtek: RTL930x: reorganize mdio functions and SerDes register layout
The RTL930x mdio functions are scattered around the code. Relocate
them to the bus (still inside the ethernet driver). With this change
the phy identification looks into the proper registers. The SerDes
phy identifier (register 2/3) must be changed.

Additionally provide a consistent SerDes register access through the
mdio bus. Until now when a SerDes directly drives a SFP module there
is no clear rule of how to handle its register set that consists of
two parts:

- c22 phy registers 0-15 live in the fiber page (2) of the SerDes
- other SerDes specific registers exist in pages before and after

The mdio bus and other SerDes functions are a wild mix of directly
looking into page 2 or just using self defined methods to access
data.

Adapt the bus to the new consistent phy interface that mixes the
SerDes register set like classic Realtek phys do it.

- Use register 31 as page select (already in the bus)
- Always keep the common registers 0-15 in place and read fiber page
- Map the SerDes internal registers into the upper vendor specific
  registers 16-23 according to the page select register (31).

That gives a register mapping as follows:

+-----------------------+-----------------------+---------------+-------------+
| reg 0x00-0x0f         | reg 0x10-0x17         | reg 0x18-0x1e | reg 0x1f    |
+-----------------------+-----------------------+---------------+-------------+
| SerDes fiber page (3) | real SerDes registers | zero          | SerDes page |
| registers 0 - 15      | in packages of 8      |               | select reg  |
+-----------------------+-----------------------+---------------+-------------+

Example to make it as clear as possible.

SerDes registers on a RTL930x show

Page / Reg   | 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B ...
-------------+----------------------------------------------------------------
0 - SDS      | 0C03 0F00 7060 7106 074D 0EBF 0F0F 0359 5248 0000 0F80 0000 ...
1 - SDS_EXT  | 0000 0000 85FA 8C6D 5CCC 0000 20D8 0003 79AA 8C64 00C3 1482 ...
2 - FIB      | 1140 6189 001C CA40 01A0 0000 0000 0004 0000 0000 0000 0000 ...
3 - FIB_EXT  | 1140 6109 001C CA40 01A0 0000 0000 0004 0000 0000 0000 0000 ...

This translates to this phy layout

             | SerDes fiber registers  normal SerDes registers  zero     p.sel
Page / Reg   | 0x00 0x01 0x02 0x03 ... 0x10 0x11 0x12 0x13 ...  0x18 ... 0x1f
-------------+---------------------------------------------------------------
0            | 1140 6189 001C CA40 ... 0C03 0F00 7060 7106 ...  0000 ... 0000
1            | 1140 6189 001C CA40 ... 5248 0000 0F80 0000 ...  0000 ... 0001
...
4            | 1140 6189 001C CA40 ... 0000 0000 85FA 8C6D ...  0000 ... 0004

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19692
Signed-off-by: Robert Marko <robimarko@gmail.com>
2025-08-10 11:47:30 +02:00
Markus Stockhausen
5f06b8ebbc realtek: dsa: rename tagged_ports to member_ports
The current variables tagged_ports and untagged_ports suggest that
these are distinct and describe only the ports in each of these
configuration types.

That is wrong. The hardware is configured via member ports and
untagged ports. The first one being a superset of the second.
Rename the variables to reflect that.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/19684
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-08 18:04:57 +02:00
Harshal Gohel
f6603de71d realtek: rtl93xx: Add learning and flooding enable/disable
Both RTL930x and RTL931x were missing the code to support enabling and
disabling MAC address learning and unknown unicast flooding on a per-port
basis.

* rtl93*x_enable_learning() allows toggling of dynamic MAC learning on
  individual ports by modifying the L2 learning constraint control
  register.
* rtl93*x_enable_flood() provides the ability to control unknown unicast
  flooding behavior, disabling forwarding when set. If it is enabled, it
  will just forward it. If it is disabled, packets will simply be dropped.

Signed-off-by: Harshal Gohel <hg@simonwunderlich.de>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19581
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-08 13:56:58 +02:00
Sven Eckelmann
92489f50c7 realtek: rtl931x: Fix size of TRK_MBR_CTRL group block
Each MBR ctrl block has 64 bits to store the 56 possible ports. The offsets
between the groups is therefore also 64 bit.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/19574
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2025-08-07 18:40:30 +02:00