xref: /dpdk/drivers/raw/ifpga/base/ifpga_feature_dev.h (revision b74ee6c808b3051075edfe974b92717a47580e6e)
1473c88f9SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2473c88f9SBruce Richardson  * Copyright(c) 2010-2018 Intel Corporation
3473c88f9SBruce Richardson  */
4473c88f9SBruce Richardson 
5473c88f9SBruce Richardson #ifndef _IFPGA_FEATURE_DEV_H_
6473c88f9SBruce Richardson #define _IFPGA_FEATURE_DEV_H_
7473c88f9SBruce Richardson 
8473c88f9SBruce Richardson #include "ifpga_hw.h"
9473c88f9SBruce Richardson 
10473c88f9SBruce Richardson struct feature_driver {
11473c88f9SBruce Richardson 	u64 id;
12473c88f9SBruce Richardson 	const char *name;
13473c88f9SBruce Richardson 	struct ifpga_feature_ops *ops;
14473c88f9SBruce Richardson };
15473c88f9SBruce Richardson 
16473c88f9SBruce Richardson /**
17473c88f9SBruce Richardson  * FEATURE_DRV - macro used to describe a specific feature driver
18473c88f9SBruce Richardson  */
19473c88f9SBruce Richardson #define FEATURE_DRV(n, s, p) \
20473c88f9SBruce Richardson 	.id = (n), .name = (s), .ops = (p)
21473c88f9SBruce Richardson 
22473c88f9SBruce Richardson static inline struct ifpga_port_hw *
get_port(struct ifpga_hw * hw,u32 port_id)23473c88f9SBruce Richardson get_port(struct ifpga_hw *hw, u32 port_id)
24473c88f9SBruce Richardson {
25473c88f9SBruce Richardson 	if (!is_valid_port_id(hw, port_id))
26473c88f9SBruce Richardson 		return NULL;
27473c88f9SBruce Richardson 
28473c88f9SBruce Richardson 	return &hw->port[port_id];
29473c88f9SBruce Richardson }
30473c88f9SBruce Richardson 
31473c88f9SBruce Richardson #define ifpga_for_each_fme_feature(hw, feature)		\
32473c88f9SBruce Richardson 	TAILQ_FOREACH(feature, &hw->feature_list, next)
33473c88f9SBruce Richardson 
34473c88f9SBruce Richardson #define ifpga_for_each_port_feature(port, feature)		\
35473c88f9SBruce Richardson 	TAILQ_FOREACH(feature, &port->feature_list, next)
36473c88f9SBruce Richardson 
37473c88f9SBruce Richardson static inline struct ifpga_feature *
get_fme_feature_by_id(struct ifpga_fme_hw * fme,u64 id)38473c88f9SBruce Richardson get_fme_feature_by_id(struct ifpga_fme_hw *fme, u64 id)
39473c88f9SBruce Richardson {
40473c88f9SBruce Richardson 	struct ifpga_feature *feature;
41473c88f9SBruce Richardson 
42473c88f9SBruce Richardson 	ifpga_for_each_fme_feature(fme, feature) {
43473c88f9SBruce Richardson 		if (feature->id == id)
44473c88f9SBruce Richardson 			return feature;
45473c88f9SBruce Richardson 	}
46473c88f9SBruce Richardson 
47473c88f9SBruce Richardson 	return NULL;
48473c88f9SBruce Richardson }
49473c88f9SBruce Richardson 
50473c88f9SBruce Richardson static inline struct ifpga_feature *
get_port_feature_by_id(struct ifpga_port_hw * port,u64 id)51473c88f9SBruce Richardson get_port_feature_by_id(struct ifpga_port_hw *port, u64 id)
52473c88f9SBruce Richardson {
53473c88f9SBruce Richardson 	struct ifpga_feature *feature;
54473c88f9SBruce Richardson 
55473c88f9SBruce Richardson 	ifpga_for_each_port_feature(port, feature) {
56473c88f9SBruce Richardson 		if (feature->id == id)
57473c88f9SBruce Richardson 			return feature;
58473c88f9SBruce Richardson 	}
59473c88f9SBruce Richardson 
60473c88f9SBruce Richardson 	return NULL;
61473c88f9SBruce Richardson }
62473c88f9SBruce Richardson 
63473c88f9SBruce Richardson static inline struct ifpga_feature *
get_feature_by_id(struct ifpga_feature_list * list,u64 id)64473c88f9SBruce Richardson get_feature_by_id(struct ifpga_feature_list *list, u64 id)
65473c88f9SBruce Richardson {
66473c88f9SBruce Richardson 	struct ifpga_feature *feature;
67473c88f9SBruce Richardson 
68473c88f9SBruce Richardson 	TAILQ_FOREACH(feature, list, next)
69473c88f9SBruce Richardson 		if (feature->id == id)
70473c88f9SBruce Richardson 			return feature;
71473c88f9SBruce Richardson 
72473c88f9SBruce Richardson 	return NULL;
73473c88f9SBruce Richardson }
74473c88f9SBruce Richardson 
75473c88f9SBruce Richardson static inline void  *
get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw * fme,int index)76473c88f9SBruce Richardson get_fme_feature_ioaddr_by_index(struct ifpga_fme_hw *fme, int index)
77473c88f9SBruce Richardson {
78473c88f9SBruce Richardson 	struct ifpga_feature *feature =
79473c88f9SBruce Richardson 		get_feature_by_id(&fme->feature_list, index);
80473c88f9SBruce Richardson 
81473c88f9SBruce Richardson 	return feature ? feature->addr : NULL;
82473c88f9SBruce Richardson }
83473c88f9SBruce Richardson 
84473c88f9SBruce Richardson static inline void  *
get_port_feature_ioaddr_by_index(struct ifpga_port_hw * port,int index)85473c88f9SBruce Richardson get_port_feature_ioaddr_by_index(struct ifpga_port_hw *port, int index)
86473c88f9SBruce Richardson {
87473c88f9SBruce Richardson 	struct ifpga_feature *feature =
88473c88f9SBruce Richardson 		get_feature_by_id(&port->feature_list, index);
89473c88f9SBruce Richardson 
90473c88f9SBruce Richardson 	return feature ? feature->addr : NULL;
91473c88f9SBruce Richardson }
92473c88f9SBruce Richardson 
93473c88f9SBruce Richardson static inline bool
is_fme_feature_present(struct ifpga_fme_hw * fme,int index)94473c88f9SBruce Richardson is_fme_feature_present(struct ifpga_fme_hw *fme, int index)
95473c88f9SBruce Richardson {
96473c88f9SBruce Richardson 	return !!get_fme_feature_ioaddr_by_index(fme, index);
97473c88f9SBruce Richardson }
98473c88f9SBruce Richardson 
99473c88f9SBruce Richardson static inline bool
is_port_feature_present(struct ifpga_port_hw * port,int index)100473c88f9SBruce Richardson is_port_feature_present(struct ifpga_port_hw *port, int index)
101473c88f9SBruce Richardson {
102473c88f9SBruce Richardson 	return !!get_port_feature_ioaddr_by_index(port, index);
103473c88f9SBruce Richardson }
104473c88f9SBruce Richardson 
105473c88f9SBruce Richardson int fpga_get_afu_uuid(struct ifpga_port_hw *port, struct uuid *uuid);
106cf38bcd7SWei Huang int fpga_get_pr_uuid(struct ifpga_fme_hw *fme, struct uuid *uuid);
107473c88f9SBruce Richardson 
108473c88f9SBruce Richardson int __fpga_port_disable(struct ifpga_port_hw *port);
109473c88f9SBruce Richardson void __fpga_port_enable(struct ifpga_port_hw *port);
110473c88f9SBruce Richardson 
fpga_port_disable(struct ifpga_port_hw * port)111473c88f9SBruce Richardson static inline int fpga_port_disable(struct ifpga_port_hw *port)
112473c88f9SBruce Richardson {
113473c88f9SBruce Richardson 	int ret;
114473c88f9SBruce Richardson 
115473c88f9SBruce Richardson 	spinlock_lock(&port->lock);
116473c88f9SBruce Richardson 	ret = __fpga_port_disable(port);
117473c88f9SBruce Richardson 	spinlock_unlock(&port->lock);
118473c88f9SBruce Richardson 	return ret;
119473c88f9SBruce Richardson }
120473c88f9SBruce Richardson 
fpga_port_enable(struct ifpga_port_hw * port)121473c88f9SBruce Richardson static inline int fpga_port_enable(struct ifpga_port_hw *port)
122473c88f9SBruce Richardson {
123473c88f9SBruce Richardson 	spinlock_lock(&port->lock);
124473c88f9SBruce Richardson 	__fpga_port_enable(port);
125473c88f9SBruce Richardson 	spinlock_unlock(&port->lock);
126473c88f9SBruce Richardson 
127473c88f9SBruce Richardson 	return 0;
128473c88f9SBruce Richardson }
129473c88f9SBruce Richardson 
__fpga_port_reset(struct ifpga_port_hw * port)130473c88f9SBruce Richardson static inline int __fpga_port_reset(struct ifpga_port_hw *port)
131473c88f9SBruce Richardson {
132473c88f9SBruce Richardson 	int ret;
133473c88f9SBruce Richardson 
134473c88f9SBruce Richardson 	ret = __fpga_port_disable(port);
135473c88f9SBruce Richardson 	if (ret)
136473c88f9SBruce Richardson 		return ret;
137473c88f9SBruce Richardson 
138473c88f9SBruce Richardson 	__fpga_port_enable(port);
139473c88f9SBruce Richardson 
140473c88f9SBruce Richardson 	return 0;
141473c88f9SBruce Richardson }
142473c88f9SBruce Richardson 
fpga_port_reset(struct ifpga_port_hw * port)143473c88f9SBruce Richardson static inline int fpga_port_reset(struct ifpga_port_hw *port)
144473c88f9SBruce Richardson {
145473c88f9SBruce Richardson 	int ret;
146473c88f9SBruce Richardson 
147473c88f9SBruce Richardson 	spinlock_lock(&port->lock);
148473c88f9SBruce Richardson 	ret = __fpga_port_reset(port);
149473c88f9SBruce Richardson 	spinlock_unlock(&port->lock);
150473c88f9SBruce Richardson 	return ret;
151473c88f9SBruce Richardson }
152473c88f9SBruce Richardson 
153473c88f9SBruce Richardson int do_pr(struct ifpga_hw *hw, u32 port_id, const char *buffer, u32 size,
154473c88f9SBruce Richardson 	  u64 *status);
155473c88f9SBruce Richardson 
156473c88f9SBruce Richardson int fme_get_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
157473c88f9SBruce Richardson int fme_set_prop(struct ifpga_fme_hw *fme, struct feature_prop *prop);
158473c88f9SBruce Richardson int fme_set_irq(struct ifpga_fme_hw *fme, u32 feature_id, void *irq_set);
159473c88f9SBruce Richardson 
160473c88f9SBruce Richardson int fme_hw_init(struct ifpga_fme_hw *fme);
161473c88f9SBruce Richardson void fme_hw_uinit(struct ifpga_fme_hw *fme);
162473c88f9SBruce Richardson void port_hw_uinit(struct ifpga_port_hw *port);
163473c88f9SBruce Richardson int port_hw_init(struct ifpga_port_hw *port);
164473c88f9SBruce Richardson int port_clear_error(struct ifpga_port_hw *port);
165473c88f9SBruce Richardson void port_err_mask(struct ifpga_port_hw *port, bool mask);
166473c88f9SBruce Richardson int port_err_clear(struct ifpga_port_hw *port, u64 err);
167473c88f9SBruce Richardson 
168473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_hdr_ops;
169473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_thermal_mgmt_ops;
170473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_power_mgmt_ops;
171473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_global_err_ops;
172473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_pr_mgmt_ops;
173473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_global_iperf_ops;
174473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_global_dperf_ops;
175473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_hssi_eth_ops;
176473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_emif_ops;
177473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_spi_master_ops;
178473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_i2c_master_ops;
179473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_eth_group_ops;
180473c88f9SBruce Richardson extern struct ifpga_feature_ops fme_nios_spi_master_ops;
181ca6eb0f7SWei Huang extern struct ifpga_feature_ops fme_pmci_ops;
182473c88f9SBruce Richardson 
183473c88f9SBruce Richardson int port_get_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
184473c88f9SBruce Richardson int port_set_prop(struct ifpga_port_hw *port, struct feature_prop *prop);
185473c88f9SBruce Richardson 
186473c88f9SBruce Richardson /* This struct is used when parsing uafu irq_set */
187473c88f9SBruce Richardson struct fpga_uafu_irq_set {
188473c88f9SBruce Richardson 	u32 start;
189473c88f9SBruce Richardson 	u32 count;
190473c88f9SBruce Richardson 	s32 *evtfds;
191473c88f9SBruce Richardson };
192473c88f9SBruce Richardson 
193473c88f9SBruce Richardson int port_set_irq(struct ifpga_port_hw *port, u32 feature_id, void *irq_set);
194473c88f9SBruce Richardson const char *get_fme_feature_name(unsigned int id);
195473c88f9SBruce Richardson const char *get_port_feature_name(unsigned int id);
196473c88f9SBruce Richardson 
197473c88f9SBruce Richardson extern struct ifpga_feature_ops ifpga_rawdev_port_hdr_ops;
198473c88f9SBruce Richardson extern struct ifpga_feature_ops ifpga_rawdev_port_error_ops;
199473c88f9SBruce Richardson extern struct ifpga_feature_ops ifpga_rawdev_port_stp_ops;
200473c88f9SBruce Richardson extern struct ifpga_feature_ops ifpga_rawdev_port_uint_ops;
201473c88f9SBruce Richardson extern struct ifpga_feature_ops ifpga_rawdev_port_afu_ops;
202473c88f9SBruce Richardson 
203473c88f9SBruce Richardson /* help functions for feature ops */
204473c88f9SBruce Richardson int fpga_msix_set_block(struct ifpga_feature *feature, unsigned int start,
205473c88f9SBruce Richardson 			unsigned int count, s32 *fds);
206473c88f9SBruce Richardson 
207473c88f9SBruce Richardson /* FME network function ops*/
208473c88f9SBruce Richardson int fme_mgr_read_mac_rom(struct ifpga_fme_hw *fme, int offset,
209473c88f9SBruce Richardson 		void *buf, int size);
210473c88f9SBruce Richardson int fme_mgr_write_mac_rom(struct ifpga_fme_hw *fme, int offset,
211473c88f9SBruce Richardson 		void *buf, int size);
212473c88f9SBruce Richardson int fme_mgr_get_eth_group_nums(struct ifpga_fme_hw *fme);
213473c88f9SBruce Richardson int fme_mgr_get_eth_group_info(struct ifpga_fme_hw *fme,
214473c88f9SBruce Richardson 		u8 group_id, struct opae_eth_group_info *info);
215473c88f9SBruce Richardson int fme_mgr_eth_group_read_reg(struct ifpga_fme_hw *fme, u8 group_id,
216473c88f9SBruce Richardson 		u8 type, u8 index, u16 addr, u32 *data);
217473c88f9SBruce Richardson int fme_mgr_eth_group_write_reg(struct ifpga_fme_hw *fme, u8 group_id,
218473c88f9SBruce Richardson 		u8 type, u8 index, u16 addr, u32 data);
219473c88f9SBruce Richardson int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
220473c88f9SBruce Richardson 		struct opae_retimer_info *info);
221473c88f9SBruce Richardson int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
222473c88f9SBruce Richardson 		struct opae_retimer_status *status);
22319118989STianfei Zhang int fme_mgr_get_sensor_value(struct ifpga_fme_hw *fme,
22419118989STianfei Zhang 		struct opae_sensor_info *sensor,
22519118989STianfei Zhang 		unsigned int *value);
226*b74ee6c8SWei Huang int fme_mgr_read_flash(struct ifpga_fme_hw *fme, u32 address,
227*b74ee6c8SWei Huang 		u32 size, void *buf);
228473c88f9SBruce Richardson #endif /* _IFPGA_FEATURE_DEV_H_ */
229