Received: by 10.223.185.116 with SMTP id b49csp7918322wrg; Thu, 1 Mar 2018 13:33:06 -0800 (PST) X-Google-Smtp-Source: AG47ELs7CvLdyQrjT/0GqWv5xMLcxxdwtVLdxD08bEMkE4mWq+NN0diN6ME1C4NekVrxwO2c4aI/ X-Received: by 2002:a17:902:904b:: with SMTP id w11-v6mr3153332plz.11.1519939986171; Thu, 01 Mar 2018 13:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519939986; cv=none; d=google.com; s=arc-20160816; b=e9khlPm5EhpA1UNOHCeq/KhSxd10dWl27rwbozapxECj2d6TjDostDHa6wGZYMaWjw CcS9LB5cVDrhxnjHDI6lLE2NAPbs5rtkKu1tajIAAJDOeABbR1gb1Tj87RLzDtjHG/TG /qUUphm4BFlOtkKAvv7sQuqHElWcIv8nkE+5C/5sNRRHmopzqP2Zm+/yQL8BbV8r0eGA JsTzrOt7TXuMmNZI/8XqnDXCmEBGoRl/azY330yt3DM2mMEYil2ZzQDFxnqGcJsl9K2E zQ6ubUIrqXVMIY+yjTzLWjfJ7YftrZx11As3ioAP7r/ggLNGCFjII6ympNZXES8zYv/W 6BJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=TBLFtdOvyl9GBXA8G1BhXXk+hu5jwSWI2v7LqSQGJzU=; b=PXIua+PjKIx2ASpwwrWXONOkLHHn3ywduxXw1jW5oRlYEfZL8LyfQBSkZ6vD8l0Kvg ZHjOnyDtTzNLK8zy55YU49COI64Fe1t/5DcFdWwKTvayvmXmCpVdvHxoZraygE0ZZ+Vb lSOqJkZz3ZA7TEMsaX6+7t9lHfbRo+2q5IyZzWtVqx8/APiCJfmbCdWes59uZZK4TRXm OI2649vzoameGlef39ZAZVYS04AOahKp8gvlsP3ZXwhSmjfQ3V3FwcgHAfMyf1diOcsM I2ddYyLC3TqgkFsJlCXCG2+6c5zei3A7IcuP7mZNbz7MVoDuhcyItvrrWxKztmYwgt36 FX1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=mguFtg2y; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i124si2193469pgd.576.2018.03.01.13.32.51; Thu, 01 Mar 2018 13:33:06 -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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=mguFtg2y; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162088AbeCAVcA (ORCPT + 99 others); Thu, 1 Mar 2018 16:32:00 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:2738 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162032AbeCAVbu (ORCPT ); Thu, 1 Mar 2018 16:31:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1519939910; x=1551475910; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=TBLFtdOvyl9GBXA8G1BhXXk+hu5jwSWI2v7LqSQGJzU=; b=mguFtg2yEkUano8D8jp8JLPxasNIN94ppHL4wXhP7YUEsWs+kTf3xYcE pJXVVDoROAN088vt0BkrsVGCVa6rIH5pWxEG+dWNoEB4uRjrgrw+Z7Jl5 I/dgetvwqgAj2+tyDCu4CON/7qoqYCiCNb+4NbRZYrVFc2fkkwyhvE2kH A=; X-IronPort-AV: E=Sophos;i="5.47,409,1515456000"; d="scan'208";a="334016844" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-9ec21598.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Mar 2018 21:31:49 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan3.amazon.com [10.0.103.150]) by email-inbound-relay-1d-9ec21598.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w21LVg1P078921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Mar 2018 21:31:45 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w21LVf0U014826; Thu, 1 Mar 2018 22:31:41 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w21LVfi8014825; Thu, 1 Mar 2018 22:31:41 +0100 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Cc: KarimAllah Ahmed , Bjorn Helgaas Subject: [PATCH v3 2/2] PCI/IOV: Use the cached VF BARs size instead of re-reading them Date: Thu, 1 Mar 2018 22:31:37 +0100 Message-Id: <1519939897-14596-2-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519939897-14596-1-git-send-email-karahmed@amazon.de> References: <1519939897-14596-1-git-send-email-karahmed@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the cached VF BARs size instead of re-reading them from the hardware. That avoids doing unnecessarily bus transactions which is specially noticable when you have a PF with a large number of VFs. Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: KarimAllah Ahmed --- drivers/pci/probe.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index a96837e..aeaa10a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -180,6 +180,7 @@ static inline unsigned long decode_bar(struct pci_dev *dev, u32 bar) int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, struct resource *res, unsigned int pos) { + int bar = res - dev->resource; u32 l = 0, sz = 0, mask; u64 l64, sz64, mask64; u16 orig_cmd; @@ -199,9 +200,13 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, res->name = pci_name(dev); pci_read_config_dword(dev, pos, &l); - pci_write_config_dword(dev, pos, l | mask); - pci_read_config_dword(dev, pos, &sz); - pci_write_config_dword(dev, pos, l); + if (dev->is_virtfn) { + sz = dev->physfn->sriov->barsz[bar] & 0xffffffff; + } else { + pci_write_config_dword(dev, pos, l | mask); + pci_read_config_dword(dev, pos, &sz); + pci_write_config_dword(dev, pos, l); + } /* * All bits set in sz means the device isn't working properly. @@ -241,9 +246,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, if (res->flags & IORESOURCE_MEM_64) { pci_read_config_dword(dev, pos + 4, &l); - pci_write_config_dword(dev, pos + 4, ~0); - pci_read_config_dword(dev, pos + 4, &sz); - pci_write_config_dword(dev, pos + 4, l); + + if (dev->is_virtfn) { + sz = (dev->physfn->sriov->barsz[bar] >> 32) & 0xffffffff; + } else { + pci_write_config_dword(dev, pos + 4, ~0); + pci_read_config_dword(dev, pos + 4, &sz); + pci_write_config_dword(dev, pos + 4, l); + } l64 |= ((u64)l << 32); sz64 |= ((u64)sz << 32); @@ -332,6 +342,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) for (pos = 0; pos < howmany; pos++) { struct resource *res = &dev->resource[pos]; reg = PCI_BASE_ADDRESS_0 + (pos << 2); + if (dev->is_virtfn && dev->physfn->sriov->barsz[pos] == 0) + continue; pos += __pci_read_base(dev, pci_bar_unknown, res, reg); } -- 2.7.4