100 Commits
Author SHA1 Message Date
Markus Stockhausen fb69055ed5 realtek: eth: rename packet to frag
Since the jumbo frame preparation the driver can work on fragments
and not only on complete packets in the receive path. This might be
implementet in the transmit patch in the future too. So a chunk of
data is best described as a fragment. Rename all occurrences.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:02:00 +02:00
Markus Stockhausen 57850d4bef realtek: eth: move tx skb into driver-only structure
The TX path stores the skb information in the coherent part. This
is only needed by the driver. Move it to its proper location.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:02:00 +02:00
Markus Stockhausen 25e30fd274 realtek: eth: move page/pool into driver structure
The paged pool handling is only required for the driver and not
for the SOC. Move it into the driver-specific part.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:02:00 +02:00
Markus Stockhausen 1588766cee realtek: eth: change skb helper function signatures
It is easier to work with ring/slot when shifting around variables
in the different structures. Replace packet pointers in existing
function signatures.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:01:59 +02:00
Markus Stockhausen 771f370d74 realtek: eth: add driver-only transmit info structure
Remove driver-only data from the coherent transmit structure.
It is not needed to keep this in uncached memory as the SOC
does not need access to it.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:01:59 +02:00
Markus Stockhausen 289011eac0 realtek: eth: Rename coherent structures
In the past the ring handling was split into a coherent (SOC/driver shared)
and a driver-only part. Give the coherent structure a meaningful name.

Link: https://github.com/openwrt/openwrt/pull/24346
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 21:01:59 +02:00
Markus Stockhausen 11a859cca7 realtek: eth: clean up non-dma ring data
The driver ring handling consists of two parts:

- rx_data: DMA coherent data shared with the SoC
- rx_qs: driver internal handling data

It is unclear what "qs" stands for. Rename that part to "rx_info".

While we are here:
- relocate slot from rx_data to rx_info as it is only needed by
  the driver and not the SoC.
- rename page_pool to pool because there is only this single pool
  inside the driver.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:10 +02:00
Markus Stockhausen 5cf2b66789 realtek: eth: align dma variables
The driver uses rx_data_dma and tx_dma although they have an
identical meaning. Align their naming.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:10 +02:00
Markus Stockhausen ec8d08496c realtek: eth: groundwork for jumbo frames
The Realtek SoC hardware can split incoming packets over multiple buffers.
This allows to receive packets that are larger than the current 2K page
pool limit without changing the design to higher order pages. Add a logic
to handle these fragments.

As a first proof of concept simulate fragmentation by reducing the buffer
size down to 400 bytes. With the current support for standard MTU (1500)
the packets might consist of up to 4 fragments.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:10 +02:00
Markus Stockhausen 7683e9e28e realtek: eth: increase error counters under lock
Change device error statistics like normal statistics - under a lock.
Reword associated messages in preparation for fragment handling.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen 7226c6edbf realtek: eth: add helper for SKB creation
Simplify rteth_hw_receive() by using a separate helper for SKB creation.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen 39d466aba3 realtek: eth: prepare napi receive for fragments
Reorder the code around napi_gro_receive() so that it fits nicely
for the upcoming fragment handling. For this relocate the FCS
stripping and eth_type_trans() calls short before the handover
when the packet is fully built.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen cba031de5d realtek: eth: Explain page allocation order
Add a comment why we are doing this and make use
of a helper variable.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen edc3c3f63f realtek: eth: prepare counters for fragments
Until now the driver packs each received packet into one ring buffer.
In the future jumbo packets will be split into multiple fragments.
Prepare the ring counters for this:

- Add the more flag to SoC packet header. This denotes if a packet
  has more data after the current fragment.
- Ring counters must be handled per packet and not per fragment.
  Increase work_done after each packet and not after each fragment.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen 54a7e09329 realtek: eth: Adapt SKB defines
Testing shows that the existing performance boost by aligning the data
to 2 bytes (NET_IP_ALIGN) breaks fragment handling on RTL838x devices. The
SoC silently drops 2 bytes between each fragment. Use this tricky alignment
only when it is supported. This will bring down performance on RTL838x SoCs
by 30%. All other SoCs are unaffected. This is a legitimate tradeoff for
allowing multiple fragments. While we are here make clearer what the
definies are about and rename them to a SKB_ prefix.

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen 419f023ec3 realtek: eth: add rteth_free_skb() helper
Add a helper to simplify SKB freeing and rx counter handling. If SKB
is given, it is freed and the pointer is set to zero. The return value
is the number of freed SKBs (0/1). With this the existing cleanup and
error handling can be simplified like

dev->stats.tx_errors += rteth_free_skb(&packet->skb);

Link: https://github.com/openwrt/openwrt/pull/24245
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-21 09:30:09 +02:00
Markus Stockhausen b73b209693 realtek: i2c: replace shared gpio driver with upstream
Upstream will support I2C GPIO based buses with shared SCL shortly [1].
Drop downstream driver, provide backport and adapt DTS.

[1] https://lore.kernel.org/linux-i2c/20260714162915.3018703-1-markus.stockhausen@gmx.de/

Link: https://github.com/openwrt/openwrt/pull/24269
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-20 18:50:01 +02:00
Markus Stockhausen e26eccaa3c realtek: dts: adapt RTL8214FC bus location on RTL839x
The RTL839x has the following hard-coded bus topology:
- Bus 0: Port 0-23
- Bus 1: Port 24-51

So the bus number and the PHY address in the dts are mostly
ignored. Nevertheless fix the assignment for the Zyxel GS1920.
This does not change the functionality it just describes the
hardware correctly. While we are here add the PHY package
description too.

Link: https://github.com/openwrt/openwrt/pull/24281
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-19 11:18:16 +02:00
Markus Stockhausen 49f0512036 realtek: dts: more ethernet-phy-package conversion
Encapsulate some more multiport PHYs into their packages.

Link: https://github.com/openwrt/openwrt/pull/24281
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-07-19 11:18:16 +02:00
Markus Stockhausen cc697093b8 realtek: l3: reorganize lock access
The layer 3 code shares the register access lock with the DSA driver.
It is currently unclear to which extent this is really needed. To
avoid permanent access to the DSA private structure reorganize the
locking as follows:

- create a lock pointer in the layer 3 control structure
- link it to the DSA lock during probing
- use the ctrl->lock pointer whenever needed.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen efe23afc8b realtek: l3: move route_use_bm to layer 3
This is another variable that belongs to the layer 3 code.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 649d926584 realtek: l3: move RTL930x setup to layer 3 code
Move the setup where it belongs and drop the no longer used
l3_setup() callback in the DSA code.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 5fe67b9887 realtek: l3: relocate RTL83xx setup
Make use of the new layer 3 setup callback for RTL83xx.

- RTL838x had no setup. Drtop it completely
- RTL839x move the setup over to the layer 3 code.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 658cdf86ad realtek: l3: add setup callback
The existin setup calls must be migrated from the DSA code into
the layer 3 code. Provide a new callback for that. Keep it empty
for now.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 867afa0e03 realtek: l3: cleanup headers
With all the code relocation it is time to clean the headers.

- otto_l3_route_ht_params is internal and can be moved to l3.c
- otto_l3_route is no longer needed in rtl-otto.h
- additionally reorder structures to avoid forward declarations

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 339db36d97 realtek: l3: relocate find_slot()
Move find_slot() and its helpers into the new layer 3 ecosystem.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen 4d82173451 realtek: l3: relocate set_egress_intf()
Relocate set_egress_intf() to layer 3 code. While we are here change
prefix of interface structure to otto_l3_ and move its definition
to the new code too.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:08 +02:00
Markus Stockhausen e0377bf382 realtek: l3: relocate get_egress_mac()
Move get_egress_mac() from DSA to layer 3 code.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:07 +02:00
Markus Stockhausen 04ca93a856 realtek: l3: move host_route_write to layer 3 source
Move another function from DSA to layer 3 coding.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:07 +02:00
Markus Stockhausen 55cf68c52c realtek: l3: move host_route_use_bm to layer 3
This is another layer 3 specific attribute. Move it to its new home.

Link: https://github.com/openwrt/openwrt/pull/23979
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 18:17:07 +02:00
Markus Stockhausen f4ddf8d7ef realtek: irq: backport upstream patches
The interrupt driver downstream patches have been sent
upstream and got accepted. Backport them and make the
driver free of downstream hacks.

Link: https://github.com/openwrt/openwrt/pull/23679
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-29 17:50:48 +02:00
Markus StockhausenandJonas Jelonek 3a7595dcde realtek: pcs: simplify gray code to binary conversion
Gray conversion is b[i] = g[i] XOR g[i+1] XOR ... XOR g[n-1]
Make the code a 3 liner. For more details see [1].

[1] https://en.wikipedia.org/wiki/Gray_code#Converting_to_and_from_Gray_code

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23984
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
2026-06-28 23:44:31 +02:00
Markus Stockhausen 23e5161399 realtek: l3: move router MAC helpers to layer 3 ecosystem
The router MAC helpers and their structures belong to layer 3.
Move them over to the new source file.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:37 +02:00
Markus Stockhausen 0738b151eb realtek: l3: move route_lookup_hw over to layer 3 structure
Another layer 3 function that needs a new home. As always convert
the code to dev_...() logging.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:37 +02:00
Markus Stockhausen b440cd00d1 realtek: l3: move nexthop helper to new struture
Another two layer 3 functions that do not belong into the DSA
space. Move them over to the L3 configuration structure.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:37 +02:00
Markus Stockhausen a74b29731c realtek: l3: move route read/write into new structure
Reading and writing routes is part of the layer 3 code.
Move it to where it belongs. While we are here convert
pr_...() logging to dev_...() logging.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:37 +02:00
Markus Stockhausen c6df98aecb realtek: l3: add device specific configuration
All the layer 3 device specific functions and attributes currently
live in the DSA driver. Add a configuration structure to the layer
3 code. For now provide and fill a dummy value. It will be replaced
with meaningful data with the next patches.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:37 +02:00
Markus Stockhausen fa45a65423 realtek: l3: convert function signatures from priv to ctrl
Get rid of the priv pointer in the function signatures.
Hand over the new layer 3 control structure instead.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:36 +02:00
Markus Stockhausen 885345b268 realtek: l3: convert to device based logging
Make device logging consistent. For this

- add a device attribute to the new layer 3 control structure
- convert pr_...() logging to dev_...() logging.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:36 +02:00
Markus Stockhausen dc753e2d32 realtek: l3: convert otto_l3_walk_data to control structure
Use new control structure in walk data.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:36 +02:00
Markus Stockhausen 1f0b80a53c realtek: l3: replace priv with ctrl in work structures
Use layer 3 control structure as attribute in work structures.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:36 +02:00
Markus Stockhausen 5bffee2b4a realtek: l3: move routes to l3 structure
Make routes an attribute of the new layer 3 control structure.

Link: https://github.com/openwrt/openwrt/pull/23963
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-28 08:46:36 +02:00
Markus Stockhausen 626cc6770b realtek: l3: move notifier blocks to private structure
Relocate the notification handlers into the new L3 ecosystem.

Link: https://github.com/openwrt/openwrt/pull/23937
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 18:06:56 +02:00
Markus Stockhausen 8c2ef13ec6 realtek: l3: add private structure
The DSA private structure provides an overwhelming mix of
information. L3 data is part of this. Provide a new separated
structure that is linked bidirectionally to the old data.
For the start it only contains a reference pointer and no L3
specific data.

Link: https://github.com/openwrt/openwrt/pull/23937
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 18:06:56 +02:00
Markus Stockhausen 1131037391 realtek: l3: provide probe/remove helpers
The L3 code is manually initialized and finalized in the DSA
probe/remove functions. Relocate the code into seperate helpers
that encapsule all required steps. Make no longer exposed L3
functions static.

Link: https://github.com/openwrt/openwrt/pull/23937
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 18:06:55 +02:00
Markus Stockhausen b586e843de realtek: l3: separate L3 coding from DSA
DSA is layer 2 and not layer 3. Nevertheless all routing management
needs a home. Separate it into its own source file. This first
step is far from perfect but at least it guides the DSA driver into
the right direction.

No functional changes. Just relocating, renaming and proper including.

Link: https://github.com/openwrt/openwrt/pull/23937
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 18:06:55 +02:00
Markus Stockhausen e59484b39e realtek: dsa/eth: adapt receive path
Improve the DSA receive tagging. For this convert the receive path
to METADATA_HW_PORT_MUX. This way no skb data mangling is needed.
See e.g. airoha_eth.c or mtk_eth_soc.c.

Link: https://github.com/openwrt/openwrt/pull/23948
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 16:43:25 +02:00
Markus Stockhausen bc910540ad realtek: dsa/eth: adapt transmit path
This is just some reordering/simplifcation of the transmit path.
Relocate the port extraction into a separate helper for a smaller
xmit function. While we are here add some documentation and
reorder the tag and its contents. As these are only arbitrary
values that help the ethernet driver to identifiy the tag this
is just cosmetic.

Link: https://github.com/openwrt/openwrt/pull/23948
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 16:43:25 +02:00
Markus Stockhausen c77ac7db48 realtek: eth: fix tx_bytes calculation
When sending data packets the hardware expects data size plus 4
bytes for the layer 2 checksum (FCS). This does not count into
"bytes sent" metric. Fix that.

Link: https://github.com/openwrt/openwrt/pull/23948
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 16:43:25 +02:00
Markus Stockhausen 1e45d12ebd realtek: eth: rename dest_port to port
Just variable renaming. No functional change.

Link: https://github.com/openwrt/openwrt/pull/23948
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-26 16:43:25 +02:00
Markus Stockhausen d6f5c2685f realtek: rt-loader increase gcc optimization level
Switch from -O2 to -O3. This increases the loader code size by
5KB and brings down the decompression time on RTL838x from
~6.5 seconds to ~3.5 seconds.

Link: https://github.com/openwrt/openwrt/pull/23811
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-16 20:36:39 +02:00
Markus Stockhausen ee02f6f16b realtek: mdio: backport upstream patches
Another round of MDIO driver patches was accepted upstream.
Not production relevant as OpenWrt still uses the downstream
driver.

Link: https://github.com/openwrt/openwrt/pull/23768
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-13 22:15:02 +02:00
Markus Stockhausen aa510aa47d realtek: dts: add phy-package to LGS352C
Describe the RTL8218D packages in the device tree.

Link: https://github.com/openwrt/openwrt/pull/23711
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-13 16:21:12 +02:00
Markus Stockhausen ea9caafdb5 realtek: dts: add phy-package to XGS1x10 series
Describe the RTL8218D packages in the device tree.

Link: https://github.com/openwrt/openwrt/pull/23711
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-13 16:21:12 +02:00
Markus Stockhausen a317079b57 realtek: eth: rename ring steering bits
A network interface card (NIC) hardware ring of the Realtek Otto switch
SoCs is nothing more than a list of pointers to the ring headers. I.E.

address | content   | comment
--------+-----------+------------------------
x + 0   | pointer 0 | points to ring header 0
x + 4   | pointer 1 | points to ring header 1
...
x + 4*n | pointer n | points to ring header n

Headers must be 4 byte aligend. So the lower two bits of the pointers
are unused. Hardware designers desided to give them special meanings.

- Bit 0: Owner of this ring entry, 1 = hardware, 0 = software
- Bit 1: Wrap, 1 = last ring pointer, 0 = normal ring pointer

The driver uses constant defines with slightly confusing naming. Replace
OWN_CPU with OWN_HW to make clear what it is about. Align prefix and
make the defines bitmasks for better readability.

Link: https://github.com/openwrt/openwrt/pull/23676
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-06 15:04:42 +02:00
Markus Stockhausen ecdf250d6b realtek: eth: sort structures and defines
Align indentation of defines and move structures to the top of
the source code. This is only cosmetic. No functional changes.

Link: https://github.com/openwrt/openwrt/pull/23676
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-06 15:04:42 +02:00
Markus Stockhausen 32bcc2986c realtek: mdio: backport upstream patches
This backports the upstream efforts for the mdio driver. No downstream
functionality is affected as OpenWrt still uses the mdio-realtek-otto
driver.

Link: https://github.com/openwrt/openwrt/pull/23678
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-06 15:03:16 +02:00
Markus Stockhausen 82ddc472d7 realtek: dts: convert to upstream switch notation
There is currently a difference how upstream and downstream define
the switch in the dts. Downstream holds the switch as a member
node below a root switchcore parent. Upstream uses the switch as
the parent.

Upstream:

  ethernet-switch@1b000000 {
    mdio-controller@ca00 { };
    ethernet { };
    ethernet-ports { };
  }

Downstream:

  switchcore@1b000000 {
    ethernet-switch {
      ethernet-ports { };
    };
    mdio-controller@ca00 { };
    ethernet { };
  }

Align downstream to upstream and merge the ethernet-switch into
the parent node. For this to work adapt the port lookup in the MDIO
and PCS driver.

Remark! With this commit the boot process will give the spurious
error message "rtl838x_eth 1b000000.ethernet-switch:ethernet eth0:
Failed to create a device link to DSA switch 1b000000.ethernet-switch"
This comes from the fact that the switch is the parent of the ethernet
device. Thus a link back from ethernet device to the switch is no
longer possible. Testing shows that the error is just cosmetic.

Link: https://github.com/openwrt/openwrt/pull/23599
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-06-01 19:15:51 +02:00
Markus Stockhausen 2b4503c7c9 realtek: eth: convert to page_pool
Drop the legacy receive handling and convert the driver to make
use of a zero-copy receive path. To save memory use the page
pool fragment feature. This way two SKBs will fit into one 4KB
page. With the parametrization of this patch the driver will
allocate about 600KB of receive buffers (2 rings with 300KB
each. This already includes space for the SKB header.

iperf3 benchmark gives:

RTL930x
- 1x stream send / from switch 170 Mbit -> 170 MBit
- 4x stream send / from switch 150 MBit -> 150 MBit
- 1x stream receive / to switch 320 MBit -> 400 MBit
- 4x stream receive / to switch 260 MBit -> 300 MBit

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen 8fd3e2fbec realtek: eth: avoid TX buffer memory leak
Although never observed, a transmit timeout might happen.
In that case there is a resource leak inside rteth_tx_timeout().
This happens when rteth_setup_ring_buffer() reinitializes the
transmit buffers and overwrites all transmit slots. Any linked
SKB is lost and leaked at this point.

Be defensive and add a cleanup rteth_free_tx_buffers() function.
Call this alongside rteth_free_rx_buffers() where needed.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen b0e263a5ed realtek: eth: Use right helper for SKB cleanup
There are two helpers to cleanup SKBs that call iternally
dev_kfree_skb_any_reason() but with different error codes.

- dev_kfree_skb_any() reason SKB_DROP_REASON_NOT_SPECIFIED
- dev_consume_skb_any() reason SKB_CONSUMED

The driver does not distinct between the two. Change this and
clean up a SKB that was handed over to the hardware with
dev_consume_skb_any(). This way kernel knows that everything
went well.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen 934de59abe realtek: eth: drop device managed netdev registration
The cleanup order of the driver is quite confusing. At least
two issues exist.

- phylink_destroy() is missing
- The implicit unregister_netdev() at the end of rteth_remove() is called
  too late. The manually managed resources are removed before. This can
  lead to stale data access.

Convert to register_netdev() and bring rteth_remove() into a meaningful
order to avoid such issues when converting to page_pool.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen 8508bcb42e realtek: eth: Add return value to rteth_setup_ring_buffer()
In the future this function will work on page_pool and might fail.
Add a return code to it and handle it where needed.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen 0a80500fb0 realtek: eth: convert to scoped_guard
In the future there will be some error paths inside locking.
Make cleanup easier by converting the sections to scoped_guard.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen c5bab7288c realtek: eth: improve error handling during probe
The error handling flow during probing has some shortcomings.

1. In case an error occurs after netif_napi_add() this must be
   cleaned up with a call to netif_napi_del().
2. If devm_register_netdev() fails not only NAPI must be cleaned
   up but also the phylink.

Add a cleanup section for the probe. Implement it generically
(checking for 0/NULL values) so it can be called any time when
encountering probe failures.

Link: https://github.com/openwrt/openwrt/pull/23483
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-30 08:50:00 +02:00
Markus Stockhausen fc61e795ee realtek: mach: specify alignment topology
The kernel has two helper defines that guide about hardware
characteristics.

MIPS_L1_CACHE_SHIFT defines the cache line sizes (1<<x) of the
target. It defaults to 5 - so it is assumed that the device has
a cache line size of 32 bytes. This is not true for MIPS 4KEc
cores that are driving the RTL838x SOCs. These cores have 16
byte cache line sizes. Adapt the CONFIG properties for this
target to match the hardware.

ARCH_DMA_MINALIGN definies the alignment for memory allocations.
Other than its name suggests on MIPS devices that have non
coherent DMA kmalloc() respects this configuration. This ensures
that no normal memory is corrupted by DMA blocks that share the
same cache line.

The default for this is 128 bytes. And kernel states itself
"Total overkill for most systems but need as a safe default. Set
this one if any device in the system might do non-coherent DMA".

Realtek devices use non coherent DMA so they are affected by the
setting of ARCH_DMA_MINALIGN. Set this to cache line size for
all devices to reduce memory waste.

Link: https://github.com/openwrt/openwrt/pull/23492
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
2026-05-28 21:02:24 +02:00
Markus StockhausenandRobert Marko c27f9b3ba0 realtek: eth: rename netdev/ndev variables to dev
Right now the driver uses variable names netdev/ndev/dev to access
a net_device structure. Align this with most of the other upstream
drivers and convert everything to dev.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23420
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:19:47 +02:00
Markus StockhausenandRobert Marko d3577dfbf3 realtek: eth: get rid of struct device
In the network context there might be confusion between "struct netdev"
and "struct device". The driver should avoid variables of type device
and name "dev" where possible. Remove all variables that point to the
device and use pdev->dev instead. This is like other network drivers
do it.

While we are here modernize logging during probing. Remove messages
from helpers and log errors during probing with dev_err_probe().

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23420
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:19:47 +02:00
Markus StockhausenandRobert Marko 04433b4e75 realtek: eth: better error handling in init_mac()
The function init_mac() can produce errors for the RTL931x devices.
When this happens it throws a message but continues. That can
leave the hardware in a wrong state.

Cleanup the error handling. Remove all messages from the function
and simply return an error value. In the probe() consumer evaluate
this error and abort probing if needed. As there were no reported
issues in the past it is ok to drop the detailed messages and
aggregate them in a single one.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23420
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:19:47 +02:00
Markus StockhausenandRobert Marko a1a4b09076 realtek: eth: reorganize control structure setup
Early assign pdev and netdev to the control structure during probing.
This way it can be used at any time later.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23420
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:19:47 +02:00
Markus StockhausenandRobert Marko 76e47b4421 realtek: mdio: convert to scoped_guard()
Upstream netdev does not like big guards. Especially
around debugging functions. Convert to scoped_guard()
and only lock the really needed code parts. This way
all debugging can run outside of the lock.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23411
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:10:27 +02:00
Markus StockhausenandRobert Marko b8fc512a05 realtek: mdio: convert to consistent a_to_b() helpers
Majority of kernel uses a_to_b(a) instead of b_from_a(a).
Convert to that to be consistent with all helpers in the
driver. Additionally drop inline function definitions.
Let the compiler decide what is best.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23411
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:10:27 +02:00
Markus StockhausenandRobert Marko 57dbfa0a9c realtek: mdio: checkpatch & documentation cleanup
checkpatch is complaining. Fix that. Additionally adapt the
documentation and move it up to the beginning of the driver.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23411
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:10:27 +02:00
Markus StockhausenandRobert Marko 3c4a547eb2 realtek: thermal: separate initialization/operation
The driver uses lazy initialization - during first temperature
get. Checking enabled status over and over again does not make
sense. Provide separate setup functions for this. With this split
the error handling will be improved. If initialization fails, the
sensor will not be registered at all.

While we are here fix some minor typos.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23405
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-21 12:07:57 +02:00
Markus StockhausenandRobert Marko da2a5cc3ac realtek: irq: switch to of_fwnode_handle()
Kernel 6.19 will get rid of of_node_to_fwnode(). Switch to its
successor of_fwnode_handle() that is already available in 6.18.
This will simplify a future kernel upgrade.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23434
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-19 10:52:23 +02:00
Markus StockhausenandRobert Marko 42cf34d3f8 realtek: pcs: use devm_kzalloc()
Just for safety. Use device managed operation so the
memory is automatically reclaimed when the parent PCS
controller is removed.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23391
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:34:47 +02:00
Markus StockhausenandRobert Marko c83c74a482 realtek: pcs: replace mdelay() with usleep_range()
Use CPU friendly operation.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23391
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:34:47 +02:00
Markus StockhausenandRobert Marko 410cc636d7 realtek: pcs: fix use after free
In rtpcs_probe_serdes_bus(), the code manages the device
tree node reference incorrectly:

- It acquires a node pointer np via of_find_compatible_node(),
  which increments the reference count.

- It calls of_mdio_find_bus(np) to locate the bus.

- It calls of_node_put(np), which decrements the reference
  count. If this was the last reference, the node is freed.

- It then attempts to check if (!of_device_is_available(np)).

The pointer np is used after its reference has been released.
This can lead to a kernel oops or unpredictable behavior if
the memory has been reclaimed.

Fixes: fe27cce1e ("realtek: add SerDes PCS driver")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23391
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:34:47 +02:00
Markus StockhausenandRobert Marko 965bfd55c2 realtek: eth: create phylink before device registration
As soon as devm_register_netdev returns, the network
interface is "live" and the kernel can call rteth_open().
If the interface is brought up immediately (e.g., by a
userspace script), rteth_open will attempt to call
phylink_start(ctrl->phylink), which will crash the
system because ctrl->phylink has not been assigned yet.

Reorder probing sequence.

While we are here sort the variables by length.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23375
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:23:34 +02:00
Markus StockhausenandRobert Marko 8134e6d187 realtek: eth: fix transmit path unmapping order
packet->dma is overwritten with a new mapping before
the previous buffer is unmapped. This causes the kernel
to unmap the wrong memory address, leading to memory
leaks and potential corruption.

Additionally set skb pointer to NULL to avoid a free
when the buffer is recycled next time.

Reorder unmapping/mapping sequence.

Fixes: 41300fd88 ("refactor transmit function")
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23375
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:23:34 +02:00
Markus StockhausenandRobert Marko ae38d72a7a realtek: mdio: rename "busses" to "buses"
Use upstream standard for plural of bus.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23299
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:22:08 +02:00
Markus StockhausenandRobert Marko 530f544e25 realtek: mdio: Enable polling after setup
The mdio driver currently leaves the phy polling disabled after
setup. The dsa driver takes over and mangles the polling registers
so that they fit its needs. While polling is something in between
mdio (PHY) and dsa (MAC) it should be controlled by the mdio
driver.

Add a final "polling enable" function to the mdio driver so that
the MAC registers are filled automatically. For this

- split valid_ports into phy_ports (attached to PHY) and sds_ports
  (attached to SerDes)
- Improve the probing so it can differentiate between a phy and a
  sds port. This is resolved by the "phy-handle" attribute.
- Split the for_each_port macro into a phy and sds version.
- After probing enable polling for all phy and sds ports.

With this in place the dsa driver can remove the polling setup
completely.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23299
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-17 12:22:08 +02:00
Markus StockhausenandRobert Marko 8482b9983b realtek: mdio: add reverse lookup bus/phy to port
Until now there is a O(n) loop that looks up a port for a
given bus/phy combination. This is slow for high port count
devices (RTL839x and RTL931x). Implement a efficient reverse
lookup table for that.

While we are here adapt tiny bits of the documentation to
better reflect the driver logic after the recent refactoring.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:30 +02:00
Markus StockhausenandRobert Marko dc08ffc707 realtek: mdio: drop memset
Use modern compound literal assignment instead.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:30 +02:00
Markus StockhausenandRobert Marko f3cd53b6a1 realtek: mdio: convert to modern fwnode helpers
Upstream is slowly converting from "of_" to "fwnode_" handling.
This is a more modern and generic approach. Make use of it.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 6186f04af8 realtek: mdio: change prefix from "rtmdio_" to "rtmd_"
The long prefix distracts the reader from the real variables,
functions and defines. Shorten it to "rtmd_" that is not
used by any other upstream driver.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 8cf43d8b66 realtek: mdio: harden rtmdio_get_phy_info()
Improve error checking and code flow.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 834d2e51f4 realtek: mdio: refactor register handling
Until now the driver works as follows:

- low level functions do a bulk write
- high level functions have device specific structures

Turn this upside down and hide the register logic in the low
level functions. To achieve this:

- add a register map to each device
- change the low level write to use this map
- use only one common unique command structure
- use the command structure in the high level functions

While we are here fix the RTL838x access patterns. The read
functions do not need to set the bitmask.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 94c79aebe3 realtek: mdio: cleanup defines
Convert hexadecimal defines to lowercase and remove unneeded
brackets like upstream mdio does. While we are here remove
unused RTMDIO_DATA_MASK macro.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 04d6de87a8 realtek: mdio: improve set_port_ability() readability
Hide the bit mangling in meaningful macros and use similar
coding for both RTL93xx targets.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 200723c795 realtek: mdio: harden setup_polling()
Polling setup silently discards regmap return codes. Change function
signature and add error checking to all regmap commands.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko cd87cef06f realtek: mdio: port naming cleanups
Be consistent with the rest of the code and make clear when the
driver accesses ports. For this rename num_phys to num_ports.
Additionally make the device specific port numbers a define and
use them in the configuration structure.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 7f01a22d92 realtek: mdio: move masks below their registers
In the define section there are still some masks that are not sorted
into the corresponding register. Move them around.

- This makes clear that C22 and command data share a register
- Add a prefix to the PHY_PATCH_DONE mask to align with rest of code

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 3a2c859e93 realtek: mdio: convert bit mask calculations to macros
There are still some cryptic bit mask calculations. Replace them
with their register/field names for better readability.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko f5fa418ad6 realtek: mdio: add helper that disables polling
Each device specific implementation disables the hardware polling
differently. Harmonize this by providing a central helper. With
this

- disable polling at the very beginning
- remove unneeded sleeping (SDK does not need it too)
- add checks for regmap returncodes

Especially for RTL839x avoid to disable hardware polling at all.
It is enough that the port specific polling is disabled during
configuration.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23230
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-11 10:32:29 +02:00
Markus StockhausenandRobert Marko 8cd391c68b realtek: mach/prom: add identifiers to soc_info structure
SoC name and system type identifiers are currently separated from
the soc_info structure. This gives no benefit. Relocate that info
into the structure where it belongs.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23173
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-07 18:19:56 +02:00
Markus StockhausenandRobert Marko c689be9eba realtek: eth: sort and rename defines
Several defines still use the old prefix and are not sorted
alphabetically. Rearange the header file and the configuration
structures.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23145
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-06 10:53:28 +02:00
Markus StockhausenandRobert Marko b07fe8216d realtek: patches: simplify dsa/phy port hacks
The mdio driver has found a simple way to handle phy addresses
for all devices with upstream kernel defaults. Remove all unneeded
hacks from the corresponding patch and reword it.

While we are here increase DSA_MAX_PORTS to 56 to match RTL931x.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23186
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-06 10:52:40 +02:00
Markus StockhausenandRobert Marko 41e9574297 realtek: mdio: harden phy address check
As of now RTL839x devices have never more than 32 devices on one
mdio bus. Harden the phy address check during probing.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23186
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-06 10:52:40 +02:00
Markus StockhausenandRobert Marko 593df57731 realtek: dts: adapt RTL839x mdio bus topology
The RTL839x actually has two mdio busses.

- mdio bus 0 serves ports 0..23
- mdio bus 1 serves ports 24..51

This is baked into hardware and cannot be changed during mdio driver
setup with any register write. With the recent changes the driver
handles ports, phys and busses in a more logical way. So a port X
is assigned to a bus Y and a phy Z (on that bus). This gives a
mapping like

- port 16 <=> bus 0, address 16
- port 32 <=> bus 1, address 8

This unique assignment is used in the mdio driver as follows:

- Request to read bus 1, address 8
- Lookup corresponding port = 32
- Read from port 32

Looking at RTL839x it becomes clear that bus/phy => port lookup can
be achieved in multiple different ways. The simple reason is, that
for this device the driver cannot setup the smi topology. It is
baked into the hardware. So adding a "virtual" second bus does not
change the hardware access but allows to keep phy addresses below 32.
Making an example

mdio_bus0 {
  PHY_C22(40, 40)
}

resolves to port 40. But the same can be achieved with

mdio_bus1 {
  PHY_C22(40, 16)
}

In the first case the kernel sees bus/phy = 0/40 and in the second
case it sees bus/phy = 1/16. Both result in the access to the same
phy device on hardware port 40.

Use this analogy for RTL839x devices to match the real hardware
topology. For this change the existing dts and

- activate mdio bus 1 in rtl839x.dtsi
- rearrange devices with ports 24..51 to make use of bus 1

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23186
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-05-06 10:52:40 +02:00