1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef _IFPGA_FEATURE_DEV_H_
6 #define _IFPGA_FEATURE_DEV_H_
10 struct feature_driver {
13 struct feature_ops *ops;
17 * FEATURE_DRV - macro used to describe a specific feature driver
19 #define FEATURE_DRV(n, s, p) \
20 .id = (n), .name = (s), .ops = (p)
22 static inline struct ifpga_port_hw *
23 get_port(struct ifpga_hw *hw, u32 port_id)
25 if (!is_valid_port_id(hw, port_id))
28 return &hw->port[port_id];
31 #define ifpga_for_each_fme_feature(hw, feature) \
32 TAILQ_FOREACH(feature, &hw->feature_list, next)
34 #define ifpga_for_each_port_feature(port, feature) \
35 TAILQ_FOREACH(feature, &port->feature_list, next)
37 static inline struct feature *
38 get_fme_feature_by_id(struct ifpga_fme_hw *fme, u64 id)
40 struct feature *feature;
42 ifpga_for_each_fme_feature(fme, feature) {
43 if (feature->id == id)
50 static inline struct feature *
51 get_port_feature_by_id(struct ifpga_port_hw *port, u64 id)
53 struct feature *feature;
55 ifpga_for_each_port_feature(port, feature) {
56 if (feature->id == id)
63 static inline struct feature *
64 get_feature_by_id(struct ifpga_feature_list *list, u64 id)
66 struct feature *feature;
68 TAILQ_FOREACH(feature, list, next)
69 if (feature->id == id)
76 get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw *fme, int index)
78 struct feature *feature = get_feature_by_id(&fme->feature_list, index);
80 return feature ? feature->addr : NULL;
84 get_port_feature_ioaddr_by_index(struct ifpga_port_hw *port, int index)
86 struct feature *feature = get_feature_by_id(&port->feature_list, index);
88 return feature ? feature->addr : NULL;
92 is_fme_feature_present(struct ifpga_fme_hw *fme, int index)
94 return !!get_fme_feature_ioaddr_by_index(fme, index);
98 is_port_feature_present(struct ifpga_port_hw *port, int index)
100 return !!get_port_feature_ioaddr_by_index(port, index);
103 int fpga_get_afu_uuid(struct ifpga_port_hw *port, struct uuid *uuid);
105 int __fpga_port_disable(struct ifpga_port_hw *port);
106 void __fpga_port_enable(struct ifpga_port_hw *port);
108 static inline int fpga_port_disable(struct ifpga_port_hw *port)
112 spinlock_lock(&port->lock);
113 ret = __fpga_port_disable(port);
114 spinlock_unlock(&port->lock);
118 static inline int fpga_port_enable(struct ifpga_port_hw *port)
120 spinlock_lock(&port->lock);
121 __fpga_port_enable(port);
122 spinlock_unlock(&port->lock);
127 static inline int __fpga_port_reset(struct ifpga_port_hw *port)
131 ret = __fpga_port_disable(port);
135 __fpga_port_enable(port);
140 static inline int fpga_port_reset(struct ifpga_port_hw *port)
144 spinlock_lock(&port->lock);
145 ret = __fpga_port_reset(port);
146 spinlock_unlock(&port->lock);
150 int do_pr(struct ifpga_hw *hw, u32 port_id, void *buffer, u32 size,
153 int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
154 int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
155 int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set);
157 int fme_hw_init(struct ifpga_fme_hw *fme);
158 void fme_hw_uinit(struct ifpga_fme_hw *fme);
159 void port_hw_uinit(struct ifpga_port_hw *port);
160 int port_hw_init(struct ifpga_port_hw *port);
161 int port_clear_error(struct ifpga_port_hw *port);
162 void port_err_mask(struct ifpga_port_hw *port, bool mask);
163 int port_err_clear(struct ifpga_port_hw *port, u64 err);
165 extern struct feature_ops fme_hdr_ops;
166 extern struct feature_ops fme_thermal_mgmt_ops;
167 extern struct feature_ops fme_power_mgmt_ops;
168 extern struct feature_ops fme_global_err_ops;
169 extern struct feature_ops fme_pr_mgmt_ops;
170 extern struct feature_ops fme_global_iperf_ops;
171 extern struct feature_ops fme_global_dperf_ops;
172 extern struct feature_ops fme_hssi_eth_ops;
173 extern struct feature_ops fme_emif_ops;
174 extern struct feature_ops fme_spi_master_ops;
175 extern struct feature_ops fme_i2c_master_ops;
176 extern struct feature_ops fme_eth_group_ops;
177 extern struct feature_ops fme_nios_spi_master_ops;
179 int port_get_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
180 int port_set_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
182 /* This struct is used when parsing uafu irq_set */
183 struct fpga_uafu_irq_set {
189 int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set);
190 const char *get_fme_feature_name(unsigned int id);
191 const char *get_port_feature_name(unsigned int id);
193 extern struct feature_ops ifpga_rawdev_port_hdr_ops;
194 extern struct feature_ops ifpga_rawdev_port_error_ops;
195 extern struct feature_ops ifpga_rawdev_port_stp_ops;
196 extern struct feature_ops ifpga_rawdev_port_uint_ops;
197 extern struct feature_ops ifpga_rawdev_port_afu_ops;
199 /* help functions for feature ops */
200 int fpga_msix_set_block(struct feature *feature, unsigned int start,
201 unsigned int count, s32 *fds);
203 /* FME network function ops*/
204 int fme_mgr_read_mac_rom(struct ifpga_fme_hw *fme, int offset,
205 void *buf, int size);
206 int fme_mgr_write_mac_rom(struct ifpga_fme_hw *fme, int offset,
207 void *buf, int size);
208 int fme_mgr_get_eth_group_nums(struct ifpga_fme_hw *fme);
209 int fme_mgr_get_eth_group_info(struct ifpga_fme_hw *fme,
210 u8 group_id, struct opae_eth_group_info *info);
211 int fme_mgr_eth_group_read_reg(struct ifpga_fme_hw *fme, u8 group_id,
212 u8 type, u8 index, u16 addr, u32 *data);
213 int fme_mgr_eth_group_write_reg(struct ifpga_fme_hw *fme, u8 group_id,
214 u8 type, u8 index, u16 addr, u32 data);
215 int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
216 struct opae_retimer_info *info);
217 int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
218 struct opae_retimer_status *status);
219 #endif /* _IFPGA_FEATURE_DEV_H_ */