1812afe71SBenoît Ganne/*
2812afe71SBenoît Ganne *------------------------------------------------------------------
3812afe71SBenoît Ganne * Copyright (c) 2019 Cisco and/or its affiliates.
4812afe71SBenoît Ganne * Licensed under the Apache License, Version 2.0 (the "License");
5812afe71SBenoît Ganne * you may not use this file except in compliance with the License.
6812afe71SBenoît Ganne * You may obtain a copy of the License at:
7812afe71SBenoît Ganne *
8812afe71SBenoît Ganne *     http://www.apache.org/licenses/LICENSE-2.0
9812afe71SBenoît Ganne *
10812afe71SBenoît Ganne * Unless required by applicable law or agreed to in writing, software
11812afe71SBenoît Ganne * distributed under the License is distributed on an "AS IS" BASIS,
12812afe71SBenoît Ganne * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13812afe71SBenoît Ganne * See the License for the specific language governing permissions and
14812afe71SBenoît Ganne * limitations under the License.
15812afe71SBenoît Ganne *------------------------------------------------------------------
16812afe71SBenoît Ganne */
17812afe71SBenoît Ganne
18812afe71SBenoît Ganne#include <vlib/vlib.h>
19812afe71SBenoît Ganne#include <vnet/vnet.h>
20812afe71SBenoît Ganne
21812afe71SBenoît Ganne#include <rdma/rdma.h>
22812afe71SBenoît Ganne
23812afe71SBenoît Ganne#include <vlibapi/api.h>
24812afe71SBenoît Ganne#include <vlibmemory/api.h>
25812afe71SBenoît Ganne
26812afe71SBenoît Ganne/* define message IDs */
27812afe71SBenoît Ganne#include <rdma/rdma.api_enum.h>
28812afe71SBenoît Ganne#include <rdma/rdma.api_types.h>
29812afe71SBenoît Ganne
30812afe71SBenoît Ganne#include <vlibapi/api_helper_macros.h>
31812afe71SBenoît Ganne
32d8c1ef92SBenoît Gannestatic rdma_mode_t
33d8c1ef92SBenoît Gannerdma_api_mode (vl_api_rdma_mode_t mode)
34d8c1ef92SBenoît Ganne{
35d8c1ef92SBenoît Ganne  switch (mode)
36d8c1ef92SBenoît Ganne    {
37d8c1ef92SBenoît Ganne    case RDMA_API_MODE_AUTO:
38d8c1ef92SBenoît Ganne      return RDMA_MODE_AUTO;
39d8c1ef92SBenoît Ganne    case RDMA_API_MODE_IBV:
40d8c1ef92SBenoît Ganne      return RDMA_MODE_IBV;
41d8c1ef92SBenoît Ganne    case RDMA_API_MODE_DV:
42d8c1ef92SBenoît Ganne      return RDMA_MODE_DV;
43d8c1ef92SBenoît Ganne    }
44d8c1ef92SBenoît Ganne  return RDMA_MODE_AUTO;
45d8c1ef92SBenoît Ganne}
46d8c1ef92SBenoît Ganne
47812afe71SBenoît Gannestatic void
48812afe71SBenoît Gannevl_api_rdma_create_t_handler (vl_api_rdma_create_t * mp)
49812afe71SBenoît Ganne{
50812afe71SBenoît Ganne  vlib_main_t *vm = vlib_get_main ();
51812afe71SBenoît Ganne  rdma_main_t *rm = &rdma_main;
52812afe71SBenoît Ganne  vl_api_rdma_create_reply_t *rmp;
53812afe71SBenoît Ganne  rdma_create_if_args_t args;
54812afe71SBenoît Ganne  int rv;
55812afe71SBenoît Ganne
56812afe71SBenoît Ganne  clib_memset (&args, 0, sizeof (rdma_create_if_args_t));
57812afe71SBenoît Ganne
58812afe71SBenoît Ganne  args.ifname = mp->host_if;
59812afe71SBenoît Ganne  args.name = mp->name;
60812afe71SBenoît Ganne  args.rxq_num = ntohs (mp->rxq_num);
61812afe71SBenoît Ganne  args.rxq_size = ntohs (mp->rxq_size);
62812afe71SBenoît Ganne  args.txq_size = ntohs (mp->txq_size);
63d8c1ef92SBenoît Ganne  args.mode = rdma_api_mode (mp->mode);
64812afe71SBenoît Ganne
65812afe71SBenoît Ganne  rdma_create_if (vm, &args);
66812afe71SBenoît Ganne  rv = args.rv;
67812afe71SBenoît Ganne
68812afe71SBenoît Ganne  /* *INDENT-OFF* */
69812afe71SBenoît Ganne  REPLY_MACRO2 (VL_API_RDMA_CREATE_REPLY + rm->msg_id_base,
70812afe71SBenoît Ganne    ({
71812afe71SBenoît Ganne      rmp->sw_if_index = ntohl (args.sw_if_index);
72812afe71SBenoît Ganne    }));
73812afe71SBenoît Ganne  /* *INDENT-ON* */
74812afe71SBenoît Ganne}
75812afe71SBenoît Ganne
76812afe71SBenoît Gannestatic void
77812afe71SBenoît Gannevl_api_rdma_delete_t_handler (vl_api_rdma_delete_t * mp)
78812afe71SBenoît Ganne{
79812afe71SBenoît Ganne  vlib_main_t *vm = vlib_get_main ();
80812afe71SBenoît Ganne  vnet_main_t *vnm = vnet_get_main ();
81812afe71SBenoît Ganne  rdma_main_t *rm = &rdma_main;
82812afe71SBenoît Ganne  vl_api_rdma_delete_reply_t *rmp;
83812afe71SBenoît Ganne  rdma_device_t *rd;
84812afe71SBenoît Ganne  vnet_hw_interface_t *hw;
85812afe71SBenoît Ganne  int rv = 0;
86812afe71SBenoît Ganne
87812afe71SBenoît Ganne  hw =
88812afe71SBenoît Ganne    vnet_get_sup_hw_interface_api_visible_or_null (vnm,
89812afe71SBenoît Ganne						   htonl (mp->sw_if_index));
90812afe71SBenoît Ganne  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
91812afe71SBenoît Ganne    {
92812afe71SBenoît Ganne      rv = VNET_API_ERROR_INVALID_INTERFACE;
93812afe71SBenoît Ganne      goto reply;
94812afe71SBenoît Ganne    }
95812afe71SBenoît Ganne
96812afe71SBenoît Ganne  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
97812afe71SBenoît Ganne
98812afe71SBenoît Ganne  rdma_delete_if (vm, rd);
99812afe71SBenoît Ganne
100812afe71SBenoît Gannereply:
101812afe71SBenoît Ganne  REPLY_MACRO (VL_API_RDMA_DELETE_REPLY + rm->msg_id_base);
102812afe71SBenoît Ganne}
103812afe71SBenoît Ganne
104812afe71SBenoît Ganne/* set tup the API message handling tables */
105812afe71SBenoît Ganne#include <rdma/rdma.api.c>
106812afe71SBenoît Gannestatic clib_error_t *
107812afe71SBenoît Gannerdma_plugin_api_hookup (vlib_main_t * vm)
108812afe71SBenoît Ganne{
109812afe71SBenoît Ganne  rdma_main_t *rm = &rdma_main;
110812afe71SBenoît Ganne
111812afe71SBenoît Ganne  /* ask for a correctly-sized block of API message decode slots */
112812afe71SBenoît Ganne  rm->msg_id_base = setup_message_id_table ();
113812afe71SBenoît Ganne  return 0;
114812afe71SBenoît Ganne}
115812afe71SBenoît Ganne
116812afe71SBenoît GanneVLIB_API_INIT_FUNCTION (rdma_plugin_api_hookup);
117812afe71SBenoît Ganne
118812afe71SBenoît Ganne/*
119812afe71SBenoît Ganne * fd.io coding-style-patch-verification: ON
120812afe71SBenoît Ganne *
121812afe71SBenoît Ganne * Local Variables:
122812afe71SBenoît Ganne * eval: (c-set-style "gnu")
123812afe71SBenoît Ganne * End:
124812afe71SBenoît Ganne */
125