1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2015-2020 Amazon.com, Inc. or its affiliates.
9 #include <rte_cycles.h>
11 #include <rte_bus_pci.h>
12 #include <rte_timer.h>
16 #define ENA_REGS_BAR 0
19 #define ENA_MAX_NUM_QUEUES 128
20 #define ENA_MIN_FRAME_LEN 64
21 #define ENA_NAME_MAX_LEN 20
22 #define ENA_PKT_MAX_BUFS 17
23 #define ENA_RX_BUF_MIN_SIZE 1400
24 #define ENA_DEFAULT_RING_SIZE 1024
26 #define ENA_MIN_MTU 128
28 #define ENA_MMIO_DISABLE_REG_READ BIT(0)
30 #define ENA_WD_TIMEOUT_SEC 3
31 #define ENA_DEVICE_KALIVE_TIMEOUT (ENA_WD_TIMEOUT_SEC * rte_get_timer_hz())
33 /* While processing submitted and completed descriptors (rx and tx path
34 * respectively) in a loop it is desired to:
35 * - perform batch submissions while populating sumbissmion queue
36 * - avoid blocking transmission of other packets during cleanup phase
37 * Hence the utilization ratio of 1/8 of a queue size or max value if the size
38 * of the ring is very big - like 8k Rx rings.
40 #define ENA_REFILL_THRESH_DIVIDER 8
41 #define ENA_REFILL_THRESH_PACKET 256
50 struct ena_tx_buffer {
51 struct rte_mbuf *mbuf;
52 unsigned int tx_descs;
53 unsigned int num_of_bufs;
54 struct ena_com_buf bufs[ENA_PKT_MAX_BUFS];
57 /* Rx buffer holds only pointer to the mbuf - may be expanded in the future */
58 struct ena_rx_buffer {
59 struct rte_mbuf *mbuf;
60 struct ena_com_buf ena_buf;
63 struct ena_calc_queue_size_ctx {
64 struct ena_com_dev_get_features_ctx *get_feat_ctx;
65 struct ena_com_dev *ena_dev;
66 u32 max_rx_queue_size;
67 u32 max_tx_queue_size;
98 enum ena_ring_type type;
99 enum ena_admin_placement_policy_type tx_mem_queue_type;
100 /* Holds the empty requests for TX/RX OOO completions */
102 uint16_t *empty_tx_reqs;
103 uint16_t *empty_rx_reqs;
107 struct ena_tx_buffer *tx_buffer_info; /* contex of tx packet */
108 struct ena_rx_buffer *rx_buffer_info; /* contex of rx packet */
110 struct rte_mbuf **rx_refill_buffer;
111 unsigned int ring_size; /* number of tx/rx_buffer_info's entries */
113 struct ena_com_io_cq *ena_com_io_cq;
114 struct ena_com_io_sq *ena_com_io_sq;
116 struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]
119 struct rte_mempool *mb_pool;
120 unsigned int port_id;
122 /* Max length PMD can push to device for LLQ */
123 uint8_t tx_max_header_size;
126 uint8_t *push_buf_intermediate_buf;
128 struct ena_adapter *adapter;
132 bool disable_meta_caching;
135 struct ena_stats_rx rx_stats;
136 struct ena_stats_tx tx_stats;
139 unsigned int numa_socket_id;
140 } __rte_cache_aligned;
142 enum ena_adapter_state {
143 ENA_ADAPTER_STATE_FREE = 0,
144 ENA_ADAPTER_STATE_INIT = 1,
145 ENA_ADAPTER_STATE_RUNNING = 2,
146 ENA_ADAPTER_STATE_STOPPED = 3,
147 ENA_ADAPTER_STATE_CONFIG = 4,
148 ENA_ADAPTER_STATE_CLOSED = 5,
151 struct ena_driver_stats {
152 rte_atomic64_t ierrors;
153 rte_atomic64_t oerrors;
154 rte_atomic64_t rx_nombuf;
158 struct ena_stats_dev {
163 * Tx drops cannot be reported as the driver statistic, because DPDK
164 * rte_eth_stats structure isn't providing appropriate field for that.
165 * As a workaround it is being published as an extended statistic.
170 struct ena_offloads {
172 bool tx_csum_supported;
173 bool rx_csum_supported;
176 /* board specific private data structure */
178 /* OS defined structs */
179 struct rte_pci_device *pdev;
180 struct rte_eth_dev_data *rte_eth_dev_data;
181 struct rte_eth_dev *rte_dev;
183 struct ena_com_dev ena_dev __rte_cache_aligned;
186 struct ena_ring tx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
187 u32 max_tx_ring_size;
191 struct ena_ring rx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
192 u32 max_rx_ring_size;
195 u32 max_num_io_queues;
197 struct ena_offloads offloads;
200 char name[ENA_NAME_MAX_LEN];
201 u8 mac_addr[RTE_ETHER_ADDR_LEN];
206 struct ena_driver_stats *drv_stats;
207 enum ena_adapter_state state;
209 uint64_t tx_supported_offloads;
210 uint64_t tx_selected_offloads;
211 uint64_t rx_supported_offloads;
212 uint64_t rx_selected_offloads;
216 enum ena_regs_reset_reason_types reset_reason;
218 struct rte_timer timer_wd;
219 uint64_t timestamp_wd;
220 uint64_t keep_alive_timeout;
222 struct ena_stats_dev dev_stats;
228 bool use_large_llq_hdr;
231 #endif /* _ENA_ETHDEV_H_ */