idpf: add native idpf driver plugin
[vpp.git] / src / plugins / idpf / format.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2023 Intel 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 <idpf/idpf.h>
19
20 u8 *
21 format_idpf_device_name (u8 *s, va_list *args)
22 {
23   vlib_main_t *vm = vlib_get_main ();
24   u32 i = va_arg (*args, u32);
25   idpf_device_t *id = idpf_get_device (i);
26   vlib_pci_addr_t *addr = vlib_pci_get_addr (vm, id->pci_dev_handle);
27
28   if (id->name)
29     return format (s, "%s", id->name);
30
31   s = format (s, "idpf-%x/%x/%x/%x", addr->domain, addr->bus, addr->slot,
32               addr->function);
33   return s;
34 }
35
36 u8 *
37 format_idpf_device_flags (u8 *s, va_list *args)
38 {
39   idpf_device_t *id = va_arg (*args, idpf_device_t *);
40   u8 *t = 0;
41
42 #define _(a, b, c)                                                            \
43   if (id->flags & (1 << a))                                                   \
44     t = format (t, "%s%s", t ? " " : "", c);
45   foreach_idpf_device_flags
46 #undef _
47     s = format (s, "%v", t);
48   vec_free (t);
49   return s;
50 }
51
52 u8 *
53 format_idpf_checksum_cap_flags (u8 *s, va_list *args)
54 {
55   u32 flags = va_arg (*args, u32);
56   int not_first = 0;
57
58   char *strs[32] = {
59 #define _(a, b, c) [a] = c,
60     foreach_idpf_checksum_cap_flag
61 #undef _
62   };
63
64   for (int i = 0; i < 32; i++)
65     {
66       if ((flags & (1 << i)) == 0)
67         continue;
68       if (not_first)
69         s = format (s, " ");
70       if (strs[i])
71         s = format (s, "%s", strs[i]);
72       else
73         s = format (s, "unknown(%u)", i);
74       not_first = 1;
75     }
76   return s;
77 }