]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/lib/librte_eal/common/eal_common_class.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / lib / librte_eal / common / eal_common_class.c
CommitLineData
11fdf7f2
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018 Gaƫtan Rivet
3 */
4
5#include <stdio.h>
6#include <string.h>
7#include <sys/queue.h>
8
9#include <rte_class.h>
10#include <rte_debug.h>
11
9f95a23c 12static struct rte_class_list rte_class_list =
11fdf7f2
TL
13 TAILQ_HEAD_INITIALIZER(rte_class_list);
14
15__rte_experimental void
16rte_class_register(struct rte_class *class)
17{
18 RTE_VERIFY(class);
19 RTE_VERIFY(class->name && strlen(class->name));
20
21 TAILQ_INSERT_TAIL(&rte_class_list, class, next);
22 RTE_LOG(DEBUG, EAL, "Registered [%s] device class.\n", class->name);
23}
24
25__rte_experimental void
26rte_class_unregister(struct rte_class *class)
27{
28 TAILQ_REMOVE(&rte_class_list, class, next);
29 RTE_LOG(DEBUG, EAL, "Unregistered [%s] device class.\n", class->name);
30}
31
32__rte_experimental
33struct rte_class *
34rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp,
35 const void *data)
36{
37 struct rte_class *cls;
38
39 if (start != NULL)
40 cls = TAILQ_NEXT(start, next);
41 else
42 cls = TAILQ_FIRST(&rte_class_list);
43 while (cls != NULL) {
44 if (cmp(cls, data) == 0)
45 break;
46 cls = TAILQ_NEXT(cls, next);
47 }
48 return cls;
49}
50
51static int
52cmp_class_name(const struct rte_class *class, const void *_name)
53{
54 const char *name = _name;
55
56 return strcmp(class->name, name);
57}
58
59__rte_experimental
60struct rte_class *
61rte_class_find_by_name(const char *name)
62{
63 return rte_class_find(NULL, cmp_class_name, (const void *)name);
64}