net: pse-pd: Add LTC4266 PSE controller driver
Subsystems (4)
v3 cover net: pse-pd: Add LTC4266 PSE controller driver
Add support for an older PSE controller that supports powering Type 1 and Type 2 PDs.
The chip has four individually controllable power channels, each with it own detection, classification and current-limiting abilities. The driver declares the static power budgeting strategy.
---
RFC v2 -> v3:
- The admin power limit is now configurable before the port is powered and is independent from the class limit. However, when a PD is powered, the current limit is set by the minimum between the PD's class and the admin power limit, to maintain compliance with the IEEE spec.
- The LTC4266 doesn't support reading a port's voltage (or current) until that port is completely and successfully powered. Since we don't have a good way to measure the port voltage, we'll first try to use the vpwr-supply voltage if available during probe, and fall back to 50V (the Type 2 PSE minimum) if the regulator isn't available (ENODEV or EPROBE_DEFER) or doesn't have a readable voltage for the port. This is the voltage the LTC4266 driver will return back to pse core when a port's power good bit is not set.
- Report the hardware admin state from the "Power Enabled" bit instead of the "Power Good" bit. The latter is set when the port is fully powered (after inrush) so a port in the process of powering up looked disabled to the core and had power domain budget allocated to it twice.
- Added a Maintainers entry for the driver.
- Avoid precision loss in pi_get_actual_pw.
- Demote a dev_err in a common path on device disconnection to dev_dbg.
- Add an err: label in map_event that'll clear all the event registers via the INTCLR push-button to prevent a possible interrupt storm.
- The supply and over-temperature faults were too hard to test, but they will result in a disconnection event for one or more channels. Replace those faults with a combination of a "power good" change and a port status check to send a disconnect event to the pse core.
- Bail out of probe early if we don't have the required IRQ.
- Replace the driver's .remove with a devm action registered before the controller and the IRQ to ensure the IRQ is freed before this driver is removed.
- Drop reset-gpios from the binding, since the driver doesn't support it at the moment (because my hardware doesn't have it correctly wired)
- Expand the description for sense-resistor-micro-ohms to indicate the property is required by the chip for accurate current limiting.
Link to RFC v2: https://lore.kernel.org/all/[email protected]/
Kyle Swenson (2):
dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
net: pse-pd: Add LTC4266 PSE controller driver
.../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 +++ MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 11 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/ltc4266.c | 1386 +++++++++++++++++ 5 files changed, 1585 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml create mode 100644 drivers/net/pse-pd/ltc4266.c
Signature · 1 line
2.55.0
PATCH v3 1/2 dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +180 -0
@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: true + properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - channels + - pse-pis + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@2f { + compatible = "lltc,ltc4266"; + reg = <0x2f>; + interrupts = <8 IRQ_TYPE_LEVEL_LOW>; + interrupt-parent = <&gpio>; + + channels { + #address-cells = <1>; + #size-cells = <0>; + + phys0: channel@0 { + reg = <0>; + sense-resistor-micro-ohms = <500000>; + }; + + phys1: channel@1 { + reg = <1>; + sense-resistor-micro-ohms = <500000>; + }; + + phys2: channel@2 { + reg = <2>; + sense-resistor-micro-ohms = <500000>; + }; + + phys3: channel@3 { + reg = <3>; + sense-resistor-micro-ohms = <500000>; + }; + }; + + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse_pi0: pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys0>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse>; + }; + + pse_pi1: pse-pi@1 { + reg = <1>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys1>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse>; + }; + + pse_pi2: pse-pi@2 { + reg = <2>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys2>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse>; + }; + + pse_pi3: pse-pi@3 { + reg = <3>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys3>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse>; + }; + }; + }; + };
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The binding does not describe the LTC4266's board-level control and supply resources.
- [Low] The commit message for "dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller" is one sentence ("Add the LTC4266 Power…
- [Low] The pse-pi@[0-3] subschema describes pairsets as "exactly one channel phandle is expected", and the channels description says the…
- [Low] interrupts is in the top-level required list of lltc,ltc4266.yaml (line 94).
Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but the base pse- controller.yaml (which lltc,ltc4266.yaml inherits) and the LTC4266…
--
dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
This commit adds a YAML device tree binding for the Linear Technology LTC4266 PSE controller. The binding describes the chip's four delivery channels, each with a sense resistor value, and PSE PIs that each map to one channel.
Quoted 4 lines
dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
[Severity: Low]
This isn't a bug, but the subject says "binding" twice. Documentation/devicetree/bindings/submitting-patches.rst asks submitters to avoid that:
Repeating "binding" again should also be avoided, so for a new device it is often enough for example: "dt-bindings: iio: adc: Add ROHM BD79100G"
Could the body also describe the hardware, a 4-port 802.3at PSE on I2C? Could it also explain the ABI choices that differ from the sibling PSE bindings? These are:
- a new required per-channel sense-resistor-micro-ohms property with a fixed 250000/500000 enum
- channels and pse-pis are both required (ti,tps23881.yaml requires neither)
- each PI is limited to a single pairset
Quoted 6 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +0
-0@@ -0,0 +1,180 @@
[ ... ]
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 24
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1
[Severity: Low]
Should this list also have reset-gpios for the chip's active-low RESET input? Should it have supply properties for the VDD and VEE rails?
The schema ends with unevaluatedProperties: false. A board DT that routes RESET to a SoC GPIO, or names its VDD/VEE regulators, would fail validation. writing-bindings.rst says:
DO attempt to make bindings complete even if a driver doesn't support some features.
The sibling ti,tps23881.yaml in the same directory documents its reset line:
reset-gpios:
maxItems: 1
The driver patch in this series ("net: pse-pd: Add LTC4266 PSE controller driver") only resets the chip in software, through the RSTPB register in ltc4266_probe():
ret = regmap_write(regmap, LTC4266_REG_RSTPB, LTC4266_RSTPB_INTCLR | LTC4266_RSTPB_RSTALL);
Suppose a board's RESET GPIO is asserted by default. Won't the chip stay in reset, so the ID read in probe fails? Nothing in the DT would let the driver deassert the line.
[ ... ]
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 89
Quoted 13 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +13
-0+ patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: true + properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1
[Severity: Low]
The description says exactly one channel phandle is expected. Should pairsets and pairset-names also be marked required in this subschema?
The only required entries inherited from pse-controller.yaml are reg and #pse-cells. The PSE core's of_load_pse_pis() accepts a pse-pi that has no pairsets. It takes the -ENOENT branch and leaves pairset[0].np NULL:
} else if (ret != -ENOENT) {The driver patch in this series then rejects that case in ltc4266_map_pis():
if (!pi->pairset[0].np)
return dev_err_probe(ltc4266->dev, -EINVAL,
"%pOF has no pairsets\n", pi->np);So there is no NULL dereference. However, a DT with a PI that has no channel mapping passes dtbs_check and then makes pse_controller_register() fail. That takes down all four ports.
Would adding this to the pse-pi subschema close the gap?
required:
- pairsets
- pairset-names
[Severity: Low]
This is a pre-existing issue and was not introduced by this patch. Neither this subschema nor the base pse-controller.yaml requires pairsets and pairset-names to appear together, for example with dependentRequired.
of_load_pse_pi_pairsets() in drivers/net/pse-pd/pse_core.c checks this at runtime:
ret = of_property_count_strings(node, "pairset-names");
if (ret != npairsets) {
pr_err(...);
return -EINVAL;
}So a node with pairsets = <&phys0>; and no pairset-names passes schema validation and then fails controller registration.
ti,tps23881.yaml and skyworks,si3474.yaml have the same gap. Would this be better fixed once in pse-controller.yaml?
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 96
Quoted 7 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +7
-0+ +required: + - compatible + - reg + - interrupts + - channels + - pse-pis
[Severity: Low]
Does interrupts need to be required? The requirement seems to come from the driver rather than the hardware. Without an IRQ, the driver patch in this series fails probe in ltc4266_probe():
if (!client->irq)
return dev_err_probe(&client->dev, -EINVAL,
"Interrupt is required for power budget management\n");On the LTC4266, INT is an open-drain output that summarises the event and status registers. Those registers can be read over I2C, so the chip can also be managed by polling. writing-bindings.rst says:
- DON'T refer to Linux or "device driver" in bindings. Bindings should be based on what the hardware has, not what an OS and driver currently support.
A board that leaves INT unconnected is valid hardware, but it would fail dtbs_check. For comparison, skyworks,si3474.yaml in the same directory does not require interrupts, while ti,tps23881.yaml does.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927212929.593366-1-kyle.swenson%40est.tech
Rob Herring
maintainerRe: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
In reply to Kyle SwensonQuoted 85 lines · Kyle Swenson
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
Signed-off-by Kyle Swenson <[email protected]>--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +70
-0@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties:
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 80
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: true
This cannot be true. That allows adding any property.
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 89
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+ properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1
An empty node is valid? Needs 'required'.
Rob
Re: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Hello Rob,
Quoted 90 lines · Rob Herring
Quoted 89 lines · Kyle Swenson
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
Signed-off-by Kyle Swenson <[email protected]>--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +74
-0@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells':
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +6
-0+ const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: trueThis cannot be true. That allows adding any property.
So my intent with the additionalProperties: true was to avoid replicating the entire pse-pis node from pse-controller.yaml. Conceptually, my goal was to inherit everything from the pse-controller.yaml binding, except limit the maxItems to 1 (since the LTC4266 only supports power over a single PI).
Is there a better way to express this?
Quoted 11 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 89
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+ properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1An empty node is valid? Needs 'required'.
I thought the 'required' comes from the pse-controller.yaml binding. If I adjust the example dts in the binding with something like
pse_pi2: pse-pi@2 {
- reg = <2>;
- #pse-cells = <0>;
- pairset-names = "alternative-a";
- pairsets = <&phys2>;
- polarity-supported = "MDI";
- vpwr-supply = <&vreg_pse>;
};Then make dt_binding_check will fail with
DTEX Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dts
DTC [C] Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dts:83.33-84.17: Warning (unit_address_vs_reg): /example-0/i2c/ethernet-pse@2f/pse-pis/pse-pi@2: node has a unit name, but no reg or ranges property Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb: ethernet-pse@2f (lltc,ltc4266): pse-pis:pse-pi@2: 'reg' is a required property
from schema $id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb: ethernet-pse@2f (lltc,ltc4266): pse-pis:pse-pi@2: '#pse-cells' is a required property
from schema $id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml
But I'm probably missing something obvious, so please don't hesitate to point it out or point me to docs.
Quoted 2 lines
Rob
Thanks so much for the review!
Kyle
Kory Maincent
maintainerRe: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Quoted 103 lines · Kyle Swenson
Hello Rob,
Quoted 90 lines · Rob Herring
Quoted 89 lines · Kyle Swenson
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
Signed-off-by Kyle Swenson <[email protected]>--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +74
-0@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells':Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +6
-0+ const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: trueThis cannot be true. That allows adding any property.
Quoted 7 lines
So my intent with the additionalProperties: true was to avoid replicating the entire pse-pis node from
pse-controller.yaml. Conceptually, my goal was to inherit everything from thepse-controller.yamlbinding, except limit the maxItems to 1 (since the LTC4266 only supports power over a single PI).Is there a better way to express this?
I think you can do something like this:
patternProperties:
'^pse-pi@[0-3]$':
type: object
$ref: pse-controller.yaml#/properties/pse-pis/patternProperties/^pse-pi@[0-9a-f]+$
unevaluatedProperties: false
properties:
pairsets:
description: The LTC4266 delivers power to a PI over a
single
pairset, driven by one of the controller's four
channels. There
is no 4-pair mode spreading a PI over two channels, so
exactly
one channel phandle is expected.
maxItems: 1
pairset-names:
maxItems: 1
Quoted 32 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 89
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+ properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1An empty node is valid? Needs 'required'.
I thought the 'required' comes from the
pse-controller.yamlbinding. If I adjust the example dts in the binding with something likepse_pi2: pse-pi@2 {(quoted diff) +0
-6- reg = <2>; - #pse-cells = <0>; - pairset-names = "alternative-a"; - pairsets = <&phys2>; - polarity-supported = "MDI"; - vpwr-supply = <&vreg_pse>; };Then make
dt_binding_checkwill fail withDTEX
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dts
DTC [C]Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dts:83.33-84.17: Warning (unit_address_vs_reg): /example-0/i2c/ethernet-pse@2f/pse-pis/pse-pi@2: node has a unit name, but no reg or ranges propertyDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb: ethernet-pse@2f (lltc,ltc4266): pse-pis:pse-pi@2: 'reg' is a required property
from schema $id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.example.dtb: ethernet-pse@2f (lltc,ltc4266): pse-pis:pse-pi@2: '#pse-cells' is a required property
Quoted 5 lines
from schema $id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yamlBut I'm probably missing something obvious, so please don't hesitate to point it out or point me to docs.
You are right on this, it should not be needed.
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Rob Herring
maintainerRe: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
Quoted 122 lines · Kory Maincent
Quoted 103 lines · Kyle Swenson
Hello Rob,
Quoted 90 lines · Rob Herring
Quoted 89 lines · Kyle Swenson
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
Signed-off-by Kyle Swenson <[email protected]>--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +74
-0@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells':Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +6
-0+ const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: trueThis cannot be true. That allows adding any property.
Quoted 7 lines
So my intent with the additionalProperties: true was to avoid replicating the entire pse-pis node from
pse-controller.yaml. Conceptually, my goal was to inherit everything from thepse-controller.yamlbinding, except limit the maxItems to 1 (since the LTC4266 only supports power over a single PI).Is there a better way to express this?
I think you can do something like this:
patternProperties: '^pse-pi@[0-3]$': type: object $ref:
Quoted 3 lines
pse-controller.yaml#/properties/pse-pis/patternProperties/^pse-pi@[0-9a-f]+$
unevaluatedProperties: false
Yes, if you want/need to allow custom properties, like this is what I meant.
However, it is hit or miss if a $ref to a regex works. Instead, pse-controller.yaml would need a $defs section that the pattern and this schema can reference. Multiple levels of nodes and allowing them to be extended gets messy.
Rob
Rob Herring
maintainerRe: [PATCH net-next v3 1/2] dt-bindings: net: pse-pd: Add bindings for LTC4266 PSE Controller
In reply to Kyle SwensonQuoted 103 lines · Kyle Swenson
Hello Rob,
Quoted 90 lines · Rob Herring
Quoted 89 lines · Kyle Swenson
Add the LTC4266 Power Sourcing Equipment controller device tree bindings documentation.
Signed-off-by Kyle Swenson <[email protected]>--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlDocumentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +74
-0@@ -0,0 +1,180 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Linear Technology LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + channels: + type: object + additionalProperties: false + description: + Defines the 4 physical delivery channels on the controller that can be + referenced by PSE PIs through their "pairsets" property. The actual port + matrix mapping is created when PSE PIs reference these channels in their + pairsets. + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement and for overcurrent detection. The I_CUT + and I_LIM register encodings depend on which value is fitted, so + a wrong value programs the wrong thresholds. + enum: [250000, 500000] + + required: + - reg + - sense-resistor-micro-ohms + + required: + - '#address-cells' + - '#size-cells' + + pse-pis: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells':Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +6
-0+ const: 0 + + patternProperties: + '^pse-pi@[0-3]$': + type: object + additionalProperties: trueThis cannot be true. That allows adding any property.
Quoted 5 lines
So my intent with the additionalProperties: true was to avoid replicating the entire pse-pis node from
pse-controller.yaml. Conceptually, my goal was to inherit everything from thepse-controller.yamlbinding, except limit the maxItems to 1 (since the LTC4266 only supports power over a single PI).
pse-controller.yaml doesn't have the constraint there either. It is fine if the constraint is there. However, that means custom properties are not allowed in pse-pi nodes. Maybe that's fine and is certainly easier for the schema. If you do forsee a need for device specific properties in this node, then you need a $ref in this node with all the common properties. IOW, similar to how the graph schema is structured.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+ properties: + pairsets: + description: The LTC4266 delivers power to a PI over a single + pairset, driven by one of the controller's four channels. There + is no 4-pair mode spreading a PI over two channels, so exactly + one channel phandle is expected. + maxItems: 1 + pairset-names: + maxItems: 1
Quoted 4 lines
Quoted 1 line
An empty node is valid? Needs 'required'.
I thought the 'required' comes from the
pse-controller.yamlbinding. If I adjust the example dts in the binding with something like
Indeed. My mistake.
Review
Quoted 8 lines
pse_pi2: pse-pi@2 {(quoted diff) +0
-6- reg = <2>; - #pse-cells = <0>; - pairset-names = "alternative-a"; - pairsets = <&phys2>; - polarity-supported = "MDI"; - vpwr-supply = <&vreg_pse>;
If instead, you add 'foo-bar' property, you won't see any failure. That's the 1st issue.
Rob
PATCH v3 2/2 net: pse-pd: Add LTC4266 PSE controller driver
In reply to Kyle SwensonAdd a new driver for the Linear Technology LTC4266 I2C Power Sourcing Equipment controller and integrate with the PSE controller core. The LTC4266 supports Type 1 and Type 2 Powered Devices.
--- MAINTAINERS | 7 + drivers/net/pse-pd/Kconfig | 11 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/ltc4266.c | 1386 ++++++++++++++++++++++++++++++++++ 4 files changed, 1405 insertions(+) create mode 100644 drivers/net/pse-pd/ltc4266.c
MAINTAINERS +7 -0
@@ -15531,10 +15531,17 @@ L: [email protected] S: Maintained W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/leds/adi,ltc3220.yaml F: drivers/leds/leds-ltc3220.c +LTC4266 PSE CONTROLLER DRIVER +M: Kyle Swenson <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml +F: drivers/net/pse-pd/ltc4266.c + LTC4282 HARDWARE MONITOR DRIVER M: Nuno Sa <[email protected]> L: [email protected] S: Supported F: Documentation/devicetree/bindings/hwmon/adi,ltc4282.yaml
drivers/net/pse-pd/Kconfig +11 -0
@@ -46,10 +46,21 @@ config PSE_REGULATOR help This module provides support for simple regulator based Ethernet Power Sourcing Equipment without automatic classification support. For example for basic implementation of PoDL (802.3bu) specification. +config PSE_LTC4266 + tristate "LTC4266 PSE controller" + depends on I2C + select REGMAP_I2C + help + This module provides support for LTC4266 regulator based Ethernet + Power Sourcing Equipment. + + To compile this driver as a module, choose M here: the + module will be called ltc4266. + config PSE_PD692X0 tristate "PD692X0 PSE controller" depends on I2C select FW_LOADER select FW_UPLOAD
drivers/net/pse-pd/Makefile +1 -0
@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only # Makefile for Linux PSE drivers obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o +obj-$(CONFIG_PSE_LTC4266) += ltc4266.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
drivers/net/pse-pd/ltc4266.c new file +1386 -0
1,386 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] pse: incorrect devres registration order causes IRQ use-after-free - [High] pse: swallowing…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] pse: incorrect devres registration order causes IRQ use-after-free
- [High] pse: swallowing -EPROBE_DEFER causes incorrect I_CUT limit calculation --
commit 1aad2f6b5a72ee34250a04fe6ad2b8aea94fa801
Author: Kyle Swenson <[email protected]>
net: pse-pd: Add LTC4266 PSE controller driver
Add a new driver for the Linear Technology LTC4266 I2C Power Sourcing Equipment controller and integrate with the PSE controller core. The LTC4266 supports Type 1 and Type 2 Powered Devices.
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +0
-0
[ ... ]
Quoted 12 lines
drivers/net/pse-pd/ltc4266.c new file +12
-0+static int ltc4266_pi_nominal_uv (struct ltc4266 *ltc4266,struct device_node *np) +{ +struct regulator *vpwr; +int uv; + + vpwr =of_regulator_get_optional (ltc4266->dev, np,"vpwr" ); +if (IS_ERR (vpwr)) { +/* -ENODEV means the PI describes no vpwr-supply at all, which +* is the case the fallback exists for. -EPROBE_DEFER means the +* rail _is_ described but has not registered yet, so the +* fallback is wrong for it. Asking for a probe retry is not an +* option from here: we run from setup_pi_matrix(), and
drivers/net/pse-pd/ltc4266.c line 912
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+* pse_controller_register() unwinds neither its notification +* fifo nor its pse_pi array when that fails, so every retry +* would leak. Warn instead so the assumed voltage is visible. +*/ +if (PTR_ERR (vpwr) == -EPROBE_DEFER ) +dev_warn (ltc4266->dev, +"%pOF: vpwr-supply is not registered yet, assuming %d uV\n" , + np,LTC4266_VPORT_NOMINAL_UV ); + +return LTC4266_VPORT_NOMINAL_UV ;
[Severity: High]
Does swallowing -EPROBE_DEFER here cause an incorrect I_CUT limit calculation?
If the vpwr-supply regulator is not yet registered when the LTC4266 driver probes, of_regulator_get_optional() returns -EPROBE_DEFER. By suppressing this error and falling back to a hardcoded 50V nominal voltage, the port might operate with an incorrect, permanently-cached power limit. This could result in delivering more power than administratively allowed, potentially damaging equipment or violating PoE budgets.
[ ... ]
Quoted 2 lines
drivers/net/pse-pd/ltc4266.c new file +2
-0+static int ltc4266_probe (struct i2c_client *client) +{
[ ... ]
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c new file +9
-0+ ret =devm_pse_controller_register (ltc4266->dev, <c4266->pcdev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to register PSE controller\n" ); + +/* Enable the interrupt pin, and only report detect events on +* change (detchg) so idle ports continuously re-running +* detection in semi-auto mode don't flood the host with a +* detect event every cycle.
drivers/net/pse-pd/ltc4266.c line 1348
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+*/ + ret =regmap_update_bits (ltc4266->regmap,LTC4266_REG_MCONF , +LTC4266_MCONF_INTERRUPT_ENABLE |LTC4266_MCONF_DETCHG , +LTC4266_MCONF_INTERRUPT_ENABLE |LTC4266_MCONF_DETCHG ); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to configure interrupts\n" ); + + ret =devm_pse_irq_helper (<c4266->pcdev, client->irq, +0 , &irq_desc);
[Severity: High]
Will this devres registration order cause an IRQ use-after-free during unbind?
Because devm_pse_controller_register() is called before devm_pse_irq_helper() in ltc4266_probe(), the devres LIFO ordering will free the IRQ first during module removal or probe failure teardown.
After the IRQ is freed, the devres teardown will unregister the controller, which unconditionally calls disable_irq(pcdev->irq) inside of pse_controller_unregister(). If the IRQ was reassigned to another device in the meantime, this could disable that device's interrupt and cause a denial of service.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 6 (3) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] If a PI's vpwr-supply is described in DT but not yet registered when the LTC4266 probes, ltc4266_pi_nominal_uv() carries on (warn plus…
- [Medium] ltc4266_pi_get_pw_class() reports the wrong power class to userspace.
- [Medium] ltc4266_pi_nominal_uv() swallows -EPROBE_DEFER from of_regulator_get_optional().
- [Medium] ltc4266_map_event() loses hardware events on every error exit.
- [Medium] ltc4266_pi_set_pw_limit() treats every negative ltc4266_port_get_class() result as 'not classified', including…
- [Medium] ltc4266_map_event() reports ETHTOOL_C33_PSE_EVENT_CLASSIFICATION whenever the detevn high nibble…
- [Medium] ltc4266_pi_disable() is carried out by ltc4266_port_init(), whose first write (RSTPB = BIT(chan)) removes power from the port.
- [Low] The LTC4266 binding sets maxItems: 1 for pse-pi 'pairsets' but does not list it as required, and pse-controller.yaml requires only…
- [Low] ltc4266_regmap_config sets only reg_bits, val_bits and max_register (0x5F), with no precious_reg or readable_reg callbacks.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new driver makes it easy to hit.
- [High] This problem wasn't introduced by this patch, but the new driver opts into the affected path.
- [Medium] This problem wasn't introduced by this patch, but: when ops->setup_pi_matrix() fails, pse_controller_register() returns…
- [Medium] This problem wasn't introduced by this patch, but:
pse_controller_unregister() calls pse_release_pis() (kfree(pcdev->pi))…
- [Medium] This problem wasn't introduced by this patch, but:
pse_control_get_internal() calls try_module_get(pcdev->owner) and…
--
net: pse-pd: Add LTC4266 PSE controller driver
This commit adds a new I2C driver for the Linear Technology LTC4266 PoE PSE controller and hooks it into the PSE controller core. The driver runs the chip in semi-auto mode and maps PSE PIs to delivery channels from the device tree. It uses the chip interrupt together with the static power budget evaluation strategy.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +0
-0@@ -0,0 +1,1386 @@
[ ... ]
drivers/net/pse-pd/ltc4266.c line 653
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+static int ltc4266_pi_disable (struct pse_controller_dev *pcdev,int id) +{ +struct ltc4266_port *port =ltc4266_pi_port (pcdev, id); + +/* Resetting the port (RSTPB, issued at the start of ltc4266_port_init) +* removes power, disables detection and classification, and clears the +* port's status register. Re-init the port so that detection and +* classification can happen again. +*/ +return ltc4266_port_init (port); +}
[Severity: Medium]
What happens if one of the writes after the RSTPB reset in ltc4266_port_init() fails?
The first write in ltc4266_port_init() has already removed power from the port. A later failure in the OPMD, HPEN, HPMD, TLIM, DISENA or DETPB write is still returned as a failed disable, and _pse_pi_disable() then skips the budget release:
drivers/net/pse-pd/pse_core.c:_pse_pi_disable() {
...
ret = ops->pi_disable(pcdev, id);
if (ret)
return ret;
pse_pi_deallocate_pw_budget(&pcdev->pi[id]);
...
}Would the core then keep budget allocated and admin_state_enabled set for a port that has no power? DETPB was never written, so detection stays off. No later classification interrupt would arrive to resync the state.
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_get_admin_state (struct pse_controller_dev *pcdev,int id, +struct pse_admin_state *admin_state) +{
[ ... ]
drivers/net/pse-pd/ltc4266.c line 679
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+ ret =regmap_read (port->ltc4266->regmap,LTC4266_REG_STATPWR , &val); +if (ret <0 ) +return ret;
[Severity: Medium]
This isn't a bug introduced by this patch, but an I2C error returned here reaches a module reference leak that already exists in the PSE core. pse_control_get_internal() calls try_module_get(pcdev->owner) and then does this:
drivers/net/pse-pd/pse_core.c:pse_control_get_internal() {
...
ret = pse_pi_is_hw_enabled(pcdev, index);
if (ret < 0)
goto free_psec;
...
}That jump skips the put_module label. If an I2C error happens while a PHY is acquiring its PSE control, does the ltc4266 module stay pinned?
[ ... ]
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+static int ltc4266_pi_get_pw_class (struct pse_controller_dev *pcdev,int id) +{ +int ret =ltc4266_port_get_class (ltc4266_pi_port (pcdev, id)); +
[ ... ]
drivers/net/pse-pd/ltc4266.c line 710
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+if (ret ==0 ) + ret =3 ; +if (ret <0 ) + ret =0 ; +return ret; +}
[Severity: Medium]
Does this report the wrong power class to userspace?
A PD that has a valid detection signature but no class signature (statp class code 0x6, which is class 0 in ltc4266_class_map[]) is reported as class 3.
Every negative result from ltc4266_port_get_class() becomes 0. That covers regmap I2C errors, -EAGAIN (classification not finished), -EINVAL (detection not good) and -ERANGE.
pse_ethtool_get_status() stores the value in status->c33_pw_class, and pse_fill_reply() only emits it when it is greater than zero:
net/ethtool/pse-pd.c:pse_fill_reply() {
...
if (st->c33_pw_class > 0 &&
nla_put_u32(skb, ETHTOOL_A_C33_PSE_PW_CLASS,
...
}So ethtool --show-pse would show class 3 for a class 0 PD, and an I2C failure would look the same as no PD at all. Other drivers, such as tps23881_pi_get_pw_class(), return the raw class and propagate errors.
ltc4266_class_pw[] and pi_get_pw_req already treat class 0 like class 3 for power budgeting. Could this callback report the real class instead? If the rewrite stays, could the commit message mention it?
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_set_pw_limit (struct pse_controller_dev *pcdev, +int id,int max_mw) +{
[ ... ]
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+ class =ltc4266_port_get_class (port); +if (class >=0 ) { + icut =ltc4266_pw_limit_to_icut (port, max_mw, class); +if (icut <0 )
drivers/net/pse-pd/ltc4266.c line 791
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+return icut; + + ret =ltc4266_port_set_icut (port, icut); +if (ret <0 ) +return ret; + } + + port->pw_limit = max_mw; + +return 0 ;
[Severity: Medium]
Should a regmap_read() failure inside ltc4266_port_get_class() be treated the same as "not classified" here?
On a powered port, a transient I2C error skips ltc4266_port_set_icut(), but port->pw_limit is still updated and 0 is returned. pse_ethtool_set_pw_limit() has already updated the power budget and only rolls it back on an error return. The core budget and the reported limit would then show the new value while the hardware keeps enforcing the old I_CUT.
[ ... ]
Quoted 13 lines
drivers/net/pse-pd/ltc4266.c new file +13
-0+static int ltc4266_pi_nominal_uv (struct ltc4266 *ltc4266,struct device_node *np) +{ +struct regulator *vpwr; +int uv; + + vpwr =of_regulator_get_optional (ltc4266->dev, np,"vpwr" ); +if (IS_ERR (vpwr)) { +/* -ENODEV means the PI describes no vpwr-supply at all, which +* is the case the fallback exists for. -EPROBE_DEFER means the +* rail _is_ described but has not registered yet, so the +* fallback is wrong for it. Asking for a probe retry is not an +* option from here: we run from setup_pi_matrix(), and +* pse_controller_register() unwinds neither its notification
drivers/net/pse-pd/ltc4266.c line 913
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+* fifo nor its pse_pi array when that fails, so every retry +* would leak. Warn instead so the assumed voltage is visible. +*/ +if (PTR_ERR (vpwr) == -EPROBE_DEFER ) +dev_warn (ltc4266->dev, +"%pOF: vpwr-supply is not registered yet, assuming %d uV\n" , + np,LTC4266_VPORT_NOMINAL_UV ); + +return LTC4266_VPORT_NOMINAL_UV ; + }
[Severity: Medium]
Does swallowing -EPROBE_DEFER here actually avoid the leak described in the comment?
ltc4266_setup_pi_matrix() still has many other error returns that go through the same unwind gap in pse_controller_register(): DT validation in ltc4266_get_of_channels() and ltc4266_map_pis(), -ENOMEM, and I2C errors from ltc4266_port_init().
drivers/net/pse-pd/pse_core.c:pse_controller_register() {
...
if (pcdev->ops->setup_pi_matrix) {
ret = pcdev->ops->setup_pi_matrix(pcdev);
if (ret)
return ret;
}
...
}In the deferred case, the 50 V nominal voltage stays for the whole life of the binding. ltc4266_pw_limit_to_icut() uses it whenever an admin limit is set on an unpowered port.
The deferral can happen in practice. fw_devlink only creates SYNC_STATE_ONLY links for suppliers referenced from child nodes, such as the pse-pi nodes, so the supply does not hold back this probe.
Could the unwind in pse_controller_register() be fixed in a prerequisite patch? Alternatively, the supplies could be resolved before devm_pse_controller_register() so that probe can return -EPROBE_DEFER.
[Severity: High]
Continuing with a deferred vpwr-supply also has a functional effect. Can the PI end up with no PSE power domain for good?
If the supply is not registered yet, regulator_resolve_supply() returns -EPROBE_DEFER and regulator_register() leaves rdev->supply NULL for the PI regulator. pse_register_pw_ds() runs only once, from pse_controller_register():
drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() {
...
if (!rdev || !rdev->supply)
continue;
...
}So pi->pw_d stays NULL even after the supply resolves, and pse_pw_d_is_sw_pw_control() returns false for this PI. Two things follow.
First, pse_isr() never calls pse_set_config_isr(). The CLASSIFICATION and DISCONNECTION events from ltc4266_map_event() then never power the port or re-arm it.
Second, on admin enable pse_pi_enable() calls ltc4266_pi_enable() directly. That fails in ltc4266_port_get_class() with -EINVAL or -EAGAIN when no PD has been classified.
The chip runs in semi-auto mode and never powers a port without a PWRPB write. Would a PD that is plugged in later stay unpowered until the driver is rebound?
This only affects a supply that is described but deferred. When vpwr-supply is missing entirely, the dummy regulator is used and a power domain is still created.
[ ... ]
drivers/net/pse-pd/ltc4266.c line 943
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+if (!pi->pairset[0 ].np) +return dev_err_probe (ltc4266->dev, -EINVAL , +"%pOF has no pairsets\n" , pi->np);
[Severity: Low]
The lltc,ltc4266.yaml binding gives pairsets maxItems: 1 for each pse-pi node but does not list it as required. pse-controller.yaml only requires reg and #pse-cells, and of_load_pse_pis() also accepts a PI without pairsets.
Should the binding list pairsets as required? Otherwise a DT that passes dt_binding_check fails probe here.
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1003
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c new file +9
-0+ ret =ltc4266_get_of_channels (ltc4266, chans); +if (!ret) + ret =ltc4266_map_pis (ltc4266, chans); + +for (i =0 ; i <LTC4266_MAX_PORTS ; i++) +of_node_put (chans[i].np); + +if (ret) +return ret;
[Severity: Medium]
This is a pre-existing issue, but every error return from ltc4266_setup_pi_matrix() runs into it.
When setup_pi_matrix() fails, pse_controller_register() returns without calling kfifo_free(&pcdev->ntf_fifo) or pse_release_pis(), and devm_pse_controller_register() only calls devres_free(). Would each failed probe leak the pcdev->pi array and the of_node references on the PI and pairset nodes?
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1195
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c new file +8
-0+if (detevn <C4266_EVN_HI (chan)) { +int class =ltc4266_port_get_class (port); + +if (class >=0 ) { + notifs[i] |=ETHTOOL_C33_PSE_EVENT_CLASSIFICATION ; + *notifs_mask |=BIT (i); + } + }
[Severity: Medium]
Should this check whether the port is already powered before reporting a classification event?
For an admin-enabled PI, pse_set_config_isr() calls _pse_pi_delivery_power_sw_pw_ctrl() on every CLASSIFICATION event. pse_pi_allocate_pw_budget_static_prio() does not check for an existing
allocation: it requests budget again and overwrites pi->pw_allocated_mW. ltc4266_pi_enable() then rewrites ILIM, ICUT and PWRPB on the live port.
Here is one way this could happen. pse_pi_enable() powers the port while holding pcdev->lock, and a class event is latched at the same time. The IRQ thread waits for pcdev->lock and then reads the stale DETEVN for a port that is now powered. A classification that completes between the DETEVN_COR read and the PWRPB write in the ISR would have the same effect.
Could this leak the first budget allocation and shut off lower-priority ports for no reason? It depends on whether the chip raises a new class event for an unchanged result while MCONF.detchg is set.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ } + +done: +return ltc4266_enable_interrupts (ltc4266); + +err:
drivers/net/pse-pd/ltc4266.c line 1211
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+/* (Attempt to) clear any remaining event registers that we might've +* missed in the event a previous read has failed. +*/ + ret =regmap_write (ltc4266->regmap,LTC4266_REG_RSTPB ,LTC4266_RSTPB_INTCLR ); +if (ret) +dev_warn (<c4266->client->dev,"Failed to clear pending interrupts, err=%d\n" , + ret); + +return ltc4266_enable_interrupts (ltc4266); +}
[Severity: Medium]
Can this error path lose hardware events?
PWREVN_COR, FLTEVN_COR, TSEVN_COR and DETEVN_COR clear on read. When a later read fails, the latches read before it (for example a tCUT bit in fltevn or a PG-lost bit in pwrevn) have already been cleared, and their values are thrown away.
The RSTPB_INTCLR write then clears the latched events on every channel, including ones that were never read. ltc4266_enable_interrupts() normally returns 0, so pse_isr() sees success with an empty mask and does nothing.
The reverse case is also a problem. If the INTMASK write in ltc4266_enable_interrupts() fails after decoding, pse_isr() throws away the notifications because of the nonzero return:
drivers/net/pse-pd/pse_core.c:pse_isr() {
...
ret = desc->map_event(irq, pcdev, h->notifs, h->notifs_mask);
if (ret || bitmap_empty(h->notifs_mask, pcdev->nr_lines)) {
mutex_unlock(&pcdev->lock);
return IRQ_NONE;
...
}INTMASK also stays at 0 from the ltc4266_disable_interrupts() call at entry, so no further interrupts would arrive.
With detchg set, a lost classification is not raised again. A lost fault or PG-loss leaves the core thinking the port is delivering, with its budget still allocated.
Is there any way for the driver to resync after one I2C error in the IRQ thread?
drivers/net/pse-pd/ltc4266.c line 1217
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ +static const struct regmap_config ltc4266_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =0x5F , +};
[Severity: Low]
Should a precious_reg callback mark the clear-on-read event registers (0x03, 0x05, 0x07, 0x09, 0x0B) as precious? Without it, a regmap debugfs registers dump reads them and clears pending detect, class and fault latches before the IRQ handler sees them. A readable_reg callback would also stop the dump from reading the reserved addresses in the gaps of the register map.
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1328
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ ltc4266->pcdev.owner =THIS_MODULE ; + ltc4266->pcdev.ops = <c4266_ops; + ltc4266->pcdev.dev = &client->dev; + ltc4266->pcdev.types =ETHTOOL_PSE_C33 ; + ltc4266->pcdev.nr_lines =LTC4266_MAX_PORTS ; + ltc4266->pcdev.supp_budget_eval_strategies =PSE_BUDGET_EVAL_STRAT_STATIC ;
[Severity: High]
This isn't a bug introduced by this patch, but choosing the static budget strategy exposes a lock ordering problem that already exists in the PSE core.
pse_isr() holds pcdev->lock and ends up taking the supply regulator lock:
pse_isr()
pse_set_config_isr()
_pse_pi_delivery_power_sw_pw_ctrl()
pse_pi_allocate_pw_budget_static_prio()
regulator_request_power_budget(pw_d->supply)
regulator_lock(rdev)An admin enable running at the same time takes the locks in the opposite order:
regulator_enable(psec->ps)
regulator_lock_dependent() (PI rdev, then its supply rdev)
_regulator_enable()
pse_pi_is_enabled() / pse_pi_enable()
mutex_lock(&pcdev->lock)Can a classification interrupt on one PI, racing with an admin enable of another PI on the same supply, deadlock both the IRQ thread and the ethtool task? The ww_mutex scheme cannot break a cycle that includes the plain pcdev->lock mutex.
drivers/net/pse-pd/ltc4266.c line 1333
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+ + ret =devm_pse_controller_register (ltc4266->dev, <c4266->pcdev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to register PSE controller\n" );
[Severity: High]
This is a pre-existing issue in the PSE core, but boards with more than one LTC4266 are likely to hit it.
devm_pse_alloc_pw_d() allocates the power domain with devm_kzalloc(pcdev->dev) and publishes it in the global pse_pw_d_map. pse_register_pw_ds() then gives the same object to any other controller whose PI supply matches:
drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() {
...
if (regulator_is_equal(pw_d->supply, rdev->supply)) {
present = true;
pcdev->pi[i].pw_d = pw_d;
...
}Consider all PIs pointing at one shared supply, as in the binding example, or sharing the dummy regulator when vpwr-supply is omitted. Unbinding the first controller frees the memory through devres, but the xarray entry and the other controller's pointers remain.
Would the second controller's pse_flush_pw_ds() then read pw_d->id and call kref_put_mutex() on freed memory? pse_isr()-> pse_pw_d_is_sw_pw_control() would use the same dangling pointer.
[Severity: Medium]
This is a pre-existing issue, but the teardown order in pse_controller_unregister() looks unsafe:
drivers/net/pse-pd/pse_core.c:pse_controller_unregister() {
...
pse_flush_pw_ds(pcdev);
pse_release_pis(pcdev);
if (pcdev->irq)
disable_irq(pcdev->irq);
cancel_work_sync(&pcdev->ntf_work);
...
}pse_send_ntf_worker() takes a psec reference with pse_control_find_by_id() and drops it with pse_control_put(). If that is the last reference, __pse_control_release() reads psec->pcdev->pi[psec->id].admin_state_enabled after pse_release_pis() has freed the array.
Could the work be cancelled before the PI array is released?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927212929.593366-1-kyle.swenson%40est.tech
Hello,
Quoted 91 lines · On Wed, Sep 30, 2026 at 09:31:02PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 6 (3) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] If a PI's vpwr-supply is described in DT but not yet registered when the LTC4266 probes,
ltc4266_pi_nominal_uv()carries on (warn plus…
- [Medium]ltc4266_pi_get_pw_class()reports the wrong power class to userspace.
- [Medium]ltc4266_pi_nominal_uv()swallows -EPROBE_DEFER fromof_regulator_get_optional().
- [Medium]ltc4266_map_event()loses hardware events on every error exit.
- [Medium]ltc4266_pi_set_pw_limit()treats every negativeltc4266_port_get_class()result as 'not classified', including…
- [Medium]ltc4266_map_event()reportsETHTOOL_C33_PSE_EVENT_CLASSIFICATIONwhenever the detevn high nibble…
- [Medium]ltc4266_pi_disable()is carried out byltc4266_port_init(), whose first write (RSTPB = BIT(chan)) removes power from the port.
- [Low] The LTC4266 binding sets maxItems: 1 for pse-pi 'pairsets' but does not list it as required, andpse-controller.yamlrequires only…
- [Low]ltc4266_regmap_configsets onlyreg_bits,val_bitsandmax_register(0x5F), with noprecious_regorreadable_regcallbacks.Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new driver makes it easy to hit.
- [High] This problem wasn't introduced by this patch, but the new driver opts into the affected path.
- [Medium] This problem wasn't introduced by this patch, but: whenops->setup_pi_matrix()fails,pse_controller_register()returns…
- [Medium] This problem wasn't introduced by this patch, but:
pse_controller_unregister()callspse_release_pis()(kfree(pcdev->pi))…
- [Medium] This problem wasn't introduced by this patch, but:
pse_control_get_internal()callstry_module_get(pcdev->owner)and…--
net: pse-pd: Add LTC4266 PSE controller driver
This commit adds a new I2C driver for the Linear Technology LTC4266 PoE PSE controller and hooks it into the PSE controller core. The driver runs the chip in semi-auto mode and maps PSE PIs to delivery channels from the device tree. It uses the chip interrupt together with the static power budget evaluation strategy.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +0
-0@@ -0,0 +1,1386 @@[ ... ]
drivers/net/pse-pd/ltc4266.c line 653
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+static int ltc4266_pi_disable (struct pse_controller_dev *pcdev,int id) +{ +struct ltc4266_port *port =ltc4266_pi_port (pcdev, id); + +/* Resetting the port (RSTPB, issued at the start of ltc4266_port_init) +* removes power, disables detection and classification, and clears the +* port's status register. Re-init the port so that detection and +* classification can happen again. +*/ +return ltc4266_port_init (port); +}[Severity: Medium]
What happens if one of the writes after the RSTPB reset inltc4266_port_init()fails?The first write in
ltc4266_port_init()has already removed power from the port. A later failure in the OPMD, HPEN, HPMD, TLIM, DISENA or DETPB write is still returned as a failed disable, and_pse_pi_disable()then skips the budget release:drivers/net/pse-pd/pse_core.c:_pse_pi_disable() { ... ret = ops->pi_disable(pcdev, id); if (ret) return ret; pse_pi_deallocate_pw_budget(&pcdev->pi[id]); ... }
Quoted 4 lines
Would the core then keep budget allocated and
admin_state_enabledset for a port that has no power? DETPB was never written, so detection stays off. No later classification interrupt would arrive to resync the state.
Yes, it appears the TPS23881 driver has this issue as well. I can see the contract go in one of two directions: drivers only return non-zero if the port wasn't able to be disabled enough to give back power budget or the core's _pse_pi_disable should always free the budget after calling pi_disable and then return the error at the end of the _pse_pi_disable.
Kory, Oleksij, what are your thoughts?
Quoted 26 lines
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_get_admin_state (struct pse_controller_dev *pcdev,int id, +struct pse_admin_state *admin_state) +{[ ... ]
drivers/net/pse-pd/ltc4266.c line 679
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+ ret =regmap_read (port->ltc4266->regmap,LTC4266_REG_STATPWR , &val); +if (ret <0 ) +return ret;[Severity: Medium]
This isn't a bug introduced by this patch, but an I2C error returned here reaches a module reference leak that already exists in the PSE core.pse_control_get_internal()callstry_module_get(pcdev->owner)and then does this:drivers/net/pse-pd/pse_core.c:pse_control_get_internal() { ... ret = pse_pi_is_hw_enabled(pcdev, index); if (ret < 0) goto free_psec; ... }
Quoted 3 lines
That jump skips the
put_modulelabel. If an I2C error happens while a PHY is acquiring its PSE control, does the ltc4266 module stay pinned?
Sure seems like it. It appears like it'd also stay pinned in a few of the other goto free_psec; statements after the try_module_get. I'll plan on pushing a separate patch with an appropriate Fixes: tag later, since I'm hesitant to mix it in with a v4 of this series.
Quoted 37 lines
[ ... ]
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+static int ltc4266_pi_get_pw_class (struct pse_controller_dev *pcdev,int id) +{ +int ret =ltc4266_port_get_class (ltc4266_pi_port (pcdev, id)); +[ ... ]
drivers/net/pse-pd/ltc4266.c line 710
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+if (ret ==0 ) + ret =3 ; +if (ret <0 ) + ret =0 ; +return ret; +}[Severity: Medium]
Does this report the wrong power class to userspace?A PD that has a valid detection signature but no class signature (statp class code
0x6, which is class 0 in ltc4266_class_map[]) is reported as class 3.Every negative result from
ltc4266_port_get_class()becomes 0. That covers regmap I2C errors,-EAGAIN(classification not finished),-EINVAL(detection not good) and-ERANGE.
pse_ethtool_get_status()stores the value instatus->c33_pw_class, andpse_fill_reply()only emits it when it is greater than zero:net/ethtool/pse-pd.c:pse_fill_reply() { ... if (st->c33_pw_class > 0 && nla_put_u32(skb, ETHTOOL_A_C33_PSE_PW_CLASS, ... }
Quoted 7 lines
So ethtool --show-pse would show class 3 for a class 0 PD, and an I2C failure would look the same as no PD at all. Other drivers, such as
tps23881_pi_get_pw_class(), return the raw class and propagate errors.ltc4266_class_pw[] and
pi_get_pw_reqalready treat class 0 like class 3 for power budgeting. Could this callback report the real class instead? If the rewrite stays, could the commit message mention it?
So the issue I was trying to work around with this was where the ethtool --show-pse command will omit the field if it's zero. Since the TPS23881 driver seems to return the raw class, including zero, I'll follow suit and adjust this in v4.
Quoted 19 lines
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_set_pw_limit (struct pse_controller_dev *pcdev, +int id,int max_mw) +{[ ... ]
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+ class =ltc4266_port_get_class (port); +if (class >=0 ) { + icut =ltc4266_pw_limit_to_icut (port, max_mw, class); +if (icut <0 ) +return icut; + + ret =ltc4266_port_set_icut (port, icut); +if (ret <0 ) +return ret; + }
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 791
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+ + port->pw_limit = max_mw; + +return 0 ;[Severity: Medium]
Should aregmap_read()failure insideltc4266_port_get_class()be treated the same as "not classified" here?
Well, my intent was that if we don't know the class of the PD connected, how can we set an accurate power limit?
Quoted 3 lines
On a powered port, a transient I2C error skips
ltc4266_port_set_icut(), butport->pw_limitis still updated and 0 is returned.
We'll skip to the port->pw_limit ( which is the admin power limit, set by the admin, and should be independent of the PD's class (if any)).
Quoted 5 lines
pse_ethtool_set_pw_limit()has already updated the power budget and only rolls it back on an error return. The core budget and the reported limit would then show the new value while the hardware keeps enforcing the oldI_CUT.
I think the real bug is that port->pw_limit isn't always set like it should be, so in v4 I'll re-arrange this such that the port->pw_limit is always set, and then I'll check if there's a PD on the port that's been classified and set the hardware limit according to the class after assigning the pw_limit.
Quoted 49 lines
[ ... ]
Quoted 13 lines
drivers/net/pse-pd/ltc4266.c new file +13
-0+static int ltc4266_pi_nominal_uv (struct ltc4266 *ltc4266,struct device_node *np) +{ +struct regulator *vpwr; +int uv; + + vpwr =of_regulator_get_optional (ltc4266->dev, np,"vpwr" ); +if (IS_ERR (vpwr)) { +/* -ENODEV means the PI describes no vpwr-supply at all, which +* is the case the fallback exists for. -EPROBE_DEFER means the +* rail _is_ described but has not registered yet, so the +* fallback is wrong for it. Asking for a probe retry is not an +* option from here: we run from setup_pi_matrix(), and +* pse_controller_register() unwinds neither its notification drivers/net/pse-pd/ltc4266.c line 913
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+* fifo nor its pse_pi array when that fails, so every retry +* would leak. Warn instead so the assumed voltage is visible. +*/ +if (PTR_ERR (vpwr) == -EPROBE_DEFER ) +dev_warn (ltc4266->dev, +"%pOF: vpwr-supply is not registered yet, assuming %d uV\n" , + np,LTC4266_VPORT_NOMINAL_UV ); + +return LTC4266_VPORT_NOMINAL_UV ; + }[Severity: Medium]
Does swallowing -EPROBE_DEFER here actually avoid the leak described in the comment?
ltc4266_setup_pi_matrix()still has many other error returns that go through the same unwind gap inpse_controller_register(): DT validation inltc4266_get_of_channels()andltc4266_map_pis(),-ENOMEM, and I2C errors fromltc4266_port_init().drivers/net/pse-pd/pse_core.c:pse_controller_register() { ... if (pcdev->ops->setup_pi_matrix) { ret = pcdev->ops->setup_pi_matrix(pcdev); if (ret) return ret; } ... }In the deferred case, the 50 V nominal voltage stays for the whole life of the binding.
ltc4266_pw_limit_to_icut()uses it whenever an admin limit is set on an unpowered port.
Quoted 8 lines
The deferral can happen in practice.
fw_devlinkonly createsSYNC_STATE_ONLYlinks for suppliers referenced from child nodes, such as the pse-pi nodes, so the supply does not hold back this probe.Could the unwind in
pse_controller_register()be fixed in a prerequisite patch? Alternatively, the supplies could be resolved beforedevm_pse_controller_register()so that probe can return -EPROBE_DEFER.
Fixing the EPROBE_DEFER leak in the pse_core seems like a better option so I'll send a fix for that separately to get other people's thoughts.
Quoted 27 lines
[Severity: High]
Continuing with a deferred vpwr-supply also has a functional effect. Can the PI end up with no PSE power domain for good?If the supply is not registered yet,
regulator_resolve_supply()returns -EPROBE_DEFER andregulator_register()leavesrdev->supplyNULL for the PI regulator.pse_register_pw_ds()runs only once, frompse_controller_register():drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() { ... if (!rdev || !rdev->supply) continue; ... }So
pi->pw_dstays NULL even after the supply resolves, andpse_pw_d_is_sw_pw_control()returns false for this PI. Two things follow.First,
pse_isr()never callspse_set_config_isr(). The CLASSIFICATION and DISCONNECTION events fromltc4266_map_event()then never power the port or re-arm it.Second, on admin enable
pse_pi_enable()callsltc4266_pi_enable()directly. That fails inltc4266_port_get_class()with-EINVALor-EAGAINwhen no PD has been classified.
Quoted 8 lines
The chip runs in semi-auto mode and never powers a port without a PWRPB write. Would a PD that is plugged in later stay unpowered until the driver is rebound?
This only affects a supply that is described but deferred. When vpwr-supply is missing entirely, the dummy regulator is used and a power domain is still created.
This seems correct to me, and I'm pretty sure the cleanest option is to fix the pse-core.
Quoted 12 lines
[ ... ]
drivers/net/pse-pd/ltc4266.c line 943
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+if (!pi->pairset[0 ].np) +return dev_err_probe (ltc4266->dev, -EINVAL , +"%pOF has no pairsets\n" , pi->np);[Severity: Low]
The lltc,ltc4266.yaml binding gives pairsets maxItems: 1 for each pse-pi node but does not list it as required.pse-controller.yamlonly requires reg and #pse-cells, andof_load_pse_pis()also accepts a PI without pairsets.
Quoted 2 lines
Should the binding list pairsets as required? Otherwise a DT that passes
dt_binding_checkfails probe here.
Yeah, it probably should since a pse-pi node with no pairsets doesn't make a lot of sense.
Quoted 17 lines
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1003
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c new file +9
-0+ ret =ltc4266_get_of_channels (ltc4266, chans); +if (!ret) + ret =ltc4266_map_pis (ltc4266, chans); + +for (i =0 ; i <LTC4266_MAX_PORTS ; i++) +of_node_put (chans[i].np); + +if (ret) +return ret;[Severity: Medium]
This is a pre-existing issue, but every error return fromltc4266_setup_pi_matrix()runs into it.
Quoted 6 lines
When
setup_pi_matrix()fails,pse_controller_register()returns without callingkfifo_free(&pcdev->ntf_fifo)orpse_release_pis(), anddevm_pse_controller_register()only callsdevres_free(). Would each failed probe leak thepcdev->piarray and theof_nodereferences on the PI and pairset nodes?
This is the same leak issue I plan on fixing separately with it's own
Fixes: tag.
Quoted 28 lines
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1195
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c new file +8
-0+if (detevn <C4266_EVN_HI (chan)) { +int class =ltc4266_port_get_class (port); + +if (class >=0 ) { + notifs[i] |=ETHTOOL_C33_PSE_EVENT_CLASSIFICATION ; + *notifs_mask |=BIT (i); + } + }[Severity: Medium]
Should this check whether the port is already powered before reporting a classification event?For an admin-enabled PI,
pse_set_config_isr()calls_pse_pi_delivery_power_sw_pw_ctrl()on every CLASSIFICATION event.pse_pi_allocate_pw_budget_static_prio()does not check for an existing
allocation: it requests budget again and overwritespi->pw_allocated_mW.ltc4266_pi_enable()then rewrites ILIM, ICUT and PWRPB on the live port.Here is one way this could happen.
pse_pi_enable()powers the port while holdingpcdev->lock, and a class event is latched at the same time. The IRQ thread waits forpcdev->lockand then reads the stale DETEVN for a port that is now powered. A classification that completes between theDETEVN_CORread and the PWRPB write in the ISR would have the same effect.
Quoted 3 lines
Could this leak the first budget allocation and shut off lower-priority ports for no reason? It depends on whether the chip raises a new class event for an unchanged result while MCONF.detchg is set.
It sounds to me, based off this analysis, the problem should be fixed in the core, not this driver.
Quoted 12 lines
Quoted 12 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+ } + +done: +return ltc4266_enable_interrupts (ltc4266); + +err: +/* (Attempt to) clear any remaining event registers that we might've +* missed in the event a previous read has failed. +*/ + ret =regmap_write (ltc4266->regmap,LTC4266_REG_RSTPB ,LTC4266_RSTPB_INTCLR ); +if (ret)
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c line 1211
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+dev_warn (<c4266->client->dev,"Failed to clear pending interrupts, err=%d\n" , + ret); + +return ltc4266_enable_interrupts (ltc4266); +}[Severity: Medium]
Can this error path lose hardware events?
Yes, seems like if there's a transient I2C error reading one of the event registers, the remaining will get lost.
Quoted 8 lines
PWREVN_COR,FLTEVN_COR,TSEVN_CORandDETEVN_CORclear on read. When a later read fails, the latches read before it (for example a tCUT bit in fltevn or a PG-lost bit in pwrevn) have already been cleared, and their values are thrown away.The
RSTPB_INTCLRwrite then clears the latched events on every channel, including ones that were never read.ltc4266_enable_interrupts()normally returns 0, sopse_isr()sees success with an empty mask and does nothing.
The intent here with the INTCLR bit was to avoid a interrupt storm if the I2C bus is in a more permanent failure state and we're not able to clear all the event registers. It's easy enough to test the "persistent failure" case on an I2C bus, but a transient (i.e. a single) I2C failure is harder for me to test. I'll think on this and come up with something that balances the two extremes.
Quoted 39 lines
The reverse case is also a problem. If the INTMASK write in
ltc4266_enable_interrupts()fails after decoding,pse_isr()throws away the notifications because of the nonzero return:drivers/net/pse-pd/pse_core.c:pse_isr() { ... ret = desc->map_event(irq, pcdev, h->notifs, h->notifs_mask); if (ret || bitmap_empty(h->notifs_mask, pcdev->nr_lines)) { mutex_unlock(&pcdev->lock); return IRQ_NONE; ... }INTMASK also stays at 0 from the
ltc4266_disable_interrupts()call at entry, so no further interrupts would arrive.With detchg set, a lost classification is not raised again. A lost fault or PG-loss leaves the core thinking the port is delivering, with its budget still allocated.
Is there any way for the driver to resync after one I2C error in the IRQ thread?
drivers/net/pse-pd/ltc4266.c line 1217
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ +static const struct regmap_config ltc4266_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .max_register =0x5F , +};[Severity: Low]
Should aprecious_regcallback mark the clear-on-read event registers (0x03,0x05,0x07,0x09,0x0B) as precious? Without it, a regmap debugfs registers dump reads them and clears pending detect, class and fault latches before the IRQ handler sees them. Areadable_regcallback would also stop the dump from reading the reserved addresses in the gaps of the register map.
Quoted 9 lines
[ ... ]
drivers/net/pse-pd/ltc4266.c line 1328
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ ltc4266->pcdev.owner =THIS_MODULE ; + ltc4266->pcdev.ops = <c4266_ops; + ltc4266->pcdev.dev = &client->dev; + ltc4266->pcdev.types =ETHTOOL_PSE_C33 ; + ltc4266->pcdev.nr_lines =LTC4266_MAX_PORTS ; + ltc4266->pcdev.supp_budget_eval_strategies =PSE_BUDGET_EVAL_STRAT_STATIC ;
Ack, easy enough to add.
Quoted 28 lines
[Severity: High]
This isn't a bug introduced by this patch, but choosing the static budget strategy exposes a lock ordering problem that already exists in the PSE core.
pse_isr()holdspcdev->lockand ends up taking the supply regulator lock:
pse_isr()
pse_set_config_isr()_pse_pi_delivery_power_sw_pw_ctrl() pse_pi_allocate_pw_budget_static_prio() regulator_request_power_budget(pw_d->supply) regulator_lock(rdev)An admin enable running at the same time takes the locks in the opposite order:
regulator_enable(psec->ps)
regulator_lock_dependent()(PI rdev, then its supply rdev)_regulator_enable() pse_pi_is_enabled() / pse_pi_enable() mutex_lock(&pcdev->lock)Can a classification interrupt on one PI, racing with an admin enable of another PI on the same supply, deadlock both the IRQ thread and the ethtool task? The
ww_mutexscheme cannot break a cycle that includes the plainpcdev->lockmutex.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c line 1333
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+ + ret =devm_pse_controller_register (ltc4266->dev, <c4266->pcdev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to register PSE controller\n" );
Yes, this is a deadlock I've hit in my testing, and it's unclear to me why lockdep doesn't seem to catch it. This is another thing I'll fix separately but it'll take some time for me to get it figured out.
Quoted 3 lines
[Severity: High]
This is a pre-existing issue in the PSE core, but boards with more than one LTC4266 are likely to hit it.
Reading more below, it seems like any board with more than one PSE controller are likely to hit it assuming they're sharing a supply.
Quoted 14 lines
devm_pse_alloc_pw_d()allocates the power domain withdevm_kzalloc(pcdev->dev)and publishes it in the globalpse_pw_d_map.pse_register_pw_ds()then gives the same object to any other controller whose PI supply matches:drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() { ... if (regulator_is_equal(pw_d->supply, rdev->supply)) { present = true; pcdev->pi[i].pw_d = pw_d; ... }
Quoted 8 lines
Consider all PIs pointing at one shared supply, as in the binding example, or sharing the dummy regulator when vpwr-supply is omitted. Unbinding the first controller frees the memory through devres, but the xarray entry and the other controller's pointers remain.
Would the second controller's
pse_flush_pw_ds()then readpw_d->idand callkref_put_mutex()on freed memory? pse_isr()->pse_pw_d_is_sw_pw_control()would use the same dangling pointer.
Seems like it. Perhaps another pse-core fix.
Quoted 15 lines
[Severity: Medium]
This is a pre-existing issue, but the teardown order inpse_controller_unregister()looks unsafe:drivers/net/pse-pd/pse_core.c:pse_controller_unregister() { ... pse_flush_pw_ds(pcdev); pse_release_pis(pcdev); if (pcdev->irq) disable_irq(pcdev->irq); cancel_work_sync(&pcdev->ntf_work); ... }
Quoted 7 lines
pse_send_ntf_worker()takes a psec reference withpse_control_find_by_id()and drops it withpse_control_put(). If that is the last reference,__pse_control_release()reads psec->pcdev->pi[psec->id].admin_state_enabled afterpse_release_pis()has freed the array.Could the work be cancelled before the PI array is released?
Yeah, and it probably should be.
Quoted 4 lines
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927212929.593366-1-kyle.swenson%40est.tech
So just to summarize, for me mostly, I'll change several things in this driver:
- ltc4266_pi_get_pw_class() will return the raw class to match tps23881_pi_get_pw_class().
- ltc4266_pi_set_pw_limit() will set port->pw_limit first.
- I'll rework the error path in ltc4266_map_event() to balance clearing stuck event registers on a persistent I2C failure against not discarding events on a single transient one.
- The lltc,ltc4266.yaml binding will list pairsets as required under pse-pi.
- Mark the COR registers "precious."
But I'd contend the remaining fixes should be in the pse core, and I'll push a series for that before re-spinning this series on top:
- Unwind pse_pi array and the notification fifo allocation when pse_controller_register() fails after of_load_pse_pis(), instead of leaking them on probe failure.
- Return -EPROBE_DEFER from pse_register_pw_ds() when a PI's supply is described but has not registered yet.
- Fix the pse_power_domain use-after-free on unbind when multiple drivers share a supply and the first one unbinds.
- Stop the notification worker before releasing the PI array in pse_controller_unregister().
- Fix the try_module_get reference leak
- Fix the deadlock in the pse_core that can happen when PI enable races with map_event.
- Fix the possible double budget allocation in the PSE core.
Thanks for your credits, it's appreciated.
Cheers,
Kyle
pw-bot: cr
Kory Maincent
maintainerHello Kyle,
Quoted 99 lines · Kyle Swenson
Hello,
Quoted 91 lines · On Wed, Sep 30, 2026 at 09:31:02PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 6 (3) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] If a PI's vpwr-supply is described in DT but not yet registered when the LTC4266 probes,
ltc4266_pi_nominal_uv()carries on (warn plus…
- [Medium]ltc4266_pi_get_pw_class()reports the wrong power class to userspace.
- [Medium]ltc4266_pi_nominal_uv()swallows -EPROBE_DEFER fromof_regulator_get_optional().
- [Medium]ltc4266_map_event()loses hardware events on every error exit.
- [Medium]ltc4266_pi_set_pw_limit()treats every negativeltc4266_port_get_class()result as 'not classified', including…
- [Medium]ltc4266_map_event()reportsETHTOOL_C33_PSE_EVENT_CLASSIFICATIONwhenever the detevn high nibble…
- [Medium]ltc4266_pi_disable()is carried out byltc4266_port_init(), whose first write (RSTPB = BIT(chan)) removes power from the port.
- [Low] The LTC4266 binding sets maxItems: 1 for pse-pi 'pairsets' but does not list it as required, andpse-controller.yamlrequires only…
- [Low]ltc4266_regmap_configsets onlyreg_bits,val_bitsandmax_register(0x5F), with noprecious_regorreadable_regcallbacks.Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new driver makes it easy to hit.
- [High] This problem wasn't introduced by this patch, but the new driver opts into the affected path.
- [Medium] This problem wasn't introduced by this patch, but: whenops->setup_pi_matrix()fails,pse_controller_register()returns…
- [Medium] This problem wasn't introduced by this patch, but:pse_controller_unregister() calls pse_release_pis() (kfree(pcdev->pi))… - [Medium] This problem wasn't introduced by this patch, but: pse_control_get_internal() calls try_module_get(pcdev->owner) and…--
net: pse-pd: Add LTC4266 PSE controller driver
This commit adds a new I2C driver for the Linear Technology LTC4266 PoE PSE controller and hooks it into the PSE controller core. The driver runs the chip in semi-auto mode and maps PSE PIs to delivery channels from the device tree. It uses the chip interrupt together with the static power budget evaluation strategy.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +0
-0@@ -0,0 +1,1386 @@[ ... ]
drivers/net/pse-pd/ltc4266.c line 653
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+static int ltc4266_pi_disable (struct pse_controller_dev *pcdev,int id) +{ +struct ltc4266_port *port =ltc4266_pi_port (pcdev, id); + +/* Resetting the port (RSTPB, issued at the start of ltc4266_port_init) +* removes power, disables detection and classification, and clears the +* port's status register. Re-init the port so that detection and +* classification can happen again. +*/ +return ltc4266_port_init (port); +}[Severity: Medium]
What happens if one of the writes after the RSTPB reset inltc4266_port_init()fails?The first write in
ltc4266_port_init()has already removed power from the port. A later failure in the OPMD, HPEN, HPMD, TLIM, DISENA or DETPB write is still returned as a failed disable, and_pse_pi_disable()then skips the budget release:drivers/net/pse-pd/pse_core.c:_pse_pi_disable() { ... ret = ops->pi_disable(pcdev, id); if (ret) return ret; pse_pi_deallocate_pw_budget(&pcdev->pi[id]); ... }Quoted 4 lines
Would the core then keep budget allocated and
admin_state_enabledset for a port that has no power? DETPB was never written, so detection stays off. No later classification interrupt would arrive to resync the state.
Quoted 8 lines
Yes, it appears the TPS23881 driver has this issue as well. I can see the contract go in one of two directions: drivers only return non-zero if the port wasn't able to be disabled enough to give back power budget or the core's
_pse_pi_disableshould always free the budget after callingpi_disableand then return the error at the end of the_pse_pi_disable.Kory, Oleksij, what are your thoughts?
Mmh that's indeed a policy we need to decide.
My first thought was in favor of always freeing the budget with a warning message. But after a second though we need to decide what is the harmless. Deallocating the budget while the PI is still power on could lead to an hardware over budget which mean there could be smoke. So I think the first option is the safer. It would be good to add kdoc and a warning to explain this.
Quoted 26 lines
Quoted 26 lines
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_get_admin_state (struct pse_controller_dev *pcdev,int id, +struct pse_admin_state *admin_state) +{[ ... ]
drivers/net/pse-pd/ltc4266.c line 679
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+ ret =regmap_read (port->ltc4266->regmap,LTC4266_REG_STATPWR , &val); +if (ret <0 ) +return ret;[Severity: Medium]
This isn't a bug introduced by this patch, but an I2C error returned here reaches a module reference leak that already exists in the PSE core.pse_control_get_internal()callstry_module_get(pcdev->owner)and then does this:drivers/net/pse-pd/pse_core.c:pse_control_get_internal() { ... ret = pse_pi_is_hw_enabled(pcdev, index); if (ret < 0) goto free_psec; ... }
Quoted 8 lines
Quoted 3 lines
That jump skips the
put_modulelabel. If an I2C error happens while a PHY is acquiring its PSE control, does the ltc4266 module stay pinned?Sure seems like it. It appears like it'd also stay pinned in a few of the other goto
free_psec; statements after thetry_module_get. I'll plan on pushing a separate patch with an appropriate Fixes: tag later, since I'm hesitant to mix it in with a v4 of this series.
If there are fixes to be sent please send them standalone to net and with the fixes tag.
Quoted 31 lines
Quoted 31 lines
[Severity: High]
Continuing with a deferred vpwr-supply also has a functional effect. Can the PI end up with no PSE power domain for good?If the supply is not registered yet,
regulator_resolve_supply()returns -EPROBE_DEFER andregulator_register()leavesrdev->supplyNULL for the PI regulator.pse_register_pw_ds()runs only once, frompse_controller_register():drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() { ... if (!rdev || !rdev->supply) continue; ... }So
pi->pw_dstays NULL even after the supply resolves, andpse_pw_d_is_sw_pw_control()returns false for this PI. Two things follow.First,
pse_isr()never callspse_set_config_isr(). The CLASSIFICATION and DISCONNECTION events fromltc4266_map_event()then never power the port or re-arm it.Second, on admin enable
pse_pi_enable()callsltc4266_pi_enable()directly. That fails inltc4266_port_get_class()with-EINVALor-EAGAINwhen no PD has been classified.The chip runs in semi-auto mode and never powers a port without a PWRPB write. Would a PD that is plugged in later stay unpowered until the driver is rebound?
Quoted 7 lines
Quoted 4 lines
This only affects a supply that is described but deferred. When vpwr-supply is missing entirely, the dummy regulator is used and a power domain is still created.
This seems correct to me, and I'm pretty sure the cleanest option is to fix the pse-core.
It seems there are still several flaws in the PSE core.
If you have the time, please fix them, but tell me if you don't. I will tackle them.
Quoted 35 lines
Quoted 28 lines
[Severity: High]
This isn't a bug introduced by this patch, but choosing the static budget strategy exposes a lock ordering problem that already exists in the PSE core.
pse_isr()holdspcdev->lockand ends up taking the supply regulator lock:
pse_isr()
pse_set_config_isr()_pse_pi_delivery_power_sw_pw_ctrl() pse_pi_allocate_pw_budget_static_prio() regulator_request_power_budget(pw_d->supply) regulator_lock(rdev)An admin enable running at the same time takes the locks in the opposite order:
regulator_enable(psec->ps)
regulator_lock_dependent()(PI rdev, then its supply rdev)_regulator_enable() pse_pi_is_enabled() / pse_pi_enable() mutex_lock(&pcdev->lock)Can a classification interrupt on one PI, racing with an admin enable of another PI on the same supply, deadlock both the IRQ thread and the ethtool task? The
ww_mutexscheme cannot break a cycle that includes the plainpcdev->lockmutex.Quoted 6 lines
drivers/net/pse-pd/ltc4266.c line 1333
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+ + ret =devm_pse_controller_register (ltc4266->dev, <c4266->pcdev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to register PSE controller\n" );
Quoted 3 lines
Yes, this is a deadlock I've hit in my testing, and it's unclear to me why lockdep doesn't seem to catch it. This is another thing I'll fix separately but it'll take some time for me to get it figured out.
Meh there is still a lock issue, again related to the regulator lock. It's painful.
Quoted 40 lines
Quoted 2 lines
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927212929.593366-1-kyle.swenson%40est.techSo just to summarize, for me mostly, I'll change several things in this driver:
-
ltc4266_pi_get_pw_class()will return the raw class to matchtps23881_pi_get_pw_class().
-ltc4266_pi_set_pw_limit()will setport->pw_limitfirst.
- I'll rework the error path inltc4266_map_event()to balance clearing stuck event registers on a persistent I2C failure against not discarding events on a single transient one.
- The lltc,ltc4266.yaml binding will list pairsets as required under pse-pi.
- Mark the COR registers "precious."But I'd contend the remaining fixes should be in the pse core, and I'll push a series for that before re-spinning this series on top:
- Unwind
pse_piarray and the notification fifo allocation whenpse_controller_register()fails afterof_load_pse_pis(), instead of leaking them on probe failure.
- Return -EPROBE_DEFER frompse_register_pw_ds()when a PI's supply is described but has not registered yet.
- Fix thepse_power_domainuse-after-free on unbind when multiple drivers share a supply and the first one unbinds.
- Stop the notification worker before releasing the PI array inpse_controller_unregister().
- Fix thetry_module_getreference leak
- Fix the deadlock in thepse_corethat can happen when PI enable races withmap_event.
- Fix the possible double budget allocation in the PSE core.Thanks for your credits, it's appreciated.
Cheers,
Kylepw-bot: cr
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Hello Kory,
Quoted 111 lines · Kory Maincent
Hello Kyle,
Quoted 99 lines · Kyle Swenson
Hello,
Quoted 91 lines · On Wed, Sep 30, 2026 at 09:31:02PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 9 potential issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 6 (3) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] If a PI's vpwr-supply is described in DT but not yet registered when the LTC4266 probes,
ltc4266_pi_nominal_uv()carries on (warn plus…
- [Medium]ltc4266_pi_get_pw_class()reports the wrong power class to userspace.
- [Medium]ltc4266_pi_nominal_uv()swallows -EPROBE_DEFER fromof_regulator_get_optional().
- [Medium]ltc4266_map_event()loses hardware events on every error exit.
- [Medium]ltc4266_pi_set_pw_limit()treats every negativeltc4266_port_get_class()result as 'not classified', including…
- [Medium]ltc4266_map_event()reportsETHTOOL_C33_PSE_EVENT_CLASSIFICATIONwhenever the detevn high nibble…
- [Medium]ltc4266_pi_disable()is carried out byltc4266_port_init(), whose first write (RSTPB = BIT(chan)) removes power from the port.
- [Low] The LTC4266 binding sets maxItems: 1 for pse-pi 'pairsets' but does not list it as required, andpse-controller.yamlrequires only…
- [Low]ltc4266_regmap_configsets onlyreg_bits,val_bitsandmax_register(0x5F), with noprecious_regorreadable_regcallbacks.Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new driver makes it easy to hit.
- [High] This problem wasn't introduced by this patch, but the new driver opts into the affected path.
- [Medium] This problem wasn't introduced by this patch, but: whenops->setup_pi_matrix()fails,pse_controller_register()returns…
- [Medium] This problem wasn't introduced by this patch, but:pse_controller_unregister() calls pse_release_pis() (kfree(pcdev->pi))… - [Medium] This problem wasn't introduced by this patch, but: pse_control_get_internal() calls try_module_get(pcdev->owner) and…--
net: pse-pd: Add LTC4266 PSE controller driver
This commit adds a new I2C driver for the Linear Technology LTC4266 PoE PSE controller and hooks it into the PSE controller core. The driver runs the chip in semi-auto mode and maps PSE PIs to delivery channels from the device tree. It uses the chip interrupt together with the static power budget evaluation strategy.
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +0
-0@@ -0,0 +1,1386 @@[ ... ]
drivers/net/pse-pd/ltc4266.c line 653
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+static int ltc4266_pi_disable (struct pse_controller_dev *pcdev,int id) +{ +struct ltc4266_port *port =ltc4266_pi_port (pcdev, id); + +/* Resetting the port (RSTPB, issued at the start of ltc4266_port_init) +* removes power, disables detection and classification, and clears the +* port's status register. Re-init the port so that detection and +* classification can happen again. +*/ +return ltc4266_port_init (port); +}[Severity: Medium]
What happens if one of the writes after the RSTPB reset inltc4266_port_init()fails?The first write in
ltc4266_port_init()has already removed power from the port. A later failure in the OPMD, HPEN, HPMD, TLIM, DISENA or DETPB write is still returned as a failed disable, and_pse_pi_disable()then skips the budget release:drivers/net/pse-pd/pse_core.c:_pse_pi_disable() { ... ret = ops->pi_disable(pcdev, id); if (ret) return ret; pse_pi_deallocate_pw_budget(&pcdev->pi[id]); ... }Quoted 4 lines
Would the core then keep budget allocated and
admin_state_enabledset for a port that has no power? DETPB was never written, so detection stays off. No later classification interrupt would arrive to resync the state.Quoted 8 lines
Yes, it appears the TPS23881 driver has this issue as well. I can see the contract go in one of two directions: drivers only return non-zero if the port wasn't able to be disabled enough to give back power budget or the core's
_pse_pi_disableshould always free the budget after callingpi_disableand then return the error at the end of the_pse_pi_disable.Kory, Oleksij, what are your thoughts?
Quoted 8 lines
Mmh that's indeed a policy we need to decide.
My first thought was in favor of always freeing the budget with a warning message. But after a second though we need to decide what is the harmless. Deallocating the budget while the PI is still power on could lead to an hardware over budget which mean there could be smoke.
So I think the first option is the safer. It would be good to add kdoc and a warning to explain this.
Yeah, I agree the first option is probably safest- PSE drivers should return non-zero if they are unable to disable the port to the point it no longer powers a device and in that case the pse_core will not free up the budget. If a driver encounters an error after the point the PI is disabled (for example, this driver's port_init phase), the driver callback will still return 0 but maybe should emit a warning message since (depending on the error) the port won't be able to re-power devices later.
Let me know if I misunderstood, and I'll wait a bit before posting this fix to give other people a chance to think about it and comment.
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
[ ... ]
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+static int ltc4266_pi_get_admin_state (struct pse_controller_dev *pcdev,int id, +struct pse_admin_state *admin_state) +{[ ... ]
drivers/net/pse-pd/ltc4266.c line 679
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+ ret =regmap_read (port->ltc4266->regmap,LTC4266_REG_STATPWR , &val); +if (ret <0 ) +return ret;[Severity: Medium]
This isn't a bug introduced by this patch, but an I2C error returned here reaches a module reference leak that already exists in the PSE core.pse_control_get_internal()callstry_module_get(pcdev->owner)and then does this:drivers/net/pse-pd/pse_core.c:pse_control_get_internal() { ... ret = pse_pi_is_hw_enabled(pcdev, index); if (ret < 0) goto free_psec; ... }That jump skips the
put_modulelabel. If an I2C error happens while a PHY is acquiring its PSE control, does the ltc4266 module stay pinned?
Quoted 7 lines
Quoted 4 lines
Sure seems like it. It appears like it'd also stay pinned in a few of the other goto
free_psec; statements after thetry_module_get. I'll plan on pushing a separate patch with an appropriate Fixes: tag later, since I'm hesitant to mix it in with a v4 of this series.If there are fixes to be sent please send them standalone to net and with the fixes tag.
Yep, will do.
Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
[Severity: High]
Continuing with a deferred vpwr-supply also has a functional effect. Can the PI end up with no PSE power domain for good?If the supply is not registered yet,
regulator_resolve_supply()returns -EPROBE_DEFER andregulator_register()leavesrdev->supplyNULL for the PI regulator.pse_register_pw_ds()runs only once, frompse_controller_register():drivers/net/pse-pd/pse_core.c:pse_register_pw_ds() { ... if (!rdev || !rdev->supply) continue; ... }So
pi->pw_dstays NULL even after the supply resolves, andpse_pw_d_is_sw_pw_control()returns false for this PI. Two things follow.First,
pse_isr()never callspse_set_config_isr(). The CLASSIFICATION and DISCONNECTION events fromltc4266_map_event()then never power the port or re-arm it.Second, on admin enable
pse_pi_enable()callsltc4266_pi_enable()directly. That fails inltc4266_port_get_class()with-EINVALor-EAGAINwhen no PD has been classified.The chip runs in semi-auto mode and never powers a port without a PWRPB write. Would a PD that is plugged in later stay unpowered until the driver is rebound?
This only affects a supply that is described but deferred. When vpwr-supply is missing entirely, the dummy regulator is used and a power domain is still created.
Quoted 6 lines
Quoted 2 lines
This seems correct to me, and I'm pretty sure the cleanest option is to fix the pse-core.
It seems there are still several flaws in the PSE core.
If you have the time, please fix them, but tell me if you don't. I will tackle them.
I'll make time to fix them, and I'll let you know if I'm running out time or won't get to some of them. I've got a few of the fixes locally, just need to get them through my testing and internal review.
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
[Severity: High]
This isn't a bug introduced by this patch, but choosing the static budget strategy exposes a lock ordering problem that already exists in the PSE core.
pse_isr()holdspcdev->lockand ends up taking the supply regulator lock:
pse_isr()
pse_set_config_isr()_pse_pi_delivery_power_sw_pw_ctrl() pse_pi_allocate_pw_budget_static_prio() regulator_request_power_budget(pw_d->supply) regulator_lock(rdev)An admin enable running at the same time takes the locks in the opposite order:
regulator_enable(psec->ps)
regulator_lock_dependent()(PI rdev, then its supply rdev)_regulator_enable() pse_pi_is_enabled() / pse_pi_enable() mutex_lock(&pcdev->lock)Can a classification interrupt on one PI, racing with an admin enable of another PI on the same supply, deadlock both the IRQ thread and the ethtool task? The
ww_mutexscheme cannot break a cycle that includes the plainpcdev->lockmutex.Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+ + ret =devm_pse_controller_register (ltc4266->dev, <c4266->pcdev); +if (ret) +return dev_err_probe (&client->dev, ret, +"Failed to register PSE controller\n" );
Quoted 6 lines
Quoted 3 lines
Yes, this is a deadlock I've hit in my testing, and it's unclear to me why lockdep doesn't seem to catch it. This is another thing I'll fix separately but it'll take some time for me to get it figured out.
Meh there is still a lock issue, again related to the regulator lock. It's painful.
Painful indeed. I'll work though it and post RFC for the lock change when I've got something that's worth sharing. If you've got ideas already on how to fix it, I'm all ears.
[...]
Quoted 4 lines
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Thanks,
Kyle