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