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