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