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 | #include <vnet/vnet.h> |
| 16 | #include <vppinfra/vec.h> |
| 17 | #include <vppinfra/error.h> |
| 18 | #include <vppinfra/format.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 19 | #include <vppinfra/bitmap.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | |
| 21 | #include <vnet/ethernet/ethernet.h> |
| 22 | #include <vnet/devices/dpdk/dpdk.h> |
| 23 | #include <vlib/unix/physmem.h> |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 24 | #include <vlib/pci/pci.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <unistd.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <sys/mount.h> |
| 31 | #include <string.h> |
| 32 | #include <fcntl.h> |
| 33 | |
| 34 | #include "dpdk_priv.h" |
| 35 | |
| 36 | dpdk_main_t dpdk_main; |
| 37 | |
| 38 | /* force linker to link functions used by vlib and declared weak */ |
| 39 | void *vlib_weakly_linked_functions[] = { |
| 40 | &rte_pktmbuf_init, |
| 41 | &rte_pktmbuf_pool_init, |
| 42 | }; |
| 43 | |
| 44 | #define LINK_STATE_ELOGS 0 |
| 45 | |
| 46 | #define DEFAULT_HUGE_DIR "/run/vpp/hugepages" |
| 47 | #define VPP_RUN_DIR "/run/vpp" |
| 48 | |
| 49 | /* Port configuration, mildly modified Intel app values */ |
| 50 | |
| 51 | static struct rte_eth_conf port_conf_template = { |
| 52 | .rxmode = { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 53 | .split_hdr_size = 0, |
| 54 | .header_split = 0, /**< Header Split disabled */ |
| 55 | .hw_ip_checksum = 0, /**< IP checksum offload disabled */ |
| 56 | .hw_vlan_filter = 0, /**< VLAN filtering disabled */ |
| 57 | .hw_strip_crc = 0, /**< CRC stripped by hardware */ |
| 58 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | .txmode = { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 60 | .mq_mode = ETH_MQ_TX_NONE, |
| 61 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | clib_error_t * |
| 65 | dpdk_port_setup (dpdk_main_t * dm, dpdk_device_t * xd) |
| 66 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 67 | vlib_main_t *vm = vlib_get_main (); |
| 68 | vlib_buffer_main_t *bm = vm->buffer_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | int rv; |
| 70 | int j; |
| 71 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 72 | ASSERT (os_get_cpu_number () == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 74 | if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 75 | { |
| 76 | vnet_hw_interface_set_flags (dm->vnet_main, xd->vlib_hw_if_index, 0); |
| 77 | rte_eth_dev_stop (xd->device_index); |
| 78 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
| 80 | rv = rte_eth_dev_configure (xd->device_index, xd->rx_q_used, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 81 | xd->tx_q_used, &xd->port_conf); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
| 83 | if (rv < 0) |
| 84 | return clib_error_return (0, "rte_eth_dev_configure[%d]: err %d", |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 85 | xd->device_index, rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | |
| 87 | /* Set up one TX-queue per worker thread */ |
| 88 | for (j = 0; j < xd->tx_q_used; j++) |
| 89 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 90 | rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc, |
| 91 | xd->cpu_socket, &xd->tx_conf); |
Damjan Marion | ae60526 | 2016-04-21 21:42:40 +0200 | [diff] [blame] | 92 | |
| 93 | /* retry with any other CPU socket */ |
| 94 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 95 | rv = rte_eth_tx_queue_setup (xd->device_index, j, xd->nb_tx_desc, |
| 96 | SOCKET_ID_ANY, &xd->tx_conf); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 98 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 101 | if (rv < 0) |
| 102 | return clib_error_return (0, "rte_eth_tx_queue_setup[%d]: err %d", |
| 103 | xd->device_index, rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
| 105 | for (j = 0; j < xd->rx_q_used; j++) |
| 106 | { |
| 107 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 108 | rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc, |
| 109 | xd->cpu_socket, 0, |
| 110 | bm-> |
| 111 | pktmbuf_pools[xd->cpu_socket_id_by_queue |
| 112 | [j]]); |
Damjan Marion | ae60526 | 2016-04-21 21:42:40 +0200 | [diff] [blame] | 113 | |
| 114 | /* retry with any other CPU socket */ |
| 115 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 116 | rv = rte_eth_rx_queue_setup (xd->device_index, j, xd->nb_rx_desc, |
| 117 | SOCKET_ID_ANY, 0, |
| 118 | bm-> |
| 119 | pktmbuf_pools[xd->cpu_socket_id_by_queue |
| 120 | [j]]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 122 | return clib_error_return (0, "rte_eth_rx_queue_setup[%d]: err %d", |
| 123 | xd->device_index, rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 126 | if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 127 | { |
Dave Barach | dd522cb | 2016-08-10 16:56:16 -0400 | [diff] [blame] | 128 | int rv; |
| 129 | rv = rte_eth_dev_start (xd->device_index); |
| 130 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 131 | clib_warning ("rte_eth_dev_start %d returned %d", |
| 132 | xd->device_index, rv); |
| 133 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 137 | static u32 |
| 138 | dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 140 | dpdk_main_t *dm = &dpdk_main; |
| 141 | dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | u32 old = 0; |
| 143 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 144 | if (ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC (flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | { |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 146 | old = (xd->flags & DPDK_DEVICE_FLAG_PROMISC) != 0; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 147 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 148 | if (flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) |
| 149 | xd->flags |= DPDK_DEVICE_FLAG_PROMISC; |
| 150 | else |
| 151 | xd->flags &= ~DPDK_DEVICE_FLAG_PROMISC; |
| 152 | |
| 153 | if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | { |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 155 | if (xd->flags & DPDK_DEVICE_FLAG_PROMISC) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 156 | rte_eth_promiscuous_enable (xd->device_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 158 | rte_eth_promiscuous_disable (xd->device_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 161 | else if (ETHERNET_INTERFACE_FLAG_CONFIG_MTU (flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | { |
| 163 | /* |
| 164 | * DAW-FIXME: The Cisco VIC firmware does not provide an api for a |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 165 | * driver to dynamically change the mtu. If/when the |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | * VIC firmware gets fixed, then this should be removed. |
| 167 | */ |
Damjan Marion | 3a94475 | 2016-07-06 23:13:39 +0200 | [diff] [blame] | 168 | if (xd->pmd == VNET_DPDK_PMD_ENIC) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | { |
| 170 | struct rte_eth_dev_info dev_info; |
| 171 | |
| 172 | /* |
| 173 | * Restore mtu to what has been set by CIMC in the firmware cfg. |
| 174 | */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 175 | rte_eth_dev_info_get (xd->device_index, &dev_info); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | hi->max_packet_bytes = dev_info.max_rx_pktlen; |
| 177 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 178 | vlib_cli_output (vlib_get_main (), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | "Cisco VIC mtu can only be changed " |
| 180 | "using CIMC then rebooting the server!"); |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | int rv; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 185 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | xd->port_conf.rxmode.max_rx_pkt_len = hi->max_packet_bytes; |
| 187 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 188 | if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 189 | rte_eth_dev_stop (xd->device_index); |
| 190 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 191 | rv = rte_eth_dev_configure |
| 192 | (xd->device_index, xd->rx_q_used, xd->tx_q_used, &xd->port_conf); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
| 194 | if (rv < 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 195 | vlib_cli_output (vlib_get_main (), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 196 | "rte_eth_dev_configure[%d]: err %d", |
| 197 | xd->device_index, rv); |
| 198 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 199 | rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 201 | if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 202 | { |
| 203 | int rv = rte_eth_dev_start (xd->device_index); |
| 204 | if (rv < 0) |
| 205 | clib_warning ("rte_eth_dev_start %d returned %d", |
| 206 | xd->device_index, rv); |
| 207 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | return old; |
| 211 | } |
| 212 | |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 213 | void |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 214 | dpdk_device_lock_init (dpdk_device_t * xd) |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 215 | { |
| 216 | int q; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 217 | vec_validate (xd->lockp, xd->tx_q_used - 1); |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 218 | for (q = 0; q < xd->tx_q_used; q++) |
| 219 | { |
| 220 | xd->lockp[q] = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 221 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 222 | memset ((void *) xd->lockp[q], 0, CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 223 | } |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 227 | dpdk_device_lock_free (dpdk_device_t * xd) |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 228 | { |
| 229 | int q; |
| 230 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 231 | for (q = 0; q < vec_len (xd->lockp); q++) |
| 232 | clib_mem_free ((void *) xd->lockp[q]); |
| 233 | vec_free (xd->lockp); |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 234 | xd->lockp = 0; |
| 235 | } |
| 236 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | static clib_error_t * |
| 238 | dpdk_lib_init (dpdk_main_t * dm) |
| 239 | { |
| 240 | u32 nports; |
| 241 | u32 nb_desc = 0; |
| 242 | int i; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 243 | clib_error_t *error; |
| 244 | vlib_main_t *vm = vlib_get_main (); |
| 245 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 246 | vlib_node_runtime_t *rt; |
| 247 | vnet_sw_interface_t *sw; |
| 248 | vnet_hw_interface_t *hi; |
| 249 | dpdk_device_t *xd; |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 250 | vlib_pci_addr_t last_pci_addr; |
| 251 | u32 last_pci_addr_port = 0; |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 252 | vlib_thread_registration_t *tr, *tr_hqos; |
| 253 | uword *p, *p_hqos; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 254 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 255 | u32 next_cpu = 0, next_hqos_cpu = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 256 | u8 af_packet_port_id = 0; |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 257 | last_pci_addr.as_u32 = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 258 | |
| 259 | dm->input_cpu_first_index = 0; |
| 260 | dm->input_cpu_count = 1; |
| 261 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 262 | rt = vlib_node_get_runtime (vm, dpdk_input_node.index); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 263 | rt->function = dpdk_input_multiarch_select (); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 264 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | /* find out which cpus will be used for input */ |
Damjan Marion | bf74147 | 2016-06-13 22:49:44 +0200 | [diff] [blame] | 266 | p = hash_get_mem (tm->thread_registrations_by_name, "workers"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 267 | tr = p ? (vlib_thread_registration_t *) p[0] : 0; |
| 268 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | if (tr && tr->count > 0) |
| 270 | { |
| 271 | dm->input_cpu_first_index = tr->first_index; |
| 272 | dm->input_cpu_count = tr->count; |
| 273 | } |
| 274 | |
| 275 | vec_validate_aligned (dm->devices_by_cpu, tm->n_vlib_mains - 1, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 276 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | |
| 278 | vec_validate_aligned (dm->workers, tm->n_vlib_mains - 1, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 279 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 281 | dm->hqos_cpu_first_index = 0; |
| 282 | dm->hqos_cpu_count = 0; |
| 283 | |
| 284 | /* find out which cpus will be used for I/O TX */ |
| 285 | p_hqos = hash_get_mem (tm->thread_registrations_by_name, "hqos-threads"); |
| 286 | tr_hqos = p_hqos ? (vlib_thread_registration_t *) p_hqos[0] : 0; |
| 287 | |
| 288 | if (tr_hqos && tr_hqos->count > 0) |
| 289 | { |
| 290 | dm->hqos_cpu_first_index = tr_hqos->first_index; |
| 291 | dm->hqos_cpu_count = tr_hqos->count; |
| 292 | } |
| 293 | |
| 294 | vec_validate_aligned (dm->devices_by_hqos_cpu, tm->n_vlib_mains - 1, |
| 295 | CLIB_CACHE_LINE_BYTES); |
| 296 | |
| 297 | vec_validate_aligned (dm->hqos_threads, tm->n_vlib_mains - 1, |
| 298 | CLIB_CACHE_LINE_BYTES); |
| 299 | |
| 300 | #ifdef NETMAP |
| 301 | if (rte_netmap_probe () < 0) |
| 302 | return clib_error_return (0, "rte netmap probe failed"); |
| 303 | #endif |
| 304 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 305 | nports = rte_eth_dev_count (); |
| 306 | if (nports < 1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | { |
| 308 | clib_warning ("DPDK drivers found no ports..."); |
| 309 | } |
| 310 | |
| 311 | if (CLIB_DEBUG > 0) |
| 312 | clib_warning ("DPDK drivers found %d ports...", nports); |
| 313 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 314 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | * All buffers are all allocated from the same rte_mempool. |
| 316 | * Thus they all have the same number of data bytes. |
| 317 | */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 318 | dm->vlib_buffer_free_list_index = |
| 319 | vlib_buffer_get_or_create_free_list (vm, |
| 320 | VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES, |
| 321 | "dpdk rx"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 323 | if (dm->conf->enable_tcp_udp_checksum) |
| 324 | dm->buffer_flags_template &= ~(IP_BUFFER_L4_CHECKSUM_CORRECT |
| 325 | | IP_BUFFER_L4_CHECKSUM_COMPUTED); |
| 326 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | for (i = 0; i < nports; i++) |
| 328 | { |
| 329 | u8 addr[6]; |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 330 | u8 vlan_strip = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 331 | int j; |
| 332 | struct rte_eth_dev_info dev_info; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 333 | clib_error_t *rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | struct rte_eth_link l; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 335 | dpdk_device_config_t *devconf = 0; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 336 | vlib_pci_addr_t pci_addr; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 337 | uword *p = 0; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 338 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 339 | rte_eth_dev_info_get (i, &dev_info); |
| 340 | if (dev_info.pci_dev) /* bonded interface has no pci info */ |
| 341 | { |
John Lo | 55ef1b1 | 2016-06-08 23:21:35 -0400 | [diff] [blame] | 342 | pci_addr.domain = dev_info.pci_dev->addr.domain; |
| 343 | pci_addr.bus = dev_info.pci_dev->addr.bus; |
| 344 | pci_addr.slot = dev_info.pci_dev->addr.devid; |
| 345 | pci_addr.function = dev_info.pci_dev->addr.function; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 346 | p = |
| 347 | hash_get (dm->conf->device_config_index_by_pci_addr, |
| 348 | pci_addr.as_u32); |
| 349 | } |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 350 | |
| 351 | if (p) |
| 352 | devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]); |
| 353 | else |
| 354 | devconf = &dm->conf->default_devconf; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | |
| 356 | /* Create vnet interface */ |
| 357 | vec_add2_aligned (dm->devices, xd, 1, CLIB_CACHE_LINE_BYTES); |
| 358 | xd->nb_rx_desc = DPDK_NB_RX_DESC_DEFAULT; |
| 359 | xd->nb_tx_desc = DPDK_NB_TX_DESC_DEFAULT; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 360 | xd->cpu_socket = (i8) rte_eth_dev_socket_id (i); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 362 | /* Handle interface naming for devices with multiple ports sharing same PCI ID */ |
| 363 | if (dev_info.pci_dev) |
| 364 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 365 | struct rte_eth_dev_info di = { 0 }; |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 366 | rte_eth_dev_info_get (i + 1, &di); |
| 367 | if (di.pci_dev && pci_addr.as_u32 != last_pci_addr.as_u32 && |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 368 | memcmp (&dev_info.pci_dev->addr, &di.pci_dev->addr, |
| 369 | sizeof (struct rte_pci_addr)) == 0) |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 370 | { |
| 371 | xd->interface_name_suffix = format (0, "0"); |
| 372 | last_pci_addr.as_u32 = pci_addr.as_u32; |
| 373 | last_pci_addr_port = i; |
| 374 | } |
| 375 | else if (pci_addr.as_u32 == last_pci_addr.as_u32) |
| 376 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 377 | xd->interface_name_suffix = |
| 378 | format (0, "%u", i - last_pci_addr_port); |
Damjan Marion | 32f7bc1 | 2016-07-21 03:42:37 -0700 | [diff] [blame] | 379 | } |
| 380 | else |
| 381 | { |
| 382 | last_pci_addr.as_u32 = ~0; |
| 383 | } |
| 384 | } |
| 385 | else |
| 386 | last_pci_addr.as_u32 = ~0; |
| 387 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 388 | clib_memcpy (&xd->tx_conf, &dev_info.default_txconf, |
| 389 | sizeof (struct rte_eth_txconf)); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 390 | if (dm->conf->no_multi_seg) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 391 | { |
| 392 | xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS; |
| 393 | port_conf_template.rxmode.jumbo_frame = 0; |
| 394 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 396 | { |
| 397 | xd->tx_conf.txq_flags &= ~ETH_TXQ_FLAGS_NOMULTSEGS; |
| 398 | port_conf_template.rxmode.jumbo_frame = 1; |
| 399 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 401 | clib_memcpy (&xd->port_conf, &port_conf_template, |
| 402 | sizeof (struct rte_eth_conf)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 404 | xd->tx_q_used = clib_min (dev_info.max_tx_queues, tm->n_vlib_mains); |
Damjan Marion | 85cdbd0 | 2016-02-12 18:00:23 +0100 | [diff] [blame] | 405 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 406 | if (devconf->num_tx_queues > 0 |
| 407 | && devconf->num_tx_queues < xd->tx_q_used) |
| 408 | xd->tx_q_used = clib_min (xd->tx_q_used, devconf->num_tx_queues); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 410 | if (devconf->num_rx_queues > 1 && dm->use_rss == 0) |
| 411 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 412 | rt->function = dpdk_input_rss_multiarch_select (); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 413 | dm->use_rss = 1; |
| 414 | } |
| 415 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 416 | if (devconf->num_rx_queues > 1 |
| 417 | && dev_info.max_rx_queues >= devconf->num_rx_queues) |
| 418 | { |
| 419 | xd->rx_q_used = devconf->num_rx_queues; |
| 420 | xd->port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS; |
| 421 | if (devconf->rss_fn == 0) |
| 422 | xd->port_conf.rx_adv_conf.rss_conf.rss_hf = |
| 423 | ETH_RSS_IP | ETH_RSS_UDP | ETH_RSS_TCP; |
| 424 | else |
| 425 | xd->port_conf.rx_adv_conf.rss_conf.rss_hf = devconf->rss_fn; |
| 426 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 428 | xd->rx_q_used = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | |
Damjan Marion | 5643170 | 2016-09-19 13:18:09 +0200 | [diff] [blame] | 430 | xd->flags |= DPDK_DEVICE_FLAG_PMD; |
Damjan Marion | 2068e98 | 2016-01-27 16:59:04 +0100 | [diff] [blame] | 431 | |
| 432 | /* workaround for drivers not setting driver_name */ |
John Lo | 55ef1b1 | 2016-06-08 23:21:35 -0400 | [diff] [blame] | 433 | if ((!dev_info.driver_name) && (dev_info.pci_dev)) |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 434 | #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 435 | dev_info.driver_name = dev_info.pci_dev->driver->name; |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 436 | #else |
| 437 | dev_info.driver_name = dev_info.pci_dev->driver->driver.name; |
| 438 | #endif |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 439 | ASSERT (dev_info.driver_name); |
Damjan Marion | 2068e98 | 2016-01-27 16:59:04 +0100 | [diff] [blame] | 440 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 441 | if (!xd->pmd) |
| 442 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 443 | |
| 444 | |
Dave Barach | dd522cb | 2016-08-10 16:56:16 -0400 | [diff] [blame] | 445 | #define _(s,f) else if (dev_info.driver_name && \ |
| 446 | !strcmp(dev_info.driver_name, s)) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | xd->pmd = VNET_DPDK_PMD_##f; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 448 | if (0) |
| 449 | ; |
| 450 | foreach_dpdk_pmd |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 451 | #undef _ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 452 | else |
| 453 | xd->pmd = VNET_DPDK_PMD_UNKNOWN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 454 | |
| 455 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 456 | switch (xd->pmd) |
| 457 | { |
| 458 | /* 1G adapters */ |
| 459 | case VNET_DPDK_PMD_E1000EM: |
| 460 | case VNET_DPDK_PMD_IGB: |
| 461 | case VNET_DPDK_PMD_IGBVF: |
| 462 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G; |
| 463 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 464 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 465 | /* 10G adapters */ |
| 466 | case VNET_DPDK_PMD_IXGBE: |
| 467 | case VNET_DPDK_PMD_IXGBEVF: |
| 468 | case VNET_DPDK_PMD_THUNDERX: |
| 469 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G; |
| 470 | xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE; |
| 471 | xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE; |
| 472 | break; |
| 473 | case VNET_DPDK_PMD_DPAA2: |
| 474 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G; |
| 475 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 476 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 477 | /* Cisco VIC */ |
| 478 | case VNET_DPDK_PMD_ENIC: |
| 479 | rte_eth_link_get_nowait (i, &l); |
| 480 | xd->nb_rx_desc = DPDK_NB_RX_DESC_ENIC; |
| 481 | if (l.link_speed == 40000) |
| 482 | { |
| 483 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G; |
| 484 | xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE; |
| 485 | } |
| 486 | else |
| 487 | { |
| 488 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G; |
| 489 | xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE; |
| 490 | } |
| 491 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 493 | /* Intel Fortville */ |
| 494 | case VNET_DPDK_PMD_I40E: |
| 495 | case VNET_DPDK_PMD_I40EVF: |
| 496 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G; |
| 497 | xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE; |
| 498 | xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 499 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 500 | switch (dev_info.pci_dev->id.device_id) |
| 501 | { |
| 502 | case I40E_DEV_ID_10G_BASE_T: |
| 503 | case I40E_DEV_ID_SFP_XL710: |
| 504 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G; |
| 505 | break; |
| 506 | case I40E_DEV_ID_QSFP_A: |
| 507 | case I40E_DEV_ID_QSFP_B: |
| 508 | case I40E_DEV_ID_QSFP_C: |
| 509 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G; |
| 510 | break; |
| 511 | case I40E_DEV_ID_VF: |
| 512 | rte_eth_link_get_nowait (i, &l); |
| 513 | xd->port_type = l.link_speed == 10000 ? |
| 514 | VNET_DPDK_PORT_TYPE_ETH_10G : VNET_DPDK_PORT_TYPE_ETH_40G; |
| 515 | break; |
| 516 | default: |
| 517 | xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN; |
| 518 | } |
| 519 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 521 | case VNET_DPDK_PMD_CXGBE: |
| 522 | switch (dev_info.pci_dev->id.device_id) |
| 523 | { |
| 524 | case 0x540d: /* T580-CR */ |
| 525 | case 0x5410: /* T580-LP-cr */ |
| 526 | xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE; |
| 527 | xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE; |
| 528 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_40G; |
| 529 | break; |
| 530 | case 0x5403: /* T540-CR */ |
| 531 | xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE; |
| 532 | xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE; |
| 533 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_10G; |
| 534 | break; |
| 535 | default: |
| 536 | xd->nb_rx_desc = DPDK_NB_RX_DESC_10GE; |
| 537 | xd->nb_tx_desc = DPDK_NB_TX_DESC_10GE; |
| 538 | xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN; |
| 539 | } |
| 540 | break; |
Damjan Marion | 2068e98 | 2016-01-27 16:59:04 +0100 | [diff] [blame] | 541 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 542 | /* Intel Red Rock Canyon */ |
| 543 | case VNET_DPDK_PMD_FM10K: |
| 544 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_SWITCH; |
| 545 | xd->nb_rx_desc = DPDK_NB_RX_DESC_40GE; |
| 546 | xd->nb_tx_desc = DPDK_NB_TX_DESC_40GE; |
| 547 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 548 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 549 | /* virtio */ |
| 550 | case VNET_DPDK_PMD_VIRTIO: |
| 551 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G; |
| 552 | xd->nb_rx_desc = DPDK_NB_RX_DESC_VIRTIO; |
| 553 | xd->nb_tx_desc = DPDK_NB_TX_DESC_VIRTIO; |
| 554 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 556 | /* vmxnet3 */ |
| 557 | case VNET_DPDK_PMD_VMXNET3: |
| 558 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_1G; |
| 559 | xd->tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS; |
| 560 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 561 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 562 | case VNET_DPDK_PMD_AF_PACKET: |
| 563 | xd->port_type = VNET_DPDK_PORT_TYPE_AF_PACKET; |
| 564 | xd->af_packet_port_id = af_packet_port_id++; |
| 565 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 566 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 567 | case VNET_DPDK_PMD_BOND: |
| 568 | xd->port_type = VNET_DPDK_PORT_TYPE_ETH_BOND; |
| 569 | break; |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 570 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 571 | default: |
| 572 | xd->port_type = VNET_DPDK_PORT_TYPE_UNKNOWN; |
| 573 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 574 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 575 | if (devconf->num_rx_desc) |
| 576 | xd->nb_rx_desc = devconf->num_rx_desc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 578 | if (devconf->num_tx_desc) |
| 579 | xd->nb_tx_desc = devconf->num_tx_desc; |
| 580 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * Ensure default mtu is not > the mtu read from the hardware. |
| 584 | * Otherwise rte_eth_dev_configure() will fail and the port will |
| 585 | * not be available. |
| 586 | */ |
Jurek Matuszewski | a69318b | 2016-03-28 15:15:15 -0400 | [diff] [blame] | 587 | if (ETHERNET_MAX_PACKET_BYTES > dev_info.max_rx_pktlen) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 588 | { |
| 589 | /* |
| 590 | * This device does not support the platforms's max frame |
| 591 | * size. Use it's advertised mru instead. |
| 592 | */ |
| 593 | xd->port_conf.rxmode.max_rx_pkt_len = dev_info.max_rx_pktlen; |
| 594 | } |
Jurek Matuszewski | a69318b | 2016-03-28 15:15:15 -0400 | [diff] [blame] | 595 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 596 | { |
| 597 | xd->port_conf.rxmode.max_rx_pkt_len = ETHERNET_MAX_PACKET_BYTES; |
Jurek Matuszewski | a69318b | 2016-03-28 15:15:15 -0400 | [diff] [blame] | 598 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 599 | /* |
| 600 | * Some platforms do not account for Ethernet FCS (4 bytes) in |
| 601 | * MTU calculations. To interop with them increase mru but only |
| 602 | * if the device's settings can support it. |
| 603 | */ |
| 604 | if ((dev_info.max_rx_pktlen >= (ETHERNET_MAX_PACKET_BYTES + 4)) && |
| 605 | xd->port_conf.rxmode.hw_strip_crc) |
| 606 | { |
| 607 | /* |
| 608 | * Allow additional 4 bytes (for Ethernet FCS). These bytes are |
| 609 | * stripped by h/w and so will not consume any buffer memory. |
| 610 | */ |
| 611 | xd->port_conf.rxmode.max_rx_pkt_len += 4; |
| 612 | } |
| 613 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 614 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 615 | if (xd->pmd == VNET_DPDK_PMD_AF_PACKET) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 616 | { |
| 617 | f64 now = vlib_time_now (vm); |
| 618 | u32 rnd; |
| 619 | rnd = (u32) (now * 1e6); |
| 620 | rnd = random_u32 (&rnd); |
| 621 | clib_memcpy (addr + 2, &rnd, sizeof (rnd)); |
| 622 | addr[0] = 2; |
| 623 | addr[1] = 0xfe; |
| 624 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 626 | rte_eth_macaddr_get (i, (struct ether_addr *) addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 627 | |
| 628 | if (xd->tx_q_used < tm->n_vlib_mains) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 629 | dpdk_device_lock_init (xd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | |
| 631 | xd->device_index = xd - dm->devices; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 632 | ASSERT (i == xd->device_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 633 | xd->per_interface_next_index = ~0; |
| 634 | |
| 635 | /* assign interface to input thread */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 636 | dpdk_device_and_queue_t *dq; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 637 | int q; |
| 638 | |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 639 | if (devconf->workers) |
| 640 | { |
| 641 | int i; |
| 642 | q = 0; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 643 | /* *INDENT-OFF* */ |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 644 | clib_bitmap_foreach (i, devconf->workers, ({ |
| 645 | int cpu = dm->input_cpu_first_index + i; |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 646 | unsigned lcore = vlib_worker_threads[cpu].lcore_id; |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 647 | vec_validate(xd->cpu_socket_id_by_queue, q); |
| 648 | xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id(lcore); |
| 649 | vec_add2(dm->devices_by_cpu[cpu], dq, 1); |
| 650 | dq->device = xd->device_index; |
| 651 | dq->queue_id = q++; |
| 652 | })); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 653 | /* *INDENT-ON* */ |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 654 | } |
| 655 | else |
| 656 | for (q = 0; q < xd->rx_q_used; q++) |
| 657 | { |
| 658 | int cpu = dm->input_cpu_first_index + next_cpu; |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 659 | unsigned lcore = vlib_worker_threads[cpu].lcore_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 660 | |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 661 | /* |
| 662 | * numa node for worker thread handling this queue |
| 663 | * needed for taking buffers from the right mempool |
| 664 | */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 665 | vec_validate (xd->cpu_socket_id_by_queue, q); |
| 666 | xd->cpu_socket_id_by_queue[q] = rte_lcore_to_socket_id (lcore); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 668 | /* |
| 669 | * construct vector of (device,queue) pairs for each worker thread |
| 670 | */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 671 | vec_add2 (dm->devices_by_cpu[cpu], dq, 1); |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 672 | dq->device = xd->device_index; |
| 673 | dq->queue_id = q; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 674 | |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 675 | next_cpu++; |
| 676 | if (next_cpu == dm->input_cpu_count) |
| 677 | next_cpu = 0; |
| 678 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 679 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 680 | |
| 681 | if (devconf->hqos_enabled) |
| 682 | { |
| 683 | xd->flags |= DPDK_DEVICE_FLAG_HQOS; |
| 684 | |
| 685 | if (devconf->hqos.hqos_thread_valid) |
| 686 | { |
| 687 | int cpu = dm->hqos_cpu_first_index + devconf->hqos.hqos_thread; |
| 688 | |
| 689 | if (devconf->hqos.hqos_thread >= dm->hqos_cpu_count) |
| 690 | return clib_error_return (0, "invalid HQoS thread index"); |
| 691 | |
| 692 | vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1); |
| 693 | dq->device = xd->device_index; |
| 694 | dq->queue_id = 0; |
| 695 | } |
| 696 | else |
| 697 | { |
| 698 | int cpu = dm->hqos_cpu_first_index + next_hqos_cpu; |
| 699 | |
| 700 | if (dm->hqos_cpu_count == 0) |
| 701 | return clib_error_return (0, "no HQoS threads available"); |
| 702 | |
| 703 | vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1); |
| 704 | dq->device = xd->device_index; |
| 705 | dq->queue_id = 0; |
| 706 | |
| 707 | next_hqos_cpu++; |
| 708 | if (next_hqos_cpu == dm->hqos_cpu_count) |
| 709 | next_hqos_cpu = 0; |
| 710 | |
| 711 | devconf->hqos.hqos_thread_valid = 1; |
| 712 | devconf->hqos.hqos_thread = cpu; |
| 713 | } |
| 714 | } |
| 715 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 716 | vec_validate_aligned (xd->tx_vectors, tm->n_vlib_mains, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 717 | CLIB_CACHE_LINE_BYTES); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 718 | for (j = 0; j < tm->n_vlib_mains; j++) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 719 | { |
Damjan Marion | b58598b | 2016-09-19 13:44:37 +0200 | [diff] [blame] | 720 | vec_validate_ha (xd->tx_vectors[j], xd->nb_tx_desc, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 721 | sizeof (tx_ring_hdr_t), CLIB_CACHE_LINE_BYTES); |
| 722 | vec_reset_length (xd->tx_vectors[j]); |
| 723 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 724 | |
| 725 | vec_validate_aligned (xd->rx_vectors, xd->rx_q_used, |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 726 | CLIB_CACHE_LINE_BYTES); |
| 727 | for (j = 0; j < xd->rx_q_used; j++) |
| 728 | { |
| 729 | vec_validate_aligned (xd->rx_vectors[j], VLIB_FRAME_SIZE - 1, |
| 730 | CLIB_CACHE_LINE_BYTES); |
| 731 | vec_reset_length (xd->rx_vectors[j]); |
| 732 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 733 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 734 | rv = dpdk_port_setup (dm, xd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 735 | |
Dave Barach | dd522cb | 2016-08-10 16:56:16 -0400 | [diff] [blame] | 736 | if (rv) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 737 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 738 | |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 739 | if (devconf->hqos_enabled) |
| 740 | { |
| 741 | rv = dpdk_port_setup_hqos (xd, &devconf->hqos); |
| 742 | if (rv < 0) |
| 743 | return rv; |
| 744 | } |
| 745 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | /* count the number of descriptors used for this device */ |
| 747 | nb_desc += xd->nb_rx_desc + xd->nb_tx_desc * xd->tx_q_used; |
| 748 | |
| 749 | error = ethernet_register_interface |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 750 | (dm->vnet_main, dpdk_device_class.index, xd->device_index, |
| 751 | /* ethernet address */ addr, |
| 752 | &xd->vlib_hw_if_index, dpdk_flag_change); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 753 | if (error) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 754 | return error; |
| 755 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | sw = vnet_get_hw_sw_interface (dm->vnet_main, xd->vlib_hw_if_index); |
| 757 | xd->vlib_sw_if_index = sw->sw_if_index; |
| 758 | hi = vnet_get_hw_interface (dm->vnet_main, xd->vlib_hw_if_index); |
| 759 | |
| 760 | /* |
| 761 | * DAW-FIXME: The Cisco VIC firmware does not provide an api for a |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 762 | * driver to dynamically change the mtu. If/when the |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 763 | * VIC firmware gets fixed, then this should be removed. |
| 764 | */ |
Damjan Marion | 3a94475 | 2016-07-06 23:13:39 +0200 | [diff] [blame] | 765 | if (xd->pmd == VNET_DPDK_PMD_ENIC) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | { |
| 767 | /* |
| 768 | * Initialize mtu to what has been set by CIMC in the firmware cfg. |
| 769 | */ |
| 770 | hi->max_packet_bytes = dev_info.max_rx_pktlen; |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 771 | if (devconf->vlan_strip_offload != DPDK_DEVICE_VLAN_STRIP_OFF) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 772 | vlan_strip = 1; /* remove vlan tag from VIC port by default */ |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 773 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 774 | clib_warning ("VLAN strip disabled for interface\n"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 775 | } |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 776 | else if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON) |
| 777 | vlan_strip = 1; |
| 778 | |
| 779 | if (vlan_strip) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 780 | { |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 781 | int vlan_off; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 782 | vlan_off = rte_eth_dev_get_vlan_offload (xd->device_index); |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 783 | vlan_off |= ETH_VLAN_STRIP_OFFLOAD; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 784 | if (rte_eth_dev_set_vlan_offload (xd->device_index, vlan_off) == 0) |
| 785 | clib_warning ("VLAN strip enabled for interface\n"); |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 786 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 787 | clib_warning ("VLAN strip cannot be supported by interface\n"); |
| 788 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 789 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 790 | hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] = |
| 791 | xd->port_conf.rxmode.max_rx_pkt_len - sizeof (ethernet_header_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 793 | rte_eth_dev_set_mtu (xd->device_index, hi->max_packet_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 796 | if (nb_desc > dm->conf->num_mbufs) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 797 | clib_warning ("%d mbufs allocated but total rx/tx ring size is %d\n", |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 798 | dm->conf->num_mbufs, nb_desc); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 799 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 800 | return 0; |
| 801 | } |
| 802 | |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 803 | static void |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 804 | dpdk_bind_devices_to_uio (dpdk_config_main_t * conf) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 805 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 806 | vlib_pci_main_t *pm = &pci_main; |
| 807 | clib_error_t *error; |
| 808 | vlib_pci_device_t *d; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 809 | u8 *pci_addr = 0; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 810 | int num_whitelisted = vec_len (conf->dev_confs); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 811 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 812 | /* *INDENT-OFF* */ |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 813 | pool_foreach (d, pm->pci_devs, ({ |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 814 | dpdk_device_config_t * devconf = 0; |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 815 | vec_reset_length (pci_addr); |
| 816 | pci_addr = format (pci_addr, "%U%c", format_vlib_pci_addr, &d->bus_address, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 817 | |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 818 | if (d->device_class != PCI_CLASS_NETWORK_ETHERNET) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 819 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 820 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 821 | if (num_whitelisted) |
| 822 | { |
| 823 | uword * p = hash_get (conf->device_config_index_by_pci_addr, d->bus_address.as_u32); |
| 824 | |
| 825 | if (!p) |
| 826 | continue; |
| 827 | |
| 828 | devconf = pool_elt_at_index (conf->dev_confs, p[0]); |
| 829 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 830 | |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 831 | /* virtio */ |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 832 | if (d->vendor_id == 0x1af4 && d->device_id == 0x1000) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 833 | ; |
| 834 | /* vmxnet3 */ |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 835 | else if (d->vendor_id == 0x15ad && d->device_id == 0x07b0) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 836 | ; |
| 837 | /* all Intel devices */ |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 838 | else if (d->vendor_id == 0x8086) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 839 | ; |
| 840 | /* Cisco VIC */ |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 841 | else if (d->vendor_id == 0x1137 && d->device_id == 0x0043) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 842 | ; |
| 843 | /* Chelsio T4/T5 */ |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 844 | else if (d->vendor_id == 0x1425 && (d->device_id & 0xe000) == 0x4000) |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 845 | ; |
| 846 | else |
| 847 | { |
| 848 | clib_warning ("Unsupported Ethernet PCI device 0x%04x:0x%04x found " |
Damjan Marion | b1b1a14 | 2016-08-23 00:53:22 +0200 | [diff] [blame] | 849 | "at PCI address %s\n", (u16) d->vendor_id, (u16) d->device_id, |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 850 | pci_addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 851 | continue; |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 852 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 854 | error = vlib_pci_bind_to_uio (d, (char *) conf->uio_driver_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 855 | |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 856 | if (error) |
| 857 | { |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 858 | if (devconf == 0) |
| 859 | { |
| 860 | pool_get (conf->dev_confs, devconf); |
| 861 | hash_set (conf->device_config_index_by_pci_addr, d->bus_address.as_u32, |
| 862 | devconf - conf->dev_confs); |
| 863 | devconf->pci_addr.as_u32 = d->bus_address.as_u32; |
| 864 | } |
| 865 | devconf->is_blacklisted = 1; |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 866 | clib_error_report (error); |
| 867 | } |
| 868 | })); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 869 | /* *INDENT-ON* */ |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 870 | vec_free (pci_addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 873 | static clib_error_t * |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 874 | dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr, |
| 875 | unformat_input_t * input, u8 is_default) |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 876 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 877 | clib_error_t *error = 0; |
| 878 | uword *p; |
| 879 | dpdk_device_config_t *devconf; |
Srivatsa Sangli | 820e363 | 2016-06-14 13:10:55 -0700 | [diff] [blame] | 880 | unformat_input_t sub_input; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 881 | |
| 882 | if (is_default) |
| 883 | { |
| 884 | devconf = &conf->default_devconf; |
| 885 | } |
| 886 | else |
| 887 | { |
| 888 | p = hash_get (conf->device_config_index_by_pci_addr, pci_addr.as_u32); |
| 889 | |
| 890 | if (!p) |
| 891 | { |
| 892 | pool_get (conf->dev_confs, devconf); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 893 | hash_set (conf->device_config_index_by_pci_addr, pci_addr.as_u32, |
| 894 | devconf - conf->dev_confs); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 895 | } |
| 896 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 897 | return clib_error_return (0, |
| 898 | "duplicate configuration for PCI address %U", |
| 899 | format_vlib_pci_addr, &pci_addr); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | devconf->pci_addr.as_u32 = pci_addr.as_u32; |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 903 | devconf->hqos_enabled = 0; |
| 904 | dpdk_device_config_hqos_default (&devconf->hqos); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 905 | |
| 906 | if (!input) |
| 907 | return 0; |
| 908 | |
| 909 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 910 | { |
| 911 | if (unformat (input, "num-rx-queues %u", &devconf->num_rx_queues)) |
| 912 | ; |
Damjan Marion | 39da621 | 2016-06-06 13:21:04 +0200 | [diff] [blame] | 913 | else if (unformat (input, "num-tx-queues %u", &devconf->num_tx_queues)) |
| 914 | ; |
| 915 | else if (unformat (input, "num-rx-desc %u", &devconf->num_rx_desc)) |
| 916 | ; |
| 917 | else if (unformat (input, "num-tx-desc %u", &devconf->num_tx_desc)) |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 918 | ; |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 919 | else if (unformat (input, "workers %U", unformat_bitmap_list, |
| 920 | &devconf->workers)) |
| 921 | ; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 922 | else |
| 923 | if (unformat |
| 924 | (input, "rss %U", unformat_vlib_cli_sub_input, &sub_input)) |
| 925 | { |
| 926 | error = unformat_rss_fn (&sub_input, &devconf->rss_fn); |
| 927 | if (error) |
| 928 | break; |
| 929 | } |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 930 | else if (unformat (input, "vlan-strip-offload off")) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 931 | devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_OFF; |
John Lo | ce3e971 | 2016-07-07 13:54:44 -0400 | [diff] [blame] | 932 | else if (unformat (input, "vlan-strip-offload on")) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 933 | devconf->vlan_strip_offload = DPDK_DEVICE_VLAN_STRIP_ON; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 934 | else |
Jasvinder Singh | 85ecc81 | 2016-07-21 17:02:19 +0100 | [diff] [blame] | 935 | if (unformat |
| 936 | (input, "hqos %U", unformat_vlib_cli_sub_input, &sub_input)) |
| 937 | { |
| 938 | devconf->hqos_enabled = 1; |
| 939 | error = unformat_hqos (&sub_input, &devconf->hqos); |
| 940 | if (error) |
| 941 | break; |
| 942 | } |
| 943 | else if (unformat (input, "hqos")) |
| 944 | { |
| 945 | devconf->hqos_enabled = 1; |
| 946 | } |
| 947 | else |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 948 | { |
| 949 | error = clib_error_return (0, "unknown input `%U'", |
| 950 | format_unformat_error, input); |
| 951 | break; |
| 952 | } |
| 953 | } |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 954 | |
| 955 | if (error) |
| 956 | return error; |
| 957 | |
| 958 | if (devconf->workers && devconf->num_rx_queues == 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 959 | devconf->num_rx_queues = clib_bitmap_count_set_bits (devconf->workers); |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 960 | else if (devconf->workers && |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 961 | clib_bitmap_count_set_bits (devconf->workers) != |
| 962 | devconf->num_rx_queues) |
| 963 | error = |
| 964 | clib_error_return (0, |
| 965 | "%U: number of worker threadds must be " |
| 966 | "equal to number of rx queues", format_vlib_pci_addr, |
| 967 | &pci_addr); |
Damjan Marion | 0b14072 | 2016-06-14 00:36:09 +0200 | [diff] [blame] | 968 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 969 | return error; |
| 970 | } |
| 971 | |
| 972 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 973 | dpdk_config (vlib_main_t * vm, unformat_input_t * input) |
| 974 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 975 | clib_error_t *error = 0; |
| 976 | dpdk_main_t *dm = &dpdk_main; |
| 977 | dpdk_config_main_t *conf = &dpdk_config_main; |
| 978 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 979 | dpdk_device_config_t *devconf; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 980 | vlib_pci_addr_t pci_addr; |
| 981 | unformat_input_t sub_input; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 982 | u8 *s, *tmp = 0; |
| 983 | u8 *rte_cmd = 0, *ethname = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 984 | u32 log_level; |
| 985 | int ret, i; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 986 | int num_whitelisted = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | u8 no_pci = 0; |
| 988 | u8 no_huge = 0; |
| 989 | u8 huge_dir = 0; |
| 990 | u8 file_prefix = 0; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 991 | u8 *socket_mem = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 992 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 993 | conf->device_config_index_by_pci_addr = hash_create (0, sizeof (uword)); |
| 994 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 995 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 996 | { |
| 997 | /* Prime the pump */ |
| 998 | if (unformat (input, "no-hugetlb")) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 999 | { |
| 1000 | vec_add1 (conf->eal_init_args, (u8 *) "no-huge"); |
| 1001 | no_huge = 1; |
| 1002 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1003 | |
Dave Barach | d81566f | 2016-02-15 11:34:13 -0500 | [diff] [blame] | 1004 | else if (unformat (input, "enable-tcp-udp-checksum")) |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1005 | conf->enable_tcp_udp_checksum = 1; |
Dave Barach | d81566f | 2016-02-15 11:34:13 -0500 | [diff] [blame] | 1006 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1007 | else if (unformat (input, "decimal-interface-names")) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1008 | conf->interface_name_format_decimal = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1009 | |
| 1010 | else if (unformat (input, "no-multi-seg")) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1011 | conf->no_multi_seg = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1012 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1013 | else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input, |
| 1014 | &sub_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1016 | error = |
| 1017 | dpdk_device_config (conf, (vlib_pci_addr_t) (u32) ~ 1, &sub_input, |
| 1018 | 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1019 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1020 | if (error) |
| 1021 | return error; |
| 1022 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1023 | else |
| 1024 | if (unformat |
| 1025 | (input, "dev %U %U", unformat_vlib_pci_addr, &pci_addr, |
| 1026 | unformat_vlib_cli_sub_input, &sub_input)) |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1027 | { |
| 1028 | error = dpdk_device_config (conf, pci_addr, &sub_input, 0); |
| 1029 | |
| 1030 | if (error) |
| 1031 | return error; |
| 1032 | |
| 1033 | num_whitelisted++; |
| 1034 | } |
| 1035 | else if (unformat (input, "dev %U", unformat_vlib_pci_addr, &pci_addr)) |
| 1036 | { |
| 1037 | error = dpdk_device_config (conf, pci_addr, 0, 0); |
| 1038 | |
| 1039 | if (error) |
| 1040 | return error; |
| 1041 | |
| 1042 | num_whitelisted++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1043 | } |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1044 | else if (unformat (input, "num-mbufs %d", &conf->num_mbufs)) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1045 | ; |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1046 | else if (unformat (input, "kni %d", &conf->num_kni)) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1047 | ; |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1048 | else if (unformat (input, "uio-driver %s", &conf->uio_driver_name)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | ; |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1050 | else if (unformat (input, "socket-mem %s", &socket_mem)) |
| 1051 | ; |
Damjan Marion | b022cd1 | 2016-08-16 13:25:59 +0200 | [diff] [blame] | 1052 | else if (unformat (input, "no-pci")) |
| 1053 | { |
| 1054 | no_pci = 1; |
| 1055 | tmp = format (0, "--no-pci%c", 0); |
| 1056 | vec_add1 (conf->eal_init_args, tmp); |
| 1057 | } |
Dave Barach | 08602d1 | 2016-06-04 14:10:59 -0400 | [diff] [blame] | 1058 | else if (unformat (input, "poll-sleep %d", &dm->poll_sleep)) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1059 | ; |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1060 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1061 | #define _(a) \ |
| 1062 | else if (unformat(input, #a)) \ |
| 1063 | { \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1064 | tmp = format (0, "--%s%c", #a, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1065 | vec_add1 (conf->eal_init_args, tmp); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1066 | } |
| 1067 | foreach_eal_double_hyphen_predicate_arg |
| 1068 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1069 | #define _(a) \ |
| 1070 | else if (unformat(input, #a " %s", &s)) \ |
| 1071 | { \ |
| 1072 | if (!strncmp(#a, "huge-dir", 8)) \ |
| 1073 | huge_dir = 1; \ |
| 1074 | else if (!strncmp(#a, "file-prefix", 11)) \ |
| 1075 | file_prefix = 1; \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1076 | tmp = format (0, "--%s%c", #a, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1077 | vec_add1 (conf->eal_init_args, tmp); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1078 | vec_add1 (s, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1079 | vec_add1 (conf->eal_init_args, s); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1080 | } |
| 1081 | foreach_eal_double_hyphen_arg |
| 1082 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1083 | #define _(a,b) \ |
| 1084 | else if (unformat(input, #a " %s", &s)) \ |
| 1085 | { \ |
| 1086 | tmp = format (0, "-%s%c", #b, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1087 | vec_add1 (conf->eal_init_args, tmp); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1088 | vec_add1 (s, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1089 | vec_add1 (conf->eal_init_args, s); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1091 | foreach_eal_single_hyphen_arg |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1092 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1093 | #define _(a,b) \ |
| 1094 | else if (unformat(input, #a " %s", &s)) \ |
| 1095 | { \ |
| 1096 | tmp = format (0, "-%s%c", #b, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1097 | vec_add1 (conf->eal_init_args, tmp); \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1098 | vec_add1 (s, 0); \ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1099 | vec_add1 (conf->eal_init_args, s); \ |
| 1100 | conf->a##_set_manually = 1; \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1101 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1102 | foreach_eal_single_hyphen_mandatory_arg |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1103 | #undef _ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1104 | else if (unformat (input, "default")) |
| 1105 | ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1106 | |
Damjan Marion | 4c20e71 | 2016-10-05 09:50:38 +0200 | [diff] [blame] | 1107 | else if (unformat_skip_white_space (input)) |
Damjan Marion | 6144802 | 2016-09-13 10:47:35 +0200 | [diff] [blame] | 1108 | ; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1109 | else |
| 1110 | { |
| 1111 | error = clib_error_return (0, "unknown input `%U'", |
| 1112 | format_unformat_error, input); |
| 1113 | goto done; |
| 1114 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1117 | if (!conf->uio_driver_name) |
| 1118 | conf->uio_driver_name = format (0, "igb_uio%c", 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1119 | |
| 1120 | /* |
| 1121 | * Use 1G huge pages if available. |
| 1122 | */ |
| 1123 | if (!no_huge && !huge_dir) |
| 1124 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1125 | u32 x, *mem_by_socket = 0; |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1126 | uword c = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1127 | u8 use_1g = 1; |
| 1128 | u8 use_2m = 1; |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1129 | u8 less_than_1g = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1130 | int rv; |
| 1131 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1132 | umount (DEFAULT_HUGE_DIR); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1133 | |
| 1134 | /* Process "socket-mem" parameter value */ |
| 1135 | if (vec_len (socket_mem)) |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1136 | { |
| 1137 | unformat_input_t in; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1138 | unformat_init_vector (&in, socket_mem); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1139 | while (unformat_check_input (&in) != UNFORMAT_END_OF_INPUT) |
| 1140 | { |
| 1141 | if (unformat (&in, "%u,", &x)) |
| 1142 | ; |
| 1143 | else if (unformat (&in, "%u", &x)) |
| 1144 | ; |
| 1145 | else if (unformat (&in, ",")) |
| 1146 | x = 0; |
| 1147 | else |
| 1148 | break; |
| 1149 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1150 | vec_add1 (mem_by_socket, x); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1151 | |
| 1152 | if (x > 1023) |
| 1153 | less_than_1g = 0; |
| 1154 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1155 | /* Note: unformat_free vec_frees(in.buffer), aka socket_mem... */ |
| 1156 | unformat_free (&in); |
| 1157 | socket_mem = 0; |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1158 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1159 | else |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1160 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1161 | /* *INDENT-OFF* */ |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1162 | clib_bitmap_foreach (c, tm->cpu_socket_bitmap, ( |
| 1163 | { |
| 1164 | vec_validate(mem_by_socket, c); |
Damjan Marion | a06dfb3 | 2016-06-26 20:16:57 +0200 | [diff] [blame] | 1165 | mem_by_socket[c] = 256; /* default per-socket mem */ |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1166 | } |
| 1167 | )); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1168 | /* *INDENT-ON* */ |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1169 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1170 | |
| 1171 | /* check if available enough 1GB pages for each socket */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1172 | /* *INDENT-OFF* */ |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1173 | clib_bitmap_foreach (c, tm->cpu_socket_bitmap, ( |
| 1174 | { |
Damjan Marion | 20f6441 | 2016-09-27 17:51:13 +0200 | [diff] [blame] | 1175 | int pages_avail, page_size, mem; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1176 | |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1177 | vec_validate(mem_by_socket, c); |
| 1178 | mem = mem_by_socket[c]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1179 | |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1180 | page_size = 1024; |
Damjan Marion | 20f6441 | 2016-09-27 17:51:13 +0200 | [diff] [blame] | 1181 | pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1182 | |
Damjan Marion | 20f6441 | 2016-09-27 17:51:13 +0200 | [diff] [blame] | 1183 | if (pages_avail < 0 || page_size * pages_avail < mem) |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1184 | use_1g = 0; |
| 1185 | |
| 1186 | page_size = 2; |
Damjan Marion | 20f6441 | 2016-09-27 17:51:13 +0200 | [diff] [blame] | 1187 | pages_avail = vlib_sysfs_get_free_hugepages(c, page_size * 1024); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1188 | |
Damjan Marion | 20f6441 | 2016-09-27 17:51:13 +0200 | [diff] [blame] | 1189 | if (pages_avail < 0 || page_size * pages_avail < mem) |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1190 | use_2m = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1191 | })); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1192 | /* *INDENT-ON* */ |
Dave Barach | dd522cb | 2016-08-10 16:56:16 -0400 | [diff] [blame] | 1193 | |
| 1194 | if (mem_by_socket == 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1195 | { |
| 1196 | error = clib_error_return (0, "mem_by_socket NULL"); |
| 1197 | goto done; |
| 1198 | } |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1199 | _vec_len (mem_by_socket) = c + 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1200 | |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1201 | /* regenerate socket_mem string */ |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1202 | vec_foreach_index (x, mem_by_socket) |
| 1203 | socket_mem = format (socket_mem, "%s%u", |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1204 | socket_mem ? "," : "", mem_by_socket[x]); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1205 | socket_mem = format (socket_mem, "%c", 0); |
| 1206 | |
| 1207 | vec_free (mem_by_socket); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1208 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1209 | rv = mkdir (VPP_RUN_DIR, 0755); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1210 | if (rv && errno != EEXIST) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1211 | { |
| 1212 | error = clib_error_return (0, "mkdir '%s' failed errno %d", |
| 1213 | VPP_RUN_DIR, errno); |
| 1214 | goto done; |
| 1215 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1216 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1217 | rv = mkdir (DEFAULT_HUGE_DIR, 0755); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1218 | if (rv && errno != EEXIST) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1219 | { |
| 1220 | error = clib_error_return (0, "mkdir '%s' failed errno %d", |
| 1221 | DEFAULT_HUGE_DIR, errno); |
| 1222 | goto done; |
| 1223 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1224 | |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1225 | if (use_1g && !(less_than_1g && use_2m)) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1226 | { |
| 1227 | rv = |
| 1228 | mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, "pagesize=1G"); |
| 1229 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1230 | else if (use_2m) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1231 | { |
| 1232 | rv = mount ("none", DEFAULT_HUGE_DIR, "hugetlbfs", 0, NULL); |
| 1233 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1234 | else |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1235 | { |
| 1236 | return clib_error_return (0, "not enough free huge pages"); |
| 1237 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1238 | |
| 1239 | if (rv) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1240 | { |
| 1241 | error = clib_error_return (0, "mount failed %d", errno); |
| 1242 | goto done; |
| 1243 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1244 | |
| 1245 | tmp = format (0, "--huge-dir%c", 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1246 | vec_add1 (conf->eal_init_args, tmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1247 | tmp = format (0, "%s%c", DEFAULT_HUGE_DIR, 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1248 | vec_add1 (conf->eal_init_args, tmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1249 | if (!file_prefix) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1250 | { |
| 1251 | tmp = format (0, "--file-prefix%c", 0); |
| 1252 | vec_add1 (conf->eal_init_args, tmp); |
| 1253 | tmp = format (0, "vpp%c", 0); |
| 1254 | vec_add1 (conf->eal_init_args, tmp); |
| 1255 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1258 | vec_free (rte_cmd); |
| 1259 | vec_free (ethname); |
| 1260 | |
| 1261 | if (error) |
| 1262 | return error; |
| 1263 | |
| 1264 | /* I'll bet that -c and -n must be the first and second args... */ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1265 | if (!conf->coremask_set_manually) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1266 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1267 | vlib_thread_registration_t *tr; |
| 1268 | uword *coremask = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1269 | int i; |
| 1270 | |
| 1271 | /* main thread core */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1272 | coremask = clib_bitmap_set (coremask, tm->main_lcore, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1273 | |
| 1274 | for (i = 0; i < vec_len (tm->registrations); i++) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1275 | { |
| 1276 | tr = tm->registrations[i]; |
| 1277 | coremask = clib_bitmap_or (coremask, tr->coremask); |
| 1278 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1279 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1280 | vec_insert (conf->eal_init_args, 2, 1); |
| 1281 | conf->eal_init_args[1] = (u8 *) "-c"; |
Damjan Marion | 14a44d3 | 2016-02-05 23:33:21 +0100 | [diff] [blame] | 1282 | tmp = format (0, "%U%c", format_bitmap_hex, coremask, 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1283 | conf->eal_init_args[2] = tmp; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1284 | clib_bitmap_free (coremask); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1287 | if (!conf->nchannels_set_manually) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1288 | { |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1289 | vec_insert (conf->eal_init_args, 2, 3); |
| 1290 | conf->eal_init_args[3] = (u8 *) "-n"; |
| 1291 | tmp = format (0, "%d", conf->nchannels); |
| 1292 | conf->eal_init_args[4] = tmp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1295 | if (no_pci == 0 && geteuid () == 0) |
| 1296 | dpdk_bind_devices_to_uio (conf); |
Damjan Marion | a42cd34 | 2016-04-13 18:03:20 +0200 | [diff] [blame] | 1297 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1298 | #define _(x) \ |
| 1299 | if (devconf->x == 0 && conf->default_devconf.x > 0) \ |
| 1300 | devconf->x = conf->default_devconf.x ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1301 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1302 | /* *INDENT-OFF* */ |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1303 | pool_foreach (devconf, conf->dev_confs, ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1304 | |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1305 | /* default per-device config items */ |
| 1306 | foreach_dpdk_device_config_item |
| 1307 | |
| 1308 | /* add DPDK EAL whitelist/blacklist entry */ |
| 1309 | if (num_whitelisted > 0 && devconf->is_blacklisted == 0) |
| 1310 | { |
| 1311 | tmp = format (0, "-w%c", 0); |
| 1312 | vec_add1 (conf->eal_init_args, tmp); |
Damjan Marion | c883fa7 | 2016-06-07 21:49:56 +0200 | [diff] [blame] | 1313 | tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1314 | vec_add1 (conf->eal_init_args, tmp); |
| 1315 | } |
| 1316 | else if (num_whitelisted == 0 && devconf->is_blacklisted != 0) |
| 1317 | { |
| 1318 | tmp = format (0, "-b%c", 0); |
| 1319 | vec_add1 (conf->eal_init_args, tmp); |
Damjan Marion | c883fa7 | 2016-06-07 21:49:56 +0200 | [diff] [blame] | 1320 | tmp = format (0, "%U%c", format_vlib_pci_addr, &devconf->pci_addr, 0); |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1321 | vec_add1 (conf->eal_init_args, tmp); |
| 1322 | } |
| 1323 | })); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1324 | /* *INDENT-ON* */ |
Damjan Marion | c68b4cb | 2016-05-25 20:11:33 +0200 | [diff] [blame] | 1325 | |
| 1326 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1327 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1328 | /* set master-lcore */ |
| 1329 | tmp = format (0, "--master-lcore%c", 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1330 | vec_add1 (conf->eal_init_args, tmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1331 | tmp = format (0, "%u%c", tm->main_lcore, 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1332 | vec_add1 (conf->eal_init_args, tmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1333 | |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1334 | /* set socket-mem */ |
| 1335 | tmp = format (0, "--socket-mem%c", 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1336 | vec_add1 (conf->eal_init_args, tmp); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1337 | tmp = format (0, "%s%c", socket_mem, 0); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1338 | vec_add1 (conf->eal_init_args, tmp); |
Damjan Marion | 7a2a378 | 2016-04-15 20:24:55 +0200 | [diff] [blame] | 1339 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1340 | /* NULL terminate the "argv" vector, in case of stupidity */ |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1341 | vec_add1 (conf->eal_init_args, 0); |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1342 | _vec_len (conf->eal_init_args) -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1343 | |
| 1344 | /* Set up DPDK eal and packet mbuf pool early. */ |
| 1345 | |
| 1346 | log_level = (CLIB_DEBUG > 0) ? RTE_LOG_DEBUG : RTE_LOG_NOTICE; |
| 1347 | |
| 1348 | rte_set_log_level (log_level); |
| 1349 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1350 | vm = vlib_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1351 | |
Damjan Marion | d8ff0e1 | 2016-02-16 12:29:57 +0100 | [diff] [blame] | 1352 | /* make copy of args as rte_eal_init tends to mess up with arg array */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1353 | for (i = 1; i < vec_len (conf->eal_init_args); i++) |
| 1354 | conf->eal_init_args_str = format (conf->eal_init_args_str, "%s ", |
| 1355 | conf->eal_init_args[i]); |
Damjan Marion | d8ff0e1 | 2016-02-16 12:29:57 +0100 | [diff] [blame] | 1356 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1357 | ret = |
| 1358 | rte_eal_init (vec_len (conf->eal_init_args), |
| 1359 | (char **) conf->eal_init_args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1360 | |
| 1361 | /* lazy umount hugepages */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1362 | umount2 (DEFAULT_HUGE_DIR, MNT_DETACH); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1363 | |
| 1364 | if (ret < 0) |
| 1365 | return clib_error_return (0, "rte_eal_init returned %d", ret); |
| 1366 | |
Sean Hope | 98efd02 | 2016-02-22 15:21:31 -0500 | [diff] [blame] | 1367 | /* Dump the physical memory layout prior to creating the mbuf_pool */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1368 | fprintf (stdout, "DPDK physical memory layout:\n"); |
| 1369 | rte_dump_physmem_layout (stdout); |
Sean Hope | 98efd02 | 2016-02-22 15:21:31 -0500 | [diff] [blame] | 1370 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1371 | /* main thread 1st */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1372 | error = vlib_buffer_pool_create (vm, conf->num_mbufs, rte_socket_id ()); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1373 | if (error) |
| 1374 | return error; |
| 1375 | |
| 1376 | for (i = 0; i < RTE_MAX_LCORE; i++) |
| 1377 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1378 | error = vlib_buffer_pool_create (vm, conf->num_mbufs, |
| 1379 | rte_lcore_to_socket_id (i)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1380 | if (error) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1381 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1384 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1385 | return error; |
| 1386 | } |
| 1387 | |
| 1388 | VLIB_CONFIG_FUNCTION (dpdk_config, "dpdk"); |
| 1389 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1390 | void |
| 1391 | dpdk_update_link_state (dpdk_device_t * xd, f64 now) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1392 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1393 | vnet_main_t *vnm = vnet_get_main (); |
| 1394 | struct rte_eth_link prev_link = xd->link; |
| 1395 | u32 hw_flags = 0; |
| 1396 | u8 hw_flags_chg = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1397 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1398 | /* only update link state for PMD interfaces */ |
Damjan Marion | 5643170 | 2016-09-19 13:18:09 +0200 | [diff] [blame] | 1399 | if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1400 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1401 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1402 | xd->time_last_link_update = now ? now : xd->time_last_link_update; |
| 1403 | memset (&xd->link, 0, sizeof (xd->link)); |
| 1404 | rte_eth_link_get_nowait (xd->device_index, &xd->link); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1405 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1406 | if (LINK_STATE_ELOGS) |
| 1407 | { |
| 1408 | vlib_main_t *vm = vlib_get_main (); |
| 1409 | ELOG_TYPE_DECLARE (e) = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1410 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1411 | .format = |
| 1412 | "update-link-state: sw_if_index %d, admin_up %d," |
| 1413 | "old link_state %d new link_state %d",.format_args = "i4i1i1i1",}; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1414 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1415 | struct |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1416 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1417 | u32 sw_if_index; |
| 1418 | u8 admin_up; |
| 1419 | u8 old_link_state; |
| 1420 | u8 new_link_state; |
| 1421 | } *ed; |
| 1422 | ed = ELOG_DATA (&vm->elog_main, e); |
| 1423 | ed->sw_if_index = xd->vlib_sw_if_index; |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 1424 | ed->admin_up = (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) != 0; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1425 | ed->old_link_state = (u8) |
| 1426 | vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index); |
| 1427 | ed->new_link_state = (u8) xd->link.link_status; |
| 1428 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1429 | |
Damjan Marion | b28e498 | 2016-08-22 22:34:38 +0200 | [diff] [blame] | 1430 | if ((xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP) && |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1431 | ((xd->link.link_status != 0) ^ |
| 1432 | vnet_hw_interface_is_link_up (vnm, xd->vlib_hw_if_index))) |
| 1433 | { |
| 1434 | hw_flags_chg = 1; |
| 1435 | hw_flags |= (xd->link.link_status ? VNET_HW_INTERFACE_FLAG_LINK_UP : 0); |
| 1436 | } |
| 1437 | |
| 1438 | if (hw_flags_chg || (xd->link.link_duplex != prev_link.link_duplex)) |
| 1439 | { |
| 1440 | hw_flags_chg = 1; |
| 1441 | switch (xd->link.link_duplex) |
| 1442 | { |
| 1443 | case ETH_LINK_HALF_DUPLEX: |
| 1444 | hw_flags |= VNET_HW_INTERFACE_FLAG_HALF_DUPLEX; |
| 1445 | break; |
| 1446 | case ETH_LINK_FULL_DUPLEX: |
| 1447 | hw_flags |= VNET_HW_INTERFACE_FLAG_FULL_DUPLEX; |
| 1448 | break; |
| 1449 | default: |
| 1450 | break; |
| 1451 | } |
| 1452 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1453 | if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed)) |
| 1454 | { |
| 1455 | hw_flags_chg = 1; |
| 1456 | switch (xd->link.link_speed) |
| 1457 | { |
| 1458 | case ETH_SPEED_NUM_10M: |
| 1459 | hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M; |
| 1460 | break; |
| 1461 | case ETH_SPEED_NUM_100M: |
| 1462 | hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M; |
| 1463 | break; |
| 1464 | case ETH_SPEED_NUM_1G: |
| 1465 | hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G; |
| 1466 | break; |
| 1467 | case ETH_SPEED_NUM_10G: |
| 1468 | hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G; |
| 1469 | break; |
| 1470 | case ETH_SPEED_NUM_40G: |
| 1471 | hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G; |
| 1472 | break; |
| 1473 | case 0: |
| 1474 | break; |
| 1475 | default: |
| 1476 | clib_warning ("unknown link speed %d", xd->link.link_speed); |
| 1477 | break; |
| 1478 | } |
| 1479 | } |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1480 | if (hw_flags_chg) |
| 1481 | { |
| 1482 | if (LINK_STATE_ELOGS) |
| 1483 | { |
| 1484 | vlib_main_t *vm = vlib_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1485 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1486 | ELOG_TYPE_DECLARE (e) = |
| 1487 | { |
| 1488 | .format = |
| 1489 | "update-link-state: sw_if_index %d, new flags %d",.format_args |
| 1490 | = "i4i4",}; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1491 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1492 | struct |
| 1493 | { |
| 1494 | u32 sw_if_index; |
| 1495 | u32 flags; |
| 1496 | } *ed; |
| 1497 | ed = ELOG_DATA (&vm->elog_main, e); |
| 1498 | ed->sw_if_index = xd->vlib_sw_if_index; |
| 1499 | ed->flags = hw_flags; |
| 1500 | } |
| 1501 | vnet_hw_interface_set_flags (vnm, xd->vlib_hw_if_index, hw_flags); |
| 1502 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | static uword |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1506 | dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1507 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1508 | clib_error_t *error; |
| 1509 | vnet_main_t *vnm = vnet_get_main (); |
| 1510 | dpdk_main_t *dm = &dpdk_main; |
| 1511 | ethernet_main_t *em = ðernet_main; |
| 1512 | dpdk_device_t *xd; |
| 1513 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1514 | int i; |
| 1515 | |
| 1516 | error = dpdk_lib_init (dm); |
| 1517 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1518 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1519 | * Turn on the input node if we found some devices to drive |
| 1520 | * and we're not running worker threads or i/o threads |
| 1521 | */ |
| 1522 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1523 | if (error == 0 && vec_len (dm->devices) > 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1524 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1525 | if (tm->n_vlib_mains == 1) |
| 1526 | vlib_node_set_state (vm, dpdk_input_node.index, |
| 1527 | VLIB_NODE_STATE_POLLING); |
| 1528 | else |
| 1529 | for (i = 0; i < tm->n_vlib_mains; i++) |
| 1530 | if (vec_len (dm->devices_by_cpu[i]) > 0) |
| 1531 | vlib_node_set_state (vlib_mains[i], dpdk_input_node.index, |
| 1532 | VLIB_NODE_STATE_POLLING); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | if (error) |
| 1536 | clib_error_report (error); |
| 1537 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1538 | tm->worker_thread_release = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1539 | |
| 1540 | f64 now = vlib_time_now (vm); |
| 1541 | vec_foreach (xd, dm->devices) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1542 | { |
| 1543 | dpdk_update_link_state (xd, now); |
| 1544 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1545 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1546 | { |
| 1547 | /* |
| 1548 | * Extra set up for bond interfaces: |
| 1549 | * 1. Setup MACs for bond interfaces and their slave links which was set |
| 1550 | * in dpdk_port_setup() but needs to be done again here to take effect. |
| 1551 | * 2. Set up info for bond interface related CLI support. |
| 1552 | */ |
| 1553 | int nports = rte_eth_dev_count (); |
| 1554 | if (nports > 0) |
| 1555 | { |
| 1556 | for (i = 0; i < nports; i++) |
| 1557 | { |
| 1558 | struct rte_eth_dev_info dev_info; |
| 1559 | rte_eth_dev_info_get (i, &dev_info); |
| 1560 | if (!dev_info.driver_name) |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 1561 | #if RTE_VERSION < RTE_VERSION_NUM(16, 11, 0, 0) |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 1562 | dev_info.driver_name = dev_info.pci_dev->driver->name; |
Damjan Marion | 3916227 | 2016-10-25 14:54:38 +0200 | [diff] [blame] | 1563 | #else |
| 1564 | dev_info.driver_name = dev_info.pci_dev->driver->driver.name; |
| 1565 | #endif |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1566 | ASSERT (dev_info.driver_name); |
| 1567 | if (strncmp (dev_info.driver_name, "rte_bond_pmd", 12) == 0) |
| 1568 | { |
| 1569 | u8 addr[6]; |
| 1570 | u8 slink[16]; |
| 1571 | int nlink = rte_eth_bond_slaves_get (i, slink, 16); |
| 1572 | if (nlink > 0) |
| 1573 | { |
| 1574 | vnet_hw_interface_t *bhi; |
| 1575 | ethernet_interface_t *bei; |
| 1576 | int rv; |
Damjan Marion | b022cd1 | 2016-08-16 13:25:59 +0200 | [diff] [blame] | 1577 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1578 | /* Get MAC of 1st slave link */ |
| 1579 | rte_eth_macaddr_get (slink[0], |
| 1580 | (struct ether_addr *) addr); |
| 1581 | /* Set MAC of bounded interface to that of 1st slave link */ |
| 1582 | rv = |
| 1583 | rte_eth_bond_mac_address_set (i, |
| 1584 | (struct ether_addr *) |
| 1585 | addr); |
| 1586 | if (rv < 0) |
| 1587 | clib_warning ("Failed to set MAC address"); |
Damjan Marion | b022cd1 | 2016-08-16 13:25:59 +0200 | [diff] [blame] | 1588 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1589 | /* Populate MAC of bonded interface in VPP hw tables */ |
| 1590 | bhi = |
| 1591 | vnet_get_hw_interface (vnm, |
| 1592 | dm->devices[i].vlib_hw_if_index); |
| 1593 | bei = |
| 1594 | pool_elt_at_index (em->interfaces, bhi->hw_instance); |
| 1595 | clib_memcpy (bhi->hw_address, addr, 6); |
| 1596 | clib_memcpy (bei->address, addr, 6); |
| 1597 | /* Init l3 packet size allowed on bonded interface */ |
Steve Shin | bf1fa7f | 2016-09-07 08:25:04 -0700 | [diff] [blame] | 1598 | bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1599 | bhi->max_l3_packet_bytes[VLIB_RX] = |
| 1600 | bhi->max_l3_packet_bytes[VLIB_TX] = |
| 1601 | ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t); |
| 1602 | while (nlink >= 1) |
| 1603 | { /* for all slave links */ |
| 1604 | int slave = slink[--nlink]; |
| 1605 | dpdk_device_t *sdev = &dm->devices[slave]; |
| 1606 | vnet_hw_interface_t *shi; |
| 1607 | vnet_sw_interface_t *ssi; |
| 1608 | /* Add MAC to all slave links except the first one */ |
| 1609 | if (nlink) |
| 1610 | rte_eth_dev_mac_addr_add (slave, |
| 1611 | (struct ether_addr *) |
| 1612 | addr, 0); |
| 1613 | /* Set slaves bitmap for bonded interface */ |
| 1614 | bhi->bond_info = |
| 1615 | clib_bitmap_set (bhi->bond_info, |
| 1616 | sdev->vlib_hw_if_index, 1); |
| 1617 | /* Set slave link flags on slave interface */ |
| 1618 | shi = |
| 1619 | vnet_get_hw_interface (vnm, sdev->vlib_hw_if_index); |
| 1620 | ssi = |
| 1621 | vnet_get_sw_interface (vnm, sdev->vlib_sw_if_index); |
| 1622 | shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE; |
| 1623 | ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE; |
Steve Shin | bf1fa7f | 2016-09-07 08:25:04 -0700 | [diff] [blame] | 1624 | |
| 1625 | /* Set l3 packet size allowed as the lowest of slave */ |
| 1626 | if (bhi->max_l3_packet_bytes[VLIB_RX] > |
| 1627 | shi->max_l3_packet_bytes[VLIB_RX]) |
| 1628 | bhi->max_l3_packet_bytes[VLIB_RX] = |
| 1629 | bhi->max_l3_packet_bytes[VLIB_TX] = |
| 1630 | shi->max_l3_packet_bytes[VLIB_RX]; |
| 1631 | |
| 1632 | /* Set max packet size allowed as the lowest of slave */ |
| 1633 | if (bhi->max_packet_bytes > shi->max_packet_bytes) |
| 1634 | bhi->max_packet_bytes = shi->max_packet_bytes; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1635 | } |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | } |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 1641 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1642 | while (1) |
| 1643 | { |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1644 | /* |
| 1645 | * check each time through the loop in case intervals are changed |
| 1646 | */ |
| 1647 | f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ? |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1648 | dm->link_state_poll_interval : dm->stat_poll_interval; |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1649 | |
| 1650 | vlib_process_wait_for_event_or_clock (vm, min_wait); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1651 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1652 | if (dpdk_get_admin_up_down_in_progress ()) |
| 1653 | /* skip the poll if an admin up down is in progress (on any interface) */ |
| 1654 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1655 | |
| 1656 | vec_foreach (xd, dm->devices) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1657 | { |
| 1658 | f64 now = vlib_time_now (vm); |
| 1659 | if ((now - xd->time_last_stats_update) >= dm->stat_poll_interval) |
| 1660 | dpdk_update_counters (xd, now); |
| 1661 | if ((now - xd->time_last_link_update) >= dm->link_state_poll_interval) |
| 1662 | dpdk_update_link_state (xd, now); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1663 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1664 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1667 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1670 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1671 | VLIB_REGISTER_NODE (dpdk_process_node,static) = { |
| 1672 | .function = dpdk_process, |
| 1673 | .type = VLIB_NODE_TYPE_PROCESS, |
| 1674 | .name = "dpdk-process", |
| 1675 | .process_log2_n_stack_bytes = 17, |
| 1676 | }; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1677 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1678 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1679 | int |
| 1680 | dpdk_set_stat_poll_interval (f64 interval) |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1681 | { |
| 1682 | if (interval < DPDK_MIN_STATS_POLL_INTERVAL) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1683 | return (VNET_API_ERROR_INVALID_VALUE); |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1684 | |
| 1685 | dpdk_main.stat_poll_interval = interval; |
| 1686 | |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1690 | int |
| 1691 | dpdk_set_link_state_poll_interval (f64 interval) |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1692 | { |
| 1693 | if (interval < DPDK_MIN_LINK_POLL_INTERVAL) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1694 | return (VNET_API_ERROR_INVALID_VALUE); |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1695 | |
| 1696 | dpdk_main.link_state_poll_interval = interval; |
| 1697 | |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1701 | clib_error_t * |
| 1702 | dpdk_init (vlib_main_t * vm) |
| 1703 | { |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1704 | dpdk_main_t *dm = &dpdk_main; |
| 1705 | vlib_node_t *ei; |
| 1706 | clib_error_t *error = 0; |
| 1707 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1708 | |
| 1709 | /* verify that structs are cacheline aligned */ |
Damjan Marion | 3b906b0 | 2016-11-01 15:16:30 +0100 | [diff] [blame] | 1710 | STATIC_ASSERT (offsetof (dpdk_device_t, cacheline0) == 0, |
| 1711 | "Cache line marker must be 1st element in dpdk_device_t"); |
| 1712 | STATIC_ASSERT (offsetof (dpdk_device_t, cacheline1) == |
| 1713 | CLIB_CACHE_LINE_BYTES, |
| 1714 | "Data in cache line 0 is bigger than cache line size"); |
| 1715 | STATIC_ASSERT (offsetof (dpdk_worker_t, cacheline0) == 0, |
| 1716 | "Cache line marker must be 1st element in dpdk_worker_t"); |
| 1717 | STATIC_ASSERT (offsetof (frame_queue_trace_t, cacheline0) == 0, |
| 1718 | "Cache line marker must be 1st element in frame_queue_trace_t"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1719 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1720 | dm->vlib_main = vm; |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1721 | dm->vnet_main = vnet_get_main (); |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1722 | dm->conf = &dpdk_config_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1723 | |
| 1724 | ei = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); |
| 1725 | if (ei == 0) |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1726 | return clib_error_return (0, "ethernet-input node AWOL"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1727 | |
| 1728 | dm->ethernet_input_node_index = ei->index; |
| 1729 | |
Damjan Marion | 64ae669 | 2016-05-25 18:40:13 +0200 | [diff] [blame] | 1730 | dm->conf->nchannels = 4; |
| 1731 | dm->conf->num_mbufs = dm->conf->num_mbufs ? dm->conf->num_mbufs : NB_MBUF; |
| 1732 | vec_add1 (dm->conf->eal_init_args, (u8 *) "vnet"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1733 | |
| 1734 | dm->dpdk_device_by_kni_port_id = hash_create (0, sizeof (uword)); |
| 1735 | dm->vu_sw_if_index_by_listener_fd = hash_create (0, sizeof (uword)); |
| 1736 | dm->vu_sw_if_index_by_sock_fd = hash_create (0, sizeof (uword)); |
| 1737 | |
| 1738 | /* $$$ use n_thread_stacks since it's known-good at this point */ |
| 1739 | vec_validate (dm->recycle, tm->n_thread_stacks - 1); |
| 1740 | |
| 1741 | /* initialize EFD (early fast discard) default settings */ |
| 1742 | dm->efd.enabled = DPDK_EFD_DISABLED; |
| 1743 | dm->efd.queue_hi_thresh = ((DPDK_EFD_DEFAULT_DEVICE_QUEUE_HI_THRESH_PCT * |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1744 | DPDK_NB_RX_DESC_10GE) / 100); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1745 | dm->efd.consec_full_frames_hi_thresh = |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1746 | DPDK_EFD_DEFAULT_CONSEC_FULL_FRAMES_HI_THRESH; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1747 | |
Dave Barach | d81566f | 2016-02-15 11:34:13 -0500 | [diff] [blame] | 1748 | /* Default vlib_buffer_t flags, DISABLES tcp/udp checksumming... */ |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1749 | dm->buffer_flags_template = |
| 1750 | (VLIB_BUFFER_TOTAL_LENGTH_VALID |
| 1751 | | IP_BUFFER_L4_CHECKSUM_COMPUTED | IP_BUFFER_L4_CHECKSUM_CORRECT); |
Dave Barach | d81566f | 2016-02-15 11:34:13 -0500 | [diff] [blame] | 1752 | |
Bud Grise | 02301ef | 2016-02-24 16:09:05 -0500 | [diff] [blame] | 1753 | dm->stat_poll_interval = DPDK_STATS_POLL_INTERVAL; |
| 1754 | dm->link_state_poll_interval = DPDK_LINK_POLL_INTERVAL; |
| 1755 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1756 | /* init CLI */ |
| 1757 | if ((error = vlib_call_init_function (vm, dpdk_cli_init))) |
| 1758 | return error; |
| 1759 | |
| 1760 | return error; |
| 1761 | } |
| 1762 | |
| 1763 | VLIB_INIT_FUNCTION (dpdk_init); |
| 1764 | |
Damjan Marion | 2566567 | 2016-08-16 18:56:08 +0200 | [diff] [blame] | 1765 | |
| 1766 | /* |
| 1767 | * fd.io coding-style-patch-verification: ON |
| 1768 | * |
| 1769 | * Local Variables: |
| 1770 | * eval: (c-set-style "gnu") |
| 1771 | * End: |
| 1772 | */ |