idpf: add native idpf driver plugin
[vpp.git] / src / plugins / idpf / cli.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2023 Intel 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 <idpf/idpf.h>
18
19 static clib_error_t *
20 idpf_create_command_fn (vlib_main_t *vm, unformat_input_t *input,
21                         vlib_cli_command_t *cmd)
22 {
23   unformat_input_t _line_input, *line_input = &_line_input;
24   idpf_create_if_args_t args;
25   u32 tmp;
26
27   clib_memset (&args, 0, sizeof (idpf_create_if_args_t));
28
29   /* Get a line of input. */
30   if (!unformat_user (input, unformat_line_input, line_input))
31     return 0;
32
33   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
34     {
35       if (unformat (line_input, "%U", unformat_vlib_pci_addr, &args.addr))
36         ;
37       else if (unformat (line_input, "rx-single %u", &tmp))
38         args.rxq_single = 1;
39       else if (unformat (line_input, "tx-single %u", &tmp))
40         args.txq_single = 1;
41       else if (unformat (line_input, "rxq-num %u", &tmp))
42         args.rxq_num = tmp;
43       else if (unformat (line_input, "txq-num %u", &tmp))
44         args.txq_num = tmp;
45       else if (unformat (line_input, "rxq-size %u", &tmp))
46         args.rxq_size = tmp;
47       else if (unformat (line_input, "txq-size %u", &tmp))
48         args.txq_size = tmp;
49       else if (unformat (line_input, "vport-num %u", &tmp))
50         args.req_vport_nb = tmp;
51       else if (unformat (line_input, "name %s", &args.name))
52         ;
53       else
54         return clib_error_return (0, "unknown input `%U'",
55                                   format_unformat_error, input);
56     }
57   unformat_free (line_input);
58
59   idpf_create_if (vm, &args);
60
61   vec_free (args.name);
62
63   return args.error;
64 }
65
66 VLIB_CLI_COMMAND (idpf_create_command, static) = {
67   .path = "create interface idpf",
68   .short_help = "create interface idpf <pci-address> "
69                 "[vport <size>] [rx-single <size>] [tx-single <size>]",
70   .function = idpf_create_command_fn,
71 };
72
73 static clib_error_t *
74 idpf_delete_command_fn (vlib_main_t *vm, unformat_input_t *input,
75                         vlib_cli_command_t *cmd)
76 {
77   unformat_input_t _line_input, *line_input = &_line_input;
78   u32 sw_if_index = ~0;
79   vnet_hw_interface_t *hw;
80   vnet_main_t *vnm = vnet_get_main ();
81
82   /* Get a line of input. */
83   if (!unformat_user (input, unformat_line_input, line_input))
84     return 0;
85
86   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
87     {
88       if (unformat (line_input, "sw_if_index %d", &sw_if_index))
89         ;
90       else if (unformat (line_input, "%U", unformat_vnet_sw_interface, vnm,
91                          &sw_if_index))
92         ;
93       else
94         return clib_error_return (0, "unknown input `%U'",
95                                   format_unformat_error, input);
96     }
97   unformat_free (line_input);
98
99   if (sw_if_index == ~0)
100     return clib_error_return (0,
101                               "please specify interface name or sw_if_index");
102
103   hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
104   if (hw == NULL || idpf_device_class.index != hw->dev_class_index)
105     return clib_error_return (0, "not an IDPF interface");
106
107   vlib_process_signal_event (vm, idpf_process_node.index,
108                              IDPF_PROCESS_EVENT_DELETE_IF, hw->dev_instance);
109
110   return 0;
111 }
112
113 VLIB_CLI_COMMAND (idpf_delete_command, static) = {
114   .path = "delete interface idpf",
115   .short_help = "delete interface idpf "
116                 "{<interface> | sw_if_index <sw_idx>}",
117   .function = idpf_delete_command_fn,
118   .is_mp_safe = 1,
119 };
120
121 clib_error_t *
122 idpf_cli_init (vlib_main_t *vm)
123 {
124   return 0;
125 }
126
127 VLIB_INIT_FUNCTION (idpf_cli_init);
128
129 /*
130  * fd.io coding-style-patch-verification: ON
131  *
132  * Local Variables:
133  * eval: (c-set-style "gnu")
134  * End:
135  */