2 * Copyright (c) 2016 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 #ifndef included_vnet_vnet_device_h
17 #define included_vnet_vnet_device_h
19 #include <vnet/unix/pcap.h>
20 #include <vnet/l3_types.h>
24 VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT,
25 VNET_DEVICE_INPUT_NEXT_IP4_INPUT,
26 VNET_DEVICE_INPUT_NEXT_IP6_INPUT,
27 VNET_DEVICE_INPUT_NEXT_MPLS_INPUT,
28 VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT,
29 VNET_DEVICE_INPUT_NEXT_DROP,
30 VNET_DEVICE_INPUT_N_NEXT_NODES,
31 } vnet_device_input_next_t;
33 #define VNET_DEVICE_INPUT_NEXT_NODES { \
34 [VNET_DEVICE_INPUT_NEXT_DROP] = "error-drop", \
35 [VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input", \
36 [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = "ip4-input-no-checksum", \
37 [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = "ip4-input", \
38 [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = "ip6-input", \
39 [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = "mpls-input", \
44 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
46 /* total input packet counter */
47 u64 aggregate_rx_packets;
48 } vnet_device_per_worker_data_t;
52 vnet_device_per_worker_data_t *workers;
53 uword first_worker_thread_index;
54 uword last_worker_thread_index;
55 uword next_worker_thread_index;
63 } vnet_device_and_queue_t;
67 vnet_device_and_queue_t *devices_and_queues;
68 } vnet_device_input_runtime_t;
70 extern vnet_device_main_t vnet_device_main;
71 extern vlib_node_registration_t device_input_node;
72 extern const u32 device_input_next_node_advance[];
75 vnet_set_device_input_node (u32 hw_if_index, u32 node_index)
77 vnet_main_t *vnm = vnet_get_main ();
78 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
79 hw->input_node_index = node_index;
82 void vnet_device_input_assign_thread (u32 hw_if_index, u16 queue_id,
86 vnet_get_aggregate_rx_packets (void)
88 vnet_device_main_t *vdm = &vnet_device_main;
90 vnet_device_per_worker_data_t *pwd;
92 vec_foreach (pwd, vdm->workers) sum += pwd->aggregate_rx_packets;
98 vnet_device_increment_rx_packets (u32 thread_index, u64 count)
100 vnet_device_main_t *vdm = &vnet_device_main;
101 vnet_device_per_worker_data_t *pwd;
103 pwd = vec_elt_at_index (vdm->workers, thread_index);
104 pwd->aggregate_rx_packets += count;
107 static_always_inline vnet_device_and_queue_t *
108 vnet_get_device_and_queue (vlib_main_t * vm, vlib_node_runtime_t * node)
110 vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
111 return rt->devices_and_queues;
114 static_always_inline void
115 vnet_device_input_set_interrupt_pending (vnet_main_t * vnm, u32 hw_if_index,
118 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
120 ASSERT (queue_id < vec_len (hw->input_node_thread_index_by_queue));
121 u32 thread_index = hw->input_node_thread_index_by_queue[queue_id];
122 vlib_node_set_interrupt_pending (vlib_mains[thread_index],
123 hw->input_node_index);
126 #endif /* included_vnet_vnet_device_h */
129 * fd.io coding-style-patch-verification: ON
132 * eval: (c-set-style "gnu")