Skip to content

Commit 1a1527c

Browse files
WuHao270gregkh
authored andcommitted
fpga: dfl: add FPGA Accelerated Function Unit driver basic framework
On DFL FPGA devices, the Accelerated Function Unit (AFU), can be reprogrammed for different functions. It connects to the FPGA infrastructure (static FPGA region) via a Port. Port CSRs are implemented separately from the AFU CSRs to provide control and status of the Port. Once valid PR bitstream is programmed into the AFU, it allows access to the AFU CSRs in the AFU MMIO space. This patch only implements basic driver framework for AFU, including device file operation framework. Signed-off-by: Tim Whisonant <[email protected]> Signed-off-by: Enno Luebbers <[email protected]> Signed-off-by: Shiva Rao <[email protected]> Signed-off-by: Christopher Rauer <[email protected]> Signed-off-by: Xiao Guangrong <[email protected]> Signed-off-by: Wu Hao <[email protected]> Acked-by: Alan Tull <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7514a42 commit 1a1527c

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

drivers/fpga/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ config FPGA_DFL_FME_REGION
174174
help
175175
Say Y to enable FPGA Region driver for FPGA Management Engine.
176176

177+
config FPGA_DFL_AFU
178+
tristate "FPGA DFL AFU Driver"
179+
depends on FPGA_DFL
180+
help
181+
This is the driver for FPGA Accelerated Function Unit (AFU) which
182+
implements AFU and Port management features. A User AFU connects
183+
to the FPGA infrastructure via a Port. There may be more than one
184+
Port/AFU per DFL based FPGA device.
185+
177186
config FPGA_DFL_PCI
178187
tristate "FPGA DFL PCIe Device Driver"
179188
depends on PCI && FPGA_DFL

drivers/fpga/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ obj-$(CONFIG_FPGA_DFL_FME) += dfl-fme.o
3535
obj-$(CONFIG_FPGA_DFL_FME_MGR) += dfl-fme-mgr.o
3636
obj-$(CONFIG_FPGA_DFL_FME_BRIDGE) += dfl-fme-br.o
3737
obj-$(CONFIG_FPGA_DFL_FME_REGION) += dfl-fme-region.o
38+
obj-$(CONFIG_FPGA_DFL_AFU) += dfl-afu.o
3839

3940
dfl-fme-objs := dfl-fme-main.o dfl-fme-pr.o
41+
dfl-afu-objs := dfl-afu-main.o
4042

4143
# Drivers for FPGAs which implement DFL
4244
obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o

drivers/fpga/dfl-afu-main.c

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Driver for FPGA Accelerated Function Unit (AFU)
4+
*
5+
* Copyright (C) 2017-2018 Intel Corporation, Inc.
6+
*
7+
* Authors:
8+
* Wu Hao <[email protected]>
9+
* Xiao Guangrong <[email protected]>
10+
* Joseph Grecco <[email protected]>
11+
* Enno Luebbers <[email protected]>
12+
* Tim Whisonant <[email protected]>
13+
* Ananda Ravuri <[email protected]>
14+
* Henry Mitchel <[email protected]>
15+
*/
16+
17+
#include <linux/kernel.h>
18+
#include <linux/module.h>
19+
20+
#include "dfl.h"
21+
22+
static int port_hdr_init(struct platform_device *pdev,
23+
struct dfl_feature *feature)
24+
{
25+
dev_dbg(&pdev->dev, "PORT HDR Init.\n");
26+
27+
return 0;
28+
}
29+
30+
static void port_hdr_uinit(struct platform_device *pdev,
31+
struct dfl_feature *feature)
32+
{
33+
dev_dbg(&pdev->dev, "PORT HDR UInit.\n");
34+
}
35+
36+
static const struct dfl_feature_ops port_hdr_ops = {
37+
.init = port_hdr_init,
38+
.uinit = port_hdr_uinit,
39+
};
40+
41+
static struct dfl_feature_driver port_feature_drvs[] = {
42+
{
43+
.id = PORT_FEATURE_ID_HEADER,
44+
.ops = &port_hdr_ops,
45+
},
46+
{
47+
.ops = NULL,
48+
}
49+
};
50+
51+
static int afu_open(struct inode *inode, struct file *filp)
52+
{
53+
struct platform_device *fdev = dfl_fpga_inode_to_feature_dev(inode);
54+
struct dfl_feature_platform_data *pdata;
55+
int ret;
56+
57+
pdata = dev_get_platdata(&fdev->dev);
58+
if (WARN_ON(!pdata))
59+
return -ENODEV;
60+
61+
ret = dfl_feature_dev_use_begin(pdata);
62+
if (ret)
63+
return ret;
64+
65+
dev_dbg(&fdev->dev, "Device File Open\n");
66+
filp->private_data = fdev;
67+
68+
return 0;
69+
}
70+
71+
static int afu_release(struct inode *inode, struct file *filp)
72+
{
73+
struct platform_device *pdev = filp->private_data;
74+
struct dfl_feature_platform_data *pdata;
75+
76+
dev_dbg(&pdev->dev, "Device File Release\n");
77+
78+
pdata = dev_get_platdata(&pdev->dev);
79+
80+
dfl_feature_dev_use_end(pdata);
81+
82+
return 0;
83+
}
84+
85+
static long afu_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
86+
{
87+
struct platform_device *pdev = filp->private_data;
88+
struct dfl_feature_platform_data *pdata;
89+
struct dfl_feature *f;
90+
long ret;
91+
92+
dev_dbg(&pdev->dev, "%s cmd 0x%x\n", __func__, cmd);
93+
94+
pdata = dev_get_platdata(&pdev->dev);
95+
96+
switch (cmd) {
97+
default:
98+
/*
99+
* Let sub-feature's ioctl function to handle the cmd
100+
* Sub-feature's ioctl returns -ENODEV when cmd is not
101+
* handled in this sub feature, and returns 0 and other
102+
* error code if cmd is handled.
103+
*/
104+
dfl_fpga_dev_for_each_feature(pdata, f)
105+
if (f->ops && f->ops->ioctl) {
106+
ret = f->ops->ioctl(pdev, f, cmd, arg);
107+
if (ret != -ENODEV)
108+
return ret;
109+
}
110+
}
111+
112+
return -EINVAL;
113+
}
114+
115+
static const struct file_operations afu_fops = {
116+
.owner = THIS_MODULE,
117+
.open = afu_open,
118+
.release = afu_release,
119+
.unlocked_ioctl = afu_ioctl,
120+
};
121+
122+
static int afu_probe(struct platform_device *pdev)
123+
{
124+
int ret;
125+
126+
dev_dbg(&pdev->dev, "%s\n", __func__);
127+
128+
ret = dfl_fpga_dev_feature_init(pdev, port_feature_drvs);
129+
if (ret)
130+
return ret;
131+
132+
ret = dfl_fpga_dev_ops_register(pdev, &afu_fops, THIS_MODULE);
133+
if (ret)
134+
dfl_fpga_dev_feature_uinit(pdev);
135+
136+
return ret;
137+
}
138+
139+
static int afu_remove(struct platform_device *pdev)
140+
{
141+
dev_dbg(&pdev->dev, "%s\n", __func__);
142+
143+
dfl_fpga_dev_ops_unregister(pdev);
144+
dfl_fpga_dev_feature_uinit(pdev);
145+
146+
return 0;
147+
}
148+
149+
static struct platform_driver afu_driver = {
150+
.driver = {
151+
.name = DFL_FPGA_FEATURE_DEV_PORT,
152+
},
153+
.probe = afu_probe,
154+
.remove = afu_remove,
155+
};
156+
157+
module_platform_driver(afu_driver);
158+
159+
MODULE_DESCRIPTION("FPGA Accelerated Function Unit driver");
160+
MODULE_AUTHOR("Intel Corporation");
161+
MODULE_LICENSE("GPL v2");
162+
MODULE_ALIAS("platform:dfl-port");

0 commit comments

Comments
 (0)