From patchwork Mon Mar 12 17:21:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 10276789 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 9238C602BD for ; Mon, 12 Mar 2018 17:21:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77FE828BC8 for ; Mon, 12 Mar 2018 17:21:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C00928E54; Mon, 12 Mar 2018 17:21:50 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 0C03828BC8 for ; Mon, 12 Mar 2018 17:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932661AbeCLRVe (ORCPT ); Mon, 12 Mar 2018 13:21:34 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:38524 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932511AbeCLRVc (ORCPT ); Mon, 12 Mar 2018 13:21:32 -0400 Received: by mail-io0-f196.google.com with SMTP id d21so4978524ioc.5; Mon, 12 Mar 2018 10:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=2LGJgbgl6u1OCLZfjZ0NOomgN8bhiurlFQNN85cUQ8E=; b=G9hyUF5FuQmBovDHZq8gFenfTsin/j64q399ifTR7H4J9FTJwH/Q7oYUlfYL4a672Z HpiTZtbwlvMk3QpUrCQAb7l+pSlWroQnD44/rYfnHBDPwAM0IShDz2NsuVdIkatSqEUI nfOiSFlooIl6YW8/+tjzLzxGz7WAvZU51ZYmPzk3771bMu32Jy1eigg1Ks4CGGhWfFwH g11Ii4IeZ6Jj3HIE8GcpQxq8GWzgKlAVMRcxH3eTJjc5PQyYeeh1jQDU3Gxes8eZrZhu JjS2IB1uQGJHfmeW8VmjprFvEvnZ7ljLN2dwkEp/eO6tE9fnLUHGHzCiGdJldUvX3LEn b6+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=2LGJgbgl6u1OCLZfjZ0NOomgN8bhiurlFQNN85cUQ8E=; b=lA+wOUGio43sp9ing7/kioQF7JfGnbIPKZqaw9Lg4rEVS/4U+O6if3b1UE042k7TW1 wN5uoIHkWk6HGmor7c5eDV+yzx+jwSbojFka8reW16oxtmcL3VLUen9tnR09+oKpKHS6 mAQOgOwKyTtGn6iNQvfkK5WzcTDsESGL9g1Yon2xw0zpoAXBfZr0gOkDGdAQnUv88RPU i2zwVFD6jWnqBfNAUWbnDrx1wXcxTb68saPcu+nL9M0EBWOEn5V6Anf7dVaeAd+ZMPeU lfz8P4E9WQMez87wWNpHJ5URyXavT9XpMSzuWzUSL0ZOvksw3lMCwPS+Rz+8rV5Qa8mq 3mXg== X-Gm-Message-State: AElRT7GwkCXAPFNAURUW25RLY1igBuncnZPGEttLRFRRabXvk6I1MLMl ka47NxjV5vbh/nKwfJEkrdA= X-Google-Smtp-Source: AG47ELsnmrsCLVWpAubV9D2ft/kfh0cd7arMgQO+SI055AiUyAh+hAUa/b2yk0VXYvZUFp5nLHDudQ== X-Received: by 10.107.163.204 with SMTP id m195mr9694442ioe.295.1520875291725; Mon, 12 Mar 2018 10:21:31 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id f76sm5433814ioi.41.2018.03.12.10.21.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 10:21:31 -0700 (PDT) Subject: [pci PATCH v5 1/4] pci: Add pci_sriov_configure_simple for PFs that don't manage VF resources From: Alexander Duyck To: bhelgaas@google.com, alexander.h.duyck@intel.com, linux-pci@vger.kernel.org Cc: virtio-dev@lists.oasis-open.org, kvm@vger.kernel.org, netdev@vger.kernel.org, dan.daly@intel.com, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, keith.busch@intel.com, netanel@amazon.com, mheyne@amazon.de, liang-min.wang@intel.com, mark.d.rustad@intel.com, dwmw2@infradead.org, hch@lst.de, dwmw@amazon.co.uk Date: Mon, 12 Mar 2018 10:21:29 -0700 Message-ID: <20180312172031.3487.20651.stgit@localhost.localdomain> In-Reply-To: <20180312171813.3487.94803.stgit@localhost.localdomain> References: <20180312171813.3487.94803.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Duyck This patch adds a common configuration function called pci_sriov_configure_simple that will allow for managing VFs on devices where the PF is not capable of managing VF resources. Signed-off-by: Alexander Duyck --- v5: New patch replacing pci_sriov_configure_unmanaged with pci_sriov_configure_simple Dropped bits related to autoprobe changes drivers/pci/iov.c | 32 ++++++++++++++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 677924ae0350..bd7021491fdb 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -807,3 +807,35 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev) return dev->sriov->total_VFs; } EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs); + +/** + * pci_sriov_configure_simple - helper to configure unmanaged SR-IOV + * @dev: the PCI device + * @nr_virtfn: number of virtual functions to enable, 0 to disable + * + * Used to provide generic enable/disable SR-IOV option for devices + * that do not manage the VFs generated by their driver + */ +int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn) +{ + int err = -EINVAL; + + might_sleep(); + + if (!dev->is_physfn) + return -ENODEV; + + if (pci_vfs_assigned(dev)) { + pci_warn(dev, + "Cannot modify SR-IOV while VFs are assigned\n"); + err = -EPERM; + } else if (!nr_virtfn) { + sriov_disable(dev); + err = 0; + } else if (!dev->sriov->num_VFs) { + err = sriov_enable(dev, nr_virtfn); + } + + return err ? err : nr_virtfn; +} +EXPORT_SYMBOL_GPL(pci_sriov_configure_simple); diff --git a/include/linux/pci.h b/include/linux/pci.h index 024a1beda008..9cab9d0d51dc 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1953,6 +1953,7 @@ static inline void pci_mmcfg_late_init(void) { } int pci_vfs_assigned(struct pci_dev *dev); int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); int pci_sriov_get_totalvfs(struct pci_dev *dev); +int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn); resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno); void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe); #else