xref: /dpdk/drivers/net/ena/ena_ethdev.h (revision 089e5ed727a15da2729cfee9b63533dd120bd04c)
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 #ifndef _ENA_ETHDEV_H_
35 #define _ENA_ETHDEV_H_
36 
37 #include <rte_cycles.h>
38 #include <rte_pci.h>
39 #include <rte_bus_pci.h>
40 #include <rte_timer.h>
41 
42 #include "ena_com.h"
43 
44 #define ENA_REGS_BAR	0
45 #define ENA_MEM_BAR	2
46 
47 #define ENA_MAX_NUM_QUEUES	128
48 #define ENA_MIN_FRAME_LEN	64
49 #define ENA_NAME_MAX_LEN	20
50 #define ENA_PKT_MAX_BUFS	17
51 
52 #define ENA_MIN_MTU		128
53 
54 #define ENA_MMIO_DISABLE_REG_READ	BIT(0)
55 
56 #define ENA_WD_TIMEOUT_SEC	3
57 #define ENA_DEVICE_KALIVE_TIMEOUT (ENA_WD_TIMEOUT_SEC * rte_get_timer_hz())
58 
59 struct ena_adapter;
60 
61 enum ena_ring_type {
62 	ENA_RING_TYPE_RX = 1,
63 	ENA_RING_TYPE_TX = 2,
64 };
65 
66 struct ena_tx_buffer {
67 	struct rte_mbuf *mbuf;
68 	unsigned int tx_descs;
69 	unsigned int num_of_bufs;
70 	struct ena_com_buf bufs[ENA_PKT_MAX_BUFS];
71 };
72 
73 struct ena_calc_queue_size_ctx {
74 	struct ena_com_dev_get_features_ctx *get_feat_ctx;
75 	struct ena_com_dev *ena_dev;
76 	u16 rx_queue_size;
77 	u16 tx_queue_size;
78 	u16 max_tx_sgl_size;
79 	u16 max_rx_sgl_size;
80 };
81 
82 struct ena_stats_tx {
83 	u64 cnt;
84 	u64 bytes;
85 	u64 prepare_ctx_err;
86 	u64 linearize;
87 	u64 linearize_failed;
88 	u64 tx_poll;
89 	u64 doorbells;
90 	u64 bad_req_id;
91 	u64 available_desc;
92 };
93 
94 struct ena_stats_rx {
95 	u64 cnt;
96 	u64 bytes;
97 	u64 refill_partial;
98 	u64 bad_csum;
99 	u64 mbuf_alloc_fail;
100 	u64 bad_desc_num;
101 	u64 bad_req_id;
102 };
103 
104 struct ena_ring {
105 	u16 next_to_use;
106 	u16 next_to_clean;
107 
108 	enum ena_ring_type type;
109 	enum ena_admin_placement_policy_type tx_mem_queue_type;
110 	/* Holds the empty requests for TX/RX OOO completions */
111 	union {
112 		uint16_t *empty_tx_reqs;
113 		uint16_t *empty_rx_reqs;
114 	};
115 
116 	union {
117 		struct ena_tx_buffer *tx_buffer_info; /* contex of tx packet */
118 		struct rte_mbuf **rx_buffer_info; /* contex of rx packet */
119 	};
120 	struct rte_mbuf **rx_refill_buffer;
121 	unsigned int ring_size; /* number of tx/rx_buffer_info's entries */
122 
123 	struct ena_com_io_cq *ena_com_io_cq;
124 	struct ena_com_io_sq *ena_com_io_sq;
125 
126 	struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]
127 						__rte_cache_aligned;
128 
129 	struct rte_mempool *mb_pool;
130 	unsigned int port_id;
131 	unsigned int id;
132 	/* Max length PMD can push to device for LLQ */
133 	uint8_t tx_max_header_size;
134 	int configured;
135 
136 	uint8_t *push_buf_intermediate_buf;
137 
138 	struct ena_adapter *adapter;
139 	uint64_t offloads;
140 	u16 sgl_size;
141 
142 	union {
143 		struct ena_stats_rx rx_stats;
144 		struct ena_stats_tx tx_stats;
145 	};
146 
147 	unsigned int numa_socket_id;
148 } __rte_cache_aligned;
149 
150 enum ena_adapter_state {
151 	ENA_ADAPTER_STATE_FREE    = 0,
152 	ENA_ADAPTER_STATE_INIT    = 1,
153 	ENA_ADAPTER_STATE_RUNNING = 2,
154 	ENA_ADAPTER_STATE_STOPPED = 3,
155 	ENA_ADAPTER_STATE_CONFIG  = 4,
156 	ENA_ADAPTER_STATE_CLOSED  = 5,
157 };
158 
159 struct ena_driver_stats {
160 	rte_atomic64_t ierrors;
161 	rte_atomic64_t oerrors;
162 	rte_atomic64_t rx_nombuf;
163 	rte_atomic64_t rx_drops;
164 };
165 
166 struct ena_stats_dev {
167 	u64 wd_expired;
168 	u64 dev_start;
169 	u64 dev_stop;
170 };
171 
172 struct ena_offloads {
173 	bool tso4_supported;
174 	bool tx_csum_supported;
175 	bool rx_csum_supported;
176 };
177 
178 /* board specific private data structure */
179 struct ena_adapter {
180 	/* OS defined structs */
181 	struct rte_pci_device *pdev;
182 	struct rte_eth_dev_data *rte_eth_dev_data;
183 	struct rte_eth_dev *rte_dev;
184 
185 	struct ena_com_dev ena_dev __rte_cache_aligned;
186 
187 	/* TX */
188 	struct ena_ring tx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
189 	int tx_ring_size;
190 	u16 max_tx_sgl_size;
191 
192 	/* RX */
193 	struct ena_ring rx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
194 	int rx_ring_size;
195 	u16 max_rx_sgl_size;
196 
197 	u16 num_queues;
198 	u16 max_mtu;
199 	struct ena_offloads offloads;
200 
201 	int id_number;
202 	char name[ENA_NAME_MAX_LEN];
203 	u8 mac_addr[RTE_ETHER_ADDR_LEN];
204 
205 	void *regs;
206 	void *dev_mem_base;
207 
208 	struct ena_driver_stats *drv_stats;
209 	enum ena_adapter_state state;
210 
211 	uint64_t tx_supported_offloads;
212 	uint64_t tx_selected_offloads;
213 	uint64_t rx_supported_offloads;
214 	uint64_t rx_selected_offloads;
215 
216 	bool link_status;
217 
218 	enum ena_regs_reset_reason_types reset_reason;
219 
220 	struct rte_timer timer_wd;
221 	uint64_t timestamp_wd;
222 	uint64_t keep_alive_timeout;
223 
224 	struct ena_stats_dev dev_stats;
225 
226 	bool trigger_reset;
227 
228 	bool wd_state;
229 };
230 
231 #endif /* _ENA_ETHDEV_H_ */
232