Received: by 10.223.185.116 with SMTP id b49csp3393984wrg; Tue, 13 Feb 2018 01:43:59 -0800 (PST) X-Google-Smtp-Source: AH8x227WpmGyoBNyKh7HYLFrN9vxfJZvCuPZQFS9fu1bYvguLwsMFDWMZ+IYiFzNguqFPMR283DT X-Received: by 10.99.117.1 with SMTP id q1mr531601pgc.350.1518515039715; Tue, 13 Feb 2018 01:43:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518515039; cv=none; d=google.com; s=arc-20160816; b=Z51ltkg7nMeRp7jQrCgjUu5WSddMBn6pk9vynxlY8keu3PY9DQmotgge7UWcFyQw3Q K0CPyfB7vl//ZmOmL9UdaErPdTaP4rD97fK3yMZhPNpIotSQhcxhwRSg2II401X6XYB0 We4To8h/gZfGSpirdRLbZ7nUAJtrE8ngWEdu5C6NegyHs5Nfa/GqWphDe7bKS0vbSgdk 05h0F7Z+nyyhmWl/KSKW89ICBv0qyUn21BzWfKFks+mPKHE+LQdH9Awz9/xHgonJyoFy K/lmuO/q0R2Lfb23Xn9L2sz1TC/c3GVfNz/VRTyGK8PTs52gqy4KxbXdzx0hXWjKm2Sa ERHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=NbulZtfNhxQy/WvSiRa11p0mcSXR+czGbtCI5aJXR7E=; b=QN2KrBB/NDF9BecUbDX9anryhFTos7GCe4FDNiY2cIhv/Tn9v79PbPw+8EfQCznJl0 JCVE4FrZOdzuDYf/ngXb8J6C9X+EpGtGGMLdBFvuowOMGQZ2lB119q9heLKk3PBVwaSX 1kO7sT9uXy7RNE2fbS60OTm9SCVlDERmckPmq3pywz97u3t9VL17L57XsomZQGV9QtlN BxV40FBt3U30wTRWlkuQsgeYAkrQtWcOOtPygrQm9BPorgGRQKObWrugJO30trghyUBc t4G/CBzpo8wZNWFTMGOU0O7T7pwomBe6cbBbwDdXijc8zzcAD0/+A/mzrCIuQLFYA31p MFxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9si1264038pfb.104.2018.02.13.01.43.44; Tue, 13 Feb 2018 01:43:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934717AbeBMJfj (ORCPT + 99 others); Tue, 13 Feb 2018 04:35:39 -0500 Received: from mga03.intel.com ([134.134.136.65]:27121 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934119AbeBMJfe (ORCPT ); Tue, 13 Feb 2018 04:35:34 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Feb 2018 01:35:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,507,1511856000"; d="scan'208";a="26889530" Received: from hao-dev.bj.intel.com ([10.238.157.61]) by FMSMGA003.fm.intel.com with ESMTP; 13 Feb 2018 01:35:30 -0800 From: Wu Hao To: atull@kernel.org, mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, luwei.kang@intel.com, yi.z.zhang@intel.com, hao.wu@intel.com, Tim Whisonant , Enno Luebbers , Shiva Rao , Christopher Rauer , Xiao Guangrong Subject: [PATCH v4 08/24] fpga: add FPGA DFL PCIe device driver Date: Tue, 13 Feb 2018 17:24:37 +0800 Message-Id: <1518513893-4719-9-git-send-email-hao.wu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518513893-4719-1-git-send-email-hao.wu@intel.com> References: <1518513893-4719-1-git-send-email-hao.wu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Yi 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 Signed-off-by: Enno Luebbers Signed-off-by: Shiva Rao Signed-off-by: Christopher Rauer Signed-off-by: Zhang Yi Signed-off-by: Xiao Guangrong Signed-off-by: Wu Hao --- v2: move the code to drivers/fpga folder as suggested by Alan Tull. switch to GPLv2 license. fix comments from Moritz Fischer. v3: switch to pci_set_dma_mask/consistent_dma_mask() function. remove pci_save_state() in probe function. rename driver to INTEL_FPGA_DFL_PCI and intel-dfl-pci.c to indicate this driver supports Intel FPGA PCI devices which implement DFL. improve Kconfig description for INTEL_FPGA_DFL_PCI v4: rename to FPGA_DFL_PCI (dfl-pci.c) for better reuse. fix SPDX license issue. --- drivers/fpga/Kconfig | 15 ++++++ drivers/fpga/Makefile | 3 ++ drivers/fpga/dfl-pci.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 drivers/fpga/dfl-pci.c diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index 01ad31f..87f3d44 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -140,4 +140,19 @@ config FPGA_DFL Gate Array (FPGA) solutions which implement Device Feature List. It provides enumeration APIs, and feature device infrastructure. +config FPGA_DFL_PCI + tristate "FPGA Device Feature List (DFL) PCIe Device Driver" + depends on PCI && FPGA_DFL + help + Select this option to enable PCIe driver for PCIe based + Field-Programmable Gate Array (FPGA) solutions which implemented + the Device Feature List (DFL). This driver provides interfaces + for userspace applications to configure, enumerate, open and access + FPGA accelerators on the FPGA DFL devices, enables system level + management functions such as FPGA partial reconfiguration, power + management, and virtualization with DFL framework and DFL feature + device drivers. + + To compile this as a module, choose M here. + endif # FPGA diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index c4c62b9..4375630 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -30,3 +30,6 @@ obj-$(CONFIG_OF_FPGA_REGION) += of-fpga-region.o # FPGA Device Feature List Support obj-$(CONFIG_FPGA_DFL) += dfl.o + +# Drivers for FPGAs which implement DFL +obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c new file mode 100644 index 0000000..d91ea42 --- /dev/null +++ b/drivers/fpga/dfl-pci.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for FPGA Device Feature List (DFL) PCIe device + * + * Copyright (C) 2017 Intel Corporation, Inc. + * + * Authors: + * Zhang Yi + * Xiao Guangrong + * Joseph Grecco + * Enno Luebbers + * Tim Whisonant + * Ananda Ravuri + * Henry Mitchel + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DRV_VERSION "0.8" +#define DRV_NAME "dfl-pci" + +/* 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_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid) +{ + int ret; + + ret = pci_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); + + ret = pci_request_regions(pcidev, DRV_NAME); + if (ret) { + dev_err(&pcidev->dev, "Failed to request regions.\n"); + goto disable_error_report_exit; + } + + 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 release_region_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 release_region_exit; + } else { + ret = -EIO; + dev_err(&pcidev->dev, "No suitable DMA support available.\n"); + goto release_region_exit; + } + + /* TODO: create and add the platform device per feature list */ + return 0; + +release_region_exit: + pci_release_regions(pcidev); +disable_error_report_exit: + pci_disable_pcie_error_reporting(pcidev); + pci_disable_device(pcidev); + return ret; +} + +static void cci_pci_remove(struct pci_dev *pcidev) +{ + pci_release_regions(pcidev); + pci_disable_pcie_error_reporting(pcidev); + pci_disable_device(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, +}; + +static int __init ccidrv_init(void) +{ + pr_info("FPGA DFL PCIe Driver: Version %s\n", DRV_VERSION); + + return pci_register_driver(&cci_pci_driver); +} + +static void __exit ccidrv_exit(void) +{ + pci_unregister_driver(&cci_pci_driver); +} + +module_init(ccidrv_init); +module_exit(ccidrv_exit); + +MODULE_DESCRIPTION("FPGA DFL PCIe Device Driver"); +MODULE_AUTHOR("Intel Corporation"); +MODULE_LICENSE("GPL v2"); -- 2.7.4