a6f80de9afeae01d94f0c1be25dae679c8f56c8a
[dpdk.git] / lib / librte_port / rte_swx_port.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4 #ifndef __INCLUDE_RTE_SWX_PORT_H__
5 #define __INCLUDE_RTE_SWX_PORT_H__
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 /**
12  * @file
13  * RTE SWX Port
14  *
15  * Packet I/O port interface.
16  */
17
18 #include <stdint.h>
19
20 /** Packet. */
21 struct rte_swx_pkt {
22         /** Opaque packet handle. */
23         void *handle;
24
25         /** Buffer where the packet is stored. */
26         uint8_t *pkt;
27
28         /** Packet buffer offset of the first packet byte. */
29         uint32_t offset;
30
31         /** Packet length in bytes. */
32         uint32_t length;
33 };
34
35 /*
36  * Input port
37  */
38
39 /**
40  * Input port create
41  *
42  * @param[in] args
43  *   Arguments for input port creation. Format specific to each port type.
44  * @return
45  *   Handle to input port instance on success, NULL on error.
46  */
47 typedef void *
48 (*rte_swx_port_in_create_t)(void *args);
49
50 /**
51  * Input port free
52  *
53  * @param[in] args
54  *   Input port handle.
55  */
56 typedef void
57 (*rte_swx_port_in_free_t)(void *port);
58
59 /**
60  * Input port packet receive
61  *
62  * @param[in] port
63  *   Input port handle.
64  * @param[out] pkt
65  *   Received packet. Only valid when the function returns 1. Must point to
66  *   valid memory.
67  * @return
68  *   0 when no packet was received, 1 when a packet was received. No other
69  *   return values are allowed.
70  */
71 typedef int
72 (*rte_swx_port_in_pkt_rx_t)(void *port,
73                             struct rte_swx_pkt *pkt);
74
75 /** Input port statistics counters. */
76 struct rte_swx_port_in_stats {
77         /** Number of packets. */
78         uint64_t n_pkts;
79
80         /** Number of bytes. */
81         uint64_t n_bytes;
82
83         /** Number of empty polls. */
84         uint64_t n_empty;
85 };
86
87 /**
88  * Input port statistics counters read
89  *
90  * @param[in] port
91  *   Input port handle.
92  * @param[out] stats
93  *   Input port statistics counters. Must point to valid memory.
94  */
95 typedef void
96 (*rte_swx_port_in_stats_read_t)(void *port,
97                                 struct rte_swx_port_in_stats *stats);
98
99 /** Input port operations. */
100 struct rte_swx_port_in_ops {
101         /** Create. Must be non-NULL. */
102         rte_swx_port_in_create_t create;
103
104         /** Free. Must be non-NULL. */
105         rte_swx_port_in_free_t free;
106
107         /** Packet reception. Must be non-NULL. */
108         rte_swx_port_in_pkt_rx_t pkt_rx;
109
110         /** Statistics counters read. Must be non-NULL. */
111         rte_swx_port_in_stats_read_t stats_read;
112 };
113
114 #ifdef __cplusplus
115 }
116 #endif
117
118 #endif