32f46ae49f867993bba73a5dfbf29165e50a874f
[dpdk.git] / drivers / net / octeontx / octeontx_rxtx.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc. 2017. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <stdint.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37
38 #include <rte_atomic.h>
39 #include <rte_common.h>
40 #include <rte_ethdev.h>
41 #include <rte_ether.h>
42 #include <rte_log.h>
43 #include <rte_mbuf.h>
44 #include <rte_prefetch.h>
45
46 #include "octeontx_ethdev.h"
47 #include "octeontx_rxtx.h"
48 #include "octeontx_logs.h"
49
50 static __rte_always_inline uint16_t __hot
51 __octeontx_xmit_pkts(void *lmtline_va, void *ioreg_va, int64_t *fc_status_va,
52                         struct rte_mbuf *tx_pkt)
53 {
54         uint64_t cmd_buf[4];
55         uint16_t gaura_id;
56
57         if (unlikely(*((volatile int64_t *)fc_status_va) < 0))
58                 return -ENOSPC;
59
60         /* Get the gaura Id */
61         gaura_id = octeontx_fpa_bufpool_gpool((uintptr_t)tx_pkt->pool->pool_id);
62
63         /* Setup PKO_SEND_HDR_S */
64         cmd_buf[0] = tx_pkt->data_len & 0xffff;
65         cmd_buf[1] = 0x0;
66
67         /* Set don't free bit if reference count > 1 */
68         if (rte_mbuf_refcnt_read(tx_pkt) > 1)
69                 cmd_buf[0] |= (1ULL << 58); /* SET DF */
70
71         /* Setup PKO_SEND_GATHER_S */
72         cmd_buf[(1 << 1) | 1] = rte_mbuf_data_dma_addr(tx_pkt);
73         cmd_buf[(1 << 1) | 0] = PKO_SEND_GATHER_SUBDC |
74                                 PKO_SEND_GATHER_LDTYPE(0x1ull) |
75                                 PKO_SEND_GATHER_GAUAR((long)gaura_id) |
76                                 tx_pkt->data_len;
77
78         octeontx_reg_lmtst(lmtline_va, ioreg_va, cmd_buf, PKO_CMD_SZ);
79
80         return 0;
81 }
82
83 uint16_t __hot
84 octeontx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
85 {
86         int count;
87         struct octeontx_txq *txq = tx_queue;
88         octeontx_dq_t *dq = &txq->dq;
89         int res;
90
91         count = 0;
92
93         while (count < nb_pkts) {
94                 res = __octeontx_xmit_pkts(dq->lmtline_va, dq->ioreg_va,
95                                            dq->fc_status_va,
96                                            tx_pkts[count]);
97                 if (res < 0)
98                         break;
99
100                 count++;
101         }
102
103         return count; /* return number of pkts transmitted */
104 }