FD.io VPP  v21.06-1-gbb7418cf9
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 <avf/avf.h>
24 
25 u8 *
26 format_avf_device_name (u8 * s, va_list * args)
27 {
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);
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  int not_first = 0;
61 
62  char *strs[32] = {
63 #define _(a, b, c) [a] = c,
65 #undef _
66  };
67 
68  for (int i = 0; i < 32; i++)
69  {
70  if ((flags & (1 << i)) == 0)
71  continue;
72  if (not_first)
73  s = format (s, " ");
74  if (strs[i])
75  s = format (s, "%s", strs[i]);
76  else
77  s = format (s, "unknown(%u)", i);
78  not_first = 1;
79  }
80  return s;
81 }
82 
83 static u8 *
84 format_virtchnl_link_speed (u8 * s, va_list * args)
85 {
86  virtchnl_link_speed_t speed = va_arg (*args, virtchnl_link_speed_t);
87 
88  if (speed == 0)
89  return format (s, "unknown");
90 #define _(a, b, c) \
91  else if (speed == VIRTCHNL_LINK_SPEED_##b) \
92  return format (s, c);
94 #undef _
95  return s;
96 }
97 
98 u8 *
99 format_avf_device (u8 * s, va_list * args)
100 {
101  u32 i = va_arg (*args, u32);
102  avf_device_t *ad = avf_get_device (i);
103  u32 indent = format_get_indent (s);
104  u8 *a = 0;
105  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, 0);
106  avf_txq_t *txq = vec_elt_at_index (ad->txqs, 0);
107 
108  s = format (s, "rx: queues %u, desc %u (min %u max %u)", ad->n_rx_queues,
110  s = format (s, "\n%Utx: queues %u, desc %u (min %u max %u)",
111  format_white_space, indent, ad->n_tx_queues, txq->size,
113  s = format (s, "\n%Uflags: %U", format_white_space, indent,
115  s = format (s, "\n%Ucapability flags: %U", format_white_space, indent,
117 
118  s = format (s, "\n%Unum-queue-pairs %d max-vectors %u max-mtu %u "
119  "rss-key-size %u rss-lut-size %u", format_white_space, indent,
120  ad->num_queue_pairs, ad->max_vectors, ad->max_mtu,
121  ad->rss_key_size, ad->rss_lut_size);
122  s = format (s, "\n%Uspeed %U", format_white_space, indent,
124  if (ad->error)
125  s = format (s, "\n%Uerror %U", format_white_space, indent,
126  format_clib_error, ad->error);
127 
128 #define _(c) if (ad->eth_stats.c - ad->last_cleared_eth_stats.c) \
129  a = format (a, "\n%U%-20U %u", format_white_space, indent + 2, \
130  format_c_identifier, #c, \
131  ad->eth_stats.c - ad->last_cleared_eth_stats.c);
133 #undef _
134  if (a)
135  s = format (s, "\n%Ustats:%v", format_white_space, indent, a);
136 
137  vec_free (a);
138  return s;
139 }
140 
141 u8 *
142 format_avf_input_trace (u8 * s, va_list * args)
143 {
144  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
145  vlib_node_t *node = va_arg (*args, vlib_node_t *);
146  avf_input_trace_t *t = va_arg (*args, avf_input_trace_t *);
147  vnet_main_t *vnm = vnet_get_main ();
149  u32 indent = format_get_indent (s);
150  int i = 0;
151 
152  s = format (s, "avf: %v (%d) qid %u next-node %U flow-id %u", hi->name,
154  node->index, t->next_index, t->flow_id);
155 
156  do
157  {
158  s = format (s, "\n%Udesc %u: status 0x%x error 0x%x ptype 0x%x len %u",
159  format_white_space, indent + 2, i,
160  t->qw1s[i] & pow2_mask (19),
161  (t->qw1s[i] >> AVF_RXD_ERROR_SHIFT) & pow2_mask (8),
162  (t->qw1s[i] >> AVF_RXD_PTYPE_SHIFT) & pow2_mask (8),
163  (t->qw1s[i] >> AVF_RXD_LEN_SHIFT));
164  }
165  while ((t->qw1s[i++] & AVF_RXD_STATUS_EOP) == 0 &&
167 
168  return s;
169 }
170 
171 u8 *
172 format_avf_vlan_support (u8 *s, va_list *args)
173 {
174  virtchnl_vlan_support_t v = va_arg (*args, u32);
175  int not_first = 0;
176 
177  char *strs[32] = {
178 #define _(a, b, c) [a] = c,
180 #undef _
181  };
182 
183  if (v == VIRTCHNL_VLAN_UNSUPPORTED)
184  return format (s, "unsupported");
185 
186  for (int i = 0; i < 32; i++)
187  {
188  if ((v & (1 << i)) == 0)
189  continue;
190  if (not_first)
191  s = format (s, " ");
192  if (strs[i])
193  s = format (s, "%s", strs[i]);
194  else
195  s = format (s, "unknown(%u)", i);
196  not_first = 1;
197  }
198  return s;
199 }
200 
201 u8 *
203 {
205  va_arg (*args, virtchnl_vlan_supported_caps_t *);
206  u32 indent = format_get_indent (s);
207 
208  s = format (s, "outer: %U", format_avf_vlan_support, sc->outer);
209  s = format (s, "\n%Uinner: %U", format_white_space, indent,
211  return s;
212 }
213 
214 u8 *
215 format_avf_vlan_caps (u8 *s, va_list *args)
216 {
217  virtchnl_vlan_caps_t *vc = va_arg (*args, virtchnl_vlan_caps_t *);
218  u32 indent = format_get_indent (s);
219 
220  s = format (s, "filtering:");
221  s = format (s, "\n%Usupport:", format_white_space, indent + 2);
222  s =
223  format (s, "\n%U%U", format_white_space, indent + 4,
225  s = format (s, "\n%Uethertype-init: 0x%x", format_white_space, indent + 4,
227  s = format (s, "\n%Umax-filters: %u", format_white_space, indent + 4,
228  vc->filtering.max_filters);
229  s = format (s, "\n%Uoffloads:", format_white_space, indent);
230  s = format (s, "\n%Ustripping support:", format_white_space, indent + 2);
231  s = format (s, "\n%U%U", format_white_space, indent + 4,
233  s = format (s, "\n%Uinserion support:", format_white_space, indent + 2);
234  s = format (s, "\n%U%U", format_white_space, indent + 4,
236  s = format (s, "\n%Uethertype-init: 0x%x", format_white_space, indent + 4,
238  s = format (s, "\n%Uethertype-match: 0x%x", format_white_space, indent + 4,
240  return s;
241 }
242 
243 u8 *
244 format_avf_eth_stats (u8 *s, va_list *args)
245 {
246  virtchnl_eth_stats_t *es = va_arg (*args, virtchnl_eth_stats_t *);
247  u32 indent = format_get_indent (s);
248  u8 *v = 0;
249 
250 #define _(st) \
251  if (v) \
252  v = format (v, "\n%U", format_white_space, indent); \
253  v = format (v, "%-20s = %lu", #st, es->st);
255 #undef _
256 
257  s = format (s, "%v", v);
258  vec_free (v);
259  return s;
260 }
u8 * format_avf_vlan_support(u8 *s, va_list *args)
Definition: format.c:172
u8 * format_avf_vlan_caps(u8 *s, va_list *args)
Definition: format.c:215
#define AVF_RXD_ERROR_SHIFT
Definition: avf.h:51
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
a
Definition: bitmap.h:544
u8 * format_avf_device_name(u8 *s, va_list *args)
Definition: format.c:26
u8 * format_avf_vlan_supported_caps(u8 *s, va_list *args)
Definition: format.c:202
u8 * format_avf_input_trace(u8 *s, va_list *args)
Definition: format.c:142
clib_error_t * error
Definition: avf.h:267
virtchnl_vlan_supported_caps_t insertion_support
Definition: virtchnl.h:441
u32 index
Definition: node.h:270
#define foreach_virtchnl_eth_stats
Definition: virtchnl.h:379
virtchnl_link_speed_t link_speed
Definition: avf.h:255
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format_avf_vf_cap_flags(u8 *s, va_list *args)
Definition: format.c:57
virtchnl_link_speed_t
Definition: virtchnl.h:227
vhost_vring_addr_t addr
Definition: vhost_user.h:130
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
u32 cap_flags
Definition: avf.h:247
static uword pow2_mask(uword x)
Definition: clib.h:252
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.
u64 qw1s[AVF_RX_MAX_DESC_IN_CHAIN]
Definition: avf.h:475
vnet_main_t * vnet_get_main(void)
u8 * format_avf_device_flags(u8 *s, va_list *args)
Definition: format.c:42
format_function_t format_vlib_next_node_name
Definition: node_funcs.h:1236
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:224
virtchnl_vlan_supported_caps_t stripping_support
Definition: virtchnl.h:440
u16 next_index
Definition: avf.h:472
u32 hw_if_index
Definition: avf.h:473
u8 * format_avf_eth_stats(u8 *s, va_list *args)
Definition: format.c:244
u8 * name
Definition: avf.h:227
__clib_export u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:428
#define AVF_QUEUE_SZ_MAX
Definition: avf.h:35
#define AVF_RXD_LEN_SHIFT
Definition: avf.h:53
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
#define AVF_RXD_STATUS_EOP
Definition: avf.h:49
u16 n_rx_queues
Definition: avf.h:233
u8 * format_avf_device(u8 *s, va_list *args)
Definition: format.c:99
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:395
Definition: avf.h:169
static_always_inline avf_device_t * avf_get_device(u32 dev_instance)
Definition: avf.h:368
vlib_pci_addr_t * vlib_pci_get_addr(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:163
virtchnl_vlan_offload_caps_t offloads
Definition: virtchnl.h:450
Definition: avf.h:183
#define AVF_RXD_PTYPE_SHIFT
Definition: avf.h:52
virtchnl_vlan_supported_caps_t filtering_support
Definition: virtchnl.h:432
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
vl_api_ip4_address_t hi
Definition: arp.api:37
u16 num_queue_pairs
Definition: avf.h:249
u32 rss_lut_size
Definition: avf.h:254
u16 n_tx_queues
Definition: avf.h:232
#define AVF_QUEUE_SZ_MIN
Definition: avf.h:36
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
virtchnl_vlan_filtering_caps_t filtering
Definition: virtchnl.h:449
virtchnl_vlan_support_t
Definition: virtchnl.h:466
u16 size
Definition: avf.h:174
avf_rxq_t * rxqs
Definition: avf.h:230
u16 size
Definition: avf.h:188
#define AVF_RX_MAX_DESC_IN_CHAIN
Definition: avf.h:54
static u8 * format_virtchnl_link_speed(u8 *s, va_list *args)
Definition: format.c:84
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
avf_txq_t * txqs
Definition: avf.h:231
u16 max_vectors
Definition: avf.h:250
u32 rss_key_size
Definition: avf.h:253
u16 max_mtu
Definition: avf.h:252