FD.io VPP  v21.01.1
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 */
63  hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
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 */
115  hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
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 */
168  hw = vnet_get_sup_hw_interface (dm->vnet_main, sw_if_index);
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 interface HQoS subport parameters set request.
Definition: dpdk.api:47
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
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
dpdk_main_t dpdk_main
Definition: init.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Optimized string handling code, including c11-compliant "safe C library" variants.
static clib_error_t * dpdk_api_init(vlib_main_t *vm)
Definition: dpdk_api.c:226
vlib_main_t * vm
Definition: in2out_ed.c:1580
unsigned char u8
Definition: types.h:56
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
description fragment has unexpected format
Definition: map.api:433
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned int u32
Definition: types.h:88
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_interface_index_t sw_if_index
Definition: dpdk.api:50
#define REPLY_MACRO(t)
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:409
#define BAD_SW_IF_INDEX_LABEL
dpdk_device_t * devices
Definition: dpdk.h:330
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
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
DPDK interface HQoS tctbl entry set request.
Definition: dpdk.api:67
#define clib_warning(format, args...)
Definition: error.h:59
#define FINISH
Definition: flowprobe.c:73
Bitmaps built as vectors of machine words.
vl_api_interface_index_t sw_if_index
Definition: dpdk.api:70
uword * thread_registrations_by_name
Definition: threads.h:295
u64 uword
Definition: types.h:112
#define hash_get_mem(h, key)
Definition: hash.h:269
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
DPDK interface HQoS pipe profile set request.
Definition: dpdk.api:27
u16 msg_id_base
Definition: dpdk.h:352
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
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
vl_api_interface_index_t sw_if_index
Definition: dpdk.api:30
vnet_main_t * vnet_main
Definition: dpdk.h:348
#define VLIB_INITS(...)
Definition: init.h:357
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
#define VALIDATE_SW_IF_INDEX(mp)