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 <unistd.h>
7 : :
8 : : #include <rte_byteorder.h>
9 : : #include <rte_common.h>
10 : : #include <rte_cycles.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_memzone.h>
13 : : #include <rte_version.h>
14 : : #include <rte_io.h>
15 : :
16 : : #include "bnxt.h"
17 : : #include "bnxt_filter.h"
18 : : #include "bnxt_hwrm.h"
19 : : #include "bnxt_rxq.h"
20 : : #include "bnxt_rxr.h"
21 : : #include "bnxt_ring.h"
22 : : #include "bnxt_txq.h"
23 : : #include "bnxt_txr.h"
24 : : #include "bnxt_vnic.h"
25 : : #include "hsi_struct_def_dpdk.h"
26 : : #include "bnxt_ulp_utils.h"
27 : :
28 : : struct bnxt_plcmodes_cfg {
29 : : uint32_t flags;
30 : : uint16_t jumbo_thresh;
31 : : uint16_t hds_offset;
32 : : uint16_t hds_threshold;
33 : : };
34 : :
35 : : const char *media_type[] = { "Unknown", "Twisted Pair",
36 : : "Direct Attached Copper", "Fiber"
37 : : };
38 : :
39 : : #define MAX_MEDIA_TYPE (sizeof(media_type) / sizeof(const char *))
40 : :
41 : : const char *link_status_str[] = { "Down. No link or cable detected.",
42 : : "Down. No link, but a cable has been detected.", "Up.",
43 : : };
44 : :
45 : : #define MAX_LINK_STR (sizeof(link_status_str) / sizeof(const char *))
46 : :
47 : : const char *fec_mode[] = {
48 : : "No active FEC",
49 : : "FEC CLAUSE 74 (Fire Code).",
50 : : "FEC CLAUSE 91 RS(528,514).",
51 : : "FEC RS544_1XN",
52 : : "FEC RS(544,528)",
53 : : "FEC RS272_1XN",
54 : : "FEC RS(272,257)"
55 : : };
56 : :
57 : : #define MAX_FEC_MODE (sizeof(fec_mode) / sizeof(const char *))
58 : :
59 : : const char *signal_mode[] = {
60 : : "NRZ", "PAM4", "PAM4_112"
61 : : };
62 : :
63 : : #define MAX_SIG_MODE (sizeof(signal_mode) / sizeof(const char *))
64 : :
65 : : /* multi-purpose multi-key table container.
66 : : * Add a unique entry for a new PHY attribs as per HW CAS.
67 : : * Query it using a helper functions.
68 : : */
69 : : struct link_speeds2_tbl {
70 : : uint16_t force_val;
71 : : uint16_t auto_val;
72 : : uint32_t rte_speed;
73 : : uint32_t rte_speed_num;
74 : : uint16_t hwrm_speed;
75 : : uint16_t sig_mode;
76 : : uint16_t lanes;
77 : : const char *desc;
78 : : } link_speeds2_tbl[] = {
79 : : {
80 : : 10,
81 : : 0,
82 : : RTE_ETH_LINK_SPEED_1G,
83 : : RTE_ETH_SPEED_NUM_1G,
84 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_1GB,
85 : : BNXT_SIG_MODE_NRZ,
86 : : 1,
87 : : "1Gb NRZ",
88 : : }, {
89 : : 100,
90 : : 1,
91 : : RTE_ETH_LINK_SPEED_10G,
92 : : RTE_ETH_SPEED_NUM_10G,
93 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_10GB,
94 : : BNXT_SIG_MODE_NRZ,
95 : : 1,
96 : : "10Gb NRZ",
97 : : }, {
98 : : 250,
99 : : 2,
100 : : RTE_ETH_LINK_SPEED_25G,
101 : : RTE_ETH_SPEED_NUM_25G,
102 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_25GB,
103 : : BNXT_SIG_MODE_NRZ,
104 : : 1,
105 : : "25Gb NRZ",
106 : : }, {
107 : : 400,
108 : : 3,
109 : : RTE_ETH_LINK_SPEED_40G,
110 : : RTE_ETH_SPEED_NUM_40G,
111 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_40GB,
112 : : BNXT_SIG_MODE_NRZ,
113 : : 4,
114 : : "40Gb NRZ",
115 : : }, {
116 : : 500,
117 : : 4,
118 : : RTE_ETH_LINK_SPEED_50G,
119 : : RTE_ETH_SPEED_NUM_50G,
120 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_50GB,
121 : : BNXT_SIG_MODE_NRZ,
122 : : 2,
123 : : "50Gb NRZ",
124 : : }, {
125 : : 1000,
126 : : 5,
127 : : RTE_ETH_LINK_SPEED_100G,
128 : : RTE_ETH_SPEED_NUM_100G,
129 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB,
130 : : BNXT_SIG_MODE_NRZ,
131 : : 4,
132 : : "100Gb NRZ",
133 : : }, {
134 : : 501,
135 : : 6,
136 : : RTE_ETH_LINK_SPEED_50G,
137 : : RTE_ETH_SPEED_NUM_50G,
138 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_50GB_PAM4_56,
139 : : BNXT_SIG_MODE_PAM4,
140 : : 1,
141 : : "50Gb (PAM4-56: 50G per lane)",
142 : : }, {
143 : : 1001,
144 : : 7,
145 : : RTE_ETH_LINK_SPEED_100G,
146 : : RTE_ETH_SPEED_NUM_100G,
147 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB_PAM4_56,
148 : : BNXT_SIG_MODE_PAM4,
149 : : 2,
150 : : "100Gb (PAM4-56: 50G per lane)",
151 : : }, {
152 : : 2001,
153 : : 8,
154 : : RTE_ETH_LINK_SPEED_200G,
155 : : RTE_ETH_SPEED_NUM_200G,
156 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_200GB_PAM4_56,
157 : : BNXT_SIG_MODE_PAM4,
158 : : 4,
159 : : "200Gb (PAM4-56: 50G per lane)",
160 : : }, {
161 : : 4001,
162 : : 9,
163 : : RTE_ETH_LINK_SPEED_400G,
164 : : RTE_ETH_SPEED_NUM_400G,
165 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_400GB_PAM4_56,
166 : : BNXT_SIG_MODE_PAM4,
167 : : 8,
168 : : "400Gb (PAM4-56: 50G per lane)",
169 : : }, {
170 : : 1002,
171 : : 10,
172 : : RTE_ETH_LINK_SPEED_100G,
173 : : RTE_ETH_SPEED_NUM_100G,
174 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_100GB_PAM4_112,
175 : : BNXT_SIG_MODE_PAM4_112,
176 : : 1,
177 : : "100Gb (PAM4-112: 100G per lane)",
178 : : }, {
179 : : 2002,
180 : : 11,
181 : : RTE_ETH_LINK_SPEED_200G,
182 : : RTE_ETH_SPEED_NUM_200G,
183 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_200GB_PAM4_112,
184 : : BNXT_SIG_MODE_PAM4_112,
185 : : 2,
186 : : "200Gb (PAM4-112: 100G per lane)",
187 : : }, {
188 : : 4002,
189 : : 12,
190 : : RTE_ETH_LINK_SPEED_400G,
191 : : RTE_ETH_SPEED_NUM_400G,
192 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_400GB_PAM4_112,
193 : : BNXT_SIG_MODE_PAM4_112,
194 : : 4,
195 : : "400Gb (PAM4-112: 100G per lane)",
196 : : }, {
197 : : 0,
198 : : 13,
199 : : RTE_ETH_LINK_SPEED_AUTONEG, /* None matches, AN is default 0 */
200 : : RTE_ETH_SPEED_NUM_NONE, /* None matches, No speed */
201 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEEDS2_1GB, /* Placeholder for wrong HWRM */
202 : : BNXT_SIG_MODE_NRZ, /* default sig */
203 : : 0,
204 : : "Unknown",
205 : : },
206 : : };
207 : :
208 : : #define BNXT_SPEEDS2_TBL_SZ (sizeof(link_speeds2_tbl) / sizeof(*link_speeds2_tbl))
209 : :
210 : : /* In hwrm_phy_qcfg reports trained up speeds in link_speed(offset:0x8[31:16]) */
211 : : struct link_speeds_tbl {
212 : : uint16_t hwrm_speed;
213 : : uint32_t rte_speed_num;
214 : : const char *desc;
215 : : } link_speeds_tbl[] = {
216 : : {
217 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB,
218 : : RTE_ETH_SPEED_NUM_100M, "100 MB",
219 : : }, {
220 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB,
221 : : RTE_ETH_SPEED_NUM_1G, "1 GB",
222 : : }, {
223 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB,
224 : : RTE_ETH_SPEED_NUM_2_5G, "25 GB",
225 : : }, {
226 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB,
227 : : RTE_ETH_SPEED_NUM_10G, "10 GB",
228 : : }, {
229 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB,
230 : : RTE_ETH_SPEED_NUM_20G, "20 GB",
231 : : }, {
232 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB,
233 : : RTE_ETH_SPEED_NUM_40G, "40 GB",
234 : : }, {
235 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB,
236 : : RTE_ETH_SPEED_NUM_50G, "50 GB",
237 : : }, {
238 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB,
239 : : RTE_ETH_SPEED_NUM_100G, "100 GB",
240 : : }, {
241 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_200GB,
242 : : RTE_ETH_SPEED_NUM_200G, "200 GB",
243 : : }, {
244 : : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_400GB,
245 : : RTE_ETH_SPEED_NUM_400G, "400 GB",
246 : : }, {
247 : : 0, RTE_ETH_SPEED_NUM_NONE, "None",
248 : : },
249 : : };
250 : :
251 : : #define BNXT_SPEEDS_TBL_SZ (sizeof(link_speeds_tbl) / sizeof(*link_speeds_tbl))
252 : :
253 : : static const char *bnxt_get_xcvr_type(uint32_t xcvr_identifier_type_tx_lpi_timer)
254 : : {
255 : 0 : uint32_t xcvr_type = HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_MASK &
256 : : xcvr_identifier_type_tx_lpi_timer;
257 : :
258 : : /* Addressing only known CMIS types */
259 : 0 : switch (xcvr_type) {
260 : : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_SFP:
261 : : return "SFP";
262 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP:
263 : 0 : return "QSFP";
264 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFPPLUS:
265 : 0 : return "QSFP+";
266 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP28:
267 : 0 : return "QSFP28";
268 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFPDD:
269 : 0 : return "QSFP112";
270 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_QSFP112:
271 : 0 : return "QSFP-DD";
272 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_XCVR_IDENTIFIER_TYPE_UNKNOWN:
273 : 0 : return "Unknown";
274 : 0 : default:
275 : : /* All other/new CMIS variants belong here */
276 : 0 : return "QSFP-xx new CMIS variant";
277 : : }
278 : : }
279 : :
280 : : /* Utility function to lookup speeds2 table and
281 : : * return a rte to hwrm speed matching row to the client
282 : : */
283 : 0 : static struct link_speeds2_tbl *bnxt_get_rte_hwrm_speeds2_entry(struct bnxt *bp)
284 : : {
285 : : int i, max;
286 : : uint32_t speed, lanes;
287 : : bool check_lanes;
288 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
289 : :
290 : 0 : speed = dev_conf->link_speeds;
291 : 0 : lanes = bp->link_info->pmd_speed_lanes;
292 : :
293 : : max = BNXT_SPEEDS2_TBL_SZ - 1;
294 : 0 : speed &= ~RTE_ETH_LINK_SPEED_FIXED;
295 : : check_lanes = !(lanes == 0);
296 : :
297 [ # # ]: 0 : for (i = 0; i < max; i++) {
298 [ # # ]: 0 : if (speed == link_speeds2_tbl[i].rte_speed &&
299 [ # # # # ]: 0 : (lanes == link_speeds2_tbl[i].lanes || !check_lanes))
300 : : break;
301 : : }
302 : :
303 [ # # ]: 0 : if (!check_lanes)
304 : 0 : PMD_DRV_LOG_LINE(INFO, "Given lanes %d, Configuring default lanes %d %s",
305 : : lanes, link_speeds2_tbl[i].lanes, link_speeds2_tbl[i].desc);
306 : 0 : return (struct link_speeds2_tbl *)&link_speeds2_tbl[i];
307 : : }
308 : :
309 : : /* Utility function to lookup speeds2 table and
310 : : * return a hwrm to rte speed matching row to the client
311 : : */
312 : : static struct link_speeds2_tbl *bnxt_get_hwrm_to_rte_speeds2_entry(uint16_t speed)
313 : : {
314 : : int i, max;
315 : :
316 : : max = BNXT_SPEEDS2_TBL_SZ - 1;
317 [ # # # # ]: 0 : for (i = 0; i < max; i++) {
318 [ # # # # ]: 0 : if (speed == link_speeds2_tbl[i].hwrm_speed)
319 : : break;
320 : : }
321 : : return (struct link_speeds2_tbl *)&link_speeds2_tbl[i];
322 : : }
323 : :
324 : : /* Helper function to lookup auto link_speed table */
325 : : static struct link_speeds_tbl *bnxt_get_hwrm_to_rte_speeds_entry(uint16_t speed)
326 : : {
327 : : int i, max;
328 : :
329 : : max = BNXT_SPEEDS_TBL_SZ - 1;
330 : :
331 [ # # ]: 0 : for (i = 0; i < max ; i++) {
332 [ # # ]: 0 : if (speed == link_speeds_tbl[i].hwrm_speed)
333 : : break;
334 : : }
335 : : return (struct link_speeds_tbl *)&link_speeds_tbl[i];
336 : : }
337 : :
338 : 0 : static int page_getenum(size_t size)
339 : : {
340 [ # # ]: 0 : if (size <= 1 << 4)
341 : : return 4;
342 [ # # ]: 0 : if (size <= 1 << 12)
343 : : return 12;
344 [ # # ]: 0 : if (size <= 1 << 13)
345 : : return 13;
346 [ # # ]: 0 : if (size <= 1 << 16)
347 : : return 16;
348 [ # # ]: 0 : if (size <= 1 << 21)
349 : : return 21;
350 [ # # ]: 0 : if (size <= 1 << 22)
351 : : return 22;
352 [ # # ]: 0 : if (size <= 1 << 30)
353 : : return 30;
354 : 0 : PMD_DRV_LOG_LINE(ERR, "Page size %zu out of range", size);
355 : 0 : return sizeof(int) * 8 - 1;
356 : : }
357 : :
358 : : static int page_roundup(size_t size)
359 : : {
360 : 0 : return 1 << page_getenum(size);
361 : : }
362 : :
363 : : static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem,
364 : : uint8_t *pg_attr,
365 : : uint64_t *pg_dir)
366 : : {
367 : 0 : if (rmem->nr_pages == 0)
368 : : return;
369 : :
370 [ # # # # : 0 : if (rmem->nr_pages > 1) {
# # # # #
# # # # #
# # ]
371 : 0 : *pg_attr = 1;
372 : 0 : *pg_dir = rte_cpu_to_le_64(rmem->pg_tbl_map);
373 : : } else {
374 : 0 : *pg_dir = rte_cpu_to_le_64(rmem->dma_arr[0]);
375 : : }
376 : : }
377 : :
378 : : static struct bnxt_cp_ring_info*
379 : 0 : bnxt_get_ring_info_by_id(struct bnxt *bp, uint16_t rid, uint16_t type)
380 : : {
381 : : struct bnxt_cp_ring_info *cp_ring = NULL;
382 : : uint16_t i;
383 : :
384 [ # # # ]: 0 : switch (type) {
385 : : case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
386 : : case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
387 : : /* FALLTHROUGH */
388 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings; i++) {
389 : 0 : struct bnxt_rx_queue *rxq = bp->rx_queues[i];
390 : :
391 [ # # ]: 0 : if (rxq->cp_ring->cp_ring_struct->fw_ring_id ==
392 : : rte_cpu_to_le_16(rid)) {
393 : 0 : return rxq->cp_ring;
394 : : }
395 : : }
396 : : break;
397 : : case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
398 [ # # ]: 0 : for (i = 0; i < bp->tx_cp_nr_rings; i++) {
399 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[i];
400 : :
401 [ # # ]: 0 : if (txq->cp_ring->cp_ring_struct->fw_ring_id ==
402 : : rte_cpu_to_le_16(rid)) {
403 : 0 : return txq->cp_ring;
404 : : }
405 : : }
406 : :
407 : : /* MPC ring is of type TX. MPC is not allocated on Thor, Wh+. */
408 [ # # ]: 0 : if (bp->mpc == NULL)
409 : 0 : goto skip_mpc;
410 : :
411 [ # # ]: 0 : for (i = 0; i < BNXT_MPC_CHNL_MAX; i++) {
412 : : struct bnxt_mpc_txq *mpc_queue;
413 : :
414 [ # # ]: 0 : if (!(bp->mpc->mpc_chnls_en & (1 << i)))
415 : 0 : continue;
416 : 0 : mpc_queue = bp->mpc->mpc_txq[i];
417 [ # # ]: 0 : if (!mpc_queue)
418 : 0 : continue;
419 : :
420 [ # # ]: 0 : if (mpc_queue->cp_ring->cp_ring_struct->fw_ring_id ==
421 : : rte_cpu_to_le_16(rid))
422 : 0 : return mpc_queue->cp_ring;
423 : : }
424 : 0 : skip_mpc:
425 : : break;
426 : : default:
427 : : return cp_ring;
428 : : }
429 : : return cp_ring;
430 : : }
431 : :
432 : : /* Complete a sweep of the CQ ring for the corresponding Tx/Rx/AGG ring.
433 : : * If the CMPL_BASE_TYPE_HWRM_DONE is not encountered by the last pass,
434 : : * before timeout, we force the done bit for the cleanup to proceed.
435 : : * Also if cpr is null, do nothing.. The HWRM command is not for a
436 : : * Tx/Rx/AGG ring cleanup.
437 : : */
438 : : static int
439 : 0 : bnxt_check_cq_hwrm_done(struct bnxt_cp_ring_info *cpr,
440 : : bool tx, bool rx, bool timeout)
441 : : {
442 : : int done = 0;
443 : :
444 [ # # ]: 0 : if (cpr != NULL) {
445 [ # # ]: 0 : if (tx)
446 : 0 : done = bnxt_flush_tx_cmp(cpr);
447 : :
448 [ # # ]: 0 : if (rx)
449 : 0 : done = bnxt_flush_rx_cmp(cpr);
450 : :
451 [ # # ]: 0 : if (done)
452 [ # # ]: 0 : PMD_DRV_LOG_LINE(DEBUG, "HWRM DONE for %s ring",
453 : : rx ? "Rx" : "Tx");
454 : :
455 : : /* We are about to timeout and still haven't seen the
456 : : * HWRM done for the Ring free. Force the cleanup.
457 : : */
458 [ # # ]: 0 : if (!done && timeout) {
459 : : done = 1;
460 [ # # ]: 0 : PMD_DRV_LOG_LINE(ERR, "Timing out for %s ring",
461 : : rx ? "Rx" : "Tx");
462 : : }
463 : : } else {
464 : : /* This HWRM command is not for a Tx/Rx/AGG ring cleanup.
465 : : * Otherwise the cpr would have been valid. So do nothing.
466 : : */
467 : : done = 1;
468 : : }
469 : :
470 : 0 : return done;
471 : : }
472 : :
473 : : /*
474 : : * HWRM Functions (sent to HWRM)
475 : : * These are named bnxt_hwrm_*() and return 0 on success or -110 if the
476 : : * HWRM command times out, or a negative error code if the HWRM
477 : : * command was failed by the FW.
478 : : */
479 : :
480 : 0 : static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
481 : : uint32_t msg_len, bool use_kong_mb)
482 : : {
483 : : unsigned int i;
484 : : struct input *req = msg;
485 : 0 : struct output *resp = bp->hwrm_cmd_resp_addr;
486 : : uint32_t *data = msg;
487 : : uint8_t *bar;
488 : : uint8_t *valid;
489 : 0 : uint16_t max_req_len = bp->max_req_len;
490 : 0 : struct hwrm_short_input short_input = { 0 };
491 [ # # ]: 0 : uint16_t bar_offset = use_kong_mb ?
492 : : GRCPF_REG_KONG_CHANNEL_OFFSET : GRCPF_REG_CHIMP_CHANNEL_OFFSET;
493 [ # # ]: 0 : uint16_t mb_trigger_offset = use_kong_mb ?
494 : : GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
495 : : struct bnxt_cp_ring_info *cpr = NULL;
496 : : bool is_rx = false;
497 : : bool is_tx = false;
498 : : uint32_t timeout;
499 : :
500 : : /* Do not send HWRM commands to firmware in error state */
501 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FATAL_ERROR)
502 : : return 0;
503 : :
504 : : /* If previous HWRM command timed out, do not send new HWRM command */
505 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_TIMEDOUT)
506 : : return 0;
507 : :
508 : 0 : timeout = bp->hwrm_cmd_timeout;
509 : :
510 : : /* Update the message length for backing store config for new FW. */
511 [ # # ]: 0 : if (bp->fw_ver >= HWRM_VERSION_1_10_2_13 &&
512 [ # # ]: 0 : rte_cpu_to_le_16(req->req_type) == HWRM_FUNC_BACKING_STORE_CFG)
513 : : msg_len = BNXT_BACKING_STORE_CFG_LEGACY_LEN;
514 : :
515 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_SHORT_CMD ||
516 [ # # ]: 0 : msg_len > bp->max_req_len) {
517 : 0 : void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
518 : :
519 : 0 : memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
520 : 0 : memcpy(short_cmd_req, req, msg_len);
521 : :
522 : 0 : short_input.req_type = rte_cpu_to_le_16(req->req_type);
523 : 0 : short_input.signature = rte_cpu_to_le_16(
524 : : HWRM_SHORT_INPUT_SIGNATURE_SHORT_CMD);
525 : 0 : short_input.size = rte_cpu_to_le_16(msg_len);
526 : 0 : short_input.req_addr =
527 : 0 : rte_cpu_to_le_64(bp->hwrm_short_cmd_req_dma_addr);
528 : :
529 : : data = (uint32_t *)&short_input;
530 : : msg_len = sizeof(short_input);
531 : :
532 : : max_req_len = BNXT_HWRM_SHORT_REQ_LEN;
533 : : }
534 : :
535 : : /* Write request msg to hwrm channel */
536 [ # # ]: 0 : for (i = 0; i < msg_len; i += 4) {
537 : 0 : bar = (uint8_t *)bp->bar0 + bar_offset + i;
538 : 0 : rte_write32(*data, bar);
539 : 0 : data++;
540 : : }
541 : :
542 : : /* Zero the rest of the request space */
543 [ # # ]: 0 : for (; i < max_req_len; i += 4) {
544 : 0 : bar = (uint8_t *)bp->bar0 + bar_offset + i;
545 : : rte_write32(0, bar);
546 : : }
547 : :
548 : : /* Ring channel doorbell */
549 : 0 : bar = (uint8_t *)bp->bar0 + mb_trigger_offset;
550 : : rte_write32(1, bar);
551 : : /*
552 : : * Make sure the channel doorbell ring command complete before
553 : : * reading the response to avoid getting stale or invalid
554 : : * responses.
555 : : */
556 : : rte_io_mb();
557 : :
558 : : /* Check ring flush is done.
559 : : * This is valid only for Tx and Rx rings (including AGG rings).
560 : : * The Tx and Rx rings should be freed once the HW confirms all
561 : : * the internal buffers and BDs associated with the rings are
562 : : * consumed and the corresponding DMA is handled.
563 : : */
564 [ # # ]: 0 : if (rte_cpu_to_le_16(req->cmpl_ring) != INVALID_HW_RING_ID) {
565 : : /* Check if the TxCQ matches. If that fails check if RxCQ
566 : : * matches. And if neither match, is_rx = false, is_tx = false.
567 : : */
568 : 0 : cpr = bnxt_get_ring_info_by_id(bp, req->cmpl_ring,
569 : : HWRM_RING_FREE_INPUT_RING_TYPE_TX);
570 [ # # ]: 0 : if (cpr == NULL) {
571 : : /* Not a TxCQ. Check if the RxCQ matches. */
572 : : cpr =
573 : 0 : bnxt_get_ring_info_by_id(bp, req->cmpl_ring,
574 : : HWRM_RING_FREE_INPUT_RING_TYPE_RX);
575 [ # # ]: 0 : if (cpr != NULL)
576 : : is_rx = true;
577 : : } else {
578 : : is_tx = true;
579 : : }
580 : : }
581 : :
582 : : /* Poll for the valid bit */
583 [ # # ]: 0 : for (i = 0; i < timeout; i++) {
584 : : int done;
585 : :
586 : 0 : done = bnxt_check_cq_hwrm_done(cpr, is_tx, is_rx,
587 : 0 : i == timeout - 1);
588 : : /* Sanity check on the resp->resp_len */
589 : 0 : rte_io_rmb();
590 [ # # # # ]: 0 : if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
591 : : /* Last byte of resp contains the valid key */
592 : 0 : valid = (uint8_t *)resp + resp->resp_len - 1;
593 [ # # # # ]: 0 : if (*valid == HWRM_RESP_VALID_KEY && done)
594 : : break;
595 : : }
596 : 0 : rte_delay_us(1);
597 : : }
598 : :
599 [ # # ]: 0 : if (i >= timeout) {
600 : : /* Suppress VER_GET timeout messages during reset recovery */
601 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_RESET &&
602 [ # # ]: 0 : rte_cpu_to_le_16(req->req_type) == HWRM_VER_GET)
603 : : return -ETIMEDOUT;
604 : :
605 : 0 : PMD_DRV_LOG_LINE(ERR,
606 : : "Error(timeout) sending msg 0x%04x, seq_id %d",
607 : : req->req_type, req->seq_id);
608 : 0 : bp->flags |= BNXT_FLAG_FW_TIMEDOUT;
609 : 0 : return -ETIMEDOUT;
610 : : }
611 : : return 0;
612 : : }
613 : :
614 : : /*
615 : : * HWRM_PREP() should be used to prepare *ALL* HWRM commands. It grabs the
616 : : * spinlock, and does initial processing.
617 : : *
618 : : * HWRM_CHECK_RESULT() returns errors on failure and may not be used. It
619 : : * releases the spinlock only if it returns. If the regular int return codes
620 : : * are not used by the function, HWRM_CHECK_RESULT() should not be used
621 : : * directly, rather it should be copied and modified to suit the function.
622 : : *
623 : : * HWRM_UNLOCK() must be called after all response processing is completed.
624 : : */
625 : : #define HWRM_PREP(req, type, kong) do { \
626 : : rte_spinlock_lock(&bp->hwrm_lock); \
627 : : if (bp->hwrm_cmd_resp_addr == NULL) { \
628 : : rte_spinlock_unlock(&bp->hwrm_lock); \
629 : : return -EACCES; \
630 : : } \
631 : : memset(bp->hwrm_cmd_resp_addr, 0, bp->max_resp_len); \
632 : : (req)->req_type = rte_cpu_to_le_16(type); \
633 : : (req)->cmpl_ring = rte_cpu_to_le_16(-1); \
634 : : (req)->seq_id = kong ? rte_cpu_to_le_16(bp->kong_cmd_seq++) :\
635 : : rte_cpu_to_le_16(bp->chimp_cmd_seq++); \
636 : : (req)->target_id = rte_cpu_to_le_16(0xffff); \
637 : : (req)->resp_addr = rte_cpu_to_le_64(bp->hwrm_cmd_resp_dma_addr); \
638 : : } while (0)
639 : :
640 : : #define HWRM_CHECK_RESULT_SILENT() do {\
641 : : if (rc) { \
642 : : rte_spinlock_unlock(&bp->hwrm_lock); \
643 : : return rc; \
644 : : } \
645 : : if (resp->error_code) { \
646 : : rc = rte_le_to_cpu_16(resp->error_code); \
647 : : rte_spinlock_unlock(&bp->hwrm_lock); \
648 : : return rc; \
649 : : } \
650 : : } while (0)
651 : :
652 : : #define HWRM_CHECK_RESULT() do {\
653 : : if (rc) { \
654 : : PMD_DRV_LOG_LINE(ERR, "failed rc:%d", rc); \
655 : : rte_spinlock_unlock(&bp->hwrm_lock); \
656 : : if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
657 : : rc = -EACCES; \
658 : : else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
659 : : rc = -ENOSPC; \
660 : : else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
661 : : rc = -EINVAL; \
662 : : else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
663 : : rc = -ENOTSUP; \
664 : : else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
665 : : rc = -EAGAIN; \
666 : : else if (rc > 0) \
667 : : rc = -EIO; \
668 : : return rc; \
669 : : } \
670 : : if (resp->error_code) { \
671 : : rc = rte_le_to_cpu_16(resp->error_code); \
672 : : if (resp->resp_len >= 16) { \
673 : : struct hwrm_err_output *tmp_hwrm_err_op = \
674 : : (void *)resp; \
675 : : PMD_DRV_LOG_LINE(ERR, \
676 : : "error %d:%d:%08x:%04x", \
677 : : rc, tmp_hwrm_err_op->cmd_err, \
678 : : rte_le_to_cpu_32(\
679 : : tmp_hwrm_err_op->opaque_0), \
680 : : rte_le_to_cpu_16(\
681 : : tmp_hwrm_err_op->opaque_1)); \
682 : : } else { \
683 : : PMD_DRV_LOG_LINE(ERR, "error %d", rc); \
684 : : } \
685 : : rte_spinlock_unlock(&bp->hwrm_lock); \
686 : : if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) \
687 : : rc = -EACCES; \
688 : : else if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) \
689 : : rc = -ENOSPC; \
690 : : else if (rc == HWRM_ERR_CODE_INVALID_PARAMS) \
691 : : rc = -EINVAL; \
692 : : else if (rc == HWRM_ERR_CODE_CMD_NOT_SUPPORTED) \
693 : : rc = -ENOTSUP; \
694 : : else if (rc == HWRM_ERR_CODE_HOT_RESET_PROGRESS) \
695 : : rc = -EAGAIN; \
696 : : else if (rc > 0) \
697 : : rc = -EIO; \
698 : : return rc; \
699 : : } \
700 : : } while (0)
701 : :
702 : : #define HWRM_UNLOCK() rte_spinlock_unlock(&bp->hwrm_lock)
703 : :
704 : 0 : int bnxt_hwrm_tf_message_direct(struct bnxt *bp,
705 : : bool use_kong_mb,
706 : : uint16_t msg_type,
707 : : void *msg,
708 : : uint32_t msg_len,
709 : : void *resp_msg,
710 : : uint32_t resp_len)
711 : : {
712 : : int rc = 0;
713 : : bool mailbox = BNXT_USE_CHIMP_MB;
714 : : struct input *req = msg;
715 : 0 : struct output *resp = bp->hwrm_cmd_resp_addr;
716 : :
717 [ # # ]: 0 : if (use_kong_mb)
718 : 0 : mailbox = BNXT_USE_KONG(bp);
719 : :
720 [ # # # # ]: 0 : HWRM_PREP(req, msg_type, mailbox);
721 : :
722 : 0 : rc = bnxt_hwrm_send_message(bp, req, msg_len, mailbox);
723 : :
724 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
725 : :
726 [ # # ]: 0 : if (resp_msg)
727 : 0 : memcpy(resp_msg, resp, resp_len);
728 : :
729 : : HWRM_UNLOCK();
730 : :
731 : 0 : return rc;
732 : : }
733 : :
734 : 0 : int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
735 : : {
736 : : int rc = 0;
737 : 0 : struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
738 : 0 : struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
739 : :
740 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
741 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
742 : 0 : req.mask = 0;
743 : :
744 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
745 : :
746 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
747 : : HWRM_UNLOCK();
748 : :
749 : 0 : return rc;
750 : : }
751 : :
752 : 0 : int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
753 : : struct bnxt_vnic_info *vnic,
754 : : uint16_t vlan_count,
755 : : struct bnxt_vlan_table_entry *vlan_table)
756 : : {
757 : : int rc = 0;
758 : 0 : struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
759 : 0 : struct hwrm_cfa_l2_set_rx_mask_output *resp = bp->hwrm_cmd_resp_addr;
760 : : uint32_t mask = 0;
761 : :
762 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
763 : : return rc;
764 : :
765 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_L2_SET_RX_MASK, BNXT_USE_CHIMP_MB);
766 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
767 : :
768 [ # # ]: 0 : if (vnic->flags & BNXT_VNIC_INFO_BCAST)
769 : : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
770 [ # # ]: 0 : if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
771 : 0 : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
772 : :
773 [ # # ]: 0 : if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
774 : 0 : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
775 : :
776 [ # # ]: 0 : if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI) {
777 : 0 : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
778 [ # # ]: 0 : } else if (vnic->flags & BNXT_VNIC_INFO_MCAST) {
779 : 0 : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
780 : 0 : req.num_mc_entries = rte_cpu_to_le_32(bp->nb_mc_addr);
781 : 0 : req.mc_tbl_addr = rte_cpu_to_le_64(bp->mc_list_dma_addr);
782 : : }
783 [ # # ]: 0 : if (vlan_table) {
784 [ # # ]: 0 : if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN))
785 : 0 : mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
786 : 0 : req.vlan_tag_tbl_addr =
787 : 0 : rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
788 : 0 : req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
789 : : }
790 : 0 : req.mask = rte_cpu_to_le_32(mask);
791 : :
792 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
793 : :
794 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
795 : : HWRM_UNLOCK();
796 : :
797 : 0 : return rc;
798 : : }
799 : :
800 : 0 : int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid,
801 : : uint16_t vlan_count,
802 : : struct bnxt_vlan_antispoof_table_entry *vlan_table)
803 : : {
804 : : int rc = 0;
805 : 0 : struct hwrm_cfa_vlan_antispoof_cfg_input req = {.req_type = 0 };
806 : 0 : struct hwrm_cfa_vlan_antispoof_cfg_output *resp =
807 : : bp->hwrm_cmd_resp_addr;
808 : :
809 : : /*
810 : : * Older HWRM versions did not support this command, and the set_rx_mask
811 : : * list was used for anti-spoof. In 1.8.0, the TX path configuration was
812 : : * removed from set_rx_mask call, and this command was added.
813 : : *
814 : : * This command is also present from 1.7.8.11 and higher,
815 : : * as well as 1.7.8.0
816 : : */
817 [ # # ]: 0 : if (bp->fw_ver < ((1 << 24) | (8 << 16))) {
818 [ # # ]: 0 : if (bp->fw_ver != ((1 << 24) | (7 << 16) | (8 << 8))) {
819 [ # # ]: 0 : if (bp->fw_ver < ((1 << 24) | (7 << 16) | (8 << 8) |
820 : : (11)))
821 : : return 0;
822 : : }
823 : : }
824 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_VLAN_ANTISPOOF_CFG, BNXT_USE_CHIMP_MB);
825 : 0 : req.fid = rte_cpu_to_le_16(fid);
826 : :
827 : 0 : req.vlan_tag_mask_tbl_addr =
828 : 0 : rte_cpu_to_le_64(rte_malloc_virt2iova(vlan_table));
829 : 0 : req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count);
830 : :
831 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
832 : :
833 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
834 : : HWRM_UNLOCK();
835 : :
836 : 0 : return rc;
837 : : }
838 : :
839 : 0 : int bnxt_hwrm_clear_l2_filter(struct bnxt *bp,
840 : : struct bnxt_filter_info *filter)
841 : : {
842 : : int rc = 0;
843 : : struct bnxt_filter_info *l2_filter = filter;
844 : : struct bnxt_vnic_info *vnic = NULL;
845 : 0 : struct hwrm_cfa_l2_filter_free_input req = {.req_type = 0 };
846 : 0 : struct hwrm_cfa_l2_filter_free_output *resp = bp->hwrm_cmd_resp_addr;
847 : :
848 [ # # ]: 0 : if (filter->fw_l2_filter_id == UINT64_MAX)
849 : : return 0;
850 : :
851 [ # # ]: 0 : if (filter->matching_l2_fltr_ptr)
852 : : l2_filter = filter->matching_l2_fltr_ptr;
853 : :
854 : 0 : PMD_DRV_LOG_LINE(DEBUG, "filter: %p l2_filter: %p ref_cnt: %d",
855 : : filter, l2_filter, l2_filter->l2_ref_cnt);
856 : :
857 [ # # ]: 0 : if (l2_filter->l2_ref_cnt == 0)
858 : : return 0;
859 : :
860 : : if (l2_filter->l2_ref_cnt > 0)
861 : 0 : l2_filter->l2_ref_cnt--;
862 : :
863 [ # # ]: 0 : if (l2_filter->l2_ref_cnt > 0)
864 : : return 0;
865 : :
866 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_L2_FILTER_FREE, BNXT_USE_CHIMP_MB);
867 : :
868 : 0 : req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
869 : :
870 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
871 : :
872 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
873 : : HWRM_UNLOCK();
874 : :
875 : 0 : filter->fw_l2_filter_id = UINT64_MAX;
876 [ # # ]: 0 : if (l2_filter->l2_ref_cnt == 0) {
877 : 0 : vnic = l2_filter->vnic;
878 [ # # ]: 0 : if (vnic) {
879 [ # # # # : 0 : STAILQ_REMOVE(&vnic->filter, l2_filter,
# # # # ]
880 : : bnxt_filter_info, next);
881 : 0 : bnxt_free_filter(bp, l2_filter);
882 : : }
883 : : }
884 : :
885 : : return 0;
886 : : }
887 : :
888 : 0 : int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
889 : : uint16_t dst_id,
890 : : struct bnxt_filter_info *filter)
891 : : {
892 : : int rc = 0;
893 : 0 : struct hwrm_cfa_l2_filter_alloc_input req = {.req_type = 0 };
894 : 0 : struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr;
895 : : uint32_t enables = 0;
896 : :
897 [ # # ]: 0 : if (filter->fw_l2_filter_id != UINT64_MAX)
898 : 0 : bnxt_hwrm_clear_l2_filter(bp, filter);
899 : :
900 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_L2_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
901 : :
902 : : /* PMD does not support XDP and RoCE */
903 : 0 : filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_XDP_DISABLE |
904 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_TRAFFIC_L2;
905 : 0 : req.flags = rte_cpu_to_le_32(filter->flags);
906 : :
907 : 0 : enables = filter->enables |
908 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
909 : 0 : req.dst_id = rte_cpu_to_le_16(dst_id);
910 : :
911 [ # # ]: 0 : if (enables &
912 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
913 : : memcpy(req.l2_addr, filter->l2_addr,
914 : : RTE_ETHER_ADDR_LEN);
915 [ # # ]: 0 : if (enables &
916 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
917 : : memcpy(req.l2_addr_mask, filter->l2_addr_mask,
918 : : RTE_ETHER_ADDR_LEN);
919 [ # # ]: 0 : if (enables &
920 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
921 : 0 : req.l2_ovlan = filter->l2_ovlan;
922 [ # # ]: 0 : if (enables &
923 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN)
924 : 0 : req.l2_ivlan = filter->l2_ivlan;
925 [ # # ]: 0 : if (enables &
926 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
927 : 0 : req.l2_ovlan_mask = filter->l2_ovlan_mask;
928 [ # # ]: 0 : if (enables &
929 : : HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK)
930 : 0 : req.l2_ivlan_mask = filter->l2_ivlan_mask;
931 [ # # ]: 0 : if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
932 : 0 : req.src_id = rte_cpu_to_le_32(filter->src_id);
933 [ # # ]: 0 : if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
934 : 0 : req.src_type = filter->src_type;
935 [ # # ]: 0 : if (filter->pri_hint) {
936 : 0 : req.pri_hint = filter->pri_hint;
937 : 0 : req.l2_filter_id_hint =
938 : 0 : rte_cpu_to_le_64(filter->l2_filter_id_hint);
939 : : }
940 : :
941 : 0 : req.enables = rte_cpu_to_le_32(enables);
942 : :
943 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
944 : :
945 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
946 : :
947 : 0 : filter->fw_l2_filter_id = rte_le_to_cpu_64(resp->l2_filter_id);
948 : 0 : filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
949 : : HWRM_UNLOCK();
950 : :
951 : 0 : filter->l2_ref_cnt++;
952 : :
953 : 0 : return rc;
954 : : }
955 : :
956 : 0 : int bnxt_hwrm_ptp_cfg(struct bnxt *bp)
957 : : {
958 : 0 : struct hwrm_port_mac_cfg_input req = {.req_type = 0};
959 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
960 : : uint32_t flags = 0;
961 : : int rc;
962 : :
963 [ # # ]: 0 : if (!ptp)
964 : : return 0;
965 : :
966 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_MAC_CFG, BNXT_USE_CHIMP_MB);
967 : :
968 [ # # ]: 0 : if (ptp->rx_filter)
969 : : flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_ENABLE;
970 : : else
971 : : flags |=
972 : : HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_RX_TS_CAPTURE_DISABLE;
973 [ # # ]: 0 : if (ptp->tx_tstamp_en)
974 : 0 : flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_ENABLE;
975 : : else
976 : 0 : flags |=
977 : : HWRM_PORT_MAC_CFG_INPUT_FLAGS_PTP_TX_TS_CAPTURE_DISABLE;
978 : :
979 [ # # ]: 0 : if (ptp->filter_all)
980 : 0 : flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_ALL_RX_TS_CAPTURE_ENABLE;
981 [ # # ]: 0 : else if (bp->fw_cap & BNXT_FW_CAP_RX_ALL_PKT_TS)
982 : 0 : flags |= HWRM_PORT_MAC_CFG_INPUT_FLAGS_ALL_RX_TS_CAPTURE_DISABLE;
983 : :
984 : 0 : req.flags = rte_cpu_to_le_32(flags);
985 : 0 : req.enables = rte_cpu_to_le_32
986 : : (HWRM_PORT_MAC_CFG_INPUT_ENABLES_RX_TS_CAPTURE_PTP_MSG_TYPE);
987 : 0 : req.rx_ts_capture_ptp_msg_type = rte_cpu_to_le_16(ptp->rxctl);
988 : :
989 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
990 : : HWRM_UNLOCK();
991 : :
992 : 0 : return rc;
993 : : }
994 : :
995 : 0 : static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
996 : : {
997 : : int rc = 0;
998 : 0 : struct hwrm_port_mac_ptp_qcfg_input req = {.req_type = 0};
999 : 0 : struct hwrm_port_mac_ptp_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1000 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
1001 : :
1002 [ # # ]: 0 : if (ptp)
1003 : : return 0;
1004 : :
1005 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_MAC_PTP_QCFG, BNXT_USE_CHIMP_MB);
1006 : :
1007 : 0 : req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
1008 : :
1009 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1010 : :
1011 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1012 : :
1013 [ # # ]: 0 : if (!BNXT_CHIP_P7(bp) &&
1014 [ # # ]: 0 : !(resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_HWRM_ACCESS))
1015 : : return 0;
1016 : :
1017 [ # # ]: 0 : if (resp->flags & HWRM_PORT_MAC_PTP_QCFG_OUTPUT_FLAGS_ONE_STEP_TX_TS)
1018 : 0 : bp->flags |= BNXT_FLAG_FW_CAP_ONE_STEP_TX_TS;
1019 : :
1020 : 0 : ptp = rte_zmalloc("ptp_cfg", sizeof(*ptp), 0);
1021 [ # # ]: 0 : if (!ptp)
1022 : : return -ENOMEM;
1023 : :
1024 : 0 : ptp->bp = bp;
1025 : 0 : bp->ptp_cfg = ptp;
1026 : :
1027 : 0 : return 0;
1028 : : }
1029 : :
1030 : 0 : void bnxt_free_vf_info(struct bnxt *bp)
1031 : : {
1032 : : int i;
1033 : :
1034 [ # # ]: 0 : if (bp->pf == NULL)
1035 : : return;
1036 : :
1037 [ # # ]: 0 : if (bp->pf->vf_info == NULL)
1038 : : return;
1039 : :
1040 [ # # ]: 0 : for (i = 0; i < bp->pf->max_vfs; i++) {
1041 : 0 : rte_free(bp->pf->vf_info[i].vlan_table);
1042 : 0 : bp->pf->vf_info[i].vlan_table = NULL;
1043 : 0 : rte_free(bp->pf->vf_info[i].vlan_as_table);
1044 : 0 : bp->pf->vf_info[i].vlan_as_table = NULL;
1045 : : }
1046 : 0 : rte_free(bp->pf->vf_info);
1047 : 0 : bp->pf->vf_info = NULL;
1048 : : }
1049 : :
1050 : 0 : static int bnxt_alloc_vf_info(struct bnxt *bp, uint16_t max_vfs)
1051 : : {
1052 : 0 : struct bnxt_child_vf_info *vf_info = bp->pf->vf_info;
1053 : : int i;
1054 : :
1055 [ # # ]: 0 : if (vf_info)
1056 : 0 : bnxt_free_vf_info(bp);
1057 : :
1058 : 0 : vf_info = rte_zmalloc("bnxt_vf_info", sizeof(*vf_info) * max_vfs, 0);
1059 [ # # ]: 0 : if (vf_info == NULL) {
1060 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc vf info");
1061 : 0 : return -ENOMEM;
1062 : : }
1063 : :
1064 : 0 : bp->pf->max_vfs = max_vfs;
1065 : 0 : bp->pf->vf_info = vf_info;
1066 [ # # ]: 0 : for (i = 0; i < max_vfs; i++) {
1067 : 0 : vf_info[i].fid = bp->pf->first_vf_id + i;
1068 : 0 : vf_info[i].vlan_table = rte_zmalloc("VF VLAN table",
1069 : 0 : getpagesize(), getpagesize());
1070 [ # # ]: 0 : if (vf_info[i].vlan_table == NULL) {
1071 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc VLAN table for VF %d", i);
1072 : 0 : goto err;
1073 : : }
1074 : 0 : rte_mem_lock_page(vf_info[i].vlan_table);
1075 : :
1076 : 0 : vf_info[i].vlan_as_table = rte_zmalloc("VF VLAN AS table",
1077 : : getpagesize(), getpagesize());
1078 [ # # ]: 0 : if (vf_info[i].vlan_as_table == NULL) {
1079 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to alloc VLAN AS table for VF %d", i);
1080 : 0 : goto err;
1081 : : }
1082 : 0 : rte_mem_lock_page(vf_info[i].vlan_as_table);
1083 : :
1084 : 0 : STAILQ_INIT(&vf_info[i].filter);
1085 : : }
1086 : :
1087 : : return 0;
1088 : 0 : err:
1089 : 0 : bnxt_free_vf_info(bp);
1090 : 0 : return -ENOMEM;
1091 : : }
1092 : :
1093 : 0 : static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
1094 : : {
1095 : : int rc = 0;
1096 : 0 : struct hwrm_func_qcaps_input req = {.req_type = 0 };
1097 : 0 : struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1098 : : uint32_t flags, flags_ext2, flags_ext3;
1099 : : uint16_t new_max_vfs;
1100 : :
1101 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
1102 : :
1103 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
1104 : :
1105 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1106 : :
1107 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1108 : :
1109 : 0 : bp->max_ring_grps = rte_le_to_cpu_32(resp->max_hw_ring_grps);
1110 [ # # ]: 0 : if (bp->max_ring_grps > BNXT_MAX_RING_GRPS)
1111 : 0 : bp->max_ring_grps = BNXT_MAX_RING_GRPS;
1112 : 0 : flags = rte_le_to_cpu_32(resp->flags);
1113 : 0 : flags_ext2 = rte_le_to_cpu_32(resp->flags_ext2);
1114 : 0 : flags_ext3 = rte_le_to_cpu_32(resp->flags_ext3);
1115 : :
1116 [ # # ]: 0 : if (BNXT_PF(bp)) {
1117 : 0 : bp->pf->port_id = resp->port_id;
1118 : 0 : bp->pf->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
1119 : 0 : bp->pf->total_vfs = rte_le_to_cpu_16(resp->max_vfs);
1120 : 0 : new_max_vfs = bp->pdev->max_vfs;
1121 [ # # ]: 0 : if (new_max_vfs != bp->pf->max_vfs) {
1122 : 0 : rc = bnxt_alloc_vf_info(bp, new_max_vfs);
1123 [ # # ]: 0 : if (rc)
1124 : 0 : goto unlock;
1125 : : }
1126 : : }
1127 : :
1128 : 0 : bp->fw_fid = rte_le_to_cpu_32(resp->fid);
1129 [ # # ]: 0 : if (!bnxt_check_zero_bytes(resp->mac_address, RTE_ETHER_ADDR_LEN)) {
1130 : 0 : bp->flags |= BNXT_FLAG_DFLT_MAC_SET;
1131 : 0 : memcpy(bp->mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
1132 : : } else {
1133 : 0 : bp->flags &= ~BNXT_FLAG_DFLT_MAC_SET;
1134 : : }
1135 : 0 : bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
1136 : 0 : bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
1137 : 0 : bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
1138 : 0 : bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
1139 : 0 : bp->first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
1140 : 0 : bp->max_rx_em_flows = rte_le_to_cpu_16(resp->max_rx_em_flows);
1141 : 0 : bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
1142 [ # # # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp) && !bp->pdev->max_vfs) {
1143 : 0 : uint32_t l2_ctx = bp->max_l2_ctx + bp->max_rx_em_flows;
1144 : 0 : bp->max_l2_ctx = (uint16_t)RTE_MIN(l2_ctx, (uint32_t)BNXT_MAX_L2_CTX);
1145 : : }
1146 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
1147 : 0 : bp->max_vnics = rte_le_to_cpu_16(BNXT_MAX_VNICS_COS_CLASSIFY);
1148 : : else
1149 : 0 : bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
1150 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Max l2_cntxts is %d vnics is %d",
1151 : : bp->max_l2_ctx, bp->max_vnics);
1152 : 0 : bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
1153 : 0 : bp->max_mcast_addr = rte_le_to_cpu_32(resp->max_mcast_filters);
1154 [ # # ]: 0 : if (!bp->max_mcast_addr)
1155 : 0 : bp->max_mcast_addr = BNXT_DFLT_MAX_MC_ADDR;
1156 [ # # ]: 0 : memcpy(bp->dsn, resp->device_serial_number, sizeof(bp->dsn));
1157 : :
1158 [ # # ]: 0 : if (BNXT_PF(bp))
1159 : 0 : bp->pf->total_vnics = rte_le_to_cpu_16(resp->max_vnics);
1160 : :
1161 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_STATS_SUPPORTED)
1162 : 0 : bp->flags |= BNXT_FLAG_EXT_STATS_SUPPORTED;
1163 : :
1164 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERROR_RECOVERY_CAPABLE) {
1165 : 0 : bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY;
1166 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Adapter Error recovery SUPPORTED");
1167 : : }
1168 : :
1169 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_ERR_RECOVER_RELOAD)
1170 : 0 : bp->fw_cap |= BNXT_FW_CAP_ERR_RECOVER_RELOAD;
1171 : :
1172 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_HOT_RESET_CAPABLE)
1173 : 0 : bp->fw_cap |= BNXT_FW_CAP_HOT_RESET;
1174 : :
1175 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_LINK_ADMIN_STATUS_SUPPORTED)
1176 : 0 : bp->fw_cap |= BNXT_FW_CAP_LINK_ADMIN;
1177 : :
1178 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT_BS_V2_SUPPORTED) {
1179 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Backing store v2 supported");
1180 [ # # ]: 0 : if (BNXT_CHIP_P7(bp))
1181 : 0 : bp->fw_cap |= BNXT_FW_CAP_BACKING_STORE_V2;
1182 : : }
1183 : :
1184 : : /* only initialize the mpc capability one time */
1185 [ # # # # ]: 0 : if (resp->mpc_chnls_cap && !bp->mpc) {
1186 : : struct bnxt_mpc *mpc;
1187 : :
1188 : 0 : mpc = rte_zmalloc("bnxt_mpc", sizeof(*mpc), 0);
1189 [ # # ]: 0 : if (!mpc) {
1190 : : /* no impact to basic NIC functionalities. Truflow
1191 : : * will be disabled if mpc is not setup.
1192 : : */
1193 : 0 : PMD_DRV_LOG_LINE(ERR, "Fail allocate mpc memory");
1194 : : } else {
1195 : 0 : mpc->mpc_chnls_cap = resp->mpc_chnls_cap;
1196 : 0 : bp->mpc = mpc;
1197 : : }
1198 : : }
1199 : :
1200 [ # # ]: 0 : if (!(flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_VLAN_ACCELERATION_TX_DISABLED)) {
1201 : 0 : bp->fw_cap |= BNXT_FW_CAP_VLAN_TX_INSERT;
1202 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VLAN acceleration for TX is enabled");
1203 : : }
1204 : :
1205 : 0 : bp->tunnel_disable_flag = rte_le_to_cpu_16(resp->tunnel_disable_flag);
1206 [ # # ]: 0 : if (bp->tunnel_disable_flag)
1207 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tunnel parsing capability is disabled, flags : %#x",
1208 : : bp->tunnel_disable_flag);
1209 : :
1210 [ # # ]: 0 : if (flags_ext2 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT2_RX_ALL_PKTS_TIMESTAMPS_SUPPORTED)
1211 : 0 : bp->fw_cap |= BNXT_FW_CAP_RX_ALL_PKT_TS;
1212 [ # # ]: 0 : if (flags_ext2 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT2_UDP_GSO_SUPPORTED)
1213 : 0 : bp->fw_cap |= BNXT_FW_CAP_UDP_GSO;
1214 [ # # ]: 0 : if (flags_ext2 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT2_TX_PKT_TS_CMPL_SUPPORTED)
1215 : 0 : bp->fw_cap |= BNXT_FW_CAP_TX_TS_CMP;
1216 [ # # ]: 0 : if (flags_ext3 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT3_RX_RATE_PROFILE_SEL_SUPPORTED)
1217 : 0 : bp->fw_cap |= BNXT_FW_CAP_RX_RATE_PROFILE;
1218 : :
1219 [ # # ]: 0 : if (flags_ext3 & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_EXT3_MULTI_L2_DB_SUPPORTED)
1220 : 0 : bp->fw_cap |= BNXT_FW_CAP_MULTI_DB;
1221 : :
1222 : : /* This block should be kept at the end of this function because it
1223 : : * sends another hwrm msg.
1224 : : */
1225 [ # # ]: 0 : if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
1226 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp) || BNXT_PF(bp)) {
1227 : 0 : bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
1228 : 0 : PMD_DRV_LOG_LINE(DEBUG, "PTP SUPPORTED");
1229 : : HWRM_UNLOCK();
1230 : 0 : bnxt_hwrm_ptp_qcfg(bp);
1231 : : }
1232 : : }
1233 : :
1234 : 0 : unlock:
1235 : : HWRM_UNLOCK();
1236 : :
1237 : 0 : return rc;
1238 : : }
1239 : :
1240 : 0 : int bnxt_hwrm_func_qcaps(struct bnxt *bp)
1241 : : {
1242 : : int rc;
1243 : :
1244 : 0 : rc = __bnxt_hwrm_func_qcaps(bp);
1245 [ # # ]: 0 : if (rc == -ENOMEM)
1246 : : return rc;
1247 : :
1248 [ # # # # ]: 0 : if (!rc && bp->hwrm_spec_code >= HWRM_SPEC_CODE_1_8_3) {
1249 : 0 : rc = bnxt_alloc_ctx_mem(bp);
1250 [ # # ]: 0 : if (rc)
1251 : : return rc;
1252 : :
1253 : : /* On older FW,
1254 : : * bnxt_hwrm_func_resc_qcaps can fail and cause init failure.
1255 : : * But the error can be ignored. Return success.
1256 : : */
1257 : 0 : rc = bnxt_hwrm_func_resc_qcaps(bp);
1258 [ # # ]: 0 : if (!rc)
1259 : 0 : bp->flags |= BNXT_FLAG_NEW_RM;
1260 : : }
1261 : :
1262 : : return 0;
1263 : : }
1264 : :
1265 : : /* VNIC cap covers capability of all VNICs. So no need to pass vnic_id */
1266 : 0 : int bnxt_hwrm_vnic_qcaps(struct bnxt *bp)
1267 : : {
1268 : : int rc = 0;
1269 : : uint32_t flags;
1270 : 0 : struct hwrm_vnic_qcaps_input req = {.req_type = 0 };
1271 : 0 : struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1272 : :
1273 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_QCAPS, BNXT_USE_CHIMP_MB);
1274 : :
1275 : : req.target_id = rte_cpu_to_le_16(0xffff);
1276 : :
1277 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1278 : :
1279 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1280 : :
1281 : 0 : bp->vnic_cap_flags = 0;
1282 : :
1283 : 0 : flags = rte_le_to_cpu_32(resp->flags);
1284 : :
1285 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_COS_ASSIGNMENT_CAP) {
1286 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_COS_CLASSIFY;
1287 : 0 : PMD_DRV_LOG_LINE(INFO, "CoS assignment capability enabled");
1288 : : }
1289 : :
1290 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_OUTERMOST_RSS_CAP)
1291 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_OUTER_RSS;
1292 : :
1293 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_OUTERMOST_RSS_TRUSTED_VF_CAP) {
1294 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_OUTER_RSS_TRUSTED_VF;
1295 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Trusted VF's outer RSS capability is enabled");
1296 : : }
1297 : :
1298 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RX_CMPL_V2_CAP)
1299 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_RX_CMPL_V2;
1300 : :
1301 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_VLAN_STRIP_CAP) {
1302 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_VLAN_RX_STRIP;
1303 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Rx VLAN strip capability enabled");
1304 : : }
1305 : :
1306 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RING_SELECT_MODE_XOR_CAP)
1307 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_XOR_MODE;
1308 : :
1309 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RING_SELECT_MODE_TOEPLITZ_CHKSM_CAP)
1310 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_CHKSM_MODE;
1311 : :
1312 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPV6_FLOW_LABEL_CAP)
1313 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE;
1314 : :
1315 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_L2_CQE_MODE_CAP)
1316 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_L2_CQE_MODE;
1317 : :
1318 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_AH_SPI_IPV4_CAP)
1319 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_AH_SPI4_CAP;
1320 : :
1321 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_AH_SPI_IPV6_CAP)
1322 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_AH_SPI6_CAP;
1323 : :
1324 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_ESP_SPI_IPV4_CAP)
1325 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_ESP_SPI4_CAP;
1326 : :
1327 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_RSS_IPSEC_ESP_SPI_IPV6_CAP)
1328 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_ESP_SPI6_CAP;
1329 : :
1330 [ # # ]: 0 : if (flags & HWRM_VNIC_QCAPS_OUTPUT_FLAGS_HW_TUNNEL_TPA_CAP)
1331 : 0 : bp->vnic_cap_flags |= BNXT_VNIC_CAP_VNIC_TUNNEL_TPA;
1332 : :
1333 : 0 : bp->max_tpa_v2 = rte_le_to_cpu_16(resp->max_aggs_supported);
1334 : :
1335 : : HWRM_UNLOCK();
1336 : :
1337 : 0 : return rc;
1338 : : }
1339 : :
1340 : 0 : int bnxt_hwrm_func_reset(struct bnxt *bp)
1341 : : {
1342 : : int rc = 0;
1343 : 0 : struct hwrm_func_reset_input req = {.req_type = 0 };
1344 : 0 : struct hwrm_func_reset_output *resp = bp->hwrm_cmd_resp_addr;
1345 : :
1346 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_RESET, BNXT_USE_CHIMP_MB);
1347 : :
1348 : 0 : req.enables = rte_cpu_to_le_32(0);
1349 : :
1350 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1351 : :
1352 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1353 : : HWRM_UNLOCK();
1354 : :
1355 : 0 : return rc;
1356 : : }
1357 : :
1358 : 0 : int bnxt_hwrm_func_driver_register(struct bnxt *bp)
1359 : : {
1360 : : int rc;
1361 : : uint32_t flags = 0;
1362 : 0 : struct hwrm_func_drv_rgtr_input req = {.req_type = 0 };
1363 : 0 : struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
1364 : :
1365 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_REGISTERED)
1366 : : return 0;
1367 : :
1368 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
1369 : : flags = HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_HOT_RESET_SUPPORT;
1370 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
1371 : 0 : flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_ERROR_RECOVERY_SUPPORT;
1372 : :
1373 : : /* PFs and trusted VFs should indicate the support of the
1374 : : * Master capability on non Stingray platform
1375 : : */
1376 [ # # # # ]: 0 : if ((BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) && !BNXT_STINGRAY(bp))
1377 : 0 : flags |= HWRM_FUNC_DRV_RGTR_INPUT_FLAGS_MASTER_SUPPORT;
1378 : :
1379 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_DRV_RGTR, BNXT_USE_CHIMP_MB);
1380 : 0 : req.enables = rte_cpu_to_le_32(HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VER |
1381 : : HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_ASYNC_EVENT_FWD);
1382 : 0 : req.ver_maj_8b = RTE_VER_YEAR;
1383 : 0 : req.ver_min_8b = RTE_VER_MONTH;
1384 : 0 : req.ver_upd_8b = RTE_VER_MINOR;
1385 : :
1386 [ # # ]: 0 : if (BNXT_PF(bp)) {
1387 : 0 : req.enables |= rte_cpu_to_le_32(
1388 : : HWRM_FUNC_DRV_RGTR_INPUT_ENABLES_VF_REQ_FWD);
1389 : 0 : memcpy(req.vf_req_fwd, bp->pf->vf_req_fwd,
1390 : : RTE_MIN(sizeof(req.vf_req_fwd),
1391 : : sizeof(bp->pf->vf_req_fwd)));
1392 : : }
1393 : :
1394 : 0 : req.flags = rte_cpu_to_le_32(flags);
1395 : :
1396 : 0 : req.async_event_fwd[0] |=
1397 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_LINK_STATUS_CHANGE |
1398 : : ASYNC_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED |
1399 : : ASYNC_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE |
1400 : : ASYNC_CMPL_EVENT_ID_LINK_SPEED_CHANGE |
1401 : : ASYNC_CMPL_EVENT_ID_RESET_NOTIFY);
1402 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)
1403 : 0 : req.async_event_fwd[0] |=
1404 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ERROR_RECOVERY);
1405 : 0 : req.async_event_fwd[1] |=
1406 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_PF_DRVR_UNLOAD |
1407 : : ASYNC_CMPL_EVENT_ID_VF_CFG_CHANGE);
1408 [ # # ]: 0 : if (BNXT_PF(bp))
1409 : 0 : req.async_event_fwd[1] |=
1410 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DBG_NOTIFICATION);
1411 : :
1412 [ # # ]: 0 : if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
1413 : 0 : req.async_event_fwd[1] |=
1414 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_DEFAULT_VNIC_CHANGE |
1415 : : ASYNC_CMPL_EVENT_ID_VF_FLR);
1416 : : }
1417 : :
1418 : 0 : req.async_event_fwd[2] |=
1419 : : rte_cpu_to_le_32(ASYNC_CMPL_EVENT_ID_ECHO_REQUEST |
1420 : : ASYNC_CMPL_EVENT_ID_ERROR_REPORT |
1421 : : ASYNC_CMPL_EVENT_ID_RSS_CHANGE);
1422 : :
1423 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1424 : :
1425 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1426 : :
1427 : 0 : flags = rte_le_to_cpu_32(resp->flags);
1428 [ # # ]: 0 : if (flags & HWRM_FUNC_DRV_RGTR_OUTPUT_FLAGS_IF_CHANGE_SUPPORTED)
1429 : 0 : bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE;
1430 : :
1431 : : HWRM_UNLOCK();
1432 : :
1433 : 0 : bp->flags |= BNXT_FLAG_REGISTERED;
1434 : :
1435 : 0 : return rc;
1436 : : }
1437 : :
1438 : 0 : int bnxt_hwrm_check_vf_rings(struct bnxt *bp)
1439 : : {
1440 [ # # ]: 0 : if (!(BNXT_VF(bp) && (bp->flags & BNXT_FLAG_NEW_RM)))
1441 : : return 0;
1442 : :
1443 : 0 : return bnxt_hwrm_func_reserve_vf_resc(bp, true);
1444 : : }
1445 : :
1446 : 0 : int bnxt_hwrm_func_reserve_vf_resc(struct bnxt *bp, bool test)
1447 : : {
1448 : : int rc;
1449 : : uint32_t flags = 0;
1450 : : uint32_t enables;
1451 : 0 : struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1452 : 0 : struct hwrm_func_vf_cfg_input req = {0};
1453 [ # # ]: 0 : uint8_t mpc_ring_cnt = bp->mpc ? BNXT_MPC_RINGS_SUPPORTED : 0;
1454 : :
1455 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
1456 : :
1457 : : enables = HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RX_RINGS |
1458 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_TX_RINGS |
1459 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
1460 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
1461 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS;
1462 : :
1463 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp)) {
1464 : : enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
1465 : 0 : req.num_hw_ring_grps = rte_cpu_to_le_16(bp->rx_nr_rings);
1466 : : }
1467 : :
1468 : 0 : req.num_tx_rings = rte_cpu_to_le_16(bp->tx_nr_rings + mpc_ring_cnt);
1469 : 0 : req.num_rx_rings = rte_cpu_to_le_16(bp->rx_nr_rings *
1470 : : AGG_RING_MULTIPLIER);
1471 : 0 : req.num_stat_ctxs = rte_cpu_to_le_16(bp->rx_nr_rings +
1472 : : bp->tx_nr_rings +
1473 : : mpc_ring_cnt);
1474 : 0 : req.num_cmpl_rings = rte_cpu_to_le_16(bp->rx_nr_rings +
1475 : : bp->tx_nr_rings +
1476 : : BNXT_NUM_ASYNC_CPR(bp) +
1477 : : mpc_ring_cnt);
1478 [ # # ]: 0 : if (BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp)) {
1479 : 0 : req.num_vnics = rte_cpu_to_le_16(RTE_MIN(BNXT_VNIC_MAX_SUPPORTED_ID,
1480 : : bp->max_vnics));
1481 : 0 : enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
1482 : 0 : req.num_rsscos_ctxs = rte_cpu_to_le_16(RTE_MIN(BNXT_VNIC_MAX_SUPPORTED_ID,
1483 : : bp->max_rsscos_ctx));
1484 : : } else {
1485 : 0 : req.num_vnics = rte_cpu_to_le_16(bp->rx_nr_rings);
1486 : : }
1487 : :
1488 [ # # ]: 0 : if (bp->vf_resv_strategy ==
1489 : : HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC) {
1490 : 0 : enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_VNICS |
1491 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_L2_CTXS |
1492 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
1493 : 0 : req.num_rsscos_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_RSS_CTX);
1494 : 0 : req.num_l2_ctxs = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_L2_CTX);
1495 : 0 : req.num_vnics = rte_cpu_to_le_16(BNXT_VF_RSV_NUM_VNIC);
1496 [ # # ]: 0 : } else if (bp->vf_resv_strategy ==
1497 : : HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MAXIMAL) {
1498 : 0 : enables |= HWRM_FUNC_VF_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS;
1499 : 0 : req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
1500 : : }
1501 : :
1502 [ # # ]: 0 : if (test)
1503 : : flags = HWRM_FUNC_VF_CFG_INPUT_FLAGS_TX_ASSETS_TEST |
1504 : : HWRM_FUNC_VF_CFG_INPUT_FLAGS_RX_ASSETS_TEST |
1505 : : HWRM_FUNC_VF_CFG_INPUT_FLAGS_CMPL_ASSETS_TEST |
1506 : : HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST |
1507 : : HWRM_FUNC_VF_CFG_INPUT_FLAGS_STAT_CTX_ASSETS_TEST |
1508 : : HWRM_FUNC_VF_CFG_INPUT_FLAGS_VNIC_ASSETS_TEST;
1509 : :
1510 [ # # # # ]: 0 : if (test && BNXT_HAS_RING_GRPS(bp))
1511 : 0 : flags |= HWRM_FUNC_VF_CFG_INPUT_FLAGS_RING_GRP_ASSETS_TEST;
1512 : :
1513 : 0 : req.flags = rte_cpu_to_le_32(flags);
1514 : 0 : req.enables |= rte_cpu_to_le_32(enables);
1515 : :
1516 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1517 : :
1518 [ # # ]: 0 : if (test)
1519 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
1520 : : else
1521 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1522 : :
1523 : : HWRM_UNLOCK();
1524 : 0 : return rc;
1525 : : }
1526 : :
1527 : 0 : int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp)
1528 : : {
1529 : : int rc;
1530 : 0 : struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1531 : 0 : struct hwrm_func_resource_qcaps_input req = {0};
1532 : :
1533 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_RESOURCE_QCAPS, BNXT_USE_CHIMP_MB);
1534 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
1535 : :
1536 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1537 : :
1538 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
1539 : :
1540 : 0 : bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
1541 : 0 : bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
1542 : 0 : bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
1543 : 0 : bp->max_rx_rings = rte_le_to_cpu_16(resp->max_rx_rings);
1544 : 0 : bp->max_ring_grps = rte_le_to_cpu_16(resp->max_hw_ring_grps);
1545 : : /* func_resource_qcaps does not return max_rx_em_flows.
1546 : : * So use the value provided by func_qcaps.
1547 : : */
1548 : 0 : bp->max_l2_ctx = rte_le_to_cpu_16(resp->max_l2_ctxs);
1549 [ # # # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp) && !bp->pdev->max_vfs) {
1550 : 0 : uint32_t l2_ctx = bp->max_l2_ctx + bp->max_rx_em_flows;
1551 : 0 : bp->max_l2_ctx = (uint16_t)RTE_MIN(l2_ctx, (uint32_t)BNXT_MAX_L2_CTX);
1552 : : }
1553 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY)
1554 : 0 : bp->max_vnics = rte_le_to_cpu_16(BNXT_MAX_VNICS_COS_CLASSIFY);
1555 : : else
1556 : 0 : bp->max_vnics = rte_le_to_cpu_16(resp->max_vnics);
1557 : 0 : bp->max_stat_ctx = rte_le_to_cpu_16(resp->max_stat_ctx);
1558 [ # # ]: 0 : if (BNXT_CHIP_P7(bp))
1559 : 0 : bp->max_nq_rings = BNXT_P7_MAX_NQ_RING_CNT;
1560 : : else
1561 : 0 : bp->max_nq_rings = rte_le_to_cpu_16(resp->max_msix);
1562 : 0 : bp->vf_resv_strategy = rte_le_to_cpu_16(resp->vf_reservation_strategy);
1563 [ # # ]: 0 : if (bp->vf_resv_strategy >
1564 : : HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESV_STRATEGY_MINIMAL_STATIC)
1565 : 0 : bp->vf_resv_strategy =
1566 : : HWRM_FUNC_RESOURCE_QCAPS_OUTPUT_VF_RESERVATION_STRATEGY_MAXIMAL;
1567 : :
1568 : : HWRM_UNLOCK();
1569 : 0 : return rc;
1570 : : }
1571 : :
1572 : 0 : int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
1573 : : {
1574 : 0 : struct hwrm_ver_get_input req = {.req_type = 0 };
1575 : 0 : struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
1576 : : uint32_t fw_version;
1577 : : uint16_t max_resp_len;
1578 : : char type[RTE_MEMZONE_NAMESIZE];
1579 : : int rc = 0;
1580 : : uint32_t dev_caps_cfg;
1581 : :
1582 : 0 : bp->max_req_len = HWRM_MAX_REQ_LEN;
1583 : 0 : bp->hwrm_cmd_timeout = timeout;
1584 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
1585 : :
1586 : 0 : req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
1587 : 0 : req.hwrm_intf_min = HWRM_VERSION_MINOR;
1588 : 0 : req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
1589 : :
1590 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1591 : :
1592 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_FW_RESET)
1593 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
1594 : : else
1595 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1596 : :
1597 : 0 : PMD_DRV_LOG_LINE(INFO, "%d.%d.%d:%d.%d.%d.%d",
1598 : : resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b,
1599 : : resp->hwrm_intf_upd_8b, resp->hwrm_fw_maj_8b,
1600 : : resp->hwrm_fw_min_8b, resp->hwrm_fw_bld_8b,
1601 : : resp->hwrm_fw_rsvd_8b);
1602 : 0 : bp->fw_ver = ((uint32_t)resp->hwrm_fw_maj_8b << 24) |
1603 : 0 : ((uint32_t)resp->hwrm_fw_min_8b << 16) |
1604 : 0 : ((uint32_t)resp->hwrm_fw_bld_8b << 8) |
1605 : 0 : resp->hwrm_fw_rsvd_8b;
1606 : 0 : PMD_DRV_LOG_LINE(INFO, "Driver HWRM version: %d.%d.%d",
1607 : : HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
1608 : :
1609 : 0 : fw_version = resp->hwrm_intf_maj_8b << 16;
1610 : 0 : fw_version |= resp->hwrm_intf_min_8b << 8;
1611 : 0 : fw_version |= resp->hwrm_intf_upd_8b;
1612 : 0 : bp->hwrm_spec_code = fw_version;
1613 : :
1614 : : /* def_req_timeout value is in milliseconds */
1615 : 0 : bp->hwrm_cmd_timeout = rte_le_to_cpu_16(resp->def_req_timeout);
1616 : : /* convert timeout to usec */
1617 : 0 : bp->hwrm_cmd_timeout *= 1000;
1618 [ # # ]: 0 : if (!bp->hwrm_cmd_timeout)
1619 : 0 : bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT;
1620 : :
1621 [ # # ]: 0 : if (resp->hwrm_intf_maj_8b != HWRM_VERSION_MAJOR) {
1622 : 0 : PMD_DRV_LOG_LINE(ERR, "Unsupported firmware API version");
1623 : : rc = -EINVAL;
1624 : 0 : goto error;
1625 : : }
1626 : :
1627 [ # # ]: 0 : if (bp->max_req_len > resp->max_req_win_len) {
1628 : 0 : PMD_DRV_LOG_LINE(ERR, "Unsupported request length");
1629 : : rc = -EINVAL;
1630 : 0 : goto error;
1631 : : }
1632 : :
1633 : 0 : bp->chip_num = rte_le_to_cpu_16(resp->chip_num);
1634 : :
1635 : 0 : bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
1636 : 0 : bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
1637 [ # # ]: 0 : if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
1638 : 0 : bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
1639 : :
1640 : 0 : max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
1641 : 0 : dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
1642 : :
1643 [ # # ]: 0 : RTE_VERIFY(max_resp_len <= bp->max_resp_len);
1644 : 0 : bp->max_resp_len = max_resp_len;
1645 : 0 : bp->chip_rev = resp->chip_rev;
1646 : :
1647 : 0 : if ((dev_caps_cfg &
1648 [ # # ]: 0 : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1649 : : (dev_caps_cfg &
1650 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
1651 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Short command supported");
1652 : 0 : bp->flags |= BNXT_FLAG_SHORT_CMD;
1653 : : }
1654 : :
1655 [ # # ]: 0 : if (((dev_caps_cfg &
1656 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
1657 : : (dev_caps_cfg &
1658 : 0 : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
1659 [ # # ]: 0 : bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
1660 : 0 : snprintf(type, sizeof(type), "bnxt_hwrm_short_" PCI_PRI_FMT,
1661 : 0 : bp->pdev->addr.domain, bp->pdev->addr.bus,
1662 : 0 : bp->pdev->addr.devid, bp->pdev->addr.function);
1663 : 0 : rte_free(bp->hwrm_short_cmd_req_addr);
1664 : :
1665 : 0 : bp->hwrm_short_cmd_req_addr =
1666 : 0 : rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
1667 [ # # ]: 0 : if (bp->hwrm_short_cmd_req_addr == NULL) {
1668 : : rc = -ENOMEM;
1669 : 0 : goto error;
1670 : : }
1671 : 0 : bp->hwrm_short_cmd_req_dma_addr =
1672 : 0 : rte_malloc_virt2iova(bp->hwrm_short_cmd_req_addr);
1673 [ # # ]: 0 : if (bp->hwrm_short_cmd_req_dma_addr == RTE_BAD_IOVA) {
1674 : 0 : rte_free(bp->hwrm_short_cmd_req_addr);
1675 : 0 : PMD_DRV_LOG_LINE(ERR,
1676 : : "Unable to map buffer to physical memory.");
1677 : : rc = -ENOMEM;
1678 : 0 : goto error;
1679 : : }
1680 : : }
1681 [ # # ]: 0 : if (dev_caps_cfg &
1682 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
1683 : 0 : bp->flags |= BNXT_FLAG_KONG_MB_EN;
1684 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Kong mailbox channel enabled");
1685 : : }
1686 [ # # ]: 0 : if (dev_caps_cfg &
1687 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_TRUSTED_VF_SUPPORTED)
1688 : 0 : PMD_DRV_LOG_LINE(DEBUG, "FW supports Trusted VFs");
1689 [ # # ]: 0 : if (dev_caps_cfg &
1690 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_ADV_FLOW_MGNT_SUPPORTED) {
1691 : 0 : bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_MGMT;
1692 : 0 : PMD_DRV_LOG_LINE(DEBUG, "FW supports advanced flow management");
1693 : : }
1694 : :
1695 [ # # ]: 0 : if (dev_caps_cfg &
1696 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_ADV_FLOW_COUNTERS_SUPPORTED) {
1697 : 0 : PMD_DRV_LOG_LINE(DEBUG, "FW supports advanced flow counters");
1698 : 0 : bp->fw_cap |= BNXT_FW_CAP_ADV_FLOW_COUNTERS;
1699 : : }
1700 : :
1701 [ # # ]: 0 : if (dev_caps_cfg &
1702 : : HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_CFA_TRUFLOW_SUPPORTED) {
1703 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Host-based truflow feature supported.");
1704 : 0 : bp->fw_cap |= BNXT_FW_CAP_TRUFLOW_EN;
1705 : : }
1706 : :
1707 : 0 : error:
1708 : : HWRM_UNLOCK();
1709 : 0 : return rc;
1710 : : }
1711 : :
1712 : 0 : int bnxt_hwrm_func_driver_unregister(struct bnxt *bp)
1713 : : {
1714 : : int rc;
1715 : 0 : struct hwrm_func_drv_unrgtr_input req = {.req_type = 0 };
1716 : 0 : struct hwrm_func_drv_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
1717 : :
1718 [ # # ]: 0 : if (!(bp->flags & BNXT_FLAG_REGISTERED))
1719 : : return 0;
1720 : :
1721 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_DRV_UNRGTR, BNXT_USE_CHIMP_MB);
1722 : :
1723 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1724 : :
1725 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1726 : : HWRM_UNLOCK();
1727 : :
1728 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Port %u: Unregistered with fw",
1729 : : bp->eth_dev->data->port_id);
1730 : :
1731 : 0 : return rc;
1732 : : }
1733 : :
1734 : 0 : static int bnxt_hwrm_port_phy_cfg(struct bnxt *bp, struct bnxt_link_info *conf)
1735 : : {
1736 : : int rc = 0;
1737 : 0 : struct hwrm_port_phy_cfg_input req = {0};
1738 : 0 : struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
1739 : : uint32_t enables = 0;
1740 : :
1741 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
1742 : :
1743 [ # # ]: 0 : if (conf->link_up) {
1744 : : /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
1745 [ # # # # ]: 0 : if (bp->link_info->auto_mode && conf->link_speed) {
1746 : 0 : req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
1747 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Disabling AutoNeg");
1748 : : }
1749 : :
1750 : 0 : req.flags = rte_cpu_to_le_32(conf->phy_flags);
1751 : : /*
1752 : : * Note, ChiMP FW 20.2.1 and 20.2.2 return an error when we set
1753 : : * any auto mode, even "none".
1754 : : */
1755 [ # # ]: 0 : if (!conf->link_speed) {
1756 : : /* No speeds specified. Enable AutoNeg - all speeds */
1757 : : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
1758 : 0 : req.auto_mode =
1759 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_ALL_SPEEDS;
1760 : : } else {
1761 [ # # ]: 0 : if (bp->link_info->link_signal_mode) {
1762 : : enables |=
1763 : : HWRM_PORT_PHY_CFG_IN_EN_FORCE_PAM4_LINK_SPEED;
1764 : 0 : req.force_pam4_link_speed =
1765 : : rte_cpu_to_le_16(conf->link_speed);
1766 : : } else {
1767 : 0 : req.force_link_speed =
1768 : : rte_cpu_to_le_16(conf->link_speed);
1769 : : }
1770 : : }
1771 : : /* AutoNeg - Advertise speeds specified. */
1772 [ # # # # ]: 0 : if ((conf->auto_link_speed_mask || conf->auto_pam4_link_speed_mask) &&
1773 [ # # ]: 0 : !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE)) {
1774 : 0 : req.auto_mode =
1775 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
1776 [ # # ]: 0 : if (conf->auto_pam4_link_speed_mask) {
1777 : 0 : enables |=
1778 : : HWRM_PORT_PHY_CFG_IN_EN_AUTO_PAM4_LINK_SPD_MASK;
1779 : 0 : req.auto_link_pam4_speed_mask =
1780 : : rte_cpu_to_le_16(conf->auto_pam4_link_speed_mask);
1781 : : }
1782 [ # # ]: 0 : if (conf->auto_link_speed_mask) {
1783 : 0 : enables |=
1784 : : HWRM_PORT_PHY_CFG_IN_EN_AUTO_LINK_SPEED_MASK;
1785 : 0 : req.auto_link_speed_mask =
1786 : : rte_cpu_to_le_16(conf->auto_link_speed_mask);
1787 : : }
1788 : : }
1789 [ # # ]: 0 : if (conf->auto_link_speed &&
1790 [ # # ]: 0 : !(conf->phy_flags & HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE))
1791 : 0 : enables |=
1792 : : HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEED;
1793 : :
1794 : 0 : req.auto_duplex = conf->duplex;
1795 : : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
1796 : 0 : req.auto_pause = conf->auto_pause;
1797 : 0 : req.force_pause = conf->force_pause;
1798 : : /* Set force_pause if there is no auto or if there is a force */
1799 [ # # # # ]: 0 : if (req.auto_pause && !req.force_pause)
1800 : 0 : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
1801 : : else
1802 : 0 : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
1803 : :
1804 : 0 : req.enables = rte_cpu_to_le_32(enables);
1805 : : } else {
1806 : 0 : req.flags =
1807 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
1808 : 0 : PMD_DRV_LOG_LINE(INFO, "Force Link Down");
1809 : : }
1810 : :
1811 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1812 : :
1813 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1814 : : HWRM_UNLOCK();
1815 : :
1816 : 0 : return rc;
1817 : : }
1818 : :
1819 : 0 : static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
1820 : : struct bnxt_link_info *link_info)
1821 : : {
1822 : : int rc = 0;
1823 : 0 : struct hwrm_port_phy_qcfg_input req = {0};
1824 : 0 : struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
1825 : :
1826 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_QCFG, BNXT_USE_CHIMP_MB);
1827 : :
1828 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1829 : :
1830 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
1831 : :
1832 : 0 : link_info->phy_link_status = resp->link;
1833 : 0 : link_info->link_up =
1834 : : (link_info->phy_link_status ==
1835 : 0 : HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) ? 1 : 0;
1836 : 0 : link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
1837 : 0 : link_info->duplex = resp->duplex_cfg;
1838 : 0 : link_info->pause = resp->pause;
1839 : 0 : link_info->auto_pause = resp->auto_pause;
1840 : 0 : link_info->force_pause = resp->force_pause;
1841 : 0 : link_info->auto_mode = resp->auto_mode;
1842 : :
1843 [ # # ]: 0 : if (link_info->auto_mode != HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE) {
1844 : 0 : link_info->autoneg = BNXT_AUTONEG_SPEED;
1845 [ # # ]: 0 : if (bp->hwrm_spec_code >= HWRM_SPEC_CODE_AUTONEG_PAUSE) {
1846 [ # # ]: 0 : if (link_info->auto_pause &
1847 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_AUTONEG_PAUSE)
1848 : 0 : link_info->autoneg |=
1849 : : BNXT_AUTONEG_FLOW_CTRL;
1850 : : } else {
1851 : : /* Firmware < HWRM_SPEC_CODE_AUTONEG_PAUSE does not
1852 : : * expose the AUTONEG_PAUSE bit. Infer flow-ctrl
1853 : : * autoneg from any non-zero auto_pause configuration.
1854 : : */
1855 [ # # ]: 0 : if (link_info->auto_pause)
1856 : 0 : link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1857 : : }
1858 : : } else {
1859 : 0 : link_info->autoneg = 0;
1860 : : }
1861 : :
1862 : 0 : link_info->phy_type = resp->phy_type;
1863 : 0 : link_info->media_type = resp->media_type;
1864 : :
1865 : 0 : link_info->support_speeds = rte_le_to_cpu_16(resp->support_speeds);
1866 : 0 : link_info->auto_link_speed = rte_le_to_cpu_16(resp->auto_link_speed);
1867 : 0 : link_info->auto_link_speed_mask = rte_le_to_cpu_16(resp->auto_link_speed_mask);
1868 : 0 : link_info->preemphasis = rte_le_to_cpu_32(resp->preemphasis);
1869 : 0 : link_info->force_link_speed = rte_le_to_cpu_16(resp->force_link_speed);
1870 : 0 : link_info->phy_ver[0] = resp->phy_maj;
1871 : 0 : link_info->phy_ver[1] = resp->phy_min;
1872 : 0 : link_info->phy_ver[2] = resp->phy_bld;
1873 : 0 : link_info->link_signal_mode =
1874 : 0 : resp->active_fec_signal_mode & HWRM_PORT_PHY_QCFG_OUTPUT_SIGNAL_MODE_MASK;
1875 : 0 : link_info->option_flags = resp->option_flags;
1876 : 0 : link_info->force_pam4_link_speed =
1877 : 0 : rte_le_to_cpu_16(resp->force_pam4_link_speed);
1878 : 0 : link_info->support_pam4_speeds =
1879 : 0 : rte_le_to_cpu_16(resp->support_pam4_speeds);
1880 : 0 : link_info->auto_pam4_link_speed_mask =
1881 : 0 : rte_le_to_cpu_16(resp->auto_pam4_link_speed_mask);
1882 : : /* P7 uses speeds2 fields */
1883 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp) && BNXT_LINK_SPEEDS_V2_OPTIONS(link_info->option_flags)) {
# # # # #
# ]
1884 : 0 : link_info->support_speeds2 = rte_le_to_cpu_16(resp->support_speeds2);
1885 : 0 : link_info->force_link_speeds2 = rte_le_to_cpu_16(resp->force_link_speeds2);
1886 : 0 : link_info->auto_link_speeds2 = rte_le_to_cpu_16(resp->auto_link_speeds2);
1887 : 0 : link_info->active_lanes = resp->active_lanes;
1888 [ # # ]: 0 : if (!link_info->auto_mode)
1889 : 0 : link_info->link_speed = link_info->force_link_speeds2;
1890 : : }
1891 : 0 : link_info->module_status = resp->module_status;
1892 : : HWRM_UNLOCK();
1893 : :
1894 : : /* Display the captured P7 phy details */
1895 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp)) {
# # # # ]
1896 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Phytype:%d, Media_type:%d, Status: %d, Link Signal:%d",
1897 : : link_info->phy_type,
1898 : : link_info->media_type,
1899 : : link_info->phy_link_status,
1900 : : link_info->link_signal_mode);
1901 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Active Fec: %d Support_speeds2:%x, Force_link_speedsv2:%x",
1902 : : (resp->active_fec_signal_mode &
1903 : : HWRM_PORT_PHY_QCFG_OUTPUT_ACTIVE_FEC_MASK) >> 4,
1904 : : link_info->support_speeds2, link_info->force_link_speeds2);
1905 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Auto_link_speedsv2:%x, Active_lanes:%d",
1906 : : link_info->auto_link_speeds2,
1907 : : link_info->active_lanes);
1908 : :
1909 : : const char *desc;
1910 : :
1911 [ # # ]: 0 : if (link_info->auto_mode)
1912 : 0 : desc = ((struct link_speeds_tbl *)
1913 : 0 : bnxt_get_hwrm_to_rte_speeds_entry(link_info->link_speed))->desc;
1914 : : else
1915 : 0 : desc = ((struct link_speeds2_tbl *)
1916 : 0 : bnxt_get_hwrm_to_rte_speeds2_entry(link_info->link_speed))->desc;
1917 : :
1918 [ # # ]: 0 : PMD_DRV_LOG_LINE(INFO, "Link Speed: %s %s, Status: %s Signal-mode: %s",
1919 : : desc,
1920 : : !(link_info->auto_mode) ? "Forced" : "AutoNegotiated",
1921 : : link_status_str[link_info->phy_link_status % MAX_LINK_STR],
1922 : : signal_mode[link_info->link_signal_mode % MAX_SIG_MODE]);
1923 [ # # # # : 0 : PMD_DRV_LOG_LINE(INFO, "Media type: %s, Xcvr type: %s, Active FEC: %s Lanes: %d",
# # # # ]
1924 : : media_type[link_info->media_type % MAX_MEDIA_TYPE],
1925 : : bnxt_get_xcvr_type(rte_le_to_cpu_32
1926 : : (resp->xcvr_identifier_type_tx_lpi_timer)),
1927 : : fec_mode[((resp->active_fec_signal_mode &
1928 : : HWRM_PORT_PHY_QCFG_OUTPUT_ACTIVE_FEC_MASK) >> 4) %
1929 : : MAX_FEC_MODE], link_info->active_lanes);
1930 : 0 : return rc;
1931 : : }
1932 : :
1933 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Link Speed:%d,Auto:%d:%x:%x,Support:%x,Force:%x",
1934 : : link_info->link_speed, link_info->auto_mode,
1935 : : link_info->auto_link_speed, link_info->auto_link_speed_mask,
1936 : : link_info->support_speeds, link_info->force_link_speed);
1937 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Link Signal:%d,PAM::Auto:%x,Support:%x,Force:%x",
1938 : : link_info->link_signal_mode,
1939 : : link_info->auto_pam4_link_speed_mask,
1940 : : link_info->support_pam4_speeds,
1941 : : link_info->force_pam4_link_speed);
1942 : 0 : return rc;
1943 : : }
1944 : :
1945 : 0 : int bnxt_hwrm_port_phy_qcaps(struct bnxt *bp)
1946 : : {
1947 : : int rc = 0;
1948 : 0 : struct hwrm_port_phy_qcaps_input req = {0};
1949 : 0 : struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
1950 : 0 : struct bnxt_link_info *link_info = bp->link_info;
1951 : :
1952 [ # # ]: 0 : if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
1953 : : return 0;
1954 : :
1955 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_QCAPS, BNXT_USE_CHIMP_MB);
1956 : :
1957 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
1958 : :
1959 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
1960 : :
1961 : 0 : bp->port_cnt = resp->port_cnt;
1962 [ # # ]: 0 : if (resp->supported_speeds_auto_mode)
1963 : 0 : link_info->support_auto_speeds =
1964 : : rte_le_to_cpu_16(resp->supported_speeds_auto_mode);
1965 [ # # ]: 0 : if (resp->supported_pam4_speeds_auto_mode)
1966 : 0 : link_info->support_pam4_auto_speeds =
1967 : : rte_le_to_cpu_16(resp->supported_pam4_speeds_auto_mode);
1968 : : /* P7 chips now report all speeds here */
1969 [ # # ]: 0 : if (resp->flags2 & HWRM_PORT_PHY_QCAPS_OUTPUT_FLAGS2_SPEEDS2_SUPPORTED)
1970 : 0 : link_info->support_speeds_v2 = true;
1971 [ # # ]: 0 : if (link_info->support_speeds_v2) {
1972 : 0 : link_info->supported_speeds2_force_mode =
1973 : 0 : rte_le_to_cpu_16(resp->supported_speeds2_force_mode);
1974 : 0 : link_info->supported_speeds2_auto_mode =
1975 : 0 : rte_le_to_cpu_16(resp->supported_speeds2_auto_mode);
1976 : : }
1977 : :
1978 : : HWRM_UNLOCK();
1979 : :
1980 : : /* Older firmware does not have supported_auto_speeds, so assume
1981 : : * that all supported speeds can be autonegotiated.
1982 : : */
1983 [ # # # # ]: 0 : if (link_info->auto_link_speed_mask && !link_info->support_auto_speeds)
1984 : 0 : link_info->support_auto_speeds = link_info->support_speeds;
1985 : :
1986 : : return 0;
1987 : : }
1988 : :
1989 : : static bool _bnxt_find_lossy_profile(struct bnxt *bp)
1990 : : {
1991 : : int i = 0;
1992 : :
1993 [ # # ]: 0 : for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
1994 [ # # ]: 0 : if (bp->tx_cos_queue[i].profile ==
1995 : : HWRM_QUEUE_SERVICE_PROFILE_LOSSY) {
1996 : 0 : bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
1997 : 0 : return true;
1998 : : }
1999 : : }
2000 : : return false;
2001 : : }
2002 : :
2003 : 0 : static bool _bnxt_find_lossy_nic_profile(struct bnxt *bp)
2004 : : {
2005 : : int i = 0, j = 0;
2006 : :
2007 [ # # ]: 0 : for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
2008 [ # # ]: 0 : for (j = 0; j < BNXT_COS_QUEUE_COUNT; j++) {
2009 [ # # ]: 0 : if (bp->tx_cos_queue[i].profile ==
2010 : 0 : HWRM_QUEUE_SERVICE_PROFILE_LOSSY &&
2011 [ # # ]: 0 : bp->tx_cos_queue[j].profile_type ==
2012 : : HWRM_QUEUE_SERVICE_PROFILE_TYPE_NIC) {
2013 : 0 : bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
2014 : 0 : return true;
2015 : : }
2016 : : }
2017 : : }
2018 : : return false;
2019 : : }
2020 : :
2021 : 0 : static bool bnxt_find_lossy_profile(struct bnxt *bp, bool use_prof_type)
2022 : : {
2023 : : int i;
2024 : :
2025 [ # # ]: 0 : for (i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
2026 : 0 : PMD_DRV_LOG_LINE(DEBUG, "profile %d, profile_id %d, type %d",
2027 : : bp->tx_cos_queue[i].profile,
2028 : : bp->tx_cos_queue[i].id,
2029 : : bp->tx_cos_queue[i].profile_type);
2030 : : }
2031 : :
2032 [ # # ]: 0 : if (use_prof_type)
2033 : 0 : return _bnxt_find_lossy_nic_profile(bp);
2034 : : else
2035 : 0 : return _bnxt_find_lossy_profile(bp);
2036 : : }
2037 : :
2038 : : static void bnxt_find_first_valid_profile(struct bnxt *bp)
2039 : : {
2040 : : int i = 0;
2041 : :
2042 [ # # ]: 0 : for (i = BNXT_COS_QUEUE_COUNT - 1; i >= 0; i--) {
2043 [ # # ]: 0 : if (bp->tx_cos_queue[i].profile !=
2044 : 0 : HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN &&
2045 [ # # ]: 0 : bp->tx_cos_queue[i].id !=
2046 : : HWRM_QUEUE_SERVICE_PROFILE_UNKNOWN) {
2047 : 0 : bp->tx_cosq_id[0] = bp->tx_cos_queue[i].id;
2048 : 0 : break;
2049 : : }
2050 : : }
2051 : : }
2052 : :
2053 : 0 : int bnxt_hwrm_queue_qportcfg(struct bnxt *bp)
2054 : : {
2055 : : int rc = 0;
2056 : 0 : struct hwrm_queue_qportcfg_input req = {.req_type = 0 };
2057 : 0 : struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr;
2058 : : uint32_t dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX;
2059 : : bool use_prof_type = false;
2060 : : int i;
2061 : :
2062 : 0 : get_rx_info:
2063 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_QUEUE_QPORTCFG, BNXT_USE_CHIMP_MB);
2064 : :
2065 : 0 : req.flags = rte_cpu_to_le_32(dir);
2066 : : /* HWRM Version >= 1.9.1 only if COS Classification is not required. */
2067 [ # # ]: 0 : if (bp->hwrm_spec_code >= HWRM_VERSION_1_9_1 &&
2068 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
2069 : 0 : req.drv_qmap_cap =
2070 : : HWRM_QUEUE_QPORTCFG_INPUT_DRV_QMAP_CAP_ENABLED;
2071 : :
2072 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2073 : :
2074 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2075 : :
2076 [ # # ]: 0 : if (resp->queue_cfg_info &
2077 : : HWRM_QUEUE_QPORTCFG_OUTPUT_QUEUE_CFG_INFO_USE_PROFILE_TYPE)
2078 : : use_prof_type = true;
2079 : :
2080 [ # # ]: 0 : if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
2081 : 0 : GET_TX_QUEUE_INFO(0);
2082 : 0 : GET_TX_QUEUE_INFO(1);
2083 : 0 : GET_TX_QUEUE_INFO(2);
2084 : 0 : GET_TX_QUEUE_INFO(3);
2085 : 0 : GET_TX_QUEUE_INFO(4);
2086 : 0 : GET_TX_QUEUE_INFO(5);
2087 : 0 : GET_TX_QUEUE_INFO(6);
2088 : 0 : GET_TX_QUEUE_INFO(7);
2089 [ # # ]: 0 : if (use_prof_type) {
2090 : 0 : GET_TX_QUEUE_TYPE_INFO(0);
2091 : 0 : GET_TX_QUEUE_TYPE_INFO(1);
2092 : 0 : GET_TX_QUEUE_TYPE_INFO(2);
2093 : 0 : GET_TX_QUEUE_TYPE_INFO(3);
2094 : 0 : GET_TX_QUEUE_TYPE_INFO(4);
2095 : 0 : GET_TX_QUEUE_TYPE_INFO(5);
2096 : 0 : GET_TX_QUEUE_TYPE_INFO(6);
2097 : 0 : GET_TX_QUEUE_TYPE_INFO(7);
2098 : : }
2099 : : } else {
2100 : 0 : GET_RX_QUEUE_INFO(0);
2101 : 0 : GET_RX_QUEUE_INFO(1);
2102 : 0 : GET_RX_QUEUE_INFO(2);
2103 : 0 : GET_RX_QUEUE_INFO(3);
2104 : 0 : GET_RX_QUEUE_INFO(4);
2105 : 0 : GET_RX_QUEUE_INFO(5);
2106 : 0 : GET_RX_QUEUE_INFO(6);
2107 : 0 : GET_RX_QUEUE_INFO(7);
2108 : : }
2109 : :
2110 : : HWRM_UNLOCK();
2111 : :
2112 [ # # ]: 0 : if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX)
2113 : 0 : goto done;
2114 : :
2115 [ # # ]: 0 : if (bp->hwrm_spec_code < HWRM_VERSION_1_9_1) {
2116 : 0 : bp->tx_cosq_id[0] = bp->tx_cos_queue[0].id;
2117 : : } else {
2118 : : int j;
2119 : :
2120 : : /* iterate and find the COSq profile to use for Tx */
2121 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
2122 [ # # ]: 0 : for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
2123 [ # # ]: 0 : if (bp->tx_cos_queue[i].id != 0xff)
2124 : 0 : bp->tx_cosq_id[j++] =
2125 : : bp->tx_cos_queue[i].id;
2126 : : }
2127 : : } else {
2128 : : /* When CoS classification is disabled, for normal NIC
2129 : : * operations, ideally we should look to use LOSSY.
2130 : : * If not found, fallback to the first valid profile
2131 : : */
2132 [ # # ]: 0 : if (!bnxt_find_lossy_profile(bp, use_prof_type))
2133 : : bnxt_find_first_valid_profile(bp);
2134 : :
2135 : : }
2136 : : }
2137 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tx COS Queue ID %d", bp->tx_cosq_id[0]);
2138 : :
2139 : 0 : bp->max_tc = resp->max_configurable_queues;
2140 : 0 : bp->max_lltc = resp->max_configurable_lossless_queues;
2141 [ # # ]: 0 : if (bp->max_tc > BNXT_MAX_QUEUE)
2142 : 0 : bp->max_tc = BNXT_MAX_QUEUE;
2143 : 0 : bp->max_q = bp->max_tc;
2144 : :
2145 : : if (dir == HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_TX) {
2146 : : dir = HWRM_QUEUE_QPORTCFG_INPUT_FLAGS_PATH_RX;
2147 : 0 : goto get_rx_info;
2148 : : }
2149 : :
2150 : : done:
2151 : 0 : return rc;
2152 : : }
2153 : :
2154 : : static const uint8_t
2155 : : mpc_chnl_types[] = {HWRM_RING_ALLOC_INPUT_MPC_CHNLS_TYPE_TCE,
2156 : : HWRM_RING_ALLOC_INPUT_MPC_CHNLS_TYPE_RCE,
2157 : : HWRM_RING_ALLOC_INPUT_MPC_CHNLS_TYPE_TE_CFA,
2158 : : HWRM_RING_ALLOC_INPUT_MPC_CHNLS_TYPE_RE_CFA,
2159 : : HWRM_RING_ALLOC_INPUT_MPC_CHNLS_TYPE_PRIMATE};
2160 : :
2161 : 0 : int bnxt_hwrm_ring_alloc(struct bnxt *bp,
2162 : : struct bnxt_ring *ring,
2163 : : uint32_t ring_type, uint32_t map_index,
2164 : : uint32_t stats_ctx_id, uint32_t cmpl_ring_id,
2165 : : uint16_t tx_cosq_id, uint16_t dpi)
2166 : : {
2167 : : int rc = 0;
2168 : : uint32_t enables = 0;
2169 : 0 : struct hwrm_ring_alloc_input req = {.req_type = 0 };
2170 : 0 : struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2171 : : struct rte_mempool *mb_pool;
2172 : : uint16_t rx_buf_size;
2173 : :
2174 [ # # # # : 0 : HWRM_PREP(&req, HWRM_RING_ALLOC, BNXT_USE_CHIMP_MB);
# # # # ]
2175 : :
2176 : 0 : req.page_tbl_addr = rte_cpu_to_le_64(ring->bd_dma);
2177 : 0 : req.fbo = rte_cpu_to_le_32(0);
2178 : : /* Association of ring index with doorbell index */
2179 : 0 : req.logical_id = rte_cpu_to_le_16(map_index);
2180 : 0 : req.length = rte_cpu_to_le_32(ring->ring_size);
2181 : :
2182 [ # # # # : 0 : switch (ring_type) {
# # ]
2183 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
2184 : 0 : req.ring_type = ring_type;
2185 : 0 : req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
2186 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
2187 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_TX_COAL_CMPL)
2188 : 0 : req.cmpl_coal_cnt =
2189 : : HWRM_RING_ALLOC_INPUT_CMPL_COAL_CNT_COAL_OFF;
2190 [ # # ]: 0 : if (tx_cosq_id != MPC_HW_COS_ID) {
2191 : 0 : req.queue_id = rte_cpu_to_le_16(tx_cosq_id);
2192 : : } else {
2193 : 0 : uint32_t mpc_chnl = BNXT_MPC_CHNL(map_index);
2194 : :
2195 : : req.logical_id =
2196 : : rte_cpu_to_le_16(BNXT_MPC_QIDX(map_index));
2197 [ # # ]: 0 : if (mpc_chnl >= BNXT_MPC_CHNL_MAX)
2198 : : return -EINVAL;
2199 : : enables |= HWRM_RING_ALLOC_INPUT_ENABLES_MPC_CHNLS_TYPE;
2200 : 0 : req.mpc_chnls_type = mpc_chnl_types[mpc_chnl];
2201 : : }
2202 [ # # ]: 0 : if (stats_ctx_id != INVALID_STATS_CTX_ID)
2203 : 0 : enables |=
2204 : : HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
2205 [ # # # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_TX_TS_CMP && bp->ptp_cfg)
2206 : 0 : req.flags =
2207 : : rte_cpu_to_le_16(HWRM_RING_ALLOC_INPUT_FLAGS_TX_PKT_TS_CMPL_ENABLE);
2208 : : break;
2209 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
2210 : 0 : req.ring_type = ring_type;
2211 : 0 : req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
2212 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
2213 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
2214 : 0 : mb_pool = bp->rx_queues[0]->mb_pool;
2215 : 0 : rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
2216 : : RTE_PKTMBUF_HEADROOM;
2217 : 0 : rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
2218 : 0 : req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
2219 : : enables |=
2220 : : HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID;
2221 : : }
2222 [ # # ]: 0 : if (stats_ctx_id != INVALID_STATS_CTX_ID)
2223 : 0 : enables |=
2224 : : HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
2225 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_RX_RATE_PROFILE) {
2226 : 0 : req.rx_rate_profile_sel =
2227 : : HWRM_RING_ALLOC_INPUT_RX_RATE_PROFILE_SEL_POLL_MODE;
2228 : 0 : enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RATE_PROFILE_VALID;
2229 : : }
2230 : : break;
2231 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
2232 : 0 : req.ring_type = ring_type;
2233 [ # # ]: 0 : if (BNXT_HAS_NQ(bp)) {
2234 : : /* Association of cp ring with nq */
2235 : 0 : req.nq_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
2236 : : enables |=
2237 : : HWRM_RING_ALLOC_INPUT_ENABLES_NQ_RING_ID_VALID;
2238 : : }
2239 : 0 : req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
2240 : 0 : break;
2241 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
2242 : 0 : req.ring_type = ring_type;
2243 : 0 : req.page_size = BNXT_PAGE_SHFT;
2244 : 0 : req.int_mode = HWRM_RING_ALLOC_INPUT_INT_MODE_MSIX;
2245 : 0 : break;
2246 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
2247 : 0 : req.ring_type = ring_type;
2248 : 0 : req.rx_ring_id = rte_cpu_to_le_16(ring->fw_rx_ring_id);
2249 : :
2250 [ # # ]: 0 : mb_pool = bp->rx_queues[0]->mb_pool;
2251 : 0 : rx_buf_size = rte_pktmbuf_data_room_size(mb_pool) -
2252 : : RTE_PKTMBUF_HEADROOM;
2253 : 0 : rx_buf_size = RTE_MIN(BNXT_MAX_PKT_LEN, rx_buf_size);
2254 : 0 : req.rx_buf_size = rte_cpu_to_le_16(rx_buf_size);
2255 : :
2256 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
2257 : : enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RING_ID_VALID |
2258 : : HWRM_RING_ALLOC_INPUT_ENABLES_RX_BUF_SIZE_VALID |
2259 : : HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
2260 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_RX_RATE_PROFILE) {
2261 : 0 : req.rx_rate_profile_sel =
2262 : : HWRM_RING_ALLOC_INPUT_RX_RATE_PROFILE_SEL_POLL_MODE;
2263 : : enables |= HWRM_RING_ALLOC_INPUT_ENABLES_RX_RATE_PROFILE_VALID;
2264 : : }
2265 : : break;
2266 : 0 : default:
2267 : 0 : PMD_DRV_LOG_LINE(ERR, "hwrm alloc invalid ring type %d",
2268 : : ring_type);
2269 : : HWRM_UNLOCK();
2270 : 0 : return -EINVAL;
2271 : : }
2272 : :
2273 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_MULTI_DB) {
2274 : 0 : req.dpi = rte_cpu_to_le_16(dpi);
2275 : 0 : enables |= HWRM_RING_ALLOC_INPUT_ENABLES_DPI_VALID;
2276 : : }
2277 : 0 : req.enables = rte_cpu_to_le_32(enables);
2278 : :
2279 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2280 : :
2281 [ # # # # ]: 0 : if (rc || resp->error_code) {
2282 [ # # # # ]: 0 : if (rc == 0 && resp->error_code)
2283 : 0 : rc = rte_le_to_cpu_16(resp->error_code);
2284 [ # # # # : 0 : switch (ring_type) {
# # ]
2285 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
2286 : 0 : PMD_DRV_LOG_LINE(ERR,
2287 : : "hwrm_ring_alloc cp failed. rc:%d", rc);
2288 : : HWRM_UNLOCK();
2289 : 0 : return rc;
2290 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
2291 : 0 : PMD_DRV_LOG_LINE(ERR,
2292 : : "hwrm_ring_alloc rx failed. rc:%d", rc);
2293 : : HWRM_UNLOCK();
2294 : 0 : return rc;
2295 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX_AGG:
2296 : 0 : PMD_DRV_LOG_LINE(ERR,
2297 : : "hwrm_ring_alloc rx agg failed. rc:%d",
2298 : : rc);
2299 : : HWRM_UNLOCK();
2300 : 0 : return rc;
2301 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
2302 : 0 : PMD_DRV_LOG_LINE(ERR,
2303 : : "hwrm_ring_alloc tx failed. rc:%d", rc);
2304 : : HWRM_UNLOCK();
2305 : 0 : return rc;
2306 : 0 : case HWRM_RING_ALLOC_INPUT_RING_TYPE_NQ:
2307 : 0 : PMD_DRV_LOG_LINE(ERR,
2308 : : "hwrm_ring_alloc nq failed. rc:%d", rc);
2309 : : HWRM_UNLOCK();
2310 : 0 : return rc;
2311 : 0 : default:
2312 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid ring. rc:%d", rc);
2313 : : HWRM_UNLOCK();
2314 : 0 : return rc;
2315 : : }
2316 : : }
2317 : :
2318 : 0 : ring->fw_ring_id = rte_le_to_cpu_16(resp->ring_id);
2319 : : HWRM_UNLOCK();
2320 : 0 : return rc;
2321 : : }
2322 : :
2323 : 0 : int bnxt_hwrm_ring_free(struct bnxt *bp,
2324 : : struct bnxt_ring *ring, uint32_t ring_type,
2325 : : uint16_t cp_ring_id)
2326 : : {
2327 : : int rc;
2328 : 0 : struct hwrm_ring_free_input req = {.req_type = 0 };
2329 : 0 : struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr;
2330 : :
2331 [ # # ]: 0 : if (ring->fw_ring_id == INVALID_HW_RING_ID)
2332 : : return -EINVAL;
2333 : :
2334 [ # # ]: 0 : HWRM_PREP(&req, HWRM_RING_FREE, BNXT_USE_CHIMP_MB);
2335 : :
2336 : 0 : req.ring_type = ring_type;
2337 : 0 : req.ring_id = rte_cpu_to_le_16(ring->fw_ring_id);
2338 : 0 : req.cmpl_ring = rte_cpu_to_le_16(cp_ring_id);
2339 : :
2340 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2341 : 0 : ring->fw_ring_id = INVALID_HW_RING_ID;
2342 : :
2343 [ # # # # ]: 0 : if (rc || resp->error_code) {
2344 [ # # # # ]: 0 : if (rc == 0 && resp->error_code)
2345 : 0 : rc = rte_le_to_cpu_16(resp->error_code);
2346 : : HWRM_UNLOCK();
2347 : :
2348 [ # # # # : 0 : switch (ring_type) {
# # ]
2349 : 0 : case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
2350 : 0 : PMD_DRV_LOG_LINE(ERR, "hwrm_ring_free cp failed. rc:%d",
2351 : : rc);
2352 : 0 : return rc;
2353 : 0 : case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
2354 : 0 : PMD_DRV_LOG_LINE(ERR, "hwrm_ring_free rx failed. rc:%d",
2355 : : rc);
2356 : 0 : return rc;
2357 : 0 : case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
2358 : 0 : PMD_DRV_LOG_LINE(ERR, "hwrm_ring_free tx failed. rc:%d",
2359 : : rc);
2360 : 0 : return rc;
2361 : 0 : case HWRM_RING_FREE_INPUT_RING_TYPE_NQ:
2362 : 0 : PMD_DRV_LOG_LINE(ERR,
2363 : : "hwrm_ring_free nq failed. rc:%d", rc);
2364 : 0 : return rc;
2365 : 0 : case HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG:
2366 : 0 : PMD_DRV_LOG_LINE(ERR,
2367 : : "hwrm_ring_free agg failed. rc:%d", rc);
2368 : 0 : return rc;
2369 : 0 : default:
2370 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid ring, rc:%d", rc);
2371 : 0 : return rc;
2372 : : }
2373 : : }
2374 : : HWRM_UNLOCK();
2375 : 0 : return 0;
2376 : : }
2377 : :
2378 : 0 : int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp, unsigned int idx)
2379 : : {
2380 : : int rc = 0;
2381 : 0 : struct hwrm_ring_grp_alloc_input req = {.req_type = 0 };
2382 : 0 : struct hwrm_ring_grp_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2383 : :
2384 : : /* Don't attempt to re-create the ring group if it is already created */
2385 [ # # ]: 0 : if (bp->grp_info[idx].fw_grp_id != INVALID_HW_RING_ID)
2386 : : return 0;
2387 : :
2388 [ # # ]: 0 : HWRM_PREP(&req, HWRM_RING_GRP_ALLOC, BNXT_USE_CHIMP_MB);
2389 : :
2390 : 0 : req.cr = rte_cpu_to_le_16(bp->grp_info[idx].cp_fw_ring_id);
2391 : 0 : req.rr = rte_cpu_to_le_16(bp->grp_info[idx].rx_fw_ring_id);
2392 : 0 : req.ar = rte_cpu_to_le_16(bp->grp_info[idx].ag_fw_ring_id);
2393 : 0 : req.sc = rte_cpu_to_le_16(bp->grp_info[idx].fw_stats_ctx);
2394 : :
2395 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2396 : :
2397 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2398 : :
2399 : 0 : bp->grp_info[idx].fw_grp_id = rte_le_to_cpu_16(resp->ring_group_id);
2400 : :
2401 : : HWRM_UNLOCK();
2402 : :
2403 : 0 : return rc;
2404 : : }
2405 : :
2406 : 0 : int bnxt_hwrm_ring_grp_free(struct bnxt *bp, unsigned int idx)
2407 : : {
2408 : : int rc;
2409 : 0 : struct hwrm_ring_grp_free_input req = {.req_type = 0 };
2410 : 0 : struct hwrm_ring_grp_free_output *resp = bp->hwrm_cmd_resp_addr;
2411 : :
2412 [ # # ]: 0 : if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
2413 : : return 0;
2414 : :
2415 [ # # ]: 0 : HWRM_PREP(&req, HWRM_RING_GRP_FREE, BNXT_USE_CHIMP_MB);
2416 : :
2417 : 0 : req.ring_group_id = rte_cpu_to_le_16(bp->grp_info[idx].fw_grp_id);
2418 : :
2419 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2420 : :
2421 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2422 : : HWRM_UNLOCK();
2423 : :
2424 : 0 : bp->grp_info[idx].fw_grp_id = INVALID_HW_RING_ID;
2425 : 0 : return rc;
2426 : : }
2427 : :
2428 : 0 : int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2429 : : {
2430 : : int rc = 0;
2431 : 0 : struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
2432 : 0 : struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
2433 : :
2434 [ # # ]: 0 : if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
2435 : : return rc;
2436 : :
2437 [ # # ]: 0 : HWRM_PREP(&req, HWRM_STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
2438 : :
2439 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
2440 : :
2441 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2442 : :
2443 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2444 : : HWRM_UNLOCK();
2445 : :
2446 : 0 : return rc;
2447 : : }
2448 : :
2449 : 0 : int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2450 : : {
2451 : : int rc;
2452 : 0 : struct hwrm_stat_ctx_alloc_input req = {.req_type = 0 };
2453 : 0 : struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2454 : :
2455 [ # # ]: 0 : if (cpr->hw_stats_ctx_id != HWRM_NA_SIGNATURE)
2456 : : return 0;
2457 : :
2458 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_STAT_CTX_ALLOC, BNXT_USE_CHIMP_MB);
2459 : :
2460 [ # # # # ]: 0 : req.stats_dma_length = rte_cpu_to_le_16(BNXT_HWRM_CTX_GET_SIZE(bp));
2461 : :
2462 : 0 : req.update_period_ms = rte_cpu_to_le_32(0);
2463 : :
2464 : 0 : req.stats_dma_addr = rte_cpu_to_le_64(cpr->hw_stats_map);
2465 : :
2466 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2467 : :
2468 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2469 : :
2470 : 0 : cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
2471 : :
2472 : : HWRM_UNLOCK();
2473 : :
2474 : 0 : return rc;
2475 : : }
2476 : :
2477 : 0 : int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
2478 : : {
2479 : : int rc;
2480 : 0 : struct hwrm_stat_ctx_free_input req = {.req_type = 0 };
2481 : 0 : struct hwrm_stat_ctx_free_output *resp = bp->hwrm_cmd_resp_addr;
2482 : :
2483 [ # # ]: 0 : if (cpr->hw_stats_ctx_id == HWRM_NA_SIGNATURE)
2484 : : return 0;
2485 : :
2486 [ # # ]: 0 : HWRM_PREP(&req, HWRM_STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
2487 : :
2488 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
2489 : :
2490 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2491 : :
2492 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2493 : : HWRM_UNLOCK();
2494 : :
2495 : 0 : cpr->hw_stats_ctx_id = HWRM_NA_SIGNATURE;
2496 : :
2497 : 0 : return rc;
2498 : : }
2499 : :
2500 : 0 : int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2501 : : {
2502 : : int rc = 0;
2503 : 0 : struct hwrm_vnic_alloc_input req = { 0 };
2504 : 0 : struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr;
2505 : :
2506 : 0 : vnic->mru = BNXT_VNIC_MRU(bp->eth_dev->data->mtu);
2507 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_ALLOC, BNXT_USE_CHIMP_MB);
2508 : :
2509 [ # # ]: 0 : if (vnic->func_default)
2510 : 0 : req.flags =
2511 : : rte_cpu_to_le_32(HWRM_VNIC_ALLOC_INPUT_FLAGS_DEFAULT);
2512 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2513 : :
2514 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2515 : :
2516 : 0 : vnic->fw_vnic_id = rte_le_to_cpu_16(resp->vnic_id);
2517 : : HWRM_UNLOCK();
2518 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC ID %x", vnic->fw_vnic_id);
2519 : 0 : return rc;
2520 : : }
2521 : :
2522 : 0 : static int bnxt_hwrm_vnic_plcmodes_qcfg(struct bnxt *bp,
2523 : : struct bnxt_vnic_info *vnic,
2524 : : struct bnxt_plcmodes_cfg *pmode)
2525 : : {
2526 : : int rc = 0;
2527 : 0 : struct hwrm_vnic_plcmodes_qcfg_input req = {.req_type = 0 };
2528 : 0 : struct hwrm_vnic_plcmodes_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2529 : :
2530 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_PLCMODES_QCFG, BNXT_USE_CHIMP_MB);
2531 : :
2532 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2533 : :
2534 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2535 : :
2536 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2537 : :
2538 : 0 : pmode->flags = rte_le_to_cpu_32(resp->flags);
2539 : : /* dflt_vnic bit doesn't exist in the _cfg command */
2540 : 0 : pmode->flags &= ~(HWRM_VNIC_PLCMODES_QCFG_OUTPUT_FLAGS_DFLT_VNIC);
2541 : 0 : pmode->jumbo_thresh = rte_le_to_cpu_16(resp->jumbo_thresh);
2542 : 0 : pmode->hds_offset = rte_le_to_cpu_16(resp->hds_offset);
2543 : 0 : pmode->hds_threshold = rte_le_to_cpu_16(resp->hds_threshold);
2544 : :
2545 : : HWRM_UNLOCK();
2546 : :
2547 : 0 : return rc;
2548 : : }
2549 : :
2550 : 0 : static int bnxt_hwrm_vnic_plcmodes_cfg(struct bnxt *bp,
2551 : : struct bnxt_vnic_info *vnic,
2552 : : struct bnxt_plcmodes_cfg *pmode)
2553 : : {
2554 : : int rc = 0;
2555 : 0 : struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
2556 : 0 : struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2557 : :
2558 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2559 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC ID %x", vnic->fw_vnic_id);
2560 : 0 : return rc;
2561 : : }
2562 : :
2563 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
2564 : :
2565 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2566 : 0 : req.flags = rte_cpu_to_le_32(pmode->flags);
2567 : 0 : req.jumbo_thresh = rte_cpu_to_le_16(pmode->jumbo_thresh);
2568 : 0 : req.hds_offset = rte_cpu_to_le_16(pmode->hds_offset);
2569 : 0 : req.hds_threshold = rte_cpu_to_le_16(pmode->hds_threshold);
2570 : 0 : req.enables = rte_cpu_to_le_32(
2571 : : HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID |
2572 : : HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_OFFSET_VALID |
2573 : : HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID
2574 : : );
2575 : :
2576 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2577 : :
2578 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2579 : : HWRM_UNLOCK();
2580 : :
2581 : 0 : return rc;
2582 : : }
2583 : :
2584 : 0 : int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2585 : : {
2586 : : int rc = 0;
2587 : 0 : struct hwrm_vnic_cfg_input req = {.req_type = 0 };
2588 : 0 : struct hwrm_vnic_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2589 : 0 : struct bnxt_plcmodes_cfg pmodes = { 0 };
2590 : : uint32_t ctx_enable_flag = 0;
2591 : : uint32_t enables = 0;
2592 : :
2593 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2594 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC ID %x", vnic->fw_vnic_id);
2595 : 0 : return rc;
2596 : : }
2597 : :
2598 : 0 : rc = bnxt_hwrm_vnic_plcmodes_qcfg(bp, vnic, &pmodes);
2599 [ # # ]: 0 : if (rc)
2600 : : return rc;
2601 : :
2602 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_CFG, BNXT_USE_CHIMP_MB);
2603 : :
2604 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
2605 : 0 : int dflt_rxq = vnic->start_grp_id;
2606 : : struct bnxt_rx_ring_info *rxr;
2607 : : struct bnxt_cp_ring_info *cpr;
2608 : : struct bnxt_rx_queue *rxq;
2609 : : int i;
2610 : :
2611 : : /*
2612 : : * The first active receive ring is used as the VNIC
2613 : : * default receive ring. If there are no active receive
2614 : : * rings (all corresponding receive queues are stopped),
2615 : : * the first receive ring is used.
2616 : : */
2617 [ # # ]: 0 : for (i = vnic->start_grp_id; i < vnic->end_grp_id; i++) {
2618 : 0 : rxq = bp->eth_dev->data->rx_queues[i];
2619 [ # # # # ]: 0 : if (rxq->rx_started &&
2620 : 0 : bnxt_vnic_queue_id_is_valid(vnic, i)) {
2621 : : dflt_rxq = i;
2622 : : break;
2623 : : }
2624 : : }
2625 : :
2626 : 0 : rxq = bp->eth_dev->data->rx_queues[dflt_rxq];
2627 : 0 : rxr = rxq->rx_ring;
2628 : 0 : cpr = rxq->cp_ring;
2629 : :
2630 : 0 : req.default_rx_ring_id =
2631 : 0 : rte_cpu_to_le_16(rxr->rx_ring_struct->fw_ring_id);
2632 : 0 : req.default_cmpl_ring_id =
2633 : 0 : rte_cpu_to_le_16(cpr->cp_ring_struct->fw_ring_id);
2634 : : enables = HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_RX_RING_ID |
2635 : : HWRM_VNIC_CFG_INPUT_ENABLES_DEFAULT_CMPL_RING_ID;
2636 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_RX_CMPL_V2) {
2637 : : enables |= HWRM_VNIC_CFG_INPUT_ENABLES_RX_CSUM_V2_MODE;
2638 : 0 : req.rx_csum_v2_mode =
2639 : : HWRM_VNIC_CFG_INPUT_RX_CSUM_V2_MODE_ALL_OK;
2640 : : }
2641 : 0 : goto config_mru;
2642 : : }
2643 : :
2644 : : /* Only RSS support for now TBD: COS & LB */
2645 : : enables = HWRM_VNIC_CFG_INPUT_ENABLES_DFLT_RING_GRP;
2646 [ # # ]: 0 : if (vnic->lb_rule != 0xffff)
2647 : : ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
2648 [ # # ]: 0 : if (vnic->cos_rule != 0xffff)
2649 : 0 : ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
2650 [ # # ]: 0 : if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
2651 : : ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
2652 : 0 : ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
2653 : : }
2654 [ # # ]: 0 : if (bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY) {
2655 : 0 : ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_QUEUE_ID;
2656 : 0 : req.queue_id = rte_cpu_to_le_16(vnic->cos_queue_id);
2657 : : }
2658 : :
2659 : 0 : enables |= ctx_enable_flag;
2660 : 0 : req.dflt_ring_grp = rte_cpu_to_le_16(vnic->dflt_ring_grp);
2661 : 0 : req.rss_rule = rte_cpu_to_le_16(vnic->rss_rule);
2662 : 0 : req.cos_rule = rte_cpu_to_le_16(vnic->cos_rule);
2663 : 0 : req.lb_rule = rte_cpu_to_le_16(vnic->lb_rule);
2664 : :
2665 [ # # ]: 0 : config_mru:
2666 : : if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
2667 : 0 : req.l2_cqe_mode = HWRM_VNIC_CFG_INPUT_L2_CQE_MODE_COMPRESSED;
2668 : 0 : enables |= HWRM_VNIC_CFG_INPUT_ENABLES_L2_CQE_MODE;
2669 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Enabling compressed Rx CQE");
2670 : : }
2671 : :
2672 : 0 : req.enables = rte_cpu_to_le_32(enables);
2673 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2674 : 0 : req.mru = rte_cpu_to_le_16(vnic->mru);
2675 : : /* Configure default VNIC only once. */
2676 [ # # # # ]: 0 : if (vnic->func_default && !(bp->flags & BNXT_FLAG_DFLT_VNIC_SET)) {
2677 : 0 : req.flags |=
2678 : : rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_DEFAULT);
2679 : 0 : bp->flags |= BNXT_FLAG_DFLT_VNIC_SET;
2680 : : }
2681 [ # # ]: 0 : if (vnic->vlan_strip)
2682 : 0 : req.flags |=
2683 : : rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_VLAN_STRIP_MODE);
2684 [ # # ]: 0 : if (vnic->bd_stall)
2685 : 0 : req.flags |=
2686 : : rte_cpu_to_le_32(HWRM_VNIC_CFG_INPUT_FLAGS_BD_STALL_MODE);
2687 [ # # ]: 0 : if (vnic->rss_dflt_cr)
2688 : 0 : req.flags |= rte_cpu_to_le_32(
2689 : : HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE);
2690 : :
2691 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2692 : :
2693 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2694 : : HWRM_UNLOCK();
2695 : :
2696 : 0 : rc = bnxt_hwrm_vnic_plcmodes_cfg(bp, vnic, &pmodes);
2697 : :
2698 : 0 : return rc;
2699 : : }
2700 : :
2701 : 0 : int bnxt_hwrm_vnic_qcfg(struct bnxt *bp, struct bnxt_vnic_info *vnic,
2702 : : int16_t fw_vf_id)
2703 : : {
2704 : : int rc = 0;
2705 : 0 : struct hwrm_vnic_qcfg_input req = {.req_type = 0 };
2706 : 0 : struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
2707 : :
2708 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2709 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC QCFG ID %d", vnic->fw_vnic_id);
2710 : 0 : return rc;
2711 : : }
2712 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_QCFG, BNXT_USE_CHIMP_MB);
2713 : :
2714 : 0 : req.enables =
2715 : : rte_cpu_to_le_32(HWRM_VNIC_QCFG_INPUT_ENABLES_VF_ID_VALID);
2716 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2717 : 0 : req.vf_id = rte_cpu_to_le_16(fw_vf_id);
2718 : :
2719 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2720 : :
2721 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2722 : :
2723 : 0 : vnic->dflt_ring_grp = rte_le_to_cpu_16(resp->dflt_ring_grp);
2724 : 0 : vnic->rss_rule = rte_le_to_cpu_16(resp->rss_rule);
2725 : 0 : vnic->cos_rule = rte_le_to_cpu_16(resp->cos_rule);
2726 : 0 : vnic->lb_rule = rte_le_to_cpu_16(resp->lb_rule);
2727 : 0 : vnic->mru = rte_le_to_cpu_16(resp->mru);
2728 : 0 : vnic->func_default = rte_le_to_cpu_32(
2729 : 0 : resp->flags) & HWRM_VNIC_QCFG_OUTPUT_FLAGS_DEFAULT;
2730 : 0 : vnic->vlan_strip = rte_le_to_cpu_32(resp->flags) &
2731 : : HWRM_VNIC_QCFG_OUTPUT_FLAGS_VLAN_STRIP_MODE;
2732 : 0 : vnic->bd_stall = rte_le_to_cpu_32(resp->flags) &
2733 : : HWRM_VNIC_QCFG_OUTPUT_FLAGS_BD_STALL_MODE;
2734 : 0 : vnic->rss_dflt_cr = rte_le_to_cpu_32(resp->flags) &
2735 : : HWRM_VNIC_QCFG_OUTPUT_FLAGS_RSS_DFLT_CR_MODE;
2736 : :
2737 : : HWRM_UNLOCK();
2738 : :
2739 : 0 : return rc;
2740 : : }
2741 : :
2742 : 0 : int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp,
2743 : : struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
2744 : : {
2745 : : int rc = 0;
2746 : : uint16_t ctx_id;
2747 : 0 : struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {.req_type = 0 };
2748 : 0 : struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp =
2749 : : bp->hwrm_cmd_resp_addr;
2750 : :
2751 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, BNXT_USE_CHIMP_MB);
2752 : :
2753 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2754 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2755 : :
2756 : 0 : ctx_id = rte_le_to_cpu_16(resp->rss_cos_lb_ctx_id);
2757 [ # # ]: 0 : if (!BNXT_HAS_RING_GRPS(bp))
2758 : 0 : vnic->fw_grp_ids[ctx_idx] = ctx_id;
2759 [ # # ]: 0 : else if (ctx_idx == 0)
2760 : 0 : vnic->rss_rule = ctx_id;
2761 : :
2762 : : HWRM_UNLOCK();
2763 : :
2764 : 0 : return rc;
2765 : : }
2766 : :
2767 : : static
2768 : 0 : int _bnxt_hwrm_vnic_ctx_free(struct bnxt *bp,
2769 : : struct bnxt_vnic_info *vnic, uint16_t ctx_idx)
2770 : : {
2771 : : int rc = 0;
2772 : 0 : struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {.req_type = 0 };
2773 : 0 : struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
2774 : : bp->hwrm_cmd_resp_addr;
2775 : :
2776 [ # # ]: 0 : if (ctx_idx == (uint16_t)HWRM_NA_SIGNATURE) {
2777 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC RSS Rule %x", vnic->rss_rule);
2778 : 0 : return rc;
2779 : : }
2780 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, BNXT_USE_CHIMP_MB);
2781 : :
2782 : 0 : req.rss_cos_lb_ctx_id = rte_cpu_to_le_16(ctx_idx);
2783 : :
2784 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2785 : :
2786 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2787 : : HWRM_UNLOCK();
2788 : :
2789 : 0 : return rc;
2790 : : }
2791 : :
2792 : 0 : int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2793 : : {
2794 : : int rc = 0;
2795 : :
2796 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
2797 : : int j;
2798 : :
2799 [ # # ]: 0 : for (j = 0; j < vnic->num_lb_ctxts; j++) {
2800 : 0 : rc = _bnxt_hwrm_vnic_ctx_free(bp,
2801 : : vnic,
2802 : 0 : vnic->fw_grp_ids[j]);
2803 : 0 : vnic->fw_grp_ids[j] = INVALID_HW_RING_ID;
2804 : : }
2805 : 0 : vnic->num_lb_ctxts = 0;
2806 : : } else {
2807 : 0 : rc = _bnxt_hwrm_vnic_ctx_free(bp, vnic, vnic->rss_rule);
2808 : 0 : vnic->rss_rule = INVALID_HW_RING_ID;
2809 : : }
2810 : :
2811 : 0 : return rc;
2812 : : }
2813 : :
2814 : 0 : int bnxt_hwrm_vnic_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2815 : : {
2816 : : int rc = 0;
2817 : 0 : struct hwrm_vnic_free_input req = {.req_type = 0 };
2818 : 0 : struct hwrm_vnic_free_output *resp = bp->hwrm_cmd_resp_addr;
2819 : :
2820 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
2821 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC FREE ID %x", vnic->fw_vnic_id);
2822 : 0 : return rc;
2823 : : }
2824 : :
2825 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_FREE, BNXT_USE_CHIMP_MB);
2826 : :
2827 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2828 : :
2829 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2830 : :
2831 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2832 : : HWRM_UNLOCK();
2833 : :
2834 : 0 : vnic->fw_vnic_id = INVALID_HW_RING_ID;
2835 : : /* Configure default VNIC again if necessary. */
2836 [ # # # # ]: 0 : if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
2837 : 0 : bp->flags &= ~BNXT_FLAG_DFLT_VNIC_SET;
2838 : :
2839 : : return rc;
2840 : : }
2841 : :
2842 : 0 : static uint32_t bnxt_sanitize_rss_type(struct bnxt *bp, uint32_t types)
2843 : : {
2844 : : uint32_t hwrm_type = types;
2845 : :
2846 [ # # ]: 0 : if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6_FLOW_LABEL &&
2847 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_IPV6_FLOW_LABEL_MODE))
2848 : 0 : hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_IPV6_FLOW_LABEL;
2849 : :
2850 [ # # ]: 0 : if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV4 &&
2851 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI4_CAP))
2852 : 0 : hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV4;
2853 [ # # ]: 0 : if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV6 &&
2854 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_ESP_SPI6_CAP))
2855 : 0 : hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_ESP_SPI_IPV6;
2856 : :
2857 [ # # ]: 0 : if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV4 &&
2858 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI4_CAP))
2859 : 0 : hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV4;
2860 : :
2861 [ # # ]: 0 : if (types & HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV6 &&
2862 [ # # ]: 0 : !(bp->vnic_cap_flags & BNXT_VNIC_CAP_AH_SPI6_CAP))
2863 : 0 : hwrm_type &= ~HWRM_VNIC_RSS_CFG_INPUT_HASH_TYPE_AH_SPI_IPV6;
2864 : :
2865 : 0 : return hwrm_type;
2866 : : }
2867 : :
2868 : :
2869 : : static int
2870 : 0 : bnxt_hwrm_vnic_rss_cfg_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2871 : : {
2872 : : int i;
2873 : : int rc = 0;
2874 : 0 : int nr_ctxs = vnic->num_lb_ctxts;
2875 : 0 : struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2876 : 0 : struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2877 : :
2878 [ # # ]: 0 : for (i = 0; i < nr_ctxs; i++) {
2879 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2880 : :
2881 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2882 : 0 : req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
2883 [ # # ]: 0 : if (BNXT_CHIP_P7(bp))
2884 : 0 : req.ring_select_mode = vnic->ring_select_mode;
2885 : :
2886 : : /* Do not embed hash_mode_flags here for VFs. Doing so, plus
2887 : : * syncing prev_hash_mode below, permanently short-circuits
2888 : : * bnxt_hwrm_vnic_rss_cfg_hash_mode_p5()'s guard for every VF,
2889 : : * so a trusted VF's explicit RSS hash-level request (e.g.
2890 : : * rss level-outer) is silently dropped. Firmware's own gate
2891 : : * (vnic_rss_cfg_cmd()) permits trusted VFs on that call, so
2892 : : * treat VFs the same as PFs here.
2893 : : */
2894 : 0 : req.hash_mode_flags = BNXT_HASH_MODE_DEFAULT;
2895 : :
2896 : 0 : req.hash_key_tbl_addr =
2897 : 0 : rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2898 : :
2899 : 0 : req.ring_grp_tbl_addr =
2900 : 0 : rte_cpu_to_le_64(vnic->rss_table_dma_addr +
2901 : : i * BNXT_RSS_ENTRIES_PER_CTX_P5 *
2902 : : 2 * sizeof(uint16_t));
2903 : 0 : req.ring_table_pair_index = i;
2904 : 0 : req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
2905 : :
2906 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
2907 : : BNXT_USE_CHIMP_MB);
2908 : :
2909 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2910 : : HWRM_UNLOCK();
2911 : 0 : PMD_DRV_LOG_LINE(DEBUG, "RSS CFG: Hash level %d", req.hash_mode_flags);
2912 : : }
2913 : :
2914 : : return rc;
2915 : : }
2916 : :
2917 : : static int
2918 : 0 : bnxt_hwrm_vnic_rss_cfg_hash_mode_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2919 : : {
2920 : 0 : struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2921 : 0 : struct hwrm_vnic_rss_cfg_input req = {.req_type = 0};
2922 : : int rc = 0;
2923 : :
2924 : : /* Return success when outer RSS is unsupported so normal RSS works. */
2925 [ # # # # : 0 : if ((BNXT_CHIP_P5(bp) && BNXT_VNIC_OUTER_RSS_UNSUPPORTED(bp)) ||
# # # # #
# # # #
# ]
2926 [ # # ]: 0 : (!BNXT_CHIP_P5(bp) && !(bp->vnic_cap_flags & BNXT_VNIC_CAP_OUTER_RSS)))
2927 : : return 0;
2928 : :
2929 [ # # ]: 0 : if (vnic->prev_hash_mode == vnic->hash_mode)
2930 : : return 0;
2931 : :
2932 : : /* Trusted VFs now reach this call the same as PFs; firmware's own
2933 : : * gate (IS_PF_FID() || pcie_func_is_trusted_vf()) restricts which
2934 : : * callers it accepts the request from. Firmware would reject a
2935 : : * request from an untrusted VF, so keep it a silent no-op here
2936 : : * instead of surfacing a new HWRM error.
2937 : : * The fw_grp_ids/num_lb_ctxts check guards against a NULL RSS
2938 : : * context that is not yet initialized or has been torn down by
2939 : : * a port stop.
2940 : : */
2941 [ # # # # ]: 0 : if (BNXT_VF(bp) &&
2942 [ # # # # ]: 0 : (!BNXT_VF_IS_TRUSTED(bp) || !vnic->fw_grp_ids || !vnic->num_lb_ctxts))
2943 : : return 0;
2944 : :
2945 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2946 : :
2947 : : /* FW DEFAULT keeps existing hash level; translate to INNERMOST so
2948 : : * the NIC uses its hardware default (inner headers).
2949 : : */
2950 [ # # ]: 0 : if (vnic->hash_mode == BNXT_HASH_MODE_DEFAULT)
2951 : 0 : req.hash_mode_flags = BNXT_HASH_MODE_INNERMOST;
2952 : : else
2953 : 0 : req.hash_mode_flags = vnic->hash_mode;
2954 : :
2955 : 0 : req.vnic_id = rte_cpu_to_le_16(BNXT_DFLT_VNIC_ID_INVALID);
2956 : 0 : req.rss_ctx_idx = rte_cpu_to_le_16(BNXT_RSS_CTX_IDX_INVALID);
2957 : 0 : PMD_DRV_LOG_LINE(DEBUG, "RSS CFG: Hash level %d", req.hash_mode_flags);
2958 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2959 : :
2960 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2961 : : if (!rc)
2962 : 0 : vnic->prev_hash_mode = vnic->hash_mode;
2963 : : HWRM_UNLOCK();
2964 : 0 : return rc;
2965 : : }
2966 : :
2967 : : static int
2968 : 0 : bnxt_hwrm_vnic_rss_cfg_non_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
2969 : : {
2970 : 0 : struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
2971 : 0 : struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
2972 : : int rc = 0;
2973 : :
2974 [ # # ]: 0 : if (vnic->num_lb_ctxts == 0)
2975 : : return rc;
2976 : :
2977 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
2978 : :
2979 : 0 : req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
2980 : 0 : req.hash_mode_flags = vnic->hash_mode;
2981 : :
2982 : 0 : req.ring_grp_tbl_addr =
2983 : 0 : rte_cpu_to_le_64(vnic->rss_table_dma_addr);
2984 : 0 : req.hash_key_tbl_addr =
2985 : 0 : rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
2986 : 0 : req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
2987 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
2988 : :
2989 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
2990 : :
2991 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
2992 : : HWRM_UNLOCK();
2993 : :
2994 : 0 : return rc;
2995 : : }
2996 : :
2997 : 0 : int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
2998 : : struct bnxt_vnic_info *vnic)
2999 : : {
3000 : : int rc = 0;
3001 : :
3002 [ # # ]: 0 : if (!vnic->rss_table)
3003 : : return 0;
3004 : :
3005 : : /* Handle all the non-thor skus rss here */
3006 [ # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp))
3007 : 0 : return bnxt_hwrm_vnic_rss_cfg_non_p5(bp, vnic);
3008 : :
3009 : : /* Handle Thor2 and Thor skus rss here */
3010 : 0 : rc = bnxt_hwrm_vnic_rss_cfg_p5(bp, vnic);
3011 : :
3012 : : /* configure hash mode for Thor/Thor2 */
3013 [ # # ]: 0 : if (!rc)
3014 : 0 : return bnxt_hwrm_vnic_rss_cfg_hash_mode_p5(bp, vnic);
3015 : :
3016 : : return rc;
3017 : : }
3018 : :
3019 : 0 : int bnxt_hwrm_vnic_plcmode_cfg(struct bnxt *bp,
3020 : : struct bnxt_vnic_info *vnic)
3021 : : {
3022 : 0 : struct hwrm_vnic_plcmodes_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3023 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
3024 : 0 : struct hwrm_vnic_plcmodes_cfg_input req = {.req_type = 0 };
3025 : 0 : uint64_t rx_offloads = dev_conf->rxmode.offloads;
3026 : 0 : uint8_t rs = !!(rx_offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT);
3027 : : uint32_t flags, enables;
3028 : : uint16_t size;
3029 : : int rc = 0;
3030 : :
3031 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
3032 : 0 : PMD_DRV_LOG_LINE(DEBUG, "VNIC ID %x", vnic->fw_vnic_id);
3033 : 0 : return rc;
3034 : : }
3035 : :
3036 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_PLCMODES_CFG, BNXT_USE_CHIMP_MB);
3037 : : flags = HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_JUMBO_PLACEMENT;
3038 : : enables = HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_JUMBO_THRESH_VALID;
3039 : :
3040 [ # # ]: 0 : size = rte_pktmbuf_data_room_size(bp->rx_queues[0]->mb_pool);
3041 : 0 : size -= RTE_PKTMBUF_HEADROOM;
3042 : 0 : size = RTE_MIN(BNXT_MAX_PKT_LEN, size);
3043 : 0 : req.jumbo_thresh = rte_cpu_to_le_16(size);
3044 : :
3045 [ # # ]: 0 : if (rs & vnic->hds_threshold) {
3046 : : flags |=
3047 : : HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_HDS_IPV4 |
3048 : : HWRM_VNIC_PLCMODES_CFG_INPUT_FLAGS_HDS_IPV6;
3049 : 0 : req.hds_threshold = rte_cpu_to_le_16(vnic->hds_threshold);
3050 : : enables |=
3051 : : HWRM_VNIC_PLCMODES_CFG_INPUT_ENABLES_HDS_THRESHOLD_VALID;
3052 : : }
3053 : :
3054 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
3055 : 0 : req.flags = rte_cpu_to_le_32(flags);
3056 : 0 : req.enables = rte_cpu_to_le_32(enables);
3057 : :
3058 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3059 : :
3060 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3061 : : HWRM_UNLOCK();
3062 : :
3063 : 0 : return rc;
3064 : : }
3065 : :
3066 : : #define BNXT_DFLT_TUNL_TPA_BMAP \
3067 : : (HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_GRE | \
3068 : : HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_IPV4 | \
3069 : : HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_IPV6)
3070 : :
3071 : : static void bnxt_vnic_update_tunl_tpa_bmap(struct bnxt *bp,
3072 : : struct hwrm_vnic_tpa_cfg_input *req)
3073 : : {
3074 : : uint32_t tunl_tpa_bmap = BNXT_DFLT_TUNL_TPA_BMAP;
3075 : :
3076 [ # # ]: 0 : if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_VNIC_TUNNEL_TPA))
3077 : : return;
3078 : :
3079 [ # # ]: 0 : if (bp->vxlan_port_cnt)
3080 : : tunl_tpa_bmap |= HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_VXLAN |
3081 : : HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_VXLAN_GPE;
3082 : :
3083 [ # # ]: 0 : if (bp->geneve_port_cnt)
3084 : 0 : tunl_tpa_bmap |= HWRM_VNIC_TPA_CFG_INPUT_TNL_TPA_EN_BITMAP_GENEVE;
3085 : :
3086 : 0 : req->enables |= rte_cpu_to_le_32(HWRM_VNIC_TPA_CFG_INPUT_ENABLES_TNL_TPA_EN);
3087 : 0 : req->tnl_tpa_en_bitmap = rte_cpu_to_le_32(tunl_tpa_bmap);
3088 : : }
3089 : :
3090 : 0 : int bnxt_hwrm_vnic_tpa_cfg(struct bnxt *bp,
3091 : : struct bnxt_vnic_info *vnic, bool enable)
3092 : : {
3093 : : int rc = 0;
3094 : 0 : struct hwrm_vnic_tpa_cfg_input req = {.req_type = 0 };
3095 [ # # ]: 0 : struct hwrm_vnic_tpa_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3096 : :
3097 : : if (bnxt_compressed_rx_cqe_mode_enabled(bp)) {
3098 : : /* Don't worry if disabling TPA */
3099 [ # # ]: 0 : if (!enable)
3100 : : return 0;
3101 : :
3102 : : /* Return an error if enabling TPA w/ compressed Rx CQE. */
3103 : 0 : PMD_DRV_LOG_LINE(ERR, "No HW support for LRO with compressed Rx");
3104 : 0 : return -ENOTSUP;
3105 : : }
3106 : :
3107 [ # # # # ]: 0 : if (!BNXT_SUPPORTS_TPA(bp)) {
3108 [ # # ]: 0 : if (enable)
3109 : 0 : PMD_DRV_LOG_LINE(ERR, "No HW support for LRO");
3110 : 0 : return 0;
3111 : : }
3112 : :
3113 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID) {
3114 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Invalid vNIC ID");
3115 : 0 : return 0;
3116 : : }
3117 : :
3118 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_TPA_CFG, BNXT_USE_CHIMP_MB);
3119 : :
3120 [ # # ]: 0 : if (enable) {
3121 : 0 : req.enables = rte_cpu_to_le_32(
3122 : : HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGG_SEGS |
3123 : : HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MAX_AGGS |
3124 : : HWRM_VNIC_TPA_CFG_INPUT_ENABLES_MIN_AGG_LEN);
3125 : 0 : req.flags = rte_cpu_to_le_32(
3126 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_TPA |
3127 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_ENCAP_TPA |
3128 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_RSC_WND_UPDATE |
3129 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_GRO |
3130 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_ECN |
3131 : : HWRM_VNIC_TPA_CFG_INPUT_FLAGS_AGG_WITH_SAME_GRE_SEQ);
3132 [ # # ]: 0 : req.max_aggs = rte_cpu_to_le_16(BNXT_TPA_MAX_AGGS(bp));
3133 [ # # ]: 0 : req.max_agg_segs = rte_cpu_to_le_16(BNXT_TPA_MAX_SEGS(bp));
3134 : 0 : req.min_agg_len = rte_cpu_to_le_32(512);
3135 : :
3136 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp))
3137 : 0 : req.max_aggs = rte_cpu_to_le_16(bp->max_tpa_v2);
3138 : :
3139 : : /* For tpa v2 handle as per spec mss and log2 units */
3140 [ # # ]: 0 : if (BNXT_CHIP_P7(bp)) {
3141 : : uint32_t nsegs, n, segs = 0;
3142 : 0 : uint16_t mss = bp->eth_dev->data->mtu - 40;
3143 : 0 : size_t page_size = rte_mem_page_size();
3144 : 0 : uint32_t max_mbuf_frags =
3145 : 0 : BNXT_TPA_MAX_PAGES / (rte_mem_page_size() + 1);
3146 : :
3147 : : /* Calculate the number of segs based on mss */
3148 [ # # ]: 0 : if (mss <= page_size) {
3149 : 0 : n = page_size / mss;
3150 : 0 : nsegs = (max_mbuf_frags - 1) * n;
3151 : : } else {
3152 : 0 : n = mss / page_size;
3153 [ # # ]: 0 : if (mss & (page_size - 1))
3154 : 0 : n++;
3155 : 0 : nsegs = (max_mbuf_frags - n) / n;
3156 : : }
3157 : : segs = rte_log2_u32(nsegs);
3158 : 0 : req.max_agg_segs = rte_cpu_to_le_16(segs);
3159 : : }
3160 : : bnxt_vnic_update_tunl_tpa_bmap(bp, &req);
3161 : : }
3162 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
3163 : :
3164 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3165 : :
3166 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3167 : : HWRM_UNLOCK();
3168 : :
3169 : 0 : return rc;
3170 : : }
3171 : :
3172 : 0 : int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
3173 : : {
3174 : 0 : struct hwrm_func_cfg_input req = {0};
3175 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3176 : : int rc;
3177 : :
3178 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
3179 : 0 : req.enables = rte_cpu_to_le_32(
3180 : : HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
3181 : : memcpy(req.dflt_mac_addr, mac_addr, sizeof(req.dflt_mac_addr));
3182 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
3183 : :
3184 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
3185 : :
3186 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3187 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3188 : : HWRM_UNLOCK();
3189 : :
3190 : 0 : bp->pf->vf_info[vf].random_mac = false;
3191 : :
3192 : 0 : return rc;
3193 : : }
3194 : :
3195 : 0 : int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
3196 : : uint64_t *dropped)
3197 : : {
3198 : : int rc = 0;
3199 : 0 : struct hwrm_func_qstats_input req = {.req_type = 0};
3200 : 0 : struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3201 : :
3202 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
3203 : :
3204 : 0 : req.fid = rte_cpu_to_le_16(fid);
3205 : :
3206 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3207 : :
3208 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3209 : :
3210 [ # # ]: 0 : if (dropped)
3211 : 0 : *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
3212 : :
3213 : : HWRM_UNLOCK();
3214 : :
3215 : 0 : return rc;
3216 : : }
3217 : :
3218 : 0 : int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
3219 : : struct rte_eth_stats *stats,
3220 : : struct hwrm_func_qstats_output *func_qstats)
3221 : : {
3222 : : int rc = 0;
3223 : 0 : struct hwrm_func_qstats_input req = {.req_type = 0};
3224 : 0 : struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
3225 : :
3226 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QSTATS, BNXT_USE_CHIMP_MB);
3227 : :
3228 : 0 : req.fid = rte_cpu_to_le_16(fid);
3229 : :
3230 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3231 : :
3232 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3233 [ # # ]: 0 : if (func_qstats)
3234 : 0 : *func_qstats = *resp;
3235 : :
3236 [ # # ]: 0 : if (!stats)
3237 : 0 : goto exit;
3238 : :
3239 : 0 : stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
3240 : 0 : stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
3241 : 0 : stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
3242 : 0 : stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
3243 : 0 : stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
3244 : 0 : stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
3245 : :
3246 : 0 : stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
3247 : 0 : stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
3248 : 0 : stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
3249 : 0 : stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
3250 : 0 : stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
3251 : 0 : stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
3252 : :
3253 : 0 : stats->imissed = rte_le_to_cpu_64(resp->rx_discard_pkts);
3254 : 0 : stats->ierrors = rte_le_to_cpu_64(resp->rx_drop_pkts);
3255 : 0 : stats->oerrors = rte_le_to_cpu_64(resp->tx_discard_pkts);
3256 : :
3257 : 0 : exit:
3258 : : HWRM_UNLOCK();
3259 : :
3260 : 0 : return rc;
3261 : : }
3262 : :
3263 : 0 : int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
3264 : : {
3265 : : int rc = 0;
3266 : 0 : struct hwrm_func_clr_stats_input req = {.req_type = 0};
3267 : 0 : struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
3268 : :
3269 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CLR_STATS, BNXT_USE_CHIMP_MB);
3270 : :
3271 : 0 : req.fid = rte_cpu_to_le_16(fid);
3272 : :
3273 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3274 : :
3275 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3276 : : HWRM_UNLOCK();
3277 : :
3278 : 0 : return rc;
3279 : : }
3280 : :
3281 : 0 : int bnxt_clear_all_hwrm_stat_ctxs(struct bnxt *bp)
3282 : : {
3283 : : unsigned int i;
3284 : : int rc = 0;
3285 : :
3286 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings + bp->tx_cp_nr_rings; i++) {
3287 : : struct bnxt_tx_queue *txq;
3288 : : struct bnxt_rx_queue *rxq;
3289 : : struct bnxt_cp_ring_info *cpr;
3290 : :
3291 [ # # ]: 0 : if (i >= bp->rx_cp_nr_rings) {
3292 : 0 : txq = bp->tx_queues[i - bp->rx_cp_nr_rings];
3293 : 0 : cpr = txq->cp_ring;
3294 : : } else {
3295 : 0 : rxq = bp->rx_queues[i];
3296 : 0 : cpr = rxq->cp_ring;
3297 : : }
3298 : :
3299 : 0 : rc = bnxt_hwrm_stat_clear(bp, cpr);
3300 [ # # ]: 0 : if (rc)
3301 : 0 : return rc;
3302 : : }
3303 : : return 0;
3304 : : }
3305 : :
3306 : : static int
3307 : 0 : bnxt_free_all_hwrm_stat_ctxs(struct bnxt *bp)
3308 : : {
3309 : : int rc;
3310 : : unsigned int i;
3311 : : struct bnxt_cp_ring_info *cpr;
3312 : :
3313 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings; i++) {
3314 : :
3315 [ # # ]: 0 : if (bp->rx_queues[i] == NULL)
3316 : 0 : continue;
3317 : :
3318 : 0 : cpr = bp->rx_queues[i]->cp_ring;
3319 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
3320 : 0 : bp->grp_info[i].fw_stats_ctx = -1;
3321 [ # # ]: 0 : if (cpr == NULL)
3322 : 0 : continue;
3323 : 0 : rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
3324 [ # # ]: 0 : if (rc)
3325 : 0 : return rc;
3326 : : }
3327 : :
3328 [ # # ]: 0 : for (i = 0; i < bp->tx_cp_nr_rings; i++) {
3329 : 0 : cpr = bp->tx_queues[i]->cp_ring;
3330 [ # # ]: 0 : if (cpr == NULL)
3331 : 0 : continue;
3332 : 0 : rc = bnxt_hwrm_stat_ctx_free(bp, cpr);
3333 [ # # ]: 0 : if (rc)
3334 : 0 : return rc;
3335 : : }
3336 : :
3337 : : return 0;
3338 : : }
3339 : :
3340 : : static int
3341 : 0 : bnxt_free_all_hwrm_ring_grps(struct bnxt *bp)
3342 : : {
3343 : : uint16_t idx;
3344 : : uint32_t rc = 0;
3345 : :
3346 [ # # ]: 0 : if (!BNXT_HAS_RING_GRPS(bp))
3347 : : return 0;
3348 : :
3349 [ # # ]: 0 : for (idx = 0; idx < bp->rx_cp_nr_rings; idx++) {
3350 : :
3351 [ # # ]: 0 : if (bp->grp_info[idx].fw_grp_id == INVALID_HW_RING_ID)
3352 : 0 : continue;
3353 : :
3354 : 0 : rc = bnxt_hwrm_ring_grp_free(bp, idx);
3355 : :
3356 [ # # ]: 0 : if (rc)
3357 : 0 : return rc;
3358 : : }
3359 : 0 : return rc;
3360 : : }
3361 : :
3362 : 0 : void bnxt_free_nq_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
3363 : : {
3364 : 0 : struct bnxt_ring *cp_ring = cpr->cp_ring_struct;
3365 : :
3366 : 0 : bnxt_hwrm_ring_free(bp,
3367 : : cp_ring,
3368 : : HWRM_RING_FREE_INPUT_RING_TYPE_NQ,
3369 : : INVALID_HW_RING_ID);
3370 : 0 : memset(cpr->cp_desc_ring, 0,
3371 : 0 : cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
3372 : 0 : cpr->cp_raw_cons = 0;
3373 : 0 : }
3374 : :
3375 : 0 : void bnxt_free_cp_ring(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
3376 : : {
3377 : : struct bnxt_ring *cp_ring;
3378 : :
3379 [ # # ]: 0 : cp_ring = cpr ? cpr->cp_ring_struct : NULL;
3380 : :
3381 [ # # # # ]: 0 : if (cp_ring == NULL || cpr->cp_desc_ring == NULL)
3382 : : return;
3383 : :
3384 : 0 : bnxt_hwrm_ring_free(bp,
3385 : : cp_ring,
3386 : : HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL,
3387 : : INVALID_HW_RING_ID);
3388 : 0 : memset(cpr->cp_desc_ring, 0,
3389 : 0 : cpr->cp_ring_struct->ring_size * sizeof(*cpr->cp_desc_ring));
3390 : 0 : cpr->cp_raw_cons = 0;
3391 : : }
3392 : :
3393 : 0 : void bnxt_free_hwrm_rx_ring(struct bnxt *bp, int queue_index)
3394 : : {
3395 : 0 : struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index];
3396 [ # # ]: 0 : struct bnxt_rx_ring_info *rxr = rxq ? rxq->rx_ring : NULL;
3397 [ # # ]: 0 : struct bnxt_ring *ring = rxr ? rxr->rx_ring_struct : NULL;
3398 [ # # ]: 0 : struct bnxt_cp_ring_info *cpr = rxq ? rxq->cp_ring : NULL;
3399 : :
3400 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
3401 : 0 : bnxt_hwrm_ring_grp_free(bp, queue_index);
3402 : :
3403 [ # # ]: 0 : if (ring != NULL && cpr != NULL)
3404 : 0 : bnxt_hwrm_ring_free(bp, ring,
3405 : : HWRM_RING_FREE_INPUT_RING_TYPE_RX,
3406 : 0 : cpr->cp_ring_struct->fw_ring_id);
3407 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
3408 : 0 : bp->grp_info[queue_index].rx_fw_ring_id = INVALID_HW_RING_ID;
3409 : :
3410 : : /* Check agg ring struct explicitly.
3411 : : * bnxt_need_agg_ring() returns the current state of offload flags,
3412 : : * but we may have to deal with agg ring struct before the offload
3413 : : * flags are updated.
3414 : : */
3415 [ # # # # ]: 0 : if (!bnxt_need_agg_ring(bp->eth_dev) ||
3416 [ # # ]: 0 : (rxr && rxr->ag_ring_struct == NULL))
3417 : 0 : goto no_agg;
3418 : :
3419 [ # # ]: 0 : ring = rxr ? rxr->ag_ring_struct : NULL;
3420 [ # # ]: 0 : if (ring != NULL && cpr != NULL) {
3421 : 0 : bnxt_hwrm_ring_free(bp, ring,
3422 : 0 : BNXT_CHIP_P5_P7(bp) ?
3423 : : HWRM_RING_FREE_INPUT_RING_TYPE_RX_AGG :
3424 : : HWRM_RING_FREE_INPUT_RING_TYPE_RX,
3425 [ # # ]: 0 : cpr->cp_ring_struct->fw_ring_id);
3426 : : }
3427 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
3428 : 0 : bp->grp_info[queue_index].ag_fw_ring_id = INVALID_HW_RING_ID;
3429 : :
3430 : 0 : no_agg:
3431 [ # # ]: 0 : if (cpr != NULL) {
3432 : 0 : bnxt_hwrm_stat_ctx_free(bp, cpr);
3433 : 0 : bnxt_free_cp_ring(bp, cpr);
3434 : : }
3435 : :
3436 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp))
3437 : 0 : bp->grp_info[queue_index].cp_fw_ring_id = INVALID_HW_RING_ID;
3438 : 0 : }
3439 : :
3440 : 0 : int bnxt_hwrm_rx_ring_reset(struct bnxt *bp, int queue_index)
3441 : : {
3442 : : int rc;
3443 : 0 : struct hwrm_ring_reset_input req = {.req_type = 0 };
3444 : 0 : struct hwrm_ring_reset_output *resp = bp->hwrm_cmd_resp_addr;
3445 : :
3446 [ # # ]: 0 : HWRM_PREP(&req, HWRM_RING_RESET, BNXT_USE_CHIMP_MB);
3447 : :
3448 : 0 : req.ring_type = HWRM_RING_RESET_INPUT_RING_TYPE_RX_RING_GRP;
3449 : 0 : req.ring_id = rte_cpu_to_le_16(bp->grp_info[queue_index].fw_grp_id);
3450 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
3451 : :
3452 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
3453 : :
3454 : : HWRM_UNLOCK();
3455 : :
3456 : 0 : return rc;
3457 : : }
3458 : :
3459 : : static int
3460 : 0 : bnxt_free_all_hwrm_rings(struct bnxt *bp)
3461 : : {
3462 : : unsigned int i;
3463 : :
3464 [ # # ]: 0 : for (i = 0; i < bp->tx_cp_nr_rings; i++)
3465 : 0 : bnxt_free_hwrm_tx_ring(bp, i);
3466 : :
3467 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings; i++)
3468 : 0 : bnxt_free_hwrm_rx_ring(bp, i);
3469 : :
3470 : 0 : return 0;
3471 : : }
3472 : :
3473 : 0 : int bnxt_alloc_all_hwrm_ring_grps(struct bnxt *bp)
3474 : : {
3475 : : uint16_t i;
3476 : : uint32_t rc = 0;
3477 : :
3478 [ # # ]: 0 : if (!BNXT_HAS_RING_GRPS(bp))
3479 : : return 0;
3480 : :
3481 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings; i++) {
3482 : 0 : rc = bnxt_hwrm_ring_grp_alloc(bp, i);
3483 [ # # ]: 0 : if (rc)
3484 : 0 : return rc;
3485 : : }
3486 : : return rc;
3487 : : }
3488 : :
3489 : : /*
3490 : : * HWRM utility functions
3491 : : */
3492 : :
3493 : 0 : void bnxt_free_hwrm_resources(struct bnxt *bp)
3494 : : {
3495 : : /* Release memzone */
3496 : 0 : rte_free(bp->hwrm_cmd_resp_addr);
3497 : 0 : rte_free(bp->hwrm_short_cmd_req_addr);
3498 : 0 : bp->hwrm_cmd_resp_addr = NULL;
3499 : 0 : bp->hwrm_short_cmd_req_addr = NULL;
3500 : 0 : bp->hwrm_cmd_resp_dma_addr = 0;
3501 : 0 : bp->hwrm_short_cmd_req_dma_addr = 0;
3502 : 0 : }
3503 : :
3504 : 0 : int bnxt_alloc_hwrm_resources(struct bnxt *bp)
3505 : : {
3506 : 0 : struct rte_pci_device *pdev = bp->pdev;
3507 : : char type[RTE_MEMZONE_NAMESIZE];
3508 : :
3509 : 0 : snprintf(type, sizeof(type), "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
3510 : 0 : pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
3511 : 0 : bp->max_resp_len = BNXT_PAGE_SIZE;
3512 : 0 : bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
3513 [ # # ]: 0 : if (bp->hwrm_cmd_resp_addr == NULL)
3514 : : return -ENOMEM;
3515 : 0 : bp->hwrm_cmd_resp_dma_addr =
3516 : 0 : rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
3517 [ # # ]: 0 : if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
3518 : 0 : PMD_DRV_LOG_LINE(ERR,
3519 : : "unable to map response address to physical memory");
3520 : 0 : return -ENOMEM;
3521 : : }
3522 : : rte_spinlock_init(&bp->hwrm_lock);
3523 : :
3524 : 0 : return 0;
3525 : : }
3526 : :
3527 : : int
3528 : 0 : bnxt_clear_one_vnic_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
3529 : : {
3530 : : int rc = 0;
3531 : :
3532 [ # # ]: 0 : if (filter->filter_type == HWRM_CFA_EM_FILTER) {
3533 : 0 : rc = bnxt_hwrm_clear_em_filter(bp, filter);
3534 [ # # ]: 0 : if (rc)
3535 : : return rc;
3536 [ # # ]: 0 : } else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER) {
3537 : 0 : rc = bnxt_hwrm_clear_ntuple_filter(bp, filter);
3538 [ # # ]: 0 : if (rc)
3539 : : return rc;
3540 : : }
3541 : :
3542 : 0 : rc = bnxt_hwrm_clear_l2_filter(bp, filter);
3543 : 0 : return rc;
3544 : : }
3545 : :
3546 : : static int
3547 : 0 : bnxt_clear_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3548 : : {
3549 : : struct bnxt_filter_info *filter;
3550 : : int rc = 0;
3551 : :
3552 [ # # ]: 0 : while (!STAILQ_EMPTY(&vnic->filter)) {
3553 : : filter = STAILQ_FIRST(&vnic->filter);
3554 : 0 : rc = bnxt_clear_one_vnic_filter(bp, filter);
3555 [ # # ]: 0 : STAILQ_REMOVE_HEAD(&vnic->filter, next);
3556 : 0 : bnxt_free_filter(bp, filter);
3557 : : }
3558 : 0 : return rc;
3559 : : }
3560 : :
3561 : : static int
3562 : 0 : bnxt_clear_hwrm_vnic_flows(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3563 : : {
3564 : : struct bnxt_filter_info *filter;
3565 : : struct rte_flow *flow;
3566 : : int rc = 0;
3567 : :
3568 [ # # ]: 0 : while (!STAILQ_EMPTY(&vnic->flow_list)) {
3569 : : flow = STAILQ_FIRST(&vnic->flow_list);
3570 : 0 : filter = flow->filter;
3571 : 0 : PMD_DRV_LOG_LINE(DEBUG, "filter type %d", filter->filter_type);
3572 : 0 : rc = bnxt_clear_one_vnic_filter(bp, filter);
3573 : :
3574 [ # # # # : 0 : STAILQ_REMOVE(&vnic->flow_list, flow, rte_flow, next);
# # # # ]
3575 : 0 : rte_free(flow);
3576 : : }
3577 : 0 : return rc;
3578 : : }
3579 : :
3580 : 0 : int bnxt_set_hwrm_vnic_filters(struct bnxt *bp, struct bnxt_vnic_info *vnic)
3581 : : {
3582 : : struct bnxt_filter_info *filter;
3583 : : int rc = 0;
3584 : :
3585 [ # # ]: 0 : STAILQ_FOREACH(filter, &vnic->filter, next) {
3586 [ # # ]: 0 : if (filter->filter_type == HWRM_CFA_EM_FILTER)
3587 : 0 : rc = bnxt_hwrm_set_em_filter(bp, filter->dst_id,
3588 : : filter);
3589 [ # # ]: 0 : else if (filter->filter_type == HWRM_CFA_NTUPLE_FILTER)
3590 : 0 : rc = bnxt_hwrm_set_ntuple_filter(bp, filter->dst_id,
3591 : : filter);
3592 : : else
3593 : 0 : rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id,
3594 : : filter);
3595 [ # # ]: 0 : if (rc)
3596 : : break;
3597 : : }
3598 : 0 : return rc;
3599 : : }
3600 : :
3601 : : static void
3602 : 0 : bnxt_free_tunnel_ports(struct bnxt *bp)
3603 : : {
3604 [ # # ]: 0 : if (bp->vxlan_port_cnt)
3605 : 0 : bnxt_hwrm_tunnel_dst_port_free(bp, bp->vxlan_fw_dst_port_id,
3606 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN);
3607 : :
3608 [ # # ]: 0 : if (bp->geneve_port_cnt)
3609 : 0 : bnxt_hwrm_tunnel_dst_port_free(bp, bp->geneve_fw_dst_port_id,
3610 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE);
3611 : :
3612 [ # # ]: 0 : if (bp->ecpri_port_cnt)
3613 : 0 : bnxt_hwrm_tunnel_dst_port_free(bp, bp->ecpri_fw_dst_port_id,
3614 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI);
3615 : :
3616 [ # # ]: 0 : if (bp->l2_etype_tunnel_cnt)
3617 : 0 : bnxt_hwrm_tunnel_dst_port_free(bp, bp->l2_etype_tunnel_id,
3618 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_L2_ETYPE);
3619 : 0 : }
3620 : :
3621 : 0 : void bnxt_free_all_hwrm_resources(struct bnxt *bp)
3622 : : {
3623 : : int i;
3624 : :
3625 [ # # ]: 0 : if (bp->vnic_info == NULL)
3626 : : return;
3627 : :
3628 : : /*
3629 : : * Cleanup VNICs in reverse order, to make sure the L2 filter
3630 : : * from vnic0 is last to be cleaned up.
3631 : : */
3632 [ # # ]: 0 : for (i = bp->max_vnics - 1; i >= 0; i--) {
3633 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
3634 : :
3635 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
3636 : 0 : continue;
3637 : :
3638 [ # # # # ]: 0 : if (vnic->func_default && (bp->flags & BNXT_FLAG_DFLT_VNIC_SET))
3639 : 0 : bnxt_hwrm_cfa_l2_clear_rx_mask(bp, vnic);
3640 : 0 : bnxt_clear_hwrm_vnic_flows(bp, vnic);
3641 : :
3642 : 0 : bnxt_clear_hwrm_vnic_filters(bp, vnic);
3643 : :
3644 : 0 : bnxt_hwrm_vnic_tpa_cfg(bp, vnic, false);
3645 : :
3646 : 0 : bnxt_hwrm_vnic_free(bp, vnic);
3647 : :
3648 : 0 : bnxt_hwrm_vnic_ctx_free(bp, vnic);
3649 : :
3650 : 0 : rte_free(vnic->fw_grp_ids);
3651 : 0 : vnic->fw_grp_ids = NULL;
3652 [ # # # # ]: 0 : if (vnic->ref_cnt && !vnic->rx_queue_cnt)
3653 : 0 : vnic->ref_cnt--;
3654 : : }
3655 : : /* Ring resources */
3656 : 0 : bnxt_free_all_hwrm_rings(bp);
3657 : 0 : bnxt_free_all_hwrm_ring_grps(bp);
3658 : 0 : bnxt_free_all_hwrm_stat_ctxs(bp);
3659 : 0 : bnxt_free_tunnel_ports(bp);
3660 : : }
3661 : :
3662 : : static uint16_t bnxt_parse_eth_link_duplex(uint32_t conf_link_speed)
3663 : : {
3664 : : uint8_t hw_link_duplex = HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
3665 : :
3666 : 0 : if ((conf_link_speed & RTE_ETH_LINK_SPEED_FIXED) == RTE_ETH_LINK_SPEED_AUTONEG)
3667 : : return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH;
3668 : :
3669 [ # # # # : 0 : switch (conf_link_speed) {
# # ]
3670 : : case RTE_ETH_LINK_SPEED_10M_HD:
3671 : : case RTE_ETH_LINK_SPEED_100M_HD:
3672 : : /* FALLTHROUGH */
3673 : : return HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF;
3674 : : }
3675 : 0 : return hw_link_duplex;
3676 : : }
3677 : :
3678 : : static uint16_t bnxt_check_eth_link_autoneg(uint32_t conf_link)
3679 : : {
3680 : 0 : return !conf_link;
3681 : : }
3682 : :
3683 : 0 : uint16_t bnxt_parse_eth_link_speed_v2(struct bnxt *bp)
3684 : : {
3685 : : /* get bitmap value based on speed */
3686 : 0 : return ((struct link_speeds2_tbl *)
3687 : 0 : bnxt_get_rte_hwrm_speeds2_entry(bp))->force_val;
3688 : : }
3689 : :
3690 : 0 : static uint16_t bnxt_parse_eth_link_speed(struct bnxt *bp, uint32_t conf_link_speed,
3691 : : struct bnxt_link_info *link_info)
3692 : : {
3693 : 0 : uint16_t support_pam4_speeds = link_info->support_pam4_speeds;
3694 : 0 : uint16_t support_speeds = link_info->support_speeds;
3695 : : uint16_t eth_link_speed = 0;
3696 : :
3697 [ # # ]: 0 : if (conf_link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
3698 : : return RTE_ETH_LINK_SPEED_AUTONEG;
3699 : :
3700 : : /* Handle P7 chips saperately. It got enhanced phy attribs to choose from */
3701 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
3702 : 0 : return bnxt_parse_eth_link_speed_v2(bp);
3703 : :
3704 [ # # # # : 0 : switch (conf_link_speed & ~RTE_ETH_LINK_SPEED_FIXED) {
# # # # #
# # ]
3705 : : case RTE_ETH_LINK_SPEED_100M:
3706 : : case RTE_ETH_LINK_SPEED_100M_HD:
3707 : : /* FALLTHROUGH */
3708 : : eth_link_speed =
3709 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100MB;
3710 : : break;
3711 : 0 : case RTE_ETH_LINK_SPEED_1G:
3712 : : eth_link_speed =
3713 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_1GB;
3714 : 0 : break;
3715 : 0 : case RTE_ETH_LINK_SPEED_2_5G:
3716 : : eth_link_speed =
3717 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_2_5GB;
3718 : 0 : break;
3719 : 0 : case RTE_ETH_LINK_SPEED_10G:
3720 : : eth_link_speed =
3721 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_10GB;
3722 : 0 : break;
3723 : 0 : case RTE_ETH_LINK_SPEED_20G:
3724 : : eth_link_speed =
3725 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_20GB;
3726 : 0 : break;
3727 : 0 : case RTE_ETH_LINK_SPEED_25G:
3728 : : eth_link_speed =
3729 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_25GB;
3730 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
3731 : 0 : break;
3732 : 0 : case RTE_ETH_LINK_SPEED_40G:
3733 : : eth_link_speed =
3734 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_40GB;
3735 : 0 : break;
3736 : 0 : case RTE_ETH_LINK_SPEED_50G:
3737 [ # # ]: 0 : if (support_speeds & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_50GB) {
3738 : : eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_50GB;
3739 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
3740 [ # # ]: 0 : } else if (support_pam4_speeds &
3741 : : HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_50G) {
3742 : : eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_50GB;
3743 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
3744 : : }
3745 : : break;
3746 : 0 : case RTE_ETH_LINK_SPEED_100G:
3747 [ # # ]: 0 : if (support_speeds & HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_SPEEDS_100GB) {
3748 : : eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_LINK_SPEED_100GB;
3749 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_NRZ;
3750 [ # # ]: 0 : } else if (support_pam4_speeds &
3751 : : HWRM_PORT_PHY_QCFG_OUTPUT_SUPPORT_PAM4_SPEEDS_100G) {
3752 : : eth_link_speed = HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_100GB;
3753 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
3754 : : }
3755 : : break;
3756 : 0 : case RTE_ETH_LINK_SPEED_200G:
3757 : : eth_link_speed =
3758 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB;
3759 : 0 : link_info->link_signal_mode = BNXT_SIG_MODE_PAM4;
3760 : 0 : break;
3761 : 0 : default:
3762 : 0 : PMD_DRV_LOG_LINE(ERR,
3763 : : "Unsupported link speed %d; default to AUTO",
3764 : : conf_link_speed);
3765 : 0 : break;
3766 : : }
3767 : : return eth_link_speed;
3768 : : }
3769 : :
3770 : : #define BNXT_SUPPORTED_SPEEDS (RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_100M_HD | \
3771 : : RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G | \
3772 : : RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_20G | RTE_ETH_LINK_SPEED_25G | \
3773 : : RTE_ETH_LINK_SPEED_40G | RTE_ETH_LINK_SPEED_50G | \
3774 : : RTE_ETH_LINK_SPEED_100G | RTE_ETH_LINK_SPEED_200G)
3775 : : #define BNXT_SUPPORTED_SPEEDS2 ((BNXT_SUPPORTED_SPEEDS | RTE_ETH_LINK_SPEED_400G) & \
3776 : : ~(RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_100M_HD | \
3777 : : RTE_ETH_LINK_SPEED_2_5G | RTE_ETH_LINK_SPEED_20G))
3778 : :
3779 : 0 : static int bnxt_validate_link_speed(struct bnxt *bp)
3780 : : {
3781 : 0 : uint32_t link_speed = bp->eth_dev->data->dev_conf.link_speeds;
3782 : 0 : uint16_t port_id = bp->eth_dev->data->port_id;
3783 : : uint32_t link_speed_capa;
3784 : : uint32_t one_speed;
3785 : :
3786 [ # # ]: 0 : if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
3787 : : return 0;
3788 : :
3789 : 0 : link_speed_capa = bnxt_get_speed_capabilities(bp);
3790 : :
3791 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_FIXED) {
3792 : 0 : one_speed = link_speed & ~RTE_ETH_LINK_SPEED_FIXED;
3793 : :
3794 [ # # ]: 0 : if (one_speed & (one_speed - 1)) {
3795 : 0 : PMD_DRV_LOG_LINE(ERR,
3796 : : "Invalid advertised speeds (%u) for port %u",
3797 : : link_speed, port_id);
3798 : 0 : return -EINVAL;
3799 : : }
3800 [ # # ]: 0 : if ((one_speed & link_speed_capa) != one_speed) {
3801 : 0 : PMD_DRV_LOG_LINE(ERR,
3802 : : "Unsupported advertised speed (%u) for port %u",
3803 : : link_speed, port_id);
3804 : 0 : return -EINVAL;
3805 : : }
3806 : : } else {
3807 [ # # ]: 0 : if (!(link_speed & link_speed_capa)) {
3808 : 0 : PMD_DRV_LOG_LINE(ERR,
3809 : : "Unsupported advertised speeds (%u) for port %u",
3810 : : link_speed, port_id);
3811 : 0 : return -EINVAL;
3812 : : }
3813 : : }
3814 : : return 0;
3815 : : }
3816 : :
3817 : : static uint16_t
3818 : : bnxt_parse_eth_link_speed_mask_v2(struct bnxt *bp, uint32_t link_speed)
3819 : : {
3820 : : uint16_t ret = 0;
3821 : :
3822 [ # # ]: 0 : if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG)
3823 : 0 : return bp->link_info->supported_speeds2_auto_mode;
3824 : :
3825 : : return ret;
3826 : : }
3827 : :
3828 : : static uint16_t
3829 : 0 : bnxt_parse_eth_link_speed_mask(struct bnxt *bp, uint32_t link_speed)
3830 : : {
3831 : : uint16_t ret = 0;
3832 : :
3833 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
3834 : 0 : return bnxt_parse_eth_link_speed_mask_v2(bp, link_speed);
3835 : :
3836 [ # # ]: 0 : if (link_speed == RTE_ETH_LINK_SPEED_AUTONEG) {
3837 [ # # ]: 0 : if (bp->link_info->support_speeds)
3838 : : return bp->link_info->support_speeds;
3839 : : link_speed = BNXT_SUPPORTED_SPEEDS;
3840 : : }
3841 : :
3842 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_100M)
3843 : : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
3844 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_100M_HD)
3845 : : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100MB;
3846 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_1G)
3847 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_1GB;
3848 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_2_5G)
3849 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_2_5GB;
3850 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_10G)
3851 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_10GB;
3852 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_20G)
3853 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_20GB;
3854 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_25G)
3855 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_25GB;
3856 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_40G)
3857 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_40GB;
3858 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_50G)
3859 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_50GB;
3860 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_100G)
3861 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_AUTO_LINK_SPEED_MASK_100GB;
3862 [ # # ]: 0 : if (link_speed & RTE_ETH_LINK_SPEED_200G)
3863 : 0 : ret |= HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB;
3864 : : return ret;
3865 : : }
3866 : :
3867 : : static uint32_t bnxt_parse_hw_link_speed_v2(uint16_t hw_link_speed)
3868 : : {
3869 : : return ((struct link_speeds2_tbl *)
3870 : 0 : bnxt_get_hwrm_to_rte_speeds2_entry(hw_link_speed))->rte_speed_num;
3871 : : }
3872 : :
3873 : 0 : static uint32_t bnxt_parse_hw_link_speed(struct bnxt *bp, uint16_t hw_link_speed)
3874 : : {
3875 : : uint32_t eth_link_speed = RTE_ETH_SPEED_NUM_NONE;
3876 : :
3877 : : /* query fixed speed2 table if not autoneg */
3878 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp) && !bp->link_info->auto_mode)
# # # # #
# ]
3879 : 0 : return bnxt_parse_hw_link_speed_v2(hw_link_speed);
3880 : :
3881 : : /* for P7 and earlier nics link_speed carries AN'd speed */
3882 [ # # # # : 0 : switch (hw_link_speed) {
# # # # #
# # # ]
3883 : : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100MB:
3884 : : eth_link_speed = RTE_ETH_SPEED_NUM_100M;
3885 : : break;
3886 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_1GB:
3887 : : eth_link_speed = RTE_ETH_SPEED_NUM_1G;
3888 : 0 : break;
3889 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2_5GB:
3890 : : eth_link_speed = RTE_ETH_SPEED_NUM_2_5G;
3891 : 0 : break;
3892 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_10GB:
3893 : : eth_link_speed = RTE_ETH_SPEED_NUM_10G;
3894 : 0 : break;
3895 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_20GB:
3896 : : eth_link_speed = RTE_ETH_SPEED_NUM_20G;
3897 : 0 : break;
3898 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_25GB:
3899 : : eth_link_speed = RTE_ETH_SPEED_NUM_25G;
3900 : 0 : break;
3901 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_40GB:
3902 : : eth_link_speed = RTE_ETH_SPEED_NUM_40G;
3903 : 0 : break;
3904 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_50GB:
3905 : : eth_link_speed = RTE_ETH_SPEED_NUM_50G;
3906 : 0 : break;
3907 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_100GB:
3908 : : eth_link_speed = RTE_ETH_SPEED_NUM_100G;
3909 : 0 : break;
3910 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_200GB:
3911 : : eth_link_speed = RTE_ETH_SPEED_NUM_200G;
3912 : 0 : break;
3913 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_400GB:
3914 : : eth_link_speed = RTE_ETH_SPEED_NUM_400G;
3915 : 0 : break;
3916 : 0 : case HWRM_PORT_PHY_QCFG_OUTPUT_LINK_SPEED_2GB:
3917 : : default:
3918 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM link speed %d not defined",
3919 : : hw_link_speed);
3920 : 0 : break;
3921 : : }
3922 : : return eth_link_speed;
3923 : : }
3924 : :
3925 : 0 : static uint16_t bnxt_parse_hw_link_duplex(uint16_t hw_link_duplex)
3926 : : {
3927 : : uint16_t eth_link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3928 : :
3929 [ # # # ]: 0 : switch (hw_link_duplex) {
3930 : : case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_BOTH:
3931 : : case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_FULL:
3932 : : /* FALLTHROUGH */
3933 : : eth_link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3934 : : break;
3935 : 0 : case HWRM_PORT_PHY_CFG_INPUT_AUTO_DUPLEX_HALF:
3936 : : eth_link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
3937 : 0 : break;
3938 : 0 : default:
3939 : 0 : PMD_DRV_LOG_LINE(ERR, "HWRM link duplex %d not defined",
3940 : : hw_link_duplex);
3941 : 0 : break;
3942 : : }
3943 : 0 : return eth_link_duplex;
3944 : : }
3945 : :
3946 : 0 : int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
3947 : : {
3948 : : int rc = 0;
3949 : 0 : struct bnxt_link_info *link_info = bp->link_info;
3950 : :
3951 : 0 : rc = bnxt_hwrm_port_phy_qcaps(bp);
3952 [ # # ]: 0 : if (rc)
3953 : 0 : PMD_DRV_LOG_LINE(ERR, "Get link config failed with rc %d", rc);
3954 : :
3955 : 0 : rc = bnxt_hwrm_port_phy_qcfg(bp, link_info);
3956 [ # # ]: 0 : if (rc) {
3957 : 0 : PMD_DRV_LOG_LINE(ERR, "Get link config failed with rc %d", rc);
3958 : 0 : goto exit;
3959 : : }
3960 : :
3961 [ # # ]: 0 : if (link_info->link_speed)
3962 : 0 : link->link_speed = bnxt_parse_hw_link_speed(bp, link_info->link_speed);
3963 : : else
3964 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3965 : 0 : link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
3966 : 0 : link->link_status = link_info->link_up;
3967 : 0 : link->link_autoneg = link_info->auto_mode ==
3968 : : HWRM_PORT_PHY_QCFG_OUTPUT_AUTO_MODE_NONE ?
3969 : 0 : RTE_ETH_LINK_FIXED : RTE_ETH_LINK_AUTONEG;
3970 : 0 : exit:
3971 : 0 : return rc;
3972 : : }
3973 : :
3974 : 0 : static int bnxt_hwrm_port_phy_cfg_v2(struct bnxt *bp, struct bnxt_link_info *conf)
3975 : : {
3976 : 0 : struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
3977 : 0 : struct hwrm_port_phy_cfg_input req = {0};
3978 : : uint32_t enables = 0;
3979 : : int rc = 0;
3980 : :
3981 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
3982 : :
3983 [ # # ]: 0 : if (!conf->link_up) {
3984 : 0 : req.flags =
3985 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE_LINK_DWN);
3986 : 0 : PMD_DRV_LOG_LINE(ERR, "Force Link Down");
3987 : 0 : goto link_down;
3988 : : }
3989 : :
3990 : : /* Setting Fixed Speed. But AutoNeg is ON, So disable it */
3991 [ # # # # ]: 0 : if (bp->link_info->auto_mode && conf->link_speed) {
3992 : 0 : req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_NONE;
3993 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Disabling AutoNeg");
3994 : : }
3995 : 0 : req.flags = rte_cpu_to_le_32(conf->phy_flags);
3996 [ # # ]: 0 : if (!conf->link_speed) {
3997 : : /* No speeds specified. Enable AutoNeg - all speeds */
3998 : : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEEDS2_MASK;
3999 : : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
4000 : 0 : req.auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
4001 : 0 : req.auto_link_speeds2_mask =
4002 : 0 : rte_cpu_to_le_16(bp->link_info->supported_speeds2_auto_mode);
4003 : : } else {
4004 : : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_LINK_SPEEDS2;
4005 : 0 : req.force_link_speeds2 = rte_cpu_to_le_16(conf->link_speed);
4006 : 0 : PMD_DRV_LOG_LINE(INFO, "Force speed %d", conf->link_speed);
4007 : : }
4008 : :
4009 : : /* Fill rest of the req message */
4010 : 0 : req.auto_duplex = conf->duplex;
4011 [ # # ]: 0 : if (req.auto_mode != HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK)
4012 : 0 : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
4013 : 0 : req.auto_pause = conf->auto_pause;
4014 : 0 : req.force_pause = conf->force_pause;
4015 [ # # ]: 0 : if (req.auto_pause)
4016 : 0 : req.force_pause = 0;
4017 : : /* Set force_pause if there is no auto or if there is a force */
4018 [ # # # # ]: 0 : if (req.auto_pause && !req.force_pause)
4019 : 0 : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE;
4020 : : else
4021 : 0 : enables |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE;
4022 : 0 : req.enables = rte_cpu_to_le_32(enables);
4023 : :
4024 : 0 : link_down:
4025 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4026 : :
4027 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4028 : : HWRM_UNLOCK();
4029 : 0 : return rc;
4030 : : }
4031 : :
4032 : : static void
4033 : 0 : bnxt_hwrm_set_pause_common(struct bnxt *bp,
4034 : : struct hwrm_port_phy_cfg_input *req)
4035 : : {
4036 : 0 : struct bnxt_link_info *link_info = bp->link_info;
4037 : :
4038 [ # # ]: 0 : if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) {
4039 [ # # ]: 0 : if (bp->hwrm_spec_code >= HWRM_SPEC_CODE_AUTONEG_PAUSE)
4040 : 0 : req->auto_pause =
4041 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_AUTONEG_PAUSE;
4042 [ # # ]: 0 : if (link_info->auto_pause &
4043 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX)
4044 : 0 : req->auto_pause |=
4045 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_RX;
4046 [ # # ]: 0 : if (link_info->auto_pause &
4047 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX)
4048 : 0 : req->auto_pause |=
4049 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_PAUSE_TX;
4050 : 0 : req->enables |=
4051 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE);
4052 : : } else {
4053 [ # # ]: 0 : if (link_info->force_pause &
4054 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX)
4055 : 0 : req->force_pause |=
4056 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_RX;
4057 [ # # ]: 0 : if (link_info->force_pause &
4058 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX)
4059 : 0 : req->force_pause |=
4060 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAUSE_TX;
4061 : 0 : req->enables |=
4062 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_PAUSE);
4063 [ # # ]: 0 : if (bp->hwrm_spec_code >= HWRM_SPEC_CODE_AUTONEG_PAUSE) {
4064 : 0 : req->auto_pause = req->force_pause;
4065 : 0 : req->enables |=
4066 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_PAUSE);
4067 : : }
4068 : : }
4069 : 0 : }
4070 : :
4071 : : static int
4072 : 0 : bnxt_hwrm_set_link_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req)
4073 : : {
4074 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
4075 : 0 : struct bnxt_link_info *link_info = bp->link_info;
4076 : : uint16_t autoneg, speed;
4077 : : uint32_t en = 0;
4078 : :
4079 : 0 : autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
4080 : :
4081 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp) &&
4082 [ # # ]: 0 : dev_conf->link_speeds & RTE_ETH_LINK_SPEED_40G)
4083 : : autoneg = 0;
4084 : :
4085 [ # # # # ]: 0 : if (autoneg == 1 && BNXT_CHIP_P5(bp) &&
4086 [ # # ]: 0 : link_info->auto_mode == 0 &&
4087 [ # # ]: 0 : link_info->force_pam4_link_speed ==
4088 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB)
4089 : : autoneg = 0;
4090 : :
4091 : 0 : speed = bnxt_parse_eth_link_speed(bp, dev_conf->link_speeds,
4092 : : link_info);
4093 : 0 : req->flags |=
4094 : : rte_cpu_to_le_32(HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY);
4095 : :
4096 [ # # ]: 0 : if (autoneg == 0 &&
4097 [ # # ]: 0 : (link_info->phy_type == HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
4098 : 0 : link_info->phy_type == HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
4099 [ # # ]: 0 : link_info->media_type == HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP)) {
4100 : 0 : PMD_DRV_LOG_LINE(ERR, "10GBase-T devices must autoneg");
4101 : 0 : return -EINVAL;
4102 : : }
4103 : :
4104 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp)) {
# # # # ]
4105 : : /* speeds-v2 firmware uses a separate field layout */
4106 [ # # ]: 0 : if (autoneg == 1) {
4107 : 0 : req->flags |= rte_cpu_to_le_32
4108 : : (HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG);
4109 : 0 : req->auto_mode =
4110 : : HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
4111 : 0 : req->auto_link_speeds2_mask = rte_cpu_to_le_16
4112 : : (bnxt_parse_eth_link_speed_mask(bp,
4113 : : dev_conf->link_speeds));
4114 : : en |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_LINK_SPEEDS2_MASK |
4115 : : HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
4116 : : } else {
4117 : 0 : req->flags |= rte_cpu_to_le_32
4118 : : (HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE);
4119 [ # # ]: 0 : if (speed) {
4120 : 0 : req->force_link_speeds2 =
4121 : : rte_cpu_to_le_16(speed);
4122 : : en |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_FORCE_LINK_SPEEDS2;
4123 : : }
4124 : : }
4125 [ # # ]: 0 : } else if (autoneg == 1 &&
4126 [ # # ]: 0 : (link_info->support_auto_speeds ||
4127 [ # # ]: 0 : link_info->support_pam4_auto_speeds)) {
4128 : 0 : req->flags |= rte_cpu_to_le_32
4129 : : (HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG);
4130 : 0 : req->auto_link_speed_mask = rte_cpu_to_le_16
4131 : : (bnxt_parse_eth_link_speed_mask(bp,
4132 : : dev_conf->link_speeds));
4133 : 0 : req->auto_link_pam4_speed_mask =
4134 : 0 : rte_cpu_to_le_16(link_info->auto_pam4_link_speed_mask);
4135 : : en |= HWRM_PORT_PHY_CFG_IN_EN_AUTO_LINK_SPEED_MASK |
4136 : : HWRM_PORT_PHY_CFG_IN_EN_AUTO_PAM4_LINK_SPD_MASK |
4137 : : HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_MODE;
4138 : 0 : req->auto_mode = HWRM_PORT_PHY_CFG_INPUT_AUTO_MODE_SPEED_MASK;
4139 : : } else {
4140 : 0 : req->flags |= rte_cpu_to_le_32
4141 : : (HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE);
4142 : :
4143 : : /* No requested speed: keep the PHY's current speed rather
4144 : : * than forcing 0.
4145 : : */
4146 [ # # ]: 0 : if (!speed) {
4147 [ # # ]: 0 : if (link_info->force_pam4_link_speed)
4148 : : speed = link_info->force_pam4_link_speed;
4149 [ # # ]: 0 : else if (link_info->force_link_speed)
4150 : : speed = link_info->force_link_speed;
4151 [ # # ]: 0 : else if (link_info->auto_pam4_link_speed_mask)
4152 : : speed = link_info->auto_pam4_link_speed_mask;
4153 [ # # ]: 0 : else if (link_info->support_pam4_speeds)
4154 : : speed = link_info->support_pam4_speeds;
4155 : : else
4156 : 0 : speed = link_info->auto_link_speed;
4157 : : /* Auto PAM4 link speed is zero, but auto_link_speed is
4158 : : * not. Use the auto_link_speed.
4159 : : */
4160 [ # # ]: 0 : if (link_info->auto_link_speed != 0 &&
4161 [ # # ]: 0 : link_info->auto_pam4_link_speed_mask == 0)
4162 : : speed = link_info->auto_link_speed;
4163 : : }
4164 : :
4165 [ # # ]: 0 : if (speed) {
4166 [ # # ]: 0 : if (link_info->link_signal_mode) {
4167 : 0 : req->force_pam4_link_speed =
4168 : : rte_cpu_to_le_16(speed);
4169 : : en |= HWRM_PORT_PHY_CFG_IN_EN_FORCE_PAM4_LINK_SPEED;
4170 : : } else {
4171 : 0 : req->force_link_speed =
4172 : : rte_cpu_to_le_16(speed);
4173 : : }
4174 : : }
4175 : : }
4176 : :
4177 [ # # ]: 0 : req->auto_duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
4178 : 0 : en |= HWRM_PORT_PHY_CFG_INPUT_ENABLES_AUTO_DUPLEX;
4179 : 0 : req->enables |= rte_cpu_to_le_32(en);
4180 : :
4181 : 0 : return 0;
4182 : : }
4183 : :
4184 : 0 : int bnxt_hwrm_set_pause(struct bnxt *bp)
4185 : : {
4186 : 0 : struct hwrm_port_phy_cfg_input req = {0};
4187 : 0 : struct hwrm_port_phy_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4188 : 0 : struct bnxt_link_info *link_info = bp->link_info;
4189 : : bool reconfig;
4190 : : int rc;
4191 : :
4192 : : /* Full reprogram on FC autoneg, or the autoneg->forced transition */
4193 [ # # ]: 0 : reconfig = (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) ||
4194 [ # # ]: 0 : link_info->link_reconfig_needed;
4195 : :
4196 : : /* Validate speeds up front, as bnxt_set_hwrm_link_config() does */
4197 [ # # ]: 0 : if (reconfig) {
4198 : 0 : rc = bnxt_validate_link_speed(bp);
4199 [ # # ]: 0 : if (rc)
4200 : : return rc;
4201 : : }
4202 : :
4203 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_CFG, BNXT_USE_CHIMP_MB);
4204 : :
4205 : 0 : bnxt_hwrm_set_pause_common(bp, &req);
4206 : :
4207 [ # # ]: 0 : if (reconfig) {
4208 : 0 : rc = bnxt_hwrm_set_link_common(bp, &req);
4209 [ # # ]: 0 : if (rc) {
4210 : : HWRM_UNLOCK();
4211 : 0 : return rc;
4212 : : }
4213 : : }
4214 : :
4215 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4216 : :
4217 : : /* HWRM_CHECK_RESULT() returns on any transport or firmware error,
4218 : : * so the state updates below are reached only on success.
4219 : : */
4220 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4221 : :
4222 [ # # ]: 0 : if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)) {
4223 : 0 : link_info->pause = link_info->force_pause;
4224 : 0 : link_info->auto_pause = 0;
4225 : : }
4226 : 0 : link_info->link_reconfig_needed = false;
4227 : :
4228 : : HWRM_UNLOCK();
4229 : 0 : return rc;
4230 : : }
4231 : :
4232 : 0 : static int bnxt_set_hwrm_link_config_v2(struct bnxt *bp, bool link_up)
4233 : : {
4234 [ # # ]: 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
4235 : : struct bnxt_link_info link_req;
4236 : : uint16_t speed, autoneg;
4237 : : int rc = 0;
4238 : :
4239 : : memset(&link_req, 0, sizeof(link_req));
4240 : 0 : link_req.link_up = link_up;
4241 [ # # ]: 0 : if (!link_up)
4242 : 0 : goto port_phy_cfg;
4243 : :
4244 : 0 : autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
4245 : 0 : speed = bnxt_parse_eth_link_speed(bp, dev_conf->link_speeds,
4246 : : bp->link_info);
4247 : 0 : link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
4248 [ # # ]: 0 : if (autoneg == 1) {
4249 : 0 : link_req.phy_flags |=
4250 : : HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
4251 : 0 : link_req.cfg_auto_link_speeds2_mask =
4252 : 0 : bnxt_parse_eth_link_speed_mask(bp, dev_conf->link_speeds);
4253 : : } else {
4254 : 0 : if (bp->link_info->phy_type ==
4255 [ # # ]: 0 : HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
4256 : : bp->link_info->phy_type ==
4257 : 0 : HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
4258 [ # # ]: 0 : bp->link_info->media_type ==
4259 : : HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
4260 : 0 : PMD_DRV_LOG_LINE(ERR, "10GBase-T devices must autoneg");
4261 : 0 : return -EINVAL;
4262 : : }
4263 : :
4264 : 0 : link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
4265 : : /* If user wants a particular speed try that first. */
4266 : 0 : link_req.link_speed = speed;
4267 : : }
4268 [ # # ]: 0 : link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
4269 : 0 : link_req.auto_pause = bp->link_info->auto_pause;
4270 : 0 : link_req.force_pause = bp->link_info->force_pause;
4271 : :
4272 : 0 : port_phy_cfg:
4273 : 0 : rc = bnxt_hwrm_port_phy_cfg_v2(bp, &link_req);
4274 [ # # ]: 0 : if (rc)
4275 : 0 : PMD_DRV_LOG_LINE(ERR, "Set link config failed with rc %d", rc);
4276 : :
4277 : : return rc;
4278 : : }
4279 : :
4280 : 0 : int bnxt_set_hwrm_link_config(struct bnxt *bp, bool link_up)
4281 : : {
4282 : : int rc = 0;
4283 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
4284 : : struct bnxt_link_info link_req;
4285 : : uint16_t speed, autoneg;
4286 : :
4287 [ # # ]: 0 : if (!BNXT_SINGLE_PF(bp) || BNXT_VF(bp))
4288 : : return 0;
4289 : :
4290 : 0 : rc = bnxt_validate_link_speed(bp);
4291 [ # # ]: 0 : if (rc)
4292 : 0 : goto error;
4293 : :
4294 [ # # # # : 0 : if (BNXT_LINK_SPEEDS_V2(bp))
# # # # ]
4295 : 0 : return bnxt_set_hwrm_link_config_v2(bp, link_up);
4296 : :
4297 : : memset(&link_req, 0, sizeof(link_req));
4298 : 0 : link_req.link_up = link_up;
4299 [ # # ]: 0 : if (!link_up)
4300 : 0 : goto port_phy_cfg;
4301 : :
4302 : : /* Get user requested autoneg setting */
4303 : 0 : autoneg = bnxt_check_eth_link_autoneg(dev_conf->link_speeds);
4304 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp) &&
4305 [ # # ]: 0 : dev_conf->link_speeds & RTE_ETH_LINK_SPEED_40G) {
4306 : : /* 40G is not supported as part of media auto detect.
4307 : : * The speed should be forced and autoneg disabled
4308 : : * to configure 40G speed.
4309 : : */
4310 : 0 : PMD_DRV_LOG_LINE(INFO, "Disabling autoneg for 40G");
4311 : : autoneg = 0;
4312 : : }
4313 : :
4314 : : /* Override based on current Autoneg setting in PHY for 200G */
4315 [ # # # # : 0 : if (autoneg == 1 && BNXT_CHIP_P5(bp) && bp->link_info->auto_mode == 0 &&
# # ]
4316 [ # # ]: 0 : bp->link_info->force_pam4_link_speed ==
4317 : : HWRM_PORT_PHY_CFG_INPUT_FORCE_PAM4_LINK_SPEED_200GB) {
4318 : : autoneg = 0;
4319 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Disabling autoneg for 200G");
4320 : : }
4321 : :
4322 : 0 : speed = bnxt_parse_eth_link_speed(bp, dev_conf->link_speeds,
4323 : : bp->link_info);
4324 : 0 : link_req.phy_flags = HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESET_PHY;
4325 : : /* Autoneg can be done only when the FW allows. */
4326 [ # # ]: 0 : if (autoneg == 1 &&
4327 [ # # # # ]: 0 : (bp->link_info->support_auto_speeds || bp->link_info->support_pam4_auto_speeds)) {
4328 : 0 : link_req.phy_flags |=
4329 : : HWRM_PORT_PHY_CFG_INPUT_FLAGS_RESTART_AUTONEG;
4330 : 0 : link_req.auto_link_speed_mask =
4331 : 0 : bnxt_parse_eth_link_speed_mask(bp,
4332 : : dev_conf->link_speeds);
4333 : 0 : link_req.auto_pam4_link_speed_mask =
4334 : 0 : bp->link_info->auto_pam4_link_speed_mask;
4335 : : } else {
4336 : 0 : if (bp->link_info->phy_type ==
4337 [ # # ]: 0 : HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASET ||
4338 : : bp->link_info->phy_type ==
4339 : 0 : HWRM_PORT_PHY_QCFG_OUTPUT_PHY_TYPE_BASETE ||
4340 [ # # ]: 0 : bp->link_info->media_type ==
4341 : : HWRM_PORT_PHY_QCFG_OUTPUT_MEDIA_TYPE_TP) {
4342 : 0 : PMD_DRV_LOG_LINE(ERR, "10GBase-T devices must autoneg");
4343 : 0 : return -EINVAL;
4344 : : }
4345 : :
4346 : 0 : link_req.phy_flags |= HWRM_PORT_PHY_CFG_INPUT_FLAGS_FORCE;
4347 : : /* If user wants a particular speed try that first. */
4348 [ # # ]: 0 : if (speed)
4349 : 0 : link_req.link_speed = speed;
4350 [ # # ]: 0 : else if (bp->link_info->force_pam4_link_speed)
4351 : 0 : link_req.link_speed =
4352 : : bp->link_info->force_pam4_link_speed;
4353 [ # # ]: 0 : else if (bp->link_info->force_link_speed)
4354 : 0 : link_req.link_speed = bp->link_info->force_link_speed;
4355 [ # # ]: 0 : else if (bp->link_info->auto_pam4_link_speed_mask)
4356 : 0 : link_req.link_speed =
4357 : : bp->link_info->auto_pam4_link_speed_mask;
4358 [ # # ]: 0 : else if (bp->link_info->support_pam4_speeds)
4359 : 0 : link_req.link_speed =
4360 : : bp->link_info->support_pam4_speeds;
4361 : : else
4362 : 0 : link_req.link_speed = bp->link_info->auto_link_speed;
4363 : : /* Auto PAM4 link speed is zero, but auto_link_speed is not
4364 : : * zero. Use the auto_link_speed.
4365 : : */
4366 [ # # ]: 0 : if (bp->link_info->auto_link_speed != 0 &&
4367 [ # # ]: 0 : bp->link_info->auto_pam4_link_speed_mask == 0)
4368 : 0 : link_req.link_speed = bp->link_info->auto_link_speed;
4369 : : }
4370 [ # # ]: 0 : link_req.duplex = bnxt_parse_eth_link_duplex(dev_conf->link_speeds);
4371 : 0 : link_req.auto_pause = bp->link_info->auto_pause;
4372 : 0 : link_req.force_pause = bp->link_info->force_pause;
4373 : :
4374 : 0 : port_phy_cfg:
4375 : 0 : rc = bnxt_hwrm_port_phy_cfg(bp, &link_req);
4376 [ # # ]: 0 : if (rc) {
4377 : 0 : PMD_DRV_LOG_LINE(ERR,
4378 : : "Set link config failed with rc %d", rc);
4379 : : }
4380 : :
4381 : 0 : error:
4382 : : return rc;
4383 : : }
4384 : :
4385 : 0 : int bnxt_hwrm_func_qcfg(struct bnxt *bp, uint16_t *mtu)
4386 : : {
4387 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4388 : 0 : struct hwrm_func_qcfg_input req = {0};
4389 : : uint16_t l2_db_multi_kb;
4390 : : uint16_t total_pages;
4391 : : uint16_t svif_info;
4392 : : uint16_t flags;
4393 : : int rc = 0;
4394 : :
4395 : 0 : bp->func_svif = BNXT_SVIF_INVALID;
4396 : :
4397 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4398 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
4399 : :
4400 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4401 : :
4402 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4403 : :
4404 : 0 : bp->vlan = rte_le_to_cpu_16(resp->vlan) & RTE_ETH_VLAN_ID_MAX;
4405 : :
4406 : 0 : svif_info = rte_le_to_cpu_16(resp->svif_info);
4407 [ # # ]: 0 : if (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)
4408 : 0 : bp->func_svif = svif_info &
4409 : : HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
4410 : :
4411 : 0 : flags = rte_le_to_cpu_16(resp->flags);
4412 [ # # # # ]: 0 : if (BNXT_PF(bp) && (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST))
4413 : 0 : bp->flags |= BNXT_FLAG_MULTI_HOST;
4414 : :
4415 [ # # ]: 0 : if (BNXT_VF(bp) &&
4416 [ # # ]: 0 : !BNXT_VF_IS_TRUSTED(bp) &&
4417 : : (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
4418 : 0 : bp->flags |= BNXT_FLAG_TRUSTED_VF_EN;
4419 : 0 : PMD_DRV_LOG_LINE(INFO, "Trusted VF cap enabled");
4420 [ # # ]: 0 : } else if (BNXT_VF(bp) &&
4421 [ # # ]: 0 : BNXT_VF_IS_TRUSTED(bp) &&
4422 : : !(flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_TRUSTED_VF)) {
4423 : 0 : bp->flags &= ~BNXT_FLAG_TRUSTED_VF_EN;
4424 : 0 : PMD_DRV_LOG_LINE(INFO, "Trusted VF cap disabled");
4425 : : }
4426 : :
4427 [ # # ]: 0 : if (mtu)
4428 : 0 : *mtu = rte_le_to_cpu_16(resp->admin_mtu);
4429 : :
4430 [ # # ]: 0 : switch (resp->port_partition_type) {
4431 : 0 : case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_0:
4432 : : case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR1_5:
4433 : : case HWRM_FUNC_QCFG_OUTPUT_PORT_PARTITION_TYPE_NPAR2_0:
4434 : : /* FALLTHROUGH */
4435 : 0 : bp->flags |= BNXT_FLAG_NPAR_PF;
4436 : 0 : break;
4437 : 0 : default:
4438 : 0 : bp->flags &= ~BNXT_FLAG_NPAR_PF;
4439 : 0 : break;
4440 : : }
4441 : 0 : bp->legacy_db_size =
4442 : 0 : BNXT_KB_TO_BYTES(rte_le_to_cpu_16(resp->legacy_l2_db_size_kb));
4443 : :
4444 : : /* Configure multi-doorbell if supported */
4445 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_MULTI_DB) {
4446 : 0 : l2_db_multi_kb = rte_le_to_cpu_16(resp->l2_db_multi_page_size_kb);
4447 [ # # ]: 0 : bp->l2_db_multi_page_size_kb = l2_db_multi_kb ? l2_db_multi_kb :
4448 : : rte_le_to_cpu_16(resp->l2_doorbell_bar_size_kb);
4449 : :
4450 [ # # ]: 0 : if (bp->l2_db_multi_page_size_kb > 0) {
4451 : 0 : bp->db_page_size = BNXT_DEFAULT_DB_PAGE_SIZE;
4452 : 0 : total_pages = BNXT_KB_TO_BYTES(bp->l2_db_multi_page_size_kb) /
4453 : : bp->db_page_size;
4454 : :
4455 : : /* P7: DPI 0=legacy, DPI 1=push reserved; P5: DPI 0=legacy */
4456 [ # # ]: 0 : bp->nq_dpi_start = BNXT_CHIP_P7(bp) ?
4457 : : BNXT_RESERVED_DPI_TWO : BNXT_RESERVED_DPI_ONE;
4458 [ # # ]: 0 : bp->nq_dpi_count = (total_pages > bp->nq_dpi_start) ?
4459 : 0 : (total_pages - bp->nq_dpi_start) : 0;
4460 : 0 : bp->nq_dpi_counter = 0;
4461 : 0 : PMD_DRV_LOG_LINE(INFO,
4462 : : "Multi-doorbell: %u KB, "
4463 : : "DPI range %u-%u (%u pages)",
4464 : : bp->l2_db_multi_page_size_kb,
4465 : : bp->nq_dpi_start,
4466 : : bp->nq_dpi_start + bp->nq_dpi_count - 1,
4467 : : bp->nq_dpi_count);
4468 : : } else {
4469 : 0 : PMD_DRV_LOG_LINE(INFO,
4470 : : "Multi-doorbell supported "
4471 : : "but no pages allocated");
4472 : : }
4473 : : }
4474 : :
4475 : : HWRM_UNLOCK();
4476 : :
4477 : 0 : return rc;
4478 : : }
4479 : :
4480 : 0 : int bnxt_hwrm_parent_pf_qcfg(struct bnxt *bp)
4481 : : {
4482 : 0 : struct hwrm_func_qcfg_input req = {0};
4483 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4484 : : uint16_t flags;
4485 : : int rc;
4486 : :
4487 [ # # ]: 0 : if (!BNXT_VF_IS_TRUSTED(bp))
4488 : : return 0;
4489 : :
4490 [ # # ]: 0 : if (!bp->parent)
4491 : : return -EINVAL;
4492 : :
4493 : 0 : bp->parent->fid = BNXT_PF_FID_INVALID;
4494 : :
4495 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4496 : :
4497 : 0 : req.fid = rte_cpu_to_le_16(0xfffe); /* Request parent PF information. */
4498 : :
4499 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4500 : :
4501 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
4502 : :
4503 [ # # ]: 0 : memcpy(bp->parent->mac_addr, resp->mac_address, RTE_ETHER_ADDR_LEN);
4504 : 0 : bp->parent->vnic = rte_le_to_cpu_16(resp->dflt_vnic_id);
4505 : 0 : bp->parent->fid = rte_le_to_cpu_16(resp->fid);
4506 : 0 : bp->parent->port_id = rte_le_to_cpu_16(resp->port_id);
4507 : :
4508 : 0 : flags = rte_le_to_cpu_16(resp->flags);
4509 : :
4510 : : /* check for the mulit-host support */
4511 [ # # ]: 0 : if (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_HOST) {
4512 : 0 : bp->flags |= BNXT_FLAG_MULTI_HOST;
4513 : 0 : bp->multi_host_pf_pci_id = resp->pci_id;
4514 : 0 : PMD_DRV_LOG_LINE(INFO, "Mult-Host system Parent PCI-ID: 0x%x", resp->pci_id);
4515 : : }
4516 : :
4517 : : /* check for the multi-root support */
4518 [ # # ]: 0 : if (flags & HWRM_FUNC_QCFG_OUTPUT_FLAGS_MULTI_ROOT) {
4519 : 0 : bp->flags2 |= BNXT_FLAGS2_MULTIROOT_EN;
4520 : 0 : PMD_DRV_LOG_LINE(DEBUG, "PF enabled with multi root capability");
4521 : : }
4522 : :
4523 : : HWRM_UNLOCK();
4524 : :
4525 : 0 : return 0;
4526 : : }
4527 : :
4528 : 0 : static int bnxt_hwrm_set_tpa(struct bnxt *bp)
4529 : : {
4530 : 0 : struct rte_eth_conf *dev_conf = &bp->eth_dev->data->dev_conf;
4531 : 0 : uint64_t rx_offloads = dev_conf->rxmode.offloads;
4532 : : bool tpa_flags = 0;
4533 : : int rc, i;
4534 : :
4535 [ # # # # ]: 0 : if (!BNXT_SUPPORTS_TPA(bp))
4536 : : return 0;
4537 : :
4538 : 0 : tpa_flags = (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) ? true : false;
4539 [ # # ]: 0 : for (i = 0; i < bp->max_vnics; i++) {
4540 : 0 : struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
4541 : :
4542 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
4543 : 0 : continue;
4544 : :
4545 : 0 : rc = bnxt_hwrm_vnic_tpa_cfg(bp, vnic, tpa_flags);
4546 [ # # ]: 0 : if (rc)
4547 : 0 : return rc;
4548 : : }
4549 : : return 0;
4550 : : }
4551 : :
4552 : 0 : int bnxt_hwrm_get_dflt_vnic_svif(struct bnxt *bp, uint16_t fid,
4553 : : uint16_t *vnic_id, uint16_t *svif)
4554 : : {
4555 : 0 : struct hwrm_func_qcfg_input req = {0};
4556 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4557 : : uint16_t svif_info;
4558 : : int rc = 0;
4559 : :
4560 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4561 : 0 : req.fid = rte_cpu_to_le_16(fid);
4562 : :
4563 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4564 : :
4565 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4566 : :
4567 : 0 : svif_info = rte_le_to_cpu_16(resp->svif_info);
4568 [ # # ]: 0 : if (svif && (svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_VALID)) {
4569 : 0 : *svif = svif_info & HWRM_FUNC_QCFG_OUTPUT_SVIF_INFO_SVIF_MASK;
4570 : : /* When the VF corresponding to the VFR is down at the time of
4571 : : * VFR conduit creation, the VFR rule will be programmed with
4572 : : * invalid vnic id because FW will return default vnic id as
4573 : : * INVALID when queried through FUNC_QCFG. As a result, when
4574 : : * the VF is brought up, VF won't receive packets because
4575 : : * INVALID vnic id is already programmed.
4576 : : *
4577 : : * Hence, use svif value as vnic id during VFR conduit creation
4578 : : * as both svif and default vnic id values are same and will
4579 : : * never change.
4580 : : */
4581 [ # # ]: 0 : if (vnic_id)
4582 : 0 : *vnic_id = *svif;
4583 : : } else {
4584 : : rc = -EINVAL;
4585 : : }
4586 : :
4587 : : HWRM_UNLOCK();
4588 : :
4589 : 0 : bnxt_hwrm_set_tpa(bp);
4590 : :
4591 : 0 : return rc;
4592 : : }
4593 : :
4594 : 0 : int bnxt_hwrm_port_mac_qcfg(struct bnxt *bp)
4595 : : {
4596 : 0 : struct hwrm_port_mac_qcfg_input req = {0};
4597 : 0 : struct hwrm_port_mac_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4598 : : uint16_t port_svif_info;
4599 : : int rc;
4600 : :
4601 : 0 : bp->port_svif = BNXT_SVIF_INVALID;
4602 : :
4603 [ # # ]: 0 : if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
4604 : : return 0;
4605 : :
4606 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_MAC_QCFG, BNXT_USE_CHIMP_MB);
4607 : :
4608 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4609 : :
4610 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
4611 : :
4612 : 0 : port_svif_info = rte_le_to_cpu_16(resp->port_svif_info);
4613 [ # # ]: 0 : if (port_svif_info &
4614 : : HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_VALID)
4615 : 0 : bp->port_svif = port_svif_info &
4616 : : HWRM_PORT_MAC_QCFG_OUTPUT_PORT_SVIF_INFO_PORT_SVIF_MASK;
4617 : :
4618 : : HWRM_UNLOCK();
4619 : :
4620 : 0 : return 0;
4621 : : }
4622 : :
4623 : 0 : static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp,
4624 : : struct bnxt_pf_resource_info *pf_resc)
4625 : : {
4626 : 0 : struct hwrm_func_cfg_input req = {0};
4627 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4628 : : uint32_t enables;
4629 : : int rc;
4630 : :
4631 : : enables = HWRM_FUNC_CFG_INPUT_ENABLES_ADMIN_MTU |
4632 : : HWRM_FUNC_CFG_INPUT_ENABLES_HOST_MTU |
4633 : : HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
4634 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
4635 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
4636 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
4637 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
4638 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
4639 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
4640 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS;
4641 : :
4642 [ # # ]: 0 : if (BNXT_HAS_RING_GRPS(bp)) {
4643 : : enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS;
4644 : 0 : req.num_hw_ring_grps =
4645 : 0 : rte_cpu_to_le_16(pf_resc->num_hw_ring_grps);
4646 : : } else if (BNXT_HAS_NQ(bp)) {
4647 : : enables |= HWRM_FUNC_CFG_INPUT_ENABLES_NUM_MSIX;
4648 : 0 : req.num_msix = rte_cpu_to_le_16(pf_resc->num_nq_rings);
4649 : : }
4650 : :
4651 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
4652 : 0 : req.admin_mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
4653 : 0 : req.host_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu);
4654 : 0 : req.mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
4655 : 0 : req.num_rsscos_ctxs = rte_cpu_to_le_16(pf_resc->num_rsscos_ctxs);
4656 : 0 : req.num_stat_ctxs = rte_cpu_to_le_16(pf_resc->num_stat_ctxs);
4657 : 0 : req.num_cmpl_rings = rte_cpu_to_le_16(pf_resc->num_cp_rings);
4658 : 0 : req.num_tx_rings = rte_cpu_to_le_16(pf_resc->num_tx_rings);
4659 : 0 : req.num_rx_rings = rte_cpu_to_le_16(pf_resc->num_rx_rings);
4660 : 0 : req.num_l2_ctxs = rte_cpu_to_le_16(pf_resc->num_l2_ctxs);
4661 : 0 : req.num_vnics = rte_cpu_to_le_16(pf_resc->num_vnics);
4662 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
4663 : 0 : req.enables = rte_cpu_to_le_32(enables);
4664 : :
4665 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
4666 : :
4667 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4668 : :
4669 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4670 : : HWRM_UNLOCK();
4671 : :
4672 : 0 : return rc;
4673 : : }
4674 : :
4675 : : /* min values are the guaranteed resources and max values are subject
4676 : : * to availability. The strategy for now is to keep both min & max
4677 : : * values the same.
4678 : : */
4679 : : static void
4680 : 0 : bnxt_fill_vf_func_cfg_req_new(struct bnxt *bp,
4681 : : struct hwrm_func_vf_resource_cfg_input *req,
4682 : : int num_vfs)
4683 : : {
4684 : 0 : req->max_rsscos_ctx = rte_cpu_to_le_16(bp->max_rsscos_ctx /
4685 : : (num_vfs + 1));
4686 : 0 : req->min_rsscos_ctx = req->max_rsscos_ctx;
4687 : 0 : req->max_stat_ctx = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
4688 : 0 : req->min_stat_ctx = req->max_stat_ctx;
4689 : 0 : req->max_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
4690 : : (num_vfs + 1));
4691 : 0 : req->min_cmpl_rings = req->max_cmpl_rings;
4692 : 0 : req->max_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
4693 : 0 : req->min_tx_rings = req->max_tx_rings;
4694 : 0 : req->max_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
4695 : 0 : req->min_rx_rings = req->max_rx_rings;
4696 : 0 : req->max_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
4697 : 0 : req->min_l2_ctxs = req->max_l2_ctxs;
4698 : 0 : req->max_vnics = rte_cpu_to_le_16(bp->max_vnics / (num_vfs + 1));
4699 : 0 : req->min_vnics = req->max_vnics;
4700 : 0 : req->max_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
4701 : : (num_vfs + 1));
4702 : 0 : req->min_hw_ring_grps = req->max_hw_ring_grps;
4703 : 0 : req->max_msix = rte_cpu_to_le_16(bp->max_nq_rings / (num_vfs + 1));
4704 : 0 : }
4705 : :
4706 : : static void
4707 : 0 : bnxt_fill_vf_func_cfg_req_old(struct bnxt *bp,
4708 : : struct hwrm_func_cfg_input *req,
4709 : : int num_vfs)
4710 : : {
4711 : 0 : req->enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_ADMIN_MTU |
4712 : : HWRM_FUNC_CFG_INPUT_ENABLES_MRU |
4713 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RSSCOS_CTXS |
4714 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_STAT_CTXS |
4715 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_CMPL_RINGS |
4716 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_TX_RINGS |
4717 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_RX_RINGS |
4718 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_L2_CTXS |
4719 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
4720 : : HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
4721 : :
4722 : 0 : req->admin_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
4723 : : RTE_ETHER_CRC_LEN + RTE_VLAN_HLEN *
4724 : : BNXT_NUM_VLANS);
4725 : 0 : req->mru = rte_cpu_to_le_16(BNXT_VNIC_MRU(bp->eth_dev->data->mtu));
4726 : 0 : req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
4727 : : (num_vfs + 1));
4728 : 0 : req->num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx / (num_vfs + 1));
4729 : 0 : req->num_cmpl_rings = rte_cpu_to_le_16(bp->max_cp_rings /
4730 : : (num_vfs + 1));
4731 : 0 : req->num_tx_rings = rte_cpu_to_le_16(bp->max_tx_rings / (num_vfs + 1));
4732 : 0 : req->num_rx_rings = rte_cpu_to_le_16(bp->max_rx_rings / (num_vfs + 1));
4733 : 0 : req->num_l2_ctxs = rte_cpu_to_le_16(bp->max_l2_ctx / (num_vfs + 1));
4734 : : /* TODO: For now, do not support VMDq/RFS on VFs. */
4735 : 0 : req->num_vnics = rte_cpu_to_le_16(1);
4736 : 0 : req->num_hw_ring_grps = rte_cpu_to_le_16(bp->max_ring_grps /
4737 : : (num_vfs + 1));
4738 : 0 : }
4739 : :
4740 : : /* Update the port wide resource values based on how many resources
4741 : : * got allocated to the VF.
4742 : : */
4743 : 0 : static int bnxt_update_max_resources(struct bnxt *bp,
4744 : : int vf)
4745 : : {
4746 : 0 : struct hwrm_func_qcfg_input req = {0};
4747 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4748 : : int rc;
4749 : :
4750 : : /* Get the actual allocated values now */
4751 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4752 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
4753 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4754 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4755 : :
4756 : 0 : bp->max_rsscos_ctx -= rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
4757 : 0 : bp->max_stat_ctx -= rte_le_to_cpu_16(resp->alloc_stat_ctx);
4758 : 0 : bp->max_cp_rings -= rte_le_to_cpu_16(resp->alloc_cmpl_rings);
4759 : 0 : bp->max_tx_rings -= rte_le_to_cpu_16(resp->alloc_tx_rings);
4760 : 0 : bp->max_rx_rings -= rte_le_to_cpu_16(resp->alloc_rx_rings);
4761 : 0 : bp->max_l2_ctx -= rte_le_to_cpu_16(resp->alloc_l2_ctx);
4762 : 0 : bp->max_ring_grps -= rte_le_to_cpu_16(resp->alloc_hw_ring_grps);
4763 : 0 : bp->max_nq_rings -= rte_le_to_cpu_16(resp->alloc_msix);
4764 : 0 : bp->max_vnics -= rte_le_to_cpu_16(resp->alloc_vnics);
4765 : :
4766 : : HWRM_UNLOCK();
4767 : :
4768 : 0 : return 0;
4769 : : }
4770 : :
4771 : : /* Update the PF resource values based on how many resources
4772 : : * got allocated to it.
4773 : : */
4774 : 0 : static int bnxt_update_max_resources_pf_only(struct bnxt *bp)
4775 : : {
4776 : 0 : struct hwrm_func_qcfg_input req = {0};
4777 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4778 : : int rc;
4779 : :
4780 : : /* Get the actual allocated values now */
4781 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4782 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
4783 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4784 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4785 : :
4786 : 0 : bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
4787 : 0 : bp->max_stat_ctx = rte_le_to_cpu_16(resp->alloc_stat_ctx);
4788 : 0 : bp->max_cp_rings = rte_le_to_cpu_16(resp->alloc_cmpl_rings);
4789 : 0 : bp->max_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
4790 : 0 : bp->max_rx_rings = rte_le_to_cpu_16(resp->alloc_rx_rings);
4791 : 0 : bp->max_l2_ctx = rte_le_to_cpu_16(resp->alloc_l2_ctx);
4792 : 0 : bp->max_ring_grps = rte_le_to_cpu_16(resp->alloc_hw_ring_grps);
4793 : 0 : bp->max_vnics = rte_le_to_cpu_16(resp->alloc_vnics);
4794 : :
4795 : : HWRM_UNLOCK();
4796 : :
4797 : 0 : return 0;
4798 : : }
4799 : :
4800 : 0 : int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
4801 : : {
4802 : 0 : struct hwrm_func_qcfg_input req = {0};
4803 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4804 : : int rc;
4805 : :
4806 : : /* Check for zero MAC address */
4807 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4808 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
4809 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4810 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4811 : 0 : rc = rte_le_to_cpu_16(resp->vlan);
4812 : :
4813 : : HWRM_UNLOCK();
4814 : :
4815 : 0 : return rc;
4816 : : }
4817 : :
4818 : 0 : static int bnxt_query_pf_resources(struct bnxt *bp,
4819 : : struct bnxt_pf_resource_info *pf_resc)
4820 : : {
4821 : 0 : struct hwrm_func_qcfg_input req = {0};
4822 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
4823 : : int rc;
4824 : :
4825 : : /* And copy the allocated numbers into the pf struct */
4826 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
4827 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
4828 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
4829 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
4830 : :
4831 : 0 : pf_resc->num_tx_rings = rte_le_to_cpu_16(resp->alloc_tx_rings);
4832 : 0 : pf_resc->num_rsscos_ctxs = rte_le_to_cpu_16(resp->alloc_rsscos_ctx);
4833 : 0 : pf_resc->num_stat_ctxs = rte_le_to_cpu_16(resp->alloc_stat_ctx);
4834 : 0 : pf_resc->num_cp_rings = rte_le_to_cpu_16(resp->alloc_cmpl_rings);
4835 : 0 : pf_resc->num_rx_rings = rte_le_to_cpu_16(resp->alloc_rx_rings);
4836 : 0 : pf_resc->num_l2_ctxs = rte_le_to_cpu_16(resp->alloc_l2_ctx);
4837 : 0 : pf_resc->num_hw_ring_grps = rte_le_to_cpu_32(resp->alloc_hw_ring_grps);
4838 : 0 : pf_resc->num_nq_rings = rte_le_to_cpu_32(resp->alloc_msix);
4839 : 0 : pf_resc->num_vnics = rte_le_to_cpu_16(resp->alloc_vnics);
4840 : 0 : bp->pf->evb_mode = resp->evb_mode;
4841 : :
4842 : : HWRM_UNLOCK();
4843 : :
4844 : 0 : return rc;
4845 : : }
4846 : :
4847 : : static void
4848 : 0 : bnxt_calculate_pf_resources(struct bnxt *bp,
4849 : : struct bnxt_pf_resource_info *pf_resc,
4850 : : int num_vfs)
4851 : : {
4852 [ # # ]: 0 : if (!num_vfs) {
4853 : 0 : pf_resc->num_rsscos_ctxs = bp->max_rsscos_ctx;
4854 : 0 : pf_resc->num_stat_ctxs = bp->max_stat_ctx;
4855 : 0 : pf_resc->num_cp_rings = bp->max_cp_rings;
4856 : 0 : pf_resc->num_tx_rings = bp->max_tx_rings;
4857 : 0 : pf_resc->num_rx_rings = bp->max_rx_rings;
4858 : 0 : pf_resc->num_l2_ctxs = bp->max_l2_ctx;
4859 : 0 : pf_resc->num_hw_ring_grps = bp->max_ring_grps;
4860 : 0 : pf_resc->num_nq_rings = bp->max_nq_rings;
4861 : 0 : pf_resc->num_vnics = bp->max_vnics;
4862 : :
4863 : 0 : return;
4864 : : }
4865 : :
4866 : 0 : pf_resc->num_rsscos_ctxs = bp->max_rsscos_ctx / (num_vfs + 1) +
4867 : 0 : bp->max_rsscos_ctx % (num_vfs + 1);
4868 : 0 : pf_resc->num_stat_ctxs = bp->max_stat_ctx / (num_vfs + 1) +
4869 : 0 : bp->max_stat_ctx % (num_vfs + 1);
4870 : 0 : pf_resc->num_cp_rings = bp->max_cp_rings / (num_vfs + 1) +
4871 : 0 : bp->max_cp_rings % (num_vfs + 1);
4872 : 0 : pf_resc->num_tx_rings = bp->max_tx_rings / (num_vfs + 1) +
4873 : 0 : bp->max_tx_rings % (num_vfs + 1);
4874 : 0 : pf_resc->num_rx_rings = bp->max_rx_rings / (num_vfs + 1) +
4875 : 0 : bp->max_rx_rings % (num_vfs + 1);
4876 : 0 : pf_resc->num_l2_ctxs = bp->max_l2_ctx / (num_vfs + 1) +
4877 : 0 : bp->max_l2_ctx % (num_vfs + 1);
4878 : 0 : pf_resc->num_hw_ring_grps = bp->max_ring_grps / (num_vfs + 1) +
4879 : 0 : bp->max_ring_grps % (num_vfs + 1);
4880 : 0 : pf_resc->num_nq_rings = bp->max_nq_rings / (num_vfs + 1) +
4881 : 0 : bp->max_nq_rings % (num_vfs + 1);
4882 : 0 : pf_resc->num_vnics = bp->max_vnics / (num_vfs + 1) +
4883 : 0 : bp->max_vnics % (num_vfs + 1);
4884 : : }
4885 : :
4886 : 0 : int bnxt_hwrm_allocate_pf_only(struct bnxt *bp)
4887 : : {
4888 : 0 : struct bnxt_pf_resource_info pf_resc = { 0 };
4889 : : int rc;
4890 : :
4891 [ # # ]: 0 : if (!BNXT_PF(bp)) {
4892 : 0 : PMD_DRV_LOG_LINE(ERR, "Attempt to allocate VFs on a VF!");
4893 : 0 : return -EINVAL;
4894 : : }
4895 : :
4896 : 0 : rc = bnxt_hwrm_func_qcaps(bp);
4897 [ # # ]: 0 : if (rc)
4898 : : return rc;
4899 : :
4900 : : bnxt_calculate_pf_resources(bp, &pf_resc, 0);
4901 : :
4902 : 0 : bp->pf->func_cfg_flags &=
4903 : : ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
4904 : : HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
4905 : 0 : bp->pf->func_cfg_flags |=
4906 : : HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE;
4907 : :
4908 : 0 : rc = bnxt_hwrm_pf_func_cfg(bp, &pf_resc);
4909 [ # # ]: 0 : if (rc)
4910 : : return rc;
4911 : :
4912 : 0 : rc = bnxt_update_max_resources_pf_only(bp);
4913 : :
4914 : 0 : return rc;
4915 : : }
4916 : :
4917 : : static int
4918 : 0 : bnxt_configure_vf_req_buf(struct bnxt *bp, int num_vfs)
4919 : : {
4920 : : size_t req_buf_sz, sz;
4921 : : int i, rc;
4922 : :
4923 : 0 : req_buf_sz = num_vfs * HWRM_MAX_REQ_LEN;
4924 : 0 : bp->pf->vf_req_buf = rte_malloc("bnxt_vf_fwd", req_buf_sz,
4925 : : page_roundup(num_vfs * HWRM_MAX_REQ_LEN));
4926 [ # # ]: 0 : if (bp->pf->vf_req_buf == NULL) {
4927 : : return -ENOMEM;
4928 : : }
4929 : :
4930 [ # # ]: 0 : for (sz = 0; sz < req_buf_sz; sz += getpagesize())
4931 : 0 : rte_mem_lock_page(((char *)bp->pf->vf_req_buf) + sz);
4932 : :
4933 [ # # ]: 0 : for (i = 0; i < num_vfs; i++)
4934 : 0 : bp->pf->vf_info[i].req_buf = ((char *)bp->pf->vf_req_buf) +
4935 : 0 : (i * HWRM_MAX_REQ_LEN);
4936 : :
4937 : 0 : rc = bnxt_hwrm_func_buf_rgtr(bp, num_vfs);
4938 [ # # ]: 0 : if (rc)
4939 : 0 : rte_free(bp->pf->vf_req_buf);
4940 : :
4941 : : return rc;
4942 : : }
4943 : :
4944 : : static int
4945 : 0 : bnxt_process_vf_resc_config_new(struct bnxt *bp, int num_vfs)
4946 : : {
4947 : 0 : struct hwrm_func_vf_resource_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4948 : 0 : struct hwrm_func_vf_resource_cfg_input req = {0};
4949 : : int i, rc = 0;
4950 : :
4951 : 0 : bnxt_fill_vf_func_cfg_req_new(bp, &req, num_vfs);
4952 : 0 : bp->pf->active_vfs = 0;
4953 [ # # ]: 0 : for (i = 0; i < num_vfs; i++) {
4954 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_VF_RESOURCE_CFG, BNXT_USE_CHIMP_MB);
4955 : 0 : req.vf_id = rte_cpu_to_le_16(bp->pf->vf_info[i].fid);
4956 : 0 : rc = bnxt_hwrm_send_message(bp,
4957 : : &req,
4958 : : sizeof(req),
4959 : : BNXT_USE_CHIMP_MB);
4960 [ # # # # ]: 0 : if (rc || resp->error_code) {
4961 : 0 : PMD_DRV_LOG_LINE(ERR,
4962 : : "Failed to initialize VF %d", i);
4963 : 0 : PMD_DRV_LOG_LINE(ERR,
4964 : : "Not all VFs available. (%d, %d)",
4965 : : rc, resp->error_code);
4966 : : HWRM_UNLOCK();
4967 : :
4968 : : /* If the first VF configuration itself fails,
4969 : : * unregister the vf_fwd_request buffer.
4970 : : */
4971 [ # # ]: 0 : if (i == 0)
4972 : 0 : bnxt_hwrm_func_buf_unrgtr(bp);
4973 : : break;
4974 : : }
4975 : : HWRM_UNLOCK();
4976 : :
4977 : : /* Update the max resource values based on the resource values
4978 : : * allocated to the VF.
4979 : : */
4980 : 0 : bnxt_update_max_resources(bp, i);
4981 : 0 : bp->pf->active_vfs++;
4982 : 0 : bnxt_hwrm_func_clr_stats(bp, bp->pf->vf_info[i].fid);
4983 : : }
4984 : :
4985 : : return 0;
4986 : : }
4987 : :
4988 : : static int
4989 : 0 : bnxt_process_vf_resc_config_old(struct bnxt *bp, int num_vfs)
4990 : : {
4991 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
4992 : 0 : struct hwrm_func_cfg_input req = {0};
4993 : : int i, rc;
4994 : :
4995 : 0 : bnxt_fill_vf_func_cfg_req_old(bp, &req, num_vfs);
4996 : :
4997 : 0 : bp->pf->active_vfs = 0;
4998 [ # # ]: 0 : for (i = 0; i < num_vfs; i++) {
4999 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5000 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->vf_info[i].func_cfg_flags);
5001 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[i].fid);
5002 : 0 : rc = bnxt_hwrm_send_message(bp,
5003 : : &req,
5004 : : sizeof(req),
5005 : : BNXT_USE_CHIMP_MB);
5006 : :
5007 : : /* Clear enable flag for next pass */
5008 : 0 : req.enables &= ~rte_cpu_to_le_32(
5009 : : HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
5010 : :
5011 [ # # # # ]: 0 : if (rc || resp->error_code) {
5012 : 0 : PMD_DRV_LOG_LINE(ERR,
5013 : : "Failed to initialize VF %d", i);
5014 : 0 : PMD_DRV_LOG_LINE(ERR,
5015 : : "Not all VFs available. (%d, %d)",
5016 : : rc, resp->error_code);
5017 : : HWRM_UNLOCK();
5018 : :
5019 : : /* If the first VF configuration itself fails,
5020 : : * unregister the vf_fwd_request buffer.
5021 : : */
5022 [ # # ]: 0 : if (i == 0)
5023 : 0 : bnxt_hwrm_func_buf_unrgtr(bp);
5024 : : break;
5025 : : }
5026 : :
5027 : : HWRM_UNLOCK();
5028 : :
5029 : : /* Update the max resource values based on the resource values
5030 : : * allocated to the VF.
5031 : : */
5032 : 0 : bnxt_update_max_resources(bp, i);
5033 : 0 : bp->pf->active_vfs++;
5034 : 0 : bnxt_hwrm_func_clr_stats(bp, bp->pf->vf_info[i].fid);
5035 : : }
5036 : :
5037 : : return 0;
5038 : : }
5039 : :
5040 : : static void
5041 : 0 : bnxt_configure_vf_resources(struct bnxt *bp, int num_vfs)
5042 : : {
5043 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_NEW_RM)
5044 : 0 : bnxt_process_vf_resc_config_new(bp, num_vfs);
5045 : : else
5046 : 0 : bnxt_process_vf_resc_config_old(bp, num_vfs);
5047 : 0 : }
5048 : :
5049 : : static void
5050 : : bnxt_update_pf_resources(struct bnxt *bp,
5051 : : struct bnxt_pf_resource_info *pf_resc)
5052 : : {
5053 : 0 : bp->max_rsscos_ctx = pf_resc->num_rsscos_ctxs;
5054 : 0 : bp->max_stat_ctx = pf_resc->num_stat_ctxs;
5055 : 0 : bp->max_cp_rings = pf_resc->num_cp_rings;
5056 : 0 : bp->max_tx_rings = pf_resc->num_tx_rings;
5057 : 0 : bp->max_rx_rings = pf_resc->num_rx_rings;
5058 : 0 : bp->max_ring_grps = pf_resc->num_hw_ring_grps;
5059 : 0 : bp->max_nq_rings = pf_resc->num_nq_rings;
5060 : 0 : bp->max_vnics = pf_resc->num_vnics;
5061 : : }
5062 : :
5063 : : static int32_t
5064 : : bnxt_configure_pf_resources(struct bnxt *bp,
5065 : : struct bnxt_pf_resource_info *pf_resc)
5066 : : {
5067 : : /*
5068 : : * We're using STD_TX_RING_MODE here which will limit the TX
5069 : : * rings. This will allow QoS to function properly. Not setting this
5070 : : * will cause PF rings to break bandwidth settings.
5071 : : */
5072 : 0 : bp->pf->func_cfg_flags &=
5073 : : ~(HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE |
5074 : : HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_DISABLE);
5075 : 0 : bp->pf->func_cfg_flags |=
5076 : : HWRM_FUNC_CFG_INPUT_FLAGS_STD_TX_RING_MODE_ENABLE;
5077 : 0 : return bnxt_hwrm_pf_func_cfg(bp, pf_resc);
5078 : : }
5079 : :
5080 : 0 : int bnxt_hwrm_allocate_vfs(struct bnxt *bp, int num_vfs)
5081 : : {
5082 : 0 : struct bnxt_pf_resource_info pf_resc = { 0 };
5083 : : int rc;
5084 : :
5085 [ # # ]: 0 : if (!BNXT_PF(bp)) {
5086 : 0 : PMD_DRV_LOG_LINE(ERR, "Attempt to allocate VFs on a VF!");
5087 : 0 : return -EINVAL;
5088 : : }
5089 : :
5090 : 0 : rc = bnxt_hwrm_func_qcaps(bp);
5091 [ # # ]: 0 : if (rc)
5092 : : return rc;
5093 : :
5094 : 0 : bnxt_calculate_pf_resources(bp, &pf_resc, num_vfs);
5095 : :
5096 : : rc = bnxt_configure_pf_resources(bp, &pf_resc);
5097 [ # # ]: 0 : if (rc)
5098 : : return rc;
5099 : :
5100 : 0 : rc = bnxt_query_pf_resources(bp, &pf_resc);
5101 [ # # ]: 0 : if (rc)
5102 : : return rc;
5103 : :
5104 : : /*
5105 : : * Now, create and register a buffer to hold forwarded VF requests
5106 : : */
5107 : 0 : rc = bnxt_configure_vf_req_buf(bp, num_vfs);
5108 [ # # ]: 0 : if (rc)
5109 : : return rc;
5110 : :
5111 : 0 : bnxt_configure_vf_resources(bp, num_vfs);
5112 : :
5113 : : bnxt_update_pf_resources(bp, &pf_resc);
5114 : :
5115 : 0 : return 0;
5116 : : }
5117 : :
5118 : 0 : int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
5119 : : {
5120 : 0 : struct hwrm_func_cfg_input req = {0};
5121 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5122 : : int rc;
5123 : :
5124 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5125 : :
5126 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
5127 : 0 : req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
5128 : 0 : req.evb_mode = bp->pf->evb_mode;
5129 : :
5130 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5131 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5132 : : HWRM_UNLOCK();
5133 : :
5134 : 0 : return rc;
5135 : : }
5136 : :
5137 : 0 : int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
5138 : : uint8_t tunnel_type)
5139 : : {
5140 : 0 : struct hwrm_tunnel_dst_port_alloc_input req = {0};
5141 : 0 : struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr;
5142 : : int rc = 0;
5143 : :
5144 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_ALLOC, BNXT_USE_CHIMP_MB);
5145 : 0 : req.tunnel_type = tunnel_type;
5146 [ # # ]: 0 : req.tunnel_dst_port_val = rte_cpu_to_be_16(port);
5147 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5148 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5149 : :
5150 [ # # # # : 0 : switch (tunnel_type) {
# # ]
5151 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN:
5152 : 0 : bp->vxlan_fw_dst_port_id =
5153 : 0 : rte_le_to_cpu_16(resp->tunnel_dst_port_id);
5154 : 0 : bp->vxlan_port = port;
5155 : 0 : break;
5156 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_GENEVE:
5157 : 0 : bp->geneve_fw_dst_port_id =
5158 : 0 : rte_le_to_cpu_16(resp->tunnel_dst_port_id);
5159 : 0 : bp->geneve_port = port;
5160 : 0 : break;
5161 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI:
5162 : 0 : bp->ecpri_fw_dst_port_id =
5163 : 0 : rte_le_to_cpu_16(resp->tunnel_dst_port_id);
5164 : 0 : bp->ecpri_port = port;
5165 : 0 : bp->ecpri_upar_in_use = resp->upar_in_use;
5166 : 0 : break;
5167 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE:
5168 : 0 : bp->l2_etype_tunnel_id = port;
5169 : 0 : bp->l2_etype_upar_in_use = resp->upar_in_use;
5170 : 0 : break;
5171 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_VXLAN_V4:
5172 : 0 : bp->vxlan_ip_upar_in_use = resp->upar_in_use;
5173 : 0 : bp->vxlan_ip_port = port;
5174 : 0 : PMD_DRV_LOG_LINE(DEBUG, "vxlan_ip_upar_in_use %x port %x",
5175 : : bp->vxlan_ip_upar_in_use, bp->vxlan_ip_port);
5176 : 0 : break;
5177 : : default:
5178 : : break;
5179 : : }
5180 : :
5181 : : HWRM_UNLOCK();
5182 : :
5183 : 0 : bnxt_hwrm_set_tpa(bp);
5184 : :
5185 : 0 : return rc;
5186 : : }
5187 : :
5188 : 0 : int bnxt_hwrm_tunnel_upar_id_get(struct bnxt *bp, uint8_t *upar_id,
5189 : : uint8_t tunnel_type)
5190 : : {
5191 : 0 : struct hwrm_tunnel_dst_port_query_input req = {0};
5192 : 0 : struct hwrm_tunnel_dst_port_query_output *resp = bp->hwrm_cmd_resp_addr;
5193 : : int rc = 0;
5194 : :
5195 [ # # ]: 0 : HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_QUERY, BNXT_USE_CHIMP_MB);
5196 : 0 : req.tunnel_type = tunnel_type;
5197 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5198 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5199 : :
5200 [ # # # # ]: 0 : switch (tunnel_type) {
5201 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_ECPRI:
5202 : 0 : *upar_id = resp->upar_in_use;
5203 : 0 : break;
5204 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_SRV6:
5205 : 0 : *upar_id = resp->upar_in_use;
5206 : 0 : break;
5207 : 0 : case HWRM_TUNNEL_DST_PORT_ALLOC_INPUT_TUNNEL_TYPE_L2_ETYPE:
5208 : 0 : *upar_id = resp->upar_in_use;
5209 : 0 : break;
5210 : 0 : default:
5211 : : /* INVALID UPAR Id if another tunnel type tries to retrieve */
5212 : 0 : *upar_id = 0xff;
5213 : 0 : break;
5214 : : }
5215 : :
5216 : : HWRM_UNLOCK();
5217 : :
5218 : 0 : return rc;
5219 : : }
5220 : :
5221 : 0 : int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
5222 : : uint8_t tunnel_type)
5223 : : {
5224 : 0 : struct hwrm_tunnel_dst_port_free_input req = {0};
5225 : 0 : struct hwrm_tunnel_dst_port_free_output *resp = bp->hwrm_cmd_resp_addr;
5226 : : int rc = 0;
5227 : :
5228 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_TUNNEL_DST_PORT_FREE, BNXT_USE_CHIMP_MB);
5229 : :
5230 : 0 : req.tunnel_type = tunnel_type;
5231 [ # # ]: 0 : req.tunnel_dst_port_id = rte_cpu_to_be_16(port);
5232 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5233 : :
5234 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5235 : : HWRM_UNLOCK();
5236 : :
5237 [ # # ]: 0 : if (tunnel_type ==
5238 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_VXLAN) {
5239 : 0 : bp->vxlan_port = 0;
5240 : 0 : bp->vxlan_port_cnt = 0;
5241 : : }
5242 : :
5243 [ # # ]: 0 : if (tunnel_type ==
5244 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_GENEVE) {
5245 : 0 : bp->geneve_port = 0;
5246 : 0 : bp->geneve_port_cnt = 0;
5247 : : }
5248 : :
5249 [ # # ]: 0 : if (tunnel_type ==
5250 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_ECPRI) {
5251 : 0 : bp->ecpri_port = 0;
5252 : 0 : bp->ecpri_upar_in_use = 0;
5253 : 0 : bp->ecpri_port_cnt = 0;
5254 : : }
5255 : :
5256 [ # # ]: 0 : if (tunnel_type ==
5257 : : HWRM_TUNNEL_DST_PORT_FREE_INPUT_TUNNEL_TYPE_L2_ETYPE) {
5258 : 0 : bp->l2_etype_tunnel_cnt = 0;
5259 : 0 : bp->l2_etype_tunnel_id = 0;
5260 : 0 : bp->l2_etype_upar_in_use = 0;
5261 : : }
5262 : :
5263 : 0 : bnxt_hwrm_set_tpa(bp);
5264 : 0 : return rc;
5265 : : }
5266 : :
5267 : 0 : int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf,
5268 : : uint32_t flags)
5269 : : {
5270 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5271 : 0 : struct hwrm_func_cfg_input req = {0};
5272 : : int rc;
5273 : :
5274 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5275 : :
5276 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
5277 : 0 : req.flags = rte_cpu_to_le_32(flags);
5278 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5279 : :
5280 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5281 : : HWRM_UNLOCK();
5282 : :
5283 : 0 : return rc;
5284 : : }
5285 : :
5286 : 0 : void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
5287 : : {
5288 : : uint32_t *flag = flagp;
5289 : :
5290 : 0 : vnic->flags = *flag;
5291 : 0 : }
5292 : :
5293 : 0 : int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
5294 : : {
5295 : 0 : return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
5296 : : }
5297 : :
5298 : 0 : int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp, int num_vfs)
5299 : : {
5300 : 0 : struct hwrm_func_buf_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
5301 : 0 : struct hwrm_func_buf_rgtr_input req = {.req_type = 0 };
5302 : : int rc;
5303 : :
5304 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BUF_RGTR, BNXT_USE_CHIMP_MB);
5305 : :
5306 : 0 : req.req_buf_num_pages = rte_cpu_to_le_16(1);
5307 : 0 : req.req_buf_page_size =
5308 : 0 : rte_cpu_to_le_16(page_getenum(num_vfs * HWRM_MAX_REQ_LEN));
5309 : 0 : req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN);
5310 : 0 : req.req_buf_page_addr0 =
5311 : 0 : rte_cpu_to_le_64(rte_malloc_virt2iova(bp->pf->vf_req_buf));
5312 [ # # ]: 0 : if (req.req_buf_page_addr0 == RTE_BAD_IOVA) {
5313 : 0 : PMD_DRV_LOG_LINE(ERR,
5314 : : "unable to map buffer address to physical memory");
5315 : : HWRM_UNLOCK();
5316 : 0 : return -ENOMEM;
5317 : : }
5318 : :
5319 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5320 : :
5321 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5322 : : HWRM_UNLOCK();
5323 : :
5324 : 0 : return rc;
5325 : : }
5326 : :
5327 : 0 : int bnxt_hwrm_func_buf_unrgtr(struct bnxt *bp)
5328 : : {
5329 : : int rc = 0;
5330 : 0 : struct hwrm_func_buf_unrgtr_input req = {.req_type = 0 };
5331 : 0 : struct hwrm_func_buf_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
5332 : :
5333 [ # # # # ]: 0 : if (!(BNXT_PF(bp) && bp->pdev->max_vfs))
5334 : : return 0;
5335 : :
5336 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BUF_UNRGTR, BNXT_USE_CHIMP_MB);
5337 : :
5338 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5339 : :
5340 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5341 : : HWRM_UNLOCK();
5342 : :
5343 : 0 : return rc;
5344 : : }
5345 : :
5346 : 0 : int bnxt_hwrm_func_cfg_def_cp(struct bnxt *bp)
5347 : : {
5348 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5349 : 0 : struct hwrm_func_cfg_input req = {0};
5350 : : int rc;
5351 : :
5352 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5353 : :
5354 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
5355 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->func_cfg_flags);
5356 : 0 : req.enables = rte_cpu_to_le_32(
5357 : : HWRM_FUNC_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
5358 : 0 : req.async_event_cr = rte_cpu_to_le_16(
5359 : : bp->async_cp_ring->cp_ring_struct->fw_ring_id);
5360 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5361 : :
5362 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5363 : : HWRM_UNLOCK();
5364 : :
5365 : 0 : return rc;
5366 : : }
5367 : :
5368 : 0 : int bnxt_hwrm_vf_func_cfg_def_cp(struct bnxt *bp)
5369 : : {
5370 : 0 : struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5371 : 0 : struct hwrm_func_vf_cfg_input req = {0};
5372 : : int rc;
5373 : :
5374 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
5375 : :
5376 : 0 : req.enables = rte_cpu_to_le_32(
5377 : : HWRM_FUNC_VF_CFG_INPUT_ENABLES_ASYNC_EVENT_CR);
5378 : 0 : req.async_event_cr = rte_cpu_to_le_16(
5379 : : bp->async_cp_ring->cp_ring_struct->fw_ring_id);
5380 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5381 : :
5382 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5383 : : HWRM_UNLOCK();
5384 : :
5385 : 0 : return rc;
5386 : : }
5387 : :
5388 : 0 : int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
5389 : : {
5390 : 0 : struct hwrm_func_cfg_input req = {0};
5391 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5392 : : uint16_t dflt_vlan, fid;
5393 : : uint32_t func_cfg_flags;
5394 : : int rc = 0;
5395 : :
5396 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5397 : :
5398 [ # # ]: 0 : if (is_vf) {
5399 : 0 : dflt_vlan = bp->pf->vf_info[vf].dflt_vlan;
5400 : 0 : fid = bp->pf->vf_info[vf].fid;
5401 : 0 : func_cfg_flags = bp->pf->vf_info[vf].func_cfg_flags;
5402 : : } else {
5403 : : fid = rte_cpu_to_le_16(0xffff);
5404 : 0 : func_cfg_flags = bp->pf->func_cfg_flags;
5405 : 0 : dflt_vlan = bp->vlan;
5406 : : }
5407 : :
5408 : 0 : req.flags = rte_cpu_to_le_32(func_cfg_flags);
5409 : 0 : req.fid = rte_cpu_to_le_16(fid);
5410 : 0 : req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
5411 : 0 : req.dflt_vlan = rte_cpu_to_le_16(dflt_vlan);
5412 : :
5413 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5414 : :
5415 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5416 : : HWRM_UNLOCK();
5417 : :
5418 : 0 : return rc;
5419 : : }
5420 : :
5421 : 0 : int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
5422 : : uint16_t max_bw, uint16_t enables)
5423 : : {
5424 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5425 : 0 : struct hwrm_func_cfg_input req = {0};
5426 : : int rc;
5427 : :
5428 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5429 : :
5430 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
5431 : 0 : req.enables |= rte_cpu_to_le_32(enables);
5432 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
5433 : 0 : req.max_bw = rte_cpu_to_le_32(max_bw);
5434 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5435 : :
5436 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5437 : : HWRM_UNLOCK();
5438 : :
5439 : 0 : return rc;
5440 : : }
5441 : :
5442 : 0 : int bnxt_hwrm_set_vf_vlan(struct bnxt *bp, int vf)
5443 : : {
5444 : 0 : struct hwrm_func_cfg_input req = {0};
5445 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5446 : : int rc = 0;
5447 : :
5448 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
5449 : :
5450 : 0 : req.flags = rte_cpu_to_le_32(bp->pf->vf_info[vf].func_cfg_flags);
5451 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
5452 : 0 : req.enables |= rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_VLAN);
5453 : 0 : req.dflt_vlan = rte_cpu_to_le_16(bp->pf->vf_info[vf].dflt_vlan);
5454 : :
5455 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5456 : :
5457 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5458 : : HWRM_UNLOCK();
5459 : :
5460 : 0 : return rc;
5461 : : }
5462 : :
5463 : 0 : int bnxt_hwrm_set_async_event_cr(struct bnxt *bp)
5464 : : {
5465 : : int rc;
5466 : :
5467 [ # # ]: 0 : if (BNXT_PF(bp))
5468 : 0 : rc = bnxt_hwrm_func_cfg_def_cp(bp);
5469 : : else
5470 : 0 : rc = bnxt_hwrm_vf_func_cfg_def_cp(bp);
5471 : :
5472 : 0 : return rc;
5473 : : }
5474 : :
5475 : 0 : int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
5476 : : void *encaped, size_t ec_size)
5477 : : {
5478 : : int rc = 0;
5479 : 0 : struct hwrm_reject_fwd_resp_input req = {.req_type = 0};
5480 : 0 : struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
5481 : :
5482 [ # # ]: 0 : if (ec_size > sizeof(req.encap_request))
5483 : : return -1;
5484 : :
5485 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_REJECT_FWD_RESP, BNXT_USE_CHIMP_MB);
5486 : :
5487 : 0 : req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
5488 [ # # ]: 0 : if (encaped)
5489 : : memcpy(req.encap_request, encaped, ec_size);
5490 : :
5491 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5492 : :
5493 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5494 : : HWRM_UNLOCK();
5495 : :
5496 : 0 : return rc;
5497 : : }
5498 : :
5499 : 0 : int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
5500 : : struct rte_ether_addr *mac)
5501 : : {
5502 : 0 : struct hwrm_func_qcfg_input req = {0};
5503 : 0 : struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
5504 : : int rc;
5505 : :
5506 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCFG, BNXT_USE_CHIMP_MB);
5507 : :
5508 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
5509 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5510 : :
5511 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5512 : :
5513 : 0 : memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
5514 : :
5515 : : HWRM_UNLOCK();
5516 : :
5517 : 0 : return rc;
5518 : : }
5519 : :
5520 : 0 : int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
5521 : : void *encaped, size_t ec_size)
5522 : : {
5523 : : int rc = 0;
5524 : 0 : struct hwrm_exec_fwd_resp_input req = {.req_type = 0};
5525 : 0 : struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
5526 : :
5527 [ # # ]: 0 : if (ec_size > sizeof(req.encap_request))
5528 : : return -1;
5529 : :
5530 [ # # ]: 0 : HWRM_PREP(&req, HWRM_EXEC_FWD_RESP, BNXT_USE_CHIMP_MB);
5531 : :
5532 : 0 : req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
5533 : : memcpy(req.encap_request, encaped, ec_size);
5534 : :
5535 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5536 : :
5537 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5538 : : HWRM_UNLOCK();
5539 : :
5540 : 0 : return rc;
5541 : : }
5542 : :
5543 : 0 : int bnxt_hwrm_fwd_resp(struct bnxt *bp, uint16_t target_id,
5544 : : void *encaped, size_t ec_size,
5545 : : uint64_t encap_resp_addr, uint16_t cmpl_ring)
5546 : : {
5547 : : int rc = 0;
5548 : 0 : struct hwrm_fwd_resp_input req = {.req_type = 0};
5549 : 0 : struct hwrm_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr;
5550 : :
5551 [ # # ]: 0 : if (ec_size > sizeof(req.encap_resp))
5552 : : return -1;
5553 : :
5554 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FWD_RESP, BNXT_USE_CHIMP_MB);
5555 : :
5556 : 0 : req.target_id = rte_cpu_to_le_16(target_id);
5557 : 0 : req.encap_resp_target_id = rte_cpu_to_le_16(target_id);
5558 : 0 : req.encap_resp_len = rte_cpu_to_le_16(ec_size);
5559 : 0 : req.encap_resp_addr = encap_resp_addr;
5560 : 0 : req.encap_resp_cmpl_ring = cmpl_ring;
5561 : : memcpy(req.encap_resp, encaped, ec_size);
5562 : :
5563 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5564 : :
5565 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5566 : : HWRM_UNLOCK();
5567 : :
5568 : 0 : return rc;
5569 : : }
5570 : :
5571 : : static void bnxt_update_prev_stat(uint64_t *cntr, uint64_t *prev_cntr)
5572 : : {
5573 : : /* One of the HW stat values that make up this counter was zero as
5574 : : * returned by HW in this iteration, so use the previous
5575 : : * iteration's counter value
5576 : : */
5577 : 0 : if (!cntr || !prev_cntr)
5578 : : return;
5579 [ # # # # : 0 : if (*prev_cntr && *cntr == 0)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
5580 : 0 : *cntr = *prev_cntr;
5581 : : else
5582 : 0 : *prev_cntr = *cntr;
5583 : : }
5584 : :
5585 : : static void bnxt_get_prev_tx_stats(struct bnxt_ring_stats *ring_stats,
5586 : : struct bnxt_ring_stats *prev_stats)
5587 : : {
5588 : 0 : ring_stats->tx_ucast_pkts = prev_stats->tx_ucast_pkts;
5589 : 0 : ring_stats->tx_mcast_pkts = prev_stats->tx_mcast_pkts;
5590 : 0 : ring_stats->tx_bcast_pkts = prev_stats->tx_bcast_pkts;
5591 : 0 : ring_stats->tx_ucast_bytes = prev_stats->tx_ucast_bytes;
5592 : 0 : ring_stats->tx_mcast_bytes = prev_stats->tx_mcast_bytes;
5593 : 0 : ring_stats->tx_bcast_bytes = prev_stats->tx_bcast_bytes;
5594 : 0 : ring_stats->tx_discard_pkts = prev_stats->tx_discard_pkts;
5595 : 0 : }
5596 : :
5597 : : static void bnxt_get_prev_rx_stats(struct bnxt_ring_stats *ring_stats,
5598 : : struct bnxt_ring_stats *prev_stats)
5599 : : {
5600 : 0 : ring_stats->rx_ucast_pkts = prev_stats->rx_ucast_pkts;
5601 : 0 : ring_stats->rx_mcast_pkts = prev_stats->rx_mcast_pkts;
5602 : 0 : ring_stats->rx_bcast_pkts = prev_stats->rx_bcast_pkts;
5603 : 0 : ring_stats->rx_ucast_bytes = prev_stats->rx_ucast_bytes;
5604 : 0 : ring_stats->rx_mcast_bytes = prev_stats->rx_mcast_bytes;
5605 : 0 : ring_stats->rx_bcast_bytes = prev_stats->rx_bcast_bytes;
5606 : 0 : ring_stats->rx_discard_pkts = prev_stats->rx_discard_pkts;
5607 : 0 : ring_stats->rx_error_pkts = prev_stats->rx_error_pkts;
5608 : 0 : ring_stats->rx_agg_pkts = prev_stats->rx_agg_pkts;
5609 : 0 : ring_stats->rx_agg_bytes = prev_stats->rx_agg_bytes;
5610 : 0 : ring_stats->rx_agg_events = prev_stats->rx_agg_events;
5611 : 0 : ring_stats->rx_agg_aborts = prev_stats->rx_agg_aborts;
5612 : 0 : }
5613 : :
5614 : 0 : int bnxt_hwrm_ring_stats(struct bnxt *bp, uint32_t cid, int idx,
5615 : : struct bnxt_ring_stats *ring_stats, bool rx)
5616 : : {
5617 : : int rc = 0;
5618 : 0 : struct hwrm_stat_ctx_query_input req = {.req_type = 0};
5619 : 0 : struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
5620 : 0 : struct bnxt_ring_stats *prev_stats = &bp->prev_rx_ring_stats[idx];
5621 : :
5622 [ # # ]: 0 : if (!rx)
5623 : 0 : prev_stats = &bp->prev_tx_ring_stats[idx];
5624 : :
5625 [ # # ]: 0 : if (!bp->eth_dev->data->dev_started) {
5626 [ # # ]: 0 : if (rx)
5627 : : bnxt_get_prev_rx_stats(ring_stats, prev_stats);
5628 : : else
5629 : : bnxt_get_prev_tx_stats(ring_stats, prev_stats);
5630 : :
5631 : 0 : return 0;
5632 : : }
5633 [ # # ]: 0 : HWRM_PREP(&req, HWRM_STAT_CTX_QUERY, BNXT_USE_CHIMP_MB);
5634 : :
5635 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(cid);
5636 : :
5637 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5638 : :
5639 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5640 : :
5641 [ # # ]: 0 : if (rx) {
5642 [ # # ]: 0 : ring_stats->rx_ucast_pkts = rte_le_to_cpu_64(resp->rx_ucast_pkts);
5643 : : bnxt_update_prev_stat(&ring_stats->rx_ucast_pkts,
5644 : : &prev_stats->rx_ucast_pkts);
5645 : :
5646 [ # # ]: 0 : ring_stats->rx_mcast_pkts = rte_le_to_cpu_64(resp->rx_mcast_pkts);
5647 : : bnxt_update_prev_stat(&ring_stats->rx_mcast_pkts,
5648 : : &prev_stats->rx_mcast_pkts);
5649 : :
5650 [ # # ]: 0 : ring_stats->rx_bcast_pkts = rte_le_to_cpu_64(resp->rx_bcast_pkts);
5651 : : bnxt_update_prev_stat(&ring_stats->rx_bcast_pkts,
5652 : : &prev_stats->rx_bcast_pkts);
5653 : :
5654 [ # # ]: 0 : ring_stats->rx_ucast_bytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
5655 : : bnxt_update_prev_stat(&ring_stats->rx_ucast_bytes,
5656 : : &prev_stats->rx_ucast_bytes);
5657 : :
5658 [ # # ]: 0 : ring_stats->rx_mcast_bytes = rte_le_to_cpu_64(resp->rx_mcast_bytes);
5659 : : bnxt_update_prev_stat(&ring_stats->rx_mcast_bytes,
5660 : : &prev_stats->rx_mcast_bytes);
5661 : :
5662 [ # # ]: 0 : ring_stats->rx_bcast_bytes = rte_le_to_cpu_64(resp->rx_bcast_bytes);
5663 : : bnxt_update_prev_stat(&ring_stats->rx_bcast_bytes,
5664 : : &prev_stats->rx_bcast_bytes);
5665 : :
5666 [ # # ]: 0 : ring_stats->rx_discard_pkts = rte_le_to_cpu_64(resp->rx_discard_pkts);
5667 : : bnxt_update_prev_stat(&ring_stats->rx_discard_pkts,
5668 : : &prev_stats->rx_discard_pkts);
5669 : :
5670 [ # # ]: 0 : ring_stats->rx_error_pkts = rte_le_to_cpu_64(resp->rx_error_pkts);
5671 : : bnxt_update_prev_stat(&ring_stats->rx_error_pkts,
5672 : : &prev_stats->rx_error_pkts);
5673 : :
5674 [ # # ]: 0 : ring_stats->rx_agg_pkts = rte_le_to_cpu_64(resp->rx_agg_pkts);
5675 : : bnxt_update_prev_stat(&ring_stats->rx_agg_pkts,
5676 : : &prev_stats->rx_agg_pkts);
5677 : :
5678 [ # # ]: 0 : ring_stats->rx_agg_bytes = rte_le_to_cpu_64(resp->rx_agg_bytes);
5679 : : bnxt_update_prev_stat(&ring_stats->rx_agg_bytes,
5680 : : &prev_stats->rx_agg_bytes);
5681 : :
5682 [ # # ]: 0 : ring_stats->rx_agg_events = rte_le_to_cpu_64(resp->rx_agg_events);
5683 : : bnxt_update_prev_stat(&ring_stats->rx_agg_events,
5684 : : &prev_stats->rx_agg_events);
5685 : :
5686 [ # # ]: 0 : ring_stats->rx_agg_aborts = rte_le_to_cpu_64(resp->rx_agg_aborts);
5687 : : bnxt_update_prev_stat(&ring_stats->rx_agg_aborts,
5688 : : &prev_stats->rx_agg_aborts);
5689 : : } else {
5690 : 0 : ring_stats->tx_ucast_pkts = rte_le_to_cpu_64(resp->tx_ucast_pkts);
5691 [ # # ]: 0 : bnxt_update_prev_stat(&ring_stats->tx_ucast_pkts,
5692 : : &prev_stats->tx_ucast_pkts);
5693 : :
5694 [ # # ]: 0 : ring_stats->tx_mcast_pkts = rte_le_to_cpu_64(resp->tx_mcast_pkts);
5695 : : bnxt_update_prev_stat(&ring_stats->tx_mcast_pkts,
5696 : : &prev_stats->tx_mcast_pkts);
5697 : :
5698 [ # # ]: 0 : ring_stats->tx_bcast_pkts = rte_le_to_cpu_64(resp->tx_bcast_pkts);
5699 : : bnxt_update_prev_stat(&ring_stats->tx_bcast_pkts,
5700 : : &prev_stats->tx_bcast_pkts);
5701 : :
5702 [ # # ]: 0 : ring_stats->tx_ucast_bytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
5703 : : bnxt_update_prev_stat(&ring_stats->tx_ucast_bytes,
5704 : : &prev_stats->tx_ucast_bytes);
5705 : :
5706 [ # # ]: 0 : ring_stats->tx_mcast_bytes = rte_le_to_cpu_64(resp->tx_mcast_bytes);
5707 : : bnxt_update_prev_stat(&ring_stats->tx_mcast_bytes,
5708 : : &prev_stats->tx_mcast_bytes);
5709 : :
5710 [ # # ]: 0 : ring_stats->tx_bcast_bytes = rte_le_to_cpu_64(resp->tx_bcast_bytes);
5711 : : bnxt_update_prev_stat(&ring_stats->tx_bcast_bytes,
5712 : : &prev_stats->tx_bcast_bytes);
5713 : :
5714 [ # # ]: 0 : ring_stats->tx_discard_pkts = rte_le_to_cpu_64(resp->tx_discard_pkts);
5715 : : bnxt_update_prev_stat(&ring_stats->tx_discard_pkts,
5716 : : &prev_stats->tx_discard_pkts);
5717 : : }
5718 : :
5719 : : HWRM_UNLOCK();
5720 : :
5721 : 0 : return rc;
5722 : : }
5723 : :
5724 : : static void bnxt_get_prev_rx_stats_ext(struct bnxt_ring_stats_ext *ring_stats,
5725 : : struct bnxt_ring_stats_ext *prev_stats)
5726 : : {
5727 : 0 : ring_stats->rx_ucast_pkts = prev_stats->rx_ucast_pkts;
5728 : 0 : ring_stats->rx_mcast_pkts = prev_stats->rx_mcast_pkts;
5729 : 0 : ring_stats->rx_bcast_pkts = prev_stats->rx_bcast_pkts;
5730 : 0 : ring_stats->rx_ucast_bytes = prev_stats->rx_ucast_bytes;
5731 : 0 : ring_stats->rx_mcast_bytes = prev_stats->rx_mcast_bytes;
5732 : 0 : ring_stats->rx_bcast_bytes = prev_stats->rx_bcast_bytes;
5733 : 0 : ring_stats->rx_discard_pkts = prev_stats->rx_discard_pkts;
5734 : 0 : ring_stats->rx_error_pkts = prev_stats->rx_error_pkts;
5735 : 0 : ring_stats->rx_tpa_eligible_pkt = prev_stats->rx_tpa_eligible_pkt;
5736 : 0 : ring_stats->rx_tpa_eligible_bytes = prev_stats->rx_tpa_eligible_bytes;
5737 : 0 : ring_stats->rx_tpa_pkt = prev_stats->rx_tpa_pkt;
5738 : 0 : ring_stats->rx_tpa_bytes = prev_stats->rx_tpa_bytes;
5739 : 0 : ring_stats->rx_tpa_errors = prev_stats->rx_tpa_errors;
5740 : 0 : ring_stats->rx_tpa_events = prev_stats->rx_tpa_events;
5741 : 0 : }
5742 : :
5743 : : static void bnxt_get_prev_tx_stats_ext(struct bnxt_ring_stats_ext *ring_stats,
5744 : : struct bnxt_ring_stats_ext *prev_stats)
5745 : : {
5746 : 0 : ring_stats->tx_ucast_pkts = prev_stats->tx_ucast_pkts;
5747 : 0 : ring_stats->tx_mcast_pkts = prev_stats->tx_mcast_pkts;
5748 : 0 : ring_stats->tx_bcast_pkts = prev_stats->tx_bcast_pkts;
5749 : 0 : ring_stats->tx_ucast_bytes = prev_stats->tx_ucast_bytes;
5750 : 0 : ring_stats->tx_mcast_bytes = prev_stats->tx_mcast_bytes;
5751 : 0 : ring_stats->tx_bcast_bytes = prev_stats->tx_bcast_bytes;
5752 : 0 : ring_stats->tx_discard_pkts = prev_stats->tx_discard_pkts;
5753 : 0 : ring_stats->tx_error_pkts = prev_stats->tx_error_pkts;
5754 : 0 : }
5755 : :
5756 : 0 : int bnxt_hwrm_ring_stats_ext(struct bnxt *bp, uint32_t cid, int idx,
5757 : : struct bnxt_ring_stats_ext *ring_stats, bool rx)
5758 : : {
5759 : : int rc = 0;
5760 : 0 : struct hwrm_stat_ext_ctx_query_input req = {.req_type = 0};
5761 : 0 : struct hwrm_stat_ext_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
5762 : :
5763 : 0 : struct bnxt_ring_stats_ext *prev_stats = &bp->prev_rx_ring_stats_ext[idx];
5764 : :
5765 [ # # ]: 0 : if (!rx)
5766 : 0 : prev_stats = &bp->prev_tx_ring_stats_ext[idx];
5767 : :
5768 [ # # ]: 0 : if (!bp->eth_dev->data->dev_started) {
5769 [ # # ]: 0 : if (rx)
5770 : : bnxt_get_prev_rx_stats_ext(ring_stats, prev_stats);
5771 : : else
5772 : : bnxt_get_prev_tx_stats_ext(ring_stats, prev_stats);
5773 : :
5774 : 0 : return 0;
5775 : : }
5776 [ # # ]: 0 : HWRM_PREP(&req, HWRM_STAT_EXT_CTX_QUERY, BNXT_USE_CHIMP_MB);
5777 : :
5778 : 0 : req.stat_ctx_id = rte_cpu_to_le_32(cid);
5779 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5780 : :
5781 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5782 : :
5783 [ # # ]: 0 : if (rx) {
5784 : 0 : ring_stats->rx_ucast_pkts = rte_le_to_cpu_64(resp->rx_ucast_pkts);
5785 [ # # ]: 0 : bnxt_update_prev_stat(&ring_stats->rx_ucast_pkts,
5786 : : &prev_stats->rx_ucast_pkts);
5787 : :
5788 [ # # ]: 0 : ring_stats->rx_mcast_pkts = rte_le_to_cpu_64(resp->rx_mcast_pkts);
5789 : : bnxt_update_prev_stat(&ring_stats->rx_mcast_pkts,
5790 : : &prev_stats->rx_mcast_pkts);
5791 : :
5792 [ # # ]: 0 : ring_stats->rx_bcast_pkts = rte_le_to_cpu_64(resp->rx_bcast_pkts);
5793 : : bnxt_update_prev_stat(&ring_stats->rx_bcast_pkts,
5794 : : &prev_stats->rx_bcast_pkts);
5795 : :
5796 [ # # ]: 0 : ring_stats->rx_ucast_bytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
5797 : : bnxt_update_prev_stat(&ring_stats->rx_ucast_bytes,
5798 : : &prev_stats->rx_ucast_bytes);
5799 : :
5800 [ # # ]: 0 : ring_stats->rx_mcast_bytes = rte_le_to_cpu_64(resp->rx_mcast_bytes);
5801 : : bnxt_update_prev_stat(&ring_stats->rx_mcast_bytes,
5802 : : &prev_stats->rx_mcast_bytes);
5803 : :
5804 [ # # ]: 0 : ring_stats->rx_bcast_bytes = rte_le_to_cpu_64(resp->rx_bcast_bytes);
5805 : : bnxt_update_prev_stat(&ring_stats->rx_bcast_bytes,
5806 : : &prev_stats->rx_bcast_bytes);
5807 : :
5808 [ # # ]: 0 : ring_stats->rx_discard_pkts = rte_le_to_cpu_64(resp->rx_discard_pkts);
5809 : : bnxt_update_prev_stat(&ring_stats->rx_discard_pkts,
5810 : : &prev_stats->rx_discard_pkts);
5811 : :
5812 [ # # ]: 0 : ring_stats->rx_error_pkts = rte_le_to_cpu_64(resp->rx_error_pkts);
5813 : : bnxt_update_prev_stat(&ring_stats->rx_error_pkts,
5814 : : &prev_stats->rx_error_pkts);
5815 : :
5816 [ # # ]: 0 : ring_stats->rx_tpa_eligible_pkt = rte_le_to_cpu_64(resp->rx_tpa_eligible_pkt);
5817 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_eligible_pkt,
5818 : : &prev_stats->rx_tpa_eligible_pkt);
5819 : :
5820 [ # # ]: 0 : ring_stats->rx_tpa_eligible_bytes = rte_le_to_cpu_64(resp->rx_tpa_eligible_bytes);
5821 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_eligible_bytes,
5822 : : &prev_stats->rx_tpa_eligible_bytes);
5823 : :
5824 [ # # ]: 0 : ring_stats->rx_tpa_pkt = rte_le_to_cpu_64(resp->rx_tpa_pkt);
5825 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_pkt,
5826 : : &prev_stats->rx_tpa_pkt);
5827 : :
5828 [ # # ]: 0 : ring_stats->rx_tpa_bytes = rte_le_to_cpu_64(resp->rx_tpa_bytes);
5829 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_bytes,
5830 : : &prev_stats->rx_tpa_bytes);
5831 : :
5832 [ # # ]: 0 : ring_stats->rx_tpa_errors = rte_le_to_cpu_64(resp->rx_tpa_errors);
5833 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_errors,
5834 : : &prev_stats->rx_tpa_errors);
5835 : :
5836 [ # # ]: 0 : ring_stats->rx_tpa_events = rte_le_to_cpu_64(resp->rx_tpa_events);
5837 : : bnxt_update_prev_stat(&ring_stats->rx_tpa_events,
5838 : : &prev_stats->rx_tpa_events);
5839 : : } else {
5840 [ # # ]: 0 : ring_stats->tx_ucast_pkts = rte_le_to_cpu_64(resp->tx_ucast_pkts);
5841 : : bnxt_update_prev_stat(&ring_stats->tx_ucast_pkts,
5842 : : &prev_stats->tx_ucast_pkts);
5843 : :
5844 [ # # ]: 0 : ring_stats->tx_mcast_pkts = rte_le_to_cpu_64(resp->tx_mcast_pkts);
5845 : : bnxt_update_prev_stat(&ring_stats->tx_mcast_pkts,
5846 : : &prev_stats->tx_mcast_pkts);
5847 : :
5848 [ # # ]: 0 : ring_stats->tx_bcast_pkts = rte_le_to_cpu_64(resp->tx_bcast_pkts);
5849 : : bnxt_update_prev_stat(&ring_stats->tx_bcast_pkts,
5850 : : &prev_stats->tx_bcast_pkts);
5851 : :
5852 [ # # ]: 0 : ring_stats->tx_ucast_bytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
5853 : : bnxt_update_prev_stat(&ring_stats->tx_ucast_bytes,
5854 : : &prev_stats->tx_ucast_bytes);
5855 : :
5856 [ # # ]: 0 : ring_stats->tx_mcast_bytes = rte_le_to_cpu_64(resp->tx_mcast_bytes);
5857 : : bnxt_update_prev_stat(&ring_stats->tx_mcast_bytes,
5858 : : &prev_stats->tx_mcast_bytes);
5859 : :
5860 [ # # ]: 0 : ring_stats->tx_bcast_bytes = rte_le_to_cpu_64(resp->tx_bcast_bytes);
5861 : : bnxt_update_prev_stat(&ring_stats->tx_bcast_bytes,
5862 : : &prev_stats->tx_bcast_bytes);
5863 : :
5864 [ # # ]: 0 : ring_stats->tx_discard_pkts = rte_le_to_cpu_64(resp->tx_discard_pkts);
5865 : : bnxt_update_prev_stat(&ring_stats->tx_discard_pkts,
5866 : : &prev_stats->tx_discard_pkts);
5867 : :
5868 [ # # ]: 0 : ring_stats->tx_error_pkts = rte_le_to_cpu_64(resp->tx_error_pkts);
5869 : : bnxt_update_prev_stat(&ring_stats->tx_error_pkts,
5870 : : &prev_stats->tx_error_pkts);
5871 : : }
5872 : :
5873 : : HWRM_UNLOCK();
5874 : :
5875 : 0 : return rc;
5876 : : }
5877 : :
5878 : 0 : int bnxt_hwrm_port_qstats(struct bnxt *bp)
5879 : : {
5880 : 0 : struct hwrm_port_qstats_input req = {0};
5881 : 0 : struct hwrm_port_qstats_output *resp = bp->hwrm_cmd_resp_addr;
5882 : 0 : struct bnxt_pf_info *pf = bp->pf;
5883 : : int rc;
5884 : :
5885 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_QSTATS, BNXT_USE_CHIMP_MB);
5886 : :
5887 : 0 : req.port_id = rte_cpu_to_le_16(pf->port_id);
5888 : 0 : req.tx_stat_host_addr = rte_cpu_to_le_64(bp->hw_tx_port_stats_map);
5889 : 0 : req.rx_stat_host_addr = rte_cpu_to_le_64(bp->hw_rx_port_stats_map);
5890 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5891 : :
5892 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5893 : : HWRM_UNLOCK();
5894 : :
5895 : 0 : return rc;
5896 : : }
5897 : :
5898 : 0 : int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
5899 : : {
5900 : 0 : struct hwrm_port_clr_stats_input req = {0};
5901 : 0 : struct hwrm_port_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
5902 : 0 : struct bnxt_pf_info *pf = bp->pf;
5903 : : int rc;
5904 : :
5905 : : /* Not allowed on NS2 device, NPAR, MultiHost, VF */
5906 [ # # ]: 0 : if (!(bp->flags & BNXT_FLAG_PORT_STATS) || BNXT_VF(bp) ||
5907 [ # # ]: 0 : BNXT_NPAR(bp) || BNXT_MH(bp) || BNXT_TOTAL_VFS(bp))
5908 : : return 0;
5909 : :
5910 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_CLR_STATS, BNXT_USE_CHIMP_MB);
5911 : :
5912 : 0 : req.port_id = rte_cpu_to_le_16(pf->port_id);
5913 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5914 : :
5915 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5916 : : HWRM_UNLOCK();
5917 : :
5918 : 0 : return rc;
5919 : : }
5920 : :
5921 : 0 : int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
5922 : : {
5923 : 0 : struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
5924 : 0 : struct hwrm_port_led_qcaps_input req = {0};
5925 : : int rc;
5926 : :
5927 [ # # ]: 0 : if (BNXT_VF(bp))
5928 : : return 0;
5929 : :
5930 [ # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_LED_QCAPS, BNXT_USE_CHIMP_MB);
5931 : 0 : req.port_id = bp->pf->port_id;
5932 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5933 : :
5934 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
5935 : :
5936 [ # # ]: 0 : if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
5937 : : unsigned int i;
5938 : :
5939 : 0 : bp->leds->num_leds = resp->num_leds;
5940 : 0 : memcpy(bp->leds, &resp->led0_id,
5941 : 0 : sizeof(bp->leds[0]) * bp->leds->num_leds);
5942 [ # # ]: 0 : for (i = 0; i < bp->leds->num_leds; i++) {
5943 : 0 : struct bnxt_led_info *led = &bp->leds[i];
5944 : :
5945 : 0 : uint16_t caps = led->led_state_caps;
5946 : :
5947 [ # # # # ]: 0 : if (!led->led_group_id ||
5948 : : !BNXT_LED_ALT_BLINK_CAP(caps)) {
5949 : 0 : bp->leds->num_leds = 0;
5950 : 0 : break;
5951 : : }
5952 : : }
5953 : : }
5954 : :
5955 : : HWRM_UNLOCK();
5956 : :
5957 : 0 : return rc;
5958 : : }
5959 : :
5960 : 0 : int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
5961 : : {
5962 : 0 : struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
5963 : 0 : struct hwrm_port_led_cfg_input req = {0};
5964 : : struct bnxt_led_cfg *led_cfg;
5965 : : uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
5966 : : uint16_t duration = 0;
5967 : : int rc, i;
5968 : :
5969 [ # # # # : 0 : if (BNXT_VF(bp) || !bp->leds || !bp->leds->num_leds)
# # ]
5970 : : return -EOPNOTSUPP;
5971 : :
5972 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
5973 : :
5974 [ # # ]: 0 : if (led_on) {
5975 : : led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
5976 : : duration = rte_cpu_to_le_16(500);
5977 : : }
5978 : 0 : req.port_id = bp->pf->port_id;
5979 : 0 : req.num_leds = bp->leds->num_leds;
5980 : : led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
5981 [ # # ]: 0 : for (i = 0; i < bp->leds->num_leds; i++, led_cfg++) {
5982 : 0 : req.enables |= BNXT_LED_DFLT_ENABLES(i);
5983 : 0 : led_cfg->led_id = bp->leds[i].led_id;
5984 : 0 : led_cfg->led_state = led_state;
5985 : 0 : led_cfg->led_blink_on = duration;
5986 : 0 : led_cfg->led_blink_off = duration;
5987 : 0 : led_cfg->led_group_id = bp->leds[i].led_group_id;
5988 : : }
5989 : :
5990 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
5991 : :
5992 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
5993 : : HWRM_UNLOCK();
5994 : :
5995 : 0 : return rc;
5996 : : }
5997 : :
5998 : 0 : int bnxt_hwrm_nvm_get_dir_info(struct bnxt *bp, uint32_t *entries,
5999 : : uint32_t *length)
6000 : : {
6001 : : int rc;
6002 : 0 : struct hwrm_nvm_get_dir_info_input req = {0};
6003 : 0 : struct hwrm_nvm_get_dir_info_output *resp = bp->hwrm_cmd_resp_addr;
6004 : :
6005 [ # # ]: 0 : HWRM_PREP(&req, HWRM_NVM_GET_DIR_INFO, BNXT_USE_CHIMP_MB);
6006 : :
6007 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6008 : :
6009 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6010 : :
6011 : 0 : *entries = rte_le_to_cpu_32(resp->entries);
6012 : 0 : *length = rte_le_to_cpu_32(resp->entry_length);
6013 : :
6014 : : HWRM_UNLOCK();
6015 : 0 : return rc;
6016 : : }
6017 : :
6018 : : #define BNXT_MAX_DIR_ENTRIES UINT8_MAX
6019 : : #define BNXT_MAX_ENTRY_LENGTH UINT8_MAX
6020 : :
6021 : 0 : int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data)
6022 : : {
6023 : : int rc;
6024 : : uint32_t dir_entries;
6025 : : uint32_t entry_length;
6026 : : uint8_t *buf;
6027 : : size_t buflen;
6028 : : rte_iova_t dma_handle;
6029 : 0 : struct hwrm_nvm_get_dir_entries_input req = {0};
6030 : 0 : struct hwrm_nvm_get_dir_entries_output *resp = bp->hwrm_cmd_resp_addr;
6031 : :
6032 [ # # ]: 0 : if (len < 2)
6033 : : return -EINVAL;
6034 : :
6035 : 0 : rc = bnxt_hwrm_nvm_get_dir_info(bp, &dir_entries, &entry_length);
6036 [ # # ]: 0 : if (rc != 0)
6037 : : return rc;
6038 : :
6039 [ # # ]: 0 : if (dir_entries == 0 || dir_entries > BNXT_MAX_DIR_ENTRIES ||
6040 [ # # # # ]: 0 : entry_length == 0 || entry_length > BNXT_MAX_ENTRY_LENGTH) {
6041 : 0 : PMD_DRV_LOG_LINE(ERR,
6042 : : "Invalid dir info: entries=%u length=%u",
6043 : : dir_entries, entry_length);
6044 : 0 : return -EINVAL;
6045 : : }
6046 : :
6047 : 0 : *data++ = dir_entries;
6048 : 0 : *data++ = entry_length;
6049 : 0 : len -= 2;
6050 : 0 : memset(data, 0xff, len);
6051 : :
6052 : 0 : buflen = (size_t)dir_entries * entry_length;
6053 : 0 : buf = rte_malloc("nvm_dir", buflen, 0);
6054 [ # # ]: 0 : if (buf == NULL)
6055 : : return -ENOMEM;
6056 : 0 : dma_handle = rte_malloc_virt2iova(buf);
6057 [ # # ]: 0 : if (dma_handle == RTE_BAD_IOVA) {
6058 : 0 : rte_free(buf);
6059 : 0 : PMD_DRV_LOG_LINE(ERR,
6060 : : "unable to map response address to physical memory");
6061 : 0 : return -ENOMEM;
6062 : : }
6063 [ # # ]: 0 : HWRM_PREP(&req, HWRM_NVM_GET_DIR_ENTRIES, BNXT_USE_CHIMP_MB);
6064 : 0 : req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
6065 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6066 : :
6067 [ # # ]: 0 : if (rc == 0)
6068 : 0 : memcpy(data, buf, len > buflen ? buflen : len);
6069 : :
6070 : 0 : rte_free(buf);
6071 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6072 : : HWRM_UNLOCK();
6073 : :
6074 : 0 : return rc;
6075 : : }
6076 : :
6077 : 0 : int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index,
6078 : : uint32_t offset, uint32_t length,
6079 : : uint8_t *data)
6080 : : {
6081 : : int rc;
6082 : : uint8_t *buf;
6083 : : rte_iova_t dma_handle;
6084 : 0 : struct hwrm_nvm_read_input req = {0};
6085 : 0 : struct hwrm_nvm_read_output *resp = bp->hwrm_cmd_resp_addr;
6086 : :
6087 : 0 : buf = rte_malloc("nvm_item", length, 0);
6088 [ # # ]: 0 : if (!buf)
6089 : : return -ENOMEM;
6090 : :
6091 : 0 : dma_handle = rte_malloc_virt2iova(buf);
6092 [ # # ]: 0 : if (dma_handle == RTE_BAD_IOVA) {
6093 : 0 : rte_free(buf);
6094 : 0 : PMD_DRV_LOG_LINE(ERR,
6095 : : "unable to map response address to physical memory");
6096 : 0 : return -ENOMEM;
6097 : : }
6098 [ # # ]: 0 : HWRM_PREP(&req, HWRM_NVM_READ, BNXT_USE_CHIMP_MB);
6099 : 0 : req.host_dest_addr = rte_cpu_to_le_64(dma_handle);
6100 : 0 : req.dir_idx = rte_cpu_to_le_16(index);
6101 : 0 : req.offset = rte_cpu_to_le_32(offset);
6102 : 0 : req.len = rte_cpu_to_le_32(length);
6103 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6104 [ # # ]: 0 : if (rc == 0)
6105 : : memcpy(data, buf, length);
6106 : :
6107 : 0 : rte_free(buf);
6108 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6109 : : HWRM_UNLOCK();
6110 : :
6111 : 0 : return rc;
6112 : : }
6113 : :
6114 : 0 : int bnxt_hwrm_erase_nvram_directory(struct bnxt *bp, uint8_t index)
6115 : : {
6116 : : int rc;
6117 : 0 : struct hwrm_nvm_erase_dir_entry_input req = {0};
6118 : 0 : struct hwrm_nvm_erase_dir_entry_output *resp = bp->hwrm_cmd_resp_addr;
6119 : :
6120 [ # # ]: 0 : HWRM_PREP(&req, HWRM_NVM_ERASE_DIR_ENTRY, BNXT_USE_CHIMP_MB);
6121 : 0 : req.dir_idx = rte_cpu_to_le_16(index);
6122 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6123 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6124 : : HWRM_UNLOCK();
6125 : :
6126 : 0 : return rc;
6127 : : }
6128 : :
6129 : 0 : int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type,
6130 : : uint16_t dir_ordinal, uint16_t dir_ext,
6131 : : uint16_t dir_attr, const uint8_t *data,
6132 : : size_t data_len)
6133 : : {
6134 : : int rc;
6135 : 0 : struct hwrm_nvm_write_input req = {0};
6136 : 0 : struct hwrm_nvm_write_output *resp = bp->hwrm_cmd_resp_addr;
6137 : : rte_iova_t dma_handle;
6138 : : uint8_t *buf;
6139 : :
6140 : 0 : buf = rte_malloc("nvm_write", data_len, 0);
6141 [ # # ]: 0 : if (!buf)
6142 : : return -ENOMEM;
6143 : :
6144 : 0 : dma_handle = rte_malloc_virt2iova(buf);
6145 [ # # ]: 0 : if (dma_handle == RTE_BAD_IOVA) {
6146 : 0 : rte_free(buf);
6147 : 0 : PMD_DRV_LOG_LINE(ERR,
6148 : : "unable to map response address to physical memory");
6149 : 0 : return -ENOMEM;
6150 : : }
6151 : : memcpy(buf, data, data_len);
6152 : :
6153 [ # # ]: 0 : HWRM_PREP(&req, HWRM_NVM_WRITE, BNXT_USE_CHIMP_MB);
6154 : :
6155 : 0 : req.dir_type = rte_cpu_to_le_16(dir_type);
6156 : 0 : req.dir_ordinal = rte_cpu_to_le_16(dir_ordinal);
6157 : 0 : req.dir_ext = rte_cpu_to_le_16(dir_ext);
6158 : 0 : req.dir_attr = rte_cpu_to_le_16(dir_attr);
6159 : 0 : req.dir_data_length = rte_cpu_to_le_32(data_len);
6160 : 0 : req.host_src_addr = rte_cpu_to_le_64(dma_handle);
6161 : :
6162 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6163 : :
6164 : 0 : rte_free(buf);
6165 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6166 : : HWRM_UNLOCK();
6167 : :
6168 : 0 : return rc;
6169 : : }
6170 : :
6171 : : static void
6172 : 0 : bnxt_vnic_count(struct bnxt_vnic_info *vnic __rte_unused, void *cbdata)
6173 : : {
6174 : : uint32_t *count = cbdata;
6175 : :
6176 : 0 : *count = *count + 1;
6177 : 0 : }
6178 : :
6179 : 0 : static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
6180 : : struct bnxt_vnic_info *vnic __rte_unused)
6181 : : {
6182 : 0 : return 0;
6183 : : }
6184 : :
6185 : 0 : int bnxt_vf_vnic_count(struct bnxt *bp, uint16_t vf)
6186 : : {
6187 : 0 : uint32_t count = 0;
6188 : :
6189 : 0 : bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
6190 : : &count, bnxt_vnic_count_hwrm_stub);
6191 : :
6192 : 0 : return count;
6193 : : }
6194 : :
6195 : 0 : static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
6196 : : uint16_t *vnic_ids)
6197 : : {
6198 : 0 : struct hwrm_func_vf_vnic_ids_query_input req = {0};
6199 : 0 : struct hwrm_func_vf_vnic_ids_query_output *resp =
6200 : : bp->hwrm_cmd_resp_addr;
6201 : : int rc;
6202 : :
6203 : : /* First query all VNIC ids */
6204 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_VF_VNIC_IDS_QUERY, BNXT_USE_CHIMP_MB);
6205 : :
6206 : 0 : req.vf_id = rte_cpu_to_le_16(bp->pf->first_vf_id + vf);
6207 : 0 : req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf->total_vnics);
6208 : 0 : req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_malloc_virt2iova(vnic_ids));
6209 : :
6210 [ # # ]: 0 : if (req.vnic_id_tbl_addr == RTE_BAD_IOVA) {
6211 : : HWRM_UNLOCK();
6212 : 0 : PMD_DRV_LOG_LINE(ERR,
6213 : : "unable to map VNIC ID table address to physical memory");
6214 : 0 : return -ENOMEM;
6215 : : }
6216 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6217 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6218 : 0 : rc = RTE_MIN(rte_le_to_cpu_32(resp->vnic_id_cnt),
6219 : : (uint32_t)bp->pf->total_vnics);
6220 : :
6221 : : HWRM_UNLOCK();
6222 : :
6223 : 0 : return rc;
6224 : : }
6225 : :
6226 : : /*
6227 : : * This function queries the VNIC IDs for a specified VF. It then calls
6228 : : * the vnic_cb to update the necessary field in vnic_info with cbdata.
6229 : : * Then it calls the hwrm_cb function to program this new vnic configuration.
6230 : : */
6231 : 0 : int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
6232 : : void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
6233 : : int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
6234 : : {
6235 : : struct bnxt_vnic_info vnic;
6236 : : int rc = 0;
6237 : : int i, num_vnic_ids;
6238 : : uint16_t *vnic_ids;
6239 : : size_t vnic_id_sz;
6240 : : size_t sz;
6241 : :
6242 : : /* First query all VNIC ids */
6243 : 0 : vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
6244 : 0 : vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
6245 : : RTE_CACHE_LINE_SIZE);
6246 [ # # ]: 0 : if (vnic_ids == NULL)
6247 : : return -ENOMEM;
6248 : :
6249 [ # # ]: 0 : for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
6250 : 0 : rte_mem_lock_page(((char *)vnic_ids) + sz);
6251 : :
6252 : 0 : num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
6253 : :
6254 [ # # ]: 0 : if (num_vnic_ids < 0) {
6255 : 0 : rte_free(vnic_ids);
6256 : 0 : return num_vnic_ids;
6257 : : }
6258 : :
6259 : : /* Retrieve VNIC, update bd_stall then update */
6260 : :
6261 [ # # ]: 0 : for (i = 0; i < num_vnic_ids; i++) {
6262 : : memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
6263 : 0 : vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
6264 : 0 : rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf->first_vf_id + vf);
6265 [ # # ]: 0 : if (rc)
6266 : : break;
6267 [ # # ]: 0 : if (vnic.mru <= 4) /* Indicates unallocated */
6268 : 0 : continue;
6269 : :
6270 : 0 : vnic_cb(&vnic, cbdata);
6271 : :
6272 : 0 : rc = hwrm_cb(bp, &vnic);
6273 [ # # ]: 0 : if (rc)
6274 : : break;
6275 : : }
6276 : :
6277 : 0 : rte_free(vnic_ids);
6278 : :
6279 : 0 : return rc;
6280 : : }
6281 : :
6282 : 0 : int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
6283 : : bool on)
6284 : : {
6285 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
6286 : 0 : struct hwrm_func_cfg_input req = {0};
6287 : : int rc;
6288 : :
6289 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
6290 : :
6291 : 0 : req.fid = rte_cpu_to_le_16(bp->pf->vf_info[vf].fid);
6292 : 0 : req.enables |= rte_cpu_to_le_32(
6293 : : HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
6294 [ # # ]: 0 : req.vlan_antispoof_mode = on ?
6295 : : HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
6296 : : HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
6297 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6298 : :
6299 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6300 : : HWRM_UNLOCK();
6301 : :
6302 : 0 : return rc;
6303 : : }
6304 : :
6305 : 0 : int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
6306 : : {
6307 : : struct bnxt_vnic_info vnic;
6308 : : uint16_t *vnic_ids;
6309 : : size_t vnic_id_sz;
6310 : : int num_vnic_ids, i;
6311 : : size_t sz;
6312 : : int rc;
6313 : :
6314 : 0 : vnic_id_sz = bp->pf->total_vnics * sizeof(*vnic_ids);
6315 : 0 : vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
6316 : : RTE_CACHE_LINE_SIZE);
6317 [ # # ]: 0 : if (vnic_ids == NULL)
6318 : : return -ENOMEM;
6319 : :
6320 [ # # ]: 0 : for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
6321 : 0 : rte_mem_lock_page(((char *)vnic_ids) + sz);
6322 : :
6323 : 0 : rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
6324 [ # # ]: 0 : if (rc <= 0)
6325 : 0 : goto exit;
6326 : : num_vnic_ids = rc;
6327 : :
6328 : : /*
6329 : : * Loop through to find the default VNIC ID.
6330 : : * TODO: The easier way would be to obtain the resp->dflt_vnic_id
6331 : : * by sending the hwrm_func_qcfg command to the firmware.
6332 : : */
6333 [ # # ]: 0 : for (i = 0; i < num_vnic_ids; i++) {
6334 : : memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
6335 : 0 : vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
6336 : 0 : rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
6337 : 0 : bp->pf->first_vf_id + vf);
6338 [ # # ]: 0 : if (rc)
6339 : 0 : goto exit;
6340 [ # # ]: 0 : if (vnic.func_default) {
6341 : 0 : rte_free(vnic_ids);
6342 : 0 : return vnic.fw_vnic_id;
6343 : : }
6344 : : }
6345 : : /* Could not find a default VNIC. */
6346 : 0 : PMD_DRV_LOG_LINE(ERR, "No default VNIC");
6347 : 0 : exit:
6348 : 0 : rte_free(vnic_ids);
6349 : 0 : return rc;
6350 : : }
6351 : :
6352 : 0 : int bnxt_hwrm_set_em_filter(struct bnxt *bp,
6353 : : uint16_t dst_id,
6354 : : struct bnxt_filter_info *filter)
6355 : : {
6356 : : int rc = 0;
6357 : 0 : struct hwrm_cfa_em_flow_alloc_input req = {.req_type = 0 };
6358 : 0 : struct hwrm_cfa_em_flow_alloc_output *resp = bp->hwrm_cmd_resp_addr;
6359 : : uint32_t enables = 0;
6360 : :
6361 [ # # ]: 0 : if (filter->fw_em_filter_id != UINT64_MAX)
6362 : 0 : bnxt_hwrm_clear_em_filter(bp, filter);
6363 : :
6364 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_EM_FLOW_ALLOC, BNXT_USE_KONG(bp));
6365 : :
6366 : 0 : req.flags = rte_cpu_to_le_32(filter->flags);
6367 : :
6368 : 0 : enables = filter->enables |
6369 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_ID;
6370 : 0 : req.dst_id = rte_cpu_to_le_16(dst_id);
6371 : :
6372 [ # # ]: 0 : if (filter->ip_addr_type) {
6373 : 0 : req.ip_addr_type = filter->ip_addr_type;
6374 : 0 : enables |= HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
6375 : : }
6376 [ # # ]: 0 : if (enables &
6377 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
6378 : 0 : req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
6379 [ # # ]: 0 : if (enables &
6380 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
6381 : : memcpy(req.src_macaddr, filter->src_macaddr,
6382 : : RTE_ETHER_ADDR_LEN);
6383 [ # # ]: 0 : if (enables &
6384 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
6385 : : memcpy(req.dst_macaddr, filter->dst_macaddr,
6386 : : RTE_ETHER_ADDR_LEN);
6387 [ # # ]: 0 : if (enables &
6388 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
6389 : 0 : req.ovlan_vid = filter->l2_ovlan;
6390 [ # # ]: 0 : if (enables &
6391 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IVLAN_VID)
6392 : 0 : req.ivlan_vid = filter->l2_ivlan;
6393 [ # # ]: 0 : if (enables &
6394 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_ETHERTYPE)
6395 [ # # ]: 0 : req.ethertype = rte_cpu_to_be_16(filter->ethertype);
6396 [ # # ]: 0 : if (enables &
6397 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
6398 : 0 : req.ip_protocol = filter->ip_protocol;
6399 [ # # ]: 0 : if (enables &
6400 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_IPADDR)
6401 [ # # ]: 0 : req.src_ipaddr[0] = rte_cpu_to_be_32(filter->src_ipaddr[0]);
6402 [ # # ]: 0 : if (enables &
6403 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_IPADDR)
6404 [ # # ]: 0 : req.dst_ipaddr[0] = rte_cpu_to_be_32(filter->dst_ipaddr[0]);
6405 [ # # ]: 0 : if (enables &
6406 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_PORT)
6407 [ # # ]: 0 : req.src_port = rte_cpu_to_be_16(filter->src_port);
6408 [ # # ]: 0 : if (enables &
6409 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_PORT)
6410 [ # # ]: 0 : req.dst_port = rte_cpu_to_be_16(filter->dst_port);
6411 [ # # ]: 0 : if (enables &
6412 : : HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_MIRROR_VNIC_ID)
6413 : 0 : req.mirror_vnic_id = filter->mirror_vnic_id;
6414 : :
6415 : 0 : req.enables = rte_cpu_to_le_32(enables);
6416 : :
6417 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
6418 : :
6419 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6420 : :
6421 : 0 : filter->fw_em_filter_id = rte_le_to_cpu_64(resp->em_filter_id);
6422 : : HWRM_UNLOCK();
6423 : :
6424 : 0 : return rc;
6425 : : }
6426 : :
6427 : 0 : int bnxt_hwrm_clear_em_filter(struct bnxt *bp, struct bnxt_filter_info *filter)
6428 : : {
6429 : : int rc = 0;
6430 : 0 : struct hwrm_cfa_em_flow_free_input req = {.req_type = 0 };
6431 : 0 : struct hwrm_cfa_em_flow_free_output *resp = bp->hwrm_cmd_resp_addr;
6432 : :
6433 [ # # ]: 0 : if (filter->fw_em_filter_id == UINT64_MAX)
6434 : : return 0;
6435 : :
6436 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_EM_FLOW_FREE, BNXT_USE_KONG(bp));
6437 : :
6438 : 0 : req.em_filter_id = rte_cpu_to_le_64(filter->fw_em_filter_id);
6439 : :
6440 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
6441 : :
6442 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6443 : : HWRM_UNLOCK();
6444 : :
6445 : 0 : filter->fw_em_filter_id = UINT64_MAX;
6446 : 0 : filter->fw_l2_filter_id = UINT64_MAX;
6447 : :
6448 : 0 : return 0;
6449 : : }
6450 : :
6451 : 0 : int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
6452 : : uint16_t dst_id,
6453 : : struct bnxt_filter_info *filter)
6454 : : {
6455 : : int rc = 0;
6456 : 0 : struct hwrm_cfa_ntuple_filter_alloc_input req = {.req_type = 0 };
6457 : 0 : struct hwrm_cfa_ntuple_filter_alloc_output *resp =
6458 : : bp->hwrm_cmd_resp_addr;
6459 : : uint32_t enables = 0;
6460 : :
6461 [ # # ]: 0 : if (filter->fw_ntuple_filter_id != UINT64_MAX)
6462 : 0 : bnxt_hwrm_clear_ntuple_filter(bp, filter);
6463 : :
6464 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_ALLOC, BNXT_USE_CHIMP_MB);
6465 : :
6466 : 0 : req.flags = rte_cpu_to_le_32(filter->flags);
6467 : :
6468 : 0 : enables = filter->enables |
6469 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_ID;
6470 : 0 : req.dst_id = rte_cpu_to_le_16(dst_id);
6471 : :
6472 [ # # ]: 0 : if (filter->ip_addr_type) {
6473 : 0 : req.ip_addr_type = filter->ip_addr_type;
6474 : 0 : enables |=
6475 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IPADDR_TYPE;
6476 : : }
6477 [ # # ]: 0 : if (enables &
6478 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID)
6479 : 0 : req.l2_filter_id = rte_cpu_to_le_64(filter->fw_l2_filter_id);
6480 [ # # ]: 0 : if (enables &
6481 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
6482 : : memcpy(req.src_macaddr, filter->src_macaddr,
6483 : : RTE_ETHER_ADDR_LEN);
6484 [ # # ]: 0 : if (enables &
6485 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
6486 [ # # ]: 0 : req.ethertype = rte_cpu_to_be_16(filter->ethertype);
6487 [ # # ]: 0 : if (enables &
6488 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_IP_PROTOCOL)
6489 : 0 : req.ip_protocol = filter->ip_protocol;
6490 [ # # ]: 0 : if (enables &
6491 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR)
6492 : 0 : req.src_ipaddr[0] = rte_cpu_to_le_32(filter->src_ipaddr[0]);
6493 [ # # ]: 0 : if (enables &
6494 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_IPADDR_MASK)
6495 : 0 : req.src_ipaddr_mask[0] =
6496 : 0 : rte_cpu_to_le_32(filter->src_ipaddr_mask[0]);
6497 [ # # ]: 0 : if (enables &
6498 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR)
6499 : 0 : req.dst_ipaddr[0] = rte_cpu_to_le_32(filter->dst_ipaddr[0]);
6500 [ # # ]: 0 : if (enables &
6501 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_IPADDR_MASK)
6502 : 0 : req.dst_ipaddr_mask[0] =
6503 [ # # ]: 0 : rte_cpu_to_be_32(filter->dst_ipaddr_mask[0]);
6504 [ # # ]: 0 : if (enables &
6505 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT)
6506 : 0 : req.src_port = rte_cpu_to_le_16(filter->src_port);
6507 [ # # ]: 0 : if (enables &
6508 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_PORT_MASK)
6509 : 0 : req.src_port_mask = rte_cpu_to_le_16(filter->src_port_mask);
6510 [ # # ]: 0 : if (enables &
6511 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT)
6512 : 0 : req.dst_port = rte_cpu_to_le_16(filter->dst_port);
6513 [ # # ]: 0 : if (enables &
6514 : : HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_PORT_MASK)
6515 : 0 : req.dst_port_mask = rte_cpu_to_le_16(filter->dst_port_mask);
6516 : :
6517 : 0 : req.enables = rte_cpu_to_le_32(enables);
6518 : :
6519 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6520 : :
6521 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6522 : :
6523 : 0 : filter->fw_ntuple_filter_id = rte_le_to_cpu_64(resp->ntuple_filter_id);
6524 : 0 : filter->flow_id = rte_le_to_cpu_32(resp->flow_id);
6525 : : HWRM_UNLOCK();
6526 : :
6527 : 0 : return rc;
6528 : : }
6529 : :
6530 : 0 : int bnxt_hwrm_clear_ntuple_filter(struct bnxt *bp,
6531 : : struct bnxt_filter_info *filter)
6532 : : {
6533 : : int rc = 0;
6534 : 0 : struct hwrm_cfa_ntuple_filter_free_input req = {.req_type = 0 };
6535 : 0 : struct hwrm_cfa_ntuple_filter_free_output *resp =
6536 : : bp->hwrm_cmd_resp_addr;
6537 : :
6538 [ # # ]: 0 : if (filter->fw_ntuple_filter_id == UINT64_MAX)
6539 : : return 0;
6540 : :
6541 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_NTUPLE_FILTER_FREE, BNXT_USE_CHIMP_MB);
6542 : :
6543 : 0 : req.ntuple_filter_id = rte_cpu_to_le_64(filter->fw_ntuple_filter_id);
6544 : :
6545 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6546 : :
6547 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6548 : : HWRM_UNLOCK();
6549 : :
6550 : 0 : filter->fw_ntuple_filter_id = UINT64_MAX;
6551 : :
6552 : 0 : return 0;
6553 : : }
6554 : :
6555 : : int
6556 : 0 : bnxt_vnic_rss_configure_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
6557 : : {
6558 : 0 : struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
6559 : 0 : uint8_t *rxq_state = bp->eth_dev->data->rx_queue_state;
6560 : 0 : struct hwrm_vnic_rss_cfg_input req = {.req_type = 0 };
6561 : 0 : struct bnxt_rx_queue **rxqs = bp->rx_queues;
6562 : 0 : uint16_t *ring_tbl = vnic->rss_table;
6563 : 0 : int nr_ctxs = vnic->num_lb_ctxts;
6564 : 0 : int max_rings = bp->rx_nr_rings;
6565 : : int i, j, k, cnt;
6566 : : int rc = 0;
6567 : :
6568 [ # # ]: 0 : for (i = 0, k = 0; i < nr_ctxs; i++) {
6569 : : struct bnxt_rx_ring_info *rxr;
6570 : : struct bnxt_cp_ring_info *cpr;
6571 : :
6572 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
6573 : :
6574 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
6575 : 0 : req.hash_type = rte_cpu_to_le_32(bnxt_sanitize_rss_type(bp, vnic->hash_type));
6576 : 0 : req.hash_mode_flags = vnic->hash_mode;
6577 : 0 : req.ring_select_mode = vnic->ring_select_mode;
6578 : :
6579 : 0 : req.ring_grp_tbl_addr =
6580 : 0 : rte_cpu_to_le_64(vnic->rss_table_dma_addr +
6581 : : i * BNXT_RSS_ENTRIES_PER_CTX_P5 *
6582 : : 2 * sizeof(*ring_tbl));
6583 : 0 : req.hash_key_tbl_addr =
6584 : 0 : rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
6585 : :
6586 : 0 : req.ring_table_pair_index = i;
6587 : 0 : req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
6588 : :
6589 [ # # ]: 0 : for (j = 0; j < 64; j++) {
6590 : : uint16_t ring_id;
6591 : :
6592 : : /* Find next active ring. */
6593 [ # # ]: 0 : for (cnt = 0; cnt < max_rings; cnt++) {
6594 [ # # ]: 0 : if (rxq_state[k] != RTE_ETH_QUEUE_STATE_STOPPED)
6595 : : break;
6596 [ # # ]: 0 : if (++k == max_rings)
6597 : : k = 0;
6598 : : }
6599 : :
6600 : : /* Return if no rings are active. */
6601 [ # # ]: 0 : if (cnt == max_rings) {
6602 : : HWRM_UNLOCK();
6603 : 0 : return 0;
6604 : : }
6605 : :
6606 : : /* Add rx/cp ring pair to RSS table. */
6607 : 0 : rxr = rxqs[k]->rx_ring;
6608 : 0 : cpr = rxqs[k]->cp_ring;
6609 : :
6610 : 0 : ring_id = rxr->rx_ring_struct->fw_ring_id;
6611 : 0 : *ring_tbl++ = rte_cpu_to_le_16(ring_id);
6612 : 0 : ring_id = cpr->cp_ring_struct->fw_ring_id;
6613 : 0 : *ring_tbl++ = rte_cpu_to_le_16(ring_id);
6614 : :
6615 [ # # ]: 0 : if (++k == max_rings)
6616 : : k = 0;
6617 : : }
6618 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
6619 : : BNXT_USE_CHIMP_MB);
6620 : :
6621 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6622 : : HWRM_UNLOCK();
6623 : : }
6624 : :
6625 : : return rc;
6626 : : }
6627 : :
6628 : 0 : int bnxt_vnic_rss_configure(struct bnxt *bp, struct bnxt_vnic_info *vnic)
6629 : : {
6630 : : unsigned int rss_idx, fw_idx, i;
6631 : :
6632 [ # # ]: 0 : if (vnic->fw_vnic_id == INVALID_HW_RING_ID)
6633 : : return 0;
6634 : :
6635 [ # # ]: 0 : if (vnic->rss_table == NULL)
6636 : : return 0;
6637 : :
6638 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp))
6639 : 0 : return bnxt_vnic_rss_configure_p5(bp, vnic);
6640 : :
6641 : : /*
6642 : : * Fill the RSS hash & redirection table with
6643 : : * ring group ids for all VNICs
6644 : : */
6645 [ # # ]: 0 : for (rss_idx = 0, fw_idx = 0; rss_idx < HW_HASH_INDEX_SIZE;
6646 : 0 : rss_idx++, fw_idx++) {
6647 [ # # ]: 0 : for (i = 0; i < bp->rx_cp_nr_rings; i++) {
6648 : 0 : fw_idx %= bp->rx_cp_nr_rings;
6649 [ # # ]: 0 : if (vnic->fw_grp_ids[fw_idx] != INVALID_HW_RING_ID)
6650 : : break;
6651 : 0 : fw_idx++;
6652 : : }
6653 : :
6654 [ # # ]: 0 : if (i == bp->rx_cp_nr_rings)
6655 : : return 0;
6656 : :
6657 : 0 : vnic->rss_table[rss_idx] = vnic->fw_grp_ids[fw_idx];
6658 : : }
6659 : :
6660 : 0 : return bnxt_hwrm_vnic_rss_cfg(bp, vnic);
6661 : : }
6662 : :
6663 : : static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal,
6664 : : struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req)
6665 : : {
6666 : : uint16_t flags;
6667 : :
6668 : 0 : req->num_cmpl_aggr_int = rte_cpu_to_le_16(hw_coal->num_cmpl_aggr_int);
6669 : :
6670 : : /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
6671 : 0 : req->num_cmpl_dma_aggr = rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr);
6672 : :
6673 : : /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */
6674 : 0 : req->num_cmpl_dma_aggr_during_int =
6675 : 0 : rte_cpu_to_le_16(hw_coal->num_cmpl_dma_aggr_during_int);
6676 : :
6677 : 0 : req->int_lat_tmr_max = rte_cpu_to_le_16(hw_coal->int_lat_tmr_max);
6678 : :
6679 : : /* min timer set to 1/2 of interrupt timer */
6680 : 0 : req->int_lat_tmr_min = rte_cpu_to_le_16(hw_coal->int_lat_tmr_min);
6681 : :
6682 : : /* buf timer set to 1/4 of interrupt timer */
6683 : 0 : req->cmpl_aggr_dma_tmr = rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr);
6684 : :
6685 : 0 : req->cmpl_aggr_dma_tmr_during_int =
6686 : 0 : rte_cpu_to_le_16(hw_coal->cmpl_aggr_dma_tmr_during_int);
6687 : :
6688 : : flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
6689 : : HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
6690 : 0 : req->flags = rte_cpu_to_le_16(flags);
6691 : 0 : }
6692 : :
6693 : 0 : static int bnxt_hwrm_set_coal_params_p5(struct bnxt *bp,
6694 : : struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *agg_req)
6695 : : {
6696 : 0 : struct hwrm_ring_aggint_qcaps_input req = {0};
6697 : 0 : struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
6698 : : uint32_t enables;
6699 : : uint16_t flags;
6700 : : int rc;
6701 : :
6702 [ # # ]: 0 : HWRM_PREP(&req, HWRM_RING_AGGINT_QCAPS, BNXT_USE_CHIMP_MB);
6703 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6704 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6705 : :
6706 : 0 : agg_req->num_cmpl_dma_aggr = resp->num_cmpl_dma_aggr_max;
6707 : 0 : agg_req->cmpl_aggr_dma_tmr = resp->cmpl_aggr_dma_tmr_min;
6708 : :
6709 : : flags = HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_TIMER_RESET |
6710 : : HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_FLAGS_RING_IDLE;
6711 : 0 : agg_req->flags = rte_cpu_to_le_16(flags);
6712 : : enables =
6713 : : HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_CMPL_AGGR_DMA_TMR |
6714 : : HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS_INPUT_ENABLES_NUM_CMPL_DMA_AGGR;
6715 : 0 : agg_req->enables = rte_cpu_to_le_32(enables);
6716 : :
6717 : : HWRM_UNLOCK();
6718 : 0 : return rc;
6719 : : }
6720 : :
6721 : 0 : int bnxt_hwrm_set_ring_coal(struct bnxt *bp,
6722 : : struct bnxt_coal *coal, uint16_t ring_id)
6723 : : {
6724 : 0 : struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req = {0};
6725 : 0 : struct hwrm_ring_cmpl_ring_cfg_aggint_params_output *resp =
6726 : : bp->hwrm_cmd_resp_addr;
6727 : : int rc;
6728 : :
6729 : : /* Set ring coalesce parameters only for 100G NICs */
6730 [ # # ]: 0 : if (BNXT_CHIP_P5_P7(bp)) {
6731 [ # # ]: 0 : if (bnxt_hwrm_set_coal_params_p5(bp, &req))
6732 : : return -1;
6733 [ # # ]: 0 : } else if (bnxt_stratus_device(bp)) {
6734 : : bnxt_hwrm_set_coal_params(coal, &req);
6735 : : } else {
6736 : : return 0;
6737 : : }
6738 : :
6739 [ # # ]: 0 : HWRM_PREP(&req,
6740 : : HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS,
6741 : : BNXT_USE_CHIMP_MB);
6742 : 0 : req.ring_id = rte_cpu_to_le_16(ring_id);
6743 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6744 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6745 : : HWRM_UNLOCK();
6746 : 0 : return 0;
6747 : : }
6748 : :
6749 : 0 : static void bnxt_init_ctx_initializer(struct bnxt_ctx_mem *ctxm,
6750 : : uint8_t init_val,
6751 : : uint8_t init_offset,
6752 : : bool init_mask_set)
6753 : : {
6754 : 0 : ctxm->init_value = init_val;
6755 : 0 : ctxm->init_offset = BNXT_CTX_INIT_INVALID_OFFSET;
6756 [ # # ]: 0 : if (init_mask_set) {
6757 : 0 : ctxm->init_offset = (uint16_t)(init_offset * 4);
6758 [ # # ]: 0 : if (ctxm->init_offset >= ctxm->entry_size) {
6759 : 0 : PMD_DRV_LOG_LINE(WARNING,
6760 : : "ctx type 0x%x: init_offset %u >= entry_size %u, disabling init",
6761 : : ctxm->type, ctxm->init_offset, ctxm->entry_size);
6762 : 0 : ctxm->init_value = 0;
6763 : 0 : ctxm->init_offset = BNXT_CTX_INIT_INVALID_OFFSET;
6764 : : }
6765 : : } else {
6766 : 0 : ctxm->init_value = 0;
6767 : : }
6768 : 0 : }
6769 : :
6770 : 0 : static int bnxt_alloc_all_ctx_pg_info(struct bnxt *bp)
6771 : : {
6772 : 0 : struct bnxt_ctx_mem_info *ctx = bp->ctx;
6773 : : char name[RTE_MEMZONE_NAMESIZE];
6774 : : uint16_t type;
6775 : :
6776 [ # # ]: 0 : for (type = 0; type < ctx->types; type++) {
6777 : 0 : struct bnxt_ctx_mem *ctxm = &ctx->ctx_arr[type];
6778 : : int n = 1;
6779 : :
6780 [ # # # # ]: 0 : if (!ctxm->max_entries || ctxm->pg_info)
6781 : 0 : continue;
6782 : :
6783 [ # # ]: 0 : if (ctxm->instance_bmap)
6784 : 0 : n = hweight32(ctxm->instance_bmap);
6785 : :
6786 : 0 : snprintf(name, sizeof(name), "bnxt_ctx_pgmem_%d_%d",
6787 : 0 : bp->eth_dev->data->port_id, type);
6788 : 0 : ctxm->pg_info = rte_malloc(name, sizeof(*ctxm->pg_info) * n,
6789 : : RTE_CACHE_LINE_SIZE);
6790 [ # # ]: 0 : if (!ctxm->pg_info)
6791 : : return -ENOMEM;
6792 : : }
6793 : : return 0;
6794 : : }
6795 : :
6796 : : static void bnxt_init_ctx_v2_driver_managed(struct bnxt *bp __rte_unused,
6797 : : struct bnxt_ctx_mem *ctxm)
6798 : : {
6799 [ # # ]: 0 : switch (ctxm->type) {
6800 : 0 : case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_SQ_DB_SHADOW:
6801 : : case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_RQ_DB_SHADOW:
6802 : : case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_SRQ_DB_SHADOW:
6803 : : case HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_CQ_DB_SHADOW:
6804 : : /* FALLTHROUGH */
6805 : 0 : ctxm->entry_size = 0;
6806 : 0 : ctxm->min_entries = 1;
6807 : 0 : ctxm->max_entries = 1;
6808 : 0 : break;
6809 : : }
6810 : : }
6811 : :
6812 : 0 : int bnxt_hwrm_func_backing_store_qcaps_v2(struct bnxt *bp)
6813 : : {
6814 : 0 : struct hwrm_func_backing_store_qcaps_v2_input req = {0};
6815 : 0 : struct hwrm_func_backing_store_qcaps_v2_output *resp =
6816 : : bp->hwrm_cmd_resp_addr;
6817 : 0 : struct bnxt_ctx_mem_info *ctx = bp->ctx;
6818 : : uint16_t last_valid_type = BNXT_CTX_INV;
6819 : : uint16_t last_valid_idx = 0;
6820 : : uint16_t types, type;
6821 : : int rc;
6822 : :
6823 : : types = 0;
6824 : : type = 0;
6825 : : do {
6826 : : struct bnxt_ctx_mem *ctxm;
6827 : : uint8_t init_val, init_off, i;
6828 : : uint32_t *p;
6829 : : uint32_t flags;
6830 : : bool cnt = true;
6831 : :
6832 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS_V2, BNXT_USE_CHIMP_MB);
6833 : 0 : req.type = rte_cpu_to_le_16(type);
6834 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6835 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6836 : :
6837 : 0 : flags = rte_le_to_cpu_32(resp->flags);
6838 : 0 : type = rte_le_to_cpu_16(resp->next_valid_type);
6839 [ # # ]: 0 : if (!(flags & HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_TYPE_VALID) ||
6840 [ # # ]: 0 : (rte_le_to_cpu_16(req.type) ==
6841 : 0 : HWRM_FUNC_BACKING_STORE_QCAPS_V2_INPUT_TYPE_TTX_PACING_TQM_RING &&
6842 [ # # ]: 0 : !(bp->fw_cap & BNXT_FW_CAP_TIMED_TX_PACING))) {
6843 : : cnt = false;
6844 : 0 : goto next;
6845 : : }
6846 : :
6847 : 0 : ctxm = &bp->ctx->ctx_arr[types];
6848 : 0 : ctxm->type = rte_le_to_cpu_16(resp->type);
6849 : :
6850 : 0 : ctxm->flags = flags;
6851 [ # # ]: 0 : if (flags &
6852 : : HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_DRIVER_MANAGED_MEMORY) {
6853 : : bnxt_init_ctx_v2_driver_managed(bp, ctxm);
6854 : 0 : goto next;
6855 : : }
6856 : 0 : ctxm->entry_size = rte_le_to_cpu_16(resp->entry_size);
6857 : :
6858 [ # # ]: 0 : if (ctxm->entry_size == 0)
6859 : 0 : goto next;
6860 : :
6861 : 0 : ctxm->instance_bmap = rte_le_to_cpu_32(resp->instance_bit_map);
6862 : 0 : ctxm->entry_multiple = resp->entry_multiple;
6863 : 0 : ctxm->max_entries = rte_le_to_cpu_32(resp->max_num_entries);
6864 : 0 : ctxm->min_entries = rte_le_to_cpu_32(resp->min_num_entries);
6865 : 0 : init_val = resp->ctx_init_value;
6866 : 0 : init_off = resp->ctx_init_offset;
6867 : 0 : bnxt_init_ctx_initializer(ctxm, init_val, init_off,
6868 : 0 : BNXT_CTX_INIT_VALID(flags));
6869 : 0 : ctxm->split_entry_cnt = RTE_MIN(resp->subtype_valid_cnt,
6870 : : BNXT_MAX_SPLIT_ENTRY);
6871 [ # # ]: 0 : for (i = 0, p = &resp->split_entry_0; i < ctxm->split_entry_cnt;
6872 : 0 : i++, p++)
6873 : 0 : ctxm->split[i] = rte_le_to_cpu_32(*p);
6874 : :
6875 : 0 : PMD_DRV_LOG_LINE(DEBUG,
6876 : : "type:0x%x size:%d multiple:%d max:%d min:%d split:%d init_val:%d init_off:%d init:%d bmap:0x%x",
6877 : : ctxm->type, ctxm->entry_size,
6878 : : ctxm->entry_multiple, ctxm->max_entries, ctxm->min_entries,
6879 : : ctxm->split_entry_cnt, init_val, init_off,
6880 : : BNXT_CTX_INIT_VALID(flags), ctxm->instance_bmap);
6881 : 0 : last_valid_type = ctxm->type;
6882 : : last_valid_idx = types;
6883 : 0 : next:
6884 [ # # ]: 0 : if (cnt)
6885 : 0 : types++;
6886 : : HWRM_UNLOCK();
6887 [ # # # # ]: 0 : } while (types < bp->ctx->types && type != BNXT_CTX_INV);
6888 : 0 : ctx->ctx_arr[last_valid_idx].last = true;
6889 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Last valid type 0x%x", last_valid_type);
6890 : :
6891 : 0 : rc = bnxt_alloc_all_ctx_pg_info(bp);
6892 [ # # ]: 0 : if (rc == 0)
6893 : 0 : rc = bnxt_alloc_ctx_pg_tbls(bp);
6894 : : return rc;
6895 : : }
6896 : :
6897 : 0 : int bnxt_hwrm_func_backing_store_types_count(struct bnxt *bp)
6898 : : {
6899 : 0 : struct hwrm_func_backing_store_qcaps_v2_input req = {0};
6900 : 0 : struct hwrm_func_backing_store_qcaps_v2_output *resp =
6901 : : bp->hwrm_cmd_resp_addr;
6902 : : uint16_t type = 0;
6903 : : int types = 0;
6904 : : int rc;
6905 : :
6906 : : /* Calculate number of valid context types */
6907 : : do {
6908 : : uint32_t flags;
6909 : :
6910 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS_V2, BNXT_USE_CHIMP_MB);
6911 : 0 : req.type = rte_cpu_to_le_16(type);
6912 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6913 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
6914 : :
6915 : 0 : flags = rte_le_to_cpu_32(resp->flags);
6916 : 0 : type = rte_le_to_cpu_16(resp->next_valid_type);
6917 : : HWRM_UNLOCK();
6918 : :
6919 [ # # ]: 0 : if ((flags & HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_FLAGS_TYPE_VALID) &&
6920 [ # # ]: 0 : !(rte_le_to_cpu_16(req.type) ==
6921 : : HWRM_FUNC_BACKING_STORE_QCAPS_V2_INPUT_TYPE_TTX_PACING_TQM_RING &&
6922 [ # # ]: 0 : !(bp->fw_cap & BNXT_FW_CAP_TIMED_TX_PACING))) {
6923 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Valid types 0x%x", req.type);
6924 : 0 : types++;
6925 : : }
6926 [ # # ]: 0 : } while (type != HWRM_FUNC_BACKING_STORE_QCAPS_V2_OUTPUT_TYPE_INVALID);
6927 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Number of valid types %d", types);
6928 : :
6929 : 0 : return types;
6930 : : }
6931 : :
6932 : 0 : int bnxt_hwrm_func_backing_store_ctx_alloc(struct bnxt *bp, uint16_t types)
6933 : : {
6934 : : int alloc_len = sizeof(struct bnxt_ctx_mem_info);
6935 : :
6936 [ # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp) ||
6937 [ # # # # ]: 0 : bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
6938 : 0 : BNXT_VF(bp) ||
6939 [ # # ]: 0 : bp->ctx)
6940 : : return 0;
6941 : :
6942 : 0 : bp->ctx = rte_zmalloc("bnxt_ctx_mem", alloc_len,
6943 : : RTE_CACHE_LINE_SIZE);
6944 [ # # ]: 0 : if (bp->ctx == NULL)
6945 : : return -ENOMEM;
6946 : :
6947 : 0 : alloc_len = sizeof(struct bnxt_ctx_mem) * types;
6948 : 0 : bp->ctx->ctx_arr = rte_zmalloc("bnxt_ctx_mem_arr",
6949 : : alloc_len,
6950 : : RTE_CACHE_LINE_SIZE);
6951 [ # # ]: 0 : if (bp->ctx->ctx_arr == NULL)
6952 : : return -ENOMEM;
6953 : :
6954 : 0 : bp->ctx->types = types;
6955 : 0 : return 0;
6956 : : }
6957 : :
6958 : 0 : int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
6959 : : {
6960 : 0 : struct hwrm_func_backing_store_qcaps_input req = {0};
6961 : 0 : struct hwrm_func_backing_store_qcaps_output *resp =
6962 : : bp->hwrm_cmd_resp_addr;
6963 : : struct bnxt_ctx_pg_info *ctx_pg;
6964 : : struct bnxt_ctx_mem_info *ctx;
6965 : : int rc, i, tqm_rings;
6966 : :
6967 [ # # ]: 0 : if (!BNXT_CHIP_P5_P7(bp) ||
6968 [ # # # # ]: 0 : bp->hwrm_spec_code < HWRM_VERSION_1_9_2 ||
6969 : 0 : BNXT_VF(bp) ||
6970 [ # # ]: 0 : bp->ctx->flags & BNXT_CTX_FLAG_INITED)
6971 : : return 0;
6972 : :
6973 : : ctx = bp->ctx;
6974 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_QCAPS, BNXT_USE_CHIMP_MB);
6975 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
6976 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
6977 : :
6978 : 0 : ctx->qp_max_entries = rte_le_to_cpu_32(resp->qp_max_entries);
6979 : 0 : ctx->qp_min_qp1_entries =
6980 : 0 : rte_le_to_cpu_16(resp->qp_min_qp1_entries);
6981 : 0 : ctx->qp_max_l2_entries =
6982 : 0 : rte_le_to_cpu_16(resp->qp_max_l2_entries);
6983 : 0 : ctx->qp_entry_size = rte_le_to_cpu_16(resp->qp_entry_size);
6984 : 0 : ctx->srq_max_l2_entries =
6985 : 0 : rte_le_to_cpu_16(resp->srq_max_l2_entries);
6986 : 0 : ctx->srq_max_entries = rte_le_to_cpu_32(resp->srq_max_entries);
6987 : 0 : ctx->srq_entry_size = rte_le_to_cpu_16(resp->srq_entry_size);
6988 [ # # ]: 0 : if (BNXT_CHIP_P7(bp))
6989 : 0 : ctx->cq_max_l2_entries =
6990 : 0 : RTE_MIN(BNXT_P7_CQ_MAX_L2_ENT,
6991 : : rte_le_to_cpu_16(resp->cq_max_l2_entries));
6992 : : else
6993 : 0 : ctx->cq_max_l2_entries =
6994 : 0 : rte_le_to_cpu_16(resp->cq_max_l2_entries);
6995 : 0 : ctx->cq_max_entries = rte_le_to_cpu_32(resp->cq_max_entries);
6996 : 0 : ctx->cq_entry_size = rte_le_to_cpu_16(resp->cq_entry_size);
6997 : 0 : ctx->vnic_max_vnic_entries =
6998 : 0 : rte_le_to_cpu_16(resp->vnic_max_vnic_entries);
6999 : 0 : ctx->vnic_max_ring_table_entries =
7000 : 0 : rte_le_to_cpu_16(resp->vnic_max_ring_table_entries);
7001 : 0 : ctx->vnic_entry_size = rte_le_to_cpu_16(resp->vnic_entry_size);
7002 : 0 : ctx->stat_max_entries =
7003 : 0 : rte_le_to_cpu_32(resp->stat_max_entries);
7004 : 0 : ctx->stat_entry_size = rte_le_to_cpu_16(resp->stat_entry_size);
7005 : 0 : ctx->tqm_entry_size = rte_le_to_cpu_16(resp->tqm_entry_size);
7006 : 0 : ctx->tqm_min_entries_per_ring =
7007 : 0 : rte_le_to_cpu_32(resp->tqm_min_entries_per_ring);
7008 : 0 : ctx->tqm_max_entries_per_ring =
7009 : 0 : rte_le_to_cpu_32(resp->tqm_max_entries_per_ring);
7010 : 0 : ctx->tqm_entries_multiple = resp->tqm_entries_multiple;
7011 [ # # ]: 0 : if (!ctx->tqm_entries_multiple)
7012 : 0 : ctx->tqm_entries_multiple = 1;
7013 : 0 : ctx->mrav_max_entries =
7014 : 0 : rte_le_to_cpu_32(resp->mrav_max_entries);
7015 : 0 : ctx->mrav_entry_size = rte_le_to_cpu_16(resp->mrav_entry_size);
7016 : 0 : ctx->tim_entry_size = rte_le_to_cpu_16(resp->tim_entry_size);
7017 : 0 : ctx->tim_max_entries = rte_le_to_cpu_32(resp->tim_max_entries);
7018 : 0 : ctx->tqm_fp_rings_count = resp->tqm_fp_rings_count;
7019 : :
7020 [ # # ]: 0 : ctx->tqm_fp_rings_count = ctx->tqm_fp_rings_count ?
7021 : 0 : RTE_MIN(ctx->tqm_fp_rings_count,
7022 : : BNXT_MAX_TQM_FP_LEGACY_RINGS) :
7023 : : bp->max_q;
7024 : :
7025 : : /* Check if the ext ring count needs to be counted.
7026 : : * Ext ring count is available only with new FW so we should not
7027 : : * look at the field on older FW.
7028 : : */
7029 [ # # ]: 0 : if (ctx->tqm_fp_rings_count == BNXT_MAX_TQM_FP_LEGACY_RINGS &&
7030 [ # # ]: 0 : bp->hwrm_max_ext_req_len >= BNXT_BACKING_STORE_CFG_LEN) {
7031 : 0 : ctx->tqm_fp_rings_count += resp->tqm_fp_rings_count_ext;
7032 : 0 : ctx->tqm_fp_rings_count = RTE_MIN(BNXT_MAX_TQM_FP_RINGS,
7033 : : ctx->tqm_fp_rings_count);
7034 : : }
7035 : :
7036 : 0 : tqm_rings = ctx->tqm_fp_rings_count + 1;
7037 : :
7038 : 0 : ctx_pg = rte_malloc("bnxt_ctx_pg_mem",
7039 : : sizeof(*ctx_pg) * tqm_rings,
7040 : : RTE_CACHE_LINE_SIZE);
7041 [ # # ]: 0 : if (!ctx_pg) {
7042 : : rc = -ENOMEM;
7043 : 0 : goto ctx_err;
7044 : : }
7045 [ # # ]: 0 : for (i = 0; i < tqm_rings; i++, ctx_pg++)
7046 : 0 : ctx->tqm_mem[i] = ctx_pg;
7047 : :
7048 : 0 : ctx_err:
7049 : : HWRM_UNLOCK();
7050 : 0 : return rc;
7051 : : }
7052 : :
7053 : 0 : int bnxt_hwrm_func_backing_store_cfg_v2(struct bnxt *bp,
7054 : : struct bnxt_ctx_mem *ctxm)
7055 : : {
7056 : 0 : struct hwrm_func_backing_store_cfg_v2_input req = {0};
7057 : 0 : struct hwrm_func_backing_store_cfg_v2_output *resp =
7058 : : bp->hwrm_cmd_resp_addr;
7059 : : struct bnxt_ctx_pg_info *ctx_pg;
7060 : : int i, j, k;
7061 : : uint32_t *p;
7062 : : int rc = 0;
7063 : : int w = 1;
7064 : : int b = 1;
7065 : :
7066 [ # # ]: 0 : if (!BNXT_PF(bp)) {
7067 : 0 : PMD_DRV_LOG_LINE(INFO,
7068 : : "Backing store config V2 can be issued on PF only");
7069 : 0 : return 0;
7070 : : }
7071 : :
7072 [ # # # # ]: 0 : if (!(ctxm->flags & BNXT_CTX_MEM_TYPE_VALID) || !ctxm->pg_info)
7073 : : return 0;
7074 : :
7075 : 0 : if (ctxm->instance_bmap)
7076 : : b = ctxm->instance_bmap;
7077 : :
7078 : 0 : w = hweight32(b);
7079 : :
7080 [ # # ]: 0 : for (i = 0, j = 0; i < w && rc == 0; i++) {
7081 [ # # ]: 0 : if (!(b & (1 << i)))
7082 : 0 : continue;
7083 : :
7084 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG_V2, BNXT_USE_CHIMP_MB);
7085 : 0 : req.type = rte_cpu_to_le_16(ctxm->type);
7086 : 0 : req.entry_size = rte_cpu_to_le_16(ctxm->entry_size);
7087 : 0 : req.subtype_valid_cnt = ctxm->split_entry_cnt;
7088 [ # # ]: 0 : for (k = 0, p = &req.split_entry_0; k < ctxm->split_entry_cnt; k++)
7089 : 0 : p[k] = rte_cpu_to_le_32(ctxm->split[k]);
7090 : :
7091 : 0 : req.instance = rte_cpu_to_le_16(i);
7092 : 0 : ctx_pg = &ctxm->pg_info[j++];
7093 [ # # ]: 0 : if (!ctx_pg->entries)
7094 : 0 : goto unlock;
7095 : :
7096 [ # # ]: 0 : req.num_entries = rte_cpu_to_le_32(ctx_pg->entries);
7097 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7098 : : &req.page_size_pbl_level,
7099 : : &req.page_dir);
7100 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7101 : : "Backing store config V2 type:0x%x last %d, instance %d, hw %d",
7102 : : req.type, ctxm->last, j, w);
7103 [ # # # # ]: 0 : if (ctxm->last && i == (w - 1))
7104 : 0 : req.flags =
7105 : : rte_cpu_to_le_32(BACKING_STORE_CFG_V2_IN_FLG_CFG_ALL_DONE);
7106 : :
7107 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7108 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7109 : 0 : unlock:
7110 : : HWRM_UNLOCK();
7111 : : }
7112 : : return rc;
7113 : : }
7114 : :
7115 : 0 : int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, uint32_t enables)
7116 : : {
7117 : 0 : struct hwrm_func_backing_store_cfg_input req = {0};
7118 : 0 : struct hwrm_func_backing_store_cfg_output *resp =
7119 : : bp->hwrm_cmd_resp_addr;
7120 : 0 : struct bnxt_ctx_mem_info *ctx = bp->ctx;
7121 : : struct bnxt_ctx_pg_info *ctx_pg;
7122 : : uint32_t *num_entries;
7123 : : uint64_t *pg_dir;
7124 : : uint8_t *pg_attr;
7125 : : uint32_t ena;
7126 : : int i, rc;
7127 : :
7128 [ # # ]: 0 : if (!ctx)
7129 : : return 0;
7130 : :
7131 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_BACKING_STORE_CFG, BNXT_USE_CHIMP_MB);
7132 : 0 : req.enables = rte_cpu_to_le_32(enables);
7133 : :
7134 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_QP) {
7135 : : ctx_pg = &ctx->qp_mem;
7136 : 0 : req.qp_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
7137 : 0 : req.qp_num_qp1_entries =
7138 : 0 : rte_cpu_to_le_16(ctx->qp_min_qp1_entries);
7139 : 0 : req.qp_num_l2_entries =
7140 : 0 : rte_cpu_to_le_16(ctx->qp_max_l2_entries);
7141 [ # # ]: 0 : req.qp_entry_size = rte_cpu_to_le_16(ctx->qp_entry_size);
7142 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7143 : : &req.qpc_pg_size_qpc_lvl,
7144 : : &req.qpc_page_dir);
7145 : : }
7146 : :
7147 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_SRQ) {
7148 : : ctx_pg = &ctx->srq_mem;
7149 : 0 : req.srq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
7150 : 0 : req.srq_num_l2_entries =
7151 : 0 : rte_cpu_to_le_16(ctx->srq_max_l2_entries);
7152 [ # # ]: 0 : req.srq_entry_size = rte_cpu_to_le_16(ctx->srq_entry_size);
7153 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7154 : : &req.srq_pg_size_srq_lvl,
7155 : : &req.srq_page_dir);
7156 : : }
7157 : :
7158 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_CQ) {
7159 : : ctx_pg = &ctx->cq_mem;
7160 : 0 : req.cq_num_entries = rte_cpu_to_le_32(ctx_pg->entries);
7161 : 0 : req.cq_num_l2_entries =
7162 : 0 : rte_cpu_to_le_16(ctx->cq_max_l2_entries);
7163 [ # # ]: 0 : req.cq_entry_size = rte_cpu_to_le_16(ctx->cq_entry_size);
7164 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7165 : : &req.cq_pg_size_cq_lvl,
7166 : : &req.cq_page_dir);
7167 : : }
7168 : :
7169 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_VNIC) {
7170 : : ctx_pg = &ctx->vnic_mem;
7171 : 0 : req.vnic_num_vnic_entries =
7172 : 0 : rte_cpu_to_le_16(ctx->vnic_max_vnic_entries);
7173 : 0 : req.vnic_num_ring_table_entries =
7174 : 0 : rte_cpu_to_le_16(ctx->vnic_max_ring_table_entries);
7175 [ # # ]: 0 : req.vnic_entry_size = rte_cpu_to_le_16(ctx->vnic_entry_size);
7176 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7177 : : &req.vnic_pg_size_vnic_lvl,
7178 : : &req.vnic_page_dir);
7179 : : }
7180 : :
7181 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_STAT) {
7182 : : ctx_pg = &ctx->stat_mem;
7183 : 0 : req.stat_num_entries = rte_cpu_to_le_16(ctx->stat_max_entries);
7184 [ # # ]: 0 : req.stat_entry_size = rte_cpu_to_le_16(ctx->stat_entry_size);
7185 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7186 : : &req.stat_pg_size_stat_lvl,
7187 : : &req.stat_page_dir);
7188 : : }
7189 : :
7190 : 0 : req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
7191 : : num_entries = &req.tqm_sp_num_entries;
7192 : : pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl;
7193 : : pg_dir = &req.tqm_sp_page_dir;
7194 : : ena = HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_SP;
7195 [ # # ]: 0 : for (i = 0; i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) {
7196 [ # # ]: 0 : if (!(enables & ena))
7197 : 0 : continue;
7198 : :
7199 : 0 : req.tqm_entry_size = rte_cpu_to_le_16(ctx->tqm_entry_size);
7200 : :
7201 : 0 : ctx_pg = ctx->tqm_mem[i];
7202 [ # # ]: 0 : *num_entries = rte_cpu_to_le_16(ctx_pg->entries);
7203 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir);
7204 : : }
7205 : :
7206 [ # # ]: 0 : if (enables & HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8) {
7207 : : /* DPDK does not need to configure MRAV and TIM type.
7208 : : * So we are skipping over MRAV and TIM. Skip to configure
7209 : : * HWRM_FUNC_BACKING_STORE_CFG_INPUT_ENABLES_TQM_RING8.
7210 : : */
7211 : 0 : ctx_pg = ctx->tqm_mem[BNXT_MAX_TQM_LEGACY_RINGS];
7212 [ # # ]: 0 : req.tqm_ring8_num_entries = rte_cpu_to_le_16(ctx_pg->entries);
7213 : : bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem,
7214 : : &req.tqm_ring8_pg_size_tqm_ring_lvl,
7215 : : &req.tqm_ring8_page_dir);
7216 : : }
7217 : :
7218 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7219 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7220 : : HWRM_UNLOCK();
7221 : :
7222 : 0 : return rc;
7223 : : }
7224 : :
7225 : 0 : int bnxt_hwrm_ext_port_qstats(struct bnxt *bp)
7226 : : {
7227 : 0 : struct hwrm_port_qstats_ext_input req = {0};
7228 : 0 : struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr;
7229 : 0 : struct bnxt_pf_info *pf = bp->pf;
7230 : : int rc;
7231 : :
7232 [ # # ]: 0 : if (!(bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS ||
7233 : : bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS))
7234 : : return 0;
7235 : :
7236 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_QSTATS_EXT, BNXT_USE_CHIMP_MB);
7237 : :
7238 : 0 : req.port_id = rte_cpu_to_le_16(pf->port_id);
7239 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_EXT_TX_PORT_STATS) {
7240 : 0 : req.tx_stat_host_addr =
7241 : 0 : rte_cpu_to_le_64(bp->hw_tx_port_stats_ext_map);
7242 : 0 : req.tx_stat_size =
7243 : : rte_cpu_to_le_16(sizeof(struct tx_port_stats_ext));
7244 : : }
7245 [ # # ]: 0 : if (bp->flags & BNXT_FLAG_EXT_RX_PORT_STATS) {
7246 : 0 : req.rx_stat_host_addr =
7247 : 0 : rte_cpu_to_le_64(bp->hw_rx_port_stats_ext_map);
7248 : 0 : req.rx_stat_size =
7249 : : rte_cpu_to_le_16(sizeof(struct rx_port_stats_ext));
7250 : : }
7251 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7252 : :
7253 [ # # ]: 0 : if (rc) {
7254 : 0 : bp->fw_rx_port_stats_ext_size = 0;
7255 : 0 : bp->fw_tx_port_stats_ext_size = 0;
7256 : : } else {
7257 : 0 : bp->fw_rx_port_stats_ext_size =
7258 : 0 : rte_le_to_cpu_16(resp->rx_stat_size);
7259 : 0 : bp->fw_tx_port_stats_ext_size =
7260 : 0 : rte_le_to_cpu_16(resp->tx_stat_size);
7261 : : }
7262 : :
7263 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7264 : : HWRM_UNLOCK();
7265 : :
7266 : 0 : return rc;
7267 : : }
7268 : :
7269 : : int
7270 : 0 : bnxt_hwrm_tunnel_redirect(struct bnxt *bp, uint8_t type)
7271 : : {
7272 : 0 : struct hwrm_cfa_redirect_tunnel_type_alloc_input req = {0};
7273 : 0 : struct hwrm_cfa_redirect_tunnel_type_alloc_output *resp =
7274 : : bp->hwrm_cmd_resp_addr;
7275 : : int rc = 0;
7276 : :
7277 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_ALLOC, BNXT_USE_CHIMP_MB);
7278 : 0 : req.tunnel_type = type;
7279 : 0 : req.dest_fid = bp->fw_fid;
7280 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7281 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7282 : :
7283 : : HWRM_UNLOCK();
7284 : :
7285 : 0 : return rc;
7286 : : }
7287 : :
7288 : : int
7289 : 0 : bnxt_hwrm_tunnel_redirect_free(struct bnxt *bp, uint8_t type)
7290 : : {
7291 : 0 : struct hwrm_cfa_redirect_tunnel_type_free_input req = {0};
7292 : 0 : struct hwrm_cfa_redirect_tunnel_type_free_output *resp =
7293 : : bp->hwrm_cmd_resp_addr;
7294 : : int rc = 0;
7295 : :
7296 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_FREE, BNXT_USE_CHIMP_MB);
7297 : 0 : req.tunnel_type = type;
7298 : 0 : req.dest_fid = bp->fw_fid;
7299 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7300 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7301 : :
7302 : : HWRM_UNLOCK();
7303 : :
7304 : 0 : return rc;
7305 : : }
7306 : :
7307 : 0 : int bnxt_hwrm_tunnel_redirect_query(struct bnxt *bp, uint32_t *type)
7308 : : {
7309 : 0 : struct hwrm_cfa_redirect_query_tunnel_type_input req = {0};
7310 : 0 : struct hwrm_cfa_redirect_query_tunnel_type_output *resp =
7311 : : bp->hwrm_cmd_resp_addr;
7312 : : int rc = 0;
7313 : :
7314 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_REDIRECT_QUERY_TUNNEL_TYPE, BNXT_USE_CHIMP_MB);
7315 : 0 : req.src_fid = bp->fw_fid;
7316 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7317 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7318 : :
7319 [ # # ]: 0 : if (type)
7320 : 0 : *type = rte_le_to_cpu_32(resp->tunnel_mask);
7321 : :
7322 : : HWRM_UNLOCK();
7323 : :
7324 : 0 : return rc;
7325 : : }
7326 : :
7327 : 0 : int bnxt_hwrm_tunnel_redirect_info(struct bnxt *bp, uint8_t tun_type,
7328 : : uint16_t *dst_fid)
7329 : : {
7330 : 0 : struct hwrm_cfa_redirect_tunnel_type_info_input req = {0};
7331 : 0 : struct hwrm_cfa_redirect_tunnel_type_info_output *resp =
7332 : : bp->hwrm_cmd_resp_addr;
7333 : : int rc = 0;
7334 : :
7335 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_REDIRECT_TUNNEL_TYPE_INFO, BNXT_USE_CHIMP_MB);
7336 : 0 : req.src_fid = bp->fw_fid;
7337 : 0 : req.tunnel_type = tun_type;
7338 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7339 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7340 : :
7341 [ # # ]: 0 : if (dst_fid)
7342 : 0 : *dst_fid = rte_le_to_cpu_16(resp->dest_fid);
7343 : :
7344 : 0 : PMD_DRV_LOG_LINE(DEBUG, "dst_fid: %x", resp->dest_fid);
7345 : :
7346 : : HWRM_UNLOCK();
7347 : :
7348 : 0 : return rc;
7349 : : }
7350 : :
7351 : 0 : int bnxt_hwrm_set_mac(struct bnxt *bp)
7352 : : {
7353 : 0 : struct hwrm_func_vf_cfg_output *resp = bp->hwrm_cmd_resp_addr;
7354 : 0 : struct hwrm_func_vf_cfg_input req = {0};
7355 : : int rc = 0;
7356 : :
7357 [ # # ]: 0 : if (!BNXT_VF(bp))
7358 : : return 0;
7359 : :
7360 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_VF_CFG, BNXT_USE_CHIMP_MB);
7361 : :
7362 : 0 : req.enables =
7363 : : rte_cpu_to_le_32(HWRM_FUNC_VF_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
7364 : : memcpy(req.dflt_mac_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
7365 : :
7366 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7367 : :
7368 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7369 : :
7370 : : HWRM_UNLOCK();
7371 : :
7372 : 0 : return rc;
7373 : : }
7374 : :
7375 : 0 : int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
7376 : : {
7377 : 0 : struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr;
7378 : 0 : struct hwrm_func_drv_if_change_input req = {0};
7379 : : uint32_t flags;
7380 : : int rc;
7381 : :
7382 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE))
7383 : : return 0;
7384 : :
7385 : : /* Do not issue FUNC_DRV_IF_CHANGE during reset recovery.
7386 : : * If we issue FUNC_DRV_IF_CHANGE with flags down before
7387 : : * FUNC_DRV_UNRGTR, FW resets before FUNC_DRV_UNRGTR
7388 : : */
7389 [ # # # # ]: 0 : if (!up && (bp->flags & BNXT_FLAG_FW_RESET))
7390 : : return 0;
7391 : :
7392 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_DRV_IF_CHANGE, BNXT_USE_CHIMP_MB);
7393 : :
7394 [ # # ]: 0 : if (up)
7395 : 0 : req.flags =
7396 : : rte_cpu_to_le_32(HWRM_FUNC_DRV_IF_CHANGE_INPUT_FLAGS_UP);
7397 : :
7398 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7399 : :
7400 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7401 : 0 : flags = rte_le_to_cpu_32(resp->flags);
7402 : : HWRM_UNLOCK();
7403 : :
7404 [ # # ]: 0 : if (!up)
7405 : : return 0;
7406 : :
7407 [ # # ]: 0 : if (flags & HWRM_FUNC_DRV_IF_CHANGE_OUTPUT_FLAGS_HOT_FW_RESET_DONE) {
7408 : 0 : PMD_DRV_LOG_LINE(INFO, "FW reset happened while port was down");
7409 : 0 : bp->flags |= BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE;
7410 : : }
7411 : :
7412 : : return 0;
7413 : : }
7414 : :
7415 : 0 : int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp)
7416 : : {
7417 : 0 : struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
7418 : 0 : struct bnxt_error_recovery_info *info = bp->recovery_info;
7419 : 0 : struct hwrm_error_recovery_qcfg_input req = {0};
7420 : : uint32_t flags = 0;
7421 : : unsigned int i;
7422 : : int rc;
7423 : :
7424 : : /* Older FW does not have error recovery support */
7425 [ # # ]: 0 : if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
7426 : : return 0;
7427 : :
7428 [ # # ]: 0 : HWRM_PREP(&req, HWRM_ERROR_RECOVERY_QCFG, BNXT_USE_CHIMP_MB);
7429 : :
7430 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7431 : :
7432 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7433 : :
7434 : 0 : flags = rte_le_to_cpu_32(resp->flags);
7435 [ # # ]: 0 : if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_HOST)
7436 : 0 : info->flags |= BNXT_FLAG_ERROR_RECOVERY_HOST;
7437 [ # # ]: 0 : else if (flags & HWRM_ERROR_RECOVERY_QCFG_OUTPUT_FLAGS_CO_CPU)
7438 : 0 : info->flags |= BNXT_FLAG_ERROR_RECOVERY_CO_CPU;
7439 : :
7440 [ # # ]: 0 : if ((info->flags & BNXT_FLAG_ERROR_RECOVERY_CO_CPU) &&
7441 [ # # ]: 0 : !(bp->flags & BNXT_FLAG_KONG_MB_EN)) {
7442 : : rc = -EINVAL;
7443 : 0 : goto err;
7444 : : }
7445 : :
7446 : : /* FW returned values are in units of 100msec */
7447 : 0 : info->driver_polling_freq =
7448 : 0 : rte_le_to_cpu_32(resp->driver_polling_freq) * 100;
7449 : 0 : info->primary_func_wait_period =
7450 : 0 : rte_le_to_cpu_32(resp->master_func_wait_period) * 100;
7451 : 0 : info->normal_func_wait_period =
7452 : 0 : rte_le_to_cpu_32(resp->normal_func_wait_period) * 100;
7453 : 0 : info->primary_func_wait_period_after_reset =
7454 : 0 : rte_le_to_cpu_32(resp->master_func_wait_period_after_reset) * 100;
7455 : 0 : info->max_bailout_time_after_reset =
7456 : 0 : rte_le_to_cpu_32(resp->max_bailout_time_after_reset) * 100;
7457 : 0 : info->status_regs[BNXT_FW_STATUS_REG] =
7458 : 0 : rte_le_to_cpu_32(resp->fw_health_status_reg);
7459 : 0 : info->status_regs[BNXT_FW_HEARTBEAT_CNT_REG] =
7460 : 0 : rte_le_to_cpu_32(resp->fw_heartbeat_reg);
7461 : 0 : info->status_regs[BNXT_FW_RECOVERY_CNT_REG] =
7462 : 0 : rte_le_to_cpu_32(resp->fw_reset_cnt_reg);
7463 : 0 : info->status_regs[BNXT_FW_RESET_INPROG_REG] =
7464 : 0 : rte_le_to_cpu_32(resp->reset_inprogress_reg);
7465 : 0 : info->reg_array_cnt =
7466 : 0 : rte_le_to_cpu_32(resp->reg_array_cnt);
7467 : :
7468 [ # # ]: 0 : if (info->reg_array_cnt >= BNXT_NUM_RESET_REG) {
7469 : : rc = -EINVAL;
7470 : 0 : goto err;
7471 : : }
7472 : :
7473 [ # # ]: 0 : for (i = 0; i < info->reg_array_cnt; i++) {
7474 : 0 : info->reset_reg[i] =
7475 : 0 : rte_le_to_cpu_32(resp->reset_reg[i]);
7476 : 0 : info->reset_reg_val[i] =
7477 : 0 : rte_le_to_cpu_32(resp->reset_reg_val[i]);
7478 : 0 : info->delay_after_reset[i] =
7479 : 0 : resp->delay_after_reset[i];
7480 : : }
7481 : 0 : err:
7482 : : HWRM_UNLOCK();
7483 : :
7484 : : /* Map the FW status registers */
7485 [ # # ]: 0 : if (!rc)
7486 : 0 : rc = bnxt_map_fw_health_status_regs(bp);
7487 : :
7488 [ # # ]: 0 : if (rc) {
7489 : 0 : rte_free(bp->recovery_info);
7490 : 0 : bp->recovery_info = NULL;
7491 : : }
7492 : : return rc;
7493 : : }
7494 : :
7495 : 0 : int bnxt_hwrm_fw_reset(struct bnxt *bp)
7496 : : {
7497 : 0 : struct hwrm_fw_reset_output *resp = bp->hwrm_cmd_resp_addr;
7498 : 0 : struct hwrm_fw_reset_input req = {0};
7499 : : int rc;
7500 : :
7501 [ # # ]: 0 : if (!BNXT_PF(bp))
7502 : : return -EOPNOTSUPP;
7503 : :
7504 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FW_RESET, BNXT_USE_KONG(bp));
7505 : :
7506 : 0 : req.embedded_proc_type =
7507 : : HWRM_FW_RESET_INPUT_EMBEDDED_PROC_TYPE_CHIP;
7508 : 0 : req.selfrst_status =
7509 : : HWRM_FW_RESET_INPUT_SELFRST_STATUS_SELFRSTASAP;
7510 : 0 : req.flags = HWRM_FW_RESET_INPUT_FLAGS_RESET_GRACEFUL;
7511 : :
7512 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req),
7513 : : BNXT_USE_KONG(bp));
7514 : :
7515 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7516 : : HWRM_UNLOCK();
7517 : :
7518 : 0 : return rc;
7519 : : }
7520 : :
7521 : 0 : int bnxt_hwrm_port_ts_query(struct bnxt *bp, uint8_t path, uint64_t *timestamp)
7522 : : {
7523 : 0 : struct hwrm_port_ts_query_output *resp = bp->hwrm_cmd_resp_addr;
7524 : 0 : struct hwrm_port_ts_query_input req = {0};
7525 : 0 : struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
7526 : : uint32_t flags = 0;
7527 : : int rc;
7528 : :
7529 [ # # ]: 0 : if (!ptp)
7530 : : return 0;
7531 : :
7532 [ # # # # : 0 : HWRM_PREP(&req, HWRM_PORT_TS_QUERY, BNXT_USE_CHIMP_MB);
# ]
7533 : :
7534 [ # # # ]: 0 : switch (path) {
7535 : : case BNXT_PTP_FLAGS_PATH_TX:
7536 : : flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_TX;
7537 : : break;
7538 : 0 : case BNXT_PTP_FLAGS_PATH_RX:
7539 : : flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_PATH_RX;
7540 : 0 : break;
7541 : 0 : case BNXT_PTP_FLAGS_CURRENT_TIME:
7542 : : flags |= HWRM_PORT_TS_QUERY_INPUT_FLAGS_CURRENT_TIME;
7543 : 0 : break;
7544 : : }
7545 : :
7546 : 0 : req.flags = rte_cpu_to_le_32(flags);
7547 : 0 : req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
7548 : :
7549 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7550 : :
7551 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7552 : :
7553 [ # # ]: 0 : if (timestamp) {
7554 : 0 : *timestamp = rte_le_to_cpu_32(resp->ptp_msg_ts[0]);
7555 : 0 : *timestamp |=
7556 : 0 : (uint64_t)(rte_le_to_cpu_32(resp->ptp_msg_ts[1])) << 32;
7557 : : }
7558 : : HWRM_UNLOCK();
7559 : :
7560 : 0 : return rc;
7561 : : }
7562 : :
7563 : 0 : int bnxt_hwrm_cfa_counter_qcaps(struct bnxt *bp, uint16_t *max_fc)
7564 : : {
7565 : : int rc = 0;
7566 : :
7567 : 0 : struct hwrm_cfa_counter_qcaps_input req = {0};
7568 : 0 : struct hwrm_cfa_counter_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
7569 : :
7570 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7571 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7572 : : "Not a PF or trusted VF. Command not supported");
7573 : 0 : return 0;
7574 : : }
7575 : :
7576 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_COUNTER_QCAPS, BNXT_USE_KONG(bp));
7577 : 0 : req.target_id = rte_cpu_to_le_16(bp->fw_fid);
7578 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
7579 : :
7580 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7581 [ # # ]: 0 : if (max_fc)
7582 : 0 : *max_fc = rte_le_to_cpu_16(resp->max_rx_fc);
7583 : : HWRM_UNLOCK();
7584 : :
7585 : 0 : return 0;
7586 : : }
7587 : :
7588 : 0 : int bnxt_hwrm_ctx_rgtr(struct bnxt *bp, rte_iova_t dma_addr, uint16_t *ctx_id)
7589 : : {
7590 : : int rc = 0;
7591 : 0 : struct hwrm_cfa_ctx_mem_rgtr_input req = {.req_type = 0 };
7592 : 0 : struct hwrm_cfa_ctx_mem_rgtr_output *resp = bp->hwrm_cmd_resp_addr;
7593 : :
7594 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7595 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7596 : : "Not a PF or trusted VF. Command not supported");
7597 : 0 : return 0;
7598 : : }
7599 : :
7600 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_CTX_MEM_RGTR, BNXT_USE_KONG(bp));
7601 : :
7602 : 0 : req.page_level = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_LEVEL_LVL_0;
7603 : 0 : req.page_size = HWRM_CFA_CTX_MEM_RGTR_INPUT_PAGE_SIZE_2M;
7604 : 0 : req.page_dir = rte_cpu_to_le_64(dma_addr);
7605 : :
7606 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
7607 : :
7608 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7609 [ # # ]: 0 : if (ctx_id) {
7610 : 0 : *ctx_id = rte_le_to_cpu_16(resp->ctx_id);
7611 : 0 : PMD_DRV_LOG_LINE(DEBUG, "ctx_id = %d", *ctx_id);
7612 : : }
7613 : : HWRM_UNLOCK();
7614 : :
7615 : 0 : return 0;
7616 : : }
7617 : :
7618 : 0 : int bnxt_hwrm_ctx_unrgtr(struct bnxt *bp, uint16_t ctx_id)
7619 : : {
7620 : : int rc = 0;
7621 : 0 : struct hwrm_cfa_ctx_mem_unrgtr_input req = {.req_type = 0 };
7622 : 0 : struct hwrm_cfa_ctx_mem_unrgtr_output *resp = bp->hwrm_cmd_resp_addr;
7623 : :
7624 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7625 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7626 : : "Not a PF or trusted VF. Command not supported");
7627 : 0 : return 0;
7628 : : }
7629 : :
7630 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_CTX_MEM_UNRGTR, BNXT_USE_KONG(bp));
7631 : :
7632 : 0 : req.ctx_id = rte_cpu_to_le_16(ctx_id);
7633 : :
7634 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
7635 : :
7636 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7637 : : HWRM_UNLOCK();
7638 : :
7639 : 0 : return rc;
7640 : : }
7641 : :
7642 : 0 : int bnxt_hwrm_cfa_counter_cfg(struct bnxt *bp, enum bnxt_flow_dir dir,
7643 : : uint16_t cntr, uint16_t ctx_id,
7644 : : uint32_t num_entries, bool enable)
7645 : : {
7646 : 0 : struct hwrm_cfa_counter_cfg_input req = {0};
7647 : 0 : struct hwrm_cfa_counter_cfg_output *resp = bp->hwrm_cmd_resp_addr;
7648 : : uint16_t flags = 0;
7649 : : int rc;
7650 : :
7651 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7652 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7653 : : "Not a PF or trusted VF. Command not supported");
7654 : 0 : return 0;
7655 : : }
7656 : :
7657 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_COUNTER_CFG, BNXT_USE_KONG(bp));
7658 : :
7659 : 0 : req.target_id = rte_cpu_to_le_16(bp->fw_fid);
7660 : 0 : req.counter_type = rte_cpu_to_le_16(cntr);
7661 [ # # ]: 0 : flags = enable ? HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_ENABLE :
7662 : : HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_CFG_MODE_DISABLE;
7663 : 0 : flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_DATA_TRANSFER_MODE_PULL;
7664 [ # # ]: 0 : if (dir == BNXT_DIR_RX)
7665 : 0 : flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_RX;
7666 : : else if (dir == BNXT_DIR_TX)
7667 : : flags |= HWRM_CFA_COUNTER_CFG_INPUT_FLAGS_PATH_TX;
7668 : 0 : req.flags = rte_cpu_to_le_16(flags);
7669 : 0 : req.ctx_id = rte_cpu_to_le_16(ctx_id);
7670 : 0 : req.num_entries = rte_cpu_to_le_32(num_entries);
7671 : :
7672 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
7673 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7674 : : HWRM_UNLOCK();
7675 : :
7676 : 0 : return 0;
7677 : : }
7678 : :
7679 : 0 : int bnxt_hwrm_cfa_counter_qstats(struct bnxt *bp,
7680 : : enum bnxt_flow_dir dir,
7681 : : uint16_t cntr,
7682 : : uint16_t num_entries)
7683 : : {
7684 : 0 : struct hwrm_cfa_counter_qstats_output *resp = bp->hwrm_cmd_resp_addr;
7685 : 0 : struct hwrm_cfa_counter_qstats_input req = {0};
7686 : : uint16_t flow_ctx_id = 0;
7687 : : uint16_t flags = 0;
7688 : : int rc = 0;
7689 : :
7690 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7691 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7692 : : "Not a PF or trusted VF. Command not supported");
7693 : 0 : return 0;
7694 : : }
7695 : :
7696 [ # # ]: 0 : if (dir == BNXT_DIR_RX) {
7697 : 0 : flow_ctx_id = bp->flow_stat->rx_fc_in_tbl.ctx_id;
7698 : : flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_RX;
7699 [ # # ]: 0 : } else if (dir == BNXT_DIR_TX) {
7700 : 0 : flow_ctx_id = bp->flow_stat->tx_fc_in_tbl.ctx_id;
7701 : : flags = HWRM_CFA_COUNTER_QSTATS_INPUT_FLAGS_PATH_TX;
7702 : : }
7703 : :
7704 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_COUNTER_QSTATS, BNXT_USE_KONG(bp));
7705 : 0 : req.target_id = rte_cpu_to_le_16(bp->fw_fid);
7706 : 0 : req.counter_type = rte_cpu_to_le_16(cntr);
7707 : 0 : req.input_flow_ctx_id = rte_cpu_to_le_16(flow_ctx_id);
7708 : 0 : req.num_entries = rte_cpu_to_le_16(num_entries);
7709 : 0 : req.flags = rte_cpu_to_le_16(flags);
7710 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_KONG(bp));
7711 : :
7712 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7713 : : HWRM_UNLOCK();
7714 : :
7715 : 0 : return 0;
7716 : : }
7717 : :
7718 : 0 : int bnxt_hwrm_first_vf_id_query(struct bnxt *bp, uint16_t fid,
7719 : : uint16_t *first_vf_id)
7720 : : {
7721 : : int rc = 0;
7722 : 0 : struct hwrm_func_qcaps_input req = {.req_type = 0 };
7723 : 0 : struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
7724 : :
7725 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_QCAPS, BNXT_USE_CHIMP_MB);
7726 : :
7727 : 0 : req.fid = rte_cpu_to_le_16(fid);
7728 : :
7729 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7730 : :
7731 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7732 : :
7733 [ # # ]: 0 : if (first_vf_id)
7734 : 0 : *first_vf_id = rte_le_to_cpu_16(resp->first_vf_id);
7735 : :
7736 : : HWRM_UNLOCK();
7737 : :
7738 : 0 : return rc;
7739 : : }
7740 : :
7741 : 0 : int bnxt_hwrm_cfa_pair_exists(struct bnxt *bp, struct bnxt_representor *rep_bp)
7742 : : {
7743 : 0 : struct hwrm_cfa_pair_info_output *resp = bp->hwrm_cmd_resp_addr;
7744 : 0 : struct hwrm_cfa_pair_info_input req = {0};
7745 : : int rc = 0;
7746 : :
7747 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7748 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7749 : : "Not a PF or trusted VF. Command not supported");
7750 : 0 : return 0;
7751 : : }
7752 : :
7753 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_PAIR_INFO, BNXT_USE_CHIMP_MB);
7754 : 0 : snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
7755 : 0 : bp->eth_dev->data->name, rep_bp->vf_id);
7756 : 0 : req.flags =
7757 : : rte_cpu_to_le_32(HWRM_CFA_PAIR_INFO_INPUT_FLAGS_LOOKUP_TYPE);
7758 : :
7759 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7760 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7761 [ # # ]: 0 : if (rc == HWRM_ERR_CODE_SUCCESS && strlen(resp->pair_name)) {
7762 : : HWRM_UNLOCK();
7763 : 0 : return !rc;
7764 : : }
7765 : : HWRM_UNLOCK();
7766 : 0 : return rc;
7767 : : }
7768 : :
7769 : 0 : int bnxt_hwrm_cfa_pair_alloc(struct bnxt *bp, struct bnxt_representor *rep_bp)
7770 : : {
7771 : 0 : struct hwrm_cfa_pair_alloc_output *resp = bp->hwrm_cmd_resp_addr;
7772 : 0 : struct hwrm_cfa_pair_alloc_input req = {0};
7773 : : int rc;
7774 : :
7775 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7776 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7777 : : "Not a PF or trusted VF. Command not supported");
7778 : 0 : return 0;
7779 : : }
7780 : :
7781 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_PAIR_ALLOC, BNXT_USE_CHIMP_MB);
7782 : 0 : req.pair_mode = HWRM_CFA_PAIR_FREE_INPUT_PAIR_MODE_REP2FN_TRUFLOW;
7783 : 0 : snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
7784 [ # # ]: 0 : bp->eth_dev->data->name, rep_bp->vf_id);
7785 : :
7786 : 0 : req.pf_b_id = rep_bp->parent_pf_idx;
7787 [ # # ]: 0 : req.vf_b_id = BNXT_REP_PF(rep_bp) ? rte_cpu_to_le_16(((uint16_t)-1)) :
7788 : : rte_cpu_to_le_16(rep_bp->vf_id);
7789 : 0 : req.vf_a_id = rte_cpu_to_le_16(bp->fw_fid);
7790 : 0 : req.host_b_id = 1; /* TBD - Confirm if this is OK */
7791 : :
7792 : 0 : req.enables |= rep_bp->flags & BNXT_REP_Q_R2F_VALID ?
7793 : 0 : HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_Q_AB_VALID : 0;
7794 : 0 : req.enables |= rep_bp->flags & BNXT_REP_Q_F2R_VALID ?
7795 : 0 : HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_Q_BA_VALID : 0;
7796 : 0 : req.enables |= rep_bp->flags & BNXT_REP_FC_R2F_VALID ?
7797 : 0 : HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_FC_AB_VALID : 0;
7798 : 0 : req.enables |= rep_bp->flags & BNXT_REP_FC_F2R_VALID ?
7799 : 0 : HWRM_CFA_PAIR_ALLOC_INPUT_ENABLES_FC_BA_VALID : 0;
7800 : :
7801 : 0 : req.q_ab = rep_bp->rep_q_r2f;
7802 : 0 : req.q_ba = rep_bp->rep_q_f2r;
7803 : 0 : req.fc_ab = rep_bp->rep_fc_r2f;
7804 : 0 : req.fc_ba = rep_bp->rep_fc_f2r;
7805 : :
7806 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7807 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7808 : :
7809 : : HWRM_UNLOCK();
7810 [ # # ]: 0 : PMD_DRV_LOG_LINE(DEBUG, "%s %d allocated",
7811 : : BNXT_REP_PF(rep_bp) ? "PFR" : "VFR", rep_bp->vf_id);
7812 : 0 : return rc;
7813 : : }
7814 : :
7815 : 0 : int bnxt_hwrm_cfa_pair_free(struct bnxt *bp, struct bnxt_representor *rep_bp)
7816 : : {
7817 : 0 : struct hwrm_cfa_pair_free_output *resp = bp->hwrm_cmd_resp_addr;
7818 : 0 : struct hwrm_cfa_pair_free_input req = {0};
7819 : : int rc;
7820 : :
7821 [ # # ]: 0 : if (!(BNXT_PF(bp) || BNXT_VF_IS_TRUSTED(bp))) {
7822 : 0 : PMD_DRV_LOG_LINE(DEBUG,
7823 : : "Not a PF or trusted VF. Command not supported");
7824 : 0 : return 0;
7825 : : }
7826 : :
7827 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_PAIR_FREE, BNXT_USE_CHIMP_MB);
7828 : 0 : snprintf(req.pair_name, sizeof(req.pair_name), "%svfr%d",
7829 [ # # ]: 0 : bp->eth_dev->data->name, rep_bp->vf_id);
7830 : :
7831 : 0 : req.pf_b_id = rep_bp->parent_pf_idx;
7832 : 0 : req.pair_mode = HWRM_CFA_PAIR_FREE_INPUT_PAIR_MODE_REP2FN_TRUFLOW;
7833 [ # # ]: 0 : req.vf_id = BNXT_REP_PF(rep_bp) ? rte_cpu_to_le_16(((uint16_t)-1)) :
7834 : : rte_cpu_to_le_16(rep_bp->vf_id);
7835 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7836 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7837 : : HWRM_UNLOCK();
7838 [ # # ]: 0 : PMD_DRV_LOG_LINE(DEBUG, "%s %d freed", BNXT_REP_PF(rep_bp) ? "PFR" : "VFR",
7839 : : rep_bp->vf_id);
7840 : 0 : return rc;
7841 : : }
7842 : :
7843 : 0 : int bnxt_hwrm_fw_echo_reply(struct bnxt *bp, uint32_t echo_req_data1,
7844 : : uint32_t echo_req_data2)
7845 : : {
7846 : 0 : struct hwrm_func_echo_response_input req = {0};
7847 : 0 : struct hwrm_func_echo_response_output *resp = bp->hwrm_cmd_resp_addr;
7848 : : int rc;
7849 : :
7850 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_ECHO_RESPONSE, BNXT_USE_CHIMP_MB);
7851 : 0 : req.event_data1 = rte_cpu_to_le_32(echo_req_data1);
7852 : 0 : req.event_data2 = rte_cpu_to_le_32(echo_req_data2);
7853 : :
7854 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7855 : :
7856 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7857 : : HWRM_UNLOCK();
7858 : :
7859 : 0 : return rc;
7860 : : }
7861 : :
7862 : 0 : int bnxt_hwrm_poll_ver_get(struct bnxt *bp)
7863 : : {
7864 : 0 : struct hwrm_ver_get_input req = {.req_type = 0 };
7865 : 0 : struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
7866 : : int rc = 0;
7867 : :
7868 : 0 : bp->max_req_len = HWRM_MAX_REQ_LEN;
7869 : 0 : bp->max_resp_len = BNXT_PAGE_SIZE;
7870 : 0 : bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
7871 : :
7872 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
7873 : 0 : req.hwrm_intf_maj = HWRM_VERSION_MAJOR;
7874 : 0 : req.hwrm_intf_min = HWRM_VERSION_MINOR;
7875 : 0 : req.hwrm_intf_upd = HWRM_VERSION_UPDATE;
7876 : :
7877 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7878 : :
7879 [ # # # # ]: 0 : HWRM_CHECK_RESULT_SILENT();
7880 : : HWRM_UNLOCK();
7881 : :
7882 : 0 : return rc;
7883 : : }
7884 : :
7885 : 0 : int bnxt_hwrm_read_sfp_module_eeprom_info(struct bnxt *bp, uint16_t i2c_addr,
7886 : : uint16_t page_number, uint16_t start_addr,
7887 : : uint16_t data_length, uint8_t *buf)
7888 : : {
7889 : 0 : struct hwrm_port_phy_i2c_read_output *resp = bp->hwrm_cmd_resp_addr;
7890 : 0 : struct hwrm_port_phy_i2c_read_input req = {0};
7891 : : uint32_t enables = HWRM_PORT_PHY_I2C_READ_INPUT_ENABLES_PAGE_OFFSET;
7892 : : int rc, byte_offset = 0;
7893 : :
7894 : : do {
7895 : : uint16_t xfer_size;
7896 : :
7897 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_PORT_PHY_I2C_READ, BNXT_USE_CHIMP_MB);
7898 : 0 : req.i2c_slave_addr = i2c_addr;
7899 : 0 : req.page_number = rte_cpu_to_le_16(page_number);
7900 : 0 : req.port_id = rte_cpu_to_le_16(bp->pf->port_id);
7901 : :
7902 : 0 : xfer_size = RTE_MIN(data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
7903 : 0 : req.page_offset = rte_cpu_to_le_16(start_addr + byte_offset);
7904 : 0 : req.data_length = xfer_size;
7905 [ # # ]: 0 : req.enables = rte_cpu_to_le_32(start_addr + byte_offset ? enables : 0);
7906 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7907 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7908 : :
7909 : 0 : memcpy(buf + byte_offset, resp->data, xfer_size);
7910 : :
7911 : 0 : data_length -= xfer_size;
7912 : 0 : byte_offset += xfer_size;
7913 : :
7914 : : HWRM_UNLOCK();
7915 [ # # ]: 0 : } while (data_length > 0);
7916 : :
7917 : : return rc;
7918 : : }
7919 : :
7920 : 0 : void bnxt_free_hwrm_tx_ring(struct bnxt *bp, int queue_index)
7921 : : {
7922 : 0 : struct bnxt_tx_queue *txq = bp->tx_queues[queue_index];
7923 : 0 : struct bnxt_tx_ring_info *txr = txq->tx_ring;
7924 : 0 : struct bnxt_ring *ring = txr->tx_ring_struct;
7925 : 0 : struct bnxt_cp_ring_info *cpr = txq->cp_ring;
7926 : :
7927 : 0 : bnxt_hwrm_ring_free(bp,
7928 : : ring,
7929 : : HWRM_RING_FREE_INPUT_RING_TYPE_TX,
7930 : 0 : cpr->cp_ring_struct->fw_ring_id);
7931 : 0 : txr->tx_raw_prod = 0;
7932 : 0 : txr->tx_raw_cons = 0;
7933 : 0 : memset(txr->tx_desc_ring, 0,
7934 : 0 : txr->tx_ring_struct->ring_size * sizeof(*txr->tx_desc_ring));
7935 : 0 : memset(txr->tx_buf_ring, 0,
7936 : 0 : txr->tx_ring_struct->ring_size * sizeof(*txr->tx_buf_ring));
7937 : :
7938 : 0 : bnxt_hwrm_stat_ctx_free(bp, cpr);
7939 : :
7940 : 0 : bnxt_free_cp_ring(bp, cpr);
7941 : 0 : }
7942 : :
7943 : 0 : int bnxt_hwrm_config_host_mtu(struct bnxt *bp)
7944 : : {
7945 : 0 : struct hwrm_func_cfg_input req = {0};
7946 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
7947 : : int rc;
7948 : :
7949 [ # # ]: 0 : if (!BNXT_PF(bp))
7950 : : return 0;
7951 : :
7952 [ # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
7953 : :
7954 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
7955 : 0 : req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_HOST_MTU);
7956 : 0 : req.host_mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu);
7957 : :
7958 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
7959 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
7960 : : HWRM_UNLOCK();
7961 : :
7962 : 0 : return rc;
7963 : : }
7964 : :
7965 : 0 : int bnxt_hwrm_func_cfg_mpc(struct bnxt *bp, uint8_t mpc_chnls_msk, bool enable)
7966 : : {
7967 : 0 : struct hwrm_func_cfg_input req = {0};
7968 : 0 : struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
7969 : : int rc;
7970 : : uint16_t mpc_chnls = 0;
7971 : :
7972 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_FUNC_CFG, BNXT_USE_CHIMP_MB);
7973 : 0 : req.fid = rte_cpu_to_le_16(0xffff);
7974 : 0 : req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_MPC_CHNLS);
7975 [ # # ]: 0 : if (enable) {
7976 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_TCE))
7977 : : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_TCE_ENABLE;
7978 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_RCE))
7979 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_RCE_ENABLE;
7980 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_TE_CFA))
7981 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_TE_CFA_ENABLE;
7982 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_RE_CFA))
7983 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_RE_CFA_ENABLE;
7984 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_PRIMATE))
7985 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_PRIMATE_ENABLE;
7986 : : } else {
7987 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_TCE))
7988 : : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_TCE_DISABLE;
7989 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_RCE))
7990 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_RCE_DISABLE;
7991 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_TE_CFA))
7992 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_TE_CFA_DISABLE;
7993 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_RE_CFA))
7994 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_RE_CFA_DISABLE;
7995 [ # # ]: 0 : if (mpc_chnls_msk & (1 << BNXT_MPC_CHNL_PRIMATE))
7996 : 0 : mpc_chnls |= HWRM_FUNC_CFG_INPUT_MPC_CHNLS_PRIMATE_DISABLE;
7997 : : }
7998 : 0 : req.mpc_chnls = rte_cpu_to_le_16(mpc_chnls);
7999 : :
8000 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
8001 : :
8002 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
8003 : : HWRM_UNLOCK();
8004 : :
8005 : 0 : return rc;
8006 : : }
8007 : :
8008 : : int
8009 : 0 : bnxt_vnic_rss_clear_p5(struct bnxt *bp, struct bnxt_vnic_info *vnic)
8010 : : {
8011 : 0 : struct hwrm_vnic_rss_cfg_output *resp = bp->hwrm_cmd_resp_addr;
8012 : 0 : struct hwrm_vnic_rss_cfg_input req = {0};
8013 : 0 : int nr_ctxs = vnic->num_lb_ctxts;
8014 : : int i, rc = 0;
8015 : :
8016 [ # # ]: 0 : for (i = 0; i < nr_ctxs; i++) {
8017 [ # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_RSS_CFG, BNXT_USE_CHIMP_MB);
8018 : :
8019 : 0 : req.rss_ctx_idx = rte_cpu_to_le_16(vnic->fw_grp_ids[i]);
8020 : 0 : req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
8021 : :
8022 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
8023 : :
8024 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
8025 : : HWRM_UNLOCK();
8026 : : }
8027 : :
8028 : : return rc;
8029 : : }
8030 : :
8031 : 0 : int bnxt_hwrm_tf_oem_cmd(struct bnxt *bp,
8032 : : uint32_t *in,
8033 : : uint16_t in_len,
8034 : : uint32_t *out,
8035 : : uint16_t out_len)
8036 : : {
8037 : 0 : struct hwrm_oem_cmd_output *resp = bp->hwrm_cmd_resp_addr;
8038 : 0 : struct hwrm_oem_cmd_input req = {0};
8039 : : int rc = 0;
8040 : :
8041 [ # # ]: 0 : if (!BNXT_VF(bp)) {
8042 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Not a VF. Command not supported");
8043 : 0 : return -ENOTSUP;
8044 : : }
8045 : :
8046 [ # # ]: 0 : HWRM_PREP(&req, HWRM_OEM_CMD, BNXT_USE_CHIMP_MB);
8047 : :
8048 : 0 : req.oem_id = rte_cpu_to_le_32(0x14e4);
8049 : 0 : req.naming_authority =
8050 : : HWRM_OEM_CMD_INPUT_NAMING_AUTHORITY_PCI_SIG;
8051 : 0 : req.message_family =
8052 : : HWRM_OEM_CMD_INPUT_MESSAGE_FAMILY_TRUFLOW;
8053 : 0 : memcpy(req.oem_data, in, in_len);
8054 : :
8055 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
8056 : :
8057 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
8058 [ # # ]: 0 : if (resp->oem_id == 0x14e4 &&
8059 [ # # ]: 0 : resp->naming_authority ==
8060 : 0 : HWRM_OEM_CMD_INPUT_NAMING_AUTHORITY_PCI_SIG &&
8061 [ # # ]: 0 : resp->message_family ==
8062 : : HWRM_OEM_CMD_INPUT_MESSAGE_FAMILY_TRUFLOW)
8063 : 0 : memcpy(out, resp->oem_data, out_len);
8064 : : HWRM_UNLOCK();
8065 : :
8066 : 0 : return rc;
8067 : : }
8068 : :
8069 : : int
8070 : 0 : bnxt_hwrm_vnic_update(struct bnxt *bp,
8071 : : struct bnxt_vnic_info *vnic,
8072 : : uint8_t valid)
8073 : : {
8074 : 0 : struct hwrm_vnic_update_input req = {0};
8075 : 0 : struct hwrm_vnic_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
8076 : : int rc;
8077 : :
8078 [ # # # # ]: 0 : HWRM_PREP(&req, HWRM_VNIC_UPDATE, BNXT_USE_CHIMP_MB);
8079 : :
8080 : 0 : req.vnic_id = rte_cpu_to_le_32(vnic->fw_vnic_id);
8081 : :
8082 [ # # ]: 0 : if (valid & HWRM_VNIC_UPDATE_INPUT_ENABLES_METADATA_FORMAT_TYPE_VALID)
8083 : 0 : req.metadata_format_type = vnic->metadata_format;
8084 [ # # ]: 0 : if (valid & HWRM_VNIC_UPDATE_INPUT_ENABLES_VNIC_STATE_VALID)
8085 : 0 : req.vnic_state = vnic->state;
8086 [ # # ]: 0 : if (valid & HWRM_VNIC_UPDATE_INPUT_ENABLES_MRU_VALID)
8087 : 0 : req.mru = rte_cpu_to_le_16(vnic->mru);
8088 : :
8089 : 0 : req.enables = rte_cpu_to_le_32(valid);
8090 : :
8091 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
8092 : :
8093 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
8094 : : HWRM_UNLOCK();
8095 : :
8096 : 0 : return rc;
8097 : : }
8098 : :
8099 : : int
8100 : 0 : bnxt_hwrm_release_afm_func(struct bnxt *bp, uint16_t fid, uint16_t rfid,
8101 : : uint8_t type, uint32_t flags)
8102 : : {
8103 : : int rc = 0;
8104 : 0 : struct hwrm_cfa_release_afm_func_input req = { 0 };
8105 : 0 : struct hwrm_cfa_release_afm_func_output *resp = bp->hwrm_cmd_resp_addr;
8106 : :
8107 [ # # ]: 0 : HWRM_PREP(&req, HWRM_CFA_RELEASE_AFM_FUNC, BNXT_USE_CHIMP_MB);
8108 : :
8109 : 0 : req.fid = rte_le_to_cpu_16(fid);
8110 : 0 : req.rfid = rte_le_to_cpu_16(rfid);
8111 : 0 : req.flags = rte_le_to_cpu_32(flags);
8112 : 0 : req.type = type;
8113 : :
8114 : 0 : rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
8115 : :
8116 [ # # # # : 0 : HWRM_CHECK_RESULT();
# # # # #
# # # ]
8117 : : HWRM_UNLOCK();
8118 : :
8119 : 0 : return rc;
8120 : : }
|