ixgbe: do not override buffer length
[dpdk.git] / lib / librte_mbuf / rte_mbuf.h
index 0b78abe..efdefc4 100644 (file)
@@ -2,6 +2,7 @@
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright 2014 6WIND S.A.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -101,7 +102,25 @@ extern "C" {
 /* add new RX flags here */
 
 /* add new TX flags here */
-#define PKT_TX_VXLAN_CKSUM   (1ULL << 50) /**< TX checksum of VXLAN computed by NIC */
+
+/**
+ * TCP segmentation offload. To enable this offload feature for a
+ * packet to be transmitted on hardware supporting TSO:
+ *  - set the PKT_TX_TCP_SEG flag in mbuf->ol_flags (this flag implies
+ *    PKT_TX_TCP_CKSUM)
+ *  - set the flag PKT_TX_IPV4 or PKT_TX_IPV6
+ *  - if it's IPv4, set the PKT_TX_IP_CKSUM flag and write the IP checksum
+ *    to 0 in the packet
+ *  - fill the mbuf offload information: l2_len, l3_len, l4_len, tso_segsz
+ *  - calculate the pseudo header checksum without taking ip_len in account,
+ *    and set it in the TCP header. Refer to rte_ipv4_phdr_cksum() and
+ *    rte_ipv6_phdr_cksum() that can be used as helpers.
+ */
+#define PKT_TX_TCP_SEG       (1ULL << 49)
+
+/** TX packet is an UDP tunneled packet. It must be specified when using
+ *  outer checksum offload (PKT_TX_OUTER_IP_CKSUM) */
+#define PKT_TX_UDP_TUNNEL_PKT (1ULL << 50) /**< TX packet is an UDP tunneled packet */
 #define PKT_TX_IEEE1588_TMST (1ULL << 51) /**< TX IEEE1588 packet to timestamp. */
 
 /**
@@ -112,7 +131,8 @@ extern "C" {
  *  - set the flags PKT_TX_TCP_CKSUM, PKT_TX_SCTP_CKSUM or PKT_TX_UDP_CKSUM
  *  - set the flag PKT_TX_IPV4 or PKT_TX_IPV6
  *  - calculate the pseudo header checksum and set it in the L4 header (only
- *    for TCP or UDP). For SCTP, set the crc field to 0.
+ *    for TCP or UDP). See rte_ipv4_phdr_cksum() and rte_ipv6_phdr_cksum().
+ *    For SCTP, set the crc field to 0.
  */
 #define PKT_TX_L4_NO_CKSUM   (0ULL << 52) /**< Disable L4 cksum of TX pkt. */
 #define PKT_TX_TCP_CKSUM     (1ULL << 52) /**< TCP cksum of TX pkt. computed by NIC. */
@@ -123,13 +143,23 @@ extern "C" {
 #define PKT_TX_IP_CKSUM      (1ULL << 54) /**< IP cksum of TX pkt. computed by NIC. */
 #define PKT_TX_IPV4_CSUM     PKT_TX_IP_CKSUM /**< Alias of PKT_TX_IP_CKSUM. */
 
-/** Tell the NIC it's an IPv4 packet. Required for L4 checksum offload. */
-#define PKT_TX_IPV4          PKT_RX_IPV4_HDR
+/** Packet is IPv4 without requiring IP checksum offload. */
+#define PKT_TX_IPV4          (1ULL << 55)
+
+/** Tell the NIC it's an IPv6 packet.*/
+#define PKT_TX_IPV6          (1ULL << 56)
+
+#define PKT_TX_VLAN_PKT      (1ULL << 57) /**< TX packet is a 802.1q VLAN packet. */
+
+/** Outer IP checksum of TX packet, computed by NIC for tunneling packet.
+ *  The tunnel type must also be specified, ex: PKT_TX_UDP_TUNNEL_PKT. */
+#define PKT_TX_OUTER_IP_CKSUM   (1ULL << 58)
 
-/** Tell the NIC it's an IPv6 packet. Required for L4 checksum offload. */
-#define PKT_TX_IPV6          PKT_RX_IPV6_HDR
+/** Packet is outer IPv4 without requiring IP checksum offload for tunneling packet. */
+#define PKT_TX_OUTER_IPV4   (1ULL << 59)
 
-#define PKT_TX_VLAN_PKT      (1ULL << 55) /**< TX packet is a 802.1q VLAN packet. */
+/** Tell the NIC it's an outer IPv6 packet for tunneling packet */
+#define PKT_TX_OUTER_IPV6    (1ULL << 60)
 
 /* Use final bit of flags to indicate a control mbuf */
 #define CTRL_MBUF_FLAG       (1ULL << 63) /**< Mbuf contains control data */
@@ -159,8 +189,10 @@ const char *rte_get_tx_ol_flag_name(uint64_t mask);
 /* define a set of marker types that can be used to refer to set points in the
  * mbuf */
 typedef void    *MARKER[0];   /**< generic marker for a point in a structure */
+typedef uint8_t  MARKER8[0];  /**< generic marker with 1B alignment */
 typedef uint64_t MARKER64[0]; /**< marker that allows us to overwrite 8 bytes
                                * with a single assignment */
+
 /**
  * The generic rte_mbuf, containing a packet mbuf.
  */
@@ -170,9 +202,10 @@ struct rte_mbuf {
        void *buf_addr;           /**< Virtual address of segment buffer. */
        phys_addr_t buf_physaddr; /**< Physical address of segment buffer. */
 
-       /* next 8 bytes are initialised on RX descriptor rearm */
-       MARKER64 rearm_data;
        uint16_t buf_len;         /**< Length of segment buffer. */
+
+       /* next 6 bytes are initialised on RX descriptor rearm */
+       MARKER8 rearm_data;
        uint16_t data_off;
 
        /**
@@ -241,22 +274,18 @@ struct rte_mbuf {
 
        /* fields to support TX offloads */
        union {
-               uint16_t l2_l3_len; /**< combined l2/l3 lengths as single var */
+               uint64_t tx_offload;       /**< combined for easy fetch */
                struct {
-                       uint16_t l3_len:9;      /**< L3 (IP) Header Length. */
-                       uint16_t l2_len:7;      /**< L2 (MAC) Header Length. */
-               };
-       };
+                       uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
+                       uint64_t l3_len:9; /**< L3 (IP) Header Length. */
+                       uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
+                       uint64_t tso_segsz:16; /**< TCP TSO segment size */
 
-       /* fields for TX offloading of tunnels */
-       union {
-               uint16_t inner_l2_l3_len;
-               /**< combined inner l2/l3 lengths as single var */
-               struct {
-                       uint16_t inner_l3_len:9;
-                       /**< inner L3 (IP) Header Length. */
-                       uint16_t inner_l2_len:7;
-                       /**< inner L2 (MAC) Header Length. */
+                       /* fields for TX offloading of tunnels */
+                       uint64_t outer_l3_len:9; /**< Outer L3 (IP) Hdr Length. */
+                       uint64_t outer_l2_len:7; /**< Outer L2 (MAC) Hdr Length. */
+
+                       /* uint64_t unused:8; */
                };
        };
 } __rte_cache_aligned;
@@ -608,8 +637,7 @@ static inline void rte_pktmbuf_reset(struct rte_mbuf *m)
 {
        m->next = NULL;
        m->pkt_len = 0;
-       m->l2_l3_len = 0;
-       m->inner_l2_l3_len = 0;
+       m->tx_offload = 0;
        m->vlan_tci = 0;
        m->nb_segs = 1;
        m->port = 0xff;
@@ -678,8 +706,7 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *md)
        mi->data_len = md->data_len;
        mi->port = md->port;
        mi->vlan_tci = md->vlan_tci;
-       mi->l2_l3_len = md->l2_l3_len;
-       mi->inner_l2_l3_len = md->inner_l2_l3_len;
+       mi->tx_offload = md->tx_offload;
        mi->hash = md->hash;
 
        mi->next = NULL;