1 // SPDX-License-Identifier: GPL-2.0-only
3 * Clause 45 PHY support
5 #include <linux/ethtool.h>
6 #include <linux/export.h>
7 #include <linux/mdio.h>
11 #include "mdio-open-alliance.h"
14 * genphy_c45_baset1_able - checks if the PMA has BASE-T1 extended abilities
15 * @phydev: target phy_device struct
17 static bool genphy_c45_baset1_able(struct phy_device
*phydev
)
21 if (phydev
->pma_extable
== -ENODATA
) {
22 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_EXTABLE
);
26 phydev
->pma_extable
= val
;
29 return !!(phydev
->pma_extable
& MDIO_PMA_EXTABLE_BT1
);
33 * genphy_c45_pma_can_sleep - checks if the PMA have sleep support
34 * @phydev: target phy_device struct
36 static bool genphy_c45_pma_can_sleep(struct phy_device
*phydev
)
40 stat1
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_STAT1
);
44 return !!(stat1
& MDIO_STAT1_LPOWERABLE
);
48 * genphy_c45_pma_resume - wakes up the PMA module
49 * @phydev: target phy_device struct
51 int genphy_c45_pma_resume(struct phy_device
*phydev
)
53 if (!genphy_c45_pma_can_sleep(phydev
))
56 return phy_clear_bits_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
,
59 EXPORT_SYMBOL_GPL(genphy_c45_pma_resume
);
62 * genphy_c45_pma_suspend - suspends the PMA module
63 * @phydev: target phy_device struct
65 int genphy_c45_pma_suspend(struct phy_device
*phydev
)
67 if (!genphy_c45_pma_can_sleep(phydev
))
70 return phy_set_bits_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
,
73 EXPORT_SYMBOL_GPL(genphy_c45_pma_suspend
);
76 * genphy_c45_pma_baset1_setup_master_slave - configures forced master/slave
77 * role of BaseT1 devices.
78 * @phydev: target phy_device struct
80 int genphy_c45_pma_baset1_setup_master_slave(struct phy_device
*phydev
)
84 switch (phydev
->master_slave_set
) {
85 case MASTER_SLAVE_CFG_MASTER_PREFERRED
:
86 case MASTER_SLAVE_CFG_MASTER_FORCE
:
87 ctl
= MDIO_PMA_PMD_BT1_CTRL_CFG_MST
;
89 case MASTER_SLAVE_CFG_SLAVE_FORCE
:
90 case MASTER_SLAVE_CFG_SLAVE_PREFERRED
:
92 case MASTER_SLAVE_CFG_UNKNOWN
:
93 case MASTER_SLAVE_CFG_UNSUPPORTED
:
96 phydev_warn(phydev
, "Unsupported Master/Slave mode\n");
100 return phy_modify_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_PMD_BT1_CTRL
,
101 MDIO_PMA_PMD_BT1_CTRL_CFG_MST
, ctl
);
103 EXPORT_SYMBOL_GPL(genphy_c45_pma_baset1_setup_master_slave
);
106 * genphy_c45_pma_setup_forced - configures a forced speed
107 * @phydev: target phy_device struct
109 int genphy_c45_pma_setup_forced(struct phy_device
*phydev
)
111 int bt1_ctrl
, ctrl1
, ctrl2
, ret
;
113 /* Half duplex is not supported */
114 if (phydev
->duplex
!= DUPLEX_FULL
)
117 ctrl1
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
);
121 ctrl2
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL2
);
125 ctrl1
&= ~MDIO_CTRL1_SPEEDSEL
;
127 * PMA/PMD type selection is 1.7.5:0 not 1.7.3:0. See 45.2.1.6.1
128 * in 802.3-2012 and 802.3-2015.
130 ctrl2
&= ~(MDIO_PMA_CTRL2_TYPE
| 0x30);
132 switch (phydev
->speed
) {
134 if (genphy_c45_baset1_able(phydev
))
135 ctrl2
|= MDIO_PMA_CTRL2_BASET1
;
137 ctrl2
|= MDIO_PMA_CTRL2_10BT
;
140 ctrl1
|= MDIO_PMA_CTRL1_SPEED100
;
141 ctrl2
|= MDIO_PMA_CTRL2_100BTX
;
144 ctrl1
|= MDIO_PMA_CTRL1_SPEED1000
;
145 /* Assume 1000base-T */
146 ctrl2
|= MDIO_PMA_CTRL2_1000BT
;
149 ctrl1
|= MDIO_CTRL1_SPEED2_5G
;
150 /* Assume 2.5Gbase-T */
151 ctrl2
|= MDIO_PMA_CTRL2_2_5GBT
;
154 ctrl1
|= MDIO_CTRL1_SPEED5G
;
155 /* Assume 5Gbase-T */
156 ctrl2
|= MDIO_PMA_CTRL2_5GBT
;
159 ctrl1
|= MDIO_CTRL1_SPEED10G
;
160 /* Assume 10Gbase-T */
161 ctrl2
|= MDIO_PMA_CTRL2_10GBT
;
167 ret
= phy_write_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
, ctrl1
);
171 ret
= phy_write_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL2
, ctrl2
);
175 if (genphy_c45_baset1_able(phydev
)) {
176 ret
= genphy_c45_pma_baset1_setup_master_slave(phydev
);
181 if (phydev
->speed
== SPEED_1000
)
182 bt1_ctrl
= MDIO_PMA_PMD_BT1_CTRL_STRAP_B1000
;
184 ret
= phy_modify_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_PMD_BT1_CTRL
,
185 MDIO_PMA_PMD_BT1_CTRL_STRAP
, bt1_ctrl
);
190 return genphy_c45_an_disable_aneg(phydev
);
192 EXPORT_SYMBOL_GPL(genphy_c45_pma_setup_forced
);
194 /* Sets master/slave preference and supported technologies.
195 * The preference is set in the BIT(4) of BASE-T1 AN
196 * advertisement register 7.515 and whether the status
197 * is forced or not, it is set in the BIT(12) of BASE-T1
198 * AN advertisement register 7.514.
199 * Sets 10BASE-T1L Ability BIT(14) in BASE-T1 autonegotiation
200 * advertisement register [31:16] if supported.
202 static int genphy_c45_baset1_an_config_aneg(struct phy_device
*phydev
)
204 u16 adv_l_mask
, adv_l
= 0;
205 u16 adv_m_mask
, adv_m
= 0;
209 adv_l_mask
= MDIO_AN_T1_ADV_L_FORCE_MS
| MDIO_AN_T1_ADV_L_PAUSE_CAP
|
210 MDIO_AN_T1_ADV_L_PAUSE_ASYM
;
211 adv_m_mask
= MDIO_AN_T1_ADV_M_1000BT1
| MDIO_AN_T1_ADV_M_100BT1
|
212 MDIO_AN_T1_ADV_M_MST
| MDIO_AN_T1_ADV_M_B10L
;
214 switch (phydev
->master_slave_set
) {
215 case MASTER_SLAVE_CFG_MASTER_FORCE
:
216 adv_m
|= MDIO_AN_T1_ADV_M_MST
;
218 case MASTER_SLAVE_CFG_SLAVE_FORCE
:
219 adv_l
|= MDIO_AN_T1_ADV_L_FORCE_MS
;
221 case MASTER_SLAVE_CFG_MASTER_PREFERRED
:
222 adv_m
|= MDIO_AN_T1_ADV_M_MST
;
224 case MASTER_SLAVE_CFG_SLAVE_PREFERRED
:
226 case MASTER_SLAVE_CFG_UNKNOWN
:
227 case MASTER_SLAVE_CFG_UNSUPPORTED
:
228 /* if master/slave role is not specified, do not overwrite it */
229 adv_l_mask
&= ~MDIO_AN_T1_ADV_L_FORCE_MS
;
230 adv_m_mask
&= ~MDIO_AN_T1_ADV_M_MST
;
233 phydev_warn(phydev
, "Unsupported Master/Slave mode\n");
237 adv_l
|= linkmode_adv_to_mii_t1_adv_l_t(phydev
->advertising
);
239 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_ADV_L
,
246 adv_m
|= linkmode_adv_to_mii_t1_adv_m_t(phydev
->advertising
);
248 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_ADV_M
,
259 * genphy_c45_an_config_aneg - configure advertisement registers
260 * @phydev: target phy_device struct
262 * Configure advertisement registers based on modes set in phydev->advertising
264 * Returns negative errno code on failure, 0 if advertisement didn't change,
265 * or 1 if advertised modes changed.
267 int genphy_c45_an_config_aneg(struct phy_device
*phydev
)
269 int changed
= 0, ret
;
272 linkmode_and(phydev
->advertising
, phydev
->advertising
,
275 ret
= genphy_c45_an_config_eee_aneg(phydev
);
281 if (genphy_c45_baset1_able(phydev
))
282 return genphy_c45_baset1_an_config_aneg(phydev
);
284 adv
= linkmode_adv_to_mii_adv_t(phydev
->advertising
);
286 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
, MDIO_AN_ADVERTISE
,
287 ADVERTISE_ALL
| ADVERTISE_100BASE4
|
288 ADVERTISE_PAUSE_CAP
| ADVERTISE_PAUSE_ASYM
,
295 adv
= linkmode_adv_to_mii_10gbt_adv_t(phydev
->advertising
);
297 ret
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
, MDIO_AN_10GBT_CTRL
,
298 MDIO_AN_10GBT_CTRL_ADV10G
|
299 MDIO_AN_10GBT_CTRL_ADV5G
|
300 MDIO_AN_10GBT_CTRL_ADV2_5G
, adv
);
308 EXPORT_SYMBOL_GPL(genphy_c45_an_config_aneg
);
311 * genphy_c45_an_disable_aneg - disable auto-negotiation
312 * @phydev: target phy_device struct
314 * Disable auto-negotiation in the Clause 45 PHY. The link parameters
315 * are controlled through the PMA/PMD MMD registers.
317 * Returns zero on success, negative errno code on failure.
319 int genphy_c45_an_disable_aneg(struct phy_device
*phydev
)
321 u16 reg
= MDIO_CTRL1
;
323 if (genphy_c45_baset1_able(phydev
))
324 reg
= MDIO_AN_T1_CTRL
;
326 return phy_clear_bits_mmd(phydev
, MDIO_MMD_AN
, reg
,
327 MDIO_AN_CTRL1_ENABLE
| MDIO_AN_CTRL1_RESTART
);
329 EXPORT_SYMBOL_GPL(genphy_c45_an_disable_aneg
);
332 * genphy_c45_restart_aneg - Enable and restart auto-negotiation
333 * @phydev: target phy_device struct
335 * This assumes that the auto-negotiation MMD is present.
337 * Enable and restart auto-negotiation.
339 int genphy_c45_restart_aneg(struct phy_device
*phydev
)
341 u16 reg
= MDIO_CTRL1
;
343 if (genphy_c45_baset1_able(phydev
))
344 reg
= MDIO_AN_T1_CTRL
;
346 return phy_set_bits_mmd(phydev
, MDIO_MMD_AN
, reg
,
347 MDIO_AN_CTRL1_ENABLE
| MDIO_AN_CTRL1_RESTART
);
349 EXPORT_SYMBOL_GPL(genphy_c45_restart_aneg
);
352 * genphy_c45_check_and_restart_aneg - Enable and restart auto-negotiation
353 * @phydev: target phy_device struct
354 * @restart: whether aneg restart is requested
356 * This assumes that the auto-negotiation MMD is present.
358 * Check, and restart auto-negotiation if needed.
360 int genphy_c45_check_and_restart_aneg(struct phy_device
*phydev
, bool restart
)
362 u16 reg
= MDIO_CTRL1
;
365 if (genphy_c45_baset1_able(phydev
))
366 reg
= MDIO_AN_T1_CTRL
;
369 /* Configure and restart aneg if it wasn't set before */
370 ret
= phy_read_mmd(phydev
, MDIO_MMD_AN
, reg
);
374 if (!(ret
& MDIO_AN_CTRL1_ENABLE
))
379 return genphy_c45_restart_aneg(phydev
);
383 EXPORT_SYMBOL_GPL(genphy_c45_check_and_restart_aneg
);
386 * genphy_c45_aneg_done - return auto-negotiation complete status
387 * @phydev: target phy_device struct
389 * This assumes that the auto-negotiation MMD is present.
391 * Reads the status register from the auto-negotiation MMD, returning:
392 * - positive if auto-negotiation is complete
393 * - negative errno code on error
396 int genphy_c45_aneg_done(struct phy_device
*phydev
)
398 int reg
= MDIO_STAT1
;
401 if (genphy_c45_baset1_able(phydev
))
402 reg
= MDIO_AN_T1_STAT
;
404 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, reg
);
406 return val
< 0 ? val
: val
& MDIO_AN_STAT1_COMPLETE
? 1 : 0;
408 EXPORT_SYMBOL_GPL(genphy_c45_aneg_done
);
411 * genphy_c45_read_link - read the overall link status from the MMDs
412 * @phydev: target phy_device struct
414 * Read the link status from the specified MMDs, and if they all indicate
415 * that the link is up, set phydev->link to 1. If an error is encountered,
416 * a negative errno will be returned, otherwise zero.
418 int genphy_c45_read_link(struct phy_device
*phydev
)
420 u32 mmd_mask
= MDIO_DEVS_PMAPMD
;
424 if (phydev
->c45_ids
.mmds_present
& MDIO_DEVS_AN
) {
425 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_CTRL1
);
429 /* Autoneg is being started, therefore disregard current
430 * link status and report link as down.
432 if (val
& MDIO_AN_CTRL1_RESTART
) {
438 while (mmd_mask
&& link
) {
439 devad
= __ffs(mmd_mask
);
440 mmd_mask
&= ~BIT(devad
);
442 /* The link state is latched low so that momentary link
443 * drops can be detected. Do not double-read the status
444 * in polling mode to detect such short link drops except
445 * the link was already down.
447 if (!phy_polling_mode(phydev
) || !phydev
->link
) {
448 val
= phy_read_mmd(phydev
, devad
, MDIO_STAT1
);
451 else if (val
& MDIO_STAT1_LSTATUS
)
455 val
= phy_read_mmd(phydev
, devad
, MDIO_STAT1
);
459 if (!(val
& MDIO_STAT1_LSTATUS
))
467 EXPORT_SYMBOL_GPL(genphy_c45_read_link
);
469 /* Read the Clause 45 defined BASE-T1 AN (7.513) status register to check
470 * if autoneg is complete. If so read the BASE-T1 Autonegotiation
471 * Advertisement registers filling in the link partner advertisement,
472 * pause and asym_pause members in phydev.
474 static int genphy_c45_baset1_read_lpa(struct phy_device
*phydev
)
478 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_STAT
);
482 if (!(val
& MDIO_AN_STAT1_COMPLETE
)) {
483 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->lp_advertising
);
484 mii_t1_adv_l_mod_linkmode_t(phydev
->lp_advertising
, 0);
485 mii_t1_adv_m_mod_linkmode_t(phydev
->lp_advertising
, 0);
488 phydev
->asym_pause
= 0;
493 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->lp_advertising
, 1);
495 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_LP_L
);
499 mii_t1_adv_l_mod_linkmode_t(phydev
->lp_advertising
, val
);
500 phydev
->pause
= val
& MDIO_AN_T1_ADV_L_PAUSE_CAP
? 1 : 0;
501 phydev
->asym_pause
= val
& MDIO_AN_T1_ADV_L_PAUSE_ASYM
? 1 : 0;
503 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_LP_M
);
507 mii_t1_adv_m_mod_linkmode_t(phydev
->lp_advertising
, val
);
513 * genphy_c45_read_lpa - read the link partner advertisement and pause
514 * @phydev: target phy_device struct
516 * Read the Clause 45 defined base (7.19) and 10G (7.33) status registers,
517 * filling in the link partner advertisement, pause and asym_pause members
518 * in @phydev. This assumes that the auto-negotiation MMD is present, and
519 * the backplane bit (7.48.0) is clear. Clause 45 PHY drivers are expected
520 * to fill in the remainder of the link partner advert from vendor registers.
522 int genphy_c45_read_lpa(struct phy_device
*phydev
)
526 if (genphy_c45_baset1_able(phydev
))
527 return genphy_c45_baset1_read_lpa(phydev
);
529 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
533 if (!(val
& MDIO_AN_STAT1_COMPLETE
)) {
534 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
,
535 phydev
->lp_advertising
);
536 mii_10gbt_stat_mod_linkmode_lpa_t(phydev
->lp_advertising
, 0);
537 mii_adv_mod_linkmode_adv_t(phydev
->lp_advertising
, 0);
539 phydev
->asym_pause
= 0;
544 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->lp_advertising
,
545 val
& MDIO_AN_STAT1_LPABLE
);
547 /* Read the link partner's base page advertisement */
548 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_LPA
);
552 mii_adv_mod_linkmode_adv_t(phydev
->lp_advertising
, val
);
553 phydev
->pause
= val
& LPA_PAUSE_CAP
? 1 : 0;
554 phydev
->asym_pause
= val
& LPA_PAUSE_ASYM
? 1 : 0;
556 /* Read the link partner's 10G advertisement */
557 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_10GBT_STAT
);
561 mii_10gbt_stat_mod_linkmode_lpa_t(phydev
->lp_advertising
, val
);
565 EXPORT_SYMBOL_GPL(genphy_c45_read_lpa
);
568 * genphy_c45_pma_baset1_read_master_slave - read forced master/slave
570 * @phydev: target phy_device struct
572 int genphy_c45_pma_baset1_read_master_slave(struct phy_device
*phydev
)
576 phydev
->master_slave_state
= MASTER_SLAVE_STATE_UNKNOWN
;
577 phydev
->master_slave_get
= MASTER_SLAVE_CFG_UNKNOWN
;
579 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_PMD_BT1_CTRL
);
583 if (val
& MDIO_PMA_PMD_BT1_CTRL_CFG_MST
) {
584 phydev
->master_slave_get
= MASTER_SLAVE_CFG_MASTER_FORCE
;
585 phydev
->master_slave_state
= MASTER_SLAVE_STATE_MASTER
;
587 phydev
->master_slave_get
= MASTER_SLAVE_CFG_SLAVE_FORCE
;
588 phydev
->master_slave_state
= MASTER_SLAVE_STATE_SLAVE
;
593 EXPORT_SYMBOL_GPL(genphy_c45_pma_baset1_read_master_slave
);
596 * genphy_c45_read_pma - read link speed etc from PMA
597 * @phydev: target phy_device struct
599 int genphy_c45_read_pma(struct phy_device
*phydev
)
603 linkmode_zero(phydev
->lp_advertising
);
605 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_CTRL1
);
609 switch (val
& MDIO_CTRL1_SPEEDSEL
) {
611 phydev
->speed
= SPEED_10
;
613 case MDIO_PMA_CTRL1_SPEED100
:
614 phydev
->speed
= SPEED_100
;
616 case MDIO_PMA_CTRL1_SPEED1000
:
617 phydev
->speed
= SPEED_1000
;
619 case MDIO_CTRL1_SPEED2_5G
:
620 phydev
->speed
= SPEED_2500
;
622 case MDIO_CTRL1_SPEED5G
:
623 phydev
->speed
= SPEED_5000
;
625 case MDIO_CTRL1_SPEED10G
:
626 phydev
->speed
= SPEED_10000
;
629 phydev
->speed
= SPEED_UNKNOWN
;
633 phydev
->duplex
= DUPLEX_FULL
;
635 if (genphy_c45_baset1_able(phydev
)) {
636 val
= genphy_c45_pma_baset1_read_master_slave(phydev
);
643 EXPORT_SYMBOL_GPL(genphy_c45_read_pma
);
646 * genphy_c45_read_mdix - read mdix status from PMA
647 * @phydev: target phy_device struct
649 int genphy_c45_read_mdix(struct phy_device
*phydev
)
653 if (phydev
->speed
== SPEED_10000
) {
654 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
,
655 MDIO_PMA_10GBT_SWAPPOL
);
660 case MDIO_PMA_10GBT_SWAPPOL_ABNX
| MDIO_PMA_10GBT_SWAPPOL_CDNX
:
661 phydev
->mdix
= ETH_TP_MDI
;
665 phydev
->mdix
= ETH_TP_MDI_X
;
669 phydev
->mdix
= ETH_TP_MDI_INVALID
;
676 EXPORT_SYMBOL_GPL(genphy_c45_read_mdix
);
679 * genphy_c45_write_eee_adv - write advertised EEE link modes
680 * @phydev: target phy_device struct
681 * @adv: the linkmode advertisement settings
683 static int genphy_c45_write_eee_adv(struct phy_device
*phydev
,
686 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp
);
687 int val
, changed
= 0;
689 linkmode_andnot(tmp
, adv
, phydev
->eee_broken_modes
);
691 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP1_FEATURES
)) {
692 val
= linkmode_to_mii_eee_cap1_t(tmp
);
694 /* IEEE 802.3-2018 45.2.7.13 EEE advertisement 1
697 val
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
,
699 MDIO_EEE_100TX
| MDIO_EEE_1000T
|
700 MDIO_EEE_10GT
| MDIO_EEE_1000KX
|
701 MDIO_EEE_10GKX4
| MDIO_EEE_10GKR
,
709 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP2_FEATURES
)) {
710 val
= linkmode_to_mii_eee_cap2_t(tmp
);
712 /* IEEE 802.3-2022 45.2.7.16 EEE advertisement 2
715 val
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
,
717 MDIO_EEE_2_5GT
| MDIO_EEE_5GT
,
725 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
726 phydev
->supported_eee
)) {
727 val
= linkmode_adv_to_mii_10base_t1_t(adv
);
728 /* IEEE 802.3cg-2019 45.2.7.25 10BASE-T1 AN control register
731 val
= phy_modify_mmd_changed(phydev
, MDIO_MMD_AN
,
732 MDIO_AN_10BT1_AN_CTRL
,
733 MDIO_AN_10BT1_AN_CTRL_ADV_EEE_T1L
,
745 * genphy_c45_read_eee_adv - read advertised EEE link modes
746 * @phydev: target phy_device struct
747 * @adv: the linkmode advertisement status
749 int genphy_c45_read_eee_adv(struct phy_device
*phydev
, unsigned long *adv
)
753 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP1_FEATURES
)) {
754 /* IEEE 802.3-2018 45.2.7.13 EEE advertisement 1
757 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_EEE_ADV
);
761 mii_eee_cap1_mod_linkmode_t(adv
, val
);
764 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP2_FEATURES
)) {
765 /* IEEE 802.3-2022 45.2.7.16 EEE advertisement 2
768 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_EEE_ADV2
);
772 mii_eee_cap2_mod_linkmode_adv_t(adv
, val
);
775 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
776 phydev
->supported_eee
)) {
777 /* IEEE 802.3cg-2019 45.2.7.25 10BASE-T1 AN control register
780 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_10BT1_AN_CTRL
);
784 mii_10base_t1_adv_mod_linkmode_t(adv
, val
);
791 * genphy_c45_read_eee_lpa - read advertised LP EEE link modes
792 * @phydev: target phy_device struct
793 * @lpa: the linkmode LP advertisement status
795 static int genphy_c45_read_eee_lpa(struct phy_device
*phydev
,
800 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP1_FEATURES
)) {
801 /* IEEE 802.3-2018 45.2.7.14 EEE link partner ability 1
804 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_EEE_LPABLE
);
808 mii_eee_cap1_mod_linkmode_t(lpa
, val
);
811 if (linkmode_intersects(phydev
->supported_eee
, PHY_EEE_CAP2_FEATURES
)) {
812 /* IEEE 802.3-2022 45.2.7.17 EEE link partner ability 2
815 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_EEE_LPABLE2
);
819 mii_eee_cap2_mod_linkmode_adv_t(lpa
, val
);
822 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
823 phydev
->supported_eee
)) {
824 /* IEEE 802.3cg-2019 45.2.7.26 10BASE-T1 AN status register
827 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_10BT1_AN_STAT
);
831 mii_10base_t1_adv_mod_linkmode_t(lpa
, val
);
838 * genphy_c45_read_eee_cap1 - read supported EEE link modes from register 3.20
839 * @phydev: target phy_device struct
841 static int genphy_c45_read_eee_cap1(struct phy_device
*phydev
)
845 /* IEEE 802.3-2018 45.2.3.10 EEE control and capability 1
848 val
= phy_read_mmd(phydev
, MDIO_MMD_PCS
, MDIO_PCS_EEE_ABLE
);
852 /* The 802.3 2018 standard says the top 2 bits are reserved and should
853 * read as 0. Also, it seems unlikely anybody will build a PHY which
854 * supports 100GBASE-R deep sleep all the way down to 100BASE-TX EEE.
855 * If MDIO_PCS_EEE_ABLE is 0xffff assume EEE is not supported.
860 mii_eee_cap1_mod_linkmode_t(phydev
->supported_eee
, val
);
862 /* Some buggy devices indicate EEE link modes in MDIO_PCS_EEE_ABLE
863 * which they don't support as indicated by BMSR, ESTATUS etc.
865 linkmode_and(phydev
->supported_eee
, phydev
->supported_eee
,
872 * genphy_c45_read_eee_cap2 - read supported EEE link modes from register 3.21
873 * @phydev: target phy_device struct
875 static int genphy_c45_read_eee_cap2(struct phy_device
*phydev
)
879 /* IEEE 802.3-2022 45.2.3.11 EEE control and capability 2
882 val
= phy_read_mmd(phydev
, MDIO_MMD_PCS
, MDIO_PCS_EEE_ABLE2
);
886 /* IEEE 802.3-2022 45.2.3.11 says 9 bits are reserved. */
890 mii_eee_cap2_mod_linkmode_sup_t(phydev
->supported_eee
, val
);
896 * genphy_c45_read_eee_abilities - read supported EEE link modes
897 * @phydev: target phy_device struct
899 int genphy_c45_read_eee_abilities(struct phy_device
*phydev
)
903 /* There is not indicator whether optional register
904 * "EEE control and capability 1" (3.20) is supported. Read it only
905 * on devices with appropriate linkmodes.
907 if (linkmode_intersects(phydev
->supported
, PHY_EEE_CAP1_FEATURES
)) {
908 val
= genphy_c45_read_eee_cap1(phydev
);
913 /* Same for cap2 (3.21) */
914 if (linkmode_intersects(phydev
->supported
, PHY_EEE_CAP2_FEATURES
)) {
915 val
= genphy_c45_read_eee_cap2(phydev
);
920 if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
921 phydev
->supported
)) {
922 /* IEEE 802.3cg-2019 45.2.1.186b 10BASE-T1L PMA status register
925 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_10T1L_STAT
);
929 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
930 phydev
->supported_eee
,
931 val
& MDIO_PMA_10T1L_STAT_EEE
);
936 EXPORT_SYMBOL_GPL(genphy_c45_read_eee_abilities
);
939 * genphy_c45_an_config_eee_aneg - configure EEE advertisement
940 * @phydev: target phy_device struct
942 int genphy_c45_an_config_eee_aneg(struct phy_device
*phydev
)
944 if (!phydev
->eee_cfg
.eee_enabled
) {
945 __ETHTOOL_DECLARE_LINK_MODE_MASK(adv
) = {};
947 return genphy_c45_write_eee_adv(phydev
, adv
);
950 return genphy_c45_write_eee_adv(phydev
, phydev
->advertising_eee
);
952 EXPORT_SYMBOL_GPL(genphy_c45_an_config_eee_aneg
);
955 * genphy_c45_pma_baset1_read_abilities - read supported baset1 link modes from PMA
956 * @phydev: target phy_device struct
958 * Read the supported link modes from the extended BASE-T1 ability register
960 int genphy_c45_pma_baset1_read_abilities(struct phy_device
*phydev
)
964 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_PMD_BT1
);
968 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT1L_Full_BIT
,
970 val
& MDIO_PMA_PMD_BT1_B10L_ABLE
);
972 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT1_Full_BIT
,
974 val
& MDIO_PMA_PMD_BT1_B100_ABLE
);
976 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT1_Full_BIT
,
978 val
& MDIO_PMA_PMD_BT1_B1000_ABLE
);
980 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_STAT
);
984 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
,
986 val
& MDIO_AN_STAT1_ABLE
);
990 EXPORT_SYMBOL_GPL(genphy_c45_pma_baset1_read_abilities
);
993 * genphy_c45_pma_read_ext_abilities - read supported link modes from PMA
994 * @phydev: target phy_device struct
996 * Read the supported link modes from the PMA/PMD extended ability register
999 int genphy_c45_pma_read_ext_abilities(struct phy_device
*phydev
)
1003 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_EXTABLE
);
1007 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT
,
1009 val
& MDIO_PMA_EXTABLE_10GBLRM
);
1010 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT
,
1012 val
& MDIO_PMA_EXTABLE_10GBT
);
1013 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT
,
1015 val
& MDIO_PMA_EXTABLE_10GBKX4
);
1016 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseKR_Full_BIT
,
1018 val
& MDIO_PMA_EXTABLE_10GBKR
);
1019 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT
,
1021 val
& MDIO_PMA_EXTABLE_1000BT
);
1022 linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseKX_Full_BIT
,
1024 val
& MDIO_PMA_EXTABLE_1000BKX
);
1026 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT
,
1028 val
& MDIO_PMA_EXTABLE_100BTX
);
1029 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT
,
1031 val
& MDIO_PMA_EXTABLE_100BTX
);
1033 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT
,
1035 val
& MDIO_PMA_EXTABLE_10BT
);
1036 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT
,
1038 val
& MDIO_PMA_EXTABLE_10BT
);
1040 if (val
& MDIO_PMA_EXTABLE_NBT
) {
1041 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
,
1042 MDIO_PMA_NG_EXTABLE
);
1046 linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT
,
1048 val
& MDIO_PMA_NG_EXTABLE_2_5GBT
);
1050 linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT
,
1052 val
& MDIO_PMA_NG_EXTABLE_5GBT
);
1055 if (val
& MDIO_PMA_EXTABLE_BT1
) {
1056 val
= genphy_c45_pma_baset1_read_abilities(phydev
);
1063 EXPORT_SYMBOL_GPL(genphy_c45_pma_read_ext_abilities
);
1066 * genphy_c45_pma_read_abilities - read supported link modes from PMA
1067 * @phydev: target phy_device struct
1069 * Read the supported link modes from the PMA Status 2 (1.8) register. If bit
1070 * 1.8.9 is set, the list of supported modes is build using the values in the
1071 * PMA Extended Abilities (1.11) register, indicating 1000BASET an 10G related
1072 * modes. If bit 1.11.14 is set, then the list is also extended with the modes
1073 * in the 2.5G/5G PMA Extended register (1.21), indicating if 2.5GBASET and
1074 * 5GBASET are supported.
1076 int genphy_c45_pma_read_abilities(struct phy_device
*phydev
)
1080 linkmode_clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, phydev
->supported
);
1081 if (phydev
->c45_ids
.mmds_present
& MDIO_DEVS_AN
) {
1082 val
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_STAT1
);
1086 if (val
& MDIO_AN_STAT1_ABLE
)
1087 linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
,
1091 val
= phy_read_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_STAT2
);
1095 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseSR_Full_BIT
,
1097 val
& MDIO_PMA_STAT2_10GBSR
);
1099 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseLR_Full_BIT
,
1101 val
& MDIO_PMA_STAT2_10GBLR
);
1103 linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseER_Full_BIT
,
1105 val
& MDIO_PMA_STAT2_10GBER
);
1107 if (val
& MDIO_PMA_STAT2_EXTABLE
) {
1108 val
= genphy_c45_pma_read_ext_abilities(phydev
);
1113 /* This is optional functionality. If not supported, we may get an error
1114 * which should be ignored.
1116 genphy_c45_read_eee_abilities(phydev
);
1120 EXPORT_SYMBOL_GPL(genphy_c45_pma_read_abilities
);
1122 /* Read master/slave preference from registers.
1123 * The preference is read from the BIT(4) of BASE-T1 AN
1124 * advertisement register 7.515 and whether the preference
1125 * is forced or not, it is read from BASE-T1 AN advertisement
1128 int genphy_c45_baset1_read_status(struct phy_device
*phydev
)
1133 phydev
->master_slave_get
= MASTER_SLAVE_CFG_UNKNOWN
;
1134 phydev
->master_slave_state
= MASTER_SLAVE_STATE_UNKNOWN
;
1136 ret
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_ADV_L
);
1140 cfg
= phy_read_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_T1_ADV_M
);
1144 if (ret
& MDIO_AN_T1_ADV_L_FORCE_MS
) {
1145 if (cfg
& MDIO_AN_T1_ADV_M_MST
)
1146 phydev
->master_slave_get
= MASTER_SLAVE_CFG_MASTER_FORCE
;
1148 phydev
->master_slave_get
= MASTER_SLAVE_CFG_SLAVE_FORCE
;
1150 if (cfg
& MDIO_AN_T1_ADV_M_MST
)
1151 phydev
->master_slave_get
= MASTER_SLAVE_CFG_MASTER_PREFERRED
;
1153 phydev
->master_slave_get
= MASTER_SLAVE_CFG_SLAVE_PREFERRED
;
1158 EXPORT_SYMBOL_GPL(genphy_c45_baset1_read_status
);
1161 * genphy_c45_read_status - read PHY status
1162 * @phydev: target phy_device struct
1164 * Reads status from PHY and sets phy_device members accordingly.
1166 int genphy_c45_read_status(struct phy_device
*phydev
)
1170 ret
= genphy_c45_read_link(phydev
);
1174 phydev
->speed
= SPEED_UNKNOWN
;
1175 phydev
->duplex
= DUPLEX_UNKNOWN
;
1177 phydev
->asym_pause
= 0;
1179 if (phydev
->autoneg
== AUTONEG_ENABLE
) {
1180 ret
= genphy_c45_read_lpa(phydev
);
1184 if (genphy_c45_baset1_able(phydev
)) {
1185 ret
= genphy_c45_baset1_read_status(phydev
);
1190 phy_resolve_aneg_linkmode(phydev
);
1192 ret
= genphy_c45_read_pma(phydev
);
1197 EXPORT_SYMBOL_GPL(genphy_c45_read_status
);
1200 * genphy_c45_config_aneg - restart auto-negotiation or forced setup
1201 * @phydev: target phy_device struct
1203 * Description: If auto-negotiation is enabled, we configure the
1204 * advertising, and then restart auto-negotiation. If it is not
1205 * enabled, then we force a configuration.
1207 int genphy_c45_config_aneg(struct phy_device
*phydev
)
1209 bool changed
= false;
1212 if (phydev
->autoneg
== AUTONEG_DISABLE
)
1213 return genphy_c45_pma_setup_forced(phydev
);
1215 ret
= genphy_c45_an_config_aneg(phydev
);
1221 return genphy_c45_check_and_restart_aneg(phydev
, changed
);
1223 EXPORT_SYMBOL_GPL(genphy_c45_config_aneg
);
1225 /* The gen10g_* functions are the old Clause 45 stub */
1227 int gen10g_config_aneg(struct phy_device
*phydev
)
1231 EXPORT_SYMBOL_GPL(gen10g_config_aneg
);
1233 int genphy_c45_loopback(struct phy_device
*phydev
, bool enable
)
1235 return phy_modify_mmd(phydev
, MDIO_MMD_PCS
, MDIO_CTRL1
,
1236 MDIO_PCS_CTRL1_LOOPBACK
,
1237 enable
? MDIO_PCS_CTRL1_LOOPBACK
: 0);
1239 EXPORT_SYMBOL_GPL(genphy_c45_loopback
);
1242 * genphy_c45_fast_retrain - configure fast retrain registers
1243 * @phydev: target phy_device struct
1244 * @enable: enable fast retrain or not
1246 * Description: If fast-retrain is enabled, we configure PHY as
1247 * advertising fast retrain capable and THP Bypass Request, then
1248 * enable fast retrain. If it is not enabled, we configure fast
1251 int genphy_c45_fast_retrain(struct phy_device
*phydev
, bool enable
)
1256 return phy_clear_bits_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_FSRT_CSR
,
1257 MDIO_PMA_10GBR_FSRT_ENABLE
);
1259 if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT
, phydev
->supported
)) {
1260 ret
= phy_set_bits_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_10GBT_CTRL
,
1261 MDIO_AN_10GBT_CTRL_ADVFSRT2_5G
);
1265 ret
= phy_set_bits_mmd(phydev
, MDIO_MMD_AN
, MDIO_AN_CTRL2
,
1266 MDIO_AN_THP_BP2_5GT
);
1271 return phy_set_bits_mmd(phydev
, MDIO_MMD_PMAPMD
, MDIO_PMA_10GBR_FSRT_CSR
,
1272 MDIO_PMA_10GBR_FSRT_ENABLE
);
1274 EXPORT_SYMBOL_GPL(genphy_c45_fast_retrain
);
1277 * genphy_c45_plca_get_cfg - get PLCA configuration from standard registers
1278 * @phydev: target phy_device struct
1279 * @plca_cfg: output structure to store the PLCA configuration
1281 * Description: if the PHY complies to the Open Alliance TC14 10BASE-T1S PLCA
1282 * Management Registers specifications, this function can be used to retrieve
1283 * the current PLCA configuration from the standard registers in MMD 31.
1285 int genphy_c45_plca_get_cfg(struct phy_device
*phydev
,
1286 struct phy_plca_cfg
*plca_cfg
)
1290 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_IDVER
);
1294 if ((ret
& MDIO_OATC14_PLCA_IDM
) != OATC14_IDM
)
1297 plca_cfg
->version
= ret
& ~MDIO_OATC14_PLCA_IDM
;
1299 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_CTRL0
);
1303 plca_cfg
->enabled
= !!(ret
& MDIO_OATC14_PLCA_EN
);
1305 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_CTRL1
);
1309 plca_cfg
->node_cnt
= (ret
& MDIO_OATC14_PLCA_NCNT
) >> 8;
1310 plca_cfg
->node_id
= (ret
& MDIO_OATC14_PLCA_ID
);
1312 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_TOTMR
);
1316 plca_cfg
->to_tmr
= ret
& MDIO_OATC14_PLCA_TOT
;
1318 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_BURST
);
1322 plca_cfg
->burst_cnt
= (ret
& MDIO_OATC14_PLCA_MAXBC
) >> 8;
1323 plca_cfg
->burst_tmr
= (ret
& MDIO_OATC14_PLCA_BTMR
);
1327 EXPORT_SYMBOL_GPL(genphy_c45_plca_get_cfg
);
1330 * genphy_c45_plca_set_cfg - set PLCA configuration using standard registers
1331 * @phydev: target phy_device struct
1332 * @plca_cfg: structure containing the PLCA configuration. Fields set to -1 are
1333 * not to be changed.
1335 * Description: if the PHY complies to the Open Alliance TC14 10BASE-T1S PLCA
1336 * Management Registers specifications, this function can be used to modify
1337 * the PLCA configuration using the standard registers in MMD 31.
1339 int genphy_c45_plca_set_cfg(struct phy_device
*phydev
,
1340 const struct phy_plca_cfg
*plca_cfg
)
1345 // PLCA IDVER is read-only
1346 if (plca_cfg
->version
>= 0)
1349 // first of all, disable PLCA if required
1350 if (plca_cfg
->enabled
== 0) {
1351 ret
= phy_clear_bits_mmd(phydev
, MDIO_MMD_VEND2
,
1352 MDIO_OATC14_PLCA_CTRL0
,
1353 MDIO_OATC14_PLCA_EN
);
1359 // check if we need to set the PLCA node count, node ID, or both
1360 if (plca_cfg
->node_cnt
>= 0 || plca_cfg
->node_id
>= 0) {
1361 /* if one between node count and node ID is -not- to be
1362 * changed, read the register to later perform merge/purge of
1363 * the configuration as appropriate
1365 if (plca_cfg
->node_cnt
< 0 || plca_cfg
->node_id
< 0) {
1366 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
,
1367 MDIO_OATC14_PLCA_CTRL1
);
1375 if (plca_cfg
->node_cnt
>= 0)
1376 val
= (val
& ~MDIO_OATC14_PLCA_NCNT
) |
1377 (plca_cfg
->node_cnt
<< 8);
1379 if (plca_cfg
->node_id
>= 0)
1380 val
= (val
& ~MDIO_OATC14_PLCA_ID
) |
1381 (plca_cfg
->node_id
);
1383 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND2
,
1384 MDIO_OATC14_PLCA_CTRL1
, val
);
1390 if (plca_cfg
->to_tmr
>= 0) {
1391 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND2
,
1392 MDIO_OATC14_PLCA_TOTMR
,
1399 // check if we need to set the PLCA burst count, burst timer, or both
1400 if (plca_cfg
->burst_cnt
>= 0 || plca_cfg
->burst_tmr
>= 0) {
1401 /* if one between burst count and burst timer is -not- to be
1402 * changed, read the register to later perform merge/purge of
1403 * the configuration as appropriate
1405 if (plca_cfg
->burst_cnt
< 0 || plca_cfg
->burst_tmr
< 0) {
1406 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
,
1407 MDIO_OATC14_PLCA_BURST
);
1415 if (plca_cfg
->burst_cnt
>= 0)
1416 val
= (val
& ~MDIO_OATC14_PLCA_MAXBC
) |
1417 (plca_cfg
->burst_cnt
<< 8);
1419 if (plca_cfg
->burst_tmr
>= 0)
1420 val
= (val
& ~MDIO_OATC14_PLCA_BTMR
) |
1421 (plca_cfg
->burst_tmr
);
1423 ret
= phy_write_mmd(phydev
, MDIO_MMD_VEND2
,
1424 MDIO_OATC14_PLCA_BURST
, val
);
1430 // if we need to enable PLCA, do it at the end
1431 if (plca_cfg
->enabled
> 0) {
1432 ret
= phy_set_bits_mmd(phydev
, MDIO_MMD_VEND2
,
1433 MDIO_OATC14_PLCA_CTRL0
,
1434 MDIO_OATC14_PLCA_EN
);
1442 EXPORT_SYMBOL_GPL(genphy_c45_plca_set_cfg
);
1445 * genphy_c45_plca_get_status - get PLCA status from standard registers
1446 * @phydev: target phy_device struct
1447 * @plca_st: output structure to store the PLCA status
1449 * Description: if the PHY complies to the Open Alliance TC14 10BASE-T1S PLCA
1450 * Management Registers specifications, this function can be used to retrieve
1451 * the current PLCA status information from the standard registers in MMD 31.
1453 int genphy_c45_plca_get_status(struct phy_device
*phydev
,
1454 struct phy_plca_status
*plca_st
)
1458 ret
= phy_read_mmd(phydev
, MDIO_MMD_VEND2
, MDIO_OATC14_PLCA_STATUS
);
1462 plca_st
->pst
= !!(ret
& MDIO_OATC14_PLCA_PST
);
1465 EXPORT_SYMBOL_GPL(genphy_c45_plca_get_status
);
1468 * genphy_c45_eee_is_active - get EEE status
1469 * @phydev: target phy_device struct
1470 * @adv: variable to store advertised linkmodes
1471 * @lp: variable to store LP advertised linkmodes
1472 * @is_enabled: variable to store EEE enabled/disabled configuration value
1474 * Description: this function will read local and link partner PHY
1475 * advertisements. Compare them return current EEE state.
1477 int genphy_c45_eee_is_active(struct phy_device
*phydev
, unsigned long *adv
,
1478 unsigned long *lp
, bool *is_enabled
)
1480 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_adv
) = {};
1481 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_lp
) = {};
1482 __ETHTOOL_DECLARE_LINK_MODE_MASK(common
);
1483 bool eee_enabled
, eee_active
;
1486 ret
= genphy_c45_read_eee_adv(phydev
, tmp_adv
);
1490 ret
= genphy_c45_read_eee_lpa(phydev
, tmp_lp
);
1494 eee_enabled
= !linkmode_empty(tmp_adv
);
1495 linkmode_and(common
, tmp_adv
, tmp_lp
);
1496 if (eee_enabled
&& !linkmode_empty(common
))
1497 eee_active
= phy_check_valid(phydev
->speed
, phydev
->duplex
,
1503 linkmode_copy(adv
, tmp_adv
);
1505 linkmode_copy(lp
, tmp_lp
);
1507 *is_enabled
= eee_enabled
;
1511 EXPORT_SYMBOL(genphy_c45_eee_is_active
);
1514 * genphy_c45_ethtool_get_eee - get EEE supported and status
1515 * @phydev: target phy_device struct
1516 * @data: ethtool_keee data
1518 * Description: it reports the Supported/Advertisement/LP Advertisement
1521 int genphy_c45_ethtool_get_eee(struct phy_device
*phydev
,
1522 struct ethtool_keee
*data
)
1527 ret
= genphy_c45_eee_is_active(phydev
, data
->advertised
,
1528 data
->lp_advertised
, &is_enabled
);
1532 data
->eee_enabled
= is_enabled
;
1533 data
->eee_active
= phydev
->eee_active
;
1534 linkmode_copy(data
->supported
, phydev
->supported_eee
);
1538 EXPORT_SYMBOL(genphy_c45_ethtool_get_eee
);
1541 * genphy_c45_ethtool_set_eee - set EEE supported and status
1542 * @phydev: target phy_device struct
1543 * @data: ethtool_keee data
1545 * Description: sets the Supported/Advertisement/LP Advertisement
1546 * capabilities. If eee_enabled is false, no links modes are
1547 * advertised, but the previously advertised link modes are
1548 * retained. This allows EEE to be enabled/disabled in a
1549 * non-destructive way.
1550 * Returns either error code, 0 if there was no change, or positive
1551 * value if there was a change which triggered auto-neg.
1553 int genphy_c45_ethtool_set_eee(struct phy_device
*phydev
,
1554 struct ethtool_keee
*data
)
1558 if (data
->eee_enabled
) {
1559 unsigned long *adv
= data
->advertised
;
1561 if (!linkmode_empty(adv
)) {
1562 __ETHTOOL_DECLARE_LINK_MODE_MASK(tmp
);
1564 if (linkmode_andnot(tmp
, adv
, phydev
->supported_eee
)) {
1565 phydev_warn(phydev
, "At least some EEE link modes are not supported.\n");
1568 linkmode_copy(phydev
->advertising_eee
, adv
);
1569 } else if (linkmode_empty(phydev
->advertising_eee
)) {
1570 phy_advertise_eee_all(phydev
);
1574 ret
= genphy_c45_an_config_eee_aneg(phydev
);
1576 ret
= phy_restart_aneg(phydev
);
1580 /* explicitly return 1, otherwise (ret > 0) value will be
1581 * overwritten by phy_restart_aneg().
1588 EXPORT_SYMBOL(genphy_c45_ethtool_set_eee
);
1590 struct phy_driver genphy_c45_driver
= {
1591 .phy_id
= 0xffffffff,
1592 .phy_id_mask
= 0xffffffff,
1593 .name
= "Generic Clause 45 PHY",
1594 .read_status
= genphy_c45_read_status
,