e878ee1d24c804ddb932c66a51150020aa283322
[dpdk.git] / drivers / net / hns3 / hns3_rxtx_vec_neon.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Hisilicon Limited.
3  */
4
5 #ifndef _HNS3_RXTX_VEC_NEON_H_
6 #define _HNS3_RXTX_VEC_NEON_H_
7
8 #include <arm_neon.h>
9
10 #pragma GCC diagnostic ignored "-Wcast-qual"
11
12 static inline void
13 hns3_vec_tx(volatile struct hns3_desc *desc, struct rte_mbuf *pkt)
14 {
15         uint64x2_t val1 = {
16                 pkt->buf_iova + pkt->data_off,
17                 ((uint64_t)pkt->data_len) << HNS3_TXD_SEND_SIZE_SHIFT
18         };
19         uint64x2_t val2 = {
20                 0,
21                 ((uint64_t)HNS3_TXD_DEFAULT_VLD_FE_BDTYPE) << HNS3_UINT32_BIT
22         };
23         vst1q_u64((uint64_t *)&desc->addr, val1);
24         vst1q_u64((uint64_t *)&desc->tx.outer_vlan_tag, val2);
25 }
26
27 static uint16_t
28 hns3_xmit_fixed_burst_vec(void *__restrict tx_queue,
29                           struct rte_mbuf **__restrict tx_pkts,
30                           uint16_t nb_pkts)
31 {
32         struct hns3_tx_queue *txq = (struct hns3_tx_queue *)tx_queue;
33         volatile struct hns3_desc *tx_desc;
34         struct hns3_entry *tx_entry;
35         uint16_t next_to_use;
36         uint16_t nb_commit;
37         uint16_t nb_tx;
38         uint16_t n, i;
39
40         if (txq->tx_bd_ready < txq->tx_free_thresh)
41                 hns3_tx_free_buffers(txq);
42
43         nb_commit = RTE_MIN(txq->tx_bd_ready, nb_pkts);
44         if (unlikely(nb_commit == 0)) {
45                 txq->queue_full_cnt++;
46                 return 0;
47         }
48         nb_tx = nb_commit;
49
50         next_to_use = txq->next_to_use;
51         tx_desc = &txq->tx_ring[next_to_use];
52         tx_entry = &txq->sw_ring[next_to_use];
53
54         /*
55          * We need to deal with n descriptors first for better performance,
56          * if nb_commit is greater than the difference between txq->nb_tx_desc
57          * and next_to_use in sw_ring and tx_ring.
58          */
59         n = txq->nb_tx_desc - next_to_use;
60         if (nb_commit >= n) {
61                 for (i = 0; i < n; i++, tx_pkts++, tx_desc++) {
62                         hns3_vec_tx(tx_desc, *tx_pkts);
63                         tx_entry[i].mbuf = *tx_pkts;
64                 }
65
66                 nb_commit -= n;
67                 next_to_use = 0;
68                 tx_desc = &txq->tx_ring[next_to_use];
69                 tx_entry = &txq->sw_ring[next_to_use];
70         }
71
72         for (i = 0; i < nb_commit; i++, tx_pkts++, tx_desc++) {
73                 hns3_vec_tx(tx_desc, *tx_pkts);
74                 tx_entry[i].mbuf = *tx_pkts;
75         }
76
77         next_to_use += nb_commit;
78         txq->next_to_use = next_to_use;
79         txq->tx_bd_ready -= nb_tx;
80
81         hns3_write_reg_opt(txq->io_tail_reg, nb_tx);
82
83         return nb_tx;
84 }
85 #endif /* _HNS3_RXTX_VEC_NEON_H_ */