[dpdk-dev,v2,02/20] mbuf: enhance the API documentation of offload flags
Commit Message
Based on http://dpdk.org/ml/archives/dev/2015-January/011127.html
Also adapt the csum forward engine code to the API.
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
app/test-pmd/csumonly.c | 6 +++---
lib/librte_mbuf/rte_mbuf.h | 43 ++++++++++++++++++++++++++++++++++++-------
2 files changed, 39 insertions(+), 10 deletions(-)
Comments
> -----Original Message-----
> From: Olivier Matz [mailto:olivier.matz@6wind.com]
> Sent: Wednesday, February 4, 2015 5:25 PM
> To: dev@dpdk.org
> Cc: Ananyev, Konstantin; Liu, Jijiang; Zhang, Helin; olivier.matz@6wind.com
> Subject: [PATCH v2 02/20] mbuf: enhance the API documentation of offload
> flags
>
> Based on http://dpdk.org/ml/archives/dev/2015-January/011127.html
>
> Also adapt the csum forward engine code to the API.
>
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> ---
> app/test-pmd/csumonly.c | 6 +++---
> lib/librte_mbuf/rte_mbuf.h | 43
> ++++++++++++++++++++++++++++++++++++-------
> 2 files changed, 39 insertions(+), 10 deletions(-)
>
> diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index
> 41711fd..4b438d1 100644
> --- a/app/test-pmd/csumonly.c
> +++ b/app/test-pmd/csumonly.c
> @@ -183,16 +183,15 @@ process_inner_cksums(void *l3_hdr, uint16_t
> ethertype, uint16_t l3_len,
> ipv4_hdr = l3_hdr;
> ipv4_hdr->hdr_checksum = 0;
>
> + ol_flags |= PKT_TX_IPV4;
> if (tso_segsz != 0 && l4_proto == IPPROTO_TCP) {
> ol_flags |= PKT_TX_IP_CKSUM;
> } else {
> if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
> ol_flags |= PKT_TX_IP_CKSUM;
> - else {
> + else
> ipv4_hdr->hdr_checksum =
> rte_ipv4_cksum(ipv4_hdr);
> - ol_flags |= PKT_TX_IPV4;
> - }
> }
> } else if (ethertype == _htons(ETHER_TYPE_IPv6))
> ol_flags |= PKT_TX_IPV6;
> @@ -261,6 +260,7 @@ process_outer_cksums(void *outer_l3_hdr, uint16_t
> outer_ethertype,
>
> if (outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
> ipv4_hdr->hdr_checksum = 0;
> + ol_flags |= PKT_TX_OUTER_IPV4;
>
> if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_VXLAN_CKSUM)
> ol_flags |= PKT_TX_OUTER_IP_CKSUM;
> diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index
> a554247..191a42c 100644
> --- a/lib/librte_mbuf/rte_mbuf.h
> +++ b/lib/librte_mbuf/rte_mbuf.h
> @@ -141,24 +141,53 @@ extern "C" {
> #define PKT_TX_UDP_CKSUM (3ULL << 52) /**< UDP cksum of TX pkt.
> computed by NIC. */
> #define PKT_TX_L4_MASK (3ULL << 52) /**< Mask for L4 cksum
> offload request. */
>
> -#define PKT_TX_IP_CKSUM (1ULL << 54) /**< IP cksum of TX pkt.
> computed by NIC. */
> +/**
> + * Offload the IP checksum in the hardware. The flag PKT_TX_IPV4 should
> + * also be set by the application, altough a PMD will only check
> + * PKT_TX_IP_CKSUM.
> + * - set the IP checksum field in the packet to 0
> + * - fill the mbuf offload information: l2_len, l3_len */
> +#define PKT_TX_IP_CKSUM (1ULL << 54)
>
> -/** Packet is IPv4 without requiring IP checksum offload. */
> +/**
> + * Packet is IPv4. This flag must be set when using any offload feature
> + * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
> + * packet.
> + */
> #define PKT_TX_IPV4 (1ULL << 55)
>
> -/** Tell the NIC it's an IPv6 packet.*/
> +/**
> + * Packet is IPv6. This flag must be set when using an offload feature
> + * (TSO or L4 checksum) to tell the NIC that the packet is an IPv6
> + * packet.
> + */
> #define PKT_TX_IPV6 (1ULL << 56)
Above two macro for IPV4/IPV6 will be used for inner L3 for tunneling case, right?
If yes, the annotations may need to mention that, to avoid confusing end users.
Regards,
Helin
>
> #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. */
> +/**
> + * Offload the IP checksum of an external header in the hardware. The
> + * flag PKT_TX_OUTER_IPV4 should also be set by the application,
> +altough
> + * a PMD will only check PKT_TX_IP_CKSUM. The IP checksum field in the
> + * packet must be set to 0.
> + * - set the outer IP checksum field in the packet to 0
> + * - fill the mbuf offload information: outer_l2_len, outer_l3_len */
> #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
>
> -/** Packet is outer IPv4 without requiring IP checksum offload for tunneling
> packet. */
> +/**
> + * Packet outer header is IPv4. This flag must be set when using any
> + * outer offload feature (L3 or L4 checksum) to tell the NIC that the
> + * packet is an IPv4 packet.
> + */
> #define PKT_TX_OUTER_IPV4 (1ULL << 59)
>
> -/** Tell the NIC it's an outer IPv6 packet for tunneling packet */
> +/**
> + * Packet outer header is IPv6. This flag must be set when using any
> + * outer offload feature (L4 checksum) to tell the NIC that the packet
> + * is an IPv6 packet.
> + */
> #define PKT_TX_OUTER_IPV6 (1ULL << 60)
>
> /* Use final bit of flags to indicate a control mbuf */
> --
> 2.1.4
Hi Helin,
On 02/10/2015 06:38 AM, Zhang, Helin wrote:
>> -/** Packet is IPv4 without requiring IP checksum offload. */
>> +/**
>> + * Packet is IPv4. This flag must be set when using any offload feature
>> + * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
>> + * packet.
>> + */
>> #define PKT_TX_IPV4 (1ULL << 55)
>>
>> -/** Tell the NIC it's an IPv6 packet.*/
>> +/**
>> + * Packet is IPv6. This flag must be set when using an offload feature
>> + * (TSO or L4 checksum) to tell the NIC that the packet is an IPv6
>> + * packet.
>> + */
>> #define PKT_TX_IPV6 (1ULL << 56)
> Above two macro for IPV4/IPV6 will be used for inner L3 for tunneling case, right?
> If yes, the annotations may need to mention that, to avoid confusing end users.
That's right, I'll clarify this in a next version.
Thanks
Olivier
Hi Olivier,
> -----Original Message-----
> From: Zhang, Helin
> Sent: Tuesday, February 10, 2015 1:39 PM
> To: Olivier Matz; dev@dpdk.org
> Cc: Ananyev, Konstantin; Liu, Jijiang
> Subject: RE: [PATCH v2 02/20] mbuf: enhance the API documentation of offload
> flags
>
>
>
> > -----Original Message-----
> > From: Olivier Matz [mailto:olivier.matz@6wind.com]
> > Sent: Wednesday, February 4, 2015 5:25 PM
> > To: dev@dpdk.org
> > Cc: Ananyev, Konstantin; Liu, Jijiang; Zhang, Helin;
> > olivier.matz@6wind.com
> > Subject: [PATCH v2 02/20] mbuf: enhance the API documentation of
> > offload flags
> >
> > Based on http://dpdk.org/ml/archives/dev/2015-January/011127.html
> >
> > Also adapt the csum forward engine code to the API.
> >
> > Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> > ---
> > app/test-pmd/csumonly.c | 6 +++---
> > lib/librte_mbuf/rte_mbuf.h | 43
> > ++++++++++++++++++++++++++++++++++++-------
> > 2 files changed, 39 insertions(+), 10 deletions(-)
> >
> > diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index
> > 41711fd..4b438d1 100644
> > --- a/app/test-pmd/csumonly.c
> > +++ b/app/test-pmd/csumonly.c
> > @@ -183,16 +183,15 @@ process_inner_cksums(void *l3_hdr, uint16_t
> > ethertype, uint16_t l3_len,
> > ipv4_hdr = l3_hdr;
> > ipv4_hdr->hdr_checksum = 0;
> >
> > + ol_flags |= PKT_TX_IPV4;
> > if (tso_segsz != 0 && l4_proto == IPPROTO_TCP) {
> > ol_flags |= PKT_TX_IP_CKSUM;
> > } else {
> > if (testpmd_ol_flags &
> TESTPMD_TX_OFFLOAD_IP_CKSUM)
> > ol_flags |= PKT_TX_IP_CKSUM;
> > - else {
> > + else
> > ipv4_hdr->hdr_checksum =
> > rte_ipv4_cksum(ipv4_hdr);
> > - ol_flags |= PKT_TX_IPV4;
> > - }
> > }
> > } else if (ethertype == _htons(ETHER_TYPE_IPv6))
> > ol_flags |= PKT_TX_IPV6;
> > @@ -261,6 +260,7 @@ process_outer_cksums(void *outer_l3_hdr, uint16_t
> > outer_ethertype,
> >
> > if (outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
> > ipv4_hdr->hdr_checksum = 0;
> > + ol_flags |= PKT_TX_OUTER_IPV4;
> >
Look at the codes again, you should extend process_outer_cksums() to support other tunneling packet.
The code changes like below,
process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
uint16_t testpmd_ol_flags, uint16_t l4_proto) // add the l4_proto parameter here.
...
/* outer UDP checksum is always done in software as we have no
* hardware supporting it today, and no API for it. */
if (l4_proto == IPPROTO_UDP)
udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + info->outer_l3_len);
/* do not recalculate udp cksum if it was 0 */
if (udp_hdr->dgram_cksum != 0) {
udp_hdr->dgram_cksum = 0;
if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4))
udp_hdr->dgram_cksum =
rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
else
udp_hdr->dgram_cksum =
rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
}
} // nothing need to do for GRE tunneling packet now
}
> > if (testpmd_ol_flags &
> TESTPMD_TX_OFFLOAD_VXLAN_CKSUM)
> > ol_flags |= PKT_TX_OUTER_IP_CKSUM; diff --git
> > a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index
> > a554247..191a42c 100644
> > --- a/lib/librte_mbuf/rte_mbuf.h
> > +++ b/lib/librte_mbuf/rte_mbuf.h
> > @@ -141,24 +141,53 @@ extern "C" {
> > #define PKT_TX_UDP_CKSUM (3ULL << 52) /**< UDP cksum of TX pkt.
> > computed by NIC. */
> > #define PKT_TX_L4_MASK (3ULL << 52) /**< Mask for L4 cksum
> > offload request. */
> >
> > -#define PKT_TX_IP_CKSUM (1ULL << 54) /**< IP cksum of TX pkt.
> > computed by NIC. */
> > +/**
> > + * Offload the IP checksum in the hardware. The flag PKT_TX_IPV4
> > +should
> > + * also be set by the application, altough a PMD will only check
> > + * PKT_TX_IP_CKSUM.
> > + * - set the IP checksum field in the packet to 0
> > + * - fill the mbuf offload information: l2_len, l3_len */
> > +#define PKT_TX_IP_CKSUM (1ULL << 54)
> >
> > -/** Packet is IPv4 without requiring IP checksum offload. */
> > +/**
> > + * Packet is IPv4. This flag must be set when using any offload
> > +feature
> > + * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an
> > +IPv4
> > + * packet.
> > + */
> > #define PKT_TX_IPV4 (1ULL << 55)
> >
> > -/** Tell the NIC it's an IPv6 packet.*/
> > +/**
> > + * Packet is IPv6. This flag must be set when using an offload
> > +feature
> > + * (TSO or L4 checksum) to tell the NIC that the packet is an IPv6
> > + * packet.
> > + */
> > #define PKT_TX_IPV6 (1ULL << 56)
> Above two macro for IPV4/IPV6 will be used for inner L3 for tunneling case,
> right?
> If yes, the annotations may need to mention that, to avoid confusing end users.
>
> Regards,
> Helin
>
> >
> > #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. */
> > +/**
> > + * Offload the IP checksum of an external header in the hardware. The
> > + * flag PKT_TX_OUTER_IPV4 should also be set by the application,
> > +altough
> > + * a PMD will only check PKT_TX_IP_CKSUM. The IP checksum field in
> > +the
> > + * packet must be set to 0.
> > + * - set the outer IP checksum field in the packet to 0
> > + * - fill the mbuf offload information: outer_l2_len, outer_l3_len
> > +*/
> > #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
> >
> > -/** Packet is outer IPv4 without requiring IP checksum offload for
> > tunneling packet. */
> > +/**
> > + * Packet outer header is IPv4. This flag must be set when using any
> > + * outer offload feature (L3 or L4 checksum) to tell the NIC that the
> > + * packet is an IPv4 packet.
> > + */
> > #define PKT_TX_OUTER_IPV4 (1ULL << 59)
> >
> > -/** Tell the NIC it's an outer IPv6 packet for tunneling packet */
> > +/**
> > + * Packet outer header is IPv6. This flag must be set when using any
> > + * outer offload feature (L4 checksum) to tell the NIC that the
> > +packet
> > + * is an IPv6 packet.
> > + */
> > #define PKT_TX_OUTER_IPV6 (1ULL << 60)
> >
> > /* Use final bit of flags to indicate a control mbuf */
> > --
> > 2.1.4
Hi Jijiang,
On 02/11/2015 08:15 AM, Liu, Jijiang wrote:
>>> diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index
>>> 41711fd..4b438d1 100644
>>> --- a/app/test-pmd/csumonly.c
>>> +++ b/app/test-pmd/csumonly.c
>>> @@ -183,16 +183,15 @@ process_inner_cksums(void *l3_hdr, uint16_t
>>> ethertype, uint16_t l3_len,
>>> ipv4_hdr = l3_hdr;
>>> ipv4_hdr->hdr_checksum = 0;
>>>
>>> + ol_flags |= PKT_TX_IPV4;
>>> if (tso_segsz != 0 && l4_proto == IPPROTO_TCP) {
>>> ol_flags |= PKT_TX_IP_CKSUM;
>>> } else {
>>> if (testpmd_ol_flags &
>> TESTPMD_TX_OFFLOAD_IP_CKSUM)
>>> ol_flags |= PKT_TX_IP_CKSUM;
>>> - else {
>>> + else
>>> ipv4_hdr->hdr_checksum =
>>> rte_ipv4_cksum(ipv4_hdr);
>>> - ol_flags |= PKT_TX_IPV4;
>>> - }
>>> }
>>> } else if (ethertype == _htons(ETHER_TYPE_IPv6))
>>> ol_flags |= PKT_TX_IPV6;
>>> @@ -261,6 +260,7 @@ process_outer_cksums(void *outer_l3_hdr, uint16_t
>>> outer_ethertype,
>>>
>>> if (outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
>>> ipv4_hdr->hdr_checksum = 0;
>>> + ol_flags |= PKT_TX_OUTER_IPV4;
>>>
>
> Look at the codes again, you should extend process_outer_cksums() to support other tunneling packet.
>
> The code changes like below,
> process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
> uint16_t testpmd_ol_flags, uint16_t l4_proto) // add the l4_proto parameter here.
> ...
> /* outer UDP checksum is always done in software as we have no
> * hardware supporting it today, and no API for it. */
> if (l4_proto == IPPROTO_UDP)
> udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + info->outer_l3_len);
> /* do not recalculate udp cksum if it was 0 */
> if (udp_hdr->dgram_cksum != 0) {
> udp_hdr->dgram_cksum = 0;
> if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4))
> udp_hdr->dgram_cksum =
> rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
> else
> udp_hdr->dgram_cksum =
> rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
> }
> } // nothing need to do for GRE tunneling packet now
> }
That's correct, I'll update the code accordingly.
Thanks,
Olivier
@@ -183,16 +183,15 @@ process_inner_cksums(void *l3_hdr, uint16_t ethertype, uint16_t l3_len,
ipv4_hdr = l3_hdr;
ipv4_hdr->hdr_checksum = 0;
+ ol_flags |= PKT_TX_IPV4;
if (tso_segsz != 0 && l4_proto == IPPROTO_TCP) {
ol_flags |= PKT_TX_IP_CKSUM;
} else {
if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
ol_flags |= PKT_TX_IP_CKSUM;
- else {
+ else
ipv4_hdr->hdr_checksum =
rte_ipv4_cksum(ipv4_hdr);
- ol_flags |= PKT_TX_IPV4;
- }
}
} else if (ethertype == _htons(ETHER_TYPE_IPv6))
ol_flags |= PKT_TX_IPV6;
@@ -261,6 +260,7 @@ process_outer_cksums(void *outer_l3_hdr, uint16_t outer_ethertype,
if (outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
ipv4_hdr->hdr_checksum = 0;
+ ol_flags |= PKT_TX_OUTER_IPV4;
if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_VXLAN_CKSUM)
ol_flags |= PKT_TX_OUTER_IP_CKSUM;
@@ -141,24 +141,53 @@ extern "C" {
#define PKT_TX_UDP_CKSUM (3ULL << 52) /**< UDP cksum of TX pkt. computed by NIC. */
#define PKT_TX_L4_MASK (3ULL << 52) /**< Mask for L4 cksum offload request. */
-#define PKT_TX_IP_CKSUM (1ULL << 54) /**< IP cksum of TX pkt. computed by NIC. */
+/**
+ * Offload the IP checksum in the hardware. The flag PKT_TX_IPV4 should
+ * also be set by the application, altough a PMD will only check
+ * PKT_TX_IP_CKSUM.
+ * - set the IP checksum field in the packet to 0
+ * - fill the mbuf offload information: l2_len, l3_len
+ */
+#define PKT_TX_IP_CKSUM (1ULL << 54)
-/** Packet is IPv4 without requiring IP checksum offload. */
+/**
+ * Packet is IPv4. This flag must be set when using any offload feature
+ * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
+ * packet.
+ */
#define PKT_TX_IPV4 (1ULL << 55)
-/** Tell the NIC it's an IPv6 packet.*/
+/**
+ * Packet is IPv6. This flag must be set when using an offload feature
+ * (TSO or L4 checksum) to tell the NIC that the packet is 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. */
+/**
+ * Offload the IP checksum of an external header in the hardware. The
+ * flag PKT_TX_OUTER_IPV4 should also be set by the application, altough
+ * a PMD will only check PKT_TX_IP_CKSUM. The IP checksum field in the
+ * packet must be set to 0.
+ * - set the outer IP checksum field in the packet to 0
+ * - fill the mbuf offload information: outer_l2_len, outer_l3_len
+ */
#define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
-/** Packet is outer IPv4 without requiring IP checksum offload for tunneling packet. */
+/**
+ * Packet outer header is IPv4. This flag must be set when using any
+ * outer offload feature (L3 or L4 checksum) to tell the NIC that the
+ * packet is an IPv4 packet.
+ */
#define PKT_TX_OUTER_IPV4 (1ULL << 59)
-/** Tell the NIC it's an outer IPv6 packet for tunneling packet */
+/**
+ * Packet outer header is IPv6. This flag must be set when using any
+ * outer offload feature (L4 checksum) to tell the NIC that the packet
+ * is an IPv6 packet.
+ */
#define PKT_TX_OUTER_IPV6 (1ULL << 60)
/* Use final bit of flags to indicate a control mbuf */