vmxnet3 device driver
[vpp.git] / src / plugins / vmxnet3 / format.c
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 {
28   u32 i = va_arg (*args, u32);
29   vmxnet3_main_t *vmxm = &vmxnet3_main;
30   vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, i);
31   vlib_pci_addr_t *addr = vlib_pci_get_addr (vd->pci_dev_handle);
32
33   s = format (s, "vmxnet3-%x/%x/%x/%x",
34               addr->domain, addr->bus, addr->slot, addr->function);
35   return s;
36 }
37
38 u8 *
39 format_vmxnet3_device_flags (u8 * s, va_list * args)
40 {
41   vmxnet3_device_t *vd = va_arg (*args, vmxnet3_device_t *);
42   u8 *t = 0;
43
44 #define _(a, b, c) if (vd->flags & (1 << a)) \
45     t = format (t, "%s%s", t ? " ":"", c);
46   foreach_vmxnet3_device_flags
47 #undef _
48     s = format (s, "%v", t);
49   vec_free (t);
50   return s;
51 }
52
53 u8 *
54 format_vmxnet3_device (u8 * s, va_list * args)
55 {
56   u32 i = va_arg (*args, u32);
57   vmxnet3_main_t *vmxm = &vmxnet3_main;
58   vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, i);
59   u32 indent = format_get_indent (s);
60   vmxnet3_queues *q = &vd->dma->queues;
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
64   s = format (s, "flags: %U", format_vmxnet3_device_flags, vd);
65   s = format (s, "\n%Urx queues %u, rx desc %u, tx queues %u, tx desc %u",
66               format_white_space, indent,
67               vd->num_rx_queues, rxq->size, vd->num_tx_queues, txq->size);
68   if (vd->error)
69     s = format (s, "\n%Uerror %U", format_white_space, indent,
70                 format_clib_error, vd->error);
71
72   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
73
74   s = format (s, "\n%UTX:", format_white_space, indent);
75   s = format (s, "\n%U  TSO packets                         %llu",
76               format_white_space, indent, q->tx.stats.tso_pkts);
77   s = format (s, "\n%U  TSO bytes                           %llu",
78               format_white_space, indent, q->tx.stats.tso_bytes);
79   s = format (s, "\n%U  ucast packets                       %llu",
80               format_white_space, indent, q->tx.stats.ucast_pkts);
81   s = format (s, "\n%U  ucast bytes                         %llu",
82               format_white_space, indent, q->tx.stats.ucast_bytes);
83   s = format (s, "\n%U  mcast packets                       %llu",
84               format_white_space, indent, q->tx.stats.mcast_pkts);
85   s = format (s, "\n%U  mcast bytes                         %llu",
86               format_white_space, indent, q->tx.stats.mcast_bytes);
87   s = format (s, "\n%U  bcast packets                       %llu",
88               format_white_space, indent, q->tx.stats.bcast_pkts);
89   s = format (s, "\n%U  bcast bytes                         %llu",
90               format_white_space, indent, q->tx.stats.bcast_bytes);
91   s = format (s, "\n%U  Errors packets                      %llu",
92               format_white_space, indent, q->tx.stats.error_pkts);
93   s = format (s, "\n%U  Discard packets                     %llu",
94               format_white_space, indent, q->tx.stats.discard_pkts);
95
96   s = format (s, "\n%URX:", format_white_space, indent);
97   s = format (s, "\n%U  LRO packets                         %llu",
98               format_white_space, indent, q->rx.stats.lro_pkts);
99   s = format (s, "\n%U  LRO bytes                           %llu",
100               format_white_space, indent, q->rx.stats.lro_bytes);
101   s = format (s, "\n%U  ucast packets                       %llu",
102               format_white_space, indent, q->rx.stats.ucast_pkts);
103   s = format (s, "\n%U  ucast bytes                         %llu",
104               format_white_space, indent, q->rx.stats.ucast_bytes);
105   s = format (s, "\n%U  mcast packets                       %llu",
106               format_white_space, indent, q->rx.stats.mcast_pkts);
107   s = format (s, "\n%U  mcast bytes                         %llu",
108               format_white_space, indent, q->rx.stats.mcast_bytes);
109   s = format (s, "\n%U  bcast packets                       %llu",
110               format_white_space, indent, q->rx.stats.bcast_pkts);
111   s = format (s, "\n%U  bcast bytes                         %llu",
112               format_white_space, indent, q->rx.stats.bcast_bytes);
113   s = format (s, "\n%U  No Bufs                             %llu",
114               format_white_space, indent, q->rx.stats.nobuf_pkts);
115   s = format (s, "\n%U  Error packets                       %llu",
116               format_white_space, indent, q->rx.stats.error_pkts);
117   return s;
118 }
119
120 u8 *
121 format_vmxnet3_input_trace (u8 * s, va_list * args)
122 {
123   vlib_main_t *vm = va_arg (*args, vlib_main_t *);
124   vlib_node_t *node = va_arg (*args, vlib_node_t *);
125   vmxnet3_input_trace_t *t = va_arg (*args, vmxnet3_input_trace_t *);
126   vnet_main_t *vnm = vnet_get_main ();
127   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, t->hw_if_index);
128
129   s = format (s, "vmxnet3: %v (%d) next-node %U",
130               hi->name, t->hw_if_index, format_vlib_next_node_name, vm,
131               node->index, t->next_index);
132   s = format (s, "\n  buffer %U", format_vlib_buffer, &t->buffer);
133
134   return s;
135 }
136
137 /*
138  * fd.io coding-style-patch-verification: ON
139  *
140  * Local Variables:
141  * eval: (c-set-style "gnu")
142  * End:
143  */