FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
dpdk_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/error.h>
18 #include <vppinfra/format.h>
19 #include <vppinfra/bitmap.h>
20 
21 #include <vnet/ethernet/ethernet.h>
22 #include <dpdk/device/dpdk.h>
23 #include <vlib/pci/pci.h>
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/stat.h>
29 #include <sys/mount.h>
30 #include <string.h>
31 #include <fcntl.h>
32 
33 #include <dpdk/device/dpdk_priv.h>
34 
35 #include <vlibapi/api.h>
36 #include <vlibmemory/api.h>
37 
38 /* define message IDs */
39 #include <dpdk/api/dpdk.api_enum.h>
40 #include <dpdk/api/dpdk.api_types.h>
41 
43 
44 static void
47 {
48  vl_api_sw_interface_set_dpdk_hqos_pipe_reply_t *rmp;
49  int rv = 0;
50 
51  dpdk_main_t *dm = &dpdk_main;
52  dpdk_device_t *xd;
53 
54  u32 sw_if_index = ntohl (mp->sw_if_index);
55  u32 subport = ntohl (mp->subport);
56  u32 pipe = ntohl (mp->pipe);
57  u32 profile = ntohl (mp->profile);
59 
61 
62  /* hw_if & dpdk device */
64 
65  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
66 
67  rv = rte_sched_pipe_config (xd->hqos_ht->hqos, subport, pipe, profile);
68 
70 
71  REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_PIPE_REPLY);
72 }
73 
76 {
77  u8 *s;
78 
79  s = format (0, "SCRIPT: sw_interface_set_dpdk_hqos_pipe ");
80 
81  s = format (s, "sw_if_index %u ", ntohl (mp->sw_if_index));
82 
83  s = format (s, "subport %u pipe %u profile %u ",
84  ntohl (mp->subport), ntohl (mp->pipe), ntohl (mp->profile));
85 
86  FINISH;
87 }
88 
89 static void
92 {
93  vl_api_sw_interface_set_dpdk_hqos_subport_reply_t *rmp;
94  int rv = 0;
95 
96  dpdk_main_t *dm = &dpdk_main;
97  dpdk_device_t *xd;
98  struct rte_sched_subport_params p;
99 
100  u32 sw_if_index = ntohl (mp->sw_if_index);
101  u32 subport = ntohl (mp->subport);
102  p.tb_rate = ntohl (mp->tb_rate);
103  p.tb_size = ntohl (mp->tb_size);
104  p.tc_rate[0] = ntohl (mp->tc_rate[0]);
105  p.tc_rate[1] = ntohl (mp->tc_rate[1]);
106  p.tc_rate[2] = ntohl (mp->tc_rate[2]);
107  p.tc_rate[3] = ntohl (mp->tc_rate[3]);
108  p.tc_period = ntohl (mp->tc_period);
109 
111 
113 
114  /* hw_if & dpdk device */
116 
117  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
118 
119  rv = rte_sched_subport_config (xd->hqos_ht->hqos, subport, &p);
120 
122 
123  REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_SUBPORT_REPLY);
124 }
125 
128 {
129  u8 *s;
130 
131  s = format (0, "SCRIPT: sw_interface_set_dpdk_hqos_subport ");
132 
133  s = format (s, "sw_if_index %u ", ntohl (mp->sw_if_index));
134 
135  s =
136  format (s,
137  "subport %u rate %u bkt_size %u tc0 %u tc1 %u tc2 %u tc3 %u period %u",
138  ntohl (mp->subport), ntohl (mp->tb_rate), ntohl (mp->tb_size),
139  ntohl (mp->tc_rate[0]), ntohl (mp->tc_rate[1]),
140  ntohl (mp->tc_rate[2]), ntohl (mp->tc_rate[3]),
141  ntohl (mp->tc_period));
142 
143  FINISH;
144 }
145 
146 static void
149 {
150  vl_api_sw_interface_set_dpdk_hqos_tctbl_reply_t *rmp;
151  int rv = 0;
152 
153  dpdk_main_t *dm = &dpdk_main;
155  dpdk_device_t *xd;
156 
157  u32 sw_if_index = ntohl (mp->sw_if_index);
158  u32 entry = ntohl (mp->entry);
159  u32 tc = ntohl (mp->tc);
160  u32 queue = ntohl (mp->queue);
161  u32 val, i;
162 
164 
166 
167  /* hw_if & dpdk device */
169 
170  xd = vec_elt_at_index (dm->devices, hw->dev_instance);
171 
172  if (tc >= RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE)
173  {
174  clib_warning ("invalid traffic class !!");
175  rv = VNET_API_ERROR_INVALID_VALUE;
176  goto done;
177  }
178  if (queue >= RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS)
179  {
180  clib_warning ("invalid queue !!");
181  rv = VNET_API_ERROR_INVALID_VALUE;
182  goto done;
183  }
184 
185  /* Detect the set of worker threads */
186  uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
187 
188  if (p == 0)
189  {
190  clib_warning ("worker thread registration AWOL !!");
191  rv = VNET_API_ERROR_INVALID_VALUE_2;
192  goto done;
193  }
194 
196  int worker_thread_first = tr->first_index;
197  int worker_thread_count = tr->count;
198 
199  val = tc * RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS + queue;
200  for (i = 0; i < worker_thread_count; i++)
201  xd->hqos_wt[worker_thread_first + i].hqos_tc_table[entry] = val;
202 
204 done:
205 
206  REPLY_MACRO (VL_API_SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY);
207 }
208 
211 {
212  u8 *s;
213 
214  s = format (0, "SCRIPT: sw_interface_set_dpdk_hqos_tctbl ");
215 
216  s = format (s, "sw_if_index %u ", ntohl (mp->sw_if_index));
217 
218  s = format (s, "entry %u tc %u queue %u",
219  ntohl (mp->entry), ntohl (mp->tc), ntohl (mp->queue));
220 
221  FINISH;
222 }
223 
224 #include <dpdk/api/dpdk.api.c>
225 static clib_error_t *
227 {
228  dpdk_main_t *dm = &dpdk_main;
229 
230  /* Ask for a correctly-sized block of API message decode slots */
232 
233  return 0;
234 }
235 
236 /* *INDENT-OFF* */
238 {
239  .runs_after = VLIB_INITS ("dpdk_init"),
240 /* *INDENT-OFF* */
241 
242 /*
243  * fd.io coding-style-patch-verification: ON
244  *
245  * Local Variables:
246  * eval: (c-set-style "gnu")
247  * End:
248  */
dpdk_main_t::msg_id_base
u16 msg_id_base
Definition: dpdk.h:379
dpdk.h
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
api.h
dpdk_main_t::devices
dpdk_device_t * devices
Definition: dpdk.h:357
vl_api_sw_interface_set_dpdk_hqos_pipe_t
DPDK interface HQoS pipe profile set request.
Definition: dpdk.api:27
bitmap.h
dpdk_main_t::vnet_main
vnet_main_t * vnet_main
Definition: dpdk.h:375
vl_api_sw_interface_set_dpdk_hqos_pipe_t_print
static void * vl_api_sw_interface_set_dpdk_hqos_pipe_t_print(vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp, void *handle)
Definition: dpdk_api.c:75
string.h
dpdk_api_init
static clib_error_t * dpdk_api_init(vlib_main_t *vm)
Definition: dpdk_api.c:226
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler
static void vl_api_sw_interface_set_dpdk_hqos_tctbl_t_handler(vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp)
Definition: dpdk_api.c:148
vl_api_sw_interface_set_dpdk_hqos_tctbl_t::queue
u32 queue
Definition: dpdk.api:73
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
vlib_thread_registration_::count
u32 count
Definition: threads.h:38
ethernet.h
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
vl_api_sw_interface_set_dpdk_hqos_subport_t::subport
u32 subport
Definition: dpdk.api:51
vl_api_sw_interface_set_dpdk_hqos_subport_t
DPDK interface HQoS subport parameters set request.
Definition: dpdk.api:47
vl_api_sw_interface_set_dpdk_hqos_pipe_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: dpdk.api:30
error.h
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vl_api_sw_interface_set_dpdk_hqos_pipe_t::profile
u32 profile
Definition: dpdk.api:33
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
dpdk_main
dpdk_main_t dpdk_main
Definition: init.c:48
dpdk_main_t
Definition: dpdk.h:353
uword
u64 uword
Definition: types.h:112
FINISH
#define FINISH
Definition: flowprobe.c:72
vl_api_sw_interface_set_dpdk_hqos_tctbl_t_print
static void * vl_api_sw_interface_set_dpdk_hqos_tctbl_t_print(vl_api_sw_interface_set_dpdk_hqos_tctbl_t *mp, void *handle)
Definition: dpdk_api.c:210
vlib_thread_main_t::thread_registrations_by_name
uword * thread_registrations_by_name
Definition: threads.h:272
vlib_thread_registration_::first_index
u32 first_index
Definition: threads.h:44
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
format.h
vl_api_sw_interface_set_dpdk_hqos_subport_t::tb_rate
u32 tb_rate
Definition: dpdk.api:52
vl_api_sw_interface_set_dpdk_hqos_pipe_t::subport
u32 subport
Definition: dpdk.api:31
vl_api_sw_interface_set_dpdk_hqos_subport_t::tc_period
u32 tc_period
Definition: dpdk.api:55
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
vnet_hw_interface_t
Definition: interface.h:638
vl_api_sw_interface_set_dpdk_hqos_subport_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: dpdk.api:50
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
vlib_thread_main_t
Definition: threads.h:264
api_helper_macros.h
pci.h
vl_api_sw_interface_set_dpdk_hqos_tctbl_t::tc
u32 tc
Definition: dpdk.api:72
vec.h
vl_api_sw_interface_set_dpdk_hqos_tctbl_t::entry
u32 entry
Definition: dpdk.api:71
vlib_main_t
Definition: main.h:102
vl_api_sw_interface_set_dpdk_hqos_subport_t::tb_size
u32 tb_size
Definition: dpdk.api:53
VLIB_INITS
#define VLIB_INITS(...)
Definition: init.h:352
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vl_api_sw_interface_set_dpdk_hqos_subport_t::tc_rate
u32 tc_rate[4]
Definition: dpdk.api:54
vl_api_sw_interface_set_dpdk_hqos_tctbl_t
DPDK interface HQoS tctbl entry set request.
Definition: dpdk.api:67
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
rv
int __clib_unused rv
Definition: application.c:491
vl_api_sw_interface_set_dpdk_hqos_tctbl_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: dpdk.api:70
vl_api_sw_interface_set_dpdk_hqos_pipe_t::pipe
u32 pipe
Definition: dpdk.api:32
vnet.h
vlib_thread_registration_
Definition: threads.h:27
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler
static void vl_api_sw_interface_set_dpdk_hqos_pipe_t_handler(vl_api_sw_interface_set_dpdk_hqos_pipe_t *mp)
Definition: dpdk_api.c:46
vl_api_sw_interface_set_dpdk_hqos_subport_t_handler
static void vl_api_sw_interface_set_dpdk_hqos_subport_t_handler(vl_api_sw_interface_set_dpdk_hqos_subport_t *mp)
Definition: dpdk_api.c:91
vl_api_sw_interface_set_dpdk_hqos_subport_t_print
static void * vl_api_sw_interface_set_dpdk_hqos_subport_t_print(vl_api_sw_interface_set_dpdk_hqos_subport_t *mp, void *handle)
Definition: dpdk_api.c:127
dpdk_priv.h
dpdk_device_t
Definition: dpdk.h:181