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