Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : : #include <cnxk_ethdev.h>
5 : :
6 : : #include <eal_export.h>
7 : : #include <rte_eventdev.h>
8 : : #include <rte_pmd_cnxk.h>
9 : :
10 : : cnxk_ethdev_rx_offload_cb_t cnxk_ethdev_rx_offload_cb;
11 : :
12 : : #define CNXK_NIX_CQ_INL_CLAMP_MAX (64UL * 1024UL)
13 : :
14 : : #define NIX_TM_DFLT_RR_WT 71
15 : :
16 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_model_str_get, 23.11)
17 : : const char *
18 : 0 : rte_pmd_cnxk_model_str_get(void)
19 : : {
20 : 0 : return roc_model->name;
21 : : }
22 : :
23 : : static inline uint64_t
24 : : nix_get_rx_offload_capa(struct cnxk_eth_dev *dev)
25 : : {
26 : : uint64_t capa = CNXK_NIX_RX_OFFLOAD_CAPA;
27 : :
28 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(&dev->nix) ||
29 [ # # ]: 0 : dev->npc.switch_header_type == ROC_PRIV_FLAGS_HIGIG)
30 : : capa &= ~RTE_ETH_RX_OFFLOAD_TIMESTAMP;
31 : :
32 : : return capa;
33 : : }
34 : :
35 : : static inline uint64_t
36 : : nix_get_tx_offload_capa(struct cnxk_eth_dev *dev)
37 : : {
38 : : RTE_SET_USED(dev);
39 : : return CNXK_NIX_TX_OFFLOAD_CAPA;
40 : : }
41 : :
42 : : static inline uint32_t
43 : 0 : nix_get_speed_capa(struct cnxk_eth_dev *dev)
44 : : {
45 : : uint32_t speed_capa;
46 : :
47 : : /* Auto negotiation disabled */
48 : : speed_capa = RTE_ETH_LINK_SPEED_FIXED;
49 [ # # # # ]: 0 : if (!roc_nix_is_vf_or_sdp(&dev->nix) && !roc_nix_is_lbk(&dev->nix)) {
50 : : speed_capa |= RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G |
51 : : RTE_ETH_LINK_SPEED_25G | RTE_ETH_LINK_SPEED_40G |
52 : : RTE_ETH_LINK_SPEED_50G | RTE_ETH_LINK_SPEED_100G;
53 : : }
54 : :
55 : 0 : return speed_capa;
56 : : }
57 : :
58 : : static uint32_t
59 [ # # ]: 0 : nix_inl_cq_sz_clamp_up(struct roc_nix *nix, struct rte_mempool *mp,
60 : : uint32_t nb_desc)
61 : : {
62 : : struct roc_nix_rq *inl_rq;
63 : : uint64_t limit;
64 : :
65 : : /* For CN10KB and above, LBP needs minimum CQ size */
66 [ # # ]: 0 : if (!roc_errata_cpt_hang_on_x2p_bp())
67 : 0 : return RTE_MAX(nb_desc, (uint32_t)4096);
68 : :
69 : : /* CQ should be able to hold all buffers in first pass RQ's aura
70 : : * this RQ's aura.
71 : : */
72 : 0 : inl_rq = roc_nix_inl_dev_rq(nix);
73 : : if (!inl_rq) {
74 : : /* This itself is going to be inline RQ's aura */
75 : : limit = roc_npa_aura_op_limit_get(mp->pool_id);
76 : : } else {
77 : : limit = roc_npa_aura_op_limit_get(inl_rq->aura_handle);
78 : : /* Also add this RQ's aura if it is different */
79 : : if (inl_rq->aura_handle != mp->pool_id)
80 : : limit += roc_npa_aura_op_limit_get(mp->pool_id);
81 : : }
82 : 0 : nb_desc = PLT_MAX(limit + 1, nb_desc);
83 [ # # ]: 0 : if (nb_desc > CNXK_NIX_CQ_INL_CLAMP_MAX) {
84 : 0 : plt_warn("Could not setup CQ size to accommodate"
85 : : " all buffers in related auras (%" PRIu64 ")",
86 : : limit);
87 : : nb_desc = CNXK_NIX_CQ_INL_CLAMP_MAX;
88 : : }
89 : : return nb_desc;
90 : : }
91 : :
92 : : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ethdev_rx_offload_cb_register)
93 : : void
94 : 0 : cnxk_ethdev_rx_offload_cb_register(cnxk_ethdev_rx_offload_cb_t cb)
95 : : {
96 : 0 : cnxk_ethdev_rx_offload_cb = cb;
97 : 0 : }
98 : :
99 : : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_nix_inb_mode_set)
100 : : int
101 : 0 : cnxk_nix_inb_mode_set(struct cnxk_eth_dev *dev, bool use_inl_dev)
102 : : {
103 : 0 : struct roc_nix *nix = &dev->nix;
104 : :
105 : 0 : plt_nix_dbg("Security sessions(%u) still active, inl=%u!!!",
106 : : dev->inb.nb_sess, !!dev->inb.inl_dev);
107 : :
108 : : /* Change the mode */
109 : 0 : dev->inb.inl_dev = use_inl_dev;
110 : :
111 : : /* Update RoC for NPC rule insertion */
112 : 0 : roc_nix_inb_mode_set(nix, use_inl_dev);
113 : :
114 : : /* Setup lookup mem */
115 : 0 : return cnxk_nix_lookup_mem_sa_base_set(dev);
116 : : }
117 : :
118 : : static int
119 : 0 : nix_security_setup(struct cnxk_eth_dev *dev)
120 : : {
121 : 0 : struct roc_nix *nix = &dev->nix;
122 : : int i, rc = 0;
123 : :
124 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
125 : : /* Setup minimum SA table when inline device is used */
126 [ # # ]: 0 : nix->ipsec_in_min_spi = dev->inb.no_inl_dev ? dev->inb.min_spi : 0;
127 [ # # ]: 0 : nix->ipsec_in_max_spi = dev->inb.no_inl_dev ? dev->inb.max_spi : 1;
128 : :
129 : : /* Enable custom meta aura when multi-chan is used */
130 [ # # # # ]: 0 : if (nix->local_meta_aura_ena && roc_nix_inl_dev_is_multi_channel() &&
131 [ # # ]: 0 : !dev->inb.custom_meta_aura_dis)
132 : 0 : nix->custom_meta_aura_ena = true;
133 : :
134 : : /* Setup Inline Inbound */
135 : 0 : rc = roc_nix_inl_inb_init(nix);
136 [ # # ]: 0 : if (rc) {
137 : 0 : plt_err("Failed to initialize nix inline inb, rc=%d",
138 : : rc);
139 : 0 : return rc;
140 : : }
141 : :
142 : : /* By default pick using inline device for poll mode.
143 : : * Will be overridden when event mode rq's are setup.
144 : : */
145 : 0 : cnxk_nix_inb_mode_set(dev, !dev->inb.no_inl_dev);
146 : :
147 : : /* Allocate memory to be used as dptr for CPT ucode
148 : : * WRITE_SA op.
149 : : */
150 : 0 : dev->inb.sa_dptr =
151 : 0 : plt_zmalloc(ROC_NIX_INL_OT_IPSEC_INB_HW_SZ, 0);
152 [ # # ]: 0 : if (!dev->inb.sa_dptr) {
153 : 0 : plt_err("Couldn't allocate memory for SA dptr");
154 : : rc = -ENOMEM;
155 : 0 : goto cleanup;
156 : : }
157 : 0 : dev->inb.inl_dev_q = roc_nix_inl_dev_qptr_get(0);
158 : : }
159 : :
160 [ # # ]: 0 : if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY ||
161 [ # # ]: 0 : dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
162 : : struct plt_bitmap *bmap;
163 : : size_t bmap_sz;
164 : : void *mem;
165 : :
166 : : /* Setup enough descriptors for all tx queues */
167 : 0 : nix->outb_nb_desc = dev->outb.nb_desc;
168 : 0 : nix->outb_nb_crypto_qs = dev->outb.nb_crypto_qs;
169 : :
170 : : /* Setup Inline Outbound */
171 : 0 : rc = roc_nix_inl_outb_init(nix);
172 [ # # ]: 0 : if (rc) {
173 : 0 : plt_err("Failed to initialize nix inline outb, rc=%d",
174 : : rc);
175 : 0 : goto sa_dptr_free;
176 : : }
177 : :
178 : 0 : dev->outb.lf_base = roc_nix_inl_outb_lf_base_get(nix);
179 : :
180 : : /* Skip the rest if DEV_TX_OFFLOAD_SECURITY is not enabled */
181 [ # # ]: 0 : if (!(dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY))
182 : : return 0;
183 : :
184 : : /* Allocate memory to be used as dptr for CPT ucode
185 : : * WRITE_SA op.
186 : : */
187 : 0 : dev->outb.sa_dptr =
188 : 0 : plt_zmalloc(ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ, 0);
189 [ # # ]: 0 : if (!dev->outb.sa_dptr) {
190 : 0 : plt_err("Couldn't allocate memory for SA dptr");
191 : : rc = -ENOMEM;
192 : 0 : goto sa_dptr_free;
193 : : }
194 : :
195 : : rc = -ENOMEM;
196 : : /* Allocate a bitmap to alloc and free sa indexes */
197 : 0 : bmap_sz = plt_bitmap_get_memory_footprint(dev->outb.max_sa);
198 : 0 : mem = plt_zmalloc(bmap_sz, PLT_CACHE_LINE_SIZE);
199 [ # # ]: 0 : if (mem == NULL) {
200 : 0 : plt_err("Outbound SA bmap alloc failed");
201 : :
202 : 0 : rc |= roc_nix_inl_outb_fini(nix);
203 : 0 : goto sa_dptr_free;
204 : : }
205 : :
206 : : rc = -EIO;
207 : 0 : bmap = plt_bitmap_init(dev->outb.max_sa, mem, bmap_sz);
208 [ # # ]: 0 : if (!bmap) {
209 : 0 : plt_err("Outbound SA bmap init failed");
210 : :
211 : 0 : rc |= roc_nix_inl_outb_fini(nix);
212 : 0 : plt_free(mem);
213 : 0 : goto sa_dptr_free;
214 : : }
215 : :
216 [ # # ]: 0 : for (i = 0; i < dev->outb.max_sa; i++)
217 : 0 : plt_bitmap_set(bmap, i);
218 : :
219 : 0 : dev->outb.sa_base = roc_nix_inl_outb_sa_base_get(nix);
220 : 0 : dev->outb.sa_bmap_mem = mem;
221 : 0 : dev->outb.sa_bmap = bmap;
222 : :
223 : 0 : dev->outb.fc_sw_mem = plt_zmalloc(dev->outb.nb_crypto_qs *
224 : : RTE_CACHE_LINE_SIZE,
225 : : RTE_CACHE_LINE_SIZE);
226 [ # # ]: 0 : if (!dev->outb.fc_sw_mem) {
227 : 0 : plt_err("Outbound fc sw mem alloc failed");
228 : 0 : goto sa_bmap_free;
229 : : }
230 : :
231 : 0 : dev->outb.cpt_eng_caps = roc_nix_inl_eng_caps_get(nix);
232 : : }
233 : : return 0;
234 : :
235 : : sa_bmap_free:
236 : 0 : plt_free(dev->outb.sa_bmap_mem);
237 : 0 : sa_dptr_free:
238 [ # # ]: 0 : if (dev->inb.sa_dptr)
239 : 0 : plt_free(dev->inb.sa_dptr);
240 [ # # ]: 0 : if (dev->outb.sa_dptr)
241 : 0 : plt_free(dev->outb.sa_dptr);
242 : 0 : cleanup:
243 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
244 : 0 : rc |= roc_nix_inl_inb_fini(nix);
245 : : return rc;
246 : : }
247 : :
248 : : static int
249 : 0 : nix_meter_fini(struct cnxk_eth_dev *dev)
250 : : {
251 : : struct cnxk_meter_node *next_mtr = NULL;
252 : 0 : struct roc_nix_bpf_objs profs = {0};
253 : : struct cnxk_meter_node *mtr = NULL;
254 : : struct cnxk_mtr *fms = &dev->mtr;
255 : 0 : struct roc_nix *nix = &dev->nix;
256 : : struct roc_nix_rq *rq;
257 : : uint32_t i;
258 : : int rc = 0;
259 : :
260 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(mtr, fms, next, next_mtr) {
261 [ # # ]: 0 : for (i = 0; i < mtr->rq_num; i++) {
262 : 0 : rq = &dev->rqs[mtr->rq_id[i]];
263 : 0 : rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
264 : : }
265 : :
266 : 0 : profs.level = mtr->level;
267 : 0 : profs.count = 1;
268 : 0 : profs.ids[0] = mtr->bpf_id;
269 : 0 : rc = roc_nix_bpf_free(nix, &profs, 1);
270 : :
271 [ # # ]: 0 : if (rc)
272 : 0 : return rc;
273 : :
274 [ # # ]: 0 : TAILQ_REMOVE(fms, mtr, next);
275 : 0 : plt_free(mtr);
276 : : }
277 : : return 0;
278 : : }
279 : :
280 : : static int
281 : 0 : nix_security_release(struct cnxk_eth_dev *dev)
282 : : {
283 : 0 : struct rte_eth_dev *eth_dev = dev->eth_dev;
284 : : struct cnxk_eth_sec_sess *eth_sec, *tvar;
285 : 0 : struct roc_nix *nix = &dev->nix;
286 : : int rc, ret = 0;
287 : :
288 : : /* Cleanup Inline inbound */
289 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
290 : : /* Destroy inbound sessions */
291 : : tvar = NULL;
292 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->inb.list, entry, tvar)
293 : 0 : cnxk_eth_sec_ops.session_destroy(eth_dev,
294 : : eth_sec->sess);
295 : :
296 : : /* Clear lookup mem */
297 : 0 : cnxk_nix_lookup_mem_sa_base_clear(dev);
298 : :
299 : 0 : rc = roc_nix_inl_inb_fini(nix);
300 [ # # ]: 0 : if (rc)
301 : 0 : plt_err("Failed to cleanup nix inline inb, rc=%d", rc);
302 : : ret |= rc;
303 : :
304 : 0 : cnxk_nix_lookup_mem_metapool_clear(dev);
305 : :
306 [ # # ]: 0 : if (dev->inb.sa_dptr) {
307 : 0 : plt_free(dev->inb.sa_dptr);
308 : 0 : dev->inb.sa_dptr = NULL;
309 : : }
310 : : }
311 : :
312 : : /* Cleanup Inline outbound */
313 [ # # ]: 0 : if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY ||
314 [ # # ]: 0 : dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
315 : : /* Destroy outbound sessions */
316 : : tvar = NULL;
317 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->outb.list, entry, tvar)
318 : 0 : cnxk_eth_sec_ops.session_destroy(eth_dev,
319 : : eth_sec->sess);
320 : :
321 : 0 : rc = roc_nix_inl_outb_fini(nix);
322 [ # # ]: 0 : if (rc)
323 : 0 : plt_err("Failed to cleanup nix inline outb, rc=%d", rc);
324 : 0 : ret |= rc;
325 : :
326 : : plt_bitmap_free(dev->outb.sa_bmap);
327 : 0 : plt_free(dev->outb.sa_bmap_mem);
328 : 0 : dev->outb.sa_bmap = NULL;
329 : 0 : dev->outb.sa_bmap_mem = NULL;
330 [ # # ]: 0 : if (dev->outb.sa_dptr) {
331 : 0 : plt_free(dev->outb.sa_dptr);
332 : 0 : dev->outb.sa_dptr = NULL;
333 : : }
334 : :
335 : 0 : plt_free(dev->outb.fc_sw_mem);
336 : 0 : dev->outb.fc_sw_mem = NULL;
337 : : }
338 : :
339 : 0 : dev->inb.inl_dev = false;
340 : 0 : roc_nix_inb_mode_set(nix, false);
341 : 0 : dev->nb_rxq_sso = 0;
342 : 0 : dev->inb.nb_sess = 0;
343 : 0 : dev->outb.nb_sess = 0;
344 : 0 : return ret;
345 : : }
346 : :
347 : : static void
348 : 0 : nix_enable_mseg_on_jumbo(struct cnxk_eth_rxq_sp *rxq)
349 : : {
350 : : struct rte_pktmbuf_pool_private *mbp_priv;
351 : : struct rte_eth_dev *eth_dev;
352 : : struct cnxk_eth_dev *dev;
353 : : uint32_t buffsz;
354 : :
355 : 0 : dev = rxq->dev;
356 : 0 : eth_dev = dev->eth_dev;
357 : :
358 : : /* Get rx buffer size */
359 [ # # ]: 0 : mbp_priv = rte_mempool_get_priv(rxq->qconf.mp);
360 : 0 : buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
361 : :
362 [ # # ]: 0 : if (eth_dev->data->mtu + (uint32_t)CNXK_NIX_L2_OVERHEAD > buffsz) {
363 : 0 : dev->rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
364 : 0 : dev->tx_offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
365 : : }
366 : 0 : }
367 : :
368 : : int
369 : 0 : nix_recalc_mtu(struct rte_eth_dev *eth_dev)
370 : : {
371 : 0 : struct rte_eth_dev_data *data = eth_dev->data;
372 : : struct cnxk_eth_rxq_sp *rxq;
373 : : int rc;
374 : :
375 : 0 : rxq = ((struct cnxk_eth_rxq_sp *)data->rx_queues[0]) - 1;
376 : : /* Setup scatter mode if needed by jumbo */
377 : 0 : nix_enable_mseg_on_jumbo(rxq);
378 : :
379 : 0 : rc = cnxk_nix_mtu_set(eth_dev, data->mtu);
380 [ # # ]: 0 : if (rc)
381 : 0 : plt_err("Failed to set default MTU size, rc=%d", rc);
382 : :
383 : 0 : return rc;
384 : : }
385 : :
386 : : static int
387 : 0 : nix_init_flow_ctrl_config(struct rte_eth_dev *eth_dev)
388 : : {
389 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
390 : : enum roc_nix_fc_mode fc_mode = ROC_NIX_FC_FULL;
391 : : struct cnxk_fc_cfg *fc = &dev->fc_cfg;
392 : : int rc;
393 : :
394 [ # # # # ]: 0 : if (roc_nix_is_vf_or_sdp(&dev->nix) && !roc_nix_is_lbk(&dev->nix))
395 : : return 0;
396 : :
397 : : /* To avoid Link credit deadlock on Ax, disable Tx FC if it's enabled */
398 [ # # ]: 0 : if (roc_model_is_cn96_ax() &&
399 [ # # ]: 0 : dev->npc.switch_header_type != ROC_PRIV_FLAGS_HIGIG)
400 : : fc_mode = ROC_NIX_FC_TX;
401 : :
402 : : /* By default enable flow control */
403 : 0 : rc = roc_nix_fc_mode_set(&dev->nix, fc_mode);
404 [ # # ]: 0 : if (rc)
405 : : return rc;
406 : :
407 [ # # ]: 0 : fc->mode = (fc_mode == ROC_NIX_FC_FULL) ? RTE_ETH_FC_FULL : RTE_ETH_FC_TX_PAUSE;
408 : 0 : fc->rx_pause = (fc->mode == RTE_ETH_FC_FULL) || (fc->mode == RTE_ETH_FC_RX_PAUSE);
409 : 0 : fc->tx_pause = (fc->mode == RTE_ETH_FC_FULL) || (fc->mode == RTE_ETH_FC_TX_PAUSE);
410 : 0 : return rc;
411 : : }
412 : :
413 : : static int
414 : 0 : nix_update_flow_ctrl_config(struct rte_eth_dev *eth_dev)
415 : : {
416 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
417 : : struct cnxk_fc_cfg *fc = &dev->fc_cfg;
418 : 0 : struct rte_eth_fc_conf fc_cfg = {0};
419 : :
420 [ # # # # ]: 0 : if (roc_nix_is_sdp(&dev->nix) || roc_nix_is_esw(&dev->nix))
421 : 0 : return 0;
422 : :
423 : : /* Don't do anything if PFC is enabled */
424 [ # # ]: 0 : if (dev->pfc_cfg.rx_pause_en || dev->pfc_cfg.tx_pause_en)
425 : : return 0;
426 : :
427 [ # # ]: 0 : fc_cfg.mode = fc->mode;
428 : :
429 : : /* To avoid Link credit deadlock on Ax, disable Tx FC if it's enabled */
430 [ # # ]: 0 : if (roc_model_is_cn96_ax() &&
431 [ # # ]: 0 : dev->npc.switch_header_type != ROC_PRIV_FLAGS_HIGIG &&
432 [ # # ]: 0 : (fc_cfg.mode == RTE_ETH_FC_FULL || fc_cfg.mode == RTE_ETH_FC_RX_PAUSE)) {
433 : 0 : fc_cfg.mode =
434 : 0 : (fc_cfg.mode == RTE_ETH_FC_FULL ||
435 : : fc_cfg.mode == RTE_ETH_FC_TX_PAUSE) ?
436 [ # # ]: 0 : RTE_ETH_FC_TX_PAUSE : RTE_ETH_FC_NONE;
437 : : }
438 : :
439 : 0 : return cnxk_nix_flow_ctrl_set(eth_dev, &fc_cfg);
440 : : }
441 : :
442 : : uint64_t
443 : 0 : cnxk_nix_rxq_mbuf_setup(struct cnxk_eth_dev *dev)
444 : : {
445 : 0 : uint16_t port_id = dev->eth_dev->data->port_id;
446 : : struct rte_mbuf mb_def;
447 : : uint64_t *tmp;
448 : :
449 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
450 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
451 : : offsetof(struct rte_mbuf, data_off) !=
452 : : 2);
453 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
454 : : offsetof(struct rte_mbuf, data_off) !=
455 : : 4);
456 : : RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
457 : : offsetof(struct rte_mbuf, data_off) !=
458 : : 6);
459 : 0 : mb_def.nb_segs = 1;
460 : 0 : mb_def.data_off = RTE_PKTMBUF_HEADROOM +
461 : 0 : (dev->ptp_en * CNXK_NIX_TIMESYNC_RX_OFFSET);
462 : 0 : mb_def.port = port_id;
463 : : rte_mbuf_refcnt_set(&mb_def, 1);
464 : :
465 : : /* Prevent compiler reordering: rearm_data covers previous fields */
466 : 0 : rte_compiler_barrier();
467 : : tmp = (uint64_t *)&mb_def.rearm_data;
468 : :
469 : 0 : return *tmp;
470 : : }
471 : :
472 : : static inline uint8_t
473 : : nix_sq_max_sqe_sz(struct cnxk_eth_dev *dev)
474 : : {
475 : : /*
476 : : * Maximum three segments can be supported with W8, Choose
477 : : * NIX_MAXSQESZ_W16 for multi segment offload.
478 : : */
479 : 0 : if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
480 : : return NIX_MAXSQESZ_W16;
481 : : else
482 : 0 : return NIX_MAXSQESZ_W8;
483 : : }
484 : :
485 : : int
486 [ # # ]: 0 : cnxk_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
487 : : uint16_t nb_desc, uint16_t fp_tx_q_sz,
488 : : const struct rte_eth_txconf *tx_conf)
489 : : {
490 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
491 : 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
492 : : struct roc_nix *nix = &dev->nix;
493 : : struct cnxk_eth_txq_sp *txq_sp;
494 : : struct roc_nix_cq *cq;
495 : : struct roc_nix_sq *sq;
496 : : size_t txq_sz;
497 : : int rc;
498 : :
499 : : /* Free memory prior to re-allocation if needed. */
500 [ # # ]: 0 : if (eth_dev->data->tx_queues[qid] != NULL) {
501 : 0 : plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
502 : 0 : dev_ops->tx_queue_release(eth_dev, qid);
503 : 0 : eth_dev->data->tx_queues[qid] = NULL;
504 : : }
505 : :
506 : : /* When Tx Security offload is enabled, increase tx desc count by
507 : : * max possible outbound desc count.
508 : : */
509 [ # # ]: 0 : if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY)
510 : 0 : nb_desc += dev->outb.nb_desc;
511 : :
512 : : /* Setup ROC SQ */
513 : 0 : sq = &dev->sqs[qid];
514 : 0 : sq->qid = qid;
515 [ # # ]: 0 : sq->nb_desc = nb_desc;
516 : 0 : sq->max_sqe_sz = nix_sq_max_sqe_sz(dev);
517 [ # # ]: 0 : if (sq->nb_desc >= CNXK_NIX_DEF_SQ_COUNT)
518 : 0 : sq->fc_hyst_bits = 0x1;
519 : :
520 [ # # ]: 0 : if (nix->tx_compl_ena) {
521 : 0 : sq->cqid = sq->qid + dev->nb_rxq;
522 : 0 : sq->cq_ena = 1;
523 : 0 : cq = &dev->cqs[sq->cqid];
524 : 0 : cq->qid = sq->cqid;
525 : 0 : cq->nb_desc = nb_desc;
526 : 0 : rc = roc_nix_cq_init(&dev->nix, cq);
527 [ # # ]: 0 : if (rc) {
528 : 0 : plt_err("Failed to init cq=%d, rc=%d", cq->qid, rc);
529 : 0 : return rc;
530 : : }
531 : : }
532 : :
533 : 0 : rc = roc_nix_sq_init(&dev->nix, sq);
534 [ # # ]: 0 : if (rc) {
535 : 0 : plt_err("Failed to init sq=%d, rc=%d", qid, rc);
536 : 0 : return rc;
537 : : }
538 : :
539 : : rc = -ENOMEM;
540 : 0 : txq_sz = sizeof(struct cnxk_eth_txq_sp) + fp_tx_q_sz;
541 : 0 : txq_sp = plt_zmalloc(txq_sz, PLT_CACHE_LINE_SIZE);
542 [ # # ]: 0 : if (!txq_sp) {
543 : 0 : plt_err("Failed to alloc tx queue mem");
544 : 0 : rc |= roc_nix_sq_fini(sq);
545 : 0 : return rc;
546 : : }
547 : :
548 : 0 : txq_sp->dev = dev;
549 : 0 : txq_sp->qid = qid;
550 : 0 : txq_sp->qconf.conf.tx = *tx_conf;
551 : : /* Queue config should reflect global offloads */
552 : 0 : txq_sp->qconf.conf.tx.offloads = dev->tx_offloads;
553 : 0 : txq_sp->qconf.nb_desc = nb_desc;
554 : :
555 : 0 : plt_nix_dbg("sq=%d fc=%p offload=0x%" PRIx64 " lmt_addr=%p"
556 : : " nb_sqb_bufs=%d sqes_per_sqb_log2=%d",
557 : : qid, sq->fc, dev->tx_offloads, sq->lmt_addr,
558 : : sq->nb_sqb_bufs, sq->sqes_per_sqb_log2);
559 : :
560 : : /* Store start of fast path area */
561 : 0 : eth_dev->data->tx_queues[qid] = txq_sp + 1;
562 : 0 : eth_dev->data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
563 : 0 : return 0;
564 : : }
565 : :
566 : : void
567 : 0 : cnxk_nix_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
568 : : {
569 : 0 : void *txq = eth_dev->data->tx_queues[qid];
570 : : struct cnxk_eth_txq_sp *txq_sp;
571 : : struct cnxk_eth_dev *dev;
572 : : struct roc_nix_sq *sq;
573 : : int rc;
574 : :
575 [ # # ]: 0 : if (!txq)
576 : : return;
577 : :
578 : : txq_sp = cnxk_eth_txq_to_sp(txq);
579 : :
580 : 0 : dev = txq_sp->dev;
581 : :
582 : 0 : plt_nix_dbg("Releasing txq %u", qid);
583 : :
584 : : /* Cleanup ROC SQ */
585 : 0 : sq = &dev->sqs[qid];
586 : 0 : rc = roc_nix_sq_fini(sq);
587 [ # # ]: 0 : if (rc)
588 : 0 : plt_err("Failed to cleanup sq, rc=%d", rc);
589 : :
590 : : /* Finally free */
591 : 0 : plt_free(txq_sp);
592 : : }
593 : :
594 : : static int
595 : 0 : cnxk_nix_process_rx_conf(const struct rte_eth_rxconf *rx_conf,
596 : : struct rte_mempool **lpb_pool,
597 : : struct rte_mempool **spb_pool)
598 : : {
599 : : struct rte_mempool *pool0;
600 : : struct rte_mempool *pool1;
601 : 0 : struct rte_mempool **mp = rx_conf->rx_mempools;
602 : : const char *platform_ops;
603 : : struct rte_mempool_ops *ops;
604 : :
605 [ # # ]: 0 : if (*lpb_pool ||
606 [ # # ]: 0 : rx_conf->rx_nmempool != CNXK_NIX_NUM_POOLS_MAX) {
607 : 0 : plt_err("invalid arguments");
608 : 0 : return -EINVAL;
609 : : }
610 : :
611 [ # # # # : 0 : if (mp == NULL || mp[0] == NULL || mp[1] == NULL) {
# # ]
612 : 0 : plt_err("invalid memory pools");
613 : 0 : return -EINVAL;
614 : : }
615 : :
616 : : pool0 = mp[0];
617 : : pool1 = mp[1];
618 : :
619 [ # # ]: 0 : if (pool0->elt_size > pool1->elt_size) {
620 : 0 : *lpb_pool = pool0;
621 : 0 : *spb_pool = pool1;
622 : :
623 : : } else {
624 : 0 : *lpb_pool = pool1;
625 : 0 : *spb_pool = pool0;
626 : : }
627 : :
628 [ # # ]: 0 : if ((*spb_pool)->pool_id == 0) {
629 : 0 : plt_err("Invalid pool_id");
630 : 0 : return -EINVAL;
631 : : }
632 : :
633 : 0 : platform_ops = rte_mbuf_platform_mempool_ops();
634 : 0 : ops = rte_mempool_get_ops((*spb_pool)->ops_index);
635 [ # # ]: 0 : if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
636 : 0 : plt_err("mempool ops should be of cnxk_npa type");
637 : 0 : return -EINVAL;
638 : : }
639 : :
640 : 0 : plt_info("spb_pool:%s lpb_pool:%s lpb_len:%u spb_len:%u", (*spb_pool)->name,
641 : : (*lpb_pool)->name, (*lpb_pool)->elt_size, (*spb_pool)->elt_size);
642 : :
643 : 0 : return 0;
644 : : }
645 : :
646 : : int
647 [ # # ]: 0 : cnxk_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
648 : : uint32_t nb_desc, uint16_t fp_rx_q_sz,
649 : : const struct rte_eth_rxconf *rx_conf,
650 : : struct rte_mempool *mp)
651 : : {
652 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
653 : 0 : struct roc_nix *nix = &dev->nix;
654 : : struct cnxk_eth_rxq_sp *rxq_sp;
655 : : struct rte_mempool_ops *ops;
656 : : uint32_t desc_cnt = nb_desc;
657 : : const char *platform_ops;
658 : : struct roc_nix_rq *rq;
659 : : struct roc_nix_cq *cq;
660 : : uint16_t first_skip;
661 : : uint16_t wqe_skip;
662 : : int rc = -EINVAL;
663 : : size_t rxq_sz;
664 : 0 : struct rte_mempool *lpb_pool = mp;
665 : 0 : struct rte_mempool *spb_pool = NULL;
666 : :
667 : : /* Sanity checks */
668 [ # # ]: 0 : if (rx_conf->rx_deferred_start == 1) {
669 : 0 : plt_err("Deferred Rx start is not supported");
670 : 0 : goto fail;
671 : : }
672 : :
673 [ # # ]: 0 : if (rx_conf->rx_nmempool > 0) {
674 : 0 : rc = cnxk_nix_process_rx_conf(rx_conf, &lpb_pool, &spb_pool);
675 [ # # ]: 0 : if (rc)
676 : 0 : goto fail;
677 : : }
678 : :
679 : 0 : platform_ops = rte_mbuf_platform_mempool_ops();
680 : : /* This driver needs cnxk_npa mempool ops to work */
681 : 0 : ops = rte_mempool_get_ops(lpb_pool->ops_index);
682 [ # # ]: 0 : if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
683 : 0 : plt_err("mempool ops should be of cnxk_npa type");
684 : 0 : goto fail;
685 : : }
686 : :
687 [ # # ]: 0 : if (lpb_pool->pool_id == 0) {
688 : 0 : plt_err("Invalid pool_id");
689 : 0 : goto fail;
690 : : }
691 : :
692 : : /* Free memory prior to re-allocation if needed */
693 [ # # ]: 0 : if (eth_dev->data->rx_queues[qid] != NULL) {
694 : 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
695 : :
696 : 0 : plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
697 : 0 : dev_ops->rx_queue_release(eth_dev, qid);
698 : 0 : eth_dev->data->rx_queues[qid] = NULL;
699 : : }
700 : :
701 : : /* Its a no-op when inline device is not used */
702 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY ||
703 [ # # ]: 0 : dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY)
704 : 0 : roc_nix_inl_dev_xaq_realloc(lpb_pool->pool_id);
705 : :
706 : : /* Increase CQ size to Aura size to avoid CQ overflow and
707 : : * then CPT buffer leak.
708 : : */
709 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
710 : 0 : nb_desc = nix_inl_cq_sz_clamp_up(nix, lpb_pool, nb_desc);
711 : :
712 : : /* Double the CQ descriptors */
713 [ # # ]: 0 : if (nix->force_tail_drop)
714 : 0 : nb_desc = 2 * RTE_MAX(nb_desc, (uint32_t)4096);
715 : :
716 : : /* Setup ROC CQ */
717 : 0 : cq = &dev->cqs[qid];
718 : 0 : cq->qid = qid;
719 : 0 : cq->nb_desc = nb_desc;
720 : 0 : rc = roc_nix_cq_init(&dev->nix, cq);
721 [ # # ]: 0 : if (rc) {
722 : 0 : plt_err("Failed to init roc cq for rq=%d, rc=%d", qid, rc);
723 : 0 : goto fail;
724 : : }
725 : :
726 : : /* Setup ROC RQ */
727 : 0 : rq = &dev->rqs[qid];
728 : 0 : rq->qid = qid;
729 : 0 : rq->cqid = cq->qid;
730 : 0 : rq->aura_handle = lpb_pool->pool_id;
731 : 0 : rq->flow_tag_width = 32;
732 [ # # ]: 0 : rq->sso_ena = false;
733 : :
734 : : /* Calculate first mbuf skip */
735 : : first_skip = (sizeof(struct rte_mbuf));
736 : : first_skip += RTE_PKTMBUF_HEADROOM;
737 : 0 : first_skip += rte_pktmbuf_priv_size(lpb_pool);
738 : 0 : rq->first_skip = first_skip;
739 : 0 : rq->later_skip = sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(lpb_pool);
740 [ # # ]: 0 : rq->lpb_size = lpb_pool->elt_size;
741 [ # # ]: 0 : if (roc_errata_nix_no_meta_aura())
742 : 0 : rq->lpb_drop_ena = !(dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY);
743 : :
744 : : /* Enable Inline IPSec on RQ, will not be used for Poll mode */
745 [ # # # # ]: 0 : if (roc_nix_inl_inb_is_enabled(nix) && !dev->inb.inl_dev) {
746 : 0 : rq->ipsech_ena = true;
747 : : /* WQE skip is needed when poll mode is enabled in CN10KA_B0 and above
748 : : * for Inline IPsec traffic to CQ without inline device.
749 : : */
750 : : wqe_skip = RTE_ALIGN_CEIL(sizeof(struct rte_mbuf), ROC_CACHE_LINE_SZ);
751 : : wqe_skip = wqe_skip / ROC_CACHE_LINE_SZ;
752 : 0 : rq->wqe_skip = wqe_skip;
753 : : }
754 : :
755 [ # # ]: 0 : if (spb_pool) {
756 : 0 : rq->spb_ena = 1;
757 : 0 : rq->spb_aura_handle = spb_pool->pool_id;
758 : 0 : rq->spb_size = spb_pool->elt_size;
759 : : }
760 : :
761 : 0 : rc = roc_nix_rq_init(&dev->nix, rq, !!eth_dev->data->dev_started);
762 [ # # ]: 0 : if (rc) {
763 : 0 : plt_err("Failed to init roc rq for rq=%d, rc=%d", qid, rc);
764 : 0 : goto cq_fini;
765 : : }
766 : :
767 : : /* Allocate and setup fast path rx queue */
768 : : rc = -ENOMEM;
769 : 0 : rxq_sz = sizeof(struct cnxk_eth_rxq_sp) + fp_rx_q_sz;
770 : 0 : rxq_sp = plt_zmalloc(rxq_sz, PLT_CACHE_LINE_SIZE);
771 [ # # ]: 0 : if (!rxq_sp) {
772 : 0 : plt_err("Failed to alloc rx queue for rq=%d", qid);
773 : 0 : goto rq_fini;
774 : : }
775 : :
776 : : /* Setup slow path fields */
777 : 0 : rxq_sp->dev = dev;
778 : 0 : rxq_sp->qid = qid;
779 : 0 : rxq_sp->qconf.conf.rx = *rx_conf;
780 : : /* Queue config should reflect global offloads */
781 : 0 : rxq_sp->qconf.conf.rx.offloads = dev->rx_offloads;
782 : 0 : rxq_sp->qconf.nb_desc = desc_cnt;
783 : 0 : rxq_sp->qconf.mp = lpb_pool;
784 : 0 : rxq_sp->tc = 0;
785 : 0 : rxq_sp->tx_pause = (dev->fc_cfg.mode == RTE_ETH_FC_FULL ||
786 : : dev->fc_cfg.mode == RTE_ETH_FC_TX_PAUSE);
787 : :
788 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
789 : : /* Pass a tagmask used to handle error packets in inline device.
790 : : * Ethdev rq's tag_mask field will be overwritten later
791 : : * when sso is setup.
792 : : */
793 : 0 : rq->tag_mask =
794 : : 0x0FF00000 | ((uint32_t)RTE_EVENT_TYPE_ETHDEV << 28);
795 : :
796 : : /* Setup rq reference for inline dev if present */
797 : 0 : rc = roc_nix_inl_dev_rq_get(rq, !!eth_dev->data->dev_started);
798 [ # # ]: 0 : if (rc)
799 : 0 : goto free_mem;
800 : : }
801 : :
802 : 0 : plt_nix_dbg("rq=%d pool=%s nb_desc=%d->%d", qid, lpb_pool->name, nb_desc,
803 : : cq->nb_desc);
804 : :
805 : : /* Store start of fast path area */
806 : 0 : eth_dev->data->rx_queues[qid] = rxq_sp + 1;
807 : 0 : eth_dev->data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
808 : :
809 : : /* Calculating delta and freq mult between PTP HI clock and tsc.
810 : : * These are needed in deriving raw clock value from tsc counter.
811 : : * read_clock eth op returns raw clock value.
812 : : */
813 [ # # # # ]: 0 : if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) || dev->ptp_en) {
814 : 0 : rc = cnxk_nix_tsc_convert(dev);
815 [ # # ]: 0 : if (rc) {
816 : 0 : plt_err("Failed to calculate delta and freq mult");
817 : 0 : goto rq_fini;
818 : : }
819 : : }
820 : :
821 : : return 0;
822 : : free_mem:
823 : 0 : plt_free(rxq_sp);
824 : 0 : rq_fini:
825 : 0 : rc |= roc_nix_rq_fini(rq);
826 : 0 : cq_fini:
827 : 0 : rc |= roc_nix_cq_fini(cq);
828 : : fail:
829 : : return rc;
830 : : }
831 : :
832 : : static void
833 : 0 : cnxk_nix_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
834 : : {
835 : 0 : void *rxq = eth_dev->data->rx_queues[qid];
836 : : struct cnxk_eth_rxq_sp *rxq_sp;
837 : : struct cnxk_eth_dev *dev;
838 : : struct roc_nix_rq *rq;
839 : : struct roc_nix_cq *cq;
840 : : int rc;
841 : :
842 [ # # ]: 0 : if (!rxq)
843 : : return;
844 : :
845 : : rxq_sp = cnxk_eth_rxq_to_sp(rxq);
846 : 0 : dev = rxq_sp->dev;
847 : 0 : rq = &dev->rqs[qid];
848 : :
849 : 0 : plt_nix_dbg("Releasing rxq %u", qid);
850 : :
851 : : /* Release rq reference for inline dev if present */
852 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
853 : 0 : roc_nix_inl_dev_rq_put(rq);
854 : :
855 : : /* Cleanup ROC RQ */
856 : 0 : rc = roc_nix_rq_fini(rq);
857 [ # # ]: 0 : if (rc)
858 : 0 : plt_err("Failed to cleanup rq, rc=%d", rc);
859 : :
860 : : /* Cleanup ROC CQ */
861 : 0 : cq = &dev->cqs[qid];
862 : 0 : rc = roc_nix_cq_fini(cq);
863 [ # # ]: 0 : if (rc)
864 : 0 : plt_err("Failed to cleanup cq, rc=%d", rc);
865 : :
866 : : /* Finally free fast path area */
867 : 0 : plt_free(rxq_sp);
868 : : }
869 : :
870 : : uint32_t
871 : 0 : cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
872 : : uint8_t rss_level)
873 : : {
874 : 0 : uint32_t flow_key_type[RSS_MAX_LEVELS][6] = {
875 : : {FLOW_KEY_TYPE_IPV4, FLOW_KEY_TYPE_IPV6, FLOW_KEY_TYPE_TCP,
876 : : FLOW_KEY_TYPE_UDP, FLOW_KEY_TYPE_SCTP, FLOW_KEY_TYPE_ETH_DMAC},
877 : : {FLOW_KEY_TYPE_INNR_IPV4, FLOW_KEY_TYPE_INNR_IPV6,
878 : : FLOW_KEY_TYPE_INNR_TCP, FLOW_KEY_TYPE_INNR_UDP,
879 : : FLOW_KEY_TYPE_INNR_SCTP, FLOW_KEY_TYPE_INNR_ETH_DMAC},
880 : : {FLOW_KEY_TYPE_IPV4 | FLOW_KEY_TYPE_INNR_IPV4,
881 : : FLOW_KEY_TYPE_IPV6 | FLOW_KEY_TYPE_INNR_IPV6,
882 : : FLOW_KEY_TYPE_TCP | FLOW_KEY_TYPE_INNR_TCP,
883 : : FLOW_KEY_TYPE_UDP | FLOW_KEY_TYPE_INNR_UDP,
884 : : FLOW_KEY_TYPE_SCTP | FLOW_KEY_TYPE_INNR_SCTP,
885 : : FLOW_KEY_TYPE_ETH_DMAC | FLOW_KEY_TYPE_INNR_ETH_DMAC}
886 : : };
887 : : uint32_t flowkey_cfg = 0;
888 : :
889 : 0 : dev->ethdev_rss_hf = ethdev_rss;
890 : :
891 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L2_PAYLOAD &&
892 [ # # ]: 0 : dev->npc.switch_header_type == ROC_PRIV_FLAGS_LEN_90B) {
893 : : flowkey_cfg |= FLOW_KEY_TYPE_CH_LEN_90B;
894 : : }
895 : :
896 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_C_VLAN)
897 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_VLAN;
898 : :
899 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L3_SRC_ONLY)
900 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_L3_SRC;
901 : :
902 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L3_DST_ONLY)
903 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_L3_DST;
904 : :
905 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L4_SRC_ONLY)
906 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_L4_SRC;
907 : :
908 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L4_DST_ONLY)
909 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_L4_DST;
910 : :
911 [ # # ]: 0 : if (ethdev_rss & RSS_IPV4_ENABLE)
912 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_IPV4_INDEX];
913 : :
914 [ # # ]: 0 : if (ethdev_rss & RSS_IPV6_ENABLE)
915 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_IPV6_INDEX];
916 : :
917 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_TCP)
918 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_TCP_INDEX];
919 : :
920 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_UDP)
921 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_UDP_INDEX];
922 : :
923 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_SCTP)
924 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_SCTP_INDEX];
925 : :
926 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_L2_PAYLOAD)
927 : 0 : flowkey_cfg |= flow_key_type[rss_level][RSS_DMAC_INDEX];
928 : :
929 [ # # ]: 0 : if (ethdev_rss & RSS_IPV6_EX_ENABLE)
930 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_IPV6_EXT;
931 : :
932 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_PORT)
933 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_PORT;
934 : :
935 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_NVGRE)
936 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_NVGRE;
937 : :
938 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_VXLAN)
939 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_VXLAN;
940 : :
941 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_GENEVE)
942 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_GENEVE;
943 : :
944 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_GTPU)
945 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_GTPU;
946 : :
947 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_ESP)
948 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_ESP;
949 : :
950 [ # # ]: 0 : if (ethdev_rss & RTE_ETH_RSS_IB_BTH)
951 : 0 : flowkey_cfg |= FLOW_KEY_TYPE_ROCEV2;
952 : :
953 : 0 : return flowkey_cfg;
954 : : }
955 : :
956 : : static int
957 : 0 : nix_rxchan_cfg_disable(struct cnxk_eth_dev *dev)
958 : : {
959 : 0 : struct roc_nix *nix = &dev->nix;
960 : : struct roc_nix_fc_cfg fc_cfg;
961 : : int rc;
962 : :
963 [ # # ]: 0 : if (!roc_nix_is_lbk(nix))
964 : : return 0;
965 : :
966 : : memset(&fc_cfg, 0, sizeof(struct roc_nix_fc_cfg));
967 : : fc_cfg.type = ROC_NIX_FC_RXCHAN_CFG;
968 : : fc_cfg.rxchan_cfg.enable = false;
969 : 0 : rc = roc_nix_fc_config_set(nix, &fc_cfg);
970 [ # # ]: 0 : if (rc) {
971 : 0 : plt_err("Failed to setup flow control, rc=%d(%s)", rc, roc_error_msg_get(rc));
972 : 0 : return rc;
973 : : }
974 : : return 0;
975 : : }
976 : :
977 : : static void
978 : 0 : nix_free_queue_mem(struct cnxk_eth_dev *dev)
979 : : {
980 : 0 : plt_free(dev->rqs);
981 : 0 : plt_free(dev->cqs);
982 : 0 : plt_free(dev->sqs);
983 : 0 : dev->rqs = NULL;
984 : 0 : dev->cqs = NULL;
985 : 0 : dev->sqs = NULL;
986 : 0 : }
987 : :
988 : : static int
989 : 0 : nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
990 : : {
991 : 0 : struct rte_eth_dev *eth_dev = dev->eth_dev;
992 : : int rc = 0;
993 : :
994 : 0 : TAILQ_INIT(&dev->mtr_profiles);
995 : 0 : TAILQ_INIT(&dev->mtr_policy);
996 : 0 : TAILQ_INIT(&dev->mtr);
997 : :
998 [ # # ]: 0 : if (eth_dev->dev_ops->mtr_ops_get == NULL)
999 : : return rc;
1000 : :
1001 : 0 : return nix_mtr_capabilities_init(eth_dev);
1002 : : }
1003 : :
1004 : : static int
1005 : 0 : nix_rss_default_setup(struct cnxk_eth_dev *dev)
1006 : : {
1007 : 0 : struct rte_eth_dev *eth_dev = dev->eth_dev;
1008 : : uint8_t rss_hash_level;
1009 : : uint32_t flowkey_cfg;
1010 : : uint64_t rss_hf;
1011 : :
1012 : 0 : rss_hf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
1013 : 0 : rss_hash_level = RTE_ETH_RSS_LEVEL(rss_hf);
1014 [ # # ]: 0 : if (rss_hash_level)
1015 : 0 : rss_hash_level -= 1;
1016 : :
1017 : 0 : flowkey_cfg = cnxk_rss_ethdev_to_nix(dev, rss_hf, rss_hash_level);
1018 : 0 : return roc_nix_rss_default_setup(&dev->nix, flowkey_cfg);
1019 : : }
1020 : :
1021 : : static int
1022 [ # # ]: 0 : nix_store_queue_cfg_and_then_release(struct rte_eth_dev *eth_dev)
1023 : : {
1024 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1025 : 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
1026 : : struct cnxk_eth_qconf *tx_qconf = NULL;
1027 : : struct cnxk_eth_qconf *rx_qconf = NULL;
1028 : : struct cnxk_eth_rxq_sp *rxq_sp;
1029 : : struct cnxk_eth_txq_sp *txq_sp;
1030 : : int i, nb_rxq, nb_txq;
1031 : : void **txq, **rxq;
1032 : :
1033 : 0 : nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
1034 : 0 : nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
1035 : :
1036 : 0 : tx_qconf = malloc(nb_txq * sizeof(*tx_qconf));
1037 [ # # ]: 0 : if (tx_qconf == NULL) {
1038 : 0 : plt_err("Failed to allocate memory for tx_qconf");
1039 : 0 : goto fail;
1040 : : }
1041 : :
1042 : 0 : rx_qconf = malloc(nb_rxq * sizeof(*rx_qconf));
1043 [ # # ]: 0 : if (rx_qconf == NULL) {
1044 : 0 : plt_err("Failed to allocate memory for rx_qconf");
1045 : 0 : goto fail;
1046 : : }
1047 : :
1048 : 0 : txq = eth_dev->data->tx_queues;
1049 [ # # ]: 0 : for (i = 0; i < nb_txq; i++) {
1050 [ # # ]: 0 : if (txq[i] == NULL) {
1051 : 0 : tx_qconf[i].valid = false;
1052 : 0 : plt_info("txq[%d] is already released", i);
1053 : 0 : continue;
1054 : : }
1055 : : txq_sp = cnxk_eth_txq_to_sp(txq[i]);
1056 : 0 : memcpy(&tx_qconf[i], &txq_sp->qconf, sizeof(*tx_qconf));
1057 : 0 : tx_qconf[i].valid = true;
1058 : 0 : dev_ops->tx_queue_release(eth_dev, i);
1059 : 0 : eth_dev->data->tx_queues[i] = NULL;
1060 : : }
1061 : :
1062 : 0 : rxq = eth_dev->data->rx_queues;
1063 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++) {
1064 [ # # ]: 0 : if (rxq[i] == NULL) {
1065 : 0 : rx_qconf[i].valid = false;
1066 : 0 : plt_info("rxq[%d] is already released", i);
1067 : 0 : continue;
1068 : : }
1069 : : rxq_sp = cnxk_eth_rxq_to_sp(rxq[i]);
1070 : 0 : memcpy(&rx_qconf[i], &rxq_sp->qconf, sizeof(*rx_qconf));
1071 : 0 : rx_qconf[i].valid = true;
1072 : 0 : dev_ops->rx_queue_release(eth_dev, i);
1073 : 0 : eth_dev->data->rx_queues[i] = NULL;
1074 : : }
1075 : :
1076 : 0 : dev->tx_qconf = tx_qconf;
1077 : 0 : dev->rx_qconf = rx_qconf;
1078 : 0 : return 0;
1079 : :
1080 : 0 : fail:
1081 : 0 : free(tx_qconf);
1082 : : free(rx_qconf);
1083 : 0 : return -ENOMEM;
1084 : : }
1085 : :
1086 : : static int
1087 : 0 : nix_restore_queue_cfg(struct rte_eth_dev *eth_dev)
1088 : : {
1089 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1090 : 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
1091 : 0 : struct cnxk_eth_qconf *tx_qconf = dev->tx_qconf;
1092 : 0 : struct cnxk_eth_qconf *rx_qconf = dev->rx_qconf;
1093 : : int rc, i, nb_rxq, nb_txq;
1094 : :
1095 : 0 : nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
1096 : 0 : nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
1097 : :
1098 : : rc = -ENOMEM;
1099 : : /* Setup tx & rx queues with previous configuration so
1100 : : * that the queues can be functional in cases like ports
1101 : : * are started without re configuring queues.
1102 : : *
1103 : : * Usual re config sequence is like below:
1104 : : * port_configure() {
1105 : : * if(reconfigure) {
1106 : : * queue_release()
1107 : : * queue_setup()
1108 : : * }
1109 : : * queue_configure() {
1110 : : * queue_release()
1111 : : * queue_setup()
1112 : : * }
1113 : : * }
1114 : : * port_start()
1115 : : *
1116 : : * In some application's control path, queue_configure() would
1117 : : * NOT be invoked for TXQs/RXQs in port_configure().
1118 : : * In such cases, queues can be functional after start as the
1119 : : * queues are already setup in port_configure().
1120 : : */
1121 [ # # ]: 0 : for (i = 0; i < nb_txq; i++) {
1122 [ # # ]: 0 : if (!tx_qconf[i].valid)
1123 : 0 : continue;
1124 : 0 : rc = dev_ops->tx_queue_setup(eth_dev, i, tx_qconf[i].nb_desc, 0,
1125 : 0 : &tx_qconf[i].conf.tx);
1126 [ # # ]: 0 : if (rc) {
1127 : 0 : plt_err("Failed to setup tx queue rc=%d", rc);
1128 [ # # ]: 0 : for (i -= 1; i >= 0; i--)
1129 : 0 : dev_ops->tx_queue_release(eth_dev, i);
1130 : 0 : goto fail;
1131 : : }
1132 : : }
1133 : :
1134 : 0 : free(tx_qconf);
1135 : : tx_qconf = NULL;
1136 : :
1137 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++) {
1138 [ # # ]: 0 : if (!rx_qconf[i].valid)
1139 : 0 : continue;
1140 : 0 : rc = dev_ops->rx_queue_setup(eth_dev, i, rx_qconf[i].nb_desc, 0,
1141 : 0 : &rx_qconf[i].conf.rx,
1142 : : rx_qconf[i].mp);
1143 [ # # ]: 0 : if (rc) {
1144 : 0 : plt_err("Failed to setup rx queue rc=%d", rc);
1145 [ # # ]: 0 : for (i -= 1; i >= 0; i--)
1146 : 0 : dev_ops->rx_queue_release(eth_dev, i);
1147 : 0 : goto tx_queue_release;
1148 : : }
1149 : : }
1150 : :
1151 : 0 : free(rx_qconf);
1152 : : rx_qconf = NULL;
1153 : :
1154 : 0 : return 0;
1155 : :
1156 : : tx_queue_release:
1157 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1158 : 0 : dev_ops->tx_queue_release(eth_dev, i);
1159 : 0 : fail:
1160 : 0 : free(tx_qconf);
1161 : 0 : free(rx_qconf);
1162 : :
1163 : 0 : return rc;
1164 : : }
1165 : :
1166 : : static void
1167 : : nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev)
1168 : : {
1169 : : /* These dummy functions are required for supporting
1170 : : * some applications which reconfigure queues without
1171 : : * stopping tx burst and rx burst threads.
1172 : : * When the queues context is saved, txq/rxqs are released
1173 : : * which caused app crash since rx/tx burst is still
1174 : : * on different lcores
1175 : : */
1176 : 0 : eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
1177 : 0 : eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1178 : : rte_mb();
1179 : : }
1180 : :
1181 : : static int
1182 : 0 : nix_lso_tun_fmt_update(struct cnxk_eth_dev *dev)
1183 : : {
1184 : : uint8_t udp_tun[ROC_NIX_LSO_TUN_MAX];
1185 : : uint8_t tun[ROC_NIX_LSO_TUN_MAX];
1186 : 0 : struct roc_nix *nix = &dev->nix;
1187 : : int rc;
1188 : :
1189 : 0 : rc = roc_nix_lso_fmt_get(nix, udp_tun, tun);
1190 [ # # ]: 0 : if (rc)
1191 : : return rc;
1192 : :
1193 : 0 : dev->lso_tun_fmt = ((uint64_t)tun[ROC_NIX_LSO_TUN_V4V4] |
1194 : 0 : (uint64_t)tun[ROC_NIX_LSO_TUN_V4V6] << 8 |
1195 : 0 : (uint64_t)tun[ROC_NIX_LSO_TUN_V6V4] << 16 |
1196 : 0 : (uint64_t)tun[ROC_NIX_LSO_TUN_V6V6] << 24);
1197 : :
1198 : 0 : dev->lso_tun_fmt |= ((uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V4] << 32 |
1199 : 0 : (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V6] << 40 |
1200 : 0 : (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V4] << 48 |
1201 : 0 : (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V6] << 56);
1202 : 0 : return 0;
1203 : : }
1204 : :
1205 : : static int
1206 : 0 : nix_lso_fmt_setup(struct cnxk_eth_dev *dev)
1207 : : {
1208 : 0 : struct roc_nix *nix = &dev->nix;
1209 : : int rc;
1210 : :
1211 : : /* Nothing much to do if offload is not enabled */
1212 [ # # ]: 0 : if (!(dev->tx_offloads &
1213 : : (RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
1214 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO)))
1215 : : return 0;
1216 : :
1217 : : /* Setup LSO formats in AF. Its a no-op if other ethdev has
1218 : : * already set it up
1219 : : */
1220 : 0 : rc = roc_nix_lso_fmt_setup(nix);
1221 [ # # ]: 0 : if (rc)
1222 : : return rc;
1223 : :
1224 : 0 : return nix_lso_tun_fmt_update(dev);
1225 : : }
1226 : :
1227 : : int
1228 : 0 : cnxk_nix_configure(struct rte_eth_dev *eth_dev)
1229 : : {
1230 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1231 : : struct rte_eth_dev_data *data = eth_dev->data;
1232 : : struct rte_eth_conf *conf = &data->dev_conf;
1233 : : struct rte_eth_rxmode *rxmode = &conf->rxmode;
1234 : : struct rte_eth_txmode *txmode = &conf->txmode;
1235 : : char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
1236 : 0 : struct roc_nix_fc_cfg fc_cfg = {0};
1237 : 0 : struct roc_nix *nix = &dev->nix;
1238 : : uint16_t nb_rxq, nb_txq, nb_cq;
1239 : : struct rte_ether_addr *ea;
1240 : : uint64_t rx_cfg;
1241 : : int rc, i;
1242 : : void *qs;
1243 : :
1244 : : rc = -EINVAL;
1245 : :
1246 : : /* Sanity checks */
1247 [ # # ]: 0 : if (rte_eal_has_hugepages() == 0) {
1248 : 0 : plt_err("Huge page is not configured");
1249 : 0 : goto fail_configure;
1250 : : }
1251 : :
1252 [ # # ]: 0 : if (conf->dcb_capability_en == 1) {
1253 : 0 : plt_err("dcb enable is not supported");
1254 : 0 : goto fail_configure;
1255 : : }
1256 : :
1257 [ # # ]: 0 : if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
1258 : : rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
1259 : 0 : plt_err("Unsupported mq rx mode %d", rxmode->mq_mode);
1260 : 0 : goto fail_configure;
1261 : : }
1262 : :
1263 [ # # ]: 0 : if (txmode->mq_mode != RTE_ETH_MQ_TX_NONE) {
1264 : 0 : plt_err("Unsupported mq tx mode %d", txmode->mq_mode);
1265 : 0 : goto fail_configure;
1266 : : }
1267 : :
1268 : : /* Free the resources allocated from the previous configure */
1269 [ # # ]: 0 : if (dev->configured == 1) {
1270 : : /* Unregister queue irq's */
1271 : 0 : roc_nix_unregister_queue_irqs(nix);
1272 : :
1273 : : /* Unregister CQ irqs if present */
1274 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.rxq)
1275 : 0 : roc_nix_unregister_cq_irqs(nix);
1276 : :
1277 : : /* Set no-op functions */
1278 : : nix_set_nop_rxtx_function(eth_dev);
1279 : : /* Store queue config for later */
1280 : 0 : rc = nix_store_queue_cfg_and_then_release(eth_dev);
1281 [ # # ]: 0 : if (rc)
1282 : 0 : goto fail_configure;
1283 : :
1284 : : /* Disable and free rte_meter entries */
1285 : 0 : rc = nix_meter_fini(dev);
1286 [ # # ]: 0 : if (rc)
1287 : 0 : goto fail_configure;
1288 : :
1289 : : /* Cleanup security support */
1290 : 0 : rc = nix_security_release(dev);
1291 [ # # ]: 0 : if (rc)
1292 : 0 : goto fail_configure;
1293 : :
1294 : 0 : roc_nix_tm_fini(nix);
1295 : 0 : nix_rxchan_cfg_disable(dev);
1296 : 0 : roc_nix_lf_free(nix);
1297 : :
1298 : : /* Reset to invalid */
1299 [ # # ]: 0 : for (i = 0; i < dev->max_mac_entries; i++)
1300 : 0 : dev->dmac_idx_map[i] = CNXK_NIX_DMAC_IDX_INVALID;
1301 : :
1302 : 0 : dev->dmac_filter_count = 1;
1303 : : }
1304 : :
1305 : 0 : dev->rx_offloads = rxmode->offloads;
1306 : 0 : dev->tx_offloads = txmode->offloads;
1307 : :
1308 [ # # ]: 0 : if (nix->custom_inb_sa)
1309 : 0 : dev->rx_offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
1310 : :
1311 : : /* Prepare rx cfg */
1312 : : rx_cfg = ROC_NIX_LF_RX_CFG_DIS_APAD;
1313 [ # # ]: 0 : if (dev->rx_offloads &
1314 : : (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM)) {
1315 : : rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_OL4;
1316 : : rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_IL4;
1317 : : }
1318 [ # # ]: 0 : rx_cfg |= (ROC_NIX_LF_RX_CFG_DROP_RE | ROC_NIX_LF_RX_CFG_L2_LEN_ERR |
1319 : : ROC_NIX_LF_RX_CFG_LEN_IL4 | ROC_NIX_LF_RX_CFG_LEN_IL3 |
1320 : : ROC_NIX_LF_RX_CFG_LEN_OL4 | ROC_NIX_LF_RX_CFG_LEN_OL3);
1321 : :
1322 : : rx_cfg &= (ROC_NIX_LF_RX_CFG_RX_ERROR_MASK);
1323 : :
1324 [ # # ]: 0 : if (roc_feature_nix_has_drop_re_mask())
1325 : 0 : rx_cfg |= (ROC_NIX_RE_CRC8_PCH | ROC_NIX_RE_MACSEC);
1326 : :
1327 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
1328 : 0 : rx_cfg |= ROC_NIX_LF_RX_CFG_IP6_UDP_OPT;
1329 : : /* Disable drop re if rx offload security is enabled and
1330 : : * platform does not support it.
1331 : : */
1332 [ # # ]: 0 : if (dev->ipsecd_drop_re_dis)
1333 : 0 : rx_cfg &= ~(ROC_NIX_LF_RX_CFG_DROP_RE);
1334 : : }
1335 : :
1336 : 0 : nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
1337 : 0 : nb_txq = RTE_MAX(data->nb_tx_queues, 1);
1338 : :
1339 [ # # ]: 0 : if (roc_nix_is_lbk(nix))
1340 : 0 : nix->enable_loop = eth_dev->data->dev_conf.lpbk_mode;
1341 : :
1342 : 0 : nix->tx_compl_ena = dev->tx_compl_ena;
1343 : :
1344 : : /* Alloc a nix lf */
1345 : 0 : rc = roc_nix_lf_alloc(nix, nb_rxq, nb_txq, rx_cfg);
1346 [ # # ]: 0 : if (rc) {
1347 : 0 : plt_err("Failed to init nix_lf rc=%d", rc);
1348 : 0 : goto fail_configure;
1349 : : }
1350 : :
1351 [ # # ]: 0 : if (!roc_nix_is_vf_or_sdp(nix)) {
1352 : : /* Sync same MAC address to CGX/RPM table */
1353 : 0 : rc = roc_nix_mac_addr_set(nix, dev->mac_addr);
1354 [ # # ]: 0 : if (rc) {
1355 : 0 : plt_err("Failed to set mac addr, rc=%d", rc);
1356 : 0 : goto fail_configure;
1357 : : }
1358 : : }
1359 : :
1360 : : /* Check if ptp is enable in PF owning this VF*/
1361 [ # # # # ]: 0 : if (!roc_nix_is_pf(nix) && (!roc_nix_is_sdp(nix)))
1362 : 0 : dev->ptp_en = roc_nix_ptp_is_enable(nix);
1363 : :
1364 : 0 : dev->npc.channel = roc_nix_get_base_chan(nix);
1365 : :
1366 : 0 : nb_rxq = data->nb_rx_queues;
1367 : 0 : nb_txq = data->nb_tx_queues;
1368 : : nb_cq = nb_rxq;
1369 [ # # ]: 0 : if (nix->tx_compl_ena)
1370 : 0 : nb_cq += nb_txq;
1371 : : rc = -ENOMEM;
1372 [ # # ]: 0 : if (nb_rxq) {
1373 : : /* Allocate memory for roc rq's and cq's */
1374 : 0 : qs = plt_zmalloc(sizeof(struct roc_nix_rq) * nb_rxq, 0);
1375 [ # # ]: 0 : if (!qs) {
1376 : 0 : plt_err("Failed to alloc rqs");
1377 : 0 : goto free_nix_lf;
1378 : : }
1379 : 0 : dev->rqs = qs;
1380 : : }
1381 : :
1382 [ # # ]: 0 : if (nb_txq) {
1383 : : /* Allocate memory for roc sq's */
1384 : 0 : qs = plt_zmalloc(sizeof(struct roc_nix_sq) * nb_txq, 0);
1385 [ # # ]: 0 : if (!qs) {
1386 : 0 : plt_err("Failed to alloc sqs");
1387 : 0 : goto free_nix_lf;
1388 : : }
1389 : 0 : dev->sqs = qs;
1390 : : }
1391 : :
1392 [ # # ]: 0 : if (nb_cq) {
1393 : 0 : qs = plt_zmalloc(sizeof(struct roc_nix_cq) * nb_cq, 0);
1394 [ # # ]: 0 : if (!qs) {
1395 : 0 : plt_err("Failed to alloc cqs");
1396 : 0 : goto free_nix_lf;
1397 : : }
1398 : 0 : dev->cqs = qs;
1399 : : }
1400 : :
1401 : : /* Re-enable NIX LF error interrupts */
1402 : 0 : roc_nix_err_intr_ena_dis(nix, true);
1403 : 0 : roc_nix_ras_intr_ena_dis(nix, true);
1404 : :
1405 [ # # ]: 0 : if (nix->rx_ptp_ena &&
1406 [ # # ]: 0 : dev->npc.switch_header_type == ROC_PRIV_FLAGS_HIGIG) {
1407 : 0 : plt_err("Both PTP and switch header enabled");
1408 : 0 : goto free_nix_lf;
1409 : : }
1410 : :
1411 : 0 : rc = roc_nix_switch_hdr_set(nix, dev->npc.switch_header_type,
1412 : 0 : dev->npc.pre_l2_size_offset,
1413 : 0 : dev->npc.pre_l2_size_offset_mask,
1414 : 0 : dev->npc.pre_l2_size_shift_dir);
1415 [ # # ]: 0 : if (rc) {
1416 : 0 : plt_err("Failed to enable switch type nix_lf rc=%d", rc);
1417 : 0 : goto free_nix_lf;
1418 : : }
1419 : :
1420 : : /* Setup LSO if needed */
1421 : 0 : rc = nix_lso_fmt_setup(dev);
1422 [ # # ]: 0 : if (rc) {
1423 : 0 : plt_err("Failed to setup nix lso format fields, rc=%d", rc);
1424 : 0 : goto free_nix_lf;
1425 : : }
1426 : :
1427 : : /* Configure RSS */
1428 : 0 : rc = nix_rss_default_setup(dev);
1429 [ # # ]: 0 : if (rc) {
1430 : 0 : plt_err("Failed to configure rss rc=%d", rc);
1431 : 0 : goto free_nix_lf;
1432 : : }
1433 : :
1434 : : /* Overwrite default RSS setup if requested by user */
1435 : 0 : rc = cnxk_nix_rss_hash_update(eth_dev, &conf->rx_adv_conf.rss_conf);
1436 [ # # ]: 0 : if (rc) {
1437 : 0 : plt_err("Failed to configure rss rc=%d", rc);
1438 : 0 : goto free_nix_lf;
1439 : : }
1440 : :
1441 : : /* Init the default TM scheduler hierarchy */
1442 : 0 : rc = roc_nix_tm_init(nix);
1443 [ # # ]: 0 : if (rc) {
1444 : 0 : plt_err("Failed to init traffic manager, rc=%d", rc);
1445 : 0 : goto free_nix_lf;
1446 : : }
1447 : :
1448 : 0 : rc = nix_ingress_policer_setup(dev);
1449 [ # # ]: 0 : if (rc) {
1450 : 0 : plt_err("Failed to setup ingress policer rc=%d", rc);
1451 : 0 : goto free_nix_lf;
1452 : : }
1453 : :
1454 : 0 : rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
1455 [ # # ]: 0 : if (rc) {
1456 : 0 : plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
1457 : 0 : goto tm_fini;
1458 : : }
1459 : :
1460 : : /* Register queue IRQs */
1461 : 0 : rc = roc_nix_register_queue_irqs(nix);
1462 [ # # ]: 0 : if (rc) {
1463 : 0 : plt_err("Failed to register queue interrupts rc=%d", rc);
1464 : 0 : goto tm_fini;
1465 : : }
1466 : :
1467 : : /* Register cq IRQs */
1468 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.rxq) {
1469 [ # # ]: 0 : if (eth_dev->data->nb_rx_queues > dev->nix.cints) {
1470 : 0 : plt_err("Rx interrupt cannot be enabled, rxq > %d",
1471 : : dev->nix.cints);
1472 : 0 : goto q_irq_fini;
1473 : : }
1474 : : /* Rx interrupt feature cannot work with vector mode because,
1475 : : * vector mode does not process packets unless min 4 pkts are
1476 : : * received, while cq interrupts are generated even for 1 pkt
1477 : : * in the CQ.
1478 : : */
1479 : 0 : dev->scalar_ena = true;
1480 : :
1481 : 0 : rc = roc_nix_register_cq_irqs(nix);
1482 [ # # ]: 0 : if (rc) {
1483 : 0 : plt_err("Failed to register CQ interrupts rc=%d", rc);
1484 : 0 : goto q_irq_fini;
1485 : : }
1486 : : }
1487 : :
1488 [ # # ]: 0 : if (roc_nix_is_lbk(nix))
1489 : 0 : goto skip_lbk_setup;
1490 : :
1491 : : /* Configure loop back mode */
1492 : 0 : rc = roc_nix_mac_loopback_enable(nix,
1493 : 0 : eth_dev->data->dev_conf.lpbk_mode);
1494 [ # # ]: 0 : if (rc) {
1495 : 0 : plt_err("Failed to configure cgx loop back mode rc=%d", rc);
1496 : 0 : goto cq_fini;
1497 : : }
1498 : :
1499 : 0 : skip_lbk_setup:
1500 : : /* Setup Inline security support */
1501 : 0 : rc = nix_security_setup(dev);
1502 [ # # ]: 0 : if (rc)
1503 : 0 : goto cq_fini;
1504 : :
1505 : : /* Init flow control configuration */
1506 [ # # ]: 0 : if (!roc_nix_is_esw(nix)) {
1507 : 0 : fc_cfg.type = ROC_NIX_FC_RXCHAN_CFG;
1508 : 0 : fc_cfg.rxchan_cfg.enable = true;
1509 : 0 : rc = roc_nix_fc_config_set(nix, &fc_cfg);
1510 [ # # ]: 0 : if (rc) {
1511 : 0 : plt_err("Failed to initialize flow control rc=%d", rc);
1512 : 0 : goto cq_fini;
1513 : : }
1514 : : }
1515 : :
1516 : : /* Update flow control configuration to PMD */
1517 : 0 : rc = nix_init_flow_ctrl_config(eth_dev);
1518 [ # # ]: 0 : if (rc) {
1519 : 0 : plt_err("Failed to initialize flow control rc=%d", rc);
1520 : 0 : goto cq_fini;
1521 : : }
1522 : :
1523 : : /*
1524 : : * Restore queue config when reconfigure followed by
1525 : : * reconfigure and no queue configure invoked from application case.
1526 : : */
1527 [ # # ]: 0 : if (dev->configured == 1) {
1528 : 0 : rc = nix_restore_queue_cfg(eth_dev);
1529 [ # # ]: 0 : if (rc)
1530 : 0 : goto sec_release;
1531 : : }
1532 : :
1533 : : /* Update the mac address */
1534 : 0 : ea = eth_dev->data->mac_addrs;
1535 [ # # ]: 0 : memcpy(ea, dev->mac_addr, RTE_ETHER_ADDR_LEN);
1536 [ # # ]: 0 : if (rte_is_zero_ether_addr(ea))
1537 : 0 : rte_eth_random_addr((uint8_t *)ea);
1538 : :
1539 : 0 : rte_ether_format_addr(ea_fmt, RTE_ETHER_ADDR_FMT_SIZE, ea);
1540 : :
1541 : 0 : plt_nix_dbg("Configured port%d mac=%s nb_rxq=%d nb_txq=%d"
1542 : : " rx_offloads=0x%" PRIx64 " tx_offloads=0x%" PRIx64 "",
1543 : : eth_dev->data->port_id, ea_fmt, nb_rxq, nb_txq,
1544 : : dev->rx_offloads, dev->tx_offloads);
1545 : :
1546 : : /* All good */
1547 : 0 : dev->configured = 1;
1548 : 0 : dev->nb_rxq = data->nb_rx_queues;
1549 : 0 : dev->nb_txq = data->nb_tx_queues;
1550 : 0 : return 0;
1551 : :
1552 : : sec_release:
1553 : 0 : rc |= nix_security_release(dev);
1554 : 0 : cq_fini:
1555 : 0 : roc_nix_unregister_cq_irqs(nix);
1556 : 0 : q_irq_fini:
1557 : 0 : roc_nix_unregister_queue_irqs(nix);
1558 : 0 : tm_fini:
1559 : 0 : roc_nix_tm_fini(nix);
1560 : 0 : free_nix_lf:
1561 : 0 : nix_free_queue_mem(dev);
1562 : 0 : rc |= nix_rxchan_cfg_disable(dev);
1563 : 0 : rc |= roc_nix_lf_free(nix);
1564 : 0 : fail_configure:
1565 : 0 : dev->configured = 0;
1566 : 0 : return rc;
1567 : : }
1568 : :
1569 : : int
1570 [ # # ]: 0 : cnxk_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
1571 : : {
1572 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1573 : : struct rte_eth_dev_data *data = eth_dev->data;
1574 : 0 : struct roc_nix_sq *sq = &dev->sqs[qid];
1575 : : int rc = -EINVAL;
1576 : :
1577 [ # # ]: 0 : if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
1578 : : return 0;
1579 : :
1580 : 0 : rc = roc_nix_sq_ena_dis(sq, true);
1581 [ # # ]: 0 : if (rc) {
1582 : 0 : plt_err("Failed to enable sq aura fc, txq=%u, rc=%d", qid, rc);
1583 : 0 : goto done;
1584 : : }
1585 : :
1586 : 0 : data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
1587 : : done:
1588 : : return rc;
1589 : : }
1590 : :
1591 : : int
1592 [ # # ]: 0 : cnxk_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
1593 : : {
1594 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1595 : : struct rte_eth_dev_data *data = eth_dev->data;
1596 : 0 : struct roc_nix_sq *sq = &dev->sqs[qid];
1597 : : int rc;
1598 : :
1599 [ # # ]: 0 : if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
1600 : : return 0;
1601 : :
1602 : 0 : rc = roc_nix_sq_ena_dis(sq, false);
1603 [ # # ]: 0 : if (rc) {
1604 : 0 : plt_err("Failed to disable sqb aura fc, txq=%u, rc=%d", qid,
1605 : : rc);
1606 : 0 : goto done;
1607 : : }
1608 : :
1609 : 0 : data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
1610 : : done:
1611 : : return rc;
1612 : : }
1613 : :
1614 : : static int
1615 [ # # ]: 0 : cnxk_nix_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
1616 : : {
1617 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1618 : : struct rte_eth_dev_data *data = eth_dev->data;
1619 : 0 : struct roc_nix_rq *rq = &dev->rqs[qid];
1620 : : int rc;
1621 : :
1622 [ # # ]: 0 : if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
1623 : : return 0;
1624 : :
1625 : 0 : rc = roc_nix_rq_ena_dis(rq, true);
1626 [ # # ]: 0 : if (rc) {
1627 : 0 : plt_err("Failed to enable rxq=%u, rc=%d", qid, rc);
1628 : 0 : goto done;
1629 : : }
1630 : :
1631 : 0 : data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
1632 : : done:
1633 : : return rc;
1634 : : }
1635 : :
1636 : : static int
1637 [ # # ]: 0 : cnxk_nix_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
1638 : : {
1639 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1640 : : struct rte_eth_dev_data *data = eth_dev->data;
1641 : 0 : struct roc_nix_rq *rq = &dev->rqs[qid];
1642 : : int rc;
1643 : :
1644 [ # # ]: 0 : if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
1645 : : return 0;
1646 : :
1647 : 0 : rc = roc_nix_rq_ena_dis(rq, false);
1648 [ # # ]: 0 : if (rc) {
1649 : 0 : plt_err("Failed to disable rxq=%u, rc=%d", qid, rc);
1650 : 0 : goto done;
1651 : : }
1652 : :
1653 : 0 : data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
1654 : : done:
1655 : : return rc;
1656 : : }
1657 : :
1658 : : static int
1659 [ # # ]: 0 : cnxk_nix_dev_stop(struct rte_eth_dev *eth_dev)
1660 : : {
1661 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1662 [ # # ]: 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
1663 : : struct rte_mbuf *rx_pkts[32];
1664 : : struct rte_eth_link link;
1665 : : int count, i, j, rc;
1666 : : void *rxq;
1667 : :
1668 : : /* In case of Inline IPSec, will need to avoid disabling the MCAM rules and NPC Rx
1669 : : * in this routine to continue processing of second pass inflight packets if any.
1670 : : * Drop of second pass packets will leak first pass buffers on some platforms
1671 : : * due to hardware limitations.
1672 : : */
1673 [ # # ]: 0 : if (roc_feature_nix_has_second_pass_drop() ||
1674 [ # # ]: 0 : !(dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)) {
1675 : : /* Disable all the NPC entries */
1676 : 0 : rc = roc_npc_mcam_enable_all_entries(&dev->npc, 0);
1677 [ # # ]: 0 : if (rc)
1678 : : return rc;
1679 : :
1680 : : /* Disable Rx via NPC */
1681 : 0 : roc_nix_npc_rx_ena_dis(&dev->nix, false);
1682 : : }
1683 : :
1684 : : /* Stop link change events */
1685 [ # # ]: 0 : if (!roc_nix_is_vf_or_sdp(&dev->nix))
1686 : 0 : roc_nix_mac_link_event_start_stop(&dev->nix, false);
1687 : :
1688 : 0 : roc_nix_inl_outb_soft_exp_poll_switch(&dev->nix, false);
1689 : :
1690 : : /* Stop inline device RQ first */
1691 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
1692 : 0 : roc_nix_inl_rq_ena_dis(&dev->nix, false);
1693 : :
1694 : : /* Stop rx queues and free up pkts pending */
1695 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1696 : 0 : rc = dev_ops->rx_queue_stop(eth_dev, i);
1697 [ # # ]: 0 : if (rc)
1698 : 0 : continue;
1699 : :
1700 : 0 : rxq = eth_dev->data->rx_queues[i];
1701 : 0 : count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
1702 [ # # ]: 0 : while (count) {
1703 [ # # ]: 0 : for (j = 0; j < count; j++)
1704 : 0 : rte_pktmbuf_free(rx_pkts[j]);
1705 : 0 : count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
1706 : : }
1707 : : }
1708 : :
1709 : : /* Stop tx queues */
1710 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1711 : 0 : dev_ops->tx_queue_stop(eth_dev, i);
1712 : :
1713 : : /* Bring down link status internally */
1714 : : memset(&link, 0, sizeof(link));
1715 : 0 : rte_eth_linkstatus_set(eth_dev, &link);
1716 : :
1717 : 0 : return 0;
1718 : : }
1719 : :
1720 : : int
1721 [ # # ]: 0 : cnxk_nix_dev_start(struct rte_eth_dev *eth_dev)
1722 : : {
1723 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1724 : : int rc, i;
1725 : :
1726 [ # # # # ]: 0 : if (eth_dev->data->nb_rx_queues != 0 && !dev->ptp_en) {
1727 : 0 : rc = nix_recalc_mtu(eth_dev);
1728 [ # # ]: 0 : if (rc)
1729 : : return rc;
1730 : : }
1731 : :
1732 : : /* Start rx queues */
1733 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1734 : 0 : rc = cnxk_nix_rx_queue_start(eth_dev, i);
1735 [ # # ]: 0 : if (rc)
1736 : 0 : return rc;
1737 : : }
1738 : :
1739 [ # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
1740 : 0 : rc = roc_nix_inl_rq_ena_dis(&dev->nix, true);
1741 [ # # ]: 0 : if (rc) {
1742 : 0 : plt_err("Failed to enable Inline device RQ, rc=%d", rc);
1743 : 0 : return rc;
1744 : : }
1745 : : }
1746 : :
1747 : : /* Start tx queues */
1748 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
1749 : 0 : rc = cnxk_nix_tx_queue_start(eth_dev, i);
1750 [ # # ]: 0 : if (rc)
1751 : 0 : return rc;
1752 : : }
1753 : :
1754 : : /* Update Flow control configuration */
1755 : 0 : rc = nix_update_flow_ctrl_config(eth_dev);
1756 [ # # ]: 0 : if (rc) {
1757 : 0 : plt_err("Failed to enable flow control. error code(%d)", rc);
1758 : 0 : return rc;
1759 : : }
1760 : :
1761 : : /* Enable Rx in NPC */
1762 : 0 : rc = roc_nix_npc_rx_ena_dis(&dev->nix, true);
1763 [ # # ]: 0 : if (rc) {
1764 : 0 : plt_err("Failed to enable NPC rx %d", rc);
1765 : 0 : return rc;
1766 : : }
1767 : :
1768 : 0 : rc = roc_npc_mcam_enable_all_entries(&dev->npc, 1);
1769 [ # # ]: 0 : if (rc) {
1770 : 0 : plt_err("Failed to enable NPC entries %d", rc);
1771 : 0 : return rc;
1772 : : }
1773 : :
1774 : 0 : cnxk_nix_toggle_flag_link_cfg(dev, true);
1775 : :
1776 : : /* Start link change events */
1777 [ # # ]: 0 : if (!roc_nix_is_vf_or_sdp(&dev->nix)) {
1778 : 0 : rc = roc_nix_mac_link_event_start_stop(&dev->nix, true);
1779 [ # # ]: 0 : if (rc) {
1780 : 0 : plt_err("Failed to start cgx link event %d", rc);
1781 : 0 : goto rx_disable;
1782 : : }
1783 : : }
1784 : :
1785 : : /* Enable PTP if it is requested by the user or already
1786 : : * enabled on PF owning this VF
1787 : : */
1788 [ # # ]: 0 : memset(&dev->tstamp, 0, sizeof(struct cnxk_timesync_info));
1789 [ # # # # ]: 0 : if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) || dev->ptp_en)
1790 : 0 : cnxk_eth_dev_ops.timesync_enable(eth_dev);
1791 : : else
1792 : 0 : cnxk_eth_dev_ops.timesync_disable(eth_dev);
1793 : :
1794 [ # # # # ]: 0 : if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP || dev->ptp_en) {
1795 : 0 : rc = rte_mbuf_dyn_rx_timestamp_register
1796 : : (&dev->tstamp.tstamp_dynfield_offset,
1797 : : &dev->tstamp.rx_tstamp_dynflag);
1798 [ # # ]: 0 : if (rc != 0) {
1799 : 0 : plt_err("Failed to register Rx timestamp field/flag");
1800 : 0 : goto rx_disable;
1801 : : }
1802 : : }
1803 : :
1804 : 0 : cnxk_nix_toggle_flag_link_cfg(dev, false);
1805 : :
1806 : 0 : roc_nix_inl_outb_soft_exp_poll_switch(&dev->nix, true);
1807 : :
1808 : 0 : return 0;
1809 : :
1810 : 0 : rx_disable:
1811 : 0 : roc_nix_npc_rx_ena_dis(&dev->nix, false);
1812 : 0 : cnxk_nix_toggle_flag_link_cfg(dev, false);
1813 : 0 : return rc;
1814 : : }
1815 : :
1816 : : static int cnxk_nix_dev_reset(struct rte_eth_dev *eth_dev);
1817 : : static int cnxk_nix_dev_close(struct rte_eth_dev *eth_dev);
1818 : :
1819 : : /* CNXK platform independent eth dev ops */
1820 : : struct eth_dev_ops cnxk_eth_dev_ops = {
1821 : : .mtu_set = cnxk_nix_mtu_set,
1822 : : .mac_addr_add = cnxk_nix_mac_addr_add,
1823 : : .mac_addr_remove = cnxk_nix_mac_addr_del,
1824 : : .mac_addr_set = cnxk_nix_mac_addr_set,
1825 : : .dev_infos_get = cnxk_nix_info_get,
1826 : : .link_update = cnxk_nix_link_update,
1827 : : .tx_queue_release = cnxk_nix_tx_queue_release,
1828 : : .rx_queue_release = cnxk_nix_rx_queue_release,
1829 : : .dev_stop = cnxk_nix_dev_stop,
1830 : : .dev_close = cnxk_nix_dev_close,
1831 : : .dev_reset = cnxk_nix_dev_reset,
1832 : : .tx_queue_start = cnxk_nix_tx_queue_start,
1833 : : .rx_queue_start = cnxk_nix_rx_queue_start,
1834 : : .rx_queue_stop = cnxk_nix_rx_queue_stop,
1835 : : .dev_supported_ptypes_get = cnxk_nix_supported_ptypes_get,
1836 : : .promiscuous_enable = cnxk_nix_promisc_enable,
1837 : : .promiscuous_disable = cnxk_nix_promisc_disable,
1838 : : .allmulticast_enable = cnxk_nix_allmulticast_enable,
1839 : : .allmulticast_disable = cnxk_nix_allmulticast_disable,
1840 : : .rx_burst_mode_get = cnxk_nix_rx_burst_mode_get,
1841 : : .tx_burst_mode_get = cnxk_nix_tx_burst_mode_get,
1842 : : .flow_ctrl_get = cnxk_nix_flow_ctrl_get,
1843 : : .flow_ctrl_set = cnxk_nix_flow_ctrl_set,
1844 : : .priority_flow_ctrl_queue_config =
1845 : : cnxk_nix_priority_flow_ctrl_queue_config,
1846 : : .priority_flow_ctrl_queue_info_get =
1847 : : cnxk_nix_priority_flow_ctrl_queue_info_get,
1848 : : .dev_set_link_up = cnxk_nix_set_link_up,
1849 : : .dev_set_link_down = cnxk_nix_set_link_down,
1850 : : .get_module_info = cnxk_nix_get_module_info,
1851 : : .get_module_eeprom = cnxk_nix_get_module_eeprom,
1852 : : .rx_queue_intr_enable = cnxk_nix_rx_queue_intr_enable,
1853 : : .rx_queue_intr_disable = cnxk_nix_rx_queue_intr_disable,
1854 : : .pool_ops_supported = cnxk_nix_pool_ops_supported,
1855 : : .queue_stats_mapping_set = cnxk_nix_queue_stats_mapping,
1856 : : .stats_get = cnxk_nix_stats_get,
1857 : : .stats_reset = cnxk_nix_stats_reset,
1858 : : .xstats_get = cnxk_nix_xstats_get,
1859 : : .xstats_get_names = cnxk_nix_xstats_get_names,
1860 : : .xstats_reset = cnxk_nix_xstats_reset,
1861 : : .xstats_get_by_id = cnxk_nix_xstats_get_by_id,
1862 : : .xstats_get_names_by_id = cnxk_nix_xstats_get_names_by_id,
1863 : : .fw_version_get = cnxk_nix_fw_version_get,
1864 : : .rxq_info_get = cnxk_nix_rxq_info_get,
1865 : : .txq_info_get = cnxk_nix_txq_info_get,
1866 : : .tx_done_cleanup = cnxk_nix_tx_done_cleanup,
1867 : : .flow_ops_get = cnxk_nix_flow_ops_get,
1868 : : .get_reg = cnxk_nix_dev_get_reg,
1869 : : .timesync_read_rx_timestamp = cnxk_nix_timesync_read_rx_timestamp,
1870 : : .timesync_read_tx_timestamp = cnxk_nix_timesync_read_tx_timestamp,
1871 : : .timesync_read_time = cnxk_nix_timesync_read_time,
1872 : : .timesync_write_time = cnxk_nix_timesync_write_time,
1873 : : .timesync_adjust_time = cnxk_nix_timesync_adjust_time,
1874 : : .read_clock = cnxk_nix_read_clock,
1875 : : .reta_update = cnxk_nix_reta_update,
1876 : : .reta_query = cnxk_nix_reta_query,
1877 : : .rss_hash_update = cnxk_nix_rss_hash_update,
1878 : : .rss_hash_conf_get = cnxk_nix_rss_hash_conf_get,
1879 : : .set_mc_addr_list = cnxk_nix_mc_addr_list_configure,
1880 : : .set_queue_rate_limit = cnxk_nix_tm_set_queue_rate_limit,
1881 : : .tm_ops_get = cnxk_nix_tm_ops_get,
1882 : : .mtr_ops_get = cnxk_nix_mtr_ops_get,
1883 : : .eth_dev_priv_dump = cnxk_nix_eth_dev_priv_dump,
1884 : : .cman_info_get = cnxk_nix_cman_info_get,
1885 : : .cman_config_init = cnxk_nix_cman_config_init,
1886 : : .cman_config_set = cnxk_nix_cman_config_set,
1887 : : .cman_config_get = cnxk_nix_cman_config_get,
1888 : : .eth_tx_descriptor_dump = cnxk_nix_tx_descriptor_dump,
1889 : : };
1890 : :
1891 : : void
1892 : 0 : cnxk_eth_dev_q_err_cb(struct roc_nix *nix, void *data)
1893 : : {
1894 : : struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
1895 : 0 : struct rte_eth_dev *eth_dev = dev->eth_dev;
1896 : :
1897 : : /* Set the flag and execute application callbacks */
1898 : 0 : rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_RESET, data);
1899 : 0 : }
1900 : :
1901 : : static int
1902 : 0 : cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
1903 : : {
1904 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1905 : : struct rte_security_ctx *sec_ctx;
1906 : 0 : struct roc_nix *nix = &dev->nix;
1907 : : struct rte_pci_device *pci_dev;
1908 : : int rc, max_entries, i;
1909 : :
1910 : 0 : eth_dev->dev_ops = &cnxk_eth_dev_ops;
1911 : 0 : eth_dev->rx_queue_count = cnxk_nix_rx_queue_count;
1912 : 0 : eth_dev->rx_descriptor_status = cnxk_nix_rx_descriptor_status;
1913 : 0 : eth_dev->tx_descriptor_status = cnxk_nix_tx_descriptor_status;
1914 : :
1915 : : /* Alloc security context */
1916 : 0 : sec_ctx = plt_zmalloc(sizeof(struct rte_security_ctx), 0);
1917 [ # # ]: 0 : if (!sec_ctx)
1918 : : return -ENOMEM;
1919 : 0 : sec_ctx->device = eth_dev;
1920 : 0 : sec_ctx->ops = &cnxk_eth_sec_ops;
1921 : 0 : sec_ctx->flags = RTE_SEC_CTX_F_FAST_SET_MDATA;
1922 : 0 : eth_dev->security_ctx = sec_ctx;
1923 : :
1924 : : /* For secondary processes, the primary has done all the work */
1925 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1926 : : return 0;
1927 : :
1928 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1929 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
1930 : :
1931 : : /* Parse devargs string */
1932 : 0 : rc = cnxk_ethdev_parse_devargs(eth_dev->device->devargs, dev);
1933 [ # # ]: 0 : if (rc) {
1934 : 0 : plt_err("Failed to parse devargs rc=%d", rc);
1935 : 0 : goto error;
1936 : : }
1937 : :
1938 : : /* Initialize base roc nix */
1939 : 0 : nix->pci_dev = pci_dev;
1940 : 0 : nix->hw_vlan_ins = true;
1941 : 0 : nix->port_id = eth_dev->data->port_id;
1942 : : /* For better performance set default VF root schedule weight */
1943 [ # # ]: 0 : nix->root_sched_weight = NIX_TM_DFLT_RR_WT;
1944 : :
1945 : : /* Skip meta aura for cn20k */
1946 [ # # # # ]: 0 : if (roc_feature_nix_has_own_meta_aura() && !roc_feature_nix_has_second_pass_drop())
1947 : 0 : nix->local_meta_aura_ena = true;
1948 : :
1949 : 0 : rc = roc_nix_dev_init(nix);
1950 [ # # ]: 0 : if (rc) {
1951 : 0 : plt_err("Failed to initialize roc nix rc=%d", rc);
1952 : 0 : goto error;
1953 : : }
1954 : :
1955 : : /* Register up msg callbacks */
1956 : 0 : roc_nix_mac_link_cb_register(nix, cnxk_eth_dev_link_status_cb);
1957 : :
1958 : : /* Register up msg callbacks */
1959 : 0 : roc_nix_mac_link_info_get_cb_register(nix,
1960 : : cnxk_eth_dev_link_status_get_cb);
1961 : :
1962 : : /* Register up msg callbacks */
1963 : 0 : roc_nix_q_err_cb_register(nix, cnxk_eth_dev_q_err_cb);
1964 : :
1965 : : /* Register callback for inline meta pool create */
1966 : 0 : roc_nix_inl_meta_pool_cb_register(cnxk_nix_inl_meta_pool_cb);
1967 : :
1968 : : /* Register callback for inline meta pool create 1:N pool:aura */
1969 : 0 : roc_nix_inl_custom_meta_pool_cb_register(cnxk_nix_inl_custom_meta_pool_cb);
1970 : :
1971 : 0 : dev->eth_dev = eth_dev;
1972 : 0 : dev->configured = 0;
1973 : 0 : dev->ptype_disable = 0;
1974 : 0 : dev->proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
1975 : :
1976 : 0 : TAILQ_INIT(&dev->inb.list);
1977 : 0 : TAILQ_INIT(&dev->outb.list);
1978 : : rte_spinlock_init(&dev->inb.lock);
1979 : : rte_spinlock_init(&dev->outb.lock);
1980 : :
1981 : : /* For vfs, returned max_entries will be 0. but to keep default mac
1982 : : * address, one entry must be allocated. so setting up to 1.
1983 : : */
1984 [ # # ]: 0 : if (roc_nix_is_vf_or_sdp(nix))
1985 : : max_entries = 1;
1986 : : else
1987 : 0 : max_entries = roc_nix_mac_max_entries_get(nix);
1988 : :
1989 [ # # ]: 0 : if (max_entries <= 0) {
1990 : 0 : plt_err("Failed to get max entries for mac addr");
1991 : : rc = -ENOTSUP;
1992 : 0 : goto dev_fini;
1993 : : }
1994 : :
1995 : 0 : eth_dev->data->mac_addrs =
1996 : 0 : rte_zmalloc("mac_addr", max_entries * RTE_ETHER_ADDR_LEN, 0);
1997 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1998 : 0 : plt_err("Failed to allocate memory for mac addr");
1999 : : rc = -ENOMEM;
2000 : 0 : goto dev_fini;
2001 : : }
2002 : :
2003 : 0 : dev->dmac_idx_map = rte_zmalloc("dmac_idx_map", max_entries * sizeof(int), 0);
2004 [ # # ]: 0 : if (dev->dmac_idx_map == NULL) {
2005 : 0 : plt_err("Failed to allocate memory for dmac idx map");
2006 : : rc = -ENOMEM;
2007 : 0 : goto free_mac_addrs;
2008 : : }
2009 : :
2010 : 0 : dev->dmac_addrs = rte_malloc("dmac_addrs", max_entries * RTE_ETHER_ADDR_LEN, 0);
2011 [ # # ]: 0 : if (dev->dmac_addrs == NULL) {
2012 : 0 : plt_err("Failed to allocate memory for dmac addresses");
2013 : : rc = -ENOMEM;
2014 : 0 : goto free_mac_addrs;
2015 : : }
2016 : :
2017 : : /* Reset to invalid */
2018 [ # # ]: 0 : for (i = 0; i < max_entries; i++)
2019 : 0 : dev->dmac_idx_map[i] = CNXK_NIX_DMAC_IDX_INVALID;
2020 : :
2021 : 0 : dev->max_mac_entries = max_entries;
2022 : 0 : dev->dmac_filter_count = 1;
2023 : :
2024 : : /* Get mac address */
2025 : 0 : rc = roc_nix_npc_mac_addr_get(nix, dev->mac_addr);
2026 [ # # ]: 0 : if (rc) {
2027 : 0 : plt_err("Failed to get mac addr, rc=%d", rc);
2028 : 0 : goto free_mac_addrs;
2029 : : }
2030 : :
2031 : : /* Update the mac address */
2032 : 0 : memcpy(eth_dev->data->mac_addrs, dev->mac_addr, RTE_ETHER_ADDR_LEN);
2033 : :
2034 : : /* Union of all capabilities supported by CNXK.
2035 : : * Platform specific capabilities will be
2036 : : * updated later.
2037 : : */
2038 : 0 : dev->rx_offload_capa = nix_get_rx_offload_capa(dev);
2039 : 0 : dev->tx_offload_capa = nix_get_tx_offload_capa(dev);
2040 : 0 : dev->speed_capa = nix_get_speed_capa(dev);
2041 : :
2042 : : /* Initialize roc npc */
2043 : 0 : dev->npc.roc_nix = nix;
2044 : 0 : rc = roc_npc_init(&dev->npc);
2045 [ # # ]: 0 : if (rc)
2046 : 0 : goto free_mac_addrs;
2047 : :
2048 [ # # # # ]: 0 : if (roc_feature_nix_has_macsec() && roc_mcs_is_supported()) {
2049 : 0 : rc = cnxk_mcs_dev_init(dev, 0);
2050 [ # # ]: 0 : if (rc) {
2051 : 0 : plt_err("Failed to init MCS");
2052 : 0 : goto free_mac_addrs;
2053 : : }
2054 : 0 : dev->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
2055 : 0 : dev->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
2056 : :
2057 : 0 : TAILQ_INIT(&dev->mcs_list);
2058 : : }
2059 : :
2060 : : /* Reserve a switch domain for eswitch device */
2061 [ # # ]: 0 : if (pci_dev->id.device_id == PCI_DEVID_CNXK_RVU_ESWITCH_VF) {
2062 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
2063 : 0 : rc = rte_eth_switch_domain_alloc(&dev->switch_domain_id);
2064 [ # # ]: 0 : if (rc) {
2065 : 0 : plt_err("Failed to alloc switch domain: %d", rc);
2066 : 0 : goto free_mac_addrs;
2067 : : }
2068 : : }
2069 : :
2070 : 0 : plt_nix_dbg("Port=%d pf=%d vf=%d ver=%s hwcap=0x%" PRIx64 " rxoffload_capa=0x%" PRIx64
2071 : : " txoffload_capa=0x%" PRIx64,
2072 : : eth_dev->data->port_id, roc_nix_get_pf(nix), roc_nix_get_vf(nix),
2073 : : CNXK_ETH_DEV_PMD_VERSION, dev->hwcap, dev->rx_offload_capa,
2074 : : dev->tx_offload_capa);
2075 : 0 : return 0;
2076 : :
2077 : 0 : free_mac_addrs:
2078 : 0 : rte_free(eth_dev->data->mac_addrs);
2079 : 0 : rte_free(dev->dmac_addrs);
2080 : 0 : dev->dmac_addrs = NULL;
2081 : 0 : rte_free(dev->dmac_idx_map);
2082 : 0 : dev_fini:
2083 : 0 : roc_nix_dev_fini(nix);
2084 : 0 : error:
2085 : 0 : plt_err("Failed to init nix eth_dev rc=%d", rc);
2086 : 0 : return rc;
2087 : : }
2088 : :
2089 : : static int
2090 : 0 : cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
2091 : : {
2092 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2093 : 0 : const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
2094 : : struct cnxk_pfc_cfg *pfc_cfg = &dev->pfc_cfg;
2095 : : struct cnxk_fc_cfg *fc_cfg = &dev->fc_cfg;
2096 : : struct rte_eth_pfc_queue_conf pfc_conf;
2097 : 0 : struct roc_nix *nix = &dev->nix;
2098 : : struct rte_eth_fc_conf fc_conf;
2099 : : int rc, i;
2100 : :
2101 : 0 : plt_free(eth_dev->security_ctx);
2102 : 0 : eth_dev->security_ctx = NULL;
2103 : :
2104 : : /* Nothing to be done for secondary processes */
2105 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2106 : : return 0;
2107 : :
2108 : : /* Disable switch hdr pkind */
2109 : 0 : roc_nix_switch_hdr_set(&dev->nix, 0, 0, 0, 0);
2110 : :
2111 : : /* Clear the flag since we are closing down */
2112 : 0 : dev->configured = 0;
2113 : :
2114 : : /* Disable all the NPC entries */
2115 : 0 : rc = roc_npc_mcam_enable_all_entries(&dev->npc, 0);
2116 [ # # ]: 0 : if (rc)
2117 : : return rc;
2118 : :
2119 : 0 : roc_nix_npc_rx_ena_dis(nix, false);
2120 : :
2121 : : /* Restore 802.3 Flow control configuration */
2122 : : memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
2123 : : memset(&fc_conf, 0, sizeof(struct rte_eth_fc_conf));
2124 [ # # ]: 0 : if (fc_cfg->rx_pause || fc_cfg->tx_pause) {
2125 : : fc_conf.mode = RTE_ETH_FC_NONE;
2126 : 0 : rc = cnxk_nix_flow_ctrl_set(eth_dev, &fc_conf);
2127 [ # # ]: 0 : if (rc < 0)
2128 : 0 : plt_err("Failed to reset control flow. error code(%d)",
2129 : : rc);
2130 : : }
2131 [ # # # # ]: 0 : if (pfc_cfg->rx_pause_en || pfc_cfg->tx_pause_en) {
2132 [ # # ]: 0 : for (i = 0; i < RTE_MAX(eth_dev->data->nb_rx_queues,
2133 : : eth_dev->data->nb_tx_queues);
2134 : 0 : i++) {
2135 : 0 : pfc_conf.mode = RTE_ETH_FC_NONE;
2136 : 0 : pfc_conf.rx_pause.tc = ROC_NIX_PFC_CLASS_INVALID;
2137 : 0 : pfc_conf.rx_pause.tx_qid = i;
2138 : 0 : pfc_conf.tx_pause.tc = ROC_NIX_PFC_CLASS_INVALID;
2139 : 0 : pfc_conf.tx_pause.rx_qid = i;
2140 : 0 : rc = cnxk_nix_priority_flow_ctrl_queue_config(eth_dev,
2141 : : &pfc_conf);
2142 [ # # ]: 0 : if (rc && rc != -ENOTSUP)
2143 : 0 : plt_err("Failed to reset PFC. error code(%d)", rc);
2144 : : }
2145 : : }
2146 : :
2147 : : /* Free switch domain ID reserved for eswitch device */
2148 [ # # # # ]: 0 : if ((eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) &&
2149 : 0 : rte_eth_switch_domain_free(dev->switch_domain_id))
2150 : 0 : plt_err("Failed to free switch domain");
2151 : :
2152 : : /* Disable and free rte_meter entries */
2153 : 0 : nix_meter_fini(dev);
2154 : :
2155 : : /* Disable and free rte_flow entries */
2156 : 0 : roc_npc_fini(&dev->npc);
2157 : :
2158 : : /* Disable link status events */
2159 : 0 : roc_nix_mac_link_event_start_stop(nix, false);
2160 : :
2161 : : /* Unregister the link update op, this is required to stop VFs from
2162 : : * receiving link status updates on exit path.
2163 : : */
2164 : 0 : roc_nix_mac_link_cb_unregister(nix);
2165 : :
2166 : : /* Free up SQs */
2167 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
2168 : 0 : dev_ops->tx_queue_release(eth_dev, i);
2169 : 0 : eth_dev->data->tx_queues[i] = NULL;
2170 : : }
2171 : 0 : eth_dev->data->nb_tx_queues = 0;
2172 : :
2173 : : /* Free up RQ's and CQ's */
2174 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
2175 : 0 : dev_ops->rx_queue_release(eth_dev, i);
2176 : 0 : eth_dev->data->rx_queues[i] = NULL;
2177 : : }
2178 [ # # ]: 0 : eth_dev->data->nb_rx_queues = 0;
2179 : :
2180 [ # # # # ]: 0 : if (roc_feature_nix_has_macsec() && roc_mcs_is_supported())
2181 : 0 : cnxk_mcs_dev_fini(dev);
2182 : :
2183 : : /* Free security resources */
2184 : 0 : nix_security_release(dev);
2185 : :
2186 : : /* Free tm resources */
2187 : 0 : roc_nix_tm_fini(nix);
2188 : :
2189 : : /* Unregister queue irqs */
2190 : 0 : roc_nix_unregister_queue_irqs(nix);
2191 : :
2192 : : /* Unregister cq irqs */
2193 [ # # ]: 0 : if (eth_dev->data->dev_conf.intr_conf.rxq)
2194 : 0 : roc_nix_unregister_cq_irqs(nix);
2195 : :
2196 : : /* Free ROC RQ's, SQ's and CQ's memory */
2197 : 0 : nix_free_queue_mem(dev);
2198 : :
2199 : : /* free nix bpid */
2200 : 0 : rc = nix_rxchan_cfg_disable(dev);
2201 [ # # ]: 0 : if (rc)
2202 : 0 : plt_err("Failed to free nix bpid, rc=%d", rc);
2203 : :
2204 : : /* Free nix lf resources */
2205 : 0 : rc = roc_nix_lf_free(nix);
2206 [ # # ]: 0 : if (rc)
2207 : 0 : plt_err("Failed to free nix lf, rc=%d", rc);
2208 : :
2209 : 0 : rte_free(dev->dmac_idx_map);
2210 : 0 : dev->dmac_idx_map = NULL;
2211 : :
2212 : 0 : rte_free(dev->dmac_addrs);
2213 : 0 : dev->dmac_addrs = NULL;
2214 : :
2215 : 0 : rte_free(eth_dev->data->mac_addrs);
2216 : 0 : eth_dev->data->mac_addrs = NULL;
2217 : :
2218 : 0 : rc = roc_nix_dev_fini(nix);
2219 : : /* Can be freed later by PMD if NPA LF is in use */
2220 [ # # ]: 0 : if (rc == -EAGAIN) {
2221 [ # # ]: 0 : if (!reset)
2222 : 0 : eth_dev->data->dev_private = NULL;
2223 : 0 : return 0;
2224 [ # # ]: 0 : } else if (rc) {
2225 : 0 : plt_err("Failed in nix dev fini, rc=%d", rc);
2226 : : }
2227 : :
2228 : : return rc;
2229 : : }
2230 : :
2231 : : static int
2232 : 0 : cnxk_nix_dev_close(struct rte_eth_dev *eth_dev)
2233 : : {
2234 : 0 : cnxk_eth_dev_uninit(eth_dev, false);
2235 : 0 : return 0;
2236 : : }
2237 : :
2238 : : static int
2239 : 0 : cnxk_nix_dev_reset(struct rte_eth_dev *eth_dev)
2240 : : {
2241 : : int rc;
2242 : :
2243 : 0 : rc = cnxk_eth_dev_uninit(eth_dev, true);
2244 [ # # ]: 0 : if (rc)
2245 : : return rc;
2246 : :
2247 : 0 : return cnxk_eth_dev_init(eth_dev);
2248 : : }
2249 : :
2250 : : int
2251 : 0 : cnxk_nix_remove(struct rte_pci_device *pci_dev)
2252 : : {
2253 : : struct rte_eth_dev *eth_dev;
2254 : : struct roc_nix *nix;
2255 : : int rc = -EINVAL;
2256 : :
2257 : 0 : eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
2258 [ # # ]: 0 : if (eth_dev) {
2259 : : /* Cleanup eth dev */
2260 : 0 : rc = cnxk_eth_dev_uninit(eth_dev, false);
2261 [ # # ]: 0 : if (rc)
2262 : : return rc;
2263 : :
2264 : 0 : rte_eth_dev_release_port(eth_dev);
2265 : : }
2266 : :
2267 : : /* Nothing to be done for secondary processes */
2268 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2269 : : return 0;
2270 : :
2271 : : /* Check if this device is hosting common resource */
2272 : 0 : nix = roc_idev_npa_nix_get();
2273 [ # # # # ]: 0 : if (!nix || nix->pci_dev != pci_dev)
2274 : : return 0;
2275 : :
2276 : : /* Try nix fini now */
2277 : 0 : rc = roc_nix_dev_fini(nix);
2278 [ # # ]: 0 : if (rc == -EAGAIN) {
2279 : 0 : plt_info("%s: common resource in use by other devices",
2280 : : pci_dev->name);
2281 : 0 : goto exit;
2282 [ # # ]: 0 : } else if (rc) {
2283 : 0 : plt_err("Failed in nix dev fini, rc=%d", rc);
2284 : 0 : goto exit;
2285 : : }
2286 : :
2287 : : /* Free device pointer as rte_ethdev does not have it anymore */
2288 : 0 : rte_free(nix);
2289 : : exit:
2290 : : return rc;
2291 : : }
2292 : :
2293 : : int
2294 : 0 : cnxk_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
2295 : : {
2296 : : int rc;
2297 : :
2298 : : RTE_SET_USED(pci_drv);
2299 : :
2300 : 0 : rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct cnxk_eth_dev),
2301 : : cnxk_eth_dev_init);
2302 : :
2303 : : /* On error on secondary, recheck if port exists in primary or
2304 : : * in mid of detach state.
2305 : : */
2306 [ # # # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
2307 [ # # ]: 0 : if (!rte_eth_dev_allocated(pci_dev->device.name))
2308 : 0 : return 0;
2309 : : return rc;
2310 : : }
|