From patchwork Tue Feb 24 08:33:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 5870501 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 80E92BF440 for ; Tue, 24 Feb 2015 08:33:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B0962064F for ; Tue, 24 Feb 2015 08:33:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C6A92060B for ; Tue, 24 Feb 2015 08:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752331AbbBXIdl (ORCPT ); Tue, 24 Feb 2015 03:33:41 -0500 Received: from mail-pd0-f174.google.com ([209.85.192.174]:46590 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751832AbbBXIdk (ORCPT ); Tue, 24 Feb 2015 03:33:40 -0500 Received: by pdjy10 with SMTP id y10so31753701pdj.13 for ; Tue, 24 Feb 2015 00:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=D+FlFLicxrB232lqH1HEGXGnp+0AIJ9no0ETAA2eMEo=; b=cPD+s8G85a9hvfaDZNszY+tptiwEUzP6b1i7wigiYZg1r5XXj/XcHZpVIdqGcyTSeX Fe5o3sy3YjWupeBY24jeqkgoRteuwzpp8xxnDUsxDXLqFOMjEe7y1IBm+2RXHBzvvs1l B7/vJ+TK11WA6Vq93prcVpY3UQAbJsiD3jSfoe9R/kwYt6OmqyKlkeyPhQOsD4oCrG8i 8+8NcCnCZPvWhU1ZkkXhrJ2AfmpdsafsYsu7H0As7q4VpkNoyhO5QdoNJeXf5uiRAfUN n3HVApG1KyOn9ZAu26HDU8SkOseei3sdQn7SNjBWRKdNzMNkRmwBolQ9eJ0BtJUqwbcs PK3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=D+FlFLicxrB232lqH1HEGXGnp+0AIJ9no0ETAA2eMEo=; b=TQ3JYwOmmmwzaHZjiSAeg7/h3PK6pBBbwkSHQ8pyCbChpNt5GFkBIxYxJcbozIaCDF G2Ldo09oSNZg0JOGK1k5bj+ImDtaEMfzsUvudaive8kupEw6KkHvDU9raF+011FRYKbk tYG45LVuBKjdD0YIzAmIC+zODsnY8MSyZDpHjE6kOMGXhYPknMZym8MPjj5FEXceBJvA lEasneQhjYUGlkPVWoMoP7jx8qQmi6wzYxwg2FxKdyXNzz7c9CsRyJeC2YAKI+RzJJAB aF2J8/6nzDkM7ilji3VmnG7NFvX3PITa8qG3Wdt7VS4H8GFPArV+gGG3LH5bKHDmjaNv BDNA== X-Gm-Message-State: ALoCoQkBq5N0IajAr/BN5b/bYPKSX+3QN5zDKr3Ms+92dFuIRDxdghtve9ASbUymG1A1PyiH2+Qy X-Received: by 10.70.95.200 with SMTP id dm8mr27339410pdb.14.1424766820356; Tue, 24 Feb 2015 00:33:40 -0800 (PST) Received: from localhost ([12.23.74.29]) by mx.google.com with ESMTPSA id y7sm845641pdp.92.2015.02.24.00.33.39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 24 Feb 2015 00:33:39 -0800 (PST) Subject: [PATCH v12 06/21] PCI: Calculate maximum number of buses required for VFs To: Wei Yang , benh@au1.ibm.com, gwshan@linux.vnet.ibm.com From: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Tue, 24 Feb 2015 02:33:38 -0600 Message-ID: <20150224083338.32124.56221.stgit@bhelgaas-glaptop2.roam.corp.google.com> In-Reply-To: <20150224082939.32124.45744.stgit@bhelgaas-glaptop2.roam.corp.google.com> References: <20150224082939.32124.45744.stgit@bhelgaas-glaptop2.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wei Yang An SR-IOV device can change its First VF Offset and VF Stride based on the values of ARI Capable Hierarchy and NumVFs. The number of buses required for all VFs is determined by NumVFs, First VF Offset, and VF Stride (see SR-IOV spec r1.1, sec 2.1.2). Previously pci_iov_bus_range() computed how many buses would be required by TotalVFs, but this was based on a single NumVFs value and may not have been the maximum for all NumVFs configurations. Iterate over all valid NumVFs and calculate the maximum number of bus numbers that could ever be required for VFs of this device. [bhelgaas: changelog, compute busnr of NumVFs, not TotalVFs, remove kerenl-doc comment marker] Signed-off-by: Wei Yang Signed-off-by: Bjorn Helgaas --- drivers/pci/iov.c | 31 +++++++++++++++++++++++++++---- drivers/pci/pci.h | 1 + 2 files changed, 28 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index a8752c2c2b53..2ae921f84bd3 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -46,6 +46,30 @@ static inline void pci_iov_set_numvfs(struct pci_dev *dev, int nr_virtfn) pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &iov->stride); } +/* + * The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride + * determine how many additional bus numbers will be consumed by VFs. + * + * Iterate over all valid NumVFs and calculate the maximum number of bus + * numbers that could ever be required. + */ +static inline u8 virtfn_max_buses(struct pci_dev *dev) +{ + struct pci_sriov *iov = dev->sriov; + int nr_virtfn; + u8 max = 0; + u8 busnr; + + for (nr_virtfn = 1; nr_virtfn <= iov->total_VFs; nr_virtfn++) { + pci_iov_set_numvfs(dev, nr_virtfn); + busnr = virtfn_bus(dev, nr_virtfn - 1); + if (busnr > max) + max = busnr; + } + + return max; +} + static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr) { struct pci_bus *child; @@ -427,6 +451,7 @@ found: dev->sriov = iov; dev->is_physfn = 1; + iov->max_VF_buses = virtfn_max_buses(dev); return 0; @@ -556,15 +581,13 @@ void pci_restore_iov_state(struct pci_dev *dev) int pci_iov_bus_range(struct pci_bus *bus) { int max = 0; - u8 busnr; struct pci_dev *dev; list_for_each_entry(dev, &bus->devices, bus_list) { if (!dev->is_physfn) continue; - busnr = virtfn_bus(dev, dev->sriov->total_VFs - 1); - if (busnr > max) - max = busnr; + if (dev->sriov->max_VF_buses > max) + max = dev->sriov->max_VF_buses; } return max ? max - bus->number : 0; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 57329645dd01..bae593c04541 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -243,6 +243,7 @@ struct pci_sriov { u16 stride; /* following VF stride */ u32 pgsz; /* page size for BAR alignment */ u8 link; /* Function Dependency Link */ + u8 max_VF_buses; /* max buses consumed by VFs */ u16 driver_max_VFs; /* max num VFs driver supports */ struct pci_dev *dev; /* lowest numbered PF */ struct pci_dev *self; /* this PF */