FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
pp2_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 Arm Limited.
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 <vlib/unix/unix.h>
20 #include <vnet/ethernet/ethernet.h>
21 
22 #include <marvell/pp2/pp2.h>
23 
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 
27 /* define message IDs */
29 
30 /* define message structures */
31 #define vl_typedefs
33 #undef vl_typedefs
34 
35 /* define generated endian-swappers */
36 #define vl_endianfun
38 #undef vl_endianfun
39 
40 /* instantiate all the print functions we know about */
41 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
42 
43 /* get the API version number */
44 #define vl_api_version(n,v) static u32 api_version=(v);
46 #undef vl_api_version
47 
48 /* Macro to finish up custom dump fns */
49 #define FINISH \
50  vec_add1 (s, 0); \
51  vl_print (handle, (char *)s); \
52  vec_free (s); \
53  return handle;
54 
56 
57 #define foreach_pp2_plugin_api_msg \
58 _(MRVL_PP2_CREATE, mrvl_pp2_create) \
59 _(MRVL_PP2_DELETE, mrvl_pp2_delete)
60 
61 
62 #define vl_msg_name_crc_list
64 #undef vl_msg_name_crc_list
65 
66 static void
68 {
70  mrvl_pp2_create_if_args_t args = { 0 };
72  int rv;
73 
74  args.name = format (0, "%s", mp->if_name);
75  args.rx_q_sz = ntohs (mp->rx_q_sz);
76  args.tx_q_sz = ntohs (mp->tx_q_sz);
77  mrvl_pp2_create_if (&args);
78  rv = args.rv;
79  vec_free (args.name);
80  if (args.error)
81  {
82  clib_error_free (args.error);
83  }
84  /* *INDENT-OFF* */
85  REPLY_MACRO2 (VL_API_MRVL_PP2_CREATE_REPLY + pp2->msg_id_base,
86  ({
87  rmp->sw_if_index = ntohl (args.sw_if_index);
88  }));
89  /* *INDENT-ON* */
90 }
91 
92 static void *
94 {
95  u8 *s;
96  s = format (0, "SCRIPT: mrvl_pp2_create ");
97  s = format (s, "if_name:%s ", mp->if_name);
98  if (mp->rx_q_sz)
99  s = format (s, "rx-queue-size:%u ", ntohs (mp->rx_q_sz));
100  if (mp->tx_q_sz)
101  s = format (s, "tx-queue-size %u ", ntohs (mp->tx_q_sz));
102 
103  FINISH;
104 }
105 
106 static void
108 {
109  vnet_main_t *vnm = vnet_get_main ();
112  vl_api_mrvl_pp2_delete_reply_t *rmp;
113  mrvl_pp2_if_t *dif;
114  int rv = 0;
115  mp->sw_if_index = ntohl (mp->sw_if_index);
116  hw = vnet_get_sup_hw_interface (vnm, mp->sw_if_index);
117  if (hw == NULL || mrvl_pp2_device_class.index != hw->dev_class_index)
118  {
119  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
120  goto reply;
121  }
122 
123  dif = pool_elt_at_index (pp2->interfaces, hw->dev_instance);
124 
125  mrvl_pp2_delete_if (dif);
126 
127 reply:
128  REPLY_MACRO (VL_API_MRVL_PP2_DELETE_REPLY + pp2->msg_id_base);
129 }
130 
131 static void *
133 {
134  u8 *s;
135 
136  s = format (0, "SCRIPT: mrvl_pp2_delete ");
137  s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
138 
139  FINISH;
140 }
141 
142 
143 static void
145 {
146 #define _(id,n,crc) \
147  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + pp2->msg_id_base);
148  foreach_vl_msg_name_crc_pp2;
149 #undef _
150 }
151 
152 
153 /* set up the API message handling tables */
154 clib_error_t *
156 {
158  api_main_t *am = &api_main;
159  u8 *name;
160 
161  /* construct the API name */
162  name = format (0, "mrvl_pp2_%08x%c", api_version, 0);
163 
164  /* ask for a correctly-sized block of API message decode slots */
166  ((char *) name, VL_MSG_FIRST_AVAILABLE);
167 
168 #define _(N,n) \
169  vl_msg_api_set_handlers((VL_API_##N + pp2->msg_id_base), \
170  #n, \
171  vl_api_##n##_t_handler, \
172  vl_noop_handler, \
173  vl_api_##n##_t_endian, \
174  vl_api_##n##_t_print, \
175  sizeof(vl_api_##n##_t), 1);
177 #undef _
178 
179  /* set up the (msg_name, crc, message-id) table */
180  setup_message_id_table (pp2, am);
181 
182  vec_free (name);
183  return 0;
184 }
185 
186 /*
187  * fd.io coding-style-patch-verification: ON
188  *
189  * Local Variables:
190  * eval: (c-set-style "gnu")
191  * End:
192  */
#define foreach_pp2_plugin_api_msg
Definition: pp2_api.c:57
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define REPLY_MACRO2(t, body)
static void setup_message_id_table(mrvl_pp2_main_t *pp2, api_main_t *am)
Definition: pp2_api.c:144
mrvl_pp2_main_t mrvl_pp2_main
Definition: pp2.c:36
vnet_device_class_t mrvl_pp2_device_class
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
#define REPLY_MACRO(t)
static void vl_api_mrvl_pp2_create_t_handler(vl_api_mrvl_pp2_create_t *mp)
Definition: pp2_api.c:67
u16 msg_id_base
Definition: pp2.h:83
u8 name[64]
Definition: memclnt.api:152
static void * vl_api_mrvl_pp2_create_t_print(vl_api_mrvl_pp2_create_t *mp, void *handle)
Definition: pp2_api.c:93
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
#define FINISH
Definition: pp2_api.c:49
clib_error_t * mrvl_pp2_plugin_api_hookup(vlib_main_t *vm)
Definition: pp2_api.c:155
void mrvl_pp2_delete_if(mrvl_pp2_if_t *ppif)
Definition: pp2.c:115
void mrvl_pp2_create_if(mrvl_pp2_create_if_args_t *args)
Definition: pp2.c:180
#define clib_error_free(e)
Definition: error.h:86
clib_error_t * error
Definition: pp2.h:98
static void * vl_api_mrvl_pp2_delete_t_print(vl_api_mrvl_pp2_delete_t *mp, void *handle)
Definition: pp2_api.c:132
mrvl_pp2_if_t * interfaces
Definition: pp2.h:79
static void vl_api_mrvl_pp2_delete_t_handler(vl_api_mrvl_pp2_delete_t *mp)
Definition: pp2_api.c:107
api_main_t api_main
Definition: api_shared.c:35
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:957