Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 1 | /* |
| 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 Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 16 | #include <vnet/vnet.h> |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 17 | #include <vnet/devices/devices.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 18 | #include <vnet/feature/feature.h> |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 19 | #include <vnet/ip/ip.h> |
| 20 | #include <vnet/ethernet/ethernet.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 21 | |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 22 | vnet_device_main_t vnet_device_main; |
| 23 | |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 24 | static uword |
| 25 | device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 26 | vlib_frame_t * frame) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 31 | /* *INDENT-OFF* */ |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 32 | VLIB_REGISTER_NODE (device_input_node) = { |
| 33 | .function = device_input_fn, |
| 34 | .name = "device-input", |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 35 | .runtime_data_bytes = sizeof (vnet_device_input_runtime_t), |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 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, |
| 40 | }; |
| 41 | |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 42 | /* Table defines how much we need to advance current data pointer |
| 43 | in the buffer if we shortcut to l3 nodes */ |
| 44 | |
| 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] = |
| 48 | { |
| 49 | [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = sizeof (ethernet_header_t), |
Sergio Gonzalez Monroy | 767b2f5 | 2016-12-20 15:20:32 +0000 | [diff] [blame] | 50 | [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = sizeof (ethernet_header_t), |
Damjan Marion | 7dc4146 | 2016-11-15 19:47:58 +0100 | [diff] [blame] | 51 | [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = sizeof (ethernet_header_t), |
| 52 | [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = sizeof (ethernet_header_t), |
| 53 | }; |
| 54 | |
Damjan Marion | bd846cd | 2017-11-21 13:12:41 +0100 | [diff] [blame] | 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] = |
| 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 Barach | 9f6186e | 2016-11-08 12:12:12 -0500 | [diff] [blame] | 65 | VNET_FEATURE_ARC_INIT (device_input, static) = |
| 66 | { |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 67 | .arc_name = "device-input", |
Damjan Marion | 51327ac | 2016-11-09 11:59:42 +0100 | [diff] [blame] | 68 | .start_nodes = VNET_FEATURES ("device-input"), |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 69 | .arc_index_ptr = &feature_main.device_input_feature_arc_index, |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | VNET_FEATURE_INIT (l2_patch, static) = { |
| 73 | .arc_name = "device-input", |
| 74 | .node_name = "l2-patch", |
| 75 | .runs_before = VNET_FEATURES ("ethernet-input"), |
| 76 | }; |
| 77 | |
| 78 | VNET_FEATURE_INIT (worker_handoff, static) = { |
| 79 | .arc_name = "device-input", |
| 80 | .node_name = "worker-handoff", |
| 81 | .runs_before = VNET_FEATURES ("ethernet-input"), |
| 82 | }; |
| 83 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 84 | VNET_FEATURE_INIT (span_input, static) = { |
| 85 | .arc_name = "device-input", |
| 86 | .node_name = "span-input", |
| 87 | .runs_before = VNET_FEATURES ("ethernet-input"), |
| 88 | }; |
| 89 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 90 | VNET_FEATURE_INIT (p2p_ethernet_node, static) = { |
| 91 | .arc_name = "device-input", |
| 92 | .node_name = "p2p-ethernet-input", |
| 93 | .runs_before = VNET_FEATURES ("ethernet-input"), |
| 94 | }; |
| 95 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 96 | VNET_FEATURE_INIT (ethernet_input, static) = { |
| 97 | .arc_name = "device-input", |
| 98 | .node_name = "ethernet-input", |
| 99 | .runs_before = 0, /* not before any other features */ |
| 100 | }; |
| 101 | /* *INDENT-ON* */ |
| 102 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 103 | static int |
| 104 | vnet_device_queue_sort (void *a1, void *a2) |
| 105 | { |
| 106 | vnet_device_and_queue_t *dq1 = a1; |
| 107 | vnet_device_and_queue_t *dq2 = a2; |
| 108 | |
| 109 | if (dq1->dev_instance > dq2->dev_instance) |
| 110 | return 1; |
| 111 | else if (dq1->dev_instance < dq2->dev_instance) |
| 112 | return -1; |
| 113 | else if (dq1->queue_id > dq2->queue_id) |
| 114 | return 1; |
| 115 | else if (dq1->queue_id < dq2->queue_id) |
| 116 | return -1; |
| 117 | else |
| 118 | return 0; |
| 119 | } |
| 120 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 121 | static void |
| 122 | vnet_device_queue_update (vnet_main_t * vnm, vnet_device_input_runtime_t * rt) |
| 123 | { |
| 124 | vnet_device_and_queue_t *dq; |
| 125 | vnet_hw_interface_t *hw; |
| 126 | |
| 127 | vec_sort_with_function (rt->devices_and_queues, vnet_device_queue_sort); |
| 128 | |
| 129 | vec_foreach (dq, rt->devices_and_queues) |
| 130 | { |
| 131 | hw = vnet_get_hw_interface (vnm, dq->hw_if_index); |
| 132 | vec_validate (hw->dq_runtime_index_by_queue, dq->queue_id); |
| 133 | hw->dq_runtime_index_by_queue[dq->queue_id] = dq - rt->devices_and_queues; |
| 134 | } |
| 135 | } |
| 136 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 137 | void |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 138 | vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index, |
| 139 | u16 queue_id, uword thread_index) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 140 | { |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 141 | vnet_device_main_t *vdm = &vnet_device_main; |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 142 | vlib_main_t *vm, *vm0; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 143 | vnet_device_input_runtime_t *rt; |
| 144 | vnet_device_and_queue_t *dq; |
| 145 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 146 | |
| 147 | ASSERT (hw->input_node_index > 0); |
| 148 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 149 | if (vdm->first_worker_thread_index == 0) |
| 150 | thread_index = 0; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 151 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 152 | if (thread_index != 0 && |
| 153 | (thread_index < vdm->first_worker_thread_index || |
| 154 | thread_index > vdm->last_worker_thread_index)) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 155 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 156 | thread_index = vdm->next_worker_thread_index++; |
| 157 | if (vdm->next_worker_thread_index > vdm->last_worker_thread_index) |
| 158 | vdm->next_worker_thread_index = vdm->first_worker_thread_index; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 161 | vm = vlib_mains[thread_index]; |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 162 | vm0 = vlib_get_main (); |
| 163 | |
| 164 | vlib_worker_thread_barrier_sync (vm0); |
| 165 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 166 | rt = vlib_node_get_runtime_data (vm, hw->input_node_index); |
| 167 | |
| 168 | vec_add2 (rt->devices_and_queues, dq, 1); |
| 169 | dq->hw_if_index = hw_if_index; |
| 170 | dq->dev_instance = hw->dev_instance; |
| 171 | dq->queue_id = queue_id; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 172 | dq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING; |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 173 | rt->enabled_node_state = VLIB_NODE_STATE_POLLING; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 174 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 175 | vnet_device_queue_update (vnm, rt); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 176 | vec_validate (hw->input_node_thread_index_by_queue, queue_id); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 177 | vec_validate (hw->rx_mode_by_queue, queue_id); |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 178 | hw->input_node_thread_index_by_queue[queue_id] = thread_index; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 179 | hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_POLLING; |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 180 | |
| 181 | vlib_worker_thread_barrier_release (vm0); |
| 182 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 183 | vlib_node_set_state (vm, hw->input_node_index, rt->enabled_node_state); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 186 | int |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 187 | vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index, |
| 188 | u16 queue_id) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 189 | { |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 190 | vlib_main_t *vm, *vm0; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 191 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 192 | vnet_device_input_runtime_t *rt; |
| 193 | vnet_device_and_queue_t *dq; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 194 | uword old_thread_index; |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 195 | vnet_hw_interface_rx_mode mode; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 196 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 197 | if (hw->input_node_thread_index_by_queue == 0) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 198 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 199 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 200 | if (vec_len (hw->input_node_thread_index_by_queue) < queue_id + 1) |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 201 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 202 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 203 | old_thread_index = hw->input_node_thread_index_by_queue[queue_id]; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 204 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 205 | vm = vlib_mains[old_thread_index]; |
| 206 | |
| 207 | rt = vlib_node_get_runtime_data (vm, hw->input_node_index); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 208 | |
| 209 | vec_foreach (dq, rt->devices_and_queues) |
| 210 | if (dq->hw_if_index == hw_if_index && dq->queue_id == queue_id) |
| 211 | { |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 212 | mode = dq->mode; |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 213 | goto delete; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 217 | |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 218 | delete: |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 219 | |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 220 | vm0 = vlib_get_main (); |
| 221 | vlib_worker_thread_barrier_sync (vm0); |
| 222 | vec_del1 (rt->devices_and_queues, dq - rt->devices_and_queues); |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 223 | vnet_device_queue_update (vnm, rt); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 224 | hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 225 | vlib_worker_thread_barrier_release (vm0); |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 226 | |
| 227 | if (vec_len (rt->devices_and_queues) == 0) |
| 228 | vlib_node_set_state (vm, hw->input_node_index, VLIB_NODE_STATE_DISABLED); |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 229 | else if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING) |
| 230 | { |
| 231 | /* |
| 232 | * if the deleted interface is polling, we may need to set the node state |
| 233 | * to interrupt if there is no more polling interface for this device's |
| 234 | * corresponding thread. This is because mixed interfaces |
| 235 | * (polling and interrupt), assigned to the same thread, set the |
| 236 | * thread to polling prior to the deletion. |
| 237 | */ |
| 238 | vec_foreach (dq, rt->devices_and_queues) |
| 239 | { |
| 240 | if (dq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING) |
| 241 | return 0; |
| 242 | } |
| 243 | rt->enabled_node_state = VLIB_NODE_STATE_INTERRUPT; |
| 244 | vlib_node_set_state (vm, hw->input_node_index, rt->enabled_node_state); |
| 245 | } |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 250 | |
| 251 | int |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 252 | vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 253 | u16 queue_id, vnet_hw_interface_rx_mode mode) |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 254 | { |
| 255 | vlib_main_t *vm; |
| 256 | uword thread_index; |
| 257 | vnet_device_and_queue_t *dq; |
| 258 | vlib_node_state_t enabled_node_state; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 259 | ASSERT (mode < VNET_HW_INTERFACE_NUM_RX_MODES); |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 260 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 261 | vnet_device_input_runtime_t *rt; |
| 262 | int is_polling = 0; |
| 263 | |
Damjan Marion | 4e53a0d | 2017-06-21 14:29:44 +0200 | [diff] [blame] | 264 | if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT) |
| 265 | mode = hw->default_rx_mode; |
| 266 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 267 | if (hw->input_node_thread_index_by_queue == 0 || hw->rx_mode_by_queue == 0) |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 268 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 269 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 270 | if (hw->rx_mode_by_queue[queue_id] == mode) |
| 271 | return 0; |
| 272 | |
| 273 | if (mode != VNET_HW_INTERFACE_RX_MODE_POLLING && |
| 274 | (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE) == 0) |
| 275 | return VNET_API_ERROR_UNSUPPORTED; |
| 276 | |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 277 | if ((vec_len (hw->input_node_thread_index_by_queue) < queue_id + 1) || |
| 278 | (vec_len (hw->rx_mode_by_queue) < queue_id + 1)) |
| 279 | return VNET_API_ERROR_INVALID_QUEUE; |
| 280 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 281 | hw->rx_mode_by_queue[queue_id] = mode; |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 282 | thread_index = hw->input_node_thread_index_by_queue[queue_id]; |
| 283 | vm = vlib_mains[thread_index]; |
| 284 | |
| 285 | rt = vlib_node_get_runtime_data (vm, hw->input_node_index); |
| 286 | |
| 287 | vec_foreach (dq, rt->devices_and_queues) |
| 288 | { |
| 289 | if (dq->hw_if_index == hw_if_index && dq->queue_id == queue_id) |
| 290 | dq->mode = mode; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 291 | if (dq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING) |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 292 | is_polling = 1; |
| 293 | } |
| 294 | |
| 295 | if (is_polling) |
| 296 | enabled_node_state = VLIB_NODE_STATE_POLLING; |
| 297 | else |
| 298 | enabled_node_state = VLIB_NODE_STATE_INTERRUPT; |
| 299 | |
| 300 | if (rt->enabled_node_state != enabled_node_state) |
| 301 | { |
| 302 | rt->enabled_node_state = enabled_node_state; |
| 303 | if (vlib_node_get_state (vm, hw->input_node_index) != |
| 304 | VLIB_NODE_STATE_DISABLED) |
| 305 | vlib_node_set_state (vm, hw->input_node_index, enabled_node_state); |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | int |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 312 | vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 313 | u16 queue_id, vnet_hw_interface_rx_mode * mode) |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 314 | { |
| 315 | vlib_main_t *vm; |
| 316 | uword thread_index; |
| 317 | vnet_device_and_queue_t *dq; |
| 318 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 319 | vnet_device_input_runtime_t *rt; |
| 320 | |
| 321 | if (hw->input_node_thread_index_by_queue == 0) |
| 322 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 323 | |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 324 | if ((vec_len (hw->input_node_thread_index_by_queue) < queue_id + 1) || |
| 325 | (vec_len (hw->rx_mode_by_queue) < queue_id + 1)) |
| 326 | return VNET_API_ERROR_INVALID_QUEUE; |
| 327 | |
Damjan Marion | 153646e | 2017-04-05 18:15:45 +0200 | [diff] [blame] | 328 | thread_index = hw->input_node_thread_index_by_queue[queue_id]; |
| 329 | vm = vlib_mains[thread_index]; |
| 330 | |
| 331 | rt = vlib_node_get_runtime_data (vm, hw->input_node_index); |
| 332 | |
| 333 | vec_foreach (dq, rt->devices_and_queues) |
| 334 | if (dq->hw_if_index == hw_if_index && dq->queue_id == queue_id) |
| 335 | { |
| 336 | *mode = dq->mode; |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | return VNET_API_ERROR_INVALID_INTERFACE; |
| 341 | } |
| 342 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 343 | |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 344 | |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 345 | static clib_error_t * |
| 346 | vnet_device_init (vlib_main_t * vm) |
| 347 | { |
| 348 | vnet_device_main_t *vdm = &vnet_device_main; |
| 349 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 350 | vlib_thread_registration_t *tr; |
| 351 | uword *p; |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 352 | |
| 353 | vec_validate_aligned (vdm->workers, tm->n_vlib_mains - 1, |
| 354 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 355 | |
| 356 | p = hash_get_mem (tm->thread_registrations_by_name, "workers"); |
| 357 | tr = p ? (vlib_thread_registration_t *) p[0] : 0; |
| 358 | if (tr && tr->count > 0) |
| 359 | { |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 360 | vdm->first_worker_thread_index = tr->first_index; |
| 361 | vdm->next_worker_thread_index = tr->first_index; |
| 362 | vdm->last_worker_thread_index = tr->first_index + tr->count - 1; |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 363 | } |
Damjan Marion | b3bb101 | 2017-02-28 21:55:28 +0100 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | VLIB_INIT_FUNCTION (vnet_device_init); |
Damjan Marion | eb743fa | 2017-03-20 16:34:15 +0100 | [diff] [blame] | 368 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 369 | /* |
| 370 | * fd.io coding-style-patch-verification: ON |
| 371 | * |
| 372 | * Local Variables: |
| 373 | * eval: (c-set-style "gnu") |
| 374 | * End: |
| 375 | */ |