d5793860a96863b2127c3d1a12fcb47365ac021c
[openwrt/staging/blocktrron.git] /
1 From ea73e5ea442ee2aade67b1fb1233ccb3cbea2ceb Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 4 Jan 2024 22:30:40 +0100
4 Subject: [PATCH 3/4] net: phy: at803x: add support for cdt cross short test
5 for qca808x
6
7 QCA808x PHY Family supports Cable Diagnostic Test also for Cross Pair
8 Short.
9
10 Add all the define to make enable and support these additional tests.
11
12 Cross Short test was previously disabled by default, this is now changed
13 and enabled by default. In this mode, the mask changed a bit and length
14 is shifted based on the fault condition.
15
16 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
17 Reviewed-by: Simon Horman <horms@kernel.org>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
19 ---
20 drivers/net/phy/at803x.c | 86 ++++++++++++++++++++++++++++++++--------
21 1 file changed, 69 insertions(+), 17 deletions(-)
22
23 --- a/drivers/net/phy/at803x.c
24 +++ b/drivers/net/phy/at803x.c
25 @@ -254,6 +254,7 @@
26
27 #define QCA808X_CDT_ENABLE_TEST BIT(15)
28 #define QCA808X_CDT_INTER_CHECK_DIS BIT(13)
29 +#define QCA808X_CDT_STATUS BIT(11)
30 #define QCA808X_CDT_LENGTH_UNIT BIT(10)
31
32 #define QCA808X_MMD3_CDT_STATUS 0x8064
33 @@ -261,16 +262,44 @@
34 #define QCA808X_MMD3_CDT_DIAG_PAIR_B 0x8066
35 #define QCA808X_MMD3_CDT_DIAG_PAIR_C 0x8067
36 #define QCA808X_MMD3_CDT_DIAG_PAIR_D 0x8068
37 -#define QCA808X_CDT_DIAG_LENGTH GENMASK(7, 0)
38 +#define QCA808X_CDT_DIAG_LENGTH_SAME_SHORT GENMASK(15, 8)
39 +#define QCA808X_CDT_DIAG_LENGTH_CROSS_SHORT GENMASK(7, 0)
40
41 #define QCA808X_CDT_CODE_PAIR_A GENMASK(15, 12)
42 #define QCA808X_CDT_CODE_PAIR_B GENMASK(11, 8)
43 #define QCA808X_CDT_CODE_PAIR_C GENMASK(7, 4)
44 #define QCA808X_CDT_CODE_PAIR_D GENMASK(3, 0)
45 -#define QCA808X_CDT_STATUS_STAT_FAIL 0
46 -#define QCA808X_CDT_STATUS_STAT_NORMAL 1
47 -#define QCA808X_CDT_STATUS_STAT_OPEN 2
48 -#define QCA808X_CDT_STATUS_STAT_SHORT 3
49 +
50 +#define QCA808X_CDT_STATUS_STAT_TYPE GENMASK(1, 0)
51 +#define QCA808X_CDT_STATUS_STAT_FAIL FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 0)
52 +#define QCA808X_CDT_STATUS_STAT_NORMAL FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 1)
53 +#define QCA808X_CDT_STATUS_STAT_SAME_OPEN FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 2)
54 +#define QCA808X_CDT_STATUS_STAT_SAME_SHORT FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_TYPE, 3)
55 +
56 +#define QCA808X_CDT_STATUS_STAT_MDI GENMASK(3, 2)
57 +#define QCA808X_CDT_STATUS_STAT_MDI1 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 1)
58 +#define QCA808X_CDT_STATUS_STAT_MDI2 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 2)
59 +#define QCA808X_CDT_STATUS_STAT_MDI3 FIELD_PREP_CONST(QCA808X_CDT_STATUS_STAT_MDI, 3)
60 +
61 +/* NORMAL are MDI with type set to 0 */
62 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI1
63 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\
64 + QCA808X_CDT_STATUS_STAT_MDI1)
65 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\
66 + QCA808X_CDT_STATUS_STAT_MDI1)
67 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI2
68 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\
69 + QCA808X_CDT_STATUS_STAT_MDI2)
70 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\
71 + QCA808X_CDT_STATUS_STAT_MDI2)
72 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL QCA808X_CDT_STATUS_STAT_MDI3
73 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN (QCA808X_CDT_STATUS_STAT_SAME_OPEN |\
74 + QCA808X_CDT_STATUS_STAT_MDI3)
75 +#define QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT (QCA808X_CDT_STATUS_STAT_SAME_SHORT |\
76 + QCA808X_CDT_STATUS_STAT_MDI3)
77 +
78 +/* Added for reference of existence but should be handled by wait_for_completion already */
79 +#define QCA808X_CDT_STATUS_STAT_BUSY (BIT(1) | BIT(3))
80
81 /* QCA808X 1G chip type */
82 #define QCA808X_PHY_MMD7_CHIP_TYPE 0x901d
83 @@ -1941,8 +1970,17 @@ static int qca808x_soft_reset(struct phy
84 static bool qca808x_cdt_fault_length_valid(int cdt_code)
85 {
86 switch (cdt_code) {
87 - case QCA808X_CDT_STATUS_STAT_SHORT:
88 - case QCA808X_CDT_STATUS_STAT_OPEN:
89 + case QCA808X_CDT_STATUS_STAT_SAME_SHORT:
90 + case QCA808X_CDT_STATUS_STAT_SAME_OPEN:
91 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL:
92 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN:
93 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT:
94 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL:
95 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN:
96 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT:
97 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL:
98 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN:
99 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT:
100 return true;
101 default:
102 return false;
103 @@ -1954,17 +1992,28 @@ static int qca808x_cable_test_result_tra
104 switch (cdt_code) {
105 case QCA808X_CDT_STATUS_STAT_NORMAL:
106 return ETHTOOL_A_CABLE_RESULT_CODE_OK;
107 - case QCA808X_CDT_STATUS_STAT_SHORT:
108 + case QCA808X_CDT_STATUS_STAT_SAME_SHORT:
109 return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
110 - case QCA808X_CDT_STATUS_STAT_OPEN:
111 + case QCA808X_CDT_STATUS_STAT_SAME_OPEN:
112 return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
113 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_NORMAL:
114 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_OPEN:
115 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI1_SAME_SHORT:
116 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_NORMAL:
117 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_OPEN:
118 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI2_SAME_SHORT:
119 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_NORMAL:
120 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_OPEN:
121 + case QCA808X_CDT_STATUS_STAT_CROSS_SHORT_WITH_MDI3_SAME_SHORT:
122 + return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT;
123 case QCA808X_CDT_STATUS_STAT_FAIL:
124 default:
125 return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
126 }
127 }
128
129 -static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair)
130 +static int qca808x_cdt_fault_length(struct phy_device *phydev, int pair,
131 + int result)
132 {
133 int val;
134 u32 cdt_length_reg = 0;
135 @@ -1990,7 +2039,11 @@ static int qca808x_cdt_fault_length(stru
136 if (val < 0)
137 return val;
138
139 - val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH, val);
140 + if (result == ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT)
141 + val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH_SAME_SHORT, val);
142 + else
143 + val = FIELD_GET(QCA808X_CDT_DIAG_LENGTH_CROSS_SHORT, val);
144 +
145 return at803x_cdt_fault_length(val);
146 }
147
148 @@ -2038,8 +2091,8 @@ static int qca808x_cable_test_start(stru
149 static int qca808x_cable_test_get_pair_status(struct phy_device *phydev, u8 pair,
150 u16 status)
151 {
152 + int length, result;
153 u16 pair_code;
154 - int length;
155
156 switch (pair) {
157 case ETHTOOL_A_CABLE_PAIR_A:
158 @@ -2058,11 +2111,11 @@ static int qca808x_cable_test_get_pair_s
159 return -EINVAL;
160 }
161
162 - ethnl_cable_test_result(phydev, pair,
163 - qca808x_cable_test_result_trans(pair_code));
164 + result = qca808x_cable_test_result_trans(pair_code);
165 + ethnl_cable_test_result(phydev, pair, result);
166
167 if (qca808x_cdt_fault_length_valid(pair_code)) {
168 - length = qca808x_cdt_fault_length(phydev, pair);
169 + length = qca808x_cdt_fault_length(phydev, pair, result);
170 ethnl_cable_test_fault_length(phydev, pair, length);
171 }
172
173 @@ -2076,8 +2129,7 @@ static int qca808x_cable_test_get_status
174 *finished = false;
175
176 val = QCA808X_CDT_ENABLE_TEST |
177 - QCA808X_CDT_LENGTH_UNIT |
178 - QCA808X_CDT_INTER_CHECK_DIS;
179 + QCA808X_CDT_LENGTH_UNIT;
180 ret = at803x_cdt_start(phydev, val);
181 if (ret)
182 return ret;