]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: txgbe: Support to set UDP tunnel port
authorJiawen Wu <jiawenwu@trustnetic.com>
Mon, 21 Apr 2025 02:29:55 +0000 (10:29 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Apr 2025 02:53:35 +0000 (19:53 -0700)
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@trustnetic.com>
Link: https://patch.msgid.link/20250421022956.508018-2-jiawenwu@trustnetic.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
drivers/net/ethernet/wangxun/txgbe/txgbe_type.h

index d40db6b42200191c7392de7f816ad04a2114babb..dcfccc6d963a55d748ffc496340bb1e08d32bc41 100644 (file)
@@ -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>
 
@@ -537,6 +538,39 @@ void txgbe_do_reset(struct net_device *netdev)
                txgbe_reset(wx);
 }
 
+static int txgbe_udp_tunnel_sync(struct net_device *dev, unsigned int table)
+{
+       struct wx *wx = netdev_priv(dev);
+       struct udp_tunnel_info ti;
+
+       udp_tunnel_nic_get_port(dev, table, 0, &ti);
+       switch (ti.type) {
+       case UDP_TUNNEL_TYPE_VXLAN:
+               wr32(wx, TXGBE_CFG_VXLAN, ntohs(ti.port));
+               break;
+       case UDP_TUNNEL_TYPE_VXLAN_GPE:
+               wr32(wx, TXGBE_CFG_VXLAN_GPE, ntohs(ti.port));
+               break;
+       case UDP_TUNNEL_TYPE_GENEVE:
+               wr32(wx, TXGBE_CFG_GENEVE, ntohs(ti.port));
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static const struct udp_tunnel_nic_info txgbe_udp_tunnels = {
+       .sync_table     = txgbe_udp_tunnel_sync,
+       .flags          = UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
+       .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 +666,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 +712,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;
index 5937cbc6bd05799dd6919259f27de297b983a394..cb553318641da935e0f2a619ac6f7dceabe79cef 100644 (file)
@@ -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