1 From e0e9ada1df6133513249861c1d91c1dbefd9383b Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 4 Jan 2024 22:30:39 +0100
4 Subject: [PATCH 2/4] net: phy: at803x: refactor qca808x cable test get status
7 Refactor qca808x cable test get status function to remove code
8 duplication and clean things up.
10 The same logic is applied to each pair hence it can be generalized and
11 moved to a common function.
13 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
14 Reviewed-by: Simon Horman <horms@kernel.org>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
17 drivers/net/phy/at803x.c | 80 ++++++++++++++++++++++++----------------
18 1 file changed, 49 insertions(+), 31 deletions(-)
20 --- a/drivers/net/phy/at803x.c
21 +++ b/drivers/net/phy/at803x.c
22 @@ -2035,10 +2035,43 @@ static int qca808x_cable_test_start(stru
26 +static int qca808x_cable_test_get_pair_status(struct phy_device *phydev, u8 pair,
33 + case ETHTOOL_A_CABLE_PAIR_A:
34 + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, status);
36 + case ETHTOOL_A_CABLE_PAIR_B:
37 + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, status);
39 + case ETHTOOL_A_CABLE_PAIR_C:
40 + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, status);
42 + case ETHTOOL_A_CABLE_PAIR_D:
43 + pair_code = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, status);
49 + ethnl_cable_test_result(phydev, pair,
50 + qca808x_cable_test_result_trans(pair_code));
52 + if (qca808x_cdt_fault_length_valid(pair_code)) {
53 + length = qca808x_cdt_fault_length(phydev, pair);
54 + ethnl_cable_test_fault_length(phydev, pair, length);
60 static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished)
63 - int pair_a, pair_b, pair_c, pair_d;
67 @@ -2057,36 +2090,21 @@ static int qca808x_cable_test_get_status
71 - pair_a = FIELD_GET(QCA808X_CDT_CODE_PAIR_A, val);
72 - pair_b = FIELD_GET(QCA808X_CDT_CODE_PAIR_B, val);
73 - pair_c = FIELD_GET(QCA808X_CDT_CODE_PAIR_C, val);
74 - pair_d = FIELD_GET(QCA808X_CDT_CODE_PAIR_D, val);
76 - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
77 - qca808x_cable_test_result_trans(pair_a));
78 - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
79 - qca808x_cable_test_result_trans(pair_b));
80 - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
81 - qca808x_cable_test_result_trans(pair_c));
82 - ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
83 - qca808x_cable_test_result_trans(pair_d));
85 - if (qca808x_cdt_fault_length_valid(pair_a)) {
86 - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A);
87 - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_A, val);
89 - if (qca808x_cdt_fault_length_valid(pair_b)) {
90 - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B);
91 - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_B, val);
93 - if (qca808x_cdt_fault_length_valid(pair_c)) {
94 - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C);
95 - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_C, val);
97 - if (qca808x_cdt_fault_length_valid(pair_d)) {
98 - val = qca808x_cdt_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D);
99 - ethnl_cable_test_fault_length(phydev, ETHTOOL_A_CABLE_PAIR_D, val);
101 + ret = qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_A, val);
105 + ret = qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_B, val);
109 + ret = qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_C, val);
113 + ret = qca808x_cable_test_get_pair_status(phydev, ETHTOOL_A_CABLE_PAIR_D, val);