Skip to content

Commit 72ddd9f

Browse files
Zhang Yigregkh
authored andcommitted
fpga: add FPGA DFL PCIe device driver
This patch implements the basic framework of the driver for FPGA PCIe device which implements the Device Feature List (DFL) in its MMIO space. This driver is verified on Intel(R) PCIe-based FPGA DFL devices, including both integrated (e.g. Intel Server Platform with In-package FPGA) and discrete (e.g. Intel FPGA PCIe Acceleration Cards) solutions. 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: Zhang Yi <[email protected]> Signed-off-by: Xiao Guangrong <[email protected]> Signed-off-by: Wu Hao <[email protected]> Acked-by: Alan Tull <[email protected]> Acked-by: Moritz Fischer <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d06b004 commit 72ddd9f

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

drivers/fpga/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,19 @@ config FPGA_DFL
146146
Gate Array (FPGA) solutions which implement Device Feature List.
147147
It provides enumeration APIs and feature device infrastructure.
148148

149+
config FPGA_DFL_PCI
150+
tristate "FPGA DFL PCIe Device Driver"
151+
depends on PCI && FPGA_DFL
152+
help
153+
Select this option to enable PCIe driver for PCIe-based
154+
Field-Programmable Gate Array (FPGA) solutions which implement
155+
the Device Feature List (DFL). This driver provides interfaces
156+
for userspace applications to configure, enumerate, open and access
157+
FPGA accelerators on the FPGA DFL devices, enables system level
158+
management functions such as FPGA partial reconfiguration, power
159+
management and virtualization with DFL framework and DFL feature
160+
device drivers.
161+
162+
To compile this as a module, choose M here.
163+
149164
endif # FPGA

drivers/fpga/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o
3131

3232
# FPGA Device Feature List Support
3333
obj-$(CONFIG_FPGA_DFL) += dfl.o
34+
35+
# Drivers for FPGAs which implement DFL
36+
obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o

drivers/fpga/dfl-pci.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Driver for FPGA Device Feature List (DFL) PCIe device
4+
*
5+
* Copyright (C) 2017-2018 Intel Corporation, Inc.
6+
*
7+
* Authors:
8+
* Zhang Yi <[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/pci.h>
18+
#include <linux/types.h>
19+
#include <linux/kernel.h>
20+
#include <linux/module.h>
21+
#include <linux/stddef.h>
22+
#include <linux/errno.h>
23+
#include <linux/aer.h>
24+
25+
#define DRV_VERSION "0.8"
26+
#define DRV_NAME "dfl-pci"
27+
28+
/* PCI Device ID */
29+
#define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD
30+
#define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0
31+
#define PCIE_DEVICE_ID_PF_DSC_1_X 0x09C4
32+
/* VF Device */
33+
#define PCIE_DEVICE_ID_VF_INT_5_X 0xBCBF
34+
#define PCIE_DEVICE_ID_VF_INT_6_X 0xBCC1
35+
#define PCIE_DEVICE_ID_VF_DSC_1_X 0x09C5
36+
37+
static struct pci_device_id cci_pcie_id_tbl[] = {
38+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_INT_5_X),},
39+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_INT_5_X),},
40+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_INT_6_X),},
41+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_INT_6_X),},
42+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_DSC_1_X),},
43+
{PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_DSC_1_X),},
44+
{0,}
45+
};
46+
MODULE_DEVICE_TABLE(pci, cci_pcie_id_tbl);
47+
48+
static
49+
int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid)
50+
{
51+
int ret;
52+
53+
ret = pcim_enable_device(pcidev);
54+
if (ret < 0) {
55+
dev_err(&pcidev->dev, "Failed to enable device %d.\n", ret);
56+
return ret;
57+
}
58+
59+
ret = pci_enable_pcie_error_reporting(pcidev);
60+
if (ret && ret != -EINVAL)
61+
dev_info(&pcidev->dev, "PCIE AER unavailable %d.\n", ret);
62+
63+
pci_set_master(pcidev);
64+
65+
if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) {
66+
ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
67+
if (ret)
68+
goto disable_error_report_exit;
69+
} else if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
70+
ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
71+
if (ret)
72+
goto disable_error_report_exit;
73+
} else {
74+
ret = -EIO;
75+
dev_err(&pcidev->dev, "No suitable DMA support available.\n");
76+
goto disable_error_report_exit;
77+
}
78+
79+
/* TODO: create and add the platform device per feature list */
80+
return 0;
81+
82+
disable_error_report_exit:
83+
pci_disable_pcie_error_reporting(pcidev);
84+
return ret;
85+
}
86+
87+
static void cci_pci_remove(struct pci_dev *pcidev)
88+
{
89+
pci_disable_pcie_error_reporting(pcidev);
90+
}
91+
92+
static struct pci_driver cci_pci_driver = {
93+
.name = DRV_NAME,
94+
.id_table = cci_pcie_id_tbl,
95+
.probe = cci_pci_probe,
96+
.remove = cci_pci_remove,
97+
};
98+
99+
module_pci_driver(cci_pci_driver);
100+
101+
MODULE_DESCRIPTION("FPGA DFL PCIe Device Driver");
102+
MODULE_AUTHOR("Intel Corporation");
103+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)