net/mlx4: add Tx bypassing Verbs
[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 #include <sys/queue.h>
39
40 /* Verbs headers do not support -pedantic. */
41 #ifdef PEDANTIC
42 #pragma GCC diagnostic ignored "-Wpedantic"
43 #endif
44 #include <infiniband/mlx4dv.h>
45 #include <infiniband/verbs.h>
46 #ifdef PEDANTIC
47 #pragma GCC diagnostic error "-Wpedantic"
48 #endif
49
50 #include <rte_ethdev.h>
51 #include <rte_mbuf.h>
52 #include <rte_mempool.h>
53
54 #include "mlx4.h"
55 #include "mlx4_prm.h"
56
57 /** Rx queue counters. */
58 struct mlx4_rxq_stats {
59         unsigned int idx; /**< Mapping index. */
60         uint64_t ipackets; /**< Total of successfully received packets. */
61         uint64_t ibytes; /**< Total of successfully received bytes. */
62         uint64_t idropped; /**< Total of packets dropped when Rx ring full. */
63         uint64_t rx_nombuf; /**< Total of Rx mbuf allocation failures. */
64 };
65
66 /** Rx element. */
67 struct rxq_elt {
68         struct ibv_recv_wr wr; /**< Work request. */
69         struct ibv_sge sge; /**< Scatter/gather element. */
70         struct rte_mbuf *buf; /**< Buffer. */
71 };
72
73 /** Rx queue descriptor. */
74 struct rxq {
75         struct priv *priv; /**< Back pointer to private data. */
76         struct rte_mempool *mp; /**< Memory pool for allocations. */
77         struct ibv_mr *mr; /**< Memory region (for mp). */
78         struct ibv_cq *cq; /**< Completion queue. */
79         struct ibv_wq *wq; /**< Work queue. */
80         struct ibv_comp_channel *channel; /**< Rx completion channel. */
81         unsigned int port_id; /**< Port ID for incoming packets. */
82         unsigned int elts_n; /**< (*elts)[] length. */
83         unsigned int elts_head; /**< Current index in (*elts)[]. */
84         struct rxq_elt (*elts)[]; /**< Rx elements. */
85         struct mlx4_rxq_stats stats; /**< Rx queue counters. */
86         unsigned int socket; /**< CPU socket ID for allocations. */
87         uint8_t data[]; /**< Remaining queue resources. */
88 };
89
90 /** Shared flow target for Rx queues. */
91 struct mlx4_rss {
92         LIST_ENTRY(mlx4_rss) next; /**< Next entry in list. */
93         struct priv *priv; /**< Back pointer to private data. */
94         uint32_t refcnt; /**< Reference count for this object. */
95         uint32_t usecnt; /**< Number of users relying on @p qp and @p ind. */
96         struct ibv_qp *qp; /**< Queue pair. */
97         struct ibv_rwq_ind_table *ind; /**< Indirection table. */
98         uint64_t fields; /**< Fields for RSS processing (Verbs format). */
99         uint8_t key[MLX4_RSS_HASH_KEY_SIZE]; /**< Hash key to use. */
100         uint16_t queues; /**< Number of target queues. */
101         uint16_t queue_id[]; /**< Target queues. */
102 };
103
104 /** Tx element. */
105 struct txq_elt {
106         struct rte_mbuf *buf; /**< Buffer. */
107 };
108
109 /** Rx queue counters. */
110 struct mlx4_txq_stats {
111         unsigned int idx; /**< Mapping index. */
112         uint64_t opackets; /**< Total of successfully sent packets. */
113         uint64_t obytes; /**< Total of successfully sent bytes. */
114         uint64_t odropped; /**< Total of packets not sent when Tx ring full. */
115 };
116
117 /** Tx queue descriptor. */
118 struct txq {
119         struct mlx4_sq msq; /**< Info for directly manipulating the SQ. */
120         struct mlx4_cq mcq; /**< Info for directly manipulating the CQ. */
121         unsigned int elts_head; /**< Current index in (*elts)[]. */
122         unsigned int elts_tail; /**< First element awaiting completion. */
123         unsigned int elts_comp; /**< Number of packets awaiting completion. */
124         int elts_comp_cd; /**< Countdown for next completion. */
125         unsigned int elts_comp_cd_init; /**< Initial value for countdown. */
126         unsigned int elts_n; /**< (*elts)[] length. */
127         struct txq_elt (*elts)[]; /**< Tx elements. */
128         struct mlx4_txq_stats stats; /**< Tx queue counters. */
129         uint32_t max_inline; /**< Max inline send size. */
130         uint8_t *bounce_buf;
131         /**< Memory used for storing the first DWORD of data TXBBs. */
132         struct {
133                 const struct rte_mempool *mp; /**< Cached memory pool. */
134                 struct ibv_mr *mr; /**< Memory region (for mp). */
135                 uint32_t lkey; /**< mr->lkey copy. */
136         } mp2mr[MLX4_PMD_TX_MP_CACHE]; /**< MP to MR translation table. */
137         struct priv *priv; /**< Back pointer to private data. */
138         unsigned int socket; /**< CPU socket ID for allocations. */
139         struct ibv_cq *cq; /**< Completion queue. */
140         struct ibv_qp *qp; /**< Queue pair. */
141         uint8_t data[]; /**< Remaining queue resources. */
142 };
143
144 /* mlx4_rxq.c */
145
146 uint8_t mlx4_rss_hash_key_default[MLX4_RSS_HASH_KEY_SIZE];
147 struct mlx4_rss *mlx4_rss_get(struct priv *priv, uint64_t fields,
148                               uint8_t key[MLX4_RSS_HASH_KEY_SIZE],
149                               uint16_t queues, const uint16_t queue_id[]);
150 void mlx4_rss_put(struct mlx4_rss *rss);
151 int mlx4_rss_attach(struct mlx4_rss *rss);
152 void mlx4_rss_detach(struct mlx4_rss *rss);
153 int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
154                         uint16_t desc, unsigned int socket,
155                         const struct rte_eth_rxconf *conf,
156                         struct rte_mempool *mp);
157 void mlx4_rx_queue_release(void *dpdk_rxq);
158
159 /* mlx4_rxtx.c */
160
161 uint32_t mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp);
162 uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
163                        uint16_t pkts_n);
164 uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
165                        uint16_t pkts_n);
166 uint16_t mlx4_tx_burst_removed(void *dpdk_txq, struct rte_mbuf **pkts,
167                                uint16_t pkts_n);
168 uint16_t mlx4_rx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts,
169                                uint16_t pkts_n);
170
171 /* mlx4_txq.c */
172
173 int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
174                         uint16_t desc, unsigned int socket,
175                         const struct rte_eth_txconf *conf);
176 void mlx4_tx_queue_release(void *dpdk_txq);
177
178 #endif /* MLX4_RXTX_H_ */