Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
Matus Fabian | 82e29c4 | 2016-05-11 04:49:46 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <net/if.h> |
| 20 | #include <sys/ioctl.h> |
| 21 | |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 22 | #include <vlib/vlib.h> |
| 23 | #include <vlib/unix/unix.h> |
| 24 | #include <vnet/ethernet/ethernet.h> |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 25 | #include <vnet/devices/devices.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 26 | #include <vnet/feature/feature.h> |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 27 | |
Matus Fabian | 82e29c4 | 2016-05-11 04:49:46 -0700 | [diff] [blame] | 28 | #include <vnet/devices/netmap/net_netmap.h> |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 29 | #include <vnet/devices/netmap/netmap.h> |
| 30 | |
| 31 | #define foreach_netmap_input_error |
| 32 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 33 | typedef enum |
| 34 | { |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 35 | #define _(f,s) NETMAP_INPUT_ERROR_##f, |
| 36 | foreach_netmap_input_error |
| 37 | #undef _ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 38 | NETMAP_INPUT_N_ERROR, |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 39 | } netmap_input_error_t; |
| 40 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 41 | static char *netmap_input_error_strings[] = { |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 42 | #define _(n,s) s, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 43 | foreach_netmap_input_error |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 44 | #undef _ |
| 45 | }; |
| 46 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 47 | typedef struct |
| 48 | { |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 49 | u32 next_index; |
| 50 | u32 hw_if_index; |
| 51 | struct netmap_slot slot; |
| 52 | } netmap_input_trace_t; |
| 53 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 54 | static u8 * |
| 55 | format_netmap_input_trace (u8 * s, va_list * args) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 56 | { |
| 57 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 58 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 59 | netmap_input_trace_t *t = va_arg (*args, netmap_input_trace_t *); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 60 | u32 indent = format_get_indent (s); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 61 | |
| 62 | s = format (s, "netmap: hw_if_index %d next-index %d", |
| 63 | t->hw_if_index, t->next_index); |
| 64 | s = format (s, "\n%Uslot: flags 0x%x len %u buf_idx %u", |
| 65 | format_white_space, indent + 2, |
| 66 | t->slot.flags, t->slot.len, t->slot.buf_idx); |
| 67 | return s; |
| 68 | } |
| 69 | |
| 70 | always_inline void |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 71 | buffer_add_to_chain (vlib_main_t * vm, u32 bi, u32 first_bi, u32 prev_bi) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 72 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 73 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 74 | vlib_buffer_t *first_b = vlib_get_buffer (vm, first_bi); |
| 75 | vlib_buffer_t *prev_b = vlib_get_buffer (vm, prev_bi); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 76 | |
| 77 | /* update first buffer */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 78 | first_b->total_length_not_including_first_buffer += b->current_length; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 79 | |
| 80 | /* update previous buffer */ |
| 81 | prev_b->next_buffer = bi; |
| 82 | prev_b->flags |= VLIB_BUFFER_NEXT_PRESENT; |
| 83 | |
| 84 | /* update current buffer */ |
| 85 | b->next_buffer = 0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | always_inline uword |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 89 | netmap_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 90 | vlib_frame_t * frame, netmap_if_t * nif) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 91 | { |
Damjan Marion | 8bdc63b | 2016-11-02 14:48:21 +0100 | [diff] [blame] | 92 | u32 next_index = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 93 | uword n_trace = vlib_get_trace_count (vm, node); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 94 | netmap_main_t *nm = &netmap_main; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 95 | u32 n_rx_packets = 0; |
| 96 | u32 n_rx_bytes = 0; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 97 | u32 *to_next = 0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 98 | u32 n_free_bufs; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 99 | struct netmap_ring *ring; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 100 | int cur_ring; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 101 | u32 thread_index = vm->thread_index; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 102 | u32 n_buffer_bytes = vlib_buffer_free_list_buffer_size (vm, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 103 | VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 104 | |
| 105 | if (nif->per_interface_next_index != ~0) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 106 | next_index = nif->per_interface_next_index; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 107 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 108 | n_free_bufs = vec_len (nm->rx_buffers[thread_index]); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 109 | if (PREDICT_FALSE (n_free_bufs < VLIB_FRAME_SIZE)) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 110 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 111 | vec_validate (nm->rx_buffers[thread_index], |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 112 | VLIB_FRAME_SIZE + n_free_bufs - 1); |
| 113 | n_free_bufs += |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 114 | vlib_buffer_alloc (vm, &nm->rx_buffers[thread_index][n_free_bufs], |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 115 | VLIB_FRAME_SIZE); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 116 | _vec_len (nm->rx_buffers[thread_index]) = n_free_bufs; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | cur_ring = nif->first_rx_ring; |
| 120 | while (cur_ring <= nif->last_rx_ring && n_free_bufs) |
| 121 | { |
| 122 | int r = 0; |
| 123 | u32 cur_slot_index; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 124 | ring = NETMAP_RXRING (nif->nifp, cur_ring); |
| 125 | r = nm_ring_space (ring); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 126 | |
| 127 | if (!r) |
| 128 | { |
| 129 | cur_ring++; |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | if (r > n_free_bufs) |
| 134 | r = n_free_bufs; |
| 135 | |
| 136 | cur_slot_index = ring->cur; |
| 137 | while (r) |
| 138 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 139 | u32 n_left_to_next; |
| 140 | u32 next0 = next_index; |
| 141 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 142 | |
| 143 | while (r && n_left_to_next) |
| 144 | { |
Damjan Marion | 109cd50 | 2016-11-07 14:05:34 +0100 | [diff] [blame] | 145 | vlib_buffer_t *first_b0 = 0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 146 | u32 offset = 0; |
| 147 | u32 bi0 = 0, first_bi0 = 0, prev_bi0; |
| 148 | u32 next_slot_index = (cur_slot_index + 1) % ring->num_slots; |
| 149 | u32 next2_slot_index = (cur_slot_index + 2) % ring->num_slots; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 150 | struct netmap_slot *slot = &ring->slot[cur_slot_index]; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 151 | u32 data_len = slot->len; |
| 152 | |
| 153 | /* prefetch 2 slots in advance */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 154 | CLIB_PREFETCH (&ring->slot[next2_slot_index], |
| 155 | CLIB_CACHE_LINE_BYTES, LOAD); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 156 | /* prefetch start of next packet */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 157 | CLIB_PREFETCH (NETMAP_BUF |
| 158 | (ring, ring->slot[next_slot_index].buf_idx), |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 159 | CLIB_CACHE_LINE_BYTES, LOAD); |
| 160 | |
| 161 | while (data_len && n_free_bufs) |
| 162 | { |
Damjan Marion | 109cd50 | 2016-11-07 14:05:34 +0100 | [diff] [blame] | 163 | vlib_buffer_t *b0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 164 | /* grab free buffer */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 165 | u32 last_empty_buffer = |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 166 | vec_len (nm->rx_buffers[thread_index]) - 1; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 167 | prev_bi0 = bi0; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 168 | bi0 = nm->rx_buffers[thread_index][last_empty_buffer]; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 169 | b0 = vlib_get_buffer (vm, bi0); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 170 | _vec_len (nm->rx_buffers[thread_index]) = last_empty_buffer; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 171 | n_free_bufs--; |
| 172 | |
| 173 | /* copy data */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 174 | u32 bytes_to_copy = |
| 175 | data_len > n_buffer_bytes ? n_buffer_bytes : data_len; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 176 | b0->current_data = 0; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 177 | clib_memcpy_fast (vlib_buffer_get_current (b0), |
| 178 | (u8 *) NETMAP_BUF (ring, slot->buf_idx) + |
| 179 | offset, bytes_to_copy); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 180 | |
| 181 | /* fill buffer header */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 182 | b0->current_length = bytes_to_copy; |
| 183 | |
| 184 | if (offset == 0) |
| 185 | { |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 186 | b0->total_length_not_including_first_buffer = 0; |
| 187 | b0->flags = VLIB_BUFFER_TOTAL_LENGTH_VALID; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 188 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = |
| 189 | nif->sw_if_index; |
| 190 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 191 | first_bi0 = bi0; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 192 | first_b0 = vlib_get_buffer (vm, first_bi0); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 193 | } |
| 194 | else |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 195 | buffer_add_to_chain (vm, bi0, first_bi0, prev_bi0); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 196 | |
| 197 | offset += bytes_to_copy; |
| 198 | data_len -= bytes_to_copy; |
| 199 | } |
| 200 | |
| 201 | /* trace */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 202 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (first_b0); |
| 203 | if (PREDICT_FALSE (n_trace > 0)) |
| 204 | { |
| 205 | if (PREDICT_TRUE (first_b0 != 0)) |
| 206 | { |
| 207 | netmap_input_trace_t *tr; |
| 208 | vlib_trace_buffer (vm, node, next0, first_b0, |
| 209 | /* follow_chain */ 0); |
| 210 | vlib_set_trace_count (vm, node, --n_trace); |
| 211 | tr = vlib_add_trace (vm, node, first_b0, sizeof (*tr)); |
| 212 | tr->next_index = next0; |
| 213 | tr->hw_if_index = nif->hw_if_index; |
| 214 | memcpy (&tr->slot, slot, sizeof (struct netmap_slot)); |
| 215 | } |
| 216 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 217 | |
| 218 | /* redirect if feature path enabled */ |
Damjan Marion | 87cd119 | 2016-11-04 11:00:27 +0100 | [diff] [blame] | 219 | vnet_feature_start_device_input_x1 (nif->sw_if_index, &next0, |
Damjan Marion | 35af9e5 | 2017-03-06 12:02:50 +0100 | [diff] [blame] | 220 | first_b0); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 221 | |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 222 | /* enque and take next packet */ |
| 223 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 224 | n_left_to_next, first_bi0, |
| 225 | next0); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 226 | |
| 227 | /* next packet */ |
| 228 | n_rx_packets++; |
| 229 | n_rx_bytes += slot->len; |
| 230 | to_next[0] = first_bi0; |
| 231 | to_next += 1; |
| 232 | n_left_to_next--; |
| 233 | cur_slot_index = next_slot_index; |
| 234 | |
| 235 | r--; |
| 236 | } |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 237 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 238 | } |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 239 | ring->head = ring->cur = cur_slot_index; |
| 240 | cur_ring++; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | if (n_rx_packets) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 244 | ioctl (nif->fd, NIOCRXSYNC, NULL); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 245 | |
| 246 | vlib_increment_combined_counter |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 247 | (vnet_get_main ()->interface_main.combined_sw_if_counters |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 248 | + VNET_INTERFACE_COUNTER_RX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 249 | vlib_get_thread_index (), nif->hw_if_index, n_rx_packets, n_rx_bytes); |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 250 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 251 | vnet_device_increment_rx_packets (thread_index, n_rx_packets); |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 252 | |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 253 | return n_rx_packets; |
| 254 | } |
| 255 | |
| 256 | static uword |
| 257 | netmap_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 258 | vlib_frame_t * frame) |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 259 | { |
| 260 | int i; |
| 261 | u32 n_rx_packets = 0; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 262 | u32 thread_index = vm->thread_index; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 263 | netmap_main_t *nm = &netmap_main; |
| 264 | netmap_if_t *nmi; |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 265 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 266 | for (i = 0; i < vec_len (nm->interfaces); i++) |
Mohsin KAZMI | a7575ea | 2016-06-16 06:58:34 +0200 | [diff] [blame] | 267 | { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 268 | nmi = vec_elt_at_index (nm->interfaces, i); |
Mohsin KAZMI | a7575ea | 2016-06-16 06:58:34 +0200 | [diff] [blame] | 269 | if (nmi->is_admin_up && |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 270 | (i % nm->input_cpu_count) == |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 271 | (thread_index - nm->input_cpu_first_index)) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 272 | n_rx_packets += netmap_device_input_fn (vm, node, frame, nmi); |
Mohsin KAZMI | a7575ea | 2016-06-16 06:58:34 +0200 | [diff] [blame] | 273 | } |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 274 | |
| 275 | return n_rx_packets; |
| 276 | } |
| 277 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 278 | /* *INDENT-OFF* */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 279 | VLIB_REGISTER_NODE (netmap_input_node) = { |
| 280 | .function = netmap_input_fn, |
| 281 | .name = "netmap-input", |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 282 | .sibling_of = "device-input", |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 283 | .format_trace = format_netmap_input_trace, |
| 284 | .type = VLIB_NODE_TYPE_INPUT, |
Mohsin KAZMI | a7575ea | 2016-06-16 06:58:34 +0200 | [diff] [blame] | 285 | /* default state is INTERRUPT mode, switch to POLLING if worker threads are enabled */ |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 286 | .state = VLIB_NODE_STATE_INTERRUPT, |
| 287 | .n_errors = NETMAP_INPUT_N_ERROR, |
| 288 | .error_strings = netmap_input_error_strings, |
Damjan Marion | 108c731 | 2016-04-20 05:04:20 +0200 | [diff] [blame] | 289 | }; |
| 290 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 291 | VLIB_NODE_FUNCTION_MULTIARCH (netmap_input_node, netmap_input_fn) |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 292 | /* *INDENT-ON* */ |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 293 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 294 | |
| 295 | /* |
| 296 | * fd.io coding-style-patch-verification: ON |
| 297 | * |
| 298 | * Local Variables: |
| 299 | * eval: (c-set-style "gnu") |
| 300 | * End: |
| 301 | */ |