Received: by 10.223.185.116 with SMTP id b49csp2833121wrg; Sun, 25 Feb 2018 07:22:10 -0800 (PST) X-Google-Smtp-Source: AH8x225o4UazfYBcBebfoec4Vi8kheGbzvnismZ+FrS3x5hxLFZe5P7TgMiR1gZfLC1UWZREeXB2 X-Received: by 10.98.139.145 with SMTP id e17mr7721774pfl.53.1519572129996; Sun, 25 Feb 2018 07:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519572129; cv=none; d=google.com; s=arc-20160816; b=pIQW0x8TfYPCxszDOV6XLI9YhTYGAF1/sBhrY80XSrDOSw2gvfKk8V7F84vzGg4MWF fxFha7+QaolCmLtECDbpJ7oXLapmhRxLUcVtLLoVXJtnWfUbqc26G0XMRXu4uyJxEAF3 yk5IaNykJAOdWlb1PG3cApqqq6iLbo5+Fce4I4SQLkZkmfFKfdtz1ASZGln/JbC95n4w RFoSB9DjsITUFFvKVblBUV38IMhomeTLkwMNXYsY4iEhMj1q7URjPftS8b3VjPY5Innc 4Phx/rF06EWNupMagPxlTG7zh/wEffXErXat8Pm6aLyj9sRKcwDwVhVpTHRYWkni5INY 1AAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:arc-authentication-results; bh=zSjI2NXJ/FEdHgylyz29yRFGhv0NE5eWl1KAkubdLis=; b=G1lceXWvdnpE6QH8B0UBm3iT20zSb6dyBN1GjVx5EHHNQfj+HwQ77lWOTdWfjSu8ed DkB1xBD1PT/HjG8lF4pduv9HMHQiiksRTsaTxtnRQbFvHZAcXPPVIxf07Jofm8Wb8rye Za9MAUOhcsnbolic+WbgUSUodmUcfQkpD7HOeZrR5YTxBiFHFIhUwnimUtVx6/B2W+bE gVYuV84fdAwMNY1mzN332gA/EUltk2Tc7IFjp/iItFQo8VLzFmgq33aTqba0Gq/JN9j3 Jv6kicerMeRn2Y6Ytz4rxd0fTaE/fQk7VP1ywCJ+wkklhhs+WRfnZ5Q4cwHNNrDb57UZ xxlA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si2216914plf.98.2018.02.25.07.21.55; Sun, 25 Feb 2018 07:22:09 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbeBYPUx convert rfc822-to-8bit (ORCPT + 99 others); Sun, 25 Feb 2018 10:20:53 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38180 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750987AbeBYPUv (ORCPT ); Sun, 25 Feb 2018 10:20:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A558E4075168; Sun, 25 Feb 2018 15:20:50 +0000 (UTC) Received: from [10.35.206.56] (unknown [10.35.206.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 707E02026DFD; Sun, 25 Feb 2018 15:20:48 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [virtio-dev] [RFC PATCH V2] virtio_pci: Add SR-IOV support From: Yan Vugenfirer In-Reply-To: <20180222175250.97135.98386.stgit@mdrustad-mac04.local> Date: Sun, 25 Feb 2018 17:20:47 +0200 Cc: virtio-dev@lists.oasis-open.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, dan.daly@intel.com, alex.williamson@redhat.com, MRustad@gmail.com, alexander.duyck@gmail.com, mst@redhat.com Content-Transfer-Encoding: 8BIT Message-Id: <7B7DC8E0-9F6A-403F-8077-39FC3939482E@redhat.com> References: <20180222175250.97135.98386.stgit@mdrustad-mac04.local> To: Mark Rustad X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 25 Feb 2018 15:20:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sun, 25 Feb 2018 15:20:50 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'yvugenfi@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 22 Feb 2018, at 19:52, Mark Rustad wrote: > > 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: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 15fe > VF: device: 1af4 vendor: 1041 subvendor: 8086 subdevice: 05fe Small mistake in the commit message. Red Hat (Qumranet) vendor ID is 1af4, virtio-net device ID is 1041. Should be: PF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 15fe VF: vendor: 1af4 device: 1041 subvendor: 8086 subdevice: 05fe Best regards, Yan. > > The patch 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 > Reviewed-by: Alexander Duyck > --- > Changes in V2: > - Simplified logic from previous version, removed added driver variable > - Disable SR-IOV on driver removal excapt when VFs are assigned > - Sent as RFC to virtio-dev, linux-pci, netdev, lkml and others > --- > drivers/virtio/virtio_pci_common.c | 47 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c > index 48d4d1cf1cb6..78b53ffc4cee 100644 > --- a/drivers/virtio/virtio_pci_common.c > +++ b/drivers/virtio/virtio_pci_common.c > @@ -572,6 +572,47 @@ static int virtio_pci_probe(struct pci_dev *pci_dev, > return rc; > } > > +#ifdef CONFIG_PCI_IOV > +static int virtio_pci_sriov_disable(struct pci_dev *pci_dev) > +{ > + /* If vfs are assigned we cannot shut down SR-IOV without causing > + * issues, so just leave the hardware available. > + */ > + if (pci_vfs_assigned(pci_dev)) { > + dev_warn(&pci_dev->dev, > + "Unloading driver while VFs are assigned - VFs will not be deallocated\n"); > + return -EPERM; > + } > + pci_disable_sriov(pci_dev); > + return 0; > +} > + > +static int virtio_pci_sriov_enable(struct pci_dev *pci_dev, int num_vfs) > +{ > + int rc = 0; > + > + if (pci_num_vf(pci_dev)) > + return -EINVAL; > + > + rc = pci_enable_sriov(pci_dev, num_vfs); > + if (rc) { > + dev_warn(&pci_dev->dev, "Failed to enable PCI sriov: %d\n", rc); > + return rc; > + } > + dev_info(&pci_dev->dev, "SR-IOV enabled with %d VFs\n", num_vfs); > + return num_vfs; > +} > + > +static int virtio_pci_sriov_configure(struct pci_dev *dev, int num_vfs) > +{ > + if (num_vfs) > + return virtio_pci_sriov_enable(dev, num_vfs); > + if (!pci_num_vf(dev)) > + return -EINVAL; > + return virtio_pci_sriov_disable(dev); > +} > +#endif /* CONFIG_PCI_IOV */ > + > static void virtio_pci_remove(struct pci_dev *pci_dev) > { > struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); > @@ -584,6 +625,9 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) > else > virtio_pci_modern_remove(vp_dev); > > +#ifdef CONFIG_PCI_IOV > + virtio_pci_sriov_disable(pci_dev); > +#endif > pci_disable_device(pci_dev); > put_device(dev); > } > @@ -596,6 +640,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 = virtio_pci_sriov_configure, > +#endif > }; > > module_pci_driver(virtio_pci_driver); > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org >