Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright (c) 2023 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #ifndef _VNET_DEV_ARGS_H_ |
| 6 | #define _VNET_DEV_ARGS_H_ |
| 7 | |
| 8 | #include <vppinfra/clib.h> |
| 9 | #include <vnet/dev/errors.h> |
| 10 | |
| 11 | #define foreach_vnet_dev_arg_type \ |
| 12 | _ (BOOL, "%u", boolean) \ |
| 13 | _ (UINT32, "%u", uint32) \ |
| 14 | _ (STRING, "\'%v\'", string) |
| 15 | |
| 16 | typedef enum |
| 17 | { |
| 18 | VNET_DEV_ARG_END, |
| 19 | #define _(n, f, v) VNET_DEV_ARG_TYPE_##n, |
| 20 | foreach_vnet_dev_arg_type |
| 21 | #undef _ |
| 22 | } __clib_packed vnet_dev_arg_type_t; |
| 23 | |
| 24 | typedef union |
| 25 | { |
| 26 | u8 boolean; |
Monendra Singh Kushwaha | 03b7ac9 | 2024-02-15 23:07:39 +0530 | [diff] [blame] | 27 | u32 uint32; |
Damjan Marion | 69768d9 | 2023-11-13 17:33:32 +0000 | [diff] [blame] | 28 | u8 *string; |
| 29 | } vnet_dev_arg_value_t; |
| 30 | |
| 31 | typedef struct |
| 32 | { |
| 33 | char *name; |
| 34 | char *desc; |
| 35 | vnet_dev_arg_type_t type; |
| 36 | u8 val_set; |
| 37 | u32 min; |
| 38 | u32 max; |
| 39 | u64 id; |
| 40 | vnet_dev_arg_value_t val; |
| 41 | vnet_dev_arg_value_t default_val; |
| 42 | } vnet_dev_arg_t; |
| 43 | |
| 44 | #define VNET_DEV_ARG_BOOL(ud, n, d, ...) \ |
| 45 | { \ |
| 46 | .type = VNET_DEV_ARG_TYPE_BOOL, .id = ud, .name = n, .desc = d, \ |
| 47 | __VA_ARGS__ \ |
| 48 | } |
| 49 | #define VNET_DEV_ARG_UINT32(ud, n, d, ...) \ |
| 50 | { \ |
| 51 | .type = VNET_DEV_ARG_TYPE_UINT32, .id = ud, .name = n, .desc = d, \ |
| 52 | __VA_ARGS__ \ |
| 53 | } |
| 54 | #define VNET_DEV_ARG_STRING(ud, n, d, ...) \ |
| 55 | { \ |
| 56 | .type = VNET_DEV_ARG_TYPE_STRING, .id = ud, .name = n, .desc = d, \ |
| 57 | __VA_ARGS__ \ |
| 58 | } |
| 59 | #define VNET_DEV_ARG_END() \ |
| 60 | { \ |
| 61 | .type = VNET_DEV_ARG_END \ |
| 62 | } |
| 63 | |
| 64 | #define VNET_DEV_ARGS(...) \ |
| 65 | (vnet_dev_arg_t[]) { __VA_ARGS__, VNET_DEV_ARG_END () } |
| 66 | |
| 67 | #define foreach_vnet_dev_args(a, d) \ |
| 68 | for (typeof ((d)->args[0]) *(a) = (d)->args; (a) < vec_end ((d)->args); \ |
| 69 | (a)++) |
| 70 | #define foreach_vnet_dev_port_args(a, p) \ |
| 71 | for (typeof ((p)->args[0]) *(a) = (p)->args; (a) < vec_end ((p)->args); \ |
| 72 | (a)++) |
| 73 | |
| 74 | #endif /* _VNET_DEV_ARGS_H_ */ |