From patchwork Thu Mar 8 19:02:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander H Duyck X-Patchwork-Id: 883259 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q7jzrOhl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zy0JD1wkLz9s1R for ; Fri, 9 Mar 2018 06:02:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754724AbeCHTCe (ORCPT ); Thu, 8 Mar 2018 14:02:34 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:45613 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186AbeCHTCc (ORCPT ); Thu, 8 Mar 2018 14:02:32 -0500 Received: by mail-io0-f196.google.com with SMTP id m22so787271iob.12; Thu, 08 Mar 2018 11:02:32 -0800 (PST) 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=oeiTbIfifosJ+++/fl4A0QDmxbnz70kR8RtPEjE+rU0=; b=Q7jzrOhlg/Fi5w79Yt6aSu+0oyRGLcwU90ex+tZ+J+pz/Wqi23LTZubMRSf1+KDRCE vPAAoTlOCYMl51H8gJ0bSl795T/tdULcFLTlHUh5TWR7ktNK1c9YdkRmfczAfTahp9yQ d6VvRYaZmLU9pg/ob6nFKtc/+sdi9Lc1TJivT1PZrFxFY2PLVMyb6uzA/V9OGi0MHyEl ADSJw8Yf2IbzzV+Cyoi4gxyMw99+RnycmFwjdNBnw1HAGxpJIJxvzxsS5MjoTVArdoYh qiNa6V31VMse0f71KRJF7qGPKvcLIGqeCJff+jlSwjvFMpRtRJqnnn8XxHk/POP2nWSZ WITQ== 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=oeiTbIfifosJ+++/fl4A0QDmxbnz70kR8RtPEjE+rU0=; b=QGBnR2Ne7vlW5XaQoGKL53n29DmQ9wtATdMs6CS7qni9DSFkbXZThGh114ghPFv5IP qBBiycHeFcMeOIKtj4jy8T8FcHP9+L2FlC9FjA2G3ZGOiaKmr8RD+UfvHQvyHSh7z2Ql uXvkVYH0pg50L+/gRubWnx2EfA3Zua1+JKg5NBjTwXo1+g3bd2+WzQwJ2c2bUr9JxbZL jyf7y4DhdVRcd+HEjG6ScaefNkb2160eb0tJShBwsgBBnJA2CkMYomJbh7FF8stCHtcW GuZGX4NjlfgzOhiMZXbkIa3J8V8z3v3nlMpd+vV+dhYOMkLnOJRU5KQ78kMJdfAFbzfh YFGw== X-Gm-Message-State: APf1xPDVfcqK+BFTDHYOHg3Rn1/TCkT/2dUmw8KvUfH9MyMgLV7EPFsY QHJtC9i9w6WjF2ops/LOJ9DYK5DTrcM= X-Google-Smtp-Source: AG47ELuUJNJl5NgL0YiD4ZYSbzImJPGpwT3BHp3/p2rgSEoccsHtLOcmZ99P9qzvGg8+ismJ37XNKA== X-Received: by 10.107.184.10 with SMTP id i10mr32830972iof.283.1520535751529; Thu, 08 Mar 2018 11:02:31 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id 87sm14302244ioq.36.2018.03.08.11.02.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 11:02:30 -0800 (PST) Subject: [pci PATCH v4 1/4] pci-iov: Add support for unmanaged SR-IOV 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: Thu, 08 Mar 2018 11:02:29 -0800 Message-ID: <20180308190047.5433.77952.stgit@localhost.localdomain> In-Reply-To: <20180308185507.5433.98830.stgit@localhost.localdomain> References: <20180308185507.5433.98830.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Alexander Duyck This patch is meant to add some basic functionality to support for SR-IOV on devices when the VFs are not managed by some other entity in the device other than the kernel. A new sysfs value called sriov_unmanaged_autoprobe has been added. This value is used as the drivers_autoprobe setting of the VFs when they are being managed by an external entity such as device firmware instead of being managed by the kernel. One side effect of this change is that the sriov_drivers_autoprobe and sriov_unmanaged_autoprobe will only apply their updates when SR-IOV VFs are allocated. Attempts to update them when SR-IOV is in use will only update the local value and will not update sriov->autoprobe. Signed-off-by: Alexander Duyck --- v3: Updated documentation to better explain sriov_unmanaged_autoprobe use v4: Further documentation updates Added bits so that sriov->autoprobe is not updated while VFs are active Added code to check for assigned VFs in pci_sriov_configure_unamanged Documentation/ABI/testing/sysfs-bus-pci | 25 ++++++++++++++++++ drivers/pci/iov.c | 42 +++++++++++++++++++++++++++++++ drivers/pci/pci-driver.c | 2 + drivers/pci/pci-sysfs.c | 29 +++++++++++++++++++++ drivers/pci/pci.h | 4 ++- include/linux/pci.h | 1 + 6 files changed, 101 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 44d4b2be92fd..82c9520e365f 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -323,3 +323,28 @@ Description: This is similar to /sys/bus/pci/drivers_autoprobe, but affects only the VFs associated with a specific PF. + +What: /sys/bus/pci/devices/.../sriov_unmanaged_autoprobe +Date: March 2018 +Contact: Alexander Duyck +Description: + This file is associated with the PF of a device that + supports SR-IOV. It determines whether newly-enabled VFs + are immediately bound to a driver when the PF driver does + not manage the VFs itself. It initially contains 0, which + means the kernel will not automatically bind VFs to a driver. + If an application writes 1 to the file before enabling VFs, + the kernel will bind VFs to a compatible driver immediately + after they are enabled. + + Currently the use of this setting is limited to drivers that + make use of pci_sriov_configure_unmanaged. Examples might + include drivers such as virtio_net which would be exposed as + a PCIe PF due to the fact that a given device exposes all of + the VFs and PFs as the same general device type but can add + the SR-IOV configuration bits to the configuration space of + the PF. + + This overrides /sys/bus/pci/devices/.../sriov_drivers_autoprobe + when a PF driver does not provide functionality to manage the + VFs when SR-IOV is enabled. diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 677924ae0350..9415a006d064 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -446,6 +446,7 @@ static int sriov_init(struct pci_dev *dev, int pos) pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_device); iov->pgsz = pgsz; iov->self = dev; + iov->autoprobe = true; iov->drivers_autoprobe = true; pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap); pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link); @@ -683,6 +684,12 @@ int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) if (!dev->is_physfn) return -ENOSYS; + if (dev->sriov->num_VFs) + return -EINVAL; + + /* Update autoprobe setting to reflect managed device */ + dev->sriov->autoprobe = dev->sriov->drivers_autoprobe; + return sriov_enable(dev, nr_virtfn); } EXPORT_SYMBOL_GPL(pci_enable_sriov); @@ -807,3 +814,38 @@ int pci_sriov_get_totalvfs(struct pci_dev *dev) return dev->sriov->total_VFs; } EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs); + +/** + * pci_sriov_configure_unmanaged - 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, or have no + * driver present. + */ +int pci_sriov_configure_unmanaged(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) { + /* Update autoprobe setting to reflect unmanaged device */ + dev->sriov->autoprobe = dev->sriov->unmanaged_autoprobe; + err = sriov_enable(dev, nr_virtfn); + } + + return err ? err : nr_virtfn; +} +EXPORT_SYMBOL_GPL(pci_sriov_configure_unmanaged); diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 3bed6beda051..2cc68dff6130 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -398,7 +398,7 @@ void __weak pcibios_free_irq(struct pci_dev *dev) #ifdef CONFIG_PCI_IOV static inline bool pci_device_can_probe(struct pci_dev *pdev) { - return (!pdev->is_virtfn || pdev->physfn->sriov->drivers_autoprobe); + return (!pdev->is_virtfn || pdev->physfn->sriov->autoprobe); } #else static inline bool pci_device_can_probe(struct pci_dev *pdev) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index eb6bee8724cc..6f78fa73e317 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -710,6 +710,30 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev, return count; } +static ssize_t sriov_unmanaged_autoprobe_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + + return sprintf(buf, "%u\n", pdev->sriov->unmanaged_autoprobe); +} + +static ssize_t sriov_unmanaged_autoprobe_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + bool unmanaged_autoprobe; + + if (kstrtobool(buf, &unmanaged_autoprobe) < 0) + return -EINVAL; + + pdev->sriov->unmanaged_autoprobe = unmanaged_autoprobe; + + return count; +} + static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs); static struct device_attribute sriov_numvfs_attr = __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP), @@ -720,6 +744,10 @@ static ssize_t sriov_drivers_autoprobe_store(struct device *dev, static struct device_attribute sriov_drivers_autoprobe_attr = __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP), sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store); +static struct device_attribute sriov_unmanaged_autoprobe_attr = + __ATTR(sriov_unmanaged_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP), + sriov_unmanaged_autoprobe_show, + sriov_unmanaged_autoprobe_store); #endif /* CONFIG_PCI_IOV */ static ssize_t driver_override_store(struct device *dev, @@ -1789,6 +1817,7 @@ static umode_t pcie_dev_attrs_are_visible(struct kobject *kobj, &sriov_stride_attr.attr, &sriov_vf_device_attr.attr, &sriov_drivers_autoprobe_attr.attr, + &sriov_unmanaged_autoprobe_attr.attr, NULL, }; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fcd81911b127..b5f8b034f02d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -272,7 +272,9 @@ struct pci_sriov { struct pci_dev *dev; /* Lowest numbered PF */ struct pci_dev *self; /* This PF */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ - bool drivers_autoprobe; /* Auto probing of VFs by driver */ + bool autoprobe; /* Auto probing of VFs by VF driver */ + bool drivers_autoprobe; /* "" managed by PF driver */ + bool unmanaged_autoprobe; /* "" unmanaged by kernel */ }; /* pci_dev priv_flags */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 024a1beda008..553860a08131 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_unmanaged(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 From patchwork Thu Mar 8 19:03:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander H Duyck X-Patchwork-Id: 883262 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OOe5W9jt"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zy0Kd4B7Tz9s1R for ; Fri, 9 Mar 2018 06:03:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752286AbeCHTDr (ORCPT ); Thu, 8 Mar 2018 14:03:47 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:35877 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752173AbeCHTDp (ORCPT ); Thu, 8 Mar 2018 14:03:45 -0500 Received: by mail-io0-f195.google.com with SMTP id e30so826059ioc.3; Thu, 08 Mar 2018 11:03:45 -0800 (PST) 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=CC5/HV0EqkzB2CEaccts+xR1ya6yic025BGjMOIxsLA=; b=OOe5W9jtqe/MceiQwVdFyvSBIKkuFIrG8ufIcAnPqqrgrGV24XggWx6j3FyfQYPyKR d73bmaN0dAqOwJe2sIp9l1fOp6UkXMSOwufJzsrvNfAGl1x0jk84E4LtSAiLz5M9VnBJ v9xnS06zYD2zNrGx2GC+48BfRA8qdQqv5hYGE092/EaofDZ94MjkXanbbz2UfOhnNSBN 43Flat4IhXlzAH90VusQYMM9h2PppnEz0g+5WiherIRIoKOuJL2wU4M+EK7NKet3P8Sq xM6s4zFs38E7LFtMB71XOgzmK2ewOWr1WjlJ5XqF3ADTogWn06omptU8yDQwPZJSDWGs UqbA== 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=CC5/HV0EqkzB2CEaccts+xR1ya6yic025BGjMOIxsLA=; b=N4MVqc2Ea+5ejJPgjz0tVutPPLE7bwB4CH+0sAZ67xYbizPfC4uqfJTkvACI4Nb97f Ip0fB922OAQQ9GDd/rbj5U4FBbX0dAv74WOej15gmc5v5bjm00suW4Utyea4rYfSESN6 l0FWEvxYsoyslWXKh5+fo20NSlnV4y3WqVaR7LIdeN7cJZ2yFDLXQ8SDYOq5DCpNgfxT O4LK868fiqhnF64sAXJGzGImO68ZjtZU1T86qjLhH+GkDEHmTZtH5xc58YUSl2sbZVH7 57Pe3du1GnwupUo5kJmlFNdfywgV0FcCqqd/VoXpG3lbfFfPN/K8XbWf5Bf3BbodPH/M ZU8A== X-Gm-Message-State: APf1xPAHW94ExKTZ3uJwEjFu26glEPLnFGn7EMHTuowGLQRk3j9XUXjE sQi2I1M2rMz6rhL4mzXvN8bc9B4GjTY= X-Google-Smtp-Source: AG47ELti3Q5L4QrF/W9SRih+G8DBvHJC36dkyWwGn14JVDNlsEPYC5c1iCjkjRlYLx5dDvd5GIptHw== X-Received: by 10.107.70.14 with SMTP id t14mr31442976ioa.281.1520535824480; Thu, 08 Mar 2018 11:03:44 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id p194sm11419324itp.34.2018.03.08.11.03.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 11:03:43 -0800 (PST) Subject: [pci PATCH v4 2/4] virtio_pci: Add support for unmanaged SR-IOV on virtio_pci devices 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: Thu, 08 Mar 2018 11:03:42 -0800 Message-ID: <20180308190236.5433.64788.stgit@localhost.localdomain> In-Reply-To: <20180308185507.5433.98830.stgit@localhost.localdomain> References: <20180308185507.5433.98830.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Alexander Duyck Hardware-realized virtio_pci devices can implement SR-IOV, so this patch enables its use. The device in question is an upcoming Intel NIC that implements both a virtio_net PF and virtio_net VFs. These are hardware realizations of what has been up to now been a software interface. The device in question has the following 4-part PCI IDs: PF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 15fe VF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 05fe The patch currently needs no check for device ID, because the callback will never be made for devices that do not assert the capability or when run on a platform incapable of SR-IOV. One reason for this patch is because the hardware requires the vendor ID of a VF to be the same as the vendor ID of the PF that created it. So it seemed logical to simply have a fully-functioning virtio_net PF create the VFs. This patch makes that possible. Signed-off-by: Mark Rustad Signed-off-by: Alexander Duyck --- v4: Dropped call to pci_disable_sriov in virtio_pci_remove function drivers/virtio/virtio_pci_common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 48d4d1cf1cb6..27ab090163b4 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -596,6 +596,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) #ifdef CONFIG_PM_SLEEP .driver.pm = &virtio_pci_pm_ops, #endif +#ifdef CONFIG_PCI_IOV + .sriov_configure = pci_sriov_configure_unmanaged, +#endif }; module_pci_driver(virtio_pci_driver); From patchwork Thu Mar 8 19:03:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander H Duyck X-Patchwork-Id: 883268 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tsx7b0sZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zy0M65kvPz9s32 for ; Fri, 9 Mar 2018 06:05:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755624AbeCHTD7 (ORCPT ); Thu, 8 Mar 2018 14:03:59 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:54102 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752173AbeCHTD4 (ORCPT ); Thu, 8 Mar 2018 14:03:56 -0500 Received: by mail-it0-f66.google.com with SMTP id w63so8864641ita.3; Thu, 08 Mar 2018 11:03:56 -0800 (PST) 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=9Y6oDAvHJlfS0Xa1fnoGFygeBb0OpuRExdEw30SHGg0=; b=tsx7b0sZntOFi0YQew5eqj9m8qLu1DJ4oxgOqT0D1z9ZLe4mjK/VYrIfl0iGTEKKKY uQ6D+TW8vzzTDPBvoDbtqIDh3ON8p38iyEBdp+OLZcBUlFh4x03ln4dy/gcbYbPSPh7D x5Mj/zj5Jk1VBbUj/65LHi6gFJcVsKumcb2sP5T3IYZ1kaVu0S0ay6s5uoOxyhsBiRse UvWfP2oGiDvUn7KkeV1dv8nSaSaH9ey9m+RnYaYRIdYWYVE2sP8gZwEIX1iE3alHqUsk RJWue7ggL2wySeqHEJSfmpBSKee3uOP4+bOMvZq4D7HT6Vnq/Do0aRB2WWKEF5XDbtOT LFdw== 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=9Y6oDAvHJlfS0Xa1fnoGFygeBb0OpuRExdEw30SHGg0=; b=YWnONhsa6j6IPsWxMXB7vxyrU834yfNCF55czvC9fBcgjH5HlIozBdpqI1dxx0I9nR Fy9kcewtWWc19t2pGsN6sc+cU5w3hN/DsMkY6kIpa6r5Zjz2TAL48i4BQL2eMf4eS1tl Ooy7z12jz2wVWuAEPs3LFdtx55MKhLeq7za3nk+DboBADDgH94NvHfYACEocbeAQJNF8 O0dIv4IVWJSe5NIHPS5o7m2zLyHKdkZ4IlooB4xb8ln/5J74V+0IP4hRTNCEdSc56cq5 P8WKdd0kPsmti1+m8wUqtXXH1RBCHGq9eVV9wN7E0IuTDJa8TumNO7p6SS4hFtVQsxes YS1A== X-Gm-Message-State: AElRT7EGVHXh7obbD4PVbCC2Vrja5vNXlTx9d5mqAfp7pZqHS5YkBTRv 43Q9DN4T4fTIoqmpBTD4HSU= X-Google-Smtp-Source: AG47ELu0SrT4yoxxuJL7upyjez3F1Vqw2UL41COPTSIHwTrSEuTZ+Mabpc3AFOTv321iLEGNk+Ug6A== X-Received: by 10.36.118.79 with SMTP id z76mr27743309itb.10.1520535835907; Thu, 08 Mar 2018 11:03:55 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id v76sm11386557itb.41.2018.03.08.11.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 11:03:55 -0800 (PST) Subject: [pci PATCH v4 3/4] ena: Migrate over to "unmanaged SR-IOV" support 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: Thu, 08 Mar 2018 11:03:53 -0800 Message-ID: <20180308190349.5433.8420.stgit@localhost.localdomain> In-Reply-To: <20180308185507.5433.98830.stgit@localhost.localdomain> References: <20180308185507.5433.98830.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Alexander Duyck Instead of implementing our own version of a SR-IOV configuration stub in the ena driver we can just reuse the existing pci_sriov_configure_unmanaged function. Signed-off-by: Alexander Duyck --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 30 +++----------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 6975150d144e..fa708dd86c96 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -3385,32 +3385,6 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } /*****************************************************************************/ -static int ena_sriov_configure(struct pci_dev *dev, int numvfs) -{ - int rc; - - if (numvfs > 0) { - rc = pci_enable_sriov(dev, numvfs); - if (rc != 0) { - dev_err(&dev->dev, - "pci_enable_sriov failed to enable: %d vfs with the error: %d\n", - numvfs, rc); - return rc; - } - - return numvfs; - } - - if (numvfs == 0) { - pci_disable_sriov(dev); - return 0; - } - - return -EINVAL; -} - -/*****************************************************************************/ -/*****************************************************************************/ /* ena_remove - Device Removal Routine * @pdev: PCI device information struct @@ -3525,7 +3499,9 @@ static int ena_resume(struct pci_dev *pdev) .suspend = ena_suspend, .resume = ena_resume, #endif - .sriov_configure = ena_sriov_configure, +#ifdef CONFIG_PCI_IOV + .sriov_configure = pci_sriov_configure_unmanaged, +#endif }; static int __init ena_init(void) From patchwork Thu Mar 8 19:04:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander H Duyck X-Patchwork-Id: 883265 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OsKyNFKX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zy0LS5XVxz9shp for ; Fri, 9 Mar 2018 06:04:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755814AbeCHTEN (ORCPT ); Thu, 8 Mar 2018 14:04:13 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:56297 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752173AbeCHTEJ (ORCPT ); Thu, 8 Mar 2018 14:04:09 -0500 Received: by mail-it0-f67.google.com with SMTP id n136so6377066itg.5; Thu, 08 Mar 2018 11:04:09 -0800 (PST) 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=68i5zWzVYqXun91nDXwf8CHf3I37XEKxFfn/1UvGzXw=; b=OsKyNFKXHBD7M3Kk2KGe70fEUYbhV9bFMPtXli8Dskm4x0jqdqpeN1qmdAR94POAFh bXX4EHrTzOdgWYYXKUrWzPtMHqpaiYIFwG9qyxiNEd5m1ngWQRZparPSbIPEe2nZ5i2R Wz+piR/az/3K2HHZ9n0FDcKZS2gwqcZ2cFCpgmEQf3ea9I20N3jh88vlPJbTIIUiSO/v yM3msJ6YrJ6nFM7EV3fOMAM4oeHfGrS5WoX0GQWi7yAhBxCocKRN3qpQDgIZPrWHykQ7 rVA1QjbWgErL03iT1oDdSktk8iWD9RWvzr+urEB/w6ZV6ML+Fehl4l/yQXU9xAoAQxT6 qINQ== 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=68i5zWzVYqXun91nDXwf8CHf3I37XEKxFfn/1UvGzXw=; b=bkZ/FrlEaiSm8jsA4Z9Q6HcxBuDu8BV7SwHC/UMlSCyKEonn3NpdopF89EI0lfeX2s f9o0+3rHBko3DKNamOThxbq/JcgYXAyZfDlP2++6j/6PXauo+2u6pxjKRKeV+G+vi0Rz r4h6qoM6BLFny+EhlthcArV01WKhvFqr2CvpS0fviAJCReJJMImmtfTTZhnBwQg9LFEv yeJNmuttbfy7qttuDqVyNKiTFqQwmUaSZfSfrxMv2vOizwKiuDVHxaIa8f1RXJnNn7Um WzIXzV8BI88s0jy2wvsRLrz+FGik4pyiKOt4oaqR7Ibvo5gYZ/tyaWULDbYRbCm6pQE2 GReg== X-Gm-Message-State: AElRT7H8t1ngWUH2+wqtqkRTUlkPZZUC1Iy9JVM9h1iZKReCtlQJkf4Z Vj16qYuAliu/+jbuVidPZxrlm62ekTI= X-Google-Smtp-Source: AG47ELtnoUN+YTPXRANzErx5jDa2p/eJguh74vVwFLgbthnG/+NySGdHccmEp02kLmIunHbNun3G9g== X-Received: by 10.36.131.72 with SMTP id d69mr28598466ite.21.1520535848637; Thu, 08 Mar 2018 11:04:08 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id i31sm14525147iod.78.2018.03.08.11.04.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 11:04:08 -0800 (PST) Subject: [pci PATCH v4 4/4] nvme: Migrate over to "unmanaged SR-IOV" support 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: Thu, 08 Mar 2018 11:04:06 -0800 Message-ID: <20180308190401.5433.13861.stgit@localhost.localdomain> In-Reply-To: <20180308185507.5433.98830.stgit@localhost.localdomain> References: <20180308185507.5433.98830.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Alexander Duyck Instead of implementing our own version of a SR-IOV configuration stub in the nvme driver we can just reuse the existing pci_sriov_configure_unmanaged function. Signed-off-by: Alexander Duyck --- drivers/nvme/host/pci.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 6fe7af00a1f4..2c753ccc1771 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2570,24 +2570,6 @@ static void nvme_remove(struct pci_dev *pdev) nvme_put_ctrl(&dev->ctrl); } -static int nvme_pci_sriov_configure(struct pci_dev *pdev, int numvfs) -{ - int ret = 0; - - if (numvfs == 0) { - if (pci_vfs_assigned(pdev)) { - dev_warn(&pdev->dev, - "Cannot disable SR-IOV VFs while assigned\n"); - return -EPERM; - } - pci_disable_sriov(pdev); - return 0; - } - - ret = pci_enable_sriov(pdev, numvfs); - return ret ? ret : numvfs; -} - #ifdef CONFIG_PM_SLEEP static int nvme_suspend(struct device *dev) { @@ -2706,7 +2688,9 @@ static void nvme_error_resume(struct pci_dev *pdev) .driver = { .pm = &nvme_dev_pm_ops, }, - .sriov_configure = nvme_pci_sriov_configure, +#ifdef CONFIG_PCI_IOV + .sriov_configure = pci_sriov_configure_unmanaged, +#endif .err_handler = &nvme_err_handler, };