Lines Matching +full:phy +full:- +full:pma
1 // SPDX-License-Identifier: GPL-2.0-only
3 * mdio.c: Generic support for MDIO-compatible transceivers
4 * Copyright 2006-2009 Solarflare Communications Inc.
14 MODULE_DESCRIPTION("Generic support for MDIO-compatible transceivers");
15 MODULE_AUTHOR("Copyright 2006-2009 Solarflare Communications Inc.");
19 * mdio45_probe - probe for an MDIO (clause 45) device
21 * @prtad: Expected PHY address
30 /* Assume PHY must have at least one of PMA/PMD, WIS, PCS, PHY in mdio45_probe()
34 stat2 = mdio->mdio_read(mdio->dev, prtad, mmd, MDIO_STAT2); in mdio45_probe()
40 devs1 = mdio->mdio_read(mdio->dev, prtad, mmd, MDIO_DEVS1); in mdio45_probe()
41 devs2 = mdio->mdio_read(mdio->dev, prtad, mmd, MDIO_DEVS2); in mdio45_probe()
45 mdio->prtad = prtad; in mdio45_probe()
46 mdio->mmds = devs1 | (devs2 << 16); in mdio45_probe()
50 return -ENODEV; in mdio45_probe()
55 * mdio_set_flag - set or clear flag in an MDIO register
57 * @prtad: PHY address
70 int old_val = mdio->mdio_read(mdio->dev, prtad, devad, addr); in mdio_set_flag()
81 return mdio->mdio_write(mdio->dev, prtad, devad, addr, new_val); in mdio_set_flag()
86 * mdio45_links_ok - is link status up/OK
90 * Returns 1 if the PHY reports link status up/OK, 0 otherwise.
91 * @mmd_mask is normally @mdio->mmds, but if loopback is enabled
100 reg = mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_links_ok()
110 mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_links_ok()
114 mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_links_ok()
118 reg = mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_links_ok()
132 * mdio45_nway_restart - restart auto-negotiation for this interface
139 if (!(mdio->mmds & MDIO_DEVS_AN)) in mdio45_nway_restart()
140 return -EOPNOTSUPP; in mdio45_nway_restart()
142 mdio_set_flag(mdio, mdio->prtad, MDIO_MMD_AN, MDIO_CTRL1, in mdio45_nway_restart()
153 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_AN, addr); in mdio45_get_an()
170 * mdio45_ethtool_gset_npage - get settings for ETHTOOL_GSET
179 * Since the CSRs for auto-negotiation using next pages are not fully
193 ecmd->transceiver = XCVR_INTERNAL; in mdio45_ethtool_gset_npage()
194 ecmd->phy_address = mdio->prtad; in mdio45_ethtool_gset_npage()
195 ecmd->mdio_support = in mdio45_ethtool_gset_npage()
196 mdio->mode_support & (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22); in mdio45_ethtool_gset_npage()
198 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
205 ecmd->port = PORT_TP; in mdio45_ethtool_gset_npage()
206 ecmd->supported = SUPPORTED_TP; in mdio45_ethtool_gset_npage()
207 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
210 ecmd->supported |= SUPPORTED_10000baseT_Full; in mdio45_ethtool_gset_npage()
212 ecmd->supported |= (SUPPORTED_1000baseT_Full | in mdio45_ethtool_gset_npage()
215 ecmd->supported |= (SUPPORTED_100baseT_Full | in mdio45_ethtool_gset_npage()
218 ecmd->supported |= (SUPPORTED_10baseT_Full | in mdio45_ethtool_gset_npage()
220 ecmd->advertising = ADVERTISED_TP; in mdio45_ethtool_gset_npage()
224 ecmd->port = PORT_OTHER; in mdio45_ethtool_gset_npage()
225 ecmd->supported = 0; in mdio45_ethtool_gset_npage()
226 ecmd->advertising = 0; in mdio45_ethtool_gset_npage()
232 ecmd->port = PORT_OTHER; in mdio45_ethtool_gset_npage()
233 ecmd->supported = SUPPORTED_Backplane; in mdio45_ethtool_gset_npage()
234 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
237 ecmd->supported |= SUPPORTED_10000baseKX4_Full; in mdio45_ethtool_gset_npage()
239 ecmd->supported |= SUPPORTED_10000baseKR_Full; in mdio45_ethtool_gset_npage()
241 ecmd->supported |= SUPPORTED_1000baseKX_Full; in mdio45_ethtool_gset_npage()
242 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
245 ecmd->supported |= SUPPORTED_10000baseR_FEC; in mdio45_ethtool_gset_npage()
246 ecmd->advertising = ADVERTISED_Backplane; in mdio45_ethtool_gset_npage()
251 ecmd->port = PORT_FIBRE; in mdio45_ethtool_gset_npage()
252 ecmd->supported = SUPPORTED_FIBRE; in mdio45_ethtool_gset_npage()
253 ecmd->advertising = ADVERTISED_FIBRE; in mdio45_ethtool_gset_npage()
257 if (mdio->mmds & MDIO_DEVS_AN) { in mdio45_ethtool_gset_npage()
258 ecmd->supported |= SUPPORTED_Autoneg; in mdio45_ethtool_gset_npage()
259 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_AN, in mdio45_ethtool_gset_npage()
262 ecmd->autoneg = AUTONEG_ENABLE; in mdio45_ethtool_gset_npage()
263 ecmd->advertising |= in mdio45_ethtool_gset_npage()
268 ecmd->autoneg = AUTONEG_DISABLE; in mdio45_ethtool_gset_npage()
271 ecmd->autoneg = AUTONEG_DISABLE; in mdio45_ethtool_gset_npage()
274 if (ecmd->autoneg) { in mdio45_ethtool_gset_npage()
276 int an_stat = mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_ethtool_gset_npage()
282 ecmd->lp_advertising = in mdio45_ethtool_gset_npage()
285 ecmd->lp_advertising |= ADVERTISED_Autoneg; in mdio45_ethtool_gset_npage()
286 modes = ecmd->advertising & ecmd->lp_advertising; in mdio45_ethtool_gset_npage()
289 modes = ecmd->advertising; in mdio45_ethtool_gset_npage()
295 ecmd->duplex = DUPLEX_FULL; in mdio45_ethtool_gset_npage()
300 ecmd->duplex = !(modes & ADVERTISED_1000baseT_Half); in mdio45_ethtool_gset_npage()
304 ecmd->duplex = !!(modes & ADVERTISED_100baseT_Full); in mdio45_ethtool_gset_npage()
307 ecmd->duplex = !!(modes & ADVERTISED_10baseT_Full); in mdio45_ethtool_gset_npage()
311 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
315 ecmd->duplex = (reg & MDIO_CTRL1_FULLDPLX || in mdio45_ethtool_gset_npage()
321 /* 10GBASE-T MDI/MDI-X */ in mdio45_ethtool_gset_npage()
322 if (ecmd->port == PORT_TP in mdio45_ethtool_gset_npage()
324 switch (mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_gset_npage()
327 ecmd->eth_tp_mdix = ETH_TP_MDI; in mdio45_ethtool_gset_npage()
330 ecmd->eth_tp_mdix = ETH_TP_MDI_X; in mdio45_ethtool_gset_npage()
334 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; in mdio45_ethtool_gset_npage()
342 * mdio45_ethtool_ksettings_get_npage - get settings for ETHTOOL_GLINKSETTINGS
351 * Since the CSRs for auto-negotiation using next pages are not fully
365 cmd->base.phy_address = mdio->prtad; in mdio45_ethtool_ksettings_get_npage()
366 cmd->base.mdio_support = in mdio45_ethtool_ksettings_get_npage()
367 mdio->mode_support & (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22); in mdio45_ethtool_ksettings_get_npage()
369 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
376 cmd->base.port = PORT_TP; in mdio45_ethtool_ksettings_get_npage()
378 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
395 cmd->base.port = PORT_OTHER; in mdio45_ethtool_ksettings_get_npage()
403 cmd->base.port = PORT_OTHER; in mdio45_ethtool_ksettings_get_npage()
405 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
413 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
422 cmd->base.port = PORT_FIBRE; in mdio45_ethtool_ksettings_get_npage()
428 if (mdio->mmds & MDIO_DEVS_AN) { in mdio45_ethtool_ksettings_get_npage()
430 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_AN, in mdio45_ethtool_ksettings_get_npage()
433 cmd->base.autoneg = AUTONEG_ENABLE; in mdio45_ethtool_ksettings_get_npage()
439 cmd->base.autoneg = AUTONEG_DISABLE; in mdio45_ethtool_ksettings_get_npage()
442 cmd->base.autoneg = AUTONEG_DISABLE; in mdio45_ethtool_ksettings_get_npage()
445 if (cmd->base.autoneg) { in mdio45_ethtool_ksettings_get_npage()
447 int an_stat = mdio->mdio_read(mdio->dev, mdio->prtad, in mdio45_ethtool_ksettings_get_npage()
467 cmd->base.duplex = DUPLEX_FULL; in mdio45_ethtool_ksettings_get_npage()
472 cmd->base.duplex = !(modes & ADVERTISED_1000baseT_Half); in mdio45_ethtool_ksettings_get_npage()
476 cmd->base.duplex = !!(modes & ADVERTISED_100baseT_Full); in mdio45_ethtool_ksettings_get_npage()
479 cmd->base.duplex = !!(modes & ADVERTISED_10baseT_Full); in mdio45_ethtool_ksettings_get_npage()
483 reg = mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
487 cmd->base.duplex = (reg & MDIO_CTRL1_FULLDPLX || in mdio45_ethtool_ksettings_get_npage()
491 cmd->base.speed = speed; in mdio45_ethtool_ksettings_get_npage()
493 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, in mdio45_ethtool_ksettings_get_npage()
495 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, in mdio45_ethtool_ksettings_get_npage()
497 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising, in mdio45_ethtool_ksettings_get_npage()
500 /* 10GBASE-T MDI/MDI-X */ in mdio45_ethtool_ksettings_get_npage()
501 if (cmd->base.port == PORT_TP && (cmd->base.speed == SPEED_10000)) { in mdio45_ethtool_ksettings_get_npage()
502 switch (mdio->mdio_read(mdio->dev, mdio->prtad, MDIO_MMD_PMAPMD, in mdio45_ethtool_ksettings_get_npage()
505 cmd->base.eth_tp_mdix = ETH_TP_MDI; in mdio45_ethtool_ksettings_get_npage()
508 cmd->base.eth_tp_mdix = ETH_TP_MDI_X; in mdio45_ethtool_ksettings_get_npage()
512 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID; in mdio45_ethtool_ksettings_get_npage()
520 * mdio_mii_ioctl - MII ioctl interface for MDIO (clause 22 or 45) PHYs
531 u16 addr = mii_data->reg_num; in mdio_mii_ioctl()
536 if (mdio->prtad == MDIO_PRTAD_NONE) in mdio_mii_ioctl()
537 return -EOPNOTSUPP; in mdio_mii_ioctl()
538 mii_data->phy_id = mdio->prtad; in mdio_mii_ioctl()
545 return -EOPNOTSUPP; in mdio_mii_ioctl()
549 if ((mdio->mode_support & MDIO_SUPPORTS_C45) && in mdio_mii_ioctl()
550 mdio_phy_id_is_c45(mii_data->phy_id)) { in mdio_mii_ioctl()
551 prtad = mdio_phy_id_prtad(mii_data->phy_id); in mdio_mii_ioctl()
552 devad = mdio_phy_id_devad(mii_data->phy_id); in mdio_mii_ioctl()
553 } else if ((mdio->mode_support & MDIO_SUPPORTS_C22) && in mdio_mii_ioctl()
554 mii_data->phy_id < 0x20) { in mdio_mii_ioctl()
555 prtad = mii_data->phy_id; in mdio_mii_ioctl()
558 } else if ((mdio->mode_support & MDIO_EMULATE_C22) && in mdio_mii_ioctl()
559 mdio->prtad != MDIO_PRTAD_NONE && in mdio_mii_ioctl()
560 mii_data->phy_id == mdio->prtad) { in mdio_mii_ioctl()
561 /* Remap commonly-used MII registers. */ in mdio_mii_ioctl()
562 prtad = mdio->prtad; in mdio_mii_ioctl()
568 devad = __ffs(mdio->mmds); in mdio_mii_ioctl()
572 if (!(mdio->mmds & MDIO_DEVS_AN)) in mdio_mii_ioctl()
573 return -EINVAL; in mdio_mii_ioctl()
581 return -EINVAL; in mdio_mii_ioctl()
584 return -EINVAL; in mdio_mii_ioctl()
588 int rc = mdio->mdio_read(mdio->dev, prtad, devad, addr); in mdio_mii_ioctl()
591 mii_data->val_out = rc; in mdio_mii_ioctl()
594 return mdio->mdio_write(mdio->dev, prtad, devad, addr, in mdio_mii_ioctl()
595 mii_data->val_in); in mdio_mii_ioctl()