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_fme_feature(hw, feature) \
20 for ((feature) = (hw)->sub_feature; \
21 (feature) < (hw)->sub_feature + (FME_FEATURE_ID_MAX); (feature)++)
23 #define ifpga_for_each_port_feature(hw, feature) \
24 for ((feature) = (hw)->sub_feature; \
25 (feature) < (hw)->sub_feature + (PORT_FEATURE_ID_MAX); (feature)++)
27 static inline struct feature
*
28 get_fme_feature_by_id(struct ifpga_fme_hw
*fme
, u64 id
)
30 struct feature
*feature
;
32 ifpga_for_each_fme_feature(fme
, feature
) {
33 if (feature
->id
== id
)
40 static inline struct feature
*
41 get_port_feature_by_id(struct ifpga_port_hw
*port
, u64 id
)
43 struct feature
*feature
;
45 ifpga_for_each_port_feature(port
, feature
) {
46 if (feature
->id
== id
)
54 get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw
*fme
, int index
)
56 return fme
->sub_feature
[index
].addr
;
60 get_port_feature_ioaddr_by_index(struct ifpga_port_hw
*port
, int index
)
62 return port
->sub_feature
[index
].addr
;
66 is_fme_feature_present(struct ifpga_fme_hw
*fme
, int index
)
68 return !!get_fme_feature_ioaddr_by_index(fme
, index
);
72 is_port_feature_present(struct ifpga_port_hw
*port
, int index
)
74 return !!get_port_feature_ioaddr_by_index(port
, index
);
77 int fpga_get_afu_uuid(struct ifpga_port_hw
*port
, struct uuid
*uuid
);
79 int __fpga_port_disable(struct ifpga_port_hw
*port
);
80 void __fpga_port_enable(struct ifpga_port_hw
*port
);
82 static inline int fpga_port_disable(struct ifpga_port_hw
*port
)
86 spinlock_lock(&port
->lock
);
87 ret
= __fpga_port_disable(port
);
88 spinlock_unlock(&port
->lock
);
92 static inline int fpga_port_enable(struct ifpga_port_hw
*port
)
94 spinlock_lock(&port
->lock
);
95 __fpga_port_enable(port
);
96 spinlock_unlock(&port
->lock
);
101 static inline int __fpga_port_reset(struct ifpga_port_hw
*port
)
105 ret
= __fpga_port_disable(port
);
109 __fpga_port_enable(port
);
114 static inline int fpga_port_reset(struct ifpga_port_hw
*port
)
118 spinlock_lock(&port
->lock
);
119 ret
= __fpga_port_reset(port
);
120 spinlock_unlock(&port
->lock
);
124 int do_pr(struct ifpga_hw
*hw
, u32 port_id
, void *buffer
, u32 size
,
127 int fme_get_prop(struct ifpga_fme_hw
*fme
, struct feature_prop
*prop
);
128 int fme_set_prop(struct ifpga_fme_hw
*fme
, struct feature_prop
*prop
);
129 int fme_set_irq(struct ifpga_fme_hw
*fme
, u32 feature_id
, void *irq_set
);
131 int fme_hw_init(struct ifpga_fme_hw
*fme
);
132 void fme_hw_uinit(struct ifpga_fme_hw
*fme
);
133 void port_hw_uinit(struct ifpga_port_hw
*port
);
134 int port_hw_init(struct ifpga_port_hw
*port
);
135 int port_clear_error(struct ifpga_port_hw
*port
);
136 void port_err_mask(struct ifpga_port_hw
*port
, bool mask
);
137 int port_err_clear(struct ifpga_port_hw
*port
, u64 err
);
139 extern struct feature_ops fme_hdr_ops
;
140 extern struct feature_ops fme_thermal_mgmt_ops
;
141 extern struct feature_ops fme_power_mgmt_ops
;
142 extern struct feature_ops fme_global_err_ops
;
143 extern struct feature_ops fme_pr_mgmt_ops
;
144 extern struct feature_ops fme_global_iperf_ops
;
145 extern struct feature_ops fme_global_dperf_ops
;
147 int port_get_prop(struct ifpga_port_hw
*port
, struct feature_prop
*prop
);
148 int port_set_prop(struct ifpga_port_hw
*port
, struct feature_prop
*prop
);
150 /* This struct is used when parsing uafu irq_set */
151 struct fpga_uafu_irq_set
{
157 int port_set_irq(struct ifpga_port_hw
*port
, u32 feature_id
, void *irq_set
);
159 extern struct feature_ops port_hdr_ops
;
160 extern struct feature_ops port_error_ops
;
161 extern struct feature_ops port_stp_ops
;
162 extern struct feature_ops port_uint_ops
;
164 /* help functions for feature ops */
165 int fpga_msix_set_block(struct feature
*feature
, unsigned int start
,
166 unsigned int count
, s32
*fds
);
168 #endif /* _IFPGA_FEATURE_DEV_H_ */