ppc: qemu: Add eTSEC support
Subsystems (4)
v3 cover ppc: qemu: Add eTSEC support
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 to avoid dependencies.
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.
Azure results: PASS
https://dev.azure.com/bmeng/GitHub/_build/results?buildId=342&view=results
This series is avaiable at u-boot-x86/eTSEC for testing.
[1] https://patchwork.ozlabs.org/project/uboot/patch/20210216224804.3355044-2-olteanv at gmail.com/
Changes in v3:
- mention that U-Boot deliberately ignores the 'phy_id' and unconditionally uses PHY_FIXED_ID
- update the code logic to prefer the new binding if both new and old bindings exist
- sort variable definitions by line length
- reuse the sandbox dsa nodes for the fixed-link testing
- new patch: net: tsec: Use map_physmem() directly instead of dev_remap_addr()
- add "ranges" in the alternate example
- keep the variable definitions sorted
- invert the strncmp logic to reduce the indentation level
- add a comment to mention only the first "queue-group" is used
- call the same map_physmem() in the common code path
- extract platform bus virtual memory mapping codes to a new routine
- add a "break" in case multiple "qemu,platform" nodes exist
Changes in v2:
- move device tree parsing from xilinxgmiitorgmii_probe() to xilinxgmiitorgmii_config() and use OF APIs
- new patch: split from <[email protected]>
- 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 (18):
dt-bindings: net: Add the old DT bindings for "fixed-link"
of: extra: Introduce ofnode_phy_is_fixed_link() API
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
test: dm: Add a case to test ofnode_phy_is_fixed_link()
net: tsec: Use map_physmem() directly instead of dev_remap_addr()
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 | 44 +++++ board/emulation/qemu-ppce500/Kconfig | 6 + board/emulation/qemu-ppce500/qemu-ppce500.c | 31 +++ configs/qemu-ppce500_defconfig | 5 + doc/board/emulation/qemu-ppce500.rst | 5 + doc/device-tree-bindings/net/fixed-link.txt | 48 +++-- doc/device-tree-bindings/net/fsl-tsec-phy.txt | 16 +- drivers/core/Kconfig | 14 ++ drivers/core/of_extra.c | 23 +++ 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 | 36 +++- include/configs/sandbox.h | 2 + include/dm/of_extra.h | 20 ++ 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, 690 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
Signature · 1 line
2.25.1
PATCH v3 1/22 dt-bindings: net: Add the old DT bindings for "fixed-link"
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.
---
Changes in v3:
- mention that U-Boot deliberately ignores the 'phy_id' and unconditionally uses PHY_FIXED_ID
doc/device-tree-bindings/net/fixed-link.txt | 48 +++++++++++++++------ 1 file changed, 36 insertions(+), 12 deletions(-)
doc/device-tree-bindings/net/fixed-link.txt +36 -12
@@ -5,21 +5,37 @@ 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. Note U-Boot deliberately ignores the 'phy_id' and + unconditionally uses PHY_FIXED_ID. + * '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 at 0 { ... fixed-link {
@@ -28,3 +44,11 @@ ethernet at 0 { }; ... }; + +The old binding: + +ethernet at 0 { + ... + fixed-link = <0 1 1000 0 0>; + ... +};
Signature · 1 line
2.25.1
PATCH v3 2/22 of: extra: Introduce ofnode_phy_is_fixed_link() API
In reply to Bin MengIntroduce 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
---
Changes in v3:
- update the code logic to prefer the new binding if both new and old bindings exist
drivers/core/of_extra.c | 23 +++++++++++++++++++++++ include/dm/of_extra.h | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+)
drivers/core/of_extra.c +23 -0
@@ -130,3 +130,26 @@ 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) +{ +ofnode node, subnode; +int len; + + subnode =ofnode_find_subnode (eth_node,"fixed-link" ); +if (ofnode_valid (subnode)) { +/* new binding */ + node = subnode; + }else if (ofnode_get_property (eth_node,"fixed-link" , &len) && + len == (5 *sizeof (__be32))) { +/* old binding */ + node = eth_node; + }else { +return false; + } + +if (phy_node) + *phy_node = node; + +return true; +}
include/dm/of_extra.h +20 -0
@@ -86,4 +86,24 @@ 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 +* +* If both new and old bindings exist, the new one is preferred. +* +* @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
Signature · 1 line
2.25.1
PATCH v3 2/22 of: extra: Introduce ofnode_phy_is_fixed_link() API
Quoted 11 lines · Bin Meng
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
Quoted 4 lines
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
PATCH v3 3/22 dm: mdio: Use ofnode_phy_is_fixed_link() API
In reply to Bin MengSwitch to use the ofnode_phy_is_fixed_link() API which can support both the new and old DT bindings.
---
(no changes since v1)
net/mdio-uclass.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mdio-uclass.c +2 -1
@@ -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; }
Signature · 1 line
2.25.1
PATCH v3 4/22 net: phy: fixed: Be compatible with live OF tree
In reply to Bin MengFrom: Vladimir Oltean <[email protected]>
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.
Message-Id: <[email protected]>
---
(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(-)
drivers/net/phy/fixed.c +17 -9
@@ -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, };
drivers/net/phy/phy.c +15 -15
@@ -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; }
net/mdio-uclass.c +4 -2
@@ -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; }
Signature · 1 line
2.25.1
PATCH v3 5/22 net: phy: fixed: Drop #ifdef CONFIG_DM_ETH around phy_connect_fixed
In reply to Bin MengFrom: Vladimir Oltean <[email protected]>
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).
Message-Id: <[email protected]>
---
(no changes since v1)
drivers/net/phy/phy.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/phy/phy.c +0 -6
@@ -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;
Signature · 1 line
2.25.1
PATCH v3 6/22 net: phy: xilinx: Be compatible with live OF tree
In reply to Bin MengFollowing 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.
---
(no changes since v2)
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(-)
drivers/net/phy/phy.c +10 -13
@@ -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;
drivers/net/phy/xilinx_gmii2rgmii.c +30 -31
81 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 7/22 net: phy: xilinx: Drop #ifdef CONFIG_DM_ETH around phy_connect_gmii2rgmii()
In reply to Bin MengAt 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.
---
(no changes since v1)
drivers/net/phy/Kconfig | 1 + drivers/net/phy/phy.c | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/net/phy/Kconfig +1 -0
@@ -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
drivers/net/phy/phy.c +0 -6
@@ -942,15 +942,9 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) }#ifdef CONFIG_PHY_XILINX_GMII2RGMII -#ifdef CONFIG_DM_ETHstatic 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);
Signature · 1 line
2.25.1
PATCH v3 8/22 net: phy: Simplify the logic of phy_connect_fixed()
In reply to Bin MengSimplify 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.
---
(no changes since v1)
drivers/net/phy/phy.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/phy/phy.c +8 -8
@@ -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; }
Signature · 1 line
2.25.1
PATCH v3 9/22 net: phy: fixed: Make driver ops static
In reply to Bin MengThe PHY driver ops should be made static.
---
(no changes since v1)
drivers/net/phy/fixed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/phy/fixed.c +4 -4
@@ -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 ; }
Signature · 1 line
2.25.1
PATCH v3 10/22 net: phy: fixed: Add the missing ending newline
In reply to Bin MengThe printf statement doesn't end with a newline. Add it.
---
(no changes since v1)
drivers/net/phy/fixed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/fixed.c +1 -1
@@ -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 ; }
Signature · 1 line
2.25.1
PATCH v3 11/22 net: phy: fixed: Support the old DT binding
In reply to Bin MengUpdate fixedphy_probe() to support the old DT binding.
---
Changes in v3:
- sort variable definitions by line length
drivers/net/phy/fixed.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/net/phy/fixed.c +23 -3
@@ -27,6 +27,8 @@ static int fixedphy_config(struct phy_device *phydev) {ofnode node =phy_get_ofnode (phydev);struct fixed_link *priv; +bool old_binding = false; +u32 old_val[5 ];u32 val;if (!ofnode_valid (node))
@@ -34,6 +36,18 @@ static int fixedphy_config(struct phy_device *phydev)/* 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 ; }
Signature · 1 line
2.25.1
PATCH v3 12/22 net: tsec: Use dm_eth_phy_connect() directly for the DM case
In reply to Bin MengFrom: Vladimir Oltean <[email protected]>
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.
Message-Id: <[email protected]>
---
(no changes since v2)
Changes in v2:
- new patch: split from <[email protected]>
drivers/net/tsec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/tsec.c +1 -5
@@ -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);
Signature · 1 line
2.25.1
PATCH v3 13/22 sandbox: Add a DSA sandbox driver and unit test
In reply to Bin MengFrom: Claudiu Manoil <[email protected]>
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.
Message-Id: <[email protected]>
---
(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
arch/Kconfig +2 -0
@@ -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"
arch/sandbox/dts/test.dts +48 -0
61 lines not on this page · raw message
drivers/net/Kconfig +9 -0
@@ -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
drivers/net/Makefile +1 -0
@@ -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
drivers/net/dsa_sandbox.c new file +179 -0
179 lines not on this page · raw message
include/configs/sandbox.h +2 -0
@@ -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"
test/dm/Makefile +1 -0
@@ -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
test/dm/dsa.c new file +82 -0
82 lines not on this page · raw message
test/dm/eth.c +5 -5
@@ -53,8 +53,8 @@ static int dm_test_eth_alias(struct unit_test_state *uts)ut_assertok (net_loop (PING ));ut_asserteq_str ("eth at 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 at 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 at 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 at 10004000" ); +env_set ("ethact" ,"lan1" );env_set ("netretry" ,"no" );sandbox_eth_skip_timeout ();ut_asserteq (-ENONET ,net_loop (PING )); -ut_asserteq_str ("eth at 10004000" ,env_get ("ethact" )); +ut_asserteq_str ("lan1" ,env_get ("ethact" ));return 0 ; }
Signature · 1 line
2.25.1
PATCH v3 14/22 test: dm: Add a case to test ofnode_phy_is_fixed_link()
In reply to Bin MengThis adds a test case to test the new ofnode_phy_is_fixed_link() API. Both the new and old DT bindings are covered.
---
Changes in v3:
- reuse the sandbox dsa nodes for the fixed-link testing
arch/sandbox/dts/test.dts | 6 +----- test/dm/of_extra.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-)
arch/sandbox/dts/test.dts +1 -5
@@ -507,11 +507,7 @@ reg = <1>; label = "lan1"; phy-mode = "rgmii-txid"; - - fixed-link { - speed = <100>; - full-duplex; - }; + fixed-link = <0 1 100 0 0>; }; port at 2 {
test/dm/of_extra.c +18 -0
@@ -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 ("/dsa-test/ports/port at 0" ); +ut_assert (ofnode_phy_is_fixed_link (eth_node, &phy_node)); + node =ofnode_path ("/dsa-test/ports/port at 0/fixed-link" ); +ut_asserteq_mem (&phy_node, &node,sizeof (ofnode)); + + eth_node =ofnode_path ("/dsa-test/ports/port at 1" ); +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 );
Signature · 1 line
2.25.1
PATCH v3 14/22 test: dm: Add a case to test ofnode_phy_is_fixed_link()
Quoted 7 lines · Bin Meng
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 <[email protected]>Reviewed-by Simon Glass <[email protected]>---
PATCH v3 15/22 net: tsec: Use map_physmem() directly instead of dev_remap_addr()
In reply to Bin Mengdev_remap_addr() eventually calls dev_read_addr_index(), while pdata->iobase holds the return value of dev_read_addr() that calls dev_read_addr_index() too. Such duplication can be avoided by using map_physmem() directly.
---
Changes in v3:
- new patch: net: tsec: Use map_physmem() directly instead of dev_remap_addr()
drivers/net/tsec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/tsec.c +3 -1
@@ -833,7 +833,9 @@ int tsec_probe(struct udevice *dev) 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 ) +return -ENOENT ; + priv->regs =map_physmem (pdata->iobase,0 ,MAP_NOCACHE ); ret =dev_read_phandle_with_args (dev,"tbi-handle" ,NULL ,0 ,0 , &phandle_args);
Signature · 1 line
2.25.1
PATCH v3 15/22 net: tsec: Use map_physmem() directly instead of dev_remap_addr()
Quoted 8 lines · Bin Meng
dev_remap_addr()eventually callsdev_read_addr_index(), whilepdata->iobaseholds the return value ofdev_read_addr()that callsdev_read_addr_index()too. Such duplication can be avoided by usingmap_physmem()directly.Signed-off-by Bin Meng <[email protected]>---
PATCH v3 16/22 dt-bindings: net: Update Freescale TSEC to support "queue-group"
In reply to Bin MengAt 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.
---
Changes in v3:
- add "ranges" in the alternate example
doc/device-tree-bindings/net/fsl-tsec-phy.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
doc/device-tree-bindings/net/fsl-tsec-phy.txt +15 -1
@@ -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,18 @@ Example: phy-connection-type = "sgmii"; }; +An alternate description with "queue-group" subnode example: + ethernet at 24000 { + compatible = "fsl,etsec2"; + phy-handle = <&phy0>; + phy-connection-type = "sgmii"; + ranges; + + 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).
Signature · 1 line
2.25.1
PATCH v3 16/22 dt-bindings: net: Update Freescale TSEC to support "queue-group"
Quoted 30 lines · Bin Meng
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.cUpdate our DT bindings to describe this alternate description.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Ramon Fried <[email protected]>---
Changes in v3:
- add "ranges" in the alternate exampledoc/device-tree-bindings/net/fsl-tsec-phy.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)doc/device-tree-bindings/net/fsl-tsec-phy.txt +0
-0
doc/device-tree-bindings/net/fsl-tsec-phy.txt line 8
Quoted 7 lines
doc/device-tree-bindings/net/fsl-tsec-phy.txt +3
-1@@ -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.
You added 'ranges' to the example, but you didn't say it is required for the alternate description (minor detail).
Either way:
Quoted 25 lines
doc/device-tree-bindings/net/fsl-tsec-phy.txt +12
-0- 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,18 @@ Example: phy-connection-type = "sgmii"; }; +An alternate description with "queue-group" subnode example: + ethernet at 24000 { + compatible = "fsl,etsec2"; + phy-handle = <&phy0>; + phy-connection-type = "sgmii"; + ranges; + + 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).Signature · 1 line
2.25.1
PATCH v3 17/22 net: tsec: Support <reg> property from the subnode "queue-group"
In reply to Bin MengAt 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.
---
Changes in v3:
- keep the variable definitions sorted
- invert the strncmp logic to reduce the indentation level
- add a comment to mention only the first "queue-group" is used
- call the same map_physmem() in the common code path
drivers/net/tsec.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/net/tsec.c +27 -3
@@ -826,15 +826,39 @@ int tsec_probe(struct udevice *dev)u32 tbiaddr =CONFIG_SYS_TBIPA_VALUE ;struct tsec_data *data;const char *phy_mode; +ofnode parent, child;fdt_addr_t reg; -ofnode parent;int ret; data = (struct tsec_data *)dev_get_driver_data (dev); pdata->iobase = (phys_addr_t )dev_read_addr (dev); -if (pdata->iobase ==FDT_ADDR_T_NONE ) -return -ENOENT ; +if (pdata->iobase ==FDT_ADDR_T_NONE ) { +ofnode_for_each_subnode (child,dev_ofnode (dev)) { +if (strncmp (ofnode_get_name (child),"queue-group" , +strlen ("queue-group" ))) +continue ; + + reg =ofnode_get_addr (child); +if (reg ==FDT_ADDR_T_NONE ) { +printf ("No 'reg' property of <queue-group>\n" ); +return -ENOENT ; + } + pdata->iobase = reg; + +/* +* if there are multiple queue groups, +* only the first one is used. +*/ +break ; + } + +if (!ofnode_valid (child)) { +printf ("No child node for <queue-group>?\n" ); +return -ENOENT ; + } + } + priv->regs =map_physmem (pdata->iobase,0 ,MAP_NOCACHE ); ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0,
Signature · 1 line
2.25.1
PATCH v3 17/22 net: tsec: Support <reg> property from the subnode "queue-group"
Quoted 7 lines · Bin Meng
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.
Quoted 6 lines
This commit updates the tsec driver to handle this case.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Ramon Fried <[email protected]>---
PATCH v3 18/22 dm: core: Correctly read <ranges> of simple-bus
In reply to Bin MengAt 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.
---
(no changes since v2)
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(-)
drivers/core/Kconfig +13 -0
@@ -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
drivers/core/simple-bus.c +25 -7
@@ -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);
include/dm/simple_bus.h +3 -3
@@ -7,9 +7,9 @@#define __DM_SIMPLE_BUS_Hstruct simple_bus_plat { -u32 base; -u32 size; -u32 target; +fdt_addr_t base; +fdt_size_t size; +fdt_addr_t target; };#endif
Signature · 1 line
2.25.1
PATCH v3 19/22 test: dm: Add a test case for simple-bus <ranges>
In reply to Bin MengThis adds a test case to verify reading <ranges> of a simple-bus is working as expected.
---
(no changes since v2)
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
drivers/core/Kconfig +1 -0
@@ -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
test/dm/Makefile +1 -0
@@ -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
test/dm/simple-bus.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2021, Bin Meng <[email protected]> +*/ + +#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 at 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 at 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 );
Signature · 1 line
2.25.1
PATCH v3 20/22 ppc: qemu: Create a virtual memory mapping of the platform bus
In reply to Bin MengQEMU 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.
---
Changes in v3:
- extract platform bus virtual memory mapping codes to a new routine
- add a "break" in case multiple "qemu,platform" nodes exist
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 | 31 +++++++++++++++++++++ configs/qemu-ppce500_defconfig | 1 + 3 files changed, 38 insertions(+)
board/emulation/qemu-ppce500/Kconfig +6 -0
@@ -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
board/emulation/qemu-ppce500/qemu-ppce500.c +31 -0
@@ -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>
@@ -109,6 +111,19 @@ static int pci_map_region(phys_addr_t paddr, phys_size_t size, ulong *pmap_addr)return 0 ; } +static int platform_bus_map_region (ulong map_addr,phys_addr_t paddr, +phys_size_t size) +{ +/* Align map_addr */ + map_addr += size -1 ; + map_addr &= ~(size -1 ); + +/* Map virtual memory for range */ +assert (!tlb_map_range (map_addr, paddr, size,TLB_MAP_IO )); + +return 0 ; +} +int misc_init_r (void ) {struct udevice *dev;
@@ -148,6 +163,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); + +platform_bus_map_region (CONFIG_PLATFORM_BUS_MAP_ADDR , + plat->target, plat->size); +break ; + } + } +return 0 ; }
configs/qemu-ppce500_defconfig +1 -0
@@ -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
Signature · 1 line
2.25.1
PATCH v3 20/22 ppc: qemu: Create a virtual memory mapping of the platform bus
board/emulation/qemu-ppce500/qemu-ppce500.c static int pci_map_region(phys_addr_t paddr, phys_size_t size, ulong *pmap_addr) · line 115
Quoted 13 lines · Bin Meng
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 <[email protected]>---
board/emulation/qemu-ppce500/qemu-ppce500.c +2
-0+static int platform_bus_map_region (ulong map_addr,phys_addr_t paddr, +phys_size_t size)
Function could have been void (minor detail).
Quoted 26 lines
board/emulation/qemu-ppce500/qemu-ppce500.c +19
-0+{ +/* Align map_addr */ + map_addr += size -1 ; + map_addr &= ~(size -1 ); + +/* Map virtual memory for range */ +assert (!tlb_map_range (map_addr, paddr, size,TLB_MAP_IO )); + +return 0 ; +} +int misc_init_r (void ) {struct udevice *dev;@@ -148,6 +163,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" )) {
board/emulation/qemu-ppce500/qemu-ppce500.c int misc_init_r(void) · line 183
Quoted 10 lines
board/emulation/qemu-ppce500/qemu-ppce500.c +8
-0+struct simple_bus_plat *plat =dev_get_uclass_plat (dev); + +platform_bus_map_region (CONFIG_PLATFORM_BUS_MAP_ADDR , + plat->target, plat->size); +break ; + } + } +return 0 ; }
PATCH v3 21/22 ppc: qemu: Enable eTSEC support
In reply to Bin MengQEMU 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.
---
(no changes since v1)
configs/qemu-ppce500_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
configs/qemu-ppce500_defconfig +4 -0
@@ -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
Signature · 1 line
2.25.1
PATCH v3 22/22 doc: board: qemu-ppce500: Document eTSEC usage
In reply to Bin MengDocument how to launch a QEMU session with eTSEC as a network device.
---
(no changes since v1)
doc/board/emulation/qemu-ppce500.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/board/emulation/qemu-ppce500.rst +5 -0
@@ -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::
Signature · 1 line
2.25.1