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