Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9352946ybi; Wed, 24 Jul 2019 02:38:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDgAbY3S6tdaLvaOqVoL38gYeFXxzEzuLSd/F6BCPfgoiosi0T6lOI94Mv7EUe7ynq6w5R X-Received: by 2002:a17:902:1566:: with SMTP id b35mr87142232plh.147.1563961118365; Wed, 24 Jul 2019 02:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563961118; cv=none; d=google.com; s=arc-20160816; b=JCrSPrlGhoEdi8w+kXTBa0P0ydfl84gchM6P0Ap7QK9REK4ZoTnJLmbfw1eM7TQtkg /AbbmKZE0b3abloiQlcWR6Qii7A5Z19vyZhBaxSXR4kIgw2Jf4kn+4qNxDT01K1QpJti cWdQeZkGSjfFZnHz6ew6USrln07lMhRZBSpr+KwRAuQMAWlI+d+V34e9gWTDsPy8CS/Y 7z7Rt0lL7FtUyRNsFidF56CSrlkJFKvP6tRmaMj6Ph33ymm5cYDtRNN8RzVGFy15XTmt vr87KepgG7z5ey2hQQKZm673rS2Hu2530fN2jgnn990kR6o9ep1XQnN+RDdpLqI6SDUk epzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=i6oNMgLhvF93z/Wpd2lBawFR4wE3yxhPpU+hi5r7moI=; b=L9Pxk1yB63a2B2C2dEY11q+0uA7vCLHXNN/ZWq8VTMg6EJu6d2KN9mYxyCTFJSr5yN cTaummCkcla/OeeyCwZVURuFXtBnVByqCfD5wQJK96F4cwTHE9GdakOR29m6dZuBZWL2 qMrU1wtnAzrWvAJo+rjEmvCPb/oPXYNFiyQaYaWIzeI2ORcqp2VQSFrx/yXYrlxuvFP5 CZegKIbU+yDJ+HL2m7SGaJECXl1G9BMW9JJMG5ay/lBgWFOqyMdWtnmgxATlgnQNs1CY Vl+MPI1IEjhIMud73wz+Uv5KRfoPzD/YlqluyIEUmrM5mzYTux4+z5UvLDBcPxvhseXA DM+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U76qhAHO; 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 p3si13747753pjr.18.2019.07.24.02.38.23; Wed, 24 Jul 2019 02:38:38 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=U76qhAHO; 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 S1726827AbfGXJhs (ORCPT + 99 others); Wed, 24 Jul 2019 05:37:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:36034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfGXJhs (ORCPT ); Wed, 24 Jul 2019 05:37:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 83925229F3; Wed, 24 Jul 2019 09:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563961067; bh=iakW1iQlWEzMo9Qp203TppZRMjPZ0rM13b2GeBSp6UM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U76qhAHOn8AKbXB73cTEQAKMnWL2NTYjLWylckWWhSjZDWV/bqxNuudiHvrPIrElH rL0mEqAfVpBmxWsO7nsKtg2c716dhm8Eo1zMlbHxvevEL5lIC1fgB18MOHSVh2N/7D yEgLo1iiJZsGwBfTkFTzBMqr5Ju5+jbgyzEy/XJE= Date: Wed, 24 Jul 2019 11:37:44 +0200 From: Greg KH To: Wu Hao Cc: mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, atull@kernel.org, Zhang Yi Z , Xu Yilun Subject: Re: [PATCH v3 03/12] fpga: dfl: pci: enable SRIOV support. Message-ID: <20190724093744.GC29532@kroah.com> References: <1563857495-26692-1-git-send-email-hao.wu@intel.com> <1563857495-26692-4-git-send-email-hao.wu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1563857495-26692-4-git-send-email-hao.wu@intel.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 23, 2019 at 12:51:26PM +0800, Wu Hao wrote: > This patch enables the standard sriov support. It allows user to > enable SRIOV (and VFs), then user could pass through accelerators > (VFs) into virtual machine or use VFs directly in host. > > Signed-off-by: Zhang Yi Z > Signed-off-by: Xu Yilun > Signed-off-by: Wu Hao > Acked-by: Alan Tull > Acked-by: Moritz Fischer > Signed-off-by: Moritz Fischer > --- > v2: remove DRV/MODULE_VERSION modifications. > --- > drivers/fpga/dfl-pci.c | 39 +++++++++++++++++++++++++++++++++++++++ > drivers/fpga/dfl.c | 41 +++++++++++++++++++++++++++++++++++++++++ > drivers/fpga/dfl.h | 1 + > 3 files changed, 81 insertions(+) > > diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c > index 66b5720..0e65d81 100644 > --- a/drivers/fpga/dfl-pci.c > +++ b/drivers/fpga/dfl-pci.c > @@ -223,8 +223,46 @@ int cci_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pcidevid) > 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; > + int ret = 0; > + > + mutex_lock(&cdev->lock); > + > + if (!num_vfs) { > + /* > + * disable SRIOV and then put released ports back to default > + * PF access mode. > + */ > + pci_disable_sriov(pcidev); > + > + __dfl_fpga_cdev_config_port_vf(cdev, false); > + > + } else if (cdev->released_port_num == num_vfs) { > + /* > + * only enable SRIOV if cdev has matched released ports, put > + * released ports into VF access mode firstly. > + */ > + __dfl_fpga_cdev_config_port_vf(cdev, true); > + > + ret = pci_enable_sriov(pcidev, num_vfs); > + if (ret) > + __dfl_fpga_cdev_config_port_vf(cdev, false); > + } else { > + ret = -EINVAL; > + } > + > + mutex_unlock(&cdev->lock); > + return ret; > +} > + > 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); > } > @@ -234,6 +272,7 @@ static void cci_pci_remove(struct pci_dev *pcidev) > .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); > diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c > index e04ed45..c3a8e1d 100644 > --- a/drivers/fpga/dfl.c > +++ b/drivers/fpga/dfl.c > @@ -1112,6 +1112,47 @@ int dfl_fpga_cdev_config_port(struct dfl_fpga_cdev *cdev, int port_id, > } > EXPORT_SYMBOL_GPL(dfl_fpga_cdev_config_port); > > +static void config_port_vf(struct device *fme_dev, int port_id, bool is_vf) > +{ > + void __iomem *base; > + u64 v; > + > + base = dfl_get_feature_ioaddr_by_id(fme_dev, FME_FEATURE_ID_HEADER); > + > + v = readq(base + FME_HDR_PORT_OFST(port_id)); > + > + v &= ~FME_PORT_OFST_ACC_CTRL; > + v |= FIELD_PREP(FME_PORT_OFST_ACC_CTRL, > + is_vf ? FME_PORT_OFST_ACC_VF : FME_PORT_OFST_ACC_PF); > + > + writeq(v, base + FME_HDR_PORT_OFST(port_id)); > +} > + > +/** > + * __dfl_fpga_cdev_config_port_vf - configure port to VF access mode > + * > + * @cdev: parent container device. > + * @if_vf: true for VF access mode, and false for PF access mode > + * > + * Return: 0 on success, negative error code otherwise. > + * > + * This function is needed in sriov configuration routine. It could be used to > + * configures the released ports access mode to VF or PF. > + * The caller needs to hold lock for protection. > + */ > +void __dfl_fpga_cdev_config_port_vf(struct dfl_fpga_cdev *cdev, bool is_vf) > +{ > + struct dfl_feature_platform_data *pdata; > + > + list_for_each_entry(pdata, &cdev->port_dev_list, node) { > + if (device_is_registered(&pdata->dev->dev)) > + continue; > + > + config_port_vf(cdev->fme_dev, pdata->id, is_vf); > + } > +} > +EXPORT_SYMBOL_GPL(__dfl_fpga_cdev_config_port_vf); Why are you exporting a function with a leading __? You are expecting someone else, in who knows what code, to do locking correctly? If so, and the caller always has to have a local lock, then it's not a big deal, just drop the '__', otherwise if you have to have a specific lock for a specific device, then you have a really complex and probably broken api here :( thanks, greg k-h