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