Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2014-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include <inttypes.h>
7 : :
8 : : #include <rte_malloc.h>
9 : :
10 : : #include "bnxt.h"
11 : : #include "bnxt_filter.h"
12 : : #include "bnxt_hwrm.h"
13 : : #include "bnxt_ring.h"
14 : : #include "bnxt_rxq.h"
15 : : #include "bnxt_rxr.h"
16 : : #include "bnxt_vnic.h"
17 : : #include "hsi_struct_def_dpdk.h"
18 : :
19 : : /*
20 : : * RX Queues
21 : : */
22 : :
23 : 0 : uint64_t bnxt_get_rx_port_offloads(struct bnxt *bp)
24 : : {
25 : : uint64_t rx_offload_capa;
26 : :
27 : : rx_offload_capa = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
28 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
29 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
30 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
31 : : RTE_ETH_RX_OFFLOAD_SCATTER |
32 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
33 : : RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT;
34 : :
35 : : /* In P7 platform if truflow is enabled then vlan offload is disabled*/
36 [ # # # # : 0 : if (!(BNXT_TRUFLOW_EN(bp) && BNXT_CHIP_P7(bp)))
# # ]
37 : : rx_offload_capa |= (RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
38 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
39 : :
40 : :
41 : 0 : if (!bnxt_compressed_rx_cqe_mode_enabled(bp) &&
42 [ # # # # ]: 0 : BNXT_SUPPORTS_TPA(bp))
43 : 0 : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
44 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_PTP_SUPPORTED)
45 : 0 : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
46 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_VLAN_RX_STRIP) {
47 [ # # # # : 0 : if (!(BNXT_TRUFLOW_EN(bp) && BNXT_CHIP_P7(bp)))
# # ]
48 : 0 : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
49 : : }
50 : :
51 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_ALL_EN(bp))
52 : 0 : rx_offload_capa |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
53 : : RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM;
54 : :
55 : 0 : return rx_offload_capa;
56 : : }
57 : :
58 : : /* Determine whether the current configuration needs aggregation ring in HW. */
59 : 0 : int bnxt_need_agg_ring(struct rte_eth_dev *eth_dev)
60 : : {
61 : : /* scattered_rx will be true if OFFLOAD_SCATTER is enabled,
62 : : * if LRO is enabled, or if the max packet len is greater than the
63 : : * mbuf data size. So AGG ring will be needed whenever scattered_rx
64 : : * is set.
65 : : */
66 : 0 : return eth_dev->data->scattered_rx ? 1 : 0;
67 : : }
68 : :
69 : 0 : void bnxt_free_rxq_stats(struct bnxt_rx_queue *rxq)
70 : : {
71 [ # # # # : 0 : if (rxq && rxq->cp_ring && rxq->cp_ring->hw_stats)
# # ]
72 : 0 : rxq->cp_ring->hw_stats = NULL;
73 : 0 : }
74 : :
75 : 0 : int bnxt_mq_rx_configure(struct bnxt *bp)
76 : : {
77 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
78 : : struct rte_eth_rss_conf *rss = &bp->rss_conf;
79 : : unsigned int i, j, nb_q_per_grp = 1, ring_idx = 0;
80 : : int start_grp_id, end_grp_id = 1, rc = 0;
81 : : struct bnxt_vnic_info *vnic;
82 : : struct bnxt_filter_info *filter;
83 : : enum rte_eth_nb_pools pools = 1;
84 : : struct bnxt_rx_queue *rxq;
85 : :
86 : 0 : bp->nr_vnics = 0;
87 : :
88 : : /* Multi-queue mode */
89 [ # # ]: 0 : switch (dev_conf->rxmode.mq_mode) {
90 : 0 : case RTE_ETH_MQ_RX_NONE:
91 : : case RTE_ETH_MQ_RX_RSS:
92 : 0 : pools = bp->rx_cosq_cnt ? bp->rx_cosq_cnt : pools;
93 : : break;
94 : 0 : default:
95 : 0 : PMD_DRV_LOG_LINE(ERR, "Unsupported mq_mode %d",
96 : : dev_conf->rxmode.mq_mode);
97 : 0 : return -EINVAL;
98 : : }
99 : :
100 : 0 : pools = RTE_MIN(pools, bp->rx_cp_nr_rings);
101 : 0 : nb_q_per_grp = bp->rx_cp_nr_rings / pools;
102 : 0 : PMD_DRV_LOG_LINE(DEBUG, "pools = %u nb_q_per_grp = %u",
103 : : pools, nb_q_per_grp);
104 : : start_grp_id = 0;
105 : 0 : end_grp_id = nb_q_per_grp;
106 : :
107 [ # # ]: 0 : for (i = 0; i < pools; i++) {
108 : 0 : vnic = &bp->vnic_info[i];
109 : 0 : vnic->flags |= BNXT_VNIC_INFO_BCAST;
110 : 0 : bp->nr_vnics++;
111 : :
112 [ # # ]: 0 : for (j = 0; j < nb_q_per_grp; j++, ring_idx++) {
113 : 0 : rxq = bp->eth_dev->data->rx_queues[ring_idx];
114 : 0 : rxq->vnic = vnic;
115 : 0 : PMD_DRV_LOG_LINE(DEBUG,
116 : : "rxq[%d] = %p vnic[%d] = %p",
117 : : ring_idx, rxq, i, vnic);
118 : : }
119 [ # # ]: 0 : if (i == 0)
120 : 0 : vnic->func_default = true;
121 : 0 : vnic->start_grp_id = start_grp_id;
122 : 0 : vnic->end_grp_id = end_grp_id;
123 : :
124 [ # # ]: 0 : if (i) {
125 [ # # ]: 0 : if (!(dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS))
126 : 0 : vnic->rss_dflt_cr = true;
127 : 0 : goto skip_filter_allocation;
128 : : }
129 : 0 : filter = bnxt_alloc_filter(bp);
130 [ # # ]: 0 : if (!filter) {
131 : 0 : PMD_DRV_LOG_LINE(ERR, "L2 filter alloc failed");
132 : : rc = -ENOMEM;
133 : 0 : goto err_out;
134 : : }
135 : 0 : filter->mac_index = 0;
136 : 0 : filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
137 : :
138 : 0 : STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
139 : :
140 : 0 : skip_filter_allocation:
141 : : start_grp_id = end_grp_id;
142 : 0 : end_grp_id += nb_q_per_grp;
143 : : }
144 : :
145 : 0 : bp->rx_num_qs_per_vnic = nb_q_per_grp;
146 : :
147 [ # # ]: 0 : for (i = 0; i < bp->nr_vnics; i++) {
148 : 0 : uint32_t lvl = RTE_ETH_RSS_LEVEL(rss->rss_hf);
149 : :
150 : 0 : vnic = &bp->vnic_info[i];
151 : 0 : vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss->rss_hf);
152 : 0 : vnic->hash_mode = bnxt_rte_to_hwrm_hash_level(bp, rss->rss_hf, lvl);
153 : :
154 : : /*
155 : : * Use the supplied key if the key length is
156 : : * acceptable and the rss_key is not NULL
157 : : */
158 [ # # # # ]: 0 : if (rss->rss_key && rss->rss_key_len <= HW_HASH_KEY_SIZE)
159 : 0 : memcpy(vnic->rss_hash_key, rss->rss_key, rss->rss_key_len);
160 : : }
161 : :
162 : : return rc;
163 : :
164 : : err_out:
165 : : /* Free allocated vnic/filters */
166 : :
167 : 0 : return rc;
168 : : }
169 : :
170 : 0 : void bnxt_rx_queue_release_mbufs(struct bnxt_rx_queue *rxq)
171 : : {
172 : : struct rte_mbuf **sw_ring;
173 : : struct bnxt_tpa_info *tpa_info;
174 : : uint32_t i;
175 : :
176 [ # # # # ]: 0 : if (!rxq || !rxq->rx_ring)
177 : : return;
178 : :
179 : 0 : sw_ring = rxq->rx_ring->rx_buf_ring;
180 [ # # ]: 0 : if (sw_ring) {
181 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
182 : : /*
183 : : * The vector receive burst function does not set used
184 : : * mbuf pointers to NULL, do that here to simplify
185 : : * cleanup logic.
186 : : */
187 [ # # ]: 0 : for (i = 0; i < rxq->rxrearm_nb; i++)
188 : 0 : sw_ring[rxq->rxrearm_start + i] = NULL;
189 : 0 : rxq->rxrearm_nb = 0;
190 : : #endif
191 : 0 : for (i = 0;
192 [ # # ]: 0 : i < rxq->rx_ring->rx_ring_struct->ring_size; i++) {
193 [ # # ]: 0 : if (sw_ring[i]) {
194 [ # # ]: 0 : if (sw_ring[i] != &rxq->fake_mbuf)
195 : : rte_pktmbuf_free_seg(sw_ring[i]);
196 : 0 : sw_ring[i] = NULL;
197 : : }
198 : : }
199 : : }
200 : : /* Free up mbufs in Agg ring */
201 [ # # ]: 0 : if (rxq->bp == NULL ||
202 [ # # # # ]: 0 : rxq->bp->eth_dev == NULL ||
203 : 0 : !bnxt_need_agg_ring(rxq->bp->eth_dev))
204 : 0 : return;
205 : :
206 : 0 : sw_ring = rxq->rx_ring->ag_buf_ring;
207 [ # # ]: 0 : if (sw_ring) {
208 : : for (i = 0;
209 [ # # ]: 0 : i < rxq->rx_ring->ag_ring_struct->ring_size; i++) {
210 [ # # ]: 0 : if (sw_ring[i]) {
211 : : rte_pktmbuf_free_seg(sw_ring[i]);
212 : 0 : sw_ring[i] = NULL;
213 : : }
214 : : }
215 : : }
216 : :
217 [ # # ]: 0 : if (bnxt_compressed_rx_cqe_mode_enabled(rxq->bp))
218 : : return;
219 : :
220 : : /* Free up mbufs in TPA */
221 : 0 : tpa_info = rxq->rx_ring->tpa_info;
222 [ # # ]: 0 : if (tpa_info) {
223 [ # # ]: 0 : uint32_t max_aggs = BNXT_TPA_MAX_AGGS(rxq->bp);
224 : :
225 [ # # ]: 0 : for (i = 0; i < max_aggs; i++) {
226 [ # # ]: 0 : if (tpa_info[i].mbuf) {
227 : : rte_pktmbuf_free_seg(tpa_info[i].mbuf);
228 : 0 : tpa_info[i].mbuf = NULL;
229 : : }
230 : : }
231 : : }
232 : :
233 : : }
234 : :
235 : 0 : void bnxt_free_rx_mbufs(struct bnxt *bp)
236 : : {
237 : : struct bnxt_rx_queue *rxq;
238 : : int i;
239 : :
240 [ # # ]: 0 : for (i = 0; i < (int)bp->rx_nr_rings; i++) {
241 : 0 : rxq = bp->rx_queues[i];
242 : 0 : bnxt_rx_queue_release_mbufs(rxq);
243 : : }
244 : 0 : }
245 : :
246 : 0 : void bnxt_free_rxq_mem(struct bnxt_rx_queue *rxq)
247 : : {
248 : 0 : bnxt_rx_queue_release_mbufs(rxq);
249 : :
250 : : /* Free RX, AGG ring hardware descriptors */
251 [ # # ]: 0 : if (rxq->rx_ring) {
252 : 0 : bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
253 : 0 : rte_free(rxq->rx_ring->rx_ring_struct);
254 : 0 : rxq->rx_ring->rx_ring_struct = NULL;
255 : : /* Free RX Agg ring hardware descriptors */
256 : 0 : bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
257 : 0 : rte_free(rxq->rx_ring->ag_ring_struct);
258 : 0 : rxq->rx_ring->ag_ring_struct = NULL;
259 : :
260 : 0 : rte_free(rxq->rx_ring);
261 : 0 : rxq->rx_ring = NULL;
262 : : }
263 : : /* Free RX completion ring hardware descriptors */
264 [ # # ]: 0 : if (rxq->cp_ring) {
265 : 0 : bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
266 : 0 : rte_free(rxq->cp_ring->cp_ring_struct);
267 : 0 : rxq->cp_ring->cp_ring_struct = NULL;
268 : 0 : rte_free(rxq->cp_ring);
269 : 0 : rxq->cp_ring = NULL;
270 : : }
271 : :
272 : 0 : bnxt_free_rxq_stats(rxq);
273 : 0 : rte_memzone_free(rxq->mz);
274 : 0 : rxq->mz = NULL;
275 : 0 : }
276 : :
277 : 0 : void bnxt_rx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
278 : : {
279 : 0 : struct bnxt_rx_queue *rxq = dev->data->rx_queues[queue_idx];
280 : :
281 [ # # ]: 0 : if (rxq != NULL) {
282 [ # # ]: 0 : if (is_bnxt_in_error(rxq->bp))
283 : : return;
284 : :
285 : 0 : bnxt_free_hwrm_rx_ring(rxq->bp, rxq->queue_id);
286 : 0 : bnxt_free_rxq_mem(rxq);
287 : 0 : rte_free(rxq);
288 : : }
289 : : }
290 : :
291 : 0 : int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev,
292 : : uint16_t queue_idx,
293 : : uint16_t nb_desc,
294 : : unsigned int socket_id,
295 : : const struct rte_eth_rxconf *rx_conf,
296 : : struct rte_mempool *mp)
297 : : {
298 : 0 : uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
299 : 0 : uint8_t rs = !!(rx_offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT);
300 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
301 : 0 : struct rte_eth_rxseg_split *rx_seg =
302 : : (struct rte_eth_rxseg_split *)rx_conf->rx_seg;
303 : 0 : uint16_t n_seg = rx_conf->rx_nseg;
304 : : struct bnxt_rx_queue *rxq;
305 : : int rc = 0;
306 : :
307 : 0 : rc = is_bnxt_in_error(bp);
308 [ # # ]: 0 : if (rc)
309 : : return rc;
310 : :
311 [ # # ]: 0 : if (n_seg > 1 && !rs) {
312 : 0 : PMD_DRV_LOG_LINE(ERR, "n_seg %d does not match buffer split %d setting",
313 : : n_seg, rs);
314 : 0 : return -EINVAL;
315 : : }
316 : :
317 [ # # ]: 0 : if (n_seg > BNXT_MAX_BUFFER_SPLIT_SEGS) {
318 : 0 : PMD_DRV_LOG_LINE(ERR, "n_seg %d not supported", n_seg);
319 : 0 : return -EINVAL;
320 : : }
321 : :
322 [ # # ]: 0 : if (queue_idx >= bnxt_max_rings(bp)) {
323 : 0 : PMD_DRV_LOG_LINE(ERR,
324 : : "Cannot create Rx ring %d. Only %d rings available",
325 : : queue_idx, bp->max_rx_rings);
326 : 0 : return -EINVAL;
327 : : }
328 : :
329 [ # # ]: 0 : if (nb_desc < BNXT_MIN_RING_DESC || nb_desc > MAX_RX_DESC_CNT) {
330 : 0 : PMD_DRV_LOG_LINE(ERR, "nb_desc %d is invalid", nb_desc);
331 : 0 : return -EINVAL;
332 : : }
333 : :
334 : 0 : rxq = eth_dev->data->rx_queues[queue_idx];
335 [ # # ]: 0 : if (rxq)
336 : 0 : bnxt_rx_queue_release_op(eth_dev, queue_idx);
337 : 0 : rxq = rte_zmalloc_socket("bnxt_rx_queue", sizeof(struct bnxt_rx_queue),
338 : : RTE_CACHE_LINE_SIZE, socket_id);
339 [ # # ]: 0 : if (!rxq) {
340 : 0 : PMD_DRV_LOG_LINE(ERR, "bnxt_rx_queue allocation failed!");
341 : 0 : return -ENOMEM;
342 : : }
343 : 0 : rxq->bp = bp;
344 [ # # ]: 0 : if (n_seg > 1) {
345 : 0 : rxq->mb_pool = rx_seg[BNXT_MEM_POOL_IDX_0].mp;
346 : 0 : rxq->agg_mb_pool = rx_seg[BNXT_MEM_POOL_IDX_1].mp;
347 : : } else {
348 : 0 : rxq->mb_pool = mp;
349 : 0 : rxq->agg_mb_pool = mp;
350 : : }
351 : :
352 : 0 : rxq->nb_rx_desc = nb_desc;
353 : 0 : rxq->rx_free_thresh =
354 : 0 : RTE_MIN(rte_align32pow2(nb_desc) / 4, RTE_BNXT_MAX_RX_BURST);
355 : :
356 : 0 : PMD_DRV_LOG_LINE(DEBUG,
357 : : "App supplied RXQ drop_en status : %d", rx_conf->rx_drop_en);
358 : 0 : rxq->drop_en = BNXT_DEFAULT_RX_DROP_EN;
359 : :
360 : 0 : PMD_DRV_LOG_LINE(DEBUG, "RX Buf MTU %d", eth_dev->data->mtu);
361 : :
362 : 0 : eth_dev->data->rx_queues[queue_idx] = rxq;
363 : :
364 : 0 : rc = bnxt_init_rx_ring_struct(rxq, socket_id);
365 [ # # ]: 0 : if (rc) {
366 : 0 : PMD_DRV_LOG_LINE(ERR,
367 : : "init_rx_ring_struct failed!");
368 : 0 : goto err;
369 : : }
370 : :
371 : 0 : PMD_DRV_LOG_LINE(DEBUG, "RX Buf size is %d", rxq->rx_buf_size);
372 : 0 : rxq->queue_id = queue_idx;
373 : 0 : rxq->port_id = eth_dev->data->port_id;
374 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
375 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
376 : : else
377 : 0 : rxq->crc_len = 0;
378 : :
379 : : /* Allocate RX ring hardware descriptors */
380 : 0 : rc = bnxt_alloc_rings(bp, socket_id, queue_idx, NULL, rxq, rxq->cp_ring,
381 : : NULL, "rxr");
382 [ # # ]: 0 : if (rc) {
383 : 0 : PMD_DRV_LOG_LINE(ERR,
384 : : "ring_dma_zone_reserve for rx_ring failed!");
385 : 0 : goto err;
386 : : }
387 : 0 : rxq->rx_mbuf_alloc_fail = 0;
388 : 0 : rxq->epoch = 0;
389 : :
390 : : /* rxq 0 must not be stopped when used as async CPR */
391 : : if (!BNXT_NUM_ASYNC_CPR(bp) && queue_idx == 0)
392 : : rxq->rx_deferred_start = false;
393 : : else
394 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
395 : :
396 : 0 : rxq->rx_started = rxq->rx_deferred_start ? false : true;
397 : 0 : rxq->vnic = bnxt_get_default_vnic(bp);
398 [ # # ]: 0 : rxq->vnic->hds_threshold = n_seg ? rxq->vnic->hds_threshold : 0;
399 : :
400 : 0 : return 0;
401 : 0 : err:
402 : 0 : bnxt_rx_queue_release_op(eth_dev, queue_idx);
403 : 0 : return rc;
404 : : }
405 : :
406 : : int
407 : 0 : bnxt_rx_queue_intr_enable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
408 : : {
409 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
410 : : struct bnxt_rx_queue *rxq;
411 : : struct bnxt_cp_ring_info *cpr;
412 : : int rc = 0;
413 : :
414 : 0 : rc = is_bnxt_in_error(bp);
415 [ # # ]: 0 : if (rc)
416 : : return rc;
417 : :
418 [ # # ]: 0 : if (eth_dev->data->rx_queues) {
419 : 0 : rxq = eth_dev->data->rx_queues[queue_id];
420 [ # # ]: 0 : if (!rxq)
421 : : return -EINVAL;
422 : :
423 : 0 : cpr = rxq->cp_ring;
424 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
425 : 0 : struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
426 : :
427 : 0 : bnxt_arm_nq_p5p(nqr, 1);
428 : 0 : bnxt_arm_rx_cq_p5p(rxq->cp_ring, 1);
429 : : } else {
430 : 0 : B_CP_DB_ARM(cpr);
431 : : }
432 : : }
433 : : return rc;
434 : : }
435 : :
436 : : int
437 : 0 : bnxt_rx_queue_intr_disable_op(struct rte_eth_dev *eth_dev, uint16_t queue_id)
438 : : {
439 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
440 : : struct bnxt_rx_queue *rxq;
441 : : struct bnxt_cp_ring_info *cpr;
442 : : int rc = 0;
443 : :
444 : 0 : rc = is_bnxt_in_error(bp);
445 [ # # ]: 0 : if (rc)
446 : : return rc;
447 : :
448 [ # # ]: 0 : if (eth_dev->data->rx_queues) {
449 : 0 : rxq = eth_dev->data->rx_queues[queue_id];
450 [ # # ]: 0 : if (!rxq)
451 : : return -EINVAL;
452 : :
453 : 0 : cpr = rxq->cp_ring;
454 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
455 : 0 : struct bnxt_cp_ring_info *nqr = bp->rxtx_nq_ring;
456 : : struct bnxt_cp_ring_info *rx_cpr;
457 : :
458 : 0 : bnxt_arm_nq_p5p(nqr, 0);
459 : : /* Loops through all RXQs and finds the one that
460 : : * received a packet if any
461 : : */
462 : 0 : uint32_t cons = RING_CMPL(nqr->cp_ring_struct->ring_mask,
463 : : nqr->cp_raw_cons);
464 : 0 : struct cmpl_base *cmpl = &((nqr->cp_desc_ring)[cons]);
465 : :
466 [ # # ]: 0 : if (CMPL_VALID(cmpl, nqr->valid)) {
467 : : unsigned int rxid = 0;
468 : :
469 : 0 : rx_cpr = rxq->cp_ring;
470 [ # # ]: 0 : for (; rxid < bp->rx_nr_rings; rxid++) {
471 : 0 : rxq = bp->rx_queues[rxid];
472 : 0 : rx_cpr = rxq->cp_ring;
473 : 0 : cons = RING_CMPL(rx_cpr->cp_ring_struct->ring_mask,
474 : : rx_cpr->cp_raw_cons);
475 : 0 : cmpl = &((rx_cpr->cp_desc_ring)[cons]);
476 : : /* Because the valid bit in the rx
477 : : * completion queue is not updated the
478 : : * cmp valid using raw cons is used
479 : : */
480 [ # # ]: 0 : if (bnxt_cpr_cmp_valid(cmpl,
481 : : rx_cpr->cp_raw_cons,
482 : : rx_cpr->cp_ring_struct->ring_size)) {
483 : : break;
484 : : }
485 : : }
486 : 0 : bnxt_process_nq(bp, nqr, rx_cpr);
487 : : }
488 : : } else {
489 : 0 : B_CP_DB_DISARM(cpr);
490 : : }
491 : : }
492 : : return rc;
493 : : }
494 : :
495 : 0 : int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
496 : : {
497 : 0 : struct bnxt *bp = dev->data->dev_private;
498 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
499 : 0 : struct bnxt_rx_queue *rxq = bp->rx_queues[rx_queue_id];
500 : : struct bnxt_vnic_info *vnic = NULL;
501 : 0 : uint16_t vnic_idx = 0;
502 : : uint16_t fw_grp_id = 0;
503 : : int rc = 0;
504 : :
505 : 0 : rc = is_bnxt_in_error(bp);
506 [ # # ]: 0 : if (rc)
507 : : return rc;
508 : :
509 [ # # ]: 0 : if (rxq == NULL) {
510 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid Rx queue %d", rx_queue_id);
511 : 0 : return -EINVAL;
512 : : }
513 : :
514 : 0 : vnic = bnxt_vnic_queue_id_get_next(bp, rx_queue_id, &vnic_idx);
515 [ # # ]: 0 : if (vnic == NULL) {
516 : 0 : PMD_DRV_LOG_LINE(ERR, "VNIC not initialized for RxQ %d",
517 : : rx_queue_id);
518 : 0 : return -EINVAL;
519 : : }
520 : :
521 : : /* reset the previous stats for the rx_queue since the counters
522 : : * will be cleared when the queue is started.
523 : : */
524 [ # # # # ]: 0 : if (BNXT_TPA_V2_P7(bp))
525 : 0 : memset(&bp->prev_rx_ring_stats_ext[rx_queue_id], 0,
526 : : sizeof(struct bnxt_ring_stats_ext));
527 : : else
528 : 0 : memset(&bp->prev_rx_ring_stats[rx_queue_id], 0,
529 : : sizeof(struct bnxt_ring_stats));
530 : :
531 : : /* Set the queue state to started here.
532 : : * We check the status of the queue while posting buffer.
533 : : * If queue is it started, we do not post buffers for Rx.
534 : : */
535 : 0 : rxq->rx_started = true;
536 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
537 : :
538 : 0 : bnxt_free_hwrm_rx_ring(bp, rx_queue_id);
539 : 0 : rc = bnxt_alloc_hwrm_rx_ring(bp, rx_queue_id);
540 [ # # ]: 0 : if (rc)
541 : : return rc;
542 : :
543 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
544 : 0 : fw_grp_id = bp->grp_info[rx_queue_id].fw_grp_id;
545 : :
546 : : do {
547 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
548 : 0 : vnic->dflt_ring_grp = fw_grp_id;
549 : : /* Reconfigure default receive ring and MRU. */
550 : 0 : bnxt_hwrm_vnic_cfg(bp, vnic);
551 : :
552 : 0 : PMD_DRV_LOG_LINE(INFO, "Rx queue started %d", rx_queue_id);
553 : :
554 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) {
555 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp)) {
556 [ # # ]: 0 : if (vnic->fw_grp_ids[rx_queue_id] !=
557 : : INVALID_HW_RING_ID) {
558 : 0 : PMD_DRV_LOG_LINE(ERR, "invalid ring id %d",
559 : : rx_queue_id);
560 : 0 : return 0;
561 : : }
562 : :
563 : 0 : vnic->fw_grp_ids[rx_queue_id] = fw_grp_id;
564 : 0 : PMD_DRV_LOG_LINE(DEBUG, "vnic = %p fw_grp_id = %d",
565 : : vnic, fw_grp_id);
566 : : }
567 : :
568 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Rx Queue Count %d",
569 : : vnic->rx_queue_cnt);
570 : 0 : rc += bnxt_vnic_rss_queue_status_update(bp, vnic);
571 : : }
572 : 0 : vnic_idx++;
573 : 0 : } while ((vnic = bnxt_vnic_queue_id_get_next(bp, rx_queue_id,
574 [ # # ]: 0 : &vnic_idx)) != NULL);
575 : :
576 [ # # ]: 0 : if (rc != 0) {
577 : 0 : dev->data->rx_queue_state[rx_queue_id] =
578 : : RTE_ETH_QUEUE_STATE_STOPPED;
579 : 0 : rxq->rx_started = false;
580 : : }
581 : :
582 : 0 : PMD_DRV_LOG_LINE(INFO,
583 : : "queue %d, rx_deferred_start %d, state %d!",
584 : : rx_queue_id, rxq->rx_deferred_start,
585 : : bp->eth_dev->data->rx_queue_state[rx_queue_id]);
586 : :
587 : 0 : return rc;
588 : : }
589 : :
590 : 0 : int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
591 : : {
592 : 0 : struct bnxt *bp = dev->data->dev_private;
593 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
594 : : struct bnxt_vnic_info *vnic = NULL;
595 : : struct bnxt_rx_queue *rxq = NULL;
596 : : int active_queue_cnt = 0;
597 : 0 : uint16_t vnic_idx = 0, q_id = rx_queue_id;
598 : : int i, rc = 0;
599 : :
600 : 0 : rc = is_bnxt_in_error(bp);
601 [ # # ]: 0 : if (rc)
602 : : return rc;
603 : :
604 : : /* For the stingray platform and other platforms needing tighter
605 : : * control of resource utilization, Rx CQ 0 also works as
606 : : * Default CQ for async notifications
607 : : */
608 : : if (!BNXT_NUM_ASYNC_CPR(bp) && !rx_queue_id) {
609 : : PMD_DRV_LOG_LINE(ERR, "Cannot stop Rx queue id %d", rx_queue_id);
610 : : return -EINVAL;
611 : : }
612 : :
613 : 0 : rxq = bp->rx_queues[rx_queue_id];
614 [ # # ]: 0 : if (!rxq) {
615 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid Rx queue %d", rx_queue_id);
616 : 0 : return -EINVAL;
617 : : }
618 : :
619 : 0 : vnic = bnxt_vnic_queue_id_get_next(bp, q_id, &vnic_idx);
620 [ # # ]: 0 : if (!vnic) {
621 : 0 : PMD_DRV_LOG_LINE(ERR, "VNIC not initialized for RxQ %d", q_id);
622 : 0 : return -EINVAL;
623 : : }
624 : :
625 [ # # ]: 0 : __rte_assume(q_id < RTE_MAX_QUEUES_PER_PORT);
626 : 0 : dev->data->rx_queue_state[q_id] = RTE_ETH_QUEUE_STATE_STOPPED;
627 : 0 : rxq->rx_started = false;
628 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Rx queue stopped");
629 : :
630 : : do {
631 : : active_queue_cnt = 0;
632 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) {
633 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
634 : 0 : vnic->fw_grp_ids[q_id] = INVALID_HW_RING_ID;
635 : :
636 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Rx Queue Count %d",
637 : : vnic->rx_queue_cnt);
638 : 0 : rc = bnxt_vnic_rss_queue_status_update(bp, vnic);
639 : : }
640 : :
641 : : /* Compute current number of active receive queues. */
642 [ # # ]: 0 : for (i = vnic->start_grp_id; i < vnic->end_grp_id; i++)
643 [ # # ]: 0 : if (bp->rx_queues[i]->rx_started)
644 : 0 : active_queue_cnt++;
645 : :
646 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
647 : : /*
648 : : * For P5, we need to ensure that the VNIC default
649 : : * receive ring corresponds to an active receive queue.
650 : : * When no queue is active, we need to temporarily set
651 : : * the MRU to zero so that packets are dropped early in
652 : : * the receive pipeline in order to prevent the VNIC
653 : : * default receive ring from being accessed.
654 : : */
655 [ # # ]: 0 : if (active_queue_cnt == 0) {
656 : 0 : uint16_t saved_mru = vnic->mru;
657 : :
658 : : /* clear RSS setting on vnic. */
659 : 0 : bnxt_vnic_rss_clear_p5(bp, vnic);
660 : :
661 : 0 : vnic->mru = 0;
662 : : /* Reconfigure default receive ring and MRU. */
663 : 0 : bnxt_hwrm_vnic_cfg(bp, vnic);
664 : 0 : vnic->mru = saved_mru;
665 : : } else {
666 : : /* Reconfigure default receive ring. */
667 : 0 : bnxt_hwrm_vnic_cfg(bp, vnic);
668 : : }
669 [ # # ]: 0 : } else if (active_queue_cnt && vnic->dflt_ring_grp ==
670 [ # # ]: 0 : bp->grp_info[q_id].fw_grp_id) {
671 : : /*
672 : : * If the queue being stopped is the current default
673 : : * queue and there are other active queues, pick one of
674 : : * them as the default and reconfigure the vnic.
675 : : */
676 [ # # ]: 0 : for (i = vnic->start_grp_id; i < vnic->end_grp_id;
677 : 0 : i++) {
678 [ # # ]: 0 : if (bp->rx_queues[i]->rx_started) {
679 : 0 : vnic->dflt_ring_grp =
680 : 0 : bp->grp_info[i].fw_grp_id;
681 : 0 : bnxt_hwrm_vnic_cfg(bp, vnic);
682 : 0 : break;
683 : : }
684 : : }
685 : : }
686 : 0 : vnic_idx++;
687 : 0 : } while ((vnic = bnxt_vnic_queue_id_get_next(bp, q_id,
688 [ # # ]: 0 : &vnic_idx)) != NULL);
689 : :
690 [ # # ]: 0 : if (rc == 0)
691 : 0 : bnxt_rx_queue_release_mbufs(rxq);
692 : :
693 : : return rc;
694 : : }
|