Skip to content

Commit 7c9f131

Browse files
elic307iSaeed Mahameed
authored andcommitted
{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: <[email protected]> CC: <[email protected]> CC: <[email protected]> Fixes: 1a86b37 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices") Signed-off-by: Eli Cohen <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 5e7923a commit 7c9f131

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

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 "en_rep.h"
4041
#include "lib/mpfs.h"

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 "esw/legacy.h"
4041
#include "mlx5_core.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
@@ -15,6 +15,7 @@
1515
#include <linux/mlx5/vport.h>
1616
#include <linux/mlx5/fs.h>
1717
#include <linux/mlx5/mlx5_ifc_vdpa.h>
18+
#include <linux/mlx5/mpfs.h>
1819
#include "mlx5_vdpa.h"
1920

2021
MODULE_AUTHOR("Eli Cohen <[email protected]>");
@@ -1859,11 +1860,16 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb
18591860
static void mlx5_vdpa_free(struct vdpa_device *vdev)
18601861
{
18611862
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
1863+
struct mlx5_core_dev *pfmdev;
18621864
struct mlx5_vdpa_net *ndev;
18631865

18641866
ndev = to_mlx5_vdpa_ndev(mvdev);
18651867

18661868
free_resources(ndev);
1869+
if (!is_zero_ether_addr(ndev->config.mac)) {
1870+
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
1871+
mlx5_mpfs_del_mac(pfmdev, ndev->config.mac);
1872+
}
18671873
mlx5_vdpa_free_resources(&ndev->mvdev);
18681874
mutex_destroy(&ndev->reslock);
18691875
}
@@ -1990,6 +1996,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
19901996
{
19911997
struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
19921998
struct virtio_net_config *config;
1999+
struct mlx5_core_dev *pfmdev;
19932000
struct mlx5_vdpa_dev *mvdev;
19942001
struct mlx5_vdpa_net *ndev;
19952002
struct mlx5_core_dev *mdev;
@@ -2023,10 +2030,17 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
20232030
if (err)
20242031
goto err_mtu;
20252032

2033+
if (!is_zero_ether_addr(config->mac)) {
2034+
pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
2035+
err = mlx5_mpfs_add_mac(pfmdev, config->mac);
2036+
if (err)
2037+
goto err_mtu;
2038+
}
2039+
20262040
mvdev->vdev.dma_dev = mdev->device;
20272041
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
20282042
if (err)
2029-
goto err_mtu;
2043+
goto err_mpfs;
20302044

20312045
err = alloc_resources(ndev);
20322046
if (err)
@@ -2044,6 +2058,9 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name)
20442058
free_resources(ndev);
20452059
err_res:
20462060
mlx5_vdpa_free_resources(&ndev->mvdev);
2061+
err_mpfs:
2062+
if (!is_zero_ether_addr(config->mac))
2063+
mlx5_mpfs_del_mac(pfmdev, config->mac);
20472064
err_mtu:
20482065
mutex_destroy(&ndev->reslock);
20492066
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)