1745 Commits

Author SHA1 Message Date
Markus Stockhausen
a0c7d5ecff realtek: mdio: rename read/write functions
Harmonize the read/write functions for better readability. This
aligns with the naming convention of the upstream rtl9300 mdio
driver.

read_phy	-> read_c22
read_phy_mmd	-> read_c45
write_phy	-> write_c22
write_phy_mmd	-> write_c45

Swap order of c22/c45 functions to keep structures sorted
alphabetically.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23197
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-03 01:43:48 +02:00
Manuel Stocker
79a6d2aab2 realtek: support configurable LED interface mode on RTL930x
Add support for changing the LED mode via the device tree.
Currently it always defaults to SERIAL mode. With this change,
one can also use the SINGLE_COLOR_SCAN and BI_COLOR_SCAN modes.

Signed-off-by: Manuel Stocker <mensi@mensi.ch>
Link: https://github.com/openwrt/openwrt/pull/23160
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-03 01:32:52 +02:00
Jonas Jelonek
84233220d3 realtek: dts: rtl93xx: use macro for PHY port definitions
Use SWITCH_PORT_LED instead of full verbose port definitions to
simplify and clean up the DTS.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23118
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:41:49 +02:00
Jonas Jelonek
322f8e6771 realtek: dts: rtl93xx: use PHY_* macros for Zyxel XGS1X10/1250
Replace the verbose ethernet-phy node definitions with the PHY_C45 and
PHY_C45_PAIR_ORDER macros to drop boilerplate.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23118
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:41:49 +02:00
Jonas Jelonek
0136c48bd5 realtek: dts: rtl93xx: replace LED magic values with macros
Replace the raw bitmask values for led_set entries with the
RTL93XX_LED_SET_* macros from macros.dtsi to make the LED configuration
self-explanatory.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23118
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:41:49 +02:00
Jonas Jelonek
858dfdd832 realtek: dts: rtl93xx: use SWITCH_PORT_SFP for ports
Make use of the SWITCH_PORT_SFP macro to simplify and make the DTS of
several devices cleaner.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23118
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:41:49 +02:00
Markus Stockhausen
d12e654a34 realtek: mdio: convert to generic regmap_bulk_write()
Each architecture has its own SMI address and SMI data size. Make the
current device specific coding generic by

- adding SMI start address and SMI data size to configuration structure
- moving regmap_bulk_write() over to the generic rtmdio_run_cmd()
- deleting all device specific rtmdio_xxxx_run_cmd() versions

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
c87e07e906 realtek: mdio: generic read handling
Each target has a specific SMI register where the result of read
commands is stored. As the read logic is always the same convert
the current logic to a generic one. Instead of a target specific
coding move eveything into the configuration structure and let
rtmdio_run_cmd() do the work.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
2283548d7e realtek: mdio: move command data into config structure
Until now the device specific I/O helpers are instrumented by individual
call parameters. Move this information over to the configuration structure.
This simplifies the code at the calling locations.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
70dcb8c291 realtek: mdio: use regmap_bulk_write() in RTL931x path
Convert the RTL931x I/O path to the new bulk write pattern. For this

- Enhance the rtmdio_931x_run_cmd() helper to take care of all register
  access and error handling.
- Convert the c22/c45/read/write functions so that they only prepare
  the I/O data without any register access.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
280808d8dd realtek: mdio: use regmap_bulk_write() in RTL930x path
Convert the RTL930x I/O path to the new bulk write pattern. For this

- Enhance the rtmdio_930x_run_cmd() helper to take care of all register
  access and error handling.
- Convert the c22/c45/read/write functions so that they only prepare
  the I/O data without any register access.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
5915fa8b74 realtek: mdio: use regmap_bulk_write() in RTL839x path
Convert the RTL839x I/O path to the new bulk write pattern. For this

- Enhance the rtmdio_839x_run_cmd() helper to take care of all register
  access and error handling.
- Convert the c22/c45/read/write functions so that they only prepare
  the I/O data without any register access.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Markus Stockhausen
2d2f0fbc70 realtek: mdio: use regmap_bulk_write() in RTL838x path
The regmap conversion only replaced the old sw() macros with their
regmap counterparts. Neither access optimization nor error handling
took place. Redesign the mdio access as follows:

- The c22/c45/read/write functions only prepare a data structure
  that describes the to-be-executed command.
- rtmdio_xxxx_run_cmd() is enhanced to bulk write the data into the
  SoC, issue all the I/O and do proper error handling. Additionally
  the signature is changed to allow read & write operations.

The bulk commands introduce some subtle changes.

- Before this patch only the needed registers were written. After
  the conversion all phy control registers are set up.
- The register write order changes

This is no issue as the hardware starts operation when issuing the
run_cmd() and only accesses the needed registers per operation.

For now adapt only the RTL838x path. Where needed rename "err" to
"ret" for consistency with kernel conventions.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23092
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 12:14:50 +02:00
Hauke Mehrtens
5309d460b0 realtek: refresh patches
Make the patches apply cleanly again.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-05-01 10:46:39 +02:00
John Audia
8ce1a59bb3 kernel: bump 6.18 to 6.18.24
Changelog: https://cdn.kernel.org/pub/linux/kernel/v6.x/ChangeLog-6.18.24

Removed upstreamed:
  backport-6.18/710-02-v7.1-net-sfp-add-quirks-for-Hisense-and-HSGQ-GPON-ONT-SFP.patch[1]

All patches automatically rebased via update_kernel.sh

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v6.18.24&id=0a59c12ce50a768e84982b65cce9c33459ef72d0

Build system: x86/64
Build-tested: x86/64-glibc
Run-tested: x86/64-glibc

Signed-off-by: John Audia <therealgraysky@proton.me>
Link: https://github.com/openwrt/openwrt/pull/22890
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-30 01:15:19 +02:00
Markus Stockhausen
a30c6aa556 realtek: dsa: drop array from stp_get signature
Now that the stp_set() helpers have been refactored the stp_get()
helpers can be simplified. Drop the last array parameter. It is
no longer needed/evaluated by its callers.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23080
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-29 23:23:11 +02:00
Markus Stockhausen
4b8af19582 realtek: dsa: remove family_id check from xstp_state_set()
The rtldsa_port_xstp_state_set() function offers a generic interface
to its callers to set the bridge state of one port. While it calls
device specific helpers in the background it runs the data mapping
for each architecture with a family_id check on its own. So the
hardware abstraction is done in two places

- rtldsa_port_xstp_state_set() translates one half
- its helper translate the other half

Convert the signature of the device specific helpers so that this
function does not need to know any hardware details. Instead move
the table/offset/bit calculations into the helpers. This way the
code path uses a consistent hardware abstraction.

- rtldsa_port_xstp_state_set() calls the helpers
- helpers do the hardware translation

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23080
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-29 23:23:11 +02:00
Sven Eckelmann
fcb2ff6ec6 realtek: rtl930x: mcx3: specify RTL8224 reset GPIO
The nRESET pins of the RTL8224 PHY on the MCX3 are wired to GPIO6 of the
SoC, but this was never described in the devicetree.

Commit c99a30668d5f ("realtek: add RTL8224 initialization to Realtek
driver") introduced support for reinitializing RTL8224 PHYs, and commit
084da38a2e74 ("realtek: mdio: activate multiple busses") allowed the MDIO
bus provider load the devicetree properties to the bus, including reset
descriptors. With both in place, a bus level PHY reset via the hardware pin
is now correctly triggered before reinitialization.

Add the missing reset-gpios property so the PHY can be reset via the
hardware pin.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Link: https://github.com/openwrt/openwrt/pull/22966
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-28 11:24:28 +02:00
Markus Stockhausen
0ba4e2c971 realtek: mdio: convert to regmap_assign_bits()
Use regmap_assign_bits() where it improves readability. With this
there is no need to calculate masks and values in separate lines.

Splitting the single update_bits() in rtmdio_931x_setup_polling()
into two separate assign_bits() is uncritical.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23099
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-28 00:41:18 +02:00
Rustam Adilov
596ce2845d realtek: arch: rtl-otto: add rtl9607 model info support
Add the registers, family id and cpu port defines to the mach header.
Since RTL96xx SoCs has additional "subtype" info, add the respective
property to soc_info struct to be used in prom file.

The same way as rtl838x, the chip_info register requires 0xa to be
written. Similarly, 0xb must be written to get the subtype info.
There doesn't seem any check for testchip in RTL96xx so, we ignore it.

Add subtype information to set_system_type function if it is present
using the added subtype variable.

There are some RTL9607 chips out there with 512MB so add the check
for RTL9607 in the prepare_highmem. The registers are the same as
in RTL9300 so nothing else need to be changed.

Signed-off-by: Rustam Adilov <adilov@tutamail.com>
Link: https://github.com/openwrt/openwrt/pull/23023
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-28 00:29:57 +02:00
Jonas Jelonek
0509464a93 realtek: refresh 'add-pcs-rtl-otto' patch
Refresh the patch to account for recent changes in the generic kernel
patches. Makes the CI kernel patch check happy again.

Fixes: c271123724fc ("generic: 6.18: fix MediaTek USXGMII driver")
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23127
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 15:23:43 +02:00
Jonas Jelonek
b447bf5686 realtek: pcs: rtl931x: drop USXGMII gating in setup_serdes
The USXGMII_10GDXGMII and USXGMII_10GQXGMII early-return was added
when the submode register was not yet programmed, making those modes
effectively unconfigurable. With the submode now wired up at probe
time and written from the set_mode path, the gating is no longer
needed.

Keep the XSGMII gate - RTL8218D/E bring-up through the proprietary
10G SGMII path is still unimplemented - and rewrite the surrounding
comment accordingly.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23120
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 13:47:18 +02:00
Jonas Jelonek
9eb0edfe2b realtek: pcs: rtl93xx: add remaining USXGMII submodes
Complete the USXGMII submode table with the four values that were
missing so far:

  0x01  10GDX    (2 x 5G)
  0x03  5GSX     (1 x 5G)
  0x04  5GDX     (2 x 2.5G)
  0x05  2_5GSX   (1 x 2.5G)

Together with the existing 10GSX (0x00) and 10GQX (0x02) this covers
all six USXGMII modes the driver declares. Add a corresponding mapping
to the hw_mode table too to cover them properly there.

Replace the switch in rtpcs_93xx_sds_apply_usxgmii_submode() with a
sparse lookup table indexed by hw_mode, using -1 as the sentinel for
modes without a submode value. Non-USXGMII modes silently no-op as
before; a USXGMII mode hitting a SerDes without an allocated submode
register now returns -EOPNOTSUPP, catching configuration mismatches
that would previously have been silently dropped.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23120
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 13:47:18 +02:00
Jonas Jelonek
23f04f6af8 realtek: pcs: rtl931x: enable USXGMII submode selection
USXGMII submode (10GSX vs 10GQX) is selected through a dedicated
register at 0x13e8, independent of the MAC and IP mode registers.
Without programming it, USXGMII-QX ports initialise as single-lane
SX and fail to link up correctly; MAC and IP mode alone are
insufficient for a working USXGMII setup.

The register packs 12 x 5-bit entries for SerDes 2..13, six per
32-bit word, non-straddling (bits 0..29 used, 30..31 padded). This
matches the available register dumps and the SDK's
reg_array_field_write() non-CROSS_REGISTERS path, which derives the
bit position as ((index - larray) % (32 / width)) * width and
accesses only a single 32-bit word. The submode values are identical
to RTL930x, so the shared RTPCS_93XX_SDS_USXGMII_SUBMODE_* defines
are reused.

Allocate the regmap_field at probe time with coordinates computed
from the SerDes ID; the regular packing needs no lookup table. Call
rtpcs_93xx_sds_apply_usxgmii_submode() from the set_mode dispatcher
after set_ip_mode - the helper's null-guard and mode filter leave
non-USXGMII paths unchanged.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23120
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 13:47:18 +02:00
Sven Eckelmann
ea3d646a08 realtek: dsa: postpone probe due to deferred PHYs
PHY drivers might need access to NVMEM or the filesystem to load
calibration/initialization data. The driver will then return -EPROBE_DEFER
to signal to the device core that the probe should be retried multiple
times again in the 10s driver_deferred_probe_timeout.

But when the switch driver calls dsa_register_switch(), it needs to connect
the PHYs directly. As result, all PHYs without an driver will automatically
get the default driver (either `genphy_c45_driver` or `genphy_driver`)
assigned and initialized. But for PHYs with the additional initialization
data from NVMEM/fs, this will usually result in not working PHYs.

Since there are Realtek based boards with RTL826x PHYs and the new driver
loads the initialization/patch values from rootfs, it is necessary to check
in the beginning of the probe function whether the PHYs are ready and the
probing can continue.

If some driver is still without driver after the deferred probe period
ended, the loading will just continue and the generic PHY drivers will
still be used.

Closes: #22811
Co-authored-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Co-authored-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Link: https://github.com/openwrt/openwrt/pull/23075
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:36:23 +02:00
Jonas Jelonek
6a23733437 realtek: pcs: rtl93xx: add shared MAC mode wrapper
RTL930x and RTL931x share a set of extras around MAC mode writes:

 - a post-write delay (kept for consistency with the original RTL930x
   behaviour; harmless on RTL931x)
 - the force-mode bit (RTL931x only, nullable field)

Add rtpcs_93xx_sds_set_mac_mode() as a shared wrapper around the
generic rtpcs_sds_set_mac_mode() that applies each of these extras
unconditionally; the nullable field makes the force-bit write a no-op
on RTL930x.

Route the three RTL93xx call sites (the 930x and 931x set_mode
dispatchers, and 931x set_ip_mode's OFF transition) through the
wrapper, removing the duplicated force-bit handling from each.

The USXGMII submode write stays out of the wrapper and is called
explicitly from the 930x dispatcher via rtpcs_93xx_sds_apply_usxgmii_submode().
Keeping submode as a separate step leaves room for RTL931x to apply it
from its IP-mode path once the submode register is wired up, without
retrofitting a MAC-mode wrapper with side effects.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Jonas Jelonek
1eeb9027d5 realtek: pcs: rtl931x: migrate MAC mode setting to regmap_field
RTL931x uses a regular 8-bit-per-SerDes layout in SERDES_MODE_CTRL, so
the reg_field can be computed in the probe hook with simple arithmetic.

The 8-bit-per-SerDes field is split into a 7-bit mac_mode (bits 0..6)
and a 1-bit mac_mode_force (bit 7), each written independently via its
own regmap_field. The mac_mode is widened to 7 bits (rather than the
5 bits strictly needed for the mode value) so MAC mode writes also
clear bit 5 (FEC enable) and bit 6 (10G speedup), matching the original
behaviour where the full 8-bit mask cleared these bits on every mode
change. FEC and speedup are mode-dependent and not yet programmed by
the driver; keeping them cleared leaves headroom for future support
without changing the effective register value.

rtpcs_931x_sds_reset() is updated to save and restore both fields
across the off/on cycle, preserving the original force-bit handling.
rtpcs_931x_sds_set_mode() uses the generic rtpcs_sds_set_mac_mode() and
sets the force bit explicitly; the same sequence also appears in
rtpcs_931x_sds_set_ip_mode()'s OFF transition. Both are folded into
the shared RTL93xx wrapper in a later commit.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Jonas Jelonek
df02f87cb9 realtek: pcs: rtl930x: migrate MAC mode setting to regmap_field
RTL930x packs 5-bit mode fields across four registers at irregular
positions. Express this as a static reg_field table indexed by SerDes
ID; the probe hook allocates the corresponding regmap_field. The
USXGMII submode register follows the same pattern with its own
reg_field table, allocated only for 10G-capable SerDes (id 2..9).

The generic rtpcs_sds_set_mac_mode() replaces the old
__rtpcs_930x_sds_set_mac_mode() helper. The previous behaviour of
writing OFF before the target mode is intentionally dropped — it was
RTL930x-specific and not required by the hardware.

The variant-level rtpcs_930x_sds_set_mode() is kept as a pure dispatch
between the IP mode path (set_ip_mode) and the MAC mode path. The
USXGMII submode write is factored into rtpcs_93xx_sds_apply_usxgmii_submode(),
which derives the submode value from hw_mode and no-ops on SerDes
without the submode register.

The __rtpcs_930x_sds_get_mac_mode() and __rtpcs_930x_sds_get_usxgmii_submode()
helpers are dropped. They were __always_unused and depended on the
removed parallel arrays. A future get_mode path will be added if a
caller needs it, likely mirroring the setter's wrapper shape.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Jonas Jelonek
a784d0ba36 realtek: pcs: rtl839x: migrate MAC mode setting to regmap_field
RTL839x packs the SerDes MAC mode in MAC_SERDES_IF_CTRL with a regular
per-SerDes layout, so the regmap_field can be computed directly in the
probe hook rather than declared as a static table.

Mode values (currently only OFF and QSGMII) move into a static
rtpcs_839x_sds_hw_mode_vals[] table. Values for 100BASEX, 1000BASEX
and SGMII from the vendor SDK are kept as comments for future
reference — they are not yet exercised here.

With no variant-specific extras (no force bit, no companion register,
no submode), rtpcs_839x_sds_set_mode() is removed; setup_serdes calls
the generic rtpcs_sds_set_mac_mode() directly.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Jonas Jelonek
bdf41ded29 realtek: pcs: rtl838x: migrate MAC mode setting to regmap_field
Replace rtpcs_838x_sds_set_mode()'s inline shift/mask arithmetic with
a regmap_field computed and allocated at probe time. The field layout
is regular (5-bit per SerDes, reverse-packed in SDS_MODE_SEL), so the
position can be derived arithmetically from the SerDes ID rather than
declared in a table.

The function keeps its wrapper role because SerDes 4 and 5 have a
second companion register (INT_MODE_CTRL) with its own per-mode value
encoding. Since RTL838x is the only variant with this quirk and the
register is written from only one call site, it is kept inline rather
than abstracted into its own config table.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Jonas Jelonek
ac916653b8 realtek: pcs: add regmap-based MAC mode infrastructure
All four Realtek PCS variants (RTL838x, RTL839x, RTL930x, RTL931x)
configure the SerDes MAC mode by writing a register field whose layout
varies per variant — different base registers, different bit positions,
and in some cases per-SerDes packing that isn't arithmetically regular.

Add the common infrastructure to express this uniformly:

 - per-SerDes regmap_field pointers in a new 'swcore_regs' anonymous
   struct on rtpcs_serdes: mac_mode, mac_mode_force (931x only, nullable)
   and usxgmii_submode (930x only, nullable).

 - a per-variant mode-value table pointer (sds_hw_mode_vals) on
   rtpcs_config, keyed by enum rtpcs_sds_mode. Values are s16 with -1 as
   the "unsupported" sentinel — u8 with 0 would collide with RTL839x's
   OFF value (0x0).

 - a generic rtpcs_sds_set_mac_mode() that looks up the value for the
   requested mode and writes it via the regmap_field.

Variant-specific extras (post-write delay, force bit, companion register
writes, USXGMII submode handling) will be added in per-variant wrappers
in the following commits.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23040
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-27 10:34:32 +02:00
Markus Stockhausen
eb4b4b3107 realtek: eth: convert eth_probe() to regmap
Remove the last sw() macros from the ethernet driver.
With this drop the required include line.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:17 +02:00
Markus Stockhausen
4e927d77b4 realtek: eth: convert set_features() to regmap
Use regmap_assign_bits() for conversion and much simpler code.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:17 +02:00
Markus Stockhausen
fb874fcef7 realtek: eth: convert mac functions to regmap
Besides converting some functions to regmap do some minor
refactoring for rteth_931x_init_mac().

- Use dev_err() instead of classic print functions
- Harmonize ALE_INIT error handling. ALE_INIT_2 has the same
  logic as the other registers. The reset is finished as soon
  as the register is completely zero.
- From testing 100ms poll timeout seems to be sufficient

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:17 +02:00
Markus Stockhausen
62e0f63aa3 realtek: eth: convert link up/down to regmap
Make use of regmap in rteth_mac_link_down and rteth_mac_link_up.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:17 +02:00
Markus Stockhausen
0102403696 realtek: eth: more regmap refactoring
Convert rteth_start_xmit() and rteth_hw_stop() to regmap.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:17 +02:00
Markus Stockhausen
80a3c35d9e realtek: eth: convert rteth_XXXX_hw_stop() to regmap
Use regmap in the following functions

- rteth_838x_hw_stop()
- rteth_839x_hw_stop()
- rteth_930x_hw_stop()
- rteth_931x_hw_stop()

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23067
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-27 00:38:16 +02:00
Jan Hoffmann
c78e2fe26d realtek: fix SMBus Rollball access
The Rollball command byte needs to be written last. Otherwise the
controller might access the wrong register or write the wrong value.

Fixes: 1fc19bc06edc ("realtek: rtl93xx: mdio-smbus support for clause 45 and Rollball SFPs")
Signed-off-by: Jan Hoffmann <jan@3e8.eu>
Link: https://github.com/openwrt/openwrt/pull/23049
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-26 09:51:09 +02:00
Jan Hoffmann
45633073fe generic: net: phy: realtek: don't disable MDIO address 0 for PHY in SFP module
At least the XikeStor SKT-2.5G-100M SFP module seems to internally use
MDIO address 0 to access the PHY. This module allows accessing PHY
registers using Rollball protocol on address 0x51, and also provides
read-only C22 access on address 0x56. However, after disabling the
PHYAD0 configuration bit, only 0xffff can be read via both methods
(except for MMD device 30 which can still be accessed).

Since having MDIO address 0 enabled shouldn't do any harm on SFP modules
just leave the configuration bit alone in that case.

Signed-off-by: Jan Hoffmann <jan@3e8.eu>
Link: https://github.com/openwrt/openwrt/pull/23065
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-26 09:47:23 +02:00
Markus Stockhausen
a4a6a06c9f realtek: mdio: fix "SMY" typo
The defines should have been named SMI like everywhere else.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23070
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-26 09:39:47 +02:00
Markus Stockhausen
aaf91b7b62 realtek: mdio: harden defines
Add brackets to avoid silent bugs.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23070
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
2026-04-26 09:39:47 +02:00
Carlo Szelinsky
8275b62ecd realtek: rtl930x: add Hasivo S600WP-5GT-2SX-SE
This commit adds support for Hasivo S600WP-5GT-2SX-SE switch.

Device specification
--------------------
SoC Type:               Realtek RTL9303
RAM:                    128MB DDR3 SDRAM
Flash:                  Fudan FM25Q128A (16 MB)
Ethernet:               5x RTL8221B 10/100/1000/2500Mbps PHY (RJ45)
                        2x SFP+ 10G (I2C/DOM via bit-banged GPIO)
LEDs:                   1x power green (no control)
                        1x system green (via RTL9303 GPIO)
                        3x RJ45 LEDs/port (HC595 shift regs on LED SPI)
                                1x Green (1G link)
                                1x Green (10M/100M link)
                                1x Orange (2.5G link)
                        2x SFP+ LEDs/port (HC595 shift regs on LED SPI)
                                1x 10G link
                                1x 1G link
Button:                 Reset
USB ports:              None
Bootloader:             Realtek U-Boot 2011.12
PoE:                    1x HS104PTI for 802.3af/at/bt PoE (driver
                        will follow in a separate patch)

Installing OpenWrt
------------------
1. UART RJ45 requires soldering a connector to the empty footprint (RJ1).
   (Amphenol RJHSEE380 or similar)
2. Connect to UART 38400@8n1, using Cisco Console Rollover cable (RS232)
3. Enter bootloader by pressing esc key during boot
4. Enter password `Hs2021cfgmg`
5. Type `XXXX` to get into U-Boot
6. Increase baudrate: `setenv baudrate 115200`
7. Use serial transfer (Y modem) via minicom:
   `loady 0x84f00000`
   Then send the initramfs image via minicom's Y modem upload.
8. `bootm 0x84f00000`

Now you should be in OpenWrt, and can use sysupgrade to install.

Signed-off-by: Carlo Szelinsky <github@szelinsky.de>
Link: https://github.com/openwrt/openwrt/pull/22310
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-24 12:17:26 +02:00
Jonas Jelonek
90c0a37ddc realtek: pcs: switch SerDes polarity to {rx,tx}-polarity
With the recent backport of the common PHY properties infrastructure
(phy-common-props and the phy_get_manual_{rx,tx}_polarity() helpers) to
OpenWrt, the generic `{rx,tx}-polarity` device tree properties are now
usable for the Realtek PCS driver. Switch the driver and all affected
boards from the local vendor-specific `realtek,pnswap-{rx,tx}` booleans
to the common properties.

Add a `config_polarity` SerDes op (implemented by RTL930x and RTL931x;
RTL838x/RTL839x polarity support not yet added) and a generic wrapper
that resolves the requested polarity via phy_get_manual_{rx,tx}_polarity()
and dispatches to the op. Variants without the op silently accept the
default polarity but warn when a non-default polarity is requested,
since that cannot be honored.

Move the polarity programming out of the variant setup_serdes callbacks
into rtpcs_pcs_config, so it runs before setup_serdes. This matches the
ordering used by the vendor SDK, which configures polarity first.

Update all board DTS files that previously used `realtek,pnswap-{rx,tx}`
to the new `{rx,tx}-polarity = <PHY_POL_INVERT>` property, and select
PHY_COMMON_PROPS from Kconfig.

Each SerDes now retains its DT node for later polarity lookup. Use
for_each_child_of_node_scoped for the iterator, and register a
devm_add_action_or_reset for each stored reference so it is released on
unbind or probe failure.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23044
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-24 10:13:38 +02:00
Markus Stockhausen
3271071579 realtek: eth: harden receive path
The hardware usually takes care that

- a packet is no larger than the available buffer
- has at least a FCS checksum of 4 bytes

Nevertheless be cautious and improve the existing
packet check. Just in case ...

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/22884
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-24 09:47:04 +02:00
Markus Stockhausen
77ddfcfbcb realtek: mdio: simplify regmap_update_bits
Some occurrences of regmap_update_bits can be simplified by
using other regmap commands. Use set_bits/clear_bits/assign_bits
for better readability.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23039
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 17:01:49 +02:00
Markus Stockhausen
6ce041be4b realtek: dsa: drop legacy table commands
All consumers of legacy table commands have been refactored and
use the rtl_table helpers. Drop unused code.

rtl839x_exec_tbl2_cmd() cannot be dropped as it is still used
in the qos code. Keep it for now.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23037
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 16:59:29 +02:00
Markus Stockhausen
1212db4d3f realtek: dsa: convert rtl931x stp functions to table helpers
rtldsa_931x_stp_get() and rtl931x_stp_set() use legacy table code.
Replace that with rtl_table_xxx() helpers.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23037
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 16:59:28 +02:00
Markus Stockhausen
511aa294a9 realtek: dsa: convert rtl930x stp functions to table helpers
rtldsa_930x_stp_get() and rtl930x_stp_set() use legacy table code.
Replace that with rtl_table_xxx() helpers.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23037
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 16:59:28 +02:00
Markus Stockhausen
e9bbf546c8 realtek: dsa: convert rtl839x stp functions to table helpers
rtldsa_839x_stp_get() and rtl839x_stp_set() use legacy table code.
Replace that with rtl_table_xxx() helpers.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23037
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 16:59:28 +02:00
Markus Stockhausen
e202670213 realtek: dsa: convert rtl838x stp functions to table helpers
rtldsa_838x_stp_get() and rtl838x_stp_set() use legacy table code.
Replace that with rtl_table_xxx() helpers.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/23037
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-04-22 16:59:28 +02:00