1fe750c24SBenoît Ganne/*
2fe750c24SBenoît Ganne *------------------------------------------------------------------
3fe750c24SBenoît Ganne * Copyright (c) 2018 Cisco and/or its affiliates.
4fe750c24SBenoît Ganne * Licensed under the Apache License, Version 2.0 (the "License");
5fe750c24SBenoît Ganne * you may not use this file except in compliance with the License.
6fe750c24SBenoît Ganne * You may obtain a copy of the License at:
7fe750c24SBenoît Ganne *
8fe750c24SBenoît Ganne *     http://www.apache.org/licenses/LICENSE-2.0
9fe750c24SBenoît Ganne *
10fe750c24SBenoît Ganne * Unless required by applicable law or agreed to in writing, software
11fe750c24SBenoît Ganne * distributed under the License is distributed on an "AS IS" BASIS,
12fe750c24SBenoît Ganne * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fe750c24SBenoît Ganne * See the License for the specific language governing permissions and
14fe750c24SBenoît Ganne * limitations under the License.
15fe750c24SBenoît Ganne *------------------------------------------------------------------
16fe750c24SBenoît Ganne */
17fe750c24SBenoît Ganne#include <stdint.h>
18fe750c24SBenoît Ganne#include <net/if.h>
19fe750c24SBenoît Ganne#include <sys/ioctl.h>
20fe750c24SBenoît Ganne#include <inttypes.h>
21fe750c24SBenoît Ganne
22fe750c24SBenoît Ganne#include <vlib/vlib.h>
23fe750c24SBenoît Ganne#include <vlib/unix/unix.h>
24fe750c24SBenoît Ganne#include <vlib/pci/pci.h>
25fe750c24SBenoît Ganne#include <vnet/ethernet/ethernet.h>
26fe750c24SBenoît Ganne
27fe750c24SBenoît Ganne#include <rdma/rdma.h>
28fe750c24SBenoît Ganne
29fe750c24SBenoît Gannestatic clib_error_t *
30fe750c24SBenoît Gannerdma_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31fe750c24SBenoît Ganne			vlib_cli_command_t * cmd)
32fe750c24SBenoît Ganne{
33fe750c24SBenoît Ganne  rdma_create_if_args_t args;
34fe750c24SBenoît Ganne
35812afe71SBenoît Ganne  if (!unformat_user (input, unformat_rdma_create_if_args, &args))
36812afe71SBenoît Ganne    return clib_error_return (0, "unknown input `%U'",
37812afe71SBenoît Ganne			      format_unformat_error, input);
38fe750c24SBenoît Ganne
39fe750c24SBenoît Ganne  rdma_create_if (vm, &args);
40fe750c24SBenoît Ganne
41fe750c24SBenoît Ganne  vec_free (args.ifname);
4296d4e533SDamjan Marion  vec_free (args.name);
43fe750c24SBenoît Ganne
44fe750c24SBenoît Ganne  return args.error;
45fe750c24SBenoît Ganne}
46fe750c24SBenoît Ganne
47fe750c24SBenoît Ganne/* *INDENT-OFF* */
48fe750c24SBenoît GanneVLIB_CLI_COMMAND (rdma_create_command, static) = {
49fe750c24SBenoît Ganne  .path = "create interface rdma",
505763e47bSBenoît Ganne  .short_help = "create interface rdma <host-if ifname> [name <name>]"
515763e47bSBenoît Ganne    " [rx-queue-size <size>] [tx-queue-size <size>]"
52d8c1ef92SBenoît Ganne    " [num-rx-queues <size>] [mode <auto|ibv|dv]",
53fe750c24SBenoît Ganne  .function = rdma_create_command_fn,
54fe750c24SBenoît Ganne};
55fe750c24SBenoît Ganne/* *INDENT-ON* */
56fe750c24SBenoît Ganne
57fe750c24SBenoît Gannestatic clib_error_t *
58fe750c24SBenoît Gannerdma_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
59fe750c24SBenoît Ganne			vlib_cli_command_t * cmd)
60fe750c24SBenoît Ganne{
61fe750c24SBenoît Ganne  unformat_input_t _line_input, *line_input = &_line_input;
62fe750c24SBenoît Ganne  u32 sw_if_index = ~0;
63fe750c24SBenoît Ganne  vnet_hw_interface_t *hw;
64fe750c24SBenoît Ganne  rdma_main_t *rm = &rdma_main;
65fe750c24SBenoît Ganne  rdma_device_t *rd;
66fe750c24SBenoît Ganne  vnet_main_t *vnm = vnet_get_main ();
67fe750c24SBenoît Ganne
68fe750c24SBenoît Ganne  /* Get a line of input. */
69fe750c24SBenoît Ganne  if (!unformat_user (input, unformat_line_input, line_input))
70fe750c24SBenoît Ganne    return 0;
71fe750c24SBenoît Ganne
72fe750c24SBenoît Ganne  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
73fe750c24SBenoît Ganne    {
74fe750c24SBenoît Ganne      if (unformat (line_input, "sw_if_index %d", &sw_if_index))
75fe750c24SBenoît Ganne	;
76fe750c24SBenoît Ganne      else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
77fe750c24SBenoît Ganne			 vnm, &sw_if_index))
78fe750c24SBenoît Ganne	;
79fe750c24SBenoît Ganne      else
80fe750c24SBenoît Ganne	return clib_error_return (0, "unknown input `%U'",
81fe750c24SBenoît Ganne				  format_unformat_error, input);
82fe750c24SBenoît Ganne    }
83fe750c24SBenoît Ganne  unformat_free (line_input);
84fe750c24SBenoît Ganne
85fe750c24SBenoît Ganne  if (sw_if_index == ~0)
86fe750c24SBenoît Ganne    return clib_error_return (0,
87fe750c24SBenoît Ganne			      "please specify interface name or sw_if_index");
88fe750c24SBenoît Ganne
893940de36SDave Barach  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
90fe750c24SBenoît Ganne  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
915763e47bSBenoît Ganne    return clib_error_return (0, "not a RDMA interface");
92fe750c24SBenoît Ganne
93fe750c24SBenoît Ganne  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
94fe750c24SBenoît Ganne
95fe750c24SBenoît Ganne  rdma_delete_if (vm, rd);
96fe750c24SBenoît Ganne
97fe750c24SBenoît Ganne  return 0;
98fe750c24SBenoît Ganne}
99fe750c24SBenoît Ganne
100fe750c24SBenoît Ganne/* *INDENT-OFF* */
101fe750c24SBenoît GanneVLIB_CLI_COMMAND (rdma_delete_command, static) = {
102fe750c24SBenoît Ganne  .path = "delete interface rdma",
103fe750c24SBenoît Ganne  .short_help = "delete interface rdma "
104fe750c24SBenoît Ganne    "{<interface> | sw_if_index <sw_idx>}",
105fe750c24SBenoît Ganne  .function = rdma_delete_command_fn,
106fe750c24SBenoît Ganne};
107fe750c24SBenoît Ganne/* *INDENT-ON* */
108fe750c24SBenoît Ganne
109dd648aacSDamjan Marionstatic clib_error_t *
110dd648aacSDamjan Mariontest_rdma_dump_command_fn (vlib_main_t * vm, unformat_input_t * input,
111dd648aacSDamjan Marion			   vlib_cli_command_t * cmd)
112dd648aacSDamjan Marion{
113dd648aacSDamjan Marion  unformat_input_t _line_input, *line_input = &_line_input;
114dd648aacSDamjan Marion  u32 sw_if_index = ~0;
115dd648aacSDamjan Marion  vnet_hw_interface_t *hw;
116dd648aacSDamjan Marion  rdma_main_t *rm = &rdma_main;
117dd648aacSDamjan Marion  rdma_device_t *rd;
118dd648aacSDamjan Marion  vnet_main_t *vnm = vnet_get_main ();
119dd648aacSDamjan Marion  int i;
120dd648aacSDamjan Marion
121dd648aacSDamjan Marion  /* Get a line of input. */
122dd648aacSDamjan Marion  if (!unformat_user (input, unformat_line_input, line_input))
123dd648aacSDamjan Marion    return 0;
124dd648aacSDamjan Marion
125dd648aacSDamjan Marion  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
126dd648aacSDamjan Marion    {
127dd648aacSDamjan Marion      if (unformat (line_input, "sw_if_index %d", &sw_if_index))
128dd648aacSDamjan Marion	;
129dd648aacSDamjan Marion      else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
130dd648aacSDamjan Marion			 vnm, &sw_if_index))
131dd648aacSDamjan Marion	;
132dd648aacSDamjan Marion      else
133dd648aacSDamjan Marion	return clib_error_return (0, "unknown input `%U'",
134dd648aacSDamjan Marion				  format_unformat_error, input);
135dd648aacSDamjan Marion    }
136dd648aacSDamjan Marion  unformat_free (line_input);
137dd648aacSDamjan Marion
138dd648aacSDamjan Marion  if (sw_if_index == ~0)
139dd648aacSDamjan Marion    return clib_error_return (0,
140dd648aacSDamjan Marion			      "please specify interface name or sw_if_index");
141dd648aacSDamjan Marion
142dd648aacSDamjan Marion  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
143dd648aacSDamjan Marion  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
144dd648aacSDamjan Marion    return clib_error_return (0, "not a RDMA interface");
145dd648aacSDamjan Marion
146dd648aacSDamjan Marion  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
147dd648aacSDamjan Marion
148dd648aacSDamjan Marion  if ((rd->flags & RDMA_DEVICE_F_MLX5DV) == 0)
149dd648aacSDamjan Marion    return clib_error_return (0, "not a mlx5 interface");
150dd648aacSDamjan Marion
151dd648aacSDamjan Marion  vlib_cli_output (vm, "netdev %s pci-addr %U lkey 0x%x",
152dd648aacSDamjan Marion		   rd->linux_ifname, format_vlib_pci_addr, &rd->pci->addr,
153dd648aacSDamjan Marion		   &rd->lkey);
154dd648aacSDamjan Marion
155dd648aacSDamjan Marion  vec_foreach_index (i, rd->rxqs)
156dd648aacSDamjan Marion  {
157dd648aacSDamjan Marion    vlib_cli_output (vm, "RX queue %u\n  %U\n", i, format_rdma_rxq, rd, i);
158dd648aacSDamjan Marion  }
159dd648aacSDamjan Marion
160dd648aacSDamjan Marion  return 0;
161dd648aacSDamjan Marion}
162dd648aacSDamjan Marion
163dd648aacSDamjan Marion/* *INDENT-OFF* */
164dd648aacSDamjan MarionVLIB_CLI_COMMAND (test_rdma_mlx5dv_dump_command, static) = {
165dd648aacSDamjan Marion  .path = "test rdma dump",
166dd648aacSDamjan Marion  .short_help = "test rdma dump {<interface> | sw_if_index <sw_idx>}",
167dd648aacSDamjan Marion  .function = test_rdma_dump_command_fn,
168dd648aacSDamjan Marion};
169dd648aacSDamjan Marion/* *INDENT-ON* */
170dd648aacSDamjan Marion
171fe750c24SBenoît Ganneclib_error_t *
172fe750c24SBenoît Gannerdma_cli_init (vlib_main_t * vm)
173fe750c24SBenoît Ganne{
174fe750c24SBenoît Ganne  return 0;
175fe750c24SBenoît Ganne}
176fe750c24SBenoît Ganne
177fe750c24SBenoît GanneVLIB_INIT_FUNCTION (rdma_cli_init);
178fe750c24SBenoît Ganne
179fe750c24SBenoît Ganne/*
180fe750c24SBenoît Ganne * fd.io coding-style-patch-verification: ON
181fe750c24SBenoît Ganne *
182fe750c24SBenoît Ganne * Local Variables:
183fe750c24SBenoît Ganne * eval: (c-set-style "gnu")
184fe750c24SBenoît Ganne * End:
185fe750c24SBenoît Ganne */