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>
28 #include <rte_bus_vmbus.h>
29 #endif /* __linux__ */
30 #include <rte_ethdev.h>
31 #include <rte_version.h>
33 #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0)
38 #include <bus_driver.h>
39 #include <bus_pci_driver.h>
41 #include <bus_vmbus_driver.h>
42 #endif /* __linux__ */
45 #include <vnet/devices/devices.h>
48 #define always_inline static inline
50 #define always_inline static inline __attribute__ ((__always_inline__))
53 #include <vlib/pci/pci.h>
54 #include <vlib/vmbus/vmbus.h>
55 #include <vnet/flow/flow.h>
57 extern vnet_device_class_t dpdk_device_class;
58 extern vlib_node_registration_t dpdk_input_node;
59 extern vlib_node_registration_t admin_up_down_process_node;
61 typedef uint16_t dpdk_portid_t;
63 #define foreach_dpdk_device_flags \
64 _ (0, ADMIN_UP, "admin-up") \
65 _ (1, PROMISC, "promisc") \
66 _ (3, PMD_INIT_FAIL, "pmd-init-fail") \
67 _ (4, MAYBE_MULTISEG, "maybe-multiseg") \
68 _ (5, HAVE_SUBIF, "subif") \
69 _ (9, TX_OFFLOAD, "tx-offload") \
70 _ (10, INTEL_PHDR_CKSUM, "intel-phdr-cksum") \
71 _ (11, RX_FLOW_OFFLOAD, "rx-flow-offload") \
72 _ (12, RX_IP4_CKSUM, "rx-ip4-cksum") \
73 _ (13, INT_SUPPORTED, "int-supported") \
74 _ (14, INT_UNMASKABLE, "int-unmaskable")
78 #define _(a, b, c) DPDK_DEVICE_FLAG_##b = (1 << a),
79 foreach_dpdk_device_flags
87 struct rte_flow *handle;
95 } dpdk_flow_lookup_entry_t;
99 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
100 u8 buffer_pool_index;
103 uword clib_file_index;
108 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
109 clib_spinlock_t lock;
117 } dpdk_driver_name_t;
121 dpdk_driver_name_t *drivers;
122 const char *interface_name_prefix;
125 u32 supported_flow_actions;
126 u32 enable_lsc_int : 1;
127 u32 enable_rxq_int : 1;
128 u32 disable_rx_scatter : 1;
129 u32 program_vlans : 1;
130 u32 mq_mode_none : 1;
131 u32 interface_number_from_port_id : 1;
132 u32 use_intel_phdr_cksum : 1;
133 u32 int_unmaskable : 1;
136 dpdk_driver_t *dpdk_driver_find (const char *name, const char **desc);
142 u16 disable_multi_seg : 1;
145 u16 enable_tcp_udp_checksum : 1;
146 u16 enable_outer_checksum_offload : 1;
147 u16 enable_lsc_int : 1;
148 u16 enable_rxq_int : 1;
149 u16 disable_tx_checksum_offload : 1;
151 u16 disable_rx_scatter : 1;
156 u32 max_lro_pkt_size;
162 STATIC_ASSERT_SIZEOF (dpdk_port_conf_t, 24);
166 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
168 dpdk_rx_queue_t *rx_queues;
169 dpdk_tx_queue_t *tx_queues;
171 /* Instance ID to access internal device array. */
178 /* next node index if we decide to steal the rx graph arc */
179 u32 per_interface_next_index;
183 /* DPDK device port number */
184 dpdk_portid_t port_id;
187 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
191 dpdk_driver_t *driver;
195 /* number of sub-interfaces */
199 u32 supported_flow_actions;
200 dpdk_flow_entry_t *flow_entries; /* pool */
201 dpdk_flow_lookup_entry_t *flow_lookup_entries; /* pool */
202 u32 *parked_lookup_indexes; /* vector */
203 u32 parked_loop_count;
204 struct rte_flow_error last_flow_error;
206 struct rte_eth_link link;
207 f64 time_last_link_update;
209 struct rte_eth_stats stats;
210 struct rte_eth_stats last_stats;
211 struct rte_eth_xstat *xstats;
212 f64 time_last_stats_update;
215 u8 *default_mac_address;
217 /* maximum supported max frame size */
218 u32 max_supported_frame_size;
220 /* due to lack of API to get ethernet max_frame_size we store information
221 * deducted from device info */
222 u8 driver_frame_overhead;
225 clib_error_t *errors;
226 dpdk_port_conf_t conf;
229 #define DPDK_MIN_POLL_INTERVAL (0.001) /* 1msec */
231 #define DPDK_STATS_POLL_INTERVAL (10.0)
232 #define DPDK_MIN_STATS_POLL_INTERVAL DPDK_MIN_POLL_INTERVAL
234 #define DPDK_LINK_POLL_INTERVAL (3.0)
235 #define DPDK_MIN_LINK_POLL_INTERVAL DPDK_MIN_POLL_INTERVAL
237 #define foreach_dpdk_device_config_item \
242 _ (max_lro_pkt_size) \
250 } dpdk_device_addr_type_t;
256 vlib_pci_addr_t pci_addr;
257 vlib_vmbus_addr_t vmbus_addr;
259 dpdk_device_addr_type_t dev_addr_type;
264 #define _(x) uword x;
265 foreach_dpdk_device_config_item
267 clib_bitmap_t * workers;
270 clib_bitmap_t *rss_queues;
272 #define DPDK_DEVICE_TSO_DEFAULT 0
273 #define DPDK_DEVICE_TSO_OFF 1
274 #define DPDK_DEVICE_TSO_ON 2
275 } dpdk_device_config_t;
282 u8 *eal_init_args_str;
286 u16 max_simd_bitwidth;
288 #define DPDK_MAX_SIMD_BITWIDTH_DEFAULT 0
289 #define DPDK_MAX_SIMD_BITWIDTH_256 256
290 #define DPDK_MAX_SIMD_BITWIDTH_512 512
293 * format interface names ala xxxEthernet%d/%d/%d instead of
294 * xxxEthernet%x/%x/%x.
296 u8 interface_name_format_decimal;
298 /* per-device config */
299 dpdk_device_config_t default_devconf;
300 dpdk_device_config_t *dev_confs;
301 uword *device_config_index_by_pci_addr;
302 mhash_t device_config_index_by_vmbus_addr;
304 /* devices blacklist by pci vendor_id, device_id */
305 u32 *blacklist_by_pci_vendor_and_device;
306 /* devices blacklist by VMBUS address */
307 vlib_vmbus_addr_t *blacklist_by_vmbus_addr;
309 } dpdk_config_main_t;
311 extern dpdk_config_main_t dpdk_config_main;
313 #define DPDK_RX_BURST_SZ VLIB_FRAME_SIZE
317 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
318 struct rte_mbuf *mbufs[DPDK_RX_BURST_SZ];
319 u32 buffers[DPDK_RX_BURST_SZ];
320 u16 next[DPDK_RX_BURST_SZ];
321 u16 etype[DPDK_RX_BURST_SZ];
322 u32 flags[DPDK_RX_BURST_SZ];
323 vlib_buffer_t buffer_template;
324 } dpdk_per_thread_data_t;
329 dpdk_device_t *devices;
330 dpdk_per_thread_data_t *per_thread_data;
333 * flag indicating that a posted admin up/down
334 * (via post_sw_interface_set_flags) is in progress
336 u8 admin_up_down_in_progress;
338 /* control interval of dpdk link state and stat polling */
339 f64 link_state_poll_interval;
340 f64 stat_poll_interval;
342 dpdk_config_main_t *conf;
343 dpdk_port_conf_t default_port_conf;
345 /* API message ID base */
349 vlib_log_class_t log_default;
350 vlib_log_class_t log_cryptodev;
353 extern dpdk_main_t dpdk_main;
361 u8 data[256]; /* First 256 data bytes, used for hexdump */
362 /* Copy of VLIB buffer; packet data stored in pre_data. */
363 vlib_buffer_t buffer;
372 u8 data[256]; /* First 256 data bytes, used for hexdump */
373 vlib_buffer_t buffer; /* Copy of VLIB buffer; pkt data stored in pre_data. */
376 void dpdk_device_setup (dpdk_device_t * xd);
377 void dpdk_device_start (dpdk_device_t * xd);
378 void dpdk_device_stop (dpdk_device_t * xd);
379 int dpdk_port_state_callback (dpdk_portid_t port_id,
380 enum rte_eth_event_type type,
381 void *param, void *ret_param);
383 #define foreach_dpdk_error \
384 _(NONE, "no error") \
385 _(RX_PACKET_ERROR, "Rx packet errors") \
386 _(RX_BAD_FCS, "Rx bad fcs") \
387 _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \
388 _(RX_ALLOC_FAIL, "rx buf alloc from free list failed") \
389 _(RX_ALLOC_NO_PHYSMEM, "rx buf alloc failed no physmem") \
390 _(RX_ALLOC_DROP_PKTS, "rx packets dropped due to alloc error")
394 #define _(f,s) DPDK_ERROR_##f,
400 #define dpdk_log_err(...) \
401 vlib_log(VLIB_LOG_LEVEL_ERR, dpdk_main.log_default, __VA_ARGS__)
402 #define dpdk_log_warn(...) \
403 vlib_log(VLIB_LOG_LEVEL_WARNING, dpdk_main.log_default, __VA_ARGS__)
404 #define dpdk_log_notice(...) \
405 vlib_log(VLIB_LOG_LEVEL_NOTICE, dpdk_main.log_default, __VA_ARGS__)
406 #define dpdk_log_info(...) \
407 vlib_log(VLIB_LOG_LEVEL_INFO, dpdk_main.log_default, __VA_ARGS__)
408 #define dpdk_log_debug(...) \
409 vlib_log (VLIB_LOG_LEVEL_DEBUG, dpdk_main.log_default, __VA_ARGS__)
411 void dpdk_update_link_state (dpdk_device_t * xd, f64 now);
413 #define foreach_dpdk_rss_hf \
414 _ (0, RTE_ETH_RSS_FRAG_IPV4, "ipv4-frag") \
415 _ (1, RTE_ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
416 _ (2, RTE_ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
417 _ (3, RTE_ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
418 _ (4, RTE_ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
419 _ (5, RTE_ETH_RSS_IPV4, "ipv4") \
420 _ (6, RTE_ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
421 _ (7, RTE_ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex") \
422 _ (8, RTE_ETH_RSS_FRAG_IPV6, "ipv6-frag") \
423 _ (9, RTE_ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
424 _ (10, RTE_ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
425 _ (11, RTE_ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
426 _ (12, RTE_ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
427 _ (13, RTE_ETH_RSS_IPV6_EX, "ipv6-ex") \
428 _ (14, RTE_ETH_RSS_IPV6, "ipv6") \
429 _ (15, RTE_ETH_RSS_L2_PAYLOAD, "l2-payload") \
430 _ (16, RTE_ETH_RSS_PORT, "port") \
431 _ (17, RTE_ETH_RSS_VXLAN, "vxlan") \
432 _ (18, RTE_ETH_RSS_GENEVE, "geneve") \
433 _ (19, RTE_ETH_RSS_NVGRE, "nvgre") \
434 _ (20, RTE_ETH_RSS_GTPU, "gtpu") \
435 _ (21, RTE_ETH_RSS_ESP, "esp") \
436 _ (22, RTE_ETH_RSS_L2TPV3, "l2tpv3") \
437 _ (60, RTE_ETH_RSS_L4_DST_ONLY, "l4-dst-only") \
438 _ (61, RTE_ETH_RSS_L4_SRC_ONLY, "l4-src-only") \
439 _ (62, RTE_ETH_RSS_L3_DST_ONLY, "l3-dst-only") \
440 _ (63, RTE_ETH_RSS_L3_SRC_ONLY, "l3-src-only")
442 format_function_t format_dpdk_device_name;
443 format_function_t format_dpdk_device;
444 format_function_t format_dpdk_device_errors;
445 format_function_t format_dpdk_tx_trace;
446 format_function_t format_dpdk_rx_trace;
447 format_function_t format_dpdk_rte_mbuf;
448 format_function_t format_dpdk_rx_rte_mbuf;
449 format_function_t format_dpdk_flow;
450 format_function_t format_dpdk_rss_hf_name;
451 format_function_t format_dpdk_rx_offload_caps;
452 format_function_t format_dpdk_tx_offload_caps;
453 format_function_t format_dpdk_burst_fn;
454 format_function_t format_dpdk_rte_device;
455 vnet_flow_dev_ops_function_t dpdk_flow_ops_fn;
457 clib_error_t *unformat_rss_fn (unformat_input_t * input, uword * rss_fn);
459 struct rte_pci_device *dpdk_get_pci_device (const struct rte_eth_dev_info
461 struct rte_vmbus_device *
462 dpdk_get_vmbus_device (const struct rte_eth_dev_info *info);
463 void dpdk_cli_reference (void);
466 int dpdk_buffer_validate_trajectory_all (u32 * uninitialized);
467 void dpdk_buffer_poison_trajectory_all (void);
470 #endif /* __included_dpdk_h__ */
473 * fd.io coding-style-patch-verification: ON
476 * eval: (c-set-style "gnu")