2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef __included_dpdk_h__
16 #define __included_dpdk_h__
18 /* $$$$ We should rename always_inline -> clib_always_inline */
21 #define ALLOW_EXPERIMENTAL_API
23 #include <rte_config.h>
26 #include <rte_bus_pci.h>
27 #include <rte_bus_vmbus.h>
28 #include <rte_ethdev.h>
29 #include <rte_version.h>
32 #include <vnet/devices/devices.h>
35 #define always_inline static inline
37 #define always_inline static inline __attribute__ ((__always_inline__))
40 #include <vlib/pci/pci.h>
41 #include <vlib/vmbus/vmbus.h>
42 #include <vnet/flow/flow.h>
44 extern vnet_device_class_t dpdk_device_class;
45 extern vlib_node_registration_t dpdk_input_node;
46 extern vlib_node_registration_t admin_up_down_process_node;
48 typedef uint16_t dpdk_portid_t;
50 #define foreach_dpdk_device_flags \
51 _ (0, ADMIN_UP, "admin-up") \
52 _ (1, PROMISC, "promisc") \
53 _ (3, PMD_INIT_FAIL, "pmd-init-fail") \
54 _ (4, MAYBE_MULTISEG, "maybe-multiseg") \
55 _ (5, HAVE_SUBIF, "subif") \
56 _ (9, TX_OFFLOAD, "tx-offload") \
57 _ (10, INTEL_PHDR_CKSUM, "intel-phdr-cksum") \
58 _ (11, RX_FLOW_OFFLOAD, "rx-flow-offload") \
59 _ (12, RX_IP4_CKSUM, "rx-ip4-cksum") \
60 _ (13, INT_SUPPORTED, "int-supported") \
61 _ (14, INT_UNMASKABLE, "int-unmaskable")
65 #define _(a, b, c) DPDK_DEVICE_FLAG_##b = (1 << a),
66 foreach_dpdk_device_flags
74 struct rte_flow *handle;
82 } dpdk_flow_lookup_entry_t;
86 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
90 uword clib_file_index;
95 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
104 } dpdk_driver_name_t;
108 dpdk_driver_name_t *drivers;
109 const char *interface_name_prefix;
112 u32 supported_flow_actions;
113 i32 enable_lsc_int : 1;
114 i32 enable_rxq_int : 1;
115 i32 disable_rx_scatter : 1;
116 i32 program_vlans : 1;
117 i32 mq_mode_none : 1;
118 i32 interface_number_from_port_id : 1;
119 i32 use_intel_phdr_cksum : 1;
120 i32 int_unmaskable : 1;
123 dpdk_driver_t *dpdk_driver_find (const char *name, const char **desc);
129 u16 disable_multi_seg : 1;
132 u16 enable_tcp_udp_checksum : 1;
133 u16 enable_outer_checksum_offload : 1;
134 u16 enable_lsc_int : 1;
135 u16 enable_rxq_int : 1;
136 u16 disable_tx_checksum_offload : 1;
138 u16 disable_rx_scatter : 1;
143 u32 max_lro_pkt_size;
149 STATIC_ASSERT_SIZEOF (dpdk_port_conf_t, 24);
153 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
155 dpdk_rx_queue_t *rx_queues;
156 dpdk_tx_queue_t *tx_queues;
158 /* Instance ID to access internal device array. */
165 /* next node index if we decide to steal the rx graph arc */
166 u32 per_interface_next_index;
170 /* DPDK device port number */
171 dpdk_portid_t port_id;
174 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
178 dpdk_driver_t *driver;
182 /* number of sub-interfaces */
186 u32 supported_flow_actions;
187 dpdk_flow_entry_t *flow_entries; /* pool */
188 dpdk_flow_lookup_entry_t *flow_lookup_entries; /* pool */
189 u32 *parked_lookup_indexes; /* vector */
190 u32 parked_loop_count;
191 struct rte_flow_error last_flow_error;
193 struct rte_eth_link link;
194 f64 time_last_link_update;
196 struct rte_eth_stats stats;
197 struct rte_eth_stats last_stats;
198 struct rte_eth_xstat *xstats;
199 f64 time_last_stats_update;
202 u8 *default_mac_address;
204 /* maximum supported max frame size */
205 u32 max_supported_frame_size;
207 /* due to lack of API to get ethernet max_frame_size we store information
208 * deducted from device info */
209 u8 driver_frame_overhead;
212 clib_error_t *errors;
213 dpdk_port_conf_t conf;
216 #define DPDK_STATS_POLL_INTERVAL (10.0)
217 #define DPDK_MIN_STATS_POLL_INTERVAL (0.001) /* 1msec */
219 #define DPDK_LINK_POLL_INTERVAL (3.0)
220 #define DPDK_MIN_LINK_POLL_INTERVAL (0.001) /* 1msec */
222 #define foreach_dpdk_device_config_item \
227 _ (max_lro_pkt_size) \
235 } dpdk_device_addr_type_t;
241 vlib_pci_addr_t pci_addr;
242 vlib_vmbus_addr_t vmbus_addr;
244 dpdk_device_addr_type_t dev_addr_type;
248 #define _(x) uword x;
249 foreach_dpdk_device_config_item
251 clib_bitmap_t * workers;
254 clib_bitmap_t *rss_queues;
256 #define DPDK_DEVICE_TSO_DEFAULT 0
257 #define DPDK_DEVICE_TSO_OFF 1
258 #define DPDK_DEVICE_TSO_ON 2
259 } dpdk_device_config_t;
266 u8 *eal_init_args_str;
269 u16 max_simd_bitwidth;
271 #define DPDK_MAX_SIMD_BITWIDTH_DEFAULT 0
272 #define DPDK_MAX_SIMD_BITWIDTH_256 256
273 #define DPDK_MAX_SIMD_BITWIDTH_512 512
276 * format interface names ala xxxEthernet%d/%d/%d instead of
277 * xxxEthernet%x/%x/%x.
279 u8 interface_name_format_decimal;
281 /* per-device config */
282 dpdk_device_config_t default_devconf;
283 dpdk_device_config_t *dev_confs;
284 uword *device_config_index_by_pci_addr;
285 mhash_t device_config_index_by_vmbus_addr;
287 /* devices blacklist by pci vendor_id, device_id */
288 u32 *blacklist_by_pci_vendor_and_device;
289 /* devices blacklist by VMBUS address */
290 vlib_vmbus_addr_t *blacklist_by_vmbus_addr;
292 } dpdk_config_main_t;
294 extern dpdk_config_main_t dpdk_config_main;
296 #define DPDK_RX_BURST_SZ VLIB_FRAME_SIZE
300 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
301 struct rte_mbuf *mbufs[DPDK_RX_BURST_SZ];
302 u32 buffers[DPDK_RX_BURST_SZ];
303 u16 next[DPDK_RX_BURST_SZ];
304 u16 etype[DPDK_RX_BURST_SZ];
305 u32 flags[DPDK_RX_BURST_SZ];
306 vlib_buffer_t buffer_template;
307 } dpdk_per_thread_data_t;
312 dpdk_device_t *devices;
313 dpdk_per_thread_data_t *per_thread_data;
316 * flag indicating that a posted admin up/down
317 * (via post_sw_interface_set_flags) is in progress
319 u8 admin_up_down_in_progress;
321 /* control interval of dpdk link state and stat polling */
322 f64 link_state_poll_interval;
323 f64 stat_poll_interval;
325 dpdk_config_main_t *conf;
326 dpdk_port_conf_t default_port_conf;
328 /* API message ID base */
332 vlib_log_class_t log_default;
333 vlib_log_class_t log_cryptodev;
336 extern dpdk_main_t dpdk_main;
344 u8 data[256]; /* First 256 data bytes, used for hexdump */
345 /* Copy of VLIB buffer; packet data stored in pre_data. */
346 vlib_buffer_t buffer;
355 u8 data[256]; /* First 256 data bytes, used for hexdump */
356 vlib_buffer_t buffer; /* Copy of VLIB buffer; pkt data stored in pre_data. */
359 void dpdk_device_setup (dpdk_device_t * xd);
360 void dpdk_device_start (dpdk_device_t * xd);
361 void dpdk_device_stop (dpdk_device_t * xd);
362 int dpdk_port_state_callback (dpdk_portid_t port_id,
363 enum rte_eth_event_type type,
364 void *param, void *ret_param);
366 #define foreach_dpdk_error \
367 _(NONE, "no error") \
368 _(RX_PACKET_ERROR, "Rx packet errors") \
369 _(RX_BAD_FCS, "Rx bad fcs") \
370 _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \
371 _(RX_ALLOC_FAIL, "rx buf alloc from free list failed") \
372 _(RX_ALLOC_NO_PHYSMEM, "rx buf alloc failed no physmem") \
373 _(RX_ALLOC_DROP_PKTS, "rx packets dropped due to alloc error")
377 #define _(f,s) DPDK_ERROR_##f,
383 #define dpdk_log_err(...) \
384 vlib_log(VLIB_LOG_LEVEL_ERR, dpdk_main.log_default, __VA_ARGS__)
385 #define dpdk_log_warn(...) \
386 vlib_log(VLIB_LOG_LEVEL_WARNING, dpdk_main.log_default, __VA_ARGS__)
387 #define dpdk_log_notice(...) \
388 vlib_log(VLIB_LOG_LEVEL_NOTICE, dpdk_main.log_default, __VA_ARGS__)
389 #define dpdk_log_info(...) \
390 vlib_log(VLIB_LOG_LEVEL_INFO, dpdk_main.log_default, __VA_ARGS__)
391 #define dpdk_log_debug(...) \
392 vlib_log (VLIB_LOG_LEVEL_DEBUG, dpdk_main.log_default, __VA_ARGS__)
394 void dpdk_update_link_state (dpdk_device_t * xd, f64 now);
396 #define foreach_dpdk_rss_hf \
397 _ (0, RTE_ETH_RSS_FRAG_IPV4, "ipv4-frag") \
398 _ (1, RTE_ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
399 _ (2, RTE_ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
400 _ (3, RTE_ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
401 _ (4, RTE_ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
402 _ (5, RTE_ETH_RSS_IPV4, "ipv4") \
403 _ (6, RTE_ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
404 _ (7, RTE_ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex") \
405 _ (8, RTE_ETH_RSS_FRAG_IPV6, "ipv6-frag") \
406 _ (9, RTE_ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
407 _ (10, RTE_ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
408 _ (11, RTE_ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
409 _ (12, RTE_ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
410 _ (13, RTE_ETH_RSS_IPV6_EX, "ipv6-ex") \
411 _ (14, RTE_ETH_RSS_IPV6, "ipv6") \
412 _ (15, RTE_ETH_RSS_L2_PAYLOAD, "l2-payload") \
413 _ (16, RTE_ETH_RSS_PORT, "port") \
414 _ (17, RTE_ETH_RSS_VXLAN, "vxlan") \
415 _ (18, RTE_ETH_RSS_GENEVE, "geneve") \
416 _ (19, RTE_ETH_RSS_NVGRE, "nvgre") \
417 _ (20, RTE_ETH_RSS_GTPU, "gtpu") \
418 _ (21, RTE_ETH_RSS_ESP, "esp") \
419 _ (60, RTE_ETH_RSS_L4_DST_ONLY, "l4-dst-only") \
420 _ (61, RTE_ETH_RSS_L4_SRC_ONLY, "l4-src-only") \
421 _ (62, RTE_ETH_RSS_L3_DST_ONLY, "l3-dst-only") \
422 _ (63, RTE_ETH_RSS_L3_SRC_ONLY, "l3-src-only")
424 format_function_t format_dpdk_device_name;
425 format_function_t format_dpdk_device;
426 format_function_t format_dpdk_device_errors;
427 format_function_t format_dpdk_tx_trace;
428 format_function_t format_dpdk_rx_trace;
429 format_function_t format_dpdk_rte_mbuf;
430 format_function_t format_dpdk_rx_rte_mbuf;
431 format_function_t format_dpdk_flow;
432 format_function_t format_dpdk_rss_hf_name;
433 format_function_t format_dpdk_rx_offload_caps;
434 format_function_t format_dpdk_tx_offload_caps;
435 format_function_t format_dpdk_burst_fn;
436 format_function_t format_dpdk_rte_device;
437 vnet_flow_dev_ops_function_t dpdk_flow_ops_fn;
439 clib_error_t *unformat_rss_fn (unformat_input_t * input, uword * rss_fn);
441 struct rte_pci_device *dpdk_get_pci_device (const struct rte_eth_dev_info
443 struct rte_vmbus_device *
444 dpdk_get_vmbus_device (const struct rte_eth_dev_info *info);
445 void dpdk_cli_reference (void);
448 int dpdk_buffer_validate_trajectory_all (u32 * uninitialized);
449 void dpdk_buffer_poison_trajectory_all (void);
452 #endif /* __included_dpdk_h__ */
455 * fd.io coding-style-patch-verification: ON
458 * eval: (c-set-style "gnu")