blob: 5345f1f4c40e4a16a4ee71c1c9a21b209c923fde [file] [log] [blame]
Love Kumare9aa4e62023-12-19 17:50:51 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5import re
6
7"""
8Note: This test relies on boardenv_* containing configuration values to define
9the PHY device info including the device name, address, register address/value
10and write data value. This test will be automatically skipped without this.
11
12For example:
13
14# Setup env__mdio_util_test to set the PHY address, device names, register
15# address, register address value, and write data value to test mdio commands.
16# Test will be skipped if env_mdio_util_test is not set
17env__mdio_util_test = {
18 "eth0": {"phy_addr": 0xc, "device_name": "TI DP83867", "reg": 0,
19 "reg_val": 0x1000, "write_val": 0x100},
20 "eth1": {"phy_addr": 0xa0, "device_name": "TI DP83867", "reg": 1,
21 "reg_val": 0x2000, "write_val": 0x100},
22}
23"""
24
Simon Glassddba5202025-02-09 09:07:14 -070025def get_mdio_test_env(ubman):
26 f = ubman.config.env.get("env__mdio_util_test", None)
Love Kumare9aa4e62023-12-19 17:50:51 +053027 if not f or len(f) == 0:
28 pytest.skip("No PHY device to test!")
29 else:
30 return f
31
32@pytest.mark.buildconfigspec("cmd_mii")
33@pytest.mark.buildconfigspec("phylib")
Simon Glassddba5202025-02-09 09:07:14 -070034def test_mdio_list(ubman):
35 f = get_mdio_test_env(ubman)
36 output = ubman.run_command("mdio list")
Love Kumare9aa4e62023-12-19 17:50:51 +053037 for dev, val in f.items():
38 phy_addr = val.get("phy_addr")
39 dev_name = val.get("device_name")
40
41 assert f"{phy_addr:x} -" in output
42 assert dev_name in output
43
44@pytest.mark.buildconfigspec("cmd_mii")
45@pytest.mark.buildconfigspec("phylib")
Simon Glassddba5202025-02-09 09:07:14 -070046def test_mdio_read(ubman):
47 f = get_mdio_test_env(ubman)
48 output = ubman.run_command("mdio list")
Love Kumare9aa4e62023-12-19 17:50:51 +053049 for dev, val in f.items():
50 phy_addr = hex(val.get("phy_addr"))
51 dev_name = val.get("device_name")
52 reg = hex(val.get("reg"))
53 reg_val = hex(val.get("reg_val"))
54
Simon Glassddba5202025-02-09 09:07:14 -070055 output = ubman.run_command(f"mdio read {phy_addr} {reg}")
Love Kumare9aa4e62023-12-19 17:50:51 +053056 assert f"PHY at address {int(phy_addr, 16):x}:" in output
57 assert f"{int(reg, 16):x} - {reg_val}" in output
58
59@pytest.mark.buildconfigspec("cmd_mii")
60@pytest.mark.buildconfigspec("phylib")
Simon Glassddba5202025-02-09 09:07:14 -070061def test_mdio_write(ubman):
62 f = get_mdio_test_env(ubman)
63 output = ubman.run_command("mdio list")
Love Kumare9aa4e62023-12-19 17:50:51 +053064 for dev, val in f.items():
65 phy_addr = hex(val.get("phy_addr"))
66 dev_name = val.get("device_name")
67 reg = hex(val.get("reg"))
68 reg_val = hex(val.get("reg_val"))
69 wr_val = hex(val.get("write_val"))
70
Simon Glassddba5202025-02-09 09:07:14 -070071 ubman.run_command(f"mdio write {phy_addr} {reg} {wr_val}")
72 output = ubman.run_command(f"mdio read {phy_addr} {reg}")
Love Kumare9aa4e62023-12-19 17:50:51 +053073 assert f"PHY at address {int(phy_addr, 16):x}:" in output
74 assert f"{int(reg, 16):x} - {wr_val}" in output
75
Simon Glassddba5202025-02-09 09:07:14 -070076 ubman.run_command(f"mdio write {phy_addr} {reg} {reg_val}")
77 output = ubman.run_command(f"mdio read {phy_addr} {reg}")
Love Kumare9aa4e62023-12-19 17:50:51 +053078 assert f"PHY at address {int(phy_addr, 16):x}:" in output
79 assert f"{int(reg, 16):x} - {reg_val}" in output