FD.io VPP  v21.06-3-gbb25fbf28
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 #include <vnet/format_fns.h>
23 #include <vmxnet3/vmxnet3.h>
24 
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 
28 /* define message IDs */
29 #include <vmxnet3/vmxnet3.api_enum.h>
30 #include <vmxnet3/vmxnet3.api_types.h>
31 
33 
34 static void
36 {
41  int rv;
42 
43  clib_memset (&args, 0, sizeof (vmxnet3_create_if_args_t));
44 
45  args.enable_elog = ntohl (mp->enable_elog);
46  args.addr.as_u32 = ntohl (mp->pci_addr);
47  args.rxq_size = ntohs (mp->rxq_size);
48  args.txq_size = ntohs (mp->txq_size);
49  args.txq_num = ntohs (mp->txq_num);
50  args.rxq_num = ntohs (mp->rxq_num);
51  args.bind = mp->bind;
52  args.enable_gso = mp->enable_gso;
53 
54  vmxnet3_create_if (vm, &args);
55  rv = args.rv;
56 
57  /* *INDENT-OFF* */
58  REPLY_MACRO2 (VL_API_VMXNET3_CREATE_REPLY + vmxm->msg_id_base,
59  ({
60  rmp->sw_if_index = ntohl (args.sw_if_index);
61  }));
62  /* *INDENT-ON* */
63 }
64 
65 static void
67 {
69  vnet_main_t *vnm = vnet_get_main ();
71  vl_api_vmxnet3_delete_reply_t *rmp;
72  vmxnet3_device_t *vd;
74  int rv = 0;
75 
76  hw =
78  htonl (mp->sw_if_index));
79  if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
80  {
81  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
82  goto reply;
83  }
84 
85  vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
86 
87  vmxnet3_delete_if (vm, vd);
88 
89 reply:
90  REPLY_MACRO (VL_API_VMXNET3_DELETE_REPLY + vmxm->msg_id_base);
91 }
92 
93 static void
95  vnet_sw_interface_t * swif, u8 * interface_name,
96  u32 context)
97 {
99  vnet_main_t *vnm = vnet_get_main ();
100  vmxnet3_main_t *vmxm = &vmxnet3_main;
101  vnet_hw_interface_t *hwif;
102  vmxnet3_rx_ring *ring;
103  u16 rid, qid;
104 
105  hwif = vnet_get_sup_hw_interface (vnm, swif->sw_if_index);
106 
107  mp = vl_msg_api_alloc (sizeof (*mp));
108  clib_memset (mp, 0, sizeof (*mp));
109 
110  mp->_vl_msg_id = htons (VL_API_VMXNET3_DETAILS + vmxm->msg_id_base);
111  mp->context = context;
112 
113  mp->sw_if_index = htonl (swif->sw_if_index);
114  strncpy ((char *) mp->if_name,
115  (char *) interface_name, ARRAY_LEN (mp->if_name) - 1);
116 
117  if (hwif->hw_address)
118  memcpy (mp->hw_addr, hwif->hw_address, ARRAY_LEN (mp->hw_addr));
119 
120  mp->version = vd->version;
121  mp->pci_addr = ntohl (vd->pci_addr.as_u32);
122  mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
123 
125  vec_foreach_index (qid, vd->rxqs)
126  {
127  vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
128  vl_api_vmxnet3_rx_list_t *rx_list = &mp->rx_list[qid];
129 
130  ASSERT (qid < VMXNET3_RXQ_MAX);
131  rx_list->rx_qsize = htons (rxq->size);
132  rx_list->rx_next = htons (rxq->rx_comp_ring.next);
133  for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
134  {
135  ring = &rxq->rx_ring[rid];
136  rx_list->rx_fill[rid] = htons (ring->fill);
137  rx_list->rx_produce[rid] = htons (ring->produce);
138  rx_list->rx_consume[rid] = htons (ring->consume);
139  }
140  }
141 
143  vec_foreach_index (qid, vd->txqs)
144  {
145  vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
146  vl_api_vmxnet3_tx_list_t *tx_list = &mp->tx_list[qid];
147 
148  ASSERT (qid < VMXNET3_TXQ_MAX);
149  tx_list->tx_qsize = htons (txq->size);
150  tx_list->tx_next = htons (txq->tx_comp_ring.next);
151  tx_list->tx_produce = htons (txq->tx_ring.produce);
152  tx_list->tx_consume = htons (txq->tx_ring.consume);
153  }
154 
155  vl_api_send_msg (reg, (u8 *) mp);
156 }
157 
158 /**
159  * @brief Message handler for vmxnet3_dump API.
160  * @param mp vl_api_vmxnet3_dump_t * mp the api message
161  */
162 static void
164 {
165  vmxnet3_main_t *vmxm = &vmxnet3_main;
166  vnet_main_t *vnm = vnet_get_main ();
168  vmxnet3_device_t *vd;
169  u8 *if_name = 0;
171 
173  if (!reg)
174  return;
175 
176  /* *INDENT-OFF* */
177  pool_foreach (vd, vmxm->devices)
178  {
180  if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
181  swif, 0);
182  send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
183  _vec_len (if_name) = 0;
184  }
185  /* *INDENT-ON* */
186 
187  vec_free (if_name);
188 }
189 
190 /**
191  * @brief Message handler for vmxnet3_dump API.
192  * @param mp vl_api_vmxnet3_dump_t * mp the api message
193  */
196 {
197  vmxnet3_main_t *vmxm = &vmxnet3_main;
198  vnet_main_t *vnm = vnet_get_main ();
200  vmxnet3_device_t *vd;
201  u8 *if_name = 0;
203  u32 filter_sw_if_index;
204 
206  if (!reg)
207  return;
208 
209  filter_sw_if_index = htonl (mp->sw_if_index);
210  if ((filter_sw_if_index != ~0) &&
211  (vnet_sw_interface_is_api_valid (vnm, filter_sw_if_index) == 0))
212  goto bad_sw_if_index;
213 
214  /* *INDENT-OFF* */
215  pool_foreach (vd, vmxm->devices)
216  {
217  if ((filter_sw_if_index == ~0) ||
218  (vd->sw_if_index == filter_sw_if_index))
219  {
221  if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
222  swif, 0);
223  send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
224  _vec_len (if_name) = 0;
225  }
226  }
227  /* *INDENT-ON* */
228 
230  vec_free (if_name);
231 }
232 
233 /* set tup the API message handling tables */
234 #include <vmxnet3/vmxnet3.api.c>
235 clib_error_t *
237 {
238  vmxnet3_main_t *vmxm = &vmxnet3_main;
239 
240  /* ask for a correctly-sized block of API message decode slots */
242  return 0;
243 }
244 
245 /*
246  * fd.io coding-style-patch-verification: ON
247  *
248  * Local Variables:
249  * eval: (c-set-style "gnu")
250  * End:
251  */
vmxnet3_main
vmxnet3_main_t vmxnet3_main
Definition: vmxnet3.c:28
vl_api_vmxnet3_dump_t
Dump all vmxnet3 interfaces.
Definition: vmxnet3.api:149
vlib.h
vl_api_vmxnet3_create_t
Definition: vmxnet3.api:38
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
vmxnet3_create_if
void vmxnet3_create_if(vlib_main_t *vm, vmxnet3_create_if_args_t *args)
Definition: vmxnet3.c:606
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_sw_vmxnet3_interface_dump_t::client_index
u32 client_index
Definition: vmxnet3.api:163
vmxnet3_create_if_args_t::bind
u8 bind
Definition: vmxnet3.h:608
vl_api_vmxnet3_dump_t::client_index
u32 client_index
Definition: vmxnet3.api:152
vnet_sw_interface_t
Definition: interface.h:868
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
send_vmxnet3_details
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:94
vl_api_vmxnet3_create_t::rxq_size
u16 rxq_size
Definition: vmxnet3.api:45
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vmxnet3_rx_ring::fill
u16 fill
Definition: vmxnet3.h:500
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
vl_api_sw_vmxnet3_interface_dump_t::context
u32 context
Definition: vmxnet3.api:164
vnet_hw_interface_t::hw_address
u8 * hw_address
Definition: interface.h:649
vl_api_vmxnet3_create_t::txq_num
u16 txq_num
Definition: vmxnet3.api:48
VMXNET3_RXQ_MAX
#define VMXNET3_RXQ_MAX
Definition: vmxnet3.h:91
vl_api_sw_vmxnet3_interface_dump_t::sw_if_index
vl_api_interface_index_t sw_if_index[default=0xffffffff]
Definition: vmxnet3.api:165
vmxnet3_device_t::pci_addr
vlib_pci_addr_t pci_addr
Definition: vmxnet3.h:566
vmxnet3_create_if_args_t::addr
vlib_pci_addr_t addr
Definition: vmxnet3.h:602
u16
unsigned short u16
Definition: types.h:57
VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:843
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vmxnet3_main_t
Definition: vmxnet3.h:591
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
VMXNET3_TXQ_MAX
#define VMXNET3_TXQ_MAX
Definition: vmxnet3.h:90
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
ethernet.h
vmxnet3_create_if_args_t::rxq_size
u16 rxq_size
Definition: vmxnet3.h:604
vmxnet3_rx_ring::produce
u16 produce
Definition: vmxnet3.h:502
vmxnet3_rxq_t::size
u16 size
Definition: vmxnet3.h:516
vmxnet3_main_t::msg_id_base
u16 msg_id_base
Definition: vmxnet3.h:594
vl_api_vmxnet3_details_t::pci_addr
u32 pci_addr
Definition: vmxnet3.api:134
vnet_sw_interface_is_api_valid
static uword vnet_sw_interface_is_api_valid(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:285
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vl_api_vmxnet3_details_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: vmxnet3.api:131
vmxnet3_rx_ring
Definition: vmxnet3.h:495
vmxnet3_create_if_args_t::rv
i32 rv
Definition: vmxnet3.h:611
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vl_api_vmxnet3_details_t::version
u8 version
Definition: vmxnet3.api:135
vl_api_vmxnet3_details_t::if_name
string if_name[64]
Definition: vmxnet3.api:132
vmxnet3_create_if_args_t
Definition: vmxnet3.h:600
vl_api_vmxnet3_details_t::rx_count
u8 rx_count
Definition: vmxnet3.api:138
vl_api_vmxnet3_create_t::pci_addr
u32 pci_addr
Definition: vmxnet3.api:43
vmxnet3_create_if_args_t::txq_num
u16 txq_num
Definition: vmxnet3.h:607
vl_api_vmxnet3_create_t::txq_size
u16 txq_size
Definition: vmxnet3.api:47
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
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vl_api_vmxnet3_dump_t::context
u32 context
Definition: vmxnet3.api:153
vl_api_vmxnet3_delete_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: vmxnet3.api:78
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vl_api_sw_vmxnet3_interface_dump_t_handler
static void vl_api_sw_vmxnet3_interface_dump_t_handler(vl_api_sw_vmxnet3_interface_dump_t *mp)
Message handler for vmxnet3_dump API.
Definition: vmxnet3_api.c:195
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
vmxnet3_txq_t::tx_comp_ring
vmxnet3_tx_comp_ring tx_comp_ring
Definition: vmxnet3.h:552
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
vmxnet3_rxq_t::rx_comp_ring
vmxnet3_rx_comp_ring rx_comp_ring
Definition: vmxnet3.h:523
vmxnet3_tx_ring::produce
u16 produce
Definition: vmxnet3.h:531
vmxnet3_rx_ring::consume
u16 consume
Definition: vmxnet3.h:503
vl_api_vmxnet3_details_t::tx_list
vl_api_vmxnet3_tx_list_t tx_list[8]
Definition: vmxnet3.api:142
vmxnet3_create_if_args_t::txq_size
u16 txq_size
Definition: vmxnet3.h:606
clib_min
#define clib_min(x, y)
Definition: clib.h:342
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
VMXNET3_RX_RING_SIZE
#define VMXNET3_RX_RING_SIZE
Definition: vmxnet3.h:158
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vl_api_vmxnet3_details_t::hw_addr
vl_api_mac_address_t hw_addr
Definition: vmxnet3.api:133
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vl_api_vmxnet3_details_t::rx_list
vl_api_vmxnet3_rx_list_t rx_list[16]
Definition: vmxnet3.api:139
vl_api_vmxnet3_create_t_handler
static void vl_api_vmxnet3_create_t_handler(vl_api_vmxnet3_create_t *mp)
Definition: vmxnet3_api.c:35
vl_api_vmxnet3_create_t::enable_gso
bool enable_gso
Definition: vmxnet3.api:50
format_fns.h
vl_api_vmxnet3_dump_t_handler
static void vl_api_vmxnet3_dump_t_handler(vl_api_vmxnet3_dump_t *mp)
Message handler for vmxnet3_dump API.
Definition: vmxnet3_api.c:163
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vmxnet3_device_t::rxqs
vmxnet3_rxq_t * rxqs
Definition: vmxnet3.h:570
vmxnet3_txq_t::tx_ring
vmxnet3_tx_ring tx_ring
Definition: vmxnet3.h:551
vmxnet3_create_if_args_t::enable_elog
u32 enable_elog
Definition: vmxnet3.h:603
vmxnet3_tx_comp_ring::next
u16 next
Definition: vmxnet3.h:539
u32
unsigned int u32
Definition: types.h:88
vmxnet3_txq_t
Definition: vmxnet3.h:542
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
vl_api_vmxnet3_delete_t_handler
static void vl_api_vmxnet3_delete_t_handler(vl_api_vmxnet3_delete_t *mp)
Definition: vmxnet3_api.c:66
vl_api_vmxnet3_delete_t
Definition: vmxnet3.api:73
api_helper_macros.h
vmxnet3_rxq_t::rx_ring
vmxnet3_rx_ring rx_ring[VMXNET3_RX_RING_SIZE]
Definition: vmxnet3.h:520
pci.h
vl_api_vmxnet3_create_t::bind
u8 bind
Definition: vmxnet3.api:49
vl_api_vmxnet3_details_t::context
u32 context
Definition: vmxnet3.api:129
vl_api_vmxnet3_create_reply_t
Definition: vmxnet3.api:60
vmxnet3_create_if_args_t::enable_gso
u8 enable_gso
Definition: vmxnet3.h:609
vmxnet3_device_t::txqs
vmxnet3_txq_t * txqs
Definition: vmxnet3.h:571
vmxnet3_device_t::sw_if_index
u32 sw_if_index
Definition: vmxnet3.h:562
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vmxnet3_rxq_t
Definition: vmxnet3.h:513
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
unix.h
vl_api_sw_vmxnet3_interface_dump_t
Dump vmxnet3 interfaces.
Definition: vmxnet3.api:161
vl_api_vmxnet3_details_t::tx_count
u8 tx_count
Definition: vmxnet3.api:141
vl_api_vmxnet3_details_t::admin_up_down
bool admin_up_down
Definition: vmxnet3.api:136
context
u32 context
Definition: ip.api:780
rv
int __clib_unused rv
Definition: application.c:491
vl_api_vmxnet3_details_t
Memory interface details structure.
Definition: vmxnet3.api:127
vmxnet3_delete_if
void vmxnet3_delete_if(vlib_main_t *vm, vmxnet3_device_t *vd)
Definition: vmxnet3.c:858
vmxnet3_plugin_api_hookup
clib_error_t * vmxnet3_plugin_api_hookup(vlib_main_t *vm)
Definition: vmxnet3_api.c:236
vmxnet3_device_t::version
u8 version
Definition: vmxnet3.h:577
vmxnet3_txq_t::size
u16 size
Definition: vmxnet3.h:545
vmxnet3_device_t
Definition: vmxnet3.h:555
vmxnet3_main_t::devices
vmxnet3_device_t * devices
Definition: vmxnet3.h:593
vl_api_vmxnet3_create_t::rxq_num
u16 rxq_num
Definition: vmxnet3.api:46
vl_api_vmxnet3_create_t::enable_elog
i32 enable_elog
Definition: vmxnet3.api:44
vmxnet3.h
vmxnet3_rx_comp_ring::next
u16 next
Definition: vmxnet3.h:510
vmxnet3_create_if_args_t::rxq_num
u16 rxq_num
Definition: vmxnet3.h:605
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:453
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
swif
u32 swif
Definition: interface_output.c:1078
vmxnet3_device_class
vnet_device_class_t vmxnet3_device_class
vmxnet3_tx_ring::consume
u16 consume
Definition: vmxnet3.h:532