raw/ifpga: introduce AFU driver framework
[dpdk.git] / drivers / raw / ifpga / afu_pmd_core.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2022 Intel Corporation
3  */
4
5 #ifndef AFU_PMD_CORE_H
6 #define AFU_PMD_CORE_H
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #include <stdint.h>
13 #include <stdio.h>
14 #include <unistd.h>
15
16 #include <rte_spinlock.h>
17 #include <rte_bus_ifpga.h>
18 #include <rte_rawdev.h>
19
20 #include "ifpga_rawdev.h"
21
22 #define AFU_RAWDEV_MAX_DRVS  32
23
24 struct afu_rawdev;
25
26 struct afu_ops {
27         int (*init)(struct afu_rawdev *dev);
28         int (*config)(struct afu_rawdev *dev, void *config,
29                 size_t config_size);
30         int (*start)(struct afu_rawdev *dev);
31         int (*stop)(struct afu_rawdev *dev);
32         int (*test)(struct afu_rawdev *dev);
33         int (*close)(struct afu_rawdev *dev);
34         int (*reset)(struct afu_rawdev *dev);
35         int (*dump)(struct afu_rawdev *dev, FILE *f);
36 };
37
38 struct afu_shared_data {
39         rte_spinlock_t lock;  /* lock for multi-process access */
40 };
41
42 struct afu_rawdev_drv {
43         TAILQ_ENTRY(afu_rawdev_drv) next;
44         struct rte_afu_uuid uuid;
45         struct afu_ops *ops;
46 };
47
48 struct afu_rawdev {
49         struct rte_rawdev *rawdev;  /* point to parent raw device */
50         struct afu_shared_data *sd;  /* shared data for multi-process */
51         struct afu_ops *ops;  /* device operation functions */
52         int port;  /* index of port the AFU attached */
53         void *addr;  /* base address of AFU registers */
54         void *priv;  /* private driver data */
55 };
56
57 static inline struct afu_rawdev *
58 afu_rawdev_get_priv(const struct rte_rawdev *rawdev)
59 {
60         return rawdev ? (struct afu_rawdev *)rawdev->dev_private : NULL;
61 }
62
63 void afu_pmd_register(struct afu_rawdev_drv *driver);
64 void afu_pmd_unregister(struct afu_rawdev_drv *driver);
65
66 #define AFU_PMD_REGISTER(drv)\
67 RTE_INIT(afupmdinitfunc_ ##drv)\
68 {\
69         afu_pmd_register(&drv);\
70 }
71
72 #ifdef __cplusplus
73 }
74 #endif
75
76 #endif /* AFU_PMD_CORE_H */