blob: 5c28cadc03c96b93f95c48eed6f5f50bd5598236 [file] [log] [blame]
Damjan Marion22311502016-10-28 20:30:15 +02001/*
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
Damjan Marion7dc41462016-11-15 19:47:58 +010016#include <vnet/vnet.h>
Damjan Marion51327ac2016-11-09 11:59:42 +010017#include <vnet/devices/devices.h>
Damjan Marion22311502016-10-28 20:30:15 +020018#include <vnet/feature/feature.h>
Damjan Marion7dc41462016-11-15 19:47:58 +010019#include <vnet/ip/ip.h>
20#include <vnet/ethernet/ethernet.h>
Damjan Marion22311502016-10-28 20:30:15 +020021
Damjan Marionb3bb1012017-02-28 21:55:28 +010022vnet_device_main_t vnet_device_main;
23
Damjan Marion51327ac2016-11-09 11:59:42 +010024static uword
25device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
26 vlib_frame_t * frame)
27{
28 return 0;
29}
30
Damjan Marion22311502016-10-28 20:30:15 +020031/* *INDENT-OFF* */
Damjan Marion51327ac2016-11-09 11:59:42 +010032VLIB_REGISTER_NODE (device_input_node) = {
33 .function = device_input_fn,
34 .name = "device-input",
Mohammed Hawarib85b0df2021-01-08 17:19:09 +010035 .runtime_data_bytes = sizeof (vnet_hw_if_rx_node_runtime_t),
Damjan Marion51327ac2016-11-09 11:59:42 +010036 .type = VLIB_NODE_TYPE_INPUT,
37 .state = VLIB_NODE_STATE_DISABLED,
38 .n_next_nodes = VNET_DEVICE_INPUT_N_NEXT_NODES,
39 .next_nodes = VNET_DEVICE_INPUT_NEXT_NODES,
40};
41
Damjan Marion7dc41462016-11-15 19:47:58 +010042/* Table defines how much we need to advance current data pointer
43 in the buffer if we shortcut to l3 nodes */
44
45const u32 __attribute__((aligned (CLIB_CACHE_LINE_BYTES)))
46device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES /
47 CLIB_CACHE_LINE_BYTES) +1) * CLIB_CACHE_LINE_BYTES] =
48{
49 [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = sizeof (ethernet_header_t),
Sergio Gonzalez Monroy767b2f52016-12-20 15:20:32 +000050 [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = sizeof (ethernet_header_t),
Damjan Marion7dc41462016-11-15 19:47:58 +010051 [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = sizeof (ethernet_header_t),
52 [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = sizeof (ethernet_header_t),
53};
54
Damjan Marionbd846cd2017-11-21 13:12:41 +010055const u32 __attribute__((aligned (CLIB_CACHE_LINE_BYTES)))
56device_input_next_node_flags[((VNET_DEVICE_INPUT_N_NEXT_NODES /
57 CLIB_CACHE_LINE_BYTES) +1) * CLIB_CACHE_LINE_BYTES] =
58{
59 [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
60 [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
61 [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
62 [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
63};
64
Dave Barach9f6186e2016-11-08 12:12:12 -050065VNET_FEATURE_ARC_INIT (device_input, static) =
66{
Damjan Marion22311502016-10-28 20:30:15 +020067 .arc_name = "device-input",
Damjan Marion51327ac2016-11-09 11:59:42 +010068 .start_nodes = VNET_FEATURES ("device-input"),
Dave Baracha25def72018-11-26 11:04:45 -050069 .last_in_arc = "ethernet-input",
Damjan Marion8b3191e2016-11-09 19:54:20 +010070 .arc_index_ptr = &feature_main.device_input_feature_arc_index,
Damjan Marion22311502016-10-28 20:30:15 +020071};
72
73VNET_FEATURE_INIT (l2_patch, static) = {
74 .arc_name = "device-input",
75 .node_name = "l2-patch",
76 .runs_before = VNET_FEATURES ("ethernet-input"),
77};
78
79VNET_FEATURE_INIT (worker_handoff, static) = {
80 .arc_name = "device-input",
81 .node_name = "worker-handoff",
82 .runs_before = VNET_FEATURES ("ethernet-input"),
83};
84
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010085VNET_FEATURE_INIT (span_input, static) = {
86 .arc_name = "device-input",
87 .node_name = "span-input",
88 .runs_before = VNET_FEATURES ("ethernet-input"),
89};
90
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020091VNET_FEATURE_INIT (p2p_ethernet_node, static) = {
92 .arc_name = "device-input",
93 .node_name = "p2p-ethernet-input",
94 .runs_before = VNET_FEATURES ("ethernet-input"),
95};
96
Damjan Marion22311502016-10-28 20:30:15 +020097VNET_FEATURE_INIT (ethernet_input, static) = {
98 .arc_name = "device-input",
99 .node_name = "ethernet-input",
100 .runs_before = 0, /* not before any other features */
101};
102/* *INDENT-ON* */
103
Damjan Marionb3bb1012017-02-28 21:55:28 +0100104static clib_error_t *
105vnet_device_init (vlib_main_t * vm)
106{
107 vnet_device_main_t *vdm = &vnet_device_main;
108 vlib_thread_main_t *tm = vlib_get_thread_main ();
Damjan Marioneb743fa2017-03-20 16:34:15 +0100109 vlib_thread_registration_t *tr;
110 uword *p;
Damjan Marionb3bb1012017-02-28 21:55:28 +0100111
112 vec_validate_aligned (vdm->workers, tm->n_vlib_mains - 1,
113 CLIB_CACHE_LINE_BYTES);
Damjan Marioneb743fa2017-03-20 16:34:15 +0100114
115 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
116 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
117 if (tr && tr->count > 0)
118 {
Damjan Marion586afd72017-04-05 19:18:20 +0200119 vdm->first_worker_thread_index = tr->first_index;
120 vdm->next_worker_thread_index = tr->first_index;
121 vdm->last_worker_thread_index = tr->first_index + tr->count - 1;
Damjan Marioneb743fa2017-03-20 16:34:15 +0100122 }
Damjan Marionb3bb1012017-02-28 21:55:28 +0100123 return 0;
124}
125
126VLIB_INIT_FUNCTION (vnet_device_init);
Damjan Marioneb743fa2017-03-20 16:34:15 +0100127
Damjan Marion22311502016-10-28 20:30:15 +0200128/*
129 * fd.io coding-style-patch-verification: ON
130 *
131 * Local Variables:
132 * eval: (c-set-style "gnu")
133 * End:
134 */