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