Skip to content

Commit a1980cc

Browse files
committed
Merge branch 'implement-udp-tunnel-port-for-txgbe'
Jiawen Wu says: ==================== Implement udp tunnel port for txgbe v3: https://lore.kernel.org/[email protected] v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 84ee6e5 + 3b05aa9 commit a1980cc

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

drivers/net/ethernet/wangxun/libwx/wx_lib.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,33 @@ netdev_features_t wx_fix_features(struct net_device *netdev,
30003000
}
30013001
EXPORT_SYMBOL(wx_fix_features);
30023002

3003+
#define WX_MAX_TUNNEL_HDR_LEN 80
3004+
netdev_features_t wx_features_check(struct sk_buff *skb,
3005+
struct net_device *netdev,
3006+
netdev_features_t features)
3007+
{
3008+
struct wx *wx = netdev_priv(netdev);
3009+
3010+
if (!skb->encapsulation)
3011+
return features;
3012+
3013+
if (wx->mac.type == wx_mac_em)
3014+
return features & ~NETIF_F_CSUM_MASK;
3015+
3016+
if (unlikely(skb_inner_mac_header(skb) - skb_transport_header(skb) >
3017+
WX_MAX_TUNNEL_HDR_LEN))
3018+
return features & ~NETIF_F_CSUM_MASK;
3019+
3020+
if (skb->inner_protocol_type == ENCAP_TYPE_ETHER &&
3021+
skb->inner_protocol != htons(ETH_P_IP) &&
3022+
skb->inner_protocol != htons(ETH_P_IPV6) &&
3023+
skb->inner_protocol != htons(ETH_P_TEB))
3024+
return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
3025+
3026+
return features;
3027+
}
3028+
EXPORT_SYMBOL(wx_features_check);
3029+
30033030
void wx_set_ring(struct wx *wx, u32 new_tx_count,
30043031
u32 new_rx_count, struct wx_ring *temp_ring)
30053032
{

drivers/net/ethernet/wangxun/libwx/wx_lib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void wx_get_stats64(struct net_device *netdev,
3333
int wx_set_features(struct net_device *netdev, netdev_features_t features);
3434
netdev_features_t wx_fix_features(struct net_device *netdev,
3535
netdev_features_t features);
36+
netdev_features_t wx_features_check(struct sk_buff *skb,
37+
struct net_device *netdev,
38+
netdev_features_t features);
3639
void wx_set_ring(struct wx *wx, u32 new_tx_count,
3740
u32 new_rx_count, struct wx_ring *temp_ring);
3841

drivers/net/ethernet/wangxun/ngbe/ngbe_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ static const struct net_device_ops ngbe_netdev_ops = {
587587
.ndo_set_rx_mode = wx_set_rx_mode,
588588
.ndo_set_features = wx_set_features,
589589
.ndo_fix_features = wx_fix_features,
590+
.ndo_features_check = wx_features_check,
590591
.ndo_validate_addr = eth_validate_addr,
591592
.ndo_set_mac_address = wx_set_mac,
592593
.ndo_get_stats64 = wx_get_stats64,

drivers/net/ethernet/wangxun/txgbe/txgbe_main.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/string.h>
99
#include <linux/etherdevice.h>
1010
#include <linux/phylink.h>
11+
#include <net/udp_tunnel.h>
1112
#include <net/ip.h>
1213
#include <linux/if_vlan.h>
1314

@@ -537,6 +538,39 @@ void txgbe_do_reset(struct net_device *netdev)
537538
txgbe_reset(wx);
538539
}
539540

541+
static int txgbe_udp_tunnel_sync(struct net_device *dev, unsigned int table)
542+
{
543+
struct wx *wx = netdev_priv(dev);
544+
struct udp_tunnel_info ti;
545+
546+
udp_tunnel_nic_get_port(dev, table, 0, &ti);
547+
switch (ti.type) {
548+
case UDP_TUNNEL_TYPE_VXLAN:
549+
wr32(wx, TXGBE_CFG_VXLAN, ntohs(ti.port));
550+
break;
551+
case UDP_TUNNEL_TYPE_VXLAN_GPE:
552+
wr32(wx, TXGBE_CFG_VXLAN_GPE, ntohs(ti.port));
553+
break;
554+
case UDP_TUNNEL_TYPE_GENEVE:
555+
wr32(wx, TXGBE_CFG_GENEVE, ntohs(ti.port));
556+
break;
557+
default:
558+
break;
559+
}
560+
561+
return 0;
562+
}
563+
564+
static const struct udp_tunnel_nic_info txgbe_udp_tunnels = {
565+
.sync_table = txgbe_udp_tunnel_sync,
566+
.flags = UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
567+
.tables = {
568+
{ .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
569+
{ .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN_GPE, },
570+
{ .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_GENEVE, },
571+
},
572+
};
573+
540574
static const struct net_device_ops txgbe_netdev_ops = {
541575
.ndo_open = txgbe_open,
542576
.ndo_stop = txgbe_close,
@@ -545,6 +579,7 @@ static const struct net_device_ops txgbe_netdev_ops = {
545579
.ndo_set_rx_mode = wx_set_rx_mode,
546580
.ndo_set_features = wx_set_features,
547581
.ndo_fix_features = wx_fix_features,
582+
.ndo_features_check = wx_features_check,
548583
.ndo_validate_addr = eth_validate_addr,
549584
.ndo_set_mac_address = wx_set_mac,
550585
.ndo_get_stats64 = wx_get_stats64,
@@ -632,6 +667,7 @@ static int txgbe_probe(struct pci_dev *pdev,
632667
wx->driver_name = txgbe_driver_name;
633668
txgbe_set_ethtool_ops(netdev);
634669
netdev->netdev_ops = &txgbe_netdev_ops;
670+
netdev->udp_tunnel_nic_info = &txgbe_udp_tunnels;
635671

636672
/* setup the private structure */
637673
err = txgbe_sw_init(wx);
@@ -677,6 +713,7 @@ static int txgbe_probe(struct pci_dev *pdev,
677713
netdev->features |= NETIF_F_HIGHDMA;
678714
netdev->hw_features |= NETIF_F_GRO;
679715
netdev->features |= NETIF_F_GRO;
716+
netdev->features |= NETIF_F_RX_UDP_TUNNEL_PORT;
680717

681718
netdev->priv_flags |= IFF_UNICAST_FLT;
682719
netdev->priv_flags |= IFF_SUPP_NOFCS;

drivers/net/ethernet/wangxun/txgbe/txgbe_type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
/* Port cfg registers */
8989
#define TXGBE_CFG_PORT_ST 0x14404
9090
#define TXGBE_CFG_PORT_ST_LINK_UP BIT(0)
91+
#define TXGBE_CFG_VXLAN 0x14410
92+
#define TXGBE_CFG_VXLAN_GPE 0x14414
93+
#define TXGBE_CFG_GENEVE 0x14418
9194

9295
/* I2C registers */
9396
#define TXGBE_I2C_BASE 0x14900

0 commit comments

Comments
 (0)