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