[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250410074456.321847-2-jiawenwu@trustnetic.com>
Date: Thu, 10 Apr 2025 15:44:55 +0800
From: Jiawen Wu <jiawenwu@...stnetic.com>
To: netdev@...r.kernel.org,
andrew+netdev@...n.ch,
davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
horms@...nel.org,
dlemoal@...nel.org,
jdamato@...tly.com,
saikrishnag@...vell.com,
vadim.fedorenko@...ux.dev,
przemyslaw.kitszel@...el.com,
ecree.xilinx@...il.com,
rmk+kernel@...linux.org.uk
Cc: mengyuanlou@...-swift.com,
Jiawen Wu <jiawenwu@...stnetic.com>
Subject: [PATCH net-next 1/2] net: txgbe: Support to set UDP tunnel port
Tunnel types VXLAN/VXLAN_GPE/GENEVE are supported for txgbe devices. The
hardware supports to set only one port for each tunnel type.
Signed-off-by: Jiawen Wu <jiawenwu@...stnetic.com>
---
.../net/ethernet/wangxun/txgbe/txgbe_main.c | 113 ++++++++++++++++++
.../net/ethernet/wangxun/txgbe/txgbe_type.h | 8 ++
2 files changed, 121 insertions(+)
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
index 6d9134a3ce4d..c984745504b4 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
@@ -8,6 +8,7 @@
#include <linux/string.h>
#include <linux/etherdevice.h>
#include <linux/phylink.h>
+#include <net/udp_tunnel.h>
#include <net/ip.h>
#include <linux/if_vlan.h>
@@ -392,6 +393,8 @@ static int txgbe_open(struct net_device *netdev)
txgbe_up_complete(wx);
+ udp_tunnel_nic_reset_ntf(netdev);
+
return 0;
err_free_irq:
@@ -537,6 +540,114 @@ void txgbe_do_reset(struct net_device *netdev)
txgbe_reset(wx);
}
+static int txgbe_udp_tunnel_set(struct net_device *dev, unsigned int table,
+ unsigned int entry, struct udp_tunnel_info *ti)
+{
+ struct wx *wx = netdev_priv(dev);
+ struct txgbe *txgbe = wx->priv;
+
+ switch (ti->type) {
+ case UDP_TUNNEL_TYPE_VXLAN:
+ if (txgbe->vxlan_port == ti->port)
+ break;
+
+ if (txgbe->vxlan_port) {
+ wx_err(wx, "VXLAN port %d set, not adding port %d\n",
+ txgbe->vxlan_port, ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->vxlan_port = ti->port;
+ wr32(wx, TXGBE_CFG_VXLAN, ntohs(ti->port));
+ break;
+ case UDP_TUNNEL_TYPE_VXLAN_GPE:
+ if (txgbe->vxlan_gpe_port == ti->port)
+ break;
+
+ if (txgbe->vxlan_gpe_port) {
+ wx_err(wx, "VXLAN-GPE port %d set, not adding port %d\n",
+ txgbe->vxlan_gpe_port, ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->vxlan_gpe_port = ti->port;
+ wr32(wx, TXGBE_CFG_VXLAN_GPE, ntohs(ti->port));
+ break;
+ case UDP_TUNNEL_TYPE_GENEVE:
+ if (txgbe->geneve_port == ti->port)
+ break;
+
+ if (txgbe->geneve_port) {
+ wx_err(wx, "GENEVE port %d set, not adding port %d\n",
+ txgbe->geneve_port, ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->geneve_port = ti->port;
+ wr32(wx, TXGBE_CFG_GENEVE, ntohs(ti->port));
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int txgbe_udp_tunnel_unset(struct net_device *dev,
+ unsigned int table, unsigned int entry,
+ struct udp_tunnel_info *ti)
+{
+ struct wx *wx = netdev_priv(dev);
+ struct txgbe *txgbe = wx->priv;
+
+ if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
+ ti->type != UDP_TUNNEL_TYPE_VXLAN_GPE &&
+ ti->type != UDP_TUNNEL_TYPE_GENEVE)
+ return -EINVAL;
+
+ switch (ti->type) {
+ case UDP_TUNNEL_TYPE_VXLAN:
+ if (txgbe->vxlan_port != ti->port) {
+ wx_err(wx, "VXLAN port %d not found\n", ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->vxlan_port = 0;
+ break;
+ case UDP_TUNNEL_TYPE_VXLAN_GPE:
+ if (txgbe->vxlan_gpe_port != ti->port) {
+ wx_err(wx, "VXLAN-GPE port %d not found\n", ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->vxlan_gpe_port = 0;
+ break;
+ case UDP_TUNNEL_TYPE_GENEVE:
+ if (txgbe->geneve_port != ti->port) {
+ wx_err(wx, "GENEVE port %d not found\n", ti->port);
+ return -EINVAL;
+ }
+
+ txgbe->geneve_port = 0;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static const struct udp_tunnel_nic_info txgbe_udp_tunnels = {
+ .set_port = txgbe_udp_tunnel_set,
+ .unset_port = txgbe_udp_tunnel_unset,
+ .flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP,
+ .tables = {
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN_GPE, },
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_GENEVE, },
+ },
+};
+
static const struct net_device_ops txgbe_netdev_ops = {
.ndo_open = txgbe_open,
.ndo_stop = txgbe_close,
@@ -632,6 +743,7 @@ static int txgbe_probe(struct pci_dev *pdev,
wx->driver_name = txgbe_driver_name;
txgbe_set_ethtool_ops(netdev);
netdev->netdev_ops = &txgbe_netdev_ops;
+ netdev->udp_tunnel_nic_info = &txgbe_udp_tunnels;
/* setup the private structure */
err = txgbe_sw_init(wx);
@@ -677,6 +789,7 @@ static int txgbe_probe(struct pci_dev *pdev,
netdev->features |= NETIF_F_HIGHDMA;
netdev->hw_features |= NETIF_F_GRO;
netdev->features |= NETIF_F_GRO;
+ netdev->features |= NETIF_F_RX_UDP_TUNNEL_PORT;
netdev->priv_flags |= IFF_UNICAST_FLT;
netdev->priv_flags |= IFF_SUPP_NOFCS;
diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
index 5937cbc6bd05..67ea81dfe786 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
@@ -88,6 +88,9 @@
/* Port cfg registers */
#define TXGBE_CFG_PORT_ST 0x14404
#define TXGBE_CFG_PORT_ST_LINK_UP BIT(0)
+#define TXGBE_CFG_VXLAN 0x14410
+#define TXGBE_CFG_VXLAN_GPE 0x14414
+#define TXGBE_CFG_GENEVE 0x14418
/* I2C registers */
#define TXGBE_I2C_BASE 0x14900
@@ -359,6 +362,11 @@ struct txgbe {
union txgbe_atr_input fdir_mask;
int fdir_filter_count;
spinlock_t fdir_perfect_lock; /* spinlock for FDIR */
+
+ /* tunnel port */
+ __be16 vxlan_port;
+ __be16 geneve_port;
+ __be16 vxlan_gpe_port;
};
#endif /* _TXGBE_TYPE_H_ */
--
2.27.0
Powered by blists - more mailing lists