hs-test: cache docker build in local filesystem
[vpp.git] / src / plugins / rdma / cli.c
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 <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
26
27 #include <rdma/rdma.h>
28
29 static clib_error_t *
30 rdma_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31                         vlib_cli_command_t * cmd)
32 {
33   rdma_create_if_args_t args;
34
35   if (!unformat_user (input, unformat_rdma_create_if_args, &args))
36     return clib_error_return (0, "unknown input `%U'",
37                               format_unformat_error, input);
38
39   rdma_create_if (vm, &args);
40
41   vec_free (args.ifname);
42   vec_free (args.name);
43
44   return args.error;
45 }
46
47 VLIB_CLI_COMMAND (rdma_create_command, static) = {
48   .path = "create interface rdma",
49   .short_help = "create interface rdma <host-if ifname> [name <name>]"
50                 " [rx-queue-size <size>] [tx-queue-size <size>]"
51                 " [num-rx-queues <size>] [mode <auto|ibv|dv>]"
52                 " [no-multi-seg] [no-striding]"
53                 " [max-pktlen <size>]",
54   .function = rdma_create_command_fn,
55 };
56
57 static clib_error_t *
58 rdma_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
59                         vlib_cli_command_t * cmd)
60 {
61   unformat_input_t _line_input, *line_input = &_line_input;
62   u32 sw_if_index = ~0;
63   vnet_hw_interface_t *hw;
64   rdma_main_t *rm = &rdma_main;
65   rdma_device_t *rd;
66   vnet_main_t *vnm = vnet_get_main ();
67
68   /* Get a line of input. */
69   if (!unformat_user (input, unformat_line_input, line_input))
70     return 0;
71
72   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
73     {
74       if (unformat (line_input, "sw_if_index %d", &sw_if_index))
75         ;
76       else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
77                          vnm, &sw_if_index))
78         ;
79       else
80         return clib_error_return (0, "unknown input `%U'",
81                                   format_unformat_error, input);
82     }
83   unformat_free (line_input);
84
85   if (sw_if_index == ~0)
86     return clib_error_return (0,
87                               "please specify interface name or sw_if_index");
88
89   hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
90   if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
91     return clib_error_return (0, "not a RDMA interface");
92
93   rd = pool_elt_at_index (rm->devices, hw->dev_instance);
94
95   rdma_delete_if (vm, rd);
96
97   return 0;
98 }
99
100 VLIB_CLI_COMMAND (rdma_delete_command, static) = {
101   .path = "delete interface rdma",
102   .short_help = "delete interface rdma "
103     "{<interface> | sw_if_index <sw_idx>}",
104   .function = rdma_delete_command_fn,
105 };
106
107 static clib_error_t *
108 test_rdma_dump_command_fn (vlib_main_t * vm, unformat_input_t * input,
109                            vlib_cli_command_t * cmd)
110 {
111   unformat_input_t _line_input, *line_input = &_line_input;
112   u32 sw_if_index = ~0;
113   vnet_hw_interface_t *hw;
114   rdma_main_t *rm = &rdma_main;
115   rdma_device_t *rd;
116   vnet_main_t *vnm = vnet_get_main ();
117   int i;
118
119   /* Get a line of input. */
120   if (!unformat_user (input, unformat_line_input, line_input))
121     return 0;
122
123   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
124     {
125       if (unformat (line_input, "sw_if_index %d", &sw_if_index))
126         ;
127       else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
128                          vnm, &sw_if_index))
129         ;
130       else
131         return clib_error_return (0, "unknown input `%U'",
132                                   format_unformat_error, input);
133     }
134   unformat_free (line_input);
135
136   if (sw_if_index == ~0)
137     return clib_error_return (0,
138                               "please specify interface name or sw_if_index");
139
140   hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
141   if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
142     return clib_error_return (0, "not a RDMA interface");
143
144   rd = pool_elt_at_index (rm->devices, hw->dev_instance);
145
146   if ((rd->flags & RDMA_DEVICE_F_MLX5DV) == 0)
147     return clib_error_return (0, "not a mlx5 interface");
148
149   vlib_cli_output (vm, "netdev %s pci-addr %U lkey 0x%x",
150                    rd->linux_ifname, format_vlib_pci_addr, &rd->pci->addr,
151                    &rd->lkey);
152
153   vec_foreach_index (i, rd->rxqs)
154   {
155     vlib_cli_output (vm, "RX queue %u\n  %U\n", i, format_rdma_rxq, rd, i);
156   }
157
158   return 0;
159 }
160
161 VLIB_CLI_COMMAND (test_rdma_mlx5dv_dump_command, static) = {
162   .path = "test rdma dump",
163   .short_help = "test rdma dump {<interface> | sw_if_index <sw_idx>}",
164   .function = test_rdma_dump_command_fn,
165 };
166
167 clib_error_t *
168 rdma_cli_init (vlib_main_t * vm)
169 {
170   return 0;
171 }
172
173 VLIB_INIT_FUNCTION (rdma_cli_init);
174
175 /*
176  * fd.io coding-style-patch-verification: ON
177  *
178  * Local Variables:
179  * eval: (c-set-style "gnu")
180  * End:
181  */