gperf: build as C++11
[openwrt/openwrt.git] / target / linux / generic / backport-6.6 / 707-v6.8-13-net-phy-at803x-drop-specific-PHY-ID-check-from-cable.patch
1 From ef9df47b449e32e06501a11272809be49019bdb6 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 8 Dec 2023 15:52:00 +0100
4 Subject: [PATCH 13/13] net: phy: at803x: drop specific PHY ID check from cable
5 test functions
6
7 Drop specific PHY ID check for cable test functions for at803x. This is
8 done to make functions more generic. While at it better describe what
9 the functions does by using more symbolic function names.
10
11 PHYs that requires to set additional reg are moved to specific function
12 calling the more generic one.
13
14 cdt_start and cdt_wait_for_completion are changed to take an additional
15 arg to pass specific values specific to the PHY.
16
17 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
19 ---
20 drivers/net/phy/at803x.c | 95 +++++++++++++++++++++-------------------
21 1 file changed, 50 insertions(+), 45 deletions(-)
22
23 --- a/drivers/net/phy/at803x.c
24 +++ b/drivers/net/phy/at803x.c
25 @@ -1222,31 +1222,16 @@ static int at803x_cdt_fault_length(u16 s
26 return (dt * 824) / 10;
27 }
28
29 -static int at803x_cdt_start(struct phy_device *phydev, int pair)
30 +static int at803x_cdt_start(struct phy_device *phydev,
31 + u32 cdt_start)
32 {
33 - u16 cdt;
34 -
35 - /* qca8081 takes the different bit 15 to enable CDT test */
36 - if (phydev->drv->phy_id == QCA8081_PHY_ID)
37 - cdt = QCA808X_CDT_ENABLE_TEST |
38 - QCA808X_CDT_LENGTH_UNIT |
39 - QCA808X_CDT_INTER_CHECK_DIS;
40 - else
41 - cdt = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
42 - AT803X_CDT_ENABLE_TEST;
43 -
44 - return phy_write(phydev, AT803X_CDT, cdt);
45 + return phy_write(phydev, AT803X_CDT, cdt_start);
46 }
47
48 -static int at803x_cdt_wait_for_completion(struct phy_device *phydev)
49 +static int at803x_cdt_wait_for_completion(struct phy_device *phydev,
50 + u32 cdt_en)
51 {
52 int val, ret;
53 - u16 cdt_en;
54 -
55 - if (phydev->drv->phy_id == QCA8081_PHY_ID)
56 - cdt_en = QCA808X_CDT_ENABLE_TEST;
57 - else
58 - cdt_en = AT803X_CDT_ENABLE_TEST;
59
60 /* One test run takes about 25ms */
61 ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
62 @@ -1266,11 +1251,13 @@ static int at803x_cable_test_one_pair(st
63 };
64 int ret, val;
65
66 - ret = at803x_cdt_start(phydev, pair);
67 + val = FIELD_PREP(AT803X_CDT_MDI_PAIR_MASK, pair) |
68 + AT803X_CDT_ENABLE_TEST;
69 + ret = at803x_cdt_start(phydev, val);
70 if (ret)
71 return ret;
72
73 - ret = at803x_cdt_wait_for_completion(phydev);
74 + ret = at803x_cdt_wait_for_completion(phydev, AT803X_CDT_ENABLE_TEST);
75 if (ret)
76 return ret;
77
78 @@ -1292,19 +1279,11 @@ static int at803x_cable_test_one_pair(st
79 }
80
81 static int at803x_cable_test_get_status(struct phy_device *phydev,
82 - bool *finished)
83 + bool *finished, unsigned long pair_mask)
84 {
85 - unsigned long pair_mask;
86 int retries = 20;
87 int pair, ret;
88
89 - if (phydev->phy_id == ATH9331_PHY_ID ||
90 - phydev->phy_id == ATH8032_PHY_ID ||
91 - phydev->phy_id == QCA9561_PHY_ID)
92 - pair_mask = 0x3;
93 - else
94 - pair_mask = 0xf;
95 -
96 *finished = false;
97
98 /* According to the datasheet the CDT can be performed when
99 @@ -1331,7 +1310,7 @@ static int at803x_cable_test_get_status(
100 return 0;
101 }
102
103 -static int at803x_cable_test_start(struct phy_device *phydev)
104 +static void at803x_cable_test_autoneg(struct phy_device *phydev)
105 {
106 /* Enable auto-negotiation, but advertise no capabilities, no link
107 * will be established. A restart of the auto-negotiation is not
108 @@ -1339,11 +1318,11 @@ static int at803x_cable_test_start(struc
109 */
110 phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
111 phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
112 - if (phydev->phy_id != ATH9331_PHY_ID &&
113 - phydev->phy_id != ATH8032_PHY_ID &&
114 - phydev->phy_id != QCA9561_PHY_ID)
115 - phy_write(phydev, MII_CTRL1000, 0);
116 +}
117
118 +static int at803x_cable_test_start(struct phy_device *phydev)
119 +{
120 + at803x_cable_test_autoneg(phydev);
121 /* we do all the (time consuming) work later */
122 return 0;
123 }
124 @@ -1618,6 +1597,29 @@ static int at8031_config_intr(struct phy
125 return at803x_config_intr(phydev);
126 }
127
128 +/* AR8031 and AR8035 share the same cable test get status reg */
129 +static int at8031_cable_test_get_status(struct phy_device *phydev,
130 + bool *finished)
131 +{
132 + return at803x_cable_test_get_status(phydev, finished, 0xf);
133 +}
134 +
135 +/* AR8031 and AR8035 share the same cable test start logic */
136 +static int at8031_cable_test_start(struct phy_device *phydev)
137 +{
138 + at803x_cable_test_autoneg(phydev);
139 + phy_write(phydev, MII_CTRL1000, 0);
140 + /* we do all the (time consuming) work later */
141 + return 0;
142 +}
143 +
144 +/* AR8032, AR9331 and QCA9561 share the same cable test get status reg */
145 +static int at8032_cable_test_get_status(struct phy_device *phydev,
146 + bool *finished)
147 +{
148 + return at803x_cable_test_get_status(phydev, finished, 0x3);
149 +}
150 +
151 static int at8035_parse_dt(struct phy_device *phydev)
152 {
153 struct at803x_priv *priv = phydev->priv;
154 @@ -2041,11 +2043,14 @@ static int qca808x_cable_test_get_status
155
156 *finished = false;
157
158 - ret = at803x_cdt_start(phydev, 0);
159 + val = QCA808X_CDT_ENABLE_TEST |
160 + QCA808X_CDT_LENGTH_UNIT |
161 + QCA808X_CDT_INTER_CHECK_DIS;
162 + ret = at803x_cdt_start(phydev, val);
163 if (ret)
164 return ret;
165
166 - ret = at803x_cdt_wait_for_completion(phydev);
167 + ret = at803x_cdt_wait_for_completion(phydev, QCA808X_CDT_ENABLE_TEST);
168 if (ret)
169 return ret;
170
171 @@ -2143,8 +2148,8 @@ static struct phy_driver at803x_driver[]
172 .handle_interrupt = at803x_handle_interrupt,
173 .get_tunable = at803x_get_tunable,
174 .set_tunable = at803x_set_tunable,
175 - .cable_test_start = at803x_cable_test_start,
176 - .cable_test_get_status = at803x_cable_test_get_status,
177 + .cable_test_start = at8031_cable_test_start,
178 + .cable_test_get_status = at8031_cable_test_get_status,
179 }, {
180 /* Qualcomm Atheros AR8030 */
181 .phy_id = ATH8030_PHY_ID,
182 @@ -2181,8 +2186,8 @@ static struct phy_driver at803x_driver[]
183 .handle_interrupt = at803x_handle_interrupt,
184 .get_tunable = at803x_get_tunable,
185 .set_tunable = at803x_set_tunable,
186 - .cable_test_start = at803x_cable_test_start,
187 - .cable_test_get_status = at803x_cable_test_get_status,
188 + .cable_test_start = at8031_cable_test_start,
189 + .cable_test_get_status = at8031_cable_test_get_status,
190 }, {
191 /* Qualcomm Atheros AR8032 */
192 PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
193 @@ -2197,7 +2202,7 @@ static struct phy_driver at803x_driver[]
194 .config_intr = at803x_config_intr,
195 .handle_interrupt = at803x_handle_interrupt,
196 .cable_test_start = at803x_cable_test_start,
197 - .cable_test_get_status = at803x_cable_test_get_status,
198 + .cable_test_get_status = at8032_cable_test_get_status,
199 }, {
200 /* ATHEROS AR9331 */
201 PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
202 @@ -2210,7 +2215,7 @@ static struct phy_driver at803x_driver[]
203 .config_intr = at803x_config_intr,
204 .handle_interrupt = at803x_handle_interrupt,
205 .cable_test_start = at803x_cable_test_start,
206 - .cable_test_get_status = at803x_cable_test_get_status,
207 + .cable_test_get_status = at8032_cable_test_get_status,
208 .read_status = at803x_read_status,
209 .soft_reset = genphy_soft_reset,
210 .config_aneg = at803x_config_aneg,
211 @@ -2226,7 +2231,7 @@ static struct phy_driver at803x_driver[]
212 .config_intr = at803x_config_intr,
213 .handle_interrupt = at803x_handle_interrupt,
214 .cable_test_start = at803x_cable_test_start,
215 - .cable_test_get_status = at803x_cable_test_get_status,
216 + .cable_test_get_status = at8032_cable_test_get_status,
217 .read_status = at803x_read_status,
218 .soft_reset = genphy_soft_reset,
219 .config_aneg = at803x_config_aneg,