net/bnxt: add Tx queue create/destroy
[dpdk.git] / drivers / net / bnxt / bnxt_txq.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Broadcom Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <inttypes.h>
35
36 #include <rte_malloc.h>
37
38 #include "bnxt.h"
39 #include "bnxt_ring.h"
40 #include "bnxt_txq.h"
41
42 /*
43  * TX Queues
44  */
45
46 void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
47 {
48         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
49
50         /* 'Unreserve' rte_memzone */
51
52         if (cpr->hw_stats)
53                 cpr->hw_stats = NULL;
54 }
55
56 static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq __rte_unused)
57 {
58         /* TODO: Requires interaction with TX ring */
59 }
60
61 void bnxt_free_tx_mbufs(struct bnxt *bp)
62 {
63         struct bnxt_tx_queue *txq;
64         int i;
65
66         for (i = 0; i < (int)bp->tx_nr_rings; i++) {
67                 txq = bp->tx_queues[i];
68                 bnxt_tx_queue_release_mbufs(txq);
69         }
70 }
71
72 void bnxt_tx_queue_release_op(void *tx_queue)
73 {
74         struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
75
76         if (txq) {
77                 /* TODO: Free ring and stats here */
78                 rte_free(txq);
79         }
80 }
81
82 int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
83                                uint16_t queue_idx,
84                                uint16_t nb_desc,
85                                unsigned int socket_id,
86                                const struct rte_eth_txconf *tx_conf)
87 {
88         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
89         struct bnxt_tx_queue *txq;
90
91         if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
92                 RTE_LOG(ERR, PMD, "nb_desc %d is invalid", nb_desc);
93                 return -EINVAL;
94         }
95
96         if (eth_dev->data->tx_queues) {
97                 txq = eth_dev->data->tx_queues[queue_idx];
98                 if (txq) {
99                         bnxt_tx_queue_release_op(txq);
100                         txq = NULL;
101                 }
102         }
103         txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
104                                  RTE_CACHE_LINE_SIZE, socket_id);
105         if (txq == NULL) {
106                 RTE_LOG(ERR, PMD, "bnxt_tx_queue allocation failed!");
107                 return -ENOMEM;
108         }
109         txq->bp = bp;
110         txq->nb_tx_desc = nb_desc;
111         txq->tx_free_thresh = tx_conf->tx_free_thresh;
112
113         /* TODO: Initialize ring structure */
114
115         txq->queue_id = queue_idx;
116         txq->port_id = eth_dev->data->port_id;
117
118         /* TODO: Allocate TX ring hardware descriptors */
119
120         /* TODO: Initialize the ring */
121
122         eth_dev->data->tx_queues[queue_idx] = txq;
123         return 0;
124 }