dm: uclass: don't assign aliased seq numbers
v7 cover dm: uclass: don't assign aliased seq numbers
If there are aliases for an uclass, set the base for the "dynamically" allocated numbers next to the highest alias.
The actual patch is 3, the first two patches will fix some breakage which would be introduced with patch 3.
changes since v6:
- added new patch to fix dev_read_alias_highest_id()
changes since v5:
- added test cases for usb dt node patch
changes since v4:
- new patch to fix the ethernet0 alias on Raspberry Pis. This has never been working, but wasn't a problem until recently. Patch 3 changes the allocation of the numbers and reserves possible aliases.
changes since v3:
- dev_read_alias_highest_id() is only available if CONFIG_OF_CONTROL is set. Thus added an additional condition "CONFIG_IS_ENABLED(OF_CONTROL)", thanks Simon.
changes since v2:
- adapt/new test cases, thanks Simon
changes since v1:
- move notice about superfluous commits from commit message to this section.
- fix the comment style
Michael Walle (3):
usb: provide a device tree node to USB devices
dm: core: fix dev_read_alias_highest_id() without libfdt
dm: uclass: don't assign aliased seq numbers
arch/sandbox/dts/test.dts | 13 +++++++++-- drivers/core/uclass.c | 21 +++++++++++++----- drivers/usb/host/usb-uclass.c | 41 ++++++++++++++++++++++++++++++----- include/configs/sandbox.h | 6 ++--- include/dm/read.h | 2 ++ test/dm/eth.c | 14 ++++++------ test/dm/test-fdt.c | 22 ++++++++++++++----- test/dm/usb.c | 22 +++++++++++++++++++ 8 files changed, 113 insertions(+), 28 deletions(-)
Signature · 1 line
2.20.1
PATCH v7 1/3 usb: provide a device tree node to USB devices
It is possible to specify a device tree node for an USB device. This is useful if you have a static USB setup and want to use aliases which point to these nodes, like on the Raspberry Pi.
The nodes are matched against their hub port number, the compatible strings are not matched for now.
--- arch/sandbox/dts/test.dts | 9 ++++++++ drivers/usb/host/usb-uclass.c | 41 ++++++++++++++++++++++++++++++----- test/dm/usb.c | 22 +++++++++++++++++++ 3 files changed, 67 insertions(+), 5 deletions(-)
arch/sandbox/dts/test.dts +9 -0
@@ -810,6 +810,8 @@ hub { compatible = "usb-hub"; usb,device-class = <9>; + #address-cells = <1>; + #size-cells = <0>; hub-emul { compatible = "sandbox,usb-hub"; #address-cells = <1>;
@@ -838,6 +840,13 @@ }; }; + + usbstor at 1 { + reg = <1>; + }; + usbstor at 3 { + reg = <3>; + }; }; };
drivers/usb/host/usb-uclass.c +36 -5
72 lines not on this page · raw message
test/dm/usb.c +22 -0
@@ -78,6 +78,28 @@ static int dm_test_usb_multi(struct unit_test_state *uts) }DM_TEST (dm_test_usb_multi,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +/* test that we have an associated ofnode with the usb device */ +static int dm_test_usb_fdt_node (struct unit_test_state *uts) +{ +struct udevice *dev; +ofnode node; + +state_set_skip_delays (true); +ut_assertok (usb_init ()); +ut_assertok (uclass_get_device (UCLASS_MASS_STORAGE ,0 , &dev)); + node =ofnode_path ("/usb at 1/hub/usbstor at 1" ); +ut_asserteq (1 ,ofnode_equal (node,dev_ofnode (dev))); +ut_assertok (uclass_get_device (UCLASS_MASS_STORAGE ,1 , &dev)); +ut_asserteq (1 ,ofnode_equal (ofnode_null (),dev_ofnode (dev))); +ut_assertok (uclass_get_device (UCLASS_MASS_STORAGE ,2 , &dev)); + node =ofnode_path ("/usb at 1/hub/usbstor at 3" ); +ut_asserteq (1 ,ofnode_equal (node,dev_ofnode (dev))); +ut_assertok (usb_stop ()); + +return 0 ; +} +DM_TEST (dm_test_usb_fdt_node,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +static int count_usb_devices (void ) {struct udevice *hub;
Signature · 1 line
2.20.1
PATCH v7 1/3 usb: provide a device tree node to USB devices
It is possible to specify a device tree node for an USB device. This is useful if you have a static USB setup and want to use aliases which point to these nodes, like on the Raspberry Pi.
The nodes are matched against their hub port number, the compatible strings are not matched for now.
--- arch/sandbox/dts/test.dts | 9 ++++++++ drivers/usb/host/usb-uclass.c | 41 ++++++++++++++++++++++++++++++----- test/dm/usb.c | 22 +++++++++++++++++++ 3 files changed, 67 insertions(+), 5 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v7 2/3 dm: core: fix dev_read_alias_highest_id() without libfdt
In reply to Michael WalleIf CONFIG_DM_DEV_READ_INLINE is set, dev_read_alias_highest_id() calls libfdt_get_highest_id(). But this function is only available if we have libfdt compiled in. If its not available return -1, which matches the return code for no alias found.
This fixes the following error on omapl138_lcdk:
arm-linux-gnueabi-ld.bfd: drivers/built-in.o: in function `dev_read_alias_highest_id':/home/mw/repo/u-boot/include/dm/read.h:986: undefined reference to `fdtdec_get_alias_highest_id'
--- include/dm/read.h | 2 ++ 1 file changed, 2 insertions(+)
include/dm/read.h +2 -0
@@ -983,6 +983,8 @@ static inline u64 dev_translate_dma_address(const struct udevice *dev,static inline int dev_read_alias_highest_id (const char *stem) { +if (!CONFIG_IS_ENABLED (OF_LIBFDT )) +return -1 ;return fdtdec_get_alias_highest_id (gd->fdt_blob, stem); }
Signature · 1 line
2.20.1
PATCH v7 2/3 dm: core: fix dev_read_alias_highest_id() without libfdt
Quoted 6 lines · Michael Walle
If
CONFIG_DM_DEV_READ_INLINEis set,dev_read_alias_highest_id()callslibfdt_get_highest_id(). But this function is only available if we have libfdt compiled in. If its not available return -1, which matches the return code for no alias found.
Quoted 8 lines
This fixes the following error on
omapl138_lcdk:
arm-linux-gnueabi-ld.bfd:drivers/built-in.o: in function `dev_read_alias_highest_id':/home/mw/repo/u-boot/include/dm/read.h:986: undefined reference to `fdtdec_get_alias_highest_id'Signed-off-by Michael Walle <[email protected]>--- include/dm/read.h | 2 ++ 1 file changed, 2 insertions(+)
PATCH v7 2/3 dm: core: fix dev_read_alias_highest_id() without libfdt
Quoted 6 lines · Michael Walle
If
CONFIG_DM_DEV_READ_INLINEis set,dev_read_alias_highest_id()callslibfdt_get_highest_id(). But this function is only available if we have libfdt compiled in. If its not available return -1, which matches the return code for no alias found.
Quoted 8 lines
This fixes the following error on
omapl138_lcdk:
arm-linux-gnueabi-ld.bfd:drivers/built-in.o: in function `dev_read_alias_highest_id':/home/mw/repo/u-boot/include/dm/read.h:986: undefined reference to `fdtdec_get_alias_highest_id'Signed-off-by Michael Walle <[email protected]>--- include/dm/read.h | 2 ++ 1 file changed, 2 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v7 3/3 dm: uclass: don't assign aliased seq numbers
In reply to Michael WalleIf there are aliases for an uclass, set the base for the "dynamically" allocated numbers next to the highest alias.
Please note, that this might lead to holes in the sequences, depending on the device tree. For example if there is only an alias "ethernet1", the next device seq number would be 2.
In particular this fixes a problem with boards which are using ethernet aliases but also might have network add-in cards like the E1000. If the board is started with the add-in card and depending on the order of the drivers, the E1000 might occupy the first ethernet device and mess up all the hardware addresses, because the devices are now shifted by one.
Also adapt the test cases to the new handling and add test cases checking the holes in the seq numbers.
--- arch/sandbox/dts/test.dts | 4 ++-- drivers/core/uclass.c | 21 +++++++++++++++------ include/configs/sandbox.h | 6 +++--- test/dm/eth.c | 14 +++++++------- test/dm/test-fdt.c | 22 +++++++++++++++++----- 5 files changed, 44 insertions(+), 23 deletions(-)
arch/sandbox/dts/test.dts +2 -2
@@ -23,8 +23,8 @@ pci0 = &pci0; pci1 = &pci1; pci2 = &pci2; - remoteproc1 = &rproc_1; - remoteproc2 = &rproc_2; + remoteproc0 = &rproc_1; + remoteproc1 = &rproc_2; rtc0 = &rtc_0; rtc1 = &rtc_1; spi0 = "/spi at 0";
drivers/core/uclass.c +15 -6
@@ -689,13 +689,14 @@ int uclass_unbind_device(struct udevice *dev)int uclass_resolve_seq (struct udevice *dev) { +struct uclass *uc = dev->uclass; +struct uclass_driver *uc_drv = uc->uc_drv;struct udevice *dup; -int seq; +int seq =0 ;int ret;assert (dev->seq ==-1 ); - ret =uclass_find_device_by_seq (dev->uclass->uc_drv->id, dev->req_seq, - false, &dup); + ret =uclass_find_device_by_seq (uc_drv->id, dev->req_seq, false, &dup);if (!ret) {dm_warn ("Device '%s': seq %d is in use by '%s'\n" , dev->name, dev->req_seq, dup->name);
@@ -707,9 +708,17 @@ int uclass_resolve_seq(struct udevice *dev)return ret; } -for (seq =0 ; seq <DM_MAX_SEQ ; seq++) { - ret =uclass_find_device_by_seq (dev->uclass->uc_drv->id, seq, - false, &dup); +if (CONFIG_IS_ENABLED (OF_CONTROL ) &&CONFIG_IS_ENABLED (DM_SEQ_ALIAS ) && + (uc_drv->flags &DM_UC_FLAG_SEQ_ALIAS )) { +/* +* dev_read_alias_highest_id() will return -1 if there no +* alias. Thus we can always add one. +*/ + seq =dev_read_alias_highest_id (uc_drv->name) +1 ; + } + +for (; seq <DM_MAX_SEQ ; seq++) { + ret =uclass_find_device_by_seq (uc_drv->id, seq, false, &dup);if (ret == -ENODEV )break ;if (ret)
include/configs/sandbox.h +3 -3
@@ -95,9 +95,9 @@#endif #define SANDBOX_ETH_SETTINGS "ethaddr=00:00:11:22:33:44\0" \ - "eth1addr=00:00:11:22:33:45\0" \ - "eth3addr=00:00:11:22:33:46\0" \ - "eth5addr=00:00:11:22:33:47\0" \ + "eth3addr=00:00:11:22:33:45\0" \ + "eth5addr=00:00:11:22:33:46\0" \ + "eth6addr=00:00:11:22:33:47\0" \ "ipaddr=1.2.3.4\0"#define MEM_LAYOUT_ENV_SETTINGS \
test/dm/eth.c +7 -7
@@ -48,7 +48,7 @@ static int dm_test_eth_alias(struct unit_test_state *uts)ut_assertok (net_loop (PING ));ut_asserteq_str ("eth at 10002000" ,env_get ("ethact" )); -env_set ("ethact" ,"eth1" ); +env_set ("ethact" ,"eth6" );ut_assertok (net_loop (PING ));ut_asserteq_str ("eth at 10004000" ,env_get ("ethact" ));
@@ -105,7 +105,7 @@ static int dm_test_eth_act(struct unit_test_state *uts)const char *ethname[DM_TEST_ETH_NUM ] = {"eth at 10002000" ,"eth at 10003000" ,"sbe5" ,"eth at 10004000" };const char *addrname[DM_TEST_ETH_NUM ] = {"ethaddr" ,"eth5addr" , -"eth3addr" ,"eth1addr" }; +"eth3addr" ,"eth6addr" };char ethaddr[DM_TEST_ETH_NUM ][18 ];int i;
@@ -188,15 +188,15 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)/* Invalidate eth1's MAC address */ memset (ethaddr,'\0' ,sizeof (ethaddr)); -strncpy (ethaddr,env_get ("eth1addr" ),17 ); -/* Must disable access protection for eth1addr before clearing */ -env_set (".flags" ,"eth1addr" ); -env_set ("eth1addr" ,NULL ); +strncpy (ethaddr,env_get ("eth6addr" ),17 ); +/* Must disable access protection for eth6addr before clearing */ +env_set (".flags" ,"eth6addr" ); +env_set ("eth6addr" ,NULL ); retval =_dm_test_eth_rotate1 (uts);/* Restore the env */ -env_set ("eth1addr" , ethaddr); +env_set ("eth6addr" , ethaddr);env_set ("ethrotate" ,NULL );if (!retval) {
test/dm/test-fdt.c +17 -5
@@ -361,20 +361,32 @@ static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)ut_assertok (uclass_get_device (UCLASS_TEST_FDT ,2 , &dev));ut_asserteq_str ("d-test" , dev->name); -/* d-test actually gets 0 */ -ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,0 , &dev)); +/* +* d-test actually gets 9, because thats the next free one after the +* aliases. +*/ +ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,9 , &dev));ut_asserteq_str ("d-test" , dev->name); -/* initially no one wants seq 1 */ -ut_asserteq (-ENODEV ,uclass_get_device_by_seq (UCLASS_TEST_FDT ,1 , +/* initially no one wants seq 10 */ +ut_asserteq (-ENODEV ,uclass_get_device_by_seq (UCLASS_TEST_FDT ,10 , &dev));ut_assertok (uclass_get_device (UCLASS_TEST_FDT ,0 , &dev));ut_assertok (uclass_get_device (UCLASS_TEST_FDT ,4 , &dev));/* But now that it is probed, we can find it */ -ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,1 , &dev)); +ut_assertok (uclass_get_device_by_seq (UCLASS_TEST_FDT ,10 , &dev));ut_asserteq_str ("f-test" , dev->name); +/* +* And we should still have holes in our sequence numbers, that is 2 +* and 4 should not be used. +*/ +ut_asserteq (-ENODEV ,uclass_find_device_by_seq (UCLASS_TEST_FDT ,2 , + true, &dev)); +ut_asserteq (-ENODEV ,uclass_find_device_by_seq (UCLASS_TEST_FDT ,4 , + true, &dev)); +return 0 ; }DM_TEST (dm_test_fdt_uclass_seq,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.20.1
PATCH v7 3/3 dm: uclass: don't assign aliased seq numbers
If there are aliases for an uclass, set the base for the "dynamically" allocated numbers next to the highest alias.
Please note, that this might lead to holes in the sequences, depending on the device tree. For example if there is only an alias "ethernet1", the next device seq number would be 2.
In particular this fixes a problem with boards which are using ethernet aliases but also might have network add-in cards like the E1000. If the board is started with the add-in card and depending on the order of the drivers, the E1000 might occupy the first ethernet device and mess up all the hardware addresses, because the devices are now shifted by one.
Also adapt the test cases to the new handling and add test cases checking the holes in the seq numbers.
--- arch/sandbox/dts/test.dts | 4 ++-- drivers/core/uclass.c | 21 +++++++++++++++------ include/configs/sandbox.h | 6 +++--- test/dm/eth.c | 14 +++++++------- test/dm/test-fdt.c | 22 +++++++++++++++++----- 5 files changed, 44 insertions(+), 23 deletions(-)
Applied to u-boot-dm, thanks!