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