1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2020-2021 NXP
4 */
5
6 #include <net/dsa.h>
7 #include <dm/test.h>
8 #include <test/ut.h>
9 #include <net.h>
10 #include <dm/uclass-internal.h>
11 #include <dm/device-internal.h>
12
13 /* This test exercises the major dsa.h API functions, after making sure
14 * that the DSA ports and the master Eth are correctly probed.
15 */
dm_test_dsa_probe(struct unit_test_state * uts)16 static int dm_test_dsa_probe(struct unit_test_state *uts)
17 {
18 struct udevice *dev_dsa, *dev_port, *dev_master;
19 struct dsa_pdata *dsa_pdata;
20 enum uclass_id id;
21
22 id = uclass_get_by_name("dsa");
23 ut_assert(id == UCLASS_DSA);
24
25 ut_assertok(uclass_find_device_by_name(UCLASS_DSA, "dsa-test",
26 &dev_dsa));
27 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test-eth",
28 &dev_master));
29 ut_assertok(device_probe(dev_master));
30
31 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@0",
32 &dev_port));
33 ut_assertok(device_probe(dev_port));
34
35 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "dsa-test@1",
36 &dev_port));
37 ut_assertok(device_probe(dev_port));
38
39 /* exercise DSA API */
40 dsa_pdata = dev_get_uclass_plat(dev_dsa);
41 ut_assertnonnull(dsa_pdata);
42 /* includes CPU port */
43 ut_assert(dsa_pdata->num_ports == 3);
44
45 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan0",
46 &dev_port));
47 ut_assertok(device_probe(dev_port));
48
49 ut_assertok(uclass_find_device_by_name(UCLASS_ETH, "lan1",
50 &dev_port));
51 ut_assertok(device_probe(dev_port));
52
53 dev_master = dsa_get_master(dev_dsa);
54 ut_assertnonnull(dev_master);
55 ut_asserteq_str("dsa-test-eth", dev_master->name);
56
57 return 0;
58 }
59
60 DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
61
62 /* This test sends ping requests with the local address through each DSA port
63 * via the sandbox DSA master Eth.
64 */
dm_test_dsa(struct unit_test_state * uts)65 static int dm_test_dsa(struct unit_test_state *uts)
66 {
67 net_ping_ip = string_to_ip("1.2.3.5");
68
69 env_set("ethact", "eth2");
70 ut_assertok(net_loop(PING));
71
72 env_set("ethact", "lan0");
73 ut_assertok(net_loop(PING));
74 env_set("ethact", "lan1");
75 ut_assertok(net_loop(PING));
76
77 env_set("ethact", "");
78
79 return 0;
80 }
81
82 DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);
83