ethtool: support FEC configuration over netlink
Subsystems (7)
Jakub Kicinski
maintainercover ethtool: support FEC configuration over netlink
This series adds support for the equivalents of ETHTOOL_GFECPARAM and ETHTOOL_SFECPARAM over netlink.
As a reminder - this is an API which allows user to query current FEC mode, as well as set FEC manually if autoneg is disabled. It does not configure anything if autoneg is enabled (that said few/no drivers currently reject .set_fecparam calls while autoneg is disabled, hopefully FW will just ignore the settings).
The existing functionality is mostly preserved in the new API. The ioctl interface uses a set of flags, and link modes to tell user which modes are supported. Here is how the flags translate to the new interface (skipping descriptions for actual FEC modes):
ioctl flag | description | new API
================================================================
ETHTOOL_FEC_OFF | disabled (supported) | \ ETHTOOL_FEC_RS | | ` link mode bitset ETHTOOL_FEC_BASER | | / .._A_FEC_MODES ETHTOOL_FEC_LLRS | | / ETHTOOL_FEC_AUTO | pick based on cable | bool .._A_FEC_AUTO ETHTOOL_FEC_NONE | not supported | no bit, no AUTO reported
Since link modes are already depended on (although somewhat implicitly) for expressing supported modes - the new interface uses them for the manual configuration, as well as uses link mode bit number to communicate the active mode.
Use of link modes allows us to define any number of FEC modes we want, and reuse the strset we already have defined.
Separating AUTO as its own attribute is the biggest changed compared to the ioctl. It means drivers can no longer report AUTO as the active FEC mode because there is no link mode for AUTO. active_fec == AUTO makes little sense in the first place IMHO, active_fec should be the actual mode, so hopefully this is fine.
The other minor departure is that None is no longer explicitly expressed in the API. But drivers are reasonable in handling of this somewhat pointless bit, so I'm not expecting any issues there.
One extension which could be considered would be moving active FEC to ETHTOOL_MSG_LINKMODE_*, but then why not move all of FEC into link modes? I don't know where to draw the line.
netdevsim support and a simple self test are included.
Next step is adding stats similar to the ones added for pause.
Jakub Kicinski (3):
ethtool: support FEC settings over netlink
netdevsim: add FEC settings support
selftests: ethtool: add a netdevsim FEC test
Documentation/networking/ethtool-netlink.rst | 62 ++++- drivers/net/netdevsim/ethtool.c | 36 +++ drivers/net/netdevsim/netdevsim.h | 3 + include/uapi/linux/ethtool_netlink.h | 17 ++ net/ethtool/Makefile | 2 +- net/ethtool/fec.c | 238 ++++++++++++++++++ net/ethtool/netlink.c | 19 ++ net/ethtool/netlink.h | 4 + .../drivers/net/netdevsim/ethtool-common.sh | 5 +- .../drivers/net/netdevsim/ethtool-fec.sh | 110 ++++++++ 10 files changed, 492 insertions(+), 4 deletions(-) create mode 100644 net/ethtool/fec.c create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-fec.sh
Signature · 1 line
2.30.2
Jakub Kicinski
maintainerPATCH 1/3 ethtool: support FEC settings over netlink
Add FEC API to netlink.
This is not a 1-to-1 conversion.
FEC settings already depend on link modes to tell user which modes are supported. Take this further an use link modes for manual configuration. Old struct ethtool_fecparam is still used to talk to the drivers, so we need to translate back and forth. We can revisit the internal API if number of FEC encodings starts to grow.
Enforce only one active FEC bit (by using a bit position rather than another mask).
--- Documentation/networking/ethtool-netlink.rst | 62 ++++- include/uapi/linux/ethtool_netlink.h | 17 ++ net/ethtool/Makefile | 2 +- net/ethtool/fec.c | 238 +++++++++++++++++++ net/ethtool/netlink.c | 19 ++ net/ethtool/netlink.h | 4 + 6 files changed, 339 insertions(+), 3 deletions(-) create mode 100644 net/ethtool/fec.c
Documentation/networking/ethtool-netlink.rst +60 -2
@@ -208,6 +208,8 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test ``ETHTOOL_MSG_CABLE_TEST_TDR_ACT`` action start raw TDR cable test ``ETHTOOL_MSG_TUNNEL_INFO_GET`` get tunnel offload info + ``ETHTOOL_MSG_FEC_GET`` get FEC settings + ``ETHTOOL_MSG_FEC_SET`` set FEC settings ===================================== ================================ Kernel to userspace:
@@ -242,6 +244,8 @@ All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix ``ETHTOOL_MSG_CABLE_TEST_NTF`` Cable test results ``ETHTOOL_MSG_CABLE_TEST_TDR_NTF`` Cable test TDR results ``ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY`` tunnel offload info + ``ETHTOOL_MSG_FEC_GET_REPLY`` FEC settings + ``ETHTOOL_MSG_FEC_NTF`` FEC settings ===================================== ================================= ``GET`` requests are sent by userspace applications to retrieve device
@@ -1280,6 +1284,60 @@ Gets information about the tunnel state NIC is aware of. For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that the table contains static entries, hard-coded by the NIC. +FEC_GET +======= + +Gets FEC configuration and state like ``ETHTOOL_GFECPARAM`` ioctl request. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_FEC_HEADER`` nested request header + ===================================== ====== ========================== + +Kernel response contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_FEC_HEADER`` nested request header + ``ETHTOOL_A_FEC_MODES`` bitset configured modes + ``ETHTOOL_A_FEC_AUTO`` bool FEC mode auto selection + ``ETHTOOL_A_FEC_ACTIVE`` u32 index of active FEC mode + ===================================== ====== ========================== + +``ETHTOOL_A_FEC_ACTIVE`` is the bit index of the FEC link mode currently +active on the interface. This attribute may not be present if device does +not support FEC. + +``ETHTOOL_A_FEC_MODES`` and ``ETHTOOL_A_FEC_AUTO`` are only meaningful when +autonegotiation is disabled. If ``ETHTOOL_A_FEC_AUTO`` is non-zero driver will +select the FEC mode automatically based on the parameters of the SFP module. +This is equivalent to the ``ETHTOOL_FEC_AUTO`` bit of the ioctl interface. +``ETHTOOL_A_FEC_MODES`` carry the current FEC configuration using link mode +bits (rather than old ``ETHTOOL_FEC_*`` bits). + +FEC_SET +======= + +Sets FEC parameters like ``ETHTOOL_SFECPARAM`` ioctl request. + +Request contents: + + ===================================== ====== ========================== + ``ETHTOOL_A_FEC_HEADER`` nested request header + ``ETHTOOL_A_FEC_MODES`` bitset configured modes + ``ETHTOOL_A_FEC_AUTO`` bool FEC mode auto selection + ===================================== ====== ========================== + +``FEC_SET`` is only meaningful when autonegotiation is disabled. Otherwise +FEC mode is selected as part of autonegotiation. + +``ETHTOOL_A_FEC_MODES`` selects which FEC mode should be used. It's recommended +to set only one bit, if multiple bits are set driver may choose between them +in an implementation specific way. + +``ETHTOOL_A_FEC_AUTO`` requests the driver to choose FEC mode based on SFP +module parameters. This does not mean autonegotiation. + Request translation ===================
@@ -1373,8 +1431,8 @@ are netlink only. ``ETHTOOL_MSG_LINKMODES_SET`` ``ETHTOOL_PHY_GTUNABLE`` n/a ``ETHTOOL_PHY_STUNABLE`` n/a - ``ETHTOOL_GFECPARAM`` n/a - ``ETHTOOL_SFECPARAM`` n/a + ``ETHTOOL_GFECPARAM`` ``ETHTOOL_MSG_FEC_GET`` + ``ETHTOOL_SFECPARAM`` ``ETHTOOL_MSG_FEC_SET`` n/a ''ETHTOOL_MSG_CABLE_TEST_ACT'' n/a ''ETHTOOL_MSG_CABLE_TEST_TDR_ACT'' n/a ``ETHTOOL_MSG_TUNNEL_INFO_GET``
include/uapi/linux/ethtool_netlink.h +17 -0
@@ -42,6 +42,8 @@ enum {ETHTOOL_MSG_CABLE_TEST_ACT ,ETHTOOL_MSG_CABLE_TEST_TDR_ACT ,ETHTOOL_MSG_TUNNEL_INFO_GET , +ETHTOOL_MSG_FEC_GET , +ETHTOOL_MSG_FEC_SET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -80,6 +82,8 @@ enum {ETHTOOL_MSG_CABLE_TEST_NTF ,ETHTOOL_MSG_CABLE_TEST_TDR_NTF ,ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY , +ETHTOOL_MSG_FEC_GET_REPLY , +ETHTOOL_MSG_FEC_NTF ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
@@ -629,6 +633,19 @@ enum { ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* FEC */ + +enum { +ETHTOOL_A_FEC_UNSPEC , +ETHTOOL_A_FEC_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_FEC_MODES ,/* bitset */ +ETHTOOL_A_FEC_AUTO ,/* u8 */ +ETHTOOL_A_FEC_ACTIVE ,/* u32 */ + + __ETHTOOL_A_FEC_CNT, +ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_CNT -1 ) +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
@@ -7,4 +7,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ linkstate.o debug.o wol.o features.o privflags.o rings.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ - tunnels.o + tunnels.o fec.o
net/ethtool/fec.c new file +238 -0
238 lines not on this page · raw message
net/ethtool/netlink.c +19 -0
@@ -244,6 +244,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops, [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, + [ETHTOOL_MSG_FEC_GET] = ðnl_fec_request_ops, [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, };
@@ -551,6 +552,7 @@ ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { [ETHTOOL_MSG_COALESCE_NTF] = ðnl_coalesce_request_ops, [ETHTOOL_MSG_PAUSE_NTF] = ðnl_pause_request_ops, [ETHTOOL_MSG_EEE_NTF] = ðnl_eee_request_ops, + [ETHTOOL_MSG_FEC_NTF] = ðnl_fec_request_ops, };/* default notification handler */
@@ -643,6 +645,7 @@ static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify, [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify, [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify, + [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify, };void ethtool_notify (struct net_device *dev,unsigned int cmd,const void *data)
@@ -912,6 +915,22 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_tunnel_info_get_policy, .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_FEC_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + .policy = ethnl_fec_get_policy, + .maxattr = ARRAY_SIZE(ethnl_fec_get_policy) - 1, + }, + { + .cmd = ETHTOOL_MSG_FEC_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_set_fec, + .policy = ethnl_fec_set_policy, + .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +4 -0
@@ -344,6 +344,7 @@ extern const struct ethnl_request_ops ethnl_coalesce_request_ops;extern const struct ethnl_request_ops ethnl_pause_request_ops;extern const struct ethnl_request_ops ethnl_eee_request_ops;extern const struct ethnl_request_ops ethnl_tsinfo_request_ops; +extern const struct ethnl_request_ops ethnl_fec_request_ops;extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS +1 ];extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS +1 ];
@@ -375,6 +376,8 @@ extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER +extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER +1 ];extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG +1 ];extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER +1 ]; +extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER +1 ]; +extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO +1 ];int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info);int ethnl_set_linkmodes (struct sk_buff *skb,struct genl_info *info);
@@ -392,5 +395,6 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info);int ethnl_tunnel_info_doit (struct sk_buff *skb,struct genl_info *info);int ethnl_tunnel_info_start (struct netlink_callback *cb);int ethnl_tunnel_info_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int ethnl_set_fec (struct sk_buff *skb,struct genl_info *info);#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.30.2
Jakub Kicinski
maintainerPATCH 3/3 selftests: ethtool: add a netdevsim FEC test
In reply to Jakub KicinskiTest FEC settings, iterate over configs.
--- .../drivers/net/netdevsim/ethtool-common.sh | 5 +- .../drivers/net/netdevsim/ethtool-fec.sh | 110 ++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/ethtool-fec.sh
tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh +4 -1
@@ -24,8 +24,11 @@ function check { local code=$1 local str=$2 local exp_str=$3 + local exp_fail=$4 - if [ $code -ne 0 ]; then + [ -z "$exp_fail" ] && cop="-ne" || cop="-eq" + + if [ $code $cop 0 ]; then ((num_errors++)) return fi
tools/testing/selftests/drivers/net/netdevsim/ethtool-fec.sh new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
2.30.2
Jakub Kicinski
maintainerPATCH 2/3 netdevsim: add FEC settings support
In reply to Jakub KicinskiAdd support for ethtool FEC and some ethtool error injection.
--- drivers/net/netdevsim/ethtool.c | 36 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 3 +++ 2 files changed, 39 insertions(+)
drivers/net/netdevsim/ethtool.c +36 -0
@@ -77,6 +77,34 @@ static int nsim_set_ringparam(struct net_device *dev,return 0 ; } +static int +nsim_get_fecparam (struct net_device *dev,struct ethtool_fecparam *fecparam) +{ +struct netdevsim *ns =netdev_priv (dev); + +if (ns->ethtool.get_err) +return -ns->ethtool.get_err; +memcpy (fecparam, &ns->ethtool.fec,sizeof (ns->ethtool.fec)); +return 0 ; +} + +static int +nsim_set_fecparam (struct net_device *dev,struct ethtool_fecparam *fecparam) +{ +struct netdevsim *ns =netdev_priv (dev); +u32 fec; + +if (ns->ethtool.set_err) +return -ns->ethtool.set_err; +memcpy (&ns->ethtool.fec, fecparam,sizeof (ns->ethtool.fec)); + fec = fecparam->fec; +if (fec ==ETHTOOL_FEC_AUTO ) + fec |=ETHTOOL_FEC_OFF ; + fec |=ETHTOOL_FEC_NONE ; + ns->ethtool.fec.active_fec =1 << (fls (fec) -1 ); +return 0 ; +} +static const struct ethtool_ops nsim_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_ALL_PARAMS , .get_pause_stats = nsim_get_pause_stats,
@@ -86,6 +114,8 @@ static const struct ethtool_ops nsim_ethtool_ops = { .get_coalesce = nsim_get_coalesce, .get_ringparam = nsim_get_ringparam, .set_ringparam = nsim_set_ringparam, + .get_fecparam = nsim_get_fecparam, + .set_fecparam = nsim_set_fecparam, };static void nsim_ethtool_ring_init (struct netdevsim *ns)
@@ -104,8 +134,14 @@ void nsim_ethtool_init(struct netdevsim *ns)nsim_ethtool_ring_init (ns); + ns->ethtool.fec.fec =ETHTOOL_FEC_NONE ; + ns->ethtool.fec.active_fec =ETHTOOL_FEC_NONE ; + ethtool =debugfs_create_dir ("ethtool" , ns->nsim_dev_port->ddir); +debugfs_create_u32 ("get_err" ,0600 , ethtool, &ns->ethtool.get_err); +debugfs_create_u32 ("set_err" ,0600 , ethtool, &ns->ethtool.set_err); + dir =debugfs_create_dir ("pause" , ethtool);debugfs_create_bool ("report_stats_rx" ,0600 , dir, &ns->ethtool.pauseparam.report_stats_rx);
drivers/net/netdevsim/netdevsim.h +3 -0
@@ -60,9 +60,12 @@ struct nsim_ethtool_pauseparam { };struct nsim_ethtool { +u32 get_err; +u32 set_err;struct nsim_ethtool_pauseparam pauseparam;struct ethtool_coalesce coalesce;struct ethtool_ringparam ring; +struct ethtool_fecparam fec; };struct netdevsim {
Signature · 1 line
2.30.2
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Mon, 29 Mar 2021 20:59:51 -0700 you wrote:
This series adds support for the equivalents of
ETHTOOL_GFECPARAMandETHTOOL_SFECPARAMover netlink.As a reminder - this is an API which allows user to query current FEC mode, as well as set FEC manually if autoneg is disabled. It does not configure anything if autoneg is enabled (that said few/no drivers currently reject .set_fecparam calls while autoneg is disabled, hopefully FW will just ignore the settings).
[...]
Here is the summary with links:
- [net-next,1/3] ethtool: support FEC settings over netlink
https://git.kernel.org/netdev/net-next/c/1e5d1f69d9fb - [net-next,2/3] netdevsim: add FEC settings support https://git.kernel.org/netdev/net-next/c/0d7f76dc11e6 - [net-next,3/3] selftests: ethtool: add a netdevsim FEC test https://git.kernel.org/netdev/net-next/c/1da07e5db356
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html