Received: by 10.213.65.68 with SMTP id h4csp179035imn; Mon, 12 Mar 2018 10:22:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELujwHnIgDgRB+RbpwEM2kSeN7VMu689g5PnGn2sNpJ7IjE6Ec+PwximAyvbdTuvjXJVLBYQ X-Received: by 2002:a17:902:5327:: with SMTP id b36-v6mr9076657pli.332.1520875379280; Mon, 12 Mar 2018 10:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520875379; cv=none; d=google.com; s=arc-20160816; b=lV/5wFf6jyNxH5BAFZFC3ORfw1pqnJ9IIQ25ik84VjJyEYQFNIY3G/vixkxvQSwgOn A8a5/fcWe0z1NY36MeJfaSsh/PAmQ93ZOIspH6jRUSJ5Fwj5dhH+EVlD4tSfdjiDb7U0 oPmqPu9f9rCYl7i4e/FlzY8F+17tkPd51+zJWYC/O7WW9N1aalPfqIyvgb8VVMVxeq4s 65Wr/8K2oFKu/bNCaR5Saic2c/L/pEVoY/2l9q4nFJk9tFnKG4dU3hIWxlgKuwPE3m2c rgLbOGbPEIMT/U+9CJDLf9LFGL2xrhL/sPGzcVzzV761KfZ4KNYpOBCe1wXYNWIJ/rLd Wr3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature:arc-authentication-results; bh=2LGJgbgl6u1OCLZfjZ0NOomgN8bhiurlFQNN85cUQ8E=; b=MWJjeo5rihozXv9IV292B/D93LAd2i8kavtOywpM6yHrFVLtcc1xClf8qQ5aDpeDpD BZwnSDYWV5jwcCLkKxXJVL8RzIbvaDdyseYG6GMDCubvS390XEidi87kJG+6/LFxJ2mn 4W1/PICpyxevumGmqEljYtpq5R6LKDhBgg0HkFO/3LQALTLrUg+DBJBMYsuw5STNSIfw AysjCQE7aL4YsvdN5mlFLOaiEwZFJMWeFa5sAUAXQ5uTLIwdt77xpoR5Hz6VQpRhUrYz 2RNI1Y3YV0Hl07O94Wrg6YEN83UMY8UtZcU3zIlH3hF9OGIPJcAVVXm+W2jmeeI3eY8H j07Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G9hyUF5F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u1si5228355pgp.498.2018.03.12.10.22.44; Mon, 12 Mar 2018 10:22:59 -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=@gmail.com header.s=20161025 header.b=G9hyUF5F; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932680AbeCLRVe (ORCPT + 99 others); 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-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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