net: pse-pd: add Realtek PSE MCU support
Subsystems (5)
Jonas Jelonek
maintainerv14 cover net: pse-pd: add Realtek PSE MCU support
This series adds a PSE-PD driver for the microcontroller (MCU) that fronts the PSE silicon on a range of managed switches, together with its DT binding.
Hardware model
==============
These boards do not expose the PSE chips to the host directly. A small microcontroller sits on an I2C/SMBus or UART bus and manages one or more PSE chips behind it; the host CPU only ever talks to that MCU, using a fixed 12-byte request/response protocol with a trailing checksum. The PSE silicon never appears on the bus.
Two generations of the protocol exist, both Realtek's: an older one on boards with Broadcom PSE silicon (BCM59111, BCM59121) and a newer one used with Realtek's own PSE silicon (RTL8238B, RTL8239, RTL8239C). They diverge in opcode numbering and a few response layouts; the driver abstracts that behind a per-dialect opcode table and parser hooks, selected by the compatible. The specific PSE chip behind the MCU is detected at runtime and only influences per-chip constants (power scaling and the per-port cap).
The compatibles
===============
The protocol compatibles name two generations of the Realtek protocol, with the I2C framing folded in:
realtek,pse-mcu-gen1 gen1, UART realtek,pse-mcu-gen1-smbus gen1, I2C/SMBus realtek,pse-mcu-gen2 gen2, UART realtek,pse-mcu-gen2-smbus gen2, I2C/SMBus realtek,pse-mcu-gen2-i2c gen2, raw I2C
and each board carries a device-specific compatible that falls back to one of these, e.g.
compatible = "zyxel,xs1930-12hp-pse", "realtek,pse-mcu-gen2-smbus";
The naming is the part most likely to raise questions, so the reasoning up front (the binding documents it too):
- The node describes the MCU together with its Realtek firmware, not a PSE chip and not the microcontroller silicon. The PSE chips sit behind the MCU, never appear on the bus, and are reported by the MCU and detected at runtime; the microcontroller itself is a general-purpose part (GigaDevice, Nuvoton, ...) that varies across boards. What is fixed and Realtek's is the firmware and its host protocol - hence the 'realtek' prefix.
- gen1 and gen2 are two generations of that protocol, both Realtek's:
gen1 on older boards fronting Broadcom PSE silicon, gen2 the altered protocol used once Realtek shipped their own PSE silicon. The generation is fixed per board and is all the driver needs at DT-parse time, so the compatible encodes it.
- On I2C the MCU firmware expects one of two framings - SMBus or raw I2C - which is a genuine programming-model difference, so it is part of the compatible ('-smbus' / '-i2c'). A UART attachment carries no framing suffix; the transport is given structurally by the parent 'serial' node.
- Each board additionally carries a device-specific compatible that falls back to the protocol one. The driver only ever binds on the protocol compatible; the device-specific string keeps the binding specific and reserves a place for a future per-board quirk without having to retrofit device trees already deployed in the field.
Testing
=======
- Linksys LGS328MPCv2 (RTL8238B, I2C) - Zyxel GS1900-10HP A1 (BCM59121, UART) - Zyxel GS1900-10HP B1 (RTL8238B, UART) - Zyxel GS1920-24HPv2 (BCM59121, SMBus) - Zyxel XMG1915-10EP (RTL8239C, UART) - Zyxel XS1930-12HP (RTL8239, SMBus)
---
v13 -> v14:
- core: on a NOT_READY reply (MCU busy), resend the command a bounded
number of times before failing, instead of returning -EAGAIN at once
(matches the userspace realtek-poe behaviour); effectively UART-only,
as I2C absorbs NOT_READY in its poll. (Sashiko)
- core: reword the set_pw_limit comment - the value/type ordering isn't
atomic; document that a mid-sequence failure leaves the previous or
the requested cap, never a stale one (no read-modify-write added)
(Sashiko)
- header: reword the resp_is_final comment - seq_num rejects a stale
normal reply; the terminal error opcodes match unconditionally, since a
request the MCU couldn't parse carries no seq to correlate (Sashiko)
v13: https://lore.kernel.org/netdev/[email protected]/
Sashiko review: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260811091218.353399-1-jelonek.jonas%40gmail.com
v12 -> v13:
- dt-bindings: added Reviewed-by from Kory
- core: clamp get_pw_limit/get_prio read-backs to the advertised max
(max_mW_per_port / pis_prio_max), matching what set + range enforce
(Sashiko)
- core: set_pw_limit programs the value before the user-mode switch, so
a failed value command keeps the port's previous cap (Sashiko)
- core: clarify disable-ports comment (also not re-gated on a later
probe error) (Sashiko)
- core: NOT adding Reviewed-by from Kory, again changes to the core
- i2c: added Reviewed-by from Kory
- uart: revert the recv non-final-frame loop back to a single wait — it
could drop a coalesced follow-up frame, issue that Sashiko raised
before hasn't been observed on real hardware; Kory's Reviewed-by
restored
v12: https://lore.kernel.org/netdev/[email protected]/
Sashiko review: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260809112251.5797-1-jelonek.jonas%40gmail.com
v11 -> v12:
- all: dropped all Reviewed-by/Acked-by due to changes
- dt-bindings: AI review declined, no changes
- core: reserve seq_num 0 to avoid an all-zero garbage frame passing
as valid reply (Sashiko)
- core: reword disable-ports comment (Sashiko)
- i2c: drop DMA bounce buffer since the assumption about DMA behavior
was invalid (Sashiko)
- i2c: const-correct the SMBus send cast (Sashiko)
- i2c: reword commit message regarding DMA (Sashiko)
- uart: recv() waits past non-final frames (NOT_READY/stale) within
budget
v11: https://lore.kernel.org/netdev/[email protected]/
Sashiko review: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260802100114.720594-1-jelonek.jonas%40gmail.com
v10 -> v11:
- patch 1: added Reviewed-by from Oleksij
- patch 2: added Acked-by from Oleksij
- rebase due to conflict in MAINTAINERS
v10: https://lore.kernel.org/netdev/[email protected]/
v9 -> v10:
- patch 2: fixed ordering in MAINTAINERS
- core: dropped unused fields, can be re-added later when actually
needed (Sashiko)
- core: harden frame desync for I2C by including seq_num in _is_final
helper (Sashiko)
- core: return constant voltage when MCU reports zero, in case the
port is not delivering. This avoids "Voltage null" errors in case a
power limit is set while port is not delivering (Sashiko)
- core: set_pw_limit: round up to avoid setting 0 in case the requested
limit is below 1 LSB (Sashiko)
- core: de-assert global port disable after MCU was discovered
successfully (Sashiko)
- core: fix and make more precise several comments (Sashiko)
v9: https://lore.kernel.org/all/[email protected]/
Sashiko review: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260726112223.1286074-1-jelonek.jonas%40gmail.com
v8 -> v9:
- dt-bindings: renamed enable-gpios -> reset-gpios, verified on boards that the GPIO which is used with this is connected to the MCU's nRESET.
- dt-bindings: added disable-ports-gpios for GPIO that gates all ports (previously incorrectly assumed to be a rail gate, thus being wired via 'power-supply')
- dt-bindings: dropped 'power-supply', not used anymore and confusing, easy to confuse with PI's vpwr-supply (Sander)
- core: adjusted to match bindings, handling reset/disable-ports-gpio correctly and dropping 'power-supply' regulator stuff
- patch 1,2: dropped Reviewed-by/Acked-by tags due to changes.
- patch 3,4: added Reviewed-by from Kory
v8: https://lore.kernel.org/all/[email protected]/
v7 -> v8:
- dt-bindings: added Reviewed-by of Oleksij
- uart: check and warn-on-error for serdev_* operations (Oleksij)
- core, i2c, uart: added Acked-by of Oleksij
v7: https://lore.kernel.org/netdev/[email protected]/
v6 -> v7:
- dt-bindings: rename file to 'realtek,pse-mcu-gen1.yml', using specific compatible as file name (Conor)
- dt-bindings: added Conor's Reviewed-by
- core: replaced some leftover 'BCM/RTK' dialect framing in comments
- core: use rolling sequence number instead of always hardcoded 0xff, adressing the issue that stale data might be accepted for new requests (Sashiko)
- core: reordered MODULE_ calls to keep consistent across all driver parts
- i2c: replaced some leftover 'BCM/RTK' dialect framing in comments
- slight commit message adjustments
v6: https://lore.kernel.org/netdev/[email protected]/
v5 -> v6:
- dt-bindings: reworked the compatibles per DT-maintainer feedback
- name the two protocol generations -gen1 / -gen2 (both Realtek's) instead of the -rtk / -brcm dialect suffix (Conor)
- encode the I2C framing in the compatible (-smbus / raw -i2c) and drop the realtek,i2c-protocol property (Rob)
- add device-specific (switch) compatibles that fall back to the protocol compatibles, with the board↔protocol pairing enforced in the schema (Conor)
- rewrite the description accordingly
- driver: track the binding rework
- match on realtek,pse-mcu-gen{1,2}[-smbus|-i2c]; the I2C transport selects SMBus-vs-raw framing from a native_i2c match-data flag instead of reading the property (drops rtpse_mcu_needs_i2c_proto)
- rename the internal dialect and parser symbols rtk/brcm → gen1/gen2 (chip identifiers like RTL8238B/BCM59121 kept)
- i2c: DMA-safe raw-I2C path — bounce each frame through a heap buffer, since i2c_master_send()/i2c_master_recv() may DMA and the core's frame buffers are on the stack (SMBus and UART paths unaffected) (sashiko-nipa)
- includes: drop unused linux/mod_devicetable.h (core) (Uwe)
- includes: drop unused linux/delay.h (uart); add linux/regulator/consumer.h (core) and linux/slab.h + linux/string.h (i2c)
- commit messages — update the binding, core, and I2C messages to match (generations, framing-in-compatible, DMA note)
v5: https://lore.kernel.org/netdev/[email protected]/
v4 -> v5:
- split the single driver patch into three — core / I2C transport / UART transport. Binding stays patch 1, unchanged in shape. (Paolo) Please give guidance on how to if I should split more.
- core: set_pw_limit: guard divide-by-zero on pw_set_lsb_mW; cap the programmed value with U8_MAX instead of a bare 0xff; prg_val is now u8. (Oleksij, Sashiko)
- core: discover: also retry transient boot-time frames (-EBADMSG / -EBADE) within the bounded window, not just silence/NAK/not-ready (Sashiko).
- core: pw_status: report Broadcom 0x3 → TEST and 0x5 → OTHERFAULT (new STS_TEST/STS_OTHER_FAULT); pw_class comment corrected (0x3/0x5 aren't "other fault" on RTL; class-0-vs-fault note). (Sashiko)
- core: dropped unused decoded fields — function_mode, cls_type, disconnect_type, pair_type, inrush_mode, limit_type, chip_addr, channel. (Oleksij)
- core: removed forward declarations by moving the response structs above the dialect struct. (Oleksij)
- core: get_pw_limit_ranges: reverse-Christmas-tree local ordering. (Oleksij)
- core: dialect comment clarified (only divergent responses are hooked); commit message "parser hooks" tightened to "…for the responses that differ." (Sashiko)
- core: made parse_system_info hook void, both implementations return hardcoded 0. (Paolo)
- core: dropped GFP_KERNEL from kzalloc_obj. (Paolo)
- core: dropped unneeded u32 cast
- kept probe dev_info() for now deliberately, due to different opinions on whether a probe might print or not
- NOT included Acked-by from Oleksij, due to several changes
v4: https://lore.kernel.org/netdev/[email protected]/
v3 -> v4:
- move owner setting from core to transport, mitigating possible use-after-free (Sashiko)
- resend because net-next was still closed
v3: https://lore.kernel.org/netdev/[email protected]/
v2 -> v3:
- dt-bindings: using brcm instead of bcm for Broadcom
- rename the driver files and Kconfig symbols to realtek-pse-mcu-* / PSE_REALTEK_MCU* for consistency with the realtek,pse-mcu-* compatibles
- rename driver-internal prefix from 'rtpse_' to 'rtpse_mcu' to emphasize this targets the MCU-centric setup (and leaves room open for eventual directly addressable PSE chips)
- rework the vendor-prefix rationale (binding + commit message): the prefix names the protocol/firmware owner (Realtek documents the protocol and supplies the firmware), and -rtk/-brcm select the Realtek or Broadcom protocol dialect
- core: reject zeroed/echo-mismatched responses via the echoed seq_num (a BCM PORT_ENABLE on port 0 was otherwise accepted from an all-zero frame)
- core: enable the PoE supply before global-enabling the MCU, and roll back the global enable on probe failure or driver removal
- core: drop inline from helpers (flagged by automated check)
- uart: update the completion under rx_lock too, so a late frame can no longer make the next transaction fail spuriously with -EIO
v2: https://lore.kernel.org/netdev/[email protected]/
v1 -> v2:
- all points flagged by Sashiko addressed:
- uart: drop frame overflow (return count, not the stored length) so serdev retains no leftover bytes that would misalign the next response
- uart: guard rx_buf/rx_len with a spinlock to close a data race between the async receive_buf callback and send/recv
- i2c: return terminal MCU error opcodes (0xfd/0xfe) to the core immediately instead of polling to the 1 s timeout
- core: cap BCM59121 at 30 W (802.3at) — the basic 8-bit set command can't program the advertised 60 W (it silently clamped to 51 W)
v1: https://lore.kernel.org/netdev/[email protected]/
---
Jonas Jelonek (4):
dt-bindings: net: pse-pd: add bindings for Realtek PSE MCU
net: pse-pd: add Realtek PSE MCU core
net: pse-pd: realtek-pse-mcu: add I2C transport
net: pse-pd: realtek-pse-mcu: add UART transport
.../net/pse-pd/realtek,pse-mcu-gen1.yaml | 182 ++++ MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 28 + drivers/net/pse-pd/Makefile | 3 + drivers/net/pse-pd/realtek-pse-mcu-core.c | 998 ++++++++++++++++++ drivers/net/pse-pd/realtek-pse-mcu-i2c.c | 148 +++ drivers/net/pse-pd/realtek-pse-mcu-uart.c | 164 +++ drivers/net/pse-pd/realtek-pse-mcu.h | 94 ++ 8 files changed, 1624 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-core.c create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-i2c.c create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-uart.c create mode 100644 drivers/net/pse-pd/realtek-pse-mcu.h
base-commit: 3da8c3c8b8fa99505624b65ef590482f48e766b6
Signature · 1 line
2.53.0
Jonas Jelonek
maintainerPATCH v14 1/4 dt-bindings: net: pse-pd: add bindings for Realtek PSE MCU
Add a binding for the microcontroller (MCU) that fronts the PSE silicon on a range of managed Realtek-based switches. The host talks only to the MCU, over I2C/SMBus or UART, using a fixed message-based protocol; the PSE chips behind it never appear on the bus.
The device is the MCU together with its Realtek firmware: the firmware and its host protocol are what the binding describes, not the general-purpose microcontroller they run on. The PSE silicon behind the MCU (Realtek or Broadcom) is reported by the MCU and detected at runtime, so it is not described here - hence the 'realtek' vendor prefix.
Two protocol generations exist, both Realtek's, selected by the
compatible: gen1 on older boards (fronting Broadcom PSE silicon) and gen2, the altered protocol used with Realtek's own PSE silicon. On an I2C attachment the framing the MCU firmware expects is part of the compatible as well - '-smbus' or raw '-i2c'; a UART attachment carries no framing suffix, as the transport is given by the parent serial node.
Each board additionally carries a device-specific compatible that falls back to one of the protocol compatibles above. Drivers bind on the protocol compatible; the device-specific string identifies the board and reserves a place for a future per-board quirk without having to retrofit device trees already in the field.
--- .../net/pse-pd/realtek,pse-mcu-gen1.yaml | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml new file +182 -0
@@ -0,0 +1,182 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/realtek,pse-mcu-gen1.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek PSE MCU + +maintainers: + - Jonas Jelonek <[email protected]> + +description: | + A microcontroller (MCU) that manages the PSE (Power Sourcing Equipment) + hardware on a range of managed PoE switches. The host CPU talks only to + this MCU - over I2C/SMBus or UART - using a small message-based protocol; + the PSE silicon it drives sits behind the MCU and is never accessed + directly. For example, on the Zyxel GS1900-10HP the SoC reaches the MCU + over UART, and the MCU manages the on-board PSE chip. + + This binding describes the MCU together with its Realtek firmware: the + firmware and its host protocol, which are stable across boards. The + microcontroller silicon is a general-purpose part that varies, and the + PSE silicon behind the MCU (Realtek RTL823x/RTL8239* or Broadcom + BCM59xxx) is reported by the MCU and detected at runtime - neither is + named here. + + Two protocol generations exist, both Realtek's: + gen1 older boards, where the MCU fronts Broadcom PSE silicon + gen2 the altered protocol used with Realtek's own PSE silicon + + On an I2C attachment the framing the MCU firmware expects is part of the + compatible: '-smbus' (reads carry a leading command byte and a repeated + start) or '-i2c' (bare block writes and reads). A UART attachment carries + no framing suffix; the transport is given by the parent 'serial' node. + + Each board additionally carries a device-specific compatible that falls + back to one of the protocol compatibles above. Drivers bind on the + protocol compatible; the device-specific string identifies the board and + reserves a place for a future per-board quirk without having to retrofit + device trees already in the field. + +properties: + compatible: + oneOf: + # UART + - items: + - enum: + - zyxel,gs1900-10hp-a1-pse + - const: realtek,pse-mcu-gen1 + + # I2C, SMBus framing + - items: + - enum: + - zyxel,gs1920-24hp-v2-pse + - const: realtek,pse-mcu-gen1-smbus + + # UART + - items: + - enum: + - zyxel,gs1900-10hp-b1-pse + - zyxel,xmg1915-10ep-pse + - const: realtek,pse-mcu-gen2 + + # I2C, SMBus framing + - items: + - enum: + - zyxel,xs1930-12hp-pse + - const: realtek,pse-mcu-gen2-smbus + + # I2C, raw framing + - items: + - enum: + - linksys,lgs328mpc-v2-pse + - const: realtek,pse-mcu-gen2-i2c + + reg: + maxItems: 1 + + reset-gpios: + description: Reset line of the MCU. + maxItems: 1 + + disable-ports-gpios: + description: + Hardware gate that forces all ports into admin-disabled state while + asserted. + maxItems: 1 + +required: + - compatible + +allOf: + - $ref: pse-controller.yaml# + # A '-smbus'/'-i2c' compatible is an I2C attachment: it has 'reg' and + # cannot carry serial bus properties. A bare gen compatible is a UART + # attachment: no 'reg', the transport comes from the parent serial node. + - if: + properties: + compatible: + contains: + enum: + - realtek,pse-mcu-gen1-smbus + - realtek,pse-mcu-gen2-smbus + - realtek,pse-mcu-gen2-i2c + then: + required: + - reg + properties: + current-speed: false + max-speed: false + else: + allOf: + - $ref: /schemas/serial/serial-peripheral-props.yaml# + + properties: + reg: false + +unevaluatedProperties: false + +examples: + # SMBus-framed I2C attachment + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@20 { + compatible = "zyxel,xs1930-12hp-pse", "realtek,pse-mcu-gen2-smbus"; + reg = <0x20>; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + }; + + # Raw-I2C-framed attachment + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@20 { + compatible = "linksys,lgs328mpc-v2-pse", "realtek,pse-mcu-gen2-i2c"; + reg = <0x20>; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + }; + + # UART attachment + - | + serial { + ethernet-pse { + compatible = "zyxel,gs1900-10hp-a1-pse", "realtek,pse-mcu-gen1"; + current-speed = <19200>; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + };
Signature · 1 line
2.53.0
Jonas Jelonek
maintainerPATCH v14 2/4 net: pse-pd: add Realtek PSE MCU core
In reply to Jonas JelonekA range of managed Realtek-based PoE switches use a small microcontroller on the PCB to front the actual PSE silicon. The host CPU talks to that MCU over I2C/SMBus or UART using a fixed 12-byte request/response protocol with a trailing checksum; the PSE chips are managed by the MCU and are not accessed directly. Two generations of the protocol exist - both Realtek's - diverging in opcode numbering and a few response layouts; the driver handles this with a per-dialect opcode table and parser hooks for the responses that differ, selected by the compatible. The specific PSE chip behind the MCU is detected at runtime and only influences per-chip constants (power scaling and the per-port cap).
This core module implements the protocol, message framing, the dialect machinery and the pse_controller_ops glue, and exports a registration helper for transport modules. The I2C and UART transports that drive it follow in the next patches; the core (PSE_REALTEK_MCU) is selected automatically by those transports and is not user-selectable on its own.
The realtek-pse-mcu-* files and PSE_REALTEK_MCU* symbols match the realtek,pse-mcu-* compatibles (see the binding for the naming rationale). The two protocol generations - gen1 on older Broadcom-PSE boards, gen2 on Realtek's own PSE silicon - are both Realtek's, handled by the same shared core, each selecting its dialect via the compatible.
Power budgeting is left to the MCU firmware; the driver advertises PSE_BUDGET_EVAL_STRAT_DYNAMIC accordingly.
--- MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 6 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/realtek-pse-mcu-core.c | 998 ++++++++++++++++++++++ drivers/net/pse-pd/realtek-pse-mcu.h | 94 ++ 5 files changed, 1106 insertions(+) create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-core.c create mode 100644 drivers/net/pse-pd/realtek-pse-mcu.h
MAINTAINERS +7 -0
@@ -22773,6 +22773,13 @@ S: Maintained F: Documentation/devicetree/bindings/watchdog/realtek,otto-wdt.yaml F: drivers/watchdog/realtek_otto_wdt.c +REALTEK PSE MCU DRIVER +M: Jonas Jelonek <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu-gen1.yaml +F: drivers/net/pse-pd/realtek-pse-mcu* + REALTEK RTL83xx SMI DSA ROUTER CHIPS M: Linus Walleij <[email protected]> M: Luiz Angelo Daros de Luca <[email protected]>
drivers/net/pse-pd/Kconfig +6 -0
@@ -13,6 +13,12 @@ menuconfig PSE_CONTROLLER if PSE_CONTROLLER +config PSE_REALTEK_MCU + tristate + help + Shared core for the Realtek PSE MCU driver. This is selected + automatically by the transport options below. + config PSE_REGULATOR tristate "Regulator based PSE controller" help
drivers/net/pse-pd/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o +obj-$(CONFIG_PSE_REALTEK_MCU) += realtek-pse-mcu-core.o obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o obj-$(CONFIG_PSE_PD692X0) += pd692x0.o obj-$(CONFIG_PSE_SI3474) += si3474.o
drivers/net/pse-pd/realtek-pse-mcu-core.c new file +998 -0
998 lines not on this page · raw message
drivers/net/pse-pd/realtek-pse-mcu.h new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next v14 2/4] net: pse-pd: add Realtek PSE MCU core
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] rtpse_mcu_resp_is_final() excludes RTPSE_MCU_OPCODE_NOT_READY, which breaks the bounded retry…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] rtpse_mcu_resp_is_final() excludes RTPSE_MCU_OPCODE_NOT_READY, which breaks the bounded retry mechanism. --
--- Patch [2]: [PATCH net-next v14 2/4] net: pse-pd: add Realtek PSE MCU core --- commit 4ec3b6f7573cbef331580bfd04e92ce4ccdb71d2
Author: Jonas Jelonek <[email protected]>
net: pse-pd: add Realtek PSE MCU core
This commit introduces the core driver module for the microcontroller fronting PSE silicon on Realtek-based PoE switches. It implements the message-based protocol, parsing for Gen1 and Gen2 dialects, and exposes a registration interface for transport drivers.
Quoted 3 lines
drivers/net/pse-pd/realtek-pse-mcu.h new file +0
-0@@ -0,0 +1,94 @@
[ ... ]
drivers/net/pse-pd/realtek-pse-mcu.h line 59
Quoted 13 lines
drivers/net/pse-pd/realtek-pse-mcu.h new file +13
-0+/* +* A polling transport can stop here: the reply to this request (opcode and +* seq_num) or a terminal error. The seq_num rejects a stale normal reply; the +* terminal errors match unconditionally, as a request the MCU couldn't parse +* carries no seq_num to correlate against. +*/ +static inline bool rtpse_mcu_resp_is_final (const struct rtpse_mcu_msg *req, +const struct rtpse_mcu_msg *resp) +{ +return (resp->opcode == req->opcode && resp->seq_num == req->seq_num) || + resp->opcode ==RTPSE_MCU_OPCODE_INCOMPLETE || + resp->opcode ==RTPSE_MCU_OPCODE_BAD_CSUM ; +}
[Severity: Medium]
Does rtpse_mcu_resp_is_final() need to include RTPSE_MCU_OPCODE_NOT_READY?
If a polling transport relies on this helper to wait for the MCU response, it will ignore NOT_READY messages and continue polling until it times out.
This would prevent the core driver from handling the transient busy state, as the transport would return a timeout error instead of passing the NOT_READY reply back to rtpse_mcu_do_xfer() for its bounded retry loop:
drivers/net/pse-pd/realtek-pse-mcu-core.c:rtpse_mcu_do_xfer() {
...
ret = pse->transport->recv(pse, req, resp);
if (ret)
return ret;
...
/* NOT_READY: MCU busy, wants the command resent; bounded retry. */
if (resp->opcode != RTPSE_MCU_OPCODE_NOT_READY ||
tries >= RTPSE_MCU_NOT_READY_RETRIES)
break;
msleep(RTPSE_MCU_RESPONSE_MS);
...
}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Jonas Jelonek
maintainerPATCH v14 3/4 net: pse-pd: realtek-pse-mcu: add I2C transport
In reply to Jonas JelonekAdd the I2C/SMBus transport for the Realtek PSE MCU core. It registers the MCU on an I2C bus and provides the send/recv callbacks the core uses to exchange the 12-byte frames.
The MCU firmware expects one of two framings on the I2C bus, and which one is part of the compatible: '-smbus' (reads carry a leading command byte and a repeated start) or raw '-i2c' (bare block writes and reads). The match data flags the raw-I2C case; SMBus is the default because that's what the majority of devices uses.
--- drivers/net/pse-pd/Kconfig | 11 ++ drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/realtek-pse-mcu-i2c.c | 148 +++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-i2c.c
drivers/net/pse-pd/Kconfig +11 -0
@@ -19,6 +19,17 @@ config PSE_REALTEK_MCU Shared core for the Realtek PSE MCU driver. This is selected automatically by the transport options below. +config PSE_REALTEK_MCU_I2C + tristate "Realtek PSE MCU driver (I2C transport)" + depends on I2C + select PSE_REALTEK_MCU + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on various Realtek-based managed switches, attached + via I2C/SMBus. The MCU exposes a message-based protocol; the actual + PSE silicon is not accessed directly. To compile this driver as a + module, choose M here: the module will be called realtek-pse-mcu-i2c. + config PSE_REGULATOR tristate "Regulator based PSE controller" help
drivers/net/pse-pd/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o obj-$(CONFIG_PSE_REALTEK_MCU) += realtek-pse-mcu-core.o +obj-$(CONFIG_PSE_REALTEK_MCU_I2C) += realtek-pse-mcu-i2c.o obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o obj-$(CONFIG_PSE_PD692X0) += pd692x0.o obj-$(CONFIG_PSE_SI3474) += si3474.o
drivers/net/pse-pd/realtek-pse-mcu-i2c.c new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.53.0
Jonas Jelonek
maintainerPATCH v14 4/4 net: pse-pd: realtek-pse-mcu: add UART transport
In reply to Jonas JelonekAdd the serdev (UART) transport for the Realtek PSE MCU core. It registers the MCU as a serdev device and provides the send/recv callbacks the core uses to exchange the 12-byte frames, receiving asynchronously via the serdev receive_buf callback.
The baud rate defaults to 19200 and can be overridden per board with the "current-speed" property.
--- drivers/net/pse-pd/Kconfig | 11 ++ drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/realtek-pse-mcu-uart.c | 164 ++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/net/pse-pd/realtek-pse-mcu-uart.c
drivers/net/pse-pd/Kconfig +11 -0
@@ -30,6 +30,17 @@ config PSE_REALTEK_MCU_I2C PSE silicon is not accessed directly. To compile this driver as a module, choose M here: the module will be called realtek-pse-mcu-i2c. +config PSE_REALTEK_MCU_UART + tristate "Realtek PSE MCU driver (UART transport)" + depends on SERIAL_DEV_BUS + select PSE_REALTEK_MCU + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on various Realtek-based managed switches, attached + via UART. The MCU exposes a message-based protocol; the actual PSE + silicon is not accessed directly. To compile this driver as a + module, choose M here: the module will be called realtek-pse-mcu-uart. + config PSE_REGULATOR tristate "Regulator based PSE controller" help
drivers/net/pse-pd/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o obj-$(CONFIG_PSE_REALTEK_MCU) += realtek-pse-mcu-core.o obj-$(CONFIG_PSE_REALTEK_MCU_I2C) += realtek-pse-mcu-i2c.o +obj-$(CONFIG_PSE_REALTEK_MCU_UART) += realtek-pse-mcu-uart.o obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o obj-$(CONFIG_PSE_PD692X0) += pd692x0.o obj-$(CONFIG_PSE_SI3474) += si3474.o
drivers/net/pse-pd/realtek-pse-mcu-uart.c new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.53.0
Paolo Abeni
maintainerQuoted 71 lines · Jonas Jelonek
This series adds a PSE-PD driver for the microcontroller (MCU) that fronts the PSE silicon on a range of managed switches, together with its DT binding.
Hardware model
==============These boards do not expose the PSE chips to the host directly. A small microcontroller sits on an I2C/SMBus or UART bus and manages one or more PSE chips behind it; the host CPU only ever talks to that MCU, using a fixed 12-byte request/response protocol with a trailing checksum. The PSE silicon never appears on the bus.
Two generations of the protocol exist, both Realtek's: an older one on boards with Broadcom PSE silicon (BCM59111, BCM59121) and a newer one used with Realtek's own PSE silicon (RTL8238B, RTL8239, RTL8239C). They diverge in opcode numbering and a few response layouts; the driver abstracts that behind a per-dialect opcode table and parser hooks, selected by the compatible. The specific PSE chip behind the MCU is detected at runtime and only influences per-chip constants (power scaling and the per-port cap).
The compatibles
===============The protocol compatibles name two generations of the Realtek protocol, with the I2C framing folded in:
realtek,pse-mcu-gen1 gen1, UART realtek,pse-mcu-gen1-smbus gen1, I2C/SMBus realtek,pse-mcu-gen2 gen2, UART realtek,pse-mcu-gen2-smbus gen2, I2C/SMBus realtek,pse-mcu-gen2-i2c gen2, raw I2Cand each board carries a device-specific compatible that falls back to one of these, e.g.
compatible = "zyxel,xs1930-12hp-pse", "realtek,pse-mcu-gen2-smbus";The naming is the part most likely to raise questions, so the reasoning up front (the binding documents it too):
- The node describes the MCU together with its Realtek firmware, not a PSE chip and not the microcontroller silicon. The PSE chips sit behind the MCU, never appear on the bus, and are reported by the MCU and detected at runtime; the microcontroller itself is a general-purpose part (GigaDevice, Nuvoton, ...) that varies across boards. What is fixed and Realtek's is the firmware and its host protocol - hence the 'realtek' prefix.
- gen1 and gen2 are two generations of that protocol, both Realtek's:
gen1 on older boards fronting Broadcom PSE silicon, gen2 the altered protocol used once Realtek shipped their own PSE silicon. The generation is fixed per board and is all the driver needs at DT-parse time, so the compatible encodes it.- On I2C the MCU firmware expects one of two framings - SMBus or raw I2C - which is a genuine programming-model difference, so it is part of the compatible ('-smbus' / '-i2c'). A UART attachment carries no framing suffix; the transport is given structurally by the parent 'serial' node.
- Each board additionally carries a device-specific compatible that falls back to the protocol one. The driver only ever binds on the protocol compatible; the device-specific string keeps the binding specific and reserves a place for a future per-board quirk without having to retrofit device trees already deployed in the field.
Testing
=======
Quoted 7 lines
- Linksys LGS328MPCv2 (RTL8238B, I2C) - Zyxel GS1900-10HP A1 (BCM59121, UART) - Zyxel GS1900-10HP B1 (RTL8238B, UART) - Zyxel GS1920-24HPv2 (BCM59121, SMBus) - Zyxel XMG1915-10EP (RTL8239C, UART) - Zyxel XS1930-12HP (RTL8239, SMBus)
Please note the the nipa sashiko instance as a few more low prio comments:
I think it's better to apply the series as-is and follow-up on such points.
Thanks,
Paolo
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Thu, 13 Aug 2026 22:20:31 +0000 you wrote:
This series adds a PSE-PD driver for the microcontroller (MCU) that fronts the PSE silicon on a range of managed switches, together with its DT binding.
Hardware model
==============[...]
Here is the summary with links:
- [net-next,v14,1/4] dt-bindings: net: pse-pd: add bindings for Realtek PSE MCU
https://git.kernel.org/netdev/net-next/c/368990e9f6c6 - [net-next,v14,2/4] net: pse-pd: add Realtek PSE MCU core https://git.kernel.org/netdev/net-next/c/44566e614d84 - [net-next,v14,3/4] net: pse-pd: realtek-pse-mcu: add I2C transport https://git.kernel.org/netdev/net-next/c/4c088d9eb32f - [net-next,v14,4/4] net: pse-pd: realtek-pse-mcu: add UART transport https://git.kernel.org/netdev/net-next/c/5cc93d989749
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Jakub Kicinski
maintainerQuoted 2 lines · On Tue, 18 Aug 2026 13:10:14 +0000 [email protected] wrote:
- [net-next,v14,1/4] dt-bindings: net: pse-pd: add bindings for Realtek PSE MCU
https://git.kernel.org/netdev/net-next/c/368990e9f6c6
Was this reviewed by device tree maintainers?
Jonas Jelonek
maintainerHi,
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 18 Aug 2026 13:10:14 +0000 [email protected] wrote:
- [net-next,v14,1/4] dt-bindings: net: pse-pd: add bindings for Realtek PSE MCU
https://git.kernel.org/netdev/net-next/c/368990e9f6c6Was this reviewed by device tree maintainers?
v8 was reviewed by Conor. Since I slightly changed the bindings after that (dropped a '-supply' property, added a '-gpios' property), I dropped his Reviewed-by again in v9. No major changes but still a change which usually requires the trailers to be dropped.
Best,
Jonas