From patchwork Mon Aug 28 13:38:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filippo Sironi X-Patchwork-Id: 806582 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; dkim=pass (1024-bit key; unprotected) header.d=amazon.de header.i=@amazon.de header.b="cnmHoREb"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xgtDb284Xz9sNr for ; Mon, 28 Aug 2017 23:39:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbdH1Njw (ORCPT ); Mon, 28 Aug 2017 09:39:52 -0400 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:16001 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751349AbdH1Njk (ORCPT ); Mon, 28 Aug 2017 09:39:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1503927580; x=1535463580; h=from:to:cc:subject:date:message-id; bh=+5zRcAiI4o1mIsNejHvCMdiHEbpqsZI8ORUuhSp4778=; b=cnmHoREbECuOlqWk9eRUQKtiuGpFmfAh5er7RWCudaHrrYo28PcMgu1d rbRgbWnf9e08hcxgC07Jcn32xtnAvV0DTlEQO7KISETqc8bc1Aof/G+ww YyFdTZSWnFIFMV7K9HA6ZiuYrJst1K32a9v0TopbdBUiuLRjECAYwMe8M Q=; X-IronPort-AV: E=Sophos;i="5.41,441,1498521600"; d="scan'208";a="680168834" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Aug 2017 13:39:18 +0000 Received: from uf8b156e456a5587c9af4.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id v7SDd89h084216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Aug 2017 13:39:09 GMT Received: from uf8b156e456a5587c9af4.ant.amazon.com (localhost [127.0.0.1]) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id v7SDd73Q026139; Mon, 28 Aug 2017 15:39:07 +0200 Received: (from sironi@localhost) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Submit) id v7SDd7pw026136; Mon, 28 Aug 2017 15:39:07 +0200 From: Filippo Sironi To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Filippo Sironi Subject: [PATCH 1/2] pci: Cache the VF device ID in the SR-IOV structure Date: Mon, 28 Aug 2017 15:38:49 +0200 Message-Id: <1503927530-26076-1-git-send-email-sironi@amazon.de> X-Mailer: git-send-email 2.7.4 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org ... and use it instead of reading it over and over from the PF config space capability. Signed-off-by: Filippo Sironi Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/iov.c | 5 +++-- drivers/pci/pci.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 120485d6f352..e8f7eafaba6a 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -134,7 +134,7 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset) virtfn->devfn = pci_iov_virtfn_devfn(dev, id); virtfn->vendor = dev->vendor; - pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device); + virtfn->device = iov->vf_did; rc = pci_setup_device(virtfn); if (rc) goto failed0; @@ -448,6 +448,7 @@ static int sriov_init(struct pci_dev *dev, int pos) iov->nres = nres; iov->ctrl = ctrl; iov->total_VFs = total; + pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_did); iov->pgsz = pgsz; iov->self = dev; iov->drivers_autoprobe = true; @@ -723,7 +724,7 @@ int pci_vfs_assigned(struct pci_dev *dev) * determine the device ID for the VFs, the vendor ID will be the * same as the PF so there is no need to check for that one */ - pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id); + dev_id = dev->sriov->vf_did; /* loop through all the VFs to see if we own any that are assigned */ vfdev = pci_get_device(dev->vendor, dev_id, NULL); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 22e061738c6f..a7270e11e1ef 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -262,6 +262,7 @@ struct pci_sriov { u16 num_VFs; /* number of VFs available */ u16 offset; /* first VF Routing ID offset */ u16 stride; /* following VF stride */ + u16 vf_did; /* VF device ID */ u32 pgsz; /* page size for BAR alignment */ u8 link; /* Function Dependency Link */ u8 max_VF_buses; /* max buses consumed by VFs */ From patchwork Mon Aug 28 13:38:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filippo Sironi X-Patchwork-Id: 806581 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; dkim=pass (1024-bit key; unprotected) header.d=amazon.de header.i=@amazon.de header.b="ju56gevQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xgtDG1D8Sz9sNr for ; Mon, 28 Aug 2017 23:39:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751348AbdH1Njk (ORCPT ); Mon, 28 Aug 2017 09:39:40 -0400 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]:22980 "EHLO smtp-fw-2101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751337AbdH1Njj (ORCPT ); Mon, 28 Aug 2017 09:39:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1503927579; x=1535463579; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=aszEu8g0CAsTZ/pw2NyXNbpiydcS6t/XIguXU4PIcXY=; b=ju56gevQAvWrw0/fYBnmKM4LZYvChbdgoh0vFolZDwW0Lzj9uhtfGW7m VdGKMYVeAheOc1ORmR+9Grt0daAETcU9cJRWik8tnmIuqKvOnuFq4kNRF a8VmBjAreYqepLcfRsF0cStlE4h9aOsMiapWNEIUCIqMo6yUybEl5qW2h o=; X-IronPort-AV: E=Sophos;i="5.41,441,1498521600"; d="scan'208";a="658277148" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Aug 2017 13:39:19 +0000 Received: from uf8b156e456a5587c9af4.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2c-1968f9fa.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id v7SDd86i034309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 Aug 2017 13:39:09 GMT Received: from uf8b156e456a5587c9af4.ant.amazon.com (localhost [127.0.0.1]) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id v7SDd8bd026143; Mon, 28 Aug 2017 15:39:08 +0200 Received: (from sironi@localhost) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Submit) id v7SDd7l0026142; Mon, 28 Aug 2017 15:39:07 +0200 From: Filippo Sironi To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Filippo Sironi Subject: [PATCH 2/2] pci: Expose offset, stride, and VF device ID via sysfs Date: Mon, 28 Aug 2017 15:38:50 +0200 Message-Id: <1503927530-26076-2-git-send-email-sironi@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503927530-26076-1-git-send-email-sironi@amazon.de> References: <1503927530-26076-1-git-send-email-sironi@amazon.de> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org ... to make it easier for userspace applications consumption. Signed-off-by: Filippo Sironi Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/pci-sysfs.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 2f3780b50723..f920afe7cff3 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -648,6 +648,33 @@ static ssize_t sriov_numvfs_store(struct device *dev, return count; } +static ssize_t sriov_offset_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->offset); +} + +static ssize_t sriov_stride_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->stride); +} + +static ssize_t sriov_vf_did_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + + return sprintf(buf, "%x\n", pdev->sriov->vf_did); +} + static ssize_t sriov_drivers_autoprobe_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -676,6 +703,9 @@ 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), sriov_numvfs_show, sriov_numvfs_store); +static struct device_attribute sriov_offset_attr = __ATTR_RO(sriov_offset); +static struct device_attribute sriov_stride_attr = __ATTR_RO(sriov_stride); +static struct device_attribute sriov_vf_did_attr = __ATTR_RO(sriov_vf_did); 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); @@ -1744,6 +1774,9 @@ static struct attribute_group pci_dev_hp_attr_group = { static struct attribute *sriov_dev_attrs[] = { &sriov_totalvfs_attr.attr, &sriov_numvfs_attr.attr, + &sriov_offset_attr.attr, + &sriov_stride_attr.attr, + &sriov_vf_did_attr.attr, &sriov_drivers_autoprobe_attr.attr, NULL, };