public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 2/7] net: phy: introduce fixed_phy_create for DSA CPU ports
Date: Mon, 25 Jan 2021 14:23:52 +0200	[thread overview]
Message-ID: <20210125122357.414742-3-olteanv@gmail.com> (raw)
In-Reply-To: <20210125122357.414742-1-olteanv@gmail.com>

From: Vladimir Oltean <vladimir.oltean@nxp.com>

The DSA (Distributed Switch Architecture) implementation has made a
design decision when it got introduced to the Linux kernel in 2008.
That was to hide away from the user the CPU-facing Ethernet MAC, since
it does not make sense to register it as a struct net_device (UCLASS_ETH
udevice for U-Boot), because that would never be beneficial for a user:
they would not be able to use it for traffic, since conceptually, a
packet delivered to the CPU port should loop back into the system.

Nonetheless, DSA has had numerous growing pains due to the lack of a
struct net_device for the CPU port, but so far it has overcome them.
It is unlikely at this stage of maturity that this aspect of it will
change.

We would like U-Boot to present the same information as Linux, to be at
parity in terms of number of interfaces, so that ethNaddr environment
variables could directly be associated between U-Boot and Linux.
Therefore, we would implicitly like U-Boot to hide the CPU port from the
user as well.

But the paradox is that DSA still needs a struct phy_device to inform
the driver of the parameters of the link that it should configure the
CPU port to. The problem is that the phy_device is typically returned
via a call to phy_connect, which needs an udevice to attach the PHY to,
and to search its ofnode for the 'fixed-link' property. But we don't
have an udevice to present for the CPU port.

Since 99% of DSA setups are MAC-to-MAC connections between the switch
and the host Ethernet controller, the struct phy_device is going to be a
fixed PHY. This simplifies things quite a bit. In U-Boot, a fixed PHY
does not need an MDIO bus, and does not need an attached dev either.
Basically, the phy_connect call doesn't do any connection, it just
creates the fixed PHY.

The proposal of this patch is to introduce a new fixed_phy_create
function which will take a single argument: the ofnode that holds this:

	port at 4 {
		reg = <4>;
		phy-mode = "internal";

		fixed-link {
			speed = <2500>;
			full-duplex;
		};
	};

and probe a fixed PHY driver using the information from this ofnode.
DSA will probably be the only user of this function.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
Changes in v4:
Patch is new.

 drivers/net/phy/phy.c | 31 +++++++++++++++++++++++++++++++
 include/phy.h         | 21 +++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 9587e6b9fae4..849ad0487de4 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -973,6 +973,37 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
 #endif
 
 #ifdef CONFIG_PHY_FIXED
+/**
+ * fixed_phy_create() - create an unconnected fixed-link pseudo-PHY device
+ * @node: OF node for the container of the fixed-link node
+ *
+ * Description: Creates a struct phy_device based on a fixed-link of_node
+ * description. Can be used without phy_connect by drivers which do not expose
+ * a UCLASS_ETH udevice.
+ */
+struct phy_device *fixed_phy_create(ofnode node)
+{
+	phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
+	const char *if_str;
+	ofnode subnode;
+
+	if_str = ofnode_read_string(node, "phy-mode");
+	if (!if_str) {
+		if_str = ofnode_read_string(node, "phy-interface-type");
+	}
+	if (if_str) {
+		interface = phy_get_interface_by_name(if_str);
+	}
+
+	subnode = ofnode_find_subnode(node, "fixed-link");
+	if (!ofnode_valid(subnode)) {
+		return NULL;
+	}
+
+	return phy_device_create(NULL, ofnode_to_offset(subnode), PHY_FIXED_ID,
+				 false, interface);
+}
+
 #ifdef CONFIG_DM_ETH
 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
 					    struct udevice *dev,
diff --git a/include/phy.h b/include/phy.h
index cbdb10d6fced..633c1e492fc9 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -402,6 +402,27 @@ int phy_reset(struct phy_device *phydev);
 struct phy_device *phy_find_by_mask(struct mii_dev *bus, unsigned phy_mask,
 		phy_interface_t interface);
 
+#ifdef CONFIG_PHY_FIXED
+
+/**
+ * fixed_phy_create() - create an unconnected fixed-link pseudo-PHY device
+ * @node: OF node for the container of the fixed-link node
+ *
+ * Description: Creates a struct phy_device based on a fixed-link of_node
+ * description. Can be used without phy_connect by drivers which do not expose
+ * a UCLASS_ETH udevice.
+ */
+struct phy_device *fixed_phy_create(ofnode node);
+
+#else
+
+static inline struct phy_device *fixed_phy_create(ofnode node)
+{
+	return NULL;
+}
+
+#endif
+
 #ifdef CONFIG_DM_ETH
 
 /**
-- 
2.25.1

  parent reply	other threads:[~2021-01-25 12:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 12:23 [PATCH v4 0/7] Introduce DSA Ethernet switch class and Felix driver Vladimir Oltean
2021-01-25 12:23 ` [PATCH v4 1/7] net: phy: fixed: support speeds of 2500 and 10000 Vladimir Oltean
2021-01-27  8:04   ` Claudiu Manoil
2021-02-16 21:55   ` Tom Rini
2021-01-25 12:23 ` Vladimir Oltean [this message]
2021-01-27  8:05   ` [PATCH v4 2/7] net: phy: introduce fixed_phy_create for DSA CPU ports Claudiu Manoil
2021-02-16 21:55   ` Tom Rini
2021-01-25 12:23 ` [PATCH v4 3/7] net: Introduce DSA class for Ethernet switches Vladimir Oltean
2021-02-16 21:55   ` Tom Rini
2021-01-25 12:23 ` [PATCH v4 4/7] sandbox: Add a DSA sandbox driver and unit test Vladimir Oltean
2021-02-16 18:14   ` Tom Rini
2021-02-16 21:02     ` Vladimir Oltean
2021-02-16 21:13       ` Tom Rini
2021-02-16 21:21         ` Vladimir Oltean
2021-02-16 21:33           ` Michael Walle
2021-02-16 21:38             ` Tom Rini
2021-02-16 21:53               ` Vladimir Oltean
2021-02-16 21:55                 ` Tom Rini
2021-02-16 21:58               ` Michael Walle
2021-02-16 22:15                 ` Michael Walle
2021-02-16 22:23                   ` Vladimir Oltean
2021-01-25 12:23 ` [PATCH v4 5/7] drivers: net: Add Felix DSA switch driver Vladimir Oltean
2021-02-16 21:55   ` Tom Rini
2021-01-25 12:23 ` [PATCH v4 6/7] arm: dts: ls1028a: Add Ethernet switch node and dependencies Vladimir Oltean
2021-01-25 12:33   ` Michael Walle
2021-02-16 21:56   ` Tom Rini
2021-01-25 12:23 ` [PATCH v4 7/7] configs: ls1028a: Enable the Ethernet switch driver in defconfig Vladimir Oltean
2021-02-16 21:56   ` Tom Rini
2021-01-25 13:02 ` [PATCH v4 0/7] Introduce DSA Ethernet switch class and Felix driver Michael Walle
2021-01-25 13:04   ` Vladimir Oltean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210125122357.414742-3-olteanv@gmail.com \
    --to=olteanv@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox