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 static inline struct ifpga_port_hw *
11 get_port(struct ifpga_hw *hw, u32 port_id)
13 if (!is_valid_port_id(hw, port_id))
16 return &hw->port[port_id];
19 #define ifpga_for_each_feature(hw, feature) \
20 for ((feature) = (hw)->sub_feature; \
21 (feature) < (hw)->sub_feature + (FME_FEATURE_ID_MAX); (feature)++)
23 static inline struct feature *
24 get_fme_feature_by_id(struct ifpga_fme_hw *fme, u64 id)
26 struct feature *feature;
28 ifpga_for_each_feature(fme, feature) {
29 if (feature->id == id)
36 static inline struct feature *
37 get_port_feature_by_id(struct ifpga_port_hw *port, u64 id)
39 struct feature *feature;
41 ifpga_for_each_feature(port, feature) {
42 if (feature->id == id)
50 get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw *fme, int index)
52 return fme->sub_feature[index].addr;
56 get_port_feature_ioaddr_by_index(struct ifpga_port_hw *port, int index)
58 return port->sub_feature[index].addr;
62 is_fme_feature_present(struct ifpga_fme_hw *fme, int index)
64 return !!get_fme_feature_ioaddr_by_index(fme, index);
68 is_port_feature_present(struct ifpga_port_hw *port, int index)
70 return !!get_port_feature_ioaddr_by_index(port, index);
73 int fpga_get_afu_uuid(struct ifpga_port_hw *port, struct uuid *uuid);
75 int __fpga_port_disable(struct ifpga_port_hw *port);
76 void __fpga_port_enable(struct ifpga_port_hw *port);
78 static inline int fpga_port_disable(struct ifpga_port_hw *port)
82 spinlock_lock(&port->lock);
83 ret = __fpga_port_disable(port);
84 spinlock_unlock(&port->lock);
88 static inline int fpga_port_enable(struct ifpga_port_hw *port)
90 spinlock_lock(&port->lock);
91 __fpga_port_enable(port);
92 spinlock_unlock(&port->lock);
97 static inline int __fpga_port_reset(struct ifpga_port_hw *port)
101 ret = __fpga_port_disable(port);
105 __fpga_port_enable(port);
110 static inline int fpga_port_reset(struct ifpga_port_hw *port)
114 spinlock_lock(&port->lock);
115 ret = __fpga_port_reset(port);
116 spinlock_unlock(&port->lock);
120 int do_pr(struct ifpga_hw *hw, u32 port_id, void *buffer, u32 size,
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);
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);
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;
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);
146 /* This struct is used when parsing uafu irq_set */
147 struct fpga_uafu_irq_set {
153 int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set);
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;
160 /* help functions for feature ops */
161 int fpga_msix_set_block(struct feature *feature, unsigned int start,
162 unsigned int count, s32 *fds);
164 #endif /* _IFPGA_FEATURE_DEV_H_ */