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