528e2ede618e960c99dd250debd003bf05d964e3
[dpdk.git] / drivers / event / dlb2 / dlb2_priv.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2022 Intel Corporation
3  */
4
5 #ifndef _DLB2_PRIV_H_
6 #define _DLB2_PRIV_H_
7
8 #include <emmintrin.h>
9 #include <stdbool.h>
10
11 #include <rte_eventdev.h>
12 #include <rte_config.h>
13 #include "dlb2_user.h"
14 #include "dlb2_log.h"
15 #include "rte_pmd_dlb2.h"
16
17 #ifndef RTE_LIBRTE_PMD_DLB2_QUELL_STATS
18 #define DLB2_INC_STAT(_stat, _incr_val) ((_stat) += _incr_val)
19 #else
20 #define DLB2_INC_STAT(_stat, _incr_val)
21 #endif
22
23 #define EVDEV_DLB2_NAME_PMD dlb2_event
24
25 /* Default values for command line devargs */
26 #define DLB2_POLL_INTERVAL_DEFAULT 1000
27 #define DLB2_SW_CREDIT_QUANTA_DEFAULT 32 /* Default = Worker */
28 #define DLB2_SW_CREDIT_P_QUANTA_DEFAULT 256 /* Producer */
29 #define DLB2_SW_CREDIT_C_QUANTA_DEFAULT 256 /* Consumer */
30 #define DLB2_DEPTH_THRESH_DEFAULT 256
31 #define DLB2_MIN_CQ_DEPTH_OVERRIDE 32
32 #define DLB2_MAX_CQ_DEPTH_OVERRIDE 1024
33
34 /*  command line arg strings */
35 #define NUMA_NODE_ARG "numa_node"
36 #define DLB2_MAX_NUM_EVENTS "max_num_events"
37 #define DLB2_NUM_DIR_CREDITS "num_dir_credits"
38 #define DEV_ID_ARG "dev_id"
39 #define DLB2_QID_DEPTH_THRESH_ARG "qid_depth_thresh"
40 #define DLB2_COS_ARG "cos"
41 #define DLB2_POLL_INTERVAL_ARG "poll_interval"
42 #define DLB2_SW_CREDIT_QUANTA_ARG "sw_credit_quanta"
43 #define DLB2_HW_CREDIT_QUANTA_ARG "hw_credit_quanta"
44 #define DLB2_DEPTH_THRESH_ARG "default_depth_thresh"
45 #define DLB2_VECTOR_OPTS_ENAB_ARG "vector_opts_enable"
46 #define DLB2_MAX_CQ_DEPTH "max_cq_depth"
47 #define DLB2_CQ_WEIGHT "cq_weight"
48 #define DLB2_PORT_COS "port_cos"
49 #define DLB2_COS_BW "cos_bw"
50
51 /* Begin HW related defines and structs */
52
53 #define DLB2_HW_V2 0
54 #define DLB2_HW_V2_5 1
55 #define DLB2_MAX_NUM_DOMAINS 32
56 #define DLB2_MAX_NUM_VFS 16
57 #define DLB2_MAX_NUM_LDB_QUEUES 32
58 #define DLB2_MAX_NUM_LDB_PORTS 64
59 #define DLB2_MAX_NUM_DIR_PORTS_V2               DLB2_MAX_NUM_DIR_QUEUES_V2
60 #define DLB2_MAX_NUM_DIR_PORTS_V2_5             DLB2_MAX_NUM_DIR_QUEUES_V2_5
61 #define DLB2_MAX_NUM_DIR_PORTS(ver)             (ver == DLB2_HW_V2 ? \
62                                                  DLB2_MAX_NUM_DIR_PORTS_V2 : \
63                                                  DLB2_MAX_NUM_DIR_PORTS_V2_5)
64 #define DLB2_MAX_NUM_DIR_QUEUES_V2              64 /* DIR == directed */
65 #define DLB2_MAX_NUM_DIR_QUEUES_V2_5            96
66 /* When needed for array sizing, the DLB 2.5 macro is used */
67 #define DLB2_MAX_NUM_DIR_QUEUES(ver)            (ver == DLB2_HW_V2 ? \
68                                                  DLB2_MAX_NUM_DIR_QUEUES_V2 : \
69                                                  DLB2_MAX_NUM_DIR_QUEUES_V2_5)
70 #define DLB2_MAX_NUM_FLOWS (64 * 1024)
71 #define DLB2_MAX_NUM_LDB_CREDITS (8 * 1024)
72 #define DLB2_MAX_NUM_DIR_CREDITS(ver)           (ver == DLB2_HW_V2 ? 4096 : 0)
73 #define DLB2_MAX_NUM_CREDITS(ver)               (ver == DLB2_HW_V2 ? \
74                                                  0 : DLB2_MAX_NUM_LDB_CREDITS)
75 #define DLB2_MAX_NUM_LDB_CREDIT_POOLS 64
76 #define DLB2_MAX_NUM_DIR_CREDIT_POOLS 64
77 #define DLB2_MAX_NUM_HIST_LIST_ENTRIES 2048
78 #define DLB2_MAX_NUM_QIDS_PER_LDB_CQ 8
79 #define DLB2_QID_PRIORITIES 8
80 #define DLB2_MAX_DEVICE_PATH 32
81 #define DLB2_MIN_DEQUEUE_TIMEOUT_NS 1
82 /* Note: "- 1" here to support the timeout range check in eventdev_autotest */
83 #define DLB2_MAX_DEQUEUE_TIMEOUT_NS (UINT32_MAX - 1)
84 #define DLB2_SW_CREDIT_BATCH_SZ 32 /* Default - Worker */
85 #define DLB2_SW_CREDIT_P_BATCH_SZ 256 /* Producer */
86 #define DLB2_SW_CREDIT_C_BATCH_SZ 256 /* Consumer */
87 #define DLB2_NUM_SN_GROUPS 2
88 #define DLB2_MAX_LDB_SN_ALLOC 1024
89 #define DLB2_MAX_QUEUE_DEPTH_THRESHOLD 8191
90
91 /* 2048 total hist list entries and 64 total ldb ports, which
92  * makes for 2048/64 == 32 hist list entries per port. However, CQ
93  * depth must be a power of 2 and must also be >= HIST LIST entries.
94  * As a result we just limit the maximum dequeue depth to 32.
95  */
96 #define DLB2_MAX_HL_ENTRIES 2048
97 #define DLB2_MIN_CQ_DEPTH 1
98 #define DLB2_DEFAULT_CQ_DEPTH 32
99 #define DLB2_MIN_HARDWARE_CQ_DEPTH 8
100 #define DLB2_NUM_HIST_LIST_ENTRIES_PER_LDB_PORT \
101         DLB2_DEFAULT_CQ_DEPTH
102
103 #define DLB2_HW_DEVICE_FROM_PCI_ID(_pdev) \
104         (((_pdev->id.device_id == PCI_DEVICE_ID_INTEL_DLB2_5_PF) ||        \
105           (_pdev->id.device_id == PCI_DEVICE_ID_INTEL_DLB2_5_VF))   ?   \
106                 DLB2_HW_V2_5 : DLB2_HW_V2)
107
108 /*
109  * Static per queue/port provisioning values
110  */
111 #define DLB2_NUM_ATOMIC_INFLIGHTS_PER_QUEUE 64
112
113 #define CQ_BASE(is_dir) ((is_dir) ? DLB2_DIR_CQ_BASE : DLB2_LDB_CQ_BASE)
114 #define CQ_SIZE(is_dir) ((is_dir) ? DLB2_DIR_CQ_MAX_SIZE : \
115                                     DLB2_LDB_CQ_MAX_SIZE)
116 #define PP_BASE(is_dir) ((is_dir) ? DLB2_DIR_PP_BASE : DLB2_LDB_PP_BASE)
117
118 #define DLB2_NUM_QES_PER_CACHE_LINE 4
119
120 #define DLB2_MAX_ENQUEUE_DEPTH 32
121 #define DLB2_MIN_ENQUEUE_DEPTH 4
122
123 #define DLB2_NAME_SIZE 64
124
125 #define DLB2_1K 1024
126 #define DLB2_2K (2 * DLB2_1K)
127 #define DLB2_4K (4 * DLB2_1K)
128 #define DLB2_16K (16 * DLB2_1K)
129 #define DLB2_32K (32 * DLB2_1K)
130 #define DLB2_1MB (DLB2_1K * DLB2_1K)
131 #define DLB2_16MB (16 * DLB2_1MB)
132
133 /* Use the upper 3 bits of the event priority to select the DLB2 priority */
134 #define EV_TO_DLB2_PRIO(x) ((x) >> 5)
135 #define DLB2_TO_EV_PRIO(x) ((x) << 5)
136
137 enum dlb2_hw_ver {
138         DLB2_HW_VER_2,
139         DLB2_HW_VER_2_5,
140 };
141
142 enum dlb2_hw_port_types {
143         DLB2_LDB_PORT,
144         DLB2_DIR_PORT,
145         DLB2_NUM_PORT_TYPES /* Must be last */
146 };
147
148 enum dlb2_hw_queue_types {
149         DLB2_LDB_QUEUE,
150         DLB2_DIR_QUEUE,
151         DLB2_NUM_QUEUE_TYPES /* Must be last */
152 };
153
154 #define DLB2_COMBINED_POOL DLB2_LDB_QUEUE
155
156 #define PORT_TYPE(p) ((p)->is_directed ? DLB2_DIR_PORT : DLB2_LDB_PORT)
157
158 /* Do not change - must match hardware! */
159 enum dlb2_hw_sched_type {
160         DLB2_SCHED_ATOMIC = 0,
161         DLB2_SCHED_UNORDERED,
162         DLB2_SCHED_ORDERED,
163         DLB2_SCHED_DIRECTED,
164         /* DLB2_NUM_HW_SCHED_TYPES must be last */
165         DLB2_NUM_HW_SCHED_TYPES
166 };
167
168 struct dlb2_hw_rsrcs {
169         int32_t nb_events_limit;
170         uint32_t num_queues;            /* Total queues (lb + dir) */
171         uint32_t num_ldb_queues;        /* Number of available ldb queues */
172         uint32_t num_ldb_ports;         /* Number of load balanced ports */
173         uint32_t num_dir_ports;         /* Number of directed ports */
174         union {
175                 struct {
176                         uint32_t num_ldb_credits; /* Number of ldb credits */
177                         uint32_t num_dir_credits; /* Number of dir credits */
178                 };
179                 struct {
180                         uint32_t num_credits; /* Number of combined credits */
181                 };
182         };
183         uint32_t reorder_window_size;   /* Size of reorder window */
184 };
185
186 struct dlb2_hw_resource_info {
187         /**> Max resources that can be provided */
188         struct dlb2_hw_rsrcs hw_rsrc_max;
189         int num_sched_domains;
190         uint32_t socket_id;
191 };
192
193 enum dlb2_enqueue_type {
194         /**>
195          * New : Used to inject a new packet into the QM.
196          */
197         DLB2_ENQ_NEW,
198         /**>
199          * Forward : Enqueues a packet, and
200          *  - if atomic: release any lock it holds in the QM
201          *  - if ordered: release the packet for egress re-ordering
202          */
203         DLB2_ENQ_FWD,
204         /**>
205          * Enqueue Drop : Release an inflight packet. Must be called with
206          * event == NULL. Used to drop a packet.
207          *
208          * Note that all packets dequeued from a load-balanced port must be
209          * released, either with DLB2_ENQ_DROP or DLB2_ENQ_FWD.
210          */
211         DLB2_ENQ_DROP,
212
213         /* marker for array sizing etc. */
214         _DLB2_NB_ENQ_TYPES
215 };
216
217 /* hw-specific format - do not change */
218
219 struct dlb2_event_type {
220         uint16_t major:4;
221         uint16_t unused:4;
222         uint16_t sub:8;
223 };
224
225 union dlb2_opaque_data {
226         uint16_t opaque_data;
227         struct dlb2_event_type event_type;
228 };
229
230 struct dlb2_msg_info {
231         uint8_t qid;
232         uint8_t sched_type:2;
233         uint8_t priority:3;
234         uint8_t msg_type:3;
235 };
236
237 #define DLB2_NEW_CMD_BYTE 0x08
238 #define DLB2_FWD_CMD_BYTE 0x0A
239 #define DLB2_COMP_CMD_BYTE 0x02
240 #define DLB2_POP_CMD_BYTE 0x01
241 #define DLB2_NOOP_CMD_BYTE 0x00
242
243 /* hw-specific format - do not change */
244 struct dlb2_enqueue_qe {
245         uint64_t data;
246         /* Word 3 */
247         union dlb2_opaque_data u;
248         uint8_t qid;
249         uint8_t sched_type:2;
250         uint8_t priority:3;
251         uint8_t msg_type:3;
252         /* Word 4 */
253         uint16_t lock_id;
254         uint8_t meas_lat:1;
255         uint8_t weight:2; /* DLB 2.5 and above */
256         uint8_t no_dec:1;
257         uint8_t cmp_id:4;
258         union {
259                 uint8_t cmd_byte;
260                 struct {
261                         uint8_t cq_token:1;
262                         uint8_t qe_comp:1;
263                         uint8_t qe_frag:1;
264                         uint8_t qe_valid:1;
265                         uint8_t rsvd3:1;
266                         uint8_t error:1;
267                         uint8_t rsvd:2;
268                 };
269         };
270 };
271
272 /* hw-specific format - do not change */
273 struct dlb2_cq_pop_qe {
274         uint64_t data;
275         union dlb2_opaque_data u;
276         uint8_t qid;
277         uint8_t sched_type:2;
278         uint8_t priority:3;
279         uint8_t msg_type:3;
280         uint16_t tokens:10;
281         uint16_t rsvd2:6;
282         uint8_t meas_lat:1;
283         uint8_t rsvd1:2;
284         uint8_t no_dec:1;
285         uint8_t cmp_id:4;
286         union {
287                 uint8_t cmd_byte;
288                 struct {
289                         uint8_t cq_token:1;
290                         uint8_t qe_comp:1;
291                         uint8_t qe_frag:1;
292                         uint8_t qe_valid:1;
293                         uint8_t rsvd3:1;
294                         uint8_t error:1;
295                         uint8_t rsvd:2;
296                 };
297         };
298 };
299
300 /* hw-specific format - do not change */
301 struct dlb2_dequeue_qe {
302         uint64_t data;
303         union dlb2_opaque_data u;
304         uint8_t qid;
305         uint8_t sched_type:2;
306         uint8_t priority:3;
307         uint8_t msg_type:3;
308         uint16_t flow_id:16; /* was pp_id in v1 */
309         uint8_t debug;
310         uint8_t cq_gen:1;
311         uint8_t qid_depth:2; /* 2 bits in v2 */
312         uint8_t rsvd1:2;
313         uint8_t error:1;
314         uint8_t rsvd2:2;
315 };
316
317 union dlb2_port_config {
318         struct dlb2_create_ldb_port_args ldb;
319         struct dlb2_create_dir_port_args dir;
320 };
321
322 enum dlb2_port_state {
323         PORT_CLOSED,
324         PORT_STARTED,
325         PORT_STOPPED
326 };
327
328 enum dlb2_configuration_state {
329         /* The resource has not been configured */
330         DLB2_NOT_CONFIGURED,
331         /* The resource was configured, but the device was stopped */
332         DLB2_PREV_CONFIGURED,
333         /* The resource is currently configured */
334         DLB2_CONFIGURED
335 };
336
337 struct dlb2_port {
338         uint32_t id;
339         bool is_directed;
340         bool gen_bit;
341         uint16_t dir_credits;
342         uint32_t dequeue_depth;
343         enum dlb2_token_pop_mode token_pop_mode;
344         union dlb2_port_config cfg;
345         uint32_t *credit_pool[DLB2_NUM_QUEUE_TYPES]; /* use __atomic builtins */
346         union {
347                 struct {
348                         uint16_t cached_ldb_credits;
349                         uint16_t ldb_credits;
350                         uint16_t cached_dir_credits;
351                 };
352                 struct {
353                         uint16_t cached_credits;
354                         uint16_t credits;
355                 };
356         };
357         bool int_armed;
358         uint16_t owed_tokens;
359         int16_t issued_releases;
360         int16_t token_pop_thresh;
361         int cq_depth;
362         uint16_t cq_idx;
363         uint16_t cq_idx_unmasked;
364         uint16_t cq_depth_mask;
365         uint16_t gen_bit_shift;
366         uint64_t cq_rolling_mask; /*
367                                    * rotate to always have right expected
368                                    * gen bits
369                                    */
370         uint64_t cq_rolling_mask_2;
371         void *cq_addr_cached; /* avoid multiple refs */
372         enum dlb2_port_state state;
373         enum dlb2_configuration_state config_state;
374         int num_mapped_qids;
375         uint8_t *qid_mappings;
376         struct dlb2_enqueue_qe *qe4; /* Cache line's worth of QEs (4) */
377         struct dlb2_enqueue_qe *int_arm_qe;
378         struct dlb2_cq_pop_qe *consume_qe;
379         struct dlb2_eventdev *dlb2; /* back ptr */
380         struct dlb2_eventdev_port *ev_port; /* back ptr */
381         bool use_scalar; /* force usage of scalar code */
382         uint16_t hw_credit_quanta;
383         bool use_avx512;
384         uint32_t cq_weight;
385 };
386
387 /* Per-process per-port mmio and memory pointers */
388 struct process_local_port_data {
389         uint64_t *pp_addr;
390         struct dlb2_dequeue_qe *cq_base;
391         const struct rte_memzone *mz;
392         bool mmaped;
393 };
394
395 struct dlb2_eventdev;
396
397 struct dlb2_port_low_level_io_functions {
398         void (*pp_enqueue_four)(void *qe4, void *pp_addr);
399 };
400
401 struct dlb2_config {
402         int configured;
403         int reserved;
404         union {
405                 struct {
406                         uint32_t num_ldb_credits;
407                         uint32_t num_dir_credits;
408                 };
409                 struct {
410                         uint32_t num_credits;
411                 };
412         };
413         struct dlb2_create_sched_domain_args resources;
414 };
415
416 enum dlb2_cos {
417         DLB2_COS_DEFAULT = -1,
418         DLB2_COS_0 = 0,
419         DLB2_COS_1,
420         DLB2_COS_2,
421         DLB2_COS_3,
422         DLB2_COS_NUM_VALS
423 };
424
425 struct dlb2_hw_dev {
426         struct dlb2_config cfg;
427         struct dlb2_hw_resource_info info;
428         void *pf_dev; /* opaque pointer to PF PMD dev (struct dlb2_dev) */
429         uint32_t domain_id;
430         rte_spinlock_t resource_lock; /* for MP support */
431 } __rte_cache_aligned;
432
433 /* End HW related defines and structs */
434
435 /* Begin DLB2 PMD Eventdev related defines and structs */
436
437 #define DLB2_MAX_NUM_QUEUES(ver)                                \
438         (DLB2_MAX_NUM_DIR_QUEUES(ver) + DLB2_MAX_NUM_LDB_QUEUES)
439
440 #define DLB2_MAX_NUM_PORTS(ver) \
441         (DLB2_MAX_NUM_DIR_PORTS(ver) + DLB2_MAX_NUM_LDB_PORTS)
442
443 #define DLB2_MAX_NUM_DIR_QUEUES_V2_5 96
444 #define DLB2_MAX_NUM_DIR_PORTS_V2_5 DLB2_MAX_NUM_DIR_QUEUES_V2_5
445 #define DLB2_MAX_NUM_QUEUES_ALL \
446         (DLB2_MAX_NUM_DIR_QUEUES_V2_5 + DLB2_MAX_NUM_LDB_QUEUES)
447 #define DLB2_MAX_NUM_PORTS_ALL \
448         (DLB2_MAX_NUM_DIR_PORTS_V2_5 + DLB2_MAX_NUM_LDB_PORTS)
449 #define DLB2_MAX_INPUT_QUEUE_DEPTH 256
450
451 /** Structure to hold the queue to port link establishment attributes */
452
453 struct dlb2_event_queue_link {
454         uint8_t queue_id;
455         uint8_t priority;
456         bool mapped;
457         bool valid;
458 };
459
460 struct dlb2_traffic_stats {
461         uint64_t rx_ok;
462         uint64_t rx_drop;
463         uint64_t rx_interrupt_wait;
464         uint64_t rx_umonitor_umwait;
465         uint64_t tx_ok;
466         uint64_t total_polls;
467         uint64_t zero_polls;
468         union {
469                 struct {
470                         uint64_t tx_nospc_ldb_hw_credits;
471                         uint64_t tx_nospc_dir_hw_credits;
472                 };
473                 struct {
474                         uint64_t tx_nospc_hw_credits;
475                 };
476         };
477         uint64_t tx_nospc_inflight_max;
478         uint64_t tx_nospc_new_event_limit;
479         uint64_t tx_nospc_inflight_credits;
480 };
481
482 /* DLB2 HW sets the 2bit qid_depth in rx QEs based on the programmable depth
483  * threshold. The global default value in config/common_base (or rte_config.h)
484  * can be overridden on a per-qid basis using a vdev command line parameter.
485  * 3: depth > threshold
486  * 2: threshold >= depth > 3/4 threshold
487  * 1: 3/4 threshold >= depth > 1/2 threshold
488  * 0: depth <= 1/2 threshold.
489  */
490 #define DLB2_QID_DEPTH_LE50 0
491 #define DLB2_QID_DEPTH_GT50_LE75 1
492 #define DLB2_QID_DEPTH_GT75_LE100 2
493 #define DLB2_QID_DEPTH_GT100 3
494 #define DLB2_NUM_QID_DEPTH_STAT_VALS 4 /* 2 bits */
495
496 struct dlb2_queue_stats {
497         uint64_t enq_ok;
498         uint64_t qid_depth[DLB2_NUM_QID_DEPTH_STAT_VALS];
499 };
500
501 struct dlb2_port_stats {
502         struct dlb2_traffic_stats traffic;
503         uint64_t tx_op_cnt[4]; /* indexed by rte_event.op */
504         uint64_t tx_implicit_rel;
505         uint64_t tx_sched_cnt[DLB2_NUM_HW_SCHED_TYPES];
506         uint64_t tx_invalid;
507         uint64_t rx_sched_cnt[DLB2_NUM_HW_SCHED_TYPES];
508         uint64_t rx_sched_invalid;
509         struct dlb2_queue_stats queue[DLB2_MAX_NUM_QUEUES_ALL];
510 };
511
512 struct dlb2_eventdev_port {
513         struct dlb2_port qm_port; /* hw specific data structure */
514         struct rte_event_port_conf conf; /* user-supplied configuration */
515         uint16_t inflight_credits; /* num credits this port has right now */
516         uint16_t credit_update_quanta;
517         struct dlb2_eventdev *dlb2; /* backlink optimization */
518         struct dlb2_port_stats stats __rte_cache_aligned;
519         struct dlb2_event_queue_link link[DLB2_MAX_NUM_QIDS_PER_LDB_CQ];
520         int num_links;
521         uint32_t id; /* port id */
522         /* num releases yet to be completed on this port.
523          * Only applies to load-balanced ports.
524          */
525         uint16_t outstanding_releases;
526         uint16_t inflight_max; /* app requested max inflights for this port */
527         int enq_retries; /* Number of attempts before ret ENOSPC */
528         /* setup_done is set when the event port is setup */
529         bool setup_done;
530         /* enq_configured is set when the qm port is created */
531         bool enq_configured;
532         uint8_t implicit_release; /* release events before dequeuing */
533         uint32_t cq_weight; /* DLB2.5 and above ldb ports only */
534         int cos_id; /*ldb port class of service */
535 }  __rte_cache_aligned;
536
537 struct dlb2_queue {
538         uint32_t num_qid_inflights; /* User config */
539         uint32_t num_atm_inflights; /* User config */
540         enum dlb2_configuration_state config_state;
541         int  sched_type; /* LB queue only */
542         uint8_t id;
543         bool     is_directed;
544 };
545
546 struct dlb2_eventdev_queue {
547         struct dlb2_queue qm_queue;
548         struct rte_event_queue_conf conf; /* User config */
549         int depth_threshold; /* use default if 0 */
550         uint32_t id;
551         bool setup_done;
552         uint8_t num_links;
553 };
554
555 enum dlb2_run_state {
556         DLB2_RUN_STATE_STOPPED = 0,
557         DLB2_RUN_STATE_STOPPING,
558         DLB2_RUN_STATE_STARTING,
559         DLB2_RUN_STATE_STARTED
560 };
561
562 struct dlb2_eventdev {
563         struct dlb2_eventdev_port ev_ports[DLB2_MAX_NUM_PORTS_ALL];
564         struct dlb2_eventdev_queue ev_queues[DLB2_MAX_NUM_QUEUES_ALL];
565         uint8_t qm_ldb_to_ev_queue_id[DLB2_MAX_NUM_QUEUES_ALL];
566         uint8_t qm_dir_to_ev_queue_id[DLB2_MAX_NUM_QUEUES_ALL];
567         /* store num stats and offset of the stats for each queue */
568         uint16_t xstats_count_per_qid[DLB2_MAX_NUM_QUEUES_ALL];
569         uint16_t xstats_offset_for_qid[DLB2_MAX_NUM_QUEUES_ALL];
570         /* store num stats and offset of the stats for each port */
571         uint16_t xstats_count_per_port[DLB2_MAX_NUM_PORTS_ALL];
572         uint16_t xstats_offset_for_port[DLB2_MAX_NUM_PORTS_ALL];
573         struct dlb2_get_num_resources_args hw_rsrc_query_results;
574         uint32_t xstats_count_mode_queue;
575         struct dlb2_hw_dev qm_instance; /* strictly hw related */
576         uint64_t global_dequeue_wait_ticks;
577         struct dlb2_xstats_entry *xstats;
578         struct rte_eventdev *event_dev; /* backlink to dev */
579         uint32_t xstats_count_mode_dev;
580         uint32_t xstats_count_mode_port;
581         uint32_t xstats_count;
582         uint32_t inflights; /* use __atomic builtins */
583         uint32_t new_event_limit;
584         int max_num_events_override;
585         int num_dir_credits_override;
586         bool vector_opts_enabled;
587         int max_cq_depth;
588         volatile enum dlb2_run_state run_state;
589         uint16_t num_dir_queues; /* total num of evdev dir queues requested */
590         union {
591                 struct {
592                         uint16_t num_dir_credits;
593                         uint16_t num_ldb_credits;
594                 };
595                 struct {
596                         uint16_t num_credits;
597                 };
598         };
599         uint16_t num_queues; /* total queues */
600         uint16_t num_ldb_queues; /* total num of evdev ldb queues requested */
601         uint16_t num_ports; /* total num of evdev ports requested */
602         uint16_t num_ldb_ports; /* total num of ldb ports requested */
603         uint16_t num_dir_ports; /* total num of dir ports requested */
604         bool umwait_allowed;
605         bool global_dequeue_wait; /* Not using per dequeue wait if true */
606         enum dlb2_cq_poll_modes poll_mode;
607         int poll_interval;
608         int sw_credit_quanta;
609         int hw_credit_quanta;
610         int default_depth_thresh;
611         uint8_t revision;
612         uint8_t version;
613         bool configured;
614         union {
615                 struct {
616                         uint16_t max_ldb_credits;
617                         uint16_t max_dir_credits;
618                         /* use __atomic builtins */ /* shared hw cred */
619                         uint32_t ldb_credit_pool __rte_cache_aligned;
620                         /* use __atomic builtins */ /* shared hw cred */
621                         uint32_t dir_credit_pool __rte_cache_aligned;
622                 };
623                 struct {
624                         uint16_t max_credits;
625                         /* use __atomic builtins */ /* shared hw cred */
626                         uint32_t credit_pool __rte_cache_aligned;
627                 };
628         };
629         uint32_t cos_ports[DLB2_COS_NUM_VALS]; /* total ldb ports in each class */
630         uint32_t cos_bw[DLB2_COS_NUM_VALS]; /* bandwidth per cos domain */
631 };
632
633 /* used for collecting and passing around the dev args */
634 struct dlb2_qid_depth_thresholds {
635         int val[DLB2_MAX_NUM_QUEUES_ALL];
636 };
637
638 struct dlb2_cq_weight {
639         int limit[DLB2_MAX_NUM_LDB_PORTS];
640 };
641
642 struct dlb2_port_cos {
643         int cos_id[DLB2_MAX_NUM_LDB_PORTS];
644 };
645
646 struct dlb2_cos_bw {
647         int val[DLB2_COS_NUM_VALS];
648 };
649
650 struct dlb2_devargs {
651         int socket_id;
652         int max_num_events;
653         int num_dir_credits_override;
654         int dev_id;
655         struct dlb2_qid_depth_thresholds qid_depth_thresholds;
656         enum dlb2_cos cos_id;
657         int poll_interval;
658         int sw_credit_quanta;
659         int hw_credit_quanta;
660         int default_depth_thresh;
661         bool vector_opts_enabled;
662         int max_cq_depth;
663         struct dlb2_cq_weight cq_weight;
664         struct dlb2_port_cos port_cos;
665         struct dlb2_cos_bw cos_bw;
666 };
667
668 /* End Eventdev related defines and structs */
669
670 /* Forwards for non-inlined functions */
671
672 void dlb2_eventdev_dump(struct rte_eventdev *dev, FILE *f);
673
674 int dlb2_xstats_init(struct dlb2_eventdev *dlb2);
675
676 void dlb2_xstats_uninit(struct dlb2_eventdev *dlb2);
677
678 int dlb2_eventdev_xstats_get(const struct rte_eventdev *dev,
679                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
680                 const unsigned int ids[], uint64_t values[], unsigned int n);
681
682 int dlb2_eventdev_xstats_get_names(const struct rte_eventdev *dev,
683                 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
684                 struct rte_event_dev_xstats_name *xstat_names,
685                 unsigned int *ids, unsigned int size);
686
687 uint64_t dlb2_eventdev_xstats_get_by_name(const struct rte_eventdev *dev,
688                                           const char *name, unsigned int *id);
689
690 int dlb2_eventdev_xstats_reset(struct rte_eventdev *dev,
691                 enum rte_event_dev_xstats_mode mode,
692                 int16_t queue_port_id,
693                 const uint32_t ids[],
694                 uint32_t nb_ids);
695
696 int test_dlb2_eventdev(void);
697
698 int dlb2_primary_eventdev_probe(struct rte_eventdev *dev,
699                                 const char *name,
700                                 struct dlb2_devargs *dlb2_args);
701
702 int dlb2_secondary_eventdev_probe(struct rte_eventdev *dev,
703                                   const char *name);
704
705 uint32_t dlb2_get_queue_depth(struct dlb2_eventdev *dlb2,
706                               struct dlb2_eventdev_queue *queue);
707
708 int dlb2_parse_params(const char *params,
709                       const char *name,
710                       struct dlb2_devargs *dlb2_args,
711                       uint8_t version);
712
713 void dlb2_event_build_hcws(struct dlb2_port *qm_port,
714                            const struct rte_event ev[],
715                            int num,
716                            uint8_t *sched_type,
717                            uint8_t *queue_id);
718
719
720 /* Extern globals */
721 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
722
723 #endif  /* _DLB2_PRIV_H_ */