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