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