netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Or Gerlitz <gerlitz.or@gmail.com>
To: Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
	Alexander Duyck <alexander.h.duyck@intel.com>
Cc: David Miller <davem@davemloft.net>,
	Linux Netdev List <netdev@vger.kernel.org>,
	nhorman@redhat.com, sassmann@redhat.com, jogreene@redhat.com,
	Tom Herbert <therbert@google.com>
Subject: Re: [net-next v3 20/29] fm10k: Add support for netdev offloads
Date: Wed, 1 Oct 2014 11:31:23 +0300	[thread overview]
Message-ID: <CAJ3xEMhv-cS+vShPjTvOuWP182wf=zubNU=_p08DSkNv9W2C-w@mail.gmail.com> (raw)
In-Reply-To: <1411471017-28213-21-git-send-email-jeffrey.t.kirsher@intel.com>

On Tue, Sep 23, 2014 at 2:16 PM, Jeff Kirsher
<jeffrey.t.kirsher@intel.com> wrote:
> From: Alexander Duyck <alexander.h.duyck@intel.com>
> This patch adds support for basic offloads including TSO, Tx checksum, Rx
> checksum, Rx hash, and the same features applied to VXLAN/NVGRE tunnels.

> --- a/drivers/net/ethernet/intel/fm10k/fm10k_main.c
> +++ b/drivers/net/ethernet/intel/fm10k/fm10k_main.c
[...]
> +#define VXLAN_HLEN (sizeof(struct udphdr) + 8)
> +static struct ethhdr *fm10k_port_is_vxlan(struct sk_buff *skb)
> +{
> +       struct fm10k_intfc *interface = netdev_priv(skb->dev);
> +       struct fm10k_vxlan_port *vxlan_port;
> +
> +       /* we can only offload a vxlan if we recognize it as such */
> +       vxlan_port = list_first_entry_or_null(&interface->vxlan_port,
> +                                             struct fm10k_vxlan_port, list);
> +
> +       if (!vxlan_port)
> +               return NULL;
> +       if (vxlan_port->port != udp_hdr(skb)->dest)
> +               return NULL;
> +
> +       /* return offset of udp_hdr plus 8 bytes for VXLAN header */
> +       return (struct ethhdr *)(skb_transport_header(skb) + VXLAN_HLEN);
> +}
> +
> +#define FM10K_NVGRE_RESERVED0_FLAGS htons(0x9FFF)
> +#define NVGRE_TNI htons(0x2000)
> +struct fm10k_nvgre_hdr {
> +       __be16 flags;
> +       __be16 proto;
> +       __be32 tni;
> +};
> +
> +static struct ethhdr *fm10k_gre_is_nvgre(struct sk_buff *skb)
> +{
> +       struct fm10k_nvgre_hdr *nvgre_hdr;
> +       int hlen = ip_hdrlen(skb);
> +
> +       /* currently only IPv4 is supported due to hlen above */
> +       if (vlan_get_protocol(skb) != htons(ETH_P_IP))
> +               return NULL;
> +
> +       /* our transport header should be NVGRE */
> +       nvgre_hdr = (struct fm10k_nvgre_hdr *)(skb_network_header(skb) + hlen);
> +
> +       /* verify all reserved flags are 0 */
> +       if (nvgre_hdr->flags & FM10K_NVGRE_RESERVED0_FLAGS)
> +               return NULL;
> +
> +       /* verify protocol is transparent Ethernet bridging */
> +       if (nvgre_hdr->proto != htons(ETH_P_TEB))
> +               return NULL;
> +
> +       /* report start of ethernet header */
> +       if (nvgre_hdr->flags & NVGRE_TNI)
> +               return (struct ethhdr *)(nvgre_hdr + 1);
> +
> +       return (struct ethhdr *)(&nvgre_hdr->tni);
> +}

this helper is fully generic, should reside elsewhere in the stack


> +
> +static __be16 fm10k_tx_encap_offload(struct sk_buff *skb)
> +{
> +       struct ethhdr *eth_hdr;
> +       u8 l4_hdr = 0;
> +
> +       switch (vlan_get_protocol(skb)) {
> +       case htons(ETH_P_IP):
> +               l4_hdr = ip_hdr(skb)->protocol;
> +               break;
> +       case htons(ETH_P_IPV6):
> +               l4_hdr = ipv6_hdr(skb)->nexthdr;
> +               break;
> +       default:
> +               return 0;
> +       }
> +
> +       switch (l4_hdr) {
> +       case IPPROTO_UDP:
> +               eth_hdr = fm10k_port_is_vxlan(skb);
> +               break;
> +       case IPPROTO_GRE:
> +               eth_hdr = fm10k_gre_is_nvgre(skb);
> +               break;
> +       default:
> +               return 0;
> +       }
> +
> +       if (!eth_hdr)
> +               return 0;
> +
> +       switch (eth_hdr->h_proto) {
> +       case htons(ETH_P_IP):
> +       case htons(ETH_P_IPV6):
> +               break;
> +       default:
> +               return 0;
> +       }
> +
> +       return eth_hdr->h_proto;
> +}
> +
> +static int fm10k_tso(struct fm10k_ring *tx_ring,
> +                    struct fm10k_tx_buffer *first)
> +{
> +       struct sk_buff *skb = first->skb;
> +       struct fm10k_tx_desc *tx_desc;
> +       unsigned char *th;
> +       u8 hdrlen;
> +
> +       if (skb->ip_summed != CHECKSUM_PARTIAL)
> +               return 0;
> +
> +       if (!skb_is_gso(skb))
> +               return 0;
> +
> +       /* compute header lengths */
> +       if (skb->encapsulation) {
> +               if (!fm10k_tx_encap_offload(skb))
> +                       goto err_vxlan;
> +               th = skb_inner_transport_header(skb);
> +       } else {
> +               th = skb_transport_header(skb);
> +       }
> +
> +       /* compute offset from SOF to transport header and add header len */
> +       hdrlen = (th - skb->data) + (((struct tcphdr *)th)->doff << 2);
> +
> +       first->tx_flags |= FM10K_TX_FLAGS_CSUM;
> +
> +       /* update gso size and bytecount with header size */
> +       first->gso_segs = skb_shinfo(skb)->gso_segs;
> +       first->bytecount += (first->gso_segs - 1) * hdrlen;
> +
> +       /* populate Tx descriptor header size and mss */
> +       tx_desc = FM10K_TX_DESC(tx_ring, tx_ring->next_to_use);
> +       tx_desc->hdrlen = hdrlen;
> +       tx_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
> +
> +       return 1;
> +err_vxlan:
> +       tx_ring->netdev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
> +       if (!net_ratelimit())
> +               netdev_err(tx_ring->netdev,
> +                          "TSO requested for unsupported tunnel, disabling offload\n");
> +       return -1;
> +}

why? if TSO was requested for some packet the driver can't do, you disable GSO
for udp tunnels for any future packets too? maybe just disable it
permanently  till you
feel safer to run under the current stack?


[...]

> @@ -732,6 +1024,7 @@ netdev_tx_t fm10k_xmit_frame_ring(struct sk_buff *skb,
>                                   struct fm10k_ring *tx_ring)
>  {
>         struct fm10k_tx_buffer *first;
> +       int tso;
>         u32 tx_flags = 0;
>  #if PAGE_SIZE > FM10K_MAX_DATA_PER_TXD
>         unsigned short f;
> @@ -763,11 +1056,23 @@ netdev_tx_t fm10k_xmit_frame_ring(struct sk_buff *skb,
>         /* record initial flags and protocol */
>         first->tx_flags = tx_flags;
>
> +       tso = fm10k_tso(tx_ring, first);
> +       if (tso < 0)
> +               goto out_drop;
> +       else if (!tso)
> +               fm10k_tx_csum(tx_ring, first);
> +
>         fm10k_tx_map(tx_ring, first);
>
>         fm10k_maybe_stop_tx(tx_ring, DESC_NEEDED);
>
>         return NETDEV_TX_OK;
> +
> +out_drop:
> +       dev_kfree_skb_any(first->skb);
> +       first->skb = NULL;
> +
> +       return NETDEV_TX_OK;
>  }

  reply	other threads:[~2014-10-01  8:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-23 11:16 [net-next v3 00/29][pull request] Intel Wired LAN Driver Updates 2014-09-23 Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 01/29] fm10k: Add skeletal frame for Intel(R) FM10000 Ethernet Switch Host Interface Driver Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 02/29] fm10k: Add register defines and basic structures Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 03/29] fm10k: Add support for TLV message parsing and generation Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 04/29] fm10k: Add support for basic interaction with hardware Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 05/29] fm10k: Add support for mailbox Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 06/29] fm10k: Implement PF <-> SM mailbox operations Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 07/29] fm10k: Add support for PF Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 08/29] fm10k: Add support for configuring PF interface Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 09/29] fm10k: Add netdev Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 10/29] fm10k: Add support for L2 filtering Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 11/29] fm10k: Add support for ndo_open/stop Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 12/29] fm10k: Add interrupt support Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 13/29] fm10k: add support for Tx/Rx rings Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 14/29] fm10k: Add service task to handle delayed events Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 15/29] fm10k: Add Tx/Rx hardware ring bring-up/tear-down Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 16/29] fm10k: Add transmit and receive fastpath and interrupt handlers Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 17/29] fm10k: Add ethtool support Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 18/29] fm10k: Add support for PCI power management and error handling Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 19/29] fm10k: Add support for multiple queues Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 20/29] fm10k: Add support for netdev offloads Jeff Kirsher
2014-10-01  8:31   ` Or Gerlitz [this message]
2014-10-01 12:02     ` Alexander Duyck
2014-10-01 12:22       ` Sathya Perla
2014-10-01 13:52         ` Duyck, Alexander H
2014-10-06  6:19           ` Sathya Perla
2014-09-23 11:16 ` [net-next v3 21/29] fm10k: Add support for MACVLAN acceleration Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 22/29] fm10k: Add support for PF <-> VF mailbox Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 23/29] fm10k: Add support for VF Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 24/29] fm10k: Add support for SR-IOV to PF core files Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 25/29] fm10k: Add support for SR-IOV to driver Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 26/29] fm10k: Add support for IEEE DCBx Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 27/29] fm10k: Add support for debugfs Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 28/29] fm10k: Add support for ptp to hw specific files Jeff Kirsher
2014-09-23 11:16 ` [net-next v3 29/29] fm10k: Add support for PTP Jeff Kirsher
2014-09-26 20:25 ` [net-next v3 00/29][pull request] Intel Wired LAN Driver Updates 2014-09-23 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ3xEMhv-cS+vShPjTvOuWP182wf=zubNU=_p08DSkNv9W2C-w@mail.gmail.com' \
    --to=gerlitz.or@gmail.com \
    --cc=alexander.h.duyck@intel.com \
    --cc=davem@davemloft.net \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jogreene@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.com \
    --cc=therbert@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).