FD.io VPP  v20.09-64-g4f7b92f0a
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);
31  vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, i);
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);
59  vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, i);
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  */
#define vec_foreach_index(var, v)
Iterate over vector indices.
u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vlib_pci_dev_handle_t pci_dev_handle
Definition: vmxnet3.h:564
u32 index
Definition: node.h:279
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define VMXNET3_RX_START(vd)
Definition: vmxnet3.h:93
vmxnet3_main_t vmxnet3_main
Definition: vmxnet3.c:28
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format_vmxnet3_device_flags(u8 *s, va_list *args)
Definition: format.c:40
vlib_main_t * vm
Definition: in2out_ed.c:1582
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vmxnet3_tx_stats * tx_stats
Definition: vmxnet3.h:586
vhost_vring_addr_t addr
Definition: vhost_user.h:111
unsigned char u8
Definition: types.h:56
static_always_inline void vmxnet3_reg_write(vmxnet3_device_t *vd, u8 bar, u32 addr, u32 val)
Definition: vmxnet3.h:652
vmxnet3_rxq_t * rxqs
Definition: vmxnet3.h:569
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
format_function_t format_vlib_next_node_name
Definition: node_funcs.h:1223
unsigned int u32
Definition: types.h:88
format_function_t format_vnet_buffer
Definition: buffer.h:498
#define VMXNET3_REG_CMD
Definition: vmxnet3.h:108
unsigned short u16
Definition: types.h:57
vlib_buffer_t buffer
Definition: vmxnet3.h:619
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
vmxnet3_txq_t * txqs
Definition: vmxnet3.h:570
clib_error_t * error
Definition: vmxnet3.h:579
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1582
vlib_pci_addr_t * vlib_pci_get_addr(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:163
vmxnet3_rx_stats * rx_stats
Definition: vmxnet3.h:587
u8 * format_vmxnet3_device_name(u8 *s, va_list *args)
Definition: format.c:26
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vl_api_ip4_address_t hi
Definition: arp.api:37
u8 * format_vmxnet3_input_trace(u8 *s, va_list *args)
Definition: format.c:156
#define VMXNET3_TX_START(vd)
Definition: vmxnet3.h:92
vmxnet3_device_t * devices
Definition: vmxnet3.h:592
u8 * format_vmxnet3_device(u8 *s, va_list *args)
Definition: format.c:55