Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ebe023a4 authored by David S. Miller's avatar David S. Miller
Browse files

Merge tag 'mlx5e-updates-2018-07-27' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux



Saeed Mahameed says:

====================
mlx5e-updates-2018-07-27 (Vxlan updates)

This series from Gal and Saeed provides updates to mlx5 vxlan implementation.

Gal, started with three cleanups to reflect the actual hardware vxlan state
- reflect 4789 UDP port default addition to software database
- check maximum number of vxlan  UDP ports
- cleanup an unused member in vxlan work

Then Gal provides performance optimization by replacing the
vxlan radix tree with a hash table.

Measuring mlx5e_vxlan_lookup_port execution time:

                      Radix Tree   Hash Table
     --------------- ------------ ------------
      Single Stream   161 ns       79  ns (51% improvement)
      Multi Stream    259 ns       136 ns (47% improvement)

    Measuring UDP stream packet rate, single fully utilized TX core:
    Radix Tree: 498,300 PPS
    Hash Table: 555,468 PPS (11% improvement)

Next, from Saeed, vxlan refactoring to allow sharing the vxlan table
between different mlx5 netdevice instances like PF and VF representors,
this is done by making mlx5 vxlan interface more generic and decoupling
it from PF netdevice structures and logic, then moving it into mlx5 core
as a low level interface so it can be used by VF representors, which is
illustrated in the last patch of the serious.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents eef6ab8b a3e67366
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@ mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o \
		fpga/ipsec.o fpga/tls.o

mlx5_core-$(CONFIG_MLX5_CORE_EN) += en_main.o en_common.o en_fs.o en_ethtool.o \
		en_tx.o en_rx.o en_dim.o en_txrx.o en/xdp.o en_stats.o vxlan.o \
		en_arfs.o en_fs_ethtool.o en_selftest.o en/port.o
		en_tx.o en_rx.o en_dim.o en_txrx.o en/xdp.o en_stats.o \
		en_arfs.o en_fs_ethtool.o en_selftest.o en/port.o lib/vxlan.o

mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o

+0 −6
Original line number Diff line number Diff line
@@ -654,11 +654,6 @@ enum {
	MLX5E_STATE_DESTROYING,
};

struct mlx5e_vxlan_db {
	spinlock_t			lock; /* protect vxlan table */
	struct radix_tree_root		tree;
};

struct mlx5e_l2_rule {
	u8  addr[ETH_ALEN + 2];
	struct mlx5_flow_handle *rule;
@@ -816,7 +811,6 @@ struct mlx5e_priv {
	u32                        tx_rates[MLX5E_MAX_NUM_SQS];

	struct mlx5e_flow_steering fs;
	struct mlx5e_vxlan_db      vxlan;

	struct workqueue_struct    *wq;
	struct work_struct         update_carrier_work;
+60 −11
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@
#include "en_accel/tls.h"
#include "accel/ipsec.h"
#include "accel/tls.h"
#include "vxlan.h"
#include "lib/vxlan.h"
#include "en/port.h"
#include "en/xdp.h"

@@ -2974,7 +2974,7 @@ int mlx5e_open(struct net_device *netdev)
		mlx5_set_port_admin_status(priv->mdev, MLX5_PORT_UP);
	mutex_unlock(&priv->state_lock);

	if (mlx5e_vxlan_allowed(priv->mdev))
	if (mlx5_vxlan_allowed(priv->mdev->vxlan))
		udp_tunnel_get_rx_info(netdev);

	return err;
@@ -3969,6 +3969,57 @@ static int mlx5e_get_vf_stats(struct net_device *dev,
}
#endif

struct mlx5e_vxlan_work {
	struct work_struct	work;
	struct mlx5e_priv	*priv;
	u16			port;
};

static void mlx5e_vxlan_add_work(struct work_struct *work)
{
	struct mlx5e_vxlan_work *vxlan_work =
		container_of(work, struct mlx5e_vxlan_work, work);
	struct mlx5e_priv *priv = vxlan_work->priv;
	u16 port = vxlan_work->port;

	mutex_lock(&priv->state_lock);
	mlx5_vxlan_add_port(priv->mdev->vxlan, port);
	mutex_unlock(&priv->state_lock);

	kfree(vxlan_work);
}

static void mlx5e_vxlan_del_work(struct work_struct *work)
{
	struct mlx5e_vxlan_work *vxlan_work =
		container_of(work, struct mlx5e_vxlan_work, work);
	struct mlx5e_priv *priv         = vxlan_work->priv;
	u16 port = vxlan_work->port;

	mutex_lock(&priv->state_lock);
	mlx5_vxlan_del_port(priv->mdev->vxlan, port);
	mutex_unlock(&priv->state_lock);
	kfree(vxlan_work);
}

static void mlx5e_vxlan_queue_work(struct mlx5e_priv *priv, u16 port, int add)
{
	struct mlx5e_vxlan_work *vxlan_work;

	vxlan_work = kmalloc(sizeof(*vxlan_work), GFP_ATOMIC);
	if (!vxlan_work)
		return;

	if (add)
		INIT_WORK(&vxlan_work->work, mlx5e_vxlan_add_work);
	else
		INIT_WORK(&vxlan_work->work, mlx5e_vxlan_del_work);

	vxlan_work->priv = priv;
	vxlan_work->port = port;
	queue_work(priv->wq, &vxlan_work->work);
}

static void mlx5e_add_vxlan_port(struct net_device *netdev,
				 struct udp_tunnel_info *ti)
{
@@ -3977,10 +4028,10 @@ static void mlx5e_add_vxlan_port(struct net_device *netdev,
	if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
		return;

	if (!mlx5e_vxlan_allowed(priv->mdev))
	if (!mlx5_vxlan_allowed(priv->mdev->vxlan))
		return;

	mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 1);
	mlx5e_vxlan_queue_work(priv, be16_to_cpu(ti->port), 1);
}

static void mlx5e_del_vxlan_port(struct net_device *netdev,
@@ -3991,10 +4042,10 @@ static void mlx5e_del_vxlan_port(struct net_device *netdev,
	if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
		return;

	if (!mlx5e_vxlan_allowed(priv->mdev))
	if (!mlx5_vxlan_allowed(priv->mdev->vxlan))
		return;

	mlx5e_vxlan_queue_work(priv, ti->sa_family, be16_to_cpu(ti->port), 0);
	mlx5e_vxlan_queue_work(priv, be16_to_cpu(ti->port), 0);
}

static netdev_features_t mlx5e_tunnel_features_check(struct mlx5e_priv *priv,
@@ -4025,7 +4076,7 @@ static netdev_features_t mlx5e_tunnel_features_check(struct mlx5e_priv *priv,
		port = be16_to_cpu(udph->dest);

		/* Verify if UDP port is being offloaded by HW */
		if (mlx5e_vxlan_lookup_port(priv, port))
		if (mlx5_vxlan_lookup_port(priv->mdev->vxlan, port))
			return features;
	}

@@ -4597,7 +4648,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
	netdev->hw_features      |= NETIF_F_HW_VLAN_CTAG_FILTER;
	netdev->hw_features      |= NETIF_F_HW_VLAN_STAG_TX;

	if (mlx5e_vxlan_allowed(mdev) || MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) {
	if (mlx5_vxlan_allowed(mdev->vxlan) || MLX5_CAP_ETH(mdev, tunnel_stateless_gre)) {
		netdev->hw_enc_features |= NETIF_F_IP_CSUM;
		netdev->hw_enc_features |= NETIF_F_IPV6_CSUM;
		netdev->hw_enc_features |= NETIF_F_TSO;
@@ -4605,7 +4656,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
		netdev->hw_enc_features |= NETIF_F_GSO_PARTIAL;
	}

	if (mlx5e_vxlan_allowed(mdev)) {
	if (mlx5_vxlan_allowed(mdev->vxlan)) {
		netdev->hw_features     |= NETIF_F_GSO_UDP_TUNNEL |
					   NETIF_F_GSO_UDP_TUNNEL_CSUM;
		netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL |
@@ -4716,14 +4767,12 @@ static void mlx5e_nic_init(struct mlx5_core_dev *mdev,
		mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
	mlx5e_build_nic_netdev(netdev);
	mlx5e_build_tc2txq_maps(priv);
	mlx5e_vxlan_init(priv);
}

static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
{
	mlx5e_tls_cleanup(priv);
	mlx5e_ipsec_cleanup(priv);
	mlx5e_vxlan_cleanup(priv);
}

static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
+3 −11
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@
#include "en_rep.h"
#include "en_tc.h"
#include "eswitch.h"
#include "vxlan.h"
#include "lib/vxlan.h"
#include "fs_core.h"
#include "en/port.h"

@@ -1124,16 +1124,12 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
			skb_flow_dissector_target(f->dissector,
						  FLOW_DISSECTOR_KEY_ENC_PORTS,
						  f->mask);
		struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
		struct mlx5e_rep_priv *uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw, REP_ETH);
		struct net_device *up_dev = uplink_rpriv->netdev;
		struct mlx5e_priv *up_priv = netdev_priv(up_dev);

		/* Full udp dst port must be given */
		if (memchr_inv(&mask->dst, 0xff, sizeof(mask->dst)))
			goto vxlan_match_offload_err;

		if (mlx5e_vxlan_lookup_port(up_priv, be16_to_cpu(key->dst)) &&
		if (mlx5_vxlan_lookup_port(priv->mdev->vxlan, be16_to_cpu(key->dst)) &&
		    MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap))
			parse_vxlan_attr(spec, f);
		else {
@@ -2533,11 +2529,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
			      struct mlx5e_tc_flow *flow)
{
	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
	struct mlx5e_rep_priv *uplink_rpriv = mlx5_eswitch_get_uplink_priv(esw,
									   REP_ETH);
	struct net_device *up_dev = uplink_rpriv->netdev;
	unsigned short family = ip_tunnel_info_af(tun_info);
	struct mlx5e_priv *up_priv = netdev_priv(up_dev);
	struct mlx5_esw_flow_attr *attr = flow->esw_attr;
	struct ip_tunnel_key *key = &tun_info->key;
	struct mlx5e_encap_entry *e;
@@ -2557,7 +2549,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
		return -EOPNOTSUPP;
	}

	if (mlx5e_vxlan_lookup_port(up_priv, be16_to_cpu(key->tp_dst)) &&
	if (mlx5_vxlan_lookup_port(priv->mdev->vxlan, be16_to_cpu(key->tp_dst)) &&
	    MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap)) {
		tunnel_type = MLX5_HEADER_TYPE_VXLAN;
	} else {
+230 −0
Original line number Diff line number Diff line
@@ -36,15 +36,27 @@
#include "mlx5_core.h"
#include "vxlan.h"

void mlx5e_vxlan_init(struct mlx5e_priv *priv)
struct mlx5_vxlan {
	struct mlx5_core_dev		*mdev;
	spinlock_t			lock; /* protect vxlan table */
	/* max_num_ports is usuallly 4, 16 buckets is more than enough */
	DECLARE_HASHTABLE(htable, 4);
	int				num_ports;
	struct mutex                    sync_lock; /* sync add/del port HW operations */
};

struct mlx5_vxlan_port {
	struct hlist_node hlist;
	atomic_t refcount;
	u16 udp_port;
};

static inline u8 mlx5_vxlan_max_udp_ports(struct mlx5_core_dev *mdev)
{
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;

	spin_lock_init(&vxlan_db->lock);
	INIT_RADIX_TREE(&vxlan_db->tree, GFP_ATOMIC);
	return MLX5_CAP_ETH(mdev, max_vxlan_udp_ports) ?: 4;
}

static int mlx5e_vxlan_core_add_port_cmd(struct mlx5_core_dev *mdev, u16 port)
static int mlx5_vxlan_core_add_port_cmd(struct mlx5_core_dev *mdev, u16 port)
{
	u32 in[MLX5_ST_SZ_DW(add_vxlan_udp_dport_in)]   = {0};
	u32 out[MLX5_ST_SZ_DW(add_vxlan_udp_dport_out)] = {0};
@@ -55,7 +67,7 @@ static int mlx5e_vxlan_core_add_port_cmd(struct mlx5_core_dev *mdev, u16 port)
	return mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
}

static int mlx5e_vxlan_core_del_port_cmd(struct mlx5_core_dev *mdev, u16 port)
static int mlx5_vxlan_core_del_port_cmd(struct mlx5_core_dev *mdev, u16 port)
{
	u32 in[MLX5_ST_SZ_DW(delete_vxlan_udp_dport_in)]   = {0};
	u32 out[MLX5_ST_SZ_DW(delete_vxlan_udp_dport_out)] = {0};
@@ -66,125 +78,153 @@ static int mlx5e_vxlan_core_del_port_cmd(struct mlx5_core_dev *mdev, u16 port)
	return mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
}

struct mlx5e_vxlan *mlx5e_vxlan_lookup_port(struct mlx5e_priv *priv, u16 port)
static struct mlx5_vxlan_port*
mlx5_vxlan_lookup_port_locked(struct mlx5_vxlan *vxlan, u16 port)
{
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	struct mlx5e_vxlan *vxlan;
	struct mlx5_vxlan_port *vxlanp;

	spin_lock_bh(&vxlan_db->lock);
	vxlan = radix_tree_lookup(&vxlan_db->tree, port);
	spin_unlock_bh(&vxlan_db->lock);
	hash_for_each_possible(vxlan->htable, vxlanp, hlist, port) {
		if (vxlanp->udp_port == port)
			return vxlanp;
	}

	return vxlan;
	return NULL;
}

static void mlx5e_vxlan_add_port(struct work_struct *work)
struct mlx5_vxlan_port *mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port)
{
	struct mlx5e_vxlan_work *vxlan_work =
		container_of(work, struct mlx5e_vxlan_work, work);
	struct mlx5e_priv *priv = vxlan_work->priv;
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	u16 port = vxlan_work->port;
	struct mlx5e_vxlan *vxlan;
	int err;
	struct mlx5_vxlan_port *vxlanp;

	if (!mlx5_vxlan_allowed(vxlan))
		return NULL;

	spin_lock_bh(&vxlan->lock);
	vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port);
	spin_unlock_bh(&vxlan->lock);

	mutex_lock(&priv->state_lock);
	vxlan = mlx5e_vxlan_lookup_port(priv, port);
	if (vxlan) {
		atomic_inc(&vxlan->refcount);
		goto free_work;
	return vxlanp;
}

	if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port))
		goto free_work;
int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
{
	struct mlx5_vxlan_port *vxlanp;
	int ret = -ENOSPC;

	vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
	if (!vxlan)
	vxlanp = mlx5_vxlan_lookup_port(vxlan, port);
	if (vxlanp) {
		atomic_inc(&vxlanp->refcount);
		return 0;
	}

	mutex_lock(&vxlan->sync_lock);
	if (vxlan->num_ports >= mlx5_vxlan_max_udp_ports(vxlan->mdev)) {
		mlx5_core_info(vxlan->mdev,
			       "UDP port (%d) not offloaded, max number of UDP ports (%d) are already offloaded\n",
			       port, mlx5_vxlan_max_udp_ports(vxlan->mdev));
		ret = -ENOSPC;
		goto unlock;
	}

	ret = mlx5_vxlan_core_add_port_cmd(vxlan->mdev, port);
	if (ret)
		goto unlock;

	vxlanp = kzalloc(sizeof(*vxlanp), GFP_KERNEL);
	if (!vxlanp) {
		ret = -ENOMEM;
		goto err_delete_port;
	}

	vxlan->udp_port = port;
	atomic_set(&vxlan->refcount, 1);
	vxlanp->udp_port = port;
	atomic_set(&vxlanp->refcount, 1);

	spin_lock_bh(&vxlan_db->lock);
	err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan);
	spin_unlock_bh(&vxlan_db->lock);
	if (err)
		goto err_free;
	spin_lock_bh(&vxlan->lock);
	hash_add(vxlan->htable, &vxlanp->hlist, port);
	spin_unlock_bh(&vxlan->lock);

	goto free_work;
	vxlan->num_ports++;
	mutex_unlock(&vxlan->sync_lock);
	return 0;

err_free:
	kfree(vxlan);
err_delete_port:
	mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
free_work:
	mutex_unlock(&priv->state_lock);
	kfree(vxlan_work);
	mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);

unlock:
	mutex_unlock(&vxlan->sync_lock);
	return ret;
}

static void mlx5e_vxlan_del_port(struct work_struct *work)
int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
{
	struct mlx5e_vxlan_work *vxlan_work =
		container_of(work, struct mlx5e_vxlan_work, work);
	struct mlx5e_priv *priv         = vxlan_work->priv;
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	u16 port = vxlan_work->port;
	struct mlx5e_vxlan *vxlan;
	struct mlx5_vxlan_port *vxlanp;
	bool remove = false;
	int ret = 0;

	mutex_lock(&priv->state_lock);
	spin_lock_bh(&vxlan_db->lock);
	vxlan = radix_tree_lookup(&vxlan_db->tree, port);
	if (!vxlan)
	mutex_lock(&vxlan->sync_lock);

	spin_lock_bh(&vxlan->lock);
	vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port);
	if (!vxlanp) {
		ret = -ENOENT;
		goto out_unlock;
	}

	if (atomic_dec_and_test(&vxlan->refcount)) {
		radix_tree_delete(&vxlan_db->tree, port);
	if (atomic_dec_and_test(&vxlanp->refcount)) {
		hash_del(&vxlanp->hlist);
		remove = true;
	}

out_unlock:
	spin_unlock_bh(&vxlan_db->lock);
	spin_unlock_bh(&vxlan->lock);

	if (remove) {
		mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
		kfree(vxlan);
		mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
		kfree(vxlanp);
		vxlan->num_ports--;
	}
	mutex_unlock(&priv->state_lock);
	kfree(vxlan_work);

	mutex_unlock(&vxlan->sync_lock);

	return ret;
}

void mlx5e_vxlan_queue_work(struct mlx5e_priv *priv, sa_family_t sa_family,
			    u16 port, int add)
struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev)
{
	struct mlx5e_vxlan_work *vxlan_work;
	struct mlx5_vxlan *vxlan;

	vxlan_work = kmalloc(sizeof(*vxlan_work), GFP_ATOMIC);
	if (!vxlan_work)
		return;
	if (!MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan) || !mlx5_core_is_pf(mdev))
		return ERR_PTR(-ENOTSUPP);

	vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
	if (!vxlan)
		return ERR_PTR(-ENOMEM);

	if (add)
		INIT_WORK(&vxlan_work->work, mlx5e_vxlan_add_port);
	else
		INIT_WORK(&vxlan_work->work, mlx5e_vxlan_del_port);
	vxlan->mdev = mdev;
	mutex_init(&vxlan->sync_lock);
	spin_lock_init(&vxlan->lock);
	hash_init(vxlan->htable);

	vxlan_work->priv = priv;
	vxlan_work->port = port;
	vxlan_work->sa_family = sa_family;
	queue_work(priv->wq, &vxlan_work->work);
	/* Hardware adds 4789 by default */
	mlx5_vxlan_add_port(vxlan, 4789);

	return vxlan;
}

void mlx5e_vxlan_cleanup(struct mlx5e_priv *priv)
void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan)
{
	struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
	struct mlx5e_vxlan *vxlan;
	unsigned int port = 0;

	/* Lockless since we are the only radix-tree consumers, wq is disabled */
	while (radix_tree_gang_lookup(&vxlan_db->tree, (void **)&vxlan, port, 1)) {
		port = vxlan->udp_port;
		radix_tree_delete(&vxlan_db->tree, port);
		mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
		kfree(vxlan);
	struct mlx5_vxlan_port *vxlanp;
	struct hlist_node *tmp;
	int bkt;

	if (!mlx5_vxlan_allowed(vxlan))
		return;

	/* Lockless since we are the only hash table consumers*/
	hash_for_each_safe(vxlan->htable, bkt, tmp, vxlanp, hlist) {
		hash_del(&vxlanp->hlist);
		mlx5_vxlan_core_del_port_cmd(vxlan->mdev, vxlanp->udp_port);
		kfree(vxlanp);
	}

	kfree(vxlan);
}
Loading