diff mbox series

[net-next,v3,1/2] net: txgbe: Support to set UDP tunnel port

Message ID 20250417080328.426554-2-jiawenwu@trustnetic.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series Implement udp tunnel port for txgbe | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 77 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 6 this patch: 6
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-04-18--09-00 (tests: 916)

Commit Message

Jiawen Wu April 17, 2025, 8:03 a.m. UTC
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>
---
 .../net/ethernet/wangxun/txgbe/txgbe_main.c   | 38 +++++++++++++++++++
 .../net/ethernet/wangxun/txgbe/txgbe_type.h   |  3 ++
 2 files changed, 41 insertions(+)

Comments

Jakub Kicinski April 17, 2025, 11:57 p.m. UTC | #1
On Thu, 17 Apr 2025 16:03:27 +0800 Jiawen Wu wrote:
> @@ -392,6 +393,8 @@ static int txgbe_open(struct net_device *netdev)
                                 ^^^^^^^^^^
>  
>  	txgbe_up_complete(wx);
>  
> +	udp_tunnel_nic_reset_ntf(netdev);
        ^^^^^^^^^^^^^^^^^^^^^^^^
>  	return 0;

> +	.flags		= UDP_TUNNEL_NIC_INFO_OPEN_ONLY,

Documentation says:

        /* Device only supports offloads when it's open, all ports
         * will be removed before close and re-added after open.
         */
        UDP_TUNNEL_NIC_INFO_OPEN_ONLY   = BIT(1),

Are you sure you have to explicitly reset?
Jiawen Wu April 18, 2025, 1:44 a.m. UTC | #2
On Fri, Apr 18, 2025 7:58 AM, Jakub Kicinski wrote:
> On Thu, 17 Apr 2025 16:03:27 +0800 Jiawen Wu wrote:
> > @@ -392,6 +393,8 @@ static int txgbe_open(struct net_device *netdev)
>                                  ^^^^^^^^^^
> >
> >  	txgbe_up_complete(wx);
> >
> > +	udp_tunnel_nic_reset_ntf(netdev);
>         ^^^^^^^^^^^^^^^^^^^^^^^^
> >  	return 0;
> 
> > +	.flags		= UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
> 
> Documentation says:
> 
>         /* Device only supports offloads when it's open, all ports
>          * will be removed before close and re-added after open.
>          */
>         UDP_TUNNEL_NIC_INFO_OPEN_ONLY   = BIT(1),
> 
> Are you sure you have to explicitly reset?

Yes. Stop device will reset hardware, which reset UDP port to the default value.
So it has to re-configure the ports.
Jakub Kicinski April 18, 2025, 2:19 a.m. UTC | #3
On Fri, 18 Apr 2025 09:44:00 +0800 Jiawen Wu wrote:
> On Fri, Apr 18, 2025 7:58 AM, Jakub Kicinski wrote:
> > On Thu, 17 Apr 2025 16:03:27 +0800 Jiawen Wu wrote:  
> > > @@ -392,6 +393,8 @@ static int txgbe_open(struct net_device *netdev)  
> >                                  ^^^^^^^^^^  
> > >
> > >  	txgbe_up_complete(wx);
> > >
> > > +	udp_tunnel_nic_reset_ntf(netdev);  
> >         ^^^^^^^^^^^^^^^^^^^^^^^^  
> > >  	return 0;  
> >   
> > > +	.flags		= UDP_TUNNEL_NIC_INFO_OPEN_ONLY,  
> > 
> > Documentation says:
> > 
> >         /* Device only supports offloads when it's open, all ports
> >          * will be removed before close and re-added after open.
> >          */
> >         UDP_TUNNEL_NIC_INFO_OPEN_ONLY   = BIT(1),
> > 
> > Are you sure you have to explicitly reset?  
> 
> Yes. Stop device will reset hardware, which reset UDP port to the default value.
> So it has to re-configure the ports.

My point is that this is basically what the
UDP_TUNNEL_NIC_INFO_OPEN_ONLY flag already assumes.
There should be no need to reset if you already told the core 
with the flag that the device forgets everything when closed.

Could you retest without the reset_ntf ?
Jiawen Wu April 18, 2025, 2:36 a.m. UTC | #4
On Fri, Apr 18, 2025 10:20 AM, Jakub Kicinski wrote:
> On Fri, 18 Apr 2025 09:44:00 +0800 Jiawen Wu wrote:
> > On Fri, Apr 18, 2025 7:58 AM, Jakub Kicinski wrote:
> > > On Thu, 17 Apr 2025 16:03:27 +0800 Jiawen Wu wrote:
> > > > @@ -392,6 +393,8 @@ static int txgbe_open(struct net_device *netdev)
> > >                                  ^^^^^^^^^^
> > > >
> > > >  	txgbe_up_complete(wx);
> > > >
> > > > +	udp_tunnel_nic_reset_ntf(netdev);
> > >         ^^^^^^^^^^^^^^^^^^^^^^^^
> > > >  	return 0;
> > >
> > > > +	.flags		= UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
> > >
> > > Documentation says:
> > >
> > >         /* Device only supports offloads when it's open, all ports
> > >          * will be removed before close and re-added after open.
> > >          */
> > >         UDP_TUNNEL_NIC_INFO_OPEN_ONLY   = BIT(1),
> > >
> > > Are you sure you have to explicitly reset?
> >
> > Yes. Stop device will reset hardware, which reset UDP port to the default value.
> > So it has to re-configure the ports.
> 
> My point is that this is basically what the
> UDP_TUNNEL_NIC_INFO_OPEN_ONLY flag already assumes.
> There should be no need to reset if you already told the core
> with the flag that the device forgets everything when closed.
> 
> Could you retest without the reset_ntf ?

Thanks for the guidance.
The test result looks the same as before, when I remove reset_ntf.
I'll fix it in patch v4. :)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
index 6d9134a3ce4d..95e5262a1e9c 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,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 +668,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 +714,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..cb553318641d 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