Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : : #ifndef __CNXK_ETHDEV_H__
5 : : #define __CNXK_ETHDEV_H__
6 : :
7 : : #include <math.h>
8 : : #include <stdint.h>
9 : :
10 : : #include <ethdev_driver.h>
11 : : #include <ethdev_pci.h>
12 : : #include <rte_compat.h>
13 : : #include <rte_kvargs.h>
14 : : #include <rte_mbuf.h>
15 : : #include <rte_mbuf_pool_ops.h>
16 : : #include <rte_mempool.h>
17 : : #include <rte_mtr_driver.h>
18 : : #include <rte_security.h>
19 : : #include <rte_security_driver.h>
20 : : #include <rte_tailq.h>
21 : : #include <rte_time.h>
22 : : #include <rte_tm_driver.h>
23 : :
24 : : #include "roc_api.h"
25 : : #include <cnxk_ethdev_dp.h>
26 : :
27 : : #define CNXK_ETH_DEV_PMD_VERSION "1.0"
28 : :
29 : : /* Macros for packing configuration fields */
30 : : #define CNXK_FIELD_MASK(width) ((1ULL << (width)) - 1)
31 : : #define PACK(val, shift, width) (((uint64_t)((val) & CNXK_FIELD_MASK(width))) << (shift))
32 : :
33 : : /* Used for struct cnxk_eth_dev::flags */
34 : : #define CNXK_LINK_CFG_IN_PROGRESS_F BIT_ULL(0)
35 : :
36 : : /* VLAN tag inserted by NIX_TX_VTAG_ACTION.
37 : : * In Tx space is always reserved for this in FRS.
38 : : */
39 : : #define CNXK_NIX_MAX_VTAG_INS 2
40 : : #define CNXK_NIX_MAX_VTAG_ACT_SIZE (4 * CNXK_NIX_MAX_VTAG_INS)
41 : :
42 : : /* ETH_HLEN+ETH_FCS+2*VLAN_HLEN */
43 : : #define CNXK_NIX_L2_OVERHEAD (RTE_ETHER_HDR_LEN + \
44 : : RTE_ETHER_CRC_LEN + \
45 : : CNXK_NIX_MAX_VTAG_ACT_SIZE)
46 : :
47 : : #define CNXK_NIX_RX_MIN_DESC 16
48 : : #define CNXK_NIX_RX_MIN_DESC_ALIGN 16
49 : : #define CNXK_NIX_RX_NB_SEG_MAX 6
50 : : #define CNXK_NIX_RX_DEFAULT_RING_SZ 4096
51 : : /* Max supported SQB count */
52 : : #define CNXK_NIX_TX_MAX_SQB 512
53 : : /* LPB & SPB */
54 : : #define CNXK_NIX_NUM_POOLS_MAX 2
55 : :
56 : : #define CNXK_NIX_DEF_SQ_COUNT 512
57 : :
58 : : #define CNXK_NIX_RSS_L3_L4_SRC_DST \
59 : : (RTE_ETH_RSS_L3_SRC_ONLY | RTE_ETH_RSS_L3_DST_ONLY | RTE_ETH_RSS_L4_SRC_ONLY | \
60 : : RTE_ETH_RSS_L4_DST_ONLY)
61 : :
62 : : #define CNXK_NIX_RSS_OFFLOAD \
63 : : (RTE_ETH_RSS_PORT | RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP | \
64 : : RTE_ETH_RSS_SCTP | RTE_ETH_RSS_TUNNEL | RTE_ETH_RSS_L2_PAYLOAD | \
65 : : CNXK_NIX_RSS_L3_L4_SRC_DST | RTE_ETH_RSS_LEVEL_MASK | RTE_ETH_RSS_C_VLAN | \
66 : : RTE_ETH_RSS_ESP | RTE_ETH_RSS_IB_BTH)
67 : :
68 : : #define CNXK_NIX_TX_OFFLOAD_CAPA \
69 : : (RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE | RTE_ETH_TX_OFFLOAD_MT_LOCKFREE | \
70 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT | RTE_ETH_TX_OFFLOAD_QINQ_INSERT | \
71 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM | \
72 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
73 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_TSO | \
74 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | \
75 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | RTE_ETH_TX_OFFLOAD_MULTI_SEGS | \
76 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | RTE_ETH_TX_OFFLOAD_SECURITY)
77 : :
78 : : #define CNXK_NIX_RX_OFFLOAD_CAPA \
79 : : (RTE_ETH_RX_OFFLOAD_CHECKSUM | RTE_ETH_RX_OFFLOAD_SCTP_CKSUM | \
80 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM | RTE_ETH_RX_OFFLOAD_SCATTER | \
81 : : RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_RSS_HASH | \
82 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP | RTE_ETH_RX_OFFLOAD_VLAN_STRIP | \
83 : : RTE_ETH_RX_OFFLOAD_SECURITY)
84 : :
85 : : #define RSS_IPV4_ENABLE \
86 : : (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
87 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV4_SCTP)
88 : :
89 : : #define RSS_IPV6_ENABLE \
90 : : (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_UDP | \
91 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_NONFRAG_IPV6_SCTP)
92 : :
93 : : #define RSS_IPV6_EX_ENABLE (RTE_ETH_RSS_IPV6_EX | RTE_ETH_RSS_IPV6_TCP_EX | RTE_ETH_RSS_IPV6_UDP_EX)
94 : :
95 : : #define RSS_MAX_LEVELS 3
96 : :
97 : : #define RSS_IPV4_INDEX 0
98 : : #define RSS_IPV6_INDEX 1
99 : : #define RSS_TCP_INDEX 2
100 : : #define RSS_UDP_INDEX 3
101 : : #define RSS_SCTP_INDEX 4
102 : : #define RSS_DMAC_INDEX 5
103 : :
104 : : /* Default mark value used when none is provided. */
105 : : #define CNXK_NIX_MTR_COUNT_MAX 73 /* 64(leaf) + 8(mid) + 1(top) */
106 : :
107 : : /* Default cycle counter mask */
108 : : #define CNXK_CYCLECOUNTER_MASK 0xffffffffffffffffULL
109 : :
110 : : /* Fastpath lookup */
111 : : #define CNXK_NIX_FASTPATH_LOOKUP_MEM "cnxk_nix_fastpath_lookup_mem"
112 : :
113 : : #define CNXK_NIX_DMAC_IDX_INVALID -1
114 : :
115 : : struct cnxk_fc_cfg {
116 : : enum rte_eth_fc_mode mode;
117 : : uint8_t rx_pause;
118 : : uint8_t tx_pause;
119 : : };
120 : :
121 : : struct cnxk_pfc_cfg {
122 : : uint16_t class_en;
123 : : uint16_t pause_time;
124 : : uint16_t rx_pause_en;
125 : : uint16_t tx_pause_en;
126 : : };
127 : :
128 : : struct cnxk_eth_qconf {
129 : : union {
130 : : struct rte_eth_txconf tx;
131 : : struct rte_eth_rxconf rx;
132 : : } conf;
133 : : struct rte_mempool *mp;
134 : : uint16_t nb_desc;
135 : : uint8_t valid;
136 : : };
137 : :
138 : : struct cnxk_meter_node {
139 : : #define MAX_PRV_MTR_NODES 10
140 : : TAILQ_ENTRY(cnxk_meter_node) next;
141 : : /**< Pointer to the next flow meter structure. */
142 : : uint32_t id; /**< Usr mtr id. */
143 : : struct cnxk_mtr_profile_node *profile;
144 : : struct cnxk_mtr_policy_node *policy;
145 : : uint32_t bpf_id; /**< Hw mtr id. */
146 : : uint32_t rq_num;
147 : : uint32_t *rq_id;
148 : : uint16_t level;
149 : : uint32_t prev_id[MAX_PRV_MTR_NODES]; /**< Prev mtr id for chaining */
150 : : uint32_t prev_cnt;
151 : : uint32_t next_id; /**< Next mtr id for chaining */
152 : : bool is_prev;
153 : : bool is_next;
154 : : struct rte_mtr_params params;
155 : : struct roc_nix_bpf_objs profs;
156 : : bool is_used;
157 : : uint32_t ref_cnt;
158 : : };
159 : :
160 : : struct action_rss {
161 : : enum rte_eth_hash_function func;
162 : : uint32_t level;
163 : : uint64_t types;
164 : : uint32_t key_len;
165 : : uint32_t queue_num;
166 : : uint8_t *key;
167 : : uint16_t *queue;
168 : : };
169 : :
170 : : struct policy_actions {
171 : : uint32_t action_fate;
172 : : union {
173 : : uint16_t queue;
174 : : uint32_t mtr_id;
175 : : struct action_rss *rss_desc;
176 : : bool skip_red;
177 : : };
178 : : };
179 : :
180 : : struct cnxk_mtr_policy_node {
181 : : TAILQ_ENTRY(cnxk_mtr_policy_node) next;
182 : : /**< Pointer to the next flow meter structure. */
183 : : uint32_t id; /**< Policy id */
184 : : uint32_t mtr_id; /** Meter id */
185 : : struct rte_mtr_meter_policy_params policy;
186 : : struct policy_actions actions[RTE_COLORS];
187 : : uint32_t ref_cnt;
188 : : };
189 : :
190 : : struct cnxk_mtr_profile_node {
191 : : TAILQ_ENTRY(cnxk_mtr_profile_node) next;
192 : : struct rte_mtr_meter_profile profile; /**< Profile detail. */
193 : : uint32_t ref_cnt; /**< Use count. */
194 : : uint32_t id; /**< Profile id. */
195 : : };
196 : :
197 : : TAILQ_HEAD(cnxk_mtr_profiles, cnxk_mtr_profile_node);
198 : : TAILQ_HEAD(cnxk_mtr_policy, cnxk_mtr_policy_node);
199 : : TAILQ_HEAD(cnxk_mtr, cnxk_meter_node);
200 : :
201 : : /* Security session private data */
202 : : struct cnxk_eth_sec_sess {
203 : : /* List entry */
204 : : TAILQ_ENTRY(cnxk_eth_sec_sess) entry;
205 : :
206 : : /* Inbound SA is from NIX_RX_IPSEC_SA_BASE or
207 : : * Outbound SA from roc_nix_inl_outb_sa_base_get()
208 : : */
209 : : void *sa;
210 : :
211 : : /* SA index */
212 : : uint32_t sa_idx;
213 : :
214 : : /* SPI */
215 : : uint32_t spi;
216 : :
217 : : /* Back pointer to session */
218 : : struct rte_security_session *sess;
219 : :
220 : : /* Inbound */
221 : : bool inb;
222 : :
223 : : /* Inbound session on inl dev */
224 : : bool inl_dev;
225 : :
226 : : /* Out-Of-Place processing */
227 : : bool inb_oop;
228 : :
229 : : /* Back pointer to eth_dev for port_id derivation in CQ callbacks */
230 : : struct rte_eth_dev *eth_dev;
231 : : };
232 : :
233 : : TAILQ_HEAD(cnxk_eth_sec_sess_list, cnxk_eth_sec_sess);
234 : :
235 : : /* Inbound security data */
236 : : struct cnxk_eth_dev_sec_inb {
237 : : /* IPSec inbound min SPI */
238 : : uint32_t min_spi;
239 : :
240 : : /* IPSec inbound max SPI */
241 : : uint32_t max_spi;
242 : :
243 : : /* Using inbound with inline device */
244 : : bool inl_dev;
245 : :
246 : : /* Device argument to disable inline device usage for inb */
247 : : bool no_inl_dev;
248 : :
249 : : /* Active sessions */
250 : : uint16_t nb_sess;
251 : :
252 : : /* List of sessions */
253 : : struct cnxk_eth_sec_sess_list list;
254 : :
255 : : /* DPTR for WRITE_SA microcode op */
256 : : void *sa_dptr;
257 : :
258 : : /* Number of oop sessions */
259 : : uint16_t nb_oop;
260 : :
261 : : /* Reassembly enabled */
262 : : bool reass_en;
263 : :
264 : : /* Lock to synchronize sa setup/release */
265 : : rte_spinlock_t lock;
266 : :
267 : : /* Disable custom meta aura */
268 : : bool custom_meta_aura_dis;
269 : :
270 : : /* Inline device CPT queue info */
271 : : struct roc_nix_inl_dev_q *inl_dev_q;
272 : : };
273 : :
274 : : /* Outbound security data */
275 : : struct cnxk_eth_dev_sec_outb {
276 : : /* IPSec outbound max SA */
277 : : uint16_t max_sa;
278 : :
279 : : /* Per CPT LF descriptor count */
280 : : uint32_t nb_desc;
281 : :
282 : : /* SA Bitmap */
283 : : struct plt_bitmap *sa_bmap;
284 : :
285 : : /* SA bitmap memory */
286 : : void *sa_bmap_mem;
287 : :
288 : : /* SA base */
289 : : uint64_t sa_base;
290 : :
291 : : /* CPT LF base */
292 : : struct roc_cpt_lf *lf_base;
293 : :
294 : : /* Crypto queues => CPT lf count */
295 : : uint16_t nb_crypto_qs;
296 : :
297 : : /* FC sw mem */
298 : : uint64_t *fc_sw_mem;
299 : :
300 : : /* Active sessions */
301 : : uint16_t nb_sess;
302 : :
303 : : /* List of sessions */
304 : : struct cnxk_eth_sec_sess_list list;
305 : :
306 : : /* DPTR for WRITE_SA microcode op */
307 : : void *sa_dptr;
308 : :
309 : : /* Lock to synchronize sa setup/release */
310 : : rte_spinlock_t lock;
311 : :
312 : : /* Engine caps */
313 : : uint64_t cpt_eng_caps;
314 : : };
315 : :
316 : : /* MACsec session private data */
317 : : struct cnxk_macsec_sess {
318 : : /* List entry */
319 : : TAILQ_ENTRY(cnxk_macsec_sess) entry;
320 : :
321 : : /* Back pointer to session */
322 : : struct rte_security_session *sess;
323 : : enum mcs_direction dir;
324 : : uint64_t sci;
325 : : uint8_t secy_id;
326 : : uint8_t sc_id;
327 : : uint8_t flow_id;
328 : : };
329 : : TAILQ_HEAD(cnxk_macsec_sess_list, cnxk_macsec_sess);
330 : :
331 : : /* Pattern template: owns deep copies tracked in copies[]. */
332 : : struct cnxk_flow_pattern_template {
333 : : struct rte_flow_pattern_template_attr attr;
334 : : struct rte_flow_item *pattern;
335 : : /* Mirrored roc handle for table-level ownership/lifecycle in roc. */
336 : : struct roc_npc_pattern_template *roc_tmpl;
337 : : uint16_t nb_items;
338 : : void **copies;
339 : : uint16_t nb_copies;
340 : : uint32_t refcnt;
341 : : };
342 : :
343 : : /* Actions template: owns deep copies tracked in copies[]. */
344 : : struct cnxk_flow_actions_template {
345 : : struct rte_flow_actions_template_attr attr;
346 : : struct rte_flow_action *actions;
347 : : struct rte_flow_action *masks;
348 : : /* Mirrored roc handle for table-level ownership/lifecycle in roc. */
349 : : struct roc_npc_actions_template *roc_tmpl;
350 : : uint16_t nb_actions;
351 : : void **copies;
352 : : uint16_t nb_copies;
353 : : uint32_t refcnt;
354 : : };
355 : :
356 : : /* Template table wrapper. The roc layer owns rule storage, MCAM reservation
357 : : * and rule lifecycle; cnxk keeps rte templates for per-rule translation.
358 : : */
359 : : struct cnxk_flow_table {
360 : : /* roc engine table handle: storage, MCAM, rule lifecycle. */
361 : : struct roc_npc_template_table *roc_table;
362 : :
363 : : struct cnxk_flow_pattern_template **pattern_templates;
364 : : struct cnxk_flow_actions_template **actions_templates;
365 : : uint8_t nb_pattern_templates;
366 : : uint8_t nb_actions_templates;
367 : :
368 : : uint32_t nb_flows;
369 : : struct roc_npc_attr flow_attr;
370 : : /* roc_npc_attr has no transfer field; replay it into each rule attr. */
371 : : bool transfer;
372 : : enum rte_flow_table_insertion_type insertion_type;
373 : : };
374 : :
375 : : struct cnxk_eth_dev {
376 : : /* ROC NIX */
377 : : struct roc_nix nix;
378 : :
379 : : /* ROC NPC */
380 : : struct roc_npc npc;
381 : :
382 : : /* ROC RQs, SQs and CQs */
383 : : struct roc_nix_rq *rqs;
384 : : struct roc_nix_sq *sqs;
385 : : struct roc_nix_cq *cqs;
386 : :
387 : : /* Configured queue count */
388 : : uint16_t nb_rxq;
389 : : uint16_t nb_txq;
390 : : uint16_t nb_rxq_sso;
391 : : uint8_t configured;
392 : :
393 : : /* Max macfilter entries */
394 : : uint8_t dmac_filter_count;
395 : : uint8_t max_mac_entries;
396 : : bool dmac_filter_enable;
397 : : int *dmac_idx_map;
398 : : struct rte_ether_addr *dmac_addrs;
399 : :
400 : : uint16_t flags;
401 : : uint8_t ptype_disable;
402 : : bool scalar_ena;
403 : : bool tx_compl_ena;
404 : : bool tx_mark;
405 : : bool ptp_en;
406 : :
407 : : /* Pointer back to rte */
408 : : struct rte_eth_dev *eth_dev;
409 : :
410 : : /* HW capabilities / Limitations */
411 : : union {
412 : : struct {
413 : : uint64_t cq_min_4k : 1;
414 : : uint64_t ipsecd_drop_re_dis : 1;
415 : : uint64_t vec_drop_re_dis : 1;
416 : : };
417 : : uint64_t hwcap;
418 : : };
419 : :
420 : : /* Rx and Tx offload capabilities */
421 : : uint64_t rx_offload_capa;
422 : : uint64_t tx_offload_capa;
423 : : uint32_t speed_capa;
424 : : uint8_t link_type;
425 : : /* Configured Rx and Tx offloads */
426 : : uint64_t rx_offloads;
427 : : uint64_t tx_offloads;
428 : : /* Platform specific offload flags */
429 : : uint16_t rx_offload_flags;
430 : : uint16_t tx_offload_flags;
431 : :
432 : : /* ETHDEV RSS HF bitmask */
433 : : uint64_t ethdev_rss_hf;
434 : :
435 : : /* Saved qconf before lf realloc */
436 : : struct cnxk_eth_qconf *tx_qconf;
437 : : struct cnxk_eth_qconf *rx_qconf;
438 : :
439 : : /* Flow control configuration */
440 : : struct cnxk_pfc_cfg pfc_cfg;
441 : : struct cnxk_fc_cfg fc_cfg;
442 : :
443 : : /* PTP Counters */
444 : : struct cnxk_timesync_info tstamp;
445 : : struct rte_timecounter systime_tc;
446 : : struct rte_timecounter rx_tstamp_tc;
447 : : struct rte_timecounter tx_tstamp_tc;
448 : : double clk_freq_mult;
449 : : uint64_t clk_delta;
450 : :
451 : : /* Ingress policer */
452 : : enum roc_nix_bpf_color precolor_tbl[ROC_NIX_BPF_PRECOLOR_TBL_SIZE_DSCP];
453 : : enum rte_mtr_color_in_protocol proto;
454 : : struct cnxk_mtr_profiles mtr_profiles;
455 : : struct cnxk_mtr_policy mtr_policy;
456 : : struct cnxk_mtr mtr;
457 : :
458 : : /* Congestion Management */
459 : : struct rte_eth_cman_config cman_cfg;
460 : :
461 : : /* Rx burst for cleanup(Only Primary) */
462 : : eth_rx_burst_t rx_pkt_burst_no_offload;
463 : :
464 : : /* Default mac address */
465 : : uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
466 : :
467 : : /* LSO Tunnel format indices */
468 : : uint64_t lso_tun_fmt;
469 : :
470 : : /* Security data */
471 : : struct cnxk_eth_dev_sec_inb inb;
472 : : struct cnxk_eth_dev_sec_outb outb;
473 : :
474 : : /* Reassembly dynfield/flag offsets */
475 : : int reass_dynfield_off;
476 : : int reass_dynflag_bit;
477 : : uint32_t ip_reass_rule_id;
478 : : bool ip_reass_en;
479 : :
480 : : /* MCS device */
481 : : struct cnxk_mcs_dev *mcs_dev;
482 : : struct cnxk_macsec_sess_list mcs_list;
483 : :
484 : : /* Inject packets */
485 : : struct cnxk_ethdev_inj_cfg inj_cfg;
486 : :
487 : : /* Eswitch domain ID */
488 : : uint16_t switch_domain_id;
489 : :
490 : : /* SSO event dev */
491 : : void *evdev_priv;
492 : :
493 : : /* SSO event dev ptp */
494 : : void (*cnxk_sso_ptp_tstamp_cb)
495 : : (uint16_t port_id, uint16_t flags, bool ptp_en);
496 : : };
497 : :
498 : : struct cnxk_eth_rxq_sp {
499 : : struct cnxk_eth_dev *dev;
500 : : struct cnxk_eth_qconf qconf;
501 : : uint16_t qid;
502 : : uint8_t tx_pause;
503 : : uint8_t tc;
504 : : } __plt_cache_aligned;
505 : :
506 : : struct cnxk_eth_txq_sp {
507 : : struct cnxk_eth_dev *dev;
508 : : struct cnxk_eth_qconf qconf;
509 : : uint16_t qid;
510 : : } __plt_cache_aligned;
511 : :
512 : : static inline struct cnxk_eth_dev *
513 : : cnxk_eth_pmd_priv(const struct rte_eth_dev *eth_dev)
514 : : {
515 [ + - # # : 4 : return eth_dev->data->dev_private;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
516 : : }
517 : :
518 : : static inline struct cnxk_eth_rxq_sp *
519 : : cnxk_eth_rxq_to_sp(void *__rxq)
520 : : {
521 : 0 : return ((struct cnxk_eth_rxq_sp *)__rxq) - 1;
522 : : }
523 : :
524 : : static inline struct cnxk_eth_txq_sp *
525 : : cnxk_eth_txq_to_sp(void *__txq)
526 : : {
527 : 0 : return ((struct cnxk_eth_txq_sp *)__txq) - 1;
528 : : }
529 : :
530 : : static inline int
531 : : cnxk_nix_tx_queue_count(uint64_t *mem, uint16_t sqes_per_sqb_log2)
532 : : {
533 : : uint64_t val;
534 : :
535 : : val = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)mem, rte_memory_order_relaxed);
536 : : val = (val << sqes_per_sqb_log2) - val;
537 : :
538 : : return (val & 0xFFFF);
539 : : }
540 : :
541 : : static inline int
542 : : cnxk_nix_tx_queue_sec_count(uint64_t *mem, uint16_t sqes_per_sqb_log2, uint64_t *sec_fc)
543 : : {
544 : : uint64_t sq_cnt, sec_cnt, val;
545 : :
546 : : sq_cnt = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)mem, rte_memory_order_relaxed);
547 : : sq_cnt = (sq_cnt << sqes_per_sqb_log2) - sq_cnt;
548 : : sec_cnt = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)sec_fc,
549 : : rte_memory_order_relaxed);
550 : : val = RTE_MAX(sq_cnt, sec_cnt);
551 : :
552 : : return (val & 0xFFFF);
553 : : }
554 : :
555 : : static inline int
556 : 0 : cnxk_nix_inl_fc_check(uint64_t __rte_atomic *fc, int32_t *fc_sw, uint32_t nb_desc, uint16_t nb_inst)
557 : : {
558 : : uint8_t retry_count = 32;
559 : : int32_t val, newval;
560 : :
561 : : /* Check if there is any CPT instruction to submit */
562 [ # # ]: 0 : if (!nb_inst)
563 : : return -EINVAL;
564 : :
565 : 0 : retry:
566 : 0 : val = rte_atomic_fetch_sub_explicit((RTE_ATOMIC(int32_t)*)fc_sw, nb_inst,
567 : 0 : rte_memory_order_relaxed) - nb_inst;
568 [ # # ]: 0 : if (likely(val >= 0))
569 : : return 0;
570 : :
571 : 0 : newval = (int64_t)nb_desc - rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)fc,
572 : : rte_memory_order_relaxed);
573 : 0 : newval -= nb_inst;
574 : :
575 [ # # ]: 0 : if (!rte_atomic_compare_exchange_strong_explicit((RTE_ATOMIC(int32_t)*)fc_sw, &val, newval,
576 : : rte_memory_order_release,
577 : : rte_memory_order_relaxed)) {
578 [ # # ]: 0 : if (retry_count) {
579 : 0 : retry_count--;
580 : 0 : goto retry;
581 : : } else {
582 : : return -EAGAIN;
583 : : }
584 : : }
585 [ # # ]: 0 : if (unlikely(newval < 0))
586 : 0 : return -EAGAIN;
587 : :
588 : : return 0;
589 : : }
590 : :
591 : : /* Common ethdev ops */
592 : : extern struct eth_dev_ops cnxk_eth_dev_ops;
593 : :
594 : : /* Common flow ops */
595 : : extern struct rte_flow_ops cnxk_flow_ops;
596 : :
597 : : /* Common security ops */
598 : : extern struct rte_security_ops cnxk_eth_sec_ops;
599 : :
600 : : /* Common tm ops */
601 : : extern struct rte_tm_ops cnxk_tm_ops;
602 : :
603 : : /* Platform specific rte pmd cnxk ops */
604 : : typedef uint16_t (*cnxk_inl_dev_submit_cb_t)(struct roc_nix_inl_dev_q *q, void *inst,
605 : : uint16_t nb_inst);
606 : :
607 : : typedef void (*cnxk_ethdev_rx_offload_cb_t)(uint16_t port_id, uint64_t flags);
608 : :
609 : : extern cnxk_ethdev_rx_offload_cb_t cnxk_ethdev_rx_offload_cb;
610 : :
611 : : struct cnxk_ethdev_pmd_ops {
612 : : cnxk_inl_dev_submit_cb_t inl_dev_submit;
613 : : };
614 : : extern struct cnxk_ethdev_pmd_ops cnxk_pmd_ops;
615 : :
616 : : /* Ops */
617 : : int cnxk_nix_probe(struct rte_pci_driver *pci_drv,
618 : : struct rte_pci_device *pci_dev);
619 : : int cnxk_nix_remove(struct rte_pci_device *pci_dev);
620 : : int cnxk_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu);
621 : : int cnxk_nix_sq_flush(struct rte_eth_dev *eth_dev);
622 : : int cnxk_nix_mc_addr_list_configure(struct rte_eth_dev *eth_dev,
623 : : struct rte_ether_addr *mc_addr_set,
624 : : uint32_t nb_mc_addr);
625 : : int cnxk_nix_mac_addr_add(struct rte_eth_dev *eth_dev,
626 : : struct rte_ether_addr *addr, uint32_t index,
627 : : uint32_t pool);
628 : : void cnxk_nix_mac_addr_del(struct rte_eth_dev *eth_dev, uint32_t index);
629 : : int cnxk_nix_mac_addr_set(struct rte_eth_dev *eth_dev,
630 : : struct rte_ether_addr *addr);
631 : : int cnxk_nix_promisc_enable(struct rte_eth_dev *eth_dev);
632 : : int cnxk_nix_promisc_disable(struct rte_eth_dev *eth_dev);
633 : : int cnxk_nix_allmulticast_enable(struct rte_eth_dev *eth_dev);
634 : : int cnxk_nix_allmulticast_disable(struct rte_eth_dev *eth_dev);
635 : : int cnxk_nix_info_get(struct rte_eth_dev *eth_dev,
636 : : struct rte_eth_dev_info *dev_info);
637 : : int cnxk_nix_rx_burst_mode_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
638 : : struct rte_eth_burst_mode *mode);
639 : : int cnxk_nix_tx_burst_mode_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
640 : : struct rte_eth_burst_mode *mode);
641 : : int cnxk_nix_flow_ctrl_set(struct rte_eth_dev *eth_dev,
642 : : struct rte_eth_fc_conf *fc_conf);
643 : : int cnxk_nix_flow_ctrl_get(struct rte_eth_dev *eth_dev,
644 : : struct rte_eth_fc_conf *fc_conf);
645 : : int cnxk_nix_priority_flow_ctrl_queue_config(struct rte_eth_dev *eth_dev,
646 : : struct rte_eth_pfc_queue_conf *pfc_conf);
647 : : int cnxk_nix_priority_flow_ctrl_queue_info_get(struct rte_eth_dev *eth_dev,
648 : : struct rte_eth_pfc_queue_info *pfc_info);
649 : : int cnxk_nix_set_link_up(struct rte_eth_dev *eth_dev);
650 : : int cnxk_nix_set_link_down(struct rte_eth_dev *eth_dev);
651 : : int cnxk_nix_get_module_info(struct rte_eth_dev *eth_dev,
652 : : struct rte_eth_dev_module_info *modinfo);
653 : : int cnxk_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
654 : : struct rte_dev_eeprom_info *info);
655 : : int cnxk_nix_rx_queue_intr_enable(struct rte_eth_dev *eth_dev,
656 : : uint16_t rx_queue_id);
657 : : int cnxk_nix_rx_queue_intr_disable(struct rte_eth_dev *eth_dev,
658 : : uint16_t rx_queue_id);
659 : : int cnxk_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool);
660 : : int cnxk_nix_tx_done_cleanup(void *txq, uint32_t free_cnt);
661 : : int cnxk_nix_flow_ops_get(struct rte_eth_dev *eth_dev,
662 : : const struct rte_flow_ops **ops);
663 : : int cnxk_nix_configure(struct rte_eth_dev *eth_dev);
664 : : int cnxk_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
665 : : uint16_t nb_desc, uint16_t fp_tx_q_sz,
666 : : const struct rte_eth_txconf *tx_conf);
667 : : int cnxk_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
668 : : uint32_t nb_desc, uint16_t fp_rx_q_sz,
669 : : const struct rte_eth_rxconf *rx_conf,
670 : : struct rte_mempool *mp);
671 : : int cnxk_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid);
672 : : void cnxk_nix_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid);
673 : : int cnxk_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid);
674 : : int cnxk_nix_dev_start(struct rte_eth_dev *eth_dev);
675 : : int cnxk_nix_timesync_enable(struct rte_eth_dev *eth_dev);
676 : : int cnxk_nix_timesync_disable(struct rte_eth_dev *eth_dev);
677 : : int cnxk_nix_timesync_read_rx_timestamp(struct rte_eth_dev *eth_dev,
678 : : struct timespec *timestamp,
679 : : uint32_t flags);
680 : : int cnxk_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev,
681 : : struct timespec *timestamp);
682 : : int cnxk_nix_timesync_read_time(struct rte_eth_dev *eth_dev,
683 : : struct timespec *ts);
684 : : int cnxk_nix_timesync_write_time(struct rte_eth_dev *eth_dev,
685 : : const struct timespec *ts);
686 : : int cnxk_nix_timesync_adjust_time(struct rte_eth_dev *eth_dev, int64_t delta);
687 : : int cnxk_nix_tsc_convert(struct cnxk_eth_dev *dev);
688 : : int cnxk_nix_read_clock(struct rte_eth_dev *eth_dev, uint64_t *clock);
689 : :
690 : : uint64_t cnxk_nix_rxq_mbuf_setup(struct cnxk_eth_dev *dev);
691 : : int cnxk_nix_tm_ops_get(struct rte_eth_dev *eth_dev, void *ops);
692 : : int cnxk_nix_tm_set_queue_rate_limit(struct rte_eth_dev *eth_dev,
693 : : uint16_t queue_idx, uint32_t tx_rate);
694 : : int cnxk_nix_tm_mark_vlan_dei(struct rte_eth_dev *eth_dev, int mark_green,
695 : : int mark_yellow, int mark_red,
696 : : struct rte_tm_error *error);
697 : : int cnxk_nix_ip_reass_rule_clr(struct rte_eth_dev *eth_dev);
698 : : int cnxk_nix_ip_reass_rule_set(struct rte_eth_dev *eth_dev, uint32_t rq);
699 : : int cnxk_nix_inl_inb_fini(struct cnxk_eth_dev *dev);
700 : :
701 : : int cnxk_nix_tm_mark_ip_ecn(struct rte_eth_dev *eth_dev, int mark_green,
702 : : int mark_yellow, int mark_red,
703 : : struct rte_tm_error *error);
704 : : int cnxk_nix_tm_mark_ip_dscp(struct rte_eth_dev *eth_dev, int mark_green,
705 : : int mark_yellow, int mark_red,
706 : : struct rte_tm_error *error);
707 : : int cnxk_nix_tx_descriptor_dump(const struct rte_eth_dev *eth_dev, uint16_t qid, uint16_t offset,
708 : : uint16_t num, FILE *file);
709 : :
710 : : /* FEC */
711 : : int cnxk_nix_fec_get_capability(struct rte_eth_dev *eth_dev,
712 : : struct rte_eth_fec_capa *speed_fec_capa, unsigned int num);
713 : : int cnxk_nix_fec_get(struct rte_eth_dev *eth_dev, uint32_t *fec_capa);
714 : : int cnxk_nix_fec_set(struct rte_eth_dev *eth_dev, uint32_t fec_capa);
715 : :
716 : : /* MTR */
717 : : int cnxk_nix_mtr_ops_get(struct rte_eth_dev *dev, void *ops);
718 : :
719 : : /* RSS */
720 : : uint32_t cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
721 : : uint8_t rss_level);
722 : : int cnxk_nix_reta_update(struct rte_eth_dev *eth_dev,
723 : : struct rte_eth_rss_reta_entry64 *reta_conf,
724 : : uint16_t reta_size);
725 : : int cnxk_nix_reta_query(struct rte_eth_dev *eth_dev,
726 : : struct rte_eth_rss_reta_entry64 *reta_conf,
727 : : uint16_t reta_size);
728 : : int cnxk_nix_rss_hash_update(struct rte_eth_dev *eth_dev,
729 : : struct rte_eth_rss_conf *rss_conf);
730 : : int cnxk_nix_rss_hash_conf_get(struct rte_eth_dev *eth_dev,
731 : : struct rte_eth_rss_conf *rss_conf);
732 : : int cnxk_nix_eth_dev_priv_dump(struct rte_eth_dev *eth_dev, FILE *file);
733 : :
734 : : /* Link */
735 : : void cnxk_nix_toggle_flag_link_cfg(struct cnxk_eth_dev *dev, bool set);
736 : : void cnxk_eth_dev_link_status_cb(struct roc_nix *nix,
737 : : struct roc_nix_link_info *link);
738 : : void cnxk_eth_dev_link_status_get_cb(struct roc_nix *nix,
739 : : struct roc_nix_link_info *link);
740 : : void cnxk_eth_dev_q_err_cb(struct roc_nix *nix, void *data);
741 : : int cnxk_nix_link_info_configure(struct rte_eth_dev *eth_dev);
742 : : int cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete);
743 : : int cnxk_nix_stats_reset(struct rte_eth_dev *dev);
744 : : int cnxk_nix_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
745 : : struct eth_queue_stats *qstats);
746 : : int cnxk_nix_xstats_get(struct rte_eth_dev *eth_dev,
747 : : struct rte_eth_xstat *xstats, unsigned int n);
748 : : int cnxk_nix_xstats_get_names(struct rte_eth_dev *eth_dev,
749 : : struct rte_eth_xstat_name *xstats_names,
750 : : unsigned int limit);
751 : : int cnxk_nix_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
752 : : const uint64_t *ids,
753 : : struct rte_eth_xstat_name *xstats_names,
754 : : unsigned int limit);
755 : : int cnxk_nix_xstats_get_by_id(struct rte_eth_dev *eth_dev, const uint64_t *ids,
756 : : uint64_t *values, unsigned int n);
757 : : int cnxk_nix_xstats_reset(struct rte_eth_dev *eth_dev);
758 : : int cnxk_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
759 : : size_t fw_size);
760 : : void cnxk_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t qid,
761 : : struct rte_eth_rxq_info *qinfo);
762 : : void cnxk_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t qid,
763 : : struct rte_eth_txq_info *qinfo);
764 : :
765 : : /* Queue status */
766 : : int cnxk_nix_rx_descriptor_status(void *rxq, uint16_t offset);
767 : : int cnxk_nix_tx_descriptor_status(void *txq, uint16_t offset);
768 : : int cnxk_nix_rx_queue_count(void *rxq);
769 : :
770 : : /* Lookup configuration */
771 : : const uint32_t *cnxk_nix_supported_ptypes_get(struct rte_eth_dev *eth_dev,
772 : : size_t *no_of_elements);
773 : : void *cnxk_nix_fastpath_lookup_mem_get(void);
774 : :
775 : : /* Devargs */
776 : : int cnxk_ethdev_parse_devargs(struct rte_devargs *devargs,
777 : : struct cnxk_eth_dev *dev);
778 : :
779 : : /* Debug */
780 : : int cnxk_nix_dev_get_reg(struct rte_eth_dev *eth_dev,
781 : : struct rte_dev_reg_info *regs);
782 : : /* Security */
783 : : int cnxk_eth_outb_sa_idx_get(struct cnxk_eth_dev *dev, uint32_t *idx_p,
784 : : uint32_t spi);
785 : : int cnxk_eth_outb_sa_idx_put(struct cnxk_eth_dev *dev, uint32_t idx);
786 : : int cnxk_nix_lookup_mem_sa_base_set(struct cnxk_eth_dev *dev);
787 : : int cnxk_nix_lookup_mem_sa_base_clear(struct cnxk_eth_dev *dev);
788 : : int cnxk_nix_lookup_mem_metapool_set(struct cnxk_eth_dev *dev);
789 : : int cnxk_nix_lookup_mem_metapool_clear(struct cnxk_eth_dev *dev);
790 : : int cnxk_nix_lookup_mem_bufsize_set(struct cnxk_eth_dev *dev, uint64_t size);
791 : : int cnxk_nix_lookup_mem_bufsize_clear(struct cnxk_eth_dev *dev);
792 : :
793 : : __rte_internal
794 : : int cnxk_nix_inb_mode_set(struct cnxk_eth_dev *dev, bool use_inl_dev);
795 : :
796 : : __rte_internal
797 : : void cnxk_ethdev_rx_offload_cb_register(cnxk_ethdev_rx_offload_cb_t cb);
798 : :
799 : : int cnxk_nix_inline_inbound_setup(struct cnxk_eth_dev *dev);
800 : : int cnxk_nix_inline_inbound_mode_setup(struct cnxk_eth_dev *dev);
801 : :
802 : : struct cnxk_eth_sec_sess *cnxk_eth_sec_sess_get_by_sa_idx(struct cnxk_eth_dev *dev,
803 : : uint32_t sa_idx, bool inb);
804 : : struct cnxk_eth_sec_sess *cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
805 : : const struct rte_security_session *sess);
806 : :
807 : : int cnxk_nix_inl_meta_pool_cb(uint64_t *aura_handle, uintptr_t *mpool, uint32_t buf_sz,
808 : : uint32_t nb_bufs, bool destroy, const char *mempool_name);
809 : : int cnxk_nix_inl_custom_meta_pool_cb(uintptr_t pmpool, uintptr_t *mpool, const char *mempool_name,
810 : : uint64_t *aura_handle, uint32_t buf_sz, uint32_t nb_bufs,
811 : : bool destroy);
812 : :
813 : : /* Congestion Management */
814 : : int cnxk_nix_cman_info_get(struct rte_eth_dev *dev, struct rte_eth_cman_info *info);
815 : :
816 : : int cnxk_nix_cman_config_init(struct rte_eth_dev *dev, struct rte_eth_cman_config *config);
817 : :
818 : : int cnxk_nix_cman_config_set(struct rte_eth_dev *dev, const struct rte_eth_cman_config *config);
819 : :
820 : : int cnxk_nix_cman_config_get(struct rte_eth_dev *dev, struct rte_eth_cman_config *config);
821 : :
822 : : int cnxk_mcs_dev_init(struct cnxk_eth_dev *dev, uint8_t mcs_idx);
823 : : void cnxk_mcs_dev_fini(struct cnxk_eth_dev *dev);
824 : :
825 : : struct cnxk_macsec_sess *cnxk_eth_macsec_sess_get_by_sess(struct cnxk_eth_dev *dev,
826 : : const struct rte_security_session *sess);
827 : : int cnxk_mcs_flow_configure(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
828 : : const struct rte_flow_item pattern[],
829 : : const struct rte_flow_action actions[], struct rte_flow_error *error,
830 : : void **mcs_flow);
831 : : int cnxk_mcs_flow_destroy(struct cnxk_eth_dev *eth_dev, void *mcs_flow);
832 : :
833 : : /* Other private functions */
834 : : int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
835 : : int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
836 : : int nix_mtr_policy_act_get(struct rte_eth_dev *eth_dev, uint32_t id,
837 : : struct cnxk_mtr_policy_node **policy);
838 : : int nix_mtr_rq_update(struct rte_eth_dev *eth_dev, uint32_t id,
839 : : uint32_t queue_num, const uint16_t *queue);
840 : : int nix_mtr_chain_update(struct rte_eth_dev *eth_dev, uint32_t cur_id,
841 : : uint32_t prev_id, uint32_t next_id);
842 : : int nix_mtr_chain_reset(struct rte_eth_dev *eth_dev, uint32_t cur_id);
843 : : struct cnxk_meter_node *nix_get_mtr(struct rte_eth_dev *eth_dev,
844 : : uint32_t cur_id);
845 : : int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
846 : : uint32_t level);
847 : : int nix_mtr_capabilities_init(struct rte_eth_dev *eth_dev);
848 : : int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
849 : : int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
850 : : int nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
851 : : struct rte_mtr_error *error);
852 : : int nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
853 : : uint32_t *prev_id, uint32_t *next_id,
854 : : struct cnxk_mtr_policy_node *policy,
855 : : int *tree_level);
856 : : int nix_priority_flow_ctrl_rq_conf(struct rte_eth_dev *eth_dev, uint16_t qid,
857 : : uint8_t tx_pause, uint8_t tc);
858 : : int nix_priority_flow_ctrl_sq_conf(struct rte_eth_dev *eth_dev, uint16_t qid,
859 : : uint8_t rx_pause, uint8_t tc);
860 : :
861 : : #endif /* __CNXK_ETHDEV_H__ */
|