877010ea561ef57948b0a2d28379864851c6f7bd
[vpp.git] / src / plugins / marvell / pp2 / 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 <sys/types.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <sys/ioctl.h>
22
23 #include <vlib/vlib.h>
24 #include <vlib/unix/unix.h>
25 #include <vnet/plugin/plugin.h>
26 #include <marvell/pp2/pp2.h>
27
28 static inline u32
29 mrvl_get_u32_bits (void *start, int offset, int first, int last)
30 {
31   u32 value = *(u32 *) (((u8 *) start) + offset);
32   if ((last == 0) && (first == 31))
33     return value;
34   value >>= last;
35   value &= (1 << (first - last + 1)) - 1;
36   return value;
37 }
38
39 u8 *
40 format_mrvl_pp2_interface_name (u8 * s, va_list * args)
41 {
42   mrvl_pp2_main_t *ppm = &mrvl_pp2_main;
43   u32 dev_instance = va_arg (*args, u32);
44   mrvl_pp2_if_t *ppif = pool_elt_at_index (ppm->interfaces, dev_instance);
45   return format (s, "mv-ppio-%d/%d", ppif->ppio->pp2_id, ppif->ppio->port_id);
46 }
47
48 #define foreach_ppio_statistics_entry \
49   _(rx_packets) \
50   _(rx_fullq_dropped) \
51   _(rx_bm_dropped) \
52   _(rx_early_dropped) \
53   _(rx_fifo_dropped) \
54   _(rx_cls_dropped) \
55   _(tx_packets)
56
57 #define foreach_ppio_inq_statistics_entry \
58   _(enq_desc) \
59   _(drop_early) \
60   _(drop_fullq) \
61   _(drop_bm)
62
63 #define foreach_ppio_outq_statistics_entry \
64   _(enq_desc) \
65   _(enq_dec_to_ddr) \
66   _(enq_buf_to_ddr) \
67   _(deq_desc)
68
69 u8 *
70 format_mrvl_pp2_interface (u8 * s, va_list * args)
71 {
72   mrvl_pp2_main_t *ppm = &mrvl_pp2_main;
73   u32 dev_instance = va_arg (*args, u32);
74   u32 indent = format_get_indent (s);
75   mrvl_pp2_if_t *ppif = pool_elt_at_index (ppm->interfaces, dev_instance);
76   struct pp2_ppio_statistics stat;
77   int i;
78   u8 *s2 = 0;
79
80   pp2_ppio_get_statistics (ppif->ppio, &stat, 0);
81
82 #define _(c) if (stat.c) \
83   s2 = format (s2, "\n%U%-25U%16Ld", \
84               format_white_space, indent + 2, \
85               format_c_identifier, #c, stat.c);
86   foreach_ppio_statistics_entry;
87
88   if (vec_len (s2))
89     s = format (s, "Interface statistics:%v", s2);
90   vec_reset_length (s2);
91
92   vec_foreach_index (i, ppif->inqs)
93   {
94     struct pp2_ppio_inq_statistics stat = { 0 };
95     pp2_ppio_inq_get_statistics (ppif->ppio, 0, i, &stat, 0);
96
97     foreach_ppio_inq_statistics_entry;
98
99     if (vec_len (s2))
100       s = format (s, "\n%UInput queue %u statistics:%v",
101                   format_white_space, indent, i, s2);
102     vec_reset_length (s2);
103   }
104   vec_foreach_index (i, ppif->outqs)
105   {
106     struct pp2_ppio_outq_statistics stat = { 0 };
107
108     pp2_ppio_outq_get_statistics (ppif->ppio, i, &stat, 0);
109
110     foreach_ppio_outq_statistics_entry;
111
112     if (vec_len (s2))
113       s = format (s, "\n%UOutput queue %u statistics:%v",
114                   format_white_space, indent, i, s2);
115     vec_reset_length (s2);
116   }
117 #undef _
118   vec_free (s2);
119   return s;
120 }
121
122 #define foreach_pp2_rx_desc_field \
123   _(0x00,  6,  0, l3_offset) \
124   _(0x00, 12,  8, ip_hdlen) \
125   _(0x00, 14, 13, ec) \
126   _(0x00, 15, 15, es) \
127   _(0x00, 19, 16, pool_id) \
128   _(0x00, 21, 21, hwf_sync) \
129   _(0x00, 22, 22, l4_chk_ok) \
130   _(0x00, 23, 23, ip_frg) \
131   _(0x00, 24, 24, ipv4_hdr_err) \
132   _(0x00, 27, 25, l4_info) \
133   _(0x00, 30, 28, l3_info) \
134   _(0x00, 31, 31, buf_header) \
135   _(0x04,  5,  0, lookup_id) \
136   _(0x04,  8,  6, cpu_code) \
137   _(0x04,  9,  9, pppoe) \
138   _(0x04, 11, 10, l3_cast_info) \
139   _(0x04, 13, 12, l2_cast_info) \
140   _(0x04, 15, 14, vlan_info) \
141   _(0x04, 31, 16, byte_count) \
142   _(0x08, 11,  0, gem_port_id) \
143   _(0x08, 13, 12, color) \
144   _(0x08, 14, 14, gop_sop_u) \
145   _(0x08, 15, 15, key_hash_enable) \
146   _(0x08, 31, 16, l4chk) \
147   _(0x0c, 31,  0, timestamp) \
148   _(0x10, 31,  0, buf_phys_ptr_lo) \
149   _(0x14,  7,  0, buf_phys_ptr_hi) \
150   _(0x14, 31,  8, key_hash) \
151   _(0x18, 31,  0, buf_virt_ptr_lo) \
152   _(0x1c,  7,  0, buf_virt_ptr_hi) \
153   _(0x1c, 14,  8, buf_qset_no) \
154   _(0x1c, 15, 15, buf_type) \
155   _(0x1c, 21, 16, mod_dscp) \
156   _(0x1c, 24, 22, mod_pri) \
157   _(0x1c, 25, 25, mdscp) \
158   _(0x1c, 26, 26, mpri) \
159   _(0x1c, 27, 27, mgpid) \
160   _(0x1c, 31, 29, port_num)
161
162 u8 *
163 format_mrvl_pp2_input_trace (u8 * s, va_list * args)
164 {
165   vlib_main_t *vm = va_arg (*args, vlib_main_t *);
166   vlib_node_t *node = va_arg (*args, vlib_node_t *);
167   mrvl_pp2_input_trace_t *t = va_arg (*args, mrvl_pp2_input_trace_t *);
168   vnet_main_t *vnm = vnet_get_main ();
169   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, t->hw_if_index);
170   u32 indent = format_get_indent (s);
171   struct pp2_ppio_desc *d = &t->desc;
172   u32 r32;
173
174   s = format (s, "pp2: %v (%d) next-node %U",
175               hi->name, t->hw_if_index, format_vlib_next_node_name, vm,
176               node->index, t->next_index);
177   s = format (s, "\n%U", format_white_space, indent + 2);
178
179 #define _(a, b, c, n) \
180   r32 = mrvl_get_u32_bits (d, a, b, c);                         \
181   if (r32 > 9)                                                  \
182     s = format (s, "%s %u (0x%x)", #n, r32, r32);               \
183   else                                                          \
184     s = format (s, "%s %u", #n,r32);                            \
185   if (format_get_indent (s) > 72)                               \
186     s = format (s, "\n%U", format_white_space, indent + 2);     \
187   else s = format (s, " ");
188
189   foreach_pp2_rx_desc_field;
190 #undef _
191   return s;
192 }
193
194 /*
195  * fd.io coding-style-patch-verification: ON
196  *
197  * Local Variables:
198  * eval: (c-set-style "gnu")
199  * End:
200  */