ethtool: Extend link modes settings uAPI with lanes
Currently, when auto negotiation is on, the user can advertise all the linkmodes which correspond to a specific speed, but does not have a similar selector for the number of lanes. This is significant when a specific speed can be achieved using different number of lanes. For example, 2x50 or 4x25. Add 'ETHTOOL_A_LINKMODES_LANES' attribute and expand 'struct ethtool_link_settings' with lanes field in order to implement a new lanes-selector that will enable the user to advertise a specific number of lanes as well. When auto negotiation is off, lanes parameter can be forced only if the driver supports it. Add a capability bit in 'struct ethtool_ops' that allows ethtool know if the driver can handle the lanes parameter when auto negotiation is off, so if it does not, an error message will be returned when trying to set lanes. Example: $ ethtool -s swp1 lanes 4 $ ethtool swp1 Settings for swp1: Supported ports: [ FIBRE ] Supported link modes: 1000baseKX/Full 10000baseKR/Full 40000baseCR4/Full 40000baseSR4/Full 40000baseLR4/Full 25000baseCR/Full 25000baseSR/Full 50000baseCR2/Full 100000baseSR4/Full 100000baseCR4/Full Supported pause frame use: Symmetric Receive-only Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 40000baseCR4/Full 40000baseSR4/Full 40000baseLR4/Full 100000baseSR4/Full 100000baseCR4/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: Unknown! Duplex: Unknown! (255) Auto-negotiation: on Port: Direct Attach Copper PHYAD: 0 Transceiver: internal Link detected: no Signed-off-by: Danielle Ratson <danieller@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: hongrongxuan <hongrongxuan@huawei.com> Conflicts: net/ethtool/linkmodes.c net/ethtool/netlink.h
This commit is contained in:
parent
6ad15a601f
commit
6abf13bd7f
|
@ -425,16 +425,17 @@ Request contents:
|
|||
``ETHTOOL_A_LINKMODES_SPEED`` u32 link speed (Mb/s)
|
||||
``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode
|
||||
``ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG`` u8 Master/slave port mode
|
||||
``ETHTOOL_A_LINKMODES_LANES`` u32 lanes
|
||||
========================================== ====== ==========================
|
||||
|
||||
``ETHTOOL_A_LINKMODES_OURS`` bit set allows setting advertised link modes. If
|
||||
autonegotiation is on (either set now or kept from before), advertised modes
|
||||
are not changed (no ``ETHTOOL_A_LINKMODES_OURS`` attribute) and at least one
|
||||
of speed and duplex is specified, kernel adjusts advertised modes to all
|
||||
supported modes matching speed, duplex or both (whatever is specified). This
|
||||
autoselection is done on ethtool side with ioctl interface, netlink interface
|
||||
is supposed to allow requesting changes without knowing what exactly kernel
|
||||
supports.
|
||||
of speed, duplex and lanes is specified, kernel adjusts advertised modes to all
|
||||
supported modes matching speed, duplex, lanes or all (whatever is specified).
|
||||
This autoselection is done on ethtool side with ioctl interface, netlink
|
||||
interface is supposed to allow requesting changes without knowing what exactly
|
||||
kernel supports.
|
||||
|
||||
|
||||
LINKSTATE_GET
|
||||
|
|
|
@ -156,6 +156,7 @@ struct ethtool_link_ksettings {
|
|||
__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
|
||||
__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
|
||||
} link_modes;
|
||||
u32 lanes;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -289,6 +290,8 @@ struct ethtool_pause_stats {
|
|||
|
||||
/**
|
||||
* struct ethtool_ops - optional netdev operations
|
||||
* @cap_link_lanes_supported: indicates if the driver supports lanes
|
||||
* parameter.
|
||||
* @supported_coalesce_params: supported types of interrupt coalescing.
|
||||
* @supported_ring_params: supported ring params.
|
||||
* @get_drvinfo: Report driver/device information. Should only set the
|
||||
|
@ -445,6 +448,7 @@ struct ethtool_pause_stats {
|
|||
* of the generic netdev features interface.
|
||||
*/
|
||||
struct ethtool_ops {
|
||||
u32 cap_link_lanes_supported:1;
|
||||
u32 supported_coalesce_params;
|
||||
u32 supported_ring_params;
|
||||
void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
|
||||
|
|
|
@ -221,6 +221,7 @@ enum {
|
|||
ETHTOOL_A_LINKMODES_DUPLEX, /* u8 */
|
||||
ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG, /* u8 */
|
||||
ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE, /* u8 */
|
||||
ETHTOOL_A_LINKMODES_LANES, /* u32 */
|
||||
|
||||
/* add new constants above here */
|
||||
__ETHTOOL_A_LINKMODES_CNT,
|
||||
|
|
|
@ -162,12 +162,47 @@ const struct ethnl_request_ops ethnl_linkmodes_request_ops = {
|
|||
|
||||
struct link_mode_info {
|
||||
int speed;
|
||||
u8 lanes;
|
||||
u8 duplex;
|
||||
};
|
||||
|
||||
#define __LINK_MODE_LANES_CR 1
|
||||
#define __LINK_MODE_LANES_CR2 2
|
||||
#define __LINK_MODE_LANES_CR4 4
|
||||
#define __LINK_MODE_LANES_CR8 8
|
||||
#define __LINK_MODE_LANES_DR 1
|
||||
#define __LINK_MODE_LANES_DR2 2
|
||||
#define __LINK_MODE_LANES_DR4 4
|
||||
#define __LINK_MODE_LANES_DR8 8
|
||||
#define __LINK_MODE_LANES_KR 1
|
||||
#define __LINK_MODE_LANES_KR2 2
|
||||
#define __LINK_MODE_LANES_KR4 4
|
||||
#define __LINK_MODE_LANES_KR8 8
|
||||
#define __LINK_MODE_LANES_SR 1
|
||||
#define __LINK_MODE_LANES_SR2 2
|
||||
#define __LINK_MODE_LANES_SR4 4
|
||||
#define __LINK_MODE_LANES_SR8 8
|
||||
#define __LINK_MODE_LANES_ER 1
|
||||
#define __LINK_MODE_LANES_KX 1
|
||||
#define __LINK_MODE_LANES_KX4 4
|
||||
#define __LINK_MODE_LANES_LR 1
|
||||
#define __LINK_MODE_LANES_LR4 4
|
||||
#define __LINK_MODE_LANES_LR4_ER4 4
|
||||
#define __LINK_MODE_LANES_LR_ER_FR 1
|
||||
#define __LINK_MODE_LANES_LR2_ER2_FR2 2
|
||||
#define __LINK_MODE_LANES_LR4_ER4_FR4 4
|
||||
#define __LINK_MODE_LANES_LR8_ER8_FR8 8
|
||||
#define __LINK_MODE_LANES_LRM 1
|
||||
#define __LINK_MODE_LANES_MLD2 2
|
||||
#define __LINK_MODE_LANES_T 1
|
||||
#define __LINK_MODE_LANES_T1 1
|
||||
#define __LINK_MODE_LANES_X 1
|
||||
#define __LINK_MODE_LANES_FX 1
|
||||
|
||||
#define __DEFINE_LINK_MODE_PARAMS(_speed, _type, _duplex) \
|
||||
[ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \
|
||||
.speed = SPEED_ ## _speed, \
|
||||
.lanes = __LINK_MODE_LANES_ ## _type, \
|
||||
.duplex = __DUPLEX_ ## _duplex \
|
||||
}
|
||||
#define __DUPLEX_Half DUPLEX_HALF
|
||||
|
@ -175,6 +210,7 @@ struct link_mode_info {
|
|||
#define __DEFINE_SPECIAL_MODE_PARAMS(_mode) \
|
||||
[ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = { \
|
||||
.speed = SPEED_UNKNOWN, \
|
||||
.lanes = 0, \
|
||||
.duplex = DUPLEX_UNKNOWN, \
|
||||
}
|
||||
|
||||
|
@ -287,16 +323,17 @@ linkmodes_set_policy[ETHTOOL_A_LINKMODES_MAX + 1] = {
|
|||
[ETHTOOL_A_LINKMODES_DUPLEX] = { .type = NLA_U8 },
|
||||
[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG] = { .type = NLA_U8 },
|
||||
[ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE] = { .type = NLA_REJECT },
|
||||
[ETHTOOL_A_LINKMODES_LANES] = NLA_POLICY_RANGE(NLA_U32, 1, 8),
|
||||
};
|
||||
|
||||
/* Set advertised link modes to all supported modes matching requested speed
|
||||
* and duplex values. Called when autonegotiation is on, speed or duplex is
|
||||
* requested but no link mode change. This is done in userspace with ioctl()
|
||||
* interface, move it into kernel for netlink.
|
||||
/* Set advertised link modes to all supported modes matching requested speed,
|
||||
* lanes and duplex values. Called when autonegotiation is on, speed, lanes or
|
||||
* duplex is requested but no link mode change. This is done in userspace with
|
||||
* ioctl() interface, move it into kernel for netlink.
|
||||
* Returns true if advertised modes bitmap was modified.
|
||||
*/
|
||||
static bool ethnl_auto_linkmodes(struct ethtool_link_ksettings *ksettings,
|
||||
bool req_speed, bool req_duplex)
|
||||
bool req_speed, bool req_lanes, bool req_duplex)
|
||||
{
|
||||
unsigned long *advertising = ksettings->link_modes.advertising;
|
||||
unsigned long *supported = ksettings->link_modes.supported;
|
||||
|
@ -315,6 +352,7 @@ static bool ethnl_auto_linkmodes(struct ethtool_link_ksettings *ksettings,
|
|||
continue;
|
||||
if (test_bit(i, supported) &&
|
||||
(!req_speed || info->speed == ksettings->base.speed) &&
|
||||
(!req_lanes || info->lanes == ksettings->lanes) &&
|
||||
(!req_duplex || info->duplex == ksettings->base.duplex))
|
||||
set_bit(i, advertising);
|
||||
else
|
||||
|
@ -340,7 +378,7 @@ static bool ethnl_validate_master_slave_cfg(u8 cfg)
|
|||
|
||||
static int ethnl_check_linkmodes(struct genl_info *info, struct nlattr **tb)
|
||||
{
|
||||
const struct nlattr *master_slave_cfg;
|
||||
const struct nlattr *master_slave_cfg, *lanes_cfg;
|
||||
|
||||
master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
|
||||
if (master_slave_cfg &&
|
||||
|
@ -350,16 +388,23 @@ static int ethnl_check_linkmodes(struct genl_info *info, struct nlattr **tb)
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
lanes_cfg = tb[ETHTOOL_A_LINKMODES_LANES];
|
||||
if (lanes_cfg && !is_power_of_2(nla_get_u32(lanes_cfg))) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, lanes_cfg,
|
||||
"lanes value is invalid");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
|
||||
struct ethtool_link_ksettings *ksettings,
|
||||
bool *mod)
|
||||
bool *mod, const struct net_device *dev)
|
||||
{
|
||||
struct ethtool_link_settings *lsettings = &ksettings->base;
|
||||
bool req_speed, req_duplex;
|
||||
const struct nlattr *master_slave_cfg;
|
||||
bool req_speed, req_lanes, req_duplex;
|
||||
const struct nlattr *master_slave_cfg, *lanes_cfg;
|
||||
int ret;
|
||||
|
||||
master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
|
||||
|
@ -373,10 +418,30 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
|
|||
|
||||
*mod = false;
|
||||
req_speed = tb[ETHTOOL_A_LINKMODES_SPEED];
|
||||
req_lanes = tb[ETHTOOL_A_LINKMODES_LANES];
|
||||
req_duplex = tb[ETHTOOL_A_LINKMODES_DUPLEX];
|
||||
|
||||
ethnl_update_u8(&lsettings->autoneg, tb[ETHTOOL_A_LINKMODES_AUTONEG],
|
||||
mod);
|
||||
|
||||
lanes_cfg = tb[ETHTOOL_A_LINKMODES_LANES];
|
||||
if (lanes_cfg) {
|
||||
/* If autoneg is off and lanes parameter is not supported by the
|
||||
* driver, return an error.
|
||||
*/
|
||||
if (!lsettings->autoneg &&
|
||||
!dev->ethtool_ops->cap_link_lanes_supported) {
|
||||
NL_SET_ERR_MSG_ATTR(info->extack, lanes_cfg,
|
||||
"lanes configuration not supported by device");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
} else if (!lsettings->autoneg) {
|
||||
/* If autoneg is off and lanes parameter is not passed from user,
|
||||
* set the lanes parameter to 0.
|
||||
*/
|
||||
ksettings->lanes = 0;
|
||||
}
|
||||
|
||||
ret = ethnl_update_bitset(ksettings->link_modes.advertising,
|
||||
__ETHTOOL_LINK_MODE_MASK_NBITS,
|
||||
tb[ETHTOOL_A_LINKMODES_OURS], link_mode_names,
|
||||
|
@ -385,13 +450,14 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
|
|||
return ret;
|
||||
ethnl_update_u32(&lsettings->speed, tb[ETHTOOL_A_LINKMODES_SPEED],
|
||||
mod);
|
||||
ethnl_update_u32(&ksettings->lanes, lanes_cfg, mod);
|
||||
ethnl_update_u8(&lsettings->duplex, tb[ETHTOOL_A_LINKMODES_DUPLEX],
|
||||
mod);
|
||||
ethnl_update_u8(&lsettings->master_slave_cfg, master_slave_cfg, mod);
|
||||
|
||||
if (!tb[ETHTOOL_A_LINKMODES_OURS] && lsettings->autoneg &&
|
||||
(req_speed || req_duplex) &&
|
||||
ethnl_auto_linkmodes(ksettings, req_speed, req_duplex))
|
||||
(req_speed || req_lanes || req_duplex) &&
|
||||
ethnl_auto_linkmodes(ksettings, req_speed, req_lanes, req_duplex))
|
||||
*mod = true;
|
||||
|
||||
return 0;
|
||||
|
@ -439,7 +505,7 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)
|
|||
goto out_ops;
|
||||
}
|
||||
|
||||
ret = ethnl_update_linkmodes(info, tb, &ksettings, &mod);
|
||||
ret = ethnl_update_linkmodes(info, tb, &ksettings, &mod, dev);
|
||||
if (ret < 0)
|
||||
goto out_ops;
|
||||
|
||||
|
|
Loading…
Reference in New Issue