net/mlx5: fix min and max MTU reporting
PATCH 1/1 net/mlx5: fix min and max MTU reporting
mlx5 PMD used hardcoded and incorrect values when reporting maximum MTU and maximum Rx packet length through rte_eth_dev_info_get().
This patch adds support for querying OS for minimum and maximum allowed MTU values. Maximum Rx packet length is then calculated based on these values.
On Linux, these values are queried through netlink, using IFLA_MIN_MTU and IFLA_MAX_MTU attributes added in Linux 4.18.
Windows API unfortunately does not expose minimum and maximum allowed MTU values. In this case, fallback hardcoded values (working on currently supported HW) will be used.
Bugzilla ID: 1719
--- drivers/common/mlx5/linux/mlx5_nl.c | 109 ++++++++++++++++++++++ drivers/common/mlx5/linux/mlx5_nl.h | 3 + drivers/net/mlx5/linux/mlx5_ethdev_os.c | 30 ++++++ drivers/net/mlx5/linux/mlx5_os.c | 2 + drivers/net/mlx5/mlx5.h | 13 +++ drivers/net/mlx5/mlx5_ethdev.c | 42 ++++++++- drivers/net/mlx5/windows/mlx5_ethdev_os.c | 28 ++++++ drivers/net/mlx5/windows/mlx5_os.c | 2 + 8 files changed, 228 insertions(+), 1 deletion(-)
drivers/common/mlx5/linux/mlx5_nl.c +109 -0
@@ -2247,3 +2247,112 @@ mlx5_nl_rdma_monitor_cap_get(int nl, uint8_t *cap) }return 0 ; } + +struct mlx5_mtu { +uint32_t min_mtu; +bool min_mtu_set; +uint32_t max_mtu; +bool max_mtu_set; +}; + +static int +mlx5_nl_get_mtu_bounds_cb (struct nlmsghdr *nh,void *arg) +{ +size_t off =NLMSG_LENGTH (sizeof (struct ifinfomsg )); +struct mlx5_mtu *out = arg; + +while (off < nh->nlmsg_len) { +struct rtattr *ra =RTE_PTR_ADD (nh, off); +uint32_t *payload; + +switch (ra->rta_type) { +case IFLA_MIN_MTU : + payload =RTA_DATA (ra); + out->min_mtu = *payload; + out->min_mtu_set = true; +break ; +case IFLA_MAX_MTU : + payload =RTA_DATA (ra); + out->max_mtu = *payload; + out->max_mtu_set = true; +break ; +default : +/* Nothing to do for other attributes. */ +break ; + } + off +=RTA_ALIGN (ra->rta_len); + } + +return 0 ; +} + +/** +* Query minimum and maximum allowed MTU values for given Linux network interface. +* +* This function queries the following interface attributes exposed in netlink since Linux 4.18: +* +* - IFLA_MIN_MTU - minimum allowed MTU +* - IFLA_MAX_MTU - maximum allowed MTU +* +* @param[in] nl +* Netlink socket of the ROUTE kind (NETLINK_ROUTE). +* @param[in] ifindex +* Linux network device index. +* @param[out] min_mtu +* Pointer to minimum allowed MTU. Populated only if both minimum and maximum MTU was queried. +* @param[out] max_mtu +* Pointer to maximum allowed MTU. Populated only if both minimum and maximum MTU was queried. +* +* @return +* 0 on success, negative on error and rte_errno is set. +* +* Known errors: +* +* - (-EINVAL) - either @p min_mtu or @p max_mtu is NULL. +* - (-ENOENT) - either minimum or maximum allowed MTU was not found in interface attributes. +*/ +RTE_EXPORT_INTERNAL_SYMBOL (mlx5_nl_get_mtu_bounds) +int +mlx5_nl_get_mtu_bounds (int nl,unsigned int ifindex,uint16_t *min_mtu,uint16_t *max_mtu) +{ +struct mlx5_mtu out = {0 }; +struct { +struct nlmsghdr nh; +struct ifinfomsg info; + } req = { + .nh = { + .nlmsg_len =NLMSG_LENGTH (sizeof (req.info)), + .nlmsg_type =RTM_GETLINK , + .nlmsg_flags =NLM_F_REQUEST |NLM_F_ACK , + }, + .info = { + .ifi_family =AF_UNSPEC , + .ifi_index = ifindex, + }, + }; +uint32_t sn =MLX5_NL_SN_GENERATE ; +int ret; + +if (min_mtu ==NULL || max_mtu ==NULL ) { + rte_errno =EINVAL ; +return -rte_errno; + } + + ret =mlx5_nl_send (nl, &req.nh, sn); +if (ret <0 ) +return ret; + + ret =mlx5_nl_recv (nl, sn, mlx5_nl_get_mtu_bounds_cb, &out); +if (ret <0 ) +return ret; + +if (!out.min_mtu_set || !out.max_mtu_set) { + rte_errno =ENOENT ; +return -rte_errno; + } + + *min_mtu = out.min_mtu; + *max_mtu = out.max_mtu; + +return ret; +}
drivers/common/mlx5/linux/mlx5_nl.h +3 -0
@@ -117,4 +117,7 @@ void mlx5_nl_rdma_monitor_info_get(struct nlmsghdr *hdr, struct mlx5_nl_port_inf__rte_internal int mlx5_nl_rdma_monitor_cap_get(int nl, uint8_t *cap); +__rte_internal +int mlx5_nl_get_mtu_bounds(int nl, unsigned int ifindex, uint16_t *min_mtu, uint16_t *max_mtu); +#endif /* RTE_PMD_MLX5_NL_H_ */
drivers/net/mlx5/linux/mlx5_ethdev_os.c +30 -0
@@ -159,6 +159,36 @@ mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr)return mlx5_ifreq_by_ifname (ifname, req, ifr); } +/** +* Get device minimum and maximum allowed MTU values. +* +* @param dev +* Pointer to Ethernet device. +* @param[out] min_mtu +* Minimum MTU value output buffer. +* @param[out] max_mtu +* Maximum MTU value output buffer. +* +* @return +* 0 on success, a negative errno value otherwise and rte_errno is set. +*/ +int +mlx5_os_get_mtu_bounds (struct rte_eth_dev *dev,uint16_t *min_mtu,uint16_t *max_mtu) +{ +struct mlx5_priv *priv = dev->data->dev_private; +int nl_route; +int ret; + + nl_route =mlx5_nl_init (NETLINK_ROUTE ,0 ); +if (nl_route <0 ) +return nl_route; + + ret =mlx5_nl_get_mtu_bounds (nl_route, priv->if_index, min_mtu, max_mtu); + +close (nl_route); +return ret; +} +/** * Get device MTU. *
drivers/net/mlx5/linux/mlx5_os.c +2 -0
@@ -1562,6 +1562,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, eth_dev->data->mac_addrs = priv->mac; eth_dev->device = dpdk_dev; eth_dev->data->dev_flags |=RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS ; +/* Fetch minimum and maximum allowed MTU from the device. */ +mlx5_get_mtu_bounds (eth_dev, &priv->min_mtu, &priv->max_mtu);/* Configure the first MAC address by default. */ if (mlx5_get_mac (eth_dev, &mac.addr_bytes)) { DRV_LOG(ERR,
drivers/net/mlx5/mlx5.h +13 -0
@@ -74,6 +74,15 @@/* Maximal number of field/field parts to map into sample registers .*/ #define MLX5_FLEX_ITEM_MAPPING_NUM 32 +/* Number of bytes not included in MTU. */ +#define MLX5_ETH_OVERHEAD (RTE_ETHER_HDR_LEN + RTE_VLAN_HLEN + RTE_ETHER_CRC_LEN) + +/* Minimum allowed MTU to be reported whenever PMD cannot query it from OS. */ +#define MLX5_ETH_MIN_MTU (RTE_ETHER_MIN_MTU) + +/* Maximum allowed MTU to be reported whenever PMD cannot query it from OS. */ +#define MLX5_ETH_MAX_MTU (9978) +enum mlx5_ipool_index {#if defined(HAVE_IBV_FLOW_DV_SUPPORT ) || !defined(HAVE_INFINIBAND_VERBS_H )MLX5_IPOOL_DECAP_ENCAP =0 ,/* Pool for encap/decap resource. */
@@ -1981,6 +1990,8 @@ struct mlx5_priv {unsigned int vlan_filter_n;/* Number of configured VLAN filters. */ /* Device properties. */ uint16_t mtu;/* Configured MTU. */ +uint16_t min_mtu;/* Minimum MTU allowed on the NIC. */ +uint16_t max_mtu;/* Maximum MTU allowed on the NIC. */ unsigned int isolated:1; /* Whether isolated mode is enabled. */ unsigned int representor:1; /* Device is a port representor. */ unsigned int master:1; /* Device is a E-Switch master. */
@@ -2333,6 +2344,7 @@ struct mlx5_priv *mlx5_dev_to_eswitch_info(struct rte_eth_dev *dev);int mlx5_dev_configure_rss_reta (struct rte_eth_dev *dev);uint64_t mlx5_get_restore_flags (struct rte_eth_dev *dev,enum rte_eth_dev_operation op); +void mlx5_get_mtu_bounds (struct rte_eth_dev *dev,uint16_t *min_mtu,uint16_t *max_mtu);/* mlx5_ethdev_os.c */
@@ -2372,6 +2384,7 @@ int mlx5_os_get_stats_n(struct rte_eth_dev *dev, bool bond_master, uint16_t *n_stats, uint16_t *n_stats_sec);void mlx5_os_stats_init (struct rte_eth_dev *dev);int mlx5_get_flag_dropless_rq (struct rte_eth_dev *dev); +int mlx5_os_get_mtu_bounds (struct rte_eth_dev *dev,uint16_t *min_mtu,uint16_t *max_mtu);/* mlx5_mac.c */
drivers/net/mlx5/mlx5_ethdev.c +41 -1
53 lines not on this page · raw message
drivers/net/mlx5/windows/mlx5_ethdev_os.c +28 -0
@@ -71,6 +71,34 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])return 0 ; } +/** +* Get device minimum and maximum allowed MTU. +* +* Windows API does not expose minimum and maximum allowed MTU. +* In this case, this just returns (-ENOTSUP) to allow platform-independent code +* to fallback to default values. +* +* @param dev +* Pointer to Ethernet device. +* @param[out] min_mtu +* Minimum MTU value output buffer. +* @param[out] max_mtu +* Maximum MTU value output buffer. +* +* @return +* (-ENOTSUP) - not supported on Windows +*/ +int +mlx5_os_get_mtu_bounds (struct rte_eth_dev *dev,uint16_t *min_mtu,uint16_t *max_mtu) +{ +RTE_SET_USED (dev); +RTE_SET_USED (min_mtu); +RTE_SET_USED (max_mtu); + + rte_errno =ENOTSUP ; +return -rte_errno; +} +/** * Get device MTU. *
drivers/net/mlx5/windows/mlx5_os.c +2 -0
@@ -477,6 +477,8 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, eth_dev->data->mac_addrs = priv->mac; eth_dev->device = dpdk_dev; eth_dev->data->dev_flags |=RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS ; +/* Fetch minimum and maximum allowed MTU from the device. */ +mlx5_get_mtu_bounds (eth_dev, &priv->min_mtu, &priv->max_mtu);/* Configure the first MAC address by default. */ if (mlx5_get_mac (eth_dev, &mac.addr_bytes)) { DRV_LOG(ERR,
--
2.39.5
Hi,
Quoted 14 lines · Dariusz Sosnowski
mlx5 PMD used hardcoded and incorrect values when reporting maximum MTU and maximum Rx packet length through
rte_eth_dev_info_get().This patch adds support for querying OS for minimum and maximum allowed MTU values. Maximum Rx packet length is then calculated based on these values.
On Linux, these values are queried through netlink, using
IFLA_MIN_MTUandIFLA_MAX_MTUattributes added in Linux 4.18.Windows API unfortunately does not expose minimum and maximum allowed MTU values. In this case, fallback hardcoded values (working on currently supported HW) will be used.
Quoted 6 lines
Bugzilla ID: 1719
Fixes e60fbd5b24fc ("mlx5: add device configure/start/stop")Signed-off-by Dariusz Sosnowski <[email protected]>
Patch applied to next-net-mlx,
Kindest regards
Raslan Darawsheh