enic: add vxlan offload support
Subsystems (3)
v2 cover enic: add vxlan offload support
This series adds vxlan offload support for enic driver. The first patch adds vxlan devcmd for configuring vxland offload parameters. Second patch adds ndo_udp_tunnel_add/del and offload on rx path. There are to modes in which fw supports vxlan offload.
mode 0: fcoe bit is set for encapsulated packet. fcoe_fc_crc_ok is set if checksum of csum is ok. This bit is or of ip_csum_ok and tcp_udp_csum_ok
mode 2: BIT(0) in rss_hash is set if it is encapsulated packet.
BIT(1) is set if outer_ip_csum_ok/
BIT(2) is set if outer_tcp_csum_ok
Some hw supports only mode 0, some support mode 0 and 2. Driver gets the supported modes bitmap using get_supported_feature_ver devcmd and selects the highest mode both driver and fw supports.
Third patch adds offload support on tx path by adding enic_features_check().
v2: Order local variable declarations from longest to shortest line,
on all three patches.
Govindarajulu Varadarajan (3):
enic: add devcmds for vxlan offload
enic: add udp_tunnel ndo for vxlan offload
enic: add vxlan offload on tx path
drivers/net/ethernet/cisco/enic/enic.h | 6 + drivers/net/ethernet/cisco/enic/enic_main.c | 282 ++++++++++++++++++++++++-- drivers/net/ethernet/cisco/enic/vnic_dev.c | 34 ++++ drivers/net/ethernet/cisco/enic/vnic_dev.h | 5 + drivers/net/ethernet/cisco/enic/vnic_devcmd.h | 51 +++++ drivers/net/ethernet/cisco/enic/vnic_enet.h | 1 + 6 files changed, 364 insertions(+), 15 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/3 enic: add devcmds for vxlan offload
This patch adds devcmds needed for vxlan offload. Implement 3 new devcmd
overlay_offload_ctrl: enable/disable offloadoverlay_offload_cfg: update offload udp port numberget_supported_feature_ver: get hw supported offload version. Each
version has different bitmap for csum_ok/encap
--- drivers/net/ethernet/cisco/enic/vnic_dev.c | 34 ++++++++++++++++++ drivers/net/ethernet/cisco/enic/vnic_dev.h | 5 +++ drivers/net/ethernet/cisco/enic/vnic_devcmd.h | 51 +++++++++++++++++++++++++++ drivers/net/ethernet/cisco/enic/vnic_enet.h | 1 + 4 files changed, 91 insertions(+)
drivers/net/ethernet/cisco/enic/vnic_dev.c +34 -0
@@ -1247,3 +1247,37 @@ int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,return ret; } + +int vnic_dev_overlay_offload_ctrl (struct vnic_dev *vdev,u8 overlay,u8 config) +{ +u64 a0 = overlay; +u64 a1 = config; +int wait =1000 ; + +return vnic_dev_cmd (vdev,CMD_OVERLAY_OFFLOAD_CTRL , &a0, &a1, wait); +} + +int vnic_dev_overlay_offload_cfg (struct vnic_dev *vdev,u8 overlay, +u16 vxlan_udp_port_number) +{ +u64 a1 = vxlan_udp_port_number; +u64 a0 = overlay; +int wait =1000 ; + +return vnic_dev_cmd (vdev,CMD_OVERLAY_OFFLOAD_CFG , &a0, &a1, wait); +} + +int vnic_dev_get_supported_feature_ver (struct vnic_dev *vdev,u8 feature, +u64 *supported_versions) +{ +u64 a0 = feature; +int wait =1000 ; +u64 a1 =0 ; +int ret; + + ret =vnic_dev_cmd (vdev,CMD_GET_SUPP_FEATURE_VER , &a0, &a1, wait); +if (!ret) + *supported_versions = a0; + +return ret; +}
drivers/net/ethernet/cisco/enic/vnic_dev.h +5 -0
@@ -179,5 +179,10 @@ int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr);int vnic_dev_classifier (struct vnic_dev *vdev,u8 cmd,u16 *entry,struct filter *data);int vnic_devcmd_init (struct vnic_dev *vdev); +int vnic_dev_overlay_offload_ctrl (struct vnic_dev *vdev,u8 overlay,u8 config); +int vnic_dev_overlay_offload_cfg (struct vnic_dev *vdev,u8 overlay, +u16 vxlan_udp_port_number); +int vnic_dev_get_supported_feature_ver (struct vnic_dev *vdev,u8 feature, +u64 *supported_versions);#endif /* _VNIC_DEV_H_ */
drivers/net/ethernet/cisco/enic/vnic_devcmd.h +51 -0
61 lines not on this page · raw message
drivers/net/ethernet/cisco/enic/vnic_enet.h +1 -0
@@ -48,6 +48,7 @@ struct vnic_enet_config {#define VENETF_RSSHASH_IPV6_EX 0x200/* Hash on IPv6 extended fields */ #define VENETF_RSSHASH_TCPIPV6_EX 0x400/* Hash on TCP + IPv6 ext. fields */ #define VENETF_LOOP 0x800/* Loopback enabled */ +#define VENETF_VXLAN 0x10000/* VxLAN offload */ #define VENET_INTR_TYPE_MIN 0/* Timer specs min interrupt spacing */ #define VENET_INTR_TYPE_IDLE 1/* Timer specs idle time before irq */
Signature · 1 line
2.11.0
PATCH v2 2/3 enic: add udp_tunnel ndo for vxlan offload
In reply to Govindarajulu VaradarajanDefines enic_udp_tunnel_add/del for configuring vxlan tunnel offload. enic supports offload of only one ipv4/udp port.
There are two modes that fw supports for vxlan offload.
mode 0: fcoe bit is set for encapsulated packet. fcoe_fc_crc_ok is set if checksum of csum is ok. This bit is or of ip_csum_ok and tcp_udp_csum_ok
mode 2: BIT(0) in rss_hash is set if it is encapsulated packet.
BIT(1) is set if outer_ip_csum_ok/
BIT(2) is set if outer_tcp_csum_ok
tcp_udp_csum_ok/ipv4_csum_ok is set if inner csum is OK.
--- drivers/net/ethernet/cisco/enic/enic.h | 6 ++ drivers/net/ethernet/cisco/enic/enic_main.c | 156 +++++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 3 deletions(-)
drivers/net/ethernet/cisco/enic/enic.h +6 -0
@@ -135,6 +135,11 @@ struct enic_rfs_flw_tbl {struct timer_list rfs_may_expire; }; +struct vxlan_offload { +u16 vxlan_udp_port_number; +u8 patch_level; +}; +/* Per-instance private data structure */ struct enic {struct net_device *netdev;
@@ -175,6 +180,7 @@ struct enic {/* receive queue cache line section */ ____cacheline_aligned struct vnic_rq rq[ENIC_RQ_MAX ];unsigned int rq_count; +struct vxlan_offload vxlan;u64 rq_truncated_pkts;u64 rq_bad_fcs;struct napi_struct napi[ENIC_RQ_MAX +ENIC_WQ_MAX ];
drivers/net/ethernet/cisco/enic/enic_main.c +153 -3
211 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v2 3/3 enic: add vxlan offload on tx path
In reply to Govindarajulu VaradarajanDefine ndo_features_check. Hw supports offload only for ipv4 inner and ipv4 outer pkt.
Code refactor for setting inner tcp pseudo csum.
--- drivers/net/ethernet/cisco/enic/enic_main.c | 126 +++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 12 deletions(-)
drivers/net/ethernet/cisco/enic/enic_main.c +114 -12
@@ -263,6 +263,48 @@ static void enic_udp_tunnel_del(struct net_device *netdev,spin_unlock_bh (&enic->devcmd_lock); } +static netdev_features_t enic_features_check (struct sk_buff *skb, +struct net_device *dev, +netdev_features_t features) +{ +const struct ethhdr *eth = (struct ethhdr *)skb_inner_mac_header (skb); +struct enic *enic =netdev_priv (dev); +struct udphdr *udph; +u16 port =0 ; +u16 proto; + +if (!skb->encapsulation) +return features; + + features =vxlan_features_check (skb, features); + +/* hardware only supports IPv4 vxlan tunnel */ +if (vlan_get_protocol (skb) !=htons (ETH_P_IP )) + goto out; + +/* hardware does not support offload of ipv6 inner pkt */ +if (eth->h_proto !=ntohs (ETH_P_IP )) + goto out; + + proto =ip_hdr (skb)->protocol; + +if (proto ==IPPROTO_UDP ) { + udph =udp_hdr (skb); + port =be16_to_cpu (udph->dest); + } + +/* HW supports offload of only one UDP port. Remove CSUM and GSO MASK +* for other UDP port tunnels +*/ +if (port != enic->vxlan.vxlan_udp_port_number) + goto out; + +return features; + +out: +return features & ~(NETIF_F_CSUM_MASK |NETIF_F_GSO_MASK ); +} +int enic_is_dynamic (struct enic *enic) {return enic->pdev->device ==PCI_DEVICE_ID_CISCO_VIC_ENET_DYN ;
@@ -591,20 +633,19 @@ static int enic_queue_wq_skb_csum_l4(struct enic *enic, struct vnic_wq *wq,return err; } -static int enic_queue_wq_skb_tso (struct enic *enic,struct vnic_wq *wq, -struct sk_buff *skb,unsigned int mss, -int vlan_tag_insert,unsigned int vlan_tag, -int loopback) +static void enic_preload_tcp_csum_encap (struct sk_buff *skb) { -unsigned int frag_len_left =skb_headlen (skb); -unsigned int len_left = skb->len - frag_len_left; -unsigned int hdr_len =skb_transport_offset (skb) +tcp_hdrlen (skb); -int eop = (len_left ==0 ); -unsigned int len; -dma_addr_t dma_addr; -unsigned int offset =0 ; -skb_frag_t *frag; +if (skb->protocol ==cpu_to_be16 (ETH_P_IP )) { +inner_ip_hdr (skb)->check =0 ; +inner_tcp_hdr (skb)->check = + ~csum_tcpudp_magic (inner_ip_hdr (skb)->saddr, +inner_ip_hdr (skb)->daddr,0 , +IPPROTO_TCP ,0 ); + } +} +static void enic_preload_tcp_csum (struct sk_buff *skb) +{/* Preload TCP csum field with IP pseudo hdr calculated * with IP length set to zero. HW will later add in length * to each TCP segment resulting from the TSO.
@@ -618,6 +659,30 @@ static int enic_queue_wq_skb_tso(struct enic *enic, struct vnic_wq *wq,tcp_hdr (skb)->check = ~csum_ipv6_magic (&ipv6_hdr (skb)->saddr, &ipv6_hdr (skb)->daddr,0 ,IPPROTO_TCP ,0 ); } +} + +static int enic_queue_wq_skb_tso (struct enic *enic,struct vnic_wq *wq, +struct sk_buff *skb,unsigned int mss, +int vlan_tag_insert,unsigned int vlan_tag, +int loopback) +{ +unsigned int frag_len_left =skb_headlen (skb); +unsigned int len_left = skb->len - frag_len_left; +int eop = (len_left ==0 ); +unsigned int offset =0 ; +unsigned int hdr_len; +dma_addr_t dma_addr; +unsigned int len; +skb_frag_t *frag; + +if (skb->encapsulation) { + hdr_len =skb_inner_transport_header (skb) - skb->data; + hdr_len +=inner_tcp_hdrlen (skb); +enic_preload_tcp_csum_encap (skb); + }else { + hdr_len =skb_transport_offset (skb) +tcp_hdrlen (skb); +enic_preload_tcp_csum (skb); + }/* Queue WQ_ENET_MAX_DESC_LEN length descriptors * for the main skb fragment
@@ -666,6 +731,38 @@ static int enic_queue_wq_skb_tso(struct enic *enic, struct vnic_wq *wq,return 0 ; } +static inline int enic_queue_wq_skb_encap (struct enic *enic,struct vnic_wq *wq, +struct sk_buff *skb, +int vlan_tag_insert, +unsigned int vlan_tag,int loopback) +{ +unsigned int head_len =skb_headlen (skb); +unsigned int len_left = skb->len - head_len; +/* Hardware will overwrite the checksum fields, calculating from +* scratch and ignoring the value placed by software. +* Offload mode = 00 +* mss[2], mss[1], mss[0] bits are set +*/ +unsigned int mss_or_csum =7 ; +int eop = (len_left ==0 ); +dma_addr_t dma_addr; +int err =0 ; + + dma_addr =pci_map_single (enic->pdev, skb->data, head_len, +PCI_DMA_TODEVICE ); +if (unlikely (enic_dma_map_check (enic, dma_addr))) +return -ENOMEM ; + +enic_queue_wq_desc_ex (wq, skb, dma_addr, head_len, mss_or_csum,0 , + vlan_tag_insert, vlan_tag, +WQ_ENET_OFFLOAD_MODE_CSUM , eop,1 /* SOP */ , eop, + loopback); +if (!eop) + err =enic_queue_wq_skb_cont (enic, wq, skb, len_left, loopback); + +return err; +} +static inline void enic_queue_wq_skb (struct enic *enic,struct vnic_wq *wq,struct sk_buff *skb) {
@@ -688,6 +785,9 @@ static inline void enic_queue_wq_skb(struct enic *enic, err =enic_queue_wq_skb_tso (enic, wq, skb, mss, vlan_tag_insert, vlan_tag, loopback); + else if (skb->encapsulation) + err =enic_queue_wq_skb_encap (enic, wq, skb, vlan_tag_insert, + vlan_tag, loopback); else if (skb->ip_summed == CHECKSUM_PARTIAL) err =enic_queue_wq_skb_csum_l4 (enic, wq, skb, vlan_tag_insert, vlan_tag, loopback);
@@ -2400,6 +2500,7 @@ static const struct net_device_ops enic_netdev_dynamic_ops = {#endif .ndo_udp_tunnel_add = enic_udp_tunnel_add, .ndo_udp_tunnel_del = enic_udp_tunnel_del, + .ndo_features_check = enic_features_check, };static const struct net_device_ops enic_netdev_ops = {
@@ -2425,6 +2526,7 @@ static const struct net_device_ops enic_netdev_ops = {#endif .ndo_udp_tunnel_add = enic_udp_tunnel_add, .ndo_udp_tunnel_del = enic_udp_tunnel_del, + .ndo_features_check = enic_features_check, };static void enic_dev_deinit (struct enic *enic)
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Govindarajulu Varadarajan <[email protected]>
Date: Wed, 8 Feb 2017 16:43:06 -0800
Quoted 17 lines
This series adds vxlan offload support for enic driver. The first patch adds vxlan devcmd for configuring vxland offload parameters. Second patch adds ndo_udp_tunnel_add/del and offload on rx path. There are to modes in which fw supports vxlan offload.
mode 0: fcoe bit is set for encapsulated packet.
fcoe_fc_crc_okis set if checksum of csum is ok. This bit is or ofip_csum_okandtcp_udp_csum_okmode 2: BIT(0) in
rss_hashis set if it is encapsulated packet.
BIT(1) is set if outer_ip_csum_ok/
BIT(2) is set ifouter_tcp_csum_okSome hw supports only mode 0, some support mode 0 and 2. Driver gets the supported modes bitmap using
get_supported_feature_verdevcmd and selects the highest mode both driver and fw supports.
Quoted 5 lines
Third patch adds offload support on tx path by adding
enic_features_check().v2: Order local variable declarations from longest to shortest line,
on all three patches.
Series applied to net-next, thanks.