Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | #ifndef __included_dpdk_h__ |
| 16 | #define __included_dpdk_h__ |
| 17 | |
| 18 | /* $$$$ We should rename always_inline -> clib_always_inline */ |
| 19 | #undef always_inline |
| 20 | |
| 21 | #include <rte_config.h> |
| 22 | |
| 23 | #include <rte_common.h> |
| 24 | #include <rte_dev.h> |
| 25 | #include <rte_log.h> |
| 26 | #include <rte_memory.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | #include <rte_memzone.h> |
| 28 | #include <rte_tailq.h> |
| 29 | #include <rte_eal.h> |
| 30 | #include <rte_per_lcore.h> |
| 31 | #include <rte_launch.h> |
| 32 | #include <rte_atomic.h> |
| 33 | #include <rte_cycles.h> |
| 34 | #include <rte_prefetch.h> |
| 35 | #include <rte_lcore.h> |
| 36 | #include <rte_per_lcore.h> |
| 37 | #include <rte_branch_prediction.h> |
| 38 | #include <rte_interrupts.h> |
| 39 | #include <rte_pci.h> |
| 40 | #include <rte_random.h> |
| 41 | #include <rte_debug.h> |
| 42 | #include <rte_ether.h> |
| 43 | #include <rte_ethdev.h> |
| 44 | #include <rte_ring.h> |
| 45 | #include <rte_mempool.h> |
| 46 | #include <rte_mbuf.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | #include <rte_virtio_net.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | #include <rte_version.h> |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 49 | #include <rte_eth_bond.h> |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 50 | #include <rte_sched.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | |
| 52 | #include <vnet/unix/pcap.h> |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 53 | #include <vnet/devices/devices.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | |
| 55 | #if CLIB_DEBUG > 0 |
| 56 | #define always_inline static inline |
| 57 | #else |
| 58 | #define always_inline static inline __attribute__ ((__always_inline__)) |
| 59 | #endif |
| 60 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 61 | #include <vlib/pci/pci.h> |
| 62 | |
Damjan Marion | a06dfb3 | 2016-06-26 20:16:57 +0200 | [diff] [blame] | 63 | #define NB_MBUF (16<<10) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 65 | extern vnet_device_class_t dpdk_device_class; |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 66 | extern vlib_node_registration_t dpdk_input_node; |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 67 | extern vlib_node_registration_t handoff_dispatch_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 69 | #if RTE_VERSION >= RTE_VERSION_NUM(16, 11, 0, 0) |
| 70 | #define foreach_dpdk_pmd \ |
| 71 | _ ("net_thunderx", THUNDERX) \ |
| 72 | _ ("net_e1000_em", E1000EM) \ |
| 73 | _ ("net_e1000_igb", IGB) \ |
| 74 | _ ("net_e1000_igb_vf", IGBVF) \ |
| 75 | _ ("net_ixgbe", IXGBE) \ |
| 76 | _ ("net_ixgbe_vf", IXGBEVF) \ |
| 77 | _ ("net_i40e", I40E) \ |
| 78 | _ ("net_i40e_vf", I40EVF) \ |
| 79 | _ ("net_virtio", VIRTIO) \ |
| 80 | _ ("net_enic", ENIC) \ |
| 81 | _ ("net_vmxnet3", VMXNET3) \ |
Billy McFall | 35b2607 | 2017-01-05 13:23:39 -0500 | [diff] [blame] | 82 | _ ("AF_PACKET PMD", AF_PACKET) \ |
Alexander Popovsky | 9dfd338 | 2016-12-04 15:26:58 -0800 | [diff] [blame] | 83 | _ ("rte_bond_pmd", BOND) \ |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 84 | _ ("net_fm10k", FM10K) \ |
| 85 | _ ("net_cxgbe", CXGBE) \ |
Damjan Marion | 696f1ad | 2016-12-23 22:42:41 +0100 | [diff] [blame] | 86 | _ ("net_mlx5", MLX5) \ |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 87 | _ ("net_dpaa2", DPAA2) |
| 88 | #else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | #define foreach_dpdk_pmd \ |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 90 | _ ("rte_nicvf_pmd", THUNDERX) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | _ ("rte_em_pmd", E1000EM) \ |
| 92 | _ ("rte_igb_pmd", IGB) \ |
| 93 | _ ("rte_igbvf_pmd", IGBVF) \ |
| 94 | _ ("rte_ixgbe_pmd", IXGBE) \ |
| 95 | _ ("rte_ixgbevf_pmd", IXGBEVF) \ |
| 96 | _ ("rte_i40e_pmd", I40E) \ |
| 97 | _ ("rte_i40evf_pmd", I40EVF) \ |
| 98 | _ ("rte_virtio_pmd", VIRTIO) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | _ ("rte_enic_pmd", ENIC) \ |
| 100 | _ ("rte_vmxnet3_pmd", VMXNET3) \ |
| 101 | _ ("AF_PACKET PMD", AF_PACKET) \ |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 102 | _ ("rte_bond_pmd", BOND) \ |
Damjan Marion | 2068e98 | 2016-01-27 16:59:04 +0100 | [diff] [blame] | 103 | _ ("rte_pmd_fm10k", FM10K) \ |
Sachin | a29f200 | 2016-06-17 09:24:20 +0530 | [diff] [blame] | 104 | _ ("rte_cxgbe_pmd", CXGBE) \ |
| 105 | _ ("rte_dpaa2_dpni", DPAA2) |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 106 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 108 | typedef enum |
| 109 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | VNET_DPDK_PMD_NONE, |
| 111 | #define _(s,f) VNET_DPDK_PMD_##f, |
| 112 | foreach_dpdk_pmd |
| 113 | #undef _ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 114 | VNET_DPDK_PMD_UNKNOWN, /* must be last */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | } dpdk_pmd_t; |
| 116 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 117 | typedef enum |
| 118 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | VNET_DPDK_PORT_TYPE_ETH_1G, |
| 120 | VNET_DPDK_PORT_TYPE_ETH_10G, |
| 121 | VNET_DPDK_PORT_TYPE_ETH_40G, |
Damjan Marion | 696f1ad | 2016-12-23 22:42:41 +0100 | [diff] [blame] | 122 | VNET_DPDK_PORT_TYPE_ETH_100G, |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 123 | VNET_DPDK_PORT_TYPE_ETH_BOND, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | VNET_DPDK_PORT_TYPE_ETH_SWITCH, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 125 | VNET_DPDK_PORT_TYPE_AF_PACKET, |
| 126 | VNET_DPDK_PORT_TYPE_UNKNOWN, |
| 127 | } dpdk_port_type_t; |
| 128 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | /* |
| 130 | * The header for the tx_vector in dpdk_device_t. |
| 131 | * Head and tail are indexes into the tx_vector and are of type |
| 132 | * u64 so they never overflow. |
| 133 | */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 134 | typedef struct |
| 135 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | u64 tx_head; |
| 137 | u64 tx_tail; |
| 138 | } tx_ring_hdr_t; |
| 139 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 140 | typedef struct |
| 141 | { |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 142 | struct rte_ring *swq; |
| 143 | |
| 144 | u64 hqos_field0_slabmask; |
| 145 | u32 hqos_field0_slabpos; |
| 146 | u32 hqos_field0_slabshr; |
| 147 | u64 hqos_field1_slabmask; |
| 148 | u32 hqos_field1_slabpos; |
| 149 | u32 hqos_field1_slabshr; |
| 150 | u64 hqos_field2_slabmask; |
| 151 | u32 hqos_field2_slabpos; |
| 152 | u32 hqos_field2_slabshr; |
| 153 | u32 hqos_tc_table[64]; |
| 154 | } dpdk_device_hqos_per_worker_thread_t; |
| 155 | |
| 156 | typedef struct |
| 157 | { |
| 158 | struct rte_ring **swq; |
| 159 | struct rte_mbuf **pkts_enq; |
| 160 | struct rte_mbuf **pkts_deq; |
| 161 | struct rte_sched_port *hqos; |
| 162 | u32 hqos_burst_enq; |
| 163 | u32 hqos_burst_deq; |
| 164 | u32 pkts_enq_len; |
| 165 | u32 swq_pos; |
David Hotham | 63f70d2 | 2016-11-01 10:51:24 +0000 | [diff] [blame] | 166 | u32 flush_count; |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 167 | } dpdk_device_hqos_per_hqos_thread_t; |
| 168 | |
| 169 | typedef struct |
| 170 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 171 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 172 | volatile u32 **lockp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | |
| 174 | /* Instance ID */ |
| 175 | u32 device_index; |
| 176 | |
| 177 | u32 vlib_hw_if_index; |
| 178 | u32 vlib_sw_if_index; |
| 179 | |
| 180 | /* next node index if we decide to steal the rx graph arc */ |
| 181 | u32 per_interface_next_index; |
| 182 | |
| 183 | /* dpdk rte_mbuf rx and tx vectors, VLIB_FRAME_SIZE */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 184 | struct rte_mbuf ***tx_vectors; /* one per worker thread */ |
| 185 | struct rte_mbuf ***rx_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
| 187 | /* vector of traced contexts, per device */ |
Damjan Marion | 4015b19 | 2016-11-18 11:41:37 +0100 | [diff] [blame] | 188 | u32 **d_trace_buffers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 189 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | dpdk_pmd_t pmd:8; |
| 191 | i8 cpu_socket; |
| 192 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 193 | u16 flags; |
John Lo | a60d4cb | 2016-12-17 03:09:58 -0500 | [diff] [blame] | 194 | #define DPDK_DEVICE_FLAG_ADMIN_UP (1 << 0) |
| 195 | #define DPDK_DEVICE_FLAG_PROMISC (1 << 1) |
| 196 | #define DPDK_DEVICE_FLAG_PMD (1 << 2) |
| 197 | #define DPDK_DEVICE_FLAG_PMD_SUPPORTS_PTYPE (1 << 3) |
| 198 | #define DPDK_DEVICE_FLAG_MAYBE_MULTISEG (1 << 4) |
| 199 | #define DPDK_DEVICE_FLAG_HAVE_SUBIF (1 << 5) |
| 200 | #define DPDK_DEVICE_FLAG_HQOS (1 << 6) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | |
Damjan Marion | b58598b | 2016-09-19 13:44:37 +0200 | [diff] [blame] | 202 | u16 nb_tx_desc; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 203 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 205 | u8 *interface_name_suffix; |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 206 | |
Damjan Marion | a7cc447 | 2016-09-19 13:31:49 +0200 | [diff] [blame] | 207 | /* number of sub-interfaces */ |
| 208 | u16 num_subifs; |
| 209 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | /* PMD related */ |
| 211 | u16 tx_q_used; |
| 212 | u16 rx_q_used; |
| 213 | u16 nb_rx_desc; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 214 | u16 *cpu_socket_id_by_queue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | struct rte_eth_conf port_conf; |
| 216 | struct rte_eth_txconf tx_conf; |
| 217 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 218 | /* HQoS related */ |
| 219 | dpdk_device_hqos_per_worker_thread_t *hqos_wt; |
| 220 | dpdk_device_hqos_per_hqos_thread_t *hqos_ht; |
| 221 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 222 | /* af_packet */ |
| 223 | u8 af_packet_port_id; |
| 224 | |
| 225 | struct rte_eth_link link; |
| 226 | f64 time_last_link_update; |
| 227 | |
| 228 | struct rte_eth_stats stats; |
| 229 | struct rte_eth_stats last_stats; |
Sean Hope | a4f16a0 | 2016-03-28 13:11:31 -0400 | [diff] [blame] | 230 | struct rte_eth_stats last_cleared_stats; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 231 | struct rte_eth_xstat *xstats; |
| 232 | struct rte_eth_xstat *last_cleared_xstats; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | f64 time_last_stats_update; |
| 234 | dpdk_port_type_t port_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | } dpdk_device_t; |
| 236 | |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 237 | #define DPDK_STATS_POLL_INTERVAL (10.0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 238 | #define DPDK_MIN_STATS_POLL_INTERVAL (0.001) /* 1msec */ |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 239 | |
| 240 | #define DPDK_LINK_POLL_INTERVAL (3.0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 241 | #define DPDK_MIN_LINK_POLL_INTERVAL (0.001) /* 1msec */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 243 | typedef struct |
| 244 | { |
| 245 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 246 | |
| 247 | /* total input packet counter */ |
| 248 | u64 aggregate_rx_packets; |
| 249 | } dpdk_worker_t; |
| 250 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 251 | typedef struct |
| 252 | { |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 253 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 254 | |
| 255 | /* total input packet counter */ |
| 256 | u64 aggregate_rx_packets; |
| 257 | } dpdk_hqos_thread_t; |
| 258 | |
| 259 | typedef struct |
| 260 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | u32 device; |
| 262 | u16 queue_id; |
| 263 | } dpdk_device_and_queue_t; |
| 264 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 265 | #ifndef DPDK_HQOS_DBG_BYPASS |
| 266 | #define DPDK_HQOS_DBG_BYPASS 0 |
| 267 | #endif |
| 268 | |
David Hotham | 63f70d2 | 2016-11-01 10:51:24 +0000 | [diff] [blame] | 269 | #ifndef HQOS_FLUSH_COUNT_THRESHOLD |
| 270 | #define HQOS_FLUSH_COUNT_THRESHOLD 100000 |
| 271 | #endif |
| 272 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 273 | typedef struct dpdk_device_config_hqos_t |
| 274 | { |
| 275 | u32 hqos_thread; |
| 276 | u32 hqos_thread_valid; |
| 277 | |
| 278 | u32 swq_size; |
| 279 | u32 burst_enq; |
| 280 | u32 burst_deq; |
| 281 | |
| 282 | u32 pktfield0_slabpos; |
| 283 | u32 pktfield1_slabpos; |
| 284 | u32 pktfield2_slabpos; |
| 285 | u64 pktfield0_slabmask; |
| 286 | u64 pktfield1_slabmask; |
| 287 | u64 pktfield2_slabmask; |
| 288 | u32 tc_table[64]; |
| 289 | |
| 290 | struct rte_sched_port_params port; |
| 291 | struct rte_sched_subport_params *subport; |
| 292 | struct rte_sched_pipe_params *pipe; |
| 293 | uint32_t *pipe_map; |
| 294 | } dpdk_device_config_hqos_t; |
| 295 | |
| 296 | int dpdk_hqos_validate_mask (u64 mask, u32 n); |
| 297 | void dpdk_device_config_hqos_pipe_profile_default (dpdk_device_config_hqos_t * |
| 298 | hqos, u32 pipe_profile_id); |
| 299 | void dpdk_device_config_hqos_default (dpdk_device_config_hqos_t * hqos); |
| 300 | clib_error_t *dpdk_port_setup_hqos (dpdk_device_t * xd, |
| 301 | dpdk_device_config_hqos_t * hqos); |
| 302 | void dpdk_hqos_metadata_set (dpdk_device_hqos_per_worker_thread_t * hqos, |
| 303 | struct rte_mbuf **pkts, u32 n_pkts); |
| 304 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 305 | #define foreach_dpdk_device_config_item \ |
| 306 | _ (num_rx_queues) \ |
Damjan Marion | 39da621 | 2016-06-06 13:21:04 +0200 | [diff] [blame] | 307 | _ (num_tx_queues) \ |
| 308 | _ (num_rx_desc) \ |
Srivatsa Sangli | 820e363 | 2016-06-14 13:10:55 -0700 | [diff] [blame] | 309 | _ (num_tx_desc) \ |
| 310 | _ (rss_fn) |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 311 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 312 | typedef struct |
| 313 | { |
| 314 | vlib_pci_addr_t pci_addr; |
| 315 | u8 is_blacklisted; |
| 316 | u8 vlan_strip_offload; |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 317 | #define DPDK_DEVICE_VLAN_STRIP_DEFAULT 0 |
| 318 | #define DPDK_DEVICE_VLAN_STRIP_OFF 1 |
| 319 | #define DPDK_DEVICE_VLAN_STRIP_ON 2 |
| 320 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 321 | #define _(x) uword x; |
| 322 | foreach_dpdk_device_config_item |
| 323 | #undef _ |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 324 | clib_bitmap_t * workers; |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 325 | u32 hqos_enabled; |
| 326 | dpdk_device_config_hqos_t hqos; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 327 | } dpdk_device_config_t; |
| 328 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 329 | typedef struct |
| 330 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 331 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 332 | /* Config stuff */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 333 | u8 **eal_init_args; |
| 334 | u8 *eal_init_args_str; |
| 335 | u8 *uio_driver_name; |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 336 | u8 no_multi_seg; |
| 337 | u8 enable_tcp_udp_checksum; |
| 338 | |
| 339 | /* Required config parameters */ |
| 340 | u8 coremask_set_manually; |
| 341 | u8 nchannels_set_manually; |
| 342 | u32 coremask; |
| 343 | u32 nchannels; |
| 344 | u32 num_mbufs; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 345 | u8 num_kni; /* while kni_init allows u32, port_id in callback fn is only u8 */ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 346 | |
| 347 | /* |
| 348 | * format interface names ala xxxEthernet%d/%d/%d instead of |
Damjan Marion | 137c7c6 | 2016-07-06 22:52:49 +0200 | [diff] [blame] | 349 | * xxxEthernet%x/%x/%x. |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 350 | */ |
| 351 | u8 interface_name_format_decimal; |
| 352 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 353 | /* per-device config */ |
| 354 | dpdk_device_config_t default_devconf; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 355 | dpdk_device_config_t *dev_confs; |
| 356 | uword *device_config_index_by_pci_addr; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 357 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 358 | } dpdk_config_main_t; |
| 359 | |
| 360 | dpdk_config_main_t dpdk_config_main; |
| 361 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 362 | typedef struct |
| 363 | { |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 364 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 365 | /* Devices */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 366 | dpdk_device_t *devices; |
| 367 | dpdk_device_and_queue_t **devices_by_cpu; |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 368 | dpdk_device_and_queue_t **devices_by_hqos_cpu; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
| 370 | /* per-thread recycle lists */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 371 | u32 **recycle; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 372 | |
Dave Barach | d81566f | 2016-02-15 11:34:13 -0500 | [diff] [blame] | 373 | /* buffer flags template, configurable to enable/disable tcp / udp cksum */ |
| 374 | u32 buffer_flags_template; |
| 375 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | /* vlib buffer free list, must be same size as an rte_mbuf */ |
| 377 | u32 vlib_buffer_free_list_index; |
| 378 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 379 | /* dpdk worker "threads" */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 380 | dpdk_worker_t *workers; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 382 | /* dpdk HQoS "threads" */ |
| 383 | dpdk_hqos_thread_t *hqos_threads; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | |
| 385 | /* Ethernet input node index */ |
| 386 | u32 ethernet_input_node_index; |
| 387 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | /* pcap tracing [only works if (CLIB_DEBUG > 0)] */ |
| 389 | int tx_pcap_enable; |
| 390 | pcap_main_t pcap_main; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 391 | u8 *pcap_filename; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 392 | u32 pcap_sw_if_index; |
| 393 | u32 pcap_pkts_to_capture; |
| 394 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | /* hashes */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 396 | uword *dpdk_device_by_kni_port_id; |
| 397 | uword *vu_sw_if_index_by_listener_fd; |
| 398 | uword *vu_sw_if_index_by_sock_fd; |
| 399 | u32 *vu_inactive_interfaces_device_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | /* |
| 402 | * flag indicating that a posted admin up/down |
| 403 | * (via post_sw_interface_set_flags) is in progress |
| 404 | */ |
| 405 | u8 admin_up_down_in_progress; |
| 406 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 407 | u8 use_rss; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 408 | |
| 409 | /* which cpus are running dpdk-input */ |
| 410 | int input_cpu_first_index; |
| 411 | int input_cpu_count; |
| 412 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 413 | /* which cpus are running I/O TX */ |
| 414 | int hqos_cpu_first_index; |
| 415 | int hqos_cpu_count; |
| 416 | |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 417 | /* control interval of dpdk link state and stat polling */ |
| 418 | f64 link_state_poll_interval; |
| 419 | f64 stat_poll_interval; |
| 420 | |
Dave Barach | 08602d1 | 2016-06-04 14:10:59 -0400 | [diff] [blame] | 421 | /* Sleep for this many MS after each device poll */ |
| 422 | u32 poll_sleep; |
| 423 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 424 | /* convenience */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 425 | vlib_main_t *vlib_main; |
| 426 | vnet_main_t *vnet_main; |
| 427 | dpdk_config_main_t *conf; |
Damjan Marion | 878c609 | 2017-01-04 13:19:27 +0100 | [diff] [blame] | 428 | |
| 429 | /* mempool */ |
| 430 | struct rte_mempool **pktmbuf_pools; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | } dpdk_main_t; |
| 432 | |
| 433 | dpdk_main_t dpdk_main; |
| 434 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 435 | typedef struct |
| 436 | { |
Damjan Marion | 7f62097 | 2016-02-25 16:00:11 +0100 | [diff] [blame] | 437 | u32 buffer_index; |
| 438 | u16 device_index; |
| 439 | u8 queue_index; |
| 440 | struct rte_mbuf mb; |
| 441 | /* Copy of VLIB buffer; packet data stored in pre_data. */ |
| 442 | vlib_buffer_t buffer; |
| 443 | } dpdk_tx_dma_trace_t; |
| 444 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 445 | typedef struct |
| 446 | { |
Damjan Marion | 7f62097 | 2016-02-25 16:00:11 +0100 | [diff] [blame] | 447 | u32 buffer_index; |
| 448 | u16 device_index; |
| 449 | u16 queue_index; |
| 450 | struct rte_mbuf mb; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 451 | vlib_buffer_t buffer; /* Copy of VLIB buffer; pkt data stored in pre_data. */ |
| 452 | u8 data[256]; /* First 256 data bytes, used for hexdump */ |
Damjan Marion | 7f62097 | 2016-02-25 16:00:11 +0100 | [diff] [blame] | 453 | } dpdk_rx_dma_trace_t; |
| 454 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 455 | void vnet_buffer_needs_dpdk_mb (vlib_buffer_t * b); |
| 456 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 457 | clib_error_t *dpdk_set_mac_address (vnet_hw_interface_t * hi, char *address); |
Christian Dechamplain | 2073cfe | 2016-02-19 12:26:57 -0500 | [diff] [blame] | 458 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 459 | clib_error_t *dpdk_set_mc_filter (vnet_hw_interface_t * hi, |
| 460 | struct ether_addr mc_addr_vec[], int naddr); |
Christian Dechamplain | 2073cfe | 2016-02-19 12:26:57 -0500 | [diff] [blame] | 461 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 462 | void dpdk_thread_input (dpdk_main_t * dm, dpdk_device_t * xd); |
| 463 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 464 | clib_error_t *dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 465 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | u32 dpdk_interface_tx_vector (vlib_main_t * vm, u32 dev_instance); |
| 467 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 468 | struct rte_mbuf *dpdk_replicate_packet_mb (vlib_buffer_t * b); |
| 469 | struct rte_mbuf *dpdk_zerocopy_replicate_packet_mb (vlib_buffer_t * b); |
Keith Burns (alagalah) | 52fc44d | 2016-03-25 09:38:50 -0700 | [diff] [blame] | 470 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 471 | #define foreach_dpdk_error \ |
| 472 | _(NONE, "no error") \ |
| 473 | _(RX_PACKET_ERROR, "Rx packet errors") \ |
| 474 | _(RX_BAD_FCS, "Rx bad fcs") \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \ |
| 476 | _(RX_ALLOC_FAIL, "rx buf alloc from free list failed") \ |
| 477 | _(RX_ALLOC_NO_PHYSMEM, "rx buf alloc failed no physmem") \ |
Damjan Marion | 4ee3a65 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 478 | _(RX_ALLOC_DROP_PKTS, "rx packets dropped due to alloc error") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 479 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 480 | typedef enum |
| 481 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 482 | #define _(f,s) DPDK_ERROR_##f, |
| 483 | foreach_dpdk_error |
| 484 | #undef _ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 485 | DPDK_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 486 | } dpdk_error_t; |
| 487 | |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 488 | int dpdk_set_stat_poll_interval (f64 interval); |
| 489 | int dpdk_set_link_state_poll_interval (f64 interval); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | void dpdk_update_link_state (dpdk_device_t * xd, f64 now); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 491 | void dpdk_device_lock_init (dpdk_device_t * xd); |
| 492 | void dpdk_device_lock_free (dpdk_device_t * xd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 493 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 494 | static inline u64 |
| 495 | vnet_get_aggregate_rx_packets (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 496 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 497 | dpdk_main_t *dm = &dpdk_main; |
| 498 | u64 sum = 0; |
| 499 | dpdk_worker_t *dw; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 501 | vec_foreach (dw, dm->workers) sum += dw->aggregate_rx_packets; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 502 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 503 | return sum; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void dpdk_rx_trace (dpdk_main_t * dm, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 507 | vlib_node_runtime_t * node, |
| 508 | dpdk_device_t * xd, |
| 509 | u16 queue_id, u32 * buffers, uword n_buffers); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | |
| 511 | #define EFD_OPERATION_LESS_THAN 0 |
| 512 | #define EFD_OPERATION_GREATER_OR_EQUAL 1 |
| 513 | |
Damjan Marion | 7f62097 | 2016-02-25 16:00:11 +0100 | [diff] [blame] | 514 | format_function_t format_dpdk_device_name; |
| 515 | format_function_t format_dpdk_device; |
| 516 | format_function_t format_dpdk_tx_dma_trace; |
| 517 | format_function_t format_dpdk_rx_dma_trace; |
| 518 | format_function_t format_dpdk_rte_mbuf; |
| 519 | format_function_t format_dpdk_rx_rte_mbuf; |
| 520 | unformat_function_t unformat_socket_mem; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 521 | clib_error_t *unformat_rss_fn (unformat_input_t * input, uword * rss_fn); |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 522 | clib_error_t *unformat_hqos (unformat_input_t * input, |
| 523 | dpdk_device_config_hqos_t * hqos); |
Damjan Marion | 7f62097 | 2016-02-25 16:00:11 +0100 | [diff] [blame] | 524 | |
Todd Foggoa | e3eefff | 2016-05-20 22:10:34 -0400 | [diff] [blame] | 525 | uword |
| 526 | admin_up_down_process (vlib_main_t * vm, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 527 | vlib_node_runtime_t * rt, vlib_frame_t * f); |
Todd Foggoa | e3eefff | 2016-05-20 22:10:34 -0400 | [diff] [blame] | 528 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 529 | #endif /* __included_dpdk_h__ */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 530 | |
| 531 | /* |
| 532 | * fd.io coding-style-patch-verification: ON |
| 533 | * |
| 534 | * Local Variables: |
| 535 | * eval: (c-set-style "gnu") |
| 536 | * End: |
| 537 | */ |