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 : : #include <stdalign.h>
8 : : #include <stdbool.h>
9 : :
10 : : #include <dev_driver.h>
11 : : #include <ethdev_driver.h>
12 : : #include <ethdev_pci.h>
13 : : #include <rte_malloc.h>
14 : : #include <rte_cycles.h>
15 : : #include <rte_alarm.h>
16 : : #include <rte_kvargs.h>
17 : : #include <rte_vect.h>
18 : :
19 : : #include "bnxt.h"
20 : : #include "bnxt_filter.h"
21 : : #include "bnxt_hwrm.h"
22 : : #include "bnxt_irq.h"
23 : : #include "bnxt_reps.h"
24 : : #include "bnxt_ring.h"
25 : : #include "bnxt_rxq.h"
26 : : #include "bnxt_rxr.h"
27 : : #include "bnxt_stats.h"
28 : : #include "bnxt_txq.h"
29 : : #include "bnxt_txr.h"
30 : : #include "bnxt_vnic.h"
31 : : #include "hsi_struct_def_dpdk.h"
32 : : #include "bnxt_nvm_defs.h"
33 : : #include "bnxt_tf_common.h"
34 : : #include "ulp_flow_db.h"
35 : : #include "rte_pmd_bnxt.h"
36 : : #include "bnxt_ulp_utils.h"
37 : :
38 : : #define DRV_MODULE_NAME "bnxt"
39 : : static const char bnxt_version[] =
40 : : "Broadcom NetXtreme driver " DRV_MODULE_NAME;
41 : :
42 : : /*
43 : : * The set of PCI devices this driver supports
44 : : */
45 : : static const struct rte_pci_id bnxt_pci_id_map[] = {
46 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
47 : : BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
48 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
49 : : BROADCOM_DEV_ID_STRATUS_NIC_VF2) },
50 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_STRATUS_NIC) },
51 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_VF) },
52 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57304_VF) },
53 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_NS2) },
54 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57406_VF) },
55 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57407_MF) },
56 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5741X_VF) },
57 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5731X_VF) },
58 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_MF) },
59 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412) },
60 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414) },
61 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_RJ45) },
62 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_RJ45) },
63 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57412_MF) },
64 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_RJ45) },
65 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57417_SFP) },
66 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_SFP) },
67 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57317_SFP) },
68 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57414_MF) },
69 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57416_MF) },
70 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802) },
71 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58804) },
72 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58808) },
73 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58802_VF) },
74 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
75 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
76 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
77 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
78 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
79 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF1) },
80 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF1) },
81 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF1) },
82 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508_MF2) },
83 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504_MF2) },
84 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502_MF2) },
85 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58812) },
86 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58814) },
87 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58818) },
88 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_58818_VF) },
89 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57608) },
90 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57604) },
91 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57602) },
92 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57601) },
93 : : { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_5760X_VF) },
94 : : { .vendor_id = 0, /* sentinel */ },
95 : : };
96 : :
97 : : #define BNXT_DEVARG_FLOW_XSTAT "flow-xstat"
98 : : #define BNXT_DEVARG_MAX_NUM_KFLOWS "max-num-kflows"
99 : : #define BNXT_DEVARG_REPRESENTOR "representor"
100 : : #define BNXT_DEVARG_REP_BASED_PF "rep-based-pf"
101 : : #define BNXT_DEVARG_REP_IS_PF "rep-is-pf"
102 : : #define BNXT_DEVARG_REP_Q_R2F "rep-q-r2f"
103 : : #define BNXT_DEVARG_REP_Q_F2R "rep-q-f2r"
104 : : #define BNXT_DEVARG_REP_FC_R2F "rep-fc-r2f"
105 : : #define BNXT_DEVARG_REP_FC_F2R "rep-fc-f2r"
106 : : #define BNXT_DEVARG_APP_ID "app-id"
107 : : #define BNXT_DEVARG_IEEE_1588 "ieee-1588"
108 : : #define BNXT_DEVARG_CQE_MODE "cqe-mode"
109 : : #define BNXT_DEVARG_MPC "mpc"
110 : :
111 : : static const char *const bnxt_dev_args[] = {
112 : : BNXT_DEVARG_REPRESENTOR,
113 : : BNXT_DEVARG_FLOW_XSTAT,
114 : : BNXT_DEVARG_MAX_NUM_KFLOWS,
115 : : BNXT_DEVARG_REP_BASED_PF,
116 : : BNXT_DEVARG_REP_IS_PF,
117 : : BNXT_DEVARG_REP_Q_R2F,
118 : : BNXT_DEVARG_REP_Q_F2R,
119 : : BNXT_DEVARG_REP_FC_R2F,
120 : : BNXT_DEVARG_REP_FC_F2R,
121 : : BNXT_DEVARG_APP_ID,
122 : : BNXT_DEVARG_IEEE_1588,
123 : : BNXT_DEVARG_CQE_MODE,
124 : : BNXT_DEVARG_MPC,
125 : : NULL
126 : : };
127 : :
128 : : #define BNXT_SPEEDS_SUPP_SPEED_LANES (RTE_ETH_LINK_SPEED_10G | \
129 : : RTE_ETH_LINK_SPEED_25G | \
130 : : RTE_ETH_LINK_SPEED_40G | \
131 : : RTE_ETH_LINK_SPEED_50G | \
132 : : RTE_ETH_LINK_SPEED_100G | \
133 : : RTE_ETH_LINK_SPEED_200G | \
134 : : RTE_ETH_LINK_SPEED_400G)
135 : :
136 : : static const struct rte_eth_speed_lanes_capa speed_lanes_capa_tbl[] = {
137 : : { RTE_ETH_SPEED_NUM_10G, RTE_BIT32(1) },
138 : : { RTE_ETH_SPEED_NUM_25G, RTE_BIT32(1) },
139 : : { RTE_ETH_SPEED_NUM_40G, RTE_BIT32(4) },
140 : : { RTE_ETH_SPEED_NUM_50G, RTE_BIT32(1) | RTE_BIT32(2) },
141 : : { RTE_ETH_SPEED_NUM_100G, RTE_BIT32(1) | RTE_BIT32(2) | RTE_BIT32(4) },
142 : : { RTE_ETH_SPEED_NUM_200G, RTE_BIT32(2) | RTE_BIT32(4) },
143 : : { RTE_ETH_SPEED_NUM_400G, RTE_BIT32(4) | RTE_BIT32(8) },
144 : : };
145 : :
146 : : /*
147 : : * cqe-mode = an non-negative 8-bit number
148 : : */
149 : : #define BNXT_DEVARG_CQE_MODE_INVALID(val) ((val) > 1)
150 : :
151 : : /*
152 : : * mpc = an non-negative 8-bit number
153 : : */
154 : : #define BNXT_DEVARG_MPC_INVALID(val) ((val) > 1)
155 : :
156 : : /*
157 : : * app-id = an non-negative 8-bit number
158 : : */
159 : : #define BNXT_DEVARG_APP_ID_INVALID(val) ((val) > 255)
160 : :
161 : : /*
162 : : * ieee-1588 = an non-negative 8-bit number
163 : : */
164 : : #define BNXT_DEVARG_IEEE_1588_INVALID(val) ((val) > 255)
165 : :
166 : : /*
167 : : * flow_xstat == false to disable the feature
168 : : * flow_xstat == true to enable the feature
169 : : */
170 : : #define BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat) ((flow_xstat) > 1)
171 : :
172 : : /*
173 : : * rep_is_pf == false to indicate VF representor
174 : : * rep_is_pf == true to indicate PF representor
175 : : */
176 : : #define BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf) ((rep_is_pf) > 1)
177 : :
178 : : /*
179 : : * rep_based_pf == Physical index of the PF
180 : : */
181 : : #define BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf) ((rep_based_pf) > 15)
182 : : /*
183 : : * rep_q_r2f == Logical COS Queue index for the rep to endpoint direction
184 : : */
185 : : #define BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f) ((rep_q_r2f) > 3)
186 : :
187 : : /*
188 : : * rep_q_f2r == Logical COS Queue index for the endpoint to rep direction
189 : : */
190 : : #define BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r) ((rep_q_f2r) > 3)
191 : :
192 : : /*
193 : : * rep_fc_r2f == Flow control for the representor to endpoint direction
194 : : */
195 : : #define BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f) ((rep_fc_r2f) > 1)
196 : :
197 : : /*
198 : : * rep_fc_f2r == Flow control for the endpoint to representor direction
199 : : */
200 : : #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r) ((rep_fc_f2r) > 1)
201 : :
202 : : int bnxt_cfa_code_dynfield_offset = -1;
203 : : unsigned long mpc;
204 : :
205 : : /*
206 : : * max_num_kflows must be >= 32
207 : : * and must be a power-of-2 supported value
208 : : * return: 1 -> invalid
209 : : * 0 -> valid
210 : : */
211 : : static int bnxt_devarg_max_num_kflow_invalid(uint16_t max_num_kflows)
212 : : {
213 [ # # ]: 0 : if (max_num_kflows < 32 || !rte_is_power_of_2(max_num_kflows))
214 : : return 1;
215 : : return 0;
216 : : }
217 : :
218 : : static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
219 : : static int bnxt_dev_uninit(struct rte_eth_dev *eth_dev);
220 : : static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev);
221 : : static int bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev);
222 : : static void bnxt_cancel_fw_health_check(struct bnxt *bp);
223 : : static int bnxt_restore_vlan_filters(struct bnxt *bp);
224 : : static void bnxt_dev_recover(void *arg);
225 : : static void bnxt_free_error_recovery_info(struct bnxt *bp);
226 : : static void bnxt_free_rep_info(struct bnxt *bp);
227 : : static int bnxt_check_fw_ready(struct bnxt *bp);
228 : : static bool bnxt_enable_ulp(struct bnxt *bp);
229 : :
230 : 0 : int is_bnxt_in_error(struct bnxt *bp)
231 : : {
232 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FATAL_ERROR)
233 : : return -EIO;
234 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_RESET)
235 : 0 : return -EBUSY;
236 : :
237 : : return 0;
238 : : }
239 : :
240 : : /***********************/
241 : :
242 : : /*
243 : : * High level utility functions
244 : : */
245 : :
246 : 0 : uint16_t bnxt_rss_ctxts(const struct bnxt *bp)
247 : : {
248 : 0 : unsigned int num_rss_rings = RTE_MIN(bp->rx_nr_rings,
249 : : BNXT_RSS_TBL_SIZE_P5);
250 : :
251 [ # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp))
252 : : return 1;
253 : :
254 : 0 : return RTE_ALIGN_MUL_CEIL(num_rss_rings,
255 : 0 : BNXT_RSS_ENTRIES_PER_CTX_P5) /
256 : : BNXT_RSS_ENTRIES_PER_CTX_P5;
257 : : }
258 : :
259 : 0 : uint16_t bnxt_rss_hash_tbl_size(const struct bnxt *bp)
260 : : {
261 [ # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp))
262 : : return HW_HASH_INDEX_SIZE;
263 : :
264 : 0 : return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_P5;
265 : : }
266 : :
267 : : static void bnxt_free_parent_info(struct bnxt *bp)
268 : : {
269 : 0 : rte_free(bp->parent);
270 : 0 : bp->parent = NULL;
271 : : }
272 : :
273 : : static void bnxt_free_pf_info(struct bnxt *bp)
274 : : {
275 : 0 : rte_free(bp->pf);
276 : 0 : bp->pf = NULL;
277 : : }
278 : :
279 : : static void bnxt_free_link_info(struct bnxt *bp)
280 : : {
281 : 0 : rte_free(bp->link_info);
282 : 0 : bp->link_info = NULL;
283 : : }
284 : :
285 : : static void bnxt_free_leds_info(struct bnxt *bp)
286 : : {
287 : 0 : if (BNXT_VF(bp))
288 : : return;
289 : :
290 : 0 : rte_free(bp->leds);
291 : 0 : bp->leds = NULL;
292 : : }
293 : :
294 : : static void bnxt_free_flow_stats_info(struct bnxt *bp)
295 : : {
296 : 0 : rte_free(bp->flow_stat);
297 : 0 : bp->flow_stat = NULL;
298 : : }
299 : :
300 : : static void bnxt_free_cos_queues(struct bnxt *bp)
301 : : {
302 : 0 : rte_free(bp->rx_cos_queue);
303 : 0 : bp->rx_cos_queue = NULL;
304 : 0 : rte_free(bp->tx_cos_queue);
305 : 0 : bp->tx_cos_queue = NULL;
306 : : }
307 : :
308 : 0 : static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
309 : : {
310 : 0 : bnxt_free_filter_mem(bp);
311 : 0 : bnxt_free_vnic_attributes(bp);
312 : 0 : bnxt_free_vnic_mem(bp);
313 : :
314 : : /* tx/rx rings are configured as part of *_queue_setup callbacks.
315 : : * If the number of rings change across fw update,
316 : : * we don't have much choice except to warn the user.
317 : : */
318 [ # # ]: 0 : if (!reconfig) {
319 : 0 : bnxt_free_stats(bp);
320 : 0 : bnxt_free_tx_rings(bp);
321 : 0 : bnxt_free_rx_rings(bp);
322 : : }
323 : 0 : bnxt_free_async_cp_ring(bp);
324 : 0 : bnxt_free_rxtx_nq_ring(bp);
325 : :
326 : 0 : rte_free(bp->grp_info);
327 : 0 : bp->grp_info = NULL;
328 : 0 : }
329 : :
330 : : static int bnxt_alloc_parent_info(struct bnxt *bp)
331 : : {
332 : 0 : bp->parent = rte_zmalloc("bnxt_parent_info",
333 : : sizeof(struct bnxt_parent_info), 0);
334 [ # # ]: 0 : if (bp->parent == NULL)
335 : : return -ENOMEM;
336 : :
337 : : return 0;
338 : : }
339 : :
340 : : static int bnxt_alloc_pf_info(struct bnxt *bp)
341 : : {
342 : 0 : bp->pf = rte_zmalloc("bnxt_pf_info", sizeof(struct bnxt_pf_info), 0);
343 [ # # ]: 0 : if (bp->pf == NULL)
344 : : return -ENOMEM;
345 : :
346 : : return 0;
347 : : }
348 : :
349 : : static int bnxt_alloc_link_info(struct bnxt *bp)
350 : : {
351 : 0 : bp->link_info =
352 : 0 : rte_zmalloc("bnxt_link_info", sizeof(struct bnxt_link_info), 0);
353 [ # # ]: 0 : if (bp->link_info == NULL)
354 : : return -ENOMEM;
355 : :
356 : : return 0;
357 : : }
358 : :
359 : 0 : static int bnxt_alloc_leds_info(struct bnxt *bp)
360 : : {
361 [ # # ]: 0 : if (BNXT_VF(bp))
362 : : return 0;
363 : :
364 : 0 : bp->leds = rte_zmalloc("bnxt_leds",
365 : : BNXT_MAX_LED * sizeof(struct bnxt_led_info),
366 : : 0);
367 [ # # ]: 0 : if (bp->leds == NULL)
368 : 0 : return -ENOMEM;
369 : :
370 : : return 0;
371 : : }
372 : :
373 : 0 : static int bnxt_alloc_cos_queues(struct bnxt *bp)
374 : : {
375 : 0 : bp->rx_cos_queue =
376 : 0 : rte_zmalloc("bnxt_rx_cosq",
377 : : BNXT_COS_QUEUE_COUNT *
378 : : sizeof(struct bnxt_cos_queue_info),
379 : : 0);
380 [ # # ]: 0 : if (bp->rx_cos_queue == NULL)
381 : : return -ENOMEM;
382 : :
383 : 0 : bp->tx_cos_queue =
384 : 0 : rte_zmalloc("bnxt_tx_cosq",
385 : : BNXT_COS_QUEUE_COUNT *
386 : : sizeof(struct bnxt_cos_queue_info),
387 : : 0);
388 [ # # ]: 0 : if (bp->tx_cos_queue == NULL)
389 : 0 : return -ENOMEM;
390 : :
391 : : return 0;
392 : : }
393 : :
394 : : static int bnxt_alloc_flow_stats_info(struct bnxt *bp)
395 : : {
396 : 0 : bp->flow_stat = rte_zmalloc("bnxt_flow_xstat",
397 : : sizeof(struct bnxt_flow_stat_info), 0);
398 [ # # ]: 0 : if (bp->flow_stat == NULL)
399 : : return -ENOMEM;
400 : :
401 : : return 0;
402 : : }
403 : :
404 : 0 : static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
405 : : {
406 : : int rc;
407 : :
408 : 0 : rc = bnxt_alloc_ring_grps(bp);
409 [ # # ]: 0 : if (rc)
410 : 0 : goto alloc_mem_err;
411 : :
412 : 0 : rc = bnxt_alloc_async_ring_struct(bp);
413 [ # # ]: 0 : if (rc)
414 : 0 : goto alloc_mem_err;
415 : :
416 : 0 : rc = bnxt_alloc_vnic_mem(bp);
417 [ # # ]: 0 : if (rc)
418 : 0 : goto alloc_mem_err;
419 : :
420 : 0 : rc = bnxt_alloc_vnic_attributes(bp, reconfig);
421 [ # # ]: 0 : if (rc)
422 : 0 : goto alloc_mem_err;
423 : :
424 : 0 : rc = bnxt_alloc_filter_mem(bp);
425 [ # # ]: 0 : if (rc)
426 : 0 : goto alloc_mem_err;
427 : :
428 : 0 : rc = bnxt_alloc_async_cp_ring(bp);
429 [ # # ]: 0 : if (rc)
430 : 0 : goto alloc_mem_err;
431 : :
432 : 0 : rc = bnxt_alloc_rxtx_nq_ring(bp);
433 [ # # ]: 0 : if (rc)
434 : 0 : goto alloc_mem_err;
435 : :
436 [ # # ]: 0 : if (BNXT_FLOW_XSTATS_EN(bp)) {
437 : : rc = bnxt_alloc_flow_stats_info(bp);
438 : : if (rc)
439 : 0 : goto alloc_mem_err;
440 : : }
441 : :
442 : : return 0;
443 : :
444 : 0 : alloc_mem_err:
445 : 0 : bnxt_free_mem(bp, reconfig);
446 : 0 : return rc;
447 : : }
448 : :
449 : 0 : static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)
450 : : {
451 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
452 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
453 : 0 : uint64_t rx_offloads = dev_conf->rxmode.offloads;
454 : : struct bnxt_rx_queue *rxq;
455 : : unsigned int j;
456 : : int rc;
457 : :
458 : 0 : rc = bnxt_vnic_grp_alloc(bp, vnic);
459 [ # # ]: 0 : if (rc)
460 : 0 : goto err_out;
461 : :
462 : 0 : PMD_DRV_LOG_LINE(DEBUG, "vnic[%d] = %p vnic->fw_grp_ids = %p",
463 : : vnic_id, vnic, vnic->fw_grp_ids);
464 : :
465 : : /* populate the fw group table */
466 : 0 : bnxt_vnic_ring_grp_populate(bp, vnic);
467 : 0 : bnxt_vnic_rules_init(vnic);
468 : :
469 : 0 : rc = bnxt_hwrm_vnic_alloc(bp, vnic);
470 [ # # ]: 0 : if (rc)
471 : 0 : goto err_out;
472 : :
473 : : /* Alloc RSS context only if RSS mode is enabled */
474 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS) {
475 : 0 : int j, nr_ctxs = bnxt_rss_ctxts(bp);
476 : :
477 : : /* RSS table size in P5 is 512.
478 : : * Cap max Rx rings to same value
479 : : */
480 [ # # ]: 0 : if (bp->rx_nr_rings > BNXT_RSS_TBL_SIZE_P5) {
481 : 0 : PMD_DRV_LOG_LINE(ERR, "RxQ cnt %d > reta_size %d",
482 : : bp->rx_nr_rings, BNXT_RSS_TBL_SIZE_P5);
483 : 0 : goto err_out;
484 : : }
485 : :
486 : : rc = 0;
487 [ # # ]: 0 : for (j = 0; j < nr_ctxs; j++) {
488 : 0 : rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, j);
489 [ # # ]: 0 : if (rc)
490 : : break;
491 : : }
492 [ # # ]: 0 : if (rc) {
493 : 0 : PMD_DRV_LOG_LINE(ERR,
494 : : "HWRM vnic %d ctx %d alloc failure rc: %x",
495 : : vnic_id, j, rc);
496 : 0 : goto err_out;
497 : : }
498 : 0 : vnic->num_lb_ctxts = nr_ctxs;
499 : : }
500 : :
501 : : /*
502 : : * Firmware sets pf pair in default vnic cfg. If the VLAN strip
503 : : * setting is not available at this time, it will not be
504 : : * configured correctly in the CFA.
505 : : */
506 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
507 : 0 : vnic->vlan_strip = true;
508 : : else
509 : 0 : vnic->vlan_strip = false;
510 : :
511 : 0 : rc = bnxt_hwrm_vnic_cfg(bp, vnic);
512 [ # # ]: 0 : if (rc)
513 : 0 : goto err_out;
514 : :
515 : 0 : rc = bnxt_set_hwrm_vnic_filters(bp, vnic);
516 [ # # ]: 0 : if (rc)
517 : 0 : goto err_out;
518 : :
519 [ # # ]: 0 : for (j = 0; j < bp->rx_num_qs_per_vnic; j++) {
520 : 0 : rxq = bp->eth_dev->data->rx_queues[j];
521 : :
522 : 0 : PMD_DRV_LOG_LINE(DEBUG,
523 : : "rxq[%d]->vnic=%p vnic->fw_grp_ids=%p",
524 : : j, rxq->vnic, rxq->vnic->fw_grp_ids);
525 : :
526 [ # # # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp) && rxq->rx_deferred_start)
527 : 0 : vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
528 : : }
529 : :
530 : 0 : PMD_DRV_LOG_LINE(DEBUG, "vnic->rx_queue_cnt = %d", vnic->rx_queue_cnt);
531 : :
532 : 0 : rc = bnxt_vnic_rss_configure(bp, vnic);
533 [ # # ]: 0 : if (rc)
534 : 0 : goto err_out;
535 : :
536 : 0 : bnxt_hwrm_vnic_plcmode_cfg(bp, vnic);
537 : :
538 : 0 : rc = bnxt_hwrm_vnic_tpa_cfg(bp, vnic,
539 : : (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) ?
540 : 0 : true : false);
541 [ # # ]: 0 : if (rc)
542 : 0 : goto err_out;
543 : :
544 : : return 0;
545 : 0 : err_out:
546 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM vnic %d cfg failure rc: %x",
547 : : vnic_id, rc);
548 : 0 : return rc;
549 : : }
550 : :
551 : 0 : static int bnxt_register_fc_ctx_mem(struct bnxt *bp)
552 : : {
553 : : int rc = 0;
554 : :
555 : 0 : rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_in_tbl.dma,
556 : 0 : &bp->flow_stat->rx_fc_in_tbl.ctx_id);
557 [ # # ]: 0 : if (rc)
558 : : return rc;
559 : :
560 : 0 : PMD_DRV_LOG_LINE(DEBUG,
561 : : "rx_fc_in_tbl.va = %p rx_fc_in_tbl.dma = %p"
562 : : " rx_fc_in_tbl.ctx_id = %d",
563 : : bp->flow_stat->rx_fc_in_tbl.va,
564 : : (void *)((uintptr_t)bp->flow_stat->rx_fc_in_tbl.dma),
565 : : bp->flow_stat->rx_fc_in_tbl.ctx_id);
566 : :
567 : 0 : rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->rx_fc_out_tbl.dma,
568 : 0 : &bp->flow_stat->rx_fc_out_tbl.ctx_id);
569 [ # # ]: 0 : if (rc)
570 : : return rc;
571 : :
572 : 0 : PMD_DRV_LOG_LINE(DEBUG,
573 : : "rx_fc_out_tbl.va = %p rx_fc_out_tbl.dma = %p"
574 : : " rx_fc_out_tbl.ctx_id = %d",
575 : : bp->flow_stat->rx_fc_out_tbl.va,
576 : : (void *)((uintptr_t)bp->flow_stat->rx_fc_out_tbl.dma),
577 : : bp->flow_stat->rx_fc_out_tbl.ctx_id);
578 : :
579 : 0 : rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_in_tbl.dma,
580 : 0 : &bp->flow_stat->tx_fc_in_tbl.ctx_id);
581 [ # # ]: 0 : if (rc)
582 : : return rc;
583 : :
584 : 0 : PMD_DRV_LOG_LINE(DEBUG,
585 : : "tx_fc_in_tbl.va = %p tx_fc_in_tbl.dma = %p"
586 : : " tx_fc_in_tbl.ctx_id = %d",
587 : : bp->flow_stat->tx_fc_in_tbl.va,
588 : : (void *)((uintptr_t)bp->flow_stat->tx_fc_in_tbl.dma),
589 : : bp->flow_stat->tx_fc_in_tbl.ctx_id);
590 : :
591 : 0 : rc = bnxt_hwrm_ctx_rgtr(bp, bp->flow_stat->tx_fc_out_tbl.dma,
592 : 0 : &bp->flow_stat->tx_fc_out_tbl.ctx_id);
593 [ # # ]: 0 : if (rc)
594 : : return rc;
595 : :
596 : 0 : PMD_DRV_LOG_LINE(DEBUG,
597 : : "tx_fc_out_tbl.va = %p tx_fc_out_tbl.dma = %p"
598 : : " tx_fc_out_tbl.ctx_id = %d",
599 : : bp->flow_stat->tx_fc_out_tbl.va,
600 : : (void *)((uintptr_t)bp->flow_stat->tx_fc_out_tbl.dma),
601 : : bp->flow_stat->tx_fc_out_tbl.ctx_id);
602 : :
603 : 0 : memset(bp->flow_stat->rx_fc_out_tbl.va,
604 : : 0,
605 : 0 : bp->flow_stat->rx_fc_out_tbl.size);
606 : 0 : rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
607 : : CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
608 : 0 : bp->flow_stat->rx_fc_out_tbl.ctx_id,
609 : 0 : bp->flow_stat->max_fc,
610 : : true);
611 [ # # ]: 0 : if (rc)
612 : : return rc;
613 : :
614 : 0 : memset(bp->flow_stat->tx_fc_out_tbl.va,
615 : : 0,
616 : 0 : bp->flow_stat->tx_fc_out_tbl.size);
617 : 0 : rc = bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
618 : : CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
619 : 0 : bp->flow_stat->tx_fc_out_tbl.ctx_id,
620 : 0 : bp->flow_stat->max_fc,
621 : : true);
622 : :
623 : 0 : return rc;
624 : : }
625 : :
626 : 0 : static int bnxt_alloc_ctx_mem_buf(struct bnxt *bp, char *type, size_t size,
627 : : struct bnxt_ctx_mem_buf_info *ctx)
628 : : {
629 [ # # ]: 0 : if (!ctx)
630 : : return -EINVAL;
631 : :
632 : 0 : ctx->va = rte_zmalloc_socket(type, size, 0,
633 : 0 : bp->eth_dev->device->numa_node);
634 [ # # ]: 0 : if (ctx->va == NULL)
635 : : return -ENOMEM;
636 : 0 : rte_mem_lock_page(ctx->va);
637 : 0 : ctx->size = size;
638 : 0 : ctx->dma = rte_mem_virt2iova(ctx->va);
639 [ # # ]: 0 : if (ctx->dma == RTE_BAD_IOVA)
640 : 0 : return -ENOMEM;
641 : :
642 : : return 0;
643 : : }
644 : :
645 : 0 : static int bnxt_init_fc_ctx_mem(struct bnxt *bp)
646 : : {
647 : 0 : struct rte_pci_device *pdev = bp->pdev;
648 : : char type[RTE_MEMZONE_NAMESIZE];
649 : : uint16_t max_fc;
650 : : int rc = 0;
651 : :
652 : 0 : max_fc = bp->flow_stat->max_fc;
653 : :
654 : 0 : sprintf(type, "bnxt_rx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
655 : 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
656 : : /* 4 bytes for each counter-id */
657 : 0 : rc = bnxt_alloc_ctx_mem_buf(bp, type,
658 : 0 : max_fc * 4,
659 : 0 : &bp->flow_stat->rx_fc_in_tbl);
660 [ # # ]: 0 : if (rc)
661 : : return rc;
662 : :
663 : 0 : sprintf(type, "bnxt_rx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
664 : 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
665 : : /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
666 : 0 : rc = bnxt_alloc_ctx_mem_buf(bp, type,
667 : 0 : max_fc * 16,
668 : 0 : &bp->flow_stat->rx_fc_out_tbl);
669 [ # # ]: 0 : if (rc)
670 : : return rc;
671 : :
672 : 0 : sprintf(type, "bnxt_tx_fc_in_" PCI_PRI_FMT, pdev->addr.domain,
673 : 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
674 : : /* 4 bytes for each counter-id */
675 : 0 : rc = bnxt_alloc_ctx_mem_buf(bp, type,
676 : : max_fc * 4,
677 : 0 : &bp->flow_stat->tx_fc_in_tbl);
678 [ # # ]: 0 : if (rc)
679 : : return rc;
680 : :
681 : 0 : sprintf(type, "bnxt_tx_fc_out_" PCI_PRI_FMT, pdev->addr.domain,
682 : 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
683 : : /* 16 bytes for each counter - 8 bytes pkt_count, 8 bytes byte_count */
684 : 0 : rc = bnxt_alloc_ctx_mem_buf(bp, type,
685 : : max_fc * 16,
686 : 0 : &bp->flow_stat->tx_fc_out_tbl);
687 [ # # ]: 0 : if (rc)
688 : : return rc;
689 : :
690 : 0 : rc = bnxt_register_fc_ctx_mem(bp);
691 : :
692 : 0 : return rc;
693 : : }
694 : :
695 : 0 : static int bnxt_init_ctx_mem(struct bnxt *bp)
696 : : {
697 : : int rc = 0;
698 : :
699 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_ADV_FLOW_COUNTERS) ||
700 [ # # # # ]: 0 : !(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) ||
701 : : !BNXT_FLOW_XSTATS_EN(bp))
702 : : return 0;
703 : :
704 : 0 : rc = bnxt_hwrm_cfa_counter_qcaps(bp, &bp->flow_stat->max_fc);
705 [ # # ]: 0 : if (rc)
706 : : return rc;
707 : :
708 : 0 : rc = bnxt_init_fc_ctx_mem(bp);
709 : :
710 : 0 : return rc;
711 : : }
712 : :
713 : : static inline bool bnxt_force_link_config(struct bnxt *bp)
714 : : {
715 : 0 : uint16_t subsystem_device_id = bp->pdev->id.subsystem_device_id;
716 : :
717 [ # # # # ]: 0 : switch (subsystem_device_id) {
718 : : case BROADCOM_DEV_957508_N2100:
719 : : case BROADCOM_DEV_957414_N225:
720 : : return true;
721 : : default:
722 : : return false;
723 : : }
724 : : }
725 : :
726 : 0 : static int bnxt_validate_speed_lanes_change(struct bnxt *bp)
727 : : {
728 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
729 : : struct rte_eth_link *link = &bp->eth_dev->data->dev_link;
730 : : uint32_t curr_speed_bit;
731 : : int rc;
732 : :
733 : : /* Check if speed x lanes combo is supported */
734 [ # # ]: 0 : if (dev_conf->link_speeds) {
735 : 0 : rc = bnxt_parse_eth_link_speed_v2(bp);
736 [ # # ]: 0 : if (rc == 0)
737 : : return -EINVAL;
738 : : }
739 : :
740 : : /* convert to speedbit flag */
741 : 0 : curr_speed_bit = rte_eth_speed_bitflag((uint32_t)link->link_speed, 1);
742 : :
743 : : /* check if speed and lanes have changed */
744 [ # # ]: 0 : if (dev_conf->link_speeds != curr_speed_bit ||
745 [ # # ]: 0 : bp->link_info->active_lanes != bp->link_info->pmd_speed_lanes)
746 : 0 : return 1;
747 : :
748 : : return 0;
749 : : }
750 : :
751 : 0 : static int bnxt_update_phy_setting(struct bnxt *bp)
752 : : {
753 : : struct rte_eth_link new;
754 : : int rc, rc1 = 0;
755 : :
756 : 0 : rc = bnxt_get_hwrm_link_config(bp, &new);
757 [ # # ]: 0 : if (rc) {
758 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to get link settings");
759 : 0 : return rc;
760 : : }
761 : :
762 : : /* Validate speeds2 requirements */
763 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp)) {
# # # # ]
764 : 0 : rc1 = bnxt_validate_speed_lanes_change(bp);
765 [ # # ]: 0 : if (rc1 == -EINVAL) {
766 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to set correct lanes");
767 : 0 : return rc1;
768 : : }
769 : : }
770 : :
771 : : /*
772 : : * Device is not obliged link down in certain scenarios, even
773 : : * when forced. When FW does not allow any user other than BMC
774 : : * to shutdown the port, bnxt_get_hwrm_link_config() call always
775 : : * returns link up. Force phy update always in that case.
776 : : */
777 [ # # # # ]: 0 : if (!new.link_status || bnxt_force_link_config(bp) || rc1 == 1) {
778 : 0 : rc = bnxt_set_hwrm_link_config(bp, true);
779 [ # # ]: 0 : if (rc) {
780 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to update PHY settings");
781 : 0 : return rc;
782 : : }
783 : : }
784 : :
785 : : return rc;
786 : : }
787 : :
788 : 0 : static void bnxt_free_prev_ring_stats(struct bnxt *bp)
789 : : {
790 : : /* tpa v2 devices use ext variant local struct */
791 [ # # # # ]: 0 : if (BNXT_TPA_V2_P7(bp)) {
792 : 0 : rte_free(bp->prev_rx_ring_stats_ext);
793 : 0 : rte_free(bp->prev_tx_ring_stats_ext);
794 : 0 : bp->prev_rx_ring_stats_ext = NULL;
795 : 0 : bp->prev_tx_ring_stats_ext = NULL;
796 : 0 : return;
797 : : }
798 : 0 : rte_free(bp->prev_rx_ring_stats);
799 : 0 : rte_free(bp->prev_tx_ring_stats);
800 : 0 : bp->prev_rx_ring_stats = NULL;
801 : 0 : bp->prev_tx_ring_stats = NULL;
802 : : }
803 : :
804 : 0 : static int bnxt_alloc_prev_ring_ext_stats(struct bnxt *bp)
805 : : {
806 : 0 : bp->prev_rx_ring_stats_ext = rte_zmalloc("bnxt_prev_rx_ring_stats_ext",
807 : : sizeof(struct bnxt_ring_stats_ext) *
808 : 0 : bp->rx_cp_nr_rings,
809 : : 0);
810 [ # # ]: 0 : if (bp->prev_rx_ring_stats_ext == NULL)
811 : : return -ENOMEM;
812 : :
813 : 0 : bp->prev_tx_ring_stats_ext = rte_zmalloc("bnxt_prev_tx_ring_stats_ext",
814 : : sizeof(struct bnxt_ring_stats_ext) *
815 : 0 : bp->tx_cp_nr_rings,
816 : : 0);
817 : :
818 [ # # # # ]: 0 : if (bp->tx_cp_nr_rings > 0 && bp->prev_tx_ring_stats_ext == NULL)
819 : 0 : goto error;
820 : :
821 : : return 0;
822 : :
823 : : error:
824 : 0 : bnxt_free_prev_ring_stats(bp);
825 : 0 : return -ENOMEM;
826 : : }
827 : :
828 : 0 : static int bnxt_alloc_prev_ring_stats(struct bnxt *bp)
829 : : {
830 [ # # # # ]: 0 : if (BNXT_TPA_V2_P7(bp))
831 : 0 : return bnxt_alloc_prev_ring_ext_stats(bp);
832 : :
833 : 0 : bp->prev_rx_ring_stats = rte_zmalloc("bnxt_prev_rx_ring_stats",
834 : : sizeof(struct bnxt_ring_stats) *
835 : 0 : bp->rx_cp_nr_rings,
836 : : 0);
837 [ # # ]: 0 : if (bp->prev_rx_ring_stats == NULL)
838 : : return -ENOMEM;
839 : :
840 : 0 : bp->prev_tx_ring_stats = rte_zmalloc("bnxt_prev_tx_ring_stats",
841 : : sizeof(struct bnxt_ring_stats) *
842 : 0 : bp->tx_cp_nr_rings,
843 : : 0);
844 [ # # # # ]: 0 : if (bp->tx_cp_nr_rings > 0 && bp->prev_tx_ring_stats == NULL)
845 : 0 : goto error;
846 : :
847 : : return 0;
848 : :
849 : : error:
850 : 0 : bnxt_free_prev_ring_stats(bp);
851 : 0 : return -ENOMEM;
852 : : }
853 : :
854 : 0 : static int bnxt_start_nic(struct bnxt *bp)
855 : : {
856 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(bp->eth_dev);
857 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
858 : : uint32_t intr_vector = 0;
859 : : uint32_t queue_id, base = BNXT_MISC_VEC_ID;
860 : : uint32_t vec = BNXT_MISC_VEC_ID;
861 : : unsigned int i, j;
862 : : int rc;
863 : :
864 [ # # ]: 0 : if (bp->eth_dev->data->mtu > RTE_ETHER_MTU)
865 : 0 : bp->flags |= BNXT_FLAG_JUMBO;
866 : : else
867 : 0 : bp->flags &= ~BNXT_FLAG_JUMBO;
868 : :
869 : : /* P5 does not support ring groups.
870 : : * But we will use the array to save RSS context IDs.
871 : : */
872 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp))
873 : 0 : bp->max_ring_grps = BNXT_MAX_RSS_CTXTS_P5;
874 : :
875 : 0 : rc = bnxt_vnic_queue_db_init(bp);
876 [ # # ]: 0 : if (rc) {
877 : 0 : PMD_DRV_LOG_LINE(ERR, "could not allocate vnic db");
878 : 0 : goto err_out;
879 : : }
880 : :
881 : 0 : rc = bnxt_alloc_hwrm_rings(bp);
882 [ # # ]: 0 : if (rc) {
883 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM ring alloc failure rc: %x", rc);
884 : 0 : goto err_out;
885 : : }
886 : :
887 : 0 : rc = bnxt_alloc_all_hwrm_ring_grps(bp);
888 [ # # ]: 0 : if (rc) {
889 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM ring grp alloc failure: %x", rc);
890 : 0 : goto err_out;
891 : : }
892 : :
893 [ # # ]: 0 : if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
894 : 0 : goto skip_cosq_cfg;
895 : :
896 [ # # ]: 0 : for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
897 [ # # ]: 0 : if (bp->rx_cos_queue[i].id != 0xff) {
898 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
899 : :
900 [ # # ]: 0 : if (!vnic) {
901 : 0 : PMD_DRV_LOG_LINE(ERR,
902 : : "Num pools more than FW profile");
903 : : rc = -EINVAL;
904 : 0 : goto err_out;
905 : : }
906 : 0 : vnic->cos_queue_id = bp->rx_cos_queue[i].id;
907 : 0 : bp->rx_cosq_cnt++;
908 : : }
909 : : }
910 : :
911 : 0 : skip_cosq_cfg:
912 : 0 : rc = bnxt_mq_rx_configure(bp);
913 [ # # ]: 0 : if (rc) {
914 : 0 : PMD_DRV_LOG_LINE(ERR, "MQ mode configure failure rc: %x", rc);
915 : 0 : goto err_out;
916 : : }
917 : :
918 [ # # ]: 0 : for (j = 0; j < bp->rx_nr_rings; j++) {
919 : 0 : struct bnxt_rx_queue *rxq = bp->rx_queues[j];
920 : :
921 [ # # ]: 0 : if (!rxq->rx_deferred_start) {
922 [ # # ]: 0 : __rte_assume(j < RTE_MAX_QUEUES_PER_PORT);
923 : 0 : bp->eth_dev->data->rx_queue_state[j] =
924 : : RTE_ETH_QUEUE_STATE_STARTED;
925 : 0 : rxq->rx_started = true;
926 : : }
927 : : }
928 : :
929 : : /* setup the default vnic details*/
930 : 0 : bnxt_vnic_queue_db_update_dlft_vnic(bp);
931 : :
932 : : /* VNIC configuration */
933 [ # # ]: 0 : for (i = 0; i < bp->nr_vnics; i++) {
934 : 0 : rc = bnxt_setup_one_vnic(bp, i);
935 [ # # ]: 0 : if (rc)
936 : 0 : goto err_out;
937 : : }
938 : :
939 [ # # ]: 0 : for (j = 0; j < bp->tx_nr_rings; j++) {
940 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[j];
941 : :
942 [ # # ]: 0 : if (!txq->tx_deferred_start) {
943 [ # # ]: 0 : __rte_assume(j < RTE_MAX_QUEUES_PER_PORT);
944 : 0 : bp->eth_dev->data->tx_queue_state[j] =
945 : : RTE_ETH_QUEUE_STATE_STARTED;
946 : 0 : txq->tx_started = true;
947 : : }
948 : : }
949 : :
950 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, &bp->vnic_info[0], 0, NULL);
951 [ # # ]: 0 : if (rc) {
952 : 0 : PMD_DRV_LOG_LINE(ERR,
953 : : "HWRM cfa l2 rx mask failure rc: %x", rc);
954 : 0 : goto err_out;
955 : : }
956 : :
957 : : /* check and configure queue intr-vector mapping */
958 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
959 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(bp->eth_dev).active) &&
960 [ # # ]: 0 : bp->eth_dev->data->dev_conf.intr_conf.rxq != 0) {
961 : 0 : intr_vector = bp->eth_dev->data->nb_rx_queues;
962 : 0 : PMD_DRV_LOG_LINE(DEBUG, "intr_vector = %d", intr_vector);
963 [ # # ]: 0 : if (intr_vector > bp->rx_cp_nr_rings) {
964 : 0 : PMD_DRV_LOG_LINE(ERR, "At most %d intr queues supported",
965 : : bp->rx_cp_nr_rings);
966 : 0 : return -ENOTSUP;
967 : : }
968 : 0 : rc = rte_intr_efd_enable(intr_handle, intr_vector);
969 [ # # ]: 0 : if (rc)
970 : : return rc;
971 : : }
972 : :
973 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
974 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
975 : 0 : bp->eth_dev->data->nb_rx_queues)) {
976 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate %d rx_queues"
977 : : " intr_vec", bp->eth_dev->data->nb_rx_queues);
978 : : rc = -ENOMEM;
979 : 0 : goto err_out;
980 : : }
981 : 0 : PMD_DRV_LOG_LINE(DEBUG, "intr_handle->nb_efd = %d "
982 : : "intr_handle->max_intr = %d",
983 : : rte_intr_nb_efd_get(intr_handle),
984 : : rte_intr_max_intr_get(intr_handle));
985 [ # # ]: 0 : for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
986 : 0 : queue_id++) {
987 : 0 : rte_intr_vec_list_index_set(intr_handle,
988 : 0 : queue_id, vec + BNXT_RX_VEC_START);
989 : 0 : if (vec < base + rte_intr_nb_efd_get(intr_handle)
990 [ # # ]: 0 : - 1)
991 : : vec++;
992 : : }
993 : : }
994 : :
995 : : /* enable uio/vfio intr/eventfd mapping */
996 : 0 : rc = rte_intr_enable(intr_handle);
997 : : #ifndef RTE_EXEC_ENV_FREEBSD
998 : : /* In FreeBSD OS, nic_uio driver does not support interrupts */
999 [ # # ]: 0 : if (rc)
1000 : 0 : goto err_out;
1001 : : #endif
1002 : :
1003 : 0 : rc = bnxt_update_phy_setting(bp);
1004 [ # # ]: 0 : if (rc)
1005 : 0 : goto err_out;
1006 : :
1007 : 0 : bp->mark_table = rte_zmalloc("bnxt_mark_table", BNXT_MARK_TABLE_SZ, 0);
1008 [ # # ]: 0 : if (!bp->mark_table)
1009 : 0 : PMD_DRV_LOG_LINE(ERR, "Allocation of mark table failed");
1010 : :
1011 : : return 0;
1012 : :
1013 : 0 : err_out:
1014 : : /* Some of the error status returned by FW may not be from errno.h */
1015 [ # # ]: 0 : if (rc > 0)
1016 : : rc = -EIO;
1017 : :
1018 : : return rc;
1019 : : }
1020 : :
1021 : 0 : static int bnxt_shutdown_nic(struct bnxt *bp)
1022 : : {
1023 : 0 : bnxt_free_all_hwrm_resources(bp);
1024 : 0 : bnxt_free_all_filters(bp);
1025 : 0 : bnxt_free_all_vnics(bp);
1026 : 0 : bnxt_vnic_queue_db_deinit(bp);
1027 : 0 : return 0;
1028 : : }
1029 : :
1030 : : /*
1031 : : * Device configuration and status function
1032 : : */
1033 : :
1034 : 0 : static uint32_t bnxt_get_speed_capabilities_v2(struct bnxt *bp)
1035 : : {
1036 : : uint32_t link_speed = 0;
1037 : : uint32_t speed_capa = 0;
1038 : :
1039 [ # # ]: 0 : if (bp->link_info == NULL)
1040 : : return 0;
1041 : :
1042 : 0 : link_speed = bp->link_info->support_speeds2;
1043 : :
1044 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_1GB)
1045 : : speed_capa |= RTE_ETH_LINK_SPEED_1G;
1046 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_10GB)
1047 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_10G;
1048 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_25GB)
1049 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_25G;
1050 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_40GB)
1051 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_40G;
1052 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_50GB)
1053 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_50G;
1054 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB)
1055 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
1056 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_50GB_PAM4_56)
1057 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_50G;
1058 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB_PAM4_56)
1059 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
1060 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_200GB_PAM4_56)
1061 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_200G;
1062 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_400GB_PAM4_56)
1063 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_400G;
1064 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_100GB_PAM4_112)
1065 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
1066 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_200GB_PAM4_112)
1067 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_200G;
1068 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS2_400GB_PAM4_112)
1069 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_400G;
1070 : :
1071 [ # # ]: 0 : if (bp->link_info->auto_mode ==
1072 : : HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
1073 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_FIXED;
1074 : :
1075 : : return speed_capa;
1076 : : }
1077 : :
1078 : 0 : uint32_t bnxt_get_speed_capabilities(struct bnxt *bp)
1079 : : {
1080 : : uint32_t pam4_link_speed = 0;
1081 : : uint32_t link_speed = 0;
1082 : : uint32_t speed_capa = 0;
1083 : :
1084 [ # # ]: 0 : if (bp->link_info == NULL)
1085 : : return 0;
1086 : :
1087 : : /* P7 uses speeds_v2 */
1088 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp))
# # ]
1089 : 0 : return bnxt_get_speed_capabilities_v2(bp);
1090 : :
1091 : 0 : link_speed = bp->link_info->support_speeds;
1092 : :
1093 : : /* If PAM4 is configured, use PAM4 supported speed */
1094 : 0 : if (bp->link_info->support_pam4_speeds > 0)
1095 : : pam4_link_speed = bp->link_info->support_pam4_speeds;
1096 : :
1097 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB)
1098 : : speed_capa |= RTE_ETH_LINK_SPEED_100M;
1099 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100MBHD)
1100 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100M_HD;
1101 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_1GB)
1102 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_1G;
1103 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_2_5GB)
1104 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_2_5G;
1105 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_10GB)
1106 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_10G;
1107 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_20GB)
1108 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_20G;
1109 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_25GB)
1110 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_25G;
1111 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_40GB)
1112 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_40G;
1113 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB)
1114 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_50G;
1115 [ # # ]: 0 : if (link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB)
1116 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
1117 [ # # ]: 0 : if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_50G)
1118 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_50G;
1119 [ # # ]: 0 : if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_100G)
1120 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_100G;
1121 [ # # ]: 0 : if (pam4_link_speed & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_200G)
1122 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_200G;
1123 : :
1124 [ # # ]: 0 : if (bp->link_info->auto_mode ==
1125 : : HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE)
1126 : 0 : speed_capa |= RTE_ETH_LINK_SPEED_FIXED;
1127 : :
1128 : : return speed_capa;
1129 : : }
1130 : :
1131 : 0 : uint64_t bnxt_eth_rss_support(struct bnxt *bp)
1132 : : {
1133 : : uint64_t support;
1134 : :
1135 : : support = RTE_ETH_RSS_IPV4 |
1136 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP |
1137 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP |
1138 : : RTE_ETH_RSS_IPV6 |
1139 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP |
1140 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP |
1141 : : RTE_ETH_RSS_LEVEL_MASK;
1142 : :
1143 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_CHKSM_MODE)
1144 : : support |= RTE_ETH_RSS_IPV4_CHKSUM |
1145 : : RTE_ETH_RSS_L4_CHKSUM;
1146 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE)
1147 : 0 : support |= RTE_ETH_RSS_IPV6_FLOW_LABEL;
1148 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI_CAP)
1149 : 0 : support |= RTE_ETH_RSS_AH;
1150 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI_CAP)
1151 : 0 : support |= RTE_ETH_RSS_ESP;
1152 : :
1153 : 0 : return support;
1154 : : }
1155 : :
1156 : 0 : static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
1157 : : struct rte_eth_dev_info *dev_info)
1158 : : {
1159 : 0 : struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
1160 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1161 : : uint16_t max_vnics, i, j, vpool, vrxq;
1162 : : unsigned int max_rx_rings;
1163 : : int rc;
1164 : :
1165 : 0 : rc = is_bnxt_in_error(bp);
1166 [ # # ]: 0 : if (rc)
1167 : : return rc;
1168 : :
1169 : : /* MAC Specifics */
1170 : 0 : dev_info->max_mac_addrs = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
1171 : 0 : dev_info->max_hash_mac_addrs = 0;
1172 : :
1173 : : /* PF/VF specifics */
1174 [ # # ]: 0 : if (BNXT_PF(bp))
1175 : 0 : dev_info->max_vfs = pdev->max_vfs;
1176 : :
1177 : 0 : max_rx_rings = bnxt_max_rings(bp);
1178 : : /* For the sake of symmetry, max_rx_queues = max_tx_queues */
1179 : 0 : dev_info->max_rx_queues = max_rx_rings;
1180 : 0 : dev_info->max_tx_queues = max_rx_rings;
1181 : 0 : dev_info->reta_size = bnxt_rss_hash_tbl_size(bp);
1182 : 0 : dev_info->hash_key_size = HW_HASH_KEY_SIZE;
1183 : 0 : max_vnics = bp->max_vnics;
1184 : :
1185 : : /* MTU specifics */
1186 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
1187 : 0 : dev_info->max_mtu = BNXT_MAX_MTU;
1188 : :
1189 : : /* Fast path specifics */
1190 : 0 : dev_info->min_rx_bufsize = 1;
1191 : 0 : dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
1192 : :
1193 : 0 : dev_info->rx_offload_capa = bnxt_get_rx_port_offloads(bp);
1194 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
1195 : 0 : dev_info->tx_offload_capa = bnxt_get_tx_port_offloads(bp) |
1196 : 0 : dev_info->tx_queue_offload_capa;
1197 : 0 : dev_info->flow_type_rss_offloads = bnxt_eth_rss_support(bp);
1198 : 0 : dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT) |
1199 : : RTE_ETH_HASH_ALGO_CAPA_MASK(TOEPLITZ);
1200 : :
1201 [ # # ]: 0 : if (BNXT_CHIP_P7(bp))
1202 : 0 : dev_info->rss_algo_capa |= RTE_ETH_HASH_ALGO_CAPA_MASK(SIMPLE_XOR);
1203 : :
1204 : 0 : dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
1205 : 0 : dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
1206 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
1207 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
1208 : :
1209 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1210 : : .rx_thresh = {
1211 : : .pthresh = 8,
1212 : : .hthresh = 8,
1213 : : .wthresh = 0,
1214 : : },
1215 : : .rx_free_thresh = 32,
1216 : : .rx_drop_en = BNXT_DEFAULT_RX_DROP_EN,
1217 : : };
1218 : :
1219 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1220 : : .tx_thresh = {
1221 : : .pthresh = 32,
1222 : : .hthresh = 0,
1223 : : .wthresh = 0,
1224 : : },
1225 : : .tx_free_thresh = 32,
1226 : : .tx_rs_thresh = 32,
1227 : : };
1228 : :
1229 : 0 : dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
1230 : 0 : dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
1231 : 0 : dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
1232 : 0 : dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
1233 : :
1234 [ # # ]: 0 : if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
1235 : 0 : dev_info->switch_info.name = eth_dev->device->name;
1236 : 0 : dev_info->switch_info.domain_id = bp->switch_domain_id;
1237 [ # # ]: 0 : dev_info->switch_info.port_id =
1238 : : BNXT_PF(bp) ? BNXT_SWITCH_PORT_ID_PF :
1239 : : BNXT_SWITCH_PORT_ID_TRUSTED_VF;
1240 : : }
1241 : :
1242 : : /*
1243 : : * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
1244 : : * need further investigation.
1245 : : */
1246 : :
1247 : : /* VMDq resources */
1248 : : vpool = 64; /* RTE_ETH_64_POOLS */
1249 : : vrxq = 128; /* RTE_ETH_VMDQ_DCB_NUM_QUEUES */
1250 [ # # ]: 0 : for (i = 0; i < 4; vpool >>= 1, i++) {
1251 [ # # ]: 0 : if (max_vnics > vpool) {
1252 [ # # ]: 0 : for (j = 0; j < 5; vrxq >>= 1, j++) {
1253 [ # # ]: 0 : if (dev_info->max_rx_queues > vrxq) {
1254 : : if (vpool > vrxq)
1255 : : vpool = vrxq;
1256 : 0 : goto found;
1257 : : }
1258 : : }
1259 : : /* Not enough resources to support VMDq */
1260 : : break;
1261 : : }
1262 : : }
1263 : : /* Not enough resources to support VMDq */
1264 : : vpool = 0;
1265 : : vrxq = 0;
1266 : 0 : found:
1267 : 0 : dev_info->max_vmdq_pools = vpool;
1268 : 0 : dev_info->vmdq_queue_num = vrxq;
1269 : :
1270 : 0 : dev_info->vmdq_pool_base = 0;
1271 : 0 : dev_info->vmdq_queue_base = 0;
1272 : :
1273 : 0 : dev_info->rx_seg_capa.max_nseg = BNXT_MAX_BUFFER_SPLIT_SEGS;
1274 : 0 : dev_info->rx_seg_capa.multi_pools = BNXT_MULTI_POOL_BUF_SPLIT_CAP;
1275 : 0 : dev_info->rx_seg_capa.offset_allowed = BNXT_BUF_SPLIT_OFFSET_CAP;
1276 : 0 : dev_info->rx_seg_capa.offset_align_log2 = BNXT_BUF_SPLIT_ALIGN_CAP;
1277 : :
1278 : 0 : dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PROACTIVE;
1279 : :
1280 : 0 : return 0;
1281 : : }
1282 : :
1283 : : /* Configure the device based on the configuration provided */
1284 : 0 : static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
1285 : : {
1286 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1287 : 0 : uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1288 : : struct rte_eth_rss_conf *rss_conf = ð_dev->data->dev_conf.rx_adv_conf.rss_conf;
1289 : : int rc;
1290 : :
1291 : 0 : bp->rx_queues = (void *)eth_dev->data->rx_queues;
1292 : 0 : bp->tx_queues = (void *)eth_dev->data->tx_queues;
1293 : 0 : bp->tx_nr_rings = eth_dev->data->nb_tx_queues;
1294 : 0 : bp->rx_nr_rings = eth_dev->data->nb_rx_queues;
1295 : :
1296 : 0 : rc = is_bnxt_in_error(bp);
1297 [ # # ]: 0 : if (rc)
1298 : : return rc;
1299 : :
1300 [ # # ]: 0 : if (BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)) {
1301 : 0 : rc = bnxt_hwrm_check_vf_rings(bp);
1302 [ # # ]: 0 : if (rc) {
1303 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM insufficient resources");
1304 : 0 : return -ENOSPC;
1305 : : }
1306 : :
1307 : : /* If a resource has already been allocated - in this case
1308 : : * it is the async completion ring, free it. Reallocate it after
1309 : : * resource reservation. This will ensure the resource counts
1310 : : * are calculated correctly.
1311 : : */
1312 : :
1313 : 0 : pthread_mutex_lock(&bp->def_cp_lock);
1314 : :
1315 [ # # # # ]: 0 : if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
1316 : 0 : bnxt_disable_int(bp);
1317 : 0 : bnxt_free_cp_ring(bp, bp->async_cp_ring);
1318 : : }
1319 : :
1320 : 0 : rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
1321 [ # # ]: 0 : if (rc) {
1322 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM resource alloc fail:%x", rc);
1323 : 0 : pthread_mutex_unlock(&bp->def_cp_lock);
1324 : 0 : return -ENOSPC;
1325 : : }
1326 : :
1327 [ # # # # ]: 0 : if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
1328 : 0 : rc = bnxt_alloc_async_cp_ring(bp);
1329 [ # # ]: 0 : if (rc) {
1330 : 0 : pthread_mutex_unlock(&bp->def_cp_lock);
1331 : 0 : return rc;
1332 : : }
1333 : 0 : bnxt_enable_int(bp);
1334 : : }
1335 : :
1336 : 0 : pthread_mutex_unlock(&bp->def_cp_lock);
1337 : : }
1338 : :
1339 : : /* Inherit new configurations */
1340 [ # # ]: 0 : if (eth_dev->data->nb_rx_queues > bp->max_rx_rings ||
1341 [ # # ]: 0 : eth_dev->data->nb_tx_queues > bp->max_tx_rings ||
1342 : 0 : eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues
1343 [ # # ]: 0 : + BNXT_NUM_ASYNC_CPR(bp) > bp->max_cp_rings ||
1344 : : eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues >
1345 [ # # ]: 0 : bp->max_stat_ctx)
1346 : 0 : goto resource_error;
1347 : :
1348 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp) &&
1349 [ # # ]: 0 : (uint32_t)(eth_dev->data->nb_rx_queues) > bp->max_ring_grps)
1350 : 0 : goto resource_error;
1351 : :
1352 [ # # ]: 0 : if (!(eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS) &&
1353 [ # # ]: 0 : bp->max_vnics < eth_dev->data->nb_rx_queues)
1354 : 0 : goto resource_error;
1355 : :
1356 : 0 : bp->rx_cp_nr_rings = bp->rx_nr_rings;
1357 : 0 : bp->tx_cp_nr_rings = bp->tx_nr_rings;
1358 : :
1359 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1360 : 0 : rx_offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1361 : 0 : eth_dev->data->dev_conf.rxmode.offloads = rx_offloads;
1362 : :
1363 : : /* application provides the hash key to program */
1364 [ # # ]: 0 : if (rss_conf->rss_key != NULL) {
1365 [ # # ]: 0 : if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE)
1366 : 0 : PMD_DRV_LOG_LINE(WARNING, "port %u RSS key len must be %d bytes long",
1367 : : eth_dev->data->port_id, HW_HASH_KEY_SIZE);
1368 : : else
1369 : 0 : memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
1370 : : }
1371 : 0 : bp->rss_conf.rss_key_len = HW_HASH_KEY_SIZE;
1372 : 0 : bp->rss_conf.rss_hf = rss_conf->rss_hf;
1373 : :
1374 : 0 : bnxt_mtu_set_op(eth_dev, eth_dev->data->mtu);
1375 : :
1376 : 0 : return 0;
1377 : :
1378 : 0 : resource_error:
1379 : 0 : PMD_DRV_LOG_LINE(ERR,
1380 : : "Insufficient resources to support requested config");
1381 : 0 : PMD_DRV_LOG_LINE(ERR,
1382 : : "Num Queues Requested: Tx %d, Rx %d",
1383 : : eth_dev->data->nb_tx_queues,
1384 : : eth_dev->data->nb_rx_queues);
1385 : 0 : PMD_DRV_LOG_LINE(ERR,
1386 : : "MAX: TxQ %d, RxQ %d, CQ %d Stat %d, Grp %d, Vnic %d",
1387 : : bp->max_tx_rings, bp->max_rx_rings, bp->max_cp_rings,
1388 : : bp->max_stat_ctx, bp->max_ring_grps, bp->max_vnics);
1389 : 0 : return -ENOSPC;
1390 : : }
1391 : :
1392 : 0 : void bnxt_print_link_info(struct rte_eth_dev *eth_dev)
1393 : : {
1394 : 0 : struct rte_eth_link *link = ð_dev->data->dev_link;
1395 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1396 : :
1397 [ # # ]: 0 : if (link->link_status)
1398 [ # # ]: 0 : PMD_DRV_LOG_LINE(DEBUG, "Port %d Link Up - speed %u Mbps - %s Lanes - %d",
1399 : : eth_dev->data->port_id,
1400 : : (uint32_t)link->link_speed,
1401 : : (link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
1402 : : ("full-duplex") : ("half-duplex"),
1403 : : (uint16_t)bp->link_info->active_lanes);
1404 : : else
1405 : 0 : PMD_DRV_LOG_LINE(INFO, "Port %d Link Down", eth_dev->data->port_id);
1406 : 0 : }
1407 : :
1408 : : /*
1409 : : * Determine whether the current configuration requires support for scattered
1410 : : * receive; return 1 if scattered receive is required and 0 if not.
1411 : : */
1412 : 0 : static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
1413 : : {
1414 : : uint32_t overhead = BNXT_MAX_PKT_LEN - BNXT_MAX_MTU;
1415 : : uint16_t buf_size;
1416 : : int i;
1417 : :
1418 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
1419 : : return 1;
1420 : :
1421 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)
1422 : : return 1;
1423 : :
1424 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
1425 : 0 : struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
1426 : :
1427 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
1428 : : RTE_PKTMBUF_HEADROOM);
1429 [ # # ]: 0 : if (eth_dev->data->mtu + overhead > buf_size)
1430 : : return 1;
1431 : : }
1432 : : return 0;
1433 : : }
1434 : :
1435 : : static eth_rx_burst_t
1436 : 0 : bnxt_receive_function(struct rte_eth_dev *eth_dev)
1437 : : {
1438 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1439 : :
1440 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1441 : : /* Vector mode receive cannot be enabled if scattered rx is in use. */
1442 [ # # ]: 0 : if (eth_dev->data->scattered_rx)
1443 : 0 : goto use_scalar_rx;
1444 : :
1445 : : /*
1446 : : * Vector mode receive cannot be enabled if Truflow is enabled or if
1447 : : * asynchronous completions and receive completions can be placed in
1448 : : * the same completion ring.
1449 : : */
1450 [ # # # # : 0 : if ((BNXT_TRUFLOW_EN(bp) && !BNXT_CHIP_P7(bp)) ||
# # ]
1451 : : !BNXT_NUM_ASYNC_CPR(bp))
1452 : 0 : goto use_scalar_rx;
1453 : :
1454 : : /*
1455 : : * Vector mode receive cannot be enabled if any receive offloads outside
1456 : : * a limited subset have been enabled.
1457 : : */
1458 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.offloads &
1459 : : ~(RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1460 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
1461 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1462 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1463 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1464 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1465 : : RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM |
1466 : : RTE_ETH_RX_OFFLOAD_RSS_HASH |
1467 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER))
1468 : 0 : goto use_scalar_rx;
1469 : :
1470 [ # # ]: 0 : if (bp->ieee_1588)
1471 : 0 : goto use_scalar_rx;
1472 : :
1473 : : #if defined(RTE_ARCH_X86)
1474 [ # # # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
1475 : 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1) {
1476 : 0 : PMD_DRV_LOG_LINE(INFO,
1477 : : "Using AVX2 vector mode receive for port %d",
1478 : : eth_dev->data->port_id);
1479 [ # # ]: 0 : bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
1480 : : if (bnxt_compressed_rx_cqe_mode_enabled(bp))
1481 : : return bnxt_crx_pkts_vec_avx2;
1482 : 0 : return bnxt_recv_pkts_vec_avx2;
1483 : : }
1484 : : #endif
1485 [ # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
1486 : 0 : PMD_DRV_LOG_LINE(INFO,
1487 : : "Using SSE vector mode receive for port %d",
1488 : : eth_dev->data->port_id);
1489 [ # # ]: 0 : bp->flags |= BNXT_FLAG_RX_VECTOR_PKT_MODE;
1490 : : if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
1491 : : #if defined(RTE_ARCH_ARM64)
1492 : : goto use_scalar_rx;
1493 : : #else
1494 : : return bnxt_crx_pkts_vec;
1495 : : #endif
1496 : : }
1497 : 0 : return bnxt_recv_pkts_vec;
1498 : : }
1499 : :
1500 : 0 : use_scalar_rx:
1501 : 0 : PMD_DRV_LOG_LINE(INFO, "Vector mode receive disabled for port %d",
1502 : : eth_dev->data->port_id);
1503 : 0 : PMD_DRV_LOG_LINE(INFO,
1504 : : "Port %d scatter: %d rx offload: %" PRIX64,
1505 : : eth_dev->data->port_id,
1506 : : eth_dev->data->scattered_rx,
1507 : : eth_dev->data->dev_conf.rxmode.offloads);
1508 : : #endif
1509 : 0 : bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1510 : 0 : return bnxt_recv_pkts;
1511 : : }
1512 : :
1513 : : static eth_tx_burst_t
1514 : 0 : bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
1515 : : {
1516 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
1517 : 0 : uint64_t offloads = eth_dev->data->dev_conf.txmode.offloads;
1518 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1519 : :
1520 : : /*
1521 : : * Vector mode transmit can be enabled only if not using scatter rx
1522 : : * or tx offloads.
1523 : : */
1524 [ # # ]: 0 : if (eth_dev->data->scattered_rx ||
1525 [ # # ]: 0 : (offloads & ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) ||
1526 [ # # # # : 0 : (BNXT_TRUFLOW_EN(bp) && !BNXT_CHIP_P7(bp)) ||
# # ]
1527 [ # # ]: 0 : bp->ieee_1588)
1528 : 0 : goto use_scalar_tx;
1529 : :
1530 : : #if defined(RTE_ARCH_X86)
1531 [ # # # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
1532 : 0 : rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1) {
1533 : 0 : PMD_DRV_LOG_LINE(INFO,
1534 : : "Using AVX2 vector mode transmit for port %d",
1535 : : eth_dev->data->port_id);
1536 : 0 : return bnxt_xmit_pkts_vec_avx2;
1537 : : }
1538 : : #endif
1539 [ # # ]: 0 : if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
1540 : 0 : PMD_DRV_LOG_LINE(INFO,
1541 : : "Using SSE vector mode transmit for port %d",
1542 : : eth_dev->data->port_id);
1543 : 0 : return bnxt_xmit_pkts_vec;
1544 : : }
1545 : :
1546 : 0 : use_scalar_tx:
1547 : 0 : PMD_DRV_LOG_LINE(INFO, "Vector mode transmit disabled for port %d",
1548 : : eth_dev->data->port_id);
1549 : 0 : PMD_DRV_LOG_LINE(INFO,
1550 : : "Port %d scatter: %d tx offload: %" PRIX64,
1551 : : eth_dev->data->port_id,
1552 : : eth_dev->data->scattered_rx,
1553 : : offloads);
1554 : : #endif
1555 : 0 : return bnxt_xmit_pkts;
1556 : : }
1557 : :
1558 : 0 : static int bnxt_handle_if_change_status(struct bnxt *bp)
1559 : : {
1560 : : int rc;
1561 : :
1562 : : /* Since fw has undergone a reset and lost all contexts,
1563 : : * set fatal flag to not issue hwrm during cleanup
1564 : : */
1565 : 0 : bp->flags |= BNXT_FLAG_FATAL_ERROR;
1566 : 0 : bnxt_uninit_resources(bp, true);
1567 : :
1568 : : /* clear fatal flag so that re-init happens */
1569 : 0 : bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
1570 : :
1571 : 0 : rc = bnxt_check_fw_ready(bp);
1572 [ # # ]: 0 : if (rc)
1573 : : return rc;
1574 : :
1575 : 0 : rc = bnxt_init_resources(bp, true);
1576 : :
1577 : 0 : bp->flags &= ~BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
1578 : :
1579 : 0 : return rc;
1580 : : }
1581 : :
1582 : 0 : static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
1583 : : {
1584 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1585 : : int rc = 0;
1586 : :
1587 [ # # ]: 0 : if (!BNXT_SINGLE_PF(bp))
1588 : : return -ENOTSUP;
1589 : :
1590 [ # # ]: 0 : if (!bp->link_info->link_up)
1591 : 0 : rc = bnxt_set_hwrm_link_config(bp, true);
1592 [ # # ]: 0 : if (!rc)
1593 : 0 : eth_dev->data->dev_link.link_status = 1;
1594 : :
1595 : 0 : bnxt_print_link_info(eth_dev);
1596 : 0 : return rc;
1597 : : }
1598 : :
1599 : 0 : static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
1600 : : {
1601 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1602 : :
1603 [ # # ]: 0 : if (!BNXT_SINGLE_PF(bp))
1604 : : return -ENOTSUP;
1605 : :
1606 : 0 : eth_dev->data->dev_link.link_status = 0;
1607 : 0 : bnxt_set_hwrm_link_config(bp, false);
1608 : 0 : bp->link_info->link_up = 0;
1609 : :
1610 : 0 : return 0;
1611 : : }
1612 : :
1613 : 0 : static void bnxt_free_switch_domain(struct bnxt *bp)
1614 : : {
1615 : : int rc = 0;
1616 : :
1617 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)))
1618 : : return;
1619 : :
1620 : 0 : rc = rte_eth_switch_domain_free(bp->switch_domain_id);
1621 [ # # ]: 0 : if (rc)
1622 : 0 : PMD_DRV_LOG_LINE(ERR, "free switch domain:%d fail: %d",
1623 : : bp->switch_domain_id, rc);
1624 : : }
1625 : :
1626 : 0 : static void bnxt_ptp_get_current_time(void *arg)
1627 : : {
1628 : : struct bnxt *bp = arg;
1629 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
1630 : : int rc;
1631 : :
1632 : 0 : rc = is_bnxt_in_error(bp);
1633 [ # # ]: 0 : if (rc)
1634 : : return;
1635 : :
1636 [ # # ]: 0 : if (!ptp)
1637 : : return;
1638 : :
1639 : 0 : rte_spinlock_lock(&ptp->ptp_lock);
1640 : 0 : ptp->old_time = ptp->current_time;
1641 : 0 : bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
1642 : : &ptp->current_time);
1643 : : rte_spinlock_unlock(&ptp->ptp_lock);
1644 : 0 : rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
1645 [ # # ]: 0 : if (rc != 0) {
1646 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to re-schedule PTP alarm");
1647 : 0 : bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
1648 : : }
1649 : : }
1650 : :
1651 : 0 : static int bnxt_schedule_ptp_alarm(struct bnxt *bp)
1652 : : {
1653 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
1654 : : int rc;
1655 : :
1656 [ # # ]: 0 : if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED)
1657 : : return 0;
1658 : :
1659 : 0 : rte_spinlock_lock(&ptp->ptp_lock);
1660 : 0 : bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
1661 : : &ptp->current_time);
1662 : 0 : ptp->old_time = ptp->current_time;
1663 : : rte_spinlock_unlock(&ptp->ptp_lock);
1664 : :
1665 : :
1666 : 0 : rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
1667 : 0 : return rc;
1668 : : }
1669 : :
1670 : : static void bnxt_cancel_ptp_alarm(struct bnxt *bp)
1671 : : {
1672 [ # # ]: 0 : if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED) {
1673 : 0 : rte_eal_alarm_cancel(bnxt_ptp_get_current_time, (void *)bp);
1674 : 0 : bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
1675 : : }
1676 : : }
1677 : :
1678 [ # # ]: 0 : static void bnxt_ptp_stop(struct bnxt *bp)
1679 : : {
1680 : : bnxt_cancel_ptp_alarm(bp);
1681 : 0 : bp->flags2 &= ~BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
1682 : 0 : }
1683 : :
1684 : 0 : static int bnxt_ptp_start(struct bnxt *bp)
1685 : : {
1686 : : int rc;
1687 : :
1688 : 0 : rc = bnxt_schedule_ptp_alarm(bp);
1689 [ # # ]: 0 : if (rc != 0) {
1690 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to schedule PTP alarm");
1691 : : } else {
1692 : 0 : bp->flags2 |= BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
1693 : 0 : bp->flags2 |= BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
1694 : : }
1695 : :
1696 : 0 : return rc;
1697 : : }
1698 : :
1699 : 0 : static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
1700 : : {
1701 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1702 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1703 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1704 : : struct rte_eth_link link;
1705 : : uint16_t i;
1706 : : int ret;
1707 : :
1708 : 0 : eth_dev->data->dev_started = 0;
1709 : :
1710 : : /* Prevent crashes when queues are still in use */
1711 : 0 : bnxt_stop_rxtx(eth_dev);
1712 : :
1713 : 0 : bnxt_disable_int(bp);
1714 : :
1715 : : /* disable uio/vfio intr/eventfd mapping */
1716 : 0 : rte_intr_disable(intr_handle);
1717 : :
1718 : : /* Stop the child representors for this device */
1719 : 0 : ret = bnxt_rep_stop_all(bp);
1720 [ # # ]: 0 : if (ret != 0)
1721 : : return ret;
1722 : :
1723 : : /* delete the bnxt ULP port details */
1724 : : if (bnxt_enable_ulp(bp))
1725 : 0 : bnxt_ulp_port_deinit(bp);
1726 : :
1727 : : bnxt_cancel_fw_health_check(bp);
1728 : :
1729 : 0 : if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
1730 : : bnxt_cancel_ptp_alarm(bp);
1731 : :
1732 : : /* Do not bring link down during reset recovery */
1733 [ # # ]: 0 : if (!is_bnxt_in_error(bp)) {
1734 : 0 : bnxt_dev_set_link_down_op(eth_dev);
1735 : : /* Wait for link to be reset */
1736 [ # # ]: 0 : if (BNXT_SINGLE_PF(bp))
1737 : : rte_delay_ms(500);
1738 : : /* clear the recorded link status */
1739 : : memset(&link, 0, sizeof(link));
1740 : 0 : rte_eth_linkstatus_set(eth_dev, &link);
1741 : : }
1742 : :
1743 : : /* Clean queue intr-vector mapping */
1744 : 0 : rte_intr_efd_disable(intr_handle);
1745 : 0 : rte_intr_vec_list_free(intr_handle);
1746 : :
1747 : 0 : bnxt_hwrm_port_clr_stats(bp);
1748 : 0 : bnxt_free_tx_mbufs(bp);
1749 : 0 : bnxt_free_rx_mbufs(bp);
1750 : : /* Process any remaining notifications in default completion queue */
1751 : 0 : bnxt_int_handler(eth_dev);
1752 : :
1753 [ # # ]: 0 : if (mpc != 0)
1754 : 0 : bnxt_mpc_close(bp);
1755 : :
1756 : 0 : bnxt_shutdown_nic(bp);
1757 : 0 : bnxt_hwrm_if_change(bp, false);
1758 : :
1759 : 0 : bnxt_free_prev_ring_stats(bp);
1760 : 0 : rte_free(bp->mark_table);
1761 : 0 : bp->mark_table = NULL;
1762 : :
1763 : 0 : bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
1764 : 0 : bp->rx_cosq_cnt = 0;
1765 : : /* All filters are deleted on a port stop. */
1766 [ # # ]: 0 : if (BNXT_FLOW_XSTATS_EN(bp))
1767 : 0 : bp->flow_stat->flow_count = 0;
1768 : :
1769 : 0 : eth_dev->data->scattered_rx = 0;
1770 : :
1771 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
1772 : 0 : eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1773 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
1774 : 0 : eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1775 : :
1776 : : return 0;
1777 : : }
1778 : :
1779 : : /* Unload the driver, release resources */
1780 : 0 : int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
1781 : : {
1782 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1783 : :
1784 : 0 : pthread_mutex_lock(&bp->err_recovery_lock);
1785 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_RESET) {
1786 : 0 : PMD_DRV_LOG_LINE(ERR,
1787 : : "Adapter recovering from error..Please retry");
1788 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
1789 : 0 : return -EAGAIN;
1790 : : }
1791 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
1792 : :
1793 : 0 : return bnxt_dev_stop(eth_dev);
1794 : : }
1795 : :
1796 : 0 : static void bnxt_update_max_rx_burst(struct bnxt *bp, struct rte_eth_link *link)
1797 : : {
1798 [ # # ]: 0 : if (link->link_speed == RTE_ETH_SPEED_NUM_400G) {
1799 : : uint32_t i;
1800 : :
1801 : : /* Faster port speed. Update threshold. Else use default. */
1802 [ # # ]: 0 : for (i = 0; i < bp->rx_nr_rings; i++) {
1803 : 0 : struct bnxt_rx_queue *rxq = bp->rx_queues[i];
1804 : :
1805 : 0 : rxq->rx_free_thresh =
1806 : 0 : RTE_MIN(rte_align32pow2(rxq->nb_rx_desc) / 4,
1807 : : RTE_BNXT_MAX_RX_BURST_TH2);
1808 : : }
1809 : : }
1810 : 0 : }
1811 : :
1812 : 0 : int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
1813 : : {
1814 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1815 : 0 : uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
1816 : 0 : struct rte_eth_link *link = ð_dev->data->dev_link;
1817 : : int vlan_mask = 0;
1818 : : int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
1819 : :
1820 [ # # ]: 0 : if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS)
1821 : 0 : PMD_DRV_LOG_LINE(ERR,
1822 : : "RxQ cnt %d > RTE_ETHDEV_QUEUE_STAT_CNTRS %d",
1823 : : bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
1824 : :
1825 : : do {
1826 : 0 : rc = bnxt_hwrm_if_change(bp, true);
1827 [ # # ]: 0 : if (rc == 0 || rc != -EAGAIN)
1828 : : break;
1829 : :
1830 : : rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
1831 [ # # ]: 0 : } while (retry_cnt--);
1832 : :
1833 [ # # ]: 0 : if (rc)
1834 : : return rc;
1835 : :
1836 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
1837 : 0 : rc = bnxt_handle_if_change_status(bp);
1838 [ # # ]: 0 : if (rc)
1839 : : return rc;
1840 : : }
1841 : :
1842 : 0 : bnxt_enable_int(bp);
1843 : :
1844 : 0 : eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
1845 : :
1846 : 0 : rc = bnxt_start_nic(bp);
1847 [ # # ]: 0 : if (rc)
1848 : 0 : goto error;
1849 : :
1850 [ # # ]: 0 : if (mpc != 0) {
1851 : 0 : rc = bnxt_mpc_open(bp);
1852 [ # # ]: 0 : if (rc != 0)
1853 : 0 : PMD_DRV_LOG_LINE(DEBUG, "MPC open failed");
1854 : : }
1855 : :
1856 : 0 : rc = bnxt_alloc_prev_ring_stats(bp);
1857 [ # # ]: 0 : if (rc)
1858 : 0 : goto error;
1859 : :
1860 : 0 : eth_dev->data->dev_started = 1;
1861 : :
1862 : 0 : bnxt_link_update_op(eth_dev, 0);
1863 : :
1864 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
1865 : : vlan_mask |= RTE_ETH_VLAN_FILTER_MASK;
1866 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1867 : 0 : vlan_mask |= RTE_ETH_VLAN_STRIP_MASK;
1868 : 0 : rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
1869 [ # # ]: 0 : if (rc)
1870 : 0 : goto error;
1871 : :
1872 : : /* Initialize bnxt ULP port details */
1873 : : if (bnxt_enable_ulp(bp)) {
1874 [ # # ]: 0 : if (BNXT_CHIP_P7(bp)) {
1875 : : /* Need to release the Fid from AFM control */
1876 : 0 : rc = bnxt_hwrm_release_afm_func(bp, bp->fw_fid,
1877 : 0 : bp->fw_fid,
1878 : : HWRM_CFA_RELEASE_AFM_FUNC_INPUT_TYPE_RFID,
1879 : : 0);
1880 [ # # ]: 0 : if (rc) {
1881 : 0 : PMD_DRV_LOG_LINE(ERR,
1882 : : "Failed in hwrm release afm func:%u rc=%d",
1883 : : bp->fw_fid, rc);
1884 : 0 : goto error;
1885 : : }
1886 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Released RFID:%d", bp->fw_fid);
1887 : : }
1888 : :
1889 : 0 : rc = bnxt_ulp_port_init(bp);
1890 [ # # ]: 0 : if (rc)
1891 : 0 : goto error;
1892 : : }
1893 : :
1894 : 0 : eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
1895 : 0 : eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
1896 : :
1897 : 0 : bnxt_update_max_rx_burst(bp, link);
1898 : :
1899 : 0 : bnxt_schedule_fw_health_check(bp);
1900 : :
1901 [ # # ]: 0 : if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
1902 : 0 : bnxt_schedule_ptp_alarm(bp);
1903 : :
1904 : : return 0;
1905 : :
1906 : 0 : error:
1907 : 0 : bnxt_dev_stop(eth_dev);
1908 : 0 : return rc;
1909 : : }
1910 : :
1911 : : static void
1912 : 0 : bnxt_uninit_locks(struct bnxt *bp)
1913 : : {
1914 : 0 : pthread_mutex_destroy(&bp->flow_lock);
1915 : 0 : pthread_mutex_destroy(&bp->def_cp_lock);
1916 : 0 : pthread_mutex_destroy(&bp->health_check_lock);
1917 : 0 : pthread_mutex_destroy(&bp->err_recovery_lock);
1918 [ # # ]: 0 : if (bp->rep_info)
1919 : 0 : pthread_mutex_destroy(&bp->rep_info->vfr_start_lock);
1920 : 0 : }
1921 : :
1922 [ # # ]: 0 : static void bnxt_drv_uninit(struct bnxt *bp)
1923 : : {
1924 : : bnxt_free_leds_info(bp);
1925 : : bnxt_free_cos_queues(bp);
1926 : : bnxt_free_link_info(bp);
1927 : : bnxt_free_parent_info(bp);
1928 : 0 : bnxt_uninit_locks(bp);
1929 : : bnxt_free_rep_info(bp);
1930 : :
1931 : 0 : rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
1932 : 0 : bp->tx_mem_zone = NULL;
1933 : 0 : rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
1934 : 0 : bp->rx_mem_zone = NULL;
1935 : :
1936 : 0 : bnxt_free_vf_info(bp);
1937 : : bnxt_free_pf_info(bp);
1938 : :
1939 : 0 : rte_free(bp->grp_info);
1940 : 0 : bp->grp_info = NULL;
1941 : 0 : }
1942 : :
1943 : 0 : static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
1944 : : {
1945 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1946 : : int ret = 0;
1947 : :
1948 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1949 : : return 0;
1950 : :
1951 : 0 : pthread_mutex_lock(&bp->err_recovery_lock);
1952 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_RESET) {
1953 : 0 : PMD_DRV_LOG_LINE(ERR,
1954 : : "Adapter recovering from error...Please retry");
1955 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
1956 : 0 : return -EAGAIN;
1957 : : }
1958 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
1959 : :
1960 : : /* cancel the recovery handler before remove dev */
1961 : 0 : rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
1962 : 0 : rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
1963 : 0 : bnxt_cancel_fc_thread(bp);
1964 : 0 : rte_eal_alarm_cancel(bnxt_handle_vf_cfg_change, (void *)bp);
1965 : :
1966 [ # # ]: 0 : if (eth_dev->data->dev_started)
1967 : 0 : ret = bnxt_dev_stop(eth_dev);
1968 : :
1969 : 0 : bnxt_uninit_resources(bp, false);
1970 : :
1971 : 0 : bnxt_drv_uninit(bp);
1972 : :
1973 : 0 : return ret;
1974 : : }
1975 : :
1976 : 0 : static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
1977 : : uint32_t index)
1978 : : {
1979 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
1980 : 0 : uint64_t pool_mask = eth_dev->data->mac_pool_sel[index];
1981 : : struct bnxt_vnic_info *vnic;
1982 : : struct bnxt_filter_info *filter, *temp_filter;
1983 : : uint32_t i;
1984 : :
1985 [ # # ]: 0 : if (is_bnxt_in_error(bp))
1986 : : return;
1987 : :
1988 : : /*
1989 : : * Loop through all VNICs from the specified filter flow pools to
1990 : : * remove the corresponding MAC addr filter
1991 : : */
1992 [ # # ]: 0 : for (i = 0; i < bp->nr_vnics; i++) {
1993 [ # # ]: 0 : if (!(pool_mask & (1ULL << i)))
1994 : 0 : continue;
1995 : :
1996 : 0 : vnic = &bp->vnic_info[i];
1997 : 0 : filter = STAILQ_FIRST(&vnic->filter);
1998 [ # # ]: 0 : while (filter) {
1999 : 0 : temp_filter = STAILQ_NEXT(filter, next);
2000 [ # # ]: 0 : if (filter->mac_index == index) {
2001 [ # # # # : 0 : STAILQ_REMOVE(&vnic->filter, filter,
# # # # ]
2002 : : bnxt_filter_info, next);
2003 : 0 : bnxt_hwrm_clear_l2_filter(bp, filter);
2004 : 0 : bnxt_free_filter(bp, filter);
2005 : : }
2006 : : filter = temp_filter;
2007 : : }
2008 : : }
2009 : : }
2010 : :
2011 : 0 : static int bnxt_add_mac_filter(struct bnxt *bp, struct bnxt_vnic_info *vnic,
2012 : : struct rte_ether_addr *mac_addr, uint32_t index,
2013 : : uint32_t pool)
2014 : : {
2015 : : struct bnxt_filter_info *filter;
2016 : : int rc = 0;
2017 : :
2018 : : /* Attach requested MAC address to the new l2_filter */
2019 [ # # ]: 0 : STAILQ_FOREACH(filter, &vnic->filter, next) {
2020 [ # # ]: 0 : if (filter->mac_index == index) {
2021 : 0 : PMD_DRV_LOG_LINE(DEBUG,
2022 : : "MAC addr already existed for pool %d",
2023 : : pool);
2024 : 0 : return 0;
2025 : : }
2026 : : }
2027 : :
2028 : 0 : filter = bnxt_alloc_filter(bp);
2029 [ # # ]: 0 : if (!filter) {
2030 : 0 : PMD_DRV_LOG_LINE(ERR, "L2 filter alloc failed");
2031 : 0 : return -ENODEV;
2032 : : }
2033 : :
2034 : : /* bnxt_alloc_filter copies default MAC to filter->l2_addr. So,
2035 : : * if the MAC that's been programmed now is a different one, then,
2036 : : * copy that addr to filter->l2_addr
2037 : : */
2038 [ # # ]: 0 : if (mac_addr)
2039 : 0 : memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
2040 : 0 : filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
2041 : :
2042 : 0 : rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
2043 [ # # ]: 0 : if (!rc) {
2044 : 0 : filter->mac_index = index;
2045 [ # # ]: 0 : if (filter->mac_index == 0)
2046 [ # # ]: 0 : STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
2047 : : else
2048 : 0 : STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2049 : : } else {
2050 : 0 : bnxt_free_filter(bp, filter);
2051 : : }
2052 : :
2053 : : return rc;
2054 : : }
2055 : :
2056 : 0 : static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
2057 : : struct rte_ether_addr *mac_addr,
2058 : : uint32_t index, uint32_t pool)
2059 : : {
2060 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2061 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
2062 : : int rc = 0;
2063 : :
2064 : 0 : rc = is_bnxt_in_error(bp);
2065 [ # # ]: 0 : if (rc)
2066 : : return rc;
2067 : :
2068 [ # # ]: 0 : if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
2069 : 0 : PMD_DRV_LOG_LINE(ERR, "Cannot add MAC address to a VF interface");
2070 : 0 : return -ENOTSUP;
2071 : : }
2072 : :
2073 [ # # ]: 0 : if (!vnic) {
2074 : 0 : PMD_DRV_LOG_LINE(ERR, "VNIC not found for pool %d!", pool);
2075 : 0 : return -EINVAL;
2076 : : }
2077 : :
2078 : : /* Filter settings will get applied when port is started */
2079 [ # # ]: 0 : if (!eth_dev->data->dev_started)
2080 : : return 0;
2081 : :
2082 : 0 : rc = bnxt_add_mac_filter(bp, vnic, mac_addr, index, pool);
2083 : :
2084 : 0 : return rc;
2085 : : }
2086 : :
2087 : 0 : int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
2088 : : {
2089 : : int rc = 0;
2090 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2091 : : struct rte_eth_link new;
2092 [ # # ]: 0 : int cnt = wait_to_complete ? BNXT_MAX_LINK_WAIT_CNT :
2093 : : BNXT_MIN_LINK_WAIT_CNT;
2094 : :
2095 : 0 : rc = is_bnxt_in_error(bp);
2096 [ # # ]: 0 : if (rc)
2097 : : return rc;
2098 : :
2099 : : memset(&new, 0, sizeof(new));
2100 : :
2101 [ # # ]: 0 : if (bp->link_info == NULL)
2102 : 0 : goto out;
2103 : :
2104 : : /* Only single function PF can bring the phy down.
2105 : : * In certain scenarios, device is not obliged link down even when forced.
2106 : : * When port is stopped, report link down in those cases.
2107 : : */
2108 [ # # ]: 0 : if (!eth_dev->data->dev_started &&
2109 [ # # ]: 0 : (!BNXT_SINGLE_PF(bp) || bnxt_force_link_config(bp)))
2110 : 0 : goto out;
2111 : :
2112 : : do {
2113 : : /* Retrieve link info from hardware */
2114 : 0 : rc = bnxt_get_hwrm_link_config(bp, &new);
2115 [ # # ]: 0 : if (rc) {
2116 : 0 : new.link_speed = RTE_ETH_LINK_SPEED_100M;
2117 : 0 : new.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2118 : 0 : PMD_DRV_LOG_LINE(ERR,
2119 : : "Failed to retrieve link rc = 0x%x!", rc);
2120 : 0 : goto out;
2121 : : }
2122 : :
2123 [ # # # # ]: 0 : if (!wait_to_complete || new.link_status)
2124 : : break;
2125 : :
2126 : : rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
2127 [ # # ]: 0 : } while (cnt--);
2128 : :
2129 : 0 : out:
2130 : : /* Timed out or success */
2131 [ # # ]: 0 : if (new.link_status != eth_dev->data->dev_link.link_status ||
2132 : : new.link_speed != eth_dev->data->dev_link.link_speed) {
2133 : 0 : rte_eth_linkstatus_set(eth_dev, &new);
2134 : 0 : bnxt_print_link_info(eth_dev);
2135 : : }
2136 : 0 : bnxt_update_max_rx_burst(bp, &new);
2137 : :
2138 : 0 : return rc;
2139 : : }
2140 : :
2141 : 0 : static int bnxt_promiscuous_enable_op(struct rte_eth_dev *eth_dev)
2142 : : {
2143 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2144 : : struct bnxt_vnic_info *vnic;
2145 : : uint32_t old_flags;
2146 : : int rc;
2147 : :
2148 : 0 : rc = is_bnxt_in_error(bp);
2149 [ # # ]: 0 : if (rc)
2150 : : return rc;
2151 : :
2152 : : /* Filter settings will get applied when port is started */
2153 [ # # ]: 0 : if (!eth_dev->data->dev_started)
2154 : : return 0;
2155 : :
2156 [ # # ]: 0 : if (bp->vnic_info == NULL)
2157 : : return 0;
2158 : :
2159 : 0 : vnic = bnxt_get_default_vnic(bp);
2160 : :
2161 : 0 : old_flags = vnic->flags;
2162 : 0 : vnic->flags |= BNXT_VNIC_INFO_PROMISC;
2163 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2164 [ # # ]: 0 : if (rc != 0)
2165 : 0 : vnic->flags = old_flags;
2166 : :
2167 : : return rc;
2168 : : }
2169 : :
2170 : 0 : static int bnxt_promiscuous_disable_op(struct rte_eth_dev *eth_dev)
2171 : : {
2172 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2173 : : struct bnxt_vnic_info *vnic;
2174 : : uint32_t old_flags;
2175 : : int rc;
2176 : :
2177 : 0 : rc = is_bnxt_in_error(bp);
2178 [ # # ]: 0 : if (rc)
2179 : : return rc;
2180 : :
2181 : : /* Filter settings will get applied when port is started */
2182 [ # # ]: 0 : if (!eth_dev->data->dev_started)
2183 : : return 0;
2184 : :
2185 [ # # ]: 0 : if (bp->vnic_info == NULL)
2186 : : return 0;
2187 : :
2188 : 0 : vnic = bnxt_get_default_vnic(bp);
2189 : :
2190 : 0 : old_flags = vnic->flags;
2191 : 0 : vnic->flags &= ~BNXT_VNIC_INFO_PROMISC;
2192 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2193 [ # # ]: 0 : if (rc != 0)
2194 : 0 : vnic->flags = old_flags;
2195 : :
2196 : : return rc;
2197 : : }
2198 : :
2199 : 0 : static int bnxt_allmulticast_enable_op(struct rte_eth_dev *eth_dev)
2200 : : {
2201 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2202 : : struct bnxt_vnic_info *vnic;
2203 : : uint32_t old_flags;
2204 : : int rc;
2205 : :
2206 : 0 : rc = is_bnxt_in_error(bp);
2207 [ # # ]: 0 : if (rc)
2208 : : return rc;
2209 : :
2210 : : /* Filter settings will get applied when port is started */
2211 [ # # ]: 0 : if (!eth_dev->data->dev_started)
2212 : : return 0;
2213 : :
2214 [ # # ]: 0 : if (bp->vnic_info == NULL)
2215 : : return 0;
2216 : :
2217 : 0 : vnic = bnxt_get_default_vnic(bp);
2218 : :
2219 : 0 : old_flags = vnic->flags;
2220 : 0 : vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
2221 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2222 [ # # ]: 0 : if (rc != 0)
2223 : 0 : vnic->flags = old_flags;
2224 : :
2225 : : return rc;
2226 : : }
2227 : :
2228 : 0 : static int bnxt_allmulticast_disable_op(struct rte_eth_dev *eth_dev)
2229 : : {
2230 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2231 : : struct bnxt_vnic_info *vnic;
2232 : : uint32_t old_flags;
2233 : : int rc;
2234 : :
2235 : 0 : rc = is_bnxt_in_error(bp);
2236 [ # # ]: 0 : if (rc)
2237 : : return rc;
2238 : :
2239 : : /* Filter settings will get applied when port is started */
2240 [ # # ]: 0 : if (!eth_dev->data->dev_started)
2241 : : return 0;
2242 : :
2243 [ # # ]: 0 : if (bp->vnic_info == NULL)
2244 : : return 0;
2245 : :
2246 : 0 : vnic = bnxt_get_default_vnic(bp);
2247 : :
2248 : 0 : old_flags = vnic->flags;
2249 : 0 : vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
2250 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2251 [ # # ]: 0 : if (rc != 0)
2252 : 0 : vnic->flags = old_flags;
2253 : :
2254 : : return rc;
2255 : : }
2256 : :
2257 : : /* Return bnxt_rx_queue pointer corresponding to a given rxq. */
2258 : : static struct bnxt_rx_queue *bnxt_qid_to_rxq(struct bnxt *bp, uint16_t qid)
2259 : : {
2260 : 0 : if (qid >= bp->rx_nr_rings)
2261 : : return NULL;
2262 : :
2263 : 0 : return bp->eth_dev->data->rx_queues[qid];
2264 : : }
2265 : :
2266 : : /* Return rxq corresponding to a given rss table ring/group ID. */
2267 : 0 : static uint16_t bnxt_rss_to_qid(struct bnxt *bp, uint16_t fwr)
2268 : : {
2269 : : struct bnxt_rx_queue *rxq;
2270 : : unsigned int i;
2271 : :
2272 [ # # ]: 0 : if (!BNXT_HAS_RING_GRPS(bp)) {
2273 [ # # ]: 0 : for (i = 0; i < bp->rx_nr_rings; i++) {
2274 : 0 : rxq = bp->eth_dev->data->rx_queues[i];
2275 [ # # ]: 0 : if (rxq->rx_ring->rx_ring_struct->fw_ring_id == fwr)
2276 : 0 : return rxq->index;
2277 : : }
2278 : : } else {
2279 [ # # ]: 0 : for (i = 0; i < bp->rx_nr_rings; i++) {
2280 [ # # ]: 0 : if (bp->grp_info[i].fw_grp_id == fwr)
2281 : 0 : return i;
2282 : : }
2283 : : }
2284 : :
2285 : : return INVALID_HW_RING_ID;
2286 : : }
2287 : :
2288 : 0 : static int bnxt_reta_update_op(struct rte_eth_dev *eth_dev,
2289 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2290 : : uint16_t reta_size)
2291 : : {
2292 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2293 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2294 : 0 : struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
2295 : 0 : uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
2296 : : uint16_t idx, sft;
2297 : : int i, rc;
2298 : :
2299 : 0 : rc = is_bnxt_in_error(bp);
2300 [ # # ]: 0 : if (rc)
2301 : : return rc;
2302 : :
2303 [ # # ]: 0 : if (!vnic->rss_table)
2304 : : return -EINVAL;
2305 : :
2306 [ # # ]: 0 : if (!(dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
2307 : : return -EINVAL;
2308 : :
2309 [ # # ]: 0 : if (reta_size != tbl_size) {
2310 : 0 : PMD_DRV_LOG_LINE(ERR, "The configured hash table lookup size "
2311 : : "(%d) must equal the size supported by the hardware "
2312 : : "(%d)", reta_size, tbl_size);
2313 : 0 : return -EINVAL;
2314 : : }
2315 : :
2316 [ # # ]: 0 : if (bnxt_vnic_reta_config_update(bp, vnic, reta_conf, reta_size)) {
2317 : 0 : PMD_DRV_LOG_LINE(ERR, "Error in setting the reta config");
2318 : 0 : return -EINVAL;
2319 : : }
2320 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
2321 : : struct bnxt_rx_queue *rxq;
2322 : :
2323 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2324 : 0 : sft = i % RTE_ETH_RETA_GROUP_SIZE;
2325 : :
2326 [ # # ]: 0 : if (!(reta_conf[idx].mask & (1ULL << sft)))
2327 : 0 : continue;
2328 : :
2329 [ # # ]: 0 : rxq = bnxt_qid_to_rxq(bp, reta_conf[idx].reta[sft]);
2330 [ # # ]: 0 : if (!rxq) {
2331 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid ring in reta_conf");
2332 : 0 : return -EINVAL;
2333 : : }
2334 : :
2335 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
2336 : 0 : vnic->rss_table[i * 2] =
2337 : 0 : rxq->rx_ring->rx_ring_struct->fw_ring_id;
2338 : 0 : vnic->rss_table[i * 2 + 1] =
2339 : 0 : rxq->cp_ring->cp_ring_struct->fw_ring_id;
2340 : : } else {
2341 : 0 : vnic->rss_table[i] =
2342 : 0 : vnic->fw_grp_ids[reta_conf[idx].reta[sft]];
2343 : : }
2344 : : }
2345 : 0 : rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
2346 : 0 : return rc;
2347 : : }
2348 : :
2349 : 0 : static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev,
2350 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2351 : : uint16_t reta_size)
2352 : : {
2353 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2354 : 0 : struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
2355 : 0 : uint16_t tbl_size = bnxt_rss_hash_tbl_size(bp);
2356 : : uint16_t idx, sft, i;
2357 : : int rc;
2358 : :
2359 : 0 : rc = is_bnxt_in_error(bp);
2360 [ # # ]: 0 : if (rc)
2361 : : return rc;
2362 : :
2363 [ # # ]: 0 : if (!vnic)
2364 : : return -EINVAL;
2365 [ # # ]: 0 : if (!vnic->rss_table)
2366 : : return -EINVAL;
2367 : :
2368 [ # # ]: 0 : if (reta_size != tbl_size) {
2369 : 0 : PMD_DRV_LOG_LINE(ERR, "The configured hash table lookup size "
2370 : : "(%d) must equal the size supported by the hardware "
2371 : : "(%d)", reta_size, tbl_size);
2372 : 0 : return -EINVAL;
2373 : : }
2374 : :
2375 [ # # ]: 0 : for (idx = 0, i = 0; i < reta_size; i++) {
2376 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2377 : 0 : sft = i % RTE_ETH_RETA_GROUP_SIZE;
2378 : :
2379 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << sft)) {
2380 : : uint16_t qid;
2381 : :
2382 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp))
2383 : 0 : qid = bnxt_rss_to_qid(bp,
2384 : 0 : vnic->rss_table[i * 2]);
2385 : : else
2386 : 0 : qid = bnxt_rss_to_qid(bp, vnic->rss_table[i]);
2387 : :
2388 [ # # ]: 0 : if (qid == INVALID_HW_RING_ID) {
2389 : 0 : PMD_DRV_LOG_LINE(ERR, "Inv. entry in rss table.");
2390 : 0 : return -EINVAL;
2391 : : }
2392 : 0 : reta_conf[idx].reta[sft] = qid;
2393 : : }
2394 : : }
2395 : :
2396 : : return 0;
2397 : : }
2398 : :
2399 : 0 : static int bnxt_rss_hash_update_op(struct rte_eth_dev *eth_dev,
2400 : : struct rte_eth_rss_conf *rss_conf)
2401 : : {
2402 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2403 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
2404 : : struct bnxt_vnic_info *vnic;
2405 : : int rc;
2406 : :
2407 : 0 : rc = is_bnxt_in_error(bp);
2408 [ # # ]: 0 : if (rc)
2409 : : return rc;
2410 : :
2411 : : /*
2412 : : * If RSS enablement were different than dev_configure,
2413 : : * then return -EINVAL
2414 : : */
2415 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) {
2416 [ # # ]: 0 : if (!rss_conf->rss_hf)
2417 : 0 : PMD_DRV_LOG_LINE(ERR, "Hash type NONE");
2418 : : } else {
2419 [ # # ]: 0 : if (rss_conf->rss_hf & bnxt_eth_rss_support(bp))
2420 : : return -EINVAL;
2421 : : }
2422 : :
2423 : : /* Update the default RSS VNIC(s) */
2424 : 0 : vnic = bnxt_get_default_vnic(bp);
2425 : 0 : vnic->hash_type = bnxt_rte_to_hwrm_hash_types(rss_conf->rss_hf);
2426 : 0 : vnic->hash_mode =
2427 : 0 : bnxt_rte_to_hwrm_hash_level(bp, rss_conf->rss_hf,
2428 : 0 : RTE_ETH_RSS_LEVEL(rss_conf->rss_hf));
2429 : 0 : rc = bnxt_rte_eth_to_hwrm_ring_select_mode(bp, rss_conf->rss_hf, vnic);
2430 [ # # ]: 0 : if (rc != 0)
2431 : : return rc;
2432 : :
2433 : : /* Cache the hash function */
2434 : 0 : bp->rss_conf.rss_hf = rss_conf->rss_hf;
2435 : :
2436 : : /* Cache the hash function */
2437 : : bp->rss_conf.rss_hf = rss_conf->rss_hf;
2438 : :
2439 : : /*
2440 : : * If hashkey is not specified, use the previously configured
2441 : : * hashkey
2442 : : */
2443 [ # # ]: 0 : if (!rss_conf->rss_key)
2444 : 0 : goto rss_config;
2445 : :
2446 [ # # ]: 0 : if (rss_conf->rss_key_len != HW_HASH_KEY_SIZE) {
2447 : 0 : PMD_DRV_LOG_LINE(ERR,
2448 : : "Invalid hashkey length, should be %d bytes",
2449 : : HW_HASH_KEY_SIZE);
2450 : 0 : return -EINVAL;
2451 : : }
2452 : 0 : memcpy(vnic->rss_hash_key, rss_conf->rss_key, rss_conf->rss_key_len);
2453 : :
2454 : : /* Cache the hash key */
2455 : 0 : memcpy(bp->rss_conf.rss_key, rss_conf->rss_key, HW_HASH_KEY_SIZE);
2456 : :
2457 : 0 : rss_config:
2458 : 0 : rc = bnxt_hwrm_vnic_rss_cfg(bp, vnic);
2459 : 0 : return rc;
2460 : : }
2461 : :
2462 : 0 : static int bnxt_rss_hash_conf_get_op(struct rte_eth_dev *eth_dev,
2463 : : struct rte_eth_rss_conf *rss_conf)
2464 : : {
2465 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2466 : 0 : struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
2467 : : int len, rc;
2468 : :
2469 : 0 : rc = is_bnxt_in_error(bp);
2470 [ # # ]: 0 : if (rc)
2471 : : return rc;
2472 : :
2473 : : /* Return the RSS configuration of the default VNIC. */
2474 [ # # # # ]: 0 : if (vnic && vnic->rss_hash_key) {
2475 [ # # ]: 0 : if (rss_conf->rss_key) {
2476 : 0 : len = rss_conf->rss_key_len <= HW_HASH_KEY_SIZE ?
2477 : 0 : rss_conf->rss_key_len : HW_HASH_KEY_SIZE;
2478 : 0 : memcpy(rss_conf->rss_key, vnic->rss_hash_key, len);
2479 : : }
2480 : 0 : bnxt_hwrm_rss_to_rte_hash_conf(vnic, &rss_conf->rss_hf);
2481 : 0 : rss_conf->rss_hf |=
2482 : 0 : bnxt_hwrm_to_rte_rss_level(bp, vnic->hash_mode);
2483 : : } else {
2484 : 0 : rss_conf->rss_hf = 0;
2485 : : }
2486 : : return 0;
2487 : : }
2488 : :
2489 : 0 : static int bnxt_flow_ctrl_get_op(struct rte_eth_dev *dev,
2490 : : struct rte_eth_fc_conf *fc_conf)
2491 : : {
2492 : 0 : struct bnxt *bp = dev->data->dev_private;
2493 : : struct rte_eth_link link_info;
2494 : : int rc;
2495 : :
2496 : 0 : rc = is_bnxt_in_error(bp);
2497 [ # # ]: 0 : if (rc)
2498 : : return rc;
2499 : :
2500 : 0 : rc = bnxt_get_hwrm_link_config(bp, &link_info);
2501 [ # # ]: 0 : if (rc)
2502 : : return rc;
2503 : :
2504 : : memset(fc_conf, 0, sizeof(*fc_conf));
2505 [ # # ]: 0 : if (bp->link_info->auto_pause)
2506 : 0 : fc_conf->autoneg = 1;
2507 [ # # # # ]: 0 : switch (bp->link_info->pause) {
2508 : : case 0:
2509 : : fc_conf->mode = RTE_ETH_FC_NONE;
2510 : : break;
2511 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX:
2512 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2513 : 0 : break;
2514 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX:
2515 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2516 : 0 : break;
2517 : 0 : case (HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_TX |
2518 : : HWRM_PORT_PHY_QCFG_OUTPUT_PAUSE_RX):
2519 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
2520 : 0 : break;
2521 : : }
2522 : : return 0;
2523 : : }
2524 : :
2525 : 0 : static int bnxt_flow_ctrl_set_op(struct rte_eth_dev *dev,
2526 : : struct rte_eth_fc_conf *fc_conf)
2527 : : {
2528 : 0 : struct bnxt *bp = dev->data->dev_private;
2529 : : int rc;
2530 : :
2531 : 0 : rc = is_bnxt_in_error(bp);
2532 [ # # ]: 0 : if (rc)
2533 : : return rc;
2534 : :
2535 [ # # ]: 0 : if (!BNXT_SINGLE_PF(bp)) {
2536 : 0 : PMD_DRV_LOG_LINE(ERR,
2537 : : "Flow Control Settings cannot be modified on VF or on shared PF");
2538 : 0 : return -ENOTSUP;
2539 : : }
2540 : :
2541 [ # # # # : 0 : switch (fc_conf->mode) {
# ]
2542 : 0 : case RTE_ETH_FC_NONE:
2543 : 0 : bp->link_info->auto_pause = 0;
2544 : 0 : bp->link_info->force_pause = 0;
2545 : 0 : break;
2546 : 0 : case RTE_ETH_FC_RX_PAUSE:
2547 [ # # ]: 0 : if (fc_conf->autoneg) {
2548 : 0 : bp->link_info->auto_pause =
2549 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2550 : 0 : bp->link_info->force_pause = 0;
2551 : : } else {
2552 : 0 : bp->link_info->auto_pause = 0;
2553 : 0 : bp->link_info->force_pause =
2554 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2555 : : }
2556 : : break;
2557 : 0 : case RTE_ETH_FC_TX_PAUSE:
2558 [ # # ]: 0 : if (fc_conf->autoneg) {
2559 : 0 : bp->link_info->auto_pause =
2560 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
2561 : 0 : bp->link_info->force_pause = 0;
2562 : : } else {
2563 : 0 : bp->link_info->auto_pause = 0;
2564 : 0 : bp->link_info->force_pause =
2565 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
2566 : : }
2567 : : break;
2568 : 0 : case RTE_ETH_FC_FULL:
2569 [ # # ]: 0 : if (fc_conf->autoneg) {
2570 : 0 : bp->link_info->auto_pause =
2571 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX |
2572 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
2573 : 0 : bp->link_info->force_pause = 0;
2574 : : } else {
2575 : 0 : bp->link_info->auto_pause = 0;
2576 : 0 : bp->link_info->force_pause =
2577 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX |
2578 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
2579 : : }
2580 : : break;
2581 : : }
2582 : 0 : return bnxt_set_hwrm_link_config(bp, true);
2583 : : }
2584 : :
2585 : : /* Add UDP tunneling port */
2586 : : int
2587 : 0 : bnxt_udp_tunnel_port_add_op(struct rte_eth_dev *eth_dev,
2588 : : struct rte_eth_udp_tunnel *udp_tunnel)
2589 : : {
2590 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2591 : : uint16_t tunnel_type = 0;
2592 : : int rc = 0;
2593 : :
2594 : 0 : rc = is_bnxt_in_error(bp);
2595 [ # # ]: 0 : if (rc)
2596 : : return rc;
2597 : :
2598 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
2599 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
2600 [ # # ]: 0 : if (bp->vxlan_port_cnt) {
2601 : 0 : PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
2602 : : udp_tunnel->udp_port);
2603 [ # # ]: 0 : if (bp->vxlan_port != udp_tunnel->udp_port) {
2604 : 0 : PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
2605 : 0 : return -ENOSPC;
2606 : : }
2607 : 0 : bp->vxlan_port_cnt++;
2608 : 0 : return 0;
2609 : : }
2610 : : tunnel_type =
2611 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN;
2612 : : break;
2613 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
2614 [ # # ]: 0 : if (bp->geneve_port_cnt) {
2615 : 0 : PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
2616 : : udp_tunnel->udp_port);
2617 [ # # ]: 0 : if (bp->geneve_port != udp_tunnel->udp_port) {
2618 : 0 : PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
2619 : 0 : return -ENOSPC;
2620 : : }
2621 : 0 : bp->geneve_port_cnt++;
2622 : 0 : return 0;
2623 : : }
2624 : : tunnel_type =
2625 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE;
2626 : : break;
2627 : 0 : case RTE_ETH_TUNNEL_TYPE_ECPRI:
2628 [ # # ]: 0 : if (bp->ecpri_port_cnt) {
2629 : 0 : PMD_DRV_LOG_LINE(ERR, "Tunnel Port %d already programmed",
2630 : : udp_tunnel->udp_port);
2631 [ # # ]: 0 : if (bp->ecpri_port != udp_tunnel->udp_port) {
2632 : 0 : PMD_DRV_LOG_LINE(ERR, "Only one port allowed");
2633 : 0 : return -ENOSPC;
2634 : : }
2635 : 0 : bp->ecpri_port_cnt++;
2636 : 0 : return 0;
2637 : : }
2638 : : tunnel_type =
2639 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI;
2640 : : break;
2641 : 0 : default:
2642 : 0 : PMD_DRV_LOG_LINE(ERR, "Tunnel type is not supported");
2643 : 0 : return -ENOTSUP;
2644 : : }
2645 : 0 : rc = bnxt_hwrm_tunnel_dst_port_alloc(bp, udp_tunnel->udp_port,
2646 : : tunnel_type);
2647 : :
2648 [ # # ]: 0 : if (rc != 0)
2649 : : return rc;
2650 : :
2651 [ # # ]: 0 : if (tunnel_type ==
2652 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN)
2653 : 0 : bp->vxlan_port_cnt++;
2654 : :
2655 [ # # ]: 0 : if (tunnel_type ==
2656 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE)
2657 : 0 : bp->geneve_port_cnt++;
2658 : :
2659 [ # # ]: 0 : if (tunnel_type ==
2660 : : HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI)
2661 : 0 : bp->ecpri_port_cnt++;
2662 : :
2663 : : return rc;
2664 : : }
2665 : :
2666 : : int
2667 : 0 : bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
2668 : : struct rte_eth_udp_tunnel *udp_tunnel)
2669 : : {
2670 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2671 : : uint16_t tunnel_type = 0;
2672 : : uint16_t port = 0;
2673 : : int rc = 0;
2674 : :
2675 : 0 : rc = is_bnxt_in_error(bp);
2676 [ # # ]: 0 : if (rc)
2677 : : return rc;
2678 : :
2679 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
2680 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
2681 [ # # ]: 0 : if (!bp->vxlan_port_cnt) {
2682 : 0 : PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
2683 : 0 : return -EINVAL;
2684 : : }
2685 [ # # ]: 0 : if (bp->vxlan_port != udp_tunnel->udp_port) {
2686 : 0 : PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
2687 : : udp_tunnel->udp_port, bp->vxlan_port);
2688 : 0 : return -EINVAL;
2689 : : }
2690 [ # # ]: 0 : if (--bp->vxlan_port_cnt)
2691 : : return 0;
2692 : :
2693 : : tunnel_type =
2694 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN;
2695 : 0 : port = bp->vxlan_fw_dst_port_id;
2696 : 0 : break;
2697 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
2698 [ # # ]: 0 : if (!bp->geneve_port_cnt) {
2699 : 0 : PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
2700 : 0 : return -EINVAL;
2701 : : }
2702 [ # # ]: 0 : if (bp->geneve_port != udp_tunnel->udp_port) {
2703 : 0 : PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
2704 : : udp_tunnel->udp_port, bp->geneve_port);
2705 : 0 : return -EINVAL;
2706 : : }
2707 [ # # ]: 0 : if (--bp->geneve_port_cnt)
2708 : : return 0;
2709 : :
2710 : : tunnel_type =
2711 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE;
2712 : 0 : port = bp->geneve_fw_dst_port_id;
2713 : 0 : break;
2714 : 0 : case RTE_ETH_TUNNEL_TYPE_ECPRI:
2715 [ # # ]: 0 : if (!bp->ecpri_port_cnt) {
2716 : 0 : PMD_DRV_LOG_LINE(ERR, "No Tunnel port configured yet");
2717 : 0 : return -EINVAL;
2718 : : }
2719 [ # # ]: 0 : if (bp->ecpri_port != udp_tunnel->udp_port) {
2720 : 0 : PMD_DRV_LOG_LINE(ERR, "Req Port: %d. Configured port: %d",
2721 : : udp_tunnel->udp_port, bp->ecpri_port);
2722 : 0 : return -EINVAL;
2723 : : }
2724 [ # # ]: 0 : if (--bp->ecpri_port_cnt)
2725 : : return 0;
2726 : :
2727 : : tunnel_type =
2728 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI;
2729 : 0 : port = bp->ecpri_fw_dst_port_id;
2730 : 0 : break;
2731 : 0 : default:
2732 : 0 : PMD_DRV_LOG_LINE(ERR, "Tunnel type is not supported");
2733 : 0 : return -ENOTSUP;
2734 : : }
2735 : :
2736 : 0 : rc = bnxt_hwrm_tunnel_dst_port_free(bp, port, tunnel_type);
2737 : 0 : return rc;
2738 : : }
2739 : :
2740 : 0 : static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2741 : : {
2742 : : struct bnxt_filter_info *filter;
2743 : : struct bnxt_vnic_info *vnic;
2744 : : int rc = 0;
2745 : : uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2746 : :
2747 : 0 : vnic = bnxt_get_default_vnic(bp);
2748 : 0 : filter = STAILQ_FIRST(&vnic->filter);
2749 [ # # ]: 0 : while (filter) {
2750 : : /* Search for this matching MAC+VLAN filter */
2751 [ # # # # : 0 : if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id)) {
# # # # ]
2752 : : /* Delete the filter */
2753 : 0 : rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2754 [ # # ]: 0 : if (rc)
2755 : : return rc;
2756 [ # # # # : 0 : STAILQ_REMOVE(&vnic->filter, filter,
# # # # ]
2757 : : bnxt_filter_info, next);
2758 : 0 : bnxt_free_filter(bp, filter);
2759 : 0 : PMD_DRV_LOG_LINE(INFO,
2760 : : "Deleted vlan filter for %d",
2761 : : vlan_id);
2762 : 0 : return 0;
2763 : : }
2764 : 0 : filter = STAILQ_NEXT(filter, next);
2765 : : }
2766 : : return -ENOENT;
2767 : : }
2768 : :
2769 : 0 : static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
2770 : : {
2771 : : struct bnxt_filter_info *filter;
2772 : : struct bnxt_vnic_info *vnic;
2773 : : int rc = 0;
2774 : : uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
2775 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
2776 : : uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
2777 : :
2778 : : /* Implementation notes on the use of VNIC in this command:
2779 : : *
2780 : : * By default, these filters belong to default vnic for the function.
2781 : : * Once these filters are set up, only destination VNIC can be modified.
2782 : : * If the destination VNIC is not specified in this command,
2783 : : * then the HWRM shall only create an l2 context id.
2784 : : */
2785 : :
2786 : 0 : vnic = bnxt_get_default_vnic(bp);
2787 : 0 : filter = STAILQ_FIRST(&vnic->filter);
2788 : : /* Check if the VLAN has already been added */
2789 [ # # ]: 0 : while (filter) {
2790 [ # # # # : 0 : if (bnxt_vlan_filter_exists(bp, filter, chk, vlan_id))
# # # # ]
2791 : : return -EEXIST;
2792 : :
2793 : 0 : filter = STAILQ_NEXT(filter, next);
2794 : : }
2795 : :
2796 : : /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
2797 : : * command to create MAC+VLAN filter with the right flags, enables set.
2798 : : */
2799 : 0 : filter = bnxt_alloc_filter(bp);
2800 [ # # ]: 0 : if (!filter) {
2801 : 0 : PMD_DRV_LOG_LINE(ERR,
2802 : : "MAC/VLAN filter alloc failed");
2803 : 0 : return -ENOMEM;
2804 : : }
2805 : : /* MAC + VLAN ID filter */
2806 : : /* If l2_ivlan == 0 and l2_ivlan_mask != 0, only
2807 : : * untagged packets are received
2808 : : *
2809 : : * If l2_ivlan != 0 and l2_ivlan_mask != 0, untagged
2810 : : * packets and only the programmed vlan's packets are received
2811 : : */
2812 : 0 : filter->l2_ivlan = vlan_id;
2813 : 0 : filter->l2_ivlan_mask = 0x0FFF;
2814 : 0 : filter->enables |= en;
2815 : 0 : filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_OUTERMOST;
2816 : :
2817 : 0 : rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
2818 [ # # ]: 0 : if (rc) {
2819 : : /* Free the newly allocated filter as we were
2820 : : * not able to create the filter in hardware.
2821 : : */
2822 : 0 : bnxt_free_filter(bp, filter);
2823 : 0 : return rc;
2824 : : }
2825 : :
2826 : 0 : filter->mac_index = 0;
2827 : : /* Add this new filter to the list */
2828 [ # # ]: 0 : if (vlan_id == 0)
2829 [ # # ]: 0 : STAILQ_INSERT_HEAD(&vnic->filter, filter, next);
2830 : : else
2831 : 0 : STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
2832 : :
2833 : 0 : PMD_DRV_LOG_LINE(INFO,
2834 : : "Added Vlan filter for %d", vlan_id);
2835 : 0 : return rc;
2836 : : }
2837 : :
2838 : 0 : static int bnxt_vlan_filter_set_op(struct rte_eth_dev *eth_dev,
2839 : : uint16_t vlan_id, int on)
2840 : : {
2841 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
2842 : : int rc;
2843 : :
2844 : 0 : rc = is_bnxt_in_error(bp);
2845 [ # # ]: 0 : if (rc)
2846 : : return rc;
2847 : :
2848 [ # # ]: 0 : if (!eth_dev->data->dev_started) {
2849 : 0 : PMD_DRV_LOG_LINE(ERR, "port must be started before setting vlan");
2850 : 0 : return -EINVAL;
2851 : : }
2852 : :
2853 : : /* These operations apply to ALL existing MAC/VLAN filters */
2854 [ # # ]: 0 : if (on)
2855 : 0 : return bnxt_add_vlan_filter(bp, vlan_id);
2856 : : else
2857 : 0 : return bnxt_del_vlan_filter(bp, vlan_id);
2858 : : }
2859 : :
2860 : 0 : static int bnxt_del_dflt_mac_filter(struct bnxt *bp,
2861 : : struct bnxt_vnic_info *vnic)
2862 : : {
2863 : : struct bnxt_filter_info *filter;
2864 : : int rc;
2865 : :
2866 : 0 : filter = STAILQ_FIRST(&vnic->filter);
2867 [ # # ]: 0 : while (filter) {
2868 [ # # ]: 0 : if (filter->mac_index == 0 &&
2869 [ # # ]: 0 : !memcmp(filter->l2_addr, bp->mac_addr,
2870 : : RTE_ETHER_ADDR_LEN)) {
2871 : 0 : rc = bnxt_hwrm_clear_l2_filter(bp, filter);
2872 [ # # ]: 0 : if (!rc) {
2873 [ # # # # : 0 : STAILQ_REMOVE(&vnic->filter, filter,
# # # # ]
2874 : : bnxt_filter_info, next);
2875 : 0 : bnxt_free_filter(bp, filter);
2876 : : }
2877 : 0 : return rc;
2878 : : }
2879 : 0 : filter = STAILQ_NEXT(filter, next);
2880 : : }
2881 : : return 0;
2882 : : }
2883 : :
2884 : : static int
2885 : 0 : bnxt_config_vlan_hw_filter(struct bnxt *bp, uint64_t rx_offloads)
2886 : : {
2887 : : struct bnxt_vnic_info *vnic;
2888 : : unsigned int i;
2889 : : int rc;
2890 : :
2891 : 0 : vnic = bnxt_get_default_vnic(bp);
2892 [ # # ]: 0 : if (!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
2893 : : /* Remove any VLAN filters programmed */
2894 [ # # ]: 0 : for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2895 : 0 : bnxt_del_vlan_filter(bp, i);
2896 : :
2897 : 0 : rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2898 [ # # ]: 0 : if (rc)
2899 : : return rc;
2900 : : } else {
2901 : : /* Default filter will allow packets that match the
2902 : : * dest mac. So, it has to be deleted, otherwise, we
2903 : : * will endup receiving vlan packets for which the
2904 : : * filter is not programmed, when hw-vlan-filter
2905 : : * configuration is ON
2906 : : */
2907 : 0 : bnxt_del_dflt_mac_filter(bp, vnic);
2908 : : /* This filter will allow only untagged packets */
2909 : 0 : bnxt_add_vlan_filter(bp, 0);
2910 : : }
2911 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VLAN Filtering: %d",
2912 : : !!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER));
2913 : :
2914 : 0 : return 0;
2915 : : }
2916 : :
2917 : 0 : static int bnxt_free_one_vnic(struct bnxt *bp, uint16_t vnic_id)
2918 : : {
2919 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id];
2920 : : unsigned int i;
2921 : : int rc;
2922 : :
2923 : : /* Destroy vnic filters and vnic */
2924 [ # # ]: 0 : if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2925 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
2926 [ # # ]: 0 : for (i = 0; i < RTE_ETHER_MAX_VLAN_ID; i++)
2927 : 0 : bnxt_del_vlan_filter(bp, i);
2928 : : }
2929 : 0 : bnxt_del_dflt_mac_filter(bp, vnic);
2930 : :
2931 : 0 : rc = bnxt_hwrm_vnic_ctx_free(bp, vnic);
2932 [ # # ]: 0 : if (rc)
2933 : : return rc;
2934 : :
2935 : 0 : rc = bnxt_hwrm_vnic_free(bp, vnic);
2936 [ # # ]: 0 : if (rc)
2937 : : return rc;
2938 : :
2939 : 0 : rte_free(vnic->fw_grp_ids);
2940 : 0 : vnic->fw_grp_ids = NULL;
2941 : :
2942 : 0 : vnic->rx_queue_cnt = 0;
2943 : :
2944 : 0 : return 0;
2945 : : }
2946 : :
2947 : : static int
2948 : 0 : bnxt_config_vlan_hw_stripping(struct bnxt *bp, uint64_t rx_offloads)
2949 : : {
2950 : 0 : struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
2951 : : int rc;
2952 : :
2953 : : /* Destroy, recreate and reconfigure the default vnic */
2954 : 0 : rc = bnxt_free_one_vnic(bp, bp->vnic_queue_db.dflt_vnic_id);
2955 [ # # ]: 0 : if (rc)
2956 : : return rc;
2957 : :
2958 : : /* setup the default vnic details*/
2959 : 0 : bnxt_vnic_queue_db_update_dlft_vnic(bp);
2960 : :
2961 : 0 : rc = bnxt_setup_one_vnic(bp, bp->vnic_queue_db.dflt_vnic_id);
2962 [ # # ]: 0 : if (rc)
2963 : : return rc;
2964 : :
2965 [ # # ]: 0 : if (bp->eth_dev->data->dev_conf.rxmode.offloads &
2966 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
2967 : 0 : rc = bnxt_add_vlan_filter(bp, 0);
2968 [ # # ]: 0 : if (rc)
2969 : : return rc;
2970 : 0 : rc = bnxt_restore_vlan_filters(bp);
2971 [ # # ]: 0 : if (rc)
2972 : : return rc;
2973 : : } else {
2974 : 0 : rc = bnxt_add_mac_filter(bp, vnic, NULL, 0, 0);
2975 [ # # ]: 0 : if (rc)
2976 : : return rc;
2977 : : }
2978 : :
2979 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
2980 [ # # ]: 0 : if (rc)
2981 : : return rc;
2982 : :
2983 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VLAN Strip Offload: %d",
2984 : : !!(rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP));
2985 : :
2986 : 0 : return rc;
2987 : : }
2988 : :
2989 : : static int
2990 : 0 : bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask)
2991 : : {
2992 : 0 : uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
2993 : 0 : struct bnxt *bp = dev->data->dev_private;
2994 : : int rc = 0;
2995 : :
2996 : 0 : rc = is_bnxt_in_error(bp);
2997 [ # # ]: 0 : if (rc)
2998 : : return rc;
2999 : :
3000 : : /* Filter settings will get applied when port is started */
3001 [ # # ]: 0 : if (!dev->data->dev_started)
3002 : : return 0;
3003 : :
3004 : : /* For P7 platform, cannot support if truflow is enabled */
3005 [ # # # # : 0 : if (BNXT_TRUFLOW_EN(bp) && BNXT_CHIP_P7(bp))
# # ]
3006 : : return rc;
3007 : :
3008 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
3009 : : /* Enable or disable VLAN filtering */
3010 : 0 : rc = bnxt_config_vlan_hw_filter(bp, rx_offloads);
3011 [ # # ]: 0 : if (rc)
3012 : : return rc;
3013 : : }
3014 : :
3015 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
3016 : : /* Enable or disable VLAN stripping */
3017 : 0 : rc = bnxt_config_vlan_hw_stripping(bp, rx_offloads);
3018 [ # # ]: 0 : if (rc)
3019 : : return rc;
3020 : : }
3021 : :
3022 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
3023 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
3024 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Extend VLAN supported");
3025 : : else
3026 : 0 : PMD_DRV_LOG_LINE(INFO, "Extend VLAN unsupported");
3027 : : }
3028 : :
3029 : : return 0;
3030 : : }
3031 : :
3032 : : static int
3033 : 0 : bnxt_vlan_tpid_set_op(struct rte_eth_dev *dev, enum rte_vlan_type vlan_type,
3034 : : uint16_t tpid)
3035 : : {
3036 : 0 : struct bnxt *bp = dev->data->dev_private;
3037 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
3038 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3039 : :
3040 [ # # ]: 0 : if (vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
3041 : : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) {
3042 : 0 : PMD_DRV_LOG_LINE(ERR,
3043 : : "Unsupported vlan type.");
3044 : 0 : return -EINVAL;
3045 : : }
3046 [ # # ]: 0 : if (!qinq) {
3047 : 0 : PMD_DRV_LOG_LINE(ERR,
3048 : : "QinQ not enabled. Needs to be ON as we can "
3049 : : "accelerate only outer vlan");
3050 : 0 : return -EINVAL;
3051 : : }
3052 : :
3053 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER) {
3054 [ # # # # : 0 : switch (tpid) {
# # ]
3055 : 0 : case RTE_ETHER_TYPE_QINQ:
3056 : 0 : bp->outer_tpid_bd =
3057 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID88A8;
3058 : 0 : break;
3059 : 0 : case RTE_ETHER_TYPE_VLAN:
3060 : 0 : bp->outer_tpid_bd =
3061 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
3062 : 0 : break;
3063 : 0 : case RTE_ETHER_TYPE_QINQ1:
3064 : 0 : bp->outer_tpid_bd =
3065 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID9100;
3066 : 0 : break;
3067 : 0 : case RTE_ETHER_TYPE_QINQ2:
3068 : 0 : bp->outer_tpid_bd =
3069 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID9200;
3070 : 0 : break;
3071 : 0 : case RTE_ETHER_TYPE_QINQ3:
3072 : 0 : bp->outer_tpid_bd =
3073 : : TX_BD_LONG_CFA_META_VLAN_TPID_TPID9300;
3074 : 0 : break;
3075 : 0 : default:
3076 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid TPID: %x", tpid);
3077 : 0 : return -EINVAL;
3078 : : }
3079 : 0 : bp->outer_tpid_bd |= tpid;
3080 : 0 : PMD_DRV_LOG_LINE(INFO, "outer_tpid_bd = %x", bp->outer_tpid_bd);
3081 : : } else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER) {
3082 : 0 : PMD_DRV_LOG_LINE(ERR,
3083 : : "Can accelerate only outer vlan in QinQ");
3084 : 0 : return -EINVAL;
3085 : : }
3086 : :
3087 : 0 : return 0;
3088 : : }
3089 : :
3090 : : static int
3091 : 0 : bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
3092 : : struct rte_ether_addr *addr)
3093 : : {
3094 : 0 : struct bnxt *bp = dev->data->dev_private;
3095 : : /* Default Filter is tied to VNIC 0 */
3096 : 0 : struct bnxt_vnic_info *vnic = bnxt_get_default_vnic(bp);
3097 : : int rc;
3098 : :
3099 : 0 : rc = is_bnxt_in_error(bp);
3100 [ # # ]: 0 : if (rc)
3101 : : return rc;
3102 : :
3103 [ # # ]: 0 : if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
3104 : : return -EPERM;
3105 : :
3106 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr))
3107 : : return -EINVAL;
3108 : :
3109 : : /* Filter settings will get applied when port is started */
3110 [ # # ]: 0 : if (!dev->data->dev_started)
3111 : : return 0;
3112 : :
3113 : : /* Check if the requested MAC is already added */
3114 [ # # ]: 0 : if (memcmp(addr, bp->mac_addr, RTE_ETHER_ADDR_LEN) == 0)
3115 : : return 0;
3116 : :
3117 : : /* Destroy filter and re-create it */
3118 : 0 : bnxt_del_dflt_mac_filter(bp, vnic);
3119 : :
3120 : : memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
3121 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
3122 : : /* This filter will allow only untagged packets */
3123 : 0 : rc = bnxt_add_vlan_filter(bp, 0);
3124 : : } else {
3125 : 0 : rc = bnxt_add_mac_filter(bp, vnic, addr, 0, 0);
3126 : : }
3127 : :
3128 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Set MAC addr");
3129 : 0 : return rc;
3130 : : }
3131 : :
3132 : : static int
3133 : 0 : bnxt_dev_set_mc_addr_list_op(struct rte_eth_dev *eth_dev,
3134 : : struct rte_ether_addr *mc_addr_set,
3135 : : uint32_t nb_mc_addr)
3136 : : {
3137 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
3138 : : struct bnxt_vnic_info *vnic;
3139 : : uint32_t i = 0;
3140 : : int rc;
3141 : :
3142 : 0 : rc = is_bnxt_in_error(bp);
3143 [ # # ]: 0 : if (rc)
3144 : : return rc;
3145 : :
3146 : 0 : vnic = bnxt_get_default_vnic(bp);
3147 : :
3148 : 0 : bp->nb_mc_addr = nb_mc_addr;
3149 : :
3150 [ # # ]: 0 : if (nb_mc_addr > BNXT_MAX_MC_ADDRS) {
3151 : 0 : PMD_DRV_LOG_LINE(INFO, "Number of Mcast MACs added (%u) exceeded Max supported (%u)",
3152 : : nb_mc_addr, BNXT_MAX_MC_ADDRS);
3153 : 0 : PMD_DRV_LOG_LINE(INFO, "Turning on Mcast promiscuous mode");
3154 : 0 : vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
3155 : 0 : goto allmulti;
3156 : : }
3157 : :
3158 : : /* TODO Check for Duplicate mcast addresses */
3159 [ # # ]: 0 : if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
3160 : 0 : PMD_DRV_LOG_LINE(INFO, "Turning off Mcast promiscuous mode");
3161 : 0 : vnic->flags &= ~BNXT_VNIC_INFO_ALLMULTI;
3162 : : }
3163 [ # # ]: 0 : for (i = 0; i < nb_mc_addr; i++)
3164 : 0 : rte_ether_addr_copy(&mc_addr_set[i], &bp->mcast_addr_list[i]);
3165 : :
3166 [ # # ]: 0 : if (bp->nb_mc_addr)
3167 : 0 : vnic->flags |= BNXT_VNIC_INFO_MCAST;
3168 : : else
3169 : 0 : vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
3170 : :
3171 : : allmulti:
3172 : 0 : rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
3173 [ # # # # ]: 0 : if (rc == -ENOSPC && (vnic->flags & BNXT_VNIC_INFO_MCAST)) {
3174 : : /* If MCAST addition failed because FW ran out of
3175 : : * multicast filters, enable all multicast mode.
3176 : : */
3177 : 0 : vnic->flags &= ~BNXT_VNIC_INFO_MCAST;
3178 : 0 : vnic->flags |= BNXT_VNIC_INFO_ALLMULTI;
3179 : 0 : goto allmulti;
3180 : : }
3181 : :
3182 : : return rc;
3183 : : }
3184 : :
3185 : : static int
3186 : 0 : bnxt_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3187 : : {
3188 : 0 : struct bnxt *bp = dev->data->dev_private;
3189 : 0 : uint8_t fw_major = (bp->fw_ver >> 24) & 0xff;
3190 : 0 : uint8_t fw_minor = (bp->fw_ver >> 16) & 0xff;
3191 : 0 : uint8_t fw_updt = (bp->fw_ver >> 8) & 0xff;
3192 : : uint8_t fw_rsvd = bp->fw_ver & 0xff;
3193 : : int ret;
3194 : :
3195 [ # # ]: 0 : ret = snprintf(fw_version, fw_size, "%d.%d.%d.%d",
3196 : : fw_major, fw_minor, fw_updt, fw_rsvd);
3197 [ # # ]: 0 : if (ret < 0)
3198 : : return -EINVAL;
3199 : :
3200 : 0 : ret += 1; /* add the size of '\0' */
3201 [ # # ]: 0 : if (fw_size < (size_t)ret)
3202 : : return ret;
3203 : : else
3204 : 0 : return 0;
3205 : : }
3206 : :
3207 : : static void
3208 : 0 : bnxt_rxq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
3209 : : struct rte_eth_rxq_info *qinfo)
3210 : : {
3211 : 0 : struct bnxt *bp = dev->data->dev_private;
3212 : : struct bnxt_rx_queue *rxq;
3213 : :
3214 [ # # ]: 0 : if (is_bnxt_in_error(bp))
3215 : : return;
3216 : :
3217 : 0 : rxq = dev->data->rx_queues[queue_id];
3218 : :
3219 : 0 : qinfo->mp = rxq->mb_pool;
3220 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
3221 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
3222 : :
3223 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
3224 : 0 : qinfo->conf.rx_drop_en = rxq->drop_en;
3225 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
3226 : 0 : qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
3227 : : }
3228 : :
3229 : : static void
3230 : 0 : bnxt_txq_info_get_op(struct rte_eth_dev *dev, uint16_t queue_id,
3231 : : struct rte_eth_txq_info *qinfo)
3232 : : {
3233 : 0 : struct bnxt *bp = dev->data->dev_private;
3234 : : struct bnxt_tx_queue *txq;
3235 : :
3236 [ # # ]: 0 : if (is_bnxt_in_error(bp))
3237 : : return;
3238 : :
3239 : 0 : txq = dev->data->tx_queues[queue_id];
3240 : :
3241 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
3242 : :
3243 : 0 : qinfo->conf.tx_thresh.pthresh = txq->pthresh;
3244 : 0 : qinfo->conf.tx_thresh.hthresh = txq->hthresh;
3245 : 0 : qinfo->conf.tx_thresh.wthresh = txq->wthresh;
3246 : :
3247 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
3248 : 0 : qinfo->conf.tx_rs_thresh = 0;
3249 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
3250 : 0 : qinfo->conf.offloads = txq->offloads;
3251 : : }
3252 : :
3253 : : static const struct {
3254 : : eth_rx_burst_t pkt_burst;
3255 : : const char *info;
3256 : : } bnxt_rx_burst_info[] = {
3257 : : {bnxt_recv_pkts, "Scalar"},
3258 : : #if defined(RTE_ARCH_X86)
3259 : : {bnxt_crx_pkts_vec, "Vector SSE"},
3260 : : {bnxt_recv_pkts_vec, "Vector SSE"},
3261 : : {bnxt_crx_pkts_vec_avx2, "Vector AVX2"},
3262 : : {bnxt_recv_pkts_vec_avx2, "Vector AVX2"},
3263 : : #endif
3264 : : #if defined(RTE_ARCH_ARM64)
3265 : : {bnxt_recv_pkts_vec, "Vector Neon"},
3266 : : #endif
3267 : : };
3268 : :
3269 : : static int
3270 : 0 : bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3271 : : struct rte_eth_burst_mode *mode)
3272 : : {
3273 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
3274 : : size_t i;
3275 : :
3276 [ # # ]: 0 : for (i = 0; i < RTE_DIM(bnxt_rx_burst_info); i++) {
3277 [ # # ]: 0 : if (pkt_burst == bnxt_rx_burst_info[i].pkt_burst) {
3278 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3279 : 0 : bnxt_rx_burst_info[i].info);
3280 : 0 : return 0;
3281 : : }
3282 : : }
3283 : :
3284 : : return -EINVAL;
3285 : : }
3286 : :
3287 : : static const struct {
3288 : : eth_tx_burst_t pkt_burst;
3289 : : const char *info;
3290 : : } bnxt_tx_burst_info[] = {
3291 : : {bnxt_xmit_pkts, "Scalar"},
3292 : : #if defined(RTE_ARCH_X86)
3293 : : {bnxt_xmit_pkts_vec, "Vector SSE"},
3294 : : {bnxt_xmit_pkts_vec_avx2, "Vector AVX2"},
3295 : : #endif
3296 : : #if defined(RTE_ARCH_ARM64)
3297 : : {bnxt_xmit_pkts_vec, "Vector Neon"},
3298 : : #endif
3299 : : };
3300 : :
3301 : : static int
3302 : 0 : bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
3303 : : struct rte_eth_burst_mode *mode)
3304 : : {
3305 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
3306 : : size_t i;
3307 : :
3308 [ # # ]: 0 : for (i = 0; i < RTE_DIM(bnxt_tx_burst_info); i++) {
3309 [ # # ]: 0 : if (pkt_burst == bnxt_tx_burst_info[i].pkt_burst) {
3310 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
3311 : 0 : bnxt_tx_burst_info[i].info);
3312 : 0 : return 0;
3313 : : }
3314 : : }
3315 : :
3316 : : return -EINVAL;
3317 : : }
3318 : :
3319 : 0 : int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
3320 : : {
3321 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
3322 : : uint32_t rc = 0;
3323 : :
3324 : 0 : rc = is_bnxt_in_error(bp);
3325 [ # # ]: 0 : if (rc)
3326 : : return rc;
3327 : :
3328 : : /* Return if port is active */
3329 [ # # ]: 0 : if (eth_dev->data->dev_started) {
3330 : 0 : PMD_DRV_LOG_LINE(ERR, "Stop port before changing MTU");
3331 : 0 : return -EBUSY;
3332 : : }
3333 : :
3334 : : /* Exit if receive queues are not configured yet */
3335 [ # # ]: 0 : if (!eth_dev->data->nb_rx_queues)
3336 : : return -ENOTSUP;
3337 : :
3338 : : /* Is there a change in mtu setting? */
3339 [ # # ]: 0 : if (eth_dev->data->mtu == new_mtu)
3340 : : return rc;
3341 : :
3342 [ # # ]: 0 : if (new_mtu > RTE_ETHER_MTU)
3343 : 0 : bp->flags |= BNXT_FLAG_JUMBO;
3344 : : else
3345 : 0 : bp->flags &= ~BNXT_FLAG_JUMBO;
3346 : :
3347 : 0 : rc = bnxt_vnic_mru_config(bp, new_mtu);
3348 [ # # ]: 0 : if (rc) {
3349 : 0 : PMD_DRV_LOG_LINE(ERR, "failed to update mtu in vnic context");
3350 : 0 : return rc;
3351 : : }
3352 : :
3353 [ # # ]: 0 : if (bnxt_hwrm_config_host_mtu(bp))
3354 : 0 : PMD_DRV_LOG_LINE(WARNING, "Failed to configure host MTU");
3355 : :
3356 : 0 : PMD_DRV_LOG_LINE(INFO, "New MTU is %d", new_mtu);
3357 : :
3358 : 0 : return rc;
3359 : : }
3360 : :
3361 : : static int
3362 : 0 : bnxt_vlan_pvid_set_op(struct rte_eth_dev *dev, uint16_t pvid, int on)
3363 : : {
3364 : 0 : struct bnxt *bp = dev->data->dev_private;
3365 : 0 : uint16_t vlan = bp->vlan;
3366 : : int rc;
3367 : :
3368 : 0 : rc = is_bnxt_in_error(bp);
3369 [ # # ]: 0 : if (rc)
3370 : : return rc;
3371 : :
3372 [ # # ]: 0 : if (!BNXT_SINGLE_PF(bp)) {
3373 : 0 : PMD_DRV_LOG_LINE(ERR, "PVID cannot be modified on VF or on shared PF");
3374 : 0 : return -ENOTSUP;
3375 : : }
3376 [ # # ]: 0 : bp->vlan = on ? pvid : 0;
3377 : :
3378 : 0 : rc = bnxt_hwrm_set_default_vlan(bp, 0, 0);
3379 [ # # ]: 0 : if (rc)
3380 : 0 : bp->vlan = vlan;
3381 : : return rc;
3382 : : }
3383 : :
3384 : : static int
3385 : 0 : bnxt_dev_led_on_op(struct rte_eth_dev *dev)
3386 : : {
3387 : 0 : struct bnxt *bp = dev->data->dev_private;
3388 : : int rc;
3389 : :
3390 : 0 : rc = is_bnxt_in_error(bp);
3391 [ # # ]: 0 : if (rc)
3392 : : return rc;
3393 : :
3394 : 0 : return bnxt_hwrm_port_led_cfg(bp, true);
3395 : : }
3396 : :
3397 : : static int
3398 : 0 : bnxt_dev_led_off_op(struct rte_eth_dev *dev)
3399 : : {
3400 : 0 : struct bnxt *bp = dev->data->dev_private;
3401 : : int rc;
3402 : :
3403 : 0 : rc = is_bnxt_in_error(bp);
3404 [ # # ]: 0 : if (rc)
3405 : : return rc;
3406 : :
3407 : 0 : return bnxt_hwrm_port_led_cfg(bp, false);
3408 : : }
3409 : :
3410 : : static uint32_t
3411 : 0 : bnxt_rx_queue_count_op(void *rx_queue)
3412 : : {
3413 : : struct bnxt *bp;
3414 : : struct bnxt_cp_ring_info *cpr;
3415 : : uint32_t desc = 0, raw_cons, cp_ring_size;
3416 : : struct bnxt_rx_queue *rxq;
3417 : : struct rx_pkt_cmpl *rxcmp;
3418 : : int rc;
3419 : :
3420 : : rxq = rx_queue;
3421 : 0 : bp = rxq->bp;
3422 : :
3423 : 0 : rc = is_bnxt_in_error(bp);
3424 [ # # ]: 0 : if (rc)
3425 : 0 : return rc;
3426 : :
3427 : 0 : cpr = rxq->cp_ring;
3428 : 0 : raw_cons = cpr->cp_raw_cons;
3429 : 0 : cp_ring_size = cpr->cp_ring_struct->ring_size;
3430 : :
3431 : : while (1) {
3432 : : uint32_t agg_cnt, cons, cmpl_type;
3433 : :
3434 : 0 : cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
3435 [ # # ]: 0 : rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
3436 : :
3437 : : if (!bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
3438 : : break;
3439 : :
3440 : 0 : cmpl_type = CMP_TYPE(rxcmp);
3441 : :
3442 [ # # # ]: 0 : switch (cmpl_type) {
3443 : 0 : case CMPL_BASE_TYPE_RX_L2:
3444 : : case CMPL_BASE_TYPE_RX_L2_V2:
3445 : 0 : agg_cnt = BNXT_RX_L2_AGG_BUFS(rxcmp);
3446 : 0 : raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
3447 : 0 : desc++;
3448 : 0 : break;
3449 : :
3450 : 0 : case CMPL_BASE_TYPE_RX_TPA_END:
3451 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(rxq->bp)) {
3452 : : struct rx_tpa_v2_end_cmpl_hi *p5_tpa_end;
3453 : :
3454 : : p5_tpa_end = (void *)rxcmp;
3455 : 0 : agg_cnt = BNXT_TPA_END_AGG_BUFS_TH(p5_tpa_end);
3456 : : } else {
3457 : : struct rx_tpa_end_cmpl *tpa_end;
3458 : :
3459 : : tpa_end = (void *)rxcmp;
3460 : 0 : agg_cnt = BNXT_TPA_END_AGG_BUFS(tpa_end);
3461 : : }
3462 : :
3463 : 0 : raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
3464 : 0 : desc++;
3465 : 0 : break;
3466 : :
3467 : 0 : default:
3468 : 0 : raw_cons += CMP_LEN(cmpl_type);
3469 : : }
3470 : : }
3471 : :
3472 : : return desc;
3473 : : }
3474 : :
3475 : : static int
3476 : 0 : bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)
3477 : : {
3478 : : struct bnxt_rx_queue *rxq = rx_queue;
3479 : : struct bnxt_cp_ring_info *cpr;
3480 : : struct bnxt_rx_ring_info *rxr;
3481 : : uint32_t desc, raw_cons, cp_ring_size;
3482 : 0 : struct bnxt *bp = rxq->bp;
3483 : : struct rx_pkt_cmpl *rxcmp;
3484 : : int rc;
3485 : :
3486 : 0 : rc = is_bnxt_in_error(bp);
3487 [ # # ]: 0 : if (rc)
3488 : : return rc;
3489 : :
3490 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc)
3491 : : return -EINVAL;
3492 : :
3493 : 0 : rxr = rxq->rx_ring;
3494 : 0 : cpr = rxq->cp_ring;
3495 : 0 : cp_ring_size = cpr->cp_ring_struct->ring_size;
3496 : :
3497 : : /*
3498 : : * For the vector receive case, the completion at the requested
3499 : : * offset can be indexed directly.
3500 : : */
3501 : : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
3502 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_RX_VECTOR_PKT_MODE) {
3503 : : struct rx_pkt_cmpl *rxcmp;
3504 : : uint32_t cons;
3505 : :
3506 : : /* Check status of completion descriptor. */
3507 : 0 : raw_cons = cpr->cp_raw_cons +
3508 : 0 : offset * CMP_LEN(CMPL_BASE_TYPE_RX_L2);
3509 : 0 : cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
3510 [ # # ]: 0 : rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
3511 : :
3512 : : if (bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
3513 : 0 : return RTE_ETH_RX_DESC_DONE;
3514 : :
3515 : : /* Check whether rx desc has an mbuf attached. */
3516 : 0 : cons = RING_CMP(rxr->rx_ring_struct, raw_cons / 2);
3517 [ # # ]: 0 : if (cons >= rxq->rxrearm_start &&
3518 [ # # ]: 0 : cons < rxq->rxrearm_start + rxq->rxrearm_nb) {
3519 : : return RTE_ETH_RX_DESC_UNAVAIL;
3520 : : }
3521 : :
3522 : 0 : return RTE_ETH_RX_DESC_AVAIL;
3523 : : }
3524 : : #endif
3525 : :
3526 : : /*
3527 : : * For the non-vector receive case, scan the completion ring to
3528 : : * locate the completion descriptor for the requested offset.
3529 : : */
3530 : 0 : raw_cons = cpr->cp_raw_cons;
3531 : : desc = 0;
3532 : : while (1) {
3533 : : uint32_t agg_cnt, cons, cmpl_type;
3534 : :
3535 : 0 : cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
3536 [ # # ]: 0 : rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
3537 : :
3538 : : if (!bnxt_cpr_cmp_valid(rxcmp, raw_cons, cp_ring_size))
3539 : : break;
3540 : :
3541 : 0 : cmpl_type = CMP_TYPE(rxcmp);
3542 : :
3543 [ # # # ]: 0 : switch (cmpl_type) {
3544 : 0 : case CMPL_BASE_TYPE_RX_L2:
3545 : : case CMPL_BASE_TYPE_RX_L2_V2:
3546 [ # # ]: 0 : if (desc == offset) {
3547 : 0 : cons = rxcmp->opaque;
3548 [ # # ]: 0 : if (rxr->rx_buf_ring[cons])
3549 : : return RTE_ETH_RX_DESC_DONE;
3550 : : else
3551 : 0 : return RTE_ETH_RX_DESC_UNAVAIL;
3552 : : }
3553 : 0 : agg_cnt = BNXT_RX_L2_AGG_BUFS(rxcmp);
3554 : 0 : raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
3555 : 0 : desc++;
3556 : 0 : break;
3557 : :
3558 : 0 : case CMPL_BASE_TYPE_RX_TPA_END:
3559 [ # # ]: 0 : if (desc == offset)
3560 : : return RTE_ETH_RX_DESC_DONE;
3561 : :
3562 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(rxq->bp)) {
3563 : : struct rx_tpa_v2_end_cmpl_hi *p5_tpa_end;
3564 : :
3565 : : p5_tpa_end = (void *)rxcmp;
3566 : 0 : agg_cnt = BNXT_TPA_END_AGG_BUFS_TH(p5_tpa_end);
3567 : : } else {
3568 : : struct rx_tpa_end_cmpl *tpa_end;
3569 : :
3570 : : tpa_end = (void *)rxcmp;
3571 : 0 : agg_cnt = BNXT_TPA_END_AGG_BUFS(tpa_end);
3572 : : }
3573 : :
3574 : 0 : raw_cons = raw_cons + CMP_LEN(cmpl_type) + agg_cnt;
3575 : 0 : desc++;
3576 : 0 : break;
3577 : :
3578 : 0 : default:
3579 : 0 : raw_cons += CMP_LEN(cmpl_type);
3580 : : }
3581 : : }
3582 : :
3583 : : return RTE_ETH_RX_DESC_AVAIL;
3584 : : }
3585 : :
3586 : : static int
3587 : 0 : bnxt_tx_descriptor_status_op(void *tx_queue, uint16_t offset)
3588 : : {
3589 : : struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
3590 : 0 : struct bnxt_cp_ring_info *cpr = txq->cp_ring;
3591 : : uint32_t ring_mask, raw_cons, nb_tx_pkts = 0;
3592 : : struct cmpl_base *cp_desc_ring;
3593 : : int rc;
3594 : :
3595 : 0 : rc = is_bnxt_in_error(txq->bp);
3596 [ # # ]: 0 : if (rc)
3597 : : return rc;
3598 : :
3599 [ # # ]: 0 : if (offset >= txq->nb_tx_desc)
3600 : : return -EINVAL;
3601 : :
3602 : : /* Return "desc done" if descriptor is available for use. */
3603 [ # # ]: 0 : if (bnxt_tx_bds_in_hw(txq) <= offset)
3604 : : return RTE_ETH_TX_DESC_DONE;
3605 : :
3606 : 0 : raw_cons = cpr->cp_raw_cons;
3607 : 0 : cp_desc_ring = cpr->cp_desc_ring;
3608 : 0 : ring_mask = cpr->cp_ring_struct->ring_mask;
3609 : :
3610 : : /* Check to see if hw has posted a completion for the descriptor. */
3611 : 0 : while (1) {
3612 : : struct tx_cmpl *txcmp;
3613 : : uint32_t cons;
3614 : :
3615 : 0 : cons = RING_CMPL(ring_mask, raw_cons);
3616 : 0 : txcmp = (struct tx_cmpl *)&cp_desc_ring[cons];
3617 : :
3618 [ # # ]: 0 : if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
3619 : : break;
3620 : :
3621 [ # # ]: 0 : if (CMP_TYPE(txcmp) == TX_CMPL_TYPE_TX_L2)
3622 : 0 : nb_tx_pkts += rte_le_to_cpu_32(txcmp->opaque);
3623 : :
3624 [ # # ]: 0 : if (nb_tx_pkts > offset)
3625 : : return RTE_ETH_TX_DESC_DONE;
3626 : :
3627 : 0 : raw_cons = NEXT_RAW_CMP(raw_cons);
3628 : : }
3629 : :
3630 : : /* Descriptor is pending transmit, not yet completed by hardware. */
3631 : : return RTE_ETH_TX_DESC_FULL;
3632 : : }
3633 : :
3634 : : int
3635 : 0 : bnxt_flow_ops_get_op(struct rte_eth_dev *dev,
3636 : : const struct rte_flow_ops **ops)
3637 : : {
3638 : 0 : struct bnxt *bp = dev->data->dev_private;
3639 : : int ret = 0;
3640 : :
3641 [ # # ]: 0 : if (!bp)
3642 : : return -EIO;
3643 : :
3644 [ # # ]: 0 : if (rte_eth_dev_is_repr(dev)) {
3645 : : struct bnxt_representor *vfr = dev->data->dev_private;
3646 : 0 : bp = vfr->parent_dev->data->dev_private;
3647 : : /* parent is deleted while children are still valid */
3648 [ # # ]: 0 : if (!bp) {
3649 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR Error",
3650 : : dev->data->port_id);
3651 : 0 : return -EIO;
3652 : : }
3653 : : }
3654 : :
3655 : 0 : ret = is_bnxt_in_error(bp);
3656 [ # # ]: 0 : if (ret)
3657 : : return ret;
3658 : :
3659 : : /* PMD supports thread-safe flow operations. rte_flow API
3660 : : * functions can avoid mutex for multi-thread safety.
3661 : : */
3662 : 0 : dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
3663 : :
3664 : : if (bnxt_enable_ulp(bp))
3665 : 0 : *ops = &bnxt_ulp_rte_flow_ops;
3666 : : else
3667 : 0 : *ops = &bnxt_flow_ops;
3668 : :
3669 : : return ret;
3670 : : }
3671 : :
3672 : : static const uint32_t *
3673 : 0 : bnxt_dev_supported_ptypes_get_op(struct rte_eth_dev *dev,
3674 : : size_t *no_of_elements)
3675 : : {
3676 : : static const uint32_t ptypes[] = {
3677 : : RTE_PTYPE_L2_ETHER_VLAN,
3678 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
3679 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
3680 : : RTE_PTYPE_L4_ICMP,
3681 : : RTE_PTYPE_L4_TCP,
3682 : : RTE_PTYPE_L4_UDP,
3683 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
3684 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
3685 : : RTE_PTYPE_INNER_L4_ICMP,
3686 : : RTE_PTYPE_INNER_L4_TCP,
3687 : : RTE_PTYPE_INNER_L4_UDP,
3688 : : };
3689 : :
3690 [ # # ]: 0 : if (!dev->rx_pkt_burst)
3691 : : return NULL;
3692 : :
3693 : 0 : *no_of_elements = RTE_DIM(ptypes);
3694 : 0 : return ptypes;
3695 : : }
3696 : :
3697 : : static int bnxt_map_regs(struct bnxt *bp, uint32_t *reg_arr, int count,
3698 : : int reg_win)
3699 : : {
3700 : 0 : uint32_t reg_base = *reg_arr & 0xfffff000;
3701 : : uint32_t win_off;
3702 : : int i;
3703 : :
3704 [ # # # # ]: 0 : for (i = 0; i < count; i++) {
3705 [ # # # # ]: 0 : if ((reg_arr[i] & 0xfffff000) != reg_base)
3706 : : return -ERANGE;
3707 : : }
3708 : : win_off = BNXT_GRCPF_REG_WINDOW_BASE_OUT + (reg_win - 1) * 4;
3709 : 0 : rte_write32(reg_base, (uint8_t *)bp->bar0 + win_off);
3710 : : return 0;
3711 : : }
3712 : :
3713 : 0 : static int bnxt_map_ptp_regs(struct bnxt *bp)
3714 : : {
3715 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3716 : : uint32_t *reg_arr;
3717 : : int rc, i;
3718 : :
3719 : 0 : reg_arr = ptp->rx_regs;
3720 : : rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_RX_REGS, 5);
3721 : : if (rc)
3722 : : return rc;
3723 : :
3724 : 0 : reg_arr = ptp->tx_regs;
3725 : : rc = bnxt_map_regs(bp, reg_arr, BNXT_PTP_TX_REGS, 6);
3726 : : if (rc)
3727 : : return rc;
3728 : :
3729 [ # # ]: 0 : for (i = 0; i < BNXT_PTP_RX_REGS; i++)
3730 : 0 : ptp->rx_mapped_regs[i] = 0x5000 + (ptp->rx_regs[i] & 0xfff);
3731 : :
3732 [ # # ]: 0 : for (i = 0; i < BNXT_PTP_TX_REGS; i++)
3733 : 0 : ptp->tx_mapped_regs[i] = 0x6000 + (ptp->tx_regs[i] & 0xfff);
3734 : :
3735 : : return 0;
3736 : : }
3737 : :
3738 : : static void bnxt_unmap_ptp_regs(struct bnxt *bp)
3739 : : {
3740 : 0 : rte_write32(0, (uint8_t *)bp->bar0 +
3741 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 16);
3742 : 0 : rte_write32(0, (uint8_t *)bp->bar0 +
3743 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 20);
3744 : 0 : }
3745 : :
3746 : : static uint64_t bnxt_cc_read(struct bnxt *bp)
3747 : : {
3748 : : uint64_t ns;
3749 : :
3750 : 0 : ns = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3751 : : BNXT_GRCPF_REG_SYNC_TIME));
3752 : 0 : ns |= (uint64_t)(rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3753 : 0 : BNXT_GRCPF_REG_SYNC_TIME + 4))) << 32;
3754 : : return ns;
3755 : : }
3756 : :
3757 : 0 : static int bnxt_get_tx_ts(struct bnxt *bp, uint64_t *ts)
3758 : : {
3759 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3760 : : uint32_t fifo;
3761 : :
3762 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3763 : : ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3764 [ # # ]: 0 : if (fifo & BNXT_PTP_TX_FIFO_EMPTY)
3765 : : return -EAGAIN;
3766 : :
3767 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3768 : : ptp->tx_mapped_regs[BNXT_PTP_TX_FIFO]));
3769 : 0 : *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3770 : : ptp->tx_mapped_regs[BNXT_PTP_TX_TS_L]));
3771 : 0 : *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3772 : 0 : ptp->tx_mapped_regs[BNXT_PTP_TX_TS_H])) << 32;
3773 : 0 : rte_read32((uint8_t *)bp->bar0 + ptp->tx_mapped_regs[BNXT_PTP_TX_SEQ]);
3774 : :
3775 : 0 : return 0;
3776 : : }
3777 : :
3778 : 0 : static int bnxt_clr_rx_ts(struct bnxt *bp, uint64_t *last_ts)
3779 : : {
3780 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3781 : 0 : struct bnxt_pf_info *pf = bp->pf;
3782 : : uint16_t port_id;
3783 : : int i = 0;
3784 : : uint32_t fifo;
3785 : :
3786 [ # # # # ]: 0 : if (!ptp || (bp->flags & BNXT_FLAG_CHIP_P5))
3787 : : return -EINVAL;
3788 : :
3789 : 0 : port_id = pf->port_id;
3790 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3791 : : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3792 [ # # # # ]: 0 : while ((fifo & BNXT_PTP_RX_FIFO_PENDING) && (i < BNXT_PTP_RX_PND_CNT)) {
3793 : 0 : rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
3794 : 0 : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
3795 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3796 : : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3797 : 0 : *last_ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3798 : : ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
3799 : 0 : *last_ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3800 : 0 : ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
3801 : 0 : i++;
3802 : : }
3803 : :
3804 [ # # ]: 0 : if (i >= BNXT_PTP_RX_PND_CNT)
3805 : 0 : return -EBUSY;
3806 : :
3807 : : return 0;
3808 : : }
3809 : :
3810 : 0 : static int bnxt_get_rx_ts(struct bnxt *bp, uint64_t *ts)
3811 : : {
3812 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3813 : 0 : struct bnxt_pf_info *pf = bp->pf;
3814 : : uint16_t port_id;
3815 : : uint32_t fifo;
3816 : :
3817 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3818 : : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3819 [ # # ]: 0 : if (!(fifo & BNXT_PTP_RX_FIFO_PENDING))
3820 : : return -EAGAIN;
3821 : :
3822 : 0 : port_id = pf->port_id;
3823 : 0 : rte_write32(1 << port_id, (uint8_t *)bp->bar0 +
3824 : 0 : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO_ADV]);
3825 : :
3826 : 0 : fifo = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3827 : : ptp->rx_mapped_regs[BNXT_PTP_RX_FIFO]));
3828 [ # # ]: 0 : if (fifo & BNXT_PTP_RX_FIFO_PENDING)
3829 : 0 : return bnxt_clr_rx_ts(bp, ts);
3830 : :
3831 : 0 : *ts = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3832 : : ptp->rx_mapped_regs[BNXT_PTP_RX_TS_L]));
3833 : 0 : *ts |= (uint64_t)rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
3834 : 0 : ptp->rx_mapped_regs[BNXT_PTP_RX_TS_H])) << 32;
3835 : :
3836 : 0 : return 0;
3837 : : }
3838 : :
3839 : : static int
3840 : 0 : bnxt_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
3841 : : {
3842 : : uint64_t ns;
3843 : 0 : struct bnxt *bp = dev->data->dev_private;
3844 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3845 : :
3846 [ # # ]: 0 : if (!ptp)
3847 : : return -ENOTSUP;
3848 : :
3849 : : ns = rte_timespec_to_ns(ts);
3850 : : /* Set the timecounters to a new value. */
3851 : 0 : ptp->tc.nsec = ns;
3852 : 0 : ptp->tx_tstamp_tc.nsec = ns;
3853 : 0 : ptp->rx_tstamp_tc.nsec = ns;
3854 : :
3855 : 0 : return 0;
3856 : : }
3857 : :
3858 : : static int
3859 : 0 : bnxt_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
3860 : : {
3861 : 0 : struct bnxt *bp = dev->data->dev_private;
3862 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3863 : 0 : uint64_t ns, systime_cycles = 0;
3864 : : int rc = 0;
3865 : :
3866 [ # # ]: 0 : if (!ptp)
3867 : : return -ENOTSUP;
3868 : :
3869 : : /* TODO Revisit for Thor 2 */
3870 [ # # ]: 0 : if (BNXT_CHIP_P5(bp))
3871 : 0 : rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
3872 : : &systime_cycles);
3873 : : else
3874 : 0 : systime_cycles = bnxt_cc_read(bp);
3875 : :
3876 [ # # ]: 0 : ns = rte_timecounter_update(&ptp->tc, systime_cycles);
3877 : 0 : *ts = rte_ns_to_timespec(ns);
3878 : :
3879 : 0 : return rc;
3880 : : }
3881 : : static int
3882 : 0 : bnxt_timesync_enable(struct rte_eth_dev *dev)
3883 : : {
3884 : 0 : struct bnxt *bp = dev->data->dev_private;
3885 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3886 : : uint32_t shift = 0;
3887 : : int rc;
3888 : :
3889 [ # # ]: 0 : if (!ptp)
3890 : : return -ENOTSUP;
3891 : :
3892 : 0 : ptp->rx_filter = 1;
3893 : 0 : ptp->tx_tstamp_en = 1;
3894 : 0 : ptp->filter_all = 1;
3895 : 0 : ptp->rxctl = BNXT_PTP_MSG_EVENTS;
3896 : :
3897 : 0 : rc = bnxt_hwrm_ptp_cfg(bp);
3898 [ # # ]: 0 : if (rc)
3899 : : return rc;
3900 : :
3901 : : rte_spinlock_init(&ptp->ptp_lock);
3902 : 0 : bp->ptp_all_rx_tstamp = 1;
3903 [ # # ]: 0 : memset(&ptp->tc, 0, sizeof(struct rte_timecounter));
3904 : 0 : memset(&ptp->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
3905 : 0 : memset(&ptp->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
3906 : :
3907 : 0 : ptp->tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3908 : : ptp->tc.cc_shift = shift;
3909 : : ptp->tc.nsec_mask = (1ULL << shift) - 1;
3910 : :
3911 : 0 : ptp->rx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3912 : : ptp->rx_tstamp_tc.cc_shift = shift;
3913 : : ptp->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
3914 : :
3915 : 0 : ptp->tx_tstamp_tc.cc_mask = BNXT_CYCLECOUNTER_MASK;
3916 : : ptp->tx_tstamp_tc.cc_shift = shift;
3917 : : ptp->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
3918 : :
3919 : : /* TODO Revisit for Thor 2 */
3920 [ # # ]: 0 : if (!BNXT_CHIP_P5(bp))
3921 : 0 : bnxt_map_ptp_regs(bp);
3922 : : else
3923 : 0 : rc = bnxt_ptp_start(bp);
3924 : :
3925 : : return rc;
3926 : : }
3927 : :
3928 : : static int
3929 : 0 : bnxt_timesync_disable(struct rte_eth_dev *dev)
3930 : : {
3931 : 0 : struct bnxt *bp = dev->data->dev_private;
3932 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3933 : :
3934 [ # # ]: 0 : if (!ptp)
3935 : : return -ENOTSUP;
3936 : :
3937 : 0 : ptp->rx_filter = 0;
3938 : 0 : ptp->tx_tstamp_en = 0;
3939 : 0 : ptp->rxctl = 0;
3940 : 0 : ptp->filter_all = 0;
3941 : :
3942 : 0 : bnxt_hwrm_ptp_cfg(bp);
3943 : :
3944 : : /* TODO Revisit for Thor 2 */
3945 : 0 : bp->ptp_all_rx_tstamp = 0;
3946 [ # # ]: 0 : if (!BNXT_CHIP_P5(bp))
3947 : : bnxt_unmap_ptp_regs(bp);
3948 : : else
3949 : 0 : bnxt_ptp_stop(bp);
3950 : :
3951 : : return 0;
3952 : : }
3953 : :
3954 : : static int
3955 : 0 : bnxt_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
3956 : : struct timespec *timestamp,
3957 : : uint32_t flags __rte_unused)
3958 : : {
3959 : 0 : struct bnxt *bp = dev->data->dev_private;
3960 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3961 : 0 : uint64_t rx_tstamp_cycles = 0;
3962 : : uint64_t ns;
3963 : :
3964 [ # # ]: 0 : if (!ptp)
3965 : : return -ENOTSUP;
3966 : :
3967 : : /* TODO Revisit for Thor 2 */
3968 [ # # ]: 0 : if (BNXT_CHIP_P5(bp))
3969 : 0 : rx_tstamp_cycles = ptp->rx_timestamp;
3970 : : else
3971 : 0 : bnxt_get_rx_ts(bp, &rx_tstamp_cycles);
3972 : :
3973 [ # # ]: 0 : ns = rte_timecounter_update(&ptp->rx_tstamp_tc, rx_tstamp_cycles);
3974 : 0 : *timestamp = rte_ns_to_timespec(ns);
3975 : 0 : return 0;
3976 : : }
3977 : :
3978 : : static int
3979 : 0 : bnxt_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
3980 : : struct timespec *timestamp)
3981 : : {
3982 : 0 : struct bnxt *bp = dev->data->dev_private;
3983 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
3984 : 0 : uint64_t tx_tstamp_cycles = 0;
3985 : : uint64_t ns;
3986 : : int rc = 0;
3987 : :
3988 [ # # ]: 0 : if (!ptp)
3989 : : return -ENOTSUP;
3990 : :
3991 : : /* TODO Revisit for Thor 2 */
3992 [ # # ]: 0 : if (BNXT_CHIP_P5(bp))
3993 : 0 : rc = bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_PATH_TX,
3994 : : &tx_tstamp_cycles);
3995 : : else
3996 : 0 : rc = bnxt_get_tx_ts(bp, &tx_tstamp_cycles);
3997 : :
3998 [ # # ]: 0 : ns = rte_timecounter_update(&ptp->tx_tstamp_tc, tx_tstamp_cycles);
3999 : 0 : *timestamp = rte_ns_to_timespec(ns);
4000 : :
4001 : 0 : return rc;
4002 : : }
4003 : :
4004 : : static int
4005 : 0 : bnxt_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
4006 : : {
4007 : 0 : struct bnxt *bp = dev->data->dev_private;
4008 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
4009 : :
4010 [ # # ]: 0 : if (!ptp)
4011 : : return -ENOTSUP;
4012 : :
4013 : 0 : ptp->tc.nsec += delta;
4014 : 0 : ptp->tx_tstamp_tc.nsec += delta;
4015 : 0 : ptp->rx_tstamp_tc.nsec += delta;
4016 : :
4017 : 0 : return 0;
4018 : : }
4019 : :
4020 : : static int
4021 : 0 : bnxt_get_eeprom_length_op(struct rte_eth_dev *dev)
4022 : : {
4023 : 0 : struct bnxt *bp = dev->data->dev_private;
4024 : : int rc;
4025 : : uint32_t dir_entries;
4026 : : uint32_t entry_length;
4027 : :
4028 : 0 : rc = is_bnxt_in_error(bp);
4029 [ # # ]: 0 : if (rc)
4030 : : return rc;
4031 : :
4032 : 0 : PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT,
4033 : : bp->pdev->addr.domain, bp->pdev->addr.bus,
4034 : : bp->pdev->addr.devid, bp->pdev->addr.function);
4035 : :
4036 : 0 : rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
4037 [ # # ]: 0 : if (rc != 0)
4038 : : return rc;
4039 : :
4040 : 0 : return dir_entries * entry_length;
4041 : : }
4042 : :
4043 : : static int
4044 : 0 : bnxt_get_eeprom_op(struct rte_eth_dev *dev,
4045 : : struct rte_dev_eeprom_info *in_eeprom)
4046 : : {
4047 : 0 : struct bnxt *bp = dev->data->dev_private;
4048 : : uint32_t index;
4049 : : uint32_t offset;
4050 : : int rc;
4051 : :
4052 : 0 : rc = is_bnxt_in_error(bp);
4053 [ # # ]: 0 : if (rc)
4054 : : return rc;
4055 : :
4056 : 0 : PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d",
4057 : : bp->pdev->addr.domain, bp->pdev->addr.bus,
4058 : : bp->pdev->addr.devid, bp->pdev->addr.function,
4059 : : in_eeprom->offset, in_eeprom->length);
4060 : :
4061 [ # # ]: 0 : if (in_eeprom->offset == 0) /* special offset value to get directory */
4062 : 0 : return bnxt_get_nvram_directory(bp, in_eeprom->length,
4063 : 0 : in_eeprom->data);
4064 : :
4065 : 0 : index = in_eeprom->offset >> 24;
4066 : 0 : offset = in_eeprom->offset & 0xffffff;
4067 : :
4068 [ # # ]: 0 : if (index != 0)
4069 : 0 : return bnxt_hwrm_get_nvram_item(bp, index - 1, offset,
4070 : 0 : in_eeprom->length, in_eeprom->data);
4071 : :
4072 : : return 0;
4073 : : }
4074 : :
4075 : : static bool bnxt_dir_type_is_ape_bin_format(uint16_t dir_type)
4076 : : {
4077 : 0 : switch (dir_type) {
4078 : : case BNX_DIR_TYPE_CHIMP_PATCH:
4079 : : case BNX_DIR_TYPE_BOOTCODE:
4080 : : case BNX_DIR_TYPE_BOOTCODE_2:
4081 : : case BNX_DIR_TYPE_APE_FW:
4082 : : case BNX_DIR_TYPE_APE_PATCH:
4083 : : case BNX_DIR_TYPE_KONG_FW:
4084 : : case BNX_DIR_TYPE_KONG_PATCH:
4085 : : case BNX_DIR_TYPE_BONO_FW:
4086 : : case BNX_DIR_TYPE_BONO_PATCH:
4087 : : /* FALLTHROUGH */
4088 : : return true;
4089 : : }
4090 : :
4091 : : return false;
4092 : : }
4093 : :
4094 : : static bool bnxt_dir_type_is_other_exec_format(uint16_t dir_type)
4095 : : {
4096 [ # # ]: 0 : switch (dir_type) {
4097 : : case BNX_DIR_TYPE_AVS:
4098 : : case BNX_DIR_TYPE_EXP_ROM_MBA:
4099 : : case BNX_DIR_TYPE_PCIE:
4100 : : case BNX_DIR_TYPE_TSCF_UCODE:
4101 : : case BNX_DIR_TYPE_EXT_PHY:
4102 : : case BNX_DIR_TYPE_CCM:
4103 : : case BNX_DIR_TYPE_ISCSI_BOOT:
4104 : : case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
4105 : : case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
4106 : : /* FALLTHROUGH */
4107 : : return true;
4108 : : }
4109 : :
4110 : : return false;
4111 : : }
4112 : :
4113 [ # # ]: 0 : static bool bnxt_dir_type_is_executable(uint16_t dir_type)
4114 : : {
4115 : 0 : return bnxt_dir_type_is_ape_bin_format(dir_type) ||
4116 : : bnxt_dir_type_is_other_exec_format(dir_type);
4117 : : }
4118 : :
4119 : : static int
4120 : 0 : bnxt_set_eeprom_op(struct rte_eth_dev *dev,
4121 : : struct rte_dev_eeprom_info *in_eeprom)
4122 : : {
4123 : 0 : struct bnxt *bp = dev->data->dev_private;
4124 : : uint8_t index, dir_op;
4125 : : uint16_t type, ext, ordinal, attr;
4126 : : int rc;
4127 : :
4128 : 0 : rc = is_bnxt_in_error(bp);
4129 [ # # ]: 0 : if (rc)
4130 : : return rc;
4131 : :
4132 : 0 : PMD_DRV_LOG_LINE(INFO, PCI_PRI_FMT " in_eeprom->offset = %d len = %d",
4133 : : bp->pdev->addr.domain, bp->pdev->addr.bus,
4134 : : bp->pdev->addr.devid, bp->pdev->addr.function,
4135 : : in_eeprom->offset, in_eeprom->length);
4136 : :
4137 [ # # ]: 0 : if (!BNXT_PF(bp)) {
4138 : 0 : PMD_DRV_LOG_LINE(ERR, "NVM write not supported from a VF");
4139 : 0 : return -EINVAL;
4140 : : }
4141 : :
4142 : 0 : type = in_eeprom->magic >> 16;
4143 : :
4144 [ # # ]: 0 : if (type == 0xffff) { /* special value for directory operations */
4145 : 0 : index = in_eeprom->magic & 0xff;
4146 : 0 : dir_op = in_eeprom->magic >> 8;
4147 [ # # ]: 0 : if (index == 0)
4148 : : return -EINVAL;
4149 [ # # ]: 0 : switch (dir_op) {
4150 : 0 : case 0x0e: /* erase */
4151 [ # # ]: 0 : if (in_eeprom->offset != ~in_eeprom->magic)
4152 : : return -EINVAL;
4153 : 0 : return bnxt_hwrm_erase_nvram_directory(bp, index - 1);
4154 : : default:
4155 : : return -EINVAL;
4156 : : }
4157 : : }
4158 : :
4159 : : /* Create or re-write an NVM item: */
4160 [ # # ]: 0 : if (bnxt_dir_type_is_executable(type) == true)
4161 : : return -EOPNOTSUPP;
4162 : : ext = in_eeprom->magic & 0xffff;
4163 : 0 : ordinal = in_eeprom->offset >> 16;
4164 : : attr = in_eeprom->offset & 0xffff;
4165 : :
4166 : 0 : return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
4167 : 0 : in_eeprom->data, in_eeprom->length);
4168 : : }
4169 : :
4170 : 0 : static int bnxt_get_module_info(struct rte_eth_dev *dev,
4171 : : struct rte_eth_dev_module_info *modinfo)
4172 : : {
4173 : : uint8_t module_info[SFF_DIAG_SUPPORT_OFFSET + 1];
4174 : 0 : struct bnxt *bp = dev->data->dev_private;
4175 : : int rc;
4176 : :
4177 : : /* No point in going further if phy status indicates
4178 : : * module is not inserted or if it is powered down or
4179 : : * if it is of type 10GBase-T
4180 : : */
4181 [ # # ]: 0 : if (bp->link_info->module_status >
4182 : : HWRM_PORT_PHY_QCFG_OUTPUT_MODULE_STATUS_WARNINGMSG) {
4183 : 0 : PMD_DRV_LOG_LINE(NOTICE, "Port %u : Module is not inserted or is powered down",
4184 : : dev->data->port_id);
4185 : 0 : return -ENOTSUP;
4186 : : }
4187 : :
4188 : : /* This feature is not supported in older firmware versions */
4189 [ # # ]: 0 : if (bp->hwrm_spec_code < 0x10202) {
4190 : 0 : PMD_DRV_LOG_LINE(NOTICE, "Port %u : Feature is not supported in older firmware",
4191 : : dev->data->port_id);
4192 : 0 : return -ENOTSUP;
4193 : : }
4194 : :
4195 : 0 : rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
4196 : : SFF_DIAG_SUPPORT_OFFSET + 1,
4197 : : module_info);
4198 : :
4199 [ # # ]: 0 : if (rc)
4200 : : return rc;
4201 : :
4202 [ # # # # ]: 0 : switch (module_info[0]) {
4203 : 0 : case SFF_MODULE_ID_SFP:
4204 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
4205 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
4206 [ # # ]: 0 : if (module_info[SFF_DIAG_SUPPORT_OFFSET] == 0)
4207 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_LEN;
4208 : : break;
4209 : 0 : case SFF_MODULE_ID_QSFP:
4210 : : case SFF_MODULE_ID_QSFP_PLUS:
4211 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
4212 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8436_LEN;
4213 : 0 : break;
4214 : 0 : case SFF_MODULE_ID_QSFP28:
4215 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
4216 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_MAX_LEN;
4217 [ # # ]: 0 : if (module_info[SFF8636_FLATMEM_OFFSET] & SFF8636_FLATMEM_MASK)
4218 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8636_LEN;
4219 : : break;
4220 : 0 : default:
4221 : 0 : PMD_DRV_LOG_LINE(NOTICE, "Port %u : Unsupported module", dev->data->port_id);
4222 : 0 : return -ENOTSUP;
4223 : : }
4224 : :
4225 : 0 : PMD_DRV_LOG_LINE(INFO, "Port %u : modinfo->type = %d modinfo->eeprom_len = %d",
4226 : : dev->data->port_id, modinfo->type, modinfo->eeprom_len);
4227 : :
4228 : 0 : return 0;
4229 : : }
4230 : :
4231 : 0 : static int bnxt_get_module_eeprom(struct rte_eth_dev *dev,
4232 : : struct rte_dev_eeprom_info *info)
4233 : : {
4234 : 0 : uint8_t pg_addr[5] = { I2C_DEV_ADDR_A0, I2C_DEV_ADDR_A0 };
4235 : 0 : uint32_t offset = info->offset, length = info->length;
4236 : : uint8_t module_info[SFF_DIAG_SUPPORT_OFFSET + 1];
4237 : 0 : struct bnxt *bp = dev->data->dev_private;
4238 : 0 : uint8_t *data = info->data;
4239 : 0 : uint8_t page = offset >> 7;
4240 : : uint8_t max_pages = 2;
4241 : : uint8_t opt_pages;
4242 : : int rc;
4243 : :
4244 : 0 : rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
4245 : : SFF_DIAG_SUPPORT_OFFSET + 1,
4246 : : module_info);
4247 [ # # ]: 0 : if (rc)
4248 : : return rc;
4249 : :
4250 [ # # # ]: 0 : switch (module_info[0]) {
4251 : 0 : case SFF_MODULE_ID_SFP:
4252 [ # # ]: 0 : if (module_info[SFF_DIAG_SUPPORT_OFFSET]) {
4253 : 0 : pg_addr[2] = I2C_DEV_ADDR_A2;
4254 : 0 : pg_addr[3] = I2C_DEV_ADDR_A2;
4255 : : max_pages = 4;
4256 : : }
4257 : : break;
4258 : 0 : case SFF_MODULE_ID_QSFP28:
4259 : 0 : rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
4260 : : SFF8636_OPT_PAGES_OFFSET,
4261 : : 1, &opt_pages);
4262 [ # # ]: 0 : if (rc)
4263 : : return rc;
4264 : :
4265 [ # # ]: 0 : if (opt_pages & SFF8636_PAGE1_MASK) {
4266 : 0 : pg_addr[2] = I2C_DEV_ADDR_A0;
4267 : : max_pages = 3;
4268 : : }
4269 [ # # ]: 0 : if (opt_pages & SFF8636_PAGE2_MASK) {
4270 : 0 : pg_addr[3] = I2C_DEV_ADDR_A0;
4271 : : max_pages = 4;
4272 : : }
4273 [ # # ]: 0 : if (~module_info[SFF8636_FLATMEM_OFFSET] & SFF8636_FLATMEM_MASK) {
4274 : 0 : pg_addr[4] = I2C_DEV_ADDR_A0;
4275 : : max_pages = 5;
4276 : : }
4277 : : break;
4278 : : default:
4279 : : break;
4280 : : }
4281 : :
4282 : 0 : memset(data, 0, length);
4283 : :
4284 : 0 : offset &= 0xff;
4285 [ # # ]: 0 : while (length && page < max_pages) {
4286 [ # # ]: 0 : uint8_t raw_page = page ? page - 1 : 0;
4287 : : uint16_t chunk;
4288 : :
4289 [ # # ]: 0 : if (pg_addr[page] == I2C_DEV_ADDR_A2)
4290 : : raw_page = 0;
4291 [ # # ]: 0 : else if (page)
4292 : 0 : offset |= 0x80;
4293 : 0 : chunk = RTE_MIN(length, 256 - offset);
4294 : :
4295 [ # # ]: 0 : if (pg_addr[page]) {
4296 : 0 : rc = bnxt_hwrm_read_sfp_module_eeprom_info(bp, pg_addr[page],
4297 : : raw_page, offset,
4298 : : chunk, data);
4299 [ # # ]: 0 : if (rc)
4300 : 0 : return rc;
4301 : : }
4302 : :
4303 : 0 : data += chunk;
4304 : 0 : length -= chunk;
4305 : : offset = 0;
4306 [ # # ]: 0 : page += 1 + (chunk > 128);
4307 : : }
4308 : :
4309 [ # # ]: 0 : return length ? -EINVAL : 0;
4310 : : }
4311 : :
4312 : : #if (RTE_VERSION_NUM(22, 11, 0, 0) <= RTE_VERSION)
4313 : 0 : static int bnxt_speed_lanes_set(struct rte_eth_dev *dev, uint32_t speed_lanes)
4314 : : {
4315 : 0 : struct bnxt *bp = dev->data->dev_private;
4316 : :
4317 [ # # # # : 0 : if (!BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
4318 : : return -ENOTSUP;
4319 : :
4320 : 0 : bp->link_info->pmd_speed_lanes = speed_lanes;
4321 : :
4322 : 0 : return 0;
4323 : : }
4324 : :
4325 : : static uint32_t
4326 : 0 : bnxt_get_speed_lanes_capa(struct rte_eth_speed_lanes_capa *speed_lanes_capa,
4327 : : uint32_t speed_capa)
4328 : : {
4329 : : uint32_t speed_bit;
4330 : : uint32_t num = 0;
4331 : : uint32_t i;
4332 : :
4333 [ # # ]: 0 : for (i = 0; i < RTE_DIM(speed_lanes_capa_tbl); i++) {
4334 : : speed_bit =
4335 : 0 : rte_eth_speed_bitflag(speed_lanes_capa_tbl[i].speed,
4336 : : RTE_ETH_LINK_FULL_DUPLEX);
4337 [ # # ]: 0 : if ((speed_capa & speed_bit) == 0)
4338 : 0 : continue;
4339 : :
4340 : 0 : speed_lanes_capa[num].speed = speed_lanes_capa_tbl[i].speed;
4341 : 0 : speed_lanes_capa[num].capa = speed_lanes_capa_tbl[i].capa;
4342 : 0 : num++;
4343 : : }
4344 : :
4345 : 0 : return num;
4346 : : }
4347 : :
4348 : 0 : static int bnxt_speed_lanes_get_capa(struct rte_eth_dev *dev,
4349 : : struct rte_eth_speed_lanes_capa *speed_lanes_capa,
4350 : : unsigned int num)
4351 : : {
4352 : 0 : struct rte_eth_link *link = &dev->data->dev_link;
4353 : 0 : struct bnxt *bp = dev->data->dev_private;
4354 : : unsigned int speed_num;
4355 : : uint32_t speed_capa;
4356 : : int rc;
4357 : :
4358 : 0 : rc = is_bnxt_in_error(bp);
4359 [ # # ]: 0 : if (rc)
4360 : : return rc;
4361 : :
4362 [ # # # # : 0 : if (!BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
4363 : : return -ENOTSUP;
4364 : :
4365 : : /* speed_num counts number of speed capabilities.
4366 : : * When link is down, show the user choice all combinations of speeds x lanes
4367 : : */
4368 [ # # ]: 0 : if (link->link_status) {
4369 : 0 : speed_capa = bnxt_get_speed_capabilities_v2(bp);
4370 [ # # ]: 0 : speed_num = rte_popcount32(speed_capa & BNXT_SPEEDS_SUPP_SPEED_LANES);
4371 : : } else {
4372 : : speed_capa = BNXT_SPEEDS_SUPP_SPEED_LANES;
4373 : : speed_num = rte_popcount32(BNXT_SPEEDS_SUPP_SPEED_LANES);
4374 : : }
4375 [ # # ]: 0 : if (speed_num == 0)
4376 : : return -ENOTSUP;
4377 : :
4378 [ # # ]: 0 : if (speed_lanes_capa == NULL)
4379 : 0 : return speed_num;
4380 : :
4381 [ # # ]: 0 : if (num < speed_num)
4382 : : return -EINVAL;
4383 : :
4384 : 0 : return bnxt_get_speed_lanes_capa(speed_lanes_capa, speed_capa);
4385 : : }
4386 : :
4387 : 0 : static int bnxt_speed_lanes_get(struct rte_eth_dev *dev, uint32_t *lanes)
4388 : : {
4389 : 0 : struct rte_eth_link *link = &dev->data->dev_link;
4390 : 0 : struct bnxt *bp = dev->data->dev_private;
4391 : : int rc;
4392 : :
4393 : 0 : rc = is_bnxt_in_error(bp);
4394 [ # # ]: 0 : if (rc)
4395 : : return rc;
4396 : :
4397 [ # # # # : 0 : if (!BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
4398 : : return -ENOTSUP;
4399 : :
4400 [ # # ]: 0 : if (!link->link_status)
4401 : : return -EINVAL;
4402 : :
4403 : : /* user app expects lanes 1 for zero */
4404 : 0 : *lanes = (bp->link_info->active_lanes) ?
4405 : : bp->link_info->active_lanes : 1;
4406 : 0 : return 0;
4407 : : }
4408 : :
4409 : : #endif
4410 : :
4411 : : /*
4412 : : * Initialization
4413 : : */
4414 : :
4415 : : static const struct eth_dev_ops bnxt_dev_ops = {
4416 : : .dev_infos_get = bnxt_dev_info_get_op,
4417 : : .dev_close = bnxt_dev_close_op,
4418 : : .dev_configure = bnxt_dev_configure_op,
4419 : : .dev_start = bnxt_dev_start_op,
4420 : : .dev_stop = bnxt_dev_stop_op,
4421 : : .dev_set_link_up = bnxt_dev_set_link_up_op,
4422 : : .dev_set_link_down = bnxt_dev_set_link_down_op,
4423 : : .stats_get = bnxt_stats_get_op,
4424 : : .stats_reset = bnxt_stats_reset_op,
4425 : : .rx_queue_setup = bnxt_rx_queue_setup_op,
4426 : : .rx_queue_release = bnxt_rx_queue_release_op,
4427 : : .tx_queue_setup = bnxt_tx_queue_setup_op,
4428 : : .tx_queue_release = bnxt_tx_queue_release_op,
4429 : : .rx_queue_intr_enable = bnxt_rx_queue_intr_enable_op,
4430 : : .rx_queue_intr_disable = bnxt_rx_queue_intr_disable_op,
4431 : : .reta_update = bnxt_reta_update_op,
4432 : : .reta_query = bnxt_reta_query_op,
4433 : : .rss_hash_update = bnxt_rss_hash_update_op,
4434 : : .rss_hash_conf_get = bnxt_rss_hash_conf_get_op,
4435 : : .link_update = bnxt_link_update_op,
4436 : : .promiscuous_enable = bnxt_promiscuous_enable_op,
4437 : : .promiscuous_disable = bnxt_promiscuous_disable_op,
4438 : : .allmulticast_enable = bnxt_allmulticast_enable_op,
4439 : : .allmulticast_disable = bnxt_allmulticast_disable_op,
4440 : : .mac_addr_add = bnxt_mac_addr_add_op,
4441 : : .mac_addr_remove = bnxt_mac_addr_remove_op,
4442 : : .flow_ctrl_get = bnxt_flow_ctrl_get_op,
4443 : : .flow_ctrl_set = bnxt_flow_ctrl_set_op,
4444 : : .udp_tunnel_port_add = bnxt_udp_tunnel_port_add_op,
4445 : : .udp_tunnel_port_del = bnxt_udp_tunnel_port_del_op,
4446 : : .vlan_filter_set = bnxt_vlan_filter_set_op,
4447 : : .vlan_offload_set = bnxt_vlan_offload_set_op,
4448 : : .vlan_tpid_set = bnxt_vlan_tpid_set_op,
4449 : : .vlan_pvid_set = bnxt_vlan_pvid_set_op,
4450 : : .mtu_set = bnxt_mtu_set_op,
4451 : : .mac_addr_set = bnxt_set_default_mac_addr_op,
4452 : : .xstats_get = bnxt_dev_xstats_get_op,
4453 : : .xstats_get_names = bnxt_dev_xstats_get_names_op,
4454 : : .xstats_reset = bnxt_dev_xstats_reset_op,
4455 : : .fw_version_get = bnxt_fw_version_get,
4456 : : .set_mc_addr_list = bnxt_dev_set_mc_addr_list_op,
4457 : : .rxq_info_get = bnxt_rxq_info_get_op,
4458 : : .txq_info_get = bnxt_txq_info_get_op,
4459 : : .rx_burst_mode_get = bnxt_rx_burst_mode_get,
4460 : : .tx_burst_mode_get = bnxt_tx_burst_mode_get,
4461 : : .dev_led_on = bnxt_dev_led_on_op,
4462 : : .dev_led_off = bnxt_dev_led_off_op,
4463 : : .rx_queue_start = bnxt_rx_queue_start,
4464 : : .rx_queue_stop = bnxt_rx_queue_stop,
4465 : : .tx_queue_start = bnxt_tx_queue_start,
4466 : : .tx_queue_stop = bnxt_tx_queue_stop,
4467 : : .flow_ops_get = bnxt_flow_ops_get_op,
4468 : : .dev_supported_ptypes_get = bnxt_dev_supported_ptypes_get_op,
4469 : : .get_eeprom_length = bnxt_get_eeprom_length_op,
4470 : : .get_eeprom = bnxt_get_eeprom_op,
4471 : : .set_eeprom = bnxt_set_eeprom_op,
4472 : : .get_module_info = bnxt_get_module_info,
4473 : : .get_module_eeprom = bnxt_get_module_eeprom,
4474 : : .timesync_enable = bnxt_timesync_enable,
4475 : : .timesync_disable = bnxt_timesync_disable,
4476 : : .timesync_read_time = bnxt_timesync_read_time,
4477 : : .timesync_write_time = bnxt_timesync_write_time,
4478 : : .timesync_adjust_time = bnxt_timesync_adjust_time,
4479 : : .timesync_read_rx_timestamp = bnxt_timesync_read_rx_timestamp,
4480 : : .timesync_read_tx_timestamp = bnxt_timesync_read_tx_timestamp,
4481 : : .mtr_ops_get = bnxt_flow_meter_ops_get,
4482 : : #if (RTE_VERSION_NUM(22, 11, 0, 0) <= RTE_VERSION)
4483 : : .speed_lanes_get = bnxt_speed_lanes_get,
4484 : : .speed_lanes_set = bnxt_speed_lanes_set,
4485 : : .speed_lanes_get_capa = bnxt_speed_lanes_get_capa,
4486 : : #endif
4487 : : };
4488 : :
4489 : : static uint32_t bnxt_map_reset_regs(struct bnxt *bp, uint32_t reg)
4490 : : {
4491 : : uint32_t offset;
4492 : :
4493 : : /* Only pre-map the reset GRC registers using window 3 */
4494 : 0 : rte_write32(reg & 0xfffff000, (uint8_t *)bp->bar0 +
4495 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 8);
4496 : :
4497 : 0 : offset = BNXT_GRCP_WINDOW_3_BASE + (reg & 0xffc);
4498 : :
4499 : : return offset;
4500 : : }
4501 : :
4502 : 0 : int bnxt_map_fw_health_status_regs(struct bnxt *bp)
4503 : : {
4504 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4505 : : uint32_t reg_base = 0xffffffff;
4506 : : int i;
4507 : :
4508 : : /* Only pre-map the monitoring GRC registers using window 2 */
4509 [ # # ]: 0 : for (i = 0; i < BNXT_FW_STATUS_REG_CNT; i++) {
4510 : 0 : uint32_t reg = info->status_regs[i];
4511 : :
4512 [ # # ]: 0 : if (BNXT_FW_STATUS_REG_TYPE(reg) != BNXT_FW_STATUS_REG_TYPE_GRC)
4513 : 0 : continue;
4514 : :
4515 [ # # ]: 0 : if (reg_base == 0xffffffff)
4516 : 0 : reg_base = reg & 0xfffff000;
4517 [ # # ]: 0 : if ((reg & 0xfffff000) != reg_base)
4518 : : return -ERANGE;
4519 : :
4520 : : /* Use mask 0xffc as the Lower 2 bits indicates
4521 : : * address space location
4522 : : */
4523 : 0 : info->mapped_status_regs[i] = BNXT_GRCP_WINDOW_2_BASE +
4524 : 0 : (reg & 0xffc);
4525 : : }
4526 : :
4527 [ # # ]: 0 : if (reg_base == 0xffffffff)
4528 : : return 0;
4529 : :
4530 : 0 : rte_write32(reg_base, (uint8_t *)bp->bar0 +
4531 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
4532 : :
4533 : 0 : return 0;
4534 : : }
4535 : :
4536 : 0 : static void bnxt_write_fw_reset_reg(struct bnxt *bp, uint32_t index)
4537 : : {
4538 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4539 : 0 : uint32_t delay = info->delay_after_reset[index];
4540 : 0 : uint32_t val = info->reset_reg_val[index];
4541 : 0 : uint32_t reg = info->reset_reg[index];
4542 : : uint32_t type, offset;
4543 : : int ret;
4544 : :
4545 : 0 : type = BNXT_FW_STATUS_REG_TYPE(reg);
4546 : 0 : offset = BNXT_FW_STATUS_REG_OFF(reg);
4547 : :
4548 [ # # # # ]: 0 : switch (type) {
4549 : 0 : case BNXT_FW_STATUS_REG_TYPE_CFG:
4550 : 0 : ret = rte_pci_write_config(bp->pdev, &val, sizeof(val), offset);
4551 [ # # ]: 0 : if (ret < 0) {
4552 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to write %#x at PCI offset %#x",
4553 : : val, offset);
4554 : 0 : return;
4555 : : }
4556 : : break;
4557 : : case BNXT_FW_STATUS_REG_TYPE_GRC:
4558 : : offset = bnxt_map_reset_regs(bp, offset);
4559 : 0 : rte_write32(val, (uint8_t *)bp->bar0 + offset);
4560 : : break;
4561 : 0 : case BNXT_FW_STATUS_REG_TYPE_BAR0:
4562 : 0 : rte_write32(val, (uint8_t *)bp->bar0 + offset);
4563 : : break;
4564 : : }
4565 : : /* wait on a specific interval of time until core reset is complete */
4566 [ # # ]: 0 : if (delay)
4567 : : rte_delay_ms(delay);
4568 : : }
4569 : :
4570 : 0 : static void bnxt_dev_cleanup(struct bnxt *bp)
4571 : : {
4572 : 0 : bp->eth_dev->data->dev_link.link_status = 0;
4573 : 0 : bp->link_info->link_up = 0;
4574 [ # # ]: 0 : if (bp->eth_dev->data->dev_started)
4575 : 0 : bnxt_dev_stop(bp->eth_dev);
4576 : :
4577 : 0 : bnxt_uninit_resources(bp, true);
4578 : 0 : }
4579 : :
4580 : : static int
4581 : 0 : bnxt_check_fw_reset_done(struct bnxt *bp)
4582 : : {
4583 : 0 : int timeout = bp->fw_reset_max_msecs;
4584 : 0 : uint16_t val = 0;
4585 : : int rc;
4586 : :
4587 : : do {
4588 : 0 : rc = rte_pci_read_config(bp->pdev, &val, sizeof(val), PCI_SUBSYSTEM_ID_OFFSET);
4589 [ # # ]: 0 : if (rc < 0) {
4590 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset 0x%x",
4591 : : PCI_SUBSYSTEM_ID_OFFSET);
4592 : 0 : return rc;
4593 : : }
4594 [ # # ]: 0 : if (val != 0xffff)
4595 : : break;
4596 : : rte_delay_ms(1);
4597 [ # # ]: 0 : } while (timeout--);
4598 : :
4599 [ # # ]: 0 : if (val == 0xffff) {
4600 : 0 : PMD_DRV_LOG_LINE(ERR, "Firmware reset aborted, PCI config space invalid");
4601 : 0 : return -1;
4602 : : }
4603 : :
4604 : : return 0;
4605 : : }
4606 : :
4607 : 0 : static int bnxt_restore_vlan_filters(struct bnxt *bp)
4608 : : {
4609 : 0 : struct rte_eth_dev *dev = bp->eth_dev;
4610 : : struct rte_vlan_filter_conf *vfc;
4611 : : int vidx, vbit, rc;
4612 : : uint16_t vlan_id;
4613 : :
4614 [ # # ]: 0 : for (vlan_id = 1; vlan_id <= RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
4615 : 0 : vfc = &dev->data->vlan_filter_conf;
4616 : 0 : vidx = vlan_id / 64;
4617 : 0 : vbit = vlan_id % 64;
4618 : :
4619 : : /* Each bit corresponds to a VLAN id */
4620 [ # # ]: 0 : if (vfc->ids[vidx] & (UINT64_C(1) << vbit)) {
4621 : 0 : rc = bnxt_add_vlan_filter(bp, vlan_id);
4622 [ # # ]: 0 : if (rc)
4623 : 0 : return rc;
4624 : : }
4625 : : }
4626 : :
4627 : : return 0;
4628 : : }
4629 : :
4630 : 0 : static int bnxt_restore_mac_filters(struct bnxt *bp)
4631 : : {
4632 : 0 : struct rte_eth_dev *dev = bp->eth_dev;
4633 : : struct rte_eth_dev_info dev_info;
4634 : : struct rte_ether_addr *addr;
4635 : : uint64_t pool_mask;
4636 : : uint32_t pool = 0;
4637 : : uint32_t i;
4638 : : int rc;
4639 : :
4640 [ # # ]: 0 : if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
4641 : : return 0;
4642 : :
4643 : 0 : rc = bnxt_dev_info_get_op(dev, &dev_info);
4644 [ # # ]: 0 : if (rc)
4645 : : return rc;
4646 : :
4647 : : /* replay MAC address configuration */
4648 [ # # ]: 0 : for (i = 1; i < dev_info.max_mac_addrs; i++) {
4649 [ # # ]: 0 : addr = &dev->data->mac_addrs[i];
4650 : :
4651 : : /* skip zero address */
4652 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr))
4653 : 0 : continue;
4654 : :
4655 : : pool = 0;
4656 : 0 : pool_mask = dev->data->mac_pool_sel[i];
4657 : :
4658 : : do {
4659 [ # # ]: 0 : if (pool_mask & 1ULL) {
4660 : 0 : rc = bnxt_mac_addr_add_op(dev, addr, i, pool);
4661 [ # # ]: 0 : if (rc)
4662 : 0 : return rc;
4663 : : }
4664 : 0 : pool_mask >>= 1;
4665 : 0 : pool++;
4666 [ # # ]: 0 : } while (pool_mask);
4667 : : }
4668 : :
4669 : : return 0;
4670 : : }
4671 : :
4672 : 0 : static int bnxt_restore_mcast_mac_filters(struct bnxt *bp)
4673 : : {
4674 : : int ret = 0;
4675 : :
4676 : 0 : ret = bnxt_dev_set_mc_addr_list_op(bp->eth_dev, bp->mcast_addr_list,
4677 : : bp->nb_mc_addr);
4678 [ # # ]: 0 : if (ret)
4679 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to restore multicast MAC addreeses");
4680 : :
4681 : 0 : return ret;
4682 : : }
4683 : :
4684 : 0 : static int bnxt_restore_filters(struct bnxt *bp)
4685 : : {
4686 : 0 : struct rte_eth_dev *dev = bp->eth_dev;
4687 : : int ret = 0;
4688 : :
4689 [ # # ]: 0 : if (dev->data->all_multicast) {
4690 : 0 : ret = bnxt_allmulticast_enable_op(dev);
4691 [ # # ]: 0 : if (ret)
4692 : : return ret;
4693 : : }
4694 [ # # ]: 0 : if (dev->data->promiscuous) {
4695 : 0 : ret = bnxt_promiscuous_enable_op(dev);
4696 [ # # ]: 0 : if (ret)
4697 : : return ret;
4698 : : }
4699 : :
4700 : 0 : ret = bnxt_restore_mac_filters(bp);
4701 [ # # ]: 0 : if (ret)
4702 : : return ret;
4703 : :
4704 : : /* if vlans are already programmed, this can fail with -EEXIST */
4705 : 0 : ret = bnxt_restore_vlan_filters(bp);
4706 [ # # ]: 0 : if (ret && ret != -EEXIST)
4707 : : return ret;
4708 : :
4709 : 0 : ret = bnxt_restore_mcast_mac_filters(bp);
4710 [ # # ]: 0 : if (ret)
4711 : 0 : return ret;
4712 : :
4713 : : return ret;
4714 : : }
4715 : :
4716 : 0 : static int bnxt_check_fw_ready(struct bnxt *bp)
4717 : : {
4718 [ # # ]: 0 : int timeout = bp->fw_reset_max_msecs ? : BNXT_MAX_FW_RESET_TIMEOUT;
4719 : : int rc = 0;
4720 : :
4721 : : do {
4722 : 0 : rc = bnxt_hwrm_poll_ver_get(bp);
4723 [ # # ]: 0 : if (rc == 0)
4724 : : break;
4725 : : rte_delay_ms(BNXT_FW_READY_WAIT_INTERVAL);
4726 : 0 : timeout -= BNXT_FW_READY_WAIT_INTERVAL;
4727 [ # # ]: 0 : } while (rc && timeout > 0);
4728 : :
4729 [ # # ]: 0 : if (rc)
4730 : 0 : PMD_DRV_LOG_LINE(ERR, "FW is not Ready after reset");
4731 : :
4732 : 0 : return rc;
4733 : : }
4734 : :
4735 : 0 : static void bnxt_dev_recover(void *arg)
4736 : : {
4737 : : struct bnxt *bp = arg;
4738 : : int rc = 0;
4739 : :
4740 : 0 : pthread_mutex_lock(&bp->err_recovery_lock);
4741 : :
4742 [ # # ]: 0 : if (!bp->fw_reset_min_msecs) {
4743 : 0 : rc = bnxt_check_fw_reset_done(bp);
4744 [ # # ]: 0 : if (rc)
4745 : 0 : goto err;
4746 : : }
4747 : :
4748 : : /* Clear Error flag so that device re-init should happen */
4749 : 0 : bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
4750 : 0 : PMD_DRV_LOG_LINE(INFO, "Port: %u Starting recovery...",
4751 : : bp->eth_dev->data->port_id);
4752 : :
4753 : 0 : rc = bnxt_check_fw_ready(bp);
4754 [ # # ]: 0 : if (rc)
4755 : 0 : goto err;
4756 : :
4757 : 0 : rc = bnxt_init_resources(bp, true);
4758 [ # # ]: 0 : if (rc) {
4759 : 0 : PMD_DRV_LOG_LINE(ERR,
4760 : : "Failed to initialize resources after reset");
4761 : 0 : goto err;
4762 : : }
4763 : : /* clear reset flag as the device is initialized now */
4764 : 0 : bp->flags &= ~BNXT_FLAG_FW_RESET;
4765 : :
4766 : 0 : rc = bnxt_dev_start_op(bp->eth_dev);
4767 [ # # ]: 0 : if (rc) {
4768 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to start port after reset");
4769 : 0 : goto err_start;
4770 : : }
4771 : :
4772 : 0 : rc = bnxt_restore_filters(bp);
4773 [ # # ]: 0 : if (rc)
4774 : 0 : goto err_start;
4775 : :
4776 : 0 : rte_eth_fp_ops[bp->eth_dev->data->port_id].rx_pkt_burst =
4777 : 0 : bp->eth_dev->rx_pkt_burst;
4778 : 0 : rte_eth_fp_ops[bp->eth_dev->data->port_id].tx_pkt_burst =
4779 : 0 : bp->eth_dev->tx_pkt_burst;
4780 : : rte_mb();
4781 : :
4782 : 0 : PMD_DRV_LOG_LINE(INFO, "Port: %u Recovered from FW reset",
4783 : : bp->eth_dev->data->port_id);
4784 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
4785 : 0 : rte_eth_dev_callback_process(bp->eth_dev,
4786 : : RTE_ETH_EVENT_RECOVERY_SUCCESS,
4787 : : NULL);
4788 : 0 : return;
4789 : 0 : err_start:
4790 : 0 : bnxt_dev_stop(bp->eth_dev);
4791 : 0 : err:
4792 : 0 : bp->flags |= BNXT_FLAG_FATAL_ERROR;
4793 : 0 : bnxt_uninit_resources(bp, false);
4794 : 0 : rte_eth_dev_callback_process(bp->eth_dev,
4795 : : RTE_ETH_EVENT_RECOVERY_FAILED,
4796 : : NULL);
4797 [ # # ]: 0 : if (bp->eth_dev->data->dev_conf.intr_conf.rmv)
4798 : 0 : rte_eth_dev_callback_process(bp->eth_dev,
4799 : : RTE_ETH_EVENT_INTR_RMV,
4800 : : NULL);
4801 : 0 : pthread_mutex_unlock(&bp->err_recovery_lock);
4802 : 0 : PMD_DRV_LOG_LINE(ERR, "Port %u: Failed to recover from FW reset",
4803 : : bp->eth_dev->data->port_id);
4804 : : }
4805 : :
4806 : 0 : void bnxt_dev_reset_and_resume(void *arg)
4807 : : {
4808 : : struct bnxt *bp = arg;
4809 : 0 : uint32_t us = US_PER_MS * bp->fw_reset_min_msecs;
4810 : 0 : uint16_t val = 0;
4811 : : int rc;
4812 : :
4813 : 0 : bnxt_dev_cleanup(bp);
4814 : 0 : PMD_DRV_LOG_LINE(INFO, "Port: %u Finished bnxt_dev_cleanup",
4815 : : bp->eth_dev->data->port_id);
4816 : :
4817 : 0 : bnxt_wait_for_device_shutdown(bp);
4818 : :
4819 : : /* During some fatal firmware error conditions, the PCI config space
4820 : : * register 0x2e which normally contains the subsystem ID will become
4821 : : * 0xffff. This register will revert back to the normal value after
4822 : : * the chip has completed core reset. If we detect this condition,
4823 : : * we can poll this config register immediately for the value to revert.
4824 : : */
4825 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FATAL_ERROR) {
4826 : 0 : rc = rte_pci_read_config(bp->pdev, &val, sizeof(val), PCI_SUBSYSTEM_ID_OFFSET);
4827 [ # # ]: 0 : if (rc < 0) {
4828 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset 0x%x",
4829 : : PCI_SUBSYSTEM_ID_OFFSET);
4830 : 0 : return;
4831 : : }
4832 [ # # ]: 0 : if (val == 0xffff) {
4833 : 0 : bp->fw_reset_min_msecs = 0;
4834 : : us = 1;
4835 : : }
4836 : : }
4837 : :
4838 : 0 : rc = rte_eal_alarm_set(us, bnxt_dev_recover, (void *)bp);
4839 [ # # ]: 0 : if (rc)
4840 : 0 : PMD_DRV_LOG_LINE(ERR, "Port %u: Error setting recovery alarm",
4841 : : bp->eth_dev->data->port_id);
4842 : : }
4843 : :
4844 : 0 : uint32_t bnxt_read_fw_status_reg(struct bnxt *bp, uint32_t index)
4845 : : {
4846 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4847 : 0 : uint32_t reg = info->status_regs[index];
4848 : 0 : uint32_t type, offset, val = 0;
4849 : : int ret = 0;
4850 : :
4851 : 0 : type = BNXT_FW_STATUS_REG_TYPE(reg);
4852 : 0 : offset = BNXT_FW_STATUS_REG_OFF(reg);
4853 : :
4854 [ # # # # ]: 0 : switch (type) {
4855 : 0 : case BNXT_FW_STATUS_REG_TYPE_CFG:
4856 : 0 : ret = rte_pci_read_config(bp->pdev, &val, sizeof(val), offset);
4857 [ # # ]: 0 : if (ret < 0)
4858 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to read PCI offset %#x",
4859 : : offset);
4860 : : break;
4861 : 0 : case BNXT_FW_STATUS_REG_TYPE_GRC:
4862 : 0 : offset = info->mapped_status_regs[index];
4863 : : /* FALLTHROUGH */
4864 : 0 : case BNXT_FW_STATUS_REG_TYPE_BAR0:
4865 : 0 : val = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
4866 : : offset));
4867 : 0 : break;
4868 : : }
4869 : :
4870 : 0 : return val;
4871 : : }
4872 : :
4873 : 0 : static int bnxt_fw_reset_all(struct bnxt *bp)
4874 : : {
4875 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4876 : : uint32_t i;
4877 : : int rc = 0;
4878 : :
4879 [ # # ]: 0 : if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4880 : : /* Reset through primary function driver */
4881 [ # # ]: 0 : for (i = 0; i < info->reg_array_cnt; i++)
4882 : 0 : bnxt_write_fw_reset_reg(bp, i);
4883 : : /* Wait for time specified by FW after triggering reset */
4884 : 0 : rte_delay_ms(info->primary_func_wait_period_after_reset);
4885 [ # # ]: 0 : } else if (info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) {
4886 : : /* Reset with the help of Kong processor */
4887 : 0 : rc = bnxt_hwrm_fw_reset(bp);
4888 [ # # ]: 0 : if (rc)
4889 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to reset FW");
4890 : : }
4891 : :
4892 : 0 : return rc;
4893 : : }
4894 : :
4895 : 0 : static void bnxt_fw_reset_cb(void *arg)
4896 : : {
4897 : : struct bnxt *bp = arg;
4898 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4899 : : int rc = 0;
4900 : :
4901 : : /* Only Primary function can do FW reset */
4902 [ # # # # ]: 0 : if (bnxt_is_primary_func(bp) &&
4903 : 0 : bnxt_is_recovery_enabled(bp)) {
4904 : 0 : rc = bnxt_fw_reset_all(bp);
4905 [ # # ]: 0 : if (rc) {
4906 : 0 : PMD_DRV_LOG_LINE(ERR, "Adapter recovery failed");
4907 : 0 : return;
4908 : : }
4909 : : }
4910 : :
4911 : : /* if recovery method is ERROR_RECOVERY_CO_CPU, KONG will send
4912 : : * EXCEPTION_FATAL_ASYNC event to all the functions
4913 : : * (including MASTER FUNC). After receiving this Async, all the active
4914 : : * drivers should treat this case as FW initiated recovery
4915 : : */
4916 [ # # ]: 0 : if (info->flags & BNXT_FLAG_ERROR_RECOVERY_HOST) {
4917 : 0 : bp->fw_reset_min_msecs = BNXT_MIN_FW_READY_TIMEOUT;
4918 : 0 : bp->fw_reset_max_msecs = BNXT_MAX_FW_RESET_TIMEOUT;
4919 : :
4920 : : /* To recover from error */
4921 : 0 : rte_eal_alarm_set(US_PER_MS, bnxt_dev_reset_and_resume,
4922 : : (void *)bp);
4923 : : }
4924 : : }
4925 : :
4926 : : /* Driver should poll FW heartbeat, reset_counter with the frequency
4927 : : * advertised by FW in HWRM_ERROR_RECOVERY_QCFG.
4928 : : * When the driver detects heartbeat stop or change in reset_counter,
4929 : : * it has to trigger a reset to recover from the error condition.
4930 : : * A “primary function” is the function who will have the privilege to
4931 : : * initiate the chimp reset. The primary function will be elected by the
4932 : : * firmware and will be notified through async message.
4933 : : */
4934 : 0 : static void bnxt_check_fw_health(void *arg)
4935 : : {
4936 : : struct bnxt *bp = arg;
4937 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
4938 : : uint32_t val = 0, wait_msec;
4939 : :
4940 [ # # # # : 0 : if (!info || !bnxt_is_recovery_enabled(bp) ||
# # ]
4941 : 0 : is_bnxt_in_error(bp))
4942 : 0 : return;
4943 : :
4944 : 0 : val = bnxt_read_fw_status_reg(bp, BNXT_FW_HEARTBEAT_CNT_REG);
4945 [ # # ]: 0 : if (val == info->last_heart_beat)
4946 : 0 : goto reset;
4947 : :
4948 : 0 : info->last_heart_beat = val;
4949 : :
4950 : 0 : val = bnxt_read_fw_status_reg(bp, BNXT_FW_RECOVERY_CNT_REG);
4951 [ # # ]: 0 : if (val != info->last_reset_counter)
4952 : 0 : goto reset;
4953 : :
4954 : 0 : info->last_reset_counter = val;
4955 : :
4956 : 0 : rte_eal_alarm_set(US_PER_MS * info->driver_polling_freq,
4957 : : bnxt_check_fw_health, (void *)bp);
4958 : :
4959 : 0 : return;
4960 : 0 : reset:
4961 : : /* Stop DMA to/from device */
4962 : 0 : bp->flags |= BNXT_FLAG_FATAL_ERROR;
4963 : 0 : bp->flags |= BNXT_FLAG_FW_RESET;
4964 : :
4965 : 0 : bnxt_stop_rxtx(bp->eth_dev);
4966 : :
4967 : 0 : PMD_DRV_LOG_LINE(ERR, "Detected FW dead condition");
4968 : :
4969 : 0 : rte_eth_dev_callback_process(bp->eth_dev,
4970 : : RTE_ETH_EVENT_ERR_RECOVERING,
4971 : : NULL);
4972 : :
4973 [ # # ]: 0 : if (bnxt_is_primary_func(bp))
4974 : 0 : wait_msec = info->primary_func_wait_period;
4975 : : else
4976 : 0 : wait_msec = info->normal_func_wait_period;
4977 : :
4978 : 0 : rte_eal_alarm_set(US_PER_MS * wait_msec,
4979 : : bnxt_fw_reset_cb, (void *)bp);
4980 : : }
4981 : :
4982 : 0 : void bnxt_schedule_fw_health_check(struct bnxt *bp)
4983 : : {
4984 : : uint32_t polling_freq;
4985 : :
4986 : 0 : pthread_mutex_lock(&bp->health_check_lock);
4987 : :
4988 [ # # ]: 0 : if (!bnxt_is_recovery_enabled(bp))
4989 : 0 : goto done;
4990 : :
4991 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED)
4992 : 0 : goto done;
4993 : :
4994 : 0 : polling_freq = bp->recovery_info->driver_polling_freq;
4995 : :
4996 : 0 : rte_eal_alarm_set(US_PER_MS * polling_freq,
4997 : : bnxt_check_fw_health, (void *)bp);
4998 : 0 : bp->flags |= BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
4999 : :
5000 : 0 : done:
5001 : 0 : pthread_mutex_unlock(&bp->health_check_lock);
5002 : 0 : }
5003 : :
5004 : : static void bnxt_cancel_fw_health_check(struct bnxt *bp)
5005 : : {
5006 : 0 : rte_eal_alarm_cancel(bnxt_check_fw_health, (void *)bp);
5007 [ # # ]: 0 : bp->flags &= ~BNXT_FLAG_FW_HEALTH_CHECK_SCHEDULED;
5008 : : }
5009 : :
5010 : 0 : static bool bnxt_vf_pciid(uint16_t device_id)
5011 : : {
5012 [ # # ]: 0 : switch (device_id) {
5013 : : case BROADCOM_DEV_ID_57304_VF:
5014 : : case BROADCOM_DEV_ID_57406_VF:
5015 : : case BROADCOM_DEV_ID_5731X_VF:
5016 : : case BROADCOM_DEV_ID_5741X_VF:
5017 : : case BROADCOM_DEV_ID_57414_VF:
5018 : : case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
5019 : : case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
5020 : : case BROADCOM_DEV_ID_58802_VF:
5021 : : case BROADCOM_DEV_ID_57500_VF1:
5022 : : case BROADCOM_DEV_ID_57500_VF2:
5023 : : case BROADCOM_DEV_ID_58818_VF:
5024 : : case BROADCOM_DEV_ID_5760X_VF:
5025 : : /* FALLTHROUGH */
5026 : : return true;
5027 : 0 : default:
5028 : 0 : return false;
5029 : : }
5030 : : }
5031 : :
5032 : : /* Phase 5 device */
5033 : : static bool bnxt_p5_device(uint16_t device_id)
5034 : : {
5035 [ # # ]: 0 : switch (device_id) {
5036 : : case BROADCOM_DEV_ID_57508:
5037 : : case BROADCOM_DEV_ID_57504:
5038 : : case BROADCOM_DEV_ID_57502:
5039 : : case BROADCOM_DEV_ID_57508_MF1:
5040 : : case BROADCOM_DEV_ID_57504_MF1:
5041 : : case BROADCOM_DEV_ID_57502_MF1:
5042 : : case BROADCOM_DEV_ID_57508_MF2:
5043 : : case BROADCOM_DEV_ID_57504_MF2:
5044 : : case BROADCOM_DEV_ID_57502_MF2:
5045 : : case BROADCOM_DEV_ID_57500_VF1:
5046 : : case BROADCOM_DEV_ID_57500_VF2:
5047 : : case BROADCOM_DEV_ID_58812:
5048 : : case BROADCOM_DEV_ID_58814:
5049 : : case BROADCOM_DEV_ID_58818:
5050 : : /* FALLTHROUGH */
5051 : : return true;
5052 : : default:
5053 : : return false;
5054 : : }
5055 : : }
5056 : :
5057 : : /* Phase 7 device */
5058 : : static bool bnxt_p7_device(uint16_t device_id)
5059 : : {
5060 [ # # ]: 0 : switch (device_id) {
5061 : : case BROADCOM_DEV_ID_58818_VF:
5062 : : case BROADCOM_DEV_ID_57608:
5063 : : case BROADCOM_DEV_ID_57604:
5064 : : case BROADCOM_DEV_ID_57602:
5065 : : case BROADCOM_DEV_ID_57601:
5066 : : case BROADCOM_DEV_ID_5760X_VF:
5067 : : /* FALLTHROUGH */
5068 : : return true;
5069 : : default:
5070 : : return false;
5071 : : }
5072 : : }
5073 : :
5074 : 0 : bool bnxt_stratus_device(struct bnxt *bp)
5075 : : {
5076 : 0 : uint16_t device_id = bp->pdev->id.device_id;
5077 : :
5078 [ # # ]: 0 : switch (device_id) {
5079 : : case BROADCOM_DEV_ID_STRATUS_NIC:
5080 : : case BROADCOM_DEV_ID_STRATUS_NIC_VF1:
5081 : : case BROADCOM_DEV_ID_STRATUS_NIC_VF2:
5082 : : /* FALLTHROUGH */
5083 : : return true;
5084 : 0 : default:
5085 : 0 : return false;
5086 : : }
5087 : : }
5088 : :
5089 : 0 : static int bnxt_map_pci_bars(struct rte_eth_dev *eth_dev)
5090 : : {
5091 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
5092 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
5093 : :
5094 : : /* enable device (incl. PCI PM wakeup), and bus-mastering */
5095 : 0 : bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
5096 : 0 : bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
5097 [ # # # # ]: 0 : if (!bp->bar0 || !bp->doorbell_base) {
5098 : 0 : PMD_DRV_LOG_LINE(ERR, "Unable to access Hardware");
5099 : 0 : return -ENODEV;
5100 : : }
5101 : :
5102 : 0 : bp->eth_dev = eth_dev;
5103 : 0 : bp->pdev = pci_dev;
5104 : :
5105 : 0 : return 0;
5106 : : }
5107 : :
5108 : 0 : static void bnxt_init_ctxm_mem(struct bnxt_ctx_mem *ctxm, void *p, int len)
5109 : : {
5110 : 0 : uint8_t init_val = ctxm->init_value;
5111 : 0 : uint16_t offset = ctxm->init_offset;
5112 : : uint8_t *p2 = p;
5113 : : int i;
5114 : :
5115 [ # # ]: 0 : if (!init_val)
5116 : : return;
5117 [ # # ]: 0 : if (offset == BNXT_CTX_INIT_INVALID_OFFSET) {
5118 : 0 : memset(p, init_val, len);
5119 : 0 : return;
5120 : : }
5121 [ # # ]: 0 : for (i = 0; i < len; i += ctxm->entry_size)
5122 : 0 : *(p2 + i + offset) = init_val;
5123 : : }
5124 : :
5125 : 0 : static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp,
5126 : : struct bnxt_ctx_pg_info *ctx_pg,
5127 : : struct bnxt_ctx_mem *ctxm,
5128 : : uint32_t mem_size,
5129 : : const char *suffix,
5130 : : uint16_t idx)
5131 : : {
5132 : : struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem;
5133 : : const struct rte_memzone *mz = NULL;
5134 : : char name[RTE_MEMZONE_NAMESIZE];
5135 : : rte_iova_t mz_phys_addr;
5136 : : uint64_t valid_bits = 0;
5137 : : uint32_t sz;
5138 : : int i;
5139 : :
5140 [ # # ]: 0 : if (!mem_size)
5141 : : return 0;
5142 : :
5143 : 0 : rmem->nr_pages =
5144 : 0 : RTE_ALIGN_MUL_CEIL(mem_size, BNXT_PAGE_SIZE) / BNXT_PAGE_SIZE;
5145 : 0 : rmem->page_size = BNXT_PAGE_SIZE;
5146 : :
5147 : 0 : snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_pg_arr%s_%x_%d",
5148 : 0 : suffix, idx, bp->eth_dev->data->port_id);
5149 : 0 : ctx_pg->ctx_pg_arr = rte_zmalloc(name, sizeof(void *) * rmem->nr_pages, 0);
5150 [ # # ]: 0 : if (ctx_pg->ctx_pg_arr == NULL)
5151 : : return -ENOMEM;
5152 : :
5153 : 0 : snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_dma_arr%s_%x_%d",
5154 : 0 : suffix, idx, bp->eth_dev->data->port_id);
5155 : 0 : ctx_pg->ctx_dma_arr = rte_zmalloc(name, sizeof(rte_iova_t *) * rmem->nr_pages, 0);
5156 [ # # ]: 0 : if (ctx_pg->ctx_dma_arr == NULL)
5157 : : return -ENOMEM;
5158 : :
5159 : 0 : rmem->pg_arr = ctx_pg->ctx_pg_arr;
5160 : 0 : rmem->dma_arr = ctx_pg->ctx_dma_arr;
5161 : 0 : rmem->flags = BNXT_RMEM_VALID_PTE_FLAG | BNXT_RMEM_USE_FULL_PAGE_FLAG;
5162 : :
5163 : : valid_bits = PTU_PTE_VALID;
5164 : :
5165 [ # # ]: 0 : if (rmem->nr_pages > 1) {
5166 : 0 : snprintf(name, RTE_MEMZONE_NAMESIZE,
5167 : : "bnxt_ctxpgtbl%s_%x_%d",
5168 : 0 : suffix, idx, bp->eth_dev->data->port_id);
5169 : 0 : name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5170 : 0 : mz = rte_memzone_lookup(name);
5171 [ # # ]: 0 : if (!mz) {
5172 : 0 : mz = rte_memzone_reserve_aligned(name,
5173 : 0 : rmem->nr_pages * 8,
5174 : 0 : bp->eth_dev->device->numa_node,
5175 : : RTE_MEMZONE_2MB |
5176 : : RTE_MEMZONE_SIZE_HINT_ONLY,
5177 : : BNXT_PAGE_SIZE);
5178 [ # # ]: 0 : if (mz == NULL)
5179 : : return -ENOMEM;
5180 : : }
5181 : :
5182 [ # # ]: 0 : memset(mz->addr, 0xff, mz->len);
5183 : 0 : mz_phys_addr = mz->iova;
5184 : :
5185 [ # # ]: 0 : if (ctxm != NULL)
5186 : 0 : bnxt_init_ctxm_mem(ctxm, mz->addr, mz->len);
5187 : 0 : rmem->pg_tbl = mz->addr;
5188 : 0 : rmem->pg_tbl_map = mz_phys_addr;
5189 : 0 : rmem->pg_tbl_mz = mz;
5190 : : }
5191 : :
5192 : 0 : snprintf(name, RTE_MEMZONE_NAMESIZE, "bnxt_ctx_%s_%x_%d",
5193 : 0 : suffix, idx, bp->eth_dev->data->port_id);
5194 : 0 : mz = rte_memzone_lookup(name);
5195 [ # # ]: 0 : if (!mz) {
5196 : 0 : mz = rte_memzone_reserve_aligned(name,
5197 : : mem_size,
5198 : 0 : bp->eth_dev->device->numa_node,
5199 : : RTE_MEMZONE_1GB |
5200 : : RTE_MEMZONE_SIZE_HINT_ONLY,
5201 : : BNXT_PAGE_SIZE);
5202 [ # # ]: 0 : if (mz == NULL)
5203 : : return -ENOMEM;
5204 : : }
5205 : :
5206 [ # # ]: 0 : memset(mz->addr, 0xff, mz->len);
5207 : 0 : mz_phys_addr = mz->iova;
5208 : :
5209 [ # # ]: 0 : if (ctxm != NULL)
5210 : 0 : bnxt_init_ctxm_mem(ctxm, mz->addr, mz->len);
5211 [ # # ]: 0 : for (sz = 0, i = 0; sz < mem_size; sz += BNXT_PAGE_SIZE, i++) {
5212 : 0 : rmem->pg_arr[i] = ((char *)mz->addr) + sz;
5213 : 0 : rmem->dma_arr[i] = mz_phys_addr + sz;
5214 : :
5215 [ # # ]: 0 : if (rmem->nr_pages > 1) {
5216 [ # # ]: 0 : if (i == rmem->nr_pages - 2 &&
5217 [ # # ]: 0 : (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
5218 : 0 : valid_bits |= PTU_PTE_NEXT_TO_LAST;
5219 [ # # ]: 0 : else if (i == rmem->nr_pages - 1 &&
5220 [ # # ]: 0 : (rmem->flags & BNXT_RMEM_RING_PTE_FLAG))
5221 : 0 : valid_bits |= PTU_PTE_LAST;
5222 : :
5223 : 0 : rmem->pg_tbl[i] = rte_cpu_to_le_64(rmem->dma_arr[i] |
5224 : : valid_bits);
5225 : : }
5226 : : }
5227 : :
5228 : 0 : rmem->mz = mz;
5229 [ # # ]: 0 : if (rmem->vmem_size)
5230 : 0 : rmem->vmem = (void **)mz->addr;
5231 : 0 : rmem->dma_arr[0] = mz_phys_addr;
5232 : 0 : return 0;
5233 : : }
5234 : :
5235 : 0 : static void bnxt_free_ctx_mem_v2(struct bnxt *bp)
5236 : : {
5237 : : uint16_t type;
5238 : :
5239 [ # # ]: 0 : for (type = 0; type < bp->ctx->types; type++) {
5240 : 0 : struct bnxt_ctx_mem *ctxm = &bp->ctx->ctx_arr[type];
5241 : 0 : struct bnxt_ctx_pg_info *ctx_pg = ctxm->pg_info;
5242 : : int i, n = 1;
5243 : :
5244 [ # # ]: 0 : if (!ctx_pg)
5245 : 0 : continue;
5246 [ # # ]: 0 : if (ctxm->instance_bmap)
5247 : 0 : n = hweight32(ctxm->instance_bmap);
5248 : :
5249 [ # # ]: 0 : for (i = 0; i < n; i++) {
5250 : 0 : rte_free(ctx_pg[i].ctx_pg_arr);
5251 : 0 : rte_free(ctx_pg[i].ctx_dma_arr);
5252 : 0 : rte_memzone_free(ctx_pg[i].ring_mem.mz);
5253 : 0 : rte_memzone_free(ctx_pg[i].ring_mem.pg_tbl_mz);
5254 : : }
5255 : :
5256 : 0 : rte_free(ctx_pg);
5257 : 0 : ctxm->pg_info = NULL;
5258 : : }
5259 : 0 : rte_free(bp->ctx->ctx_arr);
5260 : 0 : bp->ctx->ctx_arr = NULL;
5261 : 0 : }
5262 : :
5263 : 0 : static void bnxt_free_ctx_mem(struct bnxt *bp)
5264 : : {
5265 : : int i;
5266 : :
5267 [ # # # # ]: 0 : if (!bp->ctx || !(bp->ctx->flags & BNXT_CTX_FLAG_INITED))
5268 : : return;
5269 : :
5270 : 0 : bp->ctx->flags &= ~BNXT_CTX_FLAG_INITED;
5271 : :
5272 [ # # ]: 0 : if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
5273 : 0 : bnxt_free_ctx_mem_v2(bp);
5274 : 0 : goto free_ctx;
5275 : : }
5276 : :
5277 : 0 : rte_free(bp->ctx->qp_mem.ctx_pg_arr);
5278 : 0 : rte_free(bp->ctx->srq_mem.ctx_pg_arr);
5279 : 0 : rte_free(bp->ctx->cq_mem.ctx_pg_arr);
5280 : 0 : rte_free(bp->ctx->vnic_mem.ctx_pg_arr);
5281 : 0 : rte_free(bp->ctx->stat_mem.ctx_pg_arr);
5282 : 0 : rte_free(bp->ctx->qp_mem.ctx_dma_arr);
5283 : 0 : rte_free(bp->ctx->srq_mem.ctx_dma_arr);
5284 : 0 : rte_free(bp->ctx->cq_mem.ctx_dma_arr);
5285 : 0 : rte_free(bp->ctx->vnic_mem.ctx_dma_arr);
5286 : 0 : rte_free(bp->ctx->stat_mem.ctx_dma_arr);
5287 : :
5288 : 0 : rte_memzone_free(bp->ctx->qp_mem.ring_mem.mz);
5289 : 0 : rte_memzone_free(bp->ctx->srq_mem.ring_mem.mz);
5290 : 0 : rte_memzone_free(bp->ctx->cq_mem.ring_mem.mz);
5291 : 0 : rte_memzone_free(bp->ctx->vnic_mem.ring_mem.mz);
5292 : 0 : rte_memzone_free(bp->ctx->stat_mem.ring_mem.mz);
5293 : 0 : rte_memzone_free(bp->ctx->qp_mem.ring_mem.pg_tbl_mz);
5294 : 0 : rte_memzone_free(bp->ctx->srq_mem.ring_mem.pg_tbl_mz);
5295 : 0 : rte_memzone_free(bp->ctx->cq_mem.ring_mem.pg_tbl_mz);
5296 : 0 : rte_memzone_free(bp->ctx->vnic_mem.ring_mem.pg_tbl_mz);
5297 : 0 : rte_memzone_free(bp->ctx->stat_mem.ring_mem.pg_tbl_mz);
5298 : :
5299 [ # # ]: 0 : for (i = 0; i < bp->ctx->tqm_fp_rings_count + 1; i++) {
5300 : 0 : rte_free(bp->ctx->tqm_mem[i]->ctx_pg_arr);
5301 : 0 : rte_free(bp->ctx->tqm_mem[i]->ctx_dma_arr);
5302 [ # # ]: 0 : if (bp->ctx->tqm_mem[i])
5303 : 0 : rte_memzone_free(bp->ctx->tqm_mem[i]->ring_mem.mz);
5304 : : }
5305 : :
5306 : 0 : free_ctx:
5307 : 0 : rte_free(bp->ctx);
5308 : 0 : bp->ctx = NULL;
5309 : : }
5310 : :
5311 : : #define bnxt_roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
5312 : :
5313 : : #define clamp_t(type, _x, min, max) RTE_MIN_T(RTE_MAX_T(_x, min, type), max, type)
5314 : :
5315 : 0 : int bnxt_alloc_ctx_pg_tbls(struct bnxt *bp)
5316 : : {
5317 : 0 : struct bnxt_ctx_mem_info *ctx = bp->ctx;
5318 : : struct bnxt_ctx_mem *ctx2;
5319 : : uint16_t type;
5320 : : int rc = 0;
5321 : :
5322 : 0 : ctx2 = &ctx->ctx_arr[0];
5323 [ # # # # ]: 0 : for (type = 0; type < ctx->types && rc == 0; type++) {
5324 : 0 : struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[type];
5325 : : struct bnxt_ctx_pg_info *ctx_pg;
5326 : : uint32_t entries, mem_size;
5327 : : int w = 1;
5328 : : int i;
5329 : :
5330 [ # # ]: 0 : if (ctxm->entry_size == 0)
5331 : 0 : continue;
5332 : :
5333 : 0 : ctx_pg = ctxm->pg_info;
5334 : :
5335 [ # # ]: 0 : if (ctxm->instance_bmap)
5336 : 0 : w = hweight32(ctxm->instance_bmap);
5337 : :
5338 [ # # ]: 0 : for (i = 0; i < w && rc == 0; i++) {
5339 : 0 : char name[RTE_MEMZONE_NAMESIZE] = {0};
5340 : :
5341 [ # # ]: 0 : sprintf(name, "_%d_%d", i, type);
5342 : :
5343 [ # # ]: 0 : if (ctxm->entry_multiple)
5344 : 0 : entries = bnxt_roundup(ctxm->max_entries,
5345 : : ctxm->entry_multiple);
5346 : : else
5347 : 0 : entries = ctxm->max_entries;
5348 : :
5349 [ # # ]: 0 : if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_CQ)
5350 : 0 : entries = ctxm->cq_l2_entries;
5351 [ # # ]: 0 : else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_QP)
5352 : 0 : entries = ctxm->qp_l2_entries;
5353 [ # # ]: 0 : else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_MRAV)
5354 : 0 : entries = ctxm->mrav_av_entries;
5355 [ # # ]: 0 : else if (ctxm->type == HWRM_FUNC_BACKING_STORE_CFG_V2_INPUT_TYPE_TIM)
5356 : 0 : entries = ctx2->qp_l2_entries;
5357 : 0 : entries = clamp_t(uint32_t, entries, ctxm->min_entries,
5358 : : ctxm->max_entries);
5359 : 0 : ctx_pg[i].entries = entries;
5360 : 0 : mem_size = ctxm->entry_size * entries;
5361 : 0 : PMD_DRV_LOG_LINE(DEBUG,
5362 : : "Type:0x%x instance:%d entries:%d size:%d",
5363 : : ctxm->type, i, ctx_pg[i].entries, mem_size);
5364 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, &ctx_pg[i],
5365 [ # # ]: 0 : ctxm->init_value ? ctxm : NULL,
5366 : : mem_size, name, i);
5367 : : }
5368 : : }
5369 : :
5370 : 0 : return rc;
5371 : : }
5372 : :
5373 : 0 : int bnxt_alloc_ctx_mem(struct bnxt *bp)
5374 : : {
5375 : : struct bnxt_ctx_pg_info *ctx_pg;
5376 : : struct bnxt_ctx_mem_info *ctx;
5377 : : uint32_t mem_size, ena, entries;
5378 : : int types = BNXT_CTX_MIN;
5379 : : uint32_t entries_sp, min;
5380 : : int i, rc = 0;
5381 : :
5382 [ # # # # : 0 : if (!BNXT_FW_BACKING_STORE_V1_EN(bp) &&
# # ]
5383 [ # # ]: 0 : !BNXT_FW_BACKING_STORE_V2_EN(bp))
5384 : : return rc;
5385 : :
5386 [ # # ]: 0 : if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
5387 : 0 : types = bnxt_hwrm_func_backing_store_types_count(bp);
5388 [ # # ]: 0 : if (types <= 0)
5389 : : return types;
5390 : : }
5391 : :
5392 : 0 : rc = bnxt_hwrm_func_backing_store_ctx_alloc(bp, types);
5393 [ # # ]: 0 : if (rc != 0)
5394 : : return rc;
5395 : :
5396 [ # # ]: 0 : if (bp->ctx->flags & BNXT_CTX_FLAG_INITED)
5397 : : return 0;
5398 : :
5399 : : ctx = bp->ctx;
5400 [ # # ]: 0 : if (BNXT_FW_BACKING_STORE_V2_EN(bp)) {
5401 : 0 : rc = bnxt_hwrm_func_backing_store_qcaps_v2(bp);
5402 : :
5403 [ # # # # ]: 0 : for (i = 0 ; i < bp->ctx->types && rc == 0; i++) {
5404 : 0 : struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[i];
5405 : :
5406 : 0 : rc = bnxt_hwrm_func_backing_store_cfg_v2(bp, ctxm);
5407 : : }
5408 : 0 : goto done;
5409 : : }
5410 : :
5411 : 0 : rc = bnxt_hwrm_func_backing_store_qcaps(bp);
5412 [ # # ]: 0 : if (rc) {
5413 : 0 : PMD_DRV_LOG_LINE(ERR, "Query context mem capability failed");
5414 : 0 : return rc;
5415 : : }
5416 : :
5417 : 0 : ctx_pg = &ctx->qp_mem;
5418 : 0 : ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries;
5419 [ # # ]: 0 : if (ctx->qp_entry_size) {
5420 : 0 : mem_size = ctx->qp_entry_size * ctx_pg->entries;
5421 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "qp_mem", 0);
5422 [ # # ]: 0 : if (rc)
5423 : : return rc;
5424 : : }
5425 : :
5426 : 0 : ctx_pg = &ctx->srq_mem;
5427 : 0 : ctx_pg->entries = ctx->srq_max_l2_entries;
5428 [ # # ]: 0 : if (ctx->srq_entry_size) {
5429 : 0 : mem_size = ctx->srq_entry_size * ctx_pg->entries;
5430 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "srq_mem", 0);
5431 [ # # ]: 0 : if (rc)
5432 : : return rc;
5433 : : }
5434 : :
5435 : 0 : ctx_pg = &ctx->cq_mem;
5436 : 0 : ctx_pg->entries = ctx->cq_max_l2_entries;
5437 [ # # ]: 0 : if (ctx->cq_entry_size) {
5438 : 0 : mem_size = ctx->cq_entry_size * ctx_pg->entries;
5439 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "cq_mem", 0);
5440 [ # # ]: 0 : if (rc)
5441 : : return rc;
5442 : : }
5443 : :
5444 : 0 : ctx_pg = &ctx->vnic_mem;
5445 : 0 : ctx_pg->entries = ctx->vnic_max_vnic_entries +
5446 : 0 : ctx->vnic_max_ring_table_entries;
5447 [ # # ]: 0 : if (ctx->vnic_entry_size) {
5448 : 0 : mem_size = ctx->vnic_entry_size * ctx_pg->entries;
5449 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "vnic_mem", 0);
5450 [ # # ]: 0 : if (rc)
5451 : : return rc;
5452 : : }
5453 : :
5454 : 0 : ctx_pg = &ctx->stat_mem;
5455 : 0 : ctx_pg->entries = ctx->stat_max_entries;
5456 [ # # ]: 0 : if (ctx->stat_entry_size) {
5457 : 0 : mem_size = ctx->stat_entry_size * ctx_pg->entries;
5458 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL, mem_size, "stat_mem", 0);
5459 [ # # ]: 0 : if (rc)
5460 : : return rc;
5461 : : }
5462 : :
5463 : 0 : min = ctx->tqm_min_entries_per_ring;
5464 : :
5465 : 0 : entries_sp = ctx->qp_max_l2_entries +
5466 : 0 : ctx->vnic_max_vnic_entries +
5467 : 0 : 2 * ctx->qp_min_qp1_entries + min;
5468 : 0 : entries_sp = bnxt_roundup(entries_sp, ctx->tqm_entries_multiple);
5469 : :
5470 : 0 : entries = ctx->qp_max_l2_entries + ctx->qp_min_qp1_entries;
5471 : 0 : entries = bnxt_roundup(entries, ctx->tqm_entries_multiple);
5472 : 0 : entries = clamp_t(uint32_t, entries, min,
5473 : : ctx->tqm_max_entries_per_ring);
5474 [ # # ]: 0 : for (i = 0, ena = 0; i < ctx->tqm_fp_rings_count + 1; i++) {
5475 : : /* i=0 is for TQM_SP. i=1 to i=8 applies to RING0 to RING7.
5476 : : * i > 8 is other ext rings.
5477 : : */
5478 : 0 : ctx_pg = ctx->tqm_mem[i];
5479 [ # # ]: 0 : ctx_pg->entries = i ? entries : entries_sp;
5480 [ # # ]: 0 : if (ctx->tqm_entry_size) {
5481 : 0 : mem_size = ctx->tqm_entry_size * ctx_pg->entries;
5482 : 0 : rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, NULL,
5483 : : mem_size, "tqm_mem", i);
5484 [ # # ]: 0 : if (rc)
5485 : 0 : return rc;
5486 : : }
5487 [ # # ]: 0 : if (i < BNXT_MAX_TQM_LEGACY_RINGS)
5488 : 0 : ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP << i;
5489 : : else
5490 : 0 : ena |= HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8;
5491 : : }
5492 : :
5493 : 0 : ena |= FUNC_BACKING_STORE_CFG_INPUT_DFLT_ENABLES;
5494 : 0 : rc = bnxt_hwrm_func_backing_store_cfg(bp, ena);
5495 : 0 : done:
5496 [ # # ]: 0 : if (rc)
5497 : 0 : PMD_DRV_LOG_LINE(ERR,
5498 : : "Failed to configure context mem: rc = %d", rc);
5499 : : else
5500 : 0 : ctx->flags |= BNXT_CTX_FLAG_INITED;
5501 : :
5502 : : return rc;
5503 : : }
5504 : :
5505 : 0 : static int bnxt_alloc_stats_mem(struct bnxt *bp)
5506 : : {
5507 : 0 : struct rte_pci_device *pci_dev = bp->pdev;
5508 : : char mz_name[RTE_MEMZONE_NAMESIZE];
5509 : : const struct rte_memzone *mz = NULL;
5510 : : uint32_t total_alloc_len;
5511 : : rte_iova_t mz_phys_addr;
5512 : :
5513 [ # # ]: 0 : if (pci_dev->id.device_id == BROADCOM_DEV_ID_NS2)
5514 : : return 0;
5515 : :
5516 : 0 : snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5517 : : "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5518 : 0 : pci_dev->addr.bus, pci_dev->addr.devid,
5519 : 0 : pci_dev->addr.function, "rx_port_stats");
5520 : 0 : mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5521 : 0 : mz = rte_memzone_lookup(mz_name);
5522 : : total_alloc_len =
5523 : : RTE_CACHE_LINE_ROUNDUP(sizeof(struct rx_port_stats) +
5524 : : sizeof(struct rx_port_stats_ext) + 512);
5525 [ # # ]: 0 : if (!mz) {
5526 : 0 : mz = rte_memzone_reserve(mz_name, total_alloc_len,
5527 : : SOCKET_ID_ANY,
5528 : : RTE_MEMZONE_2MB |
5529 : : RTE_MEMZONE_SIZE_HINT_ONLY |
5530 : : RTE_MEMZONE_IOVA_CONTIG);
5531 [ # # ]: 0 : if (mz == NULL)
5532 : : return -ENOMEM;
5533 : : }
5534 : 0 : memset(mz->addr, 0, mz->len);
5535 : 0 : mz_phys_addr = mz->iova;
5536 : :
5537 : 0 : bp->rx_mem_zone = (const void *)mz;
5538 : 0 : bp->hw_rx_port_stats = mz->addr;
5539 : 0 : bp->hw_rx_port_stats_map = mz_phys_addr;
5540 : :
5541 : 0 : snprintf(mz_name, RTE_MEMZONE_NAMESIZE,
5542 : : "bnxt_" PCI_PRI_FMT "-%s", pci_dev->addr.domain,
5543 : 0 : pci_dev->addr.bus, pci_dev->addr.devid,
5544 : 0 : pci_dev->addr.function, "tx_port_stats");
5545 : 0 : mz_name[RTE_MEMZONE_NAMESIZE - 1] = 0;
5546 : 0 : mz = rte_memzone_lookup(mz_name);
5547 : : total_alloc_len =
5548 : : RTE_CACHE_LINE_ROUNDUP(sizeof(struct tx_port_stats) +
5549 : : sizeof(struct tx_port_stats_ext) + 512);
5550 [ # # ]: 0 : if (!mz) {
5551 : 0 : mz = rte_memzone_reserve(mz_name,
5552 : : total_alloc_len,
5553 : : SOCKET_ID_ANY,
5554 : : RTE_MEMZONE_2MB |
5555 : : RTE_MEMZONE_SIZE_HINT_ONLY |
5556 : : RTE_MEMZONE_IOVA_CONTIG);
5557 [ # # ]: 0 : if (mz == NULL)
5558 : : return -ENOMEM;
5559 : : }
5560 [ # # ]: 0 : memset(mz->addr, 0, mz->len);
5561 : 0 : mz_phys_addr = mz->iova;
5562 : :
5563 : 0 : bp->tx_mem_zone = (const void *)mz;
5564 : 0 : bp->hw_tx_port_stats = mz->addr;
5565 : 0 : bp->hw_tx_port_stats_map = mz_phys_addr;
5566 : 0 : bp->flags |= BNXT_FLAG_PORT_STATS;
5567 : :
5568 : : /* Display extended statistics if FW supports it */
5569 [ # # ]: 0 : if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_8_4 ||
5570 [ # # ]: 0 : bp->hwrm_spec_code == HWRM_SPEC_CODE_1_9_0 ||
5571 : : !(bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED))
5572 : : return 0;
5573 : :
5574 : 0 : bp->hw_rx_port_stats_ext = (void *)
5575 : 0 : ((uint8_t *)bp->hw_rx_port_stats +
5576 : : sizeof(struct rx_port_stats));
5577 : 0 : bp->hw_rx_port_stats_ext_map = bp->hw_rx_port_stats_map +
5578 : : sizeof(struct rx_port_stats);
5579 : 0 : bp->flags |= BNXT_FLAG_EXT_RX_PORT_STATS;
5580 : :
5581 : : if (bp->hwrm_spec_code < HWRM_SPEC_CODE_1_9_2 ||
5582 : : bp->flags & BNXT_FLAG_EXT_STATS_SUPPORTED) {
5583 : 0 : bp->hw_tx_port_stats_ext = (void *)
5584 : : ((uint8_t *)bp->hw_tx_port_stats +
5585 : : sizeof(struct tx_port_stats));
5586 : 0 : bp->hw_tx_port_stats_ext_map =
5587 : 0 : bp->hw_tx_port_stats_map +
5588 : : sizeof(struct tx_port_stats);
5589 : 0 : bp->flags |= BNXT_FLAG_EXT_TX_PORT_STATS;
5590 : : }
5591 : :
5592 : 0 : return 0;
5593 : : }
5594 : :
5595 : 0 : static int bnxt_setup_mac_addr(struct rte_eth_dev *eth_dev)
5596 : : {
5597 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
5598 : 0 : size_t max_mac_addr = RTE_MIN(bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
5599 : : int rc = 0;
5600 : :
5601 [ # # ]: 0 : if (bp->max_l2_ctx > RTE_ETH_NUM_RECEIVE_MAC_ADDR)
5602 : 0 : PMD_DRV_LOG_LINE(INFO, "Max number of MAC addrs supported is %d, but will be limited to %d",
5603 : : bp->max_l2_ctx, RTE_ETH_NUM_RECEIVE_MAC_ADDR);
5604 : :
5605 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("bnxt_mac_addr_tbl",
5606 : : RTE_ETHER_ADDR_LEN * max_mac_addr,
5607 : : 0);
5608 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
5609 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc MAC addr tbl");
5610 : 0 : return -ENOMEM;
5611 : : }
5612 : :
5613 [ # # ]: 0 : if (!BNXT_HAS_DFLT_MAC_SET(bp)) {
5614 [ # # ]: 0 : if (BNXT_PF(bp))
5615 : : return -EINVAL;
5616 : :
5617 : : /* Generate a random MAC address, if none was assigned by PF */
5618 : 0 : PMD_DRV_LOG_LINE(INFO, "VF MAC address not assigned by Host PF");
5619 : 0 : bnxt_eth_hw_addr_random(bp->mac_addr);
5620 : 0 : PMD_DRV_LOG_LINE(INFO,
5621 : : "Assign random MAC:" RTE_ETHER_ADDR_PRT_FMT,
5622 : : bp->mac_addr[0], bp->mac_addr[1], bp->mac_addr[2],
5623 : : bp->mac_addr[3], bp->mac_addr[4], bp->mac_addr[5]);
5624 : :
5625 : 0 : rc = bnxt_hwrm_set_mac(bp);
5626 [ # # ]: 0 : if (rc)
5627 : : return rc;
5628 : : }
5629 : :
5630 : : /* Copy the permanent MAC from the FUNC_QCAPS response */
5631 : 0 : memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, RTE_ETHER_ADDR_LEN);
5632 : :
5633 : : /*
5634 : : * Allocate memory to hold multicast mac addresses added.
5635 : : * Used to restore them during reset recovery
5636 : : */
5637 : 0 : bp->mcast_addr_list = rte_zmalloc("bnxt_mcast_addr_tbl",
5638 : : sizeof(struct rte_ether_addr) *
5639 : 0 : BNXT_MAX_MC_ADDRS, 0);
5640 [ # # ]: 0 : if (bp->mcast_addr_list == NULL) {
5641 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate multicast addr table");
5642 : 0 : return -ENOMEM;
5643 : : }
5644 : 0 : bp->mc_list_dma_addr = rte_malloc_virt2iova(bp->mcast_addr_list);
5645 [ # # ]: 0 : if (bp->mc_list_dma_addr == RTE_BAD_IOVA) {
5646 : 0 : PMD_DRV_LOG_LINE(ERR, "Fail to map mcast_addr_list to physical memory");
5647 : 0 : return -ENOMEM;
5648 : : }
5649 : :
5650 : : return rc;
5651 : : }
5652 : :
5653 : 0 : static int bnxt_restore_dflt_mac(struct bnxt *bp)
5654 : : {
5655 : : int rc = 0;
5656 : :
5657 : : /* MAC is already configured in FW */
5658 [ # # ]: 0 : if (BNXT_HAS_DFLT_MAC_SET(bp))
5659 : : return 0;
5660 : :
5661 : : /* Restore the old MAC configured */
5662 : 0 : rc = bnxt_hwrm_set_mac(bp);
5663 [ # # ]: 0 : if (rc)
5664 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to restore MAC address");
5665 : :
5666 : : return rc;
5667 : : }
5668 : :
5669 : 0 : static void bnxt_config_vf_req_fwd(struct bnxt *bp)
5670 : : {
5671 [ # # ]: 0 : if (!BNXT_PF(bp))
5672 : : return;
5673 : :
5674 [ # # ]: 0 : memset(bp->pf->vf_req_fwd, 0, sizeof(bp->pf->vf_req_fwd));
5675 : :
5676 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_LINK_ADMIN))
5677 : 0 : BNXT_HWRM_CMD_TO_FORWARD(HWRM_PORT_PHY_QCFG);
5678 : 0 : BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_CFG);
5679 : 0 : BNXT_HWRM_CMD_TO_FORWARD(HWRM_FUNC_VF_CFG);
5680 : 0 : BNXT_HWRM_CMD_TO_FORWARD(HWRM_CFA_L2_FILTER_ALLOC);
5681 : 0 : BNXT_HWRM_CMD_TO_FORWARD(HWRM_OEM_CMD);
5682 : : }
5683 : :
5684 : 0 : static void bnxt_alloc_error_recovery_info(struct bnxt *bp)
5685 : : {
5686 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
5687 : :
5688 [ # # ]: 0 : if (info) {
5689 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS))
5690 : : memset(info, 0, sizeof(*info));
5691 : 0 : return;
5692 : : }
5693 : :
5694 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
5695 : : return;
5696 : :
5697 : 0 : info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5698 : : sizeof(*info), 0);
5699 [ # # ]: 0 : if (!info)
5700 : 0 : bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5701 : :
5702 : 0 : bp->recovery_info = info;
5703 : : }
5704 : :
5705 : 0 : static void bnxt_check_fw_status(struct bnxt *bp)
5706 : : {
5707 : : uint32_t fw_status;
5708 : :
5709 [ # # ]: 0 : if (!(bp->recovery_info &&
5710 [ # # ]: 0 : (bp->fw_cap & BNXT_FW_CAP_HCOMM_FW_STATUS)))
5711 : : return;
5712 : :
5713 : 0 : fw_status = bnxt_read_fw_status_reg(bp, BNXT_FW_STATUS_REG);
5714 [ # # ]: 0 : if (fw_status != BNXT_FW_STATUS_HEALTHY)
5715 : 0 : PMD_DRV_LOG_LINE(ERR, "Firmware not responding, status: %#x",
5716 : : fw_status);
5717 : : }
5718 : :
5719 : 0 : static int bnxt_map_hcomm_fw_status_reg(struct bnxt *bp)
5720 : : {
5721 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
5722 : : uint32_t status_loc;
5723 : : uint32_t sig_ver;
5724 : :
5725 : 0 : rte_write32(HCOMM_STATUS_STRUCT_LOC, (uint8_t *)bp->bar0 +
5726 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5727 : 0 : sig_ver = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5728 : : BNXT_GRCP_WINDOW_2_BASE +
5729 : : offsetof(struct hcomm_status,
5730 : : sig_ver)));
5731 : : /* If the signature is absent, then FW does not support this feature */
5732 [ # # ]: 0 : if ((sig_ver & HCOMM_STATUS_SIGNATURE_MASK) !=
5733 : : HCOMM_STATUS_SIGNATURE_VAL)
5734 : : return 0;
5735 : :
5736 [ # # ]: 0 : if (!info) {
5737 : 0 : info = rte_zmalloc("bnxt_hwrm_error_recovery_qcfg",
5738 : : sizeof(*info), 0);
5739 [ # # ]: 0 : if (!info)
5740 : : return -ENOMEM;
5741 : 0 : bp->recovery_info = info;
5742 : : } else {
5743 : : memset(info, 0, sizeof(*info));
5744 : : }
5745 : :
5746 : 0 : status_loc = rte_le_to_cpu_32(rte_read32((uint8_t *)bp->bar0 +
5747 : : BNXT_GRCP_WINDOW_2_BASE +
5748 : : offsetof(struct hcomm_status,
5749 : : fw_status_loc)));
5750 : :
5751 : : /* Only pre-map the FW health status GRC register */
5752 [ # # ]: 0 : if (BNXT_FW_STATUS_REG_TYPE(status_loc) != BNXT_FW_STATUS_REG_TYPE_GRC)
5753 : : return 0;
5754 : :
5755 : 0 : info->status_regs[BNXT_FW_STATUS_REG] = status_loc;
5756 : 0 : info->mapped_status_regs[BNXT_FW_STATUS_REG] =
5757 : 0 : BNXT_GRCP_WINDOW_2_BASE + (status_loc & BNXT_GRCP_OFFSET_MASK);
5758 : :
5759 : 0 : rte_write32((status_loc & BNXT_GRCP_BASE_MASK), (uint8_t *)bp->bar0 +
5760 : : BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4);
5761 : :
5762 : 0 : bp->fw_cap |= BNXT_FW_CAP_HCOMM_FW_STATUS;
5763 : :
5764 : 0 : return 0;
5765 : : }
5766 : :
5767 : : /* This function gets the FW version along with the
5768 : : * capabilities(MAX and current) of the function, vnic,
5769 : : * error recovery, phy and other chip related info
5770 : : */
5771 : 0 : static int bnxt_get_config(struct bnxt *bp)
5772 : : {
5773 : : uint16_t mtu;
5774 : : int timeout;
5775 : : int rc = 0;
5776 : :
5777 : 0 : bp->fw_cap = 0;
5778 : :
5779 : 0 : rc = bnxt_map_hcomm_fw_status_reg(bp);
5780 [ # # ]: 0 : if (rc)
5781 : : return rc;
5782 : :
5783 : 0 : timeout = BNXT_CHIP_P7(bp) ?
5784 [ # # ]: 0 : PCI_FUNC_RESET_WAIT_TIMEOUT :
5785 : : DFLT_HWRM_CMD_TIMEOUT;
5786 : 0 : try_again:
5787 : 0 : rc = bnxt_hwrm_ver_get(bp, timeout);
5788 [ # # ]: 0 : if (rc) {
5789 [ # # ]: 0 : if (rc == -ETIMEDOUT && timeout == PCI_FUNC_RESET_WAIT_TIMEOUT) {
5790 : 0 : bp->flags &= ~BNXT_FLAG_FW_TIMEDOUT;
5791 : : timeout = DFLT_HWRM_CMD_TIMEOUT;
5792 : 0 : goto try_again;
5793 : : }
5794 : 0 : bnxt_check_fw_status(bp);
5795 : 0 : return rc;
5796 : : }
5797 : :
5798 : 0 : rc = bnxt_hwrm_func_reset(bp);
5799 [ # # ]: 0 : if (rc)
5800 : : return -EIO;
5801 : :
5802 : 0 : rc = bnxt_hwrm_vnic_qcaps(bp);
5803 [ # # ]: 0 : if (rc)
5804 : : return rc;
5805 : :
5806 : : if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
5807 : 0 : PMD_DRV_LOG_LINE(INFO, "Compressed CQE is set. Truflow is disabled.");
5808 : 0 : bp->fw_cap &= ~BNXT_FW_CAP_TRUFLOW_EN;
5809 : : }
5810 : :
5811 : 0 : rc = bnxt_hwrm_queue_qportcfg(bp);
5812 [ # # ]: 0 : if (rc)
5813 : : return rc;
5814 : :
5815 : : /* Get the MAX capabilities for this function.
5816 : : * This function also allocates context memory for TQM rings and
5817 : : * informs the firmware about this allocated backing store memory.
5818 : : */
5819 : 0 : rc = bnxt_hwrm_func_qcaps(bp);
5820 [ # # ]: 0 : if (rc)
5821 : : return rc;
5822 : :
5823 : 0 : rc = bnxt_hwrm_func_qcfg(bp, &mtu);
5824 [ # # ]: 0 : if (rc)
5825 : : return rc;
5826 : :
5827 : 0 : bnxt_hwrm_port_mac_qcfg(bp);
5828 : :
5829 : 0 : bnxt_hwrm_parent_pf_qcfg(bp);
5830 : :
5831 : 0 : bnxt_hwrm_port_phy_qcaps(bp);
5832 : :
5833 : 0 : bnxt_alloc_error_recovery_info(bp);
5834 : : /* Get the adapter error recovery support info */
5835 : 0 : rc = bnxt_hwrm_error_recovery_qcfg(bp);
5836 [ # # ]: 0 : if (rc)
5837 : 0 : bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
5838 : :
5839 : 0 : bnxt_hwrm_port_led_qcaps(bp);
5840 : :
5841 : 0 : return 0;
5842 : : }
5843 : :
5844 : : static int
5845 : 0 : bnxt_init_locks(struct bnxt *bp)
5846 : : {
5847 : 0 : pthread_mutex_init(&bp->flow_lock, NULL);
5848 : 0 : pthread_mutex_init(&bp->def_cp_lock, NULL);
5849 : 0 : pthread_mutex_init(&bp->health_check_lock, NULL);
5850 : 0 : pthread_mutex_init(&bp->err_recovery_lock, NULL);
5851 : :
5852 : 0 : return 0;
5853 : : }
5854 : :
5855 : : /* This should be called after we have queried trusted VF cap */
5856 : 0 : static int bnxt_alloc_switch_domain(struct bnxt *bp)
5857 : : {
5858 : : int rc = 0;
5859 : :
5860 [ # # ]: 0 : if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
5861 : 0 : rc = rte_eth_switch_domain_alloc(&bp->switch_domain_id);
5862 [ # # ]: 0 : if (rc)
5863 : 0 : PMD_DRV_LOG_LINE(ERR,
5864 : : "Failed to alloc switch domain: %d", rc);
5865 : : else
5866 : 0 : PMD_DRV_LOG_LINE(INFO,
5867 : : "Switch domain allocated %d",
5868 : : bp->switch_domain_id);
5869 : : }
5870 : :
5871 : 0 : return rc;
5872 : : }
5873 : :
5874 : 0 : static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
5875 : : {
5876 : : int rc = 0;
5877 : :
5878 [ # # ]: 0 : if (reconfig_dev) {
5879 : 0 : rc = bnxt_get_config(bp);
5880 [ # # ]: 0 : if (rc)
5881 : : return rc;
5882 : : }
5883 : :
5884 : 0 : rc = bnxt_alloc_switch_domain(bp);
5885 [ # # ]: 0 : if (rc)
5886 : : return rc;
5887 : :
5888 [ # # ]: 0 : if (!reconfig_dev) {
5889 : 0 : rc = bnxt_setup_mac_addr(bp->eth_dev);
5890 [ # # ]: 0 : if (rc)
5891 : : return rc;
5892 : : } else {
5893 : 0 : rc = bnxt_restore_dflt_mac(bp);
5894 [ # # ]: 0 : if (rc)
5895 : : return rc;
5896 : : }
5897 : :
5898 : 0 : bnxt_config_vf_req_fwd(bp);
5899 : :
5900 : 0 : rc = bnxt_hwrm_func_driver_register(bp);
5901 [ # # ]: 0 : if (rc) {
5902 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to register driver");
5903 : 0 : return -EBUSY;
5904 : : }
5905 : :
5906 [ # # ]: 0 : if (BNXT_PF(bp)) {
5907 [ # # ]: 0 : if (bp->pdev->max_vfs) {
5908 : 0 : rc = bnxt_hwrm_allocate_vfs(bp, bp->pdev->max_vfs);
5909 [ # # ]: 0 : if (rc) {
5910 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate VFs");
5911 : 0 : return rc;
5912 : : }
5913 : : } else {
5914 : 0 : rc = bnxt_hwrm_allocate_pf_only(bp);
5915 [ # # ]: 0 : if (rc) {
5916 : 0 : PMD_DRV_LOG_LINE(ERR,
5917 : : "Failed to allocate PF resources");
5918 : 0 : return rc;
5919 : : }
5920 : : }
5921 : : }
5922 : :
5923 [ # # ]: 0 : if (!reconfig_dev) {
5924 : 0 : bp->rss_conf.rss_key = rte_zmalloc("bnxt_rss_key",
5925 : : HW_HASH_KEY_SIZE, 0);
5926 [ # # ]: 0 : if (bp->rss_conf.rss_key == NULL) {
5927 : 0 : PMD_DRV_LOG_LINE(ERR, "port %u cannot allocate RSS hash key memory",
5928 : : bp->eth_dev->data->port_id);
5929 : 0 : return -ENOMEM;
5930 : : }
5931 : : }
5932 : :
5933 : 0 : rc = bnxt_alloc_mem(bp, reconfig_dev);
5934 [ # # ]: 0 : if (rc)
5935 : : return rc;
5936 : :
5937 : 0 : rc = bnxt_setup_int(bp);
5938 [ # # ]: 0 : if (rc)
5939 : : return rc;
5940 : :
5941 : 0 : rc = bnxt_request_int(bp);
5942 [ # # ]: 0 : if (rc)
5943 : : return rc;
5944 : :
5945 : 0 : rc = bnxt_init_ctx_mem(bp);
5946 [ # # ]: 0 : if (rc) {
5947 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to init adv_flow_counters");
5948 : 0 : return rc;
5949 : : }
5950 : :
5951 : : return 0;
5952 : : }
5953 : :
5954 : : static int
5955 : 0 : bnxt_parse_devarg_flow_xstat(__rte_unused const char *key,
5956 : : const char *value, void *opaque_arg)
5957 : : {
5958 : : struct bnxt *bp = opaque_arg;
5959 : : unsigned long flow_xstat;
5960 : 0 : char *end = NULL;
5961 : :
5962 [ # # ]: 0 : if (!value || !opaque_arg) {
5963 : 0 : PMD_DRV_LOG_LINE(ERR,
5964 : : "Invalid parameter passed to flow_xstat devarg.");
5965 : 0 : return -EINVAL;
5966 : : }
5967 : :
5968 : 0 : flow_xstat = strtoul(value, &end, 10);
5969 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
5970 [ # # ]: 0 : (flow_xstat == ULONG_MAX && errno == ERANGE)) {
5971 : 0 : PMD_DRV_LOG_LINE(ERR,
5972 : : "Invalid parameter passed to flow_xstat devarg.");
5973 : 0 : return -EINVAL;
5974 : : }
5975 : :
5976 [ # # ]: 0 : if (BNXT_DEVARG_FLOW_XSTAT_INVALID(flow_xstat)) {
5977 : 0 : PMD_DRV_LOG_LINE(ERR,
5978 : : "Invalid value passed to flow_xstat devarg.");
5979 : 0 : return -EINVAL;
5980 : : }
5981 : :
5982 : 0 : bp->flags |= BNXT_FLAG_FLOW_XSTATS_EN;
5983 : : if (BNXT_FLOW_XSTATS_EN(bp))
5984 : 0 : PMD_DRV_LOG_LINE(INFO, "flow_xstat feature enabled.");
5985 : :
5986 : 0 : return 0;
5987 : : }
5988 : :
5989 : : static int
5990 : 0 : bnxt_parse_devarg_max_num_kflows(__rte_unused const char *key,
5991 : : const char *value, void *opaque_arg)
5992 : : {
5993 : : struct bnxt *bp = opaque_arg;
5994 : : unsigned long max_num_kflows;
5995 : 0 : char *end = NULL;
5996 : :
5997 [ # # ]: 0 : if (!value || !opaque_arg) {
5998 : 0 : PMD_DRV_LOG_LINE(ERR,
5999 : : "Invalid parameter passed to max_num_kflows devarg.");
6000 : 0 : return -EINVAL;
6001 : : }
6002 : :
6003 : 0 : max_num_kflows = strtoul(value, &end, 10);
6004 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6005 [ # # ]: 0 : (max_num_kflows == ULONG_MAX && errno == ERANGE)) {
6006 : 0 : PMD_DRV_LOG_LINE(ERR,
6007 : : "Invalid parameter passed to max_num_kflows devarg.");
6008 : 0 : return -EINVAL;
6009 : : }
6010 : :
6011 [ # # ]: 0 : if (bnxt_devarg_max_num_kflow_invalid(max_num_kflows)) {
6012 : 0 : PMD_DRV_LOG_LINE(ERR,
6013 : : "Invalid value passed to max_num_kflows devarg.");
6014 : 0 : return -EINVAL;
6015 : : }
6016 : :
6017 : 0 : bp->max_num_kflows = max_num_kflows;
6018 : : if (bp->max_num_kflows)
6019 : 0 : PMD_DRV_LOG_LINE(INFO, "max_num_kflows set as %ldK.",
6020 : : max_num_kflows);
6021 : :
6022 : 0 : return 0;
6023 : : }
6024 : :
6025 : : static int
6026 : 0 : bnxt_parse_devarg_cqe_mode(__rte_unused const char *key,
6027 : : const char *value, void *opaque_arg)
6028 : : {
6029 : : struct bnxt *bp = opaque_arg;
6030 : : unsigned long cqe_mode;
6031 : 0 : char *end = NULL;
6032 : :
6033 [ # # ]: 0 : if (!value || !opaque_arg) {
6034 : 0 : PMD_DRV_LOG_LINE(ERR,
6035 : : "Invalid parameter passed to cqe-mode "
6036 : : "devargs.");
6037 : 0 : return -EINVAL;
6038 : : }
6039 : :
6040 : 0 : cqe_mode = strtoul(value, &end, 10);
6041 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6042 [ # # ]: 0 : (cqe_mode == ULONG_MAX && errno == ERANGE)) {
6043 : 0 : PMD_DRV_LOG_LINE(ERR,
6044 : : "Invalid parameter passed to cqe-mode "
6045 : : "devargs.");
6046 : 0 : return -EINVAL;
6047 : : }
6048 : :
6049 [ # # ]: 0 : if (BNXT_DEVARG_CQE_MODE_INVALID(cqe_mode)) {
6050 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid cqe-mode(%d) devargs.",
6051 : : (uint16_t)cqe_mode);
6052 : 0 : return -EINVAL;
6053 : : }
6054 : :
6055 [ # # ]: 0 : if (cqe_mode == 1)
6056 : 0 : bp->flags2 |= BNXT_FLAGS2_COMPRESSED_RX_CQE;
6057 : 0 : PMD_DRV_LOG_LINE(INFO, "cqe-mode=%d feature enabled.", (uint8_t)cqe_mode);
6058 : :
6059 : 0 : return 0;
6060 : : }
6061 : :
6062 : : static int
6063 : 0 : bnxt_parse_devarg_app_id(__rte_unused const char *key,
6064 : : const char *value, void *opaque_arg)
6065 : : {
6066 : : struct bnxt *bp = opaque_arg;
6067 : : unsigned long app_id;
6068 : 0 : char *end = NULL;
6069 : :
6070 [ # # ]: 0 : if (!value || !opaque_arg) {
6071 : 0 : PMD_DRV_LOG_LINE(ERR,
6072 : : "Invalid parameter passed to app-id "
6073 : : "devargs.");
6074 : 0 : return -EINVAL;
6075 : : }
6076 : :
6077 : 0 : app_id = strtoul(value, &end, 10);
6078 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6079 [ # # ]: 0 : (app_id == ULONG_MAX && errno == ERANGE)) {
6080 : 0 : PMD_DRV_LOG_LINE(ERR,
6081 : : "Invalid parameter passed to app_id "
6082 : : "devargs.");
6083 : 0 : return -EINVAL;
6084 : : }
6085 : :
6086 [ # # ]: 0 : if (BNXT_DEVARG_APP_ID_INVALID(app_id)) {
6087 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid app-id(%d) devargs.",
6088 : : (uint16_t)app_id);
6089 : 0 : return -EINVAL;
6090 : : }
6091 : :
6092 : 0 : bp->app_id = app_id;
6093 : 0 : PMD_DRV_LOG_LINE(INFO, "app-id=%d feature enabled.", (uint16_t)app_id);
6094 : :
6095 : 0 : return 0;
6096 : : }
6097 : :
6098 : : static int
6099 : 0 : bnxt_parse_devarg_mpc(__rte_unused const char *key,
6100 : : const char *value, __rte_unused void *opaque_arg)
6101 : : {
6102 : 0 : char *end = NULL;
6103 : :
6104 [ # # ]: 0 : if (!value || !opaque_arg) {
6105 : 0 : PMD_DRV_LOG_LINE(ERR,
6106 : : "Invalid parameter passed to app-id "
6107 : : "devargs");
6108 : 0 : return -EINVAL;
6109 : : }
6110 : :
6111 : 0 : mpc = strtoul(value, &end, 10);
6112 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6113 [ # # ]: 0 : (mpc == ULONG_MAX && errno == ERANGE)) {
6114 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid parameter passed to mpc "
6115 : : "devargs");
6116 : 0 : return -EINVAL;
6117 : : }
6118 : :
6119 [ # # ]: 0 : if (BNXT_DEVARG_MPC_INVALID(mpc)) {
6120 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid mpc(%d) devargs",
6121 : : (uint16_t)mpc);
6122 : 0 : return -EINVAL;
6123 : : }
6124 : :
6125 : 0 : PMD_DRV_LOG_LINE(INFO, "MPC%d feature enabled", (uint16_t)mpc);
6126 : 0 : return 0;
6127 : : }
6128 : :
6129 : : static int
6130 : 0 : bnxt_parse_devarg_ieee_1588(__rte_unused const char *key,
6131 : : const char *value, void *opaque_arg)
6132 : : {
6133 : : struct bnxt *bp = opaque_arg;
6134 : : unsigned long ieee_1588;
6135 : 0 : char *end = NULL;
6136 : :
6137 [ # # ]: 0 : if (!value || !opaque_arg) {
6138 : 0 : PMD_DRV_LOG_LINE(ERR,
6139 : : "Invalid parameter passed to ieee-1588 "
6140 : : "devargs.");
6141 : 0 : return -EINVAL;
6142 : : }
6143 : :
6144 : 0 : ieee_1588 = strtoul(value, &end, 10);
6145 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6146 [ # # ]: 0 : (ieee_1588 == ULONG_MAX && errno == ERANGE)) {
6147 : 0 : PMD_DRV_LOG_LINE(ERR,
6148 : : "Invalid parameter passed to ieee_1588 "
6149 : : "devargs.");
6150 : 0 : return -EINVAL;
6151 : : }
6152 : :
6153 [ # # ]: 0 : if (BNXT_DEVARG_IEEE_1588_INVALID(ieee_1588)) {
6154 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid ieee-1588(%d) devargs.",
6155 : : (uint16_t)ieee_1588);
6156 : 0 : return -EINVAL;
6157 : : }
6158 : :
6159 : 0 : bp->ieee_1588 = ieee_1588;
6160 : 0 : PMD_DRV_LOG_LINE(INFO, "ieee-1588=%d feature enabled.", (uint16_t)ieee_1588);
6161 : :
6162 : 0 : return 0;
6163 : : }
6164 : :
6165 : : static int
6166 : 0 : bnxt_parse_devarg_rep_is_pf(__rte_unused const char *key,
6167 : : const char *value, void *opaque_arg)
6168 : : {
6169 : : struct bnxt_representor *vfr_bp = opaque_arg;
6170 : : unsigned long rep_is_pf;
6171 : 0 : char *end = NULL;
6172 : :
6173 [ # # ]: 0 : if (!value || !opaque_arg) {
6174 : 0 : PMD_DRV_LOG_LINE(ERR,
6175 : : "Invalid parameter passed to rep_is_pf devargs.");
6176 : 0 : return -EINVAL;
6177 : : }
6178 : :
6179 : 0 : rep_is_pf = strtoul(value, &end, 10);
6180 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6181 [ # # ]: 0 : (rep_is_pf == ULONG_MAX && errno == ERANGE)) {
6182 : 0 : PMD_DRV_LOG_LINE(ERR,
6183 : : "Invalid parameter passed to rep_is_pf devargs.");
6184 : 0 : return -EINVAL;
6185 : : }
6186 : :
6187 [ # # ]: 0 : if (BNXT_DEVARG_REP_IS_PF_INVALID(rep_is_pf)) {
6188 : 0 : PMD_DRV_LOG_LINE(ERR,
6189 : : "Invalid value passed to rep_is_pf devargs.");
6190 : 0 : return -EINVAL;
6191 : : }
6192 : :
6193 : 0 : vfr_bp->flags |= rep_is_pf;
6194 [ # # ]: 0 : if (BNXT_REP_PF(vfr_bp))
6195 : 0 : PMD_DRV_LOG_LINE(INFO, "PF representor");
6196 : : else
6197 : 0 : PMD_DRV_LOG_LINE(INFO, "VF representor");
6198 : :
6199 : : return 0;
6200 : : }
6201 : :
6202 : : static int
6203 : 0 : bnxt_parse_devarg_rep_based_pf(__rte_unused const char *key,
6204 : : const char *value, void *opaque_arg)
6205 : : {
6206 : : struct bnxt_representor *vfr_bp = opaque_arg;
6207 : : unsigned long rep_based_pf;
6208 : 0 : char *end = NULL;
6209 : :
6210 [ # # ]: 0 : if (!value || !opaque_arg) {
6211 : 0 : PMD_DRV_LOG_LINE(ERR,
6212 : : "Invalid parameter passed to rep_based_pf "
6213 : : "devargs.");
6214 : 0 : return -EINVAL;
6215 : : }
6216 : :
6217 : 0 : rep_based_pf = strtoul(value, &end, 10);
6218 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6219 [ # # ]: 0 : (rep_based_pf == ULONG_MAX && errno == ERANGE)) {
6220 : 0 : PMD_DRV_LOG_LINE(ERR,
6221 : : "Invalid parameter passed to rep_based_pf "
6222 : : "devargs.");
6223 : 0 : return -EINVAL;
6224 : : }
6225 : :
6226 [ # # ]: 0 : if (BNXT_DEVARG_REP_BASED_PF_INVALID(rep_based_pf)) {
6227 : 0 : PMD_DRV_LOG_LINE(ERR,
6228 : : "Invalid value passed to rep_based_pf devargs.");
6229 : 0 : return -EINVAL;
6230 : : }
6231 : :
6232 : 0 : vfr_bp->rep_based_pf = rep_based_pf;
6233 : 0 : vfr_bp->flags |= BNXT_REP_BASED_PF_VALID;
6234 : :
6235 : 0 : PMD_DRV_LOG_LINE(INFO, "rep-based-pf = %d", vfr_bp->rep_based_pf);
6236 : :
6237 : 0 : return 0;
6238 : : }
6239 : :
6240 : : static int
6241 : 0 : bnxt_parse_devarg_rep_q_r2f(__rte_unused const char *key,
6242 : : const char *value, void *opaque_arg)
6243 : : {
6244 : : struct bnxt_representor *vfr_bp = opaque_arg;
6245 : : unsigned long rep_q_r2f;
6246 : 0 : char *end = NULL;
6247 : :
6248 [ # # ]: 0 : if (!value || !opaque_arg) {
6249 : 0 : PMD_DRV_LOG_LINE(ERR,
6250 : : "Invalid parameter passed to rep_q_r2f "
6251 : : "devargs.");
6252 : 0 : return -EINVAL;
6253 : : }
6254 : :
6255 : 0 : rep_q_r2f = strtoul(value, &end, 10);
6256 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6257 [ # # ]: 0 : (rep_q_r2f == ULONG_MAX && errno == ERANGE)) {
6258 : 0 : PMD_DRV_LOG_LINE(ERR,
6259 : : "Invalid parameter passed to rep_q_r2f "
6260 : : "devargs.");
6261 : 0 : return -EINVAL;
6262 : : }
6263 : :
6264 [ # # ]: 0 : if (BNXT_DEVARG_REP_Q_R2F_INVALID(rep_q_r2f)) {
6265 : 0 : PMD_DRV_LOG_LINE(ERR,
6266 : : "Invalid value passed to rep_q_r2f devargs.");
6267 : 0 : return -EINVAL;
6268 : : }
6269 : :
6270 : 0 : vfr_bp->rep_q_r2f = rep_q_r2f;
6271 : 0 : vfr_bp->flags |= BNXT_REP_Q_R2F_VALID;
6272 : 0 : PMD_DRV_LOG_LINE(INFO, "rep-q-r2f = %d", vfr_bp->rep_q_r2f);
6273 : :
6274 : 0 : return 0;
6275 : : }
6276 : :
6277 : : static int
6278 : 0 : bnxt_parse_devarg_rep_q_f2r(__rte_unused const char *key,
6279 : : const char *value, void *opaque_arg)
6280 : : {
6281 : : struct bnxt_representor *vfr_bp = opaque_arg;
6282 : : unsigned long rep_q_f2r;
6283 : 0 : char *end = NULL;
6284 : :
6285 [ # # ]: 0 : if (!value || !opaque_arg) {
6286 : 0 : PMD_DRV_LOG_LINE(ERR,
6287 : : "Invalid parameter passed to rep_q_f2r "
6288 : : "devargs.");
6289 : 0 : return -EINVAL;
6290 : : }
6291 : :
6292 : 0 : rep_q_f2r = strtoul(value, &end, 10);
6293 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6294 [ # # ]: 0 : (rep_q_f2r == ULONG_MAX && errno == ERANGE)) {
6295 : 0 : PMD_DRV_LOG_LINE(ERR,
6296 : : "Invalid parameter passed to rep_q_f2r "
6297 : : "devargs.");
6298 : 0 : return -EINVAL;
6299 : : }
6300 : :
6301 [ # # ]: 0 : if (BNXT_DEVARG_REP_Q_F2R_INVALID(rep_q_f2r)) {
6302 : 0 : PMD_DRV_LOG_LINE(ERR,
6303 : : "Invalid value passed to rep_q_f2r devargs.");
6304 : 0 : return -EINVAL;
6305 : : }
6306 : :
6307 : 0 : vfr_bp->rep_q_f2r = rep_q_f2r;
6308 : 0 : vfr_bp->flags |= BNXT_REP_Q_F2R_VALID;
6309 : 0 : PMD_DRV_LOG_LINE(INFO, "rep-q-f2r = %d", vfr_bp->rep_q_f2r);
6310 : :
6311 : 0 : return 0;
6312 : : }
6313 : :
6314 : : static int
6315 : 0 : bnxt_parse_devarg_rep_fc_r2f(__rte_unused const char *key,
6316 : : const char *value, void *opaque_arg)
6317 : : {
6318 : : struct bnxt_representor *vfr_bp = opaque_arg;
6319 : : unsigned long rep_fc_r2f;
6320 : 0 : char *end = NULL;
6321 : :
6322 [ # # ]: 0 : if (!value || !opaque_arg) {
6323 : 0 : PMD_DRV_LOG_LINE(ERR,
6324 : : "Invalid parameter passed to rep_fc_r2f "
6325 : : "devargs.");
6326 : 0 : return -EINVAL;
6327 : : }
6328 : :
6329 : 0 : rep_fc_r2f = strtoul(value, &end, 10);
6330 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6331 [ # # ]: 0 : (rep_fc_r2f == ULONG_MAX && errno == ERANGE)) {
6332 : 0 : PMD_DRV_LOG_LINE(ERR,
6333 : : "Invalid parameter passed to rep_fc_r2f "
6334 : : "devargs.");
6335 : 0 : return -EINVAL;
6336 : : }
6337 : :
6338 [ # # ]: 0 : if (BNXT_DEVARG_REP_FC_R2F_INVALID(rep_fc_r2f)) {
6339 : 0 : PMD_DRV_LOG_LINE(ERR,
6340 : : "Invalid value passed to rep_fc_r2f devargs.");
6341 : 0 : return -EINVAL;
6342 : : }
6343 : :
6344 : 0 : vfr_bp->flags |= BNXT_REP_FC_R2F_VALID;
6345 : 0 : vfr_bp->rep_fc_r2f = rep_fc_r2f;
6346 : 0 : PMD_DRV_LOG_LINE(INFO, "rep-fc-r2f = %lu", rep_fc_r2f);
6347 : :
6348 : 0 : return 0;
6349 : : }
6350 : :
6351 : : static int
6352 : 0 : bnxt_parse_devarg_rep_fc_f2r(__rte_unused const char *key,
6353 : : const char *value, void *opaque_arg)
6354 : : {
6355 : : struct bnxt_representor *vfr_bp = opaque_arg;
6356 : : unsigned long rep_fc_f2r;
6357 : 0 : char *end = NULL;
6358 : :
6359 [ # # ]: 0 : if (!value || !opaque_arg) {
6360 : 0 : PMD_DRV_LOG_LINE(ERR,
6361 : : "Invalid parameter passed to rep_fc_f2r "
6362 : : "devargs.");
6363 : 0 : return -EINVAL;
6364 : : }
6365 : :
6366 : 0 : rep_fc_f2r = strtoul(value, &end, 10);
6367 [ # # # # : 0 : if (end == NULL || *end != '\0' ||
# # ]
6368 [ # # ]: 0 : (rep_fc_f2r == ULONG_MAX && errno == ERANGE)) {
6369 : 0 : PMD_DRV_LOG_LINE(ERR,
6370 : : "Invalid parameter passed to rep_fc_f2r "
6371 : : "devargs.");
6372 : 0 : return -EINVAL;
6373 : : }
6374 : :
6375 [ # # ]: 0 : if (BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)) {
6376 : 0 : PMD_DRV_LOG_LINE(ERR,
6377 : : "Invalid value passed to rep_fc_f2r devargs.");
6378 : 0 : return -EINVAL;
6379 : : }
6380 : :
6381 : 0 : vfr_bp->flags |= BNXT_REP_FC_F2R_VALID;
6382 : 0 : vfr_bp->rep_fc_f2r = rep_fc_f2r;
6383 : 0 : PMD_DRV_LOG_LINE(INFO, "rep-fc-f2r = %lu", rep_fc_f2r);
6384 : :
6385 : 0 : return 0;
6386 : : }
6387 : :
6388 : : static int
6389 : 0 : bnxt_parse_dev_args(struct bnxt *bp, struct rte_devargs *devargs)
6390 : : {
6391 : : struct rte_kvargs *kvlist;
6392 : : int ret = 0;
6393 : :
6394 [ # # ]: 0 : if (devargs == NULL)
6395 : : return 0;
6396 : :
6397 : 0 : kvlist = rte_kvargs_parse(devargs->args, bnxt_dev_args);
6398 [ # # ]: 0 : if (kvlist == NULL)
6399 : : return -EINVAL;
6400 : :
6401 : : /*
6402 : : * Handler for "flow_xstat" devarg.
6403 : : * Invoked as for ex: "-a 0000:00:0d.0,flow_xstat=1"
6404 : : */
6405 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_FLOW_XSTAT,
6406 : : bnxt_parse_devarg_flow_xstat, bp);
6407 [ # # ]: 0 : if (ret)
6408 : 0 : goto err;
6409 : :
6410 : : /*
6411 : : * Handler for "max_num_kflows" devarg.
6412 : : * Invoked as for ex: "-a 000:00:0d.0,max_num_kflows=32"
6413 : : */
6414 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_MAX_NUM_KFLOWS,
6415 : : bnxt_parse_devarg_max_num_kflows, bp);
6416 [ # # ]: 0 : if (ret)
6417 : 0 : goto err;
6418 : :
6419 : 0 : err:
6420 : : /*
6421 : : * Handler for "app-id" devarg.
6422 : : * Invoked as for ex: "-a 000:00:0d.0,app-id=1"
6423 : : */
6424 : 0 : rte_kvargs_process(kvlist, BNXT_DEVARG_APP_ID,
6425 : : bnxt_parse_devarg_app_id, bp);
6426 : :
6427 : : /*
6428 : : * Handler for "ieee-1588" devarg.
6429 : : * Invoked as for ex: "-a 000:00:0d.0,ieee-1588=1"
6430 : : */
6431 : 0 : rte_kvargs_process(kvlist, BNXT_DEVARG_IEEE_1588,
6432 : : bnxt_parse_devarg_ieee_1588, bp);
6433 : :
6434 : : /*
6435 : : * Handler for "mpc" devarg.
6436 : : * Invoked as for ex: "-a 000:00:0d.0,mpc=1"
6437 : : */
6438 : 0 : rte_kvargs_process(kvlist, BNXT_DEVARG_MPC,
6439 : : bnxt_parse_devarg_mpc, bp);
6440 : :
6441 : : /*
6442 : : * Handler for "cqe-mode" devarg.
6443 : : * Invoked as for ex: "-a 000:00:0d.0,cqe-mode=1"
6444 : : */
6445 : 0 : rte_kvargs_process(kvlist, BNXT_DEVARG_CQE_MODE,
6446 : : bnxt_parse_devarg_cqe_mode, bp);
6447 : :
6448 : 0 : rte_kvargs_free(kvlist);
6449 : 0 : return ret;
6450 : : }
6451 : :
6452 : : /* Allocate and initialize various fields in bnxt struct that
6453 : : * need to be allocated/destroyed only once in the lifetime of the driver
6454 : : */
6455 : 0 : static int bnxt_drv_init(struct rte_eth_dev *eth_dev)
6456 : : {
6457 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
6458 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
6459 : : int rc = 0;
6460 : :
6461 : 0 : bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
6462 : :
6463 [ # # ]: 0 : if (bnxt_vf_pciid(pci_dev->id.device_id))
6464 : 0 : bp->flags |= BNXT_FLAG_VF;
6465 : :
6466 : : if (bnxt_p5_device(pci_dev->id.device_id))
6467 : 0 : bp->flags |= BNXT_FLAG_CHIP_P5;
6468 : :
6469 : : if (bnxt_p7_device(pci_dev->id.device_id))
6470 : 0 : bp->flags |= BNXT_FLAG_CHIP_P7;
6471 : :
6472 [ # # ]: 0 : if (pci_dev->id.device_id == BROADCOM_DEV_ID_58802 ||
6473 [ # # ]: 0 : pci_dev->id.device_id == BROADCOM_DEV_ID_58804 ||
6474 [ # # ]: 0 : pci_dev->id.device_id == BROADCOM_DEV_ID_58808 ||
6475 : : pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
6476 : 0 : bp->flags |= BNXT_FLAG_STINGRAY;
6477 : :
6478 : 0 : rc = bnxt_map_pci_bars(eth_dev);
6479 [ # # ]: 0 : if (rc) {
6480 : 0 : PMD_DRV_LOG_LINE(ERR,
6481 : : "Failed to initialize board rc: %x", rc);
6482 : 0 : return rc;
6483 : : }
6484 : :
6485 : : rc = bnxt_alloc_pf_info(bp);
6486 : : if (rc)
6487 : : return rc;
6488 : :
6489 : : rc = bnxt_alloc_link_info(bp);
6490 : : if (rc)
6491 : : return rc;
6492 : :
6493 : : rc = bnxt_alloc_parent_info(bp);
6494 : : if (rc)
6495 : : return rc;
6496 : :
6497 : 0 : rc = bnxt_alloc_hwrm_resources(bp);
6498 [ # # ]: 0 : if (rc) {
6499 : 0 : PMD_DRV_LOG_LINE(ERR,
6500 : : "Failed to allocate response buffer rc: %x", rc);
6501 : 0 : return rc;
6502 : : }
6503 : 0 : rc = bnxt_alloc_leds_info(bp);
6504 [ # # ]: 0 : if (rc)
6505 : : return rc;
6506 : :
6507 : 0 : rc = bnxt_alloc_cos_queues(bp);
6508 [ # # ]: 0 : if (rc)
6509 : : return rc;
6510 : :
6511 : 0 : rc = bnxt_init_locks(bp);
6512 [ # # ]: 0 : if (rc)
6513 : : return rc;
6514 : :
6515 : 0 : rc = bnxt_get_config(bp);
6516 [ # # ]: 0 : if (rc)
6517 : : return rc;
6518 : :
6519 [ # # # # ]: 0 : if (BNXT_TRUFLOW_EN(bp)) {
6520 : : /* extra mbuf field is required to store CFA code from mark */
6521 : : static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
6522 : : .name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
6523 : : .size = sizeof(bnxt_cfa_code_dynfield_t),
6524 : : .align = alignof(bnxt_cfa_code_dynfield_t),
6525 : : };
6526 : 0 : bnxt_cfa_code_dynfield_offset =
6527 : 0 : rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
6528 [ # # ]: 0 : if (bnxt_cfa_code_dynfield_offset < 0) {
6529 : 0 : PMD_DRV_LOG_LINE(ERR,
6530 : : "Failed to register mbuf field for TruFlow mark");
6531 : 0 : return -rte_errno;
6532 : : }
6533 : : }
6534 : :
6535 : : return rc;
6536 : : }
6537 : :
6538 : : static int
6539 : 0 : bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
6540 : : {
6541 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
6542 : : static int version_printed;
6543 : : struct bnxt *bp;
6544 : : int rc;
6545 : :
6546 [ # # ]: 0 : if (version_printed++ == 0)
6547 : 0 : PMD_DRV_LOG_LINE(INFO, "%s", bnxt_version);
6548 : :
6549 : 0 : eth_dev->dev_ops = &bnxt_dev_ops;
6550 : 0 : eth_dev->rx_queue_count = bnxt_rx_queue_count_op;
6551 : 0 : eth_dev->rx_descriptor_status = bnxt_rx_descriptor_status_op;
6552 : 0 : eth_dev->tx_descriptor_status = bnxt_tx_descriptor_status_op;
6553 : 0 : eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
6554 : 0 : eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
6555 : :
6556 : : /*
6557 : : * For secondary processes, we don't initialise any further
6558 : : * as primary has already done this work.
6559 : : */
6560 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6561 : : return 0;
6562 : :
6563 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
6564 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
6565 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
6566 : :
6567 : 0 : bp = eth_dev->data->dev_private;
6568 : :
6569 : : /* set the default app id */
6570 : 0 : bp->app_id = bnxt_ulp_default_app_id_get();
6571 : :
6572 : : /* Parse dev arguments passed on when starting the DPDK application. */
6573 : 0 : rc = bnxt_parse_dev_args(bp, pci_dev->device.devargs);
6574 [ # # ]: 0 : if (rc)
6575 : 0 : goto error_free;
6576 : :
6577 : 0 : rc = bnxt_drv_init(eth_dev);
6578 [ # # ]: 0 : if (rc)
6579 : 0 : goto error_free;
6580 : :
6581 : 0 : rc = bnxt_init_resources(bp, false);
6582 [ # # ]: 0 : if (rc)
6583 : 0 : goto error_free;
6584 : :
6585 : 0 : rc = bnxt_alloc_stats_mem(bp);
6586 [ # # ]: 0 : if (rc)
6587 : 0 : goto error_free;
6588 : :
6589 : 0 : PMD_DRV_LOG_LINE(INFO,
6590 : : "Found %s device at mem %" PRIX64 ", node addr %pM",
6591 : : DRV_MODULE_NAME,
6592 : : pci_dev->mem_resource[0].phys_addr,
6593 : : pci_dev->mem_resource[0].addr);
6594 : :
6595 : 0 : return 0;
6596 : :
6597 : 0 : error_free:
6598 : 0 : bnxt_dev_uninit(eth_dev);
6599 : 0 : return rc;
6600 : : }
6601 : :
6602 : :
6603 : : static void bnxt_free_ctx_mem_buf(struct bnxt_ctx_mem_buf_info *ctx)
6604 : : {
6605 : : if (!ctx)
6606 : : return;
6607 : :
6608 : 0 : rte_free(ctx->va);
6609 : :
6610 : 0 : ctx->va = NULL;
6611 : 0 : ctx->dma = RTE_BAD_IOVA;
6612 : 0 : ctx->ctx_id = BNXT_CTX_VAL_INVAL;
6613 : : }
6614 : :
6615 : 0 : static void bnxt_unregister_fc_ctx_mem(struct bnxt *bp)
6616 : : {
6617 : 0 : bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_RX,
6618 : : CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
6619 : 0 : bp->flow_stat->rx_fc_out_tbl.ctx_id,
6620 : 0 : bp->flow_stat->max_fc,
6621 : : false);
6622 : :
6623 : 0 : bnxt_hwrm_cfa_counter_cfg(bp, BNXT_DIR_TX,
6624 : : CFA_COUNTER_CFG_IN_COUNTER_TYPE_FC,
6625 : 0 : bp->flow_stat->tx_fc_out_tbl.ctx_id,
6626 : 0 : bp->flow_stat->max_fc,
6627 : : false);
6628 : :
6629 [ # # ]: 0 : if (bp->flow_stat->rx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6630 : 0 : bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_in_tbl.ctx_id);
6631 : 0 : bp->flow_stat->rx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6632 : :
6633 [ # # ]: 0 : if (bp->flow_stat->rx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6634 : 0 : bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->rx_fc_out_tbl.ctx_id);
6635 : 0 : bp->flow_stat->rx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6636 : :
6637 [ # # ]: 0 : if (bp->flow_stat->tx_fc_in_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6638 : 0 : bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_in_tbl.ctx_id);
6639 : 0 : bp->flow_stat->tx_fc_in_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6640 : :
6641 [ # # ]: 0 : if (bp->flow_stat->tx_fc_out_tbl.ctx_id != BNXT_CTX_VAL_INVAL)
6642 : 0 : bnxt_hwrm_ctx_unrgtr(bp, bp->flow_stat->tx_fc_out_tbl.ctx_id);
6643 : 0 : bp->flow_stat->tx_fc_out_tbl.ctx_id = BNXT_CTX_VAL_INVAL;
6644 : 0 : }
6645 : :
6646 : 0 : static void bnxt_uninit_fc_ctx_mem(struct bnxt *bp)
6647 : : {
6648 : 0 : bnxt_unregister_fc_ctx_mem(bp);
6649 : :
6650 : 0 : bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_in_tbl);
6651 : 0 : bnxt_free_ctx_mem_buf(&bp->flow_stat->rx_fc_out_tbl);
6652 : 0 : bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_in_tbl);
6653 : 0 : bnxt_free_ctx_mem_buf(&bp->flow_stat->tx_fc_out_tbl);
6654 : 0 : }
6655 : :
6656 : : static void bnxt_uninit_ctx_mem(struct bnxt *bp)
6657 : : {
6658 [ # # ]: 0 : if (BNXT_FLOW_XSTATS_EN(bp))
6659 : 0 : bnxt_uninit_fc_ctx_mem(bp);
6660 : : }
6661 : :
6662 : : static void
6663 : : bnxt_free_error_recovery_info(struct bnxt *bp)
6664 : : {
6665 : 0 : rte_free(bp->recovery_info);
6666 : 0 : bp->recovery_info = NULL;
6667 : 0 : bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
6668 : : }
6669 : :
6670 : : static int
6671 : 0 : bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
6672 : : {
6673 : : int rc;
6674 : :
6675 : 0 : bnxt_free_int(bp);
6676 : 0 : bnxt_free_mem(bp, reconfig_dev);
6677 : :
6678 : 0 : bnxt_hwrm_func_buf_unrgtr(bp);
6679 [ # # ]: 0 : if (bp->pf != NULL) {
6680 : 0 : rte_free(bp->pf->vf_req_buf);
6681 : 0 : bp->pf->vf_req_buf = NULL;
6682 : : }
6683 : :
6684 : 0 : rc = bnxt_hwrm_func_driver_unregister(bp);
6685 : 0 : bp->flags &= ~BNXT_FLAG_REGISTERED;
6686 : 0 : bnxt_free_ctx_mem(bp);
6687 [ # # ]: 0 : if (!reconfig_dev) {
6688 : 0 : bnxt_free_hwrm_resources(bp);
6689 : : bnxt_free_error_recovery_info(bp);
6690 : 0 : rte_free(bp->mcast_addr_list);
6691 : 0 : bp->mcast_addr_list = NULL;
6692 : 0 : rte_free(bp->rss_conf.rss_key);
6693 : 0 : bp->rss_conf.rss_key = NULL;
6694 : : }
6695 : :
6696 : : bnxt_uninit_ctx_mem(bp);
6697 : :
6698 : : bnxt_free_flow_stats_info(bp);
6699 : 0 : bnxt_free_switch_domain(bp);
6700 : 0 : rte_free(bp->ptp_cfg);
6701 : 0 : bp->ptp_cfg = NULL;
6702 : 0 : return rc;
6703 : : }
6704 : :
6705 : : static int
6706 : 0 : bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
6707 : : {
6708 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
6709 : : return -EPERM;
6710 : :
6711 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Calling Device uninit");
6712 : :
6713 [ # # ]: 0 : if (eth_dev->state != RTE_ETH_DEV_UNUSED)
6714 : 0 : bnxt_dev_close_op(eth_dev);
6715 : :
6716 : : return 0;
6717 : : }
6718 : :
6719 : 0 : static int bnxt_pci_remove_dev_with_reps(struct rte_eth_dev *eth_dev)
6720 : : {
6721 : 0 : struct bnxt *bp = eth_dev->data->dev_private;
6722 : : struct rte_eth_dev *vf_rep_eth_dev;
6723 : : int ret = 0, i;
6724 : :
6725 [ # # ]: 0 : if (!bp)
6726 : : return -EINVAL;
6727 : :
6728 [ # # ]: 0 : for (i = 0; i < bp->num_reps; i++) {
6729 : 0 : vf_rep_eth_dev = bp->rep_info[i].vfr_eth_dev;
6730 [ # # ]: 0 : if (!vf_rep_eth_dev)
6731 : 0 : continue;
6732 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR pci remove",
6733 : : vf_rep_eth_dev->data->port_id);
6734 : 0 : rte_eth_dev_destroy(vf_rep_eth_dev, bnxt_representor_uninit);
6735 : : }
6736 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci remove",
6737 : : eth_dev->data->port_id);
6738 : 0 : ret = rte_eth_dev_destroy(eth_dev, bnxt_dev_uninit);
6739 : :
6740 : 0 : return ret;
6741 : : }
6742 : :
6743 : : static void bnxt_free_rep_info(struct bnxt *bp)
6744 : : {
6745 : 0 : rte_free(bp->rep_info);
6746 : 0 : bp->rep_info = NULL;
6747 : 0 : rte_free(bp->cfa_code_map);
6748 : 0 : bp->cfa_code_map = NULL;
6749 : : }
6750 : :
6751 : 0 : static int bnxt_init_rep_info(struct bnxt *bp)
6752 : : {
6753 : : int i = 0;
6754 : :
6755 [ # # ]: 0 : if (bp->rep_info)
6756 : : return 0;
6757 : :
6758 : 0 : bp->rep_info = rte_zmalloc("bnxt_rep_info",
6759 [ # # ]: 0 : sizeof(bp->rep_info[0]) * BNXT_MAX_VF_REPS(bp),
6760 : : 0);
6761 [ # # ]: 0 : if (!bp->rep_info) {
6762 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc memory for rep info");
6763 : 0 : return -ENOMEM;
6764 : : }
6765 : 0 : bp->cfa_code_map = rte_zmalloc("bnxt_cfa_code_map",
6766 : : sizeof(*bp->cfa_code_map) *
6767 : : BNXT_MAX_CFA_CODE, 0);
6768 [ # # ]: 0 : if (!bp->cfa_code_map) {
6769 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc memory for cfa_code_map");
6770 : : bnxt_free_rep_info(bp);
6771 : 0 : return -ENOMEM;
6772 : : }
6773 : :
6774 [ # # ]: 0 : for (i = 0; i < BNXT_MAX_CFA_CODE; i++)
6775 : 0 : bp->cfa_code_map[i] = BNXT_VF_IDX_INVALID;
6776 : :
6777 : 0 : return pthread_mutex_init(&bp->rep_info->vfr_start_lock, NULL);
6778 : : }
6779 : :
6780 : 0 : static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
6781 : : struct rte_eth_devargs *eth_da,
6782 : : struct rte_eth_dev *backing_eth_dev,
6783 : : const char *dev_args)
6784 : : {
6785 : : struct rte_eth_dev *vf_rep_eth_dev;
6786 : : char name[RTE_ETH_NAME_MAX_LEN];
6787 : 0 : struct bnxt *backing_bp = backing_eth_dev->data->dev_private;
6788 [ # # ]: 0 : uint16_t max_vf_reps = BNXT_MAX_VF_REPS(backing_bp);
6789 : :
6790 : : uint16_t num_rep;
6791 : : int i, ret = 0;
6792 : : struct rte_kvargs *kvlist = NULL;
6793 : :
6794 [ # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
6795 : : return 0;
6796 [ # # ]: 0 : if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
6797 : 0 : PMD_DRV_LOG_LINE(ERR, "unsupported representor type %d",
6798 : : eth_da->type);
6799 : 0 : return -ENOTSUP;
6800 : : }
6801 : 0 : num_rep = eth_da->nb_representor_ports;
6802 [ # # ]: 0 : if (num_rep > max_vf_reps) {
6803 : 0 : PMD_DRV_LOG_LINE(ERR, "nb_representor_ports = %d > %d MAX VF REPS",
6804 : : num_rep, max_vf_reps);
6805 : 0 : return -EINVAL;
6806 : : }
6807 : :
6808 [ # # ]: 0 : if (num_rep >= RTE_MAX_ETHPORTS) {
6809 : 0 : PMD_DRV_LOG_LINE(ERR,
6810 : : "nb_representor_ports = %d > %d MAX ETHPORTS",
6811 : : num_rep, RTE_MAX_ETHPORTS);
6812 : 0 : return -EINVAL;
6813 : : }
6814 : :
6815 [ # # ]: 0 : if (!(BNXT_PF(backing_bp) || BNXT_VF_IS_TRUSTED(backing_bp))) {
6816 : 0 : PMD_DRV_LOG_LINE(ERR,
6817 : : "Not a PF or trusted VF. No Representor support");
6818 : : /* Returning an error is not an option.
6819 : : * Applications are not handling this correctly
6820 : : */
6821 : 0 : return 0;
6822 : : }
6823 : :
6824 [ # # ]: 0 : if (bnxt_init_rep_info(backing_bp))
6825 : : return 0;
6826 : :
6827 [ # # ]: 0 : for (i = 0; i < num_rep; i++) {
6828 : 0 : struct bnxt_representor representor = {
6829 : 0 : .vf_id = eth_da->representor_ports[i],
6830 : 0 : .switch_domain_id = backing_bp->switch_domain_id,
6831 : : .parent_dev = backing_eth_dev
6832 : : };
6833 : :
6834 [ # # ]: 0 : if (representor.vf_id >= max_vf_reps) {
6835 : 0 : PMD_DRV_LOG_LINE(ERR, "VF-Rep id %d >= %d MAX VF ID",
6836 : : representor.vf_id, max_vf_reps);
6837 : 0 : continue;
6838 : : }
6839 : :
6840 : : /* representor port net_bdf_port */
6841 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
6842 : : pci_dev->device.name, eth_da->representor_ports[i]);
6843 : :
6844 : 0 : kvlist = rte_kvargs_parse(dev_args, bnxt_dev_args);
6845 [ # # ]: 0 : if (kvlist) {
6846 : : /*
6847 : : * Handler for "rep_is_pf" devarg.
6848 : : * Invoked as for ex: "-a 000:00:0d.0,
6849 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6850 : : */
6851 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_IS_PF,
6852 : : bnxt_parse_devarg_rep_is_pf,
6853 : : (void *)&representor);
6854 [ # # ]: 0 : if (ret) {
6855 : : ret = -EINVAL;
6856 : 0 : goto err;
6857 : : }
6858 : : /*
6859 : : * Handler for "rep_based_pf" devarg.
6860 : : * Invoked as for ex: "-a 000:00:0d.0,
6861 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6862 : : */
6863 : 0 : ret = rte_kvargs_process(kvlist,
6864 : : BNXT_DEVARG_REP_BASED_PF,
6865 : : bnxt_parse_devarg_rep_based_pf,
6866 : : (void *)&representor);
6867 [ # # ]: 0 : if (ret) {
6868 : : ret = -EINVAL;
6869 : 0 : goto err;
6870 : : }
6871 : : /*
6872 : : * Handler for "rep_based_pf" devarg.
6873 : : * Invoked as for ex: "-a 000:00:0d.0,
6874 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6875 : : */
6876 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_R2F,
6877 : : bnxt_parse_devarg_rep_q_r2f,
6878 : : (void *)&representor);
6879 [ # # ]: 0 : if (ret) {
6880 : : ret = -EINVAL;
6881 : 0 : goto err;
6882 : : }
6883 : : /*
6884 : : * Handler for "rep_based_pf" devarg.
6885 : : * Invoked as for ex: "-a 000:00:0d.0,
6886 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6887 : : */
6888 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_Q_F2R,
6889 : : bnxt_parse_devarg_rep_q_f2r,
6890 : : (void *)&representor);
6891 [ # # ]: 0 : if (ret) {
6892 : : ret = -EINVAL;
6893 : 0 : goto err;
6894 : : }
6895 : : /*
6896 : : * Handler for "rep_based_pf" devarg.
6897 : : * Invoked as for ex: "-a 000:00:0d.0,
6898 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6899 : : */
6900 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_R2F,
6901 : : bnxt_parse_devarg_rep_fc_r2f,
6902 : : (void *)&representor);
6903 [ # # ]: 0 : if (ret) {
6904 : : ret = -EINVAL;
6905 : 0 : goto err;
6906 : : }
6907 : : /*
6908 : : * Handler for "rep_based_pf" devarg.
6909 : : * Invoked as for ex: "-a 000:00:0d.0,
6910 : : * rep-based-pf=<pf index> rep-is-pf=<VF=0 or PF=1>"
6911 : : */
6912 : 0 : ret = rte_kvargs_process(kvlist, BNXT_DEVARG_REP_FC_F2R,
6913 : : bnxt_parse_devarg_rep_fc_f2r,
6914 : : (void *)&representor);
6915 [ # # ]: 0 : if (ret) {
6916 : : ret = -EINVAL;
6917 : 0 : goto err;
6918 : : }
6919 : : }
6920 : :
6921 : 0 : ret = rte_eth_dev_create(&pci_dev->device, name,
6922 : : sizeof(struct bnxt_representor),
6923 : : NULL, NULL,
6924 : : bnxt_representor_init,
6925 : : &representor);
6926 [ # # ]: 0 : if (ret) {
6927 : 0 : PMD_DRV_LOG_LINE(ERR, "failed to create bnxt vf "
6928 : : "representor %s.", name);
6929 : 0 : goto err;
6930 : : }
6931 : :
6932 : 0 : vf_rep_eth_dev = rte_eth_dev_allocated(name);
6933 [ # # ]: 0 : if (!vf_rep_eth_dev) {
6934 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to find the eth_dev"
6935 : : " for VF-Rep: %s.", name);
6936 : : ret = -ENODEV;
6937 : 0 : goto err;
6938 : : }
6939 : :
6940 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d VFR pci probe",
6941 : : backing_eth_dev->data->port_id);
6942 : 0 : backing_bp->rep_info[representor.vf_id].vfr_eth_dev =
6943 : : vf_rep_eth_dev;
6944 : 0 : backing_bp->num_reps++;
6945 : :
6946 : : }
6947 : :
6948 : 0 : rte_kvargs_free(kvlist);
6949 : 0 : return 0;
6950 : :
6951 : : err:
6952 : : /* If num_rep > 1, then rollback already created
6953 : : * ports, since we'll be failing the probe anyway
6954 : : */
6955 [ # # ]: 0 : if (num_rep > 1)
6956 : 0 : bnxt_pci_remove_dev_with_reps(backing_eth_dev);
6957 : 0 : rte_errno = -ret;
6958 : 0 : rte_kvargs_free(kvlist);
6959 : :
6960 : 0 : return ret;
6961 : : }
6962 : :
6963 : 0 : static int bnxt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
6964 : : struct rte_pci_device *pci_dev)
6965 : : {
6966 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
6967 : : struct rte_eth_dev *backing_eth_dev;
6968 : : uint16_t num_rep;
6969 : : int ret = 0;
6970 : :
6971 [ # # ]: 0 : if (pci_dev->device.devargs) {
6972 : 0 : ret = rte_eth_devargs_parse(pci_dev->device.devargs->args,
6973 : : ð_da, 1);
6974 [ # # ]: 0 : if (ret < 0)
6975 : : return ret;
6976 : : }
6977 : :
6978 : 0 : num_rep = eth_da.nb_representor_ports;
6979 : 0 : PMD_DRV_LOG_LINE(DEBUG, "nb_representor_ports = %d",
6980 : : num_rep);
6981 : :
6982 : : /* We could come here after first level of probe is already invoked
6983 : : * as part of an application bringup(OVS-DPDK vswitchd), so first check
6984 : : * for already allocated eth_dev for the backing device (PF/Trusted VF)
6985 : : */
6986 : 0 : backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6987 [ # # ]: 0 : if (backing_eth_dev == NULL) {
6988 : 0 : ret = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
6989 : : sizeof(struct bnxt),
6990 : : eth_dev_pci_specific_init, pci_dev,
6991 : : bnxt_dev_init, NULL);
6992 : :
6993 [ # # ]: 0 : if (ret || !num_rep)
6994 : : return ret;
6995 : :
6996 : 0 : backing_eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
6997 : : }
6998 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci probe",
6999 : : backing_eth_dev->data->port_id);
7000 : :
7001 [ # # ]: 0 : if (!num_rep)
7002 : : return ret;
7003 : :
7004 : : /* probe representor ports now */
7005 : 0 : ret = bnxt_rep_port_probe(pci_dev, ð_da, backing_eth_dev,
7006 : 0 : pci_dev->device.devargs->args);
7007 : :
7008 : 0 : return ret;
7009 : : }
7010 : :
7011 : 0 : static int bnxt_pci_remove(struct rte_pci_device *pci_dev)
7012 : : {
7013 : : struct rte_eth_dev *eth_dev;
7014 : : uint16_t port_id;
7015 : : int rc = 0;
7016 : :
7017 : 0 : eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
7018 [ # # ]: 0 : if (!eth_dev)
7019 : : return 0; /* Invoked typically only by OVS-DPDK, by the
7020 : : * time it comes here the eth_dev is already
7021 : : * deleted by rte_eth_dev_close(), so returning
7022 : : * +ve value will at least help in proper cleanup
7023 : : */
7024 : :
7025 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
7026 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) {
7027 : 0 : PMD_DRV_LOG_LINE(DEBUG, "BNXT Port:%d pci remove", port_id);
7028 : 0 : eth_dev = &rte_eth_devices[port_id];
7029 [ # # ]: 0 : if (eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
7030 : 0 : rc = rte_eth_dev_destroy(eth_dev,
7031 : : bnxt_representor_uninit);
7032 : : else
7033 : 0 : rc = rte_eth_dev_destroy(eth_dev,
7034 : : bnxt_dev_uninit);
7035 [ # # ]: 0 : if (rc != 0)
7036 : 0 : return rc;
7037 : : }
7038 : : return rc;
7039 : : } else {
7040 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
7041 : : }
7042 : : }
7043 : :
7044 : : static struct rte_pci_driver bnxt_rte_pmd = {
7045 : : .id_table = bnxt_pci_id_map,
7046 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
7047 : : RTE_PCI_DRV_INTR_RMV |
7048 : : RTE_PCI_DRV_PROBE_AGAIN, /* Needed in case of VF-REPs
7049 : : * and OVS-DPDK
7050 : : */
7051 : : .probe = bnxt_pci_probe,
7052 : : .remove = bnxt_pci_remove,
7053 : : };
7054 : :
7055 : : static bool
7056 : : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
7057 : : {
7058 : 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
7059 : 0 : return false;
7060 : :
7061 : : return true;
7062 : : }
7063 : :
7064 [ # # ]: 0 : bool is_bnxt_supported(struct rte_eth_dev *dev)
7065 : : {
7066 : 0 : return is_device_supported(dev, &bnxt_rte_pmd);
7067 : : }
7068 : :
7069 : : struct bnxt *
7070 : 0 : bnxt_pmd_get_bp(uint16_t port)
7071 : : {
7072 : : struct bnxt *bp;
7073 : : struct rte_eth_dev *dev;
7074 : :
7075 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port)) {
7076 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid port %d", port);
7077 : 0 : return NULL;
7078 : : }
7079 : :
7080 : 0 : dev = &rte_eth_devices[port];
7081 [ # # ]: 0 : if (!is_bnxt_supported(dev)) {
7082 : 0 : PMD_DRV_LOG_LINE(ERR, "Device %d not supported", port);
7083 : 0 : return NULL;
7084 : : }
7085 : :
7086 : 0 : bp = (struct bnxt *)dev->data->dev_private;
7087 [ # # # # ]: 0 : if (!BNXT_TRUFLOW_EN(bp)) {
7088 : 0 : PMD_DRV_LOG_LINE(ERR, "TRUFLOW not enabled");
7089 : 0 : return NULL;
7090 : : }
7091 : :
7092 : : return bp;
7093 : : }
7094 : :
7095 : : /* check if ULP should be enabled or not */
7096 : : static bool bnxt_enable_ulp(struct bnxt *bp)
7097 : : {
7098 : : /* truflow and MPC should be enabled */
7099 : : /* not enabling ulp for cli and no truflow apps */
7100 [ # # # # : 0 : if (BNXT_TRUFLOW_EN(bp) && bp->app_id != 254 &&
# # # # #
# # # # #
# # # # ]
7101 : : bp->app_id != 255) {
7102 [ # # # # : 0 : if (BNXT_CHIP_P7(bp) && !mpc)
# # # # #
# # # ]
7103 : : return false;
7104 : : return true;
7105 : : }
7106 : : return false;
7107 : : }
7108 : :
7109 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(bnxt_logtype_driver, driver, NOTICE);
7110 : 252 : RTE_PMD_REGISTER_PCI(net_bnxt, bnxt_rte_pmd);
7111 : : RTE_PMD_REGISTER_PCI_TABLE(net_bnxt, bnxt_pci_id_map);
7112 : : RTE_PMD_REGISTER_KMOD_DEP(net_bnxt, "* igb_uio | uio_pci_generic | vfio-pci");
|