Commit 793cc3c7 authored by David S. Miller's avatar David S. Miller

Merge branch 'phy-rate-matching'

Sean Anderson says:

====================
net: phy: Add support for rate matching

This adds support for phy rate matching: when a phy adapts between
differing phy interface and link speeds. It was originally submitted as
part of [1], which is considered "v1" of this series.

Several past discussions [2-4] around adding rate adaptation provide
some context.

Although in earlier versions of this series, userspace could disable
rate matching, now it is only possible to determine the current rate
adaptation type. Disabling or otherwise configuring rate adaptation has
been left for future work. However, because currently only
RATE_MATCH_PAUSE is implemented, it is possible to disable rate
adaptation by modifying the advertisement appropriately.

[1] https://lore.kernel.org/netdev/20220715215954.1449214-1-sean.anderson@seco.com/T/#t
[2] https://lore.kernel.org/netdev/1579701573-6609-1-git-send-email-madalin.bucur@oss.nxp.com/
[3] https://lore.kernel.org/netdev/1580137671-22081-1-git-send-email-madalin.bucur@oss.nxp.com/
[4] https://lore.kernel.org/netdev/20200116181933.32765-1-olteanv@gmail.com/

Changes in v6:
- Don't announce that we've enabled pause frames for rate adaptation
- Merry Christmas
- Rename rate adaptation to rate matching
- Reword documentation, (hopefully) taking into account feedback

Changes in v5:
- Break off patch "net: phy: Add 1000BASE-KX interface mode" for
  separate submission.
- Document phy_rate_adaptation_to_str
- Drop patch "Add some helpers for working with mac caps"; it has been
  incorperated into the autonegotiation patch.
- Move phylink_cap_from_speed_duplex to this commit
- Rebase onto net-next/master
- Remove unnecessary comma

Changes in v4:
- Export phy_rate_adaptation_to_str
- Remove phylink_interface_max_speed, which was accidentally added
- Split off the LS1046ARDB 1G fix

Changes in v3:
- Add phylink_cap_from_speed_duplex to look up the mac capability
  corresponding to the interface's speed.
- Document MAC_(A)SYM_PAUSE
- Include RATE_ADAPT_CRS; it's a few lines and it doesn't hurt.
- Modify link settings directly in phylink_link_up, instead of doing
  things more indirectly via link_*.
- Move unused defines to next commit (where they will be used)
- Remove "Support differing link/interface speed/duplex". It has been
  rendered unnecessary due to simplification of the rate adaptation
  patches. Thanks Russell!
- Rewrite cover letter to better reflect the opinions of the developers
  involved

Changes in v2:
- Add (read-only) ethtool support for rate adaptation
- Add comments clarifying the register defines
- Add locking to phy_get_rate_adaptation
- Always use the rate adaptation setting to determine the interface
  speed/duplex (instead of sometimes using the interface mode).
- Determine the interface speed and max mac speed directly instead of
  guessing based on the caps.
- Move part of commit message to cover letter, as it gives a good
  overview of the whole series, and allows this patch to focus more on
  the specifics.
- Reorder variables in aqr107_read_rate
- Use int/defines instead of enum to allow for use in ioctls/netlink
- Use the phy's rate adaptation setting to determine whether to use its
  link speed/duplex or the MAC's speed/duplex with MLO_AN_INBAND.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 1a4019f4 3c42563b
...@@ -426,6 +426,7 @@ Kernel response contents: ...@@ -426,6 +426,7 @@ Kernel response contents:
``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode ``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode
``ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG`` u8 Master/slave port mode ``ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG`` u8 Master/slave port mode
``ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE`` u8 Master/slave port state ``ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE`` u8 Master/slave port state
``ETHTOOL_A_LINKMODES_RATE_MATCHING`` u8 PHY rate matching
========================================== ====== ========================== ========================================== ====== ==========================
For ``ETHTOOL_A_LINKMODES_OURS``, value represents advertised modes and mask For ``ETHTOOL_A_LINKMODES_OURS``, value represents advertised modes and mask
...@@ -449,6 +450,7 @@ Request contents: ...@@ -449,6 +450,7 @@ Request contents:
``ETHTOOL_A_LINKMODES_SPEED`` u32 link speed (Mb/s) ``ETHTOOL_A_LINKMODES_SPEED`` u32 link speed (Mb/s)
``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode ``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode
``ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG`` u8 Master/slave port mode ``ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG`` u8 Master/slave port mode
``ETHTOOL_A_LINKMODES_RATE_MATCHING`` u8 PHY rate matching
``ETHTOOL_A_LINKMODES_LANES`` u32 lanes ``ETHTOOL_A_LINKMODES_LANES`` u32 lanes
========================================== ====== ========================== ========================================== ====== ==========================
......
...@@ -27,9 +27,12 @@ ...@@ -27,9 +27,12 @@
#define MDIO_PHYXS_VEND_IF_STATUS 0xe812 #define MDIO_PHYXS_VEND_IF_STATUS 0xe812
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_MASK GENMASK(7, 3) #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_MASK GENMASK(7, 3)
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_KR 0 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_KR 0
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_KX 1
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_XFI 2 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_XFI 2
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_USXGMII 3 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_USXGMII 3
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_XAUI 4
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_SGMII 6 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_SGMII 6
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_RXAUI 7
#define MDIO_PHYXS_VEND_IF_STATUS_TYPE_OCSGMII 10 #define MDIO_PHYXS_VEND_IF_STATUS_TYPE_OCSGMII 10
#define MDIO_AN_VEND_PROV 0xc400 #define MDIO_AN_VEND_PROV 0xc400
...@@ -94,6 +97,19 @@ ...@@ -94,6 +97,19 @@
#define VEND1_GLOBAL_GEN_STAT2 0xc831 #define VEND1_GLOBAL_GEN_STAT2 0xc831
#define VEND1_GLOBAL_GEN_STAT2_OP_IN_PROG BIT(15) #define VEND1_GLOBAL_GEN_STAT2_OP_IN_PROG BIT(15)
/* The following registers all have similar layouts; first the registers... */
#define VEND1_GLOBAL_CFG_10M 0x0310
#define VEND1_GLOBAL_CFG_100M 0x031b
#define VEND1_GLOBAL_CFG_1G 0x031c
#define VEND1_GLOBAL_CFG_2_5G 0x031d
#define VEND1_GLOBAL_CFG_5G 0x031e
#define VEND1_GLOBAL_CFG_10G 0x031f
/* ...and now the fields */
#define VEND1_GLOBAL_CFG_RATE_ADAPT GENMASK(8, 7)
#define VEND1_GLOBAL_CFG_RATE_ADAPT_NONE 0
#define VEND1_GLOBAL_CFG_RATE_ADAPT_USX 1
#define VEND1_GLOBAL_CFG_RATE_ADAPT_PAUSE 2
#define VEND1_GLOBAL_RSVD_STAT1 0xc885 #define VEND1_GLOBAL_RSVD_STAT1 0xc885
#define VEND1_GLOBAL_RSVD_STAT1_FW_BUILD_ID GENMASK(7, 4) #define VEND1_GLOBAL_RSVD_STAT1_FW_BUILD_ID GENMASK(7, 4)
#define VEND1_GLOBAL_RSVD_STAT1_PROV_ID GENMASK(3, 0) #define VEND1_GLOBAL_RSVD_STAT1_PROV_ID GENMASK(3, 0)
...@@ -344,40 +360,57 @@ static int aqr_read_status(struct phy_device *phydev) ...@@ -344,40 +360,57 @@ static int aqr_read_status(struct phy_device *phydev)
static int aqr107_read_rate(struct phy_device *phydev) static int aqr107_read_rate(struct phy_device *phydev)
{ {
u32 config_reg;
int val; int val;
val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_TX_VEND_STATUS1); val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_TX_VEND_STATUS1);
if (val < 0) if (val < 0)
return val; return val;
if (val & MDIO_AN_TX_VEND_STATUS1_FULL_DUPLEX)
phydev->duplex = DUPLEX_FULL;
else
phydev->duplex = DUPLEX_HALF;
switch (FIELD_GET(MDIO_AN_TX_VEND_STATUS1_RATE_MASK, val)) { switch (FIELD_GET(MDIO_AN_TX_VEND_STATUS1_RATE_MASK, val)) {
case MDIO_AN_TX_VEND_STATUS1_10BASET: case MDIO_AN_TX_VEND_STATUS1_10BASET:
phydev->speed = SPEED_10; phydev->speed = SPEED_10;
config_reg = VEND1_GLOBAL_CFG_10M;
break; break;
case MDIO_AN_TX_VEND_STATUS1_100BASETX: case MDIO_AN_TX_VEND_STATUS1_100BASETX:
phydev->speed = SPEED_100; phydev->speed = SPEED_100;
config_reg = VEND1_GLOBAL_CFG_100M;
break; break;
case MDIO_AN_TX_VEND_STATUS1_1000BASET: case MDIO_AN_TX_VEND_STATUS1_1000BASET:
phydev->speed = SPEED_1000; phydev->speed = SPEED_1000;
config_reg = VEND1_GLOBAL_CFG_1G;
break; break;
case MDIO_AN_TX_VEND_STATUS1_2500BASET: case MDIO_AN_TX_VEND_STATUS1_2500BASET:
phydev->speed = SPEED_2500; phydev->speed = SPEED_2500;
config_reg = VEND1_GLOBAL_CFG_2_5G;
break; break;
case MDIO_AN_TX_VEND_STATUS1_5000BASET: case MDIO_AN_TX_VEND_STATUS1_5000BASET:
phydev->speed = SPEED_5000; phydev->speed = SPEED_5000;
config_reg = VEND1_GLOBAL_CFG_5G;
break; break;
case MDIO_AN_TX_VEND_STATUS1_10GBASET: case MDIO_AN_TX_VEND_STATUS1_10GBASET:
phydev->speed = SPEED_10000; phydev->speed = SPEED_10000;
config_reg = VEND1_GLOBAL_CFG_10G;
break; break;
default: default:
phydev->speed = SPEED_UNKNOWN; phydev->speed = SPEED_UNKNOWN;
break; return 0;
} }
if (val & MDIO_AN_TX_VEND_STATUS1_FULL_DUPLEX) val = phy_read_mmd(phydev, MDIO_MMD_VEND1, config_reg);
phydev->duplex = DUPLEX_FULL; if (val < 0)
return val;
if (FIELD_GET(VEND1_GLOBAL_CFG_RATE_ADAPT, val) ==
VEND1_GLOBAL_CFG_RATE_ADAPT_PAUSE)
phydev->rate_matching = RATE_MATCH_PAUSE;
else else
phydev->duplex = DUPLEX_HALF; phydev->rate_matching = RATE_MATCH_NONE;
return 0; return 0;
} }
...@@ -401,15 +434,24 @@ static int aqr107_read_status(struct phy_device *phydev) ...@@ -401,15 +434,24 @@ static int aqr107_read_status(struct phy_device *phydev)
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_KR: case MDIO_PHYXS_VEND_IF_STATUS_TYPE_KR:
phydev->interface = PHY_INTERFACE_MODE_10GKR; phydev->interface = PHY_INTERFACE_MODE_10GKR;
break; break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_KX:
phydev->interface = PHY_INTERFACE_MODE_1000BASEKX;
break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_XFI: case MDIO_PHYXS_VEND_IF_STATUS_TYPE_XFI:
phydev->interface = PHY_INTERFACE_MODE_10GBASER; phydev->interface = PHY_INTERFACE_MODE_10GBASER;
break; break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_USXGMII: case MDIO_PHYXS_VEND_IF_STATUS_TYPE_USXGMII:
phydev->interface = PHY_INTERFACE_MODE_USXGMII; phydev->interface = PHY_INTERFACE_MODE_USXGMII;
break; break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_XAUI:
phydev->interface = PHY_INTERFACE_MODE_XAUI;
break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_SGMII: case MDIO_PHYXS_VEND_IF_STATUS_TYPE_SGMII:
phydev->interface = PHY_INTERFACE_MODE_SGMII; phydev->interface = PHY_INTERFACE_MODE_SGMII;
break; break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_RXAUI:
phydev->interface = PHY_INTERFACE_MODE_RXAUI;
break;
case MDIO_PHYXS_VEND_IF_STATUS_TYPE_OCSGMII: case MDIO_PHYXS_VEND_IF_STATUS_TYPE_OCSGMII:
phydev->interface = PHY_INTERFACE_MODE_2500BASEX; phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
break; break;
...@@ -522,11 +564,14 @@ static int aqr107_config_init(struct phy_device *phydev) ...@@ -522,11 +564,14 @@ static int aqr107_config_init(struct phy_device *phydev)
/* Check that the PHY interface type is compatible */ /* Check that the PHY interface type is compatible */
if (phydev->interface != PHY_INTERFACE_MODE_SGMII && if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
phydev->interface != PHY_INTERFACE_MODE_1000BASEKX &&
phydev->interface != PHY_INTERFACE_MODE_2500BASEX && phydev->interface != PHY_INTERFACE_MODE_2500BASEX &&
phydev->interface != PHY_INTERFACE_MODE_XGMII && phydev->interface != PHY_INTERFACE_MODE_XGMII &&
phydev->interface != PHY_INTERFACE_MODE_USXGMII && phydev->interface != PHY_INTERFACE_MODE_USXGMII &&
phydev->interface != PHY_INTERFACE_MODE_10GKR && phydev->interface != PHY_INTERFACE_MODE_10GKR &&
phydev->interface != PHY_INTERFACE_MODE_10GBASER) phydev->interface != PHY_INTERFACE_MODE_10GBASER &&
phydev->interface != PHY_INTERFACE_MODE_XAUI &&
phydev->interface != PHY_INTERFACE_MODE_RXAUI)
return -ENODEV; return -ENODEV;
WARN(phydev->interface == PHY_INTERFACE_MODE_XGMII, WARN(phydev->interface == PHY_INTERFACE_MODE_XGMII,
...@@ -630,6 +675,16 @@ static int aqr107_wait_processor_intensive_op(struct phy_device *phydev) ...@@ -630,6 +675,16 @@ static int aqr107_wait_processor_intensive_op(struct phy_device *phydev)
return 0; return 0;
} }
static int aqr107_get_rate_matching(struct phy_device *phydev,
phy_interface_t iface)
{
if (iface == PHY_INTERFACE_MODE_10GBASER ||
iface == PHY_INTERFACE_MODE_2500BASEX ||
iface == PHY_INTERFACE_MODE_NA)
return RATE_MATCH_PAUSE;
return RATE_MATCH_NONE;
}
static int aqr107_suspend(struct phy_device *phydev) static int aqr107_suspend(struct phy_device *phydev)
{ {
int err; int err;
...@@ -703,6 +758,7 @@ static struct phy_driver aqr_driver[] = { ...@@ -703,6 +758,7 @@ static struct phy_driver aqr_driver[] = {
PHY_ID_MATCH_MODEL(PHY_ID_AQR107), PHY_ID_MATCH_MODEL(PHY_ID_AQR107),
.name = "Aquantia AQR107", .name = "Aquantia AQR107",
.probe = aqr107_probe, .probe = aqr107_probe,
.get_rate_matching = aqr107_get_rate_matching,
.config_init = aqr107_config_init, .config_init = aqr107_config_init,
.config_aneg = aqr_config_aneg, .config_aneg = aqr_config_aneg,
.config_intr = aqr_config_intr, .config_intr = aqr_config_intr,
...@@ -721,6 +777,7 @@ static struct phy_driver aqr_driver[] = { ...@@ -721,6 +777,7 @@ static struct phy_driver aqr_driver[] = {
PHY_ID_MATCH_MODEL(PHY_ID_AQCS109), PHY_ID_MATCH_MODEL(PHY_ID_AQCS109),
.name = "Aquantia AQCS109", .name = "Aquantia AQCS109",
.probe = aqr107_probe, .probe = aqr107_probe,
.get_rate_matching = aqr107_get_rate_matching,
.config_init = aqcs109_config_init, .config_init = aqcs109_config_init,
.config_aneg = aqr_config_aneg, .config_aneg = aqr_config_aneg,
.config_intr = aqr_config_intr, .config_intr = aqr_config_intr,
...@@ -747,6 +804,7 @@ static struct phy_driver aqr_driver[] = { ...@@ -747,6 +804,7 @@ static struct phy_driver aqr_driver[] = {
PHY_ID_MATCH_MODEL(PHY_ID_AQR113C), PHY_ID_MATCH_MODEL(PHY_ID_AQR113C),
.name = "Aquantia AQR113C", .name = "Aquantia AQR113C",
.probe = aqr107_probe, .probe = aqr107_probe,
.get_rate_matching = aqr107_get_rate_matching,
.config_init = aqr107_config_init, .config_init = aqr107_config_init,
.config_aneg = aqr_config_aneg, .config_aneg = aqr_config_aneg,
.config_intr = aqr_config_intr, .config_intr = aqr_config_intr,
......
...@@ -74,6 +74,27 @@ const char *phy_duplex_to_str(unsigned int duplex) ...@@ -74,6 +74,27 @@ const char *phy_duplex_to_str(unsigned int duplex)
} }
EXPORT_SYMBOL_GPL(phy_duplex_to_str); EXPORT_SYMBOL_GPL(phy_duplex_to_str);
/**
* phy_rate_matching_to_str - Return a string describing the rate matching
*
* @rate_matching: Type of rate matching to describe
*/
const char *phy_rate_matching_to_str(int rate_matching)
{
switch (rate_matching) {
case RATE_MATCH_NONE:
return "none";
case RATE_MATCH_PAUSE:
return "pause";
case RATE_MATCH_CRS:
return "crs";
case RATE_MATCH_OPEN_LOOP:
return "open-loop";
}
return "Unsupported (update phy-core.c)";
}
EXPORT_SYMBOL_GPL(phy_rate_matching_to_str);
/** /**
* phy_interface_num_ports - Return the number of links that can be carried by * phy_interface_num_ports - Return the number of links that can be carried by
* a given MAC-PHY physical link. Returns 0 if this is * a given MAC-PHY physical link. Returns 0 if this is
......
...@@ -114,6 +114,33 @@ void phy_print_status(struct phy_device *phydev) ...@@ -114,6 +114,33 @@ void phy_print_status(struct phy_device *phydev)
} }
EXPORT_SYMBOL(phy_print_status); EXPORT_SYMBOL(phy_print_status);
/**
* phy_get_rate_matching - determine if rate matching is supported
* @phydev: The phy device to return rate matching for
* @iface: The interface mode to use
*
* This determines the type of rate matching (if any) that @phy supports
* using @iface. @iface may be %PHY_INTERFACE_MODE_NA to determine if any
* interface supports rate matching.
*
* Return: The type of rate matching @phy supports for @iface, or
* %RATE_MATCH_NONE.
*/
int phy_get_rate_matching(struct phy_device *phydev,
phy_interface_t iface)
{
int ret = RATE_MATCH_NONE;
if (phydev->drv->get_rate_matching) {
mutex_lock(&phydev->lock);
ret = phydev->drv->get_rate_matching(phydev, iface);
mutex_unlock(&phydev->lock);
}
return ret;
}
EXPORT_SYMBOL_GPL(phy_get_rate_matching);
/** /**
* phy_config_interrupt - configure the PHY device for the requested interrupts * phy_config_interrupt - configure the PHY device for the requested interrupts
* @phydev: the phy_device struct * @phydev: the phy_device struct
...@@ -256,6 +283,7 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev, ...@@ -256,6 +283,7 @@ void phy_ethtool_ksettings_get(struct phy_device *phydev,
cmd->base.duplex = phydev->duplex; cmd->base.duplex = phydev->duplex;
cmd->base.master_slave_cfg = phydev->master_slave_get; cmd->base.master_slave_cfg = phydev->master_slave_get;
cmd->base.master_slave_state = phydev->master_slave_state; cmd->base.master_slave_state = phydev->master_slave_state;
cmd->base.rate_matching = phydev->rate_matching;
if (phydev->interface == PHY_INTERFACE_MODE_MOCA) if (phydev->interface == PHY_INTERFACE_MODE_MOCA)
cmd->base.port = PORT_BNC; cmd->base.port = PORT_BNC;
else else
......
This diff is collapsed.
...@@ -280,7 +280,6 @@ static inline const char *phy_modes(phy_interface_t interface) ...@@ -280,7 +280,6 @@ static inline const char *phy_modes(phy_interface_t interface)
} }
} }
#define PHY_INIT_TIMEOUT 100000 #define PHY_INIT_TIMEOUT 100000
#define PHY_FORCE_TIMEOUT 10 #define PHY_FORCE_TIMEOUT 10
...@@ -574,6 +573,7 @@ struct macsec_ops; ...@@ -574,6 +573,7 @@ struct macsec_ops;
* @lp_advertising: Current link partner advertised linkmodes * @lp_advertising: Current link partner advertised linkmodes
* @eee_broken_modes: Energy efficient ethernet modes which should be prohibited * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
* @autoneg: Flag autoneg being used * @autoneg: Flag autoneg being used
* @rate_matching: Current rate matching mode
* @link: Current link state * @link: Current link state
* @autoneg_complete: Flag auto negotiation of the link has completed * @autoneg_complete: Flag auto negotiation of the link has completed
* @mdix: Current crossover * @mdix: Current crossover
...@@ -641,6 +641,8 @@ struct phy_device { ...@@ -641,6 +641,8 @@ struct phy_device {
unsigned irq_suspended:1; unsigned irq_suspended:1;
unsigned irq_rerun:1; unsigned irq_rerun:1;
int rate_matching;
enum phy_state state; enum phy_state state;
u32 dev_flags; u32 dev_flags;
...@@ -805,6 +807,21 @@ struct phy_driver { ...@@ -805,6 +807,21 @@ struct phy_driver {
*/ */
int (*get_features)(struct phy_device *phydev); int (*get_features)(struct phy_device *phydev);
/**
* @get_rate_matching: Get the supported type of rate matching for a
* particular phy interface. This is used by phy consumers to determine
* whether to advertise lower-speed modes for that interface. It is
* assumed that if a rate matching mode is supported on an interface,
* then that interface's rate can be adapted to all slower link speeds
* supported by the phy. If iface is %PHY_INTERFACE_MODE_NA, and the phy
* supports any kind of rate matching for any interface, then it must
* return that rate matching mode (preferring %RATE_MATCH_PAUSE to
* %RATE_MATCH_CRS). If the interface is not supported, this should
* return %RATE_MATCH_NONE.
*/
int (*get_rate_matching)(struct phy_device *phydev,
phy_interface_t iface);
/* PHY Power Management */ /* PHY Power Management */
/** @suspend: Suspend the hardware, saving state if needed */ /** @suspend: Suspend the hardware, saving state if needed */
int (*suspend)(struct phy_device *phydev); int (*suspend)(struct phy_device *phydev);
...@@ -971,6 +988,7 @@ struct phy_fixup { ...@@ -971,6 +988,7 @@ struct phy_fixup {
const char *phy_speed_to_str(int speed); const char *phy_speed_to_str(int speed);
const char *phy_duplex_to_str(unsigned int duplex); const char *phy_duplex_to_str(unsigned int duplex);
const char *phy_rate_matching_to_str(int rate_matching);
int phy_interface_num_ports(phy_interface_t interface); int phy_interface_num_ports(phy_interface_t interface);
...@@ -1687,6 +1705,8 @@ int phy_disable_interrupts(struct phy_device *phydev); ...@@ -1687,6 +1705,8 @@ int phy_disable_interrupts(struct phy_device *phydev);
void phy_request_interrupt(struct phy_device *phydev); void phy_request_interrupt(struct phy_device *phydev);
void phy_free_interrupt(struct phy_device *phydev); void phy_free_interrupt(struct phy_device *phydev);
void phy_print_status(struct phy_device *phydev); void phy_print_status(struct phy_device *phydev);
int phy_get_rate_matching(struct phy_device *phydev,
phy_interface_t iface);
void phy_set_max_speed(struct phy_device *phydev, u32 max_speed); void phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode); void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode);
void phy_advertise_supported(struct phy_device *phydev); void phy_advertise_supported(struct phy_device *phydev);
......
...@@ -21,6 +21,35 @@ enum { ...@@ -21,6 +21,35 @@ enum {
MLO_AN_FIXED, /* Fixed-link mode */ MLO_AN_FIXED, /* Fixed-link mode */
MLO_AN_INBAND, /* In-band protocol */ MLO_AN_INBAND, /* In-band protocol */
/* MAC_SYM_PAUSE and MAC_ASYM_PAUSE are used when configuring our
* autonegotiation advertisement. They correspond to the PAUSE and
* ASM_DIR bits defined by 802.3, respectively.
*
* The following table lists the values of tx_pause and rx_pause which
* might be requested in mac_link_up. The exact values depend on either
* the results of autonegotation (if MLO_PAUSE_AN is set) or user
* configuration (if MLO_PAUSE_AN is not set).
*
* MAC_SYM_PAUSE MAC_ASYM_PAUSE MLO_PAUSE_AN tx_pause/rx_pause
* ============= ============== ============ ==================
* 0 0 0 0/0
* 0 0 1 0/0
* 0 1 0 0/0, 0/1, 1/0, 1/1
* 0 1 1 0/0, 1/0
* 1 0 0 0/0, 1/1
* 1 0 1 0/0, 1/1
* 1 1 0 0/0, 0/1, 1/0, 1/1
* 1 1 1 0/0, 0/1, 1/1
*
* If you set MAC_ASYM_PAUSE, the user may request any combination of
* tx_pause and rx_pause. You do not have to support these
* combinations.
*
* However, you should support combinations of tx_pause and rx_pause
* which might be the result of autonegotation. For example, don't set
* MAC_SYM_PAUSE unless your device can support tx_pause and rx_pause
* at the same time.
*/
MAC_SYM_PAUSE = BIT(0), MAC_SYM_PAUSE = BIT(0),
MAC_ASYM_PAUSE = BIT(1), MAC_ASYM_PAUSE = BIT(1),
MAC_10HD = BIT(2), MAC_10HD = BIT(2),
...@@ -59,6 +88,10 @@ static inline bool phylink_autoneg_inband(unsigned int mode) ...@@ -59,6 +88,10 @@ static inline bool phylink_autoneg_inband(unsigned int mode)
* @speed: link speed, one of the SPEED_* constants. * @speed: link speed, one of the SPEED_* constants.
* @duplex: link duplex mode, one of DUPLEX_* constants. * @duplex: link duplex mode, one of DUPLEX_* constants.
* @pause: link pause state, described by MLO_PAUSE_* constants. * @pause: link pause state, described by MLO_PAUSE_* constants.
* @rate_matching: rate matching being performed, one of the RATE_MATCH_*
* constants. If rate matching is taking place, then the speed/duplex of
* the medium link mode (@speed and @duplex) and the speed/duplex of the phy
* interface mode (@interface) are different.
* @link: true if the link is up. * @link: true if the link is up.
* @an_enabled: true if autonegotiation is enabled/desired. * @an_enabled: true if autonegotiation is enabled/desired.
* @an_complete: true if autonegotiation has completed. * @an_complete: true if autonegotiation has completed.
...@@ -70,6 +103,7 @@ struct phylink_link_state { ...@@ -70,6 +103,7 @@ struct phylink_link_state {
int speed; int speed;
int duplex; int duplex;
int pause; int pause;
int rate_matching;
unsigned int link:1; unsigned int link:1;
unsigned int an_enabled:1; unsigned int an_enabled:1;
unsigned int an_complete:1; unsigned int an_complete:1;
...@@ -518,8 +552,10 @@ void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode, ...@@ -518,8 +552,10 @@ void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
phy_interface_t interface, int speed, int duplex); phy_interface_t interface, int speed, int duplex);
#endif #endif
void phylink_get_linkmodes(unsigned long *linkmodes, phy_interface_t interface, void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
unsigned long mac_capabilities); unsigned long phylink_get_capabilities(phy_interface_t interface,
unsigned long mac_capabilities,
int rate_matching);
void phylink_generic_validate(struct phylink_config *config, void phylink_generic_validate(struct phylink_config *config,
unsigned long *supported, unsigned long *supported,
struct phylink_link_state *state); struct phylink_link_state *state);
......
...@@ -1840,6 +1840,20 @@ static inline int ethtool_validate_duplex(__u8 duplex) ...@@ -1840,6 +1840,20 @@ static inline int ethtool_validate_duplex(__u8 duplex)
#define MASTER_SLAVE_STATE_SLAVE 3 #define MASTER_SLAVE_STATE_SLAVE 3
#define MASTER_SLAVE_STATE_ERR 4 #define MASTER_SLAVE_STATE_ERR 4
/* These are used to throttle the rate of data on the phy interface when the
* native speed of the interface is higher than the link speed. These should
* not be used for phy interfaces which natively support multiple speeds (e.g.
* MII or SGMII).
*/
/* No rate matching performed. */
#define RATE_MATCH_NONE 0
/* The phy sends pause frames to throttle the MAC. */
#define RATE_MATCH_PAUSE 1
/* The phy asserts CRS to prevent the MAC from transmitting. */
#define RATE_MATCH_CRS 2
/* The MAC is programmed with a sufficiently-large IPG. */
#define RATE_MATCH_OPEN_LOOP 3
/* Which connector port. */ /* Which connector port. */
#define PORT_TP 0x00 #define PORT_TP 0x00
#define PORT_AUI 0x01 #define PORT_AUI 0x01
...@@ -2033,8 +2047,8 @@ enum ethtool_reset_flags { ...@@ -2033,8 +2047,8 @@ enum ethtool_reset_flags {
* reported consistently by PHYLIB. Read-only. * reported consistently by PHYLIB. Read-only.
* @master_slave_cfg: Master/slave port mode. * @master_slave_cfg: Master/slave port mode.
* @master_slave_state: Master/slave port state. * @master_slave_state: Master/slave port state.
* @rate_matching: Rate adaptation performed by the PHY
* @reserved: Reserved for future use; see the note on reserved space. * @reserved: Reserved for future use; see the note on reserved space.
* @reserved1: Reserved for future use; see the note on reserved space.
* @link_mode_masks: Variable length bitmaps. * @link_mode_masks: Variable length bitmaps.
* *
* If autonegotiation is disabled, the speed and @duplex represent the * If autonegotiation is disabled, the speed and @duplex represent the
...@@ -2085,7 +2099,7 @@ struct ethtool_link_settings { ...@@ -2085,7 +2099,7 @@ struct ethtool_link_settings {
__u8 transceiver; __u8 transceiver;
__u8 master_slave_cfg; __u8 master_slave_cfg;
__u8 master_slave_state; __u8 master_slave_state;
__u8 reserved1[1]; __u8 rate_matching;
__u32 reserved[7]; __u32 reserved[7];
__u32 link_mode_masks[]; __u32 link_mode_masks[];
/* layout of link_mode_masks fields: /* layout of link_mode_masks fields:
......
...@@ -242,6 +242,7 @@ enum { ...@@ -242,6 +242,7 @@ enum {
ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG, /* u8 */ ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG, /* u8 */
ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE, /* u8 */ ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE, /* u8 */
ETHTOOL_A_LINKMODES_LANES, /* u32 */ ETHTOOL_A_LINKMODES_LANES, /* u32 */
ETHTOOL_A_LINKMODES_RATE_MATCHING, /* u8 */
/* add new constants above here */ /* add new constants above here */
__ETHTOOL_A_LINKMODES_CNT, __ETHTOOL_A_LINKMODES_CNT,
......
...@@ -571,6 +571,7 @@ static int ethtool_get_link_ksettings(struct net_device *dev, ...@@ -571,6 +571,7 @@ static int ethtool_get_link_ksettings(struct net_device *dev,
= __ETHTOOL_LINK_MODE_MASK_NU32; = __ETHTOOL_LINK_MODE_MASK_NU32;
link_ksettings.base.master_slave_cfg = MASTER_SLAVE_CFG_UNSUPPORTED; link_ksettings.base.master_slave_cfg = MASTER_SLAVE_CFG_UNSUPPORTED;
link_ksettings.base.master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; link_ksettings.base.master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED;
link_ksettings.base.rate_matching = RATE_MATCH_NONE;
return store_link_ksettings_for_user(useraddr, &link_ksettings); return store_link_ksettings_for_user(useraddr, &link_ksettings);
} }
......
...@@ -70,6 +70,7 @@ static int linkmodes_reply_size(const struct ethnl_req_info *req_base, ...@@ -70,6 +70,7 @@ static int linkmodes_reply_size(const struct ethnl_req_info *req_base,
+ nla_total_size(sizeof(u32)) /* LINKMODES_SPEED */ + nla_total_size(sizeof(u32)) /* LINKMODES_SPEED */
+ nla_total_size(sizeof(u32)) /* LINKMODES_LANES */ + nla_total_size(sizeof(u32)) /* LINKMODES_LANES */
+ nla_total_size(sizeof(u8)) /* LINKMODES_DUPLEX */ + nla_total_size(sizeof(u8)) /* LINKMODES_DUPLEX */
+ nla_total_size(sizeof(u8)) /* LINKMODES_RATE_MATCHING */
+ 0; + 0;
ret = ethnl_bitset_size(ksettings->link_modes.advertising, ret = ethnl_bitset_size(ksettings->link_modes.advertising,
ksettings->link_modes.supported, ksettings->link_modes.supported,
...@@ -143,6 +144,10 @@ static int linkmodes_fill_reply(struct sk_buff *skb, ...@@ -143,6 +144,10 @@ static int linkmodes_fill_reply(struct sk_buff *skb,
lsettings->master_slave_state)) lsettings->master_slave_state))
return -EMSGSIZE; return -EMSGSIZE;
if (nla_put_u8(skb, ETHTOOL_A_LINKMODES_RATE_MATCHING,
lsettings->rate_matching))
return -EMSGSIZE;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment