FD.io VPP  v18.04-17-g3a0d853
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 {
28  u32 i = va_arg (*args, u32);
29  avf_main_t *am = &avf_main;
30  avf_device_t *ad = vec_elt_at_index (am->devices, i);
31  vlib_pci_addr_t *addr = vlib_pci_get_addr (ad->pci_dev_handle);
32 
33  s = format (s, "AVF%x/%x/%x/%x",
34  addr->domain, addr->bus, addr->slot, addr->function);
35  return s;
36 }
37 
38 u8 *
39 format_avf_device_flags (u8 * s, va_list * args)
40 {
41  avf_device_t *ad = va_arg (*args, avf_device_t *);
42  u8 *t = 0;
43 
44 #define _(a, b, c) if (ad->flags & (1 << a)) \
45 t = format (t, "%s%s", t ? " ":"", c);
47 #undef _
48  s = format (s, "%v", t);
49  vec_free (t);
50  return s;
51 }
52 
53 u8 *
54 format_avf_vf_cap_flags (u8 * s, va_list * args)
55 {
56  u32 flags = va_arg (*args, u32);
57  u8 *t = 0;
58 
59 #define _(a, b, c) if (flags & (1 << a)) \
60  t = format (t, "%s%s", t ? " ":"", c);
62 #undef _
63  s = format (s, "%v", t);
64  vec_free (t);
65  return s;
66 }
67 
68 static u8 *
69 format_virtchnl_link_speed (u8 * s, va_list * args)
70 {
71  virtchnl_link_speed_t speed = va_arg (*args, virtchnl_link_speed_t);
72 
73  if (speed == 0)
74  return format (s, "unknown");
75 #define _(a, b, c) \
76  else if (speed == VIRTCHNL_LINK_SPEED_##b) \
77  return format (s, c);
79 #undef _
80  return s;
81 }
82 
83 u8 *
84 format_avf_device (u8 * s, va_list * args)
85 {
86  u32 i = va_arg (*args, u32);
87  avf_main_t *am = &avf_main;
88  avf_device_t *ad = vec_elt_at_index (am->devices, i);
89  u32 indent = format_get_indent (s);
90  u8 *a = 0;
91 
92  s = format (s, "flags: %U", format_avf_device_flags, ad);
93  s = format (s, "\n%Uoffload features: %U", format_white_space, indent,
95 
96  s = format (s, "\n%Unum-queue-pairs %d max-vectors %u max-mtu %u "
97  "rss-key-size %u rss-lut-size %u", format_white_space, indent,
98  ad->num_queue_pairs, ad->max_vectors, ad->max_mtu,
99  ad->rss_key_size, ad->rss_lut_size);
100  s = format (s, "\n%Uspeed %U", format_white_space, indent,
102  if (ad->error)
103  s = format (s, "\n%Uerror %U", format_white_space, indent,
104  format_clib_error, ad->error);
105 
106 #define _(c) if (ad->eth_stats.c) \
107  a = format (a, "\n%U%-20U %u", format_white_space, indent + 2, \
108  format_c_identifier, #c, ad->eth_stats.c);
110 #undef _
111  if (a)
112  s = format (s, "\n%Ustats:%v", format_white_space, indent, a);
113 
114  vec_free (a);
115  return s;
116 }
117 
118 u8 *
119 format_avf_input_trace (u8 * s, va_list * args)
120 {
121  vlib_main_t *vm = va_arg (*args, vlib_main_t *);
122  vlib_node_t *node = va_arg (*args, vlib_node_t *);
123  avf_input_trace_t *t = va_arg (*args, avf_input_trace_t *);
124  vnet_main_t *vnm = vnet_get_main ();
126  u32 indent = format_get_indent (s);
127  avf_rx_vector_entry_t *rxve = &t->rxve;
128 
129  s = format (s, "avf: %v (%d) next-node %U",
131  node->index, t->next_index);
132  s = format (s, "\n%Ustatus 0x%x error 0x%x ptype 0x%x length %u",
133  format_white_space, indent + 2, rxve->status, rxve->error,
134  rxve->ptype, rxve->length);
135 
136  return s;
137 }
138 
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "gnu")
144  * End:
145  */
vmrglw vmrglh hi
u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
a
Definition: bitmap.h:516
u8 * format_avf_device_name(u8 *s, va_list *args)
Definition: format.c:26
u8 * format_avf_input_trace(u8 *s, va_list *args)
Definition: format.c:119
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
clib_error_t * error
Definition: avf.h:118
u32 index
Definition: node.h:237
#define foreach_virtchnl_eth_stats
Definition: virtchnl.h:316
virtchnl_link_speed_t link_speed
Definition: avf.h:112
vlib_pci_addr_t * vlib_pci_get_addr(vlib_pci_dev_handle_t h)
Definition: pci.c:148
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
int i
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 * format_avf_vf_cap_flags(u8 *s, va_list *args)
Definition: format.c:54
virtchnl_link_speed_t
Definition: virtchnl.h:169
u32 next_index
Definition: avf.h:254
avf_device_t * devices
Definition: avf.h:160
avf_rx_vector_entry_t rxve
Definition: avf.h:256
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 * format_avf_device_flags(u8 *s, va_list *args)
Definition: format.c:39
format_function_t format_vlib_next_node_name
Definition: node_funcs.h:1158
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:86
u32 status
Definition: avf.h:124
u32 hw_if_index
Definition: avf.h:255
u8 ptype
Definition: avf.h:127
u8 * format_avf_device(u8 *s, va_list *args)
Definition: format.c:84
vlib_main_t * vm
Definition: buffer.c:294
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
Definition: avf.h:121
u32 feature_bitmap
Definition: avf.h:105
unsigned int u32
Definition: types.h:88
u8 error
Definition: avf.h:128
avf_main_t avf_main
Definition: device.c:36
u16 num_queue_pairs
Definition: avf.h:107
u32 rss_lut_size
Definition: avf.h:111
unsigned char u8
Definition: types.h:56
vhost_vring_addr_t addr
Definition: vhost-user.h:83
u32 flags
Definition: vhost-user.h:77
static u8 * format_virtchnl_link_speed(u8 *s, va_list *args)
Definition: format.c:69
u16 length
Definition: avf.h:125
u16 max_vectors
Definition: avf.h:108
u32 rss_key_size
Definition: avf.h:110
u16 max_mtu
Definition: avf.h:109