Skip to content

Commit cb67b83

Browse files
hadarhenziondavem330
authored andcommitted
net/mlx5e: Introduce SRIOV VF representors
Implement the relevant profile functions to create mlx5e driver instance serving as VF representor. When SRIOV offloads mode is enabled, each VF will have a representor netdevice instance on the host. To do that, we also export set of shared service functions from en_main.c, such that they can be used by both NIC and repsresentors netdevs. The newly created representor netdevice has a basic set of net_device_ops which are the same ndo functions as the NIC netdevice and an ndo of it's own for phys port name. The profiling infrastructure allow sharing code between the NIC and the vport representor even though the representor has only a subset of the NIC functionality. The VF reps and the PF which is used in that mode to represent the uplink, expose switchdev ops. Currently the only op supposed is attr get for the port parent ID which here serves to identify net-devices belonging to the same HW E-Switch. Other than that, no offloading is implemented and hence switching functionality is achieved if one sets SW switching rules, e.g using tc, bridge or ovs. Port phys name (ndo_get_phys_port_name) is implemented to allow exporting to user-space the VF vport number and along with the switchdev port parent id (phys_switch_id) enable a udev base consistent naming scheme: SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \ ATTR{phys_port_name}!="", NAME="$PF_NIC$attr{phys_port_name}" where phys_switch_id is exposed by the PF (and VF reps) and $PF_NIC is the name of the PF netdevice. Signed-off-by: Hadar Hen Zion <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 127ea38 commit cb67b83

File tree

6 files changed

+574
-19
lines changed

6 files changed

+574
-19
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
88
mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o eswitch_offloads.o \
99
en_main.o en_common.o en_fs.o en_ethtool.o en_tx.o \
1010
en_rx.o en_rx_am.o en_txrx.o en_clock.o vxlan.o \
11-
en_tc.o en_arfs.o
11+
en_tc.o en_arfs.o en_rep.o
1212

1313
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <linux/mlx5/vport.h>
4545
#include <linux/mlx5/transobj.h>
4646
#include <linux/rhashtable.h>
47+
#include <net/switchdev.h>
4748
#include "wq.h"
4849
#include "mlx5_core.h"
4950
#include "en_stats.h"
@@ -816,4 +817,31 @@ int mlx5e_create_mdev_resources(struct mlx5_core_dev *mdev);
816817
void mlx5e_destroy_mdev_resources(struct mlx5_core_dev *mdev);
817818
int mlx5e_refresh_tirs_self_loopback_enable(struct mlx5_core_dev *mdev);
818819

820+
struct mlx5_eswitch_rep;
821+
int mlx5e_vport_rep_load(struct mlx5_eswitch *esw,
822+
struct mlx5_eswitch_rep *rep);
823+
void mlx5e_vport_rep_unload(struct mlx5_eswitch *esw,
824+
struct mlx5_eswitch_rep *rep);
825+
int mlx5e_nic_rep_load(struct mlx5_eswitch *esw, struct mlx5_eswitch_rep *rep);
826+
void mlx5e_nic_rep_unload(struct mlx5_eswitch *esw,
827+
struct mlx5_eswitch_rep *rep);
828+
int mlx5e_add_sqs_fwd_rules(struct mlx5e_priv *priv);
829+
void mlx5e_remove_sqs_fwd_rules(struct mlx5e_priv *priv);
830+
int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr);
831+
832+
int mlx5e_create_direct_rqts(struct mlx5e_priv *priv);
833+
void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt);
834+
int mlx5e_create_direct_tirs(struct mlx5e_priv *priv);
835+
void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv);
836+
int mlx5e_create_tises(struct mlx5e_priv *priv);
837+
void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
838+
int mlx5e_close(struct net_device *netdev);
839+
int mlx5e_open(struct net_device *netdev);
840+
void mlx5e_update_stats_work(struct work_struct *work);
841+
void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
842+
const struct mlx5e_profile *profile, void *ppriv);
843+
void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv);
844+
struct rtnl_link_stats64 *
845+
mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
846+
819847
#endif /* __MLX5_EN_H__ */

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void mlx5e_update_stats(struct mlx5e_priv *priv)
226226
mlx5e_update_sw_counters(priv);
227227
}
228228

229-
static void mlx5e_update_stats_work(struct work_struct *work)
229+
void mlx5e_update_stats_work(struct work_struct *work)
230230
{
231231
struct delayed_work *dwork = to_delayed_work(work);
232232
struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
@@ -1518,7 +1518,7 @@ static int mlx5e_create_rqt(struct mlx5e_priv *priv, int sz,
15181518
return err;
15191519
}
15201520

1521-
static void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt)
1521+
void mlx5e_destroy_rqt(struct mlx5e_priv *priv, struct mlx5e_rqt *rqt)
15221522
{
15231523
rqt->enabled = false;
15241524
mlx5_core_destroy_rqt(priv->mdev, rqt->rqtn);
@@ -1531,7 +1531,7 @@ static int mlx5e_create_indirect_rqts(struct mlx5e_priv *priv)
15311531
return mlx5e_create_rqt(priv, MLX5E_INDIR_RQT_SIZE, 0, rqt);
15321532
}
15331533

1534-
static int mlx5e_create_direct_rqts(struct mlx5e_priv *priv)
1534+
int mlx5e_create_direct_rqts(struct mlx5e_priv *priv)
15351535
{
15361536
struct mlx5e_rqt *rqt;
15371537
int err;
@@ -1743,6 +1743,7 @@ static void mlx5e_netdev_set_tcs(struct net_device *netdev)
17431743
int mlx5e_open_locked(struct net_device *netdev)
17441744
{
17451745
struct mlx5e_priv *priv = netdev_priv(netdev);
1746+
struct mlx5_core_dev *mdev = priv->mdev;
17461747
int num_txqs;
17471748
int err;
17481749

@@ -1778,9 +1779,14 @@ int mlx5e_open_locked(struct net_device *netdev)
17781779
#ifdef CONFIG_RFS_ACCEL
17791780
priv->netdev->rx_cpu_rmap = priv->mdev->rmap;
17801781
#endif
1782+
if (priv->profile->update_stats)
1783+
queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
17811784

1782-
queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
1783-
1785+
if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
1786+
err = mlx5e_add_sqs_fwd_rules(priv);
1787+
if (err)
1788+
goto err_close_channels;
1789+
}
17841790
return 0;
17851791

17861792
err_close_channels:
@@ -1790,7 +1796,7 @@ int mlx5e_open_locked(struct net_device *netdev)
17901796
return err;
17911797
}
17921798

1793-
static int mlx5e_open(struct net_device *netdev)
1799+
int mlx5e_open(struct net_device *netdev)
17941800
{
17951801
struct mlx5e_priv *priv = netdev_priv(netdev);
17961802
int err;
@@ -1805,6 +1811,7 @@ static int mlx5e_open(struct net_device *netdev)
18051811
int mlx5e_close_locked(struct net_device *netdev)
18061812
{
18071813
struct mlx5e_priv *priv = netdev_priv(netdev);
1814+
struct mlx5_core_dev *mdev = priv->mdev;
18081815

18091816
/* May already be CLOSED in case a previous configuration operation
18101817
* (e.g RX/TX queue size change) that involves close&open failed.
@@ -1814,6 +1821,9 @@ int mlx5e_close_locked(struct net_device *netdev)
18141821

18151822
clear_bit(MLX5E_STATE_OPENED, &priv->state);
18161823

1824+
if (MLX5_CAP_GEN(mdev, vport_group_manager))
1825+
mlx5e_remove_sqs_fwd_rules(priv);
1826+
18171827
mlx5e_timestamp_cleanup(priv);
18181828
netif_carrier_off(priv->netdev);
18191829
mlx5e_redirect_rqts(priv);
@@ -1822,7 +1832,7 @@ int mlx5e_close_locked(struct net_device *netdev)
18221832
return 0;
18231833
}
18241834

1825-
static int mlx5e_close(struct net_device *netdev)
1835+
int mlx5e_close(struct net_device *netdev)
18261836
{
18271837
struct mlx5e_priv *priv = netdev_priv(netdev);
18281838
int err;
@@ -1957,7 +1967,7 @@ static void mlx5e_destroy_tis(struct mlx5e_priv *priv, int tc)
19571967
mlx5_core_destroy_tis(priv->mdev, priv->tisn[tc]);
19581968
}
19591969

1960-
static int mlx5e_create_tises(struct mlx5e_priv *priv)
1970+
int mlx5e_create_tises(struct mlx5e_priv *priv)
19611971
{
19621972
int err;
19631973
int tc;
@@ -1977,7 +1987,7 @@ static int mlx5e_create_tises(struct mlx5e_priv *priv)
19771987
return err;
19781988
}
19791989

1980-
static void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv)
1990+
void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv)
19811991
{
19821992
int tc;
19831993

@@ -2143,7 +2153,7 @@ static int mlx5e_create_indirect_tirs(struct mlx5e_priv *priv)
21432153
return err;
21442154
}
21452155

2146-
static int mlx5e_create_direct_tirs(struct mlx5e_priv *priv)
2156+
int mlx5e_create_direct_tirs(struct mlx5e_priv *priv)
21472157
{
21482158
int nch = priv->profile->max_nch(priv->mdev);
21492159
struct mlx5e_tir *tir;
@@ -2190,7 +2200,7 @@ static void mlx5e_destroy_indirect_tirs(struct mlx5e_priv *priv)
21902200
mlx5e_destroy_tir(priv->mdev, &priv->indir_tir[i]);
21912201
}
21922202

2193-
static void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv)
2203+
void mlx5e_destroy_direct_tirs(struct mlx5e_priv *priv)
21942204
{
21952205
int nch = priv->profile->max_nch(priv->mdev);
21962206
int i;
@@ -2270,7 +2280,7 @@ static int mlx5e_ndo_setup_tc(struct net_device *dev, u32 handle,
22702280
return mlx5e_setup_tc(dev, tc->tc);
22712281
}
22722282

2273-
static struct rtnl_link_stats64 *
2283+
struct rtnl_link_stats64 *
22742284
mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
22752285
{
22762286
struct mlx5e_priv *priv = netdev_priv(dev);
@@ -2988,6 +2998,10 @@ static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
29882998
}
29892999
}
29903000

3001+
static const struct switchdev_ops mlx5e_switchdev_ops = {
3002+
.switchdev_port_attr_get = mlx5e_attr_get,
3003+
};
3004+
29913005
static void mlx5e_build_nic_netdev(struct net_device *netdev)
29923006
{
29933007
struct mlx5e_priv *priv = netdev_priv(netdev);
@@ -3069,6 +3083,11 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
30693083
netdev->priv_flags |= IFF_UNICAST_FLT;
30703084

30713085
mlx5e_set_netdev_dev_addr(netdev);
3086+
3087+
#ifdef CONFIG_NET_SWITCHDEV
3088+
if (MLX5_CAP_GEN(mdev, vport_group_manager))
3089+
netdev->switchdev_ops = &mlx5e_switchdev_ops;
3090+
#endif
30723091
}
30733092

30743093
static void mlx5e_create_q_counter(struct mlx5e_priv *priv)
@@ -3251,6 +3270,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
32513270
queue_work(priv->wq, &priv->set_rx_mode_work);
32523271

32533272
if (MLX5_CAP_GEN(mdev, vport_group_manager)) {
3273+
rep.load = mlx5e_nic_rep_load;
3274+
rep.unload = mlx5e_nic_rep_unload;
32543275
rep.vport = 0;
32553276
rep.priv_data = priv;
32563277
mlx5_eswitch_register_vport_rep(esw, &rep);
@@ -3277,8 +3298,8 @@ static const struct mlx5e_profile mlx5e_nic_profile = {
32773298
.max_tc = MLX5E_MAX_NUM_TC,
32783299
};
32793300

3280-
static void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
3281-
const struct mlx5e_profile *profile, void *ppriv)
3301+
void *mlx5e_create_netdev(struct mlx5_core_dev *mdev,
3302+
const struct mlx5e_profile *profile, void *ppriv)
32823303
{
32833304
struct net_device *netdev;
32843305
struct mlx5e_priv *priv;
@@ -3372,6 +3393,8 @@ static void mlx5e_register_vport_rep(struct mlx5_core_dev *mdev)
33723393
for (vport = 1; vport < total_vfs; vport++) {
33733394
struct mlx5_eswitch_rep rep;
33743395

3396+
rep.load = mlx5e_vport_rep_load;
3397+
rep.unload = mlx5e_vport_rep_unload;
33753398
rep.vport = vport;
33763399
mlx5_eswitch_register_vport_rep(esw, &rep);
33773400
}
@@ -3402,7 +3425,7 @@ static void *mlx5e_add(struct mlx5_core_dev *mdev)
34023425
return ret;
34033426
}
34043427

3405-
static void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
3428+
void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
34063429
{
34073430
const struct mlx5e_profile *profile = priv->profile;
34083431
struct net_device *netdev = priv->netdev;

0 commit comments

Comments
 (0)