Fix tcp tx buffer allocation
[vpp.git] / src / plugins / dpdk / device / cli.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/xxhash.h>
20
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
23 #include <vnet/classify/vnet_classify.h>
24 #include <vnet/mpls/packet.h>
25
26 #include <dpdk/device/dpdk_priv.h>
27
28 /**
29  * @file
30  * @brief CLI for DPDK Abstraction Layer and pcap Tx Trace.
31  *
32  * This file contains the source code for CLI for DPDK
33  * Abstraction Layer and pcap Tx Trace.
34  */
35
36
37 static clib_error_t *
38 get_hqos (u32 hw_if_index, u32 subport_id, dpdk_device_t ** xd,
39           dpdk_device_config_t ** devconf)
40 {
41   dpdk_main_t *dm = &dpdk_main;
42   vnet_hw_interface_t *hw;
43   struct rte_eth_dev_info dev_info;
44   uword *p = 0;
45   clib_error_t *error = NULL;
46
47
48   if (hw_if_index == (u32) ~ 0)
49     {
50       error = clib_error_return (0, "please specify valid interface name");
51       goto done;
52     }
53
54   if (subport_id != 0)
55     {
56       error = clib_error_return (0, "Invalid subport");
57       goto done;
58     }
59
60   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
61   *xd = vec_elt_at_index (dm->devices, hw->dev_instance);
62
63   rte_eth_dev_info_get ((*xd)->device_index, &dev_info);
64   if (dev_info.pci_dev)
65     {                           /* bonded interface has no pci info */
66       vlib_pci_addr_t pci_addr;
67
68       pci_addr.domain = dev_info.pci_dev->addr.domain;
69       pci_addr.bus = dev_info.pci_dev->addr.bus;
70       pci_addr.slot = dev_info.pci_dev->addr.devid;
71       pci_addr.function = dev_info.pci_dev->addr.function;
72
73       p =
74         hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
75     }
76
77   if (p)
78     (*devconf) = pool_elt_at_index (dm->conf->dev_confs, p[0]);
79   else
80     (*devconf) = &dm->conf->default_devconf;
81
82 done:
83   return error;
84 }
85
86 static clib_error_t *
87 pcap_trace_command_fn (vlib_main_t * vm,
88                        unformat_input_t * input, vlib_cli_command_t * cmd)
89 {
90 #define PCAP_DEF_PKT_TO_CAPTURE (100)
91
92   unformat_input_t _line_input, *line_input = &_line_input;
93   dpdk_main_t *dm = &dpdk_main;
94   u8 *filename;
95   u8 *chroot_filename = 0;
96   u32 max = 0;
97   int enabled = 0;
98   int errorFlag = 0;
99   clib_error_t *error = 0;
100
101   /* Get a line of input. */
102   if (!unformat_user (input, unformat_line_input, line_input))
103     return 0;
104
105   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
106     {
107       if (unformat (line_input, "on"))
108         {
109           if (dm->tx_pcap_enable == 0)
110             {
111               enabled = 1;
112             }
113           else
114             {
115               vlib_cli_output (vm, "pcap tx capture already on...");
116               errorFlag = 1;
117               break;
118             }
119         }
120       else if (unformat (line_input, "off"))
121         {
122           if (dm->tx_pcap_enable)
123             {
124               vlib_cli_output (vm, "captured %d pkts...",
125                                dm->pcap_main.n_packets_captured + 1);
126               if (dm->pcap_main.n_packets_captured)
127                 {
128                   dm->pcap_main.n_packets_to_capture =
129                     dm->pcap_main.n_packets_captured;
130                   error = pcap_write (&dm->pcap_main);
131                   if (error)
132                     clib_error_report (error);
133                   else
134                     vlib_cli_output (vm, "saved to %s...", dm->pcap_filename);
135                 }
136
137               dm->tx_pcap_enable = 0;
138             }
139           else
140             {
141               vlib_cli_output (vm, "pcap tx capture already off...");
142               errorFlag = 1;
143               break;
144             }
145         }
146       else if (unformat (line_input, "max %d", &max))
147         {
148           if (dm->tx_pcap_enable)
149             {
150               vlib_cli_output (vm,
151                                "can't change max value while pcap tx capture active...");
152               errorFlag = 1;
153               break;
154             }
155         }
156       else if (unformat (line_input, "intfc %U",
157                          unformat_vnet_sw_interface, dm->vnet_main,
158                          &dm->pcap_sw_if_index))
159         ;
160
161       else if (unformat (line_input, "intfc any"))
162         {
163           dm->pcap_sw_if_index = 0;
164         }
165       else if (unformat (line_input, "file %s", &filename))
166         {
167           if (dm->tx_pcap_enable)
168             {
169               vlib_cli_output (vm,
170                                "can't change file while pcap tx capture active...");
171               errorFlag = 1;
172               break;
173             }
174
175           /* Brain-police user path input */
176           if (strstr ((char *) filename, "..")
177               || index ((char *) filename, '/'))
178             {
179               vlib_cli_output (vm, "illegal characters in filename '%s'",
180                                filename);
181               vlib_cli_output (vm,
182                                "Hint: Only filename, do not enter directory structure.");
183               vec_free (filename);
184               errorFlag = 1;
185               break;
186             }
187
188           chroot_filename = format (0, "/tmp/%s%c", filename, 0);
189           vec_free (filename);
190         }
191       else if (unformat (line_input, "status"))
192         {
193           if (dm->pcap_sw_if_index == 0)
194             {
195               vlib_cli_output (vm, "max is %d for any interface to file %s",
196                                dm->
197                                pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
198                                : PCAP_DEF_PKT_TO_CAPTURE,
199                                dm->
200                                pcap_filename ? dm->pcap_filename : (u8 *)
201                                "/tmp/vpe.pcap");
202             }
203           else
204             {
205               vlib_cli_output (vm, "max is %d for interface %U to file %s",
206                                dm->
207                                pcap_pkts_to_capture ? dm->pcap_pkts_to_capture
208                                : PCAP_DEF_PKT_TO_CAPTURE,
209                                format_vnet_sw_if_index_name, dm->vnet_main,
210                                dm->pcap_sw_if_index,
211                                dm->
212                                pcap_filename ? dm->pcap_filename : (u8 *)
213                                "/tmp/vpe.pcap");
214             }
215
216           if (dm->tx_pcap_enable == 0)
217             {
218               vlib_cli_output (vm, "pcap tx capture is off...");
219             }
220           else
221             {
222               vlib_cli_output (vm, "pcap tx capture is on: %d of %d pkts...",
223                                dm->pcap_main.n_packets_captured,
224                                dm->pcap_main.n_packets_to_capture);
225             }
226           break;
227         }
228
229       else
230         {
231           error = clib_error_return (0, "unknown input `%U'",
232                                      format_unformat_error, line_input);
233           errorFlag = 1;
234           break;
235         }
236     }
237   unformat_free (line_input);
238
239
240   if (errorFlag == 0)
241     {
242       /* Since no error, save configured values. */
243       if (chroot_filename)
244         {
245           if (dm->pcap_filename)
246             vec_free (dm->pcap_filename);
247           vec_add1 (chroot_filename, 0);
248           dm->pcap_filename = chroot_filename;
249         }
250
251       if (max)
252         dm->pcap_pkts_to_capture = max;
253
254
255       if (enabled)
256         {
257           if (dm->pcap_filename == 0)
258             dm->pcap_filename = format (0, "/tmp/vpe.pcap%c", 0);
259
260           memset (&dm->pcap_main, 0, sizeof (dm->pcap_main));
261           dm->pcap_main.file_name = (char *) dm->pcap_filename;
262           dm->pcap_main.n_packets_to_capture = PCAP_DEF_PKT_TO_CAPTURE;
263           if (dm->pcap_pkts_to_capture)
264             dm->pcap_main.n_packets_to_capture = dm->pcap_pkts_to_capture;
265
266           dm->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
267           dm->tx_pcap_enable = 1;
268           vlib_cli_output (vm, "pcap tx capture on...");
269         }
270     }
271   else if (chroot_filename)
272     vec_free (chroot_filename);
273
274
275   return error;
276 }
277
278 /*?
279  * This command is used to start or stop a packet capture, or show
280  * the status of packet capture.
281  *
282  * This command has the following optional parameters:
283  *
284  * - <b>on|off</b> - Used to start or stop a packet capture.
285  *
286  * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
287  *   of packets have been received, buffer is flushed to file. Once another
288  *   '<em>nn</em>' number of packets have been received, buffer is flushed
289  *   to file, overwriting previous write. If not entered, value defaults
290  *   to 100. Can only be updated if packet capture is off.
291  *
292  * - <b>intfc <interface>|any</b> - Used to specify a given interface,
293  *   or use '<em>any</em>' to run packet capture on all interfaces.
294  *   '<em>any</em>' is the default if not provided. Settings from a previous
295  *   packet capture are preserved, so '<em>any</em>' can be used to reset
296  *   the interface setting.
297  *
298  * - <b>file <name></b> - Used to specify the output filename. The file will
299  *   be placed in the '<em>/tmp</em>' directory, so only the filename is
300  *   supported. Directory should not be entered. If file already exists, file
301  *   will be overwritten. If no filename is provided, '<em>/tmp/vpe.pcap</em>'
302  *   will be used. Can only be updated if packet capture is off.
303  *
304  * - <b>status</b> - Displays the current status and configured attributes
305  *   associated with a packet capture. If packet capture is in progress,
306  *   '<em>status</em>' also will return the number of packets currently in
307  *   the local buffer. All additional attributes entered on command line
308  *   with '<em>status</em>' will be ingnored and not applied.
309  *
310  * @cliexpar
311  * Example of how to display the status of a tx packet capture when off:
312  * @cliexstart{pcap tx trace status}
313  * max is 100, for any interface to file /tmp/vpe.pcap
314  * pcap tx capture is off...
315  * @cliexend
316  * Example of how to start a tx packet capture:
317  * @cliexstart{pcap tx trace on max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
318  * pcap tx capture on...
319  * @cliexend
320  * Example of how to display the status of a tx packet capture in progress:
321  * @cliexstart{pcap tx trace status}
322  * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
323  * pcap tx capture is on: 20 of 35 pkts...
324  * @cliexend
325  * Example of how to stop a tx packet capture:
326  * @cliexstart{vppctl pcap tx trace off}
327  * captured 21 pkts...
328  * saved to /tmp/vppTest.pcap...
329  * @cliexend
330 ?*/
331 /* *INDENT-OFF* */
332 VLIB_CLI_COMMAND (pcap_trace_command, static) = {
333     .path = "pcap tx trace",
334     .short_help =
335     "pcap tx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
336     .function = pcap_trace_command_fn,
337 };
338 /* *INDENT-ON* */
339
340
341 static clib_error_t *
342 show_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
343                   vlib_cli_command_t * cmd)
344 {
345   struct rte_mempool *rmp;
346   int i;
347
348   for (i = 0; i < vec_len (dpdk_main.pktmbuf_pools); i++)
349     {
350       rmp = dpdk_main.pktmbuf_pools[i];
351       if (rmp)
352         {
353           unsigned count = rte_mempool_avail_count (rmp);
354           unsigned free_count = rte_mempool_in_use_count (rmp);
355
356           vlib_cli_output (vm,
357                            "name=\"%s\"  available = %7d allocated = %7d total = %7d\n",
358                            rmp->name, (u32) count, (u32) free_count,
359                            (u32) (count + free_count));
360           rte_mempool_dump (stderr, rmp);
361         }
362       else
363         {
364           vlib_cli_output (vm, "rte_mempool is NULL (!)\n");
365         }
366     }
367   return 0;
368 }
369
370 /*?
371  * This command displays statistics of each DPDK mempool.
372  *
373  * @cliexpar
374  * Example of how to display DPDK buffer data:
375  * @cliexstart{show dpdk buffer}
376  * name="mbuf_pool_socket0"  available =   15104 allocated =    1280 total =   16384
377  * @cliexend
378 ?*/
379 /* *INDENT-OFF* */
380 VLIB_CLI_COMMAND (cmd_show_dpdk_bufferr,static) = {
381     .path = "show dpdk buffer",
382     .short_help = "show dpdk buffer",
383     .function = show_dpdk_buffer,
384     .is_mp_safe = 1,
385 };
386 /* *INDENT-ON* */
387
388 static clib_error_t *
389 test_dpdk_buffer (vlib_main_t * vm, unformat_input_t * input,
390                   vlib_cli_command_t * cmd)
391 {
392   static u32 *allocated_buffers;
393   u32 n_alloc = 0;
394   u32 n_free = 0;
395   u32 first, actual_alloc;
396
397   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
398     {
399       if (unformat (input, "allocate %d", &n_alloc))
400         ;
401       else if (unformat (input, "free %d", &n_free))
402         ;
403       else
404         break;
405     }
406
407   if (n_free)
408     {
409       if (vec_len (allocated_buffers) < n_free)
410         return clib_error_return (0, "Can't free %d, only %d allocated",
411                                   n_free, vec_len (allocated_buffers));
412
413       first = vec_len (allocated_buffers) - n_free;
414       vlib_buffer_free (vm, allocated_buffers + first, n_free);
415       _vec_len (allocated_buffers) = first;
416     }
417   if (n_alloc)
418     {
419       first = vec_len (allocated_buffers);
420       vec_validate (allocated_buffers,
421                     vec_len (allocated_buffers) + n_alloc - 1);
422
423       actual_alloc = vlib_buffer_alloc (vm, allocated_buffers + first,
424                                         n_alloc);
425       _vec_len (allocated_buffers) = first + actual_alloc;
426
427       if (actual_alloc < n_alloc)
428         vlib_cli_output (vm, "WARNING: only allocated %d buffers",
429                          actual_alloc);
430     }
431
432   vlib_cli_output (vm, "Currently %d buffers allocated",
433                    vec_len (allocated_buffers));
434
435   if (allocated_buffers && vec_len (allocated_buffers) == 0)
436     vec_free (allocated_buffers);
437
438   return 0;
439 }
440
441 /*?
442  * This command tests the allocation and freeing of DPDK buffers.
443  * If both '<em>allocate</em>' and '<em>free</em>' are entered on the
444  * same command, the '<em>free</em>' is executed first. If no
445  * parameters are provided, this command display how many DPDK buffers
446  * the test command has allocated.
447  *
448  * @cliexpar
449  * @parblock
450  *
451  * Example of how to display how many DPDK buffer test command has allcoated:
452  * @cliexstart{test dpdk buffer}
453  * Currently 0 buffers allocated
454  * @cliexend
455  *
456  * Example of how to allocate DPDK buffers using the test command:
457  * @cliexstart{test dpdk buffer allocate 10}
458  * Currently 10 buffers allocated
459  * @cliexend
460  *
461  * Example of how to free DPDK buffers allocated by the test command:
462  * @cliexstart{test dpdk buffer free 10}
463  * Currently 0 buffers allocated
464  * @cliexend
465  * @endparblock
466 ?*/
467 /* *INDENT-OFF* */
468 VLIB_CLI_COMMAND (cmd_test_dpdk_buffer,static) = {
469     .path = "test dpdk buffer",
470     .short_help = "test dpdk buffer [allocate <nn>] [free <nn>]",
471     .function = test_dpdk_buffer,
472     .is_mp_safe = 1,
473 };
474 /* *INDENT-ON* */
475
476 static clib_error_t *
477 set_dpdk_if_desc (vlib_main_t * vm, unformat_input_t * input,
478                   vlib_cli_command_t * cmd)
479 {
480   unformat_input_t _line_input, *line_input = &_line_input;
481   dpdk_main_t *dm = &dpdk_main;
482   vnet_hw_interface_t *hw;
483   dpdk_device_t *xd;
484   u32 hw_if_index = (u32) ~ 0;
485   u32 nb_rx_desc = (u32) ~ 0;
486   u32 nb_tx_desc = (u32) ~ 0;
487   clib_error_t *error = NULL;
488
489   if (!unformat_user (input, unformat_line_input, line_input))
490     return 0;
491
492   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
493     {
494       if (unformat
495           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
496            &hw_if_index))
497         ;
498       else if (unformat (line_input, "tx %d", &nb_tx_desc))
499         ;
500       else if (unformat (line_input, "rx %d", &nb_rx_desc))
501         ;
502       else
503         {
504           error = clib_error_return (0, "parse error: '%U'",
505                                      format_unformat_error, line_input);
506           goto done;
507         }
508     }
509
510   if (hw_if_index == (u32) ~ 0)
511     {
512       error = clib_error_return (0, "please specify valid interface name");
513       goto done;
514     }
515
516   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
517   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
518
519   if ((xd->flags & DPDK_DEVICE_FLAG_PMD) == 0)
520     {
521       error =
522         clib_error_return (0,
523                            "number of descriptors can be set only for "
524                            "physical devices");
525       goto done;
526     }
527
528   if ((nb_rx_desc == (u32) ~ 0 || nb_rx_desc == xd->nb_rx_desc) &&
529       (nb_tx_desc == (u32) ~ 0 || nb_tx_desc == xd->nb_tx_desc))
530     {
531       error = clib_error_return (0, "nothing changed");
532       goto done;
533     }
534
535   if (nb_rx_desc != (u32) ~ 0)
536     xd->nb_rx_desc = nb_rx_desc;
537
538   if (nb_tx_desc != (u32) ~ 0)
539     xd->nb_tx_desc = nb_tx_desc;
540
541   dpdk_device_setup (xd);
542
543   if (vec_len (xd->errors))
544     return clib_error_return (0, "%U", format_dpdk_device_errors, xd);
545
546 done:
547   unformat_free (line_input);
548
549   return error;
550 }
551
552 /*?
553  * This command sets the number of DPDK '<em>rx</em>' and
554  * '<em>tx</em>' descriptors for the given physical interface. Use
555  * the command '<em>show hardware-interface</em>' to display the
556  * current descriptor allocation.
557  *
558  * @cliexpar
559  * Example of how to set the DPDK interface descriptors:
560  * @cliexcmd{set dpdk interface descriptors GigabitEthernet0/8/0 rx 512 tx 512}
561 ?*/
562 /* *INDENT-OFF* */
563 VLIB_CLI_COMMAND (cmd_set_dpdk_if_desc,static) = {
564     .path = "set dpdk interface descriptors",
565     .short_help = "set dpdk interface descriptors <interface> [rx <nn>] [tx <nn>]",
566     .function = set_dpdk_if_desc,
567 };
568 /* *INDENT-ON* */
569
570 static int
571 dpdk_device_queue_sort (void *a1, void *a2)
572 {
573   dpdk_device_and_queue_t *dq1 = a1;
574   dpdk_device_and_queue_t *dq2 = a2;
575
576   if (dq1->device > dq2->device)
577     return 1;
578   else if (dq1->device < dq2->device)
579     return -1;
580   else if (dq1->queue_id > dq2->queue_id)
581     return 1;
582   else if (dq1->queue_id < dq2->queue_id)
583     return -1;
584   else
585     return 0;
586 }
587
588
589 static clib_error_t *
590 show_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input,
591                              vlib_cli_command_t * cmd)
592 {
593   vlib_thread_main_t *tm = vlib_get_thread_main ();
594   dpdk_main_t *dm = &dpdk_main;
595   dpdk_device_and_queue_t *dq;
596   int cpu;
597
598   if (tm->n_vlib_mains == 1)
599     vlib_cli_output (vm, "All interfaces are handled by main thread");
600
601   for (cpu = 0; cpu < vec_len (dm->devices_by_hqos_cpu); cpu++)
602     {
603       if (cpu >= dm->hqos_cpu_first_index &&
604           cpu < (dm->hqos_cpu_first_index + dm->hqos_cpu_count))
605         vlib_cli_output (vm, "Thread %u (%s at lcore %u):", cpu,
606                          vlib_worker_threads[cpu].name,
607                          vlib_worker_threads[cpu].lcore_id);
608
609       vec_foreach (dq, dm->devices_by_hqos_cpu[cpu])
610       {
611         u32 hw_if_index = dm->devices[dq->device].hw_if_index;
612         vnet_hw_interface_t *hi =
613           vnet_get_hw_interface (dm->vnet_main, hw_if_index);
614         vlib_cli_output (vm, "  %v queue %u", hi->name, dq->queue_id);
615       }
616     }
617   return 0;
618 }
619
620 /*?
621  * This command is used to display the thread and core each
622  * DPDK output interface and HQoS queue is assigned too.
623  *
624  * @cliexpar
625  * Example of how to display the DPDK output interface and HQoS queue placement:
626  * @cliexstart{show dpdk interface hqos placement}
627  * Thread 1 (vpp_hqos-threads_0 at lcore 3):
628  *   GigabitEthernet0/8/0 queue 0
629  * Thread 2 (vpp_hqos-threads_1 at lcore 4):
630  *   GigabitEthernet0/9/0 queue 0
631  * @cliexend
632 ?*/
633 /* *INDENT-OFF* */
634 VLIB_CLI_COMMAND (cmd_show_dpdk_if_hqos_placement, static) = {
635   .path = "show dpdk interface hqos placement",
636   .short_help = "show dpdk interface hqos placement",
637   .function = show_dpdk_if_hqos_placement,
638 };
639 /* *INDENT-ON* */
640
641 static clib_error_t *
642 set_dpdk_if_hqos_placement (vlib_main_t * vm, unformat_input_t * input,
643                             vlib_cli_command_t * cmd)
644 {
645   unformat_input_t _line_input, *line_input = &_line_input;
646   dpdk_main_t *dm = &dpdk_main;
647   dpdk_device_and_queue_t *dq;
648   vnet_hw_interface_t *hw;
649   dpdk_device_t *xd;
650   u32 hw_if_index = (u32) ~ 0;
651   u32 cpu = (u32) ~ 0;
652   int i;
653   clib_error_t *error = NULL;
654
655   if (!unformat_user (input, unformat_line_input, line_input))
656     return 0;
657
658   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
659     {
660       if (unformat
661           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
662            &hw_if_index))
663         ;
664       else if (unformat (line_input, "thread %d", &cpu))
665         ;
666       else
667         {
668           error = clib_error_return (0, "parse error: '%U'",
669                                      format_unformat_error, line_input);
670           goto done;
671         }
672     }
673
674   if (hw_if_index == (u32) ~ 0)
675     return clib_error_return (0, "please specify valid interface name");
676
677   if (cpu < dm->hqos_cpu_first_index ||
678       cpu >= (dm->hqos_cpu_first_index + dm->hqos_cpu_count))
679     {
680       error = clib_error_return (0, "please specify valid thread id");
681       goto done;
682     }
683
684   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
685   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
686
687   for (i = 0; i < vec_len (dm->devices_by_hqos_cpu); i++)
688     {
689       vec_foreach (dq, dm->devices_by_hqos_cpu[i])
690       {
691         if (hw_if_index == dm->devices[dq->device].hw_if_index)
692           {
693             if (cpu == i)       /* nothing to do */
694               goto done;
695
696             vec_del1 (dm->devices_by_hqos_cpu[i],
697                       dq - dm->devices_by_hqos_cpu[i]);
698             vec_add2 (dm->devices_by_hqos_cpu[cpu], dq, 1);
699             dq->queue_id = 0;
700             dq->device = xd->device_index;
701
702             vec_sort_with_function (dm->devices_by_hqos_cpu[i],
703                                     dpdk_device_queue_sort);
704
705             vec_sort_with_function (dm->devices_by_hqos_cpu[cpu],
706                                     dpdk_device_queue_sort);
707
708             goto done;
709           }
710       }
711     }
712
713   error = clib_error_return (0, "not found");
714
715 done:
716   unformat_free (line_input);
717
718   return error;
719 }
720
721 /*?
722  * This command is used to assign a given DPDK output interface and
723  * HQoS queue to a different thread. This will not create a thread,
724  * so the thread must already exist. Use '<em>/etc/vpp/startup.conf</em>'
725  * for the initial thread creation. See @ref qos_doc for more details.
726  *
727  * @cliexpar
728  * Example of how to display the DPDK output interface and HQoS queue placement:
729  * @cliexstart{show dpdk interface hqos placement}
730  * Thread 1 (vpp_hqos-threads_0 at lcore 3):
731  *   GigabitEthernet0/8/0 queue 0
732  * Thread 2 (vpp_hqos-threads_1 at lcore 4):
733  *   GigabitEthernet0/9/0 queue 0
734  * @cliexend
735  * Example of how to assign a DPDK output interface and HQoS queue to a thread:
736  * @cliexcmd{set dpdk interface hqos placement GigabitEthernet0/8/0 thread 2}
737 ?*/
738 /* *INDENT-OFF* */
739 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_placement, static) = {
740   .path = "set dpdk interface hqos placement",
741   .short_help = "set dpdk interface hqos placement <interface> thread <n>",
742   .function = set_dpdk_if_hqos_placement,
743 };
744 /* *INDENT-ON* */
745
746 static clib_error_t *
747 set_dpdk_if_hqos_pipe (vlib_main_t * vm, unformat_input_t * input,
748                        vlib_cli_command_t * cmd)
749 {
750   unformat_input_t _line_input, *line_input = &_line_input;
751   dpdk_main_t *dm = &dpdk_main;
752   vnet_hw_interface_t *hw;
753   dpdk_device_t *xd;
754   u32 hw_if_index = (u32) ~ 0;
755   u32 subport_id = (u32) ~ 0;
756   u32 pipe_id = (u32) ~ 0;
757   u32 profile_id = (u32) ~ 0;
758   int rv;
759   clib_error_t *error = NULL;
760
761   if (!unformat_user (input, unformat_line_input, line_input))
762     return 0;
763
764   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
765     {
766       if (unformat
767           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
768            &hw_if_index))
769         ;
770       else if (unformat (line_input, "subport %d", &subport_id))
771         ;
772       else if (unformat (line_input, "pipe %d", &pipe_id))
773         ;
774       else if (unformat (line_input, "profile %d", &profile_id))
775         ;
776       else
777         {
778           error = clib_error_return (0, "parse error: '%U'",
779                                      format_unformat_error, line_input);
780           goto done;
781         }
782     }
783
784   if (hw_if_index == (u32) ~ 0)
785     {
786       error = clib_error_return (0, "please specify valid interface name");
787       goto done;
788     }
789
790   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
791   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
792
793   rv =
794     rte_sched_pipe_config (xd->hqos_ht->hqos, subport_id, pipe_id,
795                            profile_id);
796   if (rv)
797     {
798       error = clib_error_return (0, "pipe configuration failed");
799       goto done;
800     }
801
802 done:
803   unformat_free (line_input);
804
805   return error;
806 }
807
808 /*?
809  * This command is used to change the profile associate with a HQoS pipe. The
810  * '<em><profile_id></em>' is zero based. Use the command
811  * '<em>show dpdk interface hqos</em>' to display the content of each profile.
812  * See @ref qos_doc for more details.
813  *
814  * @note
815  * Currently there is not an API to create a new HQoS pipe profile. One is
816  * created by default in the code (search for '<em>hqos_pipe_params_default</em>'').
817  * Additional profiles can be created in code and code recompiled. Then use this
818  * command to assign it.
819  *
820  * @cliexpar
821  * Example of how to assign a new profile to a HQoS pipe:
822  * @cliexcmd{set dpdk interface hqos pipe GigabitEthernet0/8/0 subport 0 pipe 2 profile 1}
823 ?*/
824 /* *INDENT-OFF* */
825 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_pipe, static) =
826 {
827   .path = "set dpdk interface hqos pipe",
828   .short_help = "set dpdk interface hqos pipe <interface> subport <subport_id> pipe <pipe_id> "
829                   "profile <profile_id>",
830   .function = set_dpdk_if_hqos_pipe,
831 };
832 /* *INDENT-ON* */
833
834 static clib_error_t *
835 set_dpdk_if_hqos_subport (vlib_main_t * vm, unformat_input_t * input,
836                           vlib_cli_command_t * cmd)
837 {
838   unformat_input_t _line_input, *line_input = &_line_input;
839   dpdk_main_t *dm = &dpdk_main;
840   dpdk_device_t *xd = NULL;
841   u32 hw_if_index = (u32) ~ 0;
842   u32 subport_id = (u32) ~ 0;
843   struct rte_sched_subport_params p;
844   int rv;
845   clib_error_t *error = NULL;
846   u32 tb_rate = (u32) ~ 0;
847   u32 tb_size = (u32) ~ 0;
848   u32 tc_rate[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE] =
849     { (u32) ~ 0, (u32) ~ 0, (u32) ~ 0, (u32) ~ 0 };
850   u32 tc_period = (u32) ~ 0;
851   dpdk_device_config_t *devconf = NULL;
852
853   if (!unformat_user (input, unformat_line_input, line_input))
854     return 0;
855
856   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
857     {
858       if (unformat
859           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
860            &hw_if_index))
861         ;
862       else if (unformat (line_input, "subport %d", &subport_id))
863         ;
864       else if (unformat (line_input, "rate %d", &tb_rate))
865         ;
866       else if (unformat (line_input, "bktsize %d", &tb_size))
867         ;
868       else if (unformat (line_input, "tc0 %d", &tc_rate[0]))
869         ;
870       else if (unformat (line_input, "tc1 %d", &tc_rate[1]))
871         ;
872       else if (unformat (line_input, "tc2 %d", &tc_rate[2]))
873         ;
874       else if (unformat (line_input, "tc3 %d", &tc_rate[3]))
875         ;
876       else if (unformat (line_input, "period %d", &tc_period))
877         ;
878       else
879         {
880           error = clib_error_return (0, "parse error: '%U'",
881                                      format_unformat_error, line_input);
882           goto done;
883         }
884     }
885
886   error = get_hqos (hw_if_index, subport_id, &xd, &devconf);
887
888   if (error == NULL)
889     {
890       /* Copy the current values over to local structure. */
891       memcpy (&p, &devconf->hqos.subport[subport_id], sizeof (p));
892
893       /* Update local structure with input values. */
894       if (tb_rate != (u32) ~ 0)
895         {
896           p.tb_rate = tb_rate;
897           p.tc_rate[0] = tb_rate;
898           p.tc_rate[1] = tb_rate;
899           p.tc_rate[2] = tb_rate;
900           p.tc_rate[3] = tb_rate;
901         }
902       if (tb_size != (u32) ~ 0)
903         {
904           p.tb_size = tb_size;
905         }
906       if (tc_rate[0] != (u32) ~ 0)
907         {
908           p.tc_rate[0] = tc_rate[0];
909         }
910       if (tc_rate[1] != (u32) ~ 0)
911         {
912           p.tc_rate[1] = tc_rate[1];
913         }
914       if (tc_rate[2] != (u32) ~ 0)
915         {
916           p.tc_rate[2] = tc_rate[2];
917         }
918       if (tc_rate[3] != (u32) ~ 0)
919         {
920           p.tc_rate[3] = tc_rate[3];
921         }
922       if (tc_period != (u32) ~ 0)
923         {
924           p.tc_period = tc_period;
925         }
926
927       /* Apply changes. */
928       rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport_id, &p);
929       if (rv)
930         {
931           error = clib_error_return (0, "subport configuration failed");
932           goto done;
933         }
934       else
935         {
936           /* Successfully applied, so save of the input values. */
937           memcpy (&devconf->hqos.subport[subport_id], &p, sizeof (p));
938         }
939     }
940
941 done:
942   unformat_free (line_input);
943
944   return error;
945 }
946
947 /*?
948  * This command is used to set the subport level parameters such as token
949  * bucket rate (bytes per seconds), token bucket size (bytes), traffic class
950  * rates (bytes per seconds) and token update period (Milliseconds).
951  *
952  * By default, the '<em>rate</em>' is set to 1250000000 bytes/second (10GbE
953  * rate) and each of the four traffic classes is set to 100% of the port rate.
954  * If the '<em>rate</em>' is updated by this command, all four traffic classes
955  * are assigned the same value. Each of the four traffic classes can be updated
956  * individually.
957  *
958  * @cliexpar
959  * Example of how modify the subport attributes for a 1GbE link:
960  * @cliexcmd{set dpdk interface hqos subport GigabitEthernet0/8/0 subport 0 rate 125000000}
961 ?*/
962 /* *INDENT-OFF* */
963 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_subport, static) = {
964   .path = "set dpdk interface hqos subport",
965   .short_help = "set dpdk interface hqos subport <interface> subport <subport_id> "
966                  "[rate <n>] [bktsize <n>] [tc0 <n>] [tc1 <n>] [tc2 <n>] [tc3 <n>] "
967                  "[period <n>]",
968   .function = set_dpdk_if_hqos_subport,
969 };
970 /* *INDENT-ON* */
971
972 static clib_error_t *
973 set_dpdk_if_hqos_tctbl (vlib_main_t * vm, unformat_input_t * input,
974                         vlib_cli_command_t * cmd)
975 {
976   unformat_input_t _line_input, *line_input = &_line_input;
977   vlib_thread_main_t *tm = vlib_get_thread_main ();
978   dpdk_main_t *dm = &dpdk_main;
979   vnet_hw_interface_t *hw;
980   dpdk_device_t *xd;
981   u32 hw_if_index = (u32) ~ 0;
982   u32 tc = (u32) ~ 0;
983   u32 queue = (u32) ~ 0;
984   u32 entry = (u32) ~ 0;
985   u32 val, i;
986   clib_error_t *error = NULL;
987
988   if (!unformat_user (input, unformat_line_input, line_input))
989     return 0;
990
991   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
992     {
993       if (unformat
994           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
995            &hw_if_index))
996         ;
997       else if (unformat (line_input, "entry %d", &entry))
998         ;
999       else if (unformat (line_input, "tc %d", &tc))
1000         ;
1001       else if (unformat (line_input, "queue %d", &queue))
1002         ;
1003       else
1004         {
1005           error = clib_error_return (0, "parse error: '%U'",
1006                                      format_unformat_error, line_input);
1007           goto done;
1008         }
1009     }
1010
1011   if (hw_if_index == (u32) ~ 0)
1012     {
1013       error = clib_error_return (0, "please specify valid interface name");
1014       goto done;
1015     }
1016   if (entry >= 64)
1017     {
1018       error = clib_error_return (0, "invalid entry");
1019       goto done;
1020     }
1021   if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
1022     {
1023       error = clib_error_return (0, "invalid traffic class");
1024       goto done;
1025     }
1026   if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
1027     {
1028       error = clib_error_return (0, "invalid traffic class queue");
1029       goto done;
1030     }
1031
1032   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1033   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1034
1035   /* Detect the set of worker threads */
1036   uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1037   /* Should never happen, shut up Coverity warning */
1038   if (p == 0)
1039     {
1040       error = clib_error_return (0, "no worker registrations?");
1041       goto done;
1042     }
1043
1044   vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1045   int worker_thread_first = tr->first_index;
1046   int worker_thread_count = tr->count;
1047
1048   val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
1049   for (i = 0; i < worker_thread_count; i++)
1050     xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
1051
1052 done:
1053   unformat_free (line_input);
1054
1055   return error;
1056 }
1057
1058 /*?
1059  * This command is used to set the traffic class translation table. The
1060  * traffic class translation table is used to map 64 values (0-63) to one of
1061  * four traffic class and one of four HQoS input queue. Use the '<em>show
1062  * dpdk interface hqos</em>' command to display the traffic class translation
1063  * table. See @ref qos_doc for more details.
1064  *
1065  * This command has the following parameters:
1066  *
1067  * - <b><interface></b> - Used to specify the output interface.
1068  *
1069  * - <b>entry <map_val></b> - Mapped value (0-63) to assign traffic class and queue to.
1070  *
1071  * - <b>tc <tc_id></b> - Traffic class (0-3) to be used by the provided mapped value.
1072  *
1073  * - <b>queue <queue_id></b> - HQoS input queue (0-3) to be used by the provided mapped value.
1074  *
1075  * @cliexpar
1076  * Example of how modify the traffic class translation table:
1077  * @cliexcmd{set dpdk interface hqos tctbl GigabitEthernet0/8/0 entry 16 tc 2 queue 2}
1078 ?*/
1079 /* *INDENT-OFF* */
1080 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_tctbl, static) = {
1081   .path = "set dpdk interface hqos tctbl",
1082   .short_help = "set dpdk interface hqos tctbl <interface> entry <map_val> tc <tc_id> queue <queue_id>",
1083   .function = set_dpdk_if_hqos_tctbl,
1084 };
1085 /* *INDENT-ON* */
1086
1087 static clib_error_t *
1088 set_dpdk_if_hqos_pktfield (vlib_main_t * vm, unformat_input_t * input,
1089                            vlib_cli_command_t * cmd)
1090 {
1091   unformat_input_t _line_input, *line_input = &_line_input;
1092   vlib_thread_main_t *tm = vlib_get_thread_main ();
1093   dpdk_main_t *dm = &dpdk_main;
1094   clib_error_t *error = NULL;
1095
1096   /* Device specific data */
1097   struct rte_eth_dev_info dev_info;
1098   dpdk_device_config_t *devconf = 0;
1099   vnet_hw_interface_t *hw;
1100   dpdk_device_t *xd;
1101   u32 hw_if_index = (u32) ~ 0;
1102
1103   /* Detect the set of worker threads */
1104   uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1105   /* Should never happen, shut up Coverity warning */
1106   if (p == 0)
1107     return clib_error_return (0, "no worker registrations?");
1108
1109   vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
1110   int worker_thread_first = tr->first_index;
1111   int worker_thread_count = tr->count;
1112
1113   /* Packet field configuration */
1114   u64 mask = (u64) ~ 0;
1115   u32 id = (u32) ~ 0;
1116   u32 offset = (u32) ~ 0;
1117
1118   /* HQoS params */
1119   u32 n_subports_per_port, n_pipes_per_subport, tctbl_size;
1120
1121   u32 i;
1122
1123   /* Parse input arguments */
1124   if (!unformat_user (input, unformat_line_input, line_input))
1125     return 0;
1126
1127   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1128     {
1129       if (unformat
1130           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1131            &hw_if_index))
1132         ;
1133       else if (unformat (line_input, "id subport"))
1134         id = 0;
1135       else if (unformat (line_input, "id pipe"))
1136         id = 1;
1137       else if (unformat (line_input, "id tc"))
1138         id = 2;
1139       else if (unformat (line_input, "id %d", &id))
1140         ;
1141       else if (unformat (line_input, "offset %d", &offset))
1142         ;
1143       else if (unformat (line_input, "mask %llx", &mask))
1144         ;
1145       else
1146         {
1147           error = clib_error_return (0, "parse error: '%U'",
1148                                      format_unformat_error, line_input);
1149           goto done;
1150         }
1151     }
1152
1153   /* Get interface */
1154   if (hw_if_index == (u32) ~ 0)
1155     {
1156       error = clib_error_return (0, "please specify valid interface name");
1157       goto done;
1158     }
1159
1160   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1161   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1162
1163   rte_eth_dev_info_get (xd->device_index, &dev_info);
1164   if (dev_info.pci_dev)
1165     {                           /* bonded interface has no pci info */
1166       vlib_pci_addr_t pci_addr;
1167
1168       pci_addr.domain = dev_info.pci_dev->addr.domain;
1169       pci_addr.bus = dev_info.pci_dev->addr.bus;
1170       pci_addr.slot = dev_info.pci_dev->addr.devid;
1171       pci_addr.function = dev_info.pci_dev->addr.function;
1172
1173       p =
1174         hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1175     }
1176
1177   if (p)
1178     devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1179   else
1180     devconf = &dm->conf->default_devconf;
1181
1182   if (devconf->hqos_enabled == 0)
1183     {
1184       vlib_cli_output (vm, "HQoS disabled for this interface");
1185       goto done;
1186     }
1187
1188   n_subports_per_port = devconf->hqos.port.n_subports_per_port;
1189   n_pipes_per_subport = devconf->hqos.port.n_pipes_per_subport;
1190   tctbl_size = RTE_DIM (devconf->hqos.tc_table);
1191
1192   /* Validate packet field configuration: id, offset and mask */
1193   if (id >= 3)
1194     {
1195       error = clib_error_return (0, "invalid packet field id");
1196       goto done;
1197     }
1198
1199   switch (id)
1200     {
1201     case 0:
1202       if (dpdk_hqos_validate_mask (mask, n_subports_per_port) != 0)
1203         {
1204           error = clib_error_return (0, "invalid subport ID mask "
1205                                      "(n_subports_per_port = %u)",
1206                                      n_subports_per_port);
1207           goto done;
1208         }
1209       break;
1210     case 1:
1211       if (dpdk_hqos_validate_mask (mask, n_pipes_per_subport) != 0)
1212         {
1213           error = clib_error_return (0, "invalid pipe ID mask "
1214                                      "(n_pipes_per_subport = %u)",
1215                                      n_pipes_per_subport);
1216           goto done;
1217         }
1218       break;
1219     case 2:
1220     default:
1221       if (dpdk_hqos_validate_mask (mask, tctbl_size) != 0)
1222         {
1223           error = clib_error_return (0, "invalid TC table index mask "
1224                                      "(TC table size = %u)", tctbl_size);
1225           goto done;
1226         }
1227     }
1228
1229   /* Propagate packet field configuration to all workers */
1230   for (i = 0; i < worker_thread_count; i++)
1231     switch (id)
1232       {
1233       case 0:
1234         xd->hqos_wt[worker_thread_first + i].hqos_field0_slabpos = offset;
1235         xd->hqos_wt[worker_thread_first + i].hqos_field0_slabmask = mask;
1236         xd->hqos_wt[worker_thread_first + i].hqos_field0_slabshr =
1237           __builtin_ctzll (mask);
1238         break;
1239       case 1:
1240         xd->hqos_wt[worker_thread_first + i].hqos_field1_slabpos = offset;
1241         xd->hqos_wt[worker_thread_first + i].hqos_field1_slabmask = mask;
1242         xd->hqos_wt[worker_thread_first + i].hqos_field1_slabshr =
1243           __builtin_ctzll (mask);
1244         break;
1245       case 2:
1246       default:
1247         xd->hqos_wt[worker_thread_first + i].hqos_field2_slabpos = offset;
1248         xd->hqos_wt[worker_thread_first + i].hqos_field2_slabmask = mask;
1249         xd->hqos_wt[worker_thread_first + i].hqos_field2_slabshr =
1250           __builtin_ctzll (mask);
1251       }
1252
1253 done:
1254   unformat_free (line_input);
1255
1256   return error;
1257 }
1258
1259 /*?
1260  * This command is used to set the packet fields required for classifiying the
1261  * incoming packet. As a result of classification process, packet field
1262  * information will be mapped to 5 tuples (subport, pipe, traffic class, pipe,
1263  * color) and stored in packet mbuf.
1264  *
1265  * This command has the following parameters:
1266  *
1267  * - <b><interface></b> - Used to specify the output interface.
1268  *
1269  * - <b>id subport|pipe|tc</b> - Classification occurs across three fields.
1270  * This parameter indicates which of the three masks are being configured. Legacy
1271  * code used 0-2 to represent these three fields, so 0-2 is still accepted.
1272  *   - <b>subport|0</b> - Currently only one subport is supported, so only
1273  * an empty mask is supported for the subport classification.
1274  *   - <b>pipe|1</b> - Currently, 4096 pipes per subport are supported, so a
1275  * 12-bit mask should be configure to map to the 0-4095 pipes.
1276  *   - <b>tc|2</b> - The translation table (see '<em>set dpdk interface hqos
1277  * tctbl</em>' command) maps each value (0-63) into one of the 4 traffic classes
1278  * per pipe. A 6-bit mask should be configure to map this field to a traffic class.
1279  *
1280  * - <b>offset <n></b> - Offset in the packet to apply the 64-bit mask for classification.
1281  * The offset should be on an 8-byte boundary (0,8,16,24..).
1282  *
1283  * - <b>mask <hex-mask></b> - 64-bit mask to apply to packet at the given '<em>offset</em>'.
1284  * Bits must be contiguous and should not include '<em>0x</em>'.
1285  *
1286  * The default values for the '<em>pktfield</em>' assumes Ethernet/IPv4/UDP packets with
1287  * no VLAN. Adjust based on expected packet format and desired classification field.
1288  * - '<em>subport</em>' is always empty (offset 0 mask 0000000000000000)
1289  * - By default, '<em>pipe</em>' maps to the UDP payload bits 12 .. 23 (offset 40
1290  * mask 0000000fff000000)
1291  * - By default, '<em>tc</em>' maps to the DSCP field in IP header (offset 48 mask
1292  * 00000000000000fc)
1293  *
1294  * @cliexpar
1295  * Example of how modify the '<em>pipe</em>' classification filter to match VLAN:
1296  * @cliexcmd{set dpdk interface hqos pktfield GigabitEthernet0/8/0 id pipe offset 8 mask 0000000000000FFF}
1297 ?*/
1298 /* *INDENT-OFF* */
1299 VLIB_CLI_COMMAND (cmd_set_dpdk_if_hqos_pktfield, static) = {
1300   .path = "set dpdk interface hqos pktfield",
1301   .short_help = "set dpdk interface hqos pktfield <interface> id subport|pipe|tc offset <n> "
1302                  "mask <hex-mask>",
1303   .function = set_dpdk_if_hqos_pktfield,
1304 };
1305 /* *INDENT-ON* */
1306
1307 static clib_error_t *
1308 show_dpdk_if_hqos (vlib_main_t * vm, unformat_input_t * input,
1309                    vlib_cli_command_t * cmd)
1310 {
1311   unformat_input_t _line_input, *line_input = &_line_input;
1312   vlib_thread_main_t *tm = vlib_get_thread_main ();
1313   dpdk_main_t *dm = &dpdk_main;
1314   vnet_hw_interface_t *hw;
1315   dpdk_device_t *xd;
1316   dpdk_device_config_hqos_t *cfg;
1317   dpdk_device_hqos_per_hqos_thread_t *ht;
1318   dpdk_device_hqos_per_worker_thread_t *wk;
1319   u32 *tctbl;
1320   u32 hw_if_index = (u32) ~ 0;
1321   u32 profile_id, subport_id, i;
1322   struct rte_eth_dev_info dev_info;
1323   dpdk_device_config_t *devconf = 0;
1324   vlib_thread_registration_t *tr;
1325   uword *p = 0;
1326   clib_error_t *error = NULL;
1327
1328   if (!unformat_user (input, unformat_line_input, line_input))
1329     return 0;
1330
1331   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1332     {
1333       if (unformat
1334           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1335            &hw_if_index))
1336         ;
1337       else
1338         {
1339           error = clib_error_return (0, "parse error: '%U'",
1340                                      format_unformat_error, line_input);
1341           goto done;
1342         }
1343     }
1344
1345   if (hw_if_index == (u32) ~ 0)
1346     {
1347       error = clib_error_return (0, "please specify interface name!!");
1348       goto done;
1349     }
1350
1351   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1352   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1353
1354   rte_eth_dev_info_get (xd->device_index, &dev_info);
1355   if (dev_info.pci_dev)
1356     {                           /* bonded interface has no pci info */
1357       vlib_pci_addr_t pci_addr;
1358
1359       pci_addr.domain = dev_info.pci_dev->addr.domain;
1360       pci_addr.bus = dev_info.pci_dev->addr.bus;
1361       pci_addr.slot = dev_info.pci_dev->addr.devid;
1362       pci_addr.function = dev_info.pci_dev->addr.function;
1363
1364       p =
1365         hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1366     }
1367
1368   if (p)
1369     devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1370   else
1371     devconf = &dm->conf->default_devconf;
1372
1373   if (devconf->hqos_enabled == 0)
1374     {
1375       vlib_cli_output (vm, "HQoS disabled for this interface");
1376       goto done;
1377     }
1378
1379   /* Detect the set of worker threads */
1380   p = hash_get_mem (tm->thread_registrations_by_name, "workers");
1381
1382   /* Should never happen, shut up Coverity warning */
1383   if (p == 0)
1384     {
1385       error = clib_error_return (0, "no worker registrations?");
1386       goto done;
1387     }
1388
1389   tr = (vlib_thread_registration_t *) p[0];
1390
1391   cfg = &devconf->hqos;
1392   ht = xd->hqos_ht;
1393   wk = &xd->hqos_wt[tr->first_index];
1394   tctbl = wk->hqos_tc_table;
1395
1396   vlib_cli_output (vm, " Thread:");
1397   vlib_cli_output (vm, "   Input SWQ size = %u packets", cfg->swq_size);
1398   vlib_cli_output (vm, "   Enqueue burst size = %u packets",
1399                    ht->hqos_burst_enq);
1400   vlib_cli_output (vm, "   Dequeue burst size = %u packets",
1401                    ht->hqos_burst_deq);
1402
1403   vlib_cli_output (vm,
1404                    "   Packet field 0: slab position = %4u, slab bitmask = 0x%016llx   (subport)",
1405                    wk->hqos_field0_slabpos, wk->hqos_field0_slabmask);
1406   vlib_cli_output (vm,
1407                    "   Packet field 1: slab position = %4u, slab bitmask = 0x%016llx   (pipe)",
1408                    wk->hqos_field1_slabpos, wk->hqos_field1_slabmask);
1409   vlib_cli_output (vm,
1410                    "   Packet field 2: slab position = %4u, slab bitmask = 0x%016llx   (tc)",
1411                    wk->hqos_field2_slabpos, wk->hqos_field2_slabmask);
1412   vlib_cli_output (vm,
1413                    "   Packet field 2  tc translation table: ([Mapped Value Range]: tc/queue tc/queue ...)");
1414   vlib_cli_output (vm,
1415                    "     [ 0 .. 15]: "
1416                    "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1417                    tctbl[0] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1418                    tctbl[0] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1419                    tctbl[1] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1420                    tctbl[1] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1421                    tctbl[2] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1422                    tctbl[2] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1423                    tctbl[3] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1424                    tctbl[3] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1425                    tctbl[4] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1426                    tctbl[4] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1427                    tctbl[5] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1428                    tctbl[5] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1429                    tctbl[6] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1430                    tctbl[6] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1431                    tctbl[7] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1432                    tctbl[7] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1433                    tctbl[8] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1434                    tctbl[8] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1435                    tctbl[9] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1436                    tctbl[9] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1437                    tctbl[10] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1438                    tctbl[10] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1439                    tctbl[11] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1440                    tctbl[11] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1441                    tctbl[12] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1442                    tctbl[12] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1443                    tctbl[13] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1444                    tctbl[13] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1445                    tctbl[14] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1446                    tctbl[14] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1447                    tctbl[15] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1448                    tctbl[15] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1449   vlib_cli_output (vm,
1450                    "     [16 .. 31]: "
1451                    "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1452                    tctbl[16] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1453                    tctbl[16] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1454                    tctbl[17] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1455                    tctbl[17] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1456                    tctbl[18] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1457                    tctbl[18] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1458                    tctbl[19] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1459                    tctbl[19] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1460                    tctbl[20] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1461                    tctbl[20] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1462                    tctbl[21] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1463                    tctbl[21] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1464                    tctbl[22] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1465                    tctbl[22] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1466                    tctbl[23] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1467                    tctbl[23] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1468                    tctbl[24] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1469                    tctbl[24] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1470                    tctbl[25] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1471                    tctbl[25] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1472                    tctbl[26] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1473                    tctbl[26] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1474                    tctbl[27] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1475                    tctbl[27] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1476                    tctbl[28] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1477                    tctbl[28] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1478                    tctbl[29] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1479                    tctbl[29] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1480                    tctbl[30] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1481                    tctbl[30] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1482                    tctbl[31] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1483                    tctbl[31] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1484   vlib_cli_output (vm,
1485                    "     [32 .. 47]: "
1486                    "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1487                    tctbl[32] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1488                    tctbl[32] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1489                    tctbl[33] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1490                    tctbl[33] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1491                    tctbl[34] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1492                    tctbl[34] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1493                    tctbl[35] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1494                    tctbl[35] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1495                    tctbl[36] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1496                    tctbl[36] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1497                    tctbl[37] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1498                    tctbl[37] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1499                    tctbl[38] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1500                    tctbl[38] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1501                    tctbl[39] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1502                    tctbl[39] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1503                    tctbl[40] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1504                    tctbl[40] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1505                    tctbl[41] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1506                    tctbl[41] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1507                    tctbl[42] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1508                    tctbl[42] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1509                    tctbl[43] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1510                    tctbl[43] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1511                    tctbl[44] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1512                    tctbl[44] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1513                    tctbl[45] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1514                    tctbl[45] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1515                    tctbl[46] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1516                    tctbl[46] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1517                    tctbl[47] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1518                    tctbl[47] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1519   vlib_cli_output (vm,
1520                    "     [48 .. 63]: "
1521                    "%u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u %u/%u",
1522                    tctbl[48] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1523                    tctbl[48] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1524                    tctbl[49] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1525                    tctbl[49] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1526                    tctbl[50] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1527                    tctbl[50] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1528                    tctbl[51] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1529                    tctbl[51] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1530                    tctbl[52] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1531                    tctbl[52] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1532                    tctbl[53] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1533                    tctbl[53] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1534                    tctbl[54] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1535                    tctbl[54] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1536                    tctbl[55] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1537                    tctbl[55] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1538                    tctbl[56] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1539                    tctbl[56] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1540                    tctbl[57] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1541                    tctbl[57] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1542                    tctbl[58] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1543                    tctbl[58] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1544                    tctbl[59] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1545                    tctbl[59] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1546                    tctbl[60] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1547                    tctbl[60] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1548                    tctbl[61] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1549                    tctbl[61] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1550                    tctbl[62] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1551                    tctbl[62] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1552                    tctbl[63] / RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS,
1553                    tctbl[63] % RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS);
1554   vlib_cli_output (vm, " Port:");
1555   vlib_cli_output (vm, "   Rate = %u bytes/second", cfg->port.rate);
1556   vlib_cli_output (vm, "   MTU = %u bytes", cfg->port.mtu);
1557   vlib_cli_output (vm, "   Frame overhead = %u bytes",
1558                    cfg->port.frame_overhead);
1559   vlib_cli_output (vm, "   Number of subports = %u",
1560                    cfg->port.n_subports_per_port);
1561   vlib_cli_output (vm, "   Number of pipes per subport = %u",
1562                    cfg->port.n_pipes_per_subport);
1563   vlib_cli_output (vm,
1564                    "   Packet queue size: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u packets",
1565                    cfg->port.qsize[0], cfg->port.qsize[1], cfg->port.qsize[2],
1566                    cfg->port.qsize[3]);
1567   vlib_cli_output (vm, "   Number of pipe profiles = %u",
1568                    cfg->port.n_pipe_profiles);
1569
1570   for (subport_id = 0; subport_id < vec_len (cfg->subport); subport_id++)
1571     {
1572       vlib_cli_output (vm, " Subport %u:", subport_id);
1573       vlib_cli_output (vm, "   Rate = %u bytes/second",
1574                        cfg->subport[subport_id].tb_rate);
1575       vlib_cli_output (vm, "   Token bucket size = %u bytes",
1576                        cfg->subport[subport_id].tb_size);
1577       vlib_cli_output (vm,
1578                        "   Traffic class rate: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u bytes/second",
1579                        cfg->subport[subport_id].tc_rate[0],
1580                        cfg->subport[subport_id].tc_rate[1],
1581                        cfg->subport[subport_id].tc_rate[2],
1582                        cfg->subport[subport_id].tc_rate[3]);
1583       vlib_cli_output (vm, "   TC period = %u milliseconds",
1584                        cfg->subport[subport_id].tc_period);
1585     }
1586
1587   for (profile_id = 0; profile_id < vec_len (cfg->pipe); profile_id++)
1588     {
1589       vlib_cli_output (vm, " Pipe profile %u:", profile_id);
1590       vlib_cli_output (vm, "   Rate = %u bytes/second",
1591                        cfg->pipe[profile_id].tb_rate);
1592       vlib_cli_output (vm, "   Token bucket size = %u bytes",
1593                        cfg->pipe[profile_id].tb_size);
1594       vlib_cli_output (vm,
1595                        "   Traffic class rate: TC0 = %u, TC1 = %u, TC2 = %u, TC3 = %u bytes/second",
1596                        cfg->pipe[profile_id].tc_rate[0],
1597                        cfg->pipe[profile_id].tc_rate[1],
1598                        cfg->pipe[profile_id].tc_rate[2],
1599                        cfg->pipe[profile_id].tc_rate[3]);
1600       vlib_cli_output (vm, "   TC period = %u milliseconds",
1601                        cfg->pipe[profile_id].tc_period);
1602 #ifdef RTE_SCHED_SUBPORT_TC_OV
1603       vlib_cli_output (vm, "   TC3 oversubscription_weight = %u",
1604                        cfg->pipe[profile_id].tc_ov_weight);
1605 #endif
1606
1607       for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1608         {
1609           vlib_cli_output (vm,
1610                            "   TC%u WRR weights: Q0 = %u, Q1 = %u, Q2 = %u, Q3 = %u",
1611                            i, cfg->pipe[profile_id].wrr_weights[i * 4],
1612                            cfg->pipe[profile_id].wrr_weights[i * 4 + 1],
1613                            cfg->pipe[profile_id].wrr_weights[i * 4 + 2],
1614                            cfg->pipe[profile_id].wrr_weights[i * 4 + 3]);
1615         }
1616     }
1617
1618 #ifdef RTE_SCHED_RED
1619   vlib_cli_output (vm, " Weighted Random Early Detection (WRED):");
1620   for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
1621     {
1622       vlib_cli_output (vm, "   TC%u min: G = %u, Y = %u, R = %u", i,
1623                        cfg->port.red_params[i][e_RTE_METER_GREEN].min_th,
1624                        cfg->port.red_params[i][e_RTE_METER_YELLOW].min_th,
1625                        cfg->port.red_params[i][e_RTE_METER_RED].min_th);
1626
1627       vlib_cli_output (vm, "   TC%u max: G = %u, Y = %u, R = %u", i,
1628                        cfg->port.red_params[i][e_RTE_METER_GREEN].max_th,
1629                        cfg->port.red_params[i][e_RTE_METER_YELLOW].max_th,
1630                        cfg->port.red_params[i][e_RTE_METER_RED].max_th);
1631
1632       vlib_cli_output (vm,
1633                        "   TC%u inverted probability: G = %u, Y = %u, R = %u",
1634                        i, cfg->port.red_params[i][e_RTE_METER_GREEN].maxp_inv,
1635                        cfg->port.red_params[i][e_RTE_METER_YELLOW].maxp_inv,
1636                        cfg->port.red_params[i][e_RTE_METER_RED].maxp_inv);
1637
1638       vlib_cli_output (vm, "   TC%u weight: R = %u, Y = %u, R = %u", i,
1639                        cfg->port.red_params[i][e_RTE_METER_GREEN].wq_log2,
1640                        cfg->port.red_params[i][e_RTE_METER_YELLOW].wq_log2,
1641                        cfg->port.red_params[i][e_RTE_METER_RED].wq_log2);
1642     }
1643 #endif
1644
1645 done:
1646   unformat_free (line_input);
1647
1648   return error;
1649 }
1650
1651 /*?
1652  * This command is used to display details of an output interface's HQoS
1653  * settings.
1654  *
1655  * @cliexpar
1656  * Example of how to display HQoS settings for an interfaces:
1657  * @cliexstart{show dpdk interface hqos GigabitEthernet0/8/0}
1658  *  Thread:
1659  *    Input SWQ size = 4096 packets
1660  *    Enqueue burst size = 256 packets
1661  *    Dequeue burst size = 220 packets
1662  *    Packet field 0: slab position =    0, slab bitmask = 0x0000000000000000   (subport)
1663  *    Packet field 1: slab position =   40, slab bitmask = 0x0000000fff000000   (pipe)
1664  *    Packet field 2: slab position =    8, slab bitmask = 0x00000000000000fc   (tc)
1665  *    Packet field 2  tc translation table: ([Mapped Value Range]: tc/queue tc/queue ...)
1666  *      [ 0 .. 15]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1667  *      [16 .. 31]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1668  *      [32 .. 47]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1669  *      [48 .. 63]: 0/0 0/1 0/2 0/3 1/0 1/1 1/2 1/3 2/0 2/1 2/2 2/3 3/0 3/1 3/2 3/3
1670  *  Port:
1671  *    Rate = 1250000000 bytes/second
1672  *    MTU = 1514 bytes
1673  *    Frame overhead = 24 bytes
1674  *    Number of subports = 1
1675  *    Number of pipes per subport = 4096
1676  *    Packet queue size: TC0 = 64, TC1 = 64, TC2 = 64, TC3 = 64 packets
1677  *    Number of pipe profiles = 2
1678  *  Subport 0:
1679  *    Rate = 1250000000 bytes/second
1680  *    Token bucket size = 1000000 bytes
1681  *    Traffic class rate: TC0 = 1250000000, TC1 = 1250000000, TC2 = 1250000000, TC3 = 1250000000 bytes/second
1682  *    TC period = 10 milliseconds
1683  *  Pipe profile 0:
1684  *    Rate = 305175 bytes/second
1685  *    Token bucket size = 1000000 bytes
1686  *    Traffic class rate: TC0 = 305175, TC1 = 305175, TC2 = 305175, TC3 = 305175 bytes/second
1687  *    TC period = 40 milliseconds
1688  *    TC0 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1689  *    TC1 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1690  *    TC2 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1691  *    TC3 WRR weights: Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1
1692  * @cliexend
1693 ?*/
1694 /* *INDENT-OFF* */
1695 VLIB_CLI_COMMAND (cmd_show_dpdk_if_hqos, static) = {
1696   .path = "show dpdk interface hqos",
1697   .short_help = "show dpdk interface hqos <interface>",
1698   .function = show_dpdk_if_hqos,
1699 };
1700
1701 /* *INDENT-ON* */
1702
1703 static clib_error_t *
1704 show_dpdk_hqos_queue_stats (vlib_main_t * vm, unformat_input_t * input,
1705                             vlib_cli_command_t * cmd)
1706 {
1707   unformat_input_t _line_input, *line_input = &_line_input;
1708   clib_error_t *error = NULL;
1709 #ifdef RTE_SCHED_COLLECT_STATS
1710   dpdk_main_t *dm = &dpdk_main;
1711   u32 hw_if_index = (u32) ~ 0;
1712   u32 subport = (u32) ~ 0;
1713   u32 pipe = (u32) ~ 0;
1714   u32 tc = (u32) ~ 0;
1715   u32 tc_q = (u32) ~ 0;
1716   vnet_hw_interface_t *hw;
1717   dpdk_device_t *xd;
1718   uword *p = 0;
1719   struct rte_eth_dev_info dev_info;
1720   dpdk_device_config_t *devconf = 0;
1721   u32 qindex;
1722   struct rte_sched_queue_stats stats;
1723   u16 qlen;
1724
1725   if (!unformat_user (input, unformat_line_input, line_input))
1726     return 0;
1727
1728   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1729     {
1730       if (unformat
1731           (line_input, "%U", unformat_vnet_hw_interface, dm->vnet_main,
1732            &hw_if_index))
1733         ;
1734
1735       else if (unformat (line_input, "subport %d", &subport))
1736         ;
1737
1738       else if (unformat (line_input, "pipe %d", &pipe))
1739         ;
1740
1741       else if (unformat (line_input, "tc %d", &tc))
1742         ;
1743
1744       else if (unformat (line_input, "tc_q %d", &tc_q))
1745         ;
1746
1747       else
1748         {
1749           error = clib_error_return (0, "parse error: '%U'",
1750                                      format_unformat_error, line_input);
1751           goto done;
1752         }
1753     }
1754
1755   if (hw_if_index == (u32) ~ 0)
1756     {
1757       error = clib_error_return (0, "please specify interface name!!");
1758       goto done;
1759     }
1760
1761   hw = vnet_get_hw_interface (dm->vnet_main, hw_if_index);
1762   xd = vec_elt_at_index (dm->devices, hw->dev_instance);
1763
1764   rte_eth_dev_info_get (xd->device_index, &dev_info);
1765   if (dev_info.pci_dev)
1766     {                           /* bonded interface has no pci info */
1767       vlib_pci_addr_t pci_addr;
1768
1769       pci_addr.domain = dev_info.pci_dev->addr.domain;
1770       pci_addr.bus = dev_info.pci_dev->addr.bus;
1771       pci_addr.slot = dev_info.pci_dev->addr.devid;
1772       pci_addr.function = dev_info.pci_dev->addr.function;
1773
1774       p =
1775         hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
1776     }
1777
1778   if (p)
1779     devconf = pool_elt_at_index (dm->conf->dev_confs, p[0]);
1780   else
1781     devconf = &dm->conf->default_devconf;
1782
1783   if (devconf->hqos_enabled == 0)
1784     {
1785       vlib_cli_output (vm, "HQoS disabled for this interface");
1786       goto done;
1787     }
1788
1789   /*
1790    * Figure out which queue to query.  cf rte_sched_port_qindex.  (Not sure why
1791    * that method isn't made public by DPDK - how _should_ we get the queue ID?)
1792    */
1793   qindex = subport * devconf->hqos.port.n_pipes_per_subport + pipe;
1794   qindex = qindex * RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE + tc;
1795   qindex = qindex * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + tc_q;
1796
1797   if (rte_sched_queue_read_stats (xd->hqos_ht->hqos, qindex, &stats, &qlen) !=
1798       0)
1799     {
1800       error = clib_error_return (0, "failed to read stats");
1801       goto done;
1802     }
1803
1804   vlib_cli_output (vm, "%=24s%=16s", "Stats Parameter", "Value");
1805   vlib_cli_output (vm, "%=24s%=16d", "Packets", stats.n_pkts);
1806   vlib_cli_output (vm, "%=24s%=16d", "Packets dropped", stats.n_pkts_dropped);
1807 #ifdef RTE_SCHED_RED
1808   vlib_cli_output (vm, "%=24s%=16d", "Packets dropped (RED)",
1809                    stats.n_pkts_red_dropped);
1810 #endif
1811   vlib_cli_output (vm, "%=24s%=16d", "Bytes", stats.n_bytes);
1812   vlib_cli_output (vm, "%=24s%=16d", "Bytes dropped", stats.n_bytes_dropped);
1813
1814 #else
1815
1816   /* Get a line of input */
1817   if (!unformat_user (input, unformat_line_input, line_input))
1818     return 0;
1819
1820   vlib_cli_output (vm, "RTE_SCHED_COLLECT_STATS disabled in DPDK");
1821   goto done;
1822
1823 #endif
1824
1825 done:
1826   unformat_free (line_input);
1827
1828   return error;
1829 }
1830
1831 /*?
1832  * This command is used to display statistics associated with a HQoS traffic class
1833  * queue.
1834  *
1835  * @note
1836  * Statistic collection by the scheduler is disabled by default in DPDK. In order to
1837  * turn it on, add the following line to '<em>../vpp/dpdk/Makefile</em>':
1838  * - <b>$(call set,RTE_SCHED_COLLECT_STATS,y)</b>
1839  *
1840  * @cliexpar
1841  * Example of how to display statistics of HQoS a HQoS traffic class queue:
1842  * @cliexstart{show dpdk hqos queue GigabitEthernet0/9/0 subport 0 pipe 3181 tc 0 tc_q 0}
1843  *      Stats Parameter          Value
1844  *          Packets               140
1845  *      Packets dropped            0
1846  *           Bytes               8400
1847  *       Bytes dropped             0
1848  * @cliexend
1849 ?*/
1850 /* *INDENT-OFF* */
1851 VLIB_CLI_COMMAND (cmd_show_dpdk_hqos_queue_stats, static) = {
1852   .path = "show dpdk hqos queue",
1853   .short_help = "show dpdk hqos queue <interface> subport <subport_id> pipe <pipe_id> tc <tc_id> tc_q <queue_id>",
1854   .function = show_dpdk_hqos_queue_stats,
1855 };
1856 /* *INDENT-ON* */
1857
1858 static clib_error_t *
1859 show_dpdk_version_command_fn (vlib_main_t * vm,
1860                               unformat_input_t * input,
1861                               vlib_cli_command_t * cmd)
1862 {
1863 #define _(a,b,c) vlib_cli_output (vm, "%-25s " b, a ":", c);
1864   _("DPDK Version", "%s", rte_version ());
1865   _("DPDK EAL init args", "%s", dpdk_config_main.eal_init_args_str);
1866 #undef _
1867   return 0;
1868 }
1869
1870 /*?
1871  * This command is used to display the current DPDK version and
1872  * the list of arguments passed to DPDK when started.
1873  *
1874  * @cliexpar
1875  * Example of how to display how many DPDK buffer test command has allcoated:
1876  * @cliexstart{show dpdk version}
1877  * DPDK Version:        DPDK 16.11.0
1878  * DPDK EAL init args:  -c 1 -n 4 --huge-dir /run/vpp/hugepages --file-prefix vpp -w 0000:00:08.0 -w 0000:00:09.0 --master-lcore 0 --socket-mem 256
1879  * @cliexend
1880 ?*/
1881 /* *INDENT-OFF* */
1882 VLIB_CLI_COMMAND (show_vpe_version_command, static) = {
1883   .path = "show dpdk version",
1884   .short_help = "show dpdk version",
1885   .function = show_dpdk_version_command_fn,
1886 };
1887 /* *INDENT-ON* */
1888
1889 clib_error_t *
1890 dpdk_cli_init (vlib_main_t * vm)
1891 {
1892   return 0;
1893 }
1894
1895 VLIB_INIT_FUNCTION (dpdk_cli_init);
1896
1897 /*
1898  * fd.io coding-style-patch-verification: ON
1899  *
1900  * Local Variables:
1901  * eval: (c-set-style "gnu")
1902  * End:
1903  */