blob: a0318a11dcdde086341f7c1cb30d4451d96cb026 [file] [log] [blame]
Ray Kinsella4830e4f2020-03-10 14:35:32 +00001/*
2 * Copyright (c) 2020 Intel 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 * node_init.c: node march variant startup initialization
17 *
18 * Copyright (c) 2020 Intel Corporation
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#include <sys/types.h>
41#include <fcntl.h>
42#include <vlib/vlib.h>
43
Ray Kinsella4830e4f2020-03-10 14:35:32 +000044static clib_error_t *
Damjan Mariona31698b2021-03-10 14:35:28 +010045vlib_node_config (vlib_main_t *vm, unformat_input_t *input)
Ray Kinsella4830e4f2020-03-10 14:35:32 +000046{
47 clib_error_t *error = 0;
Ray Kinsella4830e4f2020-03-10 14:35:32 +000048 unformat_input_t sub_input;
Damjan Mariona31698b2021-03-10 14:35:28 +010049 u32 *march_variant_by_node = 0;
50 clib_march_variant_type_t march_variant;
51 u32 node_index;
52 int i;
Ray Kinsella4830e4f2020-03-10 14:35:32 +000053
54 /* specify prioritization defaults for all graph nodes */
55 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
56 {
57 if (unformat (input, "default %U", unformat_vlib_cli_sub_input,
58 &sub_input))
59 {
60 while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
61 {
62 if (!unformat (&sub_input, "variant %U",
Damjan Mariona31698b2021-03-10 14:35:28 +010063 unformat_vlib_node_variant, &march_variant))
Ray Kinsella4830e4f2020-03-10 14:35:32 +000064 return clib_error_return (0,
65 "please specify a valid node variant");
Ray Kinsella4830e4f2020-03-10 14:35:32 +000066
Damjan Mariona31698b2021-03-10 14:35:28 +010067 vec_validate_init_empty (march_variant_by_node,
68 vec_len (vm->node_main.nodes) - 1, ~0);
69 vec_foreach_index (i, march_variant_by_node)
70 march_variant_by_node[i] = march_variant;
71 vm->node_main.node_fn_default_march_variant = march_variant;
72 unformat_free (&sub_input);
Ray Kinsella4830e4f2020-03-10 14:35:32 +000073 }
74 }
75 else /* specify prioritization for an individual graph node */
Damjan Mariona31698b2021-03-10 14:35:28 +010076 if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
Ray Kinsella4830e4f2020-03-10 14:35:32 +000077 {
Ray Kinsella4830e4f2020-03-10 14:35:32 +000078 if (unformat (input, "%U", unformat_vlib_cli_sub_input, &sub_input))
79 {
80 while (unformat_check_input (&sub_input) !=
81 UNFORMAT_END_OF_INPUT)
82 {
83 if (!unformat (&sub_input, "variant %U",
Damjan Mariona31698b2021-03-10 14:35:28 +010084 unformat_vlib_node_variant, &march_variant))
Ray Kinsella4830e4f2020-03-10 14:35:32 +000085 return clib_error_return (0,
86 "please specify a valid node variant");
Damjan Mariona31698b2021-03-10 14:35:28 +010087 vec_validate_init_empty (march_variant_by_node, node_index,
88 ~0);
89 march_variant_by_node[node_index] = march_variant;
90 unformat_free (&sub_input);
Ray Kinsella4830e4f2020-03-10 14:35:32 +000091 }
92 }
93 }
94 else
95 {
96 break;
97 }
98 }
99
Damjan Mariona31698b2021-03-10 14:35:28 +0100100 if (march_variant_by_node)
101 {
102 vec_foreach_index (i, march_variant_by_node)
103 if (march_variant_by_node[i] != ~0)
104 vlib_node_set_march_variant (vm, i, march_variant_by_node[i]);
105 vec_free (march_variant_by_node);
106 }
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000107 unformat_free (input);
108
109 return error;
110}
111
Damjan Mariona31698b2021-03-10 14:35:28 +0100112VLIB_CONFIG_FUNCTION (vlib_node_config, "node");
Ray Kinsella4830e4f2020-03-10 14:35:32 +0000113
114/*
115 * fd.io coding-style-patch-verification: ON
116 *
117 * Local Variables:
118 * eval: (c-set-style "gnu")
119 * End:
120 */