net: pse-pd: add Realtek/Broadcom PSE MCU support
Subsystems (4)
v2 cover net: pse-pd: add Realtek/Broadcom 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.
The same protocol family is used by MCUs fronting Realtek PSE chips (RTL8238B, RTL8239, RTL8239C) and Broadcom PSE chips (BCM59111, BCM59121), diverging 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).
Why the compatible names the protocol, not the chip
===================================================
The compatibles are "realtek,pse-mcu-rtk" and "realtek,pse-mcu-bcm". This is a deliberate choice and the part most likely to raise questions, so the reasoning up front.
The node names the protocol dialect, not a part:
- The DT node describes the MCU, not a PSE chip: the PSE chips are behind the MCU and never appear on the bus, so naming the node after one (e.g. "realtek,rtl8239") would describe hardware that isn't at that address.
- The PSE chips are, in principle, usable without this MCU (host-driven directly) - different hardware with a different programming model that would warrant its own binding. Claiming the PSE-chip compatibles here would collide with that.
- Naming the MCU silicon is equally wrong: these are ordinary general-purpose microcontrollers (GigaDevice, Nuvoton, ...) that vary across boards and are not dedicated to this application.
- What is fixed, and all the driver needs at DT-parse time, is the protocol dialect, so the compatible encodes exactly that. The two dialects share one protocol family and one binding, kept in a single "realtek" vendor namespace because this MCU front-end is found almost exclusively on Realtek-based switches; a "-rtk"/"-bcm" suffix selects the dialect. This follows the "google,cros-ec-*" pattern: a compatible for a firmware/protocol interface implemented by varying microcontrollers.
One compatible per dialect spans both transports:
- The 12-byte wire protocol is identical over I2C/SMBus and UART; only the plumbing differs (SMBus vs native framing on I2C, baud rate on UART), and the transport is already expressed structurally by the node's parent bus (i2c@... vs serial@...). A "-i2c"/"-uart" suffix would only duplicate that, for a protocol that does not change across transports.
- This is the multi-transport model used by e.g. "bosch,bmi160" (one compatible, separate i2c and spi drivers binding it), rather than the cros-ec model of per-transport compatibles - cros-ec splits because its on-wire framing genuinely differs per bus, which is not the case here.
The binding documents both points as well.
Testing
=======
- Linksys LGS328MPCv2 (RTL8238B, I2C)
- Zyxel GS1900-10HP A1 (BCM59121, UART)
- Zyxel GS1900-10HP B1 (RTL8238B, UART)
- Zyxel XMG1915-10EP (RTL8239C, UART)
- Zyxel XS1930-12HP (RTL8239, SMBus)
---
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 (2):
dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU
net: pse-pd: add Realtek/Broadcom PSE MCU driver
.../bindings/net/pse-pd/realtek,pse-mcu.yaml | 154 +++ MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 28 + drivers/net/pse-pd/Makefile | 3 + drivers/net/pse-pd/realtek-pse-core.c | 1007 +++++++++++++++++ drivers/net/pse-pd/realtek-pse-i2c.c | 164 +++ drivers/net/pse-pd/realtek-pse-uart.c | 156 +++ drivers/net/pse-pd/realtek-pse.h | 87 ++ 8 files changed, 1606 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml create mode 100644 drivers/net/pse-pd/realtek-pse-core.c create mode 100644 drivers/net/pse-pd/realtek-pse-i2c.c create mode 100644 drivers/net/pse-pd/realtek-pse-uart.c create mode 100644 drivers/net/pse-pd/realtek-pse.h
base-commit: f6033078a9e671e3c8b83d387b91591a6f6a54e7
Signature · 1 line
2.51.0
PATCH v2 1/2 dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU
Add a binding for the microcontroller (MCU) that fronts the PSE silicon on a range of managed 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 compatible identifies the PSE-MCU protocol dialect (realtek,pse-mcu-rtk or realtek,pse-mcu-bcm), not a specific part: the node describes the MCU - whose silicon is a general-purpose microcontroller that varies across boards - and the 'realtek' vendor prefix reflects the platform these MCUs are found on (Realtek-based PoE switches), following the google,cros-ec-* pattern rather than naming the MCU silicon. The '-rtk'/'-bcm' suffix selects the Realtek or Broadcom dialect within that one family. The specific PSE chip is detected at runtime and is not described here.
A single compatible per dialect covers both the I2C/SMBus and UART
attachments: the wire protocol is identical across them and the transport is expressed by the node's parent bus, so it is not encoded in the compatible.
Both dialects share one protocol family and one device tree contract, so they are documented in a single binding under one vendor prefix. The 'realtek' prefix is used because this MCU front-end is found almost exclusively on Realtek-based switches; the Broadcom dialect is expressed as the realtek,pse-mcu-bcm compatible within the same family.
--- .../bindings/net/pse-pd/realtek,pse-mcu.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +154 -0
@@ -0,0 +1,154 @@ +# 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.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek/Broadcom PSE MCU + +maintainers: + - Jonas Jelonek <[email protected]> + +description: | + Microcontroller (MCU) that fronts the PSE hardware on switches using + Realtek (RTL8238B, RTL8239, RTL8239C) or Broadcom (BCM59111, BCM59121) + PSE chips. The MCU exposes a small message-based protocol over either + I2C/SMBus or UART; the actual PSE silicon is not accessed directly. The + Realtek and Broadcom variants share this device tree contract but use + different protocol opcodes, selected by the compatible. + + The compatible identifies the PSE-MCU protocol dialect, not a specific + part. The device described here is the MCU, whose own silicon varies + across boards and is incidental to the protocol. The MCU is not + made by Realtek or Broadcom; the 'realtek' vendor prefix reflects the + platform these MCUs are found on (Realtek-based PoE switches) and the + '-rtk'/'-bcm' suffix selects the Realtek or Broadcom protocol dialect. + The specific PSE chip behind the MCU is not described in the device + tree either; it is detected at runtime by querying the MCU. + + A single compatible per dialect covers both the I2C/SMBus and UART + attachments: the wire protocol is identical across them and the + transport is already expressed by the node's parent bus, so it is not + encoded in the compatible. Transport-specific properties differ + accordingly - the I2C attachment carries 'reg' (and, for Realtek, + 'realtek,i2c-protocol'), while the UART attachment carries the serial + peripheral properties such as 'current-speed'. + +properties: + compatible: + enum: + - realtek,pse-mcu-rtk + - realtek,pse-mcu-bcm + + reg: + maxItems: 1 + + power-supply: + description: Regulator supplying the PoE power rail. + + enable-gpios: + maxItems: 1 + + realtek,i2c-protocol: + $ref: /schemas/types.yaml#/definitions/string + enum: [ i2c, smbus ] + description: | + Wire framing the MCU firmware expects on the I2C bus. "smbus" means + reads carry a leading command byte (0x00) and a repeated start; "i2c" + means bare 12-byte writes and reads with no command prefix. Only + applies to the Realtek I2C attachment. + +required: + - compatible + +allOf: + - $ref: pse-controller.yaml# + - $ref: /schemas/serial/serial-peripheral-props.yaml# + # The I2C attachment (identified by 'reg') cannot carry serial bus props. + - if: + required: [reg] + then: + properties: + current-speed: false + max-speed: false + # 'realtek,i2c-protocol' is meaningful only for the Realtek I2C attachment; + # the Broadcom variant and any UART attachment must not carry it. + - if: + properties: + compatible: + contains: + const: realtek,pse-mcu-rtk + required: [reg] + then: + required: + - realtek,i2c-protocol + else: + properties: + "realtek,i2c-protocol": false + +unevaluatedProperties: false + +examples: + # Realtek PSE chip, I2C attachment (SMBus framing). + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@20 { + compatible = "realtek,pse-mcu-rtk"; + reg = <0x20>; + realtek,i2c-protocol = "smbus"; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + }; + + # Broadcom PSE chip, I2C attachment. + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@20 { + compatible = "realtek,pse-mcu-bcm"; + reg = <0x20>; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + }; + + # Realtek PSE chip, UART attachment. + - | + serial { + ethernet-pse { + compatible = "realtek,pse-mcu-rtk"; + current-speed = <115200>; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + }; + }; + }; + };
Signature · 1 line
2.51.0
PATCH v2 2/2 net: pse-pd: add Realtek/Broadcom PSE MCU driver
In reply to Jonas JelonekA range of 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. The same protocol family is spoken by Realtek and Broadcom PSE MCUs, diverging in opcode numbering and a few response layouts, which the driver abstracts 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 driver is split into a shared core and two transport modules:
- PSE_REALTEK: protocol, message framing, dialect machinery, and the pse_controller_ops glue.
- PSE_REALTEK_I2C / PSE_REALTEK_UART: transport modules registering the MCU on an I2C bus or a serdev port respectively.
The realtek-* file names and PSE_REALTEK* symbols reflect the platform this setup appears on rather than vendor scope: this MCU front-end is found almost exclusively on Realtek-based switches. Broadcom PSE MCUs speak the same protocol family and are supported by the same shared core through the dialect abstraction, so the realtek-* naming is kept rather than splitting the code or renaming to a vendor-neutral scheme. For the same reason the device tree compatibles live under one vendor prefix, realtek,pse-mcu-rtk and realtek,pse-mcu-bcm, with the suffix selecting the dialect.
Power budgeting is left to the MCU firmware; the driver advertises PSE_BUDGET_EVAL_STRAT_DYNAMIC (controller-managed budget) accordingly.
--- MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 28 + drivers/net/pse-pd/Makefile | 3 + drivers/net/pse-pd/realtek-pse-core.c | 1007 +++++++++++++++++++++++++ drivers/net/pse-pd/realtek-pse-i2c.c | 164 ++++ drivers/net/pse-pd/realtek-pse-uart.c | 156 ++++ drivers/net/pse-pd/realtek-pse.h | 87 +++ 7 files changed, 1452 insertions(+) create mode 100644 drivers/net/pse-pd/realtek-pse-core.c create mode 100644 drivers/net/pse-pd/realtek-pse-i2c.c create mode 100644 drivers/net/pse-pd/realtek-pse-uart.c create mode 100644 drivers/net/pse-pd/realtek-pse.h
MAINTAINERS +7 -0
@@ -22484,6 +22484,13 @@ S: Maintained F: include/sound/rt*.h F: sound/soc/codecs/rt* +REALTEK/BROADCOM PSE MCU DRIVER +M: Jonas Jelonek <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml +F: drivers/net/pse-pd/realtek-pse* + REALTEK OTTO WATCHDOG M: Sander Vanheule <[email protected]> L: [email protected]
drivers/net/pse-pd/Kconfig +28 -0
@@ -13,6 +13,34 @@ menuconfig PSE_CONTROLLER if PSE_CONTROLLER +config PSE_REALTEK + tristate + help + Shared core for the Realtek/Broadcom PSE MCU driver. This is + selected automatically by the transport options below. + +config PSE_REALTEK_I2C + tristate "Realtek/Broadcom PSE MCU driver (I2C transport)" + depends on I2C + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-i2c. + +config PSE_REALTEK_UART + tristate "Realtek/Broadcom PSE MCU driver (UART transport)" + depends on SERIAL_DEV_BUS + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-uart. + config PSE_REGULATOR tristate "Regulator based PSE controller" help
drivers/net/pse-pd/Makefile +3 -0
@@ -3,6 +3,9 @@ obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o +obj-$(CONFIG_PSE_REALTEK) += realtek-pse-core.o +obj-$(CONFIG_PSE_REALTEK_I2C) += realtek-pse-i2c.o +obj-$(CONFIG_PSE_REALTEK_UART) += realtek-pse-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-core.c new file +1007 -0
1,007 lines not on this page · raw message
drivers/net/pse-pd/realtek-pse-i2c.c new file +164 -0
164 lines not on this page · raw message
drivers/net/pse-pd/realtek-pse-uart.c new file +156 -0
156 lines not on this page · raw message
drivers/net/pse-pd/realtek-pse.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The PoE power supply regulator is enabled after the PSE system is globally enabled, which can…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The PoE power supply regulator is enabled after the PSE system is globally enabled, which can trigger hardware faults.
- [Medium] A race condition in the UART transport between rtpse_uart_send() and rtpse_uart_receive() can cause spurious transaction failures (-EIO) for new commands. --
commit ee055c1d6f6679a77708ffd42882e725da96d11d
Author: Jonas Jelonek <[email protected]>
net: pse-pd: add Realtek/Broadcom PSE MCU driver
A range of 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.
Quoted 3 lines
drivers/net/pse-pd/realtek-pse-core.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/net/pse-pd/realtek-pse-core.c new file +2
-0+int rtpse_register (struct rtpse_ctrl *pse) +{
[ ... ]
drivers/net/pse-pd/realtek-pse-core.c line 857
Quoted 11 lines
drivers/net/pse-pd/realtek-pse-core.c new file +11
-0+if (!info.system_enable) { + ret =rtpse_set_global_state (pse, true); +/* Dialects without a global-state concept (e.g. BCM) return +* -EOPNOTSUPP; treat that as "no separate enable required". +*/ +if (ret && ret != -EOPNOTSUPP ) +return dev_err_probe (pse->dev, ret, +"failed to enable PSE system\n" ); + } + + ret =regulator_enable (pse->poe_supply);
[Severity: High]
Does this enable sequence trigger hardware faults? If rtpse_set_global_state() is called before regulator_enable(), the PSE chips might actively sense and deliver power before their main power rail is stable. This could cause the hardware to detect an Under-Voltage Lockout (UVLO) fault.
Should the poe_supply be enabled and allowed to stabilize before globally enabling the system?
Quoted 3 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +3
-0+static size_t rtpse_uart_receive (struct serdev_device *serdev, +const u8 *buf,size_t count) +{
[ ... ]
Quoted 14 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +14
-0+ scoped_guard(spinlock_irqsave, &ctx->rx_lock) { + take =min (count,sizeof (ctx->rx_buf) - ctx->rx_len); +if (take) { +memcpy (ctx->rx_buf + ctx->rx_len, buf, take); + ctx->rx_len += take; + done = (ctx->rx_len ==sizeof (ctx->rx_buf)); + } + } +if (done) +complete (&ctx->rx_done); + +/* consume all to avoid desync/misalignment */ +return count; +}
[ ... ]
drivers/net/pse-pd/realtek-pse-uart.c line 71
Quoted 9 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +9
-0+static int rtpse_uart_send (struct rtpse_ctrl *pse,const struct rtpse_mcu_msg *req) +{ +struct rtpse_uart *ctx =to_rtpse_uart (pse); +int written; + +/* clear any leftover rx state before transmitting */ +reinit_completion (&ctx->rx_done); +scoped_guard (spinlock_irqsave, &ctx->rx_lock) + ctx->rx_len = 0;
[Severity: Medium]
Can this sequence cause spurious transaction failures for new commands? In rtpse_uart_send(), reinit_completion() is called outside the rx_lock before clearing rx_len. Concurrently, in rtpse_uart_receive(), complete() is also called outside the spinlock.
If a delayed UART RX interrupt from a previous timed-out transaction fires just as a new transaction starts, could the interrupt handler fill rx_buf and call complete() after the new send reinitializes the completion, but before it clears rx_len?
This might cause the new transaction to return immediately from wait_for_completion_timeout() and falsely fail with -EIO due to rx_len being evaluated as incomplete.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Simon Horman
reviewerRe: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
In reply to Jonas JelonekThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
net: pse-pd: add Realtek/Broadcom PSE MCU driver
This patch adds a driver for a microcontroller that fronts Realtek and Broadcom PSE silicon on PoE switches, exposing the MCU over I2C/SMBus or UART using a 12-byte fixed-frame protocol. The driver is split into a shared core plus two transport modules, with a per-dialect opcode table and parser hooks for the Realtek vs Broadcom variants.
Quoted 26 lines
drivers/net/pse-pd/Kconfig +18
-0@@ -13,6 +13,34 @@ menuconfig PSE_CONTROLLER if PSE_CONTROLLER +config PSE_REALTEK + tristate + help + Shared core for the Realtek/Broadcom PSE MCU driver. This is + selected automatically by the transport options below. + +config PSE_REALTEK_I2C + tristate "Realtek/Broadcom PSE MCU driver (I2C transport)" + depends on I2C + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-i2c. + +config PSE_REALTEK_UART
drivers/net/pse-pd/Kconfig menuconfig PSE_CONTROLLER · line 43
Quoted 10 lines
drivers/net/pse-pd/Kconfig +10
-0+ tristate "Realtek/Broadcom PSE MCU driver (UART transport)" + depends on SERIAL_DEV_BUS + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-uart. +
[Medium]
The realtek, vendor prefix is used for both the Realtek dialect and the Broadcom dialect compatibles (realtek,pse-mcu-rtk and realtek,pse-mcu-bcm), and the binding documentation explicitly notes that the prefix "reflects the platform" rather than the silicon vendor. DT compatibles are stable ABI once accepted.
Would a brcm, prefix (or per-MCU-part compatibles) for the Broadcom dialect be more appropriate, given that the BCM variant uses Broadcom PSE silicon driven by an MCU built by Nuvoton or STMicro and has no Realtek involvement?
Similarly, would describing the I2C wire framing (native vs SMBus) via separate compatibles be preferable to encoding it in the realtek,i2c-protocol DT property, and would describing the actual PSE chip in DT (rather than relying on runtime device-id detection) match the usual binding patterns?
Quoted 3 lines
drivers/net/pse-pd/Kconfig +0
-0config PSE_REGULATOR tristate "Regulator based PSE controller" help
[ ... ]
Quoted 5 lines
drivers/net/pse-pd/realtek-pse-core.c new file +0
-0
[ ... ]
Quoted 8 lines
drivers/net/pse-pd/realtek-pse-core.c new file +8
-0+static int rtpse_port_cmd (struct rtpse_ctrl *pse,unsigned int port,u8 opcode,u8 arg) +{ +struct rtpse_mcu_msg req, resp; +int ret; + +rtpse_mcu_msg_init (&req, opcode); + req.payload[0 ] = port; + req.payload[1 ] = arg;
drivers/net/pse-pd/realtek-pse-core.c line 337
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+ + ret =rtpse_do_xfer (pse, &req, &resp); +if (ret) +return ret; + +if (resp.payload[0 ] != port || resp.payload[1 ] !=0 ) +return -EIO ; + +return 0 ; +}
[Medium]
Can an all-zero 12-byte buffer be silently accepted as a successful PORT_ENABLE/PORT_DISABLE on the BCM dialect for port 0?
For the BCM dialect, RTPSE_CMD_PORT_ENABLE maps to opcode 0x00, and the checksum of eleven zero bytes is 0, so an all-zero response passes the opcode and checksum checks in rtpse_do_xfer():
if (resp->opcode != req->opcode || resp->checksum != rtpse_checksum((u8 *)resp, RTPSE_MCU_MSG_SIZE - 1)) return -EBADMSG;
rtpse_port_cmd() then verifies payload[0] == port and payload[1] == 0, both of which pass when port == 0 and arg is 0 (disable) or when arg is 1 but the MCU never observed the command and the buffer is all zero anyway since payload[1] is checked against 0.
The seq_num field exists in struct rtpse_mcu_msg and is filled with 0xff by rtpse_mcu_msg_init() but is never checked on the response side. Could a seq_num round-trip check (or a non-zero opcode sentinel for the BCM dialect) reject stale or zeroed-out frames here?
[ ... ]
Quoted 12 lines
drivers/net/pse-pd/realtek-pse-core.c new file +12
-0+static int rtpse_discover (struct rtpse_ctrl *pse,struct rtpse_mcu_info *info) +{ +struct rtpse_mcu_ext_config ext_config; +unsigned long deadline; +int ret; + +/* +* The MCU may not answer on the bus yet right after power-up or +* enable-gpios assertion: depending on the transport it either stays +* silent (-ETIMEDOUT) or does not ACK its address at all (-ENXIO / +* -EREMOTEIO). Retry within a bounded wall-time window so a slow boot +* still probes, while a genuinely unresponsive MCU fails with its real
drivers/net/pse-pd/realtek-pse-core.c line 760
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+* error instead of deferring forever and masking it. +*/ + deadline = jiffies +msecs_to_jiffies (RTPSE_MCU_BOOT_TIMEOUT_MS ); +do { + ret =rtpse_mcu_get_info (pse, info); +if (ret != -ETIMEDOUT && ret != -ENXIO && + ret != -EREMOTEIO && ret != -EAGAIN ) +break ; +msleep (RTPSE_MCU_BOOT_RETRY_MS ); + }while (time_before (jiffies, deadline));
[Low]
The comment says the loop is meant to tolerate a slow-boot MCU, but the retry whitelist excludes -EBADMSG and -EIO.
rtpse_do_xfer() returns -EBADMSG when the opcode or checksum mismatch fires, and rtpse_port_query()/rtpse_port_cmd() return -EIO when the echoed port byte does not match the request. On a UART-attached MCU that emits a single garbled frame while its serial peripheral stabilises, or on an I2C-attached MCU that returns stale boot-ROM bytes right after enable-gpios assertion, the first attempt would surface as one of those errors rather than -ETIMEDOUT or -ENXIO, and the loop would break out immediately.
Should -EBADMSG (and arguably -EIO) be added to the retry set so the documented intent matches the actual behaviour?
[ ... ]
Quoted 2 lines
drivers/net/pse-pd/realtek-pse-core.c new file +2
-0+int rtpse_register (struct rtpse_ctrl *pse) +{
[ ... ]
Quoted 7 lines
drivers/net/pse-pd/realtek-pse-core.c new file +7
-0+if (!info.system_enable) { + ret =rtpse_set_global_state (pse, true); +/* Dialects without a global-state concept (e.g. BCM) return +* -EOPNOTSUPP; treat that as "no separate enable required". +*/ +if (ret && ret != -EOPNOTSUPP ) + return dev_err_probe(pse->dev, ret,
drivers/net/pse-pd/realtek-pse-core.c line 863
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+ "failed to enable PSE system\n"); + } + + ret =regulator_enable (pse->poe_supply); +if (ret) +return dev_err_probe (pse->dev, ret,"failed to enable PoE supply\n" ); + + ret =devm_add_action_or_reset (pse->dev, rtpse_regulator_disable, pse->poe_supply); +if (ret) +return ret;
[Low]
If rtpse_set_global_state(pse, true) succeeds but a later step in rtpse_register() fails (regulator_enable, devm_add_action_or_reset, or devm_pse_controller_register), is the MCU left with the PSE subsystem enabled while the kernel detaches?
The regulator is rolled back via rtpse_regulator_disable through devm_add_action_or_reset, but there does not seem to be a matching devm_add_action_or_reset to call rtpse_set_global_state(false) on probe-failure or driver-removal. Is that asymmetry intentional?
[ ... ]
Quoted 5 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +0
-0
[ ... ]
Quoted 21 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +21
-0+static size_t rtpse_uart_receive (struct serdev_device *serdev, +const u8 *buf,size_t count) +{ +struct rtpse_uart *ctx =serdev_device_get_drvdata (serdev); +bool done = false; +size_t take; + + scoped_guard(spinlock_irqsave, &ctx->rx_lock) { + take =min (count,sizeof (ctx->rx_buf) - ctx->rx_len); +if (take) { +memcpy (ctx->rx_buf + ctx->rx_len, buf, take); + ctx->rx_len += take; + done = (ctx->rx_len ==sizeof (ctx->rx_buf)); + } + } +if (done) +complete (&ctx->rx_done); + +/* consume all to avoid desync/misalignment */ +return count; +}
[ ... ]
drivers/net/pse-pd/realtek-pse-uart.c line 71
Quoted 9 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +9
-0+static int rtpse_uart_send (struct rtpse_ctrl *pse,const struct rtpse_mcu_msg *req) +{ +struct rtpse_uart *ctx =to_rtpse_uart (pse); +int written; + +/* clear any leftover rx state before transmitting */ +reinit_completion (&ctx->rx_done); +scoped_guard (spinlock_irqsave, &ctx->rx_lock) + ctx->rx_len = 0;
[High]
Is there a race between reinit_completion() here and the asynchronous serdev receive_buf callback when a previous transaction has timed out with bytes still in flight?
reinit_completion() is an unlocked x->done = 0 write, and the matching complete() in rtpse_uart_receive() is called outside rx_lock. The following interleave seems possible:
rtpse_uart_send() runs reinit_completion() /* done = 0 */
rtpse_uart_receive() takes rx_lock, fills rx_buf
to 12 bytes, computes done=true, releases lock
rtpse_uart_send() takes rx_lock, sets rx_len = 0,
releases lock
rtpse_uart_receive() calls complete(&ctx->rx_done) /* done = 1 */ rtpse_uart_send() writes the new request rtpse_uart_recv() wait_for_completion_timeout()
returns immediately (done was 1), then sees
rx_len == 0 and returns -EIO
rtpse_discover()'s retry whitelist covers -ETIMEDOUT, -ENXIO, -EREMOTEIO, and -EAGAIN but not -EIO, so a single occurrence of this race during the boot retry window would break out of the loop and turn into a permanent dev_err_probe() failure.
Would moving complete() inside rx_lock in rtpse_uart_receive(), or performing reinit_completion() and rx_len = 0 together inside rx_lock while excluding the completer, close this window?
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +10
-0+ + written =serdev_device_write (ctx->serdev, (const u8 *)req,sizeof (*req), +RTPSE_UART_TX_TIMEOUT ); +if (written <0 ) +return written; +if (written !=sizeof (*req)) +return -EIO ; + +return 0 ; +}
[ ... ]
Oleksij Rempel
maintainerRe: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
Hi Jonas,
Quoted 3 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
It probably sounds scary, but sashiko finds not all issues in one time. Bigger patches and more different included frameworks - increase findings probability a lot. With other words, it may more rounds than expected.
You may optimize it if you have access to some free or payed tokes, by using sashik-cli with LLM of you choice as backend.
Best Regards,
Oleksij
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
In reply to Simon HormanHi,
Quoted 60 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
net: pse-pd: add Realtek/Broadcom PSE MCU driverThis patch adds a driver for a microcontroller that fronts Realtek and Broadcom PSE silicon on PoE switches, exposing the MCU over I2C/SMBus or UART using a 12-byte fixed-frame protocol. The driver is split into a shared core plus two transport modules, with a per-dialect opcode table and parser hooks for the Realtek vs Broadcom variants.
Quoted 26 lines
drivers/net/pse-pd/Kconfig +18
-0@@ -13,6 +13,34 @@ menuconfig PSE_CONTROLLER if PSE_CONTROLLER +config PSE_REALTEK + tristate + help + Shared core for the Realtek/Broadcom PSE MCU driver. This is + selected automatically by the transport options below. + +config PSE_REALTEK_I2C + tristate "Realtek/Broadcom PSE MCU driver (I2C transport)" + depends on I2C + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-i2c. + +config PSE_REALTEK_UARTdrivers/net/pse-pd/Kconfig menuconfig PSE_CONTROLLER · line 43
Quoted 10 lines
drivers/net/pse-pd/Kconfig +10
-0+ tristate "Realtek/Broadcom PSE MCU driver (UART transport)" + depends on SERIAL_DEV_BUS + select PSE_REALTEK + help + Driver for the microcontroller (MCU) that fronts the PSE + hardware on switches with Realtek or Broadcom PSE chips, 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-uart. +[Medium]
The realtek, vendor prefix is used for both the Realtek dialect and the Broadcom dialect compatibles (realtek,pse-mcu-rtk and realtek,pse-mcu-bcm), and the binding documentation explicitly notes that the prefix "reflects the platform" rather than the silicon vendor. DT compatibles are stable ABI once accepted.Would a brcm, prefix (or per-MCU-part compatibles) for the Broadcom dialect be more appropriate, given that the BCM variant uses Broadcom PSE silicon driven by an MCU built by Nuvoton or STMicro and has no Realtek involvement?
Quoted 5 lines
Similarly, would describing the I2C wire framing (native vs SMBus) via separate compatibles be preferable to encoding it in the realtek,i2c-protocol DT property, and would describing the actual PSE chip in DT (rather than relying on runtime device-id detection) match the usual binding patterns?
This has been the hardest part so far but the solution I have right now seems the "best" one so far. But this part needs some guidance from DT maintainers.
I would hold against the AIs suggestions due to particular reasons. Using specific compatibles for the PSE chips would be very wrong IMO because:
(1) It would claim those PSE chips are what is interfaced on the bus. But this is not true, there's only the MCU which mostly hides the PSE chips.
(2) The PSE chips could be used without such an MCU. While this is rather theoretical for Realtek PSE chips, it is definitely the case for the Broadcom PSE chips. And in that case, they even use a different for communication, called Broadcom Serial Control.
On the other side, using specific MCU compatibles would be wrong too:
(1) The MCU silicon is irrelevant to the PSE/PoE system. Those are just general purpose MCUs where the supplied firmware on that MCU, not the silicon, defines the interface to the host.
(2) The MCUs are from various vendors (here STMicro, GigaDevice, Nuvoton), since they are general purpose they're likely used in various other applications. Claiming compatibles here for a specific application is IMO wrong.
Finally, why using the Realtek prefix/scope: The system that is described by the bindings and supported by the driver has so far been seen solely on Realtek-based switches. Some SDK sources already include a driver implementation for that. Though there is no 100% evidence of that, it seems quite reasonable that Realtek provides this MCU+firmware+PSE silicon as kind of a package. Thus, Realtek defines and provides the interface and behavior. The suffix then just denotes the protocol dialect used, correlating with the PSE silicon behind the MCU.
In older switch generations, Realtek just decided to use BCM59xxx PSE chips until they developed and shipped their owns. Likely because the capabilities of BCM and Realtek PSE silicon slightly differs, they decided to alter the protocol with different opcodes and slightly different command set.
I've seen a similar review from Sashiko on the bindings patch, my explanation above applies to it in the same way.
I'll try to improve the rationale a bit in the descriptions for the next version.
Quoted 47 lines
Quoted 3 lines
drivers/net/pse-pd/Kconfig +0
-0config PSE_REGULATOR tristate "Regulator based PSE controller" help[ ... ]
Quoted 5 lines
drivers/net/pse-pd/realtek-pse-core.c new file +0
-0[ ... ]
Quoted 8 lines
drivers/net/pse-pd/realtek-pse-core.c new file +8
-0+static int rtpse_port_cmd (struct rtpse_ctrl *pse,unsigned int port,u8 opcode,u8 arg) +{ +struct rtpse_mcu_msg req, resp; +int ret; + +rtpse_mcu_msg_init (&req, opcode); + req.payload[0 ] = port; + req.payload[1 ] = arg;drivers/net/pse-pd/realtek-pse-core.c line 337
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+ + ret =rtpse_do_xfer (pse, &req, &resp); +if (ret) +return ret; + +if (resp.payload[0 ] != port || resp.payload[1 ] !=0 ) +return -EIO ; + +return 0 ; +}[Medium]
Can an all-zero 12-byte buffer be silently accepted as a successful PORT_ENABLE/PORT_DISABLE on the BCM dialect for port 0?For the BCM dialect,
RTPSE_CMD_PORT_ENABLEmaps to opcode0x00, and the checksum of eleven zero bytes is 0, so an all-zero response passes the opcode and checksum checks inrtpse_do_xfer():if (resp->opcode != req->opcode || resp->checksum != rtpse_checksum((u8 *)resp, RTPSE_MCU_MSG_SIZE - 1)) return -EBADMSG;
rtpse_port_cmd()then verifies payload[0] == port and payload[1] == 0, both of which pass when port == 0 and arg is 0 (disable) or when arg is 1 but the MCU never observed the command and the buffer is all zero anyway since payload[1] is checked against 0.
Quoted 7 lines
The
seq_numfield exists in structrtpse_mcu_msgand is filled with0xffbyrtpse_mcu_msg_init()but is never checked on the response side. Could aseq_numround-trip check (or a non-zero opcode sentinel for the BCM dialect) reject stale or zeroed-out frames here?[ ... ]
Valid, I will add a check for the seq_num field here.
Quoted 35 lines
Quoted 12 lines
drivers/net/pse-pd/realtek-pse-core.c new file +12
-0+static int rtpse_discover (struct rtpse_ctrl *pse,struct rtpse_mcu_info *info) +{ +struct rtpse_mcu_ext_config ext_config; +unsigned long deadline; +int ret; + +/* +* The MCU may not answer on the bus yet right after power-up or +* enable-gpios assertion: depending on the transport it either stays +* silent (-ETIMEDOUT) or does not ACK its address at all (-ENXIO / +* -EREMOTEIO). Retry within a bounded wall-time window so a slow boot +* still probes, while a genuinely unresponsive MCU fails with its real drivers/net/pse-pd/realtek-pse-core.c line 760
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+* error instead of deferring forever and masking it. +*/ + deadline = jiffies +msecs_to_jiffies (RTPSE_MCU_BOOT_TIMEOUT_MS ); +do { + ret =rtpse_mcu_get_info (pse, info); +if (ret != -ETIMEDOUT && ret != -ENXIO && + ret != -EREMOTEIO && ret != -EAGAIN ) +break ; +msleep (RTPSE_MCU_BOOT_RETRY_MS ); + }while (time_before (jiffies, deadline));[Low]
The comment says the loop is meant to tolerate a slow-boot MCU, but the retry whitelist excludes-EBADMSGand-EIO.
rtpse_do_xfer()returns-EBADMSGwhen the opcode or checksum mismatch fires, and rtpse_port_query()/rtpse_port_cmd() return-EIOwhen the echoed port byte does not match the request. On a UART-attached MCU that emits a single garbled frame while its serial peripheral stabilises, or on an I2C-attached MCU that returns stale boot-ROM bytes right after enable-gpios assertion, the first attempt would surface as one of those errors rather than-ETIMEDOUTor-ENXIO, and the loop would break out immediately.
Quoted 2 lines
Should
-EBADMSG(and arguably-EIO) be added to the retry set so the documented intent matches the actual behaviour?
This would be speculative IMO, because 'no answer' was the only behavior I could observe so far. It always came up as a timeout when the MCU wasn't ready yet.
Quoted 29 lines
[ ... ]
Quoted 2 lines
drivers/net/pse-pd/realtek-pse-core.c new file +2
-0+int rtpse_register (struct rtpse_ctrl *pse) +{[ ... ]
Quoted 7 lines
drivers/net/pse-pd/realtek-pse-core.c new file +7
-0+if (!info.system_enable) { + ret =rtpse_set_global_state (pse, true); +/* Dialects without a global-state concept (e.g. BCM) return +* -EOPNOTSUPP; treat that as "no separate enable required". +*/ +if (ret && ret != -EOPNOTSUPP ) + return dev_err_probe(pse->dev, ret,drivers/net/pse-pd/realtek-pse-core.c line 863
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-core.c new file +10
-0+ "failed to enable PSE system\n"); + } + + ret =regulator_enable (pse->poe_supply); +if (ret) +return dev_err_probe (pse->dev, ret,"failed to enable PoE supply\n" ); + + ret =devm_add_action_or_reset (pse->dev, rtpse_regulator_disable, pse->poe_supply); +if (ret) +return ret;[Low]
Ifrtpse_set_global_state(pse, true)succeeds but a later step inrtpse_register()fails (regulator_enable,devm_add_action_or_reset, ordevm_pse_controller_register), is the MCU left with the PSE subsystem enabled while the kernel detaches?
Quoted 4 lines
The regulator is rolled back via
rtpse_regulator_disablethroughdevm_add_action_or_reset, but there does not seem to be a matchingdevm_add_action_or_resetto callrtpse_set_global_state(false)on probe-failure or driver-removal. Is that asymmetry intentional?
No, this is an inconsistency. I'll fix this in the next version.
Quoted 61 lines
[ ... ]
Quoted 5 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +0
-0[ ... ]
Quoted 21 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +21
-0+static size_t rtpse_uart_receive (struct serdev_device *serdev, +const u8 *buf,size_t count) +{ +struct rtpse_uart *ctx =serdev_device_get_drvdata (serdev); +bool done = false; +size_t take; + + scoped_guard(spinlock_irqsave, &ctx->rx_lock) { + take =min (count,sizeof (ctx->rx_buf) - ctx->rx_len); +if (take) { +memcpy (ctx->rx_buf + ctx->rx_len, buf, take); + ctx->rx_len += take; + done = (ctx->rx_len ==sizeof (ctx->rx_buf)); + } + } +if (done) +complete (&ctx->rx_done); + +/* consume all to avoid desync/misalignment */ +return count; +}[ ... ]
drivers/net/pse-pd/realtek-pse-uart.c line 71
Quoted 9 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +9
-0+static int rtpse_uart_send (struct rtpse_ctrl *pse,const struct rtpse_mcu_msg *req) +{ +struct rtpse_uart *ctx =to_rtpse_uart (pse); +int written; + +/* clear any leftover rx state before transmitting */ +reinit_completion (&ctx->rx_done); +scoped_guard (spinlock_irqsave, &ctx->rx_lock) + ctx->rx_len = 0;[High]
Is there a race betweenreinit_completion()here and the asynchronous serdevreceive_bufcallback when a previous transaction has timed out with bytes still in flight?
reinit_completion()is an unlockedx->done= 0 write, and the matchingcomplete()inrtpse_uart_receive()is called outsiderx_lock. The following interleave seems possible:
rtpse_uart_send()runsreinit_completion()/* done = 0 */
rtpse_uart_receive()takesrx_lock, fillsrx_buf
to 12 bytes, computes done=true, releases lock
rtpse_uart_send()takesrx_lock, setsrx_len= 0,
releases lock
rtpse_uart_receive()callscomplete(&ctx->rx_done)/* done = 1 */rtpse_uart_send()writes the new requestrtpse_uart_recv()wait_for_completion_timeout()
returns immediately (done was 1), then sees
rx_len== 0 and returns-EIO
Quoted 9 lines
rtpse_discover()'s retry whitelist covers
-ETIMEDOUT,-ENXIO,-EREMOTEIO, and-EAGAINbut not-EIO, so a single occurrence of this race during the boot retry window would break out of the loop and turn into a permanentdev_err_probe()failure.Would moving
complete()insiderx_lockinrtpse_uart_receive(), or performingreinit_completion()andrx_len= 0 together insiderx_lockwhile excluding the completer, close this window?
Valid, will fix it as suggested in the next version.
Quoted 11 lines
Quoted 10 lines
drivers/net/pse-pd/realtek-pse-uart.c new file +10
-0+ + written =serdev_device_write (ctx->serdev, (const u8 *)req,sizeof (*req), +RTPSE_UART_TX_TIMEOUT ); +if (written <0 ) +return written; +if (written !=sizeof (*req)) +return -EIO ; + +return 0 ; +}[ ... ]
Best regards,
Jonas
Re: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
In reply to Oleksij RempelHi Oleksij,
thanks for your message.
Quoted 9 lines · Oleksij Rempel
Hi Jonas,
Quoted 3 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
It probably sounds scary, but sashiko finds not all issues in one time. Bigger patches and more different included frameworks - increase findings probability a lot. With other words, it may more rounds than expected.
Sure, I've noticed that in another series recently. I'll just be patient and address/discuss the review/issues accordingly :)
Quoted 5 lines
You may optimize it if you have access to some free or payed tokes, by using sashik-cli with LLM of you choice as backend.
Best Regards,
Oleksij
Best regards,
Jonas
Simon Horman
reviewerRe: [PATCH net-next v2 2/2] net: pse-pd: add Realtek/Broadcom PSE MCU driver
In reply to Oleksij RempelQuoted 10 lines · Oleksij Rempel
Hi Jonas,
Quoted 3 lines · Simon Horman
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
It probably sounds scary, but sashiko finds not all issues in one time. Bigger patches and more different included frameworks - increase findings probability a lot. With other words, it may more rounds than expected.
FWIIW, that matches my observations too.
...
Rob Herring
maintainerRe: [PATCH net-next v2 1/2] dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU
In reply to Jonas JelonekQuoted 68 lines · Jonas Jelonek
Add a binding for the microcontroller (MCU) that fronts the PSE silicon on a range of managed 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 compatible identifies the PSE-MCU protocol dialect (realtek,pse-mcu-rtk or realtek,pse-mcu-bcm), not a specific part: the node describes the MCU - whose silicon is a general-purpose microcontroller that varies across boards - and the 'realtek' vendor prefix reflects the platform these MCUs are found on (Realtek-based PoE switches), following the google,cros-ec-* pattern rather than naming the MCU silicon. The '-rtk'/'-bcm' suffix selects the Realtek or Broadcom dialect within that one family. The specific PSE chip is detected at runtime and is not described here.
A single compatible per dialect covers both the I2C/SMBus and UART
attachments: the wire protocol is identical across them and the transport is expressed by the node's parent bus, so it is not encoded in the compatible.Both dialects share one protocol family and one device tree contract, so they are documented in a single binding under one vendor prefix. The 'realtek' prefix is used because this MCU front-end is found almost exclusively on Realtek-based switches; the Broadcom dialect is expressed as the realtek,pse-mcu-bcm compatible within the same family.
Signed-off-by Jonas Jelonek <[email protected]>--- .../bindings/net/pse-pd/realtek,pse-mcu.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yamlDocumentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +30
-0@@ -0,0 +1,154 @@ +# 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.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek/Broadcom PSE MCU + +maintainers: + - Jonas Jelonek <[email protected]> + +description: | + Microcontroller (MCU) that fronts the PSE hardware on switches using + Realtek (RTL8238B, RTL8239, RTL8239C) or Broadcom (BCM59111, BCM59121) + PSE chips. The MCU exposes a small message-based protocol over either + I2C/SMBus or UART; the actual PSE silicon is not accessed directly. The + Realtek and Broadcom variants share this device tree contract but use + different protocol opcodes, selected by the compatible. + + The compatible identifies the PSE-MCU protocol dialect, not a specific + part. The device described here is the MCU, whose own silicon varies + across boards and is incidental to the protocol. The MCU is not + made by Realtek or Broadcom; the 'realtek' vendor prefix reflects the + platform these MCUs are found on (Realtek-based PoE switches) and the + '-rtk'/'-bcm' suffix selects the Realtek or Broadcom protocol dialect. + The specific PSE chip behind the MCU is not described in the device + tree either; it is detected at runtime by querying the MCU. + + A single compatible per dialect covers both the I2C/SMBus and UART + attachments: the wire protocol is identical across them and the
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +10
-0+ transport is already expressed by the node's parent bus, so it is not + encoded in the compatible. Transport-specific properties differ + accordingly - the I2C attachment carries 'reg' (and, for Realtek, + 'realtek,i2c-protocol'), while the UART attachment carries the serial + peripheral properties such as 'current-speed'. + +properties: + compatible: + enum: + - realtek,pse-mcu-rtk
The "rtk" feels redundant.
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 41
Quoted 1 line
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +1
-0+ - realtek,pse-mcu-bcm
"brcm" is the standard vendor prefix, so use that instead of "bcm". Though who defined the protocol in this case? Realtek or Broadcom? In the latter case, I'd argue that "brcm" should be the vendor prefix.
Quoted 8 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +8
-0+ + reg: + maxItems: 1 + + power-supply: + description: Regulator supplying the PoE power rail. + + enable-gpios:
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 59
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +10
-0+ maxItems: 1 + + realtek,i2c-protocol: + $ref: /schemas/types.yaml#/definitions/string + enum: [ i2c, smbus ] + description: | + Wire framing the MCU firmware expects on the I2C bus. "smbus" means + reads carry a leading command byte (0x00) and a repeated start; "i2c" + means bare 12-byte writes and reads with no command prefix. Only + applies to the Realtek I2C attachment.
I tend to think this should be distinguished by the compatible string. That would simplify the schema given it only applies to one of the compatible strings.
Rob
Re: [PATCH net-next v2 1/2] dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU
Quoted 6 lines · Rob Herring
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 40
Quoted 4 lines · Jonas Jelonek
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +4
-0+properties: + compatible: + enum: + - realtek,pse-mcu-rtk
Quoted 7 lines
The "rtk" feels redundant.
Quoted 1 line
+ - realtek,pse-mcu-bcm
"brcm" is the standard vendor prefix, so use that instead of "bcm". Though who defined the protocol in this case? Realtek or Broadcom? In the latter case, I'd argue that "brcm" should be the vendor prefix.
The microcontroller firmware, and hence the protocol, is designed by RealTek in both cases. However, they chose to design two incmpatible protocol dialects based on the features of the PSE(s) connected to the MCU.
Re: [PATCH net-next v2 1/2] dt-bindings: net: pse-pd: add bindings for Realtek/Broadcom PSE MCU
In reply to Rob HerringHi Rob,
Quoted 8 lines · Rob Herring
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 40
Quoted 6 lines · Jonas Jelonek
[...]
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +4
-0+properties: + compatible: + enum: + - realtek,pse-mcu-rtkThe "rtk" feels redundant.
In the full Realtek case yes. Do you have a suggestion to improve that?
Quoted 4 lines
Quoted 1 line
+ - realtek,pse-mcu-bcm
"brcm" is the standard vendor prefix, so use that instead of "bcm". Though who defined the protocol in this case? Realtek or Broadcom? In the latter case, I'd argue that "brcm" should be the vendor prefix.
I'll switch to brcm.
As Daniel already mentioned, Realtek defines the firmware and thus the protocol, in both cases.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +13
-0+ + reg: + maxItems: 1 + + power-supply: + description: Regulator supplying the PoE power rail. + + enable-gpios: + maxItems: 1 + + realtek,i2c-protocol: + $ref: /schemas/types.yaml#/definitions/string + enum: [ i2c, smbus ]
Quoted 8 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml line 59
Quoted 5 lines
Documentation/devicetree/bindings/net/pse-pd/realtek,pse-mcu.yaml new file +5
-0+ description: | + Wire framing the MCU firmware expects on the I2C bus. "smbus" means + reads carry a leading command byte (0x00) and a repeated start; "i2c" + means bare 12-byte writes and reads with no command prefix. Only + applies to the Realtek I2C attachment.I tend to think this should be distinguished by the compatible string. That would simplify the schema given it only applies to one of the compatible strings.
In theory this could also apply to the Broadcom dialect, however I didn't have a device with that variant on my desk.
If you would go with separate compatibles, do you thought about something like "realtek,pse-mcu-rtk-i2c" and "realtek,pse-mcu-rtk-smbus" (given we stick with rtk) ?
Quoted 1 line
Rob
Best regards,
Jonas