net/mlx5: add hardware checksum offload for tunnel packets
[dpdk.git] / drivers / net / mlx5 / mlx5_txq.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2015 6WIND S.A.
5  *   Copyright 2015 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 #include <stddef.h>
35 #include <assert.h>
36 #include <errno.h>
37 #include <string.h>
38 #include <stdint.h>
39
40 /* Verbs header. */
41 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
42 #ifdef PEDANTIC
43 #pragma GCC diagnostic ignored "-Wpedantic"
44 #endif
45 #include <infiniband/verbs.h>
46 #ifdef PEDANTIC
47 #pragma GCC diagnostic error "-Wpedantic"
48 #endif
49
50 /* DPDK headers don't like -pedantic. */
51 #ifdef PEDANTIC
52 #pragma GCC diagnostic ignored "-Wpedantic"
53 #endif
54 #include <rte_mbuf.h>
55 #include <rte_malloc.h>
56 #include <rte_ethdev.h>
57 #include <rte_common.h>
58 #ifdef PEDANTIC
59 #pragma GCC diagnostic error "-Wpedantic"
60 #endif
61
62 #include "mlx5_utils.h"
63 #include "mlx5_defs.h"
64 #include "mlx5.h"
65 #include "mlx5_rxtx.h"
66 #include "mlx5_autoconf.h"
67 #include "mlx5_defs.h"
68
69 /**
70  * Allocate TX queue elements.
71  *
72  * @param txq_ctrl
73  *   Pointer to TX queue structure.
74  * @param elts_n
75  *   Number of elements to allocate.
76  */
77 static void
78 txq_alloc_elts(struct txq_ctrl *txq_ctrl, unsigned int elts_n)
79 {
80         unsigned int i;
81
82         for (i = 0; (i != elts_n); ++i)
83                 (*txq_ctrl->txq.elts)[i] = NULL;
84         for (i = 0; (i != (1u << txq_ctrl->txq.wqe_n)); ++i) {
85                 volatile struct mlx5_wqe64 *wqe =
86                         (volatile struct mlx5_wqe64 *)
87                         txq_ctrl->txq.wqes + i;
88
89                 memset((void *)(uintptr_t)wqe, 0x0, sizeof(*wqe));
90         }
91         DEBUG("%p: allocated and configured %u WRs", (void *)txq_ctrl, elts_n);
92         txq_ctrl->txq.elts_head = 0;
93         txq_ctrl->txq.elts_tail = 0;
94         txq_ctrl->txq.elts_comp = 0;
95 }
96
97 /**
98  * Free TX queue elements.
99  *
100  * @param txq_ctrl
101  *   Pointer to TX queue structure.
102  */
103 static void
104 txq_free_elts(struct txq_ctrl *txq_ctrl)
105 {
106         unsigned int elts_n = 1 << txq_ctrl->txq.elts_n;
107         unsigned int elts_head = txq_ctrl->txq.elts_head;
108         unsigned int elts_tail = txq_ctrl->txq.elts_tail;
109         struct rte_mbuf *(*elts)[elts_n] = txq_ctrl->txq.elts;
110
111         DEBUG("%p: freeing WRs", (void *)txq_ctrl);
112         txq_ctrl->txq.elts_head = 0;
113         txq_ctrl->txq.elts_tail = 0;
114         txq_ctrl->txq.elts_comp = 0;
115
116         while (elts_tail != elts_head) {
117                 struct rte_mbuf *elt = (*elts)[elts_tail];
118
119                 assert(elt != NULL);
120                 rte_pktmbuf_free(elt);
121 #ifndef NDEBUG
122                 /* Poisoning. */
123                 memset(&(*elts)[elts_tail],
124                        0x77,
125                        sizeof((*elts)[elts_tail]));
126 #endif
127                 if (++elts_tail == elts_n)
128                         elts_tail = 0;
129         }
130 }
131
132 /**
133  * Clean up a TX queue.
134  *
135  * Destroy objects, free allocated memory and reset the structure for reuse.
136  *
137  * @param txq_ctrl
138  *   Pointer to TX queue structure.
139  */
140 void
141 txq_cleanup(struct txq_ctrl *txq_ctrl)
142 {
143         struct ibv_exp_release_intf_params params;
144         size_t i;
145
146         DEBUG("cleaning up %p", (void *)txq_ctrl);
147         txq_free_elts(txq_ctrl);
148         if (txq_ctrl->if_qp != NULL) {
149                 assert(txq_ctrl->priv != NULL);
150                 assert(txq_ctrl->priv->ctx != NULL);
151                 assert(txq_ctrl->qp != NULL);
152                 params = (struct ibv_exp_release_intf_params){
153                         .comp_mask = 0,
154                 };
155                 claim_zero(ibv_exp_release_intf(txq_ctrl->priv->ctx,
156                                                 txq_ctrl->if_qp,
157                                                 &params));
158         }
159         if (txq_ctrl->if_cq != NULL) {
160                 assert(txq_ctrl->priv != NULL);
161                 assert(txq_ctrl->priv->ctx != NULL);
162                 assert(txq_ctrl->cq != NULL);
163                 params = (struct ibv_exp_release_intf_params){
164                         .comp_mask = 0,
165                 };
166                 claim_zero(ibv_exp_release_intf(txq_ctrl->priv->ctx,
167                                                 txq_ctrl->if_cq,
168                                                 &params));
169         }
170         if (txq_ctrl->qp != NULL)
171                 claim_zero(ibv_destroy_qp(txq_ctrl->qp));
172         if (txq_ctrl->cq != NULL)
173                 claim_zero(ibv_destroy_cq(txq_ctrl->cq));
174         if (txq_ctrl->rd != NULL) {
175                 struct ibv_exp_destroy_res_domain_attr attr = {
176                         .comp_mask = 0,
177                 };
178
179                 assert(txq_ctrl->priv != NULL);
180                 assert(txq_ctrl->priv->ctx != NULL);
181                 claim_zero(ibv_exp_destroy_res_domain(txq_ctrl->priv->ctx,
182                                                       txq_ctrl->rd,
183                                                       &attr));
184         }
185         for (i = 0; (i != RTE_DIM(txq_ctrl->txq.mp2mr)); ++i) {
186                 if (txq_ctrl->txq.mp2mr[i].mp == NULL)
187                         break;
188                 assert(txq_ctrl->txq.mp2mr[i].mr != NULL);
189                 claim_zero(ibv_dereg_mr(txq_ctrl->txq.mp2mr[i].mr));
190         }
191         memset(txq_ctrl, 0, sizeof(*txq_ctrl));
192 }
193
194 /**
195  * Initialize TX queue.
196  *
197  * @param tmpl
198  *   Pointer to TX queue control template.
199  * @param txq_ctrl
200  *   Pointer to TX queue control.
201  *
202  * @return
203  *   0 on success, errno value on failure.
204  */
205 static inline int
206 txq_setup(struct txq_ctrl *tmpl, struct txq_ctrl *txq_ctrl)
207 {
208         struct mlx5_qp *qp = to_mqp(tmpl->qp);
209         struct ibv_cq *ibcq = tmpl->cq;
210         struct mlx5_cq *cq = to_mxxx(cq, cq);
211
212         if (cq->cqe_sz != RTE_CACHE_LINE_SIZE) {
213                 ERROR("Wrong MLX5_CQE_SIZE environment variable value: "
214                       "it should be set to %u", RTE_CACHE_LINE_SIZE);
215                 return EINVAL;
216         }
217         tmpl->txq.cqe_n = log2above(ibcq->cqe);
218         tmpl->txq.qp_num_8s = qp->ctrl_seg.qp_num << 8;
219         tmpl->txq.wqes = qp->gen_data.sqstart;
220         tmpl->txq.wqe_n = log2above(qp->sq.wqe_cnt);
221         tmpl->txq.qp_db = &qp->gen_data.db[MLX5_SND_DBR];
222         tmpl->txq.bf_reg = qp->gen_data.bf->reg;
223         tmpl->txq.cq_db = cq->dbrec;
224         tmpl->txq.cqes =
225                 (volatile struct mlx5_cqe (*)[])
226                 (uintptr_t)cq->active_buf->buf;
227         tmpl->txq.elts =
228                 (struct rte_mbuf *(*)[1 << tmpl->txq.elts_n])
229                 ((uintptr_t)txq_ctrl + sizeof(*txq_ctrl));
230         return 0;
231 }
232
233 /**
234  * Configure a TX queue.
235  *
236  * @param dev
237  *   Pointer to Ethernet device structure.
238  * @param txq_ctrl
239  *   Pointer to TX queue structure.
240  * @param desc
241  *   Number of descriptors to configure in queue.
242  * @param socket
243  *   NUMA socket on which memory must be allocated.
244  * @param[in] conf
245  *   Thresholds parameters.
246  *
247  * @return
248  *   0 on success, errno value on failure.
249  */
250 int
251 txq_ctrl_setup(struct rte_eth_dev *dev, struct txq_ctrl *txq_ctrl,
252                uint16_t desc, unsigned int socket,
253                const struct rte_eth_txconf *conf)
254 {
255         struct priv *priv = mlx5_get_priv(dev);
256         struct txq_ctrl tmpl = {
257                 .priv = priv,
258                 .socket = socket,
259         };
260         union {
261                 struct ibv_exp_query_intf_params params;
262                 struct ibv_exp_qp_init_attr init;
263                 struct ibv_exp_res_domain_init_attr rd;
264                 struct ibv_exp_cq_init_attr cq;
265                 struct ibv_exp_qp_attr mod;
266                 struct ibv_exp_cq_attr cq_attr;
267         } attr;
268         enum ibv_exp_query_intf_status status;
269         int ret = 0;
270
271         if (mlx5_getenv_int("MLX5_ENABLE_CQE_COMPRESSION")) {
272                 ret = ENOTSUP;
273                 ERROR("MLX5_ENABLE_CQE_COMPRESSION must never be set");
274                 goto error;
275         }
276         (void)conf; /* Thresholds configuration (ignored). */
277         assert(desc > MLX5_TX_COMP_THRESH);
278         tmpl.txq.elts_n = log2above(desc);
279         /* MRs will be registered in mp2mr[] later. */
280         attr.rd = (struct ibv_exp_res_domain_init_attr){
281                 .comp_mask = (IBV_EXP_RES_DOMAIN_THREAD_MODEL |
282                               IBV_EXP_RES_DOMAIN_MSG_MODEL),
283                 .thread_model = IBV_EXP_THREAD_SINGLE,
284                 .msg_model = IBV_EXP_MSG_HIGH_BW,
285         };
286         tmpl.rd = ibv_exp_create_res_domain(priv->ctx, &attr.rd);
287         if (tmpl.rd == NULL) {
288                 ret = ENOMEM;
289                 ERROR("%p: RD creation failure: %s",
290                       (void *)dev, strerror(ret));
291                 goto error;
292         }
293         attr.cq = (struct ibv_exp_cq_init_attr){
294                 .comp_mask = IBV_EXP_CQ_INIT_ATTR_RES_DOMAIN,
295                 .res_domain = tmpl.rd,
296         };
297         tmpl.cq = ibv_exp_create_cq(priv->ctx,
298                                     (((desc / MLX5_TX_COMP_THRESH) - 1) ?
299                                      ((desc / MLX5_TX_COMP_THRESH) - 1) : 1),
300                                     NULL, NULL, 0, &attr.cq);
301         if (tmpl.cq == NULL) {
302                 ret = ENOMEM;
303                 ERROR("%p: CQ creation failure: %s",
304                       (void *)dev, strerror(ret));
305                 goto error;
306         }
307         DEBUG("priv->device_attr.max_qp_wr is %d",
308               priv->device_attr.max_qp_wr);
309         DEBUG("priv->device_attr.max_sge is %d",
310               priv->device_attr.max_sge);
311         attr.init = (struct ibv_exp_qp_init_attr){
312                 /* CQ to be associated with the send queue. */
313                 .send_cq = tmpl.cq,
314                 /* CQ to be associated with the receive queue. */
315                 .recv_cq = tmpl.cq,
316                 .cap = {
317                         /* Max number of outstanding WRs. */
318                         .max_send_wr = ((priv->device_attr.max_qp_wr < desc) ?
319                                         priv->device_attr.max_qp_wr :
320                                         desc),
321                         /*
322                          * Max number of scatter/gather elements in a WR,
323                          * must be 1 to prevent libmlx5 from trying to affect
324                          * too much memory. TX gather is not impacted by the
325                          * priv->device_attr.max_sge limit and will still work
326                          * properly.
327                          */
328                         .max_send_sge = 1,
329                 },
330                 .qp_type = IBV_QPT_RAW_PACKET,
331                 /* Do *NOT* enable this, completions events are managed per
332                  * TX burst. */
333                 .sq_sig_all = 0,
334                 .pd = priv->pd,
335                 .res_domain = tmpl.rd,
336                 .comp_mask = (IBV_EXP_QP_INIT_ATTR_PD |
337                               IBV_EXP_QP_INIT_ATTR_RES_DOMAIN),
338         };
339         if (priv->txq_inline && (priv->txqs_n >= priv->txqs_inline)) {
340                 tmpl.txq.max_inline =
341                         ((priv->txq_inline + (RTE_CACHE_LINE_SIZE - 1)) /
342                          RTE_CACHE_LINE_SIZE);
343                 attr.init.cap.max_inline_data =
344                         tmpl.txq.max_inline * RTE_CACHE_LINE_SIZE;
345                 tmpl.txq.inline_en = 1;
346         }
347         if (priv->tso) {
348                 uint16_t max_tso_inline = ((MLX5_MAX_TSO_HEADER +
349                                            (RTE_CACHE_LINE_SIZE - 1)) /
350                                             RTE_CACHE_LINE_SIZE);
351
352                 attr.init.max_tso_header =
353                         max_tso_inline * RTE_CACHE_LINE_SIZE;
354                 attr.init.comp_mask |= IBV_EXP_QP_INIT_ATTR_MAX_TSO_HEADER;
355                 tmpl.txq.max_inline = RTE_MAX(tmpl.txq.max_inline,
356                                               max_tso_inline);
357                 tmpl.txq.tso_en = 1;
358         }
359         if (priv->tunnel_en)
360                 tmpl.txq.tunnel_en = 1;
361         tmpl.qp = ibv_exp_create_qp(priv->ctx, &attr.init);
362         if (tmpl.qp == NULL) {
363                 ret = (errno ? errno : EINVAL);
364                 ERROR("%p: QP creation failure: %s",
365                       (void *)dev, strerror(ret));
366                 goto error;
367         }
368         DEBUG("TX queue capabilities: max_send_wr=%u, max_send_sge=%u,"
369               " max_inline_data=%u",
370               attr.init.cap.max_send_wr,
371               attr.init.cap.max_send_sge,
372               attr.init.cap.max_inline_data);
373         attr.mod = (struct ibv_exp_qp_attr){
374                 /* Move the QP to this state. */
375                 .qp_state = IBV_QPS_INIT,
376                 /* Primary port number. */
377                 .port_num = priv->port
378         };
379         ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod,
380                                 (IBV_EXP_QP_STATE | IBV_EXP_QP_PORT));
381         if (ret) {
382                 ERROR("%p: QP state to IBV_QPS_INIT failed: %s",
383                       (void *)dev, strerror(ret));
384                 goto error;
385         }
386         ret = txq_setup(&tmpl, txq_ctrl);
387         if (ret) {
388                 ERROR("%p: cannot initialize TX queue structure: %s",
389                       (void *)dev, strerror(ret));
390                 goto error;
391         }
392         txq_alloc_elts(&tmpl, desc);
393         attr.mod = (struct ibv_exp_qp_attr){
394                 .qp_state = IBV_QPS_RTR
395         };
396         ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE);
397         if (ret) {
398                 ERROR("%p: QP state to IBV_QPS_RTR failed: %s",
399                       (void *)dev, strerror(ret));
400                 goto error;
401         }
402         attr.mod.qp_state = IBV_QPS_RTS;
403         ret = ibv_exp_modify_qp(tmpl.qp, &attr.mod, IBV_EXP_QP_STATE);
404         if (ret) {
405                 ERROR("%p: QP state to IBV_QPS_RTS failed: %s",
406                       (void *)dev, strerror(ret));
407                 goto error;
408         }
409         attr.params = (struct ibv_exp_query_intf_params){
410                 .intf_scope = IBV_EXP_INTF_GLOBAL,
411                 .intf = IBV_EXP_INTF_CQ,
412                 .obj = tmpl.cq,
413         };
414         tmpl.if_cq = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
415         if (tmpl.if_cq == NULL) {
416                 ret = EINVAL;
417                 ERROR("%p: CQ interface family query failed with status %d",
418                       (void *)dev, status);
419                 goto error;
420         }
421         attr.params = (struct ibv_exp_query_intf_params){
422                 .intf_scope = IBV_EXP_INTF_GLOBAL,
423                 .intf = IBV_EXP_INTF_QP_BURST,
424                 .intf_version = 1,
425                 .obj = tmpl.qp,
426                 /* Enable multi-packet send if supported. */
427                 .family_flags =
428                         (priv->mps ?
429                          IBV_EXP_QP_BURST_CREATE_ENABLE_MULTI_PACKET_SEND_WR :
430                          0),
431         };
432         tmpl.if_qp = ibv_exp_query_intf(priv->ctx, &attr.params, &status);
433         if (tmpl.if_qp == NULL) {
434                 ret = EINVAL;
435                 ERROR("%p: QP interface family query failed with status %d",
436                       (void *)dev, status);
437                 goto error;
438         }
439         /* Clean up txq in case we're reinitializing it. */
440         DEBUG("%p: cleaning-up old txq just in case", (void *)txq_ctrl);
441         txq_cleanup(txq_ctrl);
442         *txq_ctrl = tmpl;
443         DEBUG("%p: txq updated with %p", (void *)txq_ctrl, (void *)&tmpl);
444         /* Pre-register known mempools. */
445         rte_mempool_walk(txq_mp2mr_iter, txq_ctrl);
446         assert(ret == 0);
447         return 0;
448 error:
449         txq_cleanup(&tmpl);
450         assert(ret > 0);
451         return ret;
452 }
453
454 /**
455  * DPDK callback to configure a TX queue.
456  *
457  * @param dev
458  *   Pointer to Ethernet device structure.
459  * @param idx
460  *   TX queue index.
461  * @param desc
462  *   Number of descriptors to configure in queue.
463  * @param socket
464  *   NUMA socket on which memory must be allocated.
465  * @param[in] conf
466  *   Thresholds parameters.
467  *
468  * @return
469  *   0 on success, negative errno value on failure.
470  */
471 int
472 mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
473                     unsigned int socket, const struct rte_eth_txconf *conf)
474 {
475         struct priv *priv = dev->data->dev_private;
476         struct txq *txq = (*priv->txqs)[idx];
477         struct txq_ctrl *txq_ctrl = container_of(txq, struct txq_ctrl, txq);
478         int ret;
479
480         if (mlx5_is_secondary())
481                 return -E_RTE_SECONDARY;
482
483         priv_lock(priv);
484         if (desc <= MLX5_TX_COMP_THRESH) {
485                 WARN("%p: number of descriptors requested for TX queue %u"
486                      " must be higher than MLX5_TX_COMP_THRESH, using"
487                      " %u instead of %u",
488                      (void *)dev, idx, MLX5_TX_COMP_THRESH + 1, desc);
489                 desc = MLX5_TX_COMP_THRESH + 1;
490         }
491         if (!rte_is_power_of_2(desc)) {
492                 desc = 1 << log2above(desc);
493                 WARN("%p: increased number of descriptors in TX queue %u"
494                      " to the next power of two (%d)",
495                      (void *)dev, idx, desc);
496         }
497         DEBUG("%p: configuring queue %u for %u descriptors",
498               (void *)dev, idx, desc);
499         if (idx >= priv->txqs_n) {
500                 ERROR("%p: queue index out of range (%u >= %u)",
501                       (void *)dev, idx, priv->txqs_n);
502                 priv_unlock(priv);
503                 return -EOVERFLOW;
504         }
505         if (txq != NULL) {
506                 DEBUG("%p: reusing already allocated queue index %u (%p)",
507                       (void *)dev, idx, (void *)txq);
508                 if (priv->started) {
509                         priv_unlock(priv);
510                         return -EEXIST;
511                 }
512                 (*priv->txqs)[idx] = NULL;
513                 txq_cleanup(txq_ctrl);
514         } else {
515                 txq_ctrl =
516                         rte_calloc_socket("TXQ", 1,
517                                           sizeof(*txq_ctrl) +
518                                           desc * sizeof(struct rte_mbuf *),
519                                           0, socket);
520                 if (txq_ctrl == NULL) {
521                         ERROR("%p: unable to allocate queue index %u",
522                               (void *)dev, idx);
523                         priv_unlock(priv);
524                         return -ENOMEM;
525                 }
526         }
527         ret = txq_ctrl_setup(dev, txq_ctrl, desc, socket, conf);
528         if (ret)
529                 rte_free(txq_ctrl);
530         else {
531                 txq_ctrl->txq.stats.idx = idx;
532                 DEBUG("%p: adding TX queue %p to list",
533                       (void *)dev, (void *)txq_ctrl);
534                 (*priv->txqs)[idx] = &txq_ctrl->txq;
535                 /* Update send callback. */
536                 priv_select_tx_function(priv);
537         }
538         priv_unlock(priv);
539         return -ret;
540 }
541
542 /**
543  * DPDK callback to release a TX queue.
544  *
545  * @param dpdk_txq
546  *   Generic TX queue pointer.
547  */
548 void
549 mlx5_tx_queue_release(void *dpdk_txq)
550 {
551         struct txq *txq = (struct txq *)dpdk_txq;
552         struct txq_ctrl *txq_ctrl;
553         struct priv *priv;
554         unsigned int i;
555
556         if (mlx5_is_secondary())
557                 return;
558
559         if (txq == NULL)
560                 return;
561         txq_ctrl = container_of(txq, struct txq_ctrl, txq);
562         priv = txq_ctrl->priv;
563         priv_lock(priv);
564         for (i = 0; (i != priv->txqs_n); ++i)
565                 if ((*priv->txqs)[i] == txq) {
566                         DEBUG("%p: removing TX queue %p from list",
567                               (void *)priv->dev, (void *)txq_ctrl);
568                         (*priv->txqs)[i] = NULL;
569                         break;
570                 }
571         txq_cleanup(txq_ctrl);
572         rte_free(txq_ctrl);
573         priv_unlock(priv);
574 }
575
576 /**
577  * DPDK callback for TX in secondary processes.
578  *
579  * This function configures all queues from primary process information
580  * if necessary before reverting to the normal TX burst callback.
581  *
582  * @param dpdk_txq
583  *   Generic pointer to TX queue structure.
584  * @param[in] pkts
585  *   Packets to transmit.
586  * @param pkts_n
587  *   Number of packets in array.
588  *
589  * @return
590  *   Number of packets successfully transmitted (<= pkts_n).
591  */
592 uint16_t
593 mlx5_tx_burst_secondary_setup(void *dpdk_txq, struct rte_mbuf **pkts,
594                               uint16_t pkts_n)
595 {
596         struct txq *txq = dpdk_txq;
597         struct txq_ctrl *txq_ctrl = container_of(txq, struct txq_ctrl, txq);
598         struct priv *priv = mlx5_secondary_data_setup(txq_ctrl->priv);
599         struct priv *primary_priv;
600         unsigned int index;
601
602         if (priv == NULL)
603                 return 0;
604         primary_priv =
605                 mlx5_secondary_data[priv->dev->data->port_id].primary_priv;
606         /* Look for queue index in both private structures. */
607         for (index = 0; index != priv->txqs_n; ++index)
608                 if (((*primary_priv->txqs)[index] == txq) ||
609                     ((*priv->txqs)[index] == txq))
610                         break;
611         if (index == priv->txqs_n)
612                 return 0;
613         txq = (*priv->txqs)[index];
614         return priv->dev->tx_pkt_burst(txq, pkts, pkts_n);
615 }