FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 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 
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 
21 #include <rdma/rdma.h>
22 
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25 
26 /* define message IDs */
27 #include <rdma/rdma.api_enum.h>
28 #include <rdma/rdma.api_types.h>
29 
31 
32 static rdma_mode_t
33 rdma_api_mode (vl_api_rdma_mode_t mode)
34 {
35  switch (mode)
36  {
37  case RDMA_API_MODE_AUTO:
38  return RDMA_MODE_AUTO;
39  case RDMA_API_MODE_IBV:
40  return RDMA_MODE_IBV;
41  case RDMA_API_MODE_DV:
42  return RDMA_MODE_DV;
43  }
44  return RDMA_MODE_AUTO;
45 }
46 
47 static void
49 {
51  rdma_main_t *rm = &rdma_main;
54  int rv;
55 
56  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
57 
58  args.ifname = mp->host_if;
59  args.name = mp->name;
60  args.rxq_num = ntohs (mp->rxq_num);
61  args.rxq_size = ntohs (mp->rxq_size);
62  args.txq_size = ntohs (mp->txq_size);
63  args.mode = rdma_api_mode (mp->mode);
64 
65  rdma_create_if (vm, &args);
66  rv = args.rv;
67 
68  /* *INDENT-OFF* */
69  REPLY_MACRO2 (VL_API_RDMA_CREATE_REPLY + rm->msg_id_base,
70  ({
71  rmp->sw_if_index = ntohl (args.sw_if_index);
72  }));
73  /* *INDENT-ON* */
74 }
75 
76 static void
78 {
80  vnet_main_t *vnm = vnet_get_main ();
81  rdma_main_t *rm = &rdma_main;
82  vl_api_rdma_delete_reply_t *rmp;
83  rdma_device_t *rd;
85  int rv = 0;
86 
87  hw =
89  htonl (mp->sw_if_index));
90  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
91  {
92  rv = VNET_API_ERROR_INVALID_INTERFACE;
93  goto reply;
94  }
95 
96  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
97 
98  rdma_delete_if (vm, rd);
99 
100 reply:
101  REPLY_MACRO (VL_API_RDMA_DELETE_REPLY + rm->msg_id_base);
102 }
103 
104 /* set tup the API message handling tables */
105 #include <rdma/rdma.api.c>
106 static clib_error_t *
108 {
109  rdma_main_t *rm = &rdma_main;
110 
111  /* ask for a correctly-sized block of API message decode slots */
113  return 0;
114 }
115 
117 
118 /*
119  * fd.io coding-style-patch-verification: ON
120  *
121  * Local Variables:
122  * eval: (c-set-style "gnu")
123  * End:
124  */
u16 txq_size[default=1024]
Definition: rdma.api:49
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
rdma_mode_t
Definition: rdma.h:208
#define REPLY_MACRO2(t, body)
static rdma_mode_t rdma_api_mode(vl_api_rdma_mode_t mode)
Definition: api.c:33
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u16 rxq_size[default=1024]
Definition: rdma.api:48
rdma_main_t rdma_main
Definition: device.c:46
vlib_main_t * vm
Definition: in2out_ed.c:1582
string host_if[64]
Definition: rdma.api:45
rdma_device_t * devices
Definition: rdma.h:201
u16 rxq_num[default=1]
Definition: rdma.api:47
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
vl_api_interface_index_t sw_if_index
Definition: rdma.api:78
#define REPLY_MACRO(t)
string name[64]
Definition: rdma.api:46
vl_api_tunnel_mode_t mode
Definition: gre.api:48
static void vl_api_rdma_create_t_handler(vl_api_rdma_create_t *mp)
Definition: api.c:48
rdma_mode_t mode
Definition: rdma.h:222
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
vl_api_rdma_mode_t mode[default=0]
Definition: rdma.api:50
static void setup_message_id_table(api_main_t *am)
Definition: api.c:803
u16 msg_id_base
Definition: rdma.h:203
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vnet_device_class_t rdma_device_class
static void vl_api_rdma_delete_t_handler(vl_api_rdma_delete_t *mp)
Definition: api.c:77
VLIB_API_INIT_FUNCTION(af_xdp_plugin_api_hookup)
static clib_error_t * rdma_plugin_api_hookup(vlib_main_t *vm)
Definition: api.c:107
void rdma_delete_if(vlib_main_t *vm, rdma_device_t *rd)
Definition: device.c:884
void rdma_create_if(vlib_main_t *vm, rdma_create_if_args_t *args)
Definition: device.c:726