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_dev.h> 26 27 /** Double linked list of classes */ 28 RTE_TAILQ_HEAD(rte_class_list, rte_class); 29 30 /** 31 * A structure describing a generic device class. 32 */ 33 struct rte_class { 34 RTE_TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */ 35 const char *name; /**< Name of the class */ 36 rte_dev_iterate_t dev_iterate; /**< Device iterator. */ 37 }; 38 39 /** 40 * Class comparison function. 41 * 42 * @param cls 43 * Class under test. 44 * 45 * @param data 46 * Data to compare against. 47 * 48 * @return 49 * 0 if the class matches the data. 50 * !0 if the class does not match. 51 * <0 if ordering is possible and the class is lower than the data. 52 * >0 if ordering is possible and the class is greater than the data. 53 */ 54 typedef int (*rte_class_cmp_t)(const struct rte_class *cls, const void *data); 55 56 /** 57 * Class iterator to find a particular class. 58 * 59 * This function compares each registered class to find one that matches 60 * the data passed as parameter. 61 * 62 * If the comparison function returns zero this function will stop iterating 63 * over any more classes. To continue a search the class of a previous search 64 * can be passed via the start parameter. 65 * 66 * @param start 67 * Starting point for the iteration. 68 * 69 * @param cmp 70 * Comparison function. 71 * 72 * @param data 73 * Data to pass to comparison function. 74 * 75 * @return 76 * A pointer to a rte_class structure or NULL in case no class matches 77 */ 78 __rte_experimental 79 struct rte_class * 80 rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, 81 const void *data); 82 83 /** 84 * Find the registered class for a given name. 85 */ 86 __rte_experimental 87 struct rte_class * 88 rte_class_find_by_name(const char *name); 89 90 /** 91 * Register a Class handle. 92 * 93 * @param cls 94 * A pointer to a rte_class structure describing the class 95 * to be registered. 96 */ 97 __rte_experimental 98 void rte_class_register(struct rte_class *cls); 99 100 /** 101 * Unregister a Class handle. 102 * 103 * @param cls 104 * A pointer to a rte_class structure describing the class 105 * to be unregistered. 106 */ 107 __rte_experimental 108 void rte_class_unregister(struct rte_class *cls); 109 110 /** 111 * Helper for Class registration. 112 * The constructor has lower priority than Bus constructors. 113 * The constructor has higher priority than PMD constructors. 114 */ 115 #define RTE_REGISTER_CLASS(nm, cls) \ 116 RTE_INIT_PRIO(classinitfn_ ##nm, CLASS) \ 117 {\ 118 (cls).name = RTE_STR(nm); \ 119 rte_class_register(&cls); \ 120 } 121 122 #define RTE_UNREGISTER_CLASS(nm, cls) \ 123 RTE_FINI_PRIO(classfinifn_ ##nm, CLASS) \ 124 { \ 125 rte_class_unregister(&cls); \ 126 } 127 128 #ifdef __cplusplus 129 } 130 #endif 131 132 #endif /* _RTE_CLASS_H_ */ 133