net/mlx4: convert Rx path to work queues
[dpdk.git] / drivers / net / mlx4 / mlx4_rxtx.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2017 6WIND S.A.
5  *   Copyright 2017 Mellanox
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 6WIND S.A. 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 #ifndef MLX4_RXTX_H_
35 #define MLX4_RXTX_H_
36
37 #include <stdint.h>
38
39 /* Verbs headers do not support -pedantic. */
40 #ifdef PEDANTIC
41 #pragma GCC diagnostic ignored "-Wpedantic"
42 #endif
43 #include <infiniband/verbs.h>
44 #ifdef PEDANTIC
45 #pragma GCC diagnostic error "-Wpedantic"
46 #endif
47
48 #include <rte_ethdev.h>
49 #include <rte_mbuf.h>
50 #include <rte_mempool.h>
51
52 #include "mlx4.h"
53
54 /** Rx queue counters. */
55 struct mlx4_rxq_stats {
56         unsigned int idx; /**< Mapping index. */
57         uint64_t ipackets; /**< Total of successfully received packets. */
58         uint64_t ibytes; /**< Total of successfully received bytes. */
59         uint64_t idropped; /**< Total of packets dropped when Rx ring full. */
60         uint64_t rx_nombuf; /**< Total of Rx mbuf allocation failures. */
61 };
62
63 /** Rx element. */
64 struct rxq_elt {
65         struct ibv_recv_wr wr; /**< Work request. */
66         struct ibv_sge sge; /**< Scatter/gather element. */
67         struct rte_mbuf *buf; /**< Buffer. */
68 };
69
70 /** Rx queue descriptor. */
71 struct rxq {
72         struct priv *priv; /**< Back pointer to private data. */
73         struct rte_mempool *mp; /**< Memory pool for allocations. */
74         struct ibv_mr *mr; /**< Memory region (for mp). */
75         struct ibv_cq *cq; /**< Completion queue. */
76         struct ibv_wq *wq; /**< Work queue. */
77         struct ibv_rwq_ind_table *ind; /**< Indirection table. */
78         struct ibv_qp *qp; /**< Queue pair. */
79         struct ibv_comp_channel *channel; /**< Rx completion channel. */
80         unsigned int port_id; /**< Port ID for incoming packets. */
81         unsigned int elts_n; /**< (*elts)[] length. */
82         unsigned int elts_head; /**< Current index in (*elts)[]. */
83         struct rxq_elt (*elts)[]; /**< Rx elements. */
84         struct mlx4_rxq_stats stats; /**< Rx queue counters. */
85         unsigned int socket; /**< CPU socket ID for allocations. */
86         uint8_t data[]; /**< Remaining queue resources. */
87 };
88
89 /** Tx element. */
90 struct txq_elt {
91         struct ibv_send_wr wr; /**< Work request. */
92         struct ibv_sge sge; /**< Scatter/gather element. */
93         struct rte_mbuf *buf; /**< Buffer. */
94 };
95
96 /** Rx queue counters. */
97 struct mlx4_txq_stats {
98         unsigned int idx; /**< Mapping index. */
99         uint64_t opackets; /**< Total of successfully sent packets. */
100         uint64_t obytes; /**< Total of successfully sent bytes. */
101         uint64_t odropped; /**< Total of packets not sent when Tx ring full. */
102 };
103
104 /** Tx queue descriptor. */
105 struct txq {
106         struct priv *priv; /**< Back pointer to private data. */
107         struct {
108                 const struct rte_mempool *mp; /**< Cached memory pool. */
109                 struct ibv_mr *mr; /**< Memory region (for mp). */
110                 uint32_t lkey; /**< mr->lkey copy. */
111         } mp2mr[MLX4_PMD_TX_MP_CACHE]; /**< MP to MR translation table. */
112         struct ibv_cq *cq; /**< Completion queue. */
113         struct ibv_qp *qp; /**< Queue pair. */
114         uint32_t max_inline; /**< Max inline send size. */
115         unsigned int elts_n; /**< (*elts)[] length. */
116         struct txq_elt (*elts)[]; /**< Tx elements. */
117         unsigned int elts_head; /**< Current index in (*elts)[]. */
118         unsigned int elts_tail; /**< First element awaiting completion. */
119         unsigned int elts_comp; /**< Number of completion requests. */
120         unsigned int elts_comp_cd; /**< Countdown for next completion. */
121         unsigned int elts_comp_cd_init; /**< Initial value for countdown. */
122         struct mlx4_txq_stats stats; /**< Tx queue counters. */
123         unsigned int socket; /**< CPU socket ID for allocations. */
124         uint8_t data[]; /**< Remaining queue resources. */
125 };
126
127 /* mlx4_rxq.c */
128
129 int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
130                         uint16_t desc, unsigned int socket,
131                         const struct rte_eth_rxconf *conf,
132                         struct rte_mempool *mp);
133 void mlx4_rx_queue_release(void *dpdk_rxq);
134
135 /* mlx4_rxtx.c */
136
137 uint32_t mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp);
138 uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
139                        uint16_t pkts_n);
140 uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
141                        uint16_t pkts_n);
142 uint16_t mlx4_tx_burst_removed(void *dpdk_txq, struct rte_mbuf **pkts,
143                                uint16_t pkts_n);
144 uint16_t mlx4_rx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts,
145                                uint16_t pkts_n);
146
147 /* mlx4_txq.c */
148
149 int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
150                         uint16_t desc, unsigned int socket,
151                         const struct rte_eth_txconf *conf);
152 void mlx4_tx_queue_release(void *dpdk_txq);
153
154 #endif /* MLX4_RXTX_H_ */