1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright (c) 2023 Cisco Systems, Inc.
8 #include <vppinfra/clib.h>
9 #include <vppinfra/error_bootstrap.h>
10 #include <vppinfra/format.h>
11 #include <vnet/vnet.h>
12 #include <vnet/dev/types.h>
13 #include <dev_ena/ena_defs.h>
15 #define ENA_ADMIN_QUEUE_LOG2_DEPTH 2
16 #define ENA_ASYNC_QUEUE_LOG2_DEPTH 5
17 #define ENA_ADMIN_QUEUE_DEPTH (1 << ENA_ADMIN_QUEUE_LOG2_DEPTH)
18 #define ENA_ASYNC_QUEUE_DEPTH (1 << ENA_ASYNC_QUEUE_LOG2_DEPTH)
30 ena_mmio_resp_t *mmio_resp;
35 ena_aq_sq_entry_t *sq_entries;
36 ena_aq_cq_entry_t *cq_entries;
43 ena_aq_host_info_t *host_info;
46 ena_aq_feat_device_attr_t dev_attr;
48 /* async event notification */
51 ena_aenq_entry_t *entries;
55 u64 tx_drops, tx_drops0;
56 u64 rx_drops, rx_drops0;
68 u16 *compl_sqe_indices;
85 ena_tx_llq_desc128_t *llq_descs;
104 ena_rx_cdesc_status_t status;
118 } ena_aq_feat_info_t;
120 ena_aq_feat_info_t *ena_aq_get_feat_info (ena_aq_feature_id_t);
121 vnet_dev_rv_t ena_aq_olloc (vlib_main_t *, vnet_dev_t *, u16);
122 vnet_dev_rv_t ena_aq_start (vlib_main_t *, vnet_dev_t *);
123 void ena_aq_stop (vlib_main_t *, vnet_dev_t *);
124 void ena_aq_free (vlib_main_t *, vnet_dev_t *);
125 vnet_dev_rv_t ena_aq_create_sq (vlib_main_t *, vnet_dev_t *,
126 ena_aq_create_sq_cmd_t *,
127 ena_aq_create_sq_resp_t *);
128 vnet_dev_rv_t ena_aq_create_cq (vlib_main_t *, vnet_dev_t *,
129 ena_aq_create_cq_cmd_t *,
130 ena_aq_create_cq_resp_t *);
131 vnet_dev_rv_t ena_aq_destroy_sq (vlib_main_t *, vnet_dev_t *,
132 ena_aq_destroy_sq_cmd_t *);
133 vnet_dev_rv_t ena_aq_destroy_cq (vlib_main_t *, vnet_dev_t *,
134 ena_aq_destroy_cq_cmd_t *);
135 vnet_dev_rv_t ena_aq_set_feature (vlib_main_t *, vnet_dev_t *,
136 ena_aq_feature_id_t, void *);
137 vnet_dev_rv_t ena_aq_get_feature (vlib_main_t *, vnet_dev_t *,
138 ena_aq_feature_id_t, void *);
139 vnet_dev_rv_t ena_aq_get_stats (vlib_main_t *, vnet_dev_t *,
140 ena_aq_stats_type_t, ena_aq_stats_scope_t, u16,
144 vnet_dev_rv_t ena_aenq_olloc (vlib_main_t *, vnet_dev_t *, u16);
145 vnet_dev_rv_t ena_aenq_start (vlib_main_t *, vnet_dev_t *);
146 void ena_aenq_stop (vlib_main_t *, vnet_dev_t *);
147 void ena_aenq_free (vlib_main_t *, vnet_dev_t *);
150 void ena_reg_write (vnet_dev_t *, ena_reg_t, void *);
151 void ena_reg_read (vnet_dev_t *, ena_reg_t, const void *);
152 void ena_reg_set_dma_addr (vlib_main_t *, vnet_dev_t *, u32, u32, void *);
153 vnet_dev_rv_t ena_reg_reset (vlib_main_t *, vnet_dev_t *, ena_reset_reason_t);
156 vnet_dev_rv_t ena_port_init (vlib_main_t *, vnet_dev_port_t *);
157 vnet_dev_rv_t ena_port_start (vlib_main_t *, vnet_dev_port_t *);
158 void ena_port_stop (vlib_main_t *, vnet_dev_port_t *);
159 vnet_dev_rv_t ena_port_cfg_change (vlib_main_t *, vnet_dev_port_t *,
160 vnet_dev_port_cfg_change_req_t *);
161 vnet_dev_rv_t ena_port_cfg_change_validate (vlib_main_t *, vnet_dev_port_t *,
162 vnet_dev_port_cfg_change_req_t *);
165 vnet_dev_rv_t ena_rx_queue_alloc (vlib_main_t *, vnet_dev_rx_queue_t *);
166 vnet_dev_rv_t ena_tx_queue_alloc (vlib_main_t *, vnet_dev_tx_queue_t *);
167 void ena_rx_queue_free (vlib_main_t *, vnet_dev_rx_queue_t *);
168 void ena_tx_queue_free (vlib_main_t *, vnet_dev_tx_queue_t *);
169 vnet_dev_rv_t ena_rx_queue_start (vlib_main_t *, vnet_dev_rx_queue_t *);
170 vnet_dev_rv_t ena_tx_queue_start (vlib_main_t *, vnet_dev_tx_queue_t *);
171 void ena_rx_queue_stop (vlib_main_t *, vnet_dev_rx_queue_t *);
172 void ena_tx_queue_stop (vlib_main_t *, vnet_dev_tx_queue_t *);
175 format_function_t format_ena_dev_info;
176 format_function_t format_ena_mem_addr;
177 format_function_t format_ena_tx_desc;
178 format_function_t format_ena_rx_trace;
181 format_function_t format_ena_aq_feat_desc;
182 format_function_t format_ena_aq_feat_name;
183 format_function_t format_ena_aq_opcode;
184 format_function_t format_ena_aq_status;
185 format_function_t format_ena_aq_feat_id_bitmap;
186 format_function_t format_ena_aq_create_sq_cmd;
187 format_function_t format_ena_aq_create_cq_cmd;
188 format_function_t format_ena_aq_create_sq_resp;
189 format_function_t format_ena_aq_create_cq_resp;
190 format_function_t format_ena_aq_destroy_sq_cmd;
191 format_function_t format_ena_aq_destroy_cq_cmd;
192 format_function_t format_ena_aq_basic_stats;
193 format_function_t format_ena_aq_eni_stats;
195 #define foreach_ena_rx_node_counter \
196 _ (BUFFER_ALLOC, buffer_alloc, ERROR, "buffer alloc error")
200 #define _(f, lf, t, s) ENA_RX_NODE_CTR_##f,
201 foreach_ena_rx_node_counter
206 #define foreach_ena_tx_node_counter \
207 _ (CHAIN_TOO_LONG, chain_too_long, ERROR, "buffer chain too long") \
208 _ (NO_FREE_SLOTS, no_free_slots, ERROR, "no free tx slots")
212 #define _(f, lf, t, s) ENA_TX_NODE_CTR_##f,
213 foreach_ena_tx_node_counter
218 #define log_debug(dev, f, ...) \
219 vlib_log (VLIB_LOG_LEVEL_DEBUG, ena_log.class, "%U" f, format_vnet_dev_log, \
220 (dev), clib_string_skip_prefix (__func__, "ena_"), ##__VA_ARGS__)
221 #define log_info(dev, f, ...) \
222 vlib_log (VLIB_LOG_LEVEL_INFO, ena_log.class, "%U: " f, \
223 format_vnet_dev_addr, (dev), ##__VA_ARGS__)
224 #define log_notice(dev, f, ...) \
225 vlib_log (VLIB_LOG_LEVEL_NOTICE, ena_log.class, "%U: " f, \
226 format_vnet_dev_addr, (dev), ##__VA_ARGS__)
227 #define log_warn(dev, f, ...) \
228 vlib_log (VLIB_LOG_LEVEL_WARNING, ena_log.class, "%U: " f, \
229 format_vnet_dev_addr, (dev), ##__VA_ARGS__)
230 #define log_err(dev, f, ...) \
231 vlib_log (VLIB_LOG_LEVEL_ERR, ena_log.class, "%U: " f, \
232 format_vnet_dev_addr, (dev), ##__VA_ARGS__)