1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
9 #include <rte_atomic.h>
10 #include <rte_ether.h>
11 #include <ethdev_driver.h>
12 #include <ethdev_pci.h>
13 #include <rte_cycles.h>
15 #include <rte_bus_pci.h>
16 #include <rte_timer.h>
22 #define ENA_REGS_BAR 0
25 #define ENA_MAX_NUM_QUEUES 128
26 #define ENA_MIN_FRAME_LEN 64
27 #define ENA_NAME_MAX_LEN 20
28 #define ENA_PKT_MAX_BUFS 17
29 #define ENA_RX_BUF_MIN_SIZE 1400
30 #define ENA_DEFAULT_RING_SIZE 1024
32 #define ENA_MIN_MTU 128
34 #define ENA_MMIO_DISABLE_REG_READ BIT(0)
36 #define ENA_WD_TIMEOUT_SEC 3
37 #define ENA_DEVICE_KALIVE_TIMEOUT (ENA_WD_TIMEOUT_SEC * rte_get_timer_hz())
39 #define ENA_TX_TIMEOUT (5 * rte_get_timer_hz())
40 #define ENA_MONITORED_TX_QUEUES 3
41 #define ENA_DEFAULT_MISSING_COMP 256U
43 /* While processing submitted and completed descriptors (rx and tx path
44 * respectively) in a loop it is desired to:
45 * - perform batch submissions while populating submission queue
46 * - avoid blocking transmission of other packets during cleanup phase
47 * Hence the utilization ratio of 1/8 of a queue size or max value if the size
48 * of the ring is very big - like 8k Rx rings.
50 #define ENA_REFILL_THRESH_DIVIDER 8
51 #define ENA_REFILL_THRESH_PACKET 256
53 #define ENA_IDX_NEXT_MASKED(idx, mask) (((idx) + 1) & (mask))
54 #define ENA_IDX_ADD_MASKED(idx, n, mask) (((idx) + (n)) & (mask))
56 #define ENA_RX_RSS_TABLE_LOG_SIZE 7
57 #define ENA_RX_RSS_TABLE_SIZE (1 << ENA_RX_RSS_TABLE_LOG_SIZE)
59 #define ENA_HASH_KEY_SIZE 40
61 #define ENA_ALL_RSS_HF (RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV4_UDP | \
62 RTE_ETH_RSS_NONFRAG_IPV6_TCP | RTE_ETH_RSS_NONFRAG_IPV6_UDP)
64 #define ENA_IO_TXQ_IDX(q) (2 * (q))
65 #define ENA_IO_RXQ_IDX(q) (2 * (q) + 1)
66 /* Reversed version of ENA_IO_RXQ_IDX */
67 #define ENA_IO_RXQ_IDX_REV(q) (((q) - 1) / 2)
69 extern struct ena_shared_data *ena_shared_data;
78 struct ena_tx_buffer {
79 struct rte_mbuf *mbuf;
80 unsigned int tx_descs;
81 unsigned int num_of_bufs;
84 struct ena_com_buf bufs[ENA_PKT_MAX_BUFS];
87 /* Rx buffer holds only pointer to the mbuf - may be expanded in the future */
88 struct ena_rx_buffer {
89 struct rte_mbuf *mbuf;
90 struct ena_com_buf ena_buf;
93 struct ena_calc_queue_size_ctx {
94 struct ena_com_dev_get_features_ctx *get_feat_ctx;
95 struct ena_com_dev *ena_dev;
96 u32 max_rx_queue_size;
97 u32 max_tx_queue_size;
102 struct ena_stats_tx {
113 struct ena_stats_rx {
126 uint64_t last_cleanup_ticks;
128 enum ena_ring_type type;
129 enum ena_admin_placement_policy_type tx_mem_queue_type;
131 /* Indicate there are Tx packets pushed to the device and wait for db */
132 bool pkts_without_db;
134 /* Holds the empty requests for TX/RX OOO completions */
136 uint16_t *empty_tx_reqs;
137 uint16_t *empty_rx_reqs;
141 struct ena_tx_buffer *tx_buffer_info; /* contex of tx packet */
142 struct ena_rx_buffer *rx_buffer_info; /* contex of rx packet */
144 struct rte_mbuf **rx_refill_buffer;
145 unsigned int ring_size; /* number of tx/rx_buffer_info's entries */
146 unsigned int size_mask;
148 struct ena_com_io_cq *ena_com_io_cq;
149 struct ena_com_io_sq *ena_com_io_sq;
152 uint16_t tx_free_thresh;
153 uint16_t rx_free_thresh;
156 struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]
159 struct rte_mempool *mb_pool;
160 unsigned int port_id;
162 /* Max length PMD can push to device for LLQ */
163 uint8_t tx_max_header_size;
166 uint8_t *push_buf_intermediate_buf;
168 struct ena_adapter *adapter;
172 bool disable_meta_caching;
175 struct ena_stats_rx rx_stats;
176 struct ena_stats_tx tx_stats;
179 unsigned int numa_socket_id;
181 uint32_t missing_tx_completion_threshold;
182 } __rte_cache_aligned;
184 enum ena_adapter_state {
185 ENA_ADAPTER_STATE_FREE = 0,
186 ENA_ADAPTER_STATE_INIT = 1,
187 ENA_ADAPTER_STATE_RUNNING = 2,
188 ENA_ADAPTER_STATE_STOPPED = 3,
189 ENA_ADAPTER_STATE_CONFIG = 4,
190 ENA_ADAPTER_STATE_CLOSED = 5,
193 struct ena_driver_stats {
194 rte_atomic64_t ierrors;
195 rte_atomic64_t oerrors;
196 rte_atomic64_t rx_nombuf;
200 struct ena_stats_dev {
205 * Tx drops cannot be reported as the driver statistic, because DPDK
206 * rte_eth_stats structure isn't providing appropriate field for that.
207 * As a workaround it is being published as an extended statistic.
212 struct ena_stats_eni {
214 * The number of packets shaped due to inbound aggregate BW
215 * allowance being exceeded
217 uint64_t bw_in_allowance_exceeded;
219 * The number of packets shaped due to outbound aggregate BW
220 * allowance being exceeded
222 uint64_t bw_out_allowance_exceeded;
223 /* The number of packets shaped due to PPS allowance being exceeded */
224 uint64_t pps_allowance_exceeded;
226 * The number of packets shaped due to connection tracking
227 * allowance being exceeded and leading to failure in establishment
230 uint64_t conntrack_allowance_exceeded;
232 * The number of packets shaped due to linklocal packet rate
233 * allowance being exceeded
235 uint64_t linklocal_allowance_exceeded;
238 struct ena_offloads {
239 uint32_t tx_offloads;
240 uint32_t rx_offloads;
243 /* board specific private data structure */
245 /* OS defined structs */
246 struct rte_eth_dev_data *edev_data;
248 struct ena_com_dev ena_dev __rte_cache_aligned;
251 struct ena_ring tx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
252 u32 max_tx_ring_size;
256 struct ena_ring rx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
257 u32 max_rx_ring_size;
260 u32 max_num_io_queues;
262 struct ena_offloads offloads;
264 /* The admin queue isn't protected by the lock and is used to
265 * retrieve statistics from the device. As there is no guarantee that
266 * application won't try to get statistics from multiple threads, it is
267 * safer to lock the queue to avoid admin queue failure.
269 rte_spinlock_t admin_lock;
272 char name[ENA_NAME_MAX_LEN];
273 u8 mac_addr[RTE_ETHER_ADDR_LEN];
278 struct ena_driver_stats *drv_stats;
279 enum ena_adapter_state state;
283 enum ena_regs_reset_reason_types reset_reason;
285 struct rte_timer timer_wd;
286 uint64_t timestamp_wd;
287 uint64_t keep_alive_timeout;
289 struct ena_stats_dev dev_stats;
290 struct ena_stats_eni eni_stats;
296 bool use_large_llq_hdr;
298 uint32_t last_tx_comp_qid;
299 uint64_t missing_tx_completion_to;
300 uint64_t missing_tx_completion_budget;
301 uint64_t tx_cleanup_stall_delay;
304 int ena_rss_reta_update(struct rte_eth_dev *dev,
305 struct rte_eth_rss_reta_entry64 *reta_conf,
307 int ena_rss_reta_query(struct rte_eth_dev *dev,
308 struct rte_eth_rss_reta_entry64 *reta_conf,
310 int ena_rss_hash_update(struct rte_eth_dev *dev,
311 struct rte_eth_rss_conf *rss_conf);
312 int ena_rss_hash_conf_get(struct rte_eth_dev *dev,
313 struct rte_eth_rss_conf *rss_conf);
314 int ena_rss_configure(struct ena_adapter *adapter);
316 #endif /* _ENA_ETHDEV_H_ */