api: Add API support for marvell PP2 plugin
[vpp.git] / src / plugins / marvell / pp2 / pp2_test.c
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 <vat/vat.h>
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25
26 #include <vppinfra/error.h>
27 #include <marvell/pp2/pp2.h>
28
29 #define __plugin_msg_base pp2_test_main.msg_id_base
30 #include <vlibapi/vat_helper_macros.h>
31
32 /* declare message IDs */
33 #include <marvell/pp2/pp2.api_enum.h>
34 #include <marvell/pp2/pp2.api_types.h>
35
36 typedef struct
37 {
38   /* API message ID base */
39   u16 msg_id_base;
40   vat_main_t *vat_main;
41 } pp2_test_main_t;
42
43 pp2_test_main_t pp2_test_main;
44
45 /* mrvl_pp2 create API */
46 static int
47 api_mrvl_pp2_create (vat_main_t * vam)
48 {
49   unformat_input_t *i = vam->input;
50   vl_api_mrvl_pp2_create_t *mp;
51   mrvl_pp2_create_if_args_t args;
52   int ret;
53   u16 size;
54
55   clib_memset (&args, 0, sizeof (mrvl_pp2_create_if_args_t));
56   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
57     {
58       if (unformat (i, "name %s", &args.name))
59         ;
60       else if (unformat (i, "rx-queue-size %u", &size))
61         args.rx_q_sz = size;
62       else if (unformat (i, "tx-queue-size %u", &size))
63         args.tx_q_sz = size;
64       else
65         {
66           clib_warning ("unknown input '%U'", format_unformat_error, i);
67           return -99;
68         }
69     }
70
71   M (MRVL_PP2_CREATE, mp);
72
73   strncpy_s ((char *) mp->if_name, ARRAY_LEN (mp->if_name),
74              (char *) (args.name), strlen ((char *) args.name));
75   mp->rx_q_sz = clib_host_to_net_u16 (args.rx_q_sz);
76   mp->tx_q_sz = clib_host_to_net_u16 (args.tx_q_sz);
77
78   S (mp);
79   W (ret);
80
81   vec_free (args.name);
82
83   return ret;
84 }
85
86 /* mrvl_pp2 create reply handler */
87 static void
88 vl_api_mrvl_pp2_create_reply_t_handler (vl_api_mrvl_pp2_create_reply_t * mp)
89 {
90   vat_main_t *vam = pp2_test_main.vat_main;
91   i32 retval = ntohl (mp->retval);
92
93   if (retval == 0)
94     {
95       fformat (vam->ofp, "created mrvl_pp2 with sw_if_index %d\n",
96                ntohl (mp->sw_if_index));
97     }
98
99   vam->retval = retval;
100   vam->result_ready = 1;
101   vam->regenerate_interface_table = 1;
102 }
103
104
105 /* mrvl_pp2 delete API */
106 static int
107 api_mrvl_pp2_delete (vat_main_t * vam)
108 {
109   unformat_input_t *i = vam->input;
110   //vnet_main_t *vnm = vnet_get_main ();
111   vl_api_mrvl_pp2_delete_t *mp;
112   u32 sw_if_index = 0;
113   int ret;
114
115   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
116     {
117       if (unformat (i, "sw_if_index %d", &sw_if_index))
118         ;
119       else
120         {
121           clib_warning ("unknown input '%U'", format_unformat_error, i);
122           return -99;
123         }
124     }
125
126   M (MRVL_PP2_DELETE, mp);
127
128   mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
129
130   S (mp);
131   W (ret);
132
133   return ret;
134 }
135
136 #include <marvell/pp2/pp2.api_test.c>
137
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "gnu")
143  * End:
144  */