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