FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 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 <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vnet/ethernet/ethernet.h>
25 
26 #include <marvell/pp2/pp2.h>
27 
28 static clib_error_t *
30  vlib_cli_command_t * cmd)
31 {
32  unformat_input_t _line_input, *line_input = &_line_input;
33  mrvl_pp2_create_if_args_t args = { 0 };
34  uint val;
35 
36  /* Get a line of input. */
37  if (!unformat_user (input, unformat_line_input, line_input))
38  return 0;
39 
40  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
41  {
42  if (unformat (line_input, "name %s", &args.name))
43  ;
44  else if (unformat (line_input, "rx-queue-size %u", &val))
45  args.rx_q_sz = val;
46  else if (unformat (line_input, "tx-queue-size %u", &val))
47  args.tx_q_sz = val;
48  else
49  return clib_error_return (0, "unknown input `%U'",
50  format_unformat_error, input);
51  }
52  unformat_free (line_input);
53 
54 
55  mrvl_pp2_create_if (&args);
56 
57  vec_free (args.name);
58 
59  return args.error;
60 }
61 
62 /* *INDENT-OFF* */
64  .path = "create interface marvell pp2",
65  .short_help = "create interface marvell pp2 [name <ifname>] [rx-queue-size slots] [tx-queue-size slots]",
66  .function = mrvl_pp2_create_command_fn,
67 };
68 /* *INDENT-ON* */
69 
70 static clib_error_t *
72  vlib_cli_command_t * cmd)
73 {
74  unformat_input_t _line_input, *line_input = &_line_input;
75  u32 sw_if_index = ~0;
78  mrvl_pp2_if_t *dif;
79  vnet_main_t *vnm = vnet_get_main ();
80 
81  /* Get a line of input. */
82  if (!unformat_user (input, unformat_line_input, line_input))
83  return 0;
84 
85  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
86  {
87  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
88  ;
89  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
90  vnm, &sw_if_index))
91  ;
92  else
93  return clib_error_return (0, "unknown input `%U'",
94  format_unformat_error, input);
95  }
96  unformat_free (line_input);
97 
98  if (sw_if_index == ~0)
99  return clib_error_return (0,
100  "please specify interface name or sw_if_index");
101 
103  if (hw == NULL || mrvl_pp2_device_class.index != hw->dev_class_index)
104  return clib_error_return (0, "not a Marvell PP2 interface");
105 
106  dif = pool_elt_at_index (mm->interfaces, hw->dev_instance);
107 
108  mrvl_pp2_delete_if (dif);
109 
110  return 0;
111 }
112 
113 /* *INDENT-OFF* */
115  .path = "delete interface marvell pp2",
116  .short_help = "delete interface marvell pp2 "
117  "{<interface> | sw_if_index <sw_idx>}",
118  .function = mrvl_pp2_delete_command_fn,
119 };
120 /* *INDENT-ON* */
121 
122 clib_error_t *
124 {
125  /* initialize binary API */
127 
128  return 0;
129 }
130 
132 
133 /*
134  * fd.io coding-style-patch-verification: ON
135  *
136  * Local Variables:
137  * eval: (c-set-style "gnu")
138  * End:
139  */
vlib.h
mrvl_pp2_plugin_api_hookup
clib_error_t * mrvl_pp2_plugin_api_hookup(vlib_main_t *vm)
Definition: pp2_api.c:87
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
pp2.h
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
mrvl_pp2_main
mrvl_pp2_main_t mrvl_pp2_main
Definition: pp2.c:37
unformat_input_t
struct _unformat_input_t unformat_input_t
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
mrvl_pp2_create_if_args_t::error
clib_error_t * error
Definition: pp2.h:99
ethernet.h
mrvl_pp2_create_command
static vlib_cli_command_t mrvl_pp2_create_command
(constructor) VLIB_CLI_COMMAND (mrvl_pp2_create_command)
Definition: cli.c:63
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
mrvl_pp2_create_if_args_t::rx_q_sz
u16 rx_q_sz
Definition: pp2.h:93
mrvl_pp2_cli_init
clib_error_t * mrvl_pp2_cli_init(vlib_main_t *vm)
Definition: cli.c:123
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
mrvl_pp2_create_if_args_t::name
u8 * name
Definition: pp2.h:92
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
mrvl_pp2_delete_command
static vlib_cli_command_t mrvl_pp2_delete_command
(constructor) VLIB_CLI_COMMAND (mrvl_pp2_delete_command)
Definition: cli.c:114
mrvl_pp2_device_class
vnet_device_class_t mrvl_pp2_device_class
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
mrvl_pp2_create_if_args_t::tx_q_sz
u16 tx_q_sz
Definition: pp2.h:94
mrvl_pp2_main_t::interfaces
mrvl_pp2_if_t * interfaces
Definition: pp2.h:80
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vlib_main_t
Definition: main.h:102
mrvl_pp2_create_if_args_t
Definition: pp2.h:90
mrvl_pp2_delete_if
void mrvl_pp2_delete_if(mrvl_pp2_if_t *ppif)
Definition: pp2.c:116
clib_error_t
Definition: clib_error.h:21
unix.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
mrvl_pp2_if_t
Definition: pp2.h:51
mrvl_pp2_create_if
void mrvl_pp2_create_if(mrvl_pp2_create_if_args_t *args)
Definition: pp2.c:176
mrvl_pp2_create_command_fn
static clib_error_t * mrvl_pp2_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:29
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
mrvl_pp2_main_t
Definition: pp2.h:78
mrvl_pp2_delete_command_fn
static clib_error_t * mrvl_pp2_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:71
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137