Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2025 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include "txgbe_type.h"
7 : : #include "txgbe_mbx.h"
8 : : #include "txgbe_phy.h"
9 : : #include "txgbe_dcb.h"
10 : : #include "txgbe_vf.h"
11 : : #include "txgbe_eeprom.h"
12 : : #include "txgbe_mng.h"
13 : : #include "txgbe_hw.h"
14 : : #include "txgbe_aml.h"
15 : : #include "txgbe_e56.h"
16 : : #include "txgbe_e56_bp.h"
17 : :
18 : 0 : void txgbe_init_ops_aml(struct txgbe_hw *hw)
19 : : {
20 : : struct txgbe_mac_info *mac = &hw->mac;
21 : : struct txgbe_phy_info *phy = &hw->phy;
22 : : struct txgbe_mbx_info *mbx = &hw->mbx;
23 : :
24 : 0 : txgbe_init_ops_generic(hw);
25 : :
26 : : /* PHY */
27 : 0 : phy->get_media_type = txgbe_get_media_type_aml;
28 : 0 : phy->setup_link_core = txgbe_setup_phy_link_aml;
29 : :
30 : : /* LINK */
31 : 0 : mac->init_mac_link_ops = txgbe_init_mac_link_ops_aml;
32 : 0 : mac->get_link_capabilities = txgbe_get_link_capabilities_aml;
33 : 0 : mac->check_link = txgbe_check_mac_link_aml;
34 : :
35 : : /* FW interaction */
36 : 0 : mbx->host_interface_command = txgbe_host_interface_command_aml;
37 : 0 : }
38 : :
39 : 0 : s32 txgbe_check_mac_link_aml(struct txgbe_hw *hw, u32 *speed,
40 : : bool *link_up, bool link_up_wait_to_complete)
41 : : {
42 : : u32 links_reg, links_orig;
43 : : u32 i;
44 : :
45 : : /* clear the old state */
46 : : links_orig = rd32(hw, TXGBE_PORTSTAT);
47 : :
48 : : links_reg = rd32(hw, TXGBE_PORTSTAT);
49 : :
50 [ # # ]: 0 : if (links_orig != links_reg) {
51 : 0 : DEBUGOUT("LINKS changed from %08X to %08X",
52 : : links_orig, links_reg);
53 : : }
54 : :
55 [ # # ]: 0 : if (link_up_wait_to_complete) {
56 [ # # ]: 0 : for (i = 0; i < hw->mac.max_link_up_time; i++) {
57 [ # # ]: 0 : if (!(links_reg & TXGBE_PORTSTAT_UP)) {
58 : 0 : *link_up = false;
59 : : } else {
60 : 0 : *link_up = true;
61 : 0 : break;
62 : : }
63 : : msec_delay(100);
64 : : links_reg = rd32(hw, TXGBE_PORTSTAT);
65 : : }
66 : : } else {
67 [ # # ]: 0 : if (links_reg & TXGBE_PORTSTAT_UP)
68 : 0 : *link_up = true;
69 : : else
70 : 0 : *link_up = false;
71 : : }
72 : :
73 [ # # ]: 0 : if (*link_up) {
74 [ # # # ]: 0 : switch (links_reg & TXGBE_CFG_PORT_ST_AML_LINK_MASK) {
75 : 0 : case TXGBE_CFG_PORT_ST_AML_LINK_25G:
76 : 0 : *speed = TXGBE_LINK_SPEED_25GB_FULL;
77 : 0 : break;
78 : 0 : case TXGBE_CFG_PORT_ST_AML_LINK_10G:
79 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL;
80 : 0 : break;
81 : 0 : default:
82 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
83 : : }
84 : : } else {
85 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
86 : : }
87 : :
88 [ # # ]: 0 : if (txgbe_xpcs_an_enabled(hw)) {
89 [ # # ]: 0 : if (!hw->an_done) {
90 : 0 : *link_up = false;
91 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
92 : : }
93 : : }
94 : :
95 : 0 : return 0;
96 : : }
97 : :
98 : 0 : s32 txgbe_get_link_capabilities_aml(struct txgbe_hw *hw,
99 : : u32 *speed,
100 : : bool *autoneg)
101 : : {
102 [ # # ]: 0 : if (hw->phy.multispeed_fiber) {
103 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL |
104 : : TXGBE_LINK_SPEED_25GB_FULL;
105 : 0 : *autoneg = true;
106 [ # # ]: 0 : } else if (txgbe_is_dac_cable(hw)) {
107 [ # # ]: 0 : if (hw->phy.fiber_support_speed ==
108 : : TXGBE_LINK_SPEED_10GB_FULL) {
109 : 0 : *autoneg = false;
110 : : } else {
111 : 0 : *autoneg = true;
112 : : }
113 : 0 : *speed = hw->phy.fiber_support_speed;
114 : 0 : } else if (hw->phy.sfp_type == txgbe_sfp_type_25g_sr_core0 ||
115 : : hw->phy.sfp_type == txgbe_sfp_type_25g_sr_core1 ||
116 : : hw->phy.sfp_type == txgbe_sfp_type_25g_lr_core0 ||
117 : : hw->phy.sfp_type == txgbe_sfp_type_25g_lr_core1 ||
118 [ # # ]: 0 : hw->phy.sfp_type == txgbe_sfp_type_25g_aoc_core0 ||
119 : : hw->phy.sfp_type == txgbe_sfp_type_25g_aoc_core1) {
120 : 0 : *speed = TXGBE_LINK_SPEED_25GB_FULL;
121 : 0 : *autoneg = false;
122 [ # # ]: 0 : } else if (hw->phy.media_type == txgbe_media_type_backplane) {
123 : : /* Backplane */
124 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL |
125 : : TXGBE_LINK_SPEED_25GB_FULL;
126 : : /* Backplane supports autonegotiation */
127 : 0 : *autoneg = hw->devarg.auto_neg;
128 [ # # ]: 0 : } else if (hw->phy.media_type == txgbe_media_type_fiber) {
129 : : /* Fiber */
130 : 0 : *speed = TXGBE_LINK_SPEED_10GB_FULL |
131 : : TXGBE_LINK_SPEED_25GB_FULL;
132 : 0 : *autoneg = false;
133 : : } else {
134 : : /* Unknown */
135 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN;
136 : 0 : *autoneg = false;
137 : 0 : PMD_DRV_LOG(DEBUG, "GET link capabilities failed");
138 : 0 : return TXGBE_ERR_LINK_SETUP;
139 : : }
140 : :
141 : : return 0;
142 : : }
143 : :
144 : 0 : u32 txgbe_get_media_type_aml(struct txgbe_hw *hw)
145 : : {
146 : 0 : u8 device_type = hw->subsystem_device_id & 0xF0;
147 : : enum txgbe_media_type media_type;
148 : :
149 [ # # # ]: 0 : switch (device_type) {
150 : : case TXGBE_DEV_ID_KR_KX_KX4:
151 : : media_type = txgbe_media_type_backplane;
152 : : break;
153 : 0 : case TXGBE_DEV_ID_SFP:
154 : : media_type = txgbe_media_type_fiber;
155 : 0 : break;
156 : 0 : default:
157 : : media_type = txgbe_media_type_unknown;
158 : 0 : break;
159 : : }
160 : :
161 : 0 : return media_type;
162 : : }
163 : :
164 : : static int
165 : 0 : txgbe_phy_fec_get(struct txgbe_hw *hw)
166 : : {
167 : : int value = 0;
168 : :
169 : 0 : rte_spinlock_lock(&hw->phy_lock);
170 : 0 : value = rd32_epcs(hw, SR_PMA_RS_FEC_CTRL);
171 : : rte_spinlock_unlock(&hw->phy_lock);
172 [ # # ]: 0 : if (value & 0x4)
173 : : return TXGBE_PHY_FEC_RS;
174 : :
175 : : rte_spinlock_lock(&hw->phy_lock);
176 : 0 : value = rd32_epcs(hw, SR_PMA_KR_FEC_CTRL);
177 : : rte_spinlock_unlock(&hw->phy_lock);
178 [ # # ]: 0 : if (value & 0x1)
179 : 0 : return TXGBE_PHY_FEC_BASER;
180 : :
181 : : return TXGBE_PHY_FEC_OFF;
182 : : }
183 : :
184 : 0 : void txgbe_wait_for_link_up_aml(struct txgbe_hw *hw, u32 speed)
185 : : {
186 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
187 : 0 : bool link_up = false;
188 : : int cnt = 0;
189 : : int i;
190 : :
191 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_25GB_FULL)
192 : : cnt = 4;
193 : : else
194 : : cnt = 1;
195 : :
196 [ # # ]: 0 : for (i = 0; i < (4 * cnt); i++) {
197 : 0 : hw->mac.check_link(hw, &link_speed, &link_up, false);
198 [ # # ]: 0 : if (link_up)
199 : : break;
200 : : msleep(250);
201 : : }
202 : 0 : }
203 : :
204 : 0 : s32 txgbe_setup_phy_link_aml(struct txgbe_hw *hw,
205 : : u32 speed,
206 : : bool autoneg_wait_to_complete,
207 : : bool *need_reset)
208 : : {
209 : 0 : bool autoneg = false;
210 : : s32 status = 0;
211 : : s32 ret_status = 0;
212 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
213 : 0 : bool link_up = false;
214 : : int i;
215 : 0 : u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
216 : : u32 value;
217 : :
218 : 0 : *need_reset = false;
219 : :
220 [ # # # # ]: 0 : if (hw->phy.sfp_type == txgbe_sfp_type_not_present && !txgbe_is_backplane(hw)) {
221 : 0 : DEBUGOUT("SFP not detected, skip setup mac link");
222 : 0 : return 0;
223 : : }
224 : :
225 : : /* Check to see if speed passed in is supported. */
226 : 0 : status = hw->mac.get_link_capabilities(hw,
227 : : &link_capabilities, &autoneg);
228 [ # # ]: 0 : if (status)
229 : : return status;
230 : :
231 : : /* setup the highest link when no autoneg */
232 [ # # ]: 0 : if (!autoneg) {
233 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_25GB_FULL)
234 : : speed = TXGBE_LINK_SPEED_25GB_FULL;
235 [ # # ]: 0 : else if (speed & TXGBE_LINK_SPEED_10GB_FULL)
236 : : speed = TXGBE_LINK_SPEED_10GB_FULL;
237 : : }
238 : :
239 : 0 : speed &= link_capabilities;
240 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_UNKNOWN)
241 : : return TXGBE_ERR_LINK_SETUP;
242 : :
243 [ # # ]: 0 : if (txgbe_xpcs_an_enabled(hw)) {
244 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
245 [ # # # # : 0 : if (link_up && hw->an_done && !autoneg_wait_to_complete)
# # ]
246 : : return status;
247 : :
248 : 0 : rte_spinlock_lock(&hw->phy_lock);
249 : 0 : txgbe_e56_set_phy_link_mode(hw, speed, true);
250 : : rte_spinlock_unlock(&hw->phy_lock);
251 : 0 : return 0;
252 : : }
253 : :
254 [ # # # # ]: 0 : if (txgbe_is_backplane(hw) || txgbe_is_dac_cable(hw) ||
255 [ # # ]: 0 : hw->phy.ffe_set) {
256 : 0 : rte_spinlock_lock(&hw->phy_lock);
257 : 0 : txgbe_e56_tx_ffe_cfg(hw, speed);
258 : : rte_spinlock_unlock(&hw->phy_lock);
259 : : }
260 : :
261 [ # # ]: 0 : if (txgbe_gpio_ext_check(hw, TXGBE_SFP1_MOD_ABS_LS |
262 : : TXGBE_SFP1_RX_LOS_LS)) {
263 : 0 : DEBUGOUT("RX LOS");
264 : 0 : return status;
265 : : }
266 : :
267 [ # # ]: 0 : for (i = 0; i < 4; i++) {
268 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
269 [ # # ]: 0 : if (link_up) {
270 : 0 : DEBUGOUT("check phy link_up");
271 : 0 : break;
272 : : }
273 : : msleep(250);
274 : : }
275 : :
276 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_25GB_FULL)
277 : 0 : hw->cur_fec_link = txgbe_phy_fec_get(hw);
278 : :
279 [ # # # # : 0 : if (link_speed == speed && link_up &&
# # ]
280 : 0 : !(speed == TXGBE_LINK_SPEED_25GB_FULL &&
281 [ # # ]: 0 : !(hw->fec_mode & hw->cur_fec_link)))
282 : 0 : goto out;
283 : :
284 [ # # # # ]: 0 : if (speed == TXGBE_LINK_SPEED_25GB_FULL &&
285 : : link_speed == TXGBE_LINK_SPEED_25GB_FULL) {
286 : 0 : txgbe_e56_fec_polling(hw, &link_up);
287 : :
288 [ # # ]: 0 : if (link_up)
289 : 0 : goto out;
290 : : }
291 : :
292 : 0 : rte_spinlock_lock(&hw->phy_lock);
293 : 0 : ret_status = txgbe_set_link_to_amlite(hw, speed);
294 : : rte_spinlock_unlock(&hw->phy_lock);
295 : :
296 [ # # ]: 0 : if (ret_status == TXGBE_ERR_PHY_INIT_NOT_DONE)
297 : 0 : goto out;
298 : :
299 [ # # ]: 0 : if (ret_status == TXGBE_ERR_TIMEOUT) {
300 : 0 : hw->link_valid = false;
301 : 0 : link_up = false;
302 : 0 : goto out;
303 : : } else {
304 : 0 : hw->link_valid = true;
305 : : }
306 : :
307 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_25GB_FULL) {
308 : 0 : txgbe_e56_fec_polling(hw, &link_up);
309 : : } else {
310 [ # # ]: 0 : for (i = 0; i < 4; i++) {
311 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
312 [ # # ]: 0 : if (link_up)
313 : 0 : goto out;
314 : : msleep(250);
315 : : }
316 : : }
317 : :
318 : 0 : out:
319 [ # # ]: 0 : if (link_up) {
320 : : value = rd32(hw, TXGBE_PORTSTAT);
321 [ # # ]: 0 : if (!(value & TXGBE_PORTSTAT_UP)) {
322 : 0 : DEBUGOUT("MAC link 0x14404: 0x%x", value);
323 : 0 : *need_reset = true;
324 : : value = rd32(hw, 0x110b0);
325 : 0 : DEBUGOUT("MAC intr status 0x110b0: 0x%x", value);
326 : : }
327 : : } else {
328 : 0 : *need_reset = true;
329 : 0 : DEBUGOUT("Link reconfiguration required. Reset scheduled in 2000ms.");
330 : : }
331 : :
332 : : return status;
333 : : }
334 : :
335 : : /**
336 : : * txgbe_setup_mac_link_multispeed_fiber_aml - Set MAC link speed
337 : : * @hw: pointer to hardware structure
338 : : * @speed: new link speed
339 : : * @autoneg_wait_to_complete: true when waiting for completion is needed
340 : : *
341 : : * Set the link speed in the MAC and/or PHY register and restarts link.
342 : : **/
343 : 0 : static s32 txgbe_setup_mac_link_multispeed_fiber_aml(struct txgbe_hw *hw,
344 : : u32 speed,
345 : : bool autoneg_wait_to_complete)
346 : : {
347 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
348 : : u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
349 : 0 : bool autoneg, need_reset, link_up = false;
350 : : s32 status = 0;
351 : : u32 speedcnt = 0;
352 : :
353 : : /* Mask off requested but non-supported speeds */
354 : 0 : status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
355 [ # # ]: 0 : if (status != 0)
356 : : return status;
357 : :
358 : 0 : speed &= link_speed;
359 : :
360 : : /* Try each speed one by one, highest priority first. We do this in
361 : : * software because 25Gb fiber doesn't support speed autonegotiation.
362 : : */
363 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_25GB_FULL) {
364 : : speedcnt++;
365 : : highest_link_speed = TXGBE_LINK_SPEED_25GB_FULL;
366 : :
367 : : /* If we already have link at this speed, just jump out */
368 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
369 : :
370 : 0 : hw->cur_fec_link = txgbe_phy_fec_get(hw);
371 : :
372 [ # # # # ]: 0 : if (link_speed == TXGBE_LINK_SPEED_25GB_FULL && link_up &&
373 [ # # ]: 0 : hw->fec_mode & hw->cur_fec_link)
374 : 0 : goto out;
375 : :
376 : : /* Allow module to change analog characteristics (10G -> 25G) */
377 : : msec_delay(40);
378 : :
379 : 0 : status = hw->phy.setup_link_core(hw,
380 : : TXGBE_LINK_SPEED_25GB_FULL,
381 : : autoneg_wait_to_complete,
382 : : &need_reset);
383 [ # # ]: 0 : if (status != 0)
384 : : return status;
385 : :
386 : : /* Aml wait link in setup, no need to repeatedly wait */
387 : : /* If we have link, just jump out */
388 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
389 : :
390 [ # # ]: 0 : if (link_up)
391 : 0 : goto out;
392 : : }
393 : :
394 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
395 : 0 : speedcnt++;
396 [ # # ]: 0 : if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
397 : : highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
398 : :
399 : : /* If we already have link at this speed, just jump out */
400 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
401 : :
402 [ # # # # ]: 0 : if (link_speed == TXGBE_LINK_SPEED_10GB_FULL && link_up)
403 : 0 : goto out;
404 : :
405 : : /* Allow module to change analog characteristics (25G->10G) */
406 : : msec_delay(40);
407 : :
408 : 0 : status = hw->phy.setup_link_core(hw,
409 : : TXGBE_LINK_SPEED_10GB_FULL,
410 : : autoneg_wait_to_complete,
411 : : &need_reset);
412 [ # # ]: 0 : if (status != 0)
413 : : return status;
414 : :
415 : : /* Aml wait link in setup, no need to repeatedly wait */
416 : : /* If we have link, just jump out */
417 : 0 : txgbe_e56_check_phy_link(hw, &link_speed, &link_up);
418 : :
419 [ # # ]: 0 : if (link_up)
420 : 0 : goto out;
421 : : }
422 : :
423 : : /* We didn't get link. Configure back to the highest speed we tried,
424 : : * (if there was more than one). We call ourselves back with just the
425 : : * single highest speed that the user requested.
426 : : */
427 [ # # ]: 0 : if (speedcnt > 1)
428 : 0 : status = txgbe_setup_mac_link_multispeed_fiber_aml(hw,
429 : : highest_link_speed,
430 : : autoneg_wait_to_complete);
431 : :
432 : 0 : out:
433 : : /* Set autoneg_advertised value based on input link speed */
434 : 0 : hw->phy.autoneg_advertised = 0;
435 : :
436 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_25GB_FULL)
437 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_25GB_FULL;
438 : :
439 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_10GB_FULL)
440 : 0 : hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
441 : :
442 : : return status;
443 : : }
444 : :
445 : 0 : void txgbe_init_mac_link_ops_aml(struct txgbe_hw *hw)
446 : : {
447 : : struct txgbe_mac_info *mac = &hw->mac;
448 : :
449 [ # # ]: 0 : if (hw->phy.media_type == txgbe_media_type_fiber ||
450 : : hw->phy.media_type == txgbe_media_type_fiber_qsfp) {
451 : 0 : mac->disable_tx_laser =
452 : : txgbe_disable_tx_laser_multispeed_fiber;
453 : 0 : mac->enable_tx_laser =
454 : : txgbe_enable_tx_laser_multispeed_fiber;
455 : 0 : mac->flap_tx_laser =
456 : : txgbe_flap_tx_laser_multispeed_fiber;
457 : :
458 [ # # ]: 0 : if (hw->phy.multispeed_fiber) {
459 : : /* Set up dual speed SFP+ support */
460 : 0 : mac->setup_link = txgbe_setup_mac_link_multispeed_fiber_aml;
461 : 0 : mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
462 : : } else {
463 : 0 : mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
464 : : }
465 : : }
466 : 0 : }
|