1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2020 Intel Corporation
11 #include <rte_eventdev.h>
12 #include <rte_config.h>
13 #include "dlb2_user.h"
16 #ifndef RTE_LIBRTE_PMD_DLB2_QUELL_STATS
17 #define DLB2_INC_STAT(_stat, _incr_val) ((_stat) += _incr_val)
19 #define DLB2_INC_STAT(_stat, _incr_val)
22 #define EVDEV_DLB2_NAME_PMD dlb2_event
24 /* command line arg strings */
25 #define NUMA_NODE_ARG "numa_node"
26 #define DLB2_MAX_NUM_EVENTS "max_num_events"
27 #define DLB2_NUM_DIR_CREDITS "num_dir_credits"
28 #define DEV_ID_ARG "dev_id"
29 #define DLB2_DEFER_SCHED_ARG "defer_sched"
30 #define DLB2_QID_DEPTH_THRESH_ARG "qid_depth_thresh"
31 #define DLB2_COS_ARG "cos"
33 /* Begin HW related defines and structs */
35 #define DLB2_MAX_NUM_DOMAINS 32
36 #define DLB2_MAX_NUM_VFS 16
37 #define DLB2_MAX_NUM_LDB_QUEUES 32
38 #define DLB2_MAX_NUM_LDB_PORTS 64
39 #define DLB2_MAX_NUM_DIR_PORTS 64
40 #define DLB2_MAX_NUM_DIR_QUEUES 64
41 #define DLB2_MAX_NUM_FLOWS (64 * 1024)
42 #define DLB2_MAX_NUM_LDB_CREDITS (8 * 1024)
43 #define DLB2_MAX_NUM_DIR_CREDITS (2 * 1024)
44 #define DLB2_MAX_NUM_LDB_CREDIT_POOLS 64
45 #define DLB2_MAX_NUM_DIR_CREDIT_POOLS 64
46 #define DLB2_MAX_NUM_HIST_LIST_ENTRIES 2048
47 #define DLB2_MAX_NUM_AQOS_ENTRIES 2048
48 #define DLB2_MAX_NUM_QIDS_PER_LDB_CQ 8
49 #define DLB2_QID_PRIORITIES 8
50 #define DLB2_MAX_DEVICE_PATH 32
51 #define DLB2_MIN_DEQUEUE_TIMEOUT_NS 1
52 /* Note: "- 1" here to support the timeout range check in eventdev_autotest */
53 #define DLB2_MAX_DEQUEUE_TIMEOUT_NS (UINT32_MAX - 1)
54 #define DLB2_SW_CREDIT_BATCH_SZ 32
55 #define DLB2_NUM_SN_GROUPS 2
56 #define DLB2_MAX_LDB_SN_ALLOC 1024
57 #define DLB2_MAX_QUEUE_DEPTH_THRESHOLD 8191
59 /* 2048 total hist list entries and 64 total ldb ports, which
60 * makes for 2048/64 == 32 hist list entries per port. However, CQ
61 * depth must be a power of 2 and must also be >= HIST LIST entries.
62 * As a result we just limit the maximum dequeue depth to 32.
64 #define DLB2_MIN_CQ_DEPTH 1
65 #define DLB2_MAX_CQ_DEPTH 32
66 #define DLB2_MIN_HARDWARE_CQ_DEPTH 8
67 #define DLB2_NUM_HIST_LIST_ENTRIES_PER_LDB_PORT \
71 * Static per queue/port provisioning values
73 #define DLB2_NUM_ATOMIC_INFLIGHTS_PER_QUEUE 64
75 #define CQ_BASE(is_dir) ((is_dir) ? DLB2_DIR_CQ_BASE : DLB2_LDB_CQ_BASE)
76 #define CQ_SIZE(is_dir) ((is_dir) ? DLB2_DIR_CQ_MAX_SIZE : \
78 #define PP_BASE(is_dir) ((is_dir) ? DLB2_DIR_PP_BASE : DLB2_LDB_PP_BASE)
80 #define PAGE_SIZE (sysconf(_SC_PAGESIZE))
82 #define DLB2_NUM_QES_PER_CACHE_LINE 4
84 #define DLB2_MAX_ENQUEUE_DEPTH 64
85 #define DLB2_MIN_ENQUEUE_DEPTH 4
87 #define DLB2_NAME_SIZE 64
90 #define DLB2_2K (2 * DLB2_1K)
91 #define DLB2_4K (4 * DLB2_1K)
92 #define DLB2_16K (16 * DLB2_1K)
93 #define DLB2_32K (32 * DLB2_1K)
94 #define DLB2_1MB (DLB2_1K * DLB2_1K)
95 #define DLB2_16MB (16 * DLB2_1MB)
97 /* Use the upper 3 bits of the event priority to select the DLB2 priority */
98 #define EV_TO_DLB2_PRIO(x) ((x) >> 5)
99 #define DLB2_TO_EV_PRIO(x) ((x) << 5)
101 enum dlb2_hw_port_types {
104 DLB2_NUM_PORT_TYPES /* Must be last */
107 enum dlb2_hw_queue_types {
110 DLB2_NUM_QUEUE_TYPES /* Must be last */
113 #define PORT_TYPE(p) ((p)->is_directed ? DLB2_DIR_PORT : DLB2_LDB_PORT)
115 /* Do not change - must match hardware! */
116 enum dlb2_hw_sched_type {
117 DLB2_SCHED_ATOMIC = 0,
118 DLB2_SCHED_UNORDERED,
121 /* DLB2_NUM_HW_SCHED_TYPES must be last */
122 DLB2_NUM_HW_SCHED_TYPES
125 struct dlb2_hw_rsrcs {
126 int32_t nb_events_limit;
127 uint32_t num_queues; /* Total queues (lb + dir) */
128 uint32_t num_ldb_queues; /* Number of available ldb queues */
129 uint32_t num_ldb_ports; /* Number of load balanced ports */
130 uint32_t num_dir_ports; /* Number of directed ports */
131 uint32_t num_ldb_credits; /* Number of load balanced credits */
132 uint32_t num_dir_credits; /* Number of directed credits */
133 uint32_t reorder_window_size; /* Size of reorder window */
136 struct dlb2_hw_resource_info {
137 /**> Max resources that can be provided */
138 struct dlb2_hw_rsrcs hw_rsrc_max;
139 int num_sched_domains;
143 enum dlb2_enqueue_type {
145 * New : Used to inject a new packet into the QM.
149 * Forward : Enqueues a packet, and
150 * - if atomic: release any lock it holds in the QM
151 * - if ordered: release the packet for egress re-ordering
155 * Enqueue Drop : Release an inflight packet. Must be called with
156 * event == NULL. Used to drop a packet.
158 * Note that all packets dequeued from a load-balanced port must be
159 * released, either with DLB2_ENQ_DROP or DLB2_ENQ_FWD.
163 /* marker for array sizing etc. */
167 /* hw-specific format - do not change */
169 struct dlb2_event_type {
175 union dlb2_opaque_data {
176 uint16_t opaque_data;
177 struct dlb2_event_type event_type;
180 struct dlb2_msg_info {
182 uint8_t sched_type:2;
187 #define DLB2_NEW_CMD_BYTE 0x08
188 #define DLB2_FWD_CMD_BYTE 0x0A
189 #define DLB2_COMP_CMD_BYTE 0x02
190 #define DLB2_POP_CMD_BYTE 0x01
191 #define DLB2_NOOP_CMD_BYTE 0x00
193 /* hw-specific format - do not change */
194 struct dlb2_enqueue_qe {
197 union dlb2_opaque_data u;
199 uint8_t sched_type:2;
222 /* hw-specific format - do not change */
223 struct dlb2_cq_pop_qe {
225 union dlb2_opaque_data u;
227 uint8_t sched_type:2;
250 /* hw-specific format - do not change */
251 struct dlb2_dequeue_qe {
253 union dlb2_opaque_data u;
255 uint8_t sched_type:2;
258 uint16_t flow_id:16; /* was pp_id in v1 */
261 uint8_t qid_depth:2; /* 2 bits in v2 */
267 union dlb2_port_config {
268 struct dlb2_create_ldb_port_args ldb;
269 struct dlb2_create_dir_port_args dir;
272 enum dlb2_port_state {
278 enum dlb2_configuration_state {
279 /* The resource has not been configured */
281 /* The resource was configured, but the device was stopped */
282 DLB2_PREV_CONFIGURED,
283 /* The resource is currently configured */
291 uint16_t dir_credits;
292 uint32_t dequeue_depth;
293 union dlb2_port_config cfg;
294 uint32_t *credit_pool[DLB2_NUM_QUEUE_TYPES]; /* use __atomic builtins */
295 uint16_t cached_ldb_credits;
296 uint16_t ldb_credits;
297 uint16_t cached_dir_credits;
299 uint16_t owed_tokens;
300 int16_t issued_releases;
303 uint16_t cq_idx_unmasked;
304 uint16_t cq_depth_mask;
305 uint16_t gen_bit_shift;
306 enum dlb2_port_state state;
307 enum dlb2_configuration_state config_state;
309 uint8_t *qid_mappings;
310 struct dlb2_enqueue_qe *qe4; /* Cache line's worth of QEs (4) */
311 struct dlb2_enqueue_qe *int_arm_qe;
312 struct dlb2_cq_pop_qe *consume_qe;
313 struct dlb2_eventdev *dlb2; /* back ptr */
314 struct dlb2_eventdev_port *ev_port; /* back ptr */
317 /* Per-process per-port mmio and memory pointers */
318 struct process_local_port_data {
320 struct dlb2_dequeue_qe *cq_base;
321 const struct rte_memzone *mz;
325 struct dlb2_eventdev;
330 uint32_t num_ldb_credits;
331 uint32_t num_dir_credits;
332 struct dlb2_create_sched_domain_args resources;
336 DLB2_COS_DEFAULT = -1,
344 struct dlb2_config cfg;
345 struct dlb2_hw_resource_info info;
346 void *pf_dev; /* opaque pointer to PF PMD dev (struct dlb2_dev) */
348 enum dlb2_cos cos_id;
349 rte_spinlock_t resource_lock; /* for MP support */
350 } __rte_cache_aligned;
352 /* End HW related defines and structs */
354 /* Begin DLB2 PMD Eventdev related defines and structs */
356 #define DLB2_MAX_NUM_QUEUES \
357 (DLB2_MAX_NUM_DIR_QUEUES + DLB2_MAX_NUM_LDB_QUEUES)
359 #define DLB2_MAX_NUM_PORTS (DLB2_MAX_NUM_DIR_PORTS + DLB2_MAX_NUM_LDB_PORTS)
360 #define DLB2_MAX_INPUT_QUEUE_DEPTH 256
362 /** Structure to hold the queue to port link establishment attributes */
364 struct dlb2_event_queue_link {
371 struct dlb2_traffic_stats {
374 uint64_t rx_interrupt_wait;
375 uint64_t rx_umonitor_umwait;
377 uint64_t total_polls;
379 uint64_t tx_nospc_ldb_hw_credits;
380 uint64_t tx_nospc_dir_hw_credits;
381 uint64_t tx_nospc_inflight_max;
382 uint64_t tx_nospc_new_event_limit;
383 uint64_t tx_nospc_inflight_credits;
386 /* DLB2 HW sets the 2bit qid_depth in rx QEs based on the programmable depth
387 * threshold. The global default value in config/common_base (or rte_config.h)
388 * can be overridden on a per-qid basis using a vdev command line parameter.
389 * 3: depth > threshold
390 * 2: threshold >= depth > 3/4 threshold
391 * 1: 3/4 threshold >= depth > 1/2 threshold
392 * 0: depth <= 1/2 threshold.
394 #define DLB2_QID_DEPTH_LE50 0
395 #define DLB2_QID_DEPTH_GT50_LE75 1
396 #define DLB2_QID_DEPTH_GT75_LE100 2
397 #define DLB2_QID_DEPTH_GT100 3
398 #define DLB2_NUM_QID_DEPTH_STAT_VALS 4 /* 2 bits */
400 struct dlb2_queue_stats {
402 uint64_t qid_depth[DLB2_NUM_QID_DEPTH_STAT_VALS];
405 struct dlb2_port_stats {
406 struct dlb2_traffic_stats traffic;
407 uint64_t tx_op_cnt[4]; /* indexed by rte_event.op */
408 uint64_t tx_implicit_rel;
409 uint64_t tx_sched_cnt[DLB2_NUM_HW_SCHED_TYPES];
411 uint64_t rx_sched_cnt[DLB2_NUM_HW_SCHED_TYPES];
412 uint64_t rx_sched_invalid;
413 struct dlb2_queue_stats queue[DLB2_MAX_NUM_QUEUES];
416 struct dlb2_eventdev_port {
417 struct dlb2_port qm_port; /* hw specific data structure */
418 struct rte_event_port_conf conf; /* user-supplied configuration */
419 uint16_t inflight_credits; /* num credits this port has right now */
420 uint16_t credit_update_quanta;
421 struct dlb2_eventdev *dlb2; /* backlink optimization */
422 struct dlb2_port_stats stats __rte_cache_aligned;
423 struct dlb2_event_queue_link link[DLB2_MAX_NUM_QIDS_PER_LDB_CQ];
425 uint32_t id; /* port id */
426 /* num releases yet to be completed on this port.
427 * Only applies to load-balanced ports.
429 uint16_t outstanding_releases;
430 uint16_t inflight_max; /* app requested max inflights for this port */
431 /* setup_done is set when the event port is setup */
433 /* enq_configured is set when the qm port is created */
435 uint8_t implicit_release; /* release events before dequeueing */
436 } __rte_cache_aligned;
439 uint32_t num_qid_inflights; /* User config */
440 uint32_t num_atm_inflights; /* User config */
441 enum dlb2_configuration_state config_state;
442 int sched_type; /* LB queue only */
447 struct dlb2_eventdev_queue {
448 struct dlb2_queue qm_queue;
449 struct rte_event_queue_conf conf; /* User config */
450 int depth_threshold; /* use default if 0 */
456 enum dlb2_run_state {
457 DLB2_RUN_STATE_STOPPED = 0,
458 DLB2_RUN_STATE_STOPPING,
459 DLB2_RUN_STATE_STARTING,
460 DLB2_RUN_STATE_STARTED
463 struct dlb2_eventdev {
464 struct dlb2_eventdev_port ev_ports[DLB2_MAX_NUM_PORTS];
465 struct dlb2_eventdev_queue ev_queues[DLB2_MAX_NUM_QUEUES];
466 uint8_t qm_ldb_to_ev_queue_id[DLB2_MAX_NUM_QUEUES];
467 uint8_t qm_dir_to_ev_queue_id[DLB2_MAX_NUM_QUEUES];
468 /* store num stats and offset of the stats for each queue */
469 uint16_t xstats_count_per_qid[DLB2_MAX_NUM_QUEUES];
470 uint16_t xstats_offset_for_qid[DLB2_MAX_NUM_QUEUES];
471 /* store num stats and offset of the stats for each port */
472 uint16_t xstats_count_per_port[DLB2_MAX_NUM_PORTS];
473 uint16_t xstats_offset_for_port[DLB2_MAX_NUM_PORTS];
474 struct dlb2_get_num_resources_args hw_rsrc_query_results;
475 uint32_t xstats_count_mode_queue;
476 struct dlb2_hw_dev qm_instance; /* strictly hw related */
477 uint64_t global_dequeue_wait_ticks;
478 struct dlb2_xstats_entry *xstats;
479 struct rte_eventdev *event_dev; /* backlink to dev */
480 uint32_t xstats_count_mode_dev;
481 uint32_t xstats_count_mode_port;
482 uint32_t xstats_count;
483 uint32_t inflights; /* use __atomic builtins */
484 uint32_t new_event_limit;
485 int max_num_events_override;
486 int num_dir_credits_override;
487 volatile enum dlb2_run_state run_state;
488 uint16_t num_dir_queues; /* total num of evdev dir queues requested */
489 uint16_t num_dir_credits;
490 uint16_t num_ldb_credits;
491 uint16_t num_queues; /* total queues */
492 uint16_t num_ldb_queues; /* total num of evdev ldb queues requested */
493 uint16_t num_ports; /* total num of evdev ports requested */
494 uint16_t num_ldb_ports; /* total num of ldb ports requested */
495 uint16_t num_dir_ports; /* total num of dir ports requested */
497 bool global_dequeue_wait; /* Not using per dequeue wait if true */
499 enum dlb2_cq_poll_modes poll_mode;
502 uint16_t max_ldb_credits;
503 uint16_t max_dir_credits;
505 /* force hw credit pool counters into exclusive cache lines */
507 /* use __atomic builtins */ /* shared hw cred */
508 uint32_t ldb_credit_pool __rte_cache_aligned;
509 /* use __atomic builtins */ /* shared hw cred */
510 uint32_t dir_credit_pool __rte_cache_aligned;
513 /* used for collecting and passing around the dev args */
514 struct dlb2_qid_depth_thresholds {
515 int val[DLB2_MAX_NUM_QUEUES];
518 struct dlb2_devargs {
521 int num_dir_credits_override;
524 struct dlb2_qid_depth_thresholds qid_depth_thresholds;
525 enum dlb2_cos cos_id;
528 /* End Eventdev related defines and structs */
530 /* Forwards for non-inlined functions */
532 void dlb2_eventdev_dump(struct rte_eventdev *dev, FILE *f);
534 int dlb2_xstats_init(struct dlb2_eventdev *dlb2);
536 void dlb2_xstats_uninit(struct dlb2_eventdev *dlb2);
538 int dlb2_eventdev_xstats_get(const struct rte_eventdev *dev,
539 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
540 const unsigned int ids[], uint64_t values[], unsigned int n);
542 int dlb2_eventdev_xstats_get_names(const struct rte_eventdev *dev,
543 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
544 struct rte_event_dev_xstats_name *xstat_names,
545 unsigned int *ids, unsigned int size);
547 uint64_t dlb2_eventdev_xstats_get_by_name(const struct rte_eventdev *dev,
548 const char *name, unsigned int *id);
550 int dlb2_eventdev_xstats_reset(struct rte_eventdev *dev,
551 enum rte_event_dev_xstats_mode mode,
552 int16_t queue_port_id,
553 const uint32_t ids[],
556 int test_dlb2_eventdev(void);
558 int dlb2_primary_eventdev_probe(struct rte_eventdev *dev,
560 struct dlb2_devargs *dlb2_args);
562 int dlb2_secondary_eventdev_probe(struct rte_eventdev *dev,
565 uint32_t dlb2_get_queue_depth(struct dlb2_eventdev *dlb2,
566 struct dlb2_eventdev_queue *queue);
568 int dlb2_parse_params(const char *params,
570 struct dlb2_devargs *dlb2_args);
573 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
575 #endif /* _DLB2_PRIV_H_ */