
QEMU ppce500 machine can dynamically instantiate an eTSEC device if "-device eTSEC" is given to QEMU.
This series updates the fixed-link ethernet PHY driver as well as the Freescale eTSEC driver to support the QEMU ppce500 board.
3 patches related to fixed phy in v1 are dropped in v2 as the changes were done by Vladimir's fixed phy & Sandbox DSA series [1]. Vladimir's series is now included in v2, and updated as needed.
This cover letter is cc'ed to QEMU mailing list for a heads-up. A future patch will be sent to QEMU mailing list to bring its in-tree U-Boot source codes up-to-date.
This series is avaiable at u-boot-x86/eTSEC for testing.
[1] https://patchwork.ozlabs.org/project/uboot/patch/20210216224804.3355044-2-ol...
Changes in v2: - move device tree parsing from xilinxgmiitorgmii_probe() to xilinxgmiitorgmii_config() and use OF APIs - new patch: split from 20210216224804.3355044-4-olteanv@gmail.com - include <asm/global_data.h> - use a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE to control the new behavior for boards that want this - default y if SANDBOX for CONFIG_SIMPLE_BUS_CORRECT_RANGE - turn on CONFIG_SIMPLE_BUS_CORRECT_RANGE in qemu-ppce500_defconfig
Bin Meng (17): dt-bindings: net: Add the old DT bindings for "fixed-link" of: extra: Introduce ofnode_phy_is_fixed_link() API test: dm: Add a case to test ofnode_phy_is_fixed_link() dm: mdio: Use ofnode_phy_is_fixed_link() API net: phy: xilinx: Be compatible with live OF tree net: phy: xilinx: Drop #ifdef CONFIG_DM_ETH around phy_connect_gmii2rgmii() net: phy: Simplify the logic of phy_connect_fixed() net: phy: fixed: Make driver ops static net: phy: fixed: Add the missing ending newline net: phy: fixed: Support the old DT binding dt-bindings: net: Update Freescale TSEC to support "queue-group" net: tsec: Support <reg> property from the subnode "queue-group" dm: core: Correctly read <ranges> of simple-bus test: dm: Add a test case for simple-bus <ranges> ppc: qemu: Create a virtual memory mapping of the platform bus ppc: qemu: Enable eTSEC support doc: board: qemu-ppce500: Document eTSEC usage
Claudiu Manoil (1): sandbox: Add a DSA sandbox driver and unit test
Vladimir Oltean (3): net: phy: fixed: Be compatible with live OF tree net: phy: fixed: Drop #ifdef CONFIG_DM_ETH around phy_connect_fixed net: tsec: Use dm_eth_phy_connect() directly for the DM case
arch/Kconfig | 2 + arch/sandbox/dts/test.dts | 59 ++++++ board/emulation/qemu-ppce500/Kconfig | 6 + board/emulation/qemu-ppce500/qemu-ppce500.c | 18 ++ configs/qemu-ppce500_defconfig | 5 + doc/board/emulation/qemu-ppce500.rst | 5 + doc/device-tree-bindings/net/fixed-link.txt | 47 +++-- doc/device-tree-bindings/net/fsl-tsec-phy.txt | 15 +- drivers/core/Kconfig | 14 ++ drivers/core/of_extra.c | 26 +++ drivers/core/simple-bus.c | 32 +++- drivers/net/Kconfig | 9 + drivers/net/Makefile | 1 + drivers/net/dsa_sandbox.c | 179 ++++++++++++++++++ drivers/net/phy/Kconfig | 1 + drivers/net/phy/fixed.c | 54 ++++-- drivers/net/phy/phy.c | 63 +++--- drivers/net/phy/xilinx_gmii2rgmii.c | 61 +++--- drivers/net/tsec.c | 32 +++- include/configs/sandbox.h | 2 + include/dm/of_extra.h | 18 ++ include/dm/simple_bus.h | 6 +- net/mdio-uclass.c | 7 +- test/dm/Makefile | 2 + test/dm/dsa.c | 82 ++++++++ test/dm/eth.c | 10 +- test/dm/of_extra.c | 18 ++ test/dm/simple-bus.c | 33 ++++ 28 files changed, 687 insertions(+), 120 deletions(-) create mode 100644 drivers/net/dsa_sandbox.c create mode 100644 test/dm/dsa.c create mode 100644 test/dm/simple-bus.c

Per the upstream Linux kernel doc:
Documentation/devicetree/bindings/net/ethernet-controller.yaml
There are two ways to describe a fixed PHY attached to an Ethernet device. This updates our dt-bindings doc to add the old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
doc/device-tree-bindings/net/fixed-link.txt | 47 +++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/doc/device-tree-bindings/net/fixed-link.txt b/doc/device-tree-bindings/net/fixed-link.txt index 5829bd81a2..71ab480701 100644 --- a/doc/device-tree-bindings/net/fixed-link.txt +++ b/doc/device-tree-bindings/net/fixed-link.txt @@ -5,21 +5,36 @@ Some Ethernet MACs have a "fixed link", and are not connected to a normal MDIO-managed PHY device. For those situations, a Device Tree binding allows to describe a "fixed link".
-Such a fixed link situation is described by creating a 'fixed-link' -sub-node of the Ethernet MAC device node, with the following -properties: - -* 'speed' (integer, mandatory), to indicate the link speed. Accepted - values are 10, 100 and 1000 -* 'full-duplex' (boolean, optional), to indicate that full duplex is - used. When absent, half duplex is assumed. -* 'pause' (boolean, optional), to indicate that pause should be - enabled. -* 'asym-pause' (boolean, optional), to indicate that asym_pause should - be enabled. +Note there are two ways to describe a fixed PHY attached to an +Ethernet device: + +- The new DT binding, where 'fixed-link' is a sub-node of the Ethernet + MAC device node, with the following properties: + + * 'speed' (integer, mandatory), to indicate the link speed. Accepted + values are 10, 100 and 1000 + * 'full-duplex' (boolean, optional), to indicate that full duplex is + used. When absent, half duplex is assumed. + * 'pause' (boolean, optional), to indicate that pause should be + enabled. + * 'asym-pause' (boolean, optional), to indicate that asym_pause should + be enabled. + +- The old DT binding, where 'fixed-link' is a property with 5 cells + encoding various information about the fixed PHY, in the form of + <phy_id, full-duplex, speed, pause, asym-pause>. + + * 'phy_id', emulated PHY ID, choose any but unique to the all specified + fixed-links + * 'full-duplex', 0 for half duplex or 1 for full duplex + * 'speed', link speed in Mbits/sec, accepts only 10, 100 and 1000 + * 'pause', 0 for no pause, 1 for pause + * 'asym-pause', 0 for no asymmetric pause, 1 for asymmetric pause
Examples:
+The new binding: + ethernet@0 { ... fixed-link { @@ -28,3 +43,11 @@ ethernet@0 { }; ... }; + +The old binding: + +ethernet@0 { + ... + fixed-link = <0 1 1000 0 0>; + ... +};

On Fri, Mar 12, 2021 at 09:35:42PM +0800, Bin Meng wrote:
Per the upstream Linux kernel doc:
Documentation/devicetree/bindings/net/ethernet-controller.yaml
There are two ways to describe a fixed PHY attached to an Ethernet device. This updates our dt-bindings doc to add the old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Why? Do we even parse the old-style bindings? And if so, where?

On Fri, Mar 12, 2021 at 09:35:42PM +0800, Bin Meng wrote:
+- The old DT binding, where 'fixed-link' is a property with 5 cells
- encoding various information about the fixed PHY, in the form of
- <phy_id, full-duplex, speed, pause, asym-pause>.
- 'phy_id', emulated PHY ID, choose any but unique to the all specified
- fixed-links
Could you please explicitly state that U-Boot deliberately ignores the phy_id and unconditionally uses PHY_FIXED_ID? It would be suicidal to do anything else (and I see Linux ignores fixed_link_prop[0] too), but at least we should be upfront about it.
- 'full-duplex', 0 for half duplex or 1 for full duplex
- 'speed', link speed in Mbits/sec, accepts only 10, 100 and 1000
- 'pause', 0 for no pause, 1 for pause
- 'asym-pause', 0 for no asymmetric pause, 1 for asymmetric pause
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

Introduce a helper API ofnode_phy_is_fixed_link() to detect whether the ethernet controller connects to a fixed-link pseudo-PHY device.
Note there are two ways to describe a fixed PHY attached to an Ethernet device:
- the new DT binding, where 'fixed-link' is a sub-node of the Ethernet device - the old DT binding, where 'fixed-link' is a property with 5 cells encoding various information about the fixed PHY
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org ---
(no changes since v1)
drivers/core/of_extra.c | 26 ++++++++++++++++++++++++++ include/dm/of_extra.h | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+)
diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c index 653344529e..a16f9a8dc1 100644 --- a/drivers/core/of_extra.c +++ b/drivers/core/of_extra.c @@ -130,3 +130,29 @@ int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
return 0; } + +bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node) +{ + bool found = false; + ofnode node, subnode; + int len; + + /* new binding */ + subnode = ofnode_find_subnode(eth_node, "fixed-link"); + if (ofnode_valid(subnode)) { + node = subnode; + found = true; + } + + /* old binding */ + if (ofnode_get_property(eth_node, "fixed-link", &len) && + len == (5 * sizeof(__be32))) { + node = eth_node; + found = true; + } + + if (found && phy_node) + *phy_node = node; + + return found; +} diff --git a/include/dm/of_extra.h b/include/dm/of_extra.h index ca15df21b0..3641f68fe3 100644 --- a/include/dm/of_extra.h +++ b/include/dm/of_extra.h @@ -86,4 +86,22 @@ int ofnode_decode_memory_region(ofnode config_node, const char *mem_type, const char *suffix, fdt_addr_t *basep, fdt_size_t *sizep);
+/** + * ofnode_phy_is_fixed_link() - Detect fixed-link pseudo-PHY device + * + * This function detects whether the ethernet controller connects to a + * fixed-link pseudo-PHY device. + * + * This function supports the following two DT bindings: + * - the new DT binding, where 'fixed-link' is a sub-node of the + * Ethernet device + * - the old DT binding, where 'fixed-link' is a property with 5 + * cells encoding various information about the fixed PHY + * + * @param eth_node ofnode containing the fixed-link subnode/property + * @param phy_node if fixed-link PHY detected, containing the PHY ofnode + * @return true if a fixed-link pseudo-PHY device exists, false otherwise + */ +bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node); + #endif

On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
Introduce a helper API ofnode_phy_is_fixed_link() to detect whether the ethernet controller connects to a fixed-link pseudo-PHY device.
Note there are two ways to describe a fixed PHY attached to an Ethernet device:
- the new DT binding, where 'fixed-link' is a sub-node of the Ethernet device
- the old DT binding, where 'fixed-link' is a property with 5 cells encoding various information about the fixed PHY
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
I ran a 'grep -r "ofnode_get_property.*fixed-link" .' and saw no in-tree users of the old binding. Why do we bother to be compatible with something which isn't used?

On Sat, Mar 13, 2021 at 02:14:36PM +0200, Vladimir Oltean wrote:
On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
Introduce a helper API ofnode_phy_is_fixed_link() to detect whether the ethernet controller connects to a fixed-link pseudo-PHY device.
Note there are two ways to describe a fixed PHY attached to an Ethernet device:
- the new DT binding, where 'fixed-link' is a sub-node of the Ethernet device
- the old DT binding, where 'fixed-link' is a property with 5 cells encoding various information about the fixed PHY
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
I ran a 'grep -r "ofnode_get_property.*fixed-link" .' and saw no in-tree users of the old binding. Why do we bother to be compatible with something which isn't used?
Ah, I see what's going on. QEMU fixes up the device tree here: https://github.com/qemu/qemu/blob/master/hw/ppc/e500.c#L239 and adds an old-style fixed-link binding. Can't you modify it to add a new-style fixed-link property? It's not like you didn't have to modify it for the "ranges" property too :) https://github.com/qemu/qemu/commit/e5943b00d35efc68ca72ed304cfca98a9f3a647c

Hi Vladimir,
On Sat, Mar 13, 2021 at 8:29 PM Vladimir Oltean olteanv@gmail.com wrote:
On Sat, Mar 13, 2021 at 02:14:36PM +0200, Vladimir Oltean wrote:
On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
Introduce a helper API ofnode_phy_is_fixed_link() to detect whether the ethernet controller connects to a fixed-link pseudo-PHY device.
Note there are two ways to describe a fixed PHY attached to an Ethernet device:
- the new DT binding, where 'fixed-link' is a sub-node of the Ethernet device
- the old DT binding, where 'fixed-link' is a property with 5 cells encoding various information about the fixed PHY
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
I ran a 'grep -r "ofnode_get_property.*fixed-link" .' and saw no in-tree users of the old binding. Why do we bother to be compatible with something which isn't used?
Ah, I see what's going on. QEMU fixes up the device tree here: https://github.com/qemu/qemu/blob/master/hw/ppc/e500.c#L239 and adds an old-style fixed-link binding. Can't you modify it to add a new-style fixed-link property?
I am afraid that may break guests that haven't supported new-style DT bindings yet.
It's not like you didn't have to modify it for the "ranges" property too :) https://github.com/qemu/qemu/commit/e5943b00d35efc68ca72ed304cfca98a9f3a647c
Regards, Bin

On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
+bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node) +{
- bool found = false;
- ofnode node, subnode;
- int len;
- /* new binding */
- subnode = ofnode_find_subnode(eth_node, "fixed-link");
- if (ofnode_valid(subnode)) {
node = subnode;
found = true;
- }
- /* old binding */
- if (ofnode_get_property(eth_node, "fixed-link", &len) &&
Maybe "else if" here? If an old-style and a new-style binding exist, we should prefer looking at the new one.
And with that "else if", we could remove the "found" variable:
if (ofnode_valid(subnode)) { } else if (ofnode_get_property(eth_node, "fixed-link", &len) && len == (5 * sizeof(__be32))) { } else { return false; }
if (phy_node) *phy_node = node;
len == (5 * sizeof(__be32))) {
node = eth_node;
found = true;
- }
- if (found && phy_node)
*phy_node = node;
- return found;
+}

Hi Vladimir,
On Sat, Mar 13, 2021 at 9:03 PM Vladimir Oltean olteanv@gmail.com wrote:
On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
+bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node) +{
bool found = false;
ofnode node, subnode;
int len;
/* new binding */
subnode = ofnode_find_subnode(eth_node, "fixed-link");
if (ofnode_valid(subnode)) {
node = subnode;
found = true;
}
/* old binding */
if (ofnode_get_property(eth_node, "fixed-link", &len) &&
Maybe "else if" here? If an old-style and a new-style binding exist, we should prefer looking at the new one.
Agree. Will do in v3.
And with that "else if", we could remove the "found" variable:
Regards, Bin

This adds a test case to test the new ofnode_phy_is_fixed_link() API. Both the new and old DT bindings are covered.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org ---
(no changes since v1)
arch/sandbox/dts/test.dts | 11 +++++++++++ test/dm/of_extra.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 2600360224..995c93c95a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -478,6 +478,17 @@ fake-host-hwaddr = [00 00 66 44 22 22]; };
+ fixed-link-test1 { + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + + fixed-link-test2 { + fixed-link = <0 1 1000 0 0>; + }; + firmware { sandbox_firmware: sandbox-firmware { compatible = "sandbox,firmware"; diff --git a/test/dm/of_extra.c b/test/dm/of_extra.c index b19cd3787d..d7c584fa33 100644 --- a/test/dm/of_extra.c +++ b/test/dm/of_extra.c @@ -36,3 +36,21 @@ static int dm_test_ofnode_read_fmap_entry(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_read_fmap_entry, 0); + +static int dm_test_ofnode_phy_is_fixed_link(struct unit_test_state *uts) +{ + ofnode eth_node, phy_node, node; + + eth_node = ofnode_path("/fixed-link-test1"); + ut_assert(ofnode_phy_is_fixed_link(eth_node, &phy_node)); + node = ofnode_path("/fixed-link-test1/fixed-link"); + ut_asserteq_mem(&phy_node, &node, sizeof(ofnode)); + + eth_node = ofnode_path("/fixed-link-test2"); + ut_assert(ofnode_phy_is_fixed_link(eth_node, &phy_node)); + node = eth_node; + ut_asserteq_mem(&phy_node, &node, sizeof(ofnode)); + + return 0; +} +DM_TEST(dm_test_ofnode_phy_is_fixed_link, 0);

On Fri, Mar 12, 2021 at 09:35:44PM +0800, Bin Meng wrote:
This adds a test case to test the new ofnode_phy_is_fixed_link() API. Both the new and old DT bindings are covered.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
The DSA sandbox patch adds three fixed-link nodes already. Can't you convert one of those three fixed-link nodes to an old-style binding, and modify your test case to cover those existing nodes?

Switch to use the ofnode_phy_is_fixed_link() API which can support both the new and old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
net/mdio-uclass.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 5da984ca3f..2a9533c88b 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -11,6 +11,7 @@ #include <miiphy.h> #include <dm/device-internal.h> #include <dm/device_compat.h> +#include <dm/of_extra.h> #include <dm/uclass-internal.h> #include <linux/compat.h>
@@ -140,7 +141,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, int i;
if (CONFIG_IS_ENABLED(PHY_FIXED) && - ofnode_valid(dev_read_subnode(ethdev, "fixed-link"))) { + ofnode_phy_is_fixed_link(dev_ofnode(ethdev), NULL)) { phy = phy_connect(NULL, -1, ethdev, interface); goto out; }

On Fri, Mar 12, 2021 at 09:35:45PM +0800, Bin Meng wrote:
Switch to use the ofnode_phy_is_fixed_link() API which can support both the new and old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

From: Vladimir Oltean vladimir.oltean@nxp.com
On systems that use CONFIG_OF_LIVE, the "ofnode" type is defined as const struct device_node *np, while on the flat DT systems it is defined as a long of_offset into gd->fdt_blob.
It is desirable that the fixed PHY driver uses the higher-level ofnode abstraction instead of parsing gd->fdt_blob directly, because that enables it to work on live OF systems.
The fixed PHY driver has used a nasty hack since its introduction in commit db40c1aa1c10 ("drivers/net/phy: add fixed-phy / fixed-link support"), which is to pass the long gd->fdt_blob offset inside int phydev->addr (a value that normally holds the MDIO bus address at which the PHY responds). Even ignoring the fact that the types were already mismatched leading to a potential truncation (flat OF offset was supposed to be a long and not an int), we really cannot extend this hack any longer, because there's no way an int will hold the other representation of ofnode, the struct device_node *np.
So we unfortunately need to do the right thing, which is to use the framework introduced by Grygorii Strashko in commit eef0b8a930d1 ("net: phy: add ofnode node to struct phy_device"). This will populate phydev->node for the fixed PHY.
Note that phydev->node will not be valid in the probe function, since that is called synchronously from phy_device_create and we really have no way of passing the ofnode directly through the phy_device_create API. So we do what other drivers do too: we move the OF parsing logic from the .probe to the .config method of the PHY driver. The new function will be called at phy_config() time.
I do believe I've converted all the possible call paths for creating a PHY with PHY_FIXED_ID, so there is really no reason to maintain compatibility with the old logic of retrieving a flat OF tree offset from phydev->addr. We just pass 0 to phydev->addr now.
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-2-olteanv@gmail.com [bmeng: keep fixedphy_probe(); update mdio-uclass.c to handle fixed phy] Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
(no changes since v1)
drivers/net/phy/fixed.c | 26 +++++++++++++++++--------- drivers/net/phy/phy.c | 30 +++++++++++++++--------------- net/mdio-uclass.c | 6 ++++-- 3 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 1a38c29469..11342df1c5 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -17,13 +17,23 @@ DECLARE_GLOBAL_DATA_PTR;
int fixedphy_probe(struct phy_device *phydev) { + /* fixed-link phy must not be reset by core phy code */ + phydev->flags |= PHY_FLAG_BROKEN_RESET; + + return 0; +} + +int fixedphy_config(struct phy_device *phydev) +{ + ofnode node = phy_get_ofnode(phydev); struct fixed_link *priv; - int ofnode = phydev->addr; u32 val;
+ if (!ofnode_valid(node)) + return -EINVAL; + /* check for mandatory properties within fixed-link node */ - val = fdt_getprop_u32_default_node(gd->fdt_blob, - ofnode, 0, "speed", 0); + val = ofnode_read_u32_default(node, "speed", 0); if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && val != SPEED_2500 && val != SPEED_10000) { printf("ERROR: no/invalid speed given in fixed-link node!"); @@ -38,12 +48,9 @@ int fixedphy_probe(struct phy_device *phydev) phydev->priv = priv;
priv->link_speed = val; - priv->duplex = fdtdec_get_bool(gd->fdt_blob, ofnode, "full-duplex"); - priv->pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "pause"); - priv->asym_pause = fdtdec_get_bool(gd->fdt_blob, ofnode, "asym-pause"); - - /* fixed-link phy must not be reset by core phy code */ - phydev->flags |= PHY_FLAG_BROKEN_RESET; + priv->duplex = ofnode_read_bool(node, "full-duplex"); + priv->pause = ofnode_read_bool(node, "pause"); + priv->asym_pause = ofnode_read_bool(node, "asym-pause");
return 0; } @@ -72,6 +79,7 @@ static struct phy_driver fixedphy_driver = { .name = "Fixed PHY", .features = PHY_GBIT_FEATURES | SUPPORTED_MII, .probe = fixedphy_probe, + .config = fixedphy_config, .startup = fixedphy_startup, .shutdown = fixedphy_shutdown, }; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 89e3076bfd..2feb559bba 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -988,6 +988,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, struct phy_device *fixed_phy_create(ofnode node) { phy_interface_t interface = PHY_INTERFACE_MODE_NONE; + struct phy_device *phydev; const char *if_str; ofnode subnode;
@@ -1004,8 +1005,11 @@ struct phy_device *fixed_phy_create(ofnode node) return NULL; }
- return phy_device_create(NULL, ofnode_to_offset(subnode), PHY_FIXED_ID, - false, interface); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface); + if (phydev) + phydev->node = subnode; + + return phydev; }
#ifdef CONFIG_DM_ETH @@ -1018,20 +1022,16 @@ static struct phy_device *phy_connect_fixed(struct mii_dev *bus, phy_interface_t interface) #endif { - struct phy_device *phydev = NULL; - int sn; - const char *name; + ofnode node = dev_ofnode(dev), subnode; + struct phy_device *phydev;
- sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev)); - while (sn > 0) { - name = fdt_get_name(gd->fdt_blob, sn, NULL); - if (name && strcmp(name, "fixed-link") == 0) { - phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false, - interface); - break; - } - sn = fdt_next_subnode(gd->fdt_blob, sn); - } + subnode = ofnode_find_subnode(node, "fixed-link"); + if (!ofnode_valid(subnode)) + return NULL; + + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false, interface); + if (phydev) + phydev->node = subnode;
return phydev; } diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 2a9533c88b..1b687765b8 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -138,11 +138,13 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, struct udevice *mdiodev; struct phy_device *phy; struct ofnode_phandle_args phandle = {.node = ofnode_null()}; + ofnode phynode; int i;
if (CONFIG_IS_ENABLED(PHY_FIXED) && - ofnode_phy_is_fixed_link(dev_ofnode(ethdev), NULL)) { - phy = phy_connect(NULL, -1, ethdev, interface); + ofnode_phy_is_fixed_link(dev_ofnode(ethdev), &phynode)) { + phy = phy_connect(NULL, 0, ethdev, interface); + phandle.node = phynode; goto out; }

On Fri, Mar 12, 2021 at 09:35:46PM +0800, Bin Meng wrote:
From: Vladimir Oltean vladimir.oltean@nxp.com
On systems that use CONFIG_OF_LIVE, the "ofnode" type is defined as const struct device_node *np, while on the flat DT systems it is defined as a long of_offset into gd->fdt_blob.
It is desirable that the fixed PHY driver uses the higher-level ofnode abstraction instead of parsing gd->fdt_blob directly, because that enables it to work on live OF systems.
The fixed PHY driver has used a nasty hack since its introduction in commit db40c1aa1c10 ("drivers/net/phy: add fixed-phy / fixed-link support"), which is to pass the long gd->fdt_blob offset inside int phydev->addr (a value that normally holds the MDIO bus address at which the PHY responds). Even ignoring the fact that the types were already mismatched leading to a potential truncation (flat OF offset was supposed to be a long and not an int), we really cannot extend this hack any longer, because there's no way an int will hold the other representation of ofnode, the struct device_node *np.
So we unfortunately need to do the right thing, which is to use the framework introduced by Grygorii Strashko in commit eef0b8a930d1 ("net: phy: add ofnode node to struct phy_device"). This will populate phydev->node for the fixed PHY.
Note that phydev->node will not be valid in the probe function, since that is called synchronously from phy_device_create and we really have no way of passing the ofnode directly through the phy_device_create API. So we do what other drivers do too: we move the OF parsing logic from the .probe to the .config method of the PHY driver. The new function will be called at phy_config() time.
I do believe I've converted all the possible call paths for creating a PHY with PHY_FIXED_ID, so there is really no reason to maintain compatibility with the old logic of retrieving a flat OF tree offset from phydev->addr. We just pass 0 to phydev->addr now.
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-2-olteanv@gmail.com [bmeng: keep fixedphy_probe(); update mdio-uclass.c to handle fixed phy] Signed-off-by: Bin Meng bmeng.cn@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

From: Vladimir Oltean vladimir.oltean@nxp.com
In drivers/net/phy/Kconfig, CONFIG_PHY_FIXED already depends on CONFIG_DM_ETH, so the function prototype definition when CONFIG_DM_ETH=n does nothing, so it can be dropped. It is also never reachable, since the whole function is already under #ifdef CONFIG_PHY_FIXED (which again, as I said, depends on CONFIG_DM_ETH=y).
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-3-olteanv@gmail.com Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
(no changes since v1)
drivers/net/phy/phy.c | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 2feb559bba..eae40cc0d6 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1012,15 +1012,9 @@ struct phy_device *fixed_phy_create(ofnode node) return phydev; }
-#ifdef CONFIG_DM_ETH static struct phy_device *phy_connect_fixed(struct mii_dev *bus, struct udevice *dev, phy_interface_t interface) -#else -static struct phy_device *phy_connect_fixed(struct mii_dev *bus, - struct eth_device *dev, - phy_interface_t interface) -#endif { ofnode node = dev_ofnode(dev), subnode; struct phy_device *phydev;

On Fri, Mar 12, 2021 at 09:35:47PM +0800, Bin Meng wrote:
From: Vladimir Oltean vladimir.oltean@nxp.com
In drivers/net/phy/Kconfig, CONFIG_PHY_FIXED already depends on CONFIG_DM_ETH, so the function prototype definition when CONFIG_DM_ETH=n does nothing, so it can be dropped. It is also never reachable, since the whole function is already under #ifdef CONFIG_PHY_FIXED (which again, as I said, depends on CONFIG_DM_ETH=y).
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-3-olteanv@gmail.com Signed-off-by: Bin Meng bmeng.cn@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

Following the same updates that were done to the fixed phy driver, use ofnode_ APIs instead of fdt_ APIs so that the Xilinx PHY driver can support live DT.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
---
Changes in v2: - move device tree parsing from xilinxgmiitorgmii_probe() to xilinxgmiitorgmii_config() and use OF APIs
drivers/net/phy/phy.c | 23 +++++------ drivers/net/phy/xilinx_gmii2rgmii.c | 61 ++++++++++++++--------------- 2 files changed, 40 insertions(+), 44 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index eae40cc0d6..d464379121 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -953,23 +953,20 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, #endif { struct phy_device *phydev = NULL; - int sn = dev_of_offset(dev); - int off; - - while (sn > 0) { - off = fdt_node_offset_by_compatible(gd->fdt_blob, sn, - "xlnx,gmii-to-rgmii-1.0"); - if (off > 0) { - phydev = phy_device_create(bus, off, + ofnode node = dev_ofnode(dev); + + while (ofnode_valid(node)) { + node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0"); + if (ofnode_valid(node)) { + phydev = phy_device_create(bus, 0, PHY_GMII2RGMII_ID, false, interface); + if (phydev) + phydev->node = node; break; } - if (off == -FDT_ERR_NOTFOUND) - sn = fdt_first_subnode(gd->fdt_blob, sn); - else - printf("%s: Error finding compat string:%d\n", - __func__, off); + + node = ofnode_first_subnode(node); }
return phydev; diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 74105c0b7d..635c0570ef 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -18,9 +18,38 @@ DECLARE_GLOBAL_DATA_PTR;
static int xilinxgmiitorgmii_config(struct phy_device *phydev) { - struct phy_device *ext_phydev = phydev->priv; + ofnode node = phy_get_ofnode(phydev); + struct phy_device *ext_phydev; + struct ofnode_phandle_args phandle; + int ext_phyaddr = -1; + int ret;
debug("%s\n", __func__); + + if (!ofnode_valid(node)) + return -EINVAL; + + phydev->addr = ofnode_read_u32_default(node, "reg", -1); + ret = ofnode_parse_phandle_with_args(node, "phy-handle", + NULL, 0, 0, &phandle); + if (ret) + return ret; + + ext_phyaddr = ofnode_read_u32_default(phandle.node, "reg", -1); + ext_phydev = phy_find_by_mask(phydev->bus, + 1 << ext_phyaddr, + PHY_INTERFACE_MODE_RGMII); + if (!ext_phydev) { + printf("%s, No external phy device found\n", __func__); + return -EINVAL; + } + + ext_phydev->node = phandle.node; + phydev->priv = ext_phydev; + + debug("%s, gmii2rgmmi:0x%x, extphy:0x%x\n", __func__, phydev->addr, + ext_phyaddr); + if (ext_phydev->drv->config) ext_phydev->drv->config(ext_phydev);
@@ -83,11 +112,6 @@ static int xilinxgmiitorgmii_startup(struct phy_device *phydev)
static int xilinxgmiitorgmii_probe(struct phy_device *phydev) { - int ofnode = phydev->addr; - u32 phy_of_handle; - int ext_phyaddr = -1; - struct phy_device *ext_phydev; - debug("%s\n", __func__);
if (phydev->interface != PHY_INTERFACE_MODE_GMII) { @@ -95,31 +119,6 @@ static int xilinxgmiitorgmii_probe(struct phy_device *phydev) return -EINVAL; }
- /* - * Read the phy address again as the one we read in ethernet driver - * was overwritten for the purpose of storing the ofnode - */ - phydev->addr = fdtdec_get_int(gd->fdt_blob, ofnode, "reg", -1); - phy_of_handle = fdtdec_lookup_phandle(gd->fdt_blob, ofnode, - "phy-handle"); - if (phy_of_handle > 0) - ext_phyaddr = fdtdec_get_int(gd->fdt_blob, - phy_of_handle, - "reg", -1); - ext_phydev = phy_find_by_mask(phydev->bus, - 1 << ext_phyaddr, - PHY_INTERFACE_MODE_RGMII); - if (!ext_phydev) { - printf("%s, No external phy device found\n", __func__); - return -EINVAL; - } - - ext_phydev->node = offset_to_ofnode(phy_of_handle); - phydev->priv = ext_phydev; - - debug("%s, gmii2rgmmi:0x%x, extphy:0x%x\n", __func__, phydev->addr, - ext_phyaddr); - phydev->flags |= PHY_FLAG_BROKEN_RESET;
return 0;

+Karthik/Ashok
On 3/12/21 2:35 PM, Bin Meng wrote:
Following the same updates that were done to the fixed phy driver, use ofnode_ APIs instead of fdt_ APIs so that the Xilinx PHY driver can support live DT.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Changes in v2:
- move device tree parsing from xilinxgmiitorgmii_probe() to xilinxgmiitorgmii_config() and use OF APIs
drivers/net/phy/phy.c | 23 +++++------ drivers/net/phy/xilinx_gmii2rgmii.c | 61 ++++++++++++++--------------- 2 files changed, 40 insertions(+), 44 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index eae40cc0d6..d464379121 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -953,23 +953,20 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, #endif { struct phy_device *phydev = NULL;
- int sn = dev_of_offset(dev);
- int off;
- while (sn > 0) {
off = fdt_node_offset_by_compatible(gd->fdt_blob, sn,
"xlnx,gmii-to-rgmii-1.0");
if (off > 0) {
phydev = phy_device_create(bus, off,
- ofnode node = dev_ofnode(dev);
- while (ofnode_valid(node)) {
node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0");
if (ofnode_valid(node)) {
phydev = phy_device_create(bus, 0, PHY_GMII2RGMII_ID, false, interface);
if (phydev)
}phydev->node = node; break;
if (off == -FDT_ERR_NOTFOUND)
sn = fdt_first_subnode(gd->fdt_blob, sn);
else
printf("%s: Error finding compat string:%d\n",
__func__, off);
node = ofnode_first_subnode(node);
}
return phydev;
diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 74105c0b7d..635c0570ef 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -18,9 +18,38 @@ DECLARE_GLOBAL_DATA_PTR;
static int xilinxgmiitorgmii_config(struct phy_device *phydev) {
- struct phy_device *ext_phydev = phydev->priv;
ofnode node = phy_get_ofnode(phydev);
struct phy_device *ext_phydev;
struct ofnode_phandle_args phandle;
int ext_phyaddr = -1;
int ret;
debug("%s\n", __func__);
if (!ofnode_valid(node))
return -EINVAL;
phydev->addr = ofnode_read_u32_default(node, "reg", -1);
ret = ofnode_parse_phandle_with_args(node, "phy-handle",
NULL, 0, 0, &phandle);
if (ret)
return ret;
ext_phyaddr = ofnode_read_u32_default(phandle.node, "reg", -1);
ext_phydev = phy_find_by_mask(phydev->bus,
1 << ext_phyaddr,
PHY_INTERFACE_MODE_RGMII);
if (!ext_phydev) {
printf("%s, No external phy device found\n", __func__);
return -EINVAL;
}
ext_phydev->node = phandle.node;
phydev->priv = ext_phydev;
debug("%s, gmii2rgmmi:0x%x, extphy:0x%x\n", __func__, phydev->addr,
ext_phyaddr);
if (ext_phydev->drv->config) ext_phydev->drv->config(ext_phydev);
@@ -83,11 +112,6 @@ static int xilinxgmiitorgmii_startup(struct phy_device *phydev)
static int xilinxgmiitorgmii_probe(struct phy_device *phydev) {
int ofnode = phydev->addr;
u32 phy_of_handle;
int ext_phyaddr = -1;
struct phy_device *ext_phydev;
debug("%s\n", __func__);
if (phydev->interface != PHY_INTERFACE_MODE_GMII) {
@@ -95,31 +119,6 @@ static int xilinxgmiitorgmii_probe(struct phy_device *phydev) return -EINVAL; }
/*
* Read the phy address again as the one we read in ethernet driver
* was overwritten for the purpose of storing the ofnode
*/
phydev->addr = fdtdec_get_int(gd->fdt_blob, ofnode, "reg", -1);
phy_of_handle = fdtdec_lookup_phandle(gd->fdt_blob, ofnode,
"phy-handle");
if (phy_of_handle > 0)
ext_phyaddr = fdtdec_get_int(gd->fdt_blob,
phy_of_handle,
"reg", -1);
ext_phydev = phy_find_by_mask(phydev->bus,
1 << ext_phyaddr,
PHY_INTERFACE_MODE_RGMII);
if (!ext_phydev) {
printf("%s, No external phy device found\n", __func__);
return -EINVAL;
}
ext_phydev->node = offset_to_ofnode(phy_of_handle);
phydev->priv = ext_phydev;
debug("%s, gmii2rgmmi:0x%x, extphy:0x%x\n", __func__, phydev->addr,
ext_phyaddr);
phydev->flags |= PHY_FLAG_BROKEN_RESET;
return 0;
Karthik/Ashok: Please retest it.
Thanks, Michal

At present phy_connect_gmii2rgmii() is implemented using a DM API dev_of_offset() hence it cannot support a non-DM configuration. Remove the non-DM version prototype of phy_connect_gmii2rgmii() and make the driver depend on CONFIG_DM_ETH.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Acked-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/phy/Kconfig | 1 + drivers/net/phy/phy.c | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index d69503067d..070ffa82cb 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -292,6 +292,7 @@ config PHY_XILINX
config PHY_XILINX_GMII2RGMII bool "Xilinx GMII to RGMII Ethernet PHYs support" + depends on DM_ETH help This adds support for Xilinx GMII to RGMII IP core. This IP acts as bridge between MAC connected over GMII and external phy that diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index d464379121..c7cdf64a0a 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -942,15 +942,9 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) }
#ifdef CONFIG_PHY_XILINX_GMII2RGMII -#ifdef CONFIG_DM_ETH static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, struct udevice *dev, phy_interface_t interface) -#else -static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, - struct eth_device *dev, - phy_interface_t interface) -#endif { struct phy_device *phydev = NULL; ofnode node = dev_ofnode(dev);

On Fri, Mar 12, 2021 at 09:35:49PM +0800, Bin Meng wrote:
At present phy_connect_gmii2rgmii() is implemented using a DM API dev_of_offset() hence it cannot support a non-DM configuration. Remove the non-DM version prototype of phy_connect_gmii2rgmii() and make the driver depend on CONFIG_DM_ETH.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Acked-by: Michal Simek michal.simek@xilinx.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

Simplify the logic of phy_connect_fixed() by using the new API ofnode_phy_is_fixed_link(), which brings additional bonus of supporting the old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/phy/phy.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c7cdf64a0a..dcdef9e661 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -18,6 +18,7 @@ #include <phy.h> #include <errno.h> #include <asm/global_data.h> +#include <dm/of_extra.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/err.h> @@ -1008,15 +1009,14 @@ static struct phy_device *phy_connect_fixed(struct mii_dev *bus, phy_interface_t interface) { ofnode node = dev_ofnode(dev), subnode; - struct phy_device *phydev; - - subnode = ofnode_find_subnode(node, "fixed-link"); - if (!ofnode_valid(subnode)) - return NULL; + struct phy_device *phydev = NULL;
- phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false, interface); - if (phydev) - phydev->node = subnode; + if (ofnode_phy_is_fixed_link(node, &subnode)) { + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, + false, interface); + if (phydev) + phydev->node = subnode; + }
return phydev; }

On Fri, Mar 12, 2021 at 09:35:50PM +0800, Bin Meng wrote:
Simplify the logic of phy_connect_fixed() by using the new API ofnode_phy_is_fixed_link(), which brings additional bonus of supporting the old DT bindings.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

The PHY driver ops should be made static.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/phy/fixed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 11342df1c5..1d2587278f 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -15,7 +15,7 @@
DECLARE_GLOBAL_DATA_PTR;
-int fixedphy_probe(struct phy_device *phydev) +static int fixedphy_probe(struct phy_device *phydev) { /* fixed-link phy must not be reset by core phy code */ phydev->flags |= PHY_FLAG_BROKEN_RESET; @@ -23,7 +23,7 @@ int fixedphy_probe(struct phy_device *phydev) return 0; }
-int fixedphy_config(struct phy_device *phydev) +static int fixedphy_config(struct phy_device *phydev) { ofnode node = phy_get_ofnode(phydev); struct fixed_link *priv; @@ -55,7 +55,7 @@ int fixedphy_config(struct phy_device *phydev) return 0; }
-int fixedphy_startup(struct phy_device *phydev) +static int fixedphy_startup(struct phy_device *phydev) { struct fixed_link *priv = phydev->priv;
@@ -68,7 +68,7 @@ int fixedphy_startup(struct phy_device *phydev) return 0; }
-int fixedphy_shutdown(struct phy_device *phydev) +static int fixedphy_shutdown(struct phy_device *phydev) { return 0; }

On Fri, Mar 12, 2021 at 09:35:51PM +0800, Bin Meng wrote:
The PHY driver ops should be made static.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

The printf statement doesn't end with a newline. Add it.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/phy/fixed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 1d2587278f..304e506554 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -36,7 +36,7 @@ static int fixedphy_config(struct phy_device *phydev) val = ofnode_read_u32_default(node, "speed", 0); if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && val != SPEED_2500 && val != SPEED_10000) { - printf("ERROR: no/invalid speed given in fixed-link node!"); + printf("ERROR: no/invalid speed given in fixed-link node!\n"); return -EINVAL; }

On Fri, Mar 12, 2021 at 09:35:52PM +0800, Bin Meng wrote:
The printf statement doesn't end with a newline. Add it.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

Update fixedphy_probe() to support the old DT binding.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/phy/fixed.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 304e506554..ea05a45244 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -27,13 +27,27 @@ static int fixedphy_config(struct phy_device *phydev) { ofnode node = phy_get_ofnode(phydev); struct fixed_link *priv; + bool old_binding = false; u32 val; + u32 old_val[5];
if (!ofnode_valid(node)) return -EINVAL;
/* check for mandatory properties within fixed-link node */ val = ofnode_read_u32_default(node, "speed", 0); + + if (!val) { + /* try old binding */ + old_binding = true; + if (ofnode_read_u32_array(node, "fixed-link", old_val, + ARRAY_SIZE(old_val))) { + printf("ERROR: no/invalid <fixed-link> property!\n"); + return -ENOENT; + } + val = old_val[2]; + } + if (val != SPEED_10 && val != SPEED_100 && val != SPEED_1000 && val != SPEED_2500 && val != SPEED_10000) { printf("ERROR: no/invalid speed given in fixed-link node!\n"); @@ -48,9 +62,15 @@ static int fixedphy_config(struct phy_device *phydev) phydev->priv = priv;
priv->link_speed = val; - priv->duplex = ofnode_read_bool(node, "full-duplex"); - priv->pause = ofnode_read_bool(node, "pause"); - priv->asym_pause = ofnode_read_bool(node, "asym-pause"); + if (!old_binding) { + priv->duplex = ofnode_read_bool(node, "full-duplex"); + priv->pause = ofnode_read_bool(node, "pause"); + priv->asym_pause = ofnode_read_bool(node, "asym-pause"); + } else { + priv->duplex = old_val[1]; + priv->pause = old_val[3]; + priv->asym_pause = old_val[4]; + }
return 0; }

On Fri, Mar 12, 2021 at 09:35:53PM +0800, Bin Meng wrote:
Update fixedphy_probe() to support the old DT binding.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
(no changes since v1)
drivers/net/phy/fixed.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 304e506554..ea05a45244 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -27,13 +27,27 @@ static int fixedphy_config(struct phy_device *phydev) { ofnode node = phy_get_ofnode(phydev); struct fixed_link *priv;
- bool old_binding = false; u32 val;
- u32 old_val[5];
Perhaps a pet peeve from Linux networking, but could you please keep the variable definitions sorted by line length? Thanks.
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

From: Vladimir Oltean vladimir.oltean@nxp.com
Now that the fixed phy driver has been fully adapted to OF APIs, and dm_eth_phy_connect() already can handle the fixed phy, call dm_eth_phy_connect() directly in the DM tsec driver.
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-4-olteanv@gmail.com [bmeng: split from "net: mdio: teach dm_eth_phy_connect to connect to fixed PHY"] Signed-off-by: Bin Meng bmeng.cn@gmail.com
---
Changes in v2: - new patch: split from 20210216224804.3355044-4-olteanv@gmail.com
drivers/net/tsec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index ec48689372..f801d020fb 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -707,11 +707,7 @@ static int init_phy(struct tsec_private *priv) tsec_configure_serdes(priv);
#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO) - if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev), - "fixed-link"))) - phydev = phy_connect(NULL, 0, priv->dev, priv->interface); - else - phydev = dm_eth_phy_connect(priv->dev); + phydev = dm_eth_phy_connect(priv->dev); #else phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev, priv->interface);

On Fri, Mar 12, 2021 at 09:35:54PM +0800, Bin Meng wrote:
From: Vladimir Oltean vladimir.oltean@nxp.com
Now that the fixed phy driver has been fully adapted to OF APIs, and dm_eth_phy_connect() already can handle the fixed phy, call dm_eth_phy_connect() directly in the DM tsec driver.
Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Reviewed-by: Bin Meng bmeng.cn@gmail.com Tested-by: Bin Meng bmeng.cn@gmail.com Message-Id: 20210216224804.3355044-4-olteanv@gmail.com [bmeng: split from "net: mdio: teach dm_eth_phy_connect to connect to fixed PHY"] Signed-off-by: Bin Meng bmeng.cn@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

From: Claudiu Manoil claudiu.manoil@nxp.com
The DSA sandbox driver is used for unit testing the DSA class code. It implements a simple 2 port switch plus 1 CPU port, and uses a very simple tag to identify the ports.
The DSA sandbox device is connected via CPU port to a regular Ethernet sandbox device, called 'dsa-test-eth, managed by the existing eth sandbox driver. The 'dsa-test-eth' is not intended for testing the eth class code however, but it is used to emulate traffic through the 'lan0' and 'lan1' front pannel switch ports. To achieve this the dsa sandbox driver registers a tx handler for the 'dsa-test-eth' device. The switch ports, labeled as 'lan0' and 'lan1', are also registered as eth devices by the dsa class code this time. So pinging through these switch ports is as easy as:
=> setenv ethact lan0 => ping 1.2.3.5
Unit tests for the dsa class code were also added. The 'dsa_probe' test exercises most API functions from dsa.h. The 'dsa' unit test simply exercises ARP/ICMP traffic through the two switch ports, including tag injection and extraction, with the help of the dsa sandbox driver.
I took care to minimize the impact on the existing eth unit tests, though some adjustments needed to be made with the addition of extra eth interfaces used by the dsa unit tests. The additional eth interfaces also require MAC addresses, these have been added to the sandbox default environment.
Signed-off-by: Alex Marginean alexandru.marginean@nxp.com Signed-off-by: Claudiu Manoil claudiu.manoil@nxp.com Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Vladimir Oltean vladimir.oltean@nxp.com Message-Id: 20210216224804.3355044-5-olteanv@gmail.com Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
(no changes since v1)
arch/Kconfig | 2 + arch/sandbox/dts/test.dts | 48 ++++++++++ drivers/net/Kconfig | 9 ++ drivers/net/Makefile | 1 + drivers/net/dsa_sandbox.c | 179 ++++++++++++++++++++++++++++++++++++++ include/configs/sandbox.h | 2 + test/dm/Makefile | 1 + test/dm/dsa.c | 82 +++++++++++++++++ test/dm/eth.c | 10 +-- 9 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 drivers/net/dsa_sandbox.c create mode 100644 test/dm/dsa.c
diff --git a/arch/Kconfig b/arch/Kconfig index 27843cd79c..5672d1df7e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -160,6 +160,8 @@ config SANDBOX imply CMD_CLONE imply SILENT_CONSOLE imply BOOTARGS_SUBST + imply PHY_FIXED + imply DM_DSA
config SH bool "SuperH architecture" diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 995c93c95a..0e3eb63481 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -15,7 +15,9 @@ aliases { console = &uart0; eth0 = "/eth@10002000"; + eth2 = &swp_0; eth3 = ð_3; + eth4 = &dsa_eth0; eth5 = ð_5; gpio1 = &gpio_a; gpio2 = &gpio_b; @@ -478,6 +480,52 @@ fake-host-hwaddr = [00 00 66 44 22 22]; };
+ dsa_eth0: dsa-test-eth { + compatible = "sandbox,eth"; + reg = <0x10006000 0x1000>; + fake-host-hwaddr = [00 00 66 44 22 66]; + }; + + dsa-test { + compatible = "sandbox,dsa"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + swp_0: port@0 { + reg = <0>; + label = "lan0"; + phy-mode = "rgmii-rxid"; + + fixed-link { + speed = <100>; + full-duplex; + }; + }; + + swp_1: port@1 { + reg = <1>; + label = "lan1"; + phy-mode = "rgmii-txid"; + + fixed-link { + speed = <100>; + full-duplex; + }; + }; + + port@2 { + reg = <2>; + ethernet = <&dsa_eth0>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; + }; + fixed-link-test1 { fixed-link { speed = <1000>; diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 0e84c22b50..f96ee64249 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -78,6 +78,15 @@ config DM_ETH_PHY help Enable driver model for Ethernet Generic PHY .
+config DSA_SANDBOX + depends on DM_DSA && SANDBOX + default y + bool "Sandbox: Mocked DSA driver" + help + This driver implements a dummy DSA switch connected to a dummy sandbox + Ethernet device used as DSA master, to test DSA class code, including + exported DSA API and datapath processing of Ethernet traffic. + menuconfig NETDEVICES bool "Network device support" depends on NET diff --git a/drivers/net/Makefile b/drivers/net/Makefile index a19511aaa7..108138fdb9 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_ETH_DESIGNWARE_SOCFPGA) += dwmac_socfpga.o obj-$(CONFIG_ETH_DESIGNWARE_S700) += dwmac_s700.o obj-$(CONFIG_DRIVER_DM9000) += dm9000x.o obj-$(CONFIG_DNET) += dnet.o +obj-$(CONFIG_DSA_SANDBOX) += dsa_sandbox.o obj-$(CONFIG_DM_ETH_PHY) += eth-phy-uclass.o obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o diff --git a/drivers/net/dsa_sandbox.c b/drivers/net/dsa_sandbox.c new file mode 100644 index 0000000000..4b62670e5d --- /dev/null +++ b/drivers/net/dsa_sandbox.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019-2021 NXP Semiconductors + */ + +#include <asm/eth.h> +#include <net/dsa.h> +#include <net.h> + +#define DSA_SANDBOX_MAGIC 0x00415344 +#define DSA_SANDBOX_TAG_LEN sizeof(struct dsa_sandbox_tag) + +struct dsa_sandbox_priv { + struct eth_sandbox_priv *master_priv; + int port_en_mask; +}; + +struct dsa_sandbox_tag { + u32 magic; + u32 port; +}; + +static bool sb_dsa_port_enabled(struct udevice *dev, int port) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + return priv->port_en_mask & BIT(port); +} + +static bool sb_dsa_master_enabled(struct udevice *dev) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + return !priv->master_priv->disabled; +} + +static int dsa_sandbox_port_enable(struct udevice *dev, int port, + struct phy_device *phy) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + priv->port_en_mask |= BIT(port); + + return 0; +} + +static void dsa_sandbox_port_disable(struct udevice *dev, int port, + struct phy_device *phy) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + + priv->port_en_mask &= ~BIT(port); +} + +static int dsa_sandbox_xmit(struct udevice *dev, int port, void *packet, + int length) +{ + struct dsa_sandbox_tag *tag = packet; + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + if (!sb_dsa_port_enabled(dev, port)) + return -EFAULT; + + tag->magic = DSA_SANDBOX_MAGIC; + tag->port = port; + + return 0; +} + +static int dsa_sandbox_rcv(struct udevice *dev, int *port, void *packet, + int length) +{ + struct dsa_sandbox_tag *tag = packet; + + if (!sb_dsa_master_enabled(dev)) + return -EFAULT; + + if (tag->magic != DSA_SANDBOX_MAGIC) + return -EFAULT; + + *port = tag->port; + if (!sb_dsa_port_enabled(dev, tag->port)) + return -EFAULT; + + return 0; +} + +static const struct dsa_ops dsa_sandbox_ops = { + .port_enable = dsa_sandbox_port_enable, + .port_disable = dsa_sandbox_port_disable, + .xmit = dsa_sandbox_xmit, + .rcv = dsa_sandbox_rcv, +}; + +static int sb_dsa_handler(struct udevice *dev, void *packet, + unsigned int len) +{ + struct eth_sandbox_priv *master_priv; + struct dsa_sandbox_tag *tag = packet; + struct udevice *dsa_dev; + u32 port_index; + void *rx_buf; + int i; + + /* this emulates the switch hw and the network side */ + if (tag->magic != DSA_SANDBOX_MAGIC) + return -EFAULT; + + port_index = tag->port; + master_priv = dev_get_priv(dev); + dsa_dev = master_priv->priv; + if (!sb_dsa_port_enabled(dsa_dev, port_index)) + return -EFAULT; + + packet += DSA_SANDBOX_TAG_LEN; + len -= DSA_SANDBOX_TAG_LEN; + + if (!sandbox_eth_arp_req_to_reply(dev, packet, len)) + goto dsa_tagging; + if (!sandbox_eth_ping_req_to_reply(dev, packet, len)) + goto dsa_tagging; + + return 0; + +dsa_tagging: + master_priv->recv_packets--; + i = master_priv->recv_packets; + rx_buf = master_priv->recv_packet_buffer[i]; + len = master_priv->recv_packet_length[i]; + memmove(rx_buf + DSA_SANDBOX_TAG_LEN, rx_buf, len); + + tag = rx_buf; + tag->magic = DSA_SANDBOX_MAGIC; + tag->port = port_index; + len += DSA_SANDBOX_TAG_LEN; + master_priv->recv_packet_length[i] = len; + master_priv->recv_packets++; + + return 0; +} + +static int dsa_sandbox_probe(struct udevice *dev) +{ + struct dsa_sandbox_priv *priv = dev_get_priv(dev); + struct udevice *master = dsa_get_master(dev); + struct eth_sandbox_priv *master_priv; + + if (!master) + return -ENODEV; + + dsa_set_tagging(dev, DSA_SANDBOX_TAG_LEN, 0); + + master_priv = dev_get_priv(master); + master_priv->priv = dev; + master_priv->tx_handler = sb_dsa_handler; + + priv->master_priv = master_priv; + + return 0; +} + +static const struct udevice_id dsa_sandbox_ids[] = { + { .compatible = "sandbox,dsa" }, + { } +}; + +U_BOOT_DRIVER(dsa_sandbox) = { + .name = "dsa_sandbox", + .id = UCLASS_DSA, + .of_match = dsa_sandbox_ids, + .probe = dsa_sandbox_probe, + .ops = &dsa_sandbox_ops, + .priv_auto = sizeof(struct dsa_sandbox_priv), +}; diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index e0708fe573..91f636b2c1 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -93,7 +93,9 @@ #endif
#define SANDBOX_ETH_SETTINGS "ethaddr=00:00:11:22:33:44\0" \ + "eth2addr=00:00:11:22:33:48\0" \ "eth3addr=00:00:11:22:33:45\0" \ + "eth4addr=00:00:11:22:33:48\0" \ "eth5addr=00:00:11:22:33:46\0" \ "eth6addr=00:00:11:22:33:47\0" \ "ipaddr=1.2.3.4\0" diff --git a/test/dm/Makefile b/test/dm/Makefile index fd1455109d..1c2fa95f4a 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o +obj-$(CONFIG_DM_DSA) += dsa.o obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o diff --git a/test/dm/dsa.c b/test/dm/dsa.c new file mode 100644 index 0000000000..18c1776460 --- /dev/null +++ b/test/dm/dsa.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2020-2021 NXP Semiconductors + */ + +#include <net/dsa.h> +#include <dm/test.h> +#include <test/ut.h> +#include <net.h> +#include <dm/uclass-internal.h> +#include <dm/device-internal.h> + +/* This test exercises the major dsa.h API functions, after making sure + * that the DSA ports and the master Eth are correctly probed. + */ +static int dm_test_dsa_probe(struct unit_test_state *uts) +{ + struct udevice *dev_dsa, *dev_port, *dev_master; + struct dsa_pdata *dsa_pdata; + enum uclass_id id; + + id = uclass_get_by_name("dsa"); + ut_assert(id == UCLASS_DSA); + + ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test", + &dev_dsa)); + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth", + &dev_master)); + ut_assertok(device_probe(dev_master)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + /* exercise DSA API */ + dsa_pdata = dev_get_uclass_plat(dev_dsa); + ut_assertnonnull(dsa_pdata); + /* includes CPU port */ + ut_assert(dsa_pdata->num_ports == 3); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1", + &dev_port)); + ut_assertok(device_probe(dev_port)); + + dev_master = dsa_get_master(dev_dsa); + ut_assertnonnull(dev_master); + ut_asserteq_str("dsa-test-eth", dev_master->name); + + return 0; +} + +DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT); + +/* This test sends ping requests with the local address through each DSA port + * via the sandbox DSA master Eth. + */ +static int dm_test_dsa(struct unit_test_state *uts) +{ + net_ping_ip = string_to_ip("1.2.3.5"); + + env_set("ethact", "eth2"); + ut_assertok(net_loop(PING)); + + env_set("ethact", "lan0"); + ut_assertok(net_loop(PING)); + env_set("ethact", "lan1"); + ut_assertok(net_loop(PING)); + + env_set("ethact", ""); + + return 0; +} + +DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT); diff --git a/test/dm/eth.c b/test/dm/eth.c index fa8a69da70..e4ee695610 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -53,8 +53,8 @@ static int dm_test_eth_alias(struct unit_test_state *uts) ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10004000", env_get("ethact"));
- /* Expected to fail since eth2 is not defined in the device tree */ - env_set("ethact", "eth2"); + /* Expected to fail since eth1 is not defined in the device tree */ + env_set("ethact", "eth1"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@10002000", env_get("ethact"));
@@ -227,7 +227,7 @@ static int _dm_test_net_retry(struct unit_test_state *uts) * the active device should be eth0 */ sandbox_eth_disable_response(1, true); - env_set("ethact", "eth@10004000"); + env_set("ethact", "lan1"); env_set("netretry", "yes"); sandbox_eth_skip_timeout(); ut_assertok(net_loop(PING)); @@ -237,11 +237,11 @@ static int _dm_test_net_retry(struct unit_test_state *uts) * eth1 is disabled and netretry is no, so the ping should fail and the * active device should be eth1 */ - env_set("ethact", "eth@10004000"); + env_set("ethact", "lan1"); env_set("netretry", "no"); sandbox_eth_skip_timeout(); ut_asserteq(-ENONET, net_loop(PING)); - ut_asserteq_str("eth@10004000", env_get("ethact")); + ut_asserteq_str("lan1", env_get("ethact"));
return 0; }

At present the Freescale TSEC node DT bindings doc requires a <reg> property in the TSEC node. But this might not always be the case. In the upstream Linux kernel, there is no DT bindings doc for it but the kernel driver tests a subnode of a name prefixed with "queue-group", as we can see from gfar_of_init():
for_each_available_child_of_node(np, child) { if (!of_node_name_eq(child, "queue-group")) ...
in drivers/net/ethernet/freescale/gianfar.c
Update our DT bindings to describe this alternate description.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
doc/device-tree-bindings/net/fsl-tsec-phy.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/doc/device-tree-bindings/net/fsl-tsec-phy.txt b/doc/device-tree-bindings/net/fsl-tsec-phy.txt index a44c5fd9d9..2f9309839c 100644 --- a/doc/device-tree-bindings/net/fsl-tsec-phy.txt +++ b/doc/device-tree-bindings/net/fsl-tsec-phy.txt @@ -3,7 +3,9 @@ Properties:
- compatible : Should be "fsl,etsec2" or "gianfar" - - reg : Offset and length of the register set for the device + - reg : Offset and length of the register set for the device. If this is + missing, a subnode with a name prefix "queue-group" must be provided to + provide the <reg> property. - phy-handle : See ethernet.txt file in the same directory. - phy-connection-type : See ethernet.txt file in the same directory. This property is only really needed if the connection is of type "rgmii-id", @@ -18,6 +20,17 @@ Example: phy-connection-type = "sgmii"; };
+An alternate description with "queue-group" subnode example: + ethernet@24000 { + compatible = "fsl,etsec2"; + phy-handle = <&phy0>; + phy-connection-type = "sgmii"; + + queue-group { + reg = <0x24000 0x1000>; + }; + }; + Child nodes of the TSEC controller are typically the individual PHY devices connected via the MDIO bus (sometimes the MDIO bus controller is separate).

On Fri, Mar 12, 2021 at 09:35:56PM +0800, Bin Meng wrote:
At present the Freescale TSEC node DT bindings doc requires a <reg> property in the TSEC node. But this might not always be the case. In the upstream Linux kernel, there is no DT bindings doc for it but the kernel driver tests a subnode of a name prefixed with "queue-group", as we can see from gfar_of_init():
for_each_available_child_of_node(np, child) { if (!of_node_name_eq(child, "queue-group")) ...
in drivers/net/ethernet/freescale/gianfar.c
Update our DT bindings to describe this alternate description.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
Fascinating. I did not even notice that the Linux DT bindings do not have a "reg" property and rely on "ranges" for translation to the queue-group. I guess that changes things. I'll go again through the patches starting from the first one.

At present the tsec driver uses a non-standard DT bindings to get its <reg> base / size. The upstream Linux kernel seems to require the <reg> base / size to be put under a subnode of the eTSEC node with a name prefix "queue-group". This is not documented in the kernel DT bindings, but it looks every dtsi file that contains the eTSEC node was written like this.
This commit updates the tsec driver to handle this case.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com ---
(no changes since v1)
drivers/net/tsec.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index f801d020fb..49bed0c1dd 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -827,13 +827,35 @@ int tsec_probe(struct udevice *dev) struct tsec_data *data; const char *phy_mode; fdt_addr_t reg; - ofnode parent; + ofnode parent, child; int ret;
data = (struct tsec_data *)dev_get_driver_data(dev);
pdata->iobase = (phys_addr_t)dev_read_addr(dev); - priv->regs = dev_remap_addr(dev); + if (pdata->iobase != FDT_ADDR_T_NONE) { + priv->regs = dev_remap_addr(dev); + } else { + ofnode_for_each_subnode(child, dev_ofnode(dev)) { + if (!strncmp(ofnode_get_name(child), "queue-group", + strlen("queue-group"))) { + reg = ofnode_get_addr(child); + if (reg == FDT_ADDR_T_NONE) { + printf("No 'reg' property of <queue-group>\n"); + return -ENOENT; + } + pdata->iobase = reg; + priv->regs = map_physmem(pdata->iobase, 0, + MAP_NOCACHE); + break; + } + } + + if (!ofnode_valid(child)) { + printf("No child node for <queue-group>?\n"); + return -ENOENT; + } + }
ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0, &phandle_args);

On Fri, Mar 12, 2021 at 09:35:57PM +0800, Bin Meng wrote:
At present the tsec driver uses a non-standard DT bindings to get its <reg> base / size. The upstream Linux kernel seems to require the <reg> base / size to be put under a subnode of the eTSEC node with a name prefix "queue-group". This is not documented in the kernel DT bindings, but it looks every dtsi file that contains the eTSEC node was written like this.
This commit updates the tsec driver to handle this case.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Ramon Fried rfried.dev@gmail.com
(no changes since v1)
drivers/net/tsec.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index f801d020fb..49bed0c1dd 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -827,13 +827,35 @@ int tsec_probe(struct udevice *dev) struct tsec_data *data; const char *phy_mode; fdt_addr_t reg;
- ofnode parent;
- ofnode parent, child;
Same comment about the "reverse Christmas tree" notation.
int ret;
data = (struct tsec_data *)dev_get_driver_data(dev);
pdata->iobase = (phys_addr_t)dev_read_addr(dev);
- priv->regs = dev_remap_addr(dev);
- if (pdata->iobase != FDT_ADDR_T_NONE) {
priv->regs = dev_remap_addr(dev);
- } else {
ofnode_for_each_subnode(child, dev_ofnode(dev)) {
if (!strncmp(ofnode_get_name(child), "queue-group",
strlen("queue-group"))) {
I would prefer the syntax:
if (strncmp(ofnode_get_name(child), "queue-group", strlen("queue-group"))) continue;
which allows us to reduce the indentation level.
reg = ofnode_get_addr(child);
if (reg == FDT_ADDR_T_NONE) {
printf("No 'reg' property of <queue-group>\n");
return -ENOENT;
}
pdata->iobase = reg;
priv->regs = map_physmem(pdata->iobase, 0,
MAP_NOCACHE);
Hmm, can't you just populate pdata->iobase, and call the same dev_remap_addr in the common code path?
break;
Could you please add a comment that if there are multiple queue groups, we only use the first one?
}
}
if (!ofnode_valid(child)) {
printf("No child node for <queue-group>?\n");
return -ENOENT;
}
- }

At present we decode simple bus <ranges> using the following assumption:
- parent #address-cells 1 - child #address-cells 1 - child #size-cells 1
However this might not always be the case.
Update to use fdt_addr_t and fdt_size_t in 'struct simple_bus_plat', and use fdt_read_ranges() to correctly decode it according to the actual parent and child #address-cells / #size-cells under a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE which can be turned on for any board that needs it.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
---
Changes in v2: - include <asm/global_data.h> - use a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE to control the new behavior for boards that want this
drivers/core/Kconfig | 13 +++++++++++++ drivers/core/simple-bus.c | 32 +++++++++++++++++++++++++------- include/dm/simple_bus.h | 6 +++--- 3 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index 1eccac28c6..c7504edaf8 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -235,6 +235,19 @@ config SPL_SIMPLE_BUS Supports the 'simple-bus' driver, which is used on some systems in SPL.
+config SIMPLE_BUS_CORRECT_RANGE + bool "Decode the 'simple-bus' <range> by honoring the #address-cells and #size-cells" + depends on SIMPLE_BUS + help + Decoding the 'simple-bus' <range> by honoring the #address-cells + and #size-cells of parent/child bus. If unset, #address-cells of + parent bus is assumed to be 1, #address-cells and #size-cells of + child bus is also assumed to be 1, to save some spaces of using + an advanced API to decode the <range>, which benefits SPL image + builds that have size limits. + + If you are unsure about this, Say N here. + config SIMPLE_PM_BUS bool "Support simple-pm-bus driver" depends on DM && OF_CONTROL && CLK && POWER_DOMAIN diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c index b0c2c20958..18f52d26df 100644 --- a/drivers/core/simple-bus.c +++ b/drivers/core/simple-bus.c @@ -4,8 +4,12 @@ */
#include <common.h> +#include <asm/global_data.h> #include <dm.h> #include <dm/simple_bus.h> +#include <fdt_support.h> + +DECLARE_GLOBAL_DATA_PTR;
fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr) { @@ -22,16 +26,30 @@ static int simple_bus_post_bind(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_PLATDATA) return 0; #else - u32 cell[3]; + struct simple_bus_plat *plat = dev_get_uclass_plat(dev); int ret;
- ret = dev_read_u32_array(dev, "ranges", cell, ARRAY_SIZE(cell)); - if (!ret) { - struct simple_bus_plat *plat = dev_get_uclass_plat(dev); + if (CONFIG_IS_ENABLED(SIMPLE_BUS_CORRECT_RANGE)) { + uint64_t caddr, paddr, len; + + /* only read range index 0 */ + ret = fdt_read_range((void *)gd->fdt_blob, dev_of_offset(dev), + 0, &caddr, &paddr, &len); + if (!ret) { + plat->base = caddr; + plat->target = paddr; + plat->size = len; + } + } else { + u32 cell[3];
- plat->base = cell[0]; - plat->target = cell[1]; - plat->size = cell[2]; + ret = dev_read_u32_array(dev, "ranges", cell, + ARRAY_SIZE(cell)); + if (!ret) { + plat->base = cell[0]; + plat->target = cell[1]; + plat->size = cell[2]; + } }
return dm_scan_fdt_dev(dev); diff --git a/include/dm/simple_bus.h b/include/dm/simple_bus.h index 4ad4cc4051..b7104013c0 100644 --- a/include/dm/simple_bus.h +++ b/include/dm/simple_bus.h @@ -7,9 +7,9 @@ #define __DM_SIMPLE_BUS_H
struct simple_bus_plat { - u32 base; - u32 size; - u32 target; + fdt_addr_t base; + fdt_size_t size; + fdt_addr_t target; };
#endif

On Fri, 12 Mar 2021 at 06:37, Bin Meng bmeng.cn@gmail.com wrote:
At present we decode simple bus <ranges> using the following assumption:
- parent #address-cells 1
- child #address-cells 1
- child #size-cells 1
However this might not always be the case.
Update to use fdt_addr_t and fdt_size_t in 'struct simple_bus_plat', and use fdt_read_ranges() to correctly decode it according to the actual parent and child #address-cells / #size-cells under a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE which can be turned on for any board that needs it.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Changes in v2:
- include <asm/global_data.h>
- use a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE to control the new behavior for boards that want this
drivers/core/Kconfig | 13 +++++++++++++ drivers/core/simple-bus.c | 32 +++++++++++++++++++++++++------- include/dm/simple_bus.h | 6 +++--- 3 files changed, 41 insertions(+), 10 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

This adds a test case to verify reading <ranges> of a simple-bus is working as expected.
Signed-off-by: Bin Meng bmeng.cn@gmail.com Reviewed-by: Simon Glass sjg@chromium.org
---
Changes in v2: - default y if SANDBOX for CONFIG_SIMPLE_BUS_CORRECT_RANGE
drivers/core/Kconfig | 1 + test/dm/Makefile | 1 + test/dm/simple-bus.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test/dm/simple-bus.c
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index c7504edaf8..a7c3120860 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -238,6 +238,7 @@ config SPL_SIMPLE_BUS config SIMPLE_BUS_CORRECT_RANGE bool "Decode the 'simple-bus' <range> by honoring the #address-cells and #size-cells" depends on SIMPLE_BUS + default y if SANDBOX help Decoding the 'simple-bus' <range> by honoring the #address-cells and #size-cells of parent/child bus. If unset, #address-cells of diff --git a/test/dm/Makefile b/test/dm/Makefile index 1c2fa95f4a..d0d46e7f7e 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -90,6 +90,7 @@ obj-$(CONFIG_DM_MDIO) += mdio.o obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o +obj-$(CONFIG_SIMPLE_BUS) += simple-bus.o obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o diff --git a/test/dm/simple-bus.c b/test/dm/simple-bus.c new file mode 100644 index 0000000000..3530b47fac --- /dev/null +++ b/test/dm/simple-bus.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021, Bin Meng bmeng.cn@gmail.com + */ + +#include <common.h> +#include <dm.h> +#include <dm/test.h> +#include <dm/simple_bus.h> +#include <dm/uclass-internal.h> +#include <test/ut.h> + +static int dm_test_simple_bus(struct unit_test_state *uts) +{ + struct udevice *dev; + struct simple_bus_plat *plat; + + /* locate the dummy device @ translation-test node */ + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, &dev)); + ut_asserteq_str("dev@0,0", dev->name); + + /* locate the parent node which is a simple-bus */ + ut_assertnonnull(dev = dev_get_parent(dev)); + ut_asserteq_str("translation-test@8000", dev->name); + + ut_assertnonnull(plat = dev_get_uclass_plat(dev)); + ut_asserteq(0, plat->base); + ut_asserteq(0x8000, plat->target); + ut_asserteq(0x1000, plat->size); + + return 0; +} +DM_TEST(dm_test_simple_bus, UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);

QEMU ppce500 target can dynamically instantiate an eTSEC device on a platform bus if "-device eTSEC" is given to QEMU. It is presented as a "simple-bus" in the device tree, with an additional compatible string "qemu,platform".
Let's create a virtual memory mapping for it in misc_init_r(), in preparation to adding eTSEC support.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
---
Changes in v2: - turn on CONFIG_SIMPLE_BUS_CORRECT_RANGE in qemu-ppce500_defconfig
board/emulation/qemu-ppce500/Kconfig | 6 ++++++ board/emulation/qemu-ppce500/qemu-ppce500.c | 18 ++++++++++++++++++ configs/qemu-ppce500_defconfig | 1 + 3 files changed, 25 insertions(+)
diff --git a/board/emulation/qemu-ppce500/Kconfig b/board/emulation/qemu-ppce500/Kconfig index 4312d986d8..1c5aa18aa9 100644 --- a/board/emulation/qemu-ppce500/Kconfig +++ b/board/emulation/qemu-ppce500/Kconfig @@ -9,4 +9,10 @@ config SYS_VENDOR config SYS_CONFIG_NAME default "qemu-ppce500"
+config PLATFORM_BUS_MAP_ADDR + hex + default 0xf0000000 + help + The QEMU platform bus base mapped address in the virtual memory space. + endif diff --git a/board/emulation/qemu-ppce500/qemu-ppce500.c b/board/emulation/qemu-ppce500/qemu-ppce500.c index daa103c564..0960dd1f97 100644 --- a/board/emulation/qemu-ppce500/qemu-ppce500.c +++ b/board/emulation/qemu-ppce500/qemu-ppce500.c @@ -14,6 +14,8 @@ #include <net.h> #include <pci.h> #include <time.h> +#include <dm/simple_bus.h> +#include <dm/uclass-internal.h> #include <asm/global_data.h> #include <asm/processor.h> #include <asm/mmu.h> @@ -148,6 +150,22 @@ int misc_init_r(void) */ disable_tlb(find_tlb_idx((void *)CONFIG_SYS_TMPVIRT, 1));
+ /* + * Detect the presence of the platform bus node, and + * create a virtual memory mapping for it. + */ + for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev); + dev; + ret = uclass_find_next_device(&dev)) { + if (device_is_compatible(dev, "qemu,platform")) { + struct simple_bus_plat *plat = dev_get_uclass_plat(dev); + + assert(!tlb_map_range(CONFIG_PLATFORM_BUS_MAP_ADDR, + plat->target, plat->size, + TLB_MAP_IO)); + } + } + return 0; }
diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig index 536fe7d6e1..151834b4cf 100644 --- a/configs/qemu-ppce500_defconfig +++ b/configs/qemu-ppce500_defconfig @@ -28,6 +28,7 @@ CONFIG_OF_BOARD=y CONFIG_ENV_OVERWRITE=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM=y +CONFIG_SIMPLE_BUS_CORRECT_RANGE=y CONFIG_BLK=y CONFIG_HAVE_BLOCK_DEVICE=y CONFIG_MPC8XXX_GPIO=y

On Fri, Mar 12, 2021 at 09:36:00PM +0800, Bin Meng wrote:
QEMU ppce500 target can dynamically instantiate an eTSEC device on a platform bus if "-device eTSEC" is given to QEMU. It is presented as a "simple-bus" in the device tree, with an additional compatible string "qemu,platform".
Let's create a virtual memory mapping for it in misc_init_r(), in preparation to adding eTSEC support.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Changes in v2:
- turn on CONFIG_SIMPLE_BUS_CORRECT_RANGE in qemu-ppce500_defconfig
board/emulation/qemu-ppce500/Kconfig | 6 ++++++ board/emulation/qemu-ppce500/qemu-ppce500.c | 18 ++++++++++++++++++ configs/qemu-ppce500_defconfig | 1 + 3 files changed, 25 insertions(+)
diff --git a/board/emulation/qemu-ppce500/Kconfig b/board/emulation/qemu-ppce500/Kconfig index 4312d986d8..1c5aa18aa9 100644 --- a/board/emulation/qemu-ppce500/Kconfig +++ b/board/emulation/qemu-ppce500/Kconfig @@ -9,4 +9,10 @@ config SYS_VENDOR config SYS_CONFIG_NAME default "qemu-ppce500"
+config PLATFORM_BUS_MAP_ADDR
- hex
- default 0xf0000000
- help
The QEMU platform bus base mapped address in the virtual memory space.
endif diff --git a/board/emulation/qemu-ppce500/qemu-ppce500.c b/board/emulation/qemu-ppce500/qemu-ppce500.c index daa103c564..0960dd1f97 100644 --- a/board/emulation/qemu-ppce500/qemu-ppce500.c +++ b/board/emulation/qemu-ppce500/qemu-ppce500.c @@ -14,6 +14,8 @@ #include <net.h> #include <pci.h> #include <time.h> +#include <dm/simple_bus.h> +#include <dm/uclass-internal.h> #include <asm/global_data.h> #include <asm/processor.h> #include <asm/mmu.h> @@ -148,6 +150,22 @@ int misc_init_r(void) */ disable_tlb(find_tlb_idx((void *)CONFIG_SYS_TMPVIRT, 1));
- /*
* Detect the presence of the platform bus node, and
* create a virtual memory mapping for it.
*/
- for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
dev;
ret = uclass_find_next_device(&dev)) {
if (device_is_compatible(dev, "qemu,platform")) {
struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
assert(!tlb_map_range(CONFIG_PLATFORM_BUS_MAP_ADDR,
plat->target, plat->size,
TLB_MAP_IO));
A break here, maybe? If there are multiple qemu,platform nodes, your code will attempt to create multiple TLB mappings towards the same virtual address CONFIG_PLATFORM_BUS_MAP_ADDR, which will not work. So better avoid that.
And maybe you can refactor this into a dedicated function, similar to what exists for PCI.
}
- }
- return 0;
}
}
diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig index 536fe7d6e1..151834b4cf 100644 --- a/configs/qemu-ppce500_defconfig +++ b/configs/qemu-ppce500_defconfig @@ -28,6 +28,7 @@ CONFIG_OF_BOARD=y CONFIG_ENV_OVERWRITE=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM=y +CONFIG_SIMPLE_BUS_CORRECT_RANGE=y CONFIG_BLK=y CONFIG_HAVE_BLOCK_DEVICE=y CONFIG_MPC8XXX_GPIO=y -- 2.25.1

QEMU ppce500 target can dynamically instantiate an eTSEC device if "-device eTSEC" is given to QEMU. This commit enables eTSEC driver and the required fixed PHY driver to create a usable network configuration using eTSEC.
Unlike a real world 85xx board that usually stores the eTSEC MAC address in an EEPROM, CONFIG_NET_RANDOM_ETHADDR is required for QEMU otherwise U-Boot ethernet initialization complains no valid ethernet address is set.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
(no changes since v1)
configs/qemu-ppce500_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig index 151834b4cf..a1b9ea56ca 100644 --- a/configs/qemu-ppce500_defconfig +++ b/configs/qemu-ppce500_defconfig @@ -27,6 +27,7 @@ CONFIG_OF_CONTROL=y CONFIG_OF_BOARD=y CONFIG_ENV_OVERWRITE=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y +CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SIMPLE_BUS_CORRECT_RANGE=y CONFIG_BLK=y @@ -35,8 +36,11 @@ CONFIG_MPC8XXX_GPIO=y CONFIG_DM_I2C=y CONFIG_SYS_I2C_FSL=y # CONFIG_MMC is not set +CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_E1000=y +CONFIG_TSEC_ENET=y CONFIG_DM_PCI=y CONFIG_PCI_MPC85XX=y CONFIG_DM_RTC=y

On Fri, Mar 12, 2021 at 09:36:01PM +0800, Bin Meng wrote:
QEMU ppce500 target can dynamically instantiate an eTSEC device if "-device eTSEC" is given to QEMU. This commit enables eTSEC driver and the required fixed PHY driver to create a usable network configuration using eTSEC.
Unlike a real world 85xx board that usually stores the eTSEC MAC address in an EEPROM, CONFIG_NET_RANDOM_ETHADDR is required for QEMU otherwise U-Boot ethernet initialization complains no valid ethernet address is set.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

Document how to launch a QEMU session with eTSEC as a network device.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
---
(no changes since v1)
doc/board/emulation/qemu-ppce500.rst | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/doc/board/emulation/qemu-ppce500.rst b/doc/board/emulation/qemu-ppce500.rst index 0a5c86c61a..5de0aaf55d 100644 --- a/doc/board/emulation/qemu-ppce500.rst +++ b/doc/board/emulation/qemu-ppce500.rst @@ -70,6 +70,11 @@ interface at PCI address 0.1.0, but we can switch that to an e1000 NIC by:: $ qemu-system-ppc -nographic -machine ppce500 -bios u-boot \ -nic tap,ifname=tap0,script=no,downscript=no,model=e1000
+The QEMU ppce500 machine can also dynamically instantiate an eTSEC device if +"-device eTSEC" is given to QEMU:: + + -netdev tap,ifname=tap0,script=no,downscript=no,id=net0 -device eTSEC,netdev=net0 + VirtIO BLK driver is also enabled to support booting from a disk image where a kernel image is stored. Append the following to QEMU::

On Fri, Mar 12, 2021 at 09:36:02PM +0800, Bin Meng wrote:
Document how to launch a QEMU session with eTSEC as a network device.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
Reviewed-by: Vladimir Oltean vladimir.oltean@nxp.com

On Fri, Mar 12, 2021 at 9:36 PM Bin Meng bmeng.cn@gmail.com wrote:
QEMU ppce500 machine can dynamically instantiate an eTSEC device if "-device eTSEC" is given to QEMU.
This series updates the fixed-link ethernet PHY driver as well as the Freescale eTSEC driver to support the QEMU ppce500 board.
3 patches related to fixed phy in v1 are dropped in v2 as the changes were done by Vladimir's fixed phy & Sandbox DSA series [1]. Vladimir's series is now included in v2, and updated as needed.
This cover letter is cc'ed to QEMU mailing list for a heads-up. A future patch will be sent to QEMU mailing list to bring its in-tree U-Boot source codes up-to-date.
This series is avaiable at u-boot-x86/eTSEC for testing.
[1] https://patchwork.ozlabs.org/project/uboot/patch/20210216224804.3355044-2-ol...
Changes in v2:
- move device tree parsing from xilinxgmiitorgmii_probe() to xilinxgmiitorgmii_config() and use OF APIs
- new patch: split from 20210216224804.3355044-4-olteanv@gmail.com
- include <asm/global_data.h>
- use a Kconfig option CONFIG_SIMPLE_BUS_CORRECT_RANGE to control the new behavior for boards that want this
- default y if SANDBOX for CONFIG_SIMPLE_BUS_CORRECT_RANGE
- turn on CONFIG_SIMPLE_BUS_CORRECT_RANGE in qemu-ppce500_defconfig
Azure results: PASS https://dev.azure.com/bmeng/GitHub/_build/results?buildId=340&view=resul...
participants (4)
-
Bin Meng
-
Michal Simek
-
Simon Glass
-
Vladimir Oltean