1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
3 * Copyright(c) 2018 Synopsys, Inc. All rights reserved.
6 #include "axgbe_ethdev.h"
7 #include "axgbe_common.h"
10 #define AXGBE_PHY_PORT_SPEED_100 BIT(0)
11 #define AXGBE_PHY_PORT_SPEED_1000 BIT(1)
12 #define AXGBE_PHY_PORT_SPEED_2500 BIT(2)
13 #define AXGBE_PHY_PORT_SPEED_10000 BIT(3)
15 #define AXGBE_MUTEX_RELEASE 0x80000000
17 #define AXGBE_SFP_DIRECT 7
19 /* I2C target addresses */
20 #define AXGBE_SFP_SERIAL_ID_ADDRESS 0x50
21 #define AXGBE_SFP_DIAG_INFO_ADDRESS 0x51
22 #define AXGBE_SFP_PHY_ADDRESS 0x56
23 #define AXGBE_GPIO_ADDRESS_PCA9555 0x20
25 /* SFP sideband signal indicators */
26 #define AXGBE_GPIO_NO_TX_FAULT BIT(0)
27 #define AXGBE_GPIO_NO_RATE_SELECT BIT(1)
28 #define AXGBE_GPIO_NO_MOD_ABSENT BIT(2)
29 #define AXGBE_GPIO_NO_RX_LOS BIT(3)
31 /* Rate-change complete wait/retry count */
32 #define AXGBE_RATECHANGE_COUNT 500
34 /* CDR delay values for KR support (in usec) */
35 #define AXGBE_CDR_DELAY_INIT 10000
36 #define AXGBE_CDR_DELAY_INC 10000
37 #define AXGBE_CDR_DELAY_MAX 100000
39 enum axgbe_port_mode {
40 AXGBE_PORT_MODE_RSVD = 0,
41 AXGBE_PORT_MODE_BACKPLANE,
42 AXGBE_PORT_MODE_BACKPLANE_2500,
43 AXGBE_PORT_MODE_1000BASE_T,
44 AXGBE_PORT_MODE_1000BASE_X,
45 AXGBE_PORT_MODE_NBASE_T,
46 AXGBE_PORT_MODE_10GBASE_T,
47 AXGBE_PORT_MODE_10GBASE_R,
52 enum axgbe_conn_type {
53 AXGBE_CONN_TYPE_NONE = 0,
56 AXGBE_CONN_TYPE_RSVD1,
57 AXGBE_CONN_TYPE_BACKPLANE,
61 /* SFP/SFP+ related definitions */
63 AXGBE_SFP_COMM_DIRECT = 0,
64 AXGBE_SFP_COMM_PCA9545,
67 enum axgbe_sfp_cable {
68 AXGBE_SFP_CABLE_UNKNOWN = 0,
69 AXGBE_SFP_CABLE_ACTIVE,
70 AXGBE_SFP_CABLE_PASSIVE,
74 AXGBE_SFP_BASE_UNKNOWN = 0,
75 AXGBE_SFP_BASE_1000_T,
76 AXGBE_SFP_BASE_1000_SX,
77 AXGBE_SFP_BASE_1000_LX,
78 AXGBE_SFP_BASE_1000_CX,
79 AXGBE_SFP_BASE_10000_SR,
80 AXGBE_SFP_BASE_10000_LR,
81 AXGBE_SFP_BASE_10000_LRM,
82 AXGBE_SFP_BASE_10000_ER,
83 AXGBE_SFP_BASE_10000_CR,
86 enum axgbe_sfp_speed {
87 AXGBE_SFP_SPEED_UNKNOWN = 0,
88 AXGBE_SFP_SPEED_100_1000,
90 AXGBE_SFP_SPEED_10000,
93 /* SFP Serial ID Base ID values relative to an offset of 0 */
94 #define AXGBE_SFP_BASE_ID 0
95 #define AXGBE_SFP_ID_SFP 0x03
97 #define AXGBE_SFP_BASE_EXT_ID 1
98 #define AXGBE_SFP_EXT_ID_SFP 0x04
100 #define AXGBE_SFP_BASE_10GBE_CC 3
101 #define AXGBE_SFP_BASE_10GBE_CC_SR BIT(4)
102 #define AXGBE_SFP_BASE_10GBE_CC_LR BIT(5)
103 #define AXGBE_SFP_BASE_10GBE_CC_LRM BIT(6)
104 #define AXGBE_SFP_BASE_10GBE_CC_ER BIT(7)
106 #define AXGBE_SFP_BASE_1GBE_CC 6
107 #define AXGBE_SFP_BASE_1GBE_CC_SX BIT(0)
108 #define AXGBE_SFP_BASE_1GBE_CC_LX BIT(1)
109 #define AXGBE_SFP_BASE_1GBE_CC_CX BIT(2)
110 #define AXGBE_SFP_BASE_1GBE_CC_T BIT(3)
112 #define AXGBE_SFP_BASE_CABLE 8
113 #define AXGBE_SFP_BASE_CABLE_PASSIVE BIT(2)
114 #define AXGBE_SFP_BASE_CABLE_ACTIVE BIT(3)
116 #define AXGBE_SFP_BASE_BR 12
117 #define AXGBE_SFP_BASE_BR_1GBE_MIN 0x0a
118 #define AXGBE_SFP_BASE_BR_1GBE_MAX 0x0d
119 #define AXGBE_SFP_BASE_BR_10GBE_MIN 0x64
120 #define AXGBE_SFP_BASE_BR_10GBE_MAX 0x68
122 #define AXGBE_SFP_BASE_CU_CABLE_LEN 18
124 #define AXGBE_SFP_BASE_VENDOR_NAME 20
125 #define AXGBE_SFP_BASE_VENDOR_NAME_LEN 16
126 #define AXGBE_SFP_BASE_VENDOR_PN 40
127 #define AXGBE_SFP_BASE_VENDOR_PN_LEN 16
128 #define AXGBE_SFP_BASE_VENDOR_REV 56
129 #define AXGBE_SFP_BASE_VENDOR_REV_LEN 4
131 #define AXGBE_SFP_BASE_CC 63
133 /* SFP Serial ID Extended ID values relative to an offset of 64 */
134 #define AXGBE_SFP_BASE_VENDOR_SN 4
135 #define AXGBE_SFP_BASE_VENDOR_SN_LEN 16
137 #define AXGBE_SFP_EXTD_DIAG 28
138 #define AXGBE_SFP_EXTD_DIAG_ADDR_CHANGE BIT(2)
140 #define AXGBE_SFP_EXTD_SFF_8472 30
142 #define AXGBE_SFP_EXTD_CC 31
144 struct axgbe_sfp_eeprom {
150 #define AXGBE_BEL_FUSE_VENDOR "BEL-FUSE"
151 #define AXGBE_BEL_FUSE_PARTNO "1GBT-SFP06"
153 struct axgbe_sfp_ascii {
155 char vendor[AXGBE_SFP_BASE_VENDOR_NAME_LEN + 1];
156 char partno[AXGBE_SFP_BASE_VENDOR_PN_LEN + 1];
157 char rev[AXGBE_SFP_BASE_VENDOR_REV_LEN + 1];
158 char serno[AXGBE_SFP_BASE_VENDOR_SN_LEN + 1];
162 /* MDIO PHY reset types */
163 enum axgbe_mdio_reset {
164 AXGBE_MDIO_RESET_NONE = 0,
165 AXGBE_MDIO_RESET_I2C_GPIO,
166 AXGBE_MDIO_RESET_INT_GPIO,
167 AXGBE_MDIO_RESET_MAX,
170 /* Re-driver related definitions */
171 enum axgbe_phy_redrv_if {
172 AXGBE_PHY_REDRV_IF_MDIO = 0,
173 AXGBE_PHY_REDRV_IF_I2C,
174 AXGBE_PHY_REDRV_IF_MAX,
177 enum axgbe_phy_redrv_model {
178 AXGBE_PHY_REDRV_MODEL_4223 = 0,
179 AXGBE_PHY_REDRV_MODEL_4227,
180 AXGBE_PHY_REDRV_MODEL_MAX,
183 enum axgbe_phy_redrv_mode {
184 AXGBE_PHY_REDRV_MODE_CX = 5,
185 AXGBE_PHY_REDRV_MODE_SR = 9,
188 #define AXGBE_PHY_REDRV_MODE_REG 0x12b0
190 /* PHY related configuration information */
191 struct axgbe_phy_data {
192 enum axgbe_port_mode port_mode;
194 unsigned int port_id;
196 unsigned int port_speeds;
198 enum axgbe_conn_type conn_type;
200 enum axgbe_mode cur_mode;
201 enum axgbe_mode start_mode;
203 unsigned int rrc_count;
205 unsigned int mdio_addr;
207 unsigned int comm_owned;
210 enum axgbe_sfp_comm sfp_comm;
211 unsigned int sfp_mux_address;
212 unsigned int sfp_mux_channel;
214 unsigned int sfp_gpio_address;
215 unsigned int sfp_gpio_mask;
216 unsigned int sfp_gpio_rx_los;
217 unsigned int sfp_gpio_tx_fault;
218 unsigned int sfp_gpio_mod_absent;
219 unsigned int sfp_gpio_rate_select;
221 unsigned int sfp_rx_los;
222 unsigned int sfp_tx_fault;
223 unsigned int sfp_mod_absent;
224 unsigned int sfp_diags;
225 unsigned int sfp_changed;
226 unsigned int sfp_phy_avail;
227 unsigned int sfp_cable_len;
228 enum axgbe_sfp_base sfp_base;
229 enum axgbe_sfp_cable sfp_cable;
230 enum axgbe_sfp_speed sfp_speed;
231 struct axgbe_sfp_eeprom sfp_eeprom;
233 /* External PHY support */
234 enum axgbe_mdio_mode phydev_mode;
235 enum axgbe_mdio_reset mdio_reset;
236 unsigned int mdio_reset_addr;
237 unsigned int mdio_reset_gpio;
239 /* Re-driver support */
241 unsigned int redrv_if;
242 unsigned int redrv_addr;
243 unsigned int redrv_lane;
244 unsigned int redrv_model;
247 unsigned int phy_cdr_notrack;
248 unsigned int phy_cdr_delay;
251 static enum axgbe_an_mode axgbe_phy_an_mode(struct axgbe_port *pdata);
253 static int axgbe_phy_i2c_xfer(struct axgbe_port *pdata,
254 struct axgbe_i2c_op *i2c_op)
256 struct axgbe_phy_data *phy_data = pdata->phy_data;
258 /* Be sure we own the bus */
259 if (!phy_data->comm_owned)
262 return pdata->i2c_if.i2c_xfer(pdata, i2c_op);
265 static int axgbe_phy_redrv_write(struct axgbe_port *pdata, unsigned int reg,
268 struct axgbe_phy_data *phy_data = pdata->phy_data;
269 struct axgbe_i2c_op i2c_op;
271 u8 redrv_data[5], csum;
272 unsigned int i, retry;
275 /* High byte of register contains read/write indicator */
276 redrv_data[0] = ((reg >> 8) & 0xff) << 1;
277 redrv_data[1] = reg & 0xff;
278 redrv_val = (uint16_t *)&redrv_data[2];
279 *redrv_val = rte_cpu_to_be_16(val);
281 /* Calculate 1 byte checksum */
283 for (i = 0; i < 4; i++) {
284 csum += redrv_data[i];
285 if (redrv_data[i] > csum)
288 redrv_data[4] = ~csum;
292 i2c_op.cmd = AXGBE_I2C_CMD_WRITE;
293 i2c_op.target = phy_data->redrv_addr;
294 i2c_op.len = sizeof(redrv_data);
295 i2c_op.buf = redrv_data;
296 ret = axgbe_phy_i2c_xfer(pdata, &i2c_op);
298 if ((ret == -EAGAIN) && retry--)
306 i2c_op.cmd = AXGBE_I2C_CMD_READ;
307 i2c_op.target = phy_data->redrv_addr;
309 i2c_op.buf = redrv_data;
310 ret = axgbe_phy_i2c_xfer(pdata, &i2c_op);
312 if ((ret == -EAGAIN) && retry--)
318 if (redrv_data[0] != 0xff) {
319 PMD_DRV_LOG(ERR, "Redriver write checksum error\n");
326 static int axgbe_phy_i2c_read(struct axgbe_port *pdata, unsigned int target,
327 void *reg, unsigned int reg_len,
328 void *val, unsigned int val_len)
330 struct axgbe_i2c_op i2c_op;
335 /* Set the specified register to read */
336 i2c_op.cmd = AXGBE_I2C_CMD_WRITE;
337 i2c_op.target = target;
338 i2c_op.len = reg_len;
340 ret = axgbe_phy_i2c_xfer(pdata, &i2c_op);
342 if ((ret == -EAGAIN) && retry--)
350 /* Read the specfied register */
351 i2c_op.cmd = AXGBE_I2C_CMD_READ;
352 i2c_op.target = target;
353 i2c_op.len = val_len;
355 ret = axgbe_phy_i2c_xfer(pdata, &i2c_op);
356 if ((ret == -EAGAIN) && retry--)
362 static int axgbe_phy_sfp_put_mux(struct axgbe_port *pdata)
364 struct axgbe_phy_data *phy_data = pdata->phy_data;
365 struct axgbe_i2c_op i2c_op;
368 if (phy_data->sfp_comm == AXGBE_SFP_COMM_DIRECT)
371 /* Select no mux channels */
373 i2c_op.cmd = AXGBE_I2C_CMD_WRITE;
374 i2c_op.target = phy_data->sfp_mux_address;
375 i2c_op.len = sizeof(mux_channel);
376 i2c_op.buf = &mux_channel;
378 return axgbe_phy_i2c_xfer(pdata, &i2c_op);
381 static int axgbe_phy_sfp_get_mux(struct axgbe_port *pdata)
383 struct axgbe_phy_data *phy_data = pdata->phy_data;
384 struct axgbe_i2c_op i2c_op;
387 if (phy_data->sfp_comm == AXGBE_SFP_COMM_DIRECT)
390 /* Select desired mux channel */
391 mux_channel = 1 << phy_data->sfp_mux_channel;
392 i2c_op.cmd = AXGBE_I2C_CMD_WRITE;
393 i2c_op.target = phy_data->sfp_mux_address;
394 i2c_op.len = sizeof(mux_channel);
395 i2c_op.buf = &mux_channel;
397 return axgbe_phy_i2c_xfer(pdata, &i2c_op);
400 static void axgbe_phy_put_comm_ownership(struct axgbe_port *pdata)
402 struct axgbe_phy_data *phy_data = pdata->phy_data;
404 phy_data->comm_owned = 0;
406 pthread_mutex_unlock(&pdata->phy_mutex);
409 static int axgbe_phy_get_comm_ownership(struct axgbe_port *pdata)
411 struct axgbe_phy_data *phy_data = pdata->phy_data;
413 unsigned int mutex_id;
415 if (phy_data->comm_owned)
418 /* The I2C and MDIO/GPIO bus is multiplexed between multiple devices,
419 * the driver needs to take the software mutex and then the hardware
420 * mutexes before being able to use the busses.
422 pthread_mutex_lock(&pdata->phy_mutex);
424 /* Clear the mutexes */
425 XP_IOWRITE(pdata, XP_I2C_MUTEX, AXGBE_MUTEX_RELEASE);
426 XP_IOWRITE(pdata, XP_MDIO_MUTEX, AXGBE_MUTEX_RELEASE);
428 /* Mutex formats are the same for I2C and MDIO/GPIO */
430 XP_SET_BITS(mutex_id, XP_I2C_MUTEX, ID, phy_data->port_id);
431 XP_SET_BITS(mutex_id, XP_I2C_MUTEX, ACTIVE, 1);
433 timeout = rte_get_timer_cycles() + (rte_get_timer_hz() * 5);
434 while (time_before(rte_get_timer_cycles(), timeout)) {
435 /* Must be all zeroes in order to obtain the mutex */
436 if (XP_IOREAD(pdata, XP_I2C_MUTEX) ||
437 XP_IOREAD(pdata, XP_MDIO_MUTEX)) {
442 /* Obtain the mutex */
443 XP_IOWRITE(pdata, XP_I2C_MUTEX, mutex_id);
444 XP_IOWRITE(pdata, XP_MDIO_MUTEX, mutex_id);
446 phy_data->comm_owned = 1;
450 pthread_mutex_unlock(&pdata->phy_mutex);
452 PMD_DRV_LOG(ERR, "unable to obtain hardware mutexes\n");
457 static void axgbe_phy_sfp_phy_settings(struct axgbe_port *pdata)
459 struct axgbe_phy_data *phy_data = pdata->phy_data;
461 if (phy_data->sfp_mod_absent) {
462 pdata->phy.speed = SPEED_UNKNOWN;
463 pdata->phy.duplex = DUPLEX_UNKNOWN;
464 pdata->phy.autoneg = AUTONEG_ENABLE;
465 pdata->phy.advertising = pdata->phy.supported;
468 pdata->phy.advertising &= ~ADVERTISED_Autoneg;
469 pdata->phy.advertising &= ~ADVERTISED_TP;
470 pdata->phy.advertising &= ~ADVERTISED_FIBRE;
471 pdata->phy.advertising &= ~ADVERTISED_100baseT_Full;
472 pdata->phy.advertising &= ~ADVERTISED_1000baseT_Full;
473 pdata->phy.advertising &= ~ADVERTISED_10000baseT_Full;
474 pdata->phy.advertising &= ~ADVERTISED_10000baseR_FEC;
476 switch (phy_data->sfp_base) {
477 case AXGBE_SFP_BASE_1000_T:
478 case AXGBE_SFP_BASE_1000_SX:
479 case AXGBE_SFP_BASE_1000_LX:
480 case AXGBE_SFP_BASE_1000_CX:
481 pdata->phy.speed = SPEED_UNKNOWN;
482 pdata->phy.duplex = DUPLEX_UNKNOWN;
483 pdata->phy.autoneg = AUTONEG_ENABLE;
484 pdata->phy.advertising |= ADVERTISED_Autoneg;
486 case AXGBE_SFP_BASE_10000_SR:
487 case AXGBE_SFP_BASE_10000_LR:
488 case AXGBE_SFP_BASE_10000_LRM:
489 case AXGBE_SFP_BASE_10000_ER:
490 case AXGBE_SFP_BASE_10000_CR:
492 pdata->phy.speed = SPEED_10000;
493 pdata->phy.duplex = DUPLEX_FULL;
494 pdata->phy.autoneg = AUTONEG_DISABLE;
498 switch (phy_data->sfp_base) {
499 case AXGBE_SFP_BASE_1000_T:
500 case AXGBE_SFP_BASE_1000_CX:
501 case AXGBE_SFP_BASE_10000_CR:
502 pdata->phy.advertising |= ADVERTISED_TP;
505 pdata->phy.advertising |= ADVERTISED_FIBRE;
508 switch (phy_data->sfp_speed) {
509 case AXGBE_SFP_SPEED_100_1000:
510 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100)
511 pdata->phy.advertising |= ADVERTISED_100baseT_Full;
512 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000)
513 pdata->phy.advertising |= ADVERTISED_1000baseT_Full;
515 case AXGBE_SFP_SPEED_1000:
516 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000)
517 pdata->phy.advertising |= ADVERTISED_1000baseT_Full;
519 case AXGBE_SFP_SPEED_10000:
520 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000)
521 pdata->phy.advertising |= ADVERTISED_10000baseT_Full;
524 /* Choose the fastest supported speed */
525 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000)
526 pdata->phy.advertising |= ADVERTISED_10000baseT_Full;
527 else if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000)
528 pdata->phy.advertising |= ADVERTISED_1000baseT_Full;
529 else if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100)
530 pdata->phy.advertising |= ADVERTISED_100baseT_Full;
534 static bool axgbe_phy_sfp_bit_rate(struct axgbe_sfp_eeprom *sfp_eeprom,
535 enum axgbe_sfp_speed sfp_speed)
537 u8 *sfp_base, min, max;
539 sfp_base = sfp_eeprom->base;
542 case AXGBE_SFP_SPEED_1000:
543 min = AXGBE_SFP_BASE_BR_1GBE_MIN;
544 max = AXGBE_SFP_BASE_BR_1GBE_MAX;
546 case AXGBE_SFP_SPEED_10000:
547 min = AXGBE_SFP_BASE_BR_10GBE_MIN;
548 max = AXGBE_SFP_BASE_BR_10GBE_MAX;
554 return ((sfp_base[AXGBE_SFP_BASE_BR] >= min) &&
555 (sfp_base[AXGBE_SFP_BASE_BR] <= max));
558 static void axgbe_phy_sfp_external_phy(struct axgbe_port *pdata)
560 struct axgbe_phy_data *phy_data = pdata->phy_data;
562 if (!phy_data->sfp_changed)
565 phy_data->sfp_phy_avail = 0;
567 if (phy_data->sfp_base != AXGBE_SFP_BASE_1000_T)
571 static bool axgbe_phy_belfuse_parse_quirks(struct axgbe_port *pdata)
573 struct axgbe_phy_data *phy_data = pdata->phy_data;
574 struct axgbe_sfp_eeprom *sfp_eeprom = &phy_data->sfp_eeprom;
576 if (memcmp(&sfp_eeprom->base[AXGBE_SFP_BASE_VENDOR_NAME],
577 AXGBE_BEL_FUSE_VENDOR, strlen(AXGBE_BEL_FUSE_VENDOR)))
580 if (!memcmp(&sfp_eeprom->base[AXGBE_SFP_BASE_VENDOR_PN],
581 AXGBE_BEL_FUSE_PARTNO, strlen(AXGBE_BEL_FUSE_PARTNO))) {
582 phy_data->sfp_base = AXGBE_SFP_BASE_1000_SX;
583 phy_data->sfp_cable = AXGBE_SFP_CABLE_ACTIVE;
584 phy_data->sfp_speed = AXGBE_SFP_SPEED_1000;
591 static bool axgbe_phy_sfp_parse_quirks(struct axgbe_port *pdata)
593 if (axgbe_phy_belfuse_parse_quirks(pdata))
599 static void axgbe_phy_sfp_parse_eeprom(struct axgbe_port *pdata)
601 struct axgbe_phy_data *phy_data = pdata->phy_data;
602 struct axgbe_sfp_eeprom *sfp_eeprom = &phy_data->sfp_eeprom;
605 sfp_base = sfp_eeprom->base;
607 if (sfp_base[AXGBE_SFP_BASE_ID] != AXGBE_SFP_ID_SFP)
610 if (sfp_base[AXGBE_SFP_BASE_EXT_ID] != AXGBE_SFP_EXT_ID_SFP)
613 if (axgbe_phy_sfp_parse_quirks(pdata))
616 /* Assume ACTIVE cable unless told it is PASSIVE */
617 if (sfp_base[AXGBE_SFP_BASE_CABLE] & AXGBE_SFP_BASE_CABLE_PASSIVE) {
618 phy_data->sfp_cable = AXGBE_SFP_CABLE_PASSIVE;
619 phy_data->sfp_cable_len = sfp_base[AXGBE_SFP_BASE_CU_CABLE_LEN];
621 phy_data->sfp_cable = AXGBE_SFP_CABLE_ACTIVE;
624 /* Determine the type of SFP */
625 if (sfp_base[AXGBE_SFP_BASE_10GBE_CC] & AXGBE_SFP_BASE_10GBE_CC_SR)
626 phy_data->sfp_base = AXGBE_SFP_BASE_10000_SR;
627 else if (sfp_base[AXGBE_SFP_BASE_10GBE_CC] & AXGBE_SFP_BASE_10GBE_CC_LR)
628 phy_data->sfp_base = AXGBE_SFP_BASE_10000_LR;
629 else if (sfp_base[AXGBE_SFP_BASE_10GBE_CC] &
630 AXGBE_SFP_BASE_10GBE_CC_LRM)
631 phy_data->sfp_base = AXGBE_SFP_BASE_10000_LRM;
632 else if (sfp_base[AXGBE_SFP_BASE_10GBE_CC] & AXGBE_SFP_BASE_10GBE_CC_ER)
633 phy_data->sfp_base = AXGBE_SFP_BASE_10000_ER;
634 else if (sfp_base[AXGBE_SFP_BASE_1GBE_CC] & AXGBE_SFP_BASE_1GBE_CC_SX)
635 phy_data->sfp_base = AXGBE_SFP_BASE_1000_SX;
636 else if (sfp_base[AXGBE_SFP_BASE_1GBE_CC] & AXGBE_SFP_BASE_1GBE_CC_LX)
637 phy_data->sfp_base = AXGBE_SFP_BASE_1000_LX;
638 else if (sfp_base[AXGBE_SFP_BASE_1GBE_CC] & AXGBE_SFP_BASE_1GBE_CC_CX)
639 phy_data->sfp_base = AXGBE_SFP_BASE_1000_CX;
640 else if (sfp_base[AXGBE_SFP_BASE_1GBE_CC] & AXGBE_SFP_BASE_1GBE_CC_T)
641 phy_data->sfp_base = AXGBE_SFP_BASE_1000_T;
642 else if ((phy_data->sfp_cable == AXGBE_SFP_CABLE_PASSIVE) &&
643 axgbe_phy_sfp_bit_rate(sfp_eeprom, AXGBE_SFP_SPEED_10000))
644 phy_data->sfp_base = AXGBE_SFP_BASE_10000_CR;
646 switch (phy_data->sfp_base) {
647 case AXGBE_SFP_BASE_1000_T:
648 phy_data->sfp_speed = AXGBE_SFP_SPEED_100_1000;
650 case AXGBE_SFP_BASE_1000_SX:
651 case AXGBE_SFP_BASE_1000_LX:
652 case AXGBE_SFP_BASE_1000_CX:
653 phy_data->sfp_speed = AXGBE_SFP_SPEED_1000;
655 case AXGBE_SFP_BASE_10000_SR:
656 case AXGBE_SFP_BASE_10000_LR:
657 case AXGBE_SFP_BASE_10000_LRM:
658 case AXGBE_SFP_BASE_10000_ER:
659 case AXGBE_SFP_BASE_10000_CR:
660 phy_data->sfp_speed = AXGBE_SFP_SPEED_10000;
667 static bool axgbe_phy_sfp_verify_eeprom(uint8_t cc_in, uint8_t *buf,
672 for (cc = 0; len; buf++, len--)
675 return (cc == cc_in) ? true : false;
678 static int axgbe_phy_sfp_read_eeprom(struct axgbe_port *pdata)
680 struct axgbe_phy_data *phy_data = pdata->phy_data;
681 struct axgbe_sfp_eeprom sfp_eeprom;
685 ret = axgbe_phy_sfp_get_mux(pdata);
687 PMD_DRV_LOG(ERR, "I2C error setting SFP MUX\n");
691 /* Read the SFP serial ID eeprom */
693 ret = axgbe_phy_i2c_read(pdata, AXGBE_SFP_SERIAL_ID_ADDRESS,
694 &eeprom_addr, sizeof(eeprom_addr),
695 &sfp_eeprom, sizeof(sfp_eeprom));
697 PMD_DRV_LOG(ERR, "I2C error reading SFP EEPROM\n");
701 /* Validate the contents read */
702 if (!axgbe_phy_sfp_verify_eeprom(sfp_eeprom.base[AXGBE_SFP_BASE_CC],
704 sizeof(sfp_eeprom.base) - 1)) {
709 if (!axgbe_phy_sfp_verify_eeprom(sfp_eeprom.extd[AXGBE_SFP_EXTD_CC],
711 sizeof(sfp_eeprom.extd) - 1)) {
716 /* Check for an added or changed SFP */
717 if (memcmp(&phy_data->sfp_eeprom, &sfp_eeprom, sizeof(sfp_eeprom))) {
718 phy_data->sfp_changed = 1;
719 memcpy(&phy_data->sfp_eeprom, &sfp_eeprom, sizeof(sfp_eeprom));
721 if (sfp_eeprom.extd[AXGBE_SFP_EXTD_SFF_8472]) {
723 diag_type = sfp_eeprom.extd[AXGBE_SFP_EXTD_DIAG];
725 if (!(diag_type & AXGBE_SFP_EXTD_DIAG_ADDR_CHANGE))
726 phy_data->sfp_diags = 1;
729 phy_data->sfp_changed = 0;
733 axgbe_phy_sfp_put_mux(pdata);
738 static void axgbe_phy_sfp_signals(struct axgbe_port *pdata)
740 struct axgbe_phy_data *phy_data = pdata->phy_data;
741 unsigned int gpio_input;
742 u8 gpio_reg, gpio_ports[2];
745 /* Read the input port registers */
747 ret = axgbe_phy_i2c_read(pdata, phy_data->sfp_gpio_address,
748 &gpio_reg, sizeof(gpio_reg),
749 gpio_ports, sizeof(gpio_ports));
751 PMD_DRV_LOG(ERR, "I2C error reading SFP GPIOs\n");
755 gpio_input = (gpio_ports[1] << 8) | gpio_ports[0];
757 if (phy_data->sfp_gpio_mask & AXGBE_GPIO_NO_MOD_ABSENT) {
758 /* No GPIO, just assume the module is present for now */
759 phy_data->sfp_mod_absent = 0;
761 if (!(gpio_input & (1 << phy_data->sfp_gpio_mod_absent)))
762 phy_data->sfp_mod_absent = 0;
765 if (!(phy_data->sfp_gpio_mask & AXGBE_GPIO_NO_RX_LOS) &&
766 (gpio_input & (1 << phy_data->sfp_gpio_rx_los)))
767 phy_data->sfp_rx_los = 1;
769 if (!(phy_data->sfp_gpio_mask & AXGBE_GPIO_NO_TX_FAULT) &&
770 (gpio_input & (1 << phy_data->sfp_gpio_tx_fault)))
771 phy_data->sfp_tx_fault = 1;
774 static void axgbe_phy_sfp_mod_absent(struct axgbe_port *pdata)
776 struct axgbe_phy_data *phy_data = pdata->phy_data;
778 phy_data->sfp_mod_absent = 1;
779 phy_data->sfp_phy_avail = 0;
780 memset(&phy_data->sfp_eeprom, 0, sizeof(phy_data->sfp_eeprom));
783 static void axgbe_phy_sfp_reset(struct axgbe_phy_data *phy_data)
785 phy_data->sfp_rx_los = 0;
786 phy_data->sfp_tx_fault = 0;
787 phy_data->sfp_mod_absent = 1;
788 phy_data->sfp_diags = 0;
789 phy_data->sfp_base = AXGBE_SFP_BASE_UNKNOWN;
790 phy_data->sfp_cable = AXGBE_SFP_CABLE_UNKNOWN;
791 phy_data->sfp_speed = AXGBE_SFP_SPEED_UNKNOWN;
794 static void axgbe_phy_sfp_detect(struct axgbe_port *pdata)
796 struct axgbe_phy_data *phy_data = pdata->phy_data;
799 /* Reset the SFP signals and info */
800 axgbe_phy_sfp_reset(phy_data);
802 ret = axgbe_phy_get_comm_ownership(pdata);
806 /* Read the SFP signals and check for module presence */
807 axgbe_phy_sfp_signals(pdata);
808 if (phy_data->sfp_mod_absent) {
809 axgbe_phy_sfp_mod_absent(pdata);
813 ret = axgbe_phy_sfp_read_eeprom(pdata);
815 /* Treat any error as if there isn't an SFP plugged in */
816 axgbe_phy_sfp_reset(phy_data);
817 axgbe_phy_sfp_mod_absent(pdata);
821 axgbe_phy_sfp_parse_eeprom(pdata);
822 axgbe_phy_sfp_external_phy(pdata);
825 axgbe_phy_sfp_phy_settings(pdata);
826 axgbe_phy_put_comm_ownership(pdata);
829 static void axgbe_phy_phydev_flowctrl(struct axgbe_port *pdata)
831 pdata->phy.tx_pause = 0;
832 pdata->phy.rx_pause = 0;
835 static enum axgbe_mode axgbe_phy_an73_redrv_outcome(struct axgbe_port *pdata)
837 struct axgbe_phy_data *phy_data = pdata->phy_data;
838 enum axgbe_mode mode;
839 unsigned int ad_reg, lp_reg;
841 pdata->phy.lp_advertising |= ADVERTISED_Autoneg;
842 pdata->phy.lp_advertising |= ADVERTISED_Backplane;
844 /* Use external PHY to determine flow control */
845 if (pdata->phy.pause_autoneg)
846 axgbe_phy_phydev_flowctrl(pdata);
848 /* Compare Advertisement and Link Partner register 2 */
849 ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1);
850 lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 1);
852 pdata->phy.lp_advertising |= ADVERTISED_10000baseKR_Full;
854 pdata->phy.lp_advertising |= ADVERTISED_1000baseKX_Full;
858 switch (phy_data->port_mode) {
859 case AXGBE_PORT_MODE_BACKPLANE:
860 mode = AXGBE_MODE_KR;
863 mode = AXGBE_MODE_SFI;
866 } else if (ad_reg & 0x20) {
867 switch (phy_data->port_mode) {
868 case AXGBE_PORT_MODE_BACKPLANE:
869 mode = AXGBE_MODE_KX_1000;
871 case AXGBE_PORT_MODE_1000BASE_X:
874 case AXGBE_PORT_MODE_SFP:
875 switch (phy_data->sfp_base) {
876 case AXGBE_SFP_BASE_1000_T:
877 mode = AXGBE_MODE_SGMII_1000;
879 case AXGBE_SFP_BASE_1000_SX:
880 case AXGBE_SFP_BASE_1000_LX:
881 case AXGBE_SFP_BASE_1000_CX:
888 mode = AXGBE_MODE_SGMII_1000;
892 mode = AXGBE_MODE_UNKNOWN;
895 /* Compare Advertisement and Link Partner register 3 */
896 ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2);
897 lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 2);
899 pdata->phy.lp_advertising |= ADVERTISED_10000baseR_FEC;
904 static enum axgbe_mode axgbe_phy_an73_outcome(struct axgbe_port *pdata)
906 enum axgbe_mode mode;
907 unsigned int ad_reg, lp_reg;
909 pdata->phy.lp_advertising |= ADVERTISED_Autoneg;
910 pdata->phy.lp_advertising |= ADVERTISED_Backplane;
912 /* Compare Advertisement and Link Partner register 1 */
913 ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE);
914 lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA);
916 pdata->phy.lp_advertising |= ADVERTISED_Pause;
918 pdata->phy.lp_advertising |= ADVERTISED_Asym_Pause;
920 if (pdata->phy.pause_autoneg) {
921 /* Set flow control based on auto-negotiation result */
922 pdata->phy.tx_pause = 0;
923 pdata->phy.rx_pause = 0;
925 if (ad_reg & lp_reg & 0x400) {
926 pdata->phy.tx_pause = 1;
927 pdata->phy.rx_pause = 1;
928 } else if (ad_reg & lp_reg & 0x800) {
930 pdata->phy.rx_pause = 1;
931 else if (lp_reg & 0x400)
932 pdata->phy.tx_pause = 1;
936 /* Compare Advertisement and Link Partner register 2 */
937 ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 1);
938 lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 1);
940 pdata->phy.lp_advertising |= ADVERTISED_10000baseKR_Full;
942 pdata->phy.lp_advertising |= ADVERTISED_1000baseKX_Full;
946 mode = AXGBE_MODE_KR;
947 else if (ad_reg & 0x20)
948 mode = AXGBE_MODE_KX_1000;
950 mode = AXGBE_MODE_UNKNOWN;
952 /* Compare Advertisement and Link Partner register 3 */
953 ad_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_ADVERTISE + 2);
954 lp_reg = XMDIO_READ(pdata, MDIO_MMD_AN, MDIO_AN_LPA + 2);
956 pdata->phy.lp_advertising |= ADVERTISED_10000baseR_FEC;
961 static enum axgbe_mode axgbe_phy_an_outcome(struct axgbe_port *pdata)
963 switch (pdata->an_mode) {
964 case AXGBE_AN_MODE_CL73:
965 return axgbe_phy_an73_outcome(pdata);
966 case AXGBE_AN_MODE_CL73_REDRV:
967 return axgbe_phy_an73_redrv_outcome(pdata);
968 case AXGBE_AN_MODE_CL37:
969 case AXGBE_AN_MODE_CL37_SGMII:
971 return AXGBE_MODE_UNKNOWN;
975 static unsigned int axgbe_phy_an_advertising(struct axgbe_port *pdata)
977 struct axgbe_phy_data *phy_data = pdata->phy_data;
978 unsigned int advertising;
980 /* Without a re-driver, just return current advertising */
981 if (!phy_data->redrv)
982 return pdata->phy.advertising;
984 /* With the KR re-driver we need to advertise a single speed */
985 advertising = pdata->phy.advertising;
986 advertising &= ~ADVERTISED_1000baseKX_Full;
987 advertising &= ~ADVERTISED_10000baseKR_Full;
989 switch (phy_data->port_mode) {
990 case AXGBE_PORT_MODE_BACKPLANE:
991 advertising |= ADVERTISED_10000baseKR_Full;
993 case AXGBE_PORT_MODE_BACKPLANE_2500:
994 advertising |= ADVERTISED_1000baseKX_Full;
996 case AXGBE_PORT_MODE_1000BASE_T:
997 case AXGBE_PORT_MODE_1000BASE_X:
998 case AXGBE_PORT_MODE_NBASE_T:
999 advertising |= ADVERTISED_1000baseKX_Full;
1001 case AXGBE_PORT_MODE_10GBASE_T:
1002 PMD_DRV_LOG(ERR, "10GBASE_T mode is not supported\n");
1004 case AXGBE_PORT_MODE_10GBASE_R:
1005 advertising |= ADVERTISED_10000baseKR_Full;
1007 case AXGBE_PORT_MODE_SFP:
1008 switch (phy_data->sfp_base) {
1009 case AXGBE_SFP_BASE_1000_T:
1010 case AXGBE_SFP_BASE_1000_SX:
1011 case AXGBE_SFP_BASE_1000_LX:
1012 case AXGBE_SFP_BASE_1000_CX:
1013 advertising |= ADVERTISED_1000baseKX_Full;
1016 advertising |= ADVERTISED_10000baseKR_Full;
1021 advertising |= ADVERTISED_10000baseKR_Full;
1028 static int axgbe_phy_an_config(struct axgbe_port *pdata __rte_unused)
1031 /* Dummy API since there is no case to support
1032 * external phy devices registred through kerenl apis
1036 static enum axgbe_an_mode axgbe_phy_an_sfp_mode(struct axgbe_phy_data *phy_data)
1038 switch (phy_data->sfp_base) {
1039 case AXGBE_SFP_BASE_1000_T:
1040 return AXGBE_AN_MODE_CL37_SGMII;
1041 case AXGBE_SFP_BASE_1000_SX:
1042 case AXGBE_SFP_BASE_1000_LX:
1043 case AXGBE_SFP_BASE_1000_CX:
1044 return AXGBE_AN_MODE_CL37;
1046 return AXGBE_AN_MODE_NONE;
1050 static enum axgbe_an_mode axgbe_phy_an_mode(struct axgbe_port *pdata)
1052 struct axgbe_phy_data *phy_data = pdata->phy_data;
1054 /* A KR re-driver will always require CL73 AN */
1055 if (phy_data->redrv)
1056 return AXGBE_AN_MODE_CL73_REDRV;
1058 switch (phy_data->port_mode) {
1059 case AXGBE_PORT_MODE_BACKPLANE:
1060 return AXGBE_AN_MODE_CL73;
1061 case AXGBE_PORT_MODE_BACKPLANE_2500:
1062 return AXGBE_AN_MODE_NONE;
1063 case AXGBE_PORT_MODE_1000BASE_T:
1064 return AXGBE_AN_MODE_CL37_SGMII;
1065 case AXGBE_PORT_MODE_1000BASE_X:
1066 return AXGBE_AN_MODE_CL37;
1067 case AXGBE_PORT_MODE_NBASE_T:
1068 return AXGBE_AN_MODE_CL37_SGMII;
1069 case AXGBE_PORT_MODE_10GBASE_T:
1070 return AXGBE_AN_MODE_CL73;
1071 case AXGBE_PORT_MODE_10GBASE_R:
1072 return AXGBE_AN_MODE_NONE;
1073 case AXGBE_PORT_MODE_SFP:
1074 return axgbe_phy_an_sfp_mode(phy_data);
1076 return AXGBE_AN_MODE_NONE;
1080 static int axgbe_phy_set_redrv_mode_mdio(struct axgbe_port *pdata,
1081 enum axgbe_phy_redrv_mode mode)
1083 struct axgbe_phy_data *phy_data = pdata->phy_data;
1084 u16 redrv_reg, redrv_val;
1086 redrv_reg = AXGBE_PHY_REDRV_MODE_REG + (phy_data->redrv_lane * 0x1000);
1087 redrv_val = (u16)mode;
1089 return pdata->hw_if.write_ext_mii_regs(pdata, phy_data->redrv_addr,
1090 redrv_reg, redrv_val);
1093 static int axgbe_phy_set_redrv_mode_i2c(struct axgbe_port *pdata,
1094 enum axgbe_phy_redrv_mode mode)
1096 struct axgbe_phy_data *phy_data = pdata->phy_data;
1097 unsigned int redrv_reg;
1100 /* Calculate the register to write */
1101 redrv_reg = AXGBE_PHY_REDRV_MODE_REG + (phy_data->redrv_lane * 0x1000);
1103 ret = axgbe_phy_redrv_write(pdata, redrv_reg, mode);
1108 static void axgbe_phy_set_redrv_mode(struct axgbe_port *pdata)
1110 struct axgbe_phy_data *phy_data = pdata->phy_data;
1111 enum axgbe_phy_redrv_mode mode;
1114 if (!phy_data->redrv)
1117 mode = AXGBE_PHY_REDRV_MODE_CX;
1118 if ((phy_data->port_mode == AXGBE_PORT_MODE_SFP) &&
1119 (phy_data->sfp_base != AXGBE_SFP_BASE_1000_CX) &&
1120 (phy_data->sfp_base != AXGBE_SFP_BASE_10000_CR))
1121 mode = AXGBE_PHY_REDRV_MODE_SR;
1123 ret = axgbe_phy_get_comm_ownership(pdata);
1127 if (phy_data->redrv_if)
1128 axgbe_phy_set_redrv_mode_i2c(pdata, mode);
1130 axgbe_phy_set_redrv_mode_mdio(pdata, mode);
1132 axgbe_phy_put_comm_ownership(pdata);
1135 static void axgbe_phy_start_ratechange(struct axgbe_port *pdata)
1137 if (!XP_IOREAD_BITS(pdata, XP_DRIVER_INT_RO, STATUS))
1141 static void axgbe_phy_complete_ratechange(struct axgbe_port *pdata)
1145 /* Wait for command to complete */
1146 wait = AXGBE_RATECHANGE_COUNT;
1148 if (!XP_IOREAD_BITS(pdata, XP_DRIVER_INT_RO, STATUS))
1155 static void axgbe_phy_rrc(struct axgbe_port *pdata)
1159 axgbe_phy_start_ratechange(pdata);
1161 /* Receiver Reset Cycle */
1163 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 5);
1164 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
1166 /* Call FW to make the change */
1167 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
1168 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
1169 XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
1171 axgbe_phy_complete_ratechange(pdata);
1174 static void axgbe_phy_power_off(struct axgbe_port *pdata)
1176 struct axgbe_phy_data *phy_data = pdata->phy_data;
1178 axgbe_phy_start_ratechange(pdata);
1180 /* Call FW to make the change */
1181 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, 0);
1182 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
1183 XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
1184 axgbe_phy_complete_ratechange(pdata);
1185 phy_data->cur_mode = AXGBE_MODE_UNKNOWN;
1188 static void axgbe_phy_sfi_mode(struct axgbe_port *pdata)
1190 struct axgbe_phy_data *phy_data = pdata->phy_data;
1193 axgbe_phy_set_redrv_mode(pdata);
1195 axgbe_phy_start_ratechange(pdata);
1199 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 3);
1200 if (phy_data->sfp_cable != AXGBE_SFP_CABLE_PASSIVE) {
1201 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
1203 if (phy_data->sfp_cable_len <= 1)
1204 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 1);
1205 else if (phy_data->sfp_cable_len <= 3)
1206 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 2);
1208 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 3);
1211 /* Call FW to make the change */
1212 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
1213 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
1214 XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
1215 axgbe_phy_complete_ratechange(pdata);
1216 phy_data->cur_mode = AXGBE_MODE_SFI;
1219 static void axgbe_phy_kr_mode(struct axgbe_port *pdata)
1221 struct axgbe_phy_data *phy_data = pdata->phy_data;
1224 axgbe_phy_set_redrv_mode(pdata);
1226 axgbe_phy_start_ratechange(pdata);
1230 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, 4);
1231 XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, 0);
1233 /* Call FW to make the change */
1234 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
1235 XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
1236 XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);
1237 axgbe_phy_complete_ratechange(pdata);
1238 phy_data->cur_mode = AXGBE_MODE_KR;
1241 static enum axgbe_mode axgbe_phy_cur_mode(struct axgbe_port *pdata)
1243 struct axgbe_phy_data *phy_data = pdata->phy_data;
1245 return phy_data->cur_mode;
1248 static enum axgbe_mode axgbe_phy_switch_baset_mode(struct axgbe_port *pdata)
1250 struct axgbe_phy_data *phy_data = pdata->phy_data;
1252 /* No switching if not 10GBase-T */
1253 if (phy_data->port_mode != AXGBE_PORT_MODE_10GBASE_T)
1254 return axgbe_phy_cur_mode(pdata);
1256 switch (axgbe_phy_cur_mode(pdata)) {
1257 case AXGBE_MODE_SGMII_100:
1258 case AXGBE_MODE_SGMII_1000:
1259 return AXGBE_MODE_KR;
1262 return AXGBE_MODE_SGMII_1000;
1266 static enum axgbe_mode axgbe_phy_switch_bp_2500_mode(struct axgbe_port *pdata
1269 return AXGBE_MODE_KX_2500;
1272 static enum axgbe_mode axgbe_phy_switch_bp_mode(struct axgbe_port *pdata)
1274 /* If we are in KR switch to KX, and vice-versa */
1275 switch (axgbe_phy_cur_mode(pdata)) {
1276 case AXGBE_MODE_KX_1000:
1277 return AXGBE_MODE_KR;
1280 return AXGBE_MODE_KX_1000;
1284 static enum axgbe_mode axgbe_phy_switch_mode(struct axgbe_port *pdata)
1286 struct axgbe_phy_data *phy_data = pdata->phy_data;
1288 switch (phy_data->port_mode) {
1289 case AXGBE_PORT_MODE_BACKPLANE:
1290 return axgbe_phy_switch_bp_mode(pdata);
1291 case AXGBE_PORT_MODE_BACKPLANE_2500:
1292 return axgbe_phy_switch_bp_2500_mode(pdata);
1293 case AXGBE_PORT_MODE_1000BASE_T:
1294 case AXGBE_PORT_MODE_NBASE_T:
1295 case AXGBE_PORT_MODE_10GBASE_T:
1296 return axgbe_phy_switch_baset_mode(pdata);
1297 case AXGBE_PORT_MODE_1000BASE_X:
1298 case AXGBE_PORT_MODE_10GBASE_R:
1299 case AXGBE_PORT_MODE_SFP:
1300 /* No switching, so just return current mode */
1301 return axgbe_phy_cur_mode(pdata);
1303 return AXGBE_MODE_UNKNOWN;
1307 static enum axgbe_mode axgbe_phy_get_basex_mode(struct axgbe_phy_data *phy_data
1313 return AXGBE_MODE_X;
1315 return AXGBE_MODE_KR;
1317 return AXGBE_MODE_UNKNOWN;
1321 static enum axgbe_mode axgbe_phy_get_baset_mode(struct axgbe_phy_data *phy_data
1327 return AXGBE_MODE_SGMII_100;
1329 return AXGBE_MODE_SGMII_1000;
1331 return AXGBE_MODE_KR;
1333 return AXGBE_MODE_UNKNOWN;
1337 static enum axgbe_mode axgbe_phy_get_sfp_mode(struct axgbe_phy_data *phy_data,
1342 return AXGBE_MODE_SGMII_100;
1344 if (phy_data->sfp_base == AXGBE_SFP_BASE_1000_T)
1345 return AXGBE_MODE_SGMII_1000;
1347 return AXGBE_MODE_X;
1350 return AXGBE_MODE_SFI;
1352 return AXGBE_MODE_UNKNOWN;
1356 static enum axgbe_mode axgbe_phy_get_bp_2500_mode(int speed)
1360 return AXGBE_MODE_KX_2500;
1362 return AXGBE_MODE_UNKNOWN;
1366 static enum axgbe_mode axgbe_phy_get_bp_mode(int speed)
1370 return AXGBE_MODE_KX_1000;
1372 return AXGBE_MODE_KR;
1374 return AXGBE_MODE_UNKNOWN;
1378 static enum axgbe_mode axgbe_phy_get_mode(struct axgbe_port *pdata,
1381 struct axgbe_phy_data *phy_data = pdata->phy_data;
1383 switch (phy_data->port_mode) {
1384 case AXGBE_PORT_MODE_BACKPLANE:
1385 return axgbe_phy_get_bp_mode(speed);
1386 case AXGBE_PORT_MODE_BACKPLANE_2500:
1387 return axgbe_phy_get_bp_2500_mode(speed);
1388 case AXGBE_PORT_MODE_1000BASE_T:
1389 case AXGBE_PORT_MODE_NBASE_T:
1390 case AXGBE_PORT_MODE_10GBASE_T:
1391 return axgbe_phy_get_baset_mode(phy_data, speed);
1392 case AXGBE_PORT_MODE_1000BASE_X:
1393 case AXGBE_PORT_MODE_10GBASE_R:
1394 return axgbe_phy_get_basex_mode(phy_data, speed);
1395 case AXGBE_PORT_MODE_SFP:
1396 return axgbe_phy_get_sfp_mode(phy_data, speed);
1398 return AXGBE_MODE_UNKNOWN;
1402 static void axgbe_phy_set_mode(struct axgbe_port *pdata, enum axgbe_mode mode)
1406 axgbe_phy_kr_mode(pdata);
1408 case AXGBE_MODE_SFI:
1409 axgbe_phy_sfi_mode(pdata);
1416 static bool axgbe_phy_check_mode(struct axgbe_port *pdata,
1417 enum axgbe_mode mode, u32 advert)
1419 if (pdata->phy.autoneg == AUTONEG_ENABLE) {
1420 if (pdata->phy.advertising & advert)
1423 enum axgbe_mode cur_mode;
1425 cur_mode = axgbe_phy_get_mode(pdata, pdata->phy.speed);
1426 if (cur_mode == mode)
1433 static bool axgbe_phy_use_basex_mode(struct axgbe_port *pdata,
1434 enum axgbe_mode mode)
1438 return axgbe_phy_check_mode(pdata, mode,
1439 ADVERTISED_1000baseT_Full);
1441 return axgbe_phy_check_mode(pdata, mode,
1442 ADVERTISED_10000baseT_Full);
1448 static bool axgbe_phy_use_baset_mode(struct axgbe_port *pdata,
1449 enum axgbe_mode mode)
1452 case AXGBE_MODE_SGMII_100:
1453 return axgbe_phy_check_mode(pdata, mode,
1454 ADVERTISED_100baseT_Full);
1455 case AXGBE_MODE_SGMII_1000:
1456 return axgbe_phy_check_mode(pdata, mode,
1457 ADVERTISED_1000baseT_Full);
1459 return axgbe_phy_check_mode(pdata, mode,
1460 ADVERTISED_10000baseT_Full);
1466 static bool axgbe_phy_use_sfp_mode(struct axgbe_port *pdata,
1467 enum axgbe_mode mode)
1469 struct axgbe_phy_data *phy_data = pdata->phy_data;
1473 if (phy_data->sfp_base == AXGBE_SFP_BASE_1000_T)
1475 return axgbe_phy_check_mode(pdata, mode,
1476 ADVERTISED_1000baseT_Full);
1477 case AXGBE_MODE_SGMII_100:
1478 if (phy_data->sfp_base != AXGBE_SFP_BASE_1000_T)
1480 return axgbe_phy_check_mode(pdata, mode,
1481 ADVERTISED_100baseT_Full);
1482 case AXGBE_MODE_SGMII_1000:
1483 if (phy_data->sfp_base != AXGBE_SFP_BASE_1000_T)
1485 return axgbe_phy_check_mode(pdata, mode,
1486 ADVERTISED_1000baseT_Full);
1487 case AXGBE_MODE_SFI:
1488 return axgbe_phy_check_mode(pdata, mode,
1489 ADVERTISED_10000baseT_Full);
1495 static bool axgbe_phy_use_bp_2500_mode(struct axgbe_port *pdata,
1496 enum axgbe_mode mode)
1499 case AXGBE_MODE_KX_2500:
1500 return axgbe_phy_check_mode(pdata, mode,
1501 ADVERTISED_2500baseX_Full);
1507 static bool axgbe_phy_use_bp_mode(struct axgbe_port *pdata,
1508 enum axgbe_mode mode)
1511 case AXGBE_MODE_KX_1000:
1512 return axgbe_phy_check_mode(pdata, mode,
1513 ADVERTISED_1000baseKX_Full);
1515 return axgbe_phy_check_mode(pdata, mode,
1516 ADVERTISED_10000baseKR_Full);
1522 static bool axgbe_phy_use_mode(struct axgbe_port *pdata, enum axgbe_mode mode)
1524 struct axgbe_phy_data *phy_data = pdata->phy_data;
1526 switch (phy_data->port_mode) {
1527 case AXGBE_PORT_MODE_BACKPLANE:
1528 return axgbe_phy_use_bp_mode(pdata, mode);
1529 case AXGBE_PORT_MODE_BACKPLANE_2500:
1530 return axgbe_phy_use_bp_2500_mode(pdata, mode);
1531 case AXGBE_PORT_MODE_1000BASE_T:
1532 case AXGBE_PORT_MODE_NBASE_T:
1533 case AXGBE_PORT_MODE_10GBASE_T:
1534 return axgbe_phy_use_baset_mode(pdata, mode);
1535 case AXGBE_PORT_MODE_1000BASE_X:
1536 case AXGBE_PORT_MODE_10GBASE_R:
1537 return axgbe_phy_use_basex_mode(pdata, mode);
1538 case AXGBE_PORT_MODE_SFP:
1539 return axgbe_phy_use_sfp_mode(pdata, mode);
1545 static int axgbe_phy_link_status(struct axgbe_port *pdata, int *an_restart)
1547 struct axgbe_phy_data *phy_data = pdata->phy_data;
1552 if (phy_data->port_mode == AXGBE_PORT_MODE_SFP) {
1553 /* Check SFP signals */
1554 axgbe_phy_sfp_detect(pdata);
1556 if (phy_data->sfp_changed) {
1561 if (phy_data->sfp_mod_absent || phy_data->sfp_rx_los)
1565 /* Link status is latched low, so read once to clear
1566 * and then read again to get current state
1568 reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
1569 reg = XMDIO_READ(pdata, MDIO_MMD_PCS, MDIO_STAT1);
1570 if (reg & MDIO_STAT1_LSTATUS)
1573 /* No link, attempt a receiver reset cycle */
1574 if (phy_data->rrc_count++) {
1575 phy_data->rrc_count = 0;
1576 axgbe_phy_rrc(pdata);
1582 static void axgbe_phy_sfp_gpio_setup(struct axgbe_port *pdata)
1584 struct axgbe_phy_data *phy_data = pdata->phy_data;
1587 reg = XP_IOREAD(pdata, XP_PROP_3);
1589 phy_data->sfp_gpio_address = AXGBE_GPIO_ADDRESS_PCA9555 +
1590 XP_GET_BITS(reg, XP_PROP_3, GPIO_ADDR);
1592 phy_data->sfp_gpio_mask = XP_GET_BITS(reg, XP_PROP_3, GPIO_MASK);
1594 phy_data->sfp_gpio_rx_los = XP_GET_BITS(reg, XP_PROP_3,
1596 phy_data->sfp_gpio_tx_fault = XP_GET_BITS(reg, XP_PROP_3,
1598 phy_data->sfp_gpio_mod_absent = XP_GET_BITS(reg, XP_PROP_3,
1600 phy_data->sfp_gpio_rate_select = XP_GET_BITS(reg, XP_PROP_3,
1604 static void axgbe_phy_sfp_comm_setup(struct axgbe_port *pdata)
1606 struct axgbe_phy_data *phy_data = pdata->phy_data;
1607 unsigned int reg, mux_addr_hi, mux_addr_lo;
1609 reg = XP_IOREAD(pdata, XP_PROP_4);
1611 mux_addr_hi = XP_GET_BITS(reg, XP_PROP_4, MUX_ADDR_HI);
1612 mux_addr_lo = XP_GET_BITS(reg, XP_PROP_4, MUX_ADDR_LO);
1613 if (mux_addr_lo == AXGBE_SFP_DIRECT)
1616 phy_data->sfp_comm = AXGBE_SFP_COMM_PCA9545;
1617 phy_data->sfp_mux_address = (mux_addr_hi << 2) + mux_addr_lo;
1618 phy_data->sfp_mux_channel = XP_GET_BITS(reg, XP_PROP_4, MUX_CHAN);
1621 static void axgbe_phy_sfp_setup(struct axgbe_port *pdata)
1623 axgbe_phy_sfp_comm_setup(pdata);
1624 axgbe_phy_sfp_gpio_setup(pdata);
1627 static bool axgbe_phy_redrv_error(struct axgbe_phy_data *phy_data)
1629 if (!phy_data->redrv)
1632 if (phy_data->redrv_if >= AXGBE_PHY_REDRV_IF_MAX)
1635 switch (phy_data->redrv_model) {
1636 case AXGBE_PHY_REDRV_MODEL_4223:
1637 if (phy_data->redrv_lane > 3)
1640 case AXGBE_PHY_REDRV_MODEL_4227:
1641 if (phy_data->redrv_lane > 1)
1651 static int axgbe_phy_mdio_reset_setup(struct axgbe_port *pdata)
1653 struct axgbe_phy_data *phy_data = pdata->phy_data;
1656 if (phy_data->conn_type != AXGBE_CONN_TYPE_MDIO)
1658 reg = XP_IOREAD(pdata, XP_PROP_3);
1659 phy_data->mdio_reset = XP_GET_BITS(reg, XP_PROP_3, MDIO_RESET);
1660 switch (phy_data->mdio_reset) {
1661 case AXGBE_MDIO_RESET_NONE:
1662 case AXGBE_MDIO_RESET_I2C_GPIO:
1663 case AXGBE_MDIO_RESET_INT_GPIO:
1666 PMD_DRV_LOG(ERR, "unsupported MDIO reset (%#x)\n",
1667 phy_data->mdio_reset);
1670 if (phy_data->mdio_reset == AXGBE_MDIO_RESET_I2C_GPIO) {
1671 phy_data->mdio_reset_addr = AXGBE_GPIO_ADDRESS_PCA9555 +
1672 XP_GET_BITS(reg, XP_PROP_3,
1673 MDIO_RESET_I2C_ADDR);
1674 phy_data->mdio_reset_gpio = XP_GET_BITS(reg, XP_PROP_3,
1675 MDIO_RESET_I2C_GPIO);
1676 } else if (phy_data->mdio_reset == AXGBE_MDIO_RESET_INT_GPIO) {
1677 phy_data->mdio_reset_gpio = XP_GET_BITS(reg, XP_PROP_3,
1678 MDIO_RESET_INT_GPIO);
1684 static bool axgbe_phy_port_mode_mismatch(struct axgbe_port *pdata)
1686 struct axgbe_phy_data *phy_data = pdata->phy_data;
1688 switch (phy_data->port_mode) {
1689 case AXGBE_PORT_MODE_BACKPLANE:
1690 if ((phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) ||
1691 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000))
1694 case AXGBE_PORT_MODE_BACKPLANE_2500:
1695 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_2500)
1698 case AXGBE_PORT_MODE_1000BASE_T:
1699 if ((phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) ||
1700 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000))
1703 case AXGBE_PORT_MODE_1000BASE_X:
1704 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000)
1707 case AXGBE_PORT_MODE_NBASE_T:
1708 if ((phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) ||
1709 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) ||
1710 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_2500))
1713 case AXGBE_PORT_MODE_10GBASE_T:
1714 if ((phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) ||
1715 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) ||
1716 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000))
1719 case AXGBE_PORT_MODE_10GBASE_R:
1720 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000)
1723 case AXGBE_PORT_MODE_SFP:
1724 if ((phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) ||
1725 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) ||
1726 (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000))
1736 static bool axgbe_phy_conn_type_mismatch(struct axgbe_port *pdata)
1738 struct axgbe_phy_data *phy_data = pdata->phy_data;
1740 switch (phy_data->port_mode) {
1741 case AXGBE_PORT_MODE_BACKPLANE:
1742 case AXGBE_PORT_MODE_BACKPLANE_2500:
1743 if (phy_data->conn_type == AXGBE_CONN_TYPE_BACKPLANE)
1746 case AXGBE_PORT_MODE_1000BASE_T:
1747 case AXGBE_PORT_MODE_1000BASE_X:
1748 case AXGBE_PORT_MODE_NBASE_T:
1749 case AXGBE_PORT_MODE_10GBASE_T:
1750 case AXGBE_PORT_MODE_10GBASE_R:
1751 if (phy_data->conn_type == AXGBE_CONN_TYPE_MDIO)
1754 case AXGBE_PORT_MODE_SFP:
1755 if (phy_data->conn_type == AXGBE_CONN_TYPE_SFP)
1765 static bool axgbe_phy_port_enabled(struct axgbe_port *pdata)
1769 reg = XP_IOREAD(pdata, XP_PROP_0);
1770 if (!XP_GET_BITS(reg, XP_PROP_0, PORT_SPEEDS))
1772 if (!XP_GET_BITS(reg, XP_PROP_0, CONN_TYPE))
1778 static void axgbe_phy_cdr_track(struct axgbe_port *pdata)
1780 struct axgbe_phy_data *phy_data = pdata->phy_data;
1782 if (!pdata->vdata->an_cdr_workaround)
1785 if (!phy_data->phy_cdr_notrack)
1788 rte_delay_us(phy_data->phy_cdr_delay + 400);
1790 XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
1791 AXGBE_PMA_CDR_TRACK_EN_MASK,
1792 AXGBE_PMA_CDR_TRACK_EN_ON);
1794 phy_data->phy_cdr_notrack = 0;
1797 static void axgbe_phy_cdr_notrack(struct axgbe_port *pdata)
1799 struct axgbe_phy_data *phy_data = pdata->phy_data;
1801 if (!pdata->vdata->an_cdr_workaround)
1804 if (phy_data->phy_cdr_notrack)
1807 XMDIO_WRITE_BITS(pdata, MDIO_MMD_PMAPMD, MDIO_VEND2_PMA_CDR_CONTROL,
1808 AXGBE_PMA_CDR_TRACK_EN_MASK,
1809 AXGBE_PMA_CDR_TRACK_EN_OFF);
1811 axgbe_phy_rrc(pdata);
1813 phy_data->phy_cdr_notrack = 1;
1816 static void axgbe_phy_kr_training_post(struct axgbe_port *pdata)
1818 if (!pdata->cdr_track_early)
1819 axgbe_phy_cdr_track(pdata);
1822 static void axgbe_phy_kr_training_pre(struct axgbe_port *pdata)
1824 if (pdata->cdr_track_early)
1825 axgbe_phy_cdr_track(pdata);
1828 static void axgbe_phy_an_post(struct axgbe_port *pdata)
1830 struct axgbe_phy_data *phy_data = pdata->phy_data;
1832 switch (pdata->an_mode) {
1833 case AXGBE_AN_MODE_CL73:
1834 case AXGBE_AN_MODE_CL73_REDRV:
1835 if (phy_data->cur_mode != AXGBE_MODE_KR)
1838 axgbe_phy_cdr_track(pdata);
1840 switch (pdata->an_result) {
1841 case AXGBE_AN_READY:
1842 case AXGBE_AN_COMPLETE:
1845 if (phy_data->phy_cdr_delay < AXGBE_CDR_DELAY_MAX)
1846 phy_data->phy_cdr_delay += AXGBE_CDR_DELAY_INC;
1855 static void axgbe_phy_an_pre(struct axgbe_port *pdata)
1857 struct axgbe_phy_data *phy_data = pdata->phy_data;
1859 switch (pdata->an_mode) {
1860 case AXGBE_AN_MODE_CL73:
1861 case AXGBE_AN_MODE_CL73_REDRV:
1862 if (phy_data->cur_mode != AXGBE_MODE_KR)
1865 axgbe_phy_cdr_notrack(pdata);
1872 static void axgbe_phy_stop(struct axgbe_port *pdata)
1874 struct axgbe_phy_data *phy_data = pdata->phy_data;
1876 /* Reset SFP data */
1877 axgbe_phy_sfp_reset(phy_data);
1878 axgbe_phy_sfp_mod_absent(pdata);
1880 /* Reset CDR support */
1881 axgbe_phy_cdr_track(pdata);
1883 /* Power off the PHY */
1884 axgbe_phy_power_off(pdata);
1886 /* Stop the I2C controller */
1887 pdata->i2c_if.i2c_stop(pdata);
1890 static int axgbe_phy_start(struct axgbe_port *pdata)
1892 struct axgbe_phy_data *phy_data = pdata->phy_data;
1895 /* Start the I2C controller */
1896 ret = pdata->i2c_if.i2c_start(pdata);
1900 /* Start in highest supported mode */
1901 axgbe_phy_set_mode(pdata, phy_data->start_mode);
1903 /* Reset CDR support */
1904 axgbe_phy_cdr_track(pdata);
1906 /* After starting the I2C controller, we can check for an SFP */
1907 switch (phy_data->port_mode) {
1908 case AXGBE_PORT_MODE_SFP:
1909 axgbe_phy_sfp_detect(pdata);
1918 static int axgbe_phy_reset(struct axgbe_port *pdata)
1920 struct axgbe_phy_data *phy_data = pdata->phy_data;
1921 enum axgbe_mode cur_mode;
1923 /* Reset by power cycling the PHY */
1924 cur_mode = phy_data->cur_mode;
1925 axgbe_phy_power_off(pdata);
1926 /* First time reset is done with passed unknown mode*/
1927 axgbe_phy_set_mode(pdata, cur_mode);
1931 static int axgbe_phy_init(struct axgbe_port *pdata)
1933 struct axgbe_phy_data *phy_data;
1937 /* Check if enabled */
1938 if (!axgbe_phy_port_enabled(pdata)) {
1939 PMD_DRV_LOG(ERR, "device is not enabled\n");
1943 /* Initialize the I2C controller */
1944 ret = pdata->i2c_if.i2c_init(pdata);
1948 phy_data = rte_zmalloc("phy_data memory", sizeof(*phy_data), 0);
1950 PMD_DRV_LOG(ERR, "phy_data allocation failed\n");
1953 pdata->phy_data = phy_data;
1955 reg = XP_IOREAD(pdata, XP_PROP_0);
1956 phy_data->port_mode = XP_GET_BITS(reg, XP_PROP_0, PORT_MODE);
1957 phy_data->port_id = XP_GET_BITS(reg, XP_PROP_0, PORT_ID);
1958 phy_data->port_speeds = XP_GET_BITS(reg, XP_PROP_0, PORT_SPEEDS);
1959 phy_data->conn_type = XP_GET_BITS(reg, XP_PROP_0, CONN_TYPE);
1960 phy_data->mdio_addr = XP_GET_BITS(reg, XP_PROP_0, MDIO_ADDR);
1962 reg = XP_IOREAD(pdata, XP_PROP_4);
1963 phy_data->redrv = XP_GET_BITS(reg, XP_PROP_4, REDRV_PRESENT);
1964 phy_data->redrv_if = XP_GET_BITS(reg, XP_PROP_4, REDRV_IF);
1965 phy_data->redrv_addr = XP_GET_BITS(reg, XP_PROP_4, REDRV_ADDR);
1966 phy_data->redrv_lane = XP_GET_BITS(reg, XP_PROP_4, REDRV_LANE);
1967 phy_data->redrv_model = XP_GET_BITS(reg, XP_PROP_4, REDRV_MODEL);
1969 /* Validate the connection requested */
1970 if (axgbe_phy_conn_type_mismatch(pdata)) {
1971 PMD_DRV_LOG(ERR, "phy mode/connection mismatch (%#x/%#x)\n",
1972 phy_data->port_mode, phy_data->conn_type);
1976 /* Validate the mode requested */
1977 if (axgbe_phy_port_mode_mismatch(pdata)) {
1978 PMD_DRV_LOG(ERR, "phy mode/speed mismatch (%#x/%#x)\n",
1979 phy_data->port_mode, phy_data->port_speeds);
1983 /* Check for and validate MDIO reset support */
1984 ret = axgbe_phy_mdio_reset_setup(pdata);
1988 /* Validate the re-driver information */
1989 if (axgbe_phy_redrv_error(phy_data)) {
1990 PMD_DRV_LOG(ERR, "phy re-driver settings error\n");
1993 pdata->kr_redrv = phy_data->redrv;
1995 /* Indicate current mode is unknown */
1996 phy_data->cur_mode = AXGBE_MODE_UNKNOWN;
1998 /* Initialize supported features */
1999 pdata->phy.supported = 0;
2001 switch (phy_data->port_mode) {
2002 /* Backplane support */
2003 case AXGBE_PORT_MODE_BACKPLANE:
2004 pdata->phy.supported |= SUPPORTED_Autoneg;
2005 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2006 pdata->phy.supported |= SUPPORTED_Backplane;
2007 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) {
2008 pdata->phy.supported |= SUPPORTED_1000baseKX_Full;
2009 phy_data->start_mode = AXGBE_MODE_KX_1000;
2011 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000) {
2012 pdata->phy.supported |= SUPPORTED_10000baseKR_Full;
2013 if (pdata->fec_ability & MDIO_PMA_10GBR_FECABLE_ABLE)
2014 pdata->phy.supported |=
2015 SUPPORTED_10000baseR_FEC;
2016 phy_data->start_mode = AXGBE_MODE_KR;
2019 phy_data->phydev_mode = AXGBE_MDIO_MODE_NONE;
2021 case AXGBE_PORT_MODE_BACKPLANE_2500:
2022 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2023 pdata->phy.supported |= SUPPORTED_Backplane;
2024 pdata->phy.supported |= SUPPORTED_2500baseX_Full;
2025 phy_data->start_mode = AXGBE_MODE_KX_2500;
2027 phy_data->phydev_mode = AXGBE_MDIO_MODE_NONE;
2030 /* MDIO 1GBase-T support */
2031 case AXGBE_PORT_MODE_1000BASE_T:
2032 pdata->phy.supported |= SUPPORTED_Autoneg;
2033 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2034 pdata->phy.supported |= SUPPORTED_TP;
2035 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) {
2036 pdata->phy.supported |= SUPPORTED_100baseT_Full;
2037 phy_data->start_mode = AXGBE_MODE_SGMII_100;
2039 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) {
2040 pdata->phy.supported |= SUPPORTED_1000baseT_Full;
2041 phy_data->start_mode = AXGBE_MODE_SGMII_1000;
2044 phy_data->phydev_mode = AXGBE_MDIO_MODE_CL22;
2047 /* MDIO Base-X support */
2048 case AXGBE_PORT_MODE_1000BASE_X:
2049 pdata->phy.supported |= SUPPORTED_Autoneg;
2050 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2051 pdata->phy.supported |= SUPPORTED_FIBRE;
2052 pdata->phy.supported |= SUPPORTED_1000baseT_Full;
2053 phy_data->start_mode = AXGBE_MODE_X;
2055 phy_data->phydev_mode = AXGBE_MDIO_MODE_CL22;
2058 /* MDIO NBase-T support */
2059 case AXGBE_PORT_MODE_NBASE_T:
2060 pdata->phy.supported |= SUPPORTED_Autoneg;
2061 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2062 pdata->phy.supported |= SUPPORTED_TP;
2063 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) {
2064 pdata->phy.supported |= SUPPORTED_100baseT_Full;
2065 phy_data->start_mode = AXGBE_MODE_SGMII_100;
2067 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) {
2068 pdata->phy.supported |= SUPPORTED_1000baseT_Full;
2069 phy_data->start_mode = AXGBE_MODE_SGMII_1000;
2071 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_2500) {
2072 pdata->phy.supported |= SUPPORTED_2500baseX_Full;
2073 phy_data->start_mode = AXGBE_MODE_KX_2500;
2076 phy_data->phydev_mode = AXGBE_MDIO_MODE_CL45;
2079 /* 10GBase-T support */
2080 case AXGBE_PORT_MODE_10GBASE_T:
2081 pdata->phy.supported |= SUPPORTED_Autoneg;
2082 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2083 pdata->phy.supported |= SUPPORTED_TP;
2084 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) {
2085 pdata->phy.supported |= SUPPORTED_100baseT_Full;
2086 phy_data->start_mode = AXGBE_MODE_SGMII_100;
2088 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) {
2089 pdata->phy.supported |= SUPPORTED_1000baseT_Full;
2090 phy_data->start_mode = AXGBE_MODE_SGMII_1000;
2092 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000) {
2093 pdata->phy.supported |= SUPPORTED_10000baseT_Full;
2094 phy_data->start_mode = AXGBE_MODE_KR;
2097 phy_data->phydev_mode = AXGBE_MDIO_MODE_NONE;
2100 /* 10GBase-R support */
2101 case AXGBE_PORT_MODE_10GBASE_R:
2102 pdata->phy.supported |= SUPPORTED_Autoneg;
2103 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2104 pdata->phy.supported |= SUPPORTED_TP;
2105 pdata->phy.supported |= SUPPORTED_10000baseT_Full;
2106 if (pdata->fec_ability & MDIO_PMA_10GBR_FECABLE_ABLE)
2107 pdata->phy.supported |= SUPPORTED_10000baseR_FEC;
2108 phy_data->start_mode = AXGBE_MODE_SFI;
2110 phy_data->phydev_mode = AXGBE_MDIO_MODE_NONE;
2114 case AXGBE_PORT_MODE_SFP:
2115 pdata->phy.supported |= SUPPORTED_Autoneg;
2116 pdata->phy.supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
2117 pdata->phy.supported |= SUPPORTED_TP;
2118 pdata->phy.supported |= SUPPORTED_FIBRE;
2119 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_100) {
2120 pdata->phy.supported |= SUPPORTED_100baseT_Full;
2121 phy_data->start_mode = AXGBE_MODE_SGMII_100;
2123 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_1000) {
2124 pdata->phy.supported |= SUPPORTED_1000baseT_Full;
2125 phy_data->start_mode = AXGBE_MODE_SGMII_1000;
2127 if (phy_data->port_speeds & AXGBE_PHY_PORT_SPEED_10000) {
2128 pdata->phy.supported |= SUPPORTED_10000baseT_Full;
2129 phy_data->start_mode = AXGBE_MODE_SFI;
2130 if (pdata->fec_ability & MDIO_PMA_10GBR_FECABLE_ABLE)
2131 pdata->phy.supported |=
2132 SUPPORTED_10000baseR_FEC;
2135 phy_data->phydev_mode = AXGBE_MDIO_MODE_CL22;
2137 axgbe_phy_sfp_setup(pdata);
2143 if ((phy_data->conn_type & AXGBE_CONN_TYPE_MDIO) &&
2144 (phy_data->phydev_mode != AXGBE_MDIO_MODE_NONE)) {
2145 ret = pdata->hw_if.set_ext_mii_mode(pdata, phy_data->mdio_addr,
2146 phy_data->phydev_mode);
2148 PMD_DRV_LOG(ERR, "mdio port/clause not compatible (%d/%u)\n",
2149 phy_data->mdio_addr, phy_data->phydev_mode);
2154 if (phy_data->redrv && !phy_data->redrv_if) {
2155 ret = pdata->hw_if.set_ext_mii_mode(pdata, phy_data->redrv_addr,
2156 AXGBE_MDIO_MODE_CL22);
2158 PMD_DRV_LOG(ERR, "redriver mdio port not compatible (%u)\n",
2159 phy_data->redrv_addr);
2164 phy_data->phy_cdr_delay = AXGBE_CDR_DELAY_INIT;
2167 void axgbe_init_function_ptrs_phy_v2(struct axgbe_phy_if *phy_if)
2169 struct axgbe_phy_impl_if *phy_impl = &phy_if->phy_impl;
2171 phy_impl->init = axgbe_phy_init;
2172 phy_impl->reset = axgbe_phy_reset;
2173 phy_impl->start = axgbe_phy_start;
2174 phy_impl->stop = axgbe_phy_stop;
2175 phy_impl->link_status = axgbe_phy_link_status;
2176 phy_impl->use_mode = axgbe_phy_use_mode;
2177 phy_impl->set_mode = axgbe_phy_set_mode;
2178 phy_impl->get_mode = axgbe_phy_get_mode;
2179 phy_impl->switch_mode = axgbe_phy_switch_mode;
2180 phy_impl->cur_mode = axgbe_phy_cur_mode;
2181 phy_impl->an_mode = axgbe_phy_an_mode;
2182 phy_impl->an_config = axgbe_phy_an_config;
2183 phy_impl->an_advertising = axgbe_phy_an_advertising;
2184 phy_impl->an_outcome = axgbe_phy_an_outcome;
2186 phy_impl->an_pre = axgbe_phy_an_pre;
2187 phy_impl->an_post = axgbe_phy_an_post;
2189 phy_impl->kr_training_pre = axgbe_phy_kr_training_pre;
2190 phy_impl->kr_training_post = axgbe_phy_kr_training_post;