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