From patchwork Thu Mar 1 21:31:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KarimAllah Ahmed X-Patchwork-Id: 10252555 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2912960365 for ; Thu, 1 Mar 2018 21:32:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16ED228649 for ; Thu, 1 Mar 2018 21:32:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03E0A28687; Thu, 1 Mar 2018 21:32:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F81128649 for ; Thu, 1 Mar 2018 21:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162030AbeCAVb7 (ORCPT ); Thu, 1 Mar 2018 16:31:59 -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-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); }