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