Received: by 10.223.185.116 with SMTP id b49csp7424837wrg; Thu, 1 Mar 2018 05:27:34 -0800 (PST) X-Google-Smtp-Source: AG47ELslY+/kuOtebGis50TDia1z0SpbVOTEHvO4aZpIT2XdKz0nWj7XQ/T6X/GwG1QGFsfWlqZG X-Received: by 2002:a17:902:69cf:: with SMTP id m15-v6mr1989732pln.104.1519910854492; Thu, 01 Mar 2018 05:27:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519910854; cv=none; d=google.com; s=arc-20160816; b=tY/nn4wQ0XtuIauIj3aVO4UVS5b9fmaeWQ4RKYjdyHP5CWsjXjVwEaXKMEtdZce54K 0Xbd6Z2YSLcuYCg66ToASlXHVX41S1kBNDKrVTwKJ4E+AuzbJN2uhUPzoEdc4nPIVen+ wbJ4vOkim766wYW9zoPat48RJJwOHGumhDa9Axuq9vZaEUey/vqolAuflJqiYnMF1rUj ER9qCJoaDStXMK5/EWwlvIc18cIXbPKswh0BUNCR0KozRpXBzpVDkp6M2uoRYDndcHJv j9a4IGLMw8X/+wm3HtryxJE9oumC+xJSP8o8pA/bS7rbux5CP6dXu1j9OOjMDtvGCgMq AXUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=r02/9kSEH3fd2iNjT2sd157RGZ5rQRMsWqW5CzUvQwA=; b=UBVfPjYJVgljEM10E+ACw22crQ+sJQiEhVARbYZ1Hr7qKd9OgGZ9TuEvcdEdLNqQSH EColTHhC49WBxyq8mLBflIX0nJQJKtwYtcUS1a7GHQXqfEg8g0KeZnB/5mCsnay5M67F SwCk5mFAiSX4TWXSD2hz5Ndj856YgoshXoEoENaXBJgh2gMQAPY/EPZa1zqM5PtU8eXg UBp9Fldy4k5Qt1qtOJWelpu8PRjyZxhLfy8k5X0NgQ2UPeH/Dr63vqA4UO4eP3EFPHkN WMScoFdXHXSChaWCAxIYnOSObVVVZgfRVvyi2tHircVpq/3PM8Ckj2EmnrcJXEnlbQt5 x66g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=hvIpANII; 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 g1si2412751pge.831.2018.03.01.05.27.18; Thu, 01 Mar 2018 05:27:34 -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=hvIpANII; 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 S1030619AbeCAN0l (ORCPT + 99 others); Thu, 1 Mar 2018 08:26:41 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:34187 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030379AbeCAN0j (ORCPT ); Thu, 1 Mar 2018 08:26:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1519910799; x=1551446799; h=from:to:cc:subject:date:message-id; bh=r02/9kSEH3fd2iNjT2sd157RGZ5rQRMsWqW5CzUvQwA=; b=hvIpANIIni6X/avxg47w2JxpzyiJ3eidcEShc/BmuTE+ogdFYecYGHCs 965ryryeo65umlqvrkm+BNx3hKf+V4Y1vf+QJSVFJCpmMaGeCuSNtklAF FnQlqEgatuDRChKn00S9keHpXez6kRnbeOrFnYbwULC6IJVURIQlooCFt o=; X-IronPort-AV: E=Sophos;i="5.47,408,1515456000"; d="scan'208";a="333894535" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-c5104f52.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Mar 2018 13:26:37 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2a-c5104f52.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w21DQW7u123424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Mar 2018 13:26:34 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 w21DQVGY012935; Thu, 1 Mar 2018 14:26:31 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w21DQVmB012932; Thu, 1 Mar 2018 14:26:31 +0100 From: KarimAllah Ahmed To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: KarimAllah Ahmed , Bjorn Helgaas Subject: [PATCH v2] pci: Store more data about VFs into the SRIOV struct Date: Thu, 1 Mar 2018 14:26:04 +0100 Message-Id: <1519910764-12789-1-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ... to avoid reading them from the config space of all the PCI VFs. This is specially a useful optimization when bringing up thousands of VFs. Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: KarimAllah Ahmed --- v1 -> v2: * Rebase on latest + remove dependency on a non-upstream patch. drivers/pci/iov.c | 16 ++++++++++++++++ drivers/pci/pci.h | 5 +++++ drivers/pci/probe.c | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 677924a..e1d2e3f 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -114,6 +114,19 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; } +static void pci_read_vf_config_common(struct pci_bus *bus, struct pci_dev *dev) +{ + int devfn = pci_iov_virtfn_devfn(dev, 0); + + pci_bus_read_config_dword(bus, devfn, PCI_CLASS_REVISION, + &dev->sriov->class); + pci_bus_read_config_word(bus, devfn, PCI_SUBSYSTEM_ID, + &dev->sriov->subsystem_device); + pci_bus_read_config_word(bus, devfn, PCI_SUBSYSTEM_VENDOR_ID, + &dev->sriov->subsystem_vendor); + pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &dev->sriov->hdr_type); +} + int pci_iov_add_virtfn(struct pci_dev *dev, int id) { int i; @@ -133,6 +146,9 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) if (!virtfn) goto failed0; + if (id == 0) + pci_read_vf_config_common(bus, dev); + virtfn->devfn = pci_iov_virtfn_devfn(dev, id); virtfn->vendor = dev->vendor; virtfn->device = iov->vf_device; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fcd8191..346daa5 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -271,6 +271,11 @@ struct pci_sriov { u16 driver_max_VFs; /* Max num VFs driver supports */ struct pci_dev *dev; /* Lowest numbered PF */ struct pci_dev *self; /* This PF */ + u8 hdr_type; /* VF header type */ + u32 class; /* VF device */ + u16 device; /* VF device */ + u16 subsystem_vendor; /* VF subsystem vendor */ + u16 subsystem_device; /* VF subsystem device */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ bool drivers_autoprobe; /* Auto probing of VFs by driver */ }; diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ef53774..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); } @@ -1454,7 +1466,9 @@ int pci_setup_device(struct pci_dev *dev) struct pci_bus_region region; struct resource *res; - if (pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type)) + if (dev->is_virtfn) + hdr_type = dev->physfn->sriov->hdr_type; + else if (pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type)) return -EIO; dev->sysdata = dev->bus->sysdata; @@ -1477,7 +1491,10 @@ int pci_setup_device(struct pci_dev *dev) dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); - pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); + if (dev->is_virtfn) + class = dev->physfn->sriov->class; + else + pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); dev->revision = class & 0xff; dev->class = class >> 8; /* upper 3 bytes */ @@ -1517,8 +1534,13 @@ int pci_setup_device(struct pci_dev *dev) goto bad; pci_read_irq(dev); pci_read_bases(dev, 6, PCI_ROM_ADDRESS); - pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor); - pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device); + if (dev->is_virtfn) { + dev->subsystem_vendor = dev->physfn->sriov->subsystem_vendor; + dev->subsystem_device = dev->physfn->sriov->subsystem_device; + } else { + pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor); + pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device); + } /* * Do the ugly legacy mode stuff here rather than broken chip -- 2.7.4