Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
1ada901
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
counter
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
Kconfig
Makefile
altera-cvp.c
altera-fpga2sdram.c
altera-freeze-bridge.c
altera-hps2fpga.c
altera-pr-ip-core-plat.c
altera-pr-ip-core.c
altera-ps-spi.c
dfl-afu-dma-region.c
dfl-afu-error.c
dfl-afu-main.c
dfl-afu-region.c
dfl-afu.h
dfl-fme-br.c
dfl-fme-error.c
dfl-fme-main.c
dfl-fme-mgr.c
dfl-fme-perf.c
dfl-fme-pr.c
dfl-fme-pr.h
dfl-fme-region.c
dfl-fme.h
dfl-pci.c
dfl.c
dfl.h
fpga-bridge.c
fpga-mgr.c
fpga-region.c
ice40-spi.c
machxo2-spi.c
of-fpga-region.c
socfpga-a10.c
socfpga.c
stratix10-soc.c
ts73xx-fpga.c
xilinx-pr-decoupler.c
xilinx-spi.c
zynq-fpga.c
zynqmp-fpga.c
fsi
gnss
gpio
gpu
greybus
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
ide
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sfi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
vdpa
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
fpga
/
dfl-pci.c
Blame
Blame
Latest commit
History
History
282 lines (230 loc) · 6.9 KB
Breadcrumbs
linux
/
drivers
/
fpga
/
dfl-pci.c
Top
File metadata and controls
Code
Blame
282 lines (230 loc) · 6.9 KB
Raw
// SPDX-License-Identifier: GPL-2.0 /* * Driver for FPGA Device Feature List (DFL) PCIe device * * Copyright (C) 2017-2018 Intel Corporation, Inc. * * Authors: * Zhang Yi <Yi.Z.Zhang@intel.com> * Xiao Guangrong <guangrong.xiao@linux.intel.com> * Joseph Grecco <joe.grecco@intel.com> * Enno Luebbers <enno.luebbers@intel.com> * Tim Whisonant <tim.whisonant@intel.com> * Ananda Ravuri <ananda.ravuri@intel.com> * Henry Mitchel <henry.mitchel@intel.com> */ #include <linux/pci.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/stddef.h> #include <linux/errno.h> #include <linux/aer.h> #include "dfl.h" #define DRV_VERSION "0.8" #define DRV_NAME "dfl-pci" struct cci_drvdata { struct dfl_fpga_cdev *cdev; /* container device */ }; static void __iomem *cci_pci_ioremap_bar(struct pci_dev *pcidev, int bar) { if (pcim_iomap_regions(pcidev, BIT(bar), DRV_NAME)) return NULL; return pcim_iomap_table(pcidev)[bar]; } /* PCI Device ID */ #define PCIE_DEVICE_ID_PF_INT_5_X 0xBCBD #define PCIE_DEVICE_ID_PF_INT_6_X 0xBCC0 #define PCIE_DEVICE_ID_PF_DSC_1_X 0x09C4 /* VF Device */ #define PCIE_DEVICE_ID_VF_INT_5_X 0xBCBF #define PCIE_DEVICE_ID_VF_INT_6_X 0xBCC1 #define PCIE_DEVICE_ID_VF_DSC_1_X 0x09C5 static struct pci_device_id cci_pcie_id_tbl[] = { {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_INT_5_X),}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_INT_5_X),}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_INT_6_X),}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_INT_6_X),}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_PF_DSC_1_X),}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCIE_DEVICE_ID_VF_DSC_1_X),}, {0,} }; MODULE_DEVICE_TABLE(pci, cci_pcie_id_tbl); static int cci_init_drvdata(struct pci_dev *pcidev) { struct cci_drvdata *drvdata; drvdata = devm_kzalloc(&pcidev->dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM; pci_set_drvdata(pcidev, drvdata); return 0; } static void cci_remove_feature_devs(struct pci_dev *pcidev) { struct cci_drvdata *drvdata = pci_get_drvdata(pcidev); /* remove all children feature devices */ dfl_fpga_feature_devs_remove(drvdata->cdev); } /* enumerate feature devices under pci device */ static int cci_enumerate_feature_devs(struct pci_dev *pcidev) { struct cci_drvdata *drvdata = pci_get_drvdata(pcidev); struct dfl_fpga_enum_info *info; struct dfl_fpga_cdev *cdev; resource_size_t start, len; int port_num, bar, i, ret = 0; void __iomem *base; u32 offset; u64 v; /* allocate enumeration info via pci_dev */ info = dfl_fpga_enum_info_alloc(&pcidev->dev); if (!info) return -ENOMEM; /* start to find Device Feature List from Bar 0 */ base = cci_pci_ioremap_bar(pcidev, 0); if (!base) { ret = -ENOMEM; goto enum_info_free_exit; } /* * PF device has FME and Ports/AFUs, and VF device only has one * Port/AFU. Check them and add related "Device Feature List" info * for the next step enumeration. */ if (dfl_feature_is_fme(base)) { start = pci_resource_start(pcidev, 0); len = pci_resource_len(pcidev, 0); dfl_fpga_enum_info_add_dfl(info, start, len, base); /* * find more Device Feature Lists (e.g. Ports) per information * indicated by FME module. */ v = readq(base + FME_HDR_CAP); port_num = FIELD_GET(FME_CAP_NUM_PORTS, v); WARN_ON(port_num > MAX_DFL_FPGA_PORT_NUM); for (i = 0; i < port_num; i++) { v = readq(base + FME_HDR_PORT_OFST(i)); /* skip ports which are not implemented. */ if (!(v & FME_PORT_OFST_IMP)) continue; /* * add Port's Device Feature List information for next * step enumeration. */ bar = FIELD_GET(FME_PORT_OFST_BAR_ID, v); offset = FIELD_GET(FME_PORT_OFST_DFH_OFST, v); base = cci_pci_ioremap_bar(pcidev, bar); if (!base) continue; start = pci_resource_start(pcidev, bar) + offset; len = pci_resource_len(pcidev, bar) - offset; dfl_fpga_enum_info_add_dfl(info, start, len, base + offset); } } else if (dfl_feature_is_port(base)) { start = pci_resource_start(pcidev, 0); len = pci_resource_len(pcidev, 0); dfl_fpga_enum_info_add_dfl(info, start, len, base); } else { ret = -ENODEV; goto enum_info_free_exit; } /* start enumeration with prepared enumeration information */ cdev = dfl_fpga_feature_devs_enumerate(info); if (IS_ERR(cdev)) { dev_err(&pcidev->dev, "Enumeration failure\n"); ret = PTR_ERR(cdev); goto enum_info_free_exit; } drvdata->cdev = cdev; enum_info_free_exit: dfl_fpga_enum_info_free(info); return ret; } static int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid) { int ret; ret = pcim_enable_device(pcidev); if (ret < 0) { dev_err(&pcidev->dev, "Failed to enable device %d.\n", ret); return ret; } ret = pci_enable_pcie_error_reporting(pcidev); if (ret && ret != -EINVAL) dev_info(&pcidev->dev, "PCIE AER unavailable %d.\n", ret); pci_set_master(pcidev); if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) { ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); if (ret) goto disable_error_report_exit; } else if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) { ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32)); if (ret) goto disable_error_report_exit; } else { ret = -EIO; dev_err(&pcidev->dev, "No suitable DMA support available.\n"); goto disable_error_report_exit; } ret = cci_init_drvdata(pcidev); if (ret) { dev_err(&pcidev->dev, "Fail to init drvdata %d.\n", ret); goto disable_error_report_exit; } ret = cci_enumerate_feature_devs(pcidev); if (ret) { dev_err(&pcidev->dev, "enumeration failure %d.\n", ret); goto disable_error_report_exit; } return ret; disable_error_report_exit: pci_disable_pcie_error_reporting(pcidev); return ret; } static int cci_pci_sriov_configure(struct pci_dev *pcidev, int num_vfs) { struct cci_drvdata *drvdata = pci_get_drvdata(pcidev); struct dfl_fpga_cdev *cdev = drvdata->cdev; if (!num_vfs) { /* * disable SRIOV and then put released ports back to default * PF access mode. */ pci_disable_sriov(pcidev); dfl_fpga_cdev_config_ports_pf(cdev); } else { int ret; /* * before enable SRIOV, put released ports into VF access mode * first of all. */ ret = dfl_fpga_cdev_config_ports_vf(cdev, num_vfs); if (ret) return ret; ret = pci_enable_sriov(pcidev, num_vfs); if (ret) { dfl_fpga_cdev_config_ports_pf(cdev); return ret; } } return num_vfs; } static void cci_pci_remove(struct pci_dev *pcidev) { if (dev_is_pf(&pcidev->dev)) cci_pci_sriov_configure(pcidev, 0); cci_remove_feature_devs(pcidev); pci_disable_pcie_error_reporting(pcidev); } static struct pci_driver cci_pci_driver = { .name = DRV_NAME, .id_table = cci_pcie_id_tbl, .probe = cci_pci_probe, .remove = cci_pci_remove, .sriov_configure = cci_pci_sriov_configure, }; module_pci_driver(cci_pci_driver); MODULE_DESCRIPTION("FPGA DFL PCIe Device Driver"); MODULE_AUTHOR("Intel Corporation"); MODULE_LICENSE("GPL v2");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
You can’t perform that action at this time.