blob: 4e7f30db4d6da81c0a6963a586902cae61c66f9d [file] [log] [blame]
Damjan Marion8bdc63b2016-11-02 14:48:21 +01001/*
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:
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
16#ifndef included_vnet_vnet_device_h
17#define included_vnet_vnet_device_h
18
Dave Barach3ae28732018-11-16 17:19:00 -050019#include <vppinfra/pcap.h>
Damjan Marion8bdc63b2016-11-02 14:48:21 +010020#include <vnet/l3_types.h>
21
22typedef enum
23{
John Loa60d4cb2016-12-17 03:09:58 -050024 VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT,
Damjan Marion8bdc63b2016-11-02 14:48:21 +010025 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;
32
33#define VNET_DEVICE_INPUT_NEXT_NODES { \
34 [VNET_DEVICE_INPUT_NEXT_DROP] = "error-drop", \
35 [VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input", \
John Loa60d4cb2016-12-17 03:09:58 -050036 [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = "ip4-input-no-checksum", \
37 [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = "ip4-input", \
Damjan Marion8bdc63b2016-11-02 14:48:21 +010038 [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = "ip6-input", \
39 [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = "mpls-input", \
40}
41
Damjan Marionb3bb1012017-02-28 21:55:28 +010042typedef struct
43{
44 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
45
46 /* total input packet counter */
47 u64 aggregate_rx_packets;
48} vnet_device_per_worker_data_t;
49
50typedef struct
51{
52 vnet_device_per_worker_data_t *workers;
Damjan Marion586afd72017-04-05 19:18:20 +020053 uword first_worker_thread_index;
54 uword last_worker_thread_index;
55 uword next_worker_thread_index;
Damjan Marionb3bb1012017-02-28 21:55:28 +010056} vnet_device_main_t;
57
Damjan Marioneb743fa2017-03-20 16:34:15 +010058typedef struct
59{
60 u32 hw_if_index;
61 u32 dev_instance;
62 u16 queue_id;
Damjan Marioneabd4242020-10-07 20:59:07 +020063 vnet_hw_if_rx_mode mode;
Christophe Fontaine26054ea2017-06-20 13:57:47 +020064 u32 interrupt_pending;
Damjan Marioneb743fa2017-03-20 16:34:15 +010065} vnet_device_and_queue_t;
66
67typedef struct
68{
69 vnet_device_and_queue_t *devices_and_queues;
Damjan Marion153646e2017-04-05 18:15:45 +020070 vlib_node_state_t enabled_node_state;
Damjan Marioneb743fa2017-03-20 16:34:15 +010071} vnet_device_input_runtime_t;
72
Damjan Marionb3bb1012017-02-28 21:55:28 +010073extern vnet_device_main_t vnet_device_main;
Damjan Marion51327ac2016-11-09 11:59:42 +010074extern vlib_node_registration_t device_input_node;
Damjan Marion7dc41462016-11-15 19:47:58 +010075extern const u32 device_input_next_node_advance[];
Damjan Marionbd846cd2017-11-21 13:12:41 +010076extern const u32 device_input_next_node_flags[];
Damjan Marion51327ac2016-11-09 11:59:42 +010077
Damjan Marioneb743fa2017-03-20 16:34:15 +010078static inline void
Damjan Marion44036902017-04-28 12:29:15 +020079vnet_hw_interface_set_input_node (vnet_main_t * vnm, u32 hw_if_index,
80 u32 node_index)
Damjan Marioneb743fa2017-03-20 16:34:15 +010081{
Damjan Marioneb743fa2017-03-20 16:34:15 +010082 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
83 hw->input_node_index = node_index;
84}
85
Damjan Marion44036902017-04-28 12:29:15 +020086void vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
87 u16 queue_id, uword thread_index);
88int vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
89 u16 queue_id);
90int vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
Damjan Marioneabd4242020-10-07 20:59:07 +020091 u16 queue_id, vnet_hw_if_rx_mode mode);
Damjan Marion44036902017-04-28 12:29:15 +020092int vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
Damjan Marioneabd4242020-10-07 20:59:07 +020093 u16 queue_id, vnet_hw_if_rx_mode * mode);
Damjan Marioneb743fa2017-03-20 16:34:15 +010094
Damjan Marionb3bb1012017-02-28 21:55:28 +010095static inline u64
96vnet_get_aggregate_rx_packets (void)
97{
98 vnet_device_main_t *vdm = &vnet_device_main;
99 u64 sum = 0;
100 vnet_device_per_worker_data_t *pwd;
101
102 vec_foreach (pwd, vdm->workers) sum += pwd->aggregate_rx_packets;
103
104 return sum;
105}
106
107static inline void
Damjan Marion586afd72017-04-05 19:18:20 +0200108vnet_device_increment_rx_packets (u32 thread_index, u64 count)
Damjan Marionb3bb1012017-02-28 21:55:28 +0100109{
110 vnet_device_main_t *vdm = &vnet_device_main;
111 vnet_device_per_worker_data_t *pwd;
112
Damjan Marion586afd72017-04-05 19:18:20 +0200113 pwd = vec_elt_at_index (vdm->workers, thread_index);
Damjan Marionb3bb1012017-02-28 21:55:28 +0100114 pwd->aggregate_rx_packets += count;
115}
116
Damjan Marioneb743fa2017-03-20 16:34:15 +0100117static_always_inline vnet_device_and_queue_t *
118vnet_get_device_and_queue (vlib_main_t * vm, vlib_node_runtime_t * node)
119{
120 vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
121 return rt->devices_and_queues;
122}
123
Damjan Marion153646e2017-04-05 18:15:45 +0200124static_always_inline uword
125vnet_get_device_input_thread_index (vnet_main_t * vnm, u32 hw_if_index,
126 u16 queue_id)
127{
128 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
129 ASSERT (queue_id < vec_len (hw->input_node_thread_index_by_queue));
130 return hw->input_node_thread_index_by_queue[queue_id];
131}
132
Damjan Marioneb743fa2017-03-20 16:34:15 +0100133static_always_inline void
134vnet_device_input_set_interrupt_pending (vnet_main_t * vnm, u32 hw_if_index,
135 u16 queue_id)
136{
Damjan Marion153646e2017-04-05 18:15:45 +0200137 vlib_main_t *vm;
138 vnet_hw_interface_t *hw;
139 vnet_device_input_runtime_t *rt;
140 vnet_device_and_queue_t *dq;
141 uword idx;
Damjan Marioneb743fa2017-03-20 16:34:15 +0100142
Damjan Marion153646e2017-04-05 18:15:45 +0200143 hw = vnet_get_hw_interface (vnm, hw_if_index);
144 idx = vnet_get_device_input_thread_index (vnm, hw_if_index, queue_id);
145 vm = vlib_mains[idx];
146 rt = vlib_node_get_runtime_data (vm, hw->input_node_index);
147 idx = hw->dq_runtime_index_by_queue[queue_id];
148 dq = vec_elt_at_index (rt->devices_and_queues, idx);
Sirshak Das5b718d52018-10-12 09:38:27 -0500149
150 clib_atomic_store_rel_n (&(dq->interrupt_pending), 1);
Damjan Marion153646e2017-04-05 18:15:45 +0200151
152 vlib_node_set_interrupt_pending (vm, hw->input_node_index);
Damjan Marioneb743fa2017-03-20 16:34:15 +0100153}
154
Sirshak Das5b718d52018-10-12 09:38:27 -0500155/*
156 * Acquire RMW Access
157 * Paired with Release Store in vnet_device_input_set_interrupt_pending
158 */
Dave Barach32f4e182018-03-20 08:49:02 -0400159#define foreach_device_and_queue(var,vec) \
160 for (var = (vec); var < vec_end (vec); var++) \
Damjan Marioneabd4242020-10-07 20:59:07 +0200161 if ((var->mode == VNET_HW_IF_RX_MODE_POLLING) \
Sirshak Das5b718d52018-10-12 09:38:27 -0500162 || clib_atomic_swap_acq_n (&((var)->interrupt_pending), 0))
Damjan Marion153646e2017-04-05 18:15:45 +0200163
Damjan Marion8bdc63b2016-11-02 14:48:21 +0100164#endif /* included_vnet_vnet_device_h */
165
166/*
167 * fd.io coding-style-patch-verification: ON
168 *
169 * Local Variables:
170 * eval: (c-set-style "gnu")
171 * End:
172 */