aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2020-07-14 12:18:19 -0700
committerDavid S. Miller <davem@davemloft.net>2020-07-14 17:04:27 -0700
commit641ca08547f83bd265477150a66cf2378bc98ed7 (patch)
tree5f6d572c53c1901d310d1272b558dd74cee543f9 /drivers/net/ethernet/netronome/nfp/nfp_net_common.c
parentMerge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next (diff)
downloadlinux-dev-641ca08547f83bd265477150a66cf2378bc98ed7.tar.xz
linux-dev-641ca08547f83bd265477150a66cf2378bc98ed7.zip
nfp: convert to new udp_tunnel_nic infra
NFP conversion is pretty straightforward. We want to be able to sleep, and only get callbacks when the device is open. NFP did not ask for port replay when ports were removed, now new infra will provide this feature for free. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/netronome/nfp/nfp_net_common.c')
-rw-r--r--drivers/net/ethernet/netronome/nfp/nfp_net_common.c126
1 files changed, 34 insertions, 92 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 83ff18140bfe..44608873d3d9 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -2867,15 +2867,6 @@ static int nfp_net_set_config_and_enable(struct nfp_net *nn)
for (r = 0; r < nn->dp.num_rx_rings; r++)
nfp_net_rx_ring_fill_freelist(&nn->dp, &nn->dp.rx_rings[r]);
- /* Since reconfiguration requests while NFP is down are ignored we
- * have to wipe the entire VXLAN configuration and reinitialize it.
- */
- if (nn->dp.ctrl & NFP_NET_CFG_CTRL_VXLAN) {
- memset(&nn->vxlan_ports, 0, sizeof(nn->vxlan_ports));
- memset(&nn->vxlan_usecnt, 0, sizeof(nn->vxlan_usecnt));
- udp_tunnel_get_rx_info(nn->dp.netdev);
- }
-
return 0;
}
@@ -3566,87 +3557,6 @@ nfp_net_get_phys_port_name(struct net_device *netdev, char *name, size_t len)
return 0;
}
-/**
- * nfp_net_set_vxlan_port() - set vxlan port in SW and reconfigure HW
- * @nn: NFP Net device to reconfigure
- * @idx: Index into the port table where new port should be written
- * @port: UDP port to configure (pass zero to remove VXLAN port)
- */
-static void nfp_net_set_vxlan_port(struct nfp_net *nn, int idx, __be16 port)
-{
- int i;
-
- nn->vxlan_ports[idx] = port;
-
- if (!(nn->dp.ctrl & NFP_NET_CFG_CTRL_VXLAN))
- return;
-
- BUILD_BUG_ON(NFP_NET_N_VXLAN_PORTS & 1);
- for (i = 0; i < NFP_NET_N_VXLAN_PORTS; i += 2)
- nn_writel(nn, NFP_NET_CFG_VXLAN_PORT + i * sizeof(port),
- be16_to_cpu(nn->vxlan_ports[i + 1]) << 16 |
- be16_to_cpu(nn->vxlan_ports[i]));
-
- nfp_net_reconfig_post(nn, NFP_NET_CFG_UPDATE_VXLAN);
-}
-
-/**
- * nfp_net_find_vxlan_idx() - find table entry of the port or a free one
- * @nn: NFP Network structure
- * @port: UDP port to look for
- *
- * Return: if the port is already in the table -- it's position;
- * if the port is not in the table -- free position to use;
- * if the table is full -- -ENOSPC.
- */
-static int nfp_net_find_vxlan_idx(struct nfp_net *nn, __be16 port)
-{
- int i, free_idx = -ENOSPC;
-
- for (i = 0; i < NFP_NET_N_VXLAN_PORTS; i++) {
- if (nn->vxlan_ports[i] == port)
- return i;
- if (!nn->vxlan_usecnt[i])
- free_idx = i;
- }
-
- return free_idx;
-}
-
-static void nfp_net_add_vxlan_port(struct net_device *netdev,
- struct udp_tunnel_info *ti)
-{
- struct nfp_net *nn = netdev_priv(netdev);
- int idx;
-
- if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
- return;
-
- idx = nfp_net_find_vxlan_idx(nn, ti->port);
- if (idx == -ENOSPC)
- return;
-
- if (!nn->vxlan_usecnt[idx]++)
- nfp_net_set_vxlan_port(nn, idx, ti->port);
-}
-
-static void nfp_net_del_vxlan_port(struct net_device *netdev,
- struct udp_tunnel_info *ti)
-{
- struct nfp_net *nn = netdev_priv(netdev);
- int idx;
-
- if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
- return;
-
- idx = nfp_net_find_vxlan_idx(nn, ti->port);
- if (idx == -ENOSPC || !nn->vxlan_usecnt[idx])
- return;
-
- if (!--nn->vxlan_usecnt[idx])
- nfp_net_set_vxlan_port(nn, idx, 0);
-}
-
static int nfp_net_xdp_setup_drv(struct nfp_net *nn, struct netdev_bpf *bpf)
{
struct bpf_prog *prog = bpf->prog;
@@ -3757,12 +3667,43 @@ const struct net_device_ops nfp_net_netdev_ops = {
.ndo_set_features = nfp_net_set_features,
.ndo_features_check = nfp_net_features_check,
.ndo_get_phys_port_name = nfp_net_get_phys_port_name,
- .ndo_udp_tunnel_add = nfp_net_add_vxlan_port,
- .ndo_udp_tunnel_del = nfp_net_del_vxlan_port,
+ .ndo_udp_tunnel_add = udp_tunnel_nic_add_port,
+ .ndo_udp_tunnel_del = udp_tunnel_nic_del_port,
.ndo_bpf = nfp_net_xdp,
.ndo_get_devlink_port = nfp_devlink_get_devlink_port,
};
+static int nfp_udp_tunnel_sync(struct net_device *netdev, unsigned int table)
+{
+ struct nfp_net *nn = netdev_priv(netdev);
+ int i;
+
+ BUILD_BUG_ON(NFP_NET_N_VXLAN_PORTS & 1);
+ for (i = 0; i < NFP_NET_N_VXLAN_PORTS; i += 2) {
+ struct udp_tunnel_info ti0, ti1;
+
+ udp_tunnel_nic_get_port(netdev, table, i, &ti0);
+ udp_tunnel_nic_get_port(netdev, table, i + 1, &ti1);
+
+ nn_writel(nn, NFP_NET_CFG_VXLAN_PORT + i * sizeof(ti0.port),
+ be16_to_cpu(ti1.port) << 16 | be16_to_cpu(ti0.port));
+ }
+
+ return nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_VXLAN);
+}
+
+static const struct udp_tunnel_nic_info nfp_udp_tunnels = {
+ .sync_table = nfp_udp_tunnel_sync,
+ .flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP |
+ UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
+ .tables = {
+ {
+ .n_entries = NFP_NET_N_VXLAN_PORTS,
+ .tunnel_types = UDP_TUNNEL_TYPE_VXLAN,
+ },
+ },
+};
+
/**
* nfp_net_info() - Print general info about the NIC
* @nn: NFP Net device to reconfigure
@@ -4010,6 +3951,7 @@ static void nfp_net_netdev_init(struct nfp_net *nn)
if (nn->cap & NFP_NET_CFG_CTRL_VXLAN) {
if (nn->cap & NFP_NET_CFG_CTRL_LSO)
netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
+ netdev->udp_tunnel_nic_info = &nfp_udp_tunnels;
nn->dp.ctrl |= NFP_NET_CFG_CTRL_VXLAN;
}
if (nn->cap & NFP_NET_CFG_CTRL_NVGRE) {