FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
vmxnet3_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
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 <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22 
23 #include <vmxnet3/vmxnet3.h>
24 
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 
28 /* define message IDs */
30 
31 /* define message structures */
32 #define vl_typedefs
34 #undef vl_typedefs
35 
36 /* define generated endian-swappers */
37 #define vl_endianfun
39 #undef vl_endianfun
40 
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
43 #define vl_printfun
45 #undef vl_printfun
46 
47 /* get the API version number */
48 #define vl_api_version(n,v) static u32 api_version=(v);
50 #undef vl_api_version
51 
53 
54 #define foreach_vmxnet3_plugin_api_msg \
55 _(VMXNET3_CREATE, vmxnet3_create) \
56 _(VMXNET3_DELETE, vmxnet3_delete) \
57 _(VMXNET3_DUMP, vmxnet3_dump)
58 
59 static void
61 {
66  int rv;
67 
68  clib_memset (&args, 0, sizeof (vmxnet3_create_if_args_t));
69 
70  args.enable_elog = ntohl (mp->enable_elog);
71  args.addr.as_u32 = ntohl (mp->pci_addr);
72  args.rxq_size = ntohs (mp->rxq_size);
73  args.txq_size = ntohs (mp->txq_size);
74  args.txq_num = ntohs (mp->txq_num);
75  args.rxq_num = ntohs (mp->rxq_num);
76  args.bind = mp->bind;
77 
78  vmxnet3_create_if (vm, &args);
79  rv = args.rv;
80 
81  /* *INDENT-OFF* */
82  REPLY_MACRO2 (VL_API_VMXNET3_CREATE_REPLY + vmxm->msg_id_base,
83  ({
84  rmp->sw_if_index = ntohl (args.sw_if_index);
85  }));
86  /* *INDENT-ON* */
87 }
88 
89 static void
91 {
93  vnet_main_t *vnm = vnet_get_main ();
95  vl_api_vmxnet3_delete_reply_t *rmp;
96  vmxnet3_device_t *vd;
98  int rv = 0;
99 
100  hw =
102  htonl (mp->sw_if_index));
103  if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
104  {
105  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
106  goto reply;
107  }
108 
109  vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
110 
111  vmxnet3_delete_if (vm, vd);
112 
113 reply:
114  REPLY_MACRO (VL_API_VMXNET3_DELETE_REPLY + vmxm->msg_id_base);
115 }
116 
117 static void
119  vnet_sw_interface_t * swif, u8 * interface_name,
120  u32 context)
121 {
123  vnet_main_t *vnm = vnet_get_main ();
124  vmxnet3_main_t *vmxm = &vmxnet3_main;
125  vnet_hw_interface_t *hwif;
126  vmxnet3_rx_ring *ring;
127  u16 rid, qid;
128 
129  hwif = vnet_get_sup_hw_interface (vnm, swif->sw_if_index);
130 
131  mp = vl_msg_api_alloc (sizeof (*mp));
132  clib_memset (mp, 0, sizeof (*mp));
133 
134  mp->_vl_msg_id = htons (VL_API_VMXNET3_DETAILS + vmxm->msg_id_base);
135  mp->context = context;
136 
137  mp->sw_if_index = htonl (swif->sw_if_index);
138  strncpy ((char *) mp->if_name,
139  (char *) interface_name, ARRAY_LEN (mp->if_name) - 1);
140 
141  if (hwif->hw_address)
142  memcpy (mp->hw_addr, hwif->hw_address, ARRAY_LEN (mp->hw_addr));
143 
144  mp->version = vd->version;
145  mp->pci_addr = ntohl (vd->pci_addr.as_u32);
146  mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
147 
149  vec_foreach_index (qid, vd->rxqs)
150  {
151  vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
152  vl_api_vmxnet3_rx_list_t *rx_list = &mp->rx_list[qid];
153 
154  ASSERT (qid < VMXNET3_RXQ_MAX);
155  rx_list->rx_qsize = htons (rxq->size);
156  rx_list->rx_next = htons (rxq->rx_comp_ring.next);
157  for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
158  {
159  ring = &rxq->rx_ring[rid];
160  rx_list->rx_fill[rid] = htons (ring->fill);
161  rx_list->rx_produce[rid] = htons (ring->produce);
162  rx_list->rx_consume[rid] = htons (ring->consume);
163  }
164  }
165 
167  vec_foreach_index (qid, vd->txqs)
168  {
169  vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
170  vl_api_vmxnet3_tx_list_t *tx_list = &mp->tx_list[qid];
171 
172  ASSERT (qid < VMXNET3_TXQ_MAX);
173  tx_list->tx_qsize = htons (txq->size);
174  tx_list->tx_next = htons (txq->tx_comp_ring.next);
175  tx_list->tx_produce = htons (txq->tx_ring.produce);
176  tx_list->tx_consume = htons (txq->tx_ring.consume);
177  }
178 
179  vl_api_send_msg (reg, (u8 *) mp);
180 }
181 
182 /**
183  * @brief Message handler for vmxnet3_dump API.
184  * @param mp vl_api_vmxnet3_dump_t * mp the api message
185  */
186 static void
188 {
189  vmxnet3_main_t *vmxm = &vmxnet3_main;
190  vnet_main_t *vnm = vnet_get_main ();
191  vnet_sw_interface_t *swif;
192  vmxnet3_device_t *vd;
193  u8 *if_name = 0;
195 
197  if (!reg)
198  return;
199 
200  /* *INDENT-OFF* */
201  pool_foreach (vd, vmxm->devices,
202  ({
203  swif = vnet_get_sw_interface (vnm, vd->sw_if_index);
204  if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
205  swif, 0);
206  send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
207  _vec_len (if_name) = 0;
208  }));
209  /* *INDENT-ON* */
210 
211  vec_free (if_name);
212 }
213 
214 #define vl_msg_name_crc_list
216 #undef vl_msg_name_crc_list
217 
218 static void
220 {
221 #define _(id,n,crc) \
222  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + vmxm->msg_id_base);
223  foreach_vl_msg_name_crc_vmxnet3;
224 #undef _
225 }
226 
227 /* set tup the API message handling tables */
228 clib_error_t *
230 {
231  vmxnet3_main_t *vmxm = &vmxnet3_main;
232  api_main_t *am = &api_main;
233  u8 *name;
234 
235  /* construct the API name */
236  name = format (0, "vmxnet3_%08x%c", api_version, 0);
237 
238  /* ask for a correctly-sized block of API message decode slots */
240  ((char *) name, VL_MSG_FIRST_AVAILABLE);
241 
242 #define _(N,n) \
243  vl_msg_api_set_handlers((VL_API_##N + vmxm->msg_id_base), \
244  #n, \
245  vl_api_##n##_t_handler, \
246  vl_noop_handler, \
247  vl_api_##n##_t_endian, \
248  vl_api_##n##_t_print, \
249  sizeof(vl_api_##n##_t), 1);
251 #undef _
252 
253  /* set up the (msg_name, crc, message-id) table */
254  setup_message_id_table (vmxm, am);
255 
256  vec_free (name);
257  return 0;
258 }
259 
260 /*
261  * fd.io coding-style-patch-verification: ON
262  *
263  * Local Variables:
264  * eval: (c-set-style "gnu")
265  * End:
266  */
void vmxnet3_delete_if(vlib_main_t *vm, vmxnet3_device_t *vd)
Definition: vmxnet3.c:842
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define clib_min(x, y)
Definition: clib.h:295
Dump all vmxnet3 interfaces.
Definition: vmxnet3.api:143
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define VMXNET3_RXQ_MAX
Definition: vmxnet3.h:91
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
vlib_pci_addr_t pci_addr
Definition: vmxnet3.h:565
static void send_vmxnet3_details(vl_api_registration_t *reg, vmxnet3_device_t *vd, vnet_sw_interface_t *swif, u8 *interface_name, u32 context)
Definition: vmxnet3_api.c:118
vmxnet3_main_t vmxnet3_main
Definition: vmxnet3.c:28
void vmxnet3_create_if(vlib_main_t *vm, vmxnet3_create_if_args_t *args)
Definition: vmxnet3.c:599
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
static void setup_message_id_table(vmxnet3_main_t *vmxm, api_main_t *am)
Definition: vmxnet3_api.c:219
vmxnet3_rxq_t * rxqs
Definition: vmxnet3.h:569
static void vl_api_vmxnet3_create_t_handler(vl_api_vmxnet3_create_t *mp)
Definition: vmxnet3_api.c:60
#define VMXNET3_TXQ_MAX
Definition: vmxnet3.h:90
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
#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
vlib_pci_addr_t addr
Definition: vmxnet3.h:602
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
Memory interface details structure.
Definition: vmxnet3.api:121
u16 msg_id_base
Definition: vmxnet3.h:593
unsigned short u16
Definition: types.h:57
vmxnet3_rx_comp_ring rx_comp_ring
Definition: vmxnet3.h:522
vmxnet3_tx_comp_ring tx_comp_ring
Definition: vmxnet3.h:551
vl_api_vmxnet3_rx_list_t rx_list[16]
Definition: vmxnet3.api:133
#define VMXNET3_RX_RING_SIZE
Definition: vmxnet3.h:158
#define REPLY_MACRO(t)
vnet_sw_interface_flags_t flags
Definition: interface.h:684
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
vl_api_vmxnet3_tx_list_t tx_list[8]
Definition: vmxnet3.api:136
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
u32 context
Definition: ipsec_gre.api:33
#define foreach_vmxnet3_plugin_api_msg
Definition: vmxnet3_api.c:54
#define ARRAY_LEN(x)
Definition: clib.h:62
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
vmxnet3_txq_t * txqs
Definition: vmxnet3.h:570
static void vl_api_vmxnet3_delete_t_handler(vl_api_vmxnet3_delete_t *mp)
Definition: vmxnet3_api.c:90
#define ASSERT(truth)
vmxnet3_rx_list structure
Definition: vmxnet3.api:99
clib_error_t * vmxnet3_plugin_api_hookup(vlib_main_t *vm)
Definition: vmxnet3_api.c:229
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_device_class_t vmxnet3_device_class
vmxnet3_rx_ring rx_ring[VMXNET3_RX_RING_SIZE]
Definition: vmxnet3.h:519
vmxnet3_tx_list structure
Definition: vmxnet3.api:83
vmxnet3_device_t * devices
Definition: vmxnet3.h:592
static void vl_api_vmxnet3_dump_t_handler(vl_api_vmxnet3_dump_t *mp)
Message handler for vmxnet3_dump API.
Definition: vmxnet3_api.c:187
vmxnet3_tx_ring tx_ring
Definition: vmxnet3.h:550
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:880