FD.io VPP  v21.10.1-2-g0a485f517
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);
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 }
avf_input_trace_t::hw_if_index
u32 hw_if_index
Definition: avf.h:473
vlib.h
format_avf_vlan_support
u8 * format_avf_vlan_support(u8 *s, va_list *args)
Definition: format.c:172
virtchnl_vlan_filtering_caps_t::max_filters
u16 max_filters
Definition: virtchnl.h:434
avf_device_t::pci_dev_handle
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:224
avf_txq_t
Definition: avf.h:183
avf_input_trace_t::next_index
u16 next_index
Definition: avf.h:472
virtchnl_vlan_offload_caps::insertion_support
virtchnl_vlan_supported_caps_t insertion_support
Definition: virtchnl.h:441
pow2_mask
static uword pow2_mask(uword x)
Definition: clib.h:252
virtchnl_vlan_offload_caps::ethertype_init
u32 ethertype_init
Definition: virtchnl.h:442
avf_device_t::txqs
avf_txq_t * txqs
Definition: avf.h:231
avf_device_t::n_rx_queues
u16 n_rx_queues
Definition: avf.h:233
format_avf_eth_stats
u8 * format_avf_eth_stats(u8 *s, va_list *args)
Definition: format.c:244
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
avf_rxq_t
Definition: avf.h:169
avf_device_t::rss_lut_size
u32 rss_lut_size
Definition: avf.h:254
avf_device_t::num_queue_pairs
u16 num_queue_pairs
Definition: avf.h:249
avf_device_t::n_tx_queues
u16 n_tx_queues
Definition: avf.h:232
format_avf_device
u8 * format_avf_device(u8 *s, va_list *args)
Definition: format.c:99
virtchnl_eth_stats_t
Definition: virtchnl.h:393
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
virtchnl_vlan_offload_caps::ethertype_match
u8 ethertype_match
Definition: virtchnl.h:443
foreach_virtchnl_eth_stats
#define foreach_virtchnl_eth_stats
Definition: virtchnl.h:379
avf_device_t::name
u8 * name
Definition: avf.h:227
VIRTCHNL_VLAN_UNSUPPORTED
@ VIRTCHNL_VLAN_UNSUPPORTED
Definition: virtchnl.h:468
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
avf_device_t
Definition: avf.h:215
ethernet.h
avf_device_t::rxqs
avf_rxq_t * rxqs
Definition: avf.h:230
format_avf_vf_cap_flags
u8 * format_avf_vf_cap_flags(u8 *s, va_list *args)
Definition: format.c:57
format_clib_error
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
virtchnl_vlan_supported_caps_t::outer
u32 outer
Definition: virtchnl.h:426
format_avf_vlan_caps
u8 * format_avf_vlan_caps(u8 *s, va_list *args)
Definition: format.c:215
virtchnl_vlan_supported_caps_t
Definition: virtchnl.h:424
avf_device_t::error
clib_error_t * error
Definition: avf.h:267
foreach_virtchnl_vlan_support_bit
@ foreach_virtchnl_vlan_support_bit
Definition: virtchnl.h:470
virtchnl_vlan_filtering_caps_t::filtering_support
virtchnl_vlan_supported_caps_t filtering_support
Definition: virtchnl.h:432
avf_txq_t::size
u16 size
Definition: avf.h:188
avf_device_t::max_vectors
u16 max_vectors
Definition: avf.h:250
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
foreach_avf_vf_cap_flag
@ foreach_avf_vf_cap_flag
Definition: virtchnl.h:166
AVF_RX_MAX_DESC_IN_CHAIN
#define AVF_RX_MAX_DESC_IN_CHAIN
Definition: avf.h:54
avf_device_t::link_speed
virtchnl_link_speed_t link_speed
Definition: avf.h:255
avf_input_trace_t::qw1s
u64 qw1s[AVF_RX_MAX_DESC_IN_CHAIN]
Definition: avf.h:475
AVF_QUEUE_SZ_MIN
#define AVF_QUEUE_SZ_MIN
Definition: avf.h:36
virtchnl_vlan_offload_caps::stripping_support
virtchnl_vlan_supported_caps_t stripping_support
Definition: virtchnl.h:440
format_vlib_next_node_name
format_function_t format_vlib_next_node_name
Definition: node_funcs.h:1236
virtchnl_vlan_caps_t
Definition: virtchnl.h:447
AVF_RXD_LEN_SHIFT
#define AVF_RXD_LEN_SHIFT
Definition: avf.h:53
virtchnl_vlan_caps_t::offloads
virtchnl_vlan_offload_caps_t offloads
Definition: virtchnl.h:450
avf_input_trace_t::flow_id
u32 flow_id
Definition: avf.h:474
avf.h
format
__clib_export u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:428
avf_rxq_t::size
u16 size
Definition: avf.h:174
avf_device_t::rss_key_size
u32 rss_key_size
Definition: avf.h:253
avf_device_t::max_mtu
u16 max_mtu
Definition: avf.h:252
format_avf_device_name
u8 * format_avf_device_name(u8 *s, va_list *args)
Definition: format.c:26
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
foreach_virtchnl_link_speed
@ foreach_virtchnl_link_speed
Definition: virtchnl.h:231
avf_device_t::cap_flags
u32 cap_flags
Definition: avf.h:247
AVF_QUEUE_SZ_MAX
#define AVF_QUEUE_SZ_MAX
Definition: avf.h:35
virtchnl_link_speed_t
virtchnl_link_speed_t
Definition: virtchnl.h:227
virtchnl_vlan_support_t
virtchnl_vlan_support_t
Definition: virtchnl.h:466
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
format_avf_input_trace
u8 * format_avf_input_trace(u8 *s, va_list *args)
Definition: format.c:142
u32
unsigned int u32
Definition: types.h:88
foreach_avf_device_flags
@ foreach_avf_device_flags
Definition: avf.h:123
AVF_RXD_STATUS_EOP
#define AVF_RXD_STATUS_EOP
Definition: avf.h:49
format_avf_vlan_supported_caps
u8 * format_avf_vlan_supported_caps(u8 *s, va_list *args)
Definition: format.c:202
pci.h
format_avf_device_flags
u8 * format_avf_device_flags(u8 *s, va_list *args)
Definition: format.c:42
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
unix.h
virtchnl_vlan_caps_t::filtering
virtchnl_vlan_filtering_caps_t filtering
Definition: virtchnl.h:449
i
int i
Definition: flowhash_template.h:376
avf_input_trace_t::qid
u16 qid
Definition: avf.h:471
vlib_pci_get_addr
vlib_pci_addr_t * vlib_pci_get_addr(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:163
AVF_RXD_PTYPE_SHIFT
#define AVF_RXD_PTYPE_SHIFT
Definition: avf.h:52
avf_input_trace_t
Definition: avf.h:469
AVF_RXD_ERROR_SHIFT
#define AVF_RXD_ERROR_SHIFT
Definition: avf.h:51
format_virtchnl_link_speed
static u8 * format_virtchnl_link_speed(u8 *s, va_list *args)
Definition: format.c:84
virtchnl_vlan_filtering_caps_t::ethertype_init
u32 ethertype_init
Definition: virtchnl.h:433
format_white_space
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
avf_get_device
static_always_inline avf_device_t * avf_get_device(u32 dev_instance)
Definition: avf.h:368
virtchnl_vlan_supported_caps_t::inner
u32 inner
Definition: virtchnl.h:427
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105