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 struct feature_driver {
11 u64 id;
12 const char *name;
13 struct ifpga_feature_ops *ops;
14 };
15
16 /**
17 * FEATURE_DRV - macro used to describe a specific feature driver
18 */
19 #define FEATURE_DRV(n, s, p) \
20 .id = (n), .name = (s), .ops = (p)
21
22 static inline struct ifpga_port_hw *
get_port(struct ifpga_hw * hw,u32 port_id)23 get_port(struct ifpga_hw *hw, u32 port_id)
24 {
25 if (!is_valid_port_id(hw, port_id))
26 return NULL;
27
28 return &hw->port[port_id];
29 }
30
31 #define ifpga_for_each_fme_feature(hw, feature) \
32 TAILQ_FOREACH(feature, &hw->feature_list, next)
33
34 #define ifpga_for_each_port_feature(port, feature) \
35 TAILQ_FOREACH(feature, &port->feature_list, next)
36
37 static inline struct ifpga_feature *
get_fme_feature_by_id(struct ifpga_fme_hw * fme,u64 id)38 get_fme_feature_by_id(struct ifpga_fme_hw *fme, u64 id)
39 {
40 struct ifpga_feature *feature;
41
42 ifpga_for_each_fme_feature(fme, feature) {
43 if (feature->id == id)
44 return feature;
45 }
46
47 return NULL;
48 }
49
50 static inline struct ifpga_feature *
get_port_feature_by_id(struct ifpga_port_hw * port,u64 id)51 get_port_feature_by_id(struct ifpga_port_hw *port, u64 id)
52 {
53 struct ifpga_feature *feature;
54
55 ifpga_for_each_port_feature(port, feature) {
56 if (feature->id == id)
57 return feature;
58 }
59
60 return NULL;
61 }
62
63 static inline struct ifpga_feature *
get_feature_by_id(struct ifpga_feature_list * list,u64 id)64 get_feature_by_id(struct ifpga_feature_list *list, u64 id)
65 {
66 struct ifpga_feature *feature;
67
68 TAILQ_FOREACH(feature, list, next)
69 if (feature->id == id)
70 return feature;
71
72 return NULL;
73 }
74
75 static inline void *
get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw * fme,int index)76 get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw *fme, int index)
77 {
78 struct ifpga_feature *feature =
79 get_feature_by_id(&fme->feature_list, index);
80
81 return feature ? feature->addr : NULL;
82 }
83
84 static inline void *
get_port_feature_ioaddr_by_index(struct ifpga_port_hw * port,int index)85 get_port_feature_ioaddr_by_index(struct ifpga_port_hw *port, int index)
86 {
87 struct ifpga_feature *feature =
88 get_feature_by_id(&port->feature_list, index);
89
90 return feature ? feature->addr : NULL;
91 }
92
93 static inline bool
is_fme_feature_present(struct ifpga_fme_hw * fme,int index)94 is_fme_feature_present(struct ifpga_fme_hw *fme, int index)
95 {
96 return !!get_fme_feature_ioaddr_by_index(fme, index);
97 }
98
99 static inline bool
is_port_feature_present(struct ifpga_port_hw * port,int index)100 is_port_feature_present(struct ifpga_port_hw *port, int index)
101 {
102 return !!get_port_feature_ioaddr_by_index(port, index);
103 }
104
105 int fpga_get_afu_uuid(struct ifpga_port_hw *port, struct uuid *uuid);
106 int fpga_get_pr_uuid(struct ifpga_fme_hw *fme, struct uuid *uuid);
107
108 int __fpga_port_disable(struct ifpga_port_hw *port);
109 void __fpga_port_enable(struct ifpga_port_hw *port);
110
fpga_port_disable(struct ifpga_port_hw * port)111 static inline int fpga_port_disable(struct ifpga_port_hw *port)
112 {
113 int ret;
114
115 spinlock_lock(&port->lock);
116 ret = __fpga_port_disable(port);
117 spinlock_unlock(&port->lock);
118 return ret;
119 }
120
fpga_port_enable(struct ifpga_port_hw * port)121 static inline int fpga_port_enable(struct ifpga_port_hw *port)
122 {
123 spinlock_lock(&port->lock);
124 __fpga_port_enable(port);
125 spinlock_unlock(&port->lock);
126
127 return 0;
128 }
129
__fpga_port_reset(struct ifpga_port_hw * port)130 static inline int __fpga_port_reset(struct ifpga_port_hw *port)
131 {
132 int ret;
133
134 ret = __fpga_port_disable(port);
135 if (ret)
136 return ret;
137
138 __fpga_port_enable(port);
139
140 return 0;
141 }
142
fpga_port_reset(struct ifpga_port_hw * port)143 static inline int fpga_port_reset(struct ifpga_port_hw *port)
144 {
145 int ret;
146
147 spinlock_lock(&port->lock);
148 ret = __fpga_port_reset(port);
149 spinlock_unlock(&port->lock);
150 return ret;
151 }
152
153 int do_pr(struct ifpga_hw *hw, u32 port_id, const char *buffer, u32 size,
154 u64 *status);
155
156 int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
157 int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
158 int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set);
159
160 int fme_hw_init(struct ifpga_fme_hw *fme);
161 void fme_hw_uinit(struct ifpga_fme_hw *fme);
162 void port_hw_uinit(struct ifpga_port_hw *port);
163 int port_hw_init(struct ifpga_port_hw *port);
164 int port_clear_error(struct ifpga_port_hw *port);
165 void port_err_mask(struct ifpga_port_hw *port, bool mask);
166 int port_err_clear(struct ifpga_port_hw *port, u64 err);
167
168 extern struct ifpga_feature_ops fme_hdr_ops;
169 extern struct ifpga_feature_ops fme_thermal_mgmt_ops;
170 extern struct ifpga_feature_ops fme_power_mgmt_ops;
171 extern struct ifpga_feature_ops fme_global_err_ops;
172 extern struct ifpga_feature_ops fme_pr_mgmt_ops;
173 extern struct ifpga_feature_ops fme_global_iperf_ops;
174 extern struct ifpga_feature_ops fme_global_dperf_ops;
175 extern struct ifpga_feature_ops fme_hssi_eth_ops;
176 extern struct ifpga_feature_ops fme_emif_ops;
177 extern struct ifpga_feature_ops fme_spi_master_ops;
178 extern struct ifpga_feature_ops fme_i2c_master_ops;
179 extern struct ifpga_feature_ops fme_eth_group_ops;
180 extern struct ifpga_feature_ops fme_nios_spi_master_ops;
181 extern struct ifpga_feature_ops fme_pmci_ops;
182
183 int port_get_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
184 int port_set_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
185
186 /* This struct is used when parsing uafu irq_set */
187 struct fpga_uafu_irq_set {
188 u32 start;
189 u32 count;
190 s32 *evtfds;
191 };
192
193 int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set);
194 const char *get_fme_feature_name(unsigned int id);
195 const char *get_port_feature_name(unsigned int id);
196
197 extern struct ifpga_feature_ops ifpga_rawdev_port_hdr_ops;
198 extern struct ifpga_feature_ops ifpga_rawdev_port_error_ops;
199 extern struct ifpga_feature_ops ifpga_rawdev_port_stp_ops;
200 extern struct ifpga_feature_ops ifpga_rawdev_port_uint_ops;
201 extern struct ifpga_feature_ops ifpga_rawdev_port_afu_ops;
202
203 /* help functions for feature ops */
204 int fpga_msix_set_block(struct ifpga_feature *feature, unsigned int start,
205 unsigned int count, s32 *fds);
206
207 /* FME network function ops*/
208 int fme_mgr_read_mac_rom(struct ifpga_fme_hw *fme, int offset,
209 void *buf, int size);
210 int fme_mgr_write_mac_rom(struct ifpga_fme_hw *fme, int offset,
211 void *buf, int size);
212 int fme_mgr_get_eth_group_nums(struct ifpga_fme_hw *fme);
213 int fme_mgr_get_eth_group_info(struct ifpga_fme_hw *fme,
214 u8 group_id, struct opae_eth_group_info *info);
215 int fme_mgr_eth_group_read_reg(struct ifpga_fme_hw *fme, u8 group_id,
216 u8 type, u8 index, u16 addr, u32 *data);
217 int fme_mgr_eth_group_write_reg(struct ifpga_fme_hw *fme, u8 group_id,
218 u8 type, u8 index, u16 addr, u32 data);
219 int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
220 struct opae_retimer_info *info);
221 int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
222 struct opae_retimer_status *status);
223 int fme_mgr_get_sensor_value(struct ifpga_fme_hw *fme,
224 struct opae_sensor_info *sensor,
225 unsigned int *value);
226 int fme_mgr_read_flash(struct ifpga_fme_hw *fme, u32 address,
227 u32 size, void *buf);
228 #endif /* _IFPGA_FEATURE_DEV_H_ */
229