From: Ivan Malov Date: Thu, 27 Jun 2019 21:06:18 +0000 (+0300) Subject: mbuf: clarify outer offsets for non-tunnel packets X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b51690ec69d62b93e98f867198be0e4d20665b35;p=dpdk.git mbuf: clarify outer offsets for non-tunnel packets The default policy for offload-specific fields is that they are undefined unless the corresponding offloads are requested in mbuf ol_flags. This is also the case for outer L2 and L3 length fields which must not be assumed to contain zeros for non-tunnel packets. The patch clarifies this behaviour in the comments and also adds appropriate checks to the PMDs which do not check any tunnel-related offloads before using the said fields. Signed-off-by: Ivan Malov Reviewed-by: Andrew Rybchenko Acked-by: Konstantin Ananyev Acked-by: Olivier Matz --- diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c index 124186e8f5..c71e6f1892 100644 --- a/drivers/net/bnxt/bnxt_txr.c +++ b/drivers/net/bnxt/bnxt_txr.c @@ -235,8 +235,10 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO | TX_BD_LONG_LFLAGS_T_IPID; hdr_size = tx_pkt->l2_len + tx_pkt->l3_len + - tx_pkt->l4_len + tx_pkt->outer_l2_len + - tx_pkt->outer_l3_len; + tx_pkt->l4_len; + hdr_size += (tx_pkt->ol_flags & PKT_TX_TUNNEL_MASK) ? + tx_pkt->outer_l2_len + + tx_pkt->outer_l3_len : 0; /* The hdr_size is multiple of 16bit units not 8bit. * Hence divide by 2. */ diff --git a/drivers/net/fm10k/fm10k_rxtx.c b/drivers/net/fm10k/fm10k_rxtx.c index 2f4dad0c1a..5c31121839 100644 --- a/drivers/net/fm10k/fm10k_rxtx.c +++ b/drivers/net/fm10k/fm10k_rxtx.c @@ -619,8 +619,9 @@ static inline void tx_xmit_pkt(struct fm10k_tx_queue *q, struct rte_mbuf *mb) rte_cpu_to_le_16(rte_pktmbuf_data_len(mb)); if (mb->ol_flags & PKT_TX_TCP_SEG) { - hdrlen = mb->outer_l2_len + mb->outer_l3_len + mb->l2_len + - mb->l3_len + mb->l4_len; + hdrlen = mb->l2_len + mb->l3_len + mb->l4_len; + hdrlen += (mb->ol_flags & PKT_TX_TUNNEL_MASK) ? + mb->outer_l2_len + mb->outer_l3_len : 0; if (q->hw_ring[q->next_free].flags & FM10K_TXD_FLAG_FTAG) hdrlen += sizeof(struct fm10k_ftag); diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c index 85c44f5224..34aa6c814b 100644 --- a/drivers/net/i40e/i40e_rxtx.c +++ b/drivers/net/i40e/i40e_rxtx.c @@ -981,15 +981,9 @@ i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload) return ctx_desc; } - /** - * in case of non tunneling packet, the outer_l2_len and - * outer_l3_len must be 0. - */ - hdr_len = tx_offload.outer_l2_len + - tx_offload.outer_l3_len + - tx_offload.l2_len + - tx_offload.l3_len + - tx_offload.l4_len; + hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len; + hdr_len += (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) ? + tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0; cd_cmd = I40E_TX_CTX_DESC_TSO; cd_tso_len = mbuf->pkt_len - hdr_len; diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c index 0be3ede316..2d37c17055 100644 --- a/drivers/net/iavf/iavf_rxtx.c +++ b/drivers/net/iavf/iavf_rxtx.c @@ -1449,9 +1449,6 @@ iavf_set_tso_ctx(struct rte_mbuf *mbuf, union iavf_tx_offload tx_offload) return ctx_desc; } - /* in case of non tunneling packet, the outer_l2_len and - * outer_l3_len must be 0. - */ hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len; diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c index 0fb3e7fe83..035ed84973 100644 --- a/drivers/net/ice/ice_rxtx.c +++ b/drivers/net/ice/ice_rxtx.c @@ -1940,15 +1940,9 @@ ice_set_tso_ctx(struct rte_mbuf *mbuf, union ice_tx_offload tx_offload) return ctx_desc; } - /** - * in case of non tunneling packet, the outer_l2_len and - * outer_l3_len must be 0. - */ - hdr_len = tx_offload.outer_l2_len + - tx_offload.outer_l3_len + - tx_offload.l2_len + - tx_offload.l3_len + - tx_offload.l4_len; + hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len; + hdr_len += (mbuf->ol_flags & PKT_TX_TUNNEL_MASK) ? + tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0; cd_cmd = ICE_TX_CTX_DESC_TSO; cd_tso_len = mbuf->pkt_len - hdr_len; diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 9542488554..98225ec80b 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -702,7 +702,18 @@ struct rte_mbuf { uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS; /**< TCP TSO segment size */ - /* fields for TX offloading of tunnels */ + /* + * Fields for Tx offloading of tunnels. + * These are undefined for packets which don't request + * any tunnel offloads (outer IP or UDP checksum, + * tunnel TSO). + * + * PMDs should not use these fields unconditionally + * when calculating offsets. + * + * Applications are expected to set appropriate tunnel + * offload flags when they fill in these fields. + */ uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS; /**< Outer L3 (IP) Hdr Length. */ uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;