e5da0e2bbf6084556f414716361d241a179dc0d8
[vpp.git] / src / plugins / avf / 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 <avf/avf.h>
24
25 u8 *
26 format_avf_device_name (u8 * s, va_list * args)
27 {
28   vlib_main_t *vm = vlib_get_main ();
29   u32 i = va_arg (*args, u32);
30   avf_device_t *ad = avf_get_device (i);
31   vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, ad->pci_dev_handle);
32
33   if (ad->name)
34     return format (s, "%s", ad->name);
35
36   s = format (s, "avf-%x/%x/%x/%x",
37               addr->domain, addr->bus, addr->slot, addr->function);
38   return s;
39 }
40
41 u8 *
42 format_avf_device_flags (u8 * s, va_list * args)
43 {
44   avf_device_t *ad = va_arg (*args, avf_device_t *);
45   u8 *t = 0;
46
47 #define _(a, b, c) if (ad->flags & (1 << a)) \
48 t = format (t, "%s%s", t ? " ":"", c);
49   foreach_avf_device_flags
50 #undef _
51     s = format (s, "%v", t);
52   vec_free (t);
53   return s;
54 }
55
56 u8 *
57 format_avf_vf_cap_flags (u8 * s, va_list * args)
58 {
59   u32 flags = va_arg (*args, u32);
60   u8 *t = 0;
61
62 #define _(a, b, c) if (flags & (1 << a)) \
63   t = format (t, "%s%s", t ? " ":"", c);
64   foreach_avf_vf_cap_flag;
65 #undef _
66   s = format (s, "%v", t);
67   vec_free (t);
68   return s;
69 }
70
71 static u8 *
72 format_virtchnl_link_speed (u8 * s, va_list * args)
73 {
74   virtchnl_link_speed_t speed = va_arg (*args, virtchnl_link_speed_t);
75
76   if (speed == 0)
77     return format (s, "unknown");
78 #define _(a, b, c) \
79   else if (speed == VIRTCHNL_LINK_SPEED_##b) \
80     return format (s, c);
81   foreach_virtchnl_link_speed;
82 #undef _
83   return s;
84 }
85
86 u8 *
87 format_avf_device (u8 * s, va_list * args)
88 {
89   u32 i = va_arg (*args, u32);
90   avf_device_t *ad = avf_get_device (i);
91   u32 indent = format_get_indent (s);
92   u8 *a = 0;
93
94   s = format (s, "flags: %U", format_avf_device_flags, ad);
95   s = format (s, "\n%Uoffload features: %U", format_white_space, indent,
96               format_avf_vf_cap_flags, ad->feature_bitmap);
97
98   s = format (s, "\n%Unum-queue-pairs %d max-vectors %u max-mtu %u "
99               "rss-key-size %u rss-lut-size %u", format_white_space, indent,
100               ad->num_queue_pairs, ad->max_vectors, ad->max_mtu,
101               ad->rss_key_size, ad->rss_lut_size);
102   s = format (s, "\n%Uspeed %U", format_white_space, indent,
103               format_virtchnl_link_speed, ad->link_speed);
104   if (ad->error)
105     s = format (s, "\n%Uerror %U", format_white_space, indent,
106                 format_clib_error, ad->error);
107
108 #define _(c) if (ad->eth_stats.c - ad->last_cleared_eth_stats.c) \
109   a = format (a, "\n%U%-20U %u", format_white_space, indent + 2, \
110               format_c_identifier, #c,                           \
111               ad->eth_stats.c - ad->last_cleared_eth_stats.c);
112   foreach_virtchnl_eth_stats;
113 #undef _
114   if (a)
115     s = format (s, "\n%Ustats:%v", format_white_space, indent, a);
116
117   vec_free (a);
118   return s;
119 }
120
121 u8 *
122 format_avf_input_trace (u8 * s, va_list * args)
123 {
124   vlib_main_t *vm = va_arg (*args, vlib_main_t *);
125   vlib_node_t *node = va_arg (*args, vlib_node_t *);
126   avf_input_trace_t *t = va_arg (*args, avf_input_trace_t *);
127   vnet_main_t *vnm = vnet_get_main ();
128   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, t->hw_if_index);
129   u32 indent = format_get_indent (s);
130   int i = 0;
131
132   s = format (s, "avf: %v (%d) qid %u next-node %U",
133               hi->name, t->hw_if_index, t->qid, format_vlib_next_node_name,
134               vm, node->index, t->next_index);
135
136   do
137     {
138       s = format (s, "\n%Udesc %u: status 0x%x error 0x%x ptype 0x%x len %u",
139                   format_white_space, indent + 2, i,
140                   t->qw1s[i] & pow2_mask (19),
141                   (t->qw1s[i] >> AVF_RXD_ERROR_SHIFT) & pow2_mask (8),
142                   (t->qw1s[i] >> AVF_RXD_PTYPE_SHIFT) & pow2_mask (8),
143                   (t->qw1s[i] >> AVF_RXD_LEN_SHIFT));
144     }
145   while ((t->qw1s[i++] & AVF_RXD_STATUS_EOP) == 0 &&
146          i < AVF_RX_MAX_DESC_IN_CHAIN);
147
148   return s;
149 }
150
151 /*
152  * fd.io coding-style-patch-verification: ON
153  *
154  * Local Variables:
155  * eval: (c-set-style "gnu")
156  * End:
157  */