From patchwork Mon Jun 26 01:52:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Hao" X-Patchwork-Id: 9808567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7FF7C60329 for ; Mon, 26 Jun 2017 02:02:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 841FD2847B for ; Mon, 26 Jun 2017 02:02:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78ED52847D; Mon, 26 Jun 2017 02:02:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECF6D2847B for ; Mon, 26 Jun 2017 02:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752253AbdFZB7u (ORCPT ); Sun, 25 Jun 2017 21:59:50 -0400 Received: from mga07.intel.com ([134.134.136.100]:14653 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752107AbdFZB7q (ORCPT ); Sun, 25 Jun 2017 21:59:46 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 25 Jun 2017 18:59:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,393,1493708400"; d="scan'208";a="118726510" Received: from hao-dev.bj.intel.com ([10.238.157.61]) by fmsmga005.fm.intel.com with ESMTP; 25 Jun 2017 18:59:31 -0700 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 v2 09/22] fpga: intel: pcie: adds fpga_for_each_port callback for fme device Date: Mon, 26 Jun 2017 09:52:05 +0800 Message-Id: <1498441938-14046-10-git-send-email-hao.wu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498441938-14046-1-git-send-email-hao.wu@intel.com> References: <1498441938-14046-1-git-send-email-hao.wu@intel.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For FPGA Management Engine (FME), it requires fpga_for_each_port callback for actions on ports, so export this function from PCIe driver by adding the callback to the platform data. Signed-off-by: Tim Whisonant Signed-off-by: Enno Luebbers Signed-off-by: Shiva Rao Signed-off-by: Christopher Rauer Signed-off-by: Xiao Guangrong Signed-off-by: Wu Hao --- v2: rebased --- drivers/fpga/intel-feature-dev.h | 9 +++++++++ drivers/fpga/intel-pcie.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/fpga/intel-feature-dev.h b/drivers/fpga/intel-feature-dev.h index d64a51e..06b3fb6 100644 --- a/drivers/fpga/intel-feature-dev.h +++ b/drivers/fpga/intel-feature-dev.h @@ -235,6 +235,9 @@ struct feature_platform_data { struct platform_device *dev; unsigned int disable_count; /* count for port disable */ + struct platform_device *(*fpga_for_each_port)(struct platform_device *, + void *, int (*match)(struct platform_device *, void *)); + int num; /* number of features */ struct feature features[0]; }; @@ -354,4 +357,10 @@ static inline int fpga_port_reset(struct platform_device *pdev) return pdata->features[index].ioaddr; } + +static inline struct device * +fpga_feature_dev_to_pcidev(struct platform_device *dev) +{ + return dev->dev.parent->parent; +} #endif diff --git a/drivers/fpga/intel-pcie.c b/drivers/fpga/intel-pcie.c index 54c0e3a..86ea5c7 100644 --- a/drivers/fpga/intel-pcie.c +++ b/drivers/fpga/intel-pcie.c @@ -209,6 +209,27 @@ static int parse_switch_to(struct build_feature_devs_info *binfo, int bar) return parse_start_from(binfo, bar); } +static struct platform_device *fpga_for_each_port(struct platform_device *pdev, + void *data, int (*match)(struct platform_device *, void *)) +{ + struct device *pci_dev = fpga_feature_dev_to_pcidev(pdev); + struct cci_drvdata *drvdata = dev_get_drvdata(pci_dev); + struct feature_platform_data *pdata; + struct platform_device *port_dev; + + mutex_lock(&drvdata->lock); + list_for_each_entry(pdata, &drvdata->port_dev_list, node) { + port_dev = pdata->dev; + + if (match(port_dev, data) && get_device(&port_dev->dev)) + goto exit; + } + port_dev = NULL; +exit: + mutex_unlock(&drvdata->lock); + return port_dev; +} + static struct build_feature_devs_info * build_info_alloc_and_init(struct pci_dev *pdev) { @@ -310,6 +331,9 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo) if (!pdata) return -ENOMEM; + if (type == FME_ID) + pdata->fpga_for_each_port = fpga_for_each_port; + /* * the count should be initialized to 0 to make sure *__fpga_port_enable() following __fpga_port_disable()