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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vnet/devices/devices.h>
18 #include <vnet/feature/feature.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ethernet/ethernet.h>
22 vnet_device_main_t vnet_device_main;
25 device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
32 VLIB_REGISTER_NODE (device_input_node) = {
33 .function = device_input_fn,
34 .name = "device-input",
35 .runtime_data_bytes = sizeof (vnet_hw_if_rx_node_runtime_t),
36 .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,
42 /* Table defines how much we need to advance current data pointer
43 in the buffer if we shortcut to l3 nodes */
45 const u32 __attribute__((aligned (CLIB_CACHE_LINE_BYTES)))
46 device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES /
47 CLIB_CACHE_LINE_BYTES) +1) * CLIB_CACHE_LINE_BYTES] =
49 [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = sizeof (ethernet_header_t),
50 [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = sizeof (ethernet_header_t),
51 [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = sizeof (ethernet_header_t),
52 [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = sizeof (ethernet_header_t),
55 const u32 __attribute__((aligned (CLIB_CACHE_LINE_BYTES)))
56 device_input_next_node_flags[((VNET_DEVICE_INPUT_N_NEXT_NODES /
57 CLIB_CACHE_LINE_BYTES) +1) * CLIB_CACHE_LINE_BYTES] =
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,
65 VNET_FEATURE_ARC_INIT (device_input, static) =
67 .arc_name = "device-input",
68 .start_nodes = VNET_FEATURES ("device-input"),
69 .last_in_arc = "ethernet-input",
70 .arc_index_ptr = &feature_main.device_input_feature_arc_index,
73 VNET_FEATURE_INIT (l2_patch, static) = {
74 .arc_name = "device-input",
75 .node_name = "l2-patch",
76 .runs_before = VNET_FEATURES ("ethernet-input"),
79 VNET_FEATURE_INIT (worker_handoff, static) = {
80 .arc_name = "device-input",
81 .node_name = "worker-handoff",
82 .runs_before = VNET_FEATURES ("ethernet-input"),
85 VNET_FEATURE_INIT (span_input, static) = {
86 .arc_name = "device-input",
87 .node_name = "span-input",
88 .runs_before = VNET_FEATURES ("ethernet-input"),
91 VNET_FEATURE_INIT (p2p_ethernet_node, static) = {
92 .arc_name = "device-input",
93 .node_name = "p2p-ethernet-input",
94 .runs_before = VNET_FEATURES ("ethernet-input"),
97 VNET_FEATURE_INIT (ethernet_input, static) = {
98 .arc_name = "device-input",
99 .node_name = "ethernet-input",
100 .runs_before = 0, /* not before any other features */
104 static clib_error_t *
105 vnet_device_init (vlib_main_t * vm)
107 vnet_device_main_t *vdm = &vnet_device_main;
108 vlib_thread_main_t *tm = vlib_get_thread_main ();
109 vlib_thread_registration_t *tr;
112 vec_validate_aligned (vdm->workers, tm->n_vlib_mains - 1,
113 CLIB_CACHE_LINE_BYTES);
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)
119 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;
126 VLIB_INIT_FUNCTION (vnet_device_init);
129 * fd.io coding-style-patch-verification: ON
132 * eval: (c-set-style "gnu")