net/nfb: add new netcope driver
[dpdk.git] / drivers / net / nfb / nfb_tx.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Cesnet
3  * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
4  * All rights reserved.
5  */
6
7 #include "nfb_tx.h"
8 #include "nfb.h"
9
10 int
11 nfb_eth_tx_queue_start(struct rte_eth_dev *dev, uint16_t txq_id)
12 {
13         struct ndp_tx_queue *txq = dev->data->tx_queues[txq_id];
14         int ret;
15
16         if (txq->queue == NULL) {
17                 RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
18                 return -EINVAL;
19         }
20
21         ret = ndp_queue_start(txq->queue);
22         if (ret != 0)
23                 goto err;
24         dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STARTED;
25         return 0;
26
27 err:
28         return -EINVAL;
29 }
30
31 int
32 nfb_eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t txq_id)
33 {
34         struct ndp_tx_queue *txq = dev->data->tx_queues[txq_id];
35         int ret;
36
37         if (txq->queue == NULL) {
38                 RTE_LOG(ERR, PMD, "TX NDP queue is NULL!\n");
39                 return -EINVAL;
40         }
41
42         ret = ndp_queue_stop(txq->queue);
43         if (ret != 0)
44                 return -EINVAL;
45         dev->data->tx_queue_state[txq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
46         return 0;
47 }
48
49 int
50 nfb_eth_tx_queue_setup(struct rte_eth_dev *dev,
51         uint16_t tx_queue_id,
52         uint16_t nb_tx_desc __rte_unused,
53         unsigned int socket_id,
54         const struct rte_eth_txconf *tx_conf __rte_unused)
55 {
56         struct pmd_internals *internals = dev->data->dev_private;
57         int ret;
58         struct ndp_tx_queue *txq;
59
60         txq = rte_zmalloc_socket("ndp tx queue",
61                 sizeof(struct ndp_tx_queue),
62                 RTE_CACHE_LINE_SIZE, socket_id);
63
64         if (txq == NULL) {
65                 RTE_LOG(ERR, PMD, "rte_zmalloc_socket() failed for tx queue id "
66                         "%" PRIu16 "!\n", tx_queue_id);
67                 return -ENOMEM;
68         }
69
70         ret = nfb_eth_tx_queue_init(internals->nfb,
71                 tx_queue_id,
72                 txq);
73
74         if (ret == 0)
75                 dev->data->tx_queues[tx_queue_id] = txq;
76         else
77                 rte_free(txq);
78
79         return ret;
80 }
81
82 int
83 nfb_eth_tx_queue_init(struct nfb_device *nfb,
84         uint16_t tx_queue_id,
85         struct ndp_tx_queue *txq)
86 {
87         if (nfb == NULL)
88                 return -EINVAL;
89
90         txq->queue = ndp_open_tx_queue(nfb, tx_queue_id);
91         if (txq->queue == NULL)
92                 return -EINVAL;
93
94         txq->nfb = nfb;
95         txq->tx_queue_id = tx_queue_id;
96
97         txq->tx_pkts = 0;
98         txq->tx_bytes = 0;
99         txq->err_pkts = 0;
100
101         return 0;
102 }
103
104 void
105 nfb_eth_tx_queue_release(void *q)
106 {
107         struct ndp_tx_queue *txq = (struct ndp_tx_queue *)q;
108         if (txq->queue != NULL) {
109                 ndp_close_tx_queue(txq->queue);
110                 rte_free(txq);
111                 txq->queue = NULL;
112         }
113 }