2 *------------------------------------------------------------------
3 * dpdk_api.c - dpdk interface api
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
24 #include <vnet/devices/dpdk/dpdk.h>
27 #include <vnet/vnet_msg_enum.h>
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
40 #include <vnet/vnet_all_api_h.h>
43 #include <vlibapi/api_helper_macros.h>
45 #define foreach_vpe_api_msg \
46 _(SW_INTERFACE_SET_DPDK_HQOS_PIPE, sw_interface_set_dpdk_hqos_pipe) \
47 _(SW_INTERFACE_SET_DPDK_HQOS_SUBPORT, sw_interface_set_dpdk_hqos_subport) \
48 _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL, sw_interface_set_dpdk_hqos_tctbl)
51 vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
52 (vl_api_sw_interface_set_dpdk_hqos_pipe_t * mp)
54 vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
58 dpdk_main_t *dm = &dpdk_main;
61 u32 sw_if_index = ntohl (mp->sw_if_index);
62 u32 subport = ntohl (mp->subport);
63 u32 pipe = ntohl (mp->pipe);
64 u32 profile = ntohl (mp->profile);
65 vnet_hw_interface_t *hw;
67 VALIDATE_SW_IF_INDEX (mp);
69 /* hw_if & dpdk device */
70 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
72 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
74 rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
76 BAD_SW_IF_INDEX_LABEL;
78 clib_warning ("setting HQoS pipe parameters without DPDK not implemented");
79 rv = VNET_API_ERROR_UNIMPLEMENTED;
82 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
86 vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
87 (vl_api_sw_interface_set_dpdk_hqos_subport_t * mp)
89 vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
93 dpdk_main_t *dm = &dpdk_main;
95 struct rte_sched_subport_params p;
97 u32 sw_if_index = ntohl (mp->sw_if_index);
98 u32 subport = ntohl (mp->subport);
99 p.tb_rate = ntohl (mp->tb_rate);
100 p.tb_size = ntohl (mp->tb_size);
101 p.tc_rate[0] = ntohl (mp->tc_rate[0]);
102 p.tc_rate[1] = ntohl (mp->tc_rate[1]);
103 p.tc_rate[2] = ntohl (mp->tc_rate[2]);
104 p.tc_rate[3] = ntohl (mp->tc_rate[3]);
105 p.tc_period = ntohl (mp->tc_period);
107 vnet_hw_interface_t *hw;
109 VALIDATE_SW_IF_INDEX (mp);
111 /* hw_if & dpdk device */
112 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
114 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
116 rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
118 BAD_SW_IF_INDEX_LABEL;
121 ("setting HQoS subport parameters without DPDK not implemented");
122 rv = VNET_API_ERROR_UNIMPLEMENTED;
125 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
129 vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
130 (vl_api_sw_interface_set_dpdk_hqos_tctbl_t * mp)
132 vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
136 dpdk_main_t *dm = &dpdk_main;
137 vlib_thread_main_t *tm = vlib_get_thread_main ();
140 u32 sw_if_index = ntohl (mp->sw_if_index);
141 u32 entry = ntohl (mp->entry);
142 u32 tc = ntohl (mp->tc);
143 u32 queue = ntohl (mp->queue);
146 vnet_hw_interface_t *hw;
148 VALIDATE_SW_IF_INDEX (mp);
150 /* hw_if & dpdk device */
151 hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
153 xd = vec_elt_at_index (dm->devices, hw->dev_instance);
155 if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
157 clib_warning ("invalid traffic class !!");
158 rv = VNET_API_ERROR_INVALID_VALUE;
161 if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
163 clib_warning ("invalid queue !!");
164 rv = VNET_API_ERROR_INVALID_VALUE;
168 /* Detect the set of worker threads */
169 uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
173 clib_warning ("worker thread registration AWOL !!");
174 rv = VNET_API_ERROR_INVALID_VALUE_2;
178 vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
179 int worker_thread_first = tr->first_index;
180 int worker_thread_count = tr->count;
182 val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
183 for (i = 0; i < worker_thread_count; i++)
184 xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
186 BAD_SW_IF_INDEX_LABEL;
189 clib_warning ("setting HQoS DSCP table entry without DPDK not implemented");
190 rv = VNET_API_ERROR_UNIMPLEMENTED;
193 REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
198 * Add vpe's API message handlers to the table.
199 * vlib has alread mapped shared memory and
200 * added the client registration handlers.
201 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
203 #define vl_msg_name_crc_list
204 #include <vnet/vnet_all_api_h.h>
205 #undef vl_msg_name_crc_list
208 setup_message_id_table (api_main_t * am)
210 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
211 foreach_vl_msg_name_crc_dpdk;
215 static clib_error_t *
216 dpdk_api_hookup (vlib_main_t * vm)
218 api_main_t *am = &api_main;
221 vl_msg_api_set_handlers(VL_API_##N, #n, \
222 vl_api_##n##_t_handler, \
224 vl_api_##n##_t_endian, \
225 vl_api_##n##_t_print, \
226 sizeof(vl_api_##n##_t), 1);
231 * Set up the (msg_name, crc, message-id) table
233 setup_message_id_table (am);
238 VLIB_API_INIT_FUNCTION (dpdk_api_hookup);
241 * fd.io coding-style-patch-verification: ON
244 * eval: (c-set-style "gnu")