1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <vnet/vnet.h>
#include <vppinfra/vec.h>
#include <vppinfra/error.h>
#include <vppinfra/format.h>
#include <vppinfra/xxhash.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/devices/dpdk/dpdk.h>
#include <vnet/classify/vnet_classify.h>
#include <vnet/mpls-gre/packet.h>
#include <vnet/handoff.h>
#include "dpdk_priv.h"
#ifndef MAX
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/*
* At least in certain versions of ESXi, vmware e1000's don't honor the
* "strip rx CRC" bit. Set this flag to work around that bug FOR UNIT TEST ONLY.
*
* If wireshark complains like so:
*
* "Frame check sequence: 0x00000000 [incorrect, should be <hex-num>]"
* and you're using ESXi emulated e1000's, set this flag FOR UNIT TEST ONLY.
*
* Note: do NOT check in this file with this workaround enabled! You'll lose
* actual data from e.g. 10xGE interfaces. The extra 4 bytes annoy
* wireshark, but they're harmless...
*/
#define VMWARE_LENGTH_BUG_WORKAROUND 0
static char * dpdk_error_strings[] = {
#define _(n,s) s,
foreach_dpdk_error
#undef _
};
always_inline int
dpdk_mbuf_is_ip4(struct rte_mbuf *mb)
{
#if RTE_VERSION >= RTE_VERSION_NUM(2, 1, 0, 0)
return RTE_ETH_IS_IPV4_HDR(mb->packet_type) != 0;
#else
return (mb_flags & (PKT_RX_IPV4_HDR | PKT_RX_IPV4_HDR_EXT)) != 0;
#endif
}
always_inline int
dpdk_mbuf_is_ip6(struct rte_mbuf *mb)
{
#if RTE_VERSION >= RTE_VERSION_NUM(2, 1, 0, 0)
return RTE_ETH_IS_IPV6_HDR(mb->packet_type) != 0;
#else
return (mb_flags & (PKT_RX_IPV6_HDR | PKT_RX_IPV6_HDR_EXT)) != 0;
#endif
}
always_inline int
vlib_buffer_is_mpls(vlib_buffer_t * b)
{
ethernet_header_t *h = (ethernet_header_t *) b->data;
return (h->type == clib_host_to_net_u16(ETHERNET_TYPE_MPLS_UNICAST));
}
always_inline void
dpdk_rx_next_and_error_from_mb_flags_x1 (dpdk_device_t *xd, struct rte_mbuf *mb,
vlib_buffer_t *b0,
u8 * next0, u8 * error0)
{
u8 n0;
uint16_t mb_flags = mb->ol_flags;
if (PREDICT_FALSE(mb_flags & (
#ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
PKT_EXT_RX_PKT_ERROR | PKT_EXT_RX_BAD_FCS |
#endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
PKT_RX_IP_CKSUM_BAD | PKT_RX_L4_CKSUM_BAD
)))
{
/* some error was flagged. determine the drop reason */
n0 = DPDK_RX_NEXT_DROP;
*error0 =
#ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
(mb_flags & PKT_EXT_RX_PKT_ERROR) ? DPDK_ERROR_RX_PACKET_ERROR :
(mb_flags & PKT_EXT_RX_BAD_FCS) ? DPDK_ERROR_RX_BAD_FCS :
#endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
(mb_flags & PKT_RX_IP_CKSUM_BAD) ? DPDK_ERROR_IP_CHECKSUM_ERROR :
(mb_flags & PKT_RX_L4_CKSUM_BAD) ? DPDK_ERROR_L4_CHECKSUM_ERROR :
DPDK_ERROR_NONE;
}
else
{
*error0 = DPDK_ERROR_NONE;
if (PREDICT_FALSE(xd->per_interface_next_index != ~0))
{
n0 = xd->per_interface_next_index;
b0->flags |= BUFFER_HANDOFF_NEXT_VALID;
if (PREDICT_TRUE (dpdk_mbuf_is_ip4(mb)))
vnet_buffer(b0)->handoff.next_index = HANDOFF_DISPATCH_NEXT_IP4_INPUT;
else if (PREDICT_TRUE(dpdk_mbuf_is_ip6(mb)))
vnet_buffer(b0)->handoff.next_index = HANDOFF_DISPATCH_NEXT_IP6_INPUT;
else if (PREDICT_TRUE(vlib_buffer_is_mpls(b0)))
vnet_buffer(b0)->handoff.next_index = HANDOFF_DISPATCH_NEXT_MPLS_INPUT;
else
vnet_buffer(b0)->handoff.next_index = HANDOFF_DISPATCH_NEXT_ETHERNET_INPUT;
}
else if (PREDICT_FALSE(xd->vlan_subifs || (mb_flags & PKT_RX_VLAN_PKT)))
n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
else
{
if (PREDICT_TRUE (dpdk_mbuf_is_ip4(mb)))
n0 = DPDK_RX_NEXT_IP4_INPUT;
else if (PREDICT_TRUE(dpdk_mbuf_is_ip6(mb)))
n0 = DPDK_RX_NEXT_IP6_INPUT;
else if (PREDICT_TRUE(vlib_buffer_is_mpls(b0)))
n0 = DPDK_RX_NEXT_MPLS_INPUT;
else
n0 = DPDK_RX_NEXT_ETHERNET_INPUT;
}
}
*next0 = n0;
}
void dpdk_rx_trace (dpdk_main_t * dm,
vlib_node_runtime_t * node,
dpdk_device_t * xd,
u16 queue_id,
u32 * buffers,
uword n_buffers)
{
vlib_main_t * vm = vlib_get_main();
u32 * b, n_left;
u8 next0;
n_left = n_buffers;
b = buffers;
while (n_left >= 1)
{
u32 bi0;
vlib_buffer_t * b0;
dpdk_rx_dma_trace_t * t0;
struct rte_mbuf *mb;
u8 error0;
bi0 = b[0];
n_left -= 1;
b0 = vlib_get_buffer (vm, bi0);
mb = rte_mbuf_from_vlib_buffer(b0);
dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0,
&next0, &error0);
vlib_trace_buffer (vm, node, next0, b0, /* follow_chain */ 0);
t0 = vlib_add_trace (vm, node, b0, sizeof (t0[0]));
t0->queue_index = queue_id;
t0->device_index = xd->device_index;
t0->buffer_index = bi0;
clib_memcpy (&t0->mb, mb, sizeof (t0->mb));
clib_memcpy (&t0->buffer, b0, sizeof (b0[0]) - sizeof (b0->pre_data));
clib_memcpy (t0->buffer.pre_data, b0->data, sizeof (t0->buffer.pre_data));
clib_memcpy (&t0->data, mb->buf_addr + mb->data_off, sizeof (t0->data));
#ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
/*
* Clear overloaded TX offload flags when a DPDK driver
* is using them for RX flags (e.g. Cisco VIC Ethernet driver)
*/
mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
#endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
b += 1;
}
}
/*
* dpdk_efd_update_counters()
* Update EFD (early-fast-discard) counters
*/
void dpdk_efd_update_counters (dpdk_device_t *xd,
u32 n_buffers,
u16 enabled)
{
if (enabled & DPDK_EFD_MONITOR_ENABLED)
{
u64 now = clib_cpu_time_now();
if (xd->efd_agent.last_poll_time > 0)
{
u64 elapsed_time = (now - xd->efd_agent.last_poll_time);
if (elapsed_time > xd->efd_agent.max_poll_delay)
xd->efd_agent.max_poll_delay = elapsed_time;
}
xd->efd_agent.last_poll_time = now;
}
xd->efd_agent.total_packet_cnt += n_buffers;
xd->efd_agent.last_burst_sz = n_buffers;
if (n_buffers > xd->efd_agent.max_burst_sz)
xd->efd_agent.max_burst_sz = n_buffers;
if (PREDICT_FALSE(n_buffers == VLIB_FRAME_SIZE))
{
xd->efd_agent.full_frames_cnt++;
xd->efd_agent.consec_full_frames_cnt++;
}
else
{
xd->efd_agent.consec_full_frames_cnt = 0;
}
}
/* is_efd_discardable()
* returns non zero DPDK error if packet meets early-fast-discard criteria,
* zero otherwise
*/
u32 is_efd_discardable (vlib_thread_main_t *tm,
vlib_buffer_t * b0,
struct rte_mbuf *mb)
{
ethernet_header_t *eh = (ethernet_header_t *) b0->data;
if (eh->type == clib_host_to_net_u16(ETHERNET_TYPE_IP4))
{
ip4_header_t *ipv4 =
(ip4_header_t *)&(b0->data[sizeof(ethernet_header_t)]);
u8 pkt_prec = (ipv4->tos >> 5);
return (tm->efd.ip_prec_bitmap & (1 << pkt_prec) ?
DPDK_ERROR_IPV4_EFD_DROP_PKTS : DPDK_ERROR_NONE);
}
else if (eh->type == clib_net_to_host_u16(ETHERNET_TYPE_IP6))
{
ip6_header_t *ipv6 =
(ip6_header_t *)&(b0->data[sizeof(ethernet_header_t)]);
u8 pkt_tclass =
((ipv6->ip_version_traffic_class_and_flow_label >> 20) & 0xff);
return (tm->efd.ip_prec_bitmap & (1 << pkt_tclass) ?
DPDK_ERROR_IPV6_EFD_DROP_PKTS : DPDK_ERROR_NONE);
}
else if (eh->type == clib_net_to_host_u16(ETHERNET_TYPE_MPLS_UNICAST))
{
mpls_unicast_header_t *mpls =
(mpls_unicast_header_t *)&(b0->data[sizeof(ethernet_header_t)]);
u8 pkt_exp = ((mpls->label_exp_s_ttl >> 9) & 0x07);
return (tm->efd.mpls_exp_bitmap & (1 << pkt_exp) ?
DPDK_ERROR_MPLS_EFD_DROP_PKTS : DPDK_ERROR_NONE);
}
else if ((eh->type == clib_net_to_host_u16(ETHERNET_TYPE_VLAN)) ||
(eh->type == clib_net_to_host_u16(ETHERNET_TYPE_DOT1AD)))
{
ethernet_vlan_header_t *vlan =
(ethernet_vlan_header_t *)&(b0->data[sizeof(ethernet_header_t)]);
u8 pkt_cos = ((vlan->priority_cfi_and_id >> 13) & 0x07);
return (tm->efd.vlan_cos_bitmap & (1 << pkt_cos) ?
DPDK_ERROR_VLAN_EFD_DROP_PKTS : DPDK_ERROR_NONE);
}
return DPDK_ERROR_NONE;
}
/*
* This function is used when there are no worker threads.
* The main thread performs IO and forwards the packets.
*/
static inline u32 dpdk_device_input ( dpdk_main_t * dm,
dpdk_device_t * xd,
vlib_node_runtime_t * node,
u32 cpu_index,
u16 queue_id,
int use_efd)
{
u32 n_buffers;
u32 next_index = DPDK_RX_NEXT_ETHERNET_INPUT;
u32 n_left_to_next, * to_next;
u32 mb_index;
vlib_main_t * vm = vlib_get_main();
uword n_rx_bytes = 0;
u32 n_trace, trace_cnt __attribute__((unused));
vlib_buffer_free_list_t * fl;
u8 efd_discard_burst = 0;
u32 buffer_flags_template;
if (xd->admin_up == 0)
return 0;
n_buffers = dpdk_rx_burst(dm, xd, queue_id);
if (n_buffers == 0)
{
/* check if EFD (dpdk) is enabled */
if (PREDICT_FALSE(use_efd && dm->efd.enabled))
{
/* reset a few stats */
xd->efd_agent.last_poll_time = 0;
xd->efd_agent.last_burst_sz = 0;
}
return 0;
}
buffer_flags_template = dm->buffer_flags_template;
vec_reset_length (xd->d_trace_buffers);
trace_cnt = n_trace = vlib_get_trace_count (vm, node);
fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
/*
* DAW-FIXME: VMXNET3 device stop/start doesn't work,
* therefore fake the stop in the dpdk driver by
* silently dropping all of the incoming pkts instead of
* stopping the driver / hardware.
*/
if (PREDICT_FALSE(xd->admin_up != 1))
{
for (mb_index = 0; mb_index < n_buffers; mb_index++)
rte_pktmbuf_free (xd->rx_vectors[queue_id][mb_index]);
return 0;
}
/* Check for congestion if EFD (Early-Fast-Discard) is enabled
* in any mode (e.g. dpdk, monitor, or drop_all)
*/
if (PREDICT_FALSE(use_efd && dm->efd.enabled))
{
/* update EFD counters */
dpdk_efd_update_counters(xd, n_buffers, dm->efd.enabled);
if (PREDICT_FALSE(dm->efd.enabled & DPDK_EFD_DROPALL_ENABLED))
{
/* discard all received packets */
for (mb_index = 0; mb_index < n_buffers; mb_index++)
rte_pktmbuf_free(xd->rx_vectors[queue_id][mb_index]);
xd->efd_agent.discard_cnt += n_buffers;
increment_efd_drop_counter(vm,
DPDK_ERROR_VLAN_EFD_DROP_PKTS,
n_buffers);
return 0;
}
if (PREDICT_FALSE(xd->efd_agent.consec_full_frames_cnt >=
dm->efd.consec_full_frames_hi_thresh))
{
u32 device_queue_sz = rte_eth_rx_queue_count(xd->device_index,
queue_id);
if (device_queue_sz >= dm->efd.queue_hi_thresh)
{
/* dpdk device queue has reached the critical threshold */
xd->efd_agent.congestion_cnt++;
/* apply EFD to packets from the burst */
efd_discard_burst = 1;
}
}
}
mb_index = 0;
while (n_buffers > 0)
{
u32 bi0;
u8 next0, error0;
u32 l3_offset0;
vlib_buffer_t * b0, * b_seg, * b_chain = 0;
u32 cntr_type;
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_buffers > 0 && n_left_to_next > 0)
{
u8 nb_seg = 1;
struct rte_mbuf *mb = xd->rx_vectors[queue_id][mb_index];
struct rte_mbuf *mb_seg = mb->next;
if (PREDICT_TRUE(n_buffers > 2))
{
struct rte_mbuf *pfmb = xd->rx_vectors[queue_id][mb_index+2];
vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf(pfmb);
CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, STORE);
CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
}
ASSERT(mb);
b0 = vlib_buffer_from_rte_mbuf(mb);
/* check whether EFD is looking for packets to discard */
if (PREDICT_FALSE(efd_discard_burst))
{
vlib_thread_main_t * tm = vlib_get_thread_main();
if (PREDICT_TRUE(cntr_type = is_efd_discardable(tm, b0, mb)))
{
rte_pktmbuf_free(mb);
xd->efd_agent.discard_cnt++;
increment_efd_drop_counter(vm,
cntr_type,
1);
n_buffers--;
mb_index++;
continue;
}
}
/* Prefetch one next segment if it exists. */
if (PREDICT_FALSE(mb->nb_segs > 1))
{
struct rte_mbuf *pfmb = mb->next;
vlib_buffer_t *bp = vlib_buffer_from_rte_mbuf(pfmb);
CLIB_PREFETCH (pfmb, CLIB_CACHE_LINE_BYTES, LOAD);
CLIB_PREFETCH (bp, CLIB_CACHE_LINE_BYTES, STORE);
b_chain = b0;
}
vlib_buffer_init_for_free_list (b0, fl);
bi0 = vlib_get_buffer_index (vm, b0);
to_next[0] = bi0;
to_next++;
n_left_to_next--;
dpdk_rx_next_and_error_from_mb_flags_x1 (xd, mb, b0,
&next0, &error0);
#ifdef RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS
/*
* Clear overloaded TX offload flags when a DPDK driver
* is using them for RX flags (e.g. Cisco VIC Ethernet driver)
*/
if (PREDICT_TRUE(trace_cnt == 0))
mb->ol_flags &= PKT_EXT_RX_CLR_TX_FLAGS_MASK;
else
trace_cnt--;
#endif /* RTE_LIBRTE_MBUF_EXT_RX_OLFLAGS */
b0->error = node->errors[error0];
l3_offset0 = ((next0 == DPDK_RX_NEXT_IP4_INPUT ||
next0 == DPDK_RX_NEXT_IP6_INPUT ||
next0 == DPDK_RX_NEXT_MPLS_INPUT) ?
sizeof (ethernet_header_t) : 0);
b0->current_data = l3_offset0;
/* Some drivers like fm10k receive frames with
mb->data_off > RTE_PKTMBUF_HEADROOM */
b0->current_data += mb->data_off - RTE_PKTMBUF_HEADROOM;
b0->current_length = mb->data_len - l3_offset0;
b0->flags = buffer_flags_template;
if (VMWARE_LENGTH_BUG_WORKAROUND)
b0->current_length -= 4;
vnet_buffer(b0)->sw_if_index[VLIB_RX] = xd->vlib_sw_if_index;
vnet_buffer(b0)->sw_if_index[VLIB_TX] = (u32)~0;
n_rx_bytes += mb->pkt_len;
/* Process subsequent segments of multi-segment packets */
while ((mb->nb_segs > 1) && (nb_seg < mb->nb_segs))
{
ASSERT(mb_seg != 0);
b_seg = vlib_buffer_from_rte_mbuf(mb_seg);
vlib_buffer_init_for_free_list (b_seg, fl);
ASSERT((b_seg->flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
ASSERT(b_seg->current_data == 0);
/*
* The driver (e.g. virtio) may not put the packet data at the start
* of the segment, so don't assume b_seg->current_data == 0 is correct.
*/
b_seg->current_data = (mb_seg->buf_addr + mb_seg->data_off) - (void *)b_seg->data;
b_seg->current_length = mb_seg->data_len;
b0->total_length_not_including_first_buffer +=
mb_seg->data_len;
b_chain->flags |= VLIB_BUFFER_NEXT_PRESENT;
b_chain->next_buffer = vlib_get_buffer_index (vm, b_seg);
b_chain = b_seg;
mb_seg = mb_seg->next;
nb_seg++;
}
/*
* Turn this on if you run into
* "bad monkey" contexts, and you want to know exactly
* which nodes they've visited... See main.c...
*/
VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b0);
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
if (PREDICT_FALSE (n_trace > mb_index))
vec_add1 (xd->d_trace_buffers, bi0);
n_buffers--;
mb_index++;
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
if (PREDICT_FALSE (vec_len (xd->d_trace_buffers) > 0))
{
dpdk_rx_trace (dm, node, xd, queue_id, xd->d_trace_buffers,
vec_len (xd->d_trace_buffers));
vlib_set_trace_count (vm, node, n_trace - vec_len (xd->d_trace_buffers));
}
vlib_increment_combined_counter
(vnet_get_main()->interface_main.combined_sw_if_counters
+ VNET_INTERFACE_COUNTER_RX,
cpu_index,
xd->vlib_sw_if_index,
mb_index, n_rx_bytes);
dpdk_worker_t * dw = vec_elt_at_index(dm->workers, cpu_index);
dw->aggregate_rx_packets += mb_index;
return mb_index;
}
static inline void poll_rate_limit(dpdk_main_t * dm)
{
/* Limit the poll rate by sleeping for N msec between polls */
if (PREDICT_FALSE (dm->poll_sleep != 0))
{
struct timespec ts, tsrem;
ts.tv_sec = 0;
ts.tv_nsec = 1000*1000*dm->poll_sleep; /* 1ms */
while (nanosleep(&ts, &tsrem) < 0)
{
ts = tsrem;
}
}
}
static uword
dpdk_input (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * f)
{
dpdk_main_t * dm = &dpdk_main;
dpdk_device_t * xd;
uword n_rx_packets = 0;
dpdk_device_and_queue_t * dq;
u32 cpu_index = os_get_cpu_number();
/*
* Poll all devices on this cpu for input/interrupts.
*/
vec_foreach (dq, dm->devices_by_cpu[cpu_index])
{
xd = vec_elt_at_index(dm->devices, dq->device);
ASSERT(dq->queue_id == 0);
n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, 0, 0);
}
poll_rate_limit(dm);
return n_rx_packets;
}
uword
dpdk_input_rss (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * f)
{
dpdk_main_t * dm = &dpdk_main;
dpdk_device_t * xd;
uword n_rx_packets = 0;
dpdk_device_and_queue_t * dq;
u32 cpu_index = os_get_cpu_number();
/*
* Poll all devices on this cpu for input/interrupts.
*/
vec_foreach (dq, dm->devices_by_cpu[cpu_index])
{
xd = vec_elt_at_index(dm->devices, dq->device);
n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 0);
}
poll_rate_limit(dm);
return n_rx_packets;
}
uword
dpdk_input_efd (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * f)
{
dpdk_main_t * dm = &dpdk_main;
dpdk_device_t * xd;
uword n_rx_packets = 0;
dpdk_device_and_queue_t * dq;
u32 cpu_index = os_get_cpu_number();
/*
* Poll all devices on this cpu for input/interrupts.
*/
vec_foreach (dq, dm->devices_by_cpu[cpu_index])
{
xd = vec_elt_at_index(dm->devices, dq->device);
n_rx_packets += dpdk_device_input (dm, xd, node, cpu_index, dq->queue_id, 1);
}
poll_rate_limit(dm);
return n_rx_packets;
}
VLIB_REGISTER_NODE (dpdk_input_node) = {
.function = dpdk_input,
.type = VLIB_NODE_TYPE_INPUT,
.name = "dpdk-input",
/* Will be enabled if/when hardware is detected. */
.state = VLIB_NODE_STATE_DISABLED,
.format_buffer = format_ethernet_header_with_length,
.format_trace = format_dpdk_rx_dma_trace,
.n_errors = DPDK_N_ERROR,
.error_strings = dpdk_error_strings,
.n_next_nodes = DPDK_RX_N_NEXT,
.next_nodes = {
[DPDK_RX_NEXT_DROP] = "error-drop",
[DPDK_RX_NEXT_ETHERNET_INPUT] = "ethernet-input",
[DPDK_RX_NEXT_IP4_INPUT] = "ip4-input-no-checksum",
[DPDK_RX_NEXT_IP6_INPUT] = "ip6-input",
[DPDK_RX_NEXT_MPLS_INPUT] = "mpls-gre-input",
},
};
/* handle dpdk_input_rss alternative function */
VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input)
VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_rss)
VLIB_NODE_FUNCTION_MULTIARCH_CLONE(dpdk_input_efd)
/* this macro defines dpdk_input_rss_multiarch_select() */
CLIB_MULTIARCH_SELECT_FN(dpdk_input);
CLIB_MULTIARCH_SELECT_FN(dpdk_input_rss);
CLIB_MULTIARCH_SELECT_FN(dpdk_input_efd);
/*
* Override the next nodes for the dpdk input nodes.
* Must be invoked prior to VLIB_INIT_FUNCTION calls.
*/
void dpdk_set_next_node (dpdk_rx_next_t next, char *name)
{
vlib_node_registration_t *r = &dpdk_input_node;
vlib_node_registration_t *r_handoff = &handoff_dispatch_node;
switch (next)
{
case DPDK_RX_NEXT_IP4_INPUT:
case DPDK_RX_NEXT_IP6_INPUT:
case DPDK_RX_NEXT_MPLS_INPUT:
case DPDK_RX_NEXT_ETHERNET_INPUT:
r->next_nodes[next] = name;
r_handoff->next_nodes[next] = name;
break;
default:
clib_warning ("%s: illegal next %d\n", __FUNCTION__, next);
break;
}
}
/*
* set_efd_bitmap()
* Based on the operation type, set lower/upper bits for the given index value
*/
void
set_efd_bitmap (u8 *bitmap, u32 value, u32 op)
{
int ix;
*bitmap = 0;
for (ix = 0; ix < 8; ix++) {
if (((op == EFD_OPERATION_LESS_THAN) && (ix < value)) ||
((op == EFD_OPERATION_GREATER_OR_EQUAL) && (ix >= value))){
(*bitmap) |= (1 << ix);
}
}
}
void
efd_config (u32 enabled,
u32 ip_prec, u32 ip_op,
u32 mpls_exp, u32 mpls_op,
u32 vlan_cos, u32 vlan_op)
{
vlib_thread_main_t * tm = vlib_get_thread_main();
dpdk_main_t * dm = &dpdk_main;
if (enabled) {
tm->efd.enabled |= VLIB_EFD_DISCARD_ENABLED;
dm->efd.enabled |= DPDK_EFD_DISCARD_ENABLED;
} else {
tm->efd.enabled &= ~VLIB_EFD_DISCARD_ENABLED;
dm->efd.enabled &= ~DPDK_EFD_DISCARD_ENABLED;
}
set_efd_bitmap(&tm->efd.ip_prec_bitmap, ip_prec, ip_op);
set_efd_bitmap(&tm->efd.mpls_exp_bitmap, mpls_exp, mpls_op);
set_efd_bitmap(&tm->efd.vlan_cos_bitmap, vlan_cos, vlan_op);
}
|