From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 52D7D2B8B for ; Mon, 24 Oct 2016 14:14:53 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 05:14:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,542,1473145200"; d="scan'208";a="23029258" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by orsmga005.jf.intel.com with ESMTP; 24 Oct 2016 05:14:51 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.177]) by IRSMSX104.ger.corp.intel.com ([163.33.3.159]) with mapi id 14.03.0248.002; Mon, 24 Oct 2016 13:14:50 +0100 From: "Ananyev, Konstantin" To: "Kulasek, TomaszX" , "dev@dpdk.org" CC: "olivier.matz@6wind.com" Thread-Topic: [PATCH v8 1/6] ethdev: add Tx preparation Thread-Index: AQHSK6npwSXXPzaQDkC9bhxU/0FwXKC3hxBw Date: Mon, 24 Oct 2016 12:14:49 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772583F0CB086@irsmsx105.ger.corp.intel.com> References: <1477057376-16224-1-git-send-email-tomaszx.kulasek@intel.com> <1477061177-15828-1-git-send-email-tomaszx.kulasek@intel.com> <1477061177-15828-2-git-send-email-tomaszx.kulasek@intel.com> In-Reply-To: <1477061177-15828-2-git-send-email-tomaszx.kulasek@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v8 1/6] ethdev: add Tx preparation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Oct 2016 12:14:53 -0000 Hi Tomasz, >=20 > /** > + * Validate general requirements for tx offload in mbuf. > + * > + * This function checks correctness and completeness of Tx offload setti= ngs. > + * > + * @param m > + * The packet mbuf to be validated. > + * @return > + * 0 if packet is valid > + */ > +static inline int > +rte_validate_tx_offload(const struct rte_mbuf *m) > +{ > + uint64_t ol_flags =3D m->ol_flags; > + > + /* Does packet set any of available offloads? */ > + if (!(ol_flags & PKT_TX_OFFLOAD_MASK)) > + return 0; > + > + /* IP checksum can be counted only for IPv4 packet */ > + if ((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6)) > + return -EINVAL; > + > + /* IP type not set when required */ > + if (ol_flags & (PKT_TX_L4_MASK | PKT_TX_TCP_SEG)) > + if (!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6))) > + return -EINVAL; > + > + /* Check requirements for TSO packet */ > + if (ol_flags & PKT_TX_TCP_SEG) > + if ((m->tso_segsz =3D=3D 0) || > + ((ol_flags & PKT_TX_IPV4) && > + !(ol_flags & PKT_TX_IP_CKSUM))) > + return -EINVAL; > + > + /* PKT_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */ > + if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) && > + !(ol_flags & PKT_TX_OUTER_IPV4)) > + return -EINVAL; > + > + return 0; > +} > + > +/** > * Dump an mbuf structure to a file. > * > * Dump all fields for the given packet mbuf and all its associated > diff --git a/lib/librte_net/rte_net.h b/lib/librte_net/rte_net.h > index d4156ae..79669d7 100644 > --- a/lib/librte_net/rte_net.h > +++ b/lib/librte_net/rte_net.h > @@ -38,6 +38,11 @@ > extern "C" { > #endif >=20 > +#include > +#include > +#include > +#include > + > /** > * Structure containing header lengths associated to a packet, filled > * by rte_net_get_ptype(). > @@ -86,6 +91,91 @@ struct rte_net_hdr_lens { > uint32_t rte_net_get_ptype(const struct rte_mbuf *m, > struct rte_net_hdr_lens *hdr_lens, uint32_t layers); >=20 > +/** > + * Fix pseudo header checksum > + * > + * This function fixes pseudo header checksum for TSO and non-TSO tcp/ud= p in > + * provided mbufs packet data. > + * > + * - for non-TSO tcp/udp packets full pseudo-header checksum is counted = and set > + * in packet data, > + * - for TSO the IP payload length is not included in pseudo header. > + * > + * This function expects that used headers are in the first data segment= of > + * mbuf, and are not fragmented. > + * > + * @param m > + * The packet mbuf to be validated. > + * @return > + * 0 if checksum is initialized properly > + */ > +static inline int > +rte_phdr_cksum_fix(struct rte_mbuf *m) > +{ > + struct ipv4_hdr *ipv4_hdr; > + struct ipv6_hdr *ipv6_hdr; > + struct tcp_hdr *tcp_hdr; > + struct udp_hdr *udp_hdr; > + uint64_t ol_flags =3D m->ol_flags; > + uint64_t inner_l3_offset =3D m->l2_len; > + > + if (ol_flags & PKT_TX_OUTER_IP_CKSUM) > + inner_l3_offset +=3D m->outer_l2_len + m->outer_l3_len; > + > + /* headers are fragmented */ > + if (unlikely(rte_pktmbuf_data_len(m) >=3D inner_l3_offset + m->l3_len + > + m->l4_len)) Might be better to move that check into rte_validate_tx_offload(), so it would be called only when TX_DEBUG is on. Another thing, shouldn't it be: if (rte_pktmbuf_data_len(m) < inner_l3_offset + m->l3_len + m->l4_len) ? Konstantin > + return -ENOTSUP; > + > + if ((ol_flags & PKT_TX_UDP_CKSUM) =3D=3D PKT_TX_UDP_CKSUM) { > + if (ol_flags & PKT_TX_IPV4) { > + ipv4_hdr =3D rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, > + inner_l3_offset); > + > + if (ol_flags & PKT_TX_IP_CKSUM) > + ipv4_hdr->hdr_checksum =3D 0; > + > + udp_hdr =3D (struct udp_hdr *)((char *)ipv4_hdr + > + m->l3_len); > + udp_hdr->dgram_cksum =3D rte_ipv4_phdr_cksum(ipv4_hdr, > + ol_flags); > + } else { > + ipv6_hdr =3D rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, > + inner_l3_offset); > + /* non-TSO udp */ > + udp_hdr =3D rte_pktmbuf_mtod_offset(m, struct udp_hdr *, > + inner_l3_offset + m->l3_len); > + udp_hdr->dgram_cksum =3D rte_ipv6_phdr_cksum(ipv6_hdr, > + ol_flags); > + } > + } else if ((ol_flags & PKT_TX_TCP_CKSUM) || > + (ol_flags & PKT_TX_TCP_SEG)) { > + if (ol_flags & PKT_TX_IPV4) { > + ipv4_hdr =3D rte_pktmbuf_mtod_offset(m, struct ipv4_hdr *, > + inner_l3_offset); > + > + if (ol_flags & PKT_TX_IP_CKSUM) > + ipv4_hdr->hdr_checksum =3D 0; > + > + /* non-TSO tcp or TSO */ > + tcp_hdr =3D (struct tcp_hdr *)((char *)ipv4_hdr + > + m->l3_len); > + tcp_hdr->cksum =3D rte_ipv4_phdr_cksum(ipv4_hdr, > + ol_flags); > + } else { > + ipv6_hdr =3D rte_pktmbuf_mtod_offset(m, struct ipv6_hdr *, > + inner_l3_offset); > + /* non-TSO tcp or TSO */ > + tcp_hdr =3D rte_pktmbuf_mtod_offset(m, struct tcp_hdr *, > + inner_l3_offset + m->l3_len); > + tcp_hdr->cksum =3D rte_ipv6_phdr_cksum(ipv6_hdr, > + ol_flags); > + } > + } > + > + return 0; > +} > + > #ifdef __cplusplus > } > #endif > -- > 1.7.9.5