raw/ifpga/base: add Intel FPGA OPAE share code
[dpdk.git] / drivers / raw / ifpga_rawdev / base / ifpga_feature_dev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _IFPGA_FEATURE_DEV_H_
6 #define _IFPGA_FEATURE_DEV_H_
7
8 #include "ifpga_hw.h"
9
10 static inline struct ifpga_port_hw *
11 get_port(struct ifpga_hw *hw, u32 port_id)
12 {
13         if (!is_valid_port_id(hw, port_id))
14                 return NULL;
15
16         return &hw->port[port_id];
17 }
18
19 #define ifpga_for_each_feature(hw, feature)             \
20         for ((feature) = (hw)->sub_feature;                     \
21            (feature) < (hw)->sub_feature + (FME_FEATURE_ID_MAX); (feature)++)
22
23 static inline struct feature *
24 get_fme_feature_by_id(struct ifpga_fme_hw *fme, u64 id)
25 {
26         struct feature *feature;
27
28         ifpga_for_each_feature(fme, feature) {
29                 if (feature->id == id)
30                         return feature;
31         }
32
33         return NULL;
34 }
35
36 static inline struct feature *
37 get_port_feature_by_id(struct ifpga_port_hw *port, u64 id)
38 {
39         struct feature *feature;
40
41         ifpga_for_each_feature(port, feature) {
42                 if (feature->id == id)
43                         return feature;
44         }
45
46         return NULL;
47 }
48
49 static inline void  *
50 get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw *fme, int index)
51 {
52         return fme->sub_feature[index].addr;
53 }
54
55 static inline void  *
56 get_port_feature_ioaddr_by_index(struct ifpga_port_hw *port, int index)
57 {
58         return port->sub_feature[index].addr;
59 }
60
61 static inline bool
62 is_fme_feature_present(struct ifpga_fme_hw *fme, int index)
63 {
64         return !!get_fme_feature_ioaddr_by_index(fme, index);
65 }
66
67 static inline bool
68 is_port_feature_present(struct ifpga_port_hw *port, int index)
69 {
70         return !!get_port_feature_ioaddr_by_index(port, index);
71 }
72
73 int fpga_get_afu_uuid(struct ifpga_port_hw *port, struct uuid *uuid);
74
75 int __fpga_port_disable(struct ifpga_port_hw *port);
76 void __fpga_port_enable(struct ifpga_port_hw *port);
77
78 static inline int fpga_port_disable(struct ifpga_port_hw *port)
79 {
80         int ret;
81
82         spinlock_lock(&port->lock);
83         ret = __fpga_port_disable(port);
84         spinlock_unlock(&port->lock);
85         return ret;
86 }
87
88 static inline int fpga_port_enable(struct ifpga_port_hw *port)
89 {
90         spinlock_lock(&port->lock);
91         __fpga_port_enable(port);
92         spinlock_unlock(&port->lock);
93
94         return 0;
95 }
96
97 static inline int __fpga_port_reset(struct ifpga_port_hw *port)
98 {
99         int ret;
100
101         ret = __fpga_port_disable(port);
102         if (ret)
103                 return ret;
104
105         __fpga_port_enable(port);
106
107         return 0;
108 }
109
110 static inline int fpga_port_reset(struct ifpga_port_hw *port)
111 {
112         int ret;
113
114         spinlock_lock(&port->lock);
115         ret = __fpga_port_reset(port);
116         spinlock_unlock(&port->lock);
117         return ret;
118 }
119
120 int do_pr(struct ifpga_hw *hw, u32 port_id, void *buffer, u32 size,
121           u64 *status);
122
123 int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
124 int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
125 int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set);
126
127 int fme_hw_init(struct ifpga_fme_hw *fme);
128 void fme_hw_uinit(struct ifpga_fme_hw *fme);
129 void port_hw_uinit(struct ifpga_port_hw *port);
130 int port_hw_init(struct ifpga_port_hw *port);
131 int port_clear_error(struct ifpga_port_hw *port);
132 void port_err_mask(struct ifpga_port_hw *port, bool mask);
133 int port_err_clear(struct ifpga_port_hw *port, u64 err);
134
135 extern struct feature_ops fme_hdr_ops;
136 extern struct feature_ops fme_thermal_mgmt_ops;
137 extern struct feature_ops fme_power_mgmt_ops;
138 extern struct feature_ops fme_global_err_ops;
139 extern struct feature_ops fme_pr_mgmt_ops;
140 extern struct feature_ops fme_global_iperf_ops;
141 extern struct feature_ops fme_global_dperf_ops;
142
143 int port_get_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
144 int port_set_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
145
146 /* This struct is used when parsing uafu irq_set */
147 struct fpga_uafu_irq_set {
148         u32 start;
149         u32 count;
150         s32 *evtfds;
151 };
152
153 int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set);
154
155 extern struct feature_ops port_hdr_ops;
156 extern struct feature_ops port_error_ops;
157 extern struct feature_ops port_stp_ops;
158 extern struct feature_ops port_uint_ops;
159
160 /* help functions for feature ops */
161 int fpga_msix_set_block(struct feature *feature, unsigned int start,
162                         unsigned int count, s32 *fds);
163
164 #endif /* _IFPGA_FEATURE_DEV_H_ */