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