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