1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2018 Gaëtan Rivet 3 */ 4 5 #ifndef _RTE_CLASS_H_ 6 #define _RTE_CLASS_H_ 7 8 /** 9 * @file 10 * 11 * DPDK device class interface. 12 * 13 * This file describes the interface of the device class 14 * abstraction layer. 15 * 16 * A device class defines the type of function a device 17 * will be used for e.g.: Ethernet adapter (eth), 18 * cryptographic co-processor (crypto), etc. 19 */ 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #include <rte_compat.h> 26 #include <rte_dev.h> 27 28 /** Double linked list of classes */ 29 RTE_TAILQ_HEAD(rte_class_list, rte_class); 30 31 /** 32 * A structure describing a generic device class. 33 */ 34 struct rte_class { 35 RTE_TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */ 36 const char *name; /**< Name of the class */ 37 rte_dev_iterate_t dev_iterate; /**< Device iterator. */ 38 }; 39 40 /** 41 * Class comparison function. 42 * 43 * @param cls 44 * Class under test. 45 * 46 * @param data 47 * Data to compare against. 48 * 49 * @return 50 * 0 if the class matches the data. 51 * !0 if the class does not match. 52 * <0 if ordering is possible and the class is lower than the data. 53 * >0 if ordering is possible and the class is greater than the data. 54 */ 55 typedef int (*rte_class_cmp_t)(const struct rte_class *cls, const void *data); 56 57 /** 58 * Class iterator to find a particular class. 59 * 60 * This function compares each registered class to find one that matches 61 * the data passed as parameter. 62 * 63 * If the comparison function returns zero this function will stop iterating 64 * over any more classes. To continue a search the class of a previous search 65 * can be passed via the start parameter. 66 * 67 * @param start 68 * Starting point for the iteration. 69 * 70 * @param cmp 71 * Comparison function. 72 * 73 * @param data 74 * Data to pass to comparison function. 75 * 76 * @return 77 * A pointer to a rte_class structure or NULL in case no class matches 78 */ 79 __rte_experimental 80 struct rte_class * 81 rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, 82 const void *data); 83 84 /** 85 * Find the registered class for a given name. 86 */ 87 __rte_experimental 88 struct rte_class * 89 rte_class_find_by_name(const char *name); 90 91 /** 92 * Register a Class handle. 93 * 94 * @param cls 95 * A pointer to a rte_class structure describing the class 96 * to be registered. 97 */ 98 __rte_experimental 99 void rte_class_register(struct rte_class *cls); 100 101 /** 102 * Unregister a Class handle. 103 * 104 * @param cls 105 * A pointer to a rte_class structure describing the class 106 * to be unregistered. 107 */ 108 __rte_experimental 109 void rte_class_unregister(struct rte_class *cls); 110 111 /** 112 * Helper for Class registration. 113 * The constructor has lower priority than Bus constructors. 114 * The constructor has higher priority than PMD constructors. 115 */ 116 #define RTE_REGISTER_CLASS(nm, cls) \ 117 RTE_INIT_PRIO(classinitfn_ ##nm, CLASS) \ 118 {\ 119 (cls).name = RTE_STR(nm); \ 120 rte_class_register(&cls); \ 121 } 122 123 #define RTE_UNREGISTER_CLASS(nm, cls) \ 124 RTE_FINI_PRIO(classfinifn_ ##nm, CLASS) \ 125 { \ 126 rte_class_unregister(&cls); \ 127 } 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #endif /* _RTE_CLASS_H_ */ 134