From patchwork Wed Sep 27 12:59:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 9974031 X-Patchwork-Delegate: bhelgaas@google.com 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 57295602D6 for ; Wed, 27 Sep 2017 13:17:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4365D289A3 for ; Wed, 27 Sep 2017 13:17:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 368B8289ED; Wed, 27 Sep 2017 13:17:51 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 26420289A3 for ; Wed, 27 Sep 2017 13:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752264AbdI0NRr (ORCPT ); Wed, 27 Sep 2017 09:17:47 -0400 Received: from casper.infradead.org ([85.118.1.10]:41724 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751959AbdI0NRq (ORCPT ); Wed, 27 Sep 2017 09:17:46 -0400 X-Greylist: delayed 1101 seconds by postgrey-1.27 at vger.kernel.org; Wed, 27 Sep 2017 09:17:46 EDT DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Mime-Version:Content-Type:Date:To:From: Subject:Message-ID:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pyENLtZ6h2nuramqLUgr6AThLphTvU38XfMZ7wSmgRI=; b=APP0uGnULNLEcMx79hnbT6a2lJ xP2TIJS66tzUPlFVZyA2XJkXDrccaH5knQIJC4Kap8jgMpTmNGn+TPF7uIimoDZifml5ibLiB2gt6 rhChKyhnVQ9Keq60Nxc9amG5aZv+9MVlxiHUF7l6aGJRkyGEEhIlSBGMszRzTZw80+9UXzfHC36E6 nu4F8qvTdvN9hXwIKNTs6Px00VU/fhaBvzQDCf79FmVmkPy8zjWu5J3hkooKifBhWmrqkE+jJm6HT fRppoVflbQJ8wvglnvzce+KljqsGiV8fgwBkU2DDEbK0MEDU7WH6UWpMEcPn8oYQuhDqOMn2nGZhA Es4ShbOQ==; Received: from i7.infradead.org ([90.155.92.213]) by casper.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dxBvv-0002lf-Mf; Wed, 27 Sep 2017 12:59:23 +0000 Message-ID: <1506517162.30379.2.camel@infradead.org> Subject: [PATCH] uio/uio_pci_generic: Add SR-IOV support From: David Woodhouse To: Greg Kroah-Hartman , linux-pci , linux-kernel Date: Wed, 27 Sep 2017 13:59:22 +0100 X-Mailer: Evolution 3.22.6 (3.22.6-2.fc25) Mime-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Woodhouse Allow userspace to configure SR-IOV VFs through sysfs. Currently, we need an in-kernel driver to permit this. But sometimes *all* we want to do is enable the VFs so that we can assign them to guests; we don't actually need to deal with the PF in any other way from the host kernel. So let's make it possible to use UIO for that. Signed-off-by: David Woodhouse --- It's not entirely clear to me why we require the driver to "enable" SR-IOV like this anyway — were there some which needed to do something special and device-specific instead of just falling through to pci_{en,dis}able_sriov(), such that we need to effectively whitelist this in the driver rather than blacklisting the "problematic" ones via PCI quirks? drivers/uio/uio_pci_generic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c index a56fdf9..bd196f0 100644 --- a/drivers/uio/uio_pci_generic.c +++ b/drivers/uio/uio_pci_generic.c @@ -108,15 +108,27 @@ static void remove(struct pci_dev *pdev) struct uio_pci_generic_dev *gdev = pci_get_drvdata(pdev); uio_unregister_device(&gdev->info); + pci_disable_sriov(pdev); pci_disable_device(pdev); kfree(gdev); } +static int sriov_configure(struct pci_dev *pdev, int num_vfs) +{ + if (!num_vfs) { + pci_disable_sriov(pdev); + return 0; + } + + return pci_enable_sriov(pdev, num_vfs); +} + static struct pci_driver uio_pci_driver = { .name = "uio_pci_generic", .id_table = NULL, /* only dynamic id's */ .probe = probe, .remove = remove, + .sriov_configure = sriov_configure, }; module_pci_driver(uio_pci_driver);