xref: /linux/drivers/fpga/dfl.h (revision 20bed0d6ff62d985fe8222958825504b8aad4e88)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Driver Header File for FPGA Device Feature List (DFL) Support
4  *
5  * Copyright (C) 2017-2018 Intel Corporation, Inc.
6  *
7  * Authors:
8  *   Kang Luwei <luwei.kang@intel.com>
9  *   Zhang Yi <yi.z.zhang@intel.com>
10  *   Wu Hao <hao.wu@intel.com>
11  *   Xiao Guangrong <guangrong.xiao@linux.intel.com>
12  */
13 
14 #ifndef __FPGA_DFL_H
15 #define __FPGA_DFL_H
16 
17 #include <linux/bitfield.h>
18 #include <linux/cdev.h>
19 #include <linux/delay.h>
20 #include <linux/dfl.h>
21 #include <linux/eventfd.h>
22 #include <linux/fs.h>
23 #include <linux/interrupt.h>
24 #include <linux/iopoll.h>
25 #include <linux/io-64-nonatomic-lo-hi.h>
26 #include <linux/platform_device.h>
27 #include <linux/slab.h>
28 #include <linux/uuid.h>
29 #include <linux/fpga/fpga-region.h>
30 
31 /* maximum supported number of ports */
32 #define MAX_DFL_FPGA_PORT_NUM 4
33 /* plus one for fme device */
34 #define MAX_DFL_FEATURE_DEV_NUM    (MAX_DFL_FPGA_PORT_NUM + 1)
35 
36 /* Reserved 0xfe for Header Group Register and 0xff for AFU */
37 #define FEATURE_ID_FIU_HEADER		0xfe
38 #define FEATURE_ID_AFU			0xff
39 
40 #define FME_FEATURE_ID_HEADER		FEATURE_ID_FIU_HEADER
41 #define FME_FEATURE_ID_THERMAL_MGMT	0x1
42 #define FME_FEATURE_ID_POWER_MGMT	0x2
43 #define FME_FEATURE_ID_GLOBAL_IPERF	0x3
44 #define FME_FEATURE_ID_GLOBAL_ERR	0x4
45 #define FME_FEATURE_ID_PR_MGMT		0x5
46 #define FME_FEATURE_ID_HSSI		0x6
47 #define FME_FEATURE_ID_GLOBAL_DPERF	0x7
48 
49 #define PORT_FEATURE_ID_HEADER		FEATURE_ID_FIU_HEADER
50 #define PORT_FEATURE_ID_AFU		FEATURE_ID_AFU
51 #define PORT_FEATURE_ID_ERROR		0x10
52 #define PORT_FEATURE_ID_UMSG		0x11
53 #define PORT_FEATURE_ID_UINT		0x12
54 #define PORT_FEATURE_ID_STP		0x13
55 
56 /*
57  * Device Feature Header Register Set
58  *
59  * For FIUs, they all have DFH + GUID + NEXT_AFU as common header registers.
60  * For AFUs, they have DFH + GUID as common header registers.
61  * For private features, they only have DFH register as common header.
62  */
63 #define DFH			0x0
64 #define GUID_L			0x8
65 #define GUID_H			0x10
66 #define NEXT_AFU		0x18
67 
68 #define DFH_SIZE		0x8
69 
70 /* Device Feature Header Register Bitfield */
71 #define DFH_ID			GENMASK_ULL(11, 0)	/* Feature ID */
72 #define DFH_ID_FIU_FME		0
73 #define DFH_ID_FIU_PORT		1
74 #define DFH_REVISION		GENMASK_ULL(15, 12)	/* Feature revision */
75 #define DFH_NEXT_HDR_OFST	GENMASK_ULL(39, 16)	/* Offset to next DFH */
76 #define DFH_EOL			BIT_ULL(40)		/* End of list */
77 #define DFH_VERSION		GENMASK_ULL(59, 52)	/* DFH version */
78 #define DFH_TYPE		GENMASK_ULL(63, 60)	/* Feature type */
79 #define DFH_TYPE_AFU		1
80 #define DFH_TYPE_PRIVATE	3
81 #define DFH_TYPE_FIU		4
82 
83 /*
84  * DFHv1 Register Offset definitions
85  * In DHFv1, DFH + GUID + CSR_START + CSR_SIZE_GROUP + PARAM_HDR + PARAM_DATA
86  * as common header registers
87  */
88 #define DFHv1_CSR_ADDR		0x18  /* CSR Register start address */
89 #define DFHv1_CSR_SIZE_GRP	0x20  /* Size of Reg Block and Group/tag */
90 #define DFHv1_PARAM_HDR		0x28  /* Optional First Param header */
91 
92 /*
93  * CSR Rel Bit, 1'b0 = relative (offset from feature DFH start),
94  * 1'b1 = absolute (ARM or other non-PCIe use)
95  */
96 #define DFHv1_CSR_ADDR_REL	BIT_ULL(0)
97 
98 /* CSR Header Register Bit Definitions */
99 #define DFHv1_CSR_ADDR_MASK       GENMASK_ULL(63, 1)  /* 63:1 of CSR address */
100 
101 /* CSR SIZE Goup Register Bit Definitions */
102 #define DFHv1_CSR_SIZE_GRP_INSTANCE_ID	GENMASK_ULL(15, 0)	/* Enumeration instantiated IP */
103 #define DFHv1_CSR_SIZE_GRP_GROUPING_ID	GENMASK_ULL(30, 16)	/* Group Features/interfaces */
104 #define DFHv1_CSR_SIZE_GRP_HAS_PARAMS	BIT_ULL(31)		/* Presence of Parameters */
105 #define DFHv1_CSR_SIZE_GRP_SIZE		GENMASK_ULL(63, 32)	/* Size of CSR Block in bytes */
106 
107 /* PARAM Header Register Bit Definitions */
108 #define DFHv1_PARAM_HDR_ID		GENMASK_ULL(15, 0) /* Id of this Param  */
109 #define DFHv1_PARAM_HDR_VER		GENMASK_ULL(31, 16) /* Version Param */
110 #define DFHv1_PARAM_HDR_NEXT_OFFSET	GENMASK_ULL(63, 35) /* Offset of next Param */
111 #define DFHv1_PARAM_HDR_NEXT_EOP	BIT_ULL(32)
112 #define DFHv1_PARAM_DATA		0x08  /* Offset of Param data from Param header */
113 
114 #define DFHv1_PARAM_ID_MSI_X		0x1
115 #define DFHv1_PARAM_MSI_X_NUMV		GENMASK_ULL(63, 32)
116 #define DFHv1_PARAM_MSI_X_STARTV	GENMASK_ULL(31, 0)
117 
118 /* Next AFU Register Bitfield */
119 #define NEXT_AFU_NEXT_DFH_OFST	GENMASK_ULL(23, 0)	/* Offset to next AFU */
120 
121 /* FME Header Register Set */
122 #define FME_HDR_DFH		DFH
123 #define FME_HDR_GUID_L		GUID_L
124 #define FME_HDR_GUID_H		GUID_H
125 #define FME_HDR_NEXT_AFU	NEXT_AFU
126 #define FME_HDR_CAP		0x30
127 #define FME_HDR_PORT_OFST(n)	(0x38 + ((n) * 0x8))
128 #define FME_PORT_OFST_BAR_SKIP	7
129 #define FME_HDR_BITSTREAM_ID	0x60
130 #define FME_HDR_BITSTREAM_MD	0x68
131 
132 /* FME Fab Capability Register Bitfield */
133 #define FME_CAP_FABRIC_VERID	GENMASK_ULL(7, 0)	/* Fabric version ID */
134 #define FME_CAP_SOCKET_ID	BIT_ULL(8)		/* Socket ID */
135 #define FME_CAP_PCIE0_LINK_AVL	BIT_ULL(12)		/* PCIE0 Link */
136 #define FME_CAP_PCIE1_LINK_AVL	BIT_ULL(13)		/* PCIE1 Link */
137 #define FME_CAP_COHR_LINK_AVL	BIT_ULL(14)		/* Coherent Link */
138 #define FME_CAP_IOMMU_AVL	BIT_ULL(16)		/* IOMMU available */
139 #define FME_CAP_NUM_PORTS	GENMASK_ULL(19, 17)	/* Number of ports */
140 #define FME_CAP_ADDR_WIDTH	GENMASK_ULL(29, 24)	/* Address bus width */
141 #define FME_CAP_CACHE_SIZE	GENMASK_ULL(43, 32)	/* cache size in KB */
142 #define FME_CAP_CACHE_ASSOC	GENMASK_ULL(47, 44)	/* Associativity */
143 
144 /* FME Port Offset Register Bitfield */
145 /* Offset to port device feature header */
146 #define FME_PORT_OFST_DFH_OFST	GENMASK_ULL(23, 0)
147 /* PCI Bar ID for this port */
148 #define FME_PORT_OFST_BAR_ID	GENMASK_ULL(34, 32)
149 /* AFU MMIO access permission. 1 - VF, 0 - PF. */
150 #define FME_PORT_OFST_ACC_CTRL	BIT_ULL(55)
151 #define FME_PORT_OFST_ACC_PF	0
152 #define FME_PORT_OFST_ACC_VF	1
153 #define FME_PORT_OFST_IMP	BIT_ULL(60)
154 
155 /* FME Error Capability Register */
156 #define FME_ERROR_CAP		0x70
157 
158 /* FME Error Capability Register Bitfield */
159 #define FME_ERROR_CAP_SUPP_INT	BIT_ULL(0)		/* Interrupt Support */
160 #define FME_ERROR_CAP_INT_VECT	GENMASK_ULL(12, 1)	/* Interrupt vector */
161 
162 /* PORT Header Register Set */
163 #define PORT_HDR_DFH		DFH
164 #define PORT_HDR_GUID_L		GUID_L
165 #define PORT_HDR_GUID_H		GUID_H
166 #define PORT_HDR_NEXT_AFU	NEXT_AFU
167 #define PORT_HDR_CAP		0x30
168 #define PORT_HDR_CTRL		0x38
169 #define PORT_HDR_STS		0x40
170 #define PORT_HDR_USRCLK_CMD0	0x50
171 #define PORT_HDR_USRCLK_CMD1	0x58
172 #define PORT_HDR_USRCLK_STS0	0x60
173 #define PORT_HDR_USRCLK_STS1	0x68
174 
175 /* Port Capability Register Bitfield */
176 #define PORT_CAP_PORT_NUM	GENMASK_ULL(1, 0)	/* ID of this port */
177 #define PORT_CAP_MMIO_SIZE	GENMASK_ULL(23, 8)	/* MMIO size in KB */
178 #define PORT_CAP_SUPP_INT_NUM	GENMASK_ULL(35, 32)	/* Interrupts num */
179 
180 /* Port Control Register Bitfield */
181 #define PORT_CTRL_SFTRST	BIT_ULL(0)		/* Port soft reset */
182 /* Latency tolerance reporting. '1' >= 40us, '0' < 40us.*/
183 #define PORT_CTRL_LATENCY	BIT_ULL(2)
184 #define PORT_CTRL_SFTRST_ACK	BIT_ULL(4)		/* HW ack for reset */
185 
186 /* Port Status Register Bitfield */
187 #define PORT_STS_AP2_EVT	BIT_ULL(13)		/* AP2 event detected */
188 #define PORT_STS_AP1_EVT	BIT_ULL(12)		/* AP1 event detected */
189 #define PORT_STS_PWR_STATE	GENMASK_ULL(11, 8)	/* AFU power states */
190 #define PORT_STS_PWR_STATE_NORM 0
191 #define PORT_STS_PWR_STATE_AP1	1			/* 50% throttling */
192 #define PORT_STS_PWR_STATE_AP2	2			/* 90% throttling */
193 #define PORT_STS_PWR_STATE_AP6	6			/* 100% throttling */
194 
195 /* Port Error Capability Register */
196 #define PORT_ERROR_CAP		0x38
197 
198 /* Port Error Capability Register Bitfield */
199 #define PORT_ERROR_CAP_SUPP_INT	BIT_ULL(0)		/* Interrupt Support */
200 #define PORT_ERROR_CAP_INT_VECT	GENMASK_ULL(12, 1)	/* Interrupt vector */
201 
202 /* Port Uint Capability Register */
203 #define PORT_UINT_CAP		0x8
204 
205 /* Port Uint Capability Register Bitfield */
206 #define PORT_UINT_CAP_INT_NUM	GENMASK_ULL(11, 0)	/* Interrupts num */
207 #define PORT_UINT_CAP_FST_VECT	GENMASK_ULL(23, 12)	/* First Vector */
208 
209 struct dfl_feature_dev_data;
210 
211 /**
212  * struct dfl_fpga_port_ops - port ops
213  *
214  * @name: name of this port ops, to match with port platform device.
215  * @owner: pointer to the module which owns this port ops.
216  * @node: node to link port ops to global list.
217  * @get_id: get port id from hardware.
218  * @enable_set: enable/disable the port.
219  */
220 struct dfl_fpga_port_ops {
221 	const char *name;
222 	struct module *owner;
223 	struct list_head node;
224 	int (*get_id)(struct dfl_feature_dev_data *fdata);
225 	int (*enable_set)(struct dfl_feature_dev_data *fdata, bool enable);
226 };
227 
228 void dfl_fpga_port_ops_add(struct dfl_fpga_port_ops *ops);
229 void dfl_fpga_port_ops_del(struct dfl_fpga_port_ops *ops);
230 struct dfl_fpga_port_ops *dfl_fpga_port_ops_get(struct dfl_feature_dev_data *fdata);
231 void dfl_fpga_port_ops_put(struct dfl_fpga_port_ops *ops);
232 int dfl_fpga_check_port_id(struct dfl_feature_dev_data *fdata, void *pport_id);
233 
234 /**
235  * struct dfl_feature_id - dfl private feature id
236  *
237  * @id: unique dfl private feature id.
238  */
239 struct dfl_feature_id {
240 	u16 id;
241 };
242 
243 /**
244  * struct dfl_feature_driver - dfl private feature driver
245  *
246  * @id_table: id_table for dfl private features supported by this driver.
247  * @ops: ops of this dfl private feature driver.
248  */
249 struct dfl_feature_driver {
250 	const struct dfl_feature_id *id_table;
251 	const struct dfl_feature_ops *ops;
252 };
253 
254 /**
255  * struct dfl_feature_irq_ctx - dfl private feature interrupt context
256  *
257  * @irq: Linux IRQ number of this interrupt.
258  * @trigger: eventfd context to signal when interrupt happens.
259  * @name: irq name needed when requesting irq.
260  */
261 struct dfl_feature_irq_ctx {
262 	int irq;
263 	struct eventfd_ctx *trigger;
264 	char *name;
265 };
266 
267 /**
268  * struct dfl_feature - sub feature of the feature devices
269  *
270  * @dev: ptr to pdev of the feature device which has the sub feature.
271  * @id: sub feature id.
272  * @revision: revision of this sub feature.
273  * @resource_index: each sub feature has one mmio resource for its registers.
274  *		    this index is used to find its mmio resource from the
275  *		    feature dev (platform device)'s resources.
276  * @ioaddr: mapped mmio resource address.
277  * @irq_ctx: interrupt context list.
278  * @nr_irqs: number of interrupt contexts.
279  * @ops: ops of this sub feature.
280  * @ddev: ptr to the dfl device of this sub feature.
281  * @priv: priv data of this feature.
282  * @dfh_version: version of the DFH
283  * @param_size: size of dfh parameters
284  * @params: point to memory copy of dfh parameters
285  */
286 struct dfl_feature {
287 	struct platform_device *dev;
288 	u16 id;
289 	u8 revision;
290 	int resource_index;
291 	void __iomem *ioaddr;
292 	struct dfl_feature_irq_ctx *irq_ctx;
293 	unsigned int nr_irqs;
294 	const struct dfl_feature_ops *ops;
295 	struct dfl_device *ddev;
296 	void *priv;
297 	u8 dfh_version;
298 	unsigned int param_size;
299 	void *params;
300 };
301 
302 #define FEATURE_DEV_ID_UNUSED	(-1)
303 
304 /**
305  * struct dfl_feature_dev_data - dfl enumeration data for dfl feature dev.
306  *
307  * @node: node to link the data structure to container device's port_dev_list.
308  * @lock: mutex to protect feature dev data.
309  * @dev: ptr to the feature's platform device linked with this structure.
310  * @type: type of DFL FIU for the feature dev. See enum dfl_id_type.
311  * @pdev_id: platform device id for the feature dev.
312  * @pdev_name: platform device name for the feature dev.
313  * @dfl_cdev: ptr to container device.
314  * @id: id used for the feature device.
315  * @disable_count: count for port disable.
316  * @excl_open: set on feature device exclusive open.
317  * @open_count: count for feature device open.
318  * @num: number for sub features.
319  * @private: ptr to feature dev private data.
320  * @features: sub features for the feature dev.
321  * @resource_num: number of resources for the feature dev.
322  * @resources: resources for the feature dev.
323  */
324 struct dfl_feature_dev_data {
325 	struct list_head node;
326 	struct mutex lock;
327 	struct platform_device *dev;
328 	enum dfl_id_type type;
329 	int pdev_id;
330 	const char *pdev_name;
331 	struct dfl_fpga_cdev *dfl_cdev;
332 	int id;
333 	unsigned int disable_count;
334 	bool excl_open;
335 	int open_count;
336 	void *private;
337 	int num;
338 	struct dfl_feature *features;
339 	int resource_num;
340 	struct resource *resources;
341 };
342 
343 /**
344  * struct dfl_feature_platform_data - platform data for feature devices
345  *
346  * @cdev: cdev of feature dev.
347  * @fdata: dfl enumeration data for the dfl feature device.
348  */
349 struct dfl_feature_platform_data {
350 	struct cdev cdev;
351 	struct dfl_feature_dev_data *fdata;
352 };
353 
354 static inline
355 int dfl_feature_dev_use_begin(struct dfl_feature_dev_data *fdata,
356 			      bool excl)
357 {
358 	if (fdata->excl_open)
359 		return -EBUSY;
360 
361 	if (excl) {
362 		if (fdata->open_count)
363 			return -EBUSY;
364 
365 		fdata->excl_open = true;
366 	}
367 	fdata->open_count++;
368 
369 	return 0;
370 }
371 
372 static inline
373 void dfl_feature_dev_use_end(struct dfl_feature_dev_data *fdata)
374 {
375 	fdata->excl_open = false;
376 
377 	if (WARN_ON(fdata->open_count <= 0))
378 		return;
379 
380 	fdata->open_count--;
381 }
382 
383 static inline
384 int dfl_feature_dev_use_count(struct dfl_feature_dev_data *fdata)
385 {
386 	return fdata->open_count;
387 }
388 
389 static inline
390 void dfl_fpga_fdata_set_private(struct dfl_feature_dev_data *fdata,
391 				void *private)
392 {
393 	fdata->private = private;
394 }
395 
396 static inline
397 void *dfl_fpga_fdata_get_private(struct dfl_feature_dev_data *fdata)
398 {
399 	return fdata->private;
400 }
401 
402 struct dfl_feature_ops {
403 	int (*init)(struct platform_device *pdev, struct dfl_feature *feature);
404 	void (*uinit)(struct platform_device *pdev,
405 		      struct dfl_feature *feature);
406 	long (*ioctl)(struct platform_device *pdev, struct dfl_feature *feature,
407 		      unsigned int cmd, unsigned long arg);
408 };
409 
410 #define DFL_FPGA_FEATURE_DEV_FME		"dfl-fme"
411 #define DFL_FPGA_FEATURE_DEV_PORT		"dfl-port"
412 
413 void dfl_fpga_dev_feature_uinit(struct platform_device *pdev);
414 int dfl_fpga_dev_feature_init(struct platform_device *pdev,
415 			      struct dfl_feature_driver *feature_drvs);
416 
417 int dfl_fpga_dev_ops_register(struct platform_device *pdev,
418 			      const struct file_operations *fops,
419 			      struct module *owner);
420 void dfl_fpga_dev_ops_unregister(struct platform_device *pdev);
421 
422 static inline struct dfl_feature_dev_data *
423 dfl_fpga_inode_to_feature_dev_data(struct inode *inode)
424 {
425 	struct dfl_feature_platform_data *pdata;
426 
427 	pdata = container_of(inode->i_cdev, struct dfl_feature_platform_data,
428 			     cdev);
429 	return pdata->fdata;
430 }
431 
432 #define dfl_fpga_dev_for_each_feature(fdata, feature)			    \
433 	for ((feature) = (fdata)->features;				    \
434 	   (feature) < (fdata)->features + (fdata)->num; (feature)++)
435 
436 static inline struct dfl_feature *
437 dfl_get_feature_by_id(struct dfl_feature_dev_data *fdata, u16 id)
438 {
439 	struct dfl_feature *feature;
440 
441 	dfl_fpga_dev_for_each_feature(fdata, feature)
442 		if (feature->id == id)
443 			return feature;
444 
445 	return NULL;
446 }
447 
448 static inline void __iomem *
449 dfl_get_feature_ioaddr_by_id(struct dfl_feature_dev_data *fdata, u16 id)
450 {
451 	struct dfl_feature *feature = dfl_get_feature_by_id(fdata, id);
452 
453 	if (feature && feature->ioaddr)
454 		return feature->ioaddr;
455 
456 	WARN_ON(1);
457 	return NULL;
458 }
459 
460 static inline struct dfl_feature_dev_data *
461 to_dfl_feature_dev_data(struct device *dev)
462 {
463 	struct dfl_feature_platform_data *pdata = dev_get_platdata(dev);
464 
465 	return pdata->fdata;
466 }
467 
468 static inline
469 struct device *dfl_fpga_fdata_to_parent(struct dfl_feature_dev_data *fdata)
470 {
471 	return fdata->dev->dev.parent->parent;
472 }
473 
474 static inline bool dfl_feature_is_fme(void __iomem *base)
475 {
476 	u64 v = readq(base + DFH);
477 
478 	return (FIELD_GET(DFH_TYPE, v) == DFH_TYPE_FIU) &&
479 		(FIELD_GET(DFH_ID, v) == DFH_ID_FIU_FME);
480 }
481 
482 static inline bool dfl_feature_is_port(void __iomem *base)
483 {
484 	u64 v = readq(base + DFH);
485 
486 	return (FIELD_GET(DFH_TYPE, v) == DFH_TYPE_FIU) &&
487 		(FIELD_GET(DFH_ID, v) == DFH_ID_FIU_PORT);
488 }
489 
490 static inline u8 dfl_feature_revision(void __iomem *base)
491 {
492 	return (u8)FIELD_GET(DFH_REVISION, readq(base + DFH));
493 }
494 
495 /**
496  * struct dfl_fpga_enum_info - DFL FPGA enumeration information
497  *
498  * @dev: parent device.
499  * @dfls: list of device feature lists.
500  * @nr_irqs: number of irqs for all feature devices.
501  * @irq_table: Linux IRQ numbers for all irqs, indexed by hw irq numbers.
502  */
503 struct dfl_fpga_enum_info {
504 	struct device *dev;
505 	struct list_head dfls;
506 	unsigned int nr_irqs;
507 	int *irq_table;
508 };
509 
510 /**
511  * struct dfl_fpga_enum_dfl - DFL FPGA enumeration device feature list info
512  *
513  * @start: base address of this device feature list.
514  * @len: size of this device feature list.
515  * @node: node in list of device feature lists.
516  */
517 struct dfl_fpga_enum_dfl {
518 	resource_size_t start;
519 	resource_size_t len;
520 	struct list_head node;
521 };
522 
523 struct dfl_fpga_enum_info *dfl_fpga_enum_info_alloc(struct device *dev);
524 int dfl_fpga_enum_info_add_dfl(struct dfl_fpga_enum_info *info,
525 			       resource_size_t start, resource_size_t len);
526 int dfl_fpga_enum_info_add_irq(struct dfl_fpga_enum_info *info,
527 			       unsigned int nr_irqs, int *irq_table);
528 void dfl_fpga_enum_info_free(struct dfl_fpga_enum_info *info);
529 
530 /**
531  * struct dfl_fpga_cdev - container device of DFL based FPGA
532  *
533  * @parent: parent device of this container device.
534  * @region: base fpga region.
535  * @fme_dev: FME feature device under this container device.
536  * @lock: mutex lock to protect the port device list.
537  * @port_dev_list: list of all port feature devices under this container device.
538  * @released_port_num: released port number under this container device.
539  */
540 struct dfl_fpga_cdev {
541 	struct device *parent;
542 	struct fpga_region *region;
543 	struct device *fme_dev;
544 	struct mutex lock;
545 	struct list_head port_dev_list;
546 	int released_port_num;
547 };
548 
549 struct dfl_fpga_cdev *
550 dfl_fpga_feature_devs_enumerate(struct dfl_fpga_enum_info *info);
551 void dfl_fpga_feature_devs_remove(struct dfl_fpga_cdev *cdev);
552 
553 struct dfl_feature_dev_data *
554 __dfl_fpga_cdev_find_port_data(struct dfl_fpga_cdev *cdev, void *data,
555 			       int (*match)(struct dfl_feature_dev_data *, void *));
556 
557 static inline struct dfl_feature_dev_data *
558 dfl_fpga_cdev_find_port_data(struct dfl_fpga_cdev *cdev, void *data,
559 			     int (*match)(struct dfl_feature_dev_data *, void *))
560 {
561 	struct dfl_feature_dev_data *fdata;
562 
563 	mutex_lock(&cdev->lock);
564 	fdata = __dfl_fpga_cdev_find_port_data(cdev, data, match);
565 	mutex_unlock(&cdev->lock);
566 
567 	return fdata;
568 }
569 
570 int dfl_fpga_cdev_release_port(struct dfl_fpga_cdev *cdev, int port_id);
571 int dfl_fpga_cdev_assign_port(struct dfl_fpga_cdev *cdev, int port_id);
572 void dfl_fpga_cdev_config_ports_pf(struct dfl_fpga_cdev *cdev);
573 int dfl_fpga_cdev_config_ports_vf(struct dfl_fpga_cdev *cdev, int num_vf);
574 int dfl_fpga_set_irq_triggers(struct dfl_feature *feature, unsigned int start,
575 			      unsigned int count, int32_t *fds);
576 long dfl_feature_ioctl_get_num_irqs(struct platform_device *pdev,
577 				    struct dfl_feature *feature,
578 				    unsigned long arg);
579 long dfl_feature_ioctl_set_irq(struct platform_device *pdev,
580 			       struct dfl_feature *feature,
581 			       unsigned long arg);
582 
583 #endif /* __FPGA_DFL_H */
584