Previously, mac_own was a bit-field indicating the MAC addresses owned by the PMD, specifically marking those added to VFs by the PMD and allowing them to be flushed during exit.
With this commit, the bit-field now applies to all MAC addresses added by the PMD, including those for PF, VF, and SFs. The process for flushing MAC addresses added to VFs by the PMD remains unchanged. Signed-off-by: Gavin Li <gav...@nvidia.com> --- drivers/common/mlx5/linux/mlx5_nl.c | 26 ++++++++++++-------------- drivers/common/mlx5/linux/mlx5_nl.h | 8 ++++---- drivers/net/mlx5/linux/mlx5_os.c | 12 +++++++++--- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c index dd69e229e3..1c2f15ad8a 100644 --- a/drivers/common/mlx5/linux/mlx5_nl.c +++ b/drivers/common/mlx5/linux/mlx5_nl.c @@ -721,8 +721,6 @@ mlx5_nl_vf_mac_addr_modify(int nlsk_fd, unsigned int iface_idx, * Netlink socket file descriptor. * @param[in] iface_idx * Net device interface index. - * @param mac_own - * BITFIELD_DECLARE array to store the mac. * @param mac * MAC address to register. * @param index @@ -734,8 +732,7 @@ mlx5_nl_vf_mac_addr_modify(int nlsk_fd, unsigned int iface_idx, RTE_EXPORT_INTERNAL_SYMBOL(mlx5_nl_mac_addr_add) int mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, - uint64_t *mac_own, struct rte_ether_addr *mac, - uint32_t index) + struct rte_ether_addr *mac, uint32_t index) { int ret; @@ -744,8 +741,6 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); if (index >= MLX5_MAX_MAC_ADDRESSES) return -EINVAL; - - BITFIELD_SET(mac_own, index); } if (ret == -EEXIST) return 0; @@ -759,8 +754,6 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, * Netlink socket file descriptor. * @param[in] iface_idx * Net device interface index. - * @param mac_own - * BITFIELD_DECLARE array to store the mac. * @param mac * MAC address to remove. * @param index @@ -771,14 +764,13 @@ mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, */ RTE_EXPORT_INTERNAL_SYMBOL(mlx5_nl_mac_addr_remove) int -mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, +mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, struct rte_ether_addr *mac, uint32_t index) { MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); if (index >= MLX5_MAX_MAC_ADDRESSES) return -EINVAL; - BITFIELD_RESET(mac_own, index); return mlx5_nl_mac_addr_modify(nlsk_fd, iface_idx, mac, 0); } @@ -850,12 +842,14 @@ mlx5_nl_mac_addr_sync(int nlsk_fd, unsigned int iface_idx, * @p mac_addrs array size. * @param mac_own * BITFIELD_DECLARE array to store the mac. + * @param vf + * Flag for a VF device. */ RTE_EXPORT_INTERNAL_SYMBOL(mlx5_nl_mac_addr_flush) void mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int iface_idx, struct rte_ether_addr *mac_addrs, int n, - uint64_t *mac_own) + uint64_t *mac_own, bool vf) { int i; @@ -865,9 +859,13 @@ mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int iface_idx, for (i = n - 1; i >= 0; --i) { struct rte_ether_addr *m = &mac_addrs[i]; - if (BITFIELD_ISSET(mac_own, i)) - mlx5_nl_mac_addr_remove(nlsk_fd, iface_idx, mac_own, m, - i); + if (BITFIELD_ISSET(mac_own, i)) { + if (vf) + mlx5_nl_mac_addr_remove(nlsk_fd, + iface_idx, + m, i); + BITFIELD_RESET(mac_own, i); + } } } diff --git a/drivers/common/mlx5/linux/mlx5_nl.h b/drivers/common/mlx5/linux/mlx5_nl.h index 26923a88fd..3f79a73c85 100644 --- a/drivers/common/mlx5/linux/mlx5_nl.h +++ b/drivers/common/mlx5/linux/mlx5_nl.h @@ -56,19 +56,19 @@ struct mlx5_nl_port_info { __rte_internal int mlx5_nl_init(int protocol, int groups); __rte_internal -int mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own, +int mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, struct rte_ether_addr *mac, uint32_t index); __rte_internal int mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx, - uint64_t *mac_own, struct rte_ether_addr *mac, - uint32_t index); + struct rte_ether_addr *mac, uint32_t index); __rte_internal void mlx5_nl_mac_addr_sync(int nlsk_fd, unsigned int iface_idx, struct rte_ether_addr *mac_addrs, int n); __rte_internal void mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int iface_idx, struct rte_ether_addr *mac_addrs, int n, - uint64_t *mac_own); + uint64_t *mac_own, + bool vf); __rte_internal int mlx5_nl_promisc(int nlsk_fd, unsigned int iface_idx, int enable); __rte_internal diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 85b3fabaf5..dda51a138e 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -3223,8 +3223,10 @@ mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) if (vf) mlx5_nl_mac_addr_remove(priv->nl_socket_route, - mlx5_ifindex(dev), priv->mac_own, + mlx5_ifindex(dev), &dev->data->mac_addrs[index], index); + if (index < MLX5_MAX_MAC_ADDRESSES) + BITFIELD_RESET(priv->mac_own, index); } /** @@ -3250,8 +3252,11 @@ mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, if (vf) ret = mlx5_nl_mac_addr_add(priv->nl_socket_route, - mlx5_ifindex(dev), priv->mac_own, + mlx5_ifindex(dev), mac, index); + if (!ret) + BITFIELD_SET(priv->mac_own, index); + return ret; } @@ -3331,8 +3336,9 @@ void mlx5_os_mac_addr_flush(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; + const int vf = priv->sh->dev_cap.vf; mlx5_nl_mac_addr_flush(priv->nl_socket_route, mlx5_ifindex(dev), dev->data->mac_addrs, - MLX5_MAX_MAC_ADDRESSES, priv->mac_own); + MLX5_MAX_MAC_ADDRESSES, priv->mac_own, vf); } -- 2.34.1