From patchwork Sat Jun 22 21:03:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 11011457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD6691395 for ; Sat, 22 Jun 2019 21:03:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B9B28B6A for ; Sat, 22 Jun 2019 21:03:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAC5028B6E; Sat, 22 Jun 2019 21:03:41 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 33E1428B6A for ; Sat, 22 Jun 2019 21:03:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbfFVVDk (ORCPT ); Sat, 22 Jun 2019 17:03:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:60346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725844AbfFVVDk (ORCPT ); Sat, 22 Jun 2019 17:03:40 -0400 Received: from localhost (173.sub-174-234-4.myvzw.com [174.234.4.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA67F20657; Sat, 22 Jun 2019 21:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561237419; bh=nb6TH9VIl779URO+eN/PRQF37XVlb6F19oGN4sP9cX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ThZ3uy7BoNdzKX2SUuzKvZWfGiRnMRWBuMfK8ju8oDPqB1xshh0mxSmeKrhZeUj7e UnutaECcekgA9IUB7pjJT3sf61qRUaYM8EBoN1ryWImzAt+Tq1f5Li8oBpJqAy6sQp J38thrmemINWfxkxbpum39iH6WCIrhjqBp0t7wdU= From: Bjorn Helgaas To: Mika Westerberg , Nicholas Johnson Cc: Logan Gunthorpe , Benjamin Herrenschmidt , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 1/2] PCI: Simplify pci_bus_distribute_available_resources() Date: Sat, 22 Jun 2019 16:03:10 -0500 Message-Id: <20190622210310.180905-2-helgaas@kernel.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190622210310.180905-1-helgaas@kernel.org> References: <20190622210310.180905-1-helgaas@kernel.org> MIME-Version: 1.0 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 From: Bjorn Helgaas Reorder pci_bus_distribute_available_resources() to group related code together. No functional change intended. Link: https://lore.kernel.org/r/PS2P216MB0642C7A485649D2D787A1C6F80000@PS2P216MB0642.KORP216.PROD.OUTLOOK.COM Based-on-patch-by: Nicholas Johnson [bhelgaas: extracted from larger patch] Signed-off-by: Bjorn Helgaas Reviewed-by: Mika Westerberg Reviewed-by: Logan Gunthorpe --- The original order was: 1) remaining_io = available_io 2) for_each_pci_bridge(dev, bus) # count hotplug_bridges, normal_bridges 3) for_each_pci_bridge(dev, bus) if (!dev->is_hotplug_bridge) # reduce remaining_io by dev window 4) if (hotplug_bridges + normal_bridges == 1) # distribute available_io to the single bridge # return 5) for_each_pci_bridge(dev, bus) # distribute remaining_io to hotplug bridges Blocks 2 and 4 don't require remaining_io, so do them first. Blocks 1, 3, 5 deal with remaining_io, so group them together. --- drivers/pci/setup-bus.c | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 0cdd5ff389de..af28af898e42 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1860,16 +1860,6 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, extend_bridge_window(bridge, mmio_pref_res, add_list, available_mmio_pref); - /* - * Calculate the total amount of extra resource space we can - * pass to bridges below this one. This is basically the - * extra space reduced by the minimal required space for the - * non-hotplug bridges. - */ - remaining_io = available_io; - remaining_mmio = available_mmio; - remaining_mmio_pref = available_mmio_pref; - /* * Calculate how many hotplug bridges and normal bridges there * are on this bus. We will distribute the additional available @@ -1882,6 +1872,31 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, normal_bridges++; } + /* + * There is only one bridge on the bus so it gets all available + * resources which it can then distribute to the possible hotplug + * bridges below. + */ + if (hotplug_bridges + normal_bridges == 1) { + dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); + if (dev->subordinate) { + pci_bus_distribute_available_resources(dev->subordinate, + add_list, available_io, available_mmio, + available_mmio_pref); + } + return; + } + + /* + * Calculate the total amount of extra resource space we can + * pass to bridges below this one. This is basically the + * extra space reduced by the minimal required space for the + * non-hotplug bridges. + */ + remaining_io = available_io; + remaining_mmio = available_mmio; + remaining_mmio_pref = available_mmio_pref; + for_each_pci_bridge(dev, bus) { const struct resource *res; @@ -1905,21 +1920,6 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, remaining_mmio_pref -= resource_size(res); } - /* - * There is only one bridge on the bus so it gets all available - * resources which it can then distribute to the possible hotplug - * bridges below. - */ - if (hotplug_bridges + normal_bridges == 1) { - dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); - if (dev->subordinate) { - pci_bus_distribute_available_resources(dev->subordinate, - add_list, available_io, available_mmio, - available_mmio_pref); - } - return; - } - /* * Go over devices on this bus and distribute the remaining * resource space between hotplug bridges. From patchwork Sat Jun 22 21:03:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 11011459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 613651395 for ; Sat, 22 Jun 2019 21:03:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5196728B6A for ; Sat, 22 Jun 2019 21:03:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4616C28B6E; Sat, 22 Jun 2019 21:03:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 E539828B6A for ; Sat, 22 Jun 2019 21:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbfFVVDn (ORCPT ); Sat, 22 Jun 2019 17:03:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:60422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbfFVVDn (ORCPT ); Sat, 22 Jun 2019 17:03:43 -0400 Received: from localhost (173.sub-174-234-4.myvzw.com [174.234.4.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9632420820; Sat, 22 Jun 2019 21:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561237423; bh=ZBHeAKYOzJ563zqzeZHaIQUy51yxP6J6xXlhK4Es36g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iJf3rW6bzBUWONchlG5rcB9Rttd1wn9iYe0eWS/OleF1wnIeQV7DMQi+Gud9AV5TN yMlrkq3ks1xeoizRRnvhQKGZ5sAUCRzGEeM6buwetSMGtFFTZZMV5iz49xBqtmuZE3 GQyiJW12IfskfsoY3z727RGjfmMs6CsogHersSu8= From: Bjorn Helgaas To: Mika Westerberg , Nicholas Johnson Cc: Logan Gunthorpe , Benjamin Herrenschmidt , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 2/2] PCI: Skip resource distribution when no hotplug bridges Date: Sat, 22 Jun 2019 16:03:11 -0500 Message-Id: <20190622210310.180905-3-helgaas@kernel.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190622210310.180905-1-helgaas@kernel.org> References: <20190622210310.180905-1-helgaas@kernel.org> MIME-Version: 1.0 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 From: Bjorn Helgaas If "hotplug_bridges == 0", "!dev->is_hotplug_bridge" is always true, so the loop that divides the remaining resources among hotplug-capable bridges does nothing. Check for "hotplug_bridges == 0" earlier, so we don't even have to compute the amount of remaining resources. No functional change intended. Reviewed-by: Mika Westerberg Reviewed-by: Logan Gunthorpe --- I'm pretty sure this patch preserves the previous behavior of pci_bus_distribute_available_resources(), but I'm not sure that behavior is what we want. For example, in the following topology, when we process bus 10, we find two non-hotplug bridges and no hotplug bridges, so IIUC we return without distributing any resources to them. But I would think we should try to give 10:1c.0 more space if possible because it has a hotplug bridge below it. 00:1c.0: hotplug bridge to [bus 10-2f] 10:1c.0: non-hotplug bridge to [bus 11-2e] 11:00.0: hotplug bridge to [bus 12-2e] 10:1c.1: non-hotplug bridge to [bus 2f] --- drivers/pci/setup-bus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index af28af898e42..04adeebe8866 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1887,6 +1887,9 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, return; } + if (hotplug_bridges == 0) + return; + /* * Calculate the total amount of extra resource space we can * pass to bridges below this one. This is basically the @@ -1936,8 +1939,6 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * Distribute available extra resources equally between * hotplug-capable downstream ports taking alignment into * account. - * - * Here hotplug_bridges is always != 0. */ align = pci_resource_alignment(bridge, io_res); io = div64_ul(available_io, hotplug_bridges);