[PATCH net-next v6 03/14] net: phy: Introduce PHY ports representation
Kory Maincent
kory.maincent at bootlin.com
Tue May 13 06:53:25 PDT 2025
On Wed, 7 May 2025 15:53:19 +0200
Maxime Chevallier <maxime.chevallier at bootlin.com> wrote:
> Ethernet provides a wide variety of layer 1 protocols and standards for
> data transmission. The front-facing ports of an interface have their own
> complexity and configurability.
>
> Introduce a representation of these front-facing ports. The current code
> is minimalistic and only support ports controlled by PHY devices, but
> the plan is to extend that to SFP as well as raw Ethernet MACs that
> don't use PHY devices.
>
> This minimal port representation allows describing the media and number
> of lanes of a port. From that information, we can derive the linkmodes
> usable on the port, which can be used to limit the capabilities of an
> interface.
>
> For now, the port lanes and medium is derived from devicetree, defined
> by the PHY driver, or populated with default values (as we assume that
> all PHYs expose at least one port).
>
> The typical example is 100M ethernet. 100BaseT can work using only 2
> lanes on a Cat 5 cables. However, in the situation where a 10/100/1000
> capable PHY is wired to its RJ45 port through 2 lanes only, we have no
> way of detecting that. The "max-speed" DT property can be used, but a
> more accurate representation can be used :
>
> mdi {
> connector-0 {
> media = "BaseT";
> lanes = <2>;
> };
> };
>
> From that information, we can derive the max speed reachable on the
> port.
>
> Another benefit of having that is to avoid vendor-specific DT properties
> (micrel,fiber-mode or ti,fiber-mode).
>
> This basic representation is meant to be expanded, by the introduction
> of port ops, userspace listing of ports, and support for multi-port
> devices.
>
> Signed-off-by: Maxime Chevallier <maxime.chevallier at bootlin.com>
...
> + for_each_available_child_of_node_scoped(mdi, port_node) {
> + port = phy_of_parse_port(port_node);
> + if (IS_ERR(port)) {
> + err = PTR_ERR(port);
> + goto out_err;
> + }
> +
> + port->parent_type = PHY_PORT_PHY;
> + port->phy = phydev;
> + err = phy_add_port(phydev, port);
> + if (err)
> + goto out_err;
I think of_node_put(port_node) is missing here.
...
> @@ -1968,6 +1997,7 @@ void phy_trigger_machine(struct phy_device *phydev);
> void phy_mac_interrupt(struct phy_device *phydev);
> void phy_start_machine(struct phy_device *phydev);
> void phy_stop_machine(struct phy_device *phydev);
> +
New empty line here?
> +/**
> + * struct phy_port - A representation of a network device physical interface
> + *
> + * @head: Used by the port's parent to list ports
> + * @parent_type: The type of device this port is directly connected to
> + * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port
> + * @ops: Callback ops implemented by the port controller
> + * @lanes: The number of lanes (diff pairs) this port has, 0 if not
> applicable
> + * @mediums: Bitmask of the physical mediums this port provides access to
> + * @supported: The link modes this port can expose, if this port is MDI (not
> MII)
> + * @interfaces: The MII interfaces this port supports, if this port is MII
> + * @active: Indicates if the port is currently part of the active link.
> + * @is_serdes: Indicates if this port is Serialised MII (Media Independent
> + * Interface), or an MDI (Media Dependent Interface).
> + */
> +struct phy_port {
> + struct list_head head;
> + enum phy_port_parent parent_type;
> + union {
> + struct phy_device *phy;
> + };
The union is useless here?
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
More information about the linux-arm-kernel
mailing list