ethdev: introduce generic dummy packet burst function
[dpdk.git] / drivers / net / hns3 / hns3_rxtx_vec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020-2021 HiSilicon Limited.
3  */
4
5 #ifndef _HNS3_RXTX_VEC_H_
6 #define _HNS3_RXTX_VEC_H_
7
8 #include "hns3_rxtx.h"
9 #include "hns3_ethdev.h"
10
11 static inline void
12 hns3_tx_bulk_free_buffers(struct hns3_tx_queue *txq)
13 {
14         struct rte_mbuf **free = txq->free;
15         struct hns3_entry *tx_entry;
16         struct rte_mbuf *m;
17         int nb_free = 0;
18         int i;
19
20         tx_entry = &txq->sw_ring[txq->next_to_clean];
21         if (txq->mbuf_fast_free_en) {
22                 rte_mempool_put_bulk(tx_entry->mbuf->pool, (void **)tx_entry,
23                                      txq->tx_rs_thresh);
24                 for (i = 0; i < txq->tx_rs_thresh; i++)
25                         tx_entry[i].mbuf = NULL;
26                 goto update_field;
27         }
28
29         for (i = 0; i < txq->tx_rs_thresh; i++, tx_entry++) {
30                 m = rte_pktmbuf_prefree_seg(tx_entry->mbuf);
31                 tx_entry->mbuf = NULL;
32
33                 if (m == NULL)
34                         continue;
35
36                 if (nb_free && m->pool != free[0]->pool) {
37                         rte_mempool_put_bulk(free[0]->pool, (void **)free,
38                                              nb_free);
39                         nb_free = 0;
40                 }
41                 free[nb_free++] = m;
42         }
43
44         if (nb_free)
45                 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
46
47 update_field:
48         /* Update numbers of available descriptor due to buffer freed */
49         txq->tx_bd_ready += txq->tx_rs_thresh;
50         txq->next_to_clean += txq->tx_rs_thresh;
51         if (txq->next_to_clean >= txq->nb_tx_desc)
52                 txq->next_to_clean = 0;
53 }
54
55 static inline void
56 hns3_tx_free_buffers(struct hns3_tx_queue *txq)
57 {
58         struct hns3_desc *tx_desc;
59         int i;
60
61         /*
62          * All mbufs can be released only when the VLD bits of all
63          * descriptors in a batch are cleared.
64          */
65         tx_desc = &txq->tx_ring[txq->next_to_clean];
66         for (i = 0; i < txq->tx_rs_thresh; i++, tx_desc++) {
67                 if (tx_desc->tx.tp_fe_sc_vld_ra_ri &
68                                 rte_le_to_cpu_16(BIT(HNS3_TXD_VLD_B)))
69                         return;
70         }
71
72         hns3_tx_bulk_free_buffers(txq);
73 }
74
75 static inline uint16_t
76 hns3_rx_reassemble_pkts(struct rte_mbuf **rx_pkts,
77                         uint16_t nb_pkts,
78                         uint64_t pkt_err_mask)
79 {
80         uint16_t count, i;
81         uint64_t mask;
82
83         if (likely(pkt_err_mask == 0))
84                 return nb_pkts;
85
86         count = 0;
87         for (i = 0; i < nb_pkts; i++) {
88                 mask = ((uint64_t)1u) << i;
89                 if (pkt_err_mask & mask)
90                         rte_pktmbuf_free_seg(rx_pkts[i]);
91                 else
92                         rx_pkts[count++] = rx_pkts[i];
93         }
94
95         return count;
96 }
97 #endif /* _HNS3_RXTX_VEC_H_ */