Skip to content

Commit 89a0e38

Browse files
elic307igregkh
authored andcommitted
{net,vdpa}/mlx5: Configure interface MAC into mpfs L2 table
commit 7c9f131 upstream. 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: 1a86b37 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bbd00c4 commit 89a0e38

6 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/en_fs.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/ipv6.h>
3636
#include <linux/tcp.h>
3737
#include <linux/mlx5/fs.h>
38+
#include <linux/mlx5/mpfs.h>
3839
#include "en.h"
3940
#include "lib/mpfs.h"
4041

‎drivers/net/ethernet/mellanox/mlx5/core/eswitch.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/mlx5/mlx5_ifc.h>
3636
#include <linux/mlx5/vport.h>
3737
#include <linux/mlx5/fs.h>
38+
#include <linux/mlx5/mpfs.h>
3839
#include "esw/acl/lgcy.h"
3940
#include "mlx5_core.h"
4041
#include "lib/eq.h"

‎drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/etherdevice.h>
3434
#include <linux/mlx5/driver.h>
3535
#include <linux/mlx5/mlx5_ifc.h>
36+
#include <linux/mlx5/mpfs.h>
3637
#include <linux/mlx5/eswitch.h>
3738
#include "mlx5_core.h"
3839
#include "lib/mpfs.h"
@@ -175,6 +176,7 @@ int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac)
175176
mutex_unlock(&mpfs->lock);
176177
return err;
177178
}
179+
EXPORT_SYMBOL(mlx5_mpfs_add_mac);
178180

179181
int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac)
180182
{
@@ -206,3 +208,4 @@ int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac)
206208
mutex_unlock(&mpfs->lock);
207209
return err;
208210
}
211+
EXPORT_SYMBOL(mlx5_mpfs_del_mac);

‎drivers/net/ethernet/mellanox/mlx5/core/lib/mpfs.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ struct l2addr_node {
8484
#ifdef CONFIG_MLX5_MPFS
8585
int mlx5_mpfs_init(struct mlx5_core_dev *dev);
8686
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);
8987
#else /* #ifndef CONFIG_MLX5_MPFS */
9088
static inline int mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; }
9189
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; }
9490
#endif
91+
9592
#endif

‎drivers/vdpa/mlx5/net/mlx5_vnet.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/mlx5/vport.h>
1010
#include <linux/mlx5/fs.h>
1111
#include <linux/mlx5/device.h>
12+
#include <linux/mlx5/mpfs.h>
1213
#include "mlx5_vnet.h"
1314
#include "mlx5_vdpa_ifc.h"
1415
#include "mlx5_vdpa.h"
@@ -1839,11 +1840,16 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb
18391840
static void mlx5_vdpa_free(struct vdpa_device *vdev)
18401841
{
18411842
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
1843+
struct mlx5_core_dev *pfmdev;
18421844
struct mlx5_vdpa_net *ndev;
18431845

18441846
ndev = to_mlx5_vdpa_ndev(mvdev);
18451847

18461848
free_resources(ndev);
1849+
if (!is_zero_ether_addr(ndev->config.mac)) {
1850+
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
1851+
mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
1852+
}
18471853
mlx5_vdpa_free_resources(&ndev->mvdev);
18481854
mutex_destroy(&ndev->reslock);
18491855
}
@@ -1962,6 +1968,7 @@ static void init_mvqs(struct mlx5_vdpa_net *ndev)
19621968
void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
19631969
{
19641970
struct virtio_net_config *config;
1971+
struct mlx5_core_dev *pfmdev;
19651972
struct mlx5_vdpa_dev *mvdev;
19661973
struct mlx5_vdpa_net *ndev;
19671974
u32 max_vqs;
@@ -1990,10 +1997,17 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
19901997
if (err)
19911998
goto err_mtu;
19921999

2000+
if (!is_zero_ether_addr(config->mac)) {
2001+
pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
2002+
err = mlx5_mpfs_add_mac(pfmdev, config->mac);
2003+
if (err)
2004+
goto err_mtu;
2005+
}
2006+
19932007
mvdev->vdev.dma_dev = mdev->device;
19942008
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
19952009
if (err)
1996-
goto err_mtu;
2010+
goto err_mpfs;
19972011

19982012
err = alloc_resources(ndev);
19992013
if (err)
@@ -2009,6 +2023,9 @@ void *mlx5_vdpa_add_dev(struct mlx5_core_dev *mdev)
20092023
free_resources(ndev);
20102024
err_res:
20112025
mlx5_vdpa_free_resources(&ndev->mvdev);
2026+
err_mpfs:
2027+
if (!is_zero_ether_addr(config->mac))
2028+
mlx5_mpfs_del_mac(pfmdev, config->mac);
20122029
err_mtu:
20132030
mutex_destroy(&ndev->reslock);
20142031
put_device(&mvdev->vdev.dev);

‎include/linux/mlx5/mpfs.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

0 commit comments

Comments
 (0)