Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

{net,vdpa}/mlx5: Configure interface MAC into mpfs L2 table

net/mlx5: Expose MPFS configuration API

MPFS is the multi physical function switch that bridges traffic between
the physical port and any physical functions associated with it. The
driver is required to add or remove MAC entries to properly forward
incoming traffic to the correct physical function.

We export the API to control MPFS so that other drivers, such as
mlx5_vdpa are able to add MAC addresses of their network interfaces.

The MAC address of the vdpa interface must be configured into the MPFS L2
address. Failing to do so could cause, in some NIC configurations, failure
to forward packets to the vdpa network device instance.

Fix this by adding calls to update the MPFS table.

CC: <mst@redhat.com>
CC: <jasowang@redhat.com>
CC: <virtualization@lists.linux-foundation.org>
Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Signed-off-by: Eli Cohen <elic@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>

authored by

Eli Cohen and committed by
Saeed Mahameed
7c9f131f 5e7923ac

+42 -5
+1
drivers/net/ethernet/mellanox/mlx5/core/en_fs.c
··· 35 35 #include <linux/ipv6.h> 36 36 #include <linux/tcp.h> 37 37 #include <linux/mlx5/fs.h> 38 + #include <linux/mlx5/mpfs.h> 38 39 #include "en.h" 39 40 #include "en_rep.h" 40 41 #include "lib/mpfs.h"
+1
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
··· 35 35 #include <linux/mlx5/mlx5_ifc.h> 36 36 #include <linux/mlx5/vport.h> 37 37 #include <linux/mlx5/fs.h> 38 + #include <linux/mlx5/mpfs.h> 38 39 #include "esw/acl/lgcy.h" 39 40 #include "esw/legacy.h" 40 41 #include "mlx5_core.h"
+3
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c
··· 33 33 #include <linux/etherdevice.h> 34 34 #include <linux/mlx5/driver.h> 35 35 #include <linux/mlx5/mlx5_ifc.h> 36 + #include <linux/mlx5/mpfs.h> 36 37 #include <linux/mlx5/eswitch.h> 37 38 #include "mlx5_core.h" 38 39 #include "lib/mpfs.h" ··· 176 175 mutex_unlock(&mpfs->lock); 177 176 return err; 178 177 } 178 + EXPORT_SYMBOL(mlx5_mpfs_add_mac); 179 179 180 180 int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) 181 181 { ··· 208 206 mutex_unlock(&mpfs->lock); 209 207 return err; 210 208 } 209 + EXPORT_SYMBOL(mlx5_mpfs_del_mac);
+1 -4
drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.h
··· 84 84 #ifdef CONFIG_MLX5_MPFS 85 85 int mlx5_mpfs_init(struct mlx5_core_dev *dev); 86 86 void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev); 87 - int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac); 88 - int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac); 89 87 #else /* #ifndef CONFIG_MLX5_MPFS */ 90 88 static inline int mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; } 91 89 static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {} 92 - static inline int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; } 93 - static inline int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; } 94 90 #endif 91 + 95 92 #endif
+18 -1
drivers/vdpa/mlx5/net/mlx5_vnet.c
··· 15 15 #include <linux/mlx5/vport.h> 16 16 #include <linux/mlx5/fs.h> 17 17 #include <linux/mlx5/mlx5_ifc_vdpa.h> 18 + #include <linux/mlx5/mpfs.h> 18 19 #include "mlx5_vdpa.h" 19 20 20 21 MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); ··· 1860 1859 static void mlx5_vdpa_free(struct vdpa_device *vdev) 1861 1860 { 1862 1861 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 1862 + struct mlx5_core_dev *pfmdev; 1863 1863 struct mlx5_vdpa_net *ndev; 1864 1864 1865 1865 ndev = to_mlx5_vdpa_ndev(mvdev); 1866 1866 1867 1867 free_resources(ndev); 1868 + if (!is_zero_ether_addr(ndev->config.mac)) { 1869 + pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); 1870 + mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); 1871 + } 1868 1872 mlx5_vdpa_free_resources(&ndev->mvdev); 1869 1873 mutex_destroy(&ndev->reslock); 1870 1874 } ··· 1996 1990 { 1997 1991 struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev); 1998 1992 struct virtio_net_config *config; 1993 + struct mlx5_core_dev *pfmdev; 1999 1994 struct mlx5_vdpa_dev *mvdev; 2000 1995 struct mlx5_vdpa_net *ndev; 2001 1996 struct mlx5_core_dev *mdev; ··· 2030 2023 if (err) 2031 2024 goto err_mtu; 2032 2025 2026 + if (!is_zero_ether_addr(config->mac)) { 2027 + pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev)); 2028 + err = mlx5_mpfs_add_mac(pfmdev, config->mac); 2029 + if (err) 2030 + goto err_mtu; 2031 + } 2032 + 2033 2033 mvdev->vdev.dma_dev = mdev->device; 2034 2034 err = mlx5_vdpa_alloc_resources(&ndev->mvdev); 2035 2035 if (err) 2036 - goto err_mtu; 2036 + goto err_mpfs; 2037 2037 2038 2038 err = alloc_resources(ndev); 2039 2039 if (err) ··· 2058 2044 free_resources(ndev); 2059 2045 err_res: 2060 2046 mlx5_vdpa_free_resources(&ndev->mvdev); 2047 + err_mpfs: 2048 + if (!is_zero_ether_addr(config->mac)) 2049 + mlx5_mpfs_del_mac(pfmdev, config->mac); 2061 2050 err_mtu: 2062 2051 mutex_destroy(&ndev->reslock); 2063 2052 put_device(&mvdev->vdev.dev);
+18
include/linux/mlx5/mpfs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2 + * Copyright (c) 2021 Mellanox Technologies Ltd. 3 + */ 4 + 5 + #ifndef _MLX5_MPFS_ 6 + #define _MLX5_MPFS_ 7 + 8 + struct mlx5_core_dev; 9 + 10 + #ifdef CONFIG_MLX5_MPFS 11 + int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac); 12 + int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac); 13 + #else /* #ifndef CONFIG_MLX5_MPFS */ 14 + static inline int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; } 15 + static inline int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; } 16 + #endif 17 + 18 + #endif