diff mbox series

[21/27] dm: Switch over to use new sequence number for dev_seq()

Message ID 20201130015402.2328621-20-sjg@chromium.org
State Superseded
Delegated to: Simon Glass
Headers show
Series dm: Change the way sequence numbers are implemented | expand

Commit Message

Simon Glass Nov. 30, 2020, 1:53 a.m. UTC
Update this function to use the new sequence number and fix up the test
that deals with this.

For networking, the sequence number has changed, so update to code to
suit.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/dts/test.dts |  2 +-
 drivers/core/uclass.c     |  6 ++----
 include/configs/sandbox.h |  2 +-
 include/dm/device.h       |  2 +-
 test/dm/eth.c             | 14 ++++++-------
 test/dm/test-fdt.c        | 42 +++++++++++++++++----------------------
 6 files changed, 30 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index f3b766271d3..fb838049be5 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -33,7 +33,7 @@ 
 		testfdt6 = "/e-test";
 		testbus3 = "/some-bus";
 		testfdt0 = "/some-bus/c-test@0";
-		testfdt1 = "/some-bus/c-test@1";
+		testfdt12 = "/some-bus/c-test@1";
 		testfdt3 = "/b-test";
 		testfdt5 = "/some-bus/c-test@5";
 		testfdt8 = "/a-test";
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index d4de88bfb57..e28eea05f62 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -346,8 +346,7 @@  int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
 	uclass_foreach_dev(dev, uc) {
 		log_debug("   - %d %d '%s'\n",
 			  dev->req_seq, dev_seq(dev), dev->name);
-		if ((find_req_seq ? dev->req_seq : dev_seq(dev)) ==
-				seq_or_req_seq) {
+		if (dev_seq(dev) == seq_or_req_seq) {
 			*devp = dev;
 			log_debug("   - found\n");
 			return 0;
@@ -732,8 +731,7 @@  int uclass_resolve_seq(struct udevice *dev)
 	assert(dev_seq(dev) == -1);
 	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);
+		/* Do nothing here for now */
 	} else if (ret == -ENODEV) {
 		/* Our requested sequence number is available */
 		if (dev->req_seq != -1)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index e0708fe5739..70433bf5760 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -95,7 +95,7 @@ 
 #define SANDBOX_ETH_SETTINGS		"ethaddr=00:00:11:22:33:44\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" \
+					"eth1addr=00:00:11:22:33:47\0" \
 					"ipaddr=1.2.3.4\0"
 
 #define MEM_LAYOUT_ENV_SETTINGS \
diff --git a/include/dm/device.h b/include/dm/device.h
index 80cd0955362..3362569dc98 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -192,7 +192,7 @@  static inline bool dev_has_of_node(struct udevice *dev)
 
 static inline int dev_seq(const struct udevice *dev)
 {
-	return dev->seq;
+	return dev->sqq;
 }
 
 /**
diff --git a/test/dm/eth.c b/test/dm/eth.c
index fa8a69da701..8e0d784a92d 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -49,7 +49,7 @@  static int dm_test_eth_alias(struct unit_test_state *uts)
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth@10002000", env_get("ethact"));
 
-	env_set("ethact", "eth6");
+	env_set("ethact", "eth1");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth@10004000", env_get("ethact"));
 
@@ -106,7 +106,7 @@  static int dm_test_eth_act(struct unit_test_state *uts)
 	const char *ethname[DM_TEST_ETH_NUM] = {"eth@10002000", "eth@10003000",
 						"sbe5", "eth@10004000"};
 	const char *addrname[DM_TEST_ETH_NUM] = {"ethaddr", "eth5addr",
-						 "eth3addr", "eth6addr"};
+						 "eth3addr", "eth1addr"};
 	char ethaddr[DM_TEST_ETH_NUM][18];
 	int i;
 
@@ -189,15 +189,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("eth6addr"), 17);
-	/* Must disable access protection for eth6addr before clearing */
-	env_set(".flags", "eth6addr");
-	env_set("eth6addr", NULL);
+	strncpy(ethaddr, env_get("eth1addr"), 17);
+	/* Must disable access protection for eth1addr before clearing */
+	env_set(".flags", "eth1addr");
+	env_set("eth1addr", NULL);
 
 	retval = _dm_test_eth_rotate1(uts);
 
 	/* Restore the env */
-	env_set("eth6addr", ethaddr);
+	env_set("eth1addr", ethaddr);
 	env_set("ethrotate", NULL);
 
 	if (!retval) {
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 673ffb4de94..75b72313e86 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -329,6 +329,7 @@  DM_TEST(dm_test_fdt_pre_reloc, 0);
 static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 {
 	struct udevice *dev;
+	int i;
 
 	/* A few basic santiy tests */
 	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 3, true, &dev));
@@ -337,7 +338,14 @@  static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 8, true, &dev));
 	ut_asserteq_str("a-test", dev->name);
 
-	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 5,
+	/*
+	 * c-test@0 has the testfdt0 alias but is not bound since some-bus does
+	 * not bind its children. So d-test gets it.
+	 */
+	ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, 0, true, &dev));
+	ut_asserteq_str("d-test", dev->name);
+
+	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
 						       true, &dev));
 	ut_asserteq_ptr(NULL, dev);
 
@@ -345,9 +353,6 @@  static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 6, &dev));
 	ut_asserteq_str("e-test", dev->name);
 
-	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 7,
-						       true, &dev));
-
 	/*
 	 * Note that c-test nodes are not probed since it is not a top-level
 	 * node
@@ -363,29 +368,18 @@  static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 	ut_asserteq_str("d-test", dev->name);
 
 	/*
-	 * d-test actually gets 9, because thats the next free one after the
-	 * aliases.
+	 * g-test actually gets 2, because that number doesn't have an alias,
+	 * so it is free
 	 */
-	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 9, &dev));
-	ut_asserteq_str("d-test", dev->name);
+	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 2, &dev));
+	ut_asserteq_str("g-test", dev->name);
 
-	/* initially no one wants seq 10 */
-	ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_TEST_FDT, 10,
+	/* There should be no holes in our sequence numbers */
+	for (i = 0; i < 9; i++) {
+		ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_FDT, i, true,
 						      &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, 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,
+	}
+	ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_TEST_FDT, 9,
 						       true, &dev));
 
 	return 0;