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

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
...@@ -14,8 +14,8 @@ mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o \ ...@@ -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 fpga/ipsec.o fpga/tls.o
mlx5_core-$(CONFIG_MLX5_CORE_EN) += en_main.o en_common.o en_fs.o en_ethtool.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_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 en_arfs.o en_fs_ethtool.o en_selftest.o en/port.o lib/vxlan.o
mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o
......
...@@ -654,11 +654,6 @@ enum { ...@@ -654,11 +654,6 @@ enum {
MLX5E_STATE_DESTROYING, MLX5E_STATE_DESTROYING,
}; };
struct mlx5e_vxlan_db {
spinlock_t lock; /* protect vxlan table */
struct radix_tree_root tree;
};
struct mlx5e_l2_rule { struct mlx5e_l2_rule {
u8 addr[ETH_ALEN + 2]; u8 addr[ETH_ALEN + 2];
struct mlx5_flow_handle *rule; struct mlx5_flow_handle *rule;
...@@ -816,7 +811,6 @@ struct mlx5e_priv { ...@@ -816,7 +811,6 @@ struct mlx5e_priv {
u32 tx_rates[MLX5E_MAX_NUM_SQS]; u32 tx_rates[MLX5E_MAX_NUM_SQS];
struct mlx5e_flow_steering fs; struct mlx5e_flow_steering fs;
struct mlx5e_vxlan_db vxlan;
struct workqueue_struct *wq; struct workqueue_struct *wq;
struct work_struct update_carrier_work; struct work_struct update_carrier_work;
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#include "en_accel/tls.h" #include "en_accel/tls.h"
#include "accel/ipsec.h" #include "accel/ipsec.h"
#include "accel/tls.h" #include "accel/tls.h"
#include "vxlan.h" #include "lib/vxlan.h"
#include "en/port.h" #include "en/port.h"
#include "en/xdp.h" #include "en/xdp.h"
...@@ -2974,7 +2974,7 @@ int mlx5e_open(struct net_device *netdev) ...@@ -2974,7 +2974,7 @@ int mlx5e_open(struct net_device *netdev)
mlx5_set_port_admin_status(priv->mdev, MLX5_PORT_UP); mlx5_set_port_admin_status(priv->mdev, MLX5_PORT_UP);
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
if (mlx5e_vxlan_allowed(priv->mdev)) if (mlx5_vxlan_allowed(priv->mdev->vxlan))
udp_tunnel_get_rx_info(netdev); udp_tunnel_get_rx_info(netdev);
return err; return err;
...@@ -3969,6 +3969,57 @@ static int mlx5e_get_vf_stats(struct net_device *dev, ...@@ -3969,6 +3969,57 @@ static int mlx5e_get_vf_stats(struct net_device *dev,
} }
#endif #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, static void mlx5e_add_vxlan_port(struct net_device *netdev,
struct udp_tunnel_info *ti) struct udp_tunnel_info *ti)
{ {
...@@ -3977,10 +4028,10 @@ static void mlx5e_add_vxlan_port(struct net_device *netdev, ...@@ -3977,10 +4028,10 @@ static void mlx5e_add_vxlan_port(struct net_device *netdev,
if (ti->type != UDP_TUNNEL_TYPE_VXLAN) if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
return; return;
if (!mlx5e_vxlan_allowed(priv->mdev)) if (!mlx5_vxlan_allowed(priv->mdev->vxlan))
return; 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, static void mlx5e_del_vxlan_port(struct net_device *netdev,
...@@ -3991,10 +4042,10 @@ 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) if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
return; return;
if (!mlx5e_vxlan_allowed(priv->mdev)) if (!mlx5_vxlan_allowed(priv->mdev->vxlan))
return; 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, 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, ...@@ -4025,7 +4076,7 @@ static netdev_features_t mlx5e_tunnel_features_check(struct mlx5e_priv *priv,
port = be16_to_cpu(udph->dest); port = be16_to_cpu(udph->dest);
/* Verify if UDP port is being offloaded by HW */ /* 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; return features;
} }
...@@ -4597,7 +4648,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) ...@@ -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_CTAG_FILTER;
netdev->hw_features |= NETIF_F_HW_VLAN_STAG_TX; 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_IP_CSUM;
netdev->hw_enc_features |= NETIF_F_IPV6_CSUM; netdev->hw_enc_features |= NETIF_F_IPV6_CSUM;
netdev->hw_enc_features |= NETIF_F_TSO; netdev->hw_enc_features |= NETIF_F_TSO;
...@@ -4605,7 +4656,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) ...@@ -4605,7 +4656,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
netdev->hw_enc_features |= NETIF_F_GSO_PARTIAL; 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 | netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_GSO_UDP_TUNNEL_CSUM; NETIF_F_GSO_UDP_TUNNEL_CSUM;
netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL | netdev->hw_enc_features |= NETIF_F_GSO_UDP_TUNNEL |
...@@ -4716,14 +4767,12 @@ static void mlx5e_nic_init(struct mlx5_core_dev *mdev, ...@@ -4716,14 +4767,12 @@ static void mlx5e_nic_init(struct mlx5_core_dev *mdev,
mlx5_core_err(mdev, "TLS initialization failed, %d\n", err); mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
mlx5e_build_nic_netdev(netdev); mlx5e_build_nic_netdev(netdev);
mlx5e_build_tc2txq_maps(priv); mlx5e_build_tc2txq_maps(priv);
mlx5e_vxlan_init(priv);
} }
static void mlx5e_nic_cleanup(struct mlx5e_priv *priv) static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
{ {
mlx5e_tls_cleanup(priv); mlx5e_tls_cleanup(priv);
mlx5e_ipsec_cleanup(priv); mlx5e_ipsec_cleanup(priv);
mlx5e_vxlan_cleanup(priv);
} }
static int mlx5e_init_nic_rx(struct mlx5e_priv *priv) static int mlx5e_init_nic_rx(struct mlx5e_priv *priv)
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
#include "en_rep.h" #include "en_rep.h"
#include "en_tc.h" #include "en_tc.h"
#include "eswitch.h" #include "eswitch.h"
#include "vxlan.h" #include "lib/vxlan.h"
#include "fs_core.h" #include "fs_core.h"
#include "en/port.h" #include "en/port.h"
...@@ -1124,16 +1124,12 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv, ...@@ -1124,16 +1124,12 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
skb_flow_dissector_target(f->dissector, skb_flow_dissector_target(f->dissector,
FLOW_DISSECTOR_KEY_ENC_PORTS, FLOW_DISSECTOR_KEY_ENC_PORTS,
f->mask); 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 */ /* Full udp dst port must be given */
if (memchr_inv(&mask->dst, 0xff, sizeof(mask->dst))) if (memchr_inv(&mask->dst, 0xff, sizeof(mask->dst)))
goto vxlan_match_offload_err; 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)) MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap))
parse_vxlan_attr(spec, f); parse_vxlan_attr(spec, f);
else { else {
...@@ -2533,11 +2529,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2533,11 +2529,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
struct mlx5e_tc_flow *flow) struct mlx5e_tc_flow *flow)
{ {
struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; 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); 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 mlx5_esw_flow_attr *attr = flow->esw_attr;
struct ip_tunnel_key *key = &tun_info->key; struct ip_tunnel_key *key = &tun_info->key;
struct mlx5e_encap_entry *e; struct mlx5e_encap_entry *e;
...@@ -2557,7 +2549,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, ...@@ -2557,7 +2549,7 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv,
return -EOPNOTSUPP; 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)) { MLX5_CAP_ESW(priv->mdev, vxlan_encap_decap)) {
tunnel_type = MLX5_HEADER_TYPE_VXLAN; tunnel_type = MLX5_HEADER_TYPE_VXLAN;
} else { } else {
......
...@@ -36,15 +36,27 @@ ...@@ -36,15 +36,27 @@
#include "mlx5_core.h" #include "mlx5_core.h"
#include "vxlan.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; return MLX5_CAP_ETH(mdev, max_vxlan_udp_ports) ?: 4;
spin_lock_init(&vxlan_db->lock);
INIT_RADIX_TREE(&vxlan_db->tree, GFP_ATOMIC);
} }
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 in[MLX5_ST_SZ_DW(add_vxlan_udp_dport_in)] = {0};
u32 out[MLX5_ST_SZ_DW(add_vxlan_udp_dport_out)] = {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) ...@@ -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)); 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 in[MLX5_ST_SZ_DW(delete_vxlan_udp_dport_in)] = {0};
u32 out[MLX5_ST_SZ_DW(delete_vxlan_udp_dport_out)] = {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) ...@@ -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)); 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 mlx5_vxlan_port *vxlanp;
struct mlx5e_vxlan *vxlan;
spin_lock_bh(&vxlan_db->lock); hash_for_each_possible(vxlan->htable, vxlanp, hlist, port) {
vxlan = radix_tree_lookup(&vxlan_db->tree, port); if (vxlanp->udp_port == port)
spin_unlock_bh(&vxlan_db->lock); return vxlanp;
}
return vxlan; return NULL;
}
struct mlx5_vxlan_port *mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port)
{
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);
return vxlanp;
} }
static void mlx5e_vxlan_add_port(struct work_struct *work) int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
{ {
struct mlx5e_vxlan_work *vxlan_work = struct mlx5_vxlan_port *vxlanp;
container_of(work, struct mlx5e_vxlan_work, work); int ret = -ENOSPC;
struct mlx5e_priv *priv = vxlan_work->priv;
struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan; vxlanp = mlx5_vxlan_lookup_port(vxlan, port);
u16 port = vxlan_work->port; if (vxlanp) {
struct mlx5e_vxlan *vxlan; atomic_inc(&vxlanp->refcount);
int err; return 0;
mutex_lock(&priv->state_lock);
vxlan = mlx5e_vxlan_lookup_port(priv, port);
if (vxlan) {
atomic_inc(&vxlan->refcount);
goto free_work;
} }
if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port)) mutex_lock(&vxlan->sync_lock);
goto free_work; 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;
}
vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL); ret = mlx5_vxlan_core_add_port_cmd(vxlan->mdev, port);
if (!vxlan) if (ret)
goto unlock;
vxlanp = kzalloc(sizeof(*vxlanp), GFP_KERNEL);
if (!vxlanp) {
ret = -ENOMEM;
goto err_delete_port; goto err_delete_port;
}
vxlan->udp_port = port; vxlanp->udp_port = port;
atomic_set(&vxlan->refcount, 1); atomic_set(&vxlanp->refcount, 1);
spin_lock_bh(&vxlan_db->lock); spin_lock_bh(&vxlan->lock);
err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan); hash_add(vxlan->htable, &vxlanp->hlist, port);
spin_unlock_bh(&vxlan_db->lock); spin_unlock_bh(&vxlan->lock);
if (err)
goto err_free;
goto free_work; vxlan->num_ports++;
mutex_unlock(&vxlan->sync_lock);
return 0;
err_free:
kfree(vxlan);
err_delete_port: err_delete_port:
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port); mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
free_work:
mutex_unlock(&priv->state_lock); unlock:
kfree(vxlan_work); 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 = struct mlx5_vxlan_port *vxlanp;
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;
bool remove = false; bool remove = false;
int ret = 0;
mutex_lock(&priv->state_lock); mutex_lock(&vxlan->sync_lock);
spin_lock_bh(&vxlan_db->lock);
vxlan = radix_tree_lookup(&vxlan_db->tree, port); spin_lock_bh(&vxlan->lock);
if (!vxlan) vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port);
if (!vxlanp) {
ret = -ENOENT;
goto out_unlock; goto out_unlock;
}
if (atomic_dec_and_test(&vxlan->refcount)) { if (atomic_dec_and_test(&vxlanp->refcount)) {
radix_tree_delete(&vxlan_db->tree, port); hash_del(&vxlanp->hlist);
remove = true; remove = true;
} }
out_unlock: out_unlock:
spin_unlock_bh(&vxlan_db->lock); spin_unlock_bh(&vxlan->lock);
if (remove) { if (remove) {
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port); mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
kfree(vxlan); 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, struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev)
u16 port, int add)
{ {
struct mlx5e_vxlan_work *vxlan_work; struct mlx5_vxlan *vxlan;
vxlan_work = kmalloc(sizeof(*vxlan_work), GFP_ATOMIC); if (!MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan) || !mlx5_core_is_pf(mdev))
if (!vxlan_work) return ERR_PTR(-ENOTSUPP);
return;
vxlan = kzalloc(sizeof(*vxlan), GFP_KERNEL);
if (!vxlan)
return ERR_PTR(-ENOMEM);
if (add) vxlan->mdev = mdev;
INIT_WORK(&vxlan_work->work, mlx5e_vxlan_add_port); mutex_init(&vxlan->sync_lock);
else spin_lock_init(&vxlan->lock);
INIT_WORK(&vxlan_work->work, mlx5e_vxlan_del_port); hash_init(vxlan->htable);
vxlan_work->priv = priv; /* Hardware adds 4789 by default */
vxlan_work->port = port; mlx5_vxlan_add_port(vxlan, 4789);
vxlan_work->sa_family = sa_family;
queue_work(priv->wq, &vxlan_work->work); 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 mlx5_vxlan_port *vxlanp;
struct mlx5e_vxlan *vxlan; struct hlist_node *tmp;
unsigned int port = 0; int bkt;
/* Lockless since we are the only radix-tree consumers, wq is disabled */ if (!mlx5_vxlan_allowed(vxlan))
while (radix_tree_gang_lookup(&vxlan_db->tree, (void **)&vxlan, port, 1)) { return;
port = vxlan->udp_port;
radix_tree_delete(&vxlan_db->tree, port); /* Lockless since we are the only hash table consumers*/
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port); hash_for_each_safe(vxlan->htable, bkt, tmp, vxlanp, hlist) {
kfree(vxlan); hash_del(&vxlanp->hlist);
mlx5_vxlan_core_del_port_cmd(vxlan->mdev, vxlanp->udp_port);
kfree(vxlanp);
} }
kfree(vxlan);
} }
...@@ -33,31 +33,32 @@ ...@@ -33,31 +33,32 @@
#define __MLX5_VXLAN_H__ #define __MLX5_VXLAN_H__
#include <linux/mlx5/driver.h> #include <linux/mlx5/driver.h>
#include "en.h"
struct mlx5e_vxlan { struct mlx5_vxlan;
atomic_t refcount; struct mlx5_vxlan_port;
u16 udp_port;
};
struct mlx5e_vxlan_work { #ifdef CONFIG_MLX5_CORE_EN
struct work_struct work;
struct mlx5e_priv *priv;
sa_family_t sa_family;
u16 port;
};
static inline bool mlx5e_vxlan_allowed(struct mlx5_core_dev *mdev) static inline bool mlx5_vxlan_allowed(struct mlx5_vxlan *vxlan)
{ {
return (MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan) && /* not allowed reason is encoded in vxlan pointer as error,
mlx5_core_is_pf(mdev)); * on mlx5_vxlan_create
*/
return !IS_ERR_OR_NULL(vxlan);
} }
void mlx5e_vxlan_init(struct mlx5e_priv *priv); struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev);
void mlx5e_vxlan_cleanup(struct mlx5e_priv *priv); void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan);
int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port);
int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port);
struct mlx5_vxlan_port *mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port);
#else
static inline struct mlx5_vxlan*
mlx5_vxlan_create(struct mlx5_core_dev *mdev) { return ERR_PTR(-ENOTSUPP); }
static inline void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan) { return; }
void mlx5e_vxlan_queue_work(struct mlx5e_priv *priv, sa_family_t sa_family, #endif
u16 port, int add);
struct mlx5e_vxlan *mlx5e_vxlan_lookup_port(struct mlx5e_priv *priv, u16 port);
#endif /* __MLX5_VXLAN_H__ */ #endif /* __MLX5_VXLAN_H__ */
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "accel/ipsec.h" #include "accel/ipsec.h"
#include "accel/tls.h" #include "accel/tls.h"
#include "lib/clock.h" #include "lib/clock.h"
#include "lib/vxlan.h"
#include "diag/fw_tracer.h" #include "diag/fw_tracer.h"
MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
...@@ -961,6 +962,8 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv) ...@@ -961,6 +962,8 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
mlx5_init_clock(dev); mlx5_init_clock(dev);
dev->vxlan = mlx5_vxlan_create(dev);
err = mlx5_init_rl_table(dev); err = mlx5_init_rl_table(dev);
if (err) { if (err) {
dev_err(&pdev->dev, "Failed to init rate limiting\n"); dev_err(&pdev->dev, "Failed to init rate limiting\n");
...@@ -1004,6 +1007,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv) ...@@ -1004,6 +1007,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
err_rl_cleanup: err_rl_cleanup:
mlx5_cleanup_rl_table(dev); mlx5_cleanup_rl_table(dev);
err_tables_cleanup: err_tables_cleanup:
mlx5_vxlan_destroy(dev->vxlan);
mlx5_cleanup_mkey_table(dev); mlx5_cleanup_mkey_table(dev);
mlx5_cleanup_srq_table(dev); mlx5_cleanup_srq_table(dev);
mlx5_cleanup_qp_table(dev); mlx5_cleanup_qp_table(dev);
...@@ -1024,6 +1028,7 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev) ...@@ -1024,6 +1028,7 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
mlx5_eswitch_cleanup(dev->priv.eswitch); mlx5_eswitch_cleanup(dev->priv.eswitch);
mlx5_mpfs_cleanup(dev); mlx5_mpfs_cleanup(dev);
mlx5_cleanup_rl_table(dev); mlx5_cleanup_rl_table(dev);
mlx5_vxlan_destroy(dev->vxlan);
mlx5_cleanup_clock(dev); mlx5_cleanup_clock(dev);
mlx5_cleanup_reserved_gids(dev); mlx5_cleanup_reserved_gids(dev);
mlx5_cleanup_mkey_table(dev); mlx5_cleanup_mkey_table(dev);
......
...@@ -818,6 +818,7 @@ struct mlx5_clock { ...@@ -818,6 +818,7 @@ struct mlx5_clock {
}; };
struct mlx5_fw_tracer; struct mlx5_fw_tracer;
struct mlx5_vxlan;
struct mlx5_core_dev { struct mlx5_core_dev {
struct pci_dev *pdev; struct pci_dev *pdev;
...@@ -850,6 +851,7 @@ struct mlx5_core_dev { ...@@ -850,6 +851,7 @@ struct mlx5_core_dev {
atomic_t num_qps; atomic_t num_qps;
u32 issi; u32 issi;
struct mlx5e_resources mlx5e_res; struct mlx5e_resources mlx5e_res;
struct mlx5_vxlan *vxlan;
struct { struct {
struct mlx5_rsvd_gids reserved_gids; struct mlx5_rsvd_gids reserved_gids;
u32 roce_en; u32 roce_en;
......
...@@ -668,7 +668,9 @@ struct mlx5_ifc_per_protocol_networking_offload_caps_bits { ...@@ -668,7 +668,9 @@ struct mlx5_ifc_per_protocol_networking_offload_caps_bits {
u8 swp[0x1]; u8 swp[0x1];
u8 swp_csum[0x1]; u8 swp_csum[0x1];
u8 swp_lso[0x1]; u8 swp_lso[0x1];
u8 reserved_at_23[0x1b]; u8 reserved_at_23[0xd];
u8 max_vxlan_udp_ports[0x8];
u8 reserved_at_38[0x6];
u8 max_geneve_opt_len[0x1]; u8 max_geneve_opt_len[0x1];
u8 tunnel_stateless_geneve_rx[0x1]; u8 tunnel_stateless_geneve_rx[0x1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment