918a34ed1fac38a41ca2a962cf195119f2ba908b
[dpdk.git] / lib / librte_ethdev / rte_ethdev_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _RTE_ETHDEV_CORE_H_
6 #define _RTE_ETHDEV_CORE_H_
7
8 #include <pthread.h>
9 #include <sys/types.h>
10
11 /**
12  * @file
13  *
14  * RTE Ethernet Device internal header.
15  *
16  * This header contains internal data types. But they are still part of the
17  * public API because they are used by inline functions in the published API.
18  *
19  * Applications should not use these directly.
20  *
21  */
22
23 struct rte_eth_dev_callback;
24 /** @internal Structure to keep track of registered callbacks */
25 TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);
26
27 struct rte_eth_dev;
28
29 typedef uint16_t (*eth_rx_burst_t)(void *rxq,
30                                    struct rte_mbuf **rx_pkts,
31                                    uint16_t nb_pkts);
32 /**< @internal Retrieve input packets from a receive queue of an Ethernet device. */
33
34 typedef uint16_t (*eth_tx_burst_t)(void *txq,
35                                    struct rte_mbuf **tx_pkts,
36                                    uint16_t nb_pkts);
37 /**< @internal Send output packets on a transmit queue of an Ethernet device. */
38
39 typedef uint16_t (*eth_tx_prep_t)(void *txq,
40                                    struct rte_mbuf **tx_pkts,
41                                    uint16_t nb_pkts);
42 /**< @internal Prepare output packets on a transmit queue of an Ethernet device. */
43
44
45 typedef uint32_t (*eth_rx_queue_count_t)(struct rte_eth_dev *dev,
46                                          uint16_t rx_queue_id);
47 /**< @internal Get number of used descriptors on a receive queue. */
48
49 typedef int (*eth_rx_descriptor_done_t)(void *rxq, uint16_t offset);
50 /**< @internal Check DD bit of specific RX descriptor */
51
52 typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);
53 /**< @internal Check the status of a Rx descriptor */
54
55 typedef int (*eth_tx_descriptor_status_t)(void *txq, uint16_t offset);
56 /**< @internal Check the status of a Tx descriptor */
57
58
59 /**
60  * @internal
61  * Structure used to hold information about the callbacks to be called for a
62  * queue on RX and TX.
63  */
64 struct rte_eth_rxtx_callback {
65         struct rte_eth_rxtx_callback *next;
66         union{
67                 rte_rx_callback_fn rx;
68                 rte_tx_callback_fn tx;
69         } fn;
70         void *param;
71 };
72
73 /**
74  * @internal
75  * The generic data structure associated with each ethernet device.
76  *
77  * Pointers to burst-oriented packet receive and transmit functions are
78  * located at the beginning of the structure, along with the pointer to
79  * where all the data elements for the particular device are stored in shared
80  * memory. This split allows the function pointer and driver data to be per-
81  * process, while the actual configuration data for the device is shared.
82  */
83 struct rte_eth_dev {
84         eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
85         eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
86         eth_tx_prep_t tx_pkt_prepare; /**< Pointer to PMD transmit prepare function. */
87
88         eth_rx_queue_count_t       rx_queue_count; /**< Get the number of used RX descriptors. */
89         eth_rx_descriptor_done_t   rx_descriptor_done;   /**< Check rxd DD bit. */
90         eth_rx_descriptor_status_t rx_descriptor_status; /**< Check the status of a Rx descriptor. */
91         eth_tx_descriptor_status_t tx_descriptor_status; /**< Check the status of a Tx descriptor. */
92
93         /**
94          * Next two fields are per-device data but *data is shared between
95          * primary and secondary processes and *process_private is per-process
96          * private. The second one is managed by PMDs if necessary.
97          */
98         struct rte_eth_dev_data *data;  /**< Pointer to device data. */
99         void *process_private; /**< Pointer to per-process device data. */
100         const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
101         struct rte_device *device; /**< Backing device */
102         struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
103         /** User application callbacks for NIC interrupts */
104         struct rte_eth_dev_cb_list link_intr_cbs;
105         /**
106          * User-supplied functions called from rx_burst to post-process
107          * received packets before passing them to the user
108          */
109         struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
110         /**
111          * User-supplied functions called from tx_burst to pre-process
112          * received packets before passing them to the driver for transmission.
113          */
114         struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
115         enum rte_eth_dev_state state; /**< Flag indicating the port state */
116         void *security_ctx; /**< Context for security ops */
117
118         uint64_t reserved_64s[4]; /**< Reserved for future fields */
119         void *reserved_ptrs[4];   /**< Reserved for future fields */
120 } __rte_cache_aligned;
121
122 struct rte_eth_dev_sriov;
123 struct rte_eth_dev_owner;
124
125 /**
126  * @internal
127  * The data part, with no function pointers, associated with each ethernet device.
128  *
129  * This structure is safe to place in shared memory to be common among different
130  * processes in a multi-process configuration.
131  */
132 struct rte_eth_dev_data {
133         char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */
134
135         void **rx_queues; /**< Array of pointers to RX queues. */
136         void **tx_queues; /**< Array of pointers to TX queues. */
137         uint16_t nb_rx_queues; /**< Number of RX queues. */
138         uint16_t nb_tx_queues; /**< Number of TX queues. */
139
140         struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
141
142         void *dev_private;
143                         /**< PMD-specific private data.
144                          *   @see rte_eth_dev_release_port()
145                          */
146
147         struct rte_eth_link dev_link;   /**< Link-level information & status. */
148         struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
149         uint16_t mtu;                   /**< Maximum Transmission Unit. */
150         uint32_t min_rx_buf_size;
151                         /**< Common RX buffer size handled by all queues. */
152
153         uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
154         struct rte_ether_addr *mac_addrs;
155                         /**< Device Ethernet link address.
156                          *   @see rte_eth_dev_release_port()
157                          */
158         uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
159                         /**< Bitmap associating MAC addresses to pools. */
160         struct rte_ether_addr *hash_mac_addrs;
161                         /**< Device Ethernet MAC addresses of hash filtering.
162                          *   @see rte_eth_dev_release_port()
163                          */
164         uint16_t port_id;           /**< Device [external] port identifier. */
165
166         __extension__
167         uint8_t promiscuous   : 1, /**< RX promiscuous mode ON(1) / OFF(0). */
168                 scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
169                 all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
170                 dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
171                 lro         : 1;   /**< RX LRO is ON(1) / OFF(0) */
172         uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
173                 /**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
174         uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
175                 /**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
176         uint32_t dev_flags;             /**< Capabilities. */
177         int numa_node;                  /**< NUMA node connection. */
178         struct rte_vlan_filter_conf vlan_filter_conf;
179                         /**< VLAN filter configuration. */
180         struct rte_eth_dev_owner owner; /**< The port owner. */
181         uint16_t representor_id;
182                         /**< Switch-specific identifier.
183                          *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
184                          */
185
186         pthread_mutex_t flow_ops_mutex; /**< rte_flow ops mutex. */
187         uint64_t reserved_64s[4]; /**< Reserved for future fields */
188         void *reserved_ptrs[4];   /**< Reserved for future fields */
189 } __rte_cache_aligned;
190
191 /**
192  * @internal
193  * The pool of *rte_eth_dev* structures. The size of the pool
194  * is configured at compile-time in the <rte_ethdev.c> file.
195  */
196 extern struct rte_eth_dev rte_eth_devices[];
197
198 #endif /* _RTE_ETHDEV_CORE_H_ */