7ce5b261cc178a4296a8586b0adedc0334de1a0c
[dpdk.git] / drivers / net / mlx4 / mlx4_rxq.c
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 /**
35  * @file
36  * Rx queues configuration for mlx4 driver.
37  */
38
39 #include <assert.h>
40 #include <errno.h>
41 #include <stddef.h>
42 #include <stdint.h>
43 #include <string.h>
44
45 /* Verbs headers do not support -pedantic. */
46 #ifdef PEDANTIC
47 #pragma GCC diagnostic ignored "-Wpedantic"
48 #endif
49 #include <infiniband/verbs.h>
50 #ifdef PEDANTIC
51 #pragma GCC diagnostic error "-Wpedantic"
52 #endif
53
54 #include <rte_byteorder.h>
55 #include <rte_common.h>
56 #include <rte_errno.h>
57 #include <rte_ethdev.h>
58 #include <rte_flow.h>
59 #include <rte_malloc.h>
60 #include <rte_mbuf.h>
61 #include <rte_mempool.h>
62
63 #include "mlx4.h"
64 #include "mlx4_flow.h"
65 #include "mlx4_rxtx.h"
66 #include "mlx4_utils.h"
67
68 /**
69  * Historical RSS hash key.
70  *
71  * This used to be the default for mlx4 in Linux before v3.19 switched to
72  * generating random hash keys through netdev_rss_key_fill().
73  *
74  * It is used in this PMD for consistency with past DPDK releases but can
75  * now be overridden through user configuration.
76  *
77  * Note: this is not const to work around API quirks.
78  */
79 uint8_t
80 mlx4_rss_hash_key_default[MLX4_RSS_HASH_KEY_SIZE] = {
81         0x2c, 0xc6, 0x81, 0xd1,
82         0x5b, 0xdb, 0xf4, 0xf7,
83         0xfc, 0xa2, 0x83, 0x19,
84         0xdb, 0x1a, 0x3e, 0x94,
85         0x6b, 0x9e, 0x38, 0xd9,
86         0x2c, 0x9c, 0x03, 0xd1,
87         0xad, 0x99, 0x44, 0xa7,
88         0xd9, 0x56, 0x3d, 0x59,
89         0x06, 0x3c, 0x25, 0xf3,
90         0xfc, 0x1f, 0xdc, 0x2a,
91 };
92
93 /**
94  * Obtain a RSS context with specified properties.
95  *
96  * Used when creating a flow rule targeting one or several Rx queues.
97  *
98  * If a matching RSS context already exists, it is returned with its
99  * reference count incremented.
100  *
101  * @param priv
102  *   Pointer to private structure.
103  * @param fields
104  *   Fields for RSS processing (Verbs format).
105  * @param[in] key
106  *   Hash key to use (whose size is exactly MLX4_RSS_HASH_KEY_SIZE).
107  * @param queues
108  *   Number of target queues.
109  * @param[in] queue_id
110  *   Target queues.
111  *
112  * @return
113  *   Pointer to RSS context on success, NULL otherwise and rte_errno is set.
114  */
115 struct mlx4_rss *
116 mlx4_rss_get(struct priv *priv, uint64_t fields,
117              uint8_t key[MLX4_RSS_HASH_KEY_SIZE],
118              uint16_t queues, const uint16_t queue_id[])
119 {
120         struct mlx4_rss *rss;
121         size_t queue_id_size = sizeof(queue_id[0]) * queues;
122
123         LIST_FOREACH(rss, &priv->rss, next)
124                 if (fields == rss->fields &&
125                     queues == rss->queues &&
126                     !memcmp(key, rss->key, MLX4_RSS_HASH_KEY_SIZE) &&
127                     !memcmp(queue_id, rss->queue_id, queue_id_size)) {
128                         ++rss->refcnt;
129                         return rss;
130                 }
131         rss = rte_malloc(__func__, offsetof(struct mlx4_rss, queue_id) +
132                          queue_id_size, 0);
133         if (!rss)
134                 goto error;
135         *rss = (struct mlx4_rss){
136                 .priv = priv,
137                 .refcnt = 1,
138                 .usecnt = 0,
139                 .qp = NULL,
140                 .ind = NULL,
141                 .fields = fields,
142                 .queues = queues,
143         };
144         memcpy(rss->key, key, MLX4_RSS_HASH_KEY_SIZE);
145         memcpy(rss->queue_id, queue_id, queue_id_size);
146         LIST_INSERT_HEAD(&priv->rss, rss, next);
147         return rss;
148 error:
149         rte_errno = ENOMEM;
150         return NULL;
151 }
152
153 /**
154  * Release a RSS context instance.
155  *
156  * Used when destroying a flow rule targeting one or several Rx queues.
157  *
158  * This function decrements the reference count of the context and destroys
159  * it after reaching 0. The context must have no users at this point; all
160  * prior calls to mlx4_rss_attach() must have been followed by matching
161  * calls to mlx4_rss_detach().
162  *
163  * @param rss
164  *   RSS context to release.
165  */
166 void mlx4_rss_put(struct mlx4_rss *rss)
167 {
168         assert(rss->refcnt);
169         if (--rss->refcnt)
170                 return;
171         assert(!rss->usecnt);
172         assert(!rss->qp);
173         assert(!rss->ind);
174         LIST_REMOVE(rss, next);
175         rte_free(rss);
176 }
177
178 /**
179  * Attach a user to a RSS context instance.
180  *
181  * Used when the RSS QP and indirection table objects must be instantiated,
182  * that is, when a flow rule must be enabled.
183  *
184  * This function increments the usage count of the context.
185  *
186  * @param rss
187  *   RSS context to attach to.
188  */
189 int mlx4_rss_attach(struct mlx4_rss *rss)
190 {
191         assert(rss->refcnt);
192         if (rss->usecnt++) {
193                 assert(rss->qp);
194                 assert(rss->ind);
195                 return 0;
196         }
197
198         struct ibv_wq *ind_tbl[rss->queues];
199         struct priv *priv = rss->priv;
200         const char *msg;
201         unsigned int i;
202         int ret;
203
204         if (!rte_is_power_of_2(RTE_DIM(ind_tbl))) {
205                 msg = "number of RSS queues must be a power of two";
206                 goto error;
207         }
208         for (i = 0; i != RTE_DIM(ind_tbl); ++i) {
209                 uint16_t id = rss->queue_id[i];
210                 struct rxq *rxq = NULL;
211
212                 if (id < priv->dev->data->nb_rx_queues)
213                         rxq = priv->dev->data->rx_queues[id];
214                 if (!rxq) {
215                         msg = "RSS target queue is not configured";
216                         goto error;
217                 }
218                 ind_tbl[i] = rxq->wq;
219         }
220         rss->ind = ibv_create_rwq_ind_table
221                 (priv->ctx,
222                  &(struct ibv_rwq_ind_table_init_attr){
223                         .log_ind_tbl_size = rte_log2_u32(RTE_DIM(ind_tbl)),
224                         .ind_tbl = ind_tbl,
225                         .comp_mask = 0,
226                  });
227         if (!rss->ind) {
228                 msg = "RSS indirection table creation failure";
229                 goto error;
230         }
231         rss->qp = ibv_create_qp_ex
232                 (priv->ctx,
233                  &(struct ibv_qp_init_attr_ex){
234                         .comp_mask = (IBV_QP_INIT_ATTR_PD |
235                                       IBV_QP_INIT_ATTR_RX_HASH |
236                                       IBV_QP_INIT_ATTR_IND_TABLE),
237                         .qp_type = IBV_QPT_RAW_PACKET,
238                         .pd = priv->pd,
239                         .rwq_ind_tbl = rss->ind,
240                         .rx_hash_conf = {
241                                 .rx_hash_function = IBV_RX_HASH_FUNC_TOEPLITZ,
242                                 .rx_hash_key_len = MLX4_RSS_HASH_KEY_SIZE,
243                                 .rx_hash_key = rss->key,
244                                 .rx_hash_fields_mask = rss->fields,
245                         },
246                  });
247         if (!rss->qp) {
248                 msg = "RSS hash QP creation failure";
249                 goto error;
250         }
251         ret = ibv_modify_qp
252                 (rss->qp,
253                  &(struct ibv_qp_attr){
254                         .qp_state = IBV_QPS_INIT,
255                         .port_num = priv->port,
256                  },
257                  IBV_QP_STATE | IBV_QP_PORT);
258         if (ret) {
259                 msg = "failed to switch RSS hash QP to INIT state";
260                 goto error;
261         }
262         ret = ibv_modify_qp
263                 (rss->qp,
264                  &(struct ibv_qp_attr){
265                         .qp_state = IBV_QPS_RTR,
266                  },
267                  IBV_QP_STATE);
268         if (ret) {
269                 msg = "failed to switch RSS hash QP to RTR state";
270                 goto error;
271         }
272         return 0;
273 error:
274         ERROR("mlx4: %s", msg);
275         --rss->usecnt;
276         rte_errno = EINVAL;
277         return -rte_errno;
278 }
279
280 /**
281  * Detach a user from a RSS context instance.
282  *
283  * Used when disabling (not destroying) a flow rule.
284  *
285  * This function decrements the usage count of the context and destroys
286  * usage resources after reaching 0.
287  *
288  * @param rss
289  *   RSS context to detach from.
290  */
291 void mlx4_rss_detach(struct mlx4_rss *rss)
292 {
293         assert(rss->refcnt);
294         assert(rss->qp);
295         assert(rss->ind);
296         if (--rss->usecnt)
297                 return;
298         claim_zero(ibv_destroy_qp(rss->qp));
299         rss->qp = NULL;
300         claim_zero(ibv_destroy_rwq_ind_table(rss->ind));
301         rss->ind = NULL;
302 }
303
304 /**
305  * Allocate Rx queue elements.
306  *
307  * @param rxq
308  *   Pointer to Rx queue structure.
309  *
310  * @return
311  *   0 on success, negative errno value otherwise and rte_errno is set.
312  */
313 static int
314 mlx4_rxq_alloc_elts(struct rxq *rxq)
315 {
316         const uint32_t elts_n = 1 << rxq->elts_n;
317         const uint32_t sges_n = 1 << rxq->sges_n;
318         struct rte_mbuf *(*elts)[elts_n] = rxq->elts;
319         unsigned int i;
320
321         assert(rte_is_power_of_2(elts_n));
322         for (i = 0; i != RTE_DIM(*elts); ++i) {
323                 volatile struct mlx4_wqe_data_seg *scat = &(*rxq->wqes)[i];
324                 struct rte_mbuf *buf = rte_pktmbuf_alloc(rxq->mp);
325
326                 if (buf == NULL) {
327                         while (i--) {
328                                 rte_pktmbuf_free_seg((*elts)[i]);
329                                 (*elts)[i] = NULL;
330                         }
331                         rte_errno = ENOMEM;
332                         return -rte_errno;
333                 }
334                 /* Headroom is reserved by rte_pktmbuf_alloc(). */
335                 assert(buf->data_off == RTE_PKTMBUF_HEADROOM);
336                 /* Buffer is supposed to be empty. */
337                 assert(rte_pktmbuf_data_len(buf) == 0);
338                 assert(rte_pktmbuf_pkt_len(buf) == 0);
339                 /* Only the first segment keeps headroom. */
340                 if (i % sges_n)
341                         buf->data_off = 0;
342                 buf->port = rxq->port_id;
343                 buf->data_len = rte_pktmbuf_tailroom(buf);
344                 buf->pkt_len = rte_pktmbuf_tailroom(buf);
345                 buf->nb_segs = 1;
346                 *scat = (struct mlx4_wqe_data_seg){
347                         .addr = rte_cpu_to_be_64(rte_pktmbuf_mtod(buf,
348                                                                   uintptr_t)),
349                         .byte_count = rte_cpu_to_be_32(buf->data_len),
350                         .lkey = rte_cpu_to_be_32(rxq->mr->lkey),
351                 };
352                 (*elts)[i] = buf;
353         }
354         DEBUG("%p: allocated and configured %u segments (max %u packets)",
355               (void *)rxq, elts_n, elts_n / sges_n);
356         return 0;
357 }
358
359 /**
360  * Free Rx queue elements.
361  *
362  * @param rxq
363  *   Pointer to Rx queue structure.
364  */
365 static void
366 mlx4_rxq_free_elts(struct rxq *rxq)
367 {
368         unsigned int i;
369         struct rte_mbuf *(*elts)[1 << rxq->elts_n] = rxq->elts;
370
371         DEBUG("%p: freeing Rx queue elements", (void *)rxq);
372         for (i = 0; (i != RTE_DIM(*elts)); ++i) {
373                 if (!(*elts)[i])
374                         continue;
375                 rte_pktmbuf_free_seg((*elts)[i]);
376                 (*elts)[i] = NULL;
377         }
378 }
379
380 /**
381  * DPDK callback to configure a Rx queue.
382  *
383  * @param dev
384  *   Pointer to Ethernet device structure.
385  * @param idx
386  *   Rx queue index.
387  * @param desc
388  *   Number of descriptors to configure in queue.
389  * @param socket
390  *   NUMA socket on which memory must be allocated.
391  * @param[in] conf
392  *   Thresholds parameters.
393  * @param mp
394  *   Memory pool for buffer allocations.
395  *
396  * @return
397  *   0 on success, negative errno value otherwise and rte_errno is set.
398  */
399 int
400 mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
401                     unsigned int socket, const struct rte_eth_rxconf *conf,
402                     struct rte_mempool *mp)
403 {
404         struct priv *priv = dev->data->dev_private;
405         struct mlx4dv_obj mlxdv;
406         struct mlx4dv_rwq dv_rwq;
407         struct mlx4dv_cq dv_cq;
408         uint32_t mb_len = rte_pktmbuf_data_room_size(mp);
409         struct rte_mbuf *(*elts)[rte_align32pow2(desc)];
410         struct rte_flow_error error;
411         struct rxq *rxq;
412         struct mlx4_malloc_vec vec[] = {
413                 {
414                         .align = RTE_CACHE_LINE_SIZE,
415                         .size = sizeof(*rxq),
416                         .addr = (void **)&rxq,
417                 },
418                 {
419                         .align = RTE_CACHE_LINE_SIZE,
420                         .size = sizeof(*elts),
421                         .addr = (void **)&elts,
422                 },
423         };
424         int ret;
425
426         (void)conf; /* Thresholds configuration (ignored). */
427         DEBUG("%p: configuring queue %u for %u descriptors",
428               (void *)dev, idx, desc);
429         if (idx >= dev->data->nb_rx_queues) {
430                 rte_errno = EOVERFLOW;
431                 ERROR("%p: queue index out of range (%u >= %u)",
432                       (void *)dev, idx, dev->data->nb_rx_queues);
433                 return -rte_errno;
434         }
435         rxq = dev->data->rx_queues[idx];
436         if (rxq) {
437                 rte_errno = EEXIST;
438                 ERROR("%p: Rx queue %u already configured, release it first",
439                       (void *)dev, idx);
440                 return -rte_errno;
441         }
442         if (!desc) {
443                 rte_errno = EINVAL;
444                 ERROR("%p: invalid number of Rx descriptors", (void *)dev);
445                 return -rte_errno;
446         }
447         if (desc != RTE_DIM(*elts)) {
448                 desc = RTE_DIM(*elts);
449                 WARN("%p: increased number of descriptors in Rx queue %u"
450                      " to the next power of two (%u)",
451                      (void *)dev, idx, desc);
452         }
453         /* Allocate and initialize Rx queue. */
454         mlx4_zmallocv_socket("RXQ", vec, RTE_DIM(vec), socket);
455         if (!rxq) {
456                 ERROR("%p: unable to allocate queue index %u",
457                       (void *)dev, idx);
458                 return -rte_errno;
459         }
460         *rxq = (struct rxq){
461                 .priv = priv,
462                 .mp = mp,
463                 .port_id = dev->data->port_id,
464                 .sges_n = 0,
465                 .elts_n = rte_log2_u32(desc),
466                 .elts = elts,
467                 /* Toggle Rx checksum offload if hardware supports it. */
468                 .csum = (priv->hw_csum &&
469                          dev->data->dev_conf.rxmode.hw_ip_checksum),
470                 .csum_l2tun = (priv->hw_csum_l2tun &&
471                                dev->data->dev_conf.rxmode.hw_ip_checksum),
472                 .stats.idx = idx,
473                 .socket = socket,
474         };
475         /* Enable scattered packets support for this queue if necessary. */
476         assert(mb_len >= RTE_PKTMBUF_HEADROOM);
477         if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
478             (mb_len - RTE_PKTMBUF_HEADROOM)) {
479                 ;
480         } else if (dev->data->dev_conf.rxmode.enable_scatter) {
481                 uint32_t size =
482                         RTE_PKTMBUF_HEADROOM +
483                         dev->data->dev_conf.rxmode.max_rx_pkt_len;
484                 uint32_t sges_n;
485
486                 /*
487                  * Determine the number of SGEs needed for a full packet
488                  * and round it to the next power of two.
489                  */
490                 sges_n = rte_log2_u32((size / mb_len) + !!(size % mb_len));
491                 rxq->sges_n = sges_n;
492                 /* Make sure sges_n did not overflow. */
493                 size = mb_len * (1 << rxq->sges_n);
494                 size -= RTE_PKTMBUF_HEADROOM;
495                 if (size < dev->data->dev_conf.rxmode.max_rx_pkt_len) {
496                         rte_errno = EOVERFLOW;
497                         ERROR("%p: too many SGEs (%u) needed to handle"
498                               " requested maximum packet size %u",
499                               (void *)dev,
500                               1 << sges_n,
501                               dev->data->dev_conf.rxmode.max_rx_pkt_len);
502                         goto error;
503                 }
504         } else {
505                 WARN("%p: the requested maximum Rx packet size (%u) is"
506                      " larger than a single mbuf (%u) and scattered"
507                      " mode has not been requested",
508                      (void *)dev,
509                      dev->data->dev_conf.rxmode.max_rx_pkt_len,
510                      mb_len - RTE_PKTMBUF_HEADROOM);
511         }
512         DEBUG("%p: maximum number of segments per packet: %u",
513               (void *)dev, 1 << rxq->sges_n);
514         if (desc % (1 << rxq->sges_n)) {
515                 rte_errno = EINVAL;
516                 ERROR("%p: number of Rx queue descriptors (%u) is not a"
517                       " multiple of maximum segments per packet (%u)",
518                       (void *)dev,
519                       desc,
520                       1 << rxq->sges_n);
521                 goto error;
522         }
523         /* Use the entire Rx mempool as the memory region. */
524         rxq->mr = mlx4_mp2mr(priv->pd, mp);
525         if (!rxq->mr) {
526                 rte_errno = EINVAL;
527                 ERROR("%p: MR creation failure: %s",
528                       (void *)dev, strerror(rte_errno));
529                 goto error;
530         }
531         if (dev->data->dev_conf.intr_conf.rxq) {
532                 rxq->channel = ibv_create_comp_channel(priv->ctx);
533                 if (rxq->channel == NULL) {
534                         rte_errno = ENOMEM;
535                         ERROR("%p: Rx interrupt completion channel creation"
536                               " failure: %s",
537                               (void *)dev, strerror(rte_errno));
538                         goto error;
539                 }
540                 if (mlx4_fd_set_non_blocking(rxq->channel->fd) < 0) {
541                         ERROR("%p: unable to make Rx interrupt completion"
542                               " channel non-blocking: %s",
543                               (void *)dev, strerror(rte_errno));
544                         goto error;
545                 }
546         }
547         rxq->cq = ibv_create_cq(priv->ctx, desc >> rxq->sges_n, NULL,
548                                 rxq->channel, 0);
549         if (!rxq->cq) {
550                 rte_errno = ENOMEM;
551                 ERROR("%p: CQ creation failure: %s",
552                       (void *)dev, strerror(rte_errno));
553                 goto error;
554         }
555         rxq->wq = ibv_create_wq
556                 (priv->ctx,
557                  &(struct ibv_wq_init_attr){
558                         .wq_type = IBV_WQT_RQ,
559                         .max_wr = desc >> rxq->sges_n,
560                         .max_sge = 1 << rxq->sges_n,
561                         .pd = priv->pd,
562                         .cq = rxq->cq,
563                  });
564         if (!rxq->wq) {
565                 rte_errno = errno ? errno : EINVAL;
566                 ERROR("%p: WQ creation failure: %s",
567                       (void *)dev, strerror(rte_errno));
568                 goto error;
569         }
570         ret = ibv_modify_wq
571                 (rxq->wq,
572                  &(struct ibv_wq_attr){
573                         .attr_mask = IBV_WQ_ATTR_STATE,
574                         .wq_state = IBV_WQS_RDY,
575                  });
576         if (ret) {
577                 rte_errno = ret;
578                 ERROR("%p: WQ state to IBV_WPS_RDY failed: %s",
579                       (void *)dev, strerror(rte_errno));
580                 goto error;
581         }
582         /* Retrieve device queue information. */
583         mlxdv.cq.in = rxq->cq;
584         mlxdv.cq.out = &dv_cq;
585         mlxdv.rwq.in = rxq->wq;
586         mlxdv.rwq.out = &dv_rwq;
587         ret = mlx4dv_init_obj(&mlxdv, MLX4DV_OBJ_RWQ | MLX4DV_OBJ_CQ);
588         if (ret) {
589                 rte_errno = EINVAL;
590                 ERROR("%p: failed to obtain device information", (void *)dev);
591                 goto error;
592         }
593         rxq->wqes =
594                 (volatile struct mlx4_wqe_data_seg (*)[])
595                 ((uintptr_t)dv_rwq.buf.buf + dv_rwq.rq.offset);
596         rxq->rq_db = dv_rwq.rdb;
597         rxq->rq_ci = 0;
598         rxq->mcq.buf = dv_cq.buf.buf;
599         rxq->mcq.cqe_cnt = dv_cq.cqe_cnt;
600         rxq->mcq.set_ci_db = dv_cq.set_ci_db;
601         rxq->mcq.cqe_64 = (dv_cq.cqe_size & 64) ? 1 : 0;
602         ret = mlx4_rxq_alloc_elts(rxq);
603         if (ret) {
604                 ERROR("%p: RXQ allocation failed: %s",
605                       (void *)dev, strerror(rte_errno));
606                 goto error;
607         }
608         DEBUG("%p: adding Rx queue %p to list", (void *)dev, (void *)rxq);
609         dev->data->rx_queues[idx] = rxq;
610         /* Enable associated flows. */
611         ret = mlx4_flow_sync(priv, &error);
612         if (!ret) {
613                 /* Update doorbell counter. */
614                 rxq->rq_ci = desc >> rxq->sges_n;
615                 rte_wmb();
616                 *rxq->rq_db = rte_cpu_to_be_32(rxq->rq_ci);
617                 return 0;
618         }
619         ERROR("cannot re-attach flow rules to queue %u"
620               " (code %d, \"%s\"), flow error type %d, cause %p, message: %s",
621               idx, -ret, strerror(-ret), error.type, error.cause,
622               error.message ? error.message : "(unspecified)");
623 error:
624         dev->data->rx_queues[idx] = NULL;
625         ret = rte_errno;
626         mlx4_rx_queue_release(rxq);
627         rte_errno = ret;
628         assert(rte_errno > 0);
629         return -rte_errno;
630 }
631
632 /**
633  * DPDK callback to release a Rx queue.
634  *
635  * @param dpdk_rxq
636  *   Generic Rx queue pointer.
637  */
638 void
639 mlx4_rx_queue_release(void *dpdk_rxq)
640 {
641         struct rxq *rxq = (struct rxq *)dpdk_rxq;
642         struct priv *priv;
643         unsigned int i;
644
645         if (rxq == NULL)
646                 return;
647         priv = rxq->priv;
648         for (i = 0; i != priv->dev->data->nb_rx_queues; ++i)
649                 if (priv->dev->data->rx_queues[i] == rxq) {
650                         DEBUG("%p: removing Rx queue %p from list",
651                               (void *)priv->dev, (void *)rxq);
652                         priv->dev->data->rx_queues[i] = NULL;
653                         break;
654                 }
655         mlx4_flow_sync(priv, NULL);
656         mlx4_rxq_free_elts(rxq);
657         if (rxq->wq)
658                 claim_zero(ibv_destroy_wq(rxq->wq));
659         if (rxq->cq)
660                 claim_zero(ibv_destroy_cq(rxq->cq));
661         if (rxq->channel)
662                 claim_zero(ibv_destroy_comp_channel(rxq->channel));
663         if (rxq->mr)
664                 claim_zero(ibv_dereg_mr(rxq->mr));
665         rte_free(rxq);
666 }