FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
format.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 u8 *
26 format_vmxnet3_device_name (u8 * s, va_list * args)
27 {
29  u32 i = va_arg (*args, u32);
32  vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, vd->pci_dev_handle);
33 
34  s = format (s, "vmxnet3-%x/%x/%x/%x",
35  addr->domain, addr->bus, addr->slot, addr->function);
36  return s;
37 }
38 
39 u8 *
40 format_vmxnet3_device_flags (u8 * s, va_list * args)
41 {
42  vmxnet3_device_t *vd = va_arg (*args, vmxnet3_device_t *);
43  u8 *t = 0;
44 
45 #define _(a, b, c) if (vd->flags & (1 << a)) \
46  t = format (t, "%s%s", t ? " ":"", c);
48 #undef _
49  s = format (s, "%v", t);
50  vec_free (t);
51  return s;
52 }
53 
54 u8 *
55 format_vmxnet3_device (u8 * s, va_list * args)
56 {
57  u32 i = va_arg (*args, u32);
60  u32 indent = format_get_indent (s);
61  vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, 0);
62  vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, 0);
63  vmxnet3_tx_queue *tx = VMXNET3_TX_START (vd);
64  vmxnet3_rx_queue *rx = VMXNET3_RX_START (vd);
65  u16 qid;
66 
67  s = format (s, "flags: %U", format_vmxnet3_device_flags, vd);
68  s = format (s, "\n%Urx queues %u, rx desc %u, tx queues %u, tx desc %u",
69  format_white_space, indent,
70  vd->num_rx_queues, rxq->size, vd->num_tx_queues, txq->size);
71  if (vd->error)
72  s = format (s, "\n%Uerror %U", format_white_space, indent,
74 
75  vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
76 
77  vec_foreach_index (qid, vd->txqs)
78  {
79  vmxnet3_tx_stats *txs = vec_elt_at_index (vd->tx_stats, qid);
80 
81  s = format (s, "\n%UTX Queue %u:", format_white_space, indent, qid);
82  s = format (s, "\n%U TSO packets %llu",
83  format_white_space, indent,
84  tx->stats.tso_pkts - txs->tso_pkts);
85  s = format (s, "\n%U TSO bytes %llu",
86  format_white_space, indent,
87  tx->stats.tso_bytes - txs->tso_bytes);
88  s = format (s, "\n%U ucast packets %llu",
89  format_white_space, indent,
90  tx->stats.ucast_pkts - txs->ucast_pkts);
91  s = format (s, "\n%U ucast bytes %llu",
92  format_white_space, indent,
93  tx->stats.ucast_bytes - txs->ucast_bytes);
94  s = format (s, "\n%U mcast packets %llu",
95  format_white_space, indent,
96  tx->stats.mcast_pkts - txs->mcast_pkts);
97  s = format (s, "\n%U mcast bytes %llu",
98  format_white_space, indent,
99  tx->stats.mcast_bytes - txs->mcast_bytes);
100  s = format (s, "\n%U bcast packets %llu",
101  format_white_space, indent,
102  tx->stats.bcast_pkts - txs->bcast_pkts);
103  s = format (s, "\n%U bcast bytes %llu",
104  format_white_space, indent,
105  tx->stats.bcast_bytes - txs->bcast_bytes);
106  s = format (s, "\n%U Errors packets %llu",
107  format_white_space, indent,
108  tx->stats.error_pkts - txs->error_pkts);
109  s = format (s, "\n%U Discard packets %llu",
110  format_white_space, indent,
111  tx->stats.discard_pkts - txs->discard_pkts);
112  tx++;
113  }
114 
115  vec_foreach_index (qid, vd->rxqs)
116  {
117  vmxnet3_rx_stats *rxs = vec_elt_at_index (vd->rx_stats, qid);
118 
119  s = format (s, "\n%URX Queue %u:", format_white_space, indent, qid);
120  s = format (s, "\n%U LRO packets %llu",
121  format_white_space, indent,
122  rx->stats.lro_pkts - rxs->lro_pkts);
123  s = format (s, "\n%U LRO bytes %llu",
124  format_white_space, indent,
125  rx->stats.lro_bytes - rxs->lro_bytes);
126  s = format (s, "\n%U ucast packets %llu",
127  format_white_space, indent,
128  rx->stats.ucast_pkts - rxs->ucast_pkts);
129  s = format (s, "\n%U ucast bytes %llu",
130  format_white_space, indent,
131  rx->stats.ucast_bytes - rxs->ucast_bytes);
132  s = format (s, "\n%U mcast packets %llu",
133  format_white_space, indent,
134  rx->stats.mcast_pkts - rxs->mcast_pkts);
135  s = format (s, "\n%U mcast bytes %llu",
136  format_white_space, indent,
137  rx->stats.mcast_bytes - rxs->mcast_bytes);
138  s = format (s, "\n%U bcast packets %llu",
139  format_white_space, indent,
140  rx->stats.bcast_pkts - rxs->bcast_pkts);
141  s = format (s, "\n%U bcast bytes %llu",
142  format_white_space, indent,
143  rx->stats.bcast_bytes - rxs->bcast_bytes);
144  s = format (s, "\n%U No Bufs %llu",
145  format_white_space, indent,
146  rx->stats.nobuf_pkts - rxs->nobuf_pkts);
147  s = format (s, "\n%U Error packets %llu",
148  format_white_space, indent,
149  rx->stats.error_pkts - rxs->error_pkts);
150  rx++;
151  }
152  return s;
153 }
154 
155 u8 *
156 format_vmxnet3_input_trace (u8 * s, va_list * args)
157 {
158  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
159  vlib_node_t *node = va_arg (*args, vlib_node_t *);
160  vmxnet3_input_trace_t *t = va_arg (*args, vmxnet3_input_trace_t *);
161  vnet_main_t *vnm = vnet_get_main ();
163 
164  s = format (s, "vmxnet3: %v (%d) next-node %U",
166  node->index, t->next_index);
167  s = format (s, "\n buffer %U", format_vnet_buffer, &t->buffer);
168 
169  return s;
170 }
171 
172 /*
173  * fd.io coding-style-patch-verification: ON
174  *
175  * Local Variables:
176  * eval: (c-set-style "gnu")
177  * End:
178  */
vmxnet3_main
vmxnet3_main_t vmxnet3_main
Definition: vmxnet3.c:28
vlib.h
vmxnet3_device_t::num_rx_queues
u16 num_rx_queues
Definition: vmxnet3.h:574
vmxnet3_device_t::pci_dev_handle
vlib_pci_dev_handle_t pci_dev_handle
Definition: vmxnet3.h:565
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vmxnet3_device_t::tx_stats
vmxnet3_tx_stats * tx_stats
Definition: vmxnet3.h:587
vmxnet3_reg_write
static_always_inline void vmxnet3_reg_write(vmxnet3_device_t *vd, u8 bar, u32 addr, u32 val)
Definition: vmxnet3.h:653
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vmxnet3_main_t
Definition: vmxnet3.h:591
format_vmxnet3_device_name
u8 * format_vmxnet3_device_name(u8 *s, va_list *args)
Definition: format.c:26
VMXNET3_RX_START
#define VMXNET3_RX_START(vd)
Definition: vmxnet3.h:93
vmxnet3_device_t::error
clib_error_t * error
Definition: vmxnet3.h:580
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
ethernet.h
vmxnet3_rxq_t::size
u16 size
Definition: vmxnet3.h:516
format_clib_error
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
vmxnet3_input_trace_t::buffer
vlib_buffer_t buffer
Definition: vmxnet3.h:620
format_vmxnet3_input_trace
u8 * format_vmxnet3_input_trace(u8 *s, va_list *args)
Definition: format.c:156
VMXNET3_REG_CMD
#define VMXNET3_REG_CMD
Definition: vmxnet3.h:108
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_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
vmxnet3_input_trace_t::next_index
u32 next_index
Definition: vmxnet3.h:618
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
format_vlib_next_node_name
format_function_t format_vlib_next_node_name
Definition: node_funcs.h:1236
vmxnet3_input_trace_t
Definition: vmxnet3.h:616
format
__clib_export u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:428
foreach_vmxnet3_device_flags
@ foreach_vmxnet3_device_flags
Definition: vmxnet3.h:199
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
vmxnet3_device_t::rxqs
vmxnet3_rxq_t * rxqs
Definition: vmxnet3.h:570
u32
unsigned int u32
Definition: types.h:88
vmxnet3_txq_t
Definition: vmxnet3.h:542
pci.h
vmxnet3_device_t::rx_stats
vmxnet3_rx_stats * rx_stats
Definition: vmxnet3.h:588
vmxnet3_device_t::txqs
vmxnet3_txq_t * txqs
Definition: vmxnet3.h:571
format_vmxnet3_device_flags
u8 * format_vmxnet3_device_flags(u8 *s, va_list *args)
Definition: format.c:40
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
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
unix.h
vlib_pci_get_addr
vlib_pci_addr_t * vlib_pci_get_addr(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:163
format_vmxnet3_device
u8 * format_vmxnet3_device(u8 *s, va_list *args)
Definition: format.c:55
vmxnet3_input_trace_t::hw_if_index
u32 hw_if_index
Definition: vmxnet3.h:619
vmxnet3_txq_t::size
u16 size
Definition: vmxnet3.h:545
vmxnet3_device_t
Definition: vmxnet3.h:555
vmxnet3_device_t::num_tx_queues
u16 num_tx_queues
Definition: vmxnet3.h:573
vmxnet3_main_t::devices
vmxnet3_device_t * devices
Definition: vmxnet3.h:593
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
vmxnet3.h
VMXNET3_TX_START
#define VMXNET3_TX_START(vd)
Definition: vmxnet3.h:92
format_vnet_buffer
format_function_t format_vnet_buffer
Definition: buffer.h:515