1c1d14583SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2c1d14583SBruce Richardson * Copyright(c) 2019 Intel Corporation 3c1d14583SBruce Richardson */ 4c1d14583SBruce Richardson 5c1d14583SBruce Richardson #ifndef _ICE_RXTX_VEC_COMMON_H_ 6c1d14583SBruce Richardson #define _ICE_RXTX_VEC_COMMON_H_ 7c1d14583SBruce Richardson 882fbc4a4SBruce Richardson #include "../common/rx.h" 9c1d14583SBruce Richardson #include "ice_rxtx.h" 10c1d14583SBruce Richardson 11c1d14583SBruce Richardson static inline uint16_t 12c1d14583SBruce Richardson ice_rx_reassemble_packets(struct ice_rx_queue *rxq, struct rte_mbuf **rx_bufs, 13c1d14583SBruce Richardson uint16_t nb_bufs, uint8_t *split_flags) 14c1d14583SBruce Richardson { 15c1d14583SBruce Richardson struct rte_mbuf *pkts[ICE_VPMD_RX_BURST] = {0}; /*finished pkts*/ 16c1d14583SBruce Richardson struct rte_mbuf *start = rxq->pkt_first_seg; 17c1d14583SBruce Richardson struct rte_mbuf *end = rxq->pkt_last_seg; 18c1d14583SBruce Richardson unsigned int pkt_idx, buf_idx; 19c1d14583SBruce Richardson 20c1d14583SBruce Richardson for (buf_idx = 0, pkt_idx = 0; buf_idx < nb_bufs; buf_idx++) { 21c1d14583SBruce Richardson if (end) { 22c1d14583SBruce Richardson /* processing a split packet */ 23c1d14583SBruce Richardson end->next = rx_bufs[buf_idx]; 24c1d14583SBruce Richardson rx_bufs[buf_idx]->data_len += rxq->crc_len; 25c1d14583SBruce Richardson 26c1d14583SBruce Richardson start->nb_segs++; 27c1d14583SBruce Richardson start->pkt_len += rx_bufs[buf_idx]->data_len; 28c1d14583SBruce Richardson end = end->next; 29c1d14583SBruce Richardson 30c1d14583SBruce Richardson if (!split_flags[buf_idx]) { 31c1d14583SBruce Richardson /* it's the last packet of the set */ 32c1d14583SBruce Richardson start->hash = end->hash; 33c1d14583SBruce Richardson start->vlan_tci = end->vlan_tci; 34c1d14583SBruce Richardson start->ol_flags = end->ol_flags; 35c1d14583SBruce Richardson /* we need to strip crc for the whole packet */ 36c1d14583SBruce Richardson start->pkt_len -= rxq->crc_len; 37c1d14583SBruce Richardson if (end->data_len > rxq->crc_len) { 38c1d14583SBruce Richardson end->data_len -= rxq->crc_len; 39c1d14583SBruce Richardson } else { 40c1d14583SBruce Richardson /* free up last mbuf */ 41c1d14583SBruce Richardson struct rte_mbuf *secondlast = start; 42c1d14583SBruce Richardson 43c1d14583SBruce Richardson start->nb_segs--; 44c1d14583SBruce Richardson while (secondlast->next != end) 45c1d14583SBruce Richardson secondlast = secondlast->next; 46c1d14583SBruce Richardson secondlast->data_len -= (rxq->crc_len - 47c1d14583SBruce Richardson end->data_len); 48c1d14583SBruce Richardson secondlast->next = NULL; 49c1d14583SBruce Richardson rte_pktmbuf_free_seg(end); 50c1d14583SBruce Richardson } 51c1d14583SBruce Richardson pkts[pkt_idx++] = start; 52c1d14583SBruce Richardson start = NULL; 53c1d14583SBruce Richardson end = NULL; 54c1d14583SBruce Richardson } 55c1d14583SBruce Richardson } else { 56c1d14583SBruce Richardson /* not processing a split packet */ 57c1d14583SBruce Richardson if (!split_flags[buf_idx]) { 58c1d14583SBruce Richardson /* not a split packet, save and skip */ 59c1d14583SBruce Richardson pkts[pkt_idx++] = rx_bufs[buf_idx]; 60c1d14583SBruce Richardson continue; 61c1d14583SBruce Richardson } 62c1d14583SBruce Richardson start = rx_bufs[buf_idx]; 63c1d14583SBruce Richardson end = start; 64c1d14583SBruce Richardson rx_bufs[buf_idx]->data_len += rxq->crc_len; 65c1d14583SBruce Richardson rx_bufs[buf_idx]->pkt_len += rxq->crc_len; 66c1d14583SBruce Richardson } 67c1d14583SBruce Richardson } 68c1d14583SBruce Richardson 69c1d14583SBruce Richardson /* save the partial packet for next time */ 70c1d14583SBruce Richardson rxq->pkt_first_seg = start; 71c1d14583SBruce Richardson rxq->pkt_last_seg = end; 72c1d14583SBruce Richardson memcpy(rx_bufs, pkts, pkt_idx * (sizeof(*pkts))); 73c1d14583SBruce Richardson return pkt_idx; 74c1d14583SBruce Richardson } 75c1d14583SBruce Richardson 76c1d14583SBruce Richardson static __rte_always_inline int 77c1d14583SBruce Richardson ice_tx_free_bufs_vec(struct ice_tx_queue *txq) 78c1d14583SBruce Richardson { 79*5cc9919fSBruce Richardson struct ci_tx_entry *txep; 80c1d14583SBruce Richardson uint32_t n; 81c1d14583SBruce Richardson uint32_t i; 82c1d14583SBruce Richardson int nb_free = 0; 83c1d14583SBruce Richardson struct rte_mbuf *m, *free[ICE_TX_MAX_FREE_BUF_SZ]; 84c1d14583SBruce Richardson 85c1d14583SBruce Richardson /* check DD bits on threshold descriptor */ 86c1d14583SBruce Richardson if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz & 87c1d14583SBruce Richardson rte_cpu_to_le_64(ICE_TXD_QW1_DTYPE_M)) != 88c1d14583SBruce Richardson rte_cpu_to_le_64(ICE_TX_DESC_DTYPE_DESC_DONE)) 89c1d14583SBruce Richardson return 0; 90c1d14583SBruce Richardson 91c1d14583SBruce Richardson n = txq->tx_rs_thresh; 92c1d14583SBruce Richardson 93c1d14583SBruce Richardson /* first buffer to free from S/W ring is at index 94c1d14583SBruce Richardson * tx_next_dd - (tx_rs_thresh-1) 95c1d14583SBruce Richardson */ 96c1d14583SBruce Richardson txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)]; 97c1d14583SBruce Richardson m = rte_pktmbuf_prefree_seg(txep[0].mbuf); 98c1d14583SBruce Richardson if (likely(m)) { 99c1d14583SBruce Richardson free[0] = m; 100c1d14583SBruce Richardson nb_free = 1; 101c1d14583SBruce Richardson for (i = 1; i < n; i++) { 102c1d14583SBruce Richardson m = rte_pktmbuf_prefree_seg(txep[i].mbuf); 103c1d14583SBruce Richardson if (likely(m)) { 104c1d14583SBruce Richardson if (likely(m->pool == free[0]->pool)) { 105c1d14583SBruce Richardson free[nb_free++] = m; 106c1d14583SBruce Richardson } else { 107c1d14583SBruce Richardson rte_mempool_put_bulk(free[0]->pool, 108c1d14583SBruce Richardson (void *)free, 109c1d14583SBruce Richardson nb_free); 110c1d14583SBruce Richardson free[0] = m; 111c1d14583SBruce Richardson nb_free = 1; 112c1d14583SBruce Richardson } 113c1d14583SBruce Richardson } 114c1d14583SBruce Richardson } 115c1d14583SBruce Richardson rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free); 116c1d14583SBruce Richardson } else { 117c1d14583SBruce Richardson for (i = 1; i < n; i++) { 118c1d14583SBruce Richardson m = rte_pktmbuf_prefree_seg(txep[i].mbuf); 119c1d14583SBruce Richardson if (m) 120c1d14583SBruce Richardson rte_mempool_put(m->pool, m); 121c1d14583SBruce Richardson } 122c1d14583SBruce Richardson } 123c1d14583SBruce Richardson 124c1d14583SBruce Richardson /* buffers were freed, update counters */ 125c1d14583SBruce Richardson txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh); 126c1d14583SBruce Richardson txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh); 127c1d14583SBruce Richardson if (txq->tx_next_dd >= txq->nb_tx_desc) 128c1d14583SBruce Richardson txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1); 129c1d14583SBruce Richardson 130c1d14583SBruce Richardson return txq->tx_rs_thresh; 131c1d14583SBruce Richardson } 132c1d14583SBruce Richardson 133c1d14583SBruce Richardson static __rte_always_inline void 134*5cc9919fSBruce Richardson ice_tx_backlog_entry(struct ci_tx_entry *txep, 135c1d14583SBruce Richardson struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 136c1d14583SBruce Richardson { 137c1d14583SBruce Richardson int i; 138c1d14583SBruce Richardson 139c1d14583SBruce Richardson for (i = 0; i < (int)nb_pkts; ++i) 140c1d14583SBruce Richardson txep[i].mbuf = tx_pkts[i]; 141c1d14583SBruce Richardson } 142c1d14583SBruce Richardson 143c1d14583SBruce Richardson static inline void 144c1d14583SBruce Richardson _ice_rx_queue_release_mbufs_vec(struct ice_rx_queue *rxq) 145c1d14583SBruce Richardson { 146c1d14583SBruce Richardson const unsigned int mask = rxq->nb_rx_desc - 1; 147c1d14583SBruce Richardson unsigned int i; 148c1d14583SBruce Richardson 149c1d14583SBruce Richardson if (unlikely(!rxq->sw_ring)) { 150c1d14583SBruce Richardson PMD_DRV_LOG(DEBUG, "sw_ring is NULL"); 151c1d14583SBruce Richardson return; 152c1d14583SBruce Richardson } 153c1d14583SBruce Richardson 154c1d14583SBruce Richardson if (rxq->rxrearm_nb >= rxq->nb_rx_desc) 155c1d14583SBruce Richardson return; 156c1d14583SBruce Richardson 157c1d14583SBruce Richardson /* free all mbufs that are valid in the ring */ 158c1d14583SBruce Richardson if (rxq->rxrearm_nb == 0) { 159c1d14583SBruce Richardson for (i = 0; i < rxq->nb_rx_desc; i++) { 160c1d14583SBruce Richardson if (rxq->sw_ring[i].mbuf) 161c1d14583SBruce Richardson rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf); 162c1d14583SBruce Richardson } 163c1d14583SBruce Richardson } else { 164c1d14583SBruce Richardson for (i = rxq->rx_tail; 165c1d14583SBruce Richardson i != rxq->rxrearm_start; 166c1d14583SBruce Richardson i = (i + 1) & mask) { 167c1d14583SBruce Richardson if (rxq->sw_ring[i].mbuf) 168c1d14583SBruce Richardson rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf); 169c1d14583SBruce Richardson } 170c1d14583SBruce Richardson } 171c1d14583SBruce Richardson 172c1d14583SBruce Richardson rxq->rxrearm_nb = rxq->nb_rx_desc; 173c1d14583SBruce Richardson 174c1d14583SBruce Richardson /* set all entries to NULL */ 175c1d14583SBruce Richardson memset(rxq->sw_ring, 0, sizeof(rxq->sw_ring[0]) * rxq->nb_rx_desc); 176c1d14583SBruce Richardson } 177c1d14583SBruce Richardson 178c1d14583SBruce Richardson static inline void 179c1d14583SBruce Richardson _ice_tx_queue_release_mbufs_vec(struct ice_tx_queue *txq) 180c1d14583SBruce Richardson { 181c1d14583SBruce Richardson uint16_t i; 182c1d14583SBruce Richardson 183c1d14583SBruce Richardson if (unlikely(!txq || !txq->sw_ring)) { 184c1d14583SBruce Richardson PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL"); 185c1d14583SBruce Richardson return; 186c1d14583SBruce Richardson } 187c1d14583SBruce Richardson 188c1d14583SBruce Richardson /** 189c1d14583SBruce Richardson * vPMD tx will not set sw_ring's mbuf to NULL after free, 190c1d14583SBruce Richardson * so need to free remains more carefully. 191c1d14583SBruce Richardson */ 192c1d14583SBruce Richardson i = txq->tx_next_dd - txq->tx_rs_thresh + 1; 193c1d14583SBruce Richardson 194c1d14583SBruce Richardson #ifdef __AVX512VL__ 195c1d14583SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[txq->vsi->adapter->pf.dev_data->port_id]; 196c1d14583SBruce Richardson 197c1d14583SBruce Richardson if (dev->tx_pkt_burst == ice_xmit_pkts_vec_avx512 || 198c1d14583SBruce Richardson dev->tx_pkt_burst == ice_xmit_pkts_vec_avx512_offload) { 199*5cc9919fSBruce Richardson struct ci_tx_entry_vec *swr = (void *)txq->sw_ring; 200c1d14583SBruce Richardson 201c1d14583SBruce Richardson if (txq->tx_tail < i) { 202c1d14583SBruce Richardson for (; i < txq->nb_tx_desc; i++) { 203c1d14583SBruce Richardson rte_pktmbuf_free_seg(swr[i].mbuf); 204c1d14583SBruce Richardson swr[i].mbuf = NULL; 205c1d14583SBruce Richardson } 206c1d14583SBruce Richardson i = 0; 207c1d14583SBruce Richardson } 208c1d14583SBruce Richardson for (; i < txq->tx_tail; i++) { 209c1d14583SBruce Richardson rte_pktmbuf_free_seg(swr[i].mbuf); 210c1d14583SBruce Richardson swr[i].mbuf = NULL; 211c1d14583SBruce Richardson } 212c1d14583SBruce Richardson } else 213c1d14583SBruce Richardson #endif 214c1d14583SBruce Richardson { 215c1d14583SBruce Richardson if (txq->tx_tail < i) { 216c1d14583SBruce Richardson for (; i < txq->nb_tx_desc; i++) { 217c1d14583SBruce Richardson rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf); 218c1d14583SBruce Richardson txq->sw_ring[i].mbuf = NULL; 219c1d14583SBruce Richardson } 220c1d14583SBruce Richardson i = 0; 221c1d14583SBruce Richardson } 222c1d14583SBruce Richardson for (; i < txq->tx_tail; i++) { 223c1d14583SBruce Richardson rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf); 224c1d14583SBruce Richardson txq->sw_ring[i].mbuf = NULL; 225c1d14583SBruce Richardson } 226c1d14583SBruce Richardson } 227c1d14583SBruce Richardson } 228c1d14583SBruce Richardson 229c1d14583SBruce Richardson static inline int 230c1d14583SBruce Richardson ice_rxq_vec_setup_default(struct ice_rx_queue *rxq) 231c1d14583SBruce Richardson { 232c1d14583SBruce Richardson uintptr_t p; 233c1d14583SBruce Richardson struct rte_mbuf mb_def = { .buf_addr = 0 }; /* zeroed mbuf */ 234c1d14583SBruce Richardson 235c1d14583SBruce Richardson mb_def.nb_segs = 1; 236c1d14583SBruce Richardson mb_def.data_off = RTE_PKTMBUF_HEADROOM; 237c1d14583SBruce Richardson mb_def.port = rxq->port_id; 238c1d14583SBruce Richardson rte_mbuf_refcnt_set(&mb_def, 1); 239c1d14583SBruce Richardson 240c1d14583SBruce Richardson /* prevent compiler reordering: rearm_data covers previous fields */ 241c1d14583SBruce Richardson rte_compiler_barrier(); 242c1d14583SBruce Richardson p = (uintptr_t)&mb_def.rearm_data; 243c1d14583SBruce Richardson rxq->mbuf_initializer = *(uint64_t *)p; 244c1d14583SBruce Richardson return 0; 245c1d14583SBruce Richardson } 246c1d14583SBruce Richardson 247c1d14583SBruce Richardson #define ICE_TX_NO_VECTOR_FLAGS ( \ 248c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_MULTI_SEGS | \ 249c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | \ 250c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_TCP_TSO | \ 251c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | \ 252c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | \ 253c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO | \ 254c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | \ 255c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) 256c1d14583SBruce Richardson 257c1d14583SBruce Richardson #define ICE_TX_VECTOR_OFFLOAD ( \ 258c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \ 259c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_QINQ_INSERT | \ 260c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \ 261c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | \ 262c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \ 263c1d14583SBruce Richardson RTE_ETH_TX_OFFLOAD_TCP_CKSUM) 264c1d14583SBruce Richardson 265c1d14583SBruce Richardson #define ICE_RX_VECTOR_OFFLOAD ( \ 266c1d14583SBruce Richardson RTE_ETH_RX_OFFLOAD_CHECKSUM | \ 267c1d14583SBruce Richardson RTE_ETH_RX_OFFLOAD_SCTP_CKSUM | \ 268c1d14583SBruce Richardson RTE_ETH_RX_OFFLOAD_VLAN | \ 269c1d14583SBruce Richardson RTE_ETH_RX_OFFLOAD_RSS_HASH) 270c1d14583SBruce Richardson 271c1d14583SBruce Richardson #define ICE_VECTOR_PATH 0 272c1d14583SBruce Richardson #define ICE_VECTOR_OFFLOAD_PATH 1 273c1d14583SBruce Richardson 274c1d14583SBruce Richardson static inline int 275c1d14583SBruce Richardson ice_rx_vec_queue_default(struct ice_rx_queue *rxq) 276c1d14583SBruce Richardson { 277c1d14583SBruce Richardson if (!rxq) 278c1d14583SBruce Richardson return -1; 279c1d14583SBruce Richardson 280c1d14583SBruce Richardson if (!rte_is_power_of_2(rxq->nb_rx_desc)) 281c1d14583SBruce Richardson return -1; 282c1d14583SBruce Richardson 283c1d14583SBruce Richardson if (rxq->rx_free_thresh < ICE_VPMD_RX_BURST) 284c1d14583SBruce Richardson return -1; 285c1d14583SBruce Richardson 286c1d14583SBruce Richardson if (rxq->nb_rx_desc % rxq->rx_free_thresh) 287c1d14583SBruce Richardson return -1; 288c1d14583SBruce Richardson 289c1d14583SBruce Richardson if (rxq->proto_xtr != PROTO_XTR_NONE) 290c1d14583SBruce Richardson return -1; 291c1d14583SBruce Richardson 292c1d14583SBruce Richardson if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) 293c1d14583SBruce Richardson return -1; 294c1d14583SBruce Richardson 295c1d14583SBruce Richardson if (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) 296c1d14583SBruce Richardson return -1; 297c1d14583SBruce Richardson 298c1d14583SBruce Richardson if (rxq->offloads & ICE_RX_VECTOR_OFFLOAD) 299c1d14583SBruce Richardson return ICE_VECTOR_OFFLOAD_PATH; 300c1d14583SBruce Richardson 301c1d14583SBruce Richardson return ICE_VECTOR_PATH; 302c1d14583SBruce Richardson } 303c1d14583SBruce Richardson 304c1d14583SBruce Richardson static inline int 305c1d14583SBruce Richardson ice_tx_vec_queue_default(struct ice_tx_queue *txq) 306c1d14583SBruce Richardson { 307c1d14583SBruce Richardson if (!txq) 308c1d14583SBruce Richardson return -1; 309c1d14583SBruce Richardson 310c1d14583SBruce Richardson if (txq->tx_rs_thresh < ICE_VPMD_TX_BURST || 311c1d14583SBruce Richardson txq->tx_rs_thresh > ICE_TX_MAX_FREE_BUF_SZ) 312c1d14583SBruce Richardson return -1; 313c1d14583SBruce Richardson 314c1d14583SBruce Richardson if (txq->offloads & ICE_TX_NO_VECTOR_FLAGS) 315c1d14583SBruce Richardson return -1; 316c1d14583SBruce Richardson 317c1d14583SBruce Richardson if (txq->offloads & ICE_TX_VECTOR_OFFLOAD) 318c1d14583SBruce Richardson return ICE_VECTOR_OFFLOAD_PATH; 319c1d14583SBruce Richardson 320c1d14583SBruce Richardson return ICE_VECTOR_PATH; 321c1d14583SBruce Richardson } 322c1d14583SBruce Richardson 323c1d14583SBruce Richardson static inline int 324c1d14583SBruce Richardson ice_rx_vec_dev_check_default(struct rte_eth_dev *dev) 325c1d14583SBruce Richardson { 326c1d14583SBruce Richardson int i; 327c1d14583SBruce Richardson struct ice_rx_queue *rxq; 328c1d14583SBruce Richardson int ret = 0; 329c1d14583SBruce Richardson int result = 0; 330c1d14583SBruce Richardson 331c1d14583SBruce Richardson for (i = 0; i < dev->data->nb_rx_queues; i++) { 332c1d14583SBruce Richardson rxq = dev->data->rx_queues[i]; 333c1d14583SBruce Richardson ret = (ice_rx_vec_queue_default(rxq)); 334c1d14583SBruce Richardson if (ret < 0) 335c1d14583SBruce Richardson return -1; 336c1d14583SBruce Richardson if (ret == ICE_VECTOR_OFFLOAD_PATH) 337c1d14583SBruce Richardson result = ret; 338c1d14583SBruce Richardson } 339c1d14583SBruce Richardson 340c1d14583SBruce Richardson return result; 341c1d14583SBruce Richardson } 342c1d14583SBruce Richardson 343c1d14583SBruce Richardson static inline int 344c1d14583SBruce Richardson ice_tx_vec_dev_check_default(struct rte_eth_dev *dev) 345c1d14583SBruce Richardson { 346c1d14583SBruce Richardson int i; 347c1d14583SBruce Richardson struct ice_tx_queue *txq; 348c1d14583SBruce Richardson int ret = 0; 349c1d14583SBruce Richardson int result = 0; 350c1d14583SBruce Richardson 351c1d14583SBruce Richardson for (i = 0; i < dev->data->nb_tx_queues; i++) { 352c1d14583SBruce Richardson txq = dev->data->tx_queues[i]; 353c1d14583SBruce Richardson ret = ice_tx_vec_queue_default(txq); 354c1d14583SBruce Richardson if (ret < 0) 355c1d14583SBruce Richardson return -1; 356c1d14583SBruce Richardson if (ret == ICE_VECTOR_OFFLOAD_PATH) 357c1d14583SBruce Richardson result = ret; 358c1d14583SBruce Richardson } 359c1d14583SBruce Richardson 360c1d14583SBruce Richardson return result; 361c1d14583SBruce Richardson } 362c1d14583SBruce Richardson 363c1d14583SBruce Richardson static inline void 364c1d14583SBruce Richardson ice_txd_enable_offload(struct rte_mbuf *tx_pkt, 365c1d14583SBruce Richardson uint64_t *txd_hi) 366c1d14583SBruce Richardson { 367c1d14583SBruce Richardson uint64_t ol_flags = tx_pkt->ol_flags; 368c1d14583SBruce Richardson uint32_t td_cmd = 0; 369c1d14583SBruce Richardson uint32_t td_offset = 0; 370c1d14583SBruce Richardson 371c1d14583SBruce Richardson /* Tx Checksum Offload */ 372c1d14583SBruce Richardson /* SET MACLEN */ 373c1d14583SBruce Richardson td_offset |= (tx_pkt->l2_len >> 1) << 374c1d14583SBruce Richardson ICE_TX_DESC_LEN_MACLEN_S; 375c1d14583SBruce Richardson 376c1d14583SBruce Richardson /* Enable L3 checksum offload */ 377c1d14583SBruce Richardson if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) { 378c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV4_CSUM; 379c1d14583SBruce Richardson td_offset |= (tx_pkt->l3_len >> 2) << 380c1d14583SBruce Richardson ICE_TX_DESC_LEN_IPLEN_S; 381c1d14583SBruce Richardson } else if (ol_flags & RTE_MBUF_F_TX_IPV4) { 382c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV4; 383c1d14583SBruce Richardson td_offset |= (tx_pkt->l3_len >> 2) << 384c1d14583SBruce Richardson ICE_TX_DESC_LEN_IPLEN_S; 385c1d14583SBruce Richardson } else if (ol_flags & RTE_MBUF_F_TX_IPV6) { 386c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_IIPT_IPV6; 387c1d14583SBruce Richardson td_offset |= (tx_pkt->l3_len >> 2) << 388c1d14583SBruce Richardson ICE_TX_DESC_LEN_IPLEN_S; 389c1d14583SBruce Richardson } 390c1d14583SBruce Richardson 391c1d14583SBruce Richardson /* Enable L4 checksum offloads */ 392c1d14583SBruce Richardson switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) { 393c1d14583SBruce Richardson case RTE_MBUF_F_TX_TCP_CKSUM: 394c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_TCP; 395c1d14583SBruce Richardson td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) << 396c1d14583SBruce Richardson ICE_TX_DESC_LEN_L4_LEN_S; 397c1d14583SBruce Richardson break; 398c1d14583SBruce Richardson case RTE_MBUF_F_TX_SCTP_CKSUM: 399c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_SCTP; 400c1d14583SBruce Richardson td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) << 401c1d14583SBruce Richardson ICE_TX_DESC_LEN_L4_LEN_S; 402c1d14583SBruce Richardson break; 403c1d14583SBruce Richardson case RTE_MBUF_F_TX_UDP_CKSUM: 404c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_L4T_EOFT_UDP; 405c1d14583SBruce Richardson td_offset |= (sizeof(struct rte_udp_hdr) >> 2) << 406c1d14583SBruce Richardson ICE_TX_DESC_LEN_L4_LEN_S; 407c1d14583SBruce Richardson break; 408c1d14583SBruce Richardson default: 409c1d14583SBruce Richardson break; 410c1d14583SBruce Richardson } 411c1d14583SBruce Richardson 412c1d14583SBruce Richardson *txd_hi |= ((uint64_t)td_offset) << ICE_TXD_QW1_OFFSET_S; 413c1d14583SBruce Richardson 414c1d14583SBruce Richardson /* Tx VLAN/QINQ insertion Offload */ 415c1d14583SBruce Richardson if (ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) { 416c1d14583SBruce Richardson td_cmd |= ICE_TX_DESC_CMD_IL2TAG1; 417c1d14583SBruce Richardson *txd_hi |= ((uint64_t)tx_pkt->vlan_tci << 418c1d14583SBruce Richardson ICE_TXD_QW1_L2TAG1_S); 419c1d14583SBruce Richardson } 420c1d14583SBruce Richardson 421c1d14583SBruce Richardson *txd_hi |= ((uint64_t)td_cmd) << ICE_TXD_QW1_CMD_S; 422c1d14583SBruce Richardson } 423c1d14583SBruce Richardson #endif 424