Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +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 | #include <vnet/vnet.h> |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 18 | #include <vnet/hash/hash.h> |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 19 | #include <vlib/threads.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 20 | #include <vnet/feature/feature.h> |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 21 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 22 | typedef struct |
| 23 | { |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 24 | vnet_hash_fn_t hash_fn; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 25 | uword *workers_bitmap; |
| 26 | u32 *workers; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 27 | } per_inteface_handoff_data_t; |
| 28 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 29 | typedef struct |
| 30 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 31 | u32 cached_next_index; |
| 32 | u32 num_workers; |
| 33 | u32 first_worker_index; |
| 34 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 35 | per_inteface_handoff_data_t *if_data; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 36 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 37 | /* Worker handoff index */ |
| 38 | u32 frame_queue_index; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 39 | } handoff_main_t; |
| 40 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 41 | extern handoff_main_t handoff_main; |
| 42 | |
| 43 | #ifndef CLIB_MARCH_VARIANT |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 44 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 45 | handoff_main_t handoff_main; |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 46 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 47 | #endif /* CLIB_MARCH_VARIANT */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 48 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 49 | typedef struct |
| 50 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 51 | u32 sw_if_index; |
| 52 | u32 next_worker_index; |
| 53 | u32 buffer_index; |
| 54 | } worker_handoff_trace_t; |
| 55 | |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 56 | #define foreach_worker_handoff_error \ |
| 57 | _(CONGESTION_DROP, "congestion drop") |
| 58 | |
| 59 | typedef enum |
| 60 | { |
| 61 | #define _(sym,str) WORKER_HANDOFF_ERROR_##sym, |
| 62 | foreach_worker_handoff_error |
| 63 | #undef _ |
| 64 | WORKER_HANDOFF_N_ERROR, |
| 65 | } worker_handoff_error_t; |
| 66 | |
| 67 | static char *worker_handoff_error_strings[] = { |
| 68 | #define _(sym,string) string, |
| 69 | foreach_worker_handoff_error |
| 70 | #undef _ |
| 71 | }; |
| 72 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 73 | /* packet trace format function */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 74 | static u8 * |
| 75 | format_worker_handoff_trace (u8 * s, va_list * args) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 76 | { |
| 77 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 78 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 79 | worker_handoff_trace_t *t = va_arg (*args, worker_handoff_trace_t *); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 80 | |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 81 | s = format (s, "worker-handoff: sw_if_index %d, next_worker %d, buffer 0x%x", |
| 82 | t->sw_if_index, t->next_worker_index, t->buffer_index); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 83 | return s; |
| 84 | } |
| 85 | |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 86 | static void |
| 87 | worker_handoff_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 88 | vlib_buffer_t **bufs, u16 *threads, u32 n_vectors) |
| 89 | { |
| 90 | worker_handoff_trace_t *t; |
| 91 | vlib_buffer_t **b; |
| 92 | u16 *ti; |
| 93 | |
| 94 | b = bufs; |
| 95 | ti = threads; |
| 96 | |
| 97 | while (n_vectors) |
| 98 | { |
| 99 | t = vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 100 | t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 101 | t->next_worker_index = ti[0]; |
| 102 | t->buffer_index = vlib_get_buffer_index (vm, b[0]); |
| 103 | |
| 104 | b += 1; |
| 105 | ti += 1; |
| 106 | n_vectors -= 1; |
| 107 | } |
| 108 | } |
| 109 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 110 | VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, |
| 111 | vlib_node_runtime_t * node, |
| 112 | vlib_frame_t * frame) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 113 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 114 | handoff_main_t *hm = &handoff_main; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 115 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 116 | u32 n_enq, n_left_from, *from; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 117 | u16 thread_indices[VLIB_FRAME_SIZE], *ti; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 118 | |
| 119 | from = vlib_frame_vector_args (frame); |
| 120 | n_left_from = frame->n_vectors; |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 121 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 122 | |
| 123 | b = bufs; |
| 124 | ti = thread_indices; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 125 | |
| 126 | while (n_left_from > 0) |
| 127 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 128 | per_inteface_handoff_data_t *ihd0; |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 129 | u32 sw_if_index0, hash, index0; |
| 130 | void *data; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 131 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 132 | sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 133 | ihd0 = vec_elt_at_index (hm->if_data, sw_if_index0); |
| 134 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 135 | /* Compute ingress LB hash */ |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 136 | data = vlib_buffer_get_current (b[0]); |
| 137 | ihd0->hash_fn (&data, &hash, 1); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 138 | |
| 139 | /* if input node did not specify next index, then packet |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 140 | should go to ethernet-input */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 141 | |
| 142 | if (PREDICT_TRUE (is_pow2 (vec_len (ihd0->workers)))) |
| 143 | index0 = hash & (vec_len (ihd0->workers) - 1); |
| 144 | else |
| 145 | index0 = hash % vec_len (ihd0->workers); |
| 146 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 147 | ti[0] = hm->first_worker_index + ihd0->workers[index0]; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 148 | |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 149 | /* next */ |
| 150 | n_left_from -= 1; |
| 151 | ti += 1; |
| 152 | b += 1; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 155 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) |
| 156 | worker_handoff_trace_frame (vm, node, bufs, thread_indices, |
| 157 | frame->n_vectors); |
| 158 | |
Damjan Marion | 9e7a0b4 | 2021-05-14 14:50:01 +0200 | [diff] [blame] | 159 | n_enq = vlib_buffer_enqueue_to_thread (vm, node, hm->frame_queue_index, from, |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 160 | thread_indices, frame->n_vectors, 1); |
| 161 | |
| 162 | if (n_enq < frame->n_vectors) |
| 163 | vlib_node_increment_counter (vm, node->node_index, |
| 164 | WORKER_HANDOFF_ERROR_CONGESTION_DROP, |
| 165 | frame->n_vectors - n_enq); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 166 | return frame->n_vectors; |
| 167 | } |
| 168 | |
| 169 | VLIB_REGISTER_NODE (worker_handoff_node) = { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 170 | .name = "worker-handoff", |
| 171 | .vector_size = sizeof (u32), |
| 172 | .format_trace = format_worker_handoff_trace, |
| 173 | .type = VLIB_NODE_TYPE_INTERNAL, |
Damjan Marion | 78fd7e8 | 2018-07-20 18:47:05 +0200 | [diff] [blame] | 174 | .n_errors = ARRAY_LEN(worker_handoff_error_strings), |
| 175 | .error_strings = worker_handoff_error_strings, |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 176 | |
| 177 | .n_next_nodes = 1, |
| 178 | .next_nodes = { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 179 | [0] = "error-drop", |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 180 | }, |
| 181 | }; |
| 182 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 183 | #ifndef CLIB_MARCH_VARIANT |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 184 | |
Damjan Marion | e33b9e0 | 2016-10-17 12:51:18 +0200 | [diff] [blame] | 185 | int |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 186 | interface_handoff_enable_disable (vlib_main_t *vm, u32 sw_if_index, |
| 187 | uword *bitmap, u8 is_sym, int is_l4, |
| 188 | int enable_disable) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 189 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 190 | handoff_main_t *hm = &handoff_main; |
| 191 | vnet_sw_interface_t *sw; |
| 192 | vnet_main_t *vnm = vnet_get_main (); |
| 193 | per_inteface_handoff_data_t *d; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 194 | int i, rv = 0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 195 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 196 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 197 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 198 | |
| 199 | sw = vnet_get_sw_interface (vnm, sw_if_index); |
| 200 | if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 201 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 202 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 203 | if (clib_bitmap_last_set (bitmap) >= hm->num_workers) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 204 | return VNET_API_ERROR_INVALID_WORKER; |
| 205 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 206 | if (hm->frame_queue_index == ~0) |
Damjan Marion | 4d56e05 | 2018-07-19 17:52:31 +0200 | [diff] [blame] | 207 | { |
| 208 | vlib_node_t *n = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); |
| 209 | hm->frame_queue_index = vlib_frame_queue_main_init (n->index, 0); |
| 210 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 211 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 212 | vec_validate (hm->if_data, sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 213 | d = vec_elt_at_index (hm->if_data, sw_if_index); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 214 | |
| 215 | vec_free (d->workers); |
| 216 | vec_free (d->workers_bitmap); |
| 217 | |
| 218 | if (enable_disable) |
| 219 | { |
| 220 | d->workers_bitmap = bitmap; |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 221 | clib_bitmap_foreach (i, bitmap) |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 222 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 223 | vec_add1(d->workers, i); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 224 | } |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 225 | |
| 226 | if (is_sym) |
| 227 | { |
| 228 | if (is_l4) |
| 229 | return VNET_API_ERROR_UNIMPLEMENTED; |
| 230 | |
| 231 | d->hash_fn = vnet_hash_function_from_name ( |
Florin Coras | 1e6d30b | 2021-11-02 10:32:19 -0700 | [diff] [blame] | 232 | "handoff-eth-sym", VNET_HASH_FN_TYPE_ETHERNET); |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 233 | } |
| 234 | else |
| 235 | { |
| 236 | if (is_l4) |
| 237 | d->hash_fn = |
| 238 | vnet_hash_default_function (VNET_HASH_FN_TYPE_ETHERNET); |
| 239 | else |
| 240 | d->hash_fn = vnet_hash_function_from_name ( |
Florin Coras | 1e6d30b | 2021-11-02 10:32:19 -0700 | [diff] [blame] | 241 | "handoff-eth", VNET_HASH_FN_TYPE_ETHERNET); |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 242 | } |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 245 | vnet_feature_enable_disable ("device-input", "worker-handoff", |
| 246 | sw_if_index, enable_disable, 0, 0); |
Damjan Marion | 38c6191 | 2023-10-17 16:06:26 +0000 | [diff] [blame] | 247 | vnet_feature_enable_disable ("port-rx-eth", "worker-handoff", sw_if_index, |
| 248 | enable_disable, 0, 0); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 249 | return rv; |
| 250 | } |
| 251 | |
| 252 | static clib_error_t * |
| 253 | set_interface_handoff_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 254 | unformat_input_t * input, |
| 255 | vlib_cli_command_t * cmd) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 256 | { |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 257 | u32 sw_if_index = ~0, is_sym = 0, is_l4 = 0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 258 | int enable_disable = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 259 | uword *bitmap = 0; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 260 | int rv = 0; |
| 261 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 262 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 263 | { |
| 264 | if (unformat (input, "disable")) |
| 265 | enable_disable = 0; |
| 266 | else if (unformat (input, "workers %U", unformat_bitmap_list, &bitmap)) |
| 267 | ; |
| 268 | else if (unformat (input, "%U", unformat_vnet_sw_interface, |
| 269 | vnet_get_main (), &sw_if_index)) |
| 270 | ; |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 271 | else if (unformat (input, "symmetrical")) |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 272 | is_sym = 1; |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 273 | else if (unformat (input, "asymmetrical")) |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 274 | is_sym = 0; |
| 275 | else if (unformat (input, "l4")) |
| 276 | is_l4 = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 277 | else |
| 278 | break; |
| 279 | } |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 280 | |
| 281 | if (sw_if_index == ~0) |
| 282 | return clib_error_return (0, "Please specify an interface..."); |
| 283 | |
| 284 | if (bitmap == 0) |
| 285 | return clib_error_return (0, "Please specify list of workers..."); |
| 286 | |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 287 | rv = interface_handoff_enable_disable (vm, sw_if_index, bitmap, is_sym, |
| 288 | is_l4, enable_disable); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 289 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 290 | switch (rv) |
| 291 | { |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 292 | case 0: |
| 293 | break; |
| 294 | |
| 295 | case VNET_API_ERROR_INVALID_SW_IF_INDEX: |
| 296 | return clib_error_return (0, "Invalid interface"); |
| 297 | break; |
| 298 | |
| 299 | case VNET_API_ERROR_INVALID_WORKER: |
| 300 | return clib_error_return (0, "Invalid worker(s)"); |
| 301 | break; |
| 302 | |
| 303 | case VNET_API_ERROR_UNIMPLEMENTED: |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 304 | return clib_error_return (0, |
| 305 | "Device driver doesn't support redirection"); |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 306 | break; |
| 307 | |
| 308 | default: |
| 309 | return clib_error_return (0, "unknown return value %d", rv); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 310 | } |
Gabriel Ganne | c0a36c0 | 2016-11-16 16:57:00 +0100 | [diff] [blame] | 311 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 315 | /* *INDENT-OFF* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 316 | VLIB_CLI_COMMAND (set_interface_handoff_command, static) = { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 317 | .path = "set interface handoff", |
Florin Coras | 943a4b0 | 2021-10-27 15:17:47 -0700 | [diff] [blame] | 318 | .short_help = "set interface handoff <interface-name> workers <workers-list>" |
| 319 | " [symmetrical|asymmetrical]", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 320 | .function = set_interface_handoff_command_fn, |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 321 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 322 | /* *INDENT-ON* */ |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 323 | |
Damjan Marion | e33b9e0 | 2016-10-17 12:51:18 +0200 | [diff] [blame] | 324 | clib_error_t * |
| 325 | handoff_init (vlib_main_t * vm) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 326 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 327 | handoff_main_t *hm = &handoff_main; |
| 328 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 329 | clib_error_t *error; |
| 330 | uword *p; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 331 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 332 | if ((error = vlib_call_init_function (vm, threads_init))) |
| 333 | return error; |
| 334 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 335 | vlib_thread_registration_t *tr; |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 336 | /* Only the standard vnet worker threads are supported */ |
| 337 | p = hash_get_mem (tm->thread_registrations_by_name, "workers"); |
Dave Barach | 5a9c9b8 | 2016-06-13 18:16:27 -0400 | [diff] [blame] | 338 | if (p) |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 339 | { |
Dave Barach | 5a9c9b8 | 2016-06-13 18:16:27 -0400 | [diff] [blame] | 340 | tr = (vlib_thread_registration_t *) p[0]; |
| 341 | if (tr) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 342 | { |
| 343 | hm->num_workers = tr->count; |
| 344 | hm->first_worker_index = tr->first_index; |
| 345 | } |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 348 | hm->frame_queue_index = ~0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 349 | |
Damjan Marion | 0247b46 | 2016-06-08 01:37:11 +0200 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | VLIB_INIT_FUNCTION (handoff_init); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 354 | |
Filip Tehlar | c3a0e8d | 2019-03-11 05:53:35 -0700 | [diff] [blame] | 355 | #endif /* CLIB_MARCH_VARIANT */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 356 | /* |
| 357 | * fd.io coding-style-patch-verification: ON |
| 358 | * |
| 359 | * Local Variables: |
| 360 | * eval: (c-set-style "gnu") |
| 361 | * End: |
| 362 | */ |