xref: /dpdk/lib/ethdev/rte_ethdev_core.h (revision 8d7d4fcd)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2017 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_ETHDEV_CORE_H_
699a2dd95SBruce Richardson #define _RTE_ETHDEV_CORE_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson #include <pthread.h>
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson /**
1199a2dd95SBruce Richardson  * @file
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * RTE Ethernet Device internal header.
1499a2dd95SBruce Richardson  *
1599a2dd95SBruce Richardson  * This header contains internal data types. But they are still part of the
1699a2dd95SBruce Richardson  * public API because they are used by inline functions in the published API.
1799a2dd95SBruce Richardson  *
1899a2dd95SBruce Richardson  * Applications should not use these directly.
1999a2dd95SBruce Richardson  *
2099a2dd95SBruce Richardson  */
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson struct rte_eth_dev_callback;
2399a2dd95SBruce Richardson /** @internal Structure to keep track of registered callbacks */
24f1f6ebc0SWilliam Tu RTE_TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback);
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson struct rte_eth_dev;
2799a2dd95SBruce Richardson 
2899a2dd95SBruce Richardson typedef uint16_t (*eth_rx_burst_t)(void *rxq,
2999a2dd95SBruce Richardson 				   struct rte_mbuf **rx_pkts,
3099a2dd95SBruce Richardson 				   uint16_t nb_pkts);
3199a2dd95SBruce Richardson /**< @internal Retrieve input packets from a receive queue of an Ethernet device. */
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson typedef uint16_t (*eth_tx_burst_t)(void *txq,
3499a2dd95SBruce Richardson 				   struct rte_mbuf **tx_pkts,
3599a2dd95SBruce Richardson 				   uint16_t nb_pkts);
3699a2dd95SBruce Richardson /**< @internal Send output packets on a transmit queue of an Ethernet device. */
3799a2dd95SBruce Richardson 
3899a2dd95SBruce Richardson typedef uint16_t (*eth_tx_prep_t)(void *txq,
3999a2dd95SBruce Richardson 				   struct rte_mbuf **tx_pkts,
4099a2dd95SBruce Richardson 				   uint16_t nb_pkts);
4199a2dd95SBruce Richardson /**< @internal Prepare output packets on a transmit queue of an Ethernet device. */
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson 
44*8d7d4fcdSKonstantin Ananyev typedef uint32_t (*eth_rx_queue_count_t)(void *rxq);
4599a2dd95SBruce Richardson /**< @internal Get number of used descriptors on a receive queue. */
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson typedef int (*eth_rx_descriptor_status_t)(void *rxq, uint16_t offset);
4899a2dd95SBruce Richardson /**< @internal Check the status of a Rx descriptor */
4999a2dd95SBruce Richardson 
5099a2dd95SBruce Richardson typedef int (*eth_tx_descriptor_status_t)(void *txq, uint16_t offset);
5199a2dd95SBruce Richardson /**< @internal Check the status of a Tx descriptor */
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson 
5499a2dd95SBruce Richardson /**
5599a2dd95SBruce Richardson  * @internal
5699a2dd95SBruce Richardson  * Structure used to hold information about the callbacks to be called for a
5799a2dd95SBruce Richardson  * queue on RX and TX.
5899a2dd95SBruce Richardson  */
5999a2dd95SBruce Richardson struct rte_eth_rxtx_callback {
6099a2dd95SBruce Richardson 	struct rte_eth_rxtx_callback *next;
6199a2dd95SBruce Richardson 	union{
6299a2dd95SBruce Richardson 		rte_rx_callback_fn rx;
6399a2dd95SBruce Richardson 		rte_tx_callback_fn tx;
6499a2dd95SBruce Richardson 	} fn;
6599a2dd95SBruce Richardson 	void *param;
6699a2dd95SBruce Richardson };
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson /**
6999a2dd95SBruce Richardson  * @internal
7099a2dd95SBruce Richardson  * The generic data structure associated with each ethernet device.
7199a2dd95SBruce Richardson  *
7299a2dd95SBruce Richardson  * Pointers to burst-oriented packet receive and transmit functions are
7399a2dd95SBruce Richardson  * located at the beginning of the structure, along with the pointer to
7499a2dd95SBruce Richardson  * where all the data elements for the particular device are stored in shared
7599a2dd95SBruce Richardson  * memory. This split allows the function pointer and driver data to be per-
7699a2dd95SBruce Richardson  * process, while the actual configuration data for the device is shared.
7799a2dd95SBruce Richardson  */
7899a2dd95SBruce Richardson struct rte_eth_dev {
7999a2dd95SBruce Richardson 	eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
8099a2dd95SBruce Richardson 	eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
8199a2dd95SBruce Richardson 	eth_tx_prep_t tx_pkt_prepare; /**< Pointer to PMD transmit prepare function. */
8299a2dd95SBruce Richardson 
8399a2dd95SBruce Richardson 	eth_rx_queue_count_t       rx_queue_count; /**< Get the number of used RX descriptors. */
8499a2dd95SBruce Richardson 	eth_rx_descriptor_status_t rx_descriptor_status; /**< Check the status of a Rx descriptor. */
8599a2dd95SBruce Richardson 	eth_tx_descriptor_status_t tx_descriptor_status; /**< Check the status of a Tx descriptor. */
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson 	/**
8899a2dd95SBruce Richardson 	 * Next two fields are per-device data but *data is shared between
8999a2dd95SBruce Richardson 	 * primary and secondary processes and *process_private is per-process
9099a2dd95SBruce Richardson 	 * private. The second one is managed by PMDs if necessary.
9199a2dd95SBruce Richardson 	 */
9299a2dd95SBruce Richardson 	struct rte_eth_dev_data *data;  /**< Pointer to device data. */
9399a2dd95SBruce Richardson 	void *process_private; /**< Pointer to per-process device data. */
9499a2dd95SBruce Richardson 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
9599a2dd95SBruce Richardson 	struct rte_device *device; /**< Backing device */
9699a2dd95SBruce Richardson 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
9799a2dd95SBruce Richardson 	/** User application callbacks for NIC interrupts */
9899a2dd95SBruce Richardson 	struct rte_eth_dev_cb_list link_intr_cbs;
9999a2dd95SBruce Richardson 	/**
10099a2dd95SBruce Richardson 	 * User-supplied functions called from rx_burst to post-process
10199a2dd95SBruce Richardson 	 * received packets before passing them to the user
10299a2dd95SBruce Richardson 	 */
10399a2dd95SBruce Richardson 	struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
10499a2dd95SBruce Richardson 	/**
10599a2dd95SBruce Richardson 	 * User-supplied functions called from tx_burst to pre-process
10699a2dd95SBruce Richardson 	 * received packets before passing them to the driver for transmission.
10799a2dd95SBruce Richardson 	 */
10899a2dd95SBruce Richardson 	struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
10999a2dd95SBruce Richardson 	enum rte_eth_dev_state state; /**< Flag indicating the port state */
11099a2dd95SBruce Richardson 	void *security_ctx; /**< Context for security ops */
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
11399a2dd95SBruce Richardson 	void *reserved_ptrs[4];   /**< Reserved for future fields */
11499a2dd95SBruce Richardson } __rte_cache_aligned;
11599a2dd95SBruce Richardson 
11699a2dd95SBruce Richardson struct rte_eth_dev_sriov;
11799a2dd95SBruce Richardson struct rte_eth_dev_owner;
11899a2dd95SBruce Richardson 
11999a2dd95SBruce Richardson /**
12099a2dd95SBruce Richardson  * @internal
12199a2dd95SBruce Richardson  * The data part, with no function pointers, associated with each ethernet device.
12299a2dd95SBruce Richardson  *
12399a2dd95SBruce Richardson  * This structure is safe to place in shared memory to be common among different
12499a2dd95SBruce Richardson  * processes in a multi-process configuration.
12599a2dd95SBruce Richardson  */
12699a2dd95SBruce Richardson struct rte_eth_dev_data {
12799a2dd95SBruce Richardson 	char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */
12899a2dd95SBruce Richardson 
12999a2dd95SBruce Richardson 	void **rx_queues; /**< Array of pointers to RX queues. */
13099a2dd95SBruce Richardson 	void **tx_queues; /**< Array of pointers to TX queues. */
13199a2dd95SBruce Richardson 	uint16_t nb_rx_queues; /**< Number of RX queues. */
13299a2dd95SBruce Richardson 	uint16_t nb_tx_queues; /**< Number of TX queues. */
13399a2dd95SBruce Richardson 
13499a2dd95SBruce Richardson 	struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
13599a2dd95SBruce Richardson 
13699a2dd95SBruce Richardson 	void *dev_private;
13799a2dd95SBruce Richardson 			/**< PMD-specific private data.
13899a2dd95SBruce Richardson 			 *   @see rte_eth_dev_release_port()
13999a2dd95SBruce Richardson 			 */
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson 	struct rte_eth_link dev_link;   /**< Link-level information & status. */
14299a2dd95SBruce Richardson 	struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
14399a2dd95SBruce Richardson 	uint16_t mtu;                   /**< Maximum Transmission Unit. */
14499a2dd95SBruce Richardson 	uint32_t min_rx_buf_size;
14599a2dd95SBruce Richardson 			/**< Common RX buffer size handled by all queues. */
14699a2dd95SBruce Richardson 
14799a2dd95SBruce Richardson 	uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
14899a2dd95SBruce Richardson 	struct rte_ether_addr *mac_addrs;
14999a2dd95SBruce Richardson 			/**< Device Ethernet link address.
15099a2dd95SBruce Richardson 			 *   @see rte_eth_dev_release_port()
15199a2dd95SBruce Richardson 			 */
15299a2dd95SBruce Richardson 	uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
15399a2dd95SBruce Richardson 			/**< Bitmap associating MAC addresses to pools. */
15499a2dd95SBruce Richardson 	struct rte_ether_addr *hash_mac_addrs;
15599a2dd95SBruce Richardson 			/**< Device Ethernet MAC addresses of hash filtering.
15699a2dd95SBruce Richardson 			 *   @see rte_eth_dev_release_port()
15799a2dd95SBruce Richardson 			 */
15899a2dd95SBruce Richardson 	uint16_t port_id;           /**< Device [external] port identifier. */
15999a2dd95SBruce Richardson 
16099a2dd95SBruce Richardson 	__extension__
16199a2dd95SBruce Richardson 	uint8_t promiscuous   : 1, /**< RX promiscuous mode ON(1) / OFF(0). */
16299a2dd95SBruce Richardson 		scattered_rx : 1,  /**< RX of scattered packets is ON(1) / OFF(0) */
16399a2dd95SBruce Richardson 		all_multicast : 1, /**< RX all multicast mode ON(1) / OFF(0). */
16499a2dd95SBruce Richardson 		dev_started : 1,   /**< Device state: STARTED(1) / STOPPED(0). */
16502edbfabSHuisong Li 		lro         : 1,   /**< RX LRO is ON(1) / OFF(0) */
16602edbfabSHuisong Li 		dev_configured : 1;
16702edbfabSHuisong Li 		/**< Indicates whether the device is configured.
16802edbfabSHuisong Li 		 *   CONFIGURED(1) / NOT CONFIGURED(0).
16902edbfabSHuisong Li 		 */
17099a2dd95SBruce Richardson 	uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
17199a2dd95SBruce Richardson 		/**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
17299a2dd95SBruce Richardson 	uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
17399a2dd95SBruce Richardson 		/**< Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0). */
17499a2dd95SBruce Richardson 	uint32_t dev_flags;             /**< Capabilities. */
17599a2dd95SBruce Richardson 	int numa_node;                  /**< NUMA node connection. */
17699a2dd95SBruce Richardson 	struct rte_vlan_filter_conf vlan_filter_conf;
17799a2dd95SBruce Richardson 			/**< VLAN filter configuration. */
17899a2dd95SBruce Richardson 	struct rte_eth_dev_owner owner; /**< The port owner. */
17999a2dd95SBruce Richardson 	uint16_t representor_id;
18099a2dd95SBruce Richardson 			/**< Switch-specific identifier.
18199a2dd95SBruce Richardson 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
18299a2dd95SBruce Richardson 			 */
183ff4e52efSViacheslav Galaktionov 	uint16_t backer_port_id;
184ff4e52efSViacheslav Galaktionov 			/**< Port ID of the backing device.
185ff4e52efSViacheslav Galaktionov 			 *   This device will be used to query representor
186ff4e52efSViacheslav Galaktionov 			 *   info and calculate representor IDs.
187ff4e52efSViacheslav Galaktionov 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
188ff4e52efSViacheslav Galaktionov 			 */
18999a2dd95SBruce Richardson 
19099a2dd95SBruce Richardson 	pthread_mutex_t flow_ops_mutex; /**< rte_flow ops mutex. */
19199a2dd95SBruce Richardson 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
19299a2dd95SBruce Richardson 	void *reserved_ptrs[4];   /**< Reserved for future fields */
19399a2dd95SBruce Richardson } __rte_cache_aligned;
19499a2dd95SBruce Richardson 
19599a2dd95SBruce Richardson /**
19699a2dd95SBruce Richardson  * @internal
19799a2dd95SBruce Richardson  * The pool of *rte_eth_dev* structures. The size of the pool
19899a2dd95SBruce Richardson  * is configured at compile-time in the <rte_ethdev.c> file.
19999a2dd95SBruce Richardson  */
20099a2dd95SBruce Richardson extern struct rte_eth_dev rte_eth_devices[];
20199a2dd95SBruce Richardson 
20299a2dd95SBruce Richardson #endif /* _RTE_ETHDEV_CORE_H_ */
203