From patchwork Thu Jun 4 06:41:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 6543991 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A5B239F326 for ; Thu, 4 Jun 2015 06:43:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64A1120755 for ; Thu, 4 Jun 2015 06:43:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D59C820752 for ; Thu, 4 Jun 2015 06:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752440AbbFDGna (ORCPT ); Thu, 4 Jun 2015 02:43:30 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:37158 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752457AbbFDGn1 (ORCPT ); Thu, 4 Jun 2015 02:43:27 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 Jun 2015 16:43:24 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 Jun 2015 16:43:21 +1000 Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 8F281357804F; Thu, 4 Jun 2015 16:43:21 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t546hDXi56361024; Thu, 4 Jun 2015 16:43:21 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t546gl6W004918; Thu, 4 Jun 2015 16:42:49 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t546glYx004228; Thu, 4 Jun 2015 16:42:47 +1000 Received: from bran.ozlabs.ibm.com (unknown [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id AB37AA03BE; Thu, 4 Jun 2015 16:42:23 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id B64A1E387C; Thu, 4 Jun 2015 16:42:23 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id A56799422B2; Thu, 4 Jun 2015 16:42:23 +1000 (AEST) From: Gavin Shan To: linuxppc-dev@lists.ozlabs.org Cc: linux-pci@vger.kernel.org, devicetree@vger.kernel.org, benh@kernel.crashing.org, bhelgaas@google.com, aik@ozlabs.ru, panto@antoniou-consulting.com, robherring2@gmail.com, grant.likely@linaro.org, Gavin Shan Subject: [PATCH v5 03/42] powerpc/powernv: M64 support improvement Date: Thu, 4 Jun 2015 16:41:32 +1000 Message-Id: <1433400131-18429-4-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433400131-18429-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1433400131-18429-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15060406-0025-0000-0000-0000019D2FAC 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 We're having the hardware (on PHB3) or software enforced (on P7IOC) limitation: M64 segment#x can only be assigned to PE#x. IO and M32 segment can be mapped to arbitrary PE# via IODT and M32DT. It means the PE number should be x if M64 segment#x has been assigned to the PE. Also, each PE owns one M64 segment at most. Currently, we are reserving PE# according to root port's M64 window. It won't be reliable once we extend M64 windows of root port, or the upstream port of the PCIE switch behind root port to PHB's M64 window, in order to support PCI hotplug in future. The patch reserves PE# for M64 segments according to the M64 resources of the PCI devices (not bridges) contained in the PE. Besides, it's always worthy to trace the M64 segments consumed by the PE, which can be released at PCI unplugging time. Signed-off-by: Gavin Shan --- v5: * Made the changelog more descriptive on the fixed M64 seg# mapping * Dropped unnecessary and corrected comments pointed by aik * Replace "pe_bitsmap" with "pe_bitmap" * Fixed coding style complained by checkpatch.pl --- arch/powerpc/platforms/powernv/pci-ioda.c | 189 ++++++++++++++++++------------ arch/powerpc/platforms/powernv/pci.h | 10 +- 2 files changed, 121 insertions(+), 78 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c index 245ef81..71afb38 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -294,28 +294,78 @@ fail: return -EIO; } -static void pnv_ioda_reserve_m64_pe(struct pnv_phb *phb) +/* We extend the M64 window of root port, or the upstream bridge port + * of the PCIE switch behind root port. So we shouldn't reserve PEs + * for M64 resources because there are no (normal) PCI devices consuming + * M64 resources on the PCI buses leading from root port, or the upstream + * bridge port. The function returns true if the indicated PCI bus needs + * reserved PEs because of M64 resources in advance. Otherwise, the + * function returns false. + */ +static bool pnv_ioda_need_m64_pe(struct pnv_phb *phb, + struct pci_bus *bus) { - resource_size_t sgsz = phb->ioda.m64_segsize; + if (!bus || pci_is_root_bus(bus)) + return false; + + /* Bus leading from root port. We need check what types of PCI + * devices on the bus. If it's connecting PCI bridge, we don't + * need reserve M64 PEs for it. Otherwise, we still need to do + * that. + */ + if (pci_is_root_bus(bus->self->bus)) { + struct pci_dev *pdev; + + list_for_each_entry(pdev, &bus->devices, bus_list) { + if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) + return true; + } + + return false; + } + + /* Bus leading from the upstream bridge port on top level */ + if (pci_is_root_bus(bus->self->bus->self->bus)) + return false; + + return true; +} + +static void pnv_ioda_reserve_m64_pe(struct pnv_phb *phb, + struct pci_bus *bus) +{ + resource_size_t segsz = phb->ioda.m64_segsize; struct pci_dev *pdev; struct resource *r; - int base, step, i; + unsigned long pe_no, limit; + int i; - /* - * Root bus always has full M64 range and root port has - * M64 range used in reality. So we're checking root port - * instead of root bus. + if (!pnv_ioda_need_m64_pe(phb, bus)) + return; + + /* The bridge's M64 window might have been extended to the + * PHB's M64 window in order to support PCI hotplug. So the + * bridge's M64 window isn't reliable to be used for picking + * PE# for its leading PCI bus. We have to check the M64 + * resources consumed by the PCI devices, which seat on the + * PCI bus. */ - list_for_each_entry(pdev, &phb->hose->bus->devices, bus_list) { - for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { - r = &pdev->resource[PCI_BRIDGE_RESOURCES + i]; - if (!r->parent || - !pnv_pci_is_mem_pref_64(r->flags)) + list_for_each_entry(pdev, &bus->devices, bus_list) { + for (i = 0; i < PCI_NUM_RESOURCES; i++) { +#ifdef CONFIG_PCI_IOV + if (i >= PCI_IOV_RESOURCES && i <= PCI_IOV_RESOURCE_END) + continue; +#endif + r = &pdev->resource[i]; + if (!r->flags || r->start >= r->end || + !r->parent || !pnv_pci_is_mem_pref_64(r->flags)) continue; - base = (r->start - phb->ioda.m64_base) / sgsz; - for (step = 0; step < resource_size(r) / sgsz; step++) - pnv_ioda_reserve_pe(phb, base + step); + pe_no = (r->start - phb->ioda.m64_base) / segsz; + limit = ALIGN(r->end - phb->ioda.m64_base, segsz) / + segsz; + for (; pe_no < limit; pe_no++) + pnv_ioda_reserve_pe(phb, pe_no); } } } @@ -327,85 +377,63 @@ static int pnv_ioda_pick_m64_pe(struct pnv_phb *phb, struct pci_dev *pdev; struct resource *r; struct pnv_ioda_pe *master_pe, *pe; - unsigned long size, *pe_alloc; - bool found; - int start, i, j; - - /* Root bus shouldn't use M64 */ - if (pci_is_root_bus(bus)) - return IODA_INVALID_PE; - - /* We support only one M64 window on each bus */ - found = false; - pci_bus_for_each_resource(bus, r, i) { - if (r && r->parent && - pnv_pci_is_mem_pref_64(r->flags)) { - found = true; - break; - } - } + unsigned long size, *pe_bitmap; + unsigned long pe_no, limit; + int i; - /* No M64 window found ? */ - if (!found) + if (!pnv_ioda_need_m64_pe(phb, bus)) return IODA_INVALID_PE; /* Allocate bitmap */ size = _ALIGN_UP(phb->ioda.total_pe / 8, sizeof(unsigned long)); - pe_alloc = kzalloc(size, GFP_KERNEL); - if (!pe_alloc) { - pr_warn("%s: Out of memory !\n", - __func__); + pe_bitmap = kzalloc(size, GFP_KERNEL); + if (!pe_bitmap) return IODA_INVALID_PE; - } - /* - * Figure out reserved PE numbers by the PE - * the its child PEs. - */ - start = (r->start - phb->ioda.m64_base) / segsz; - for (i = 0; i < resource_size(r) / segsz; i++) - set_bit(start + i, pe_alloc); - - if (all) - goto done; - - /* - * If the PE doesn't cover all subordinate buses, - * we need subtract from reserved PEs for children. + /* The bridge's M64 window might be extended to PHB's M64 + * window by intention to support PCI hotplug. So we have + * to check the M64 resources consumed by the PCI devices + * on the PCI bus. */ list_for_each_entry(pdev, &bus->devices, bus_list) { - if (!pdev->subordinate) - continue; + for (i = 0; i < PCI_NUM_RESOURCES; i++) { +#ifdef CONFIG_PCI_IOV + if (i >= PCI_IOV_RESOURCES && + i <= PCI_IOV_RESOURCE_END) + continue; +#endif + /* Don't scan bridge's window if the PE + * doesn't contain its subordinate bus. + */ + if (!all && i >= PCI_BRIDGE_RESOURCES && + i <= PCI_BRIDGE_RESOURCE_END) + continue; - pci_bus_for_each_resource(pdev->subordinate, r, i) { - if (!r || !r->parent || - !pnv_pci_is_mem_pref_64(r->flags)) + r = &pdev->resource[i]; + if (!r->flags || r->start >= r->end || + !r->parent || !pnv_pci_is_mem_pref_64(r->flags)) continue; - start = (r->start - phb->ioda.m64_base) / segsz; - for (j = 0; j < resource_size(r) / segsz ; j++) - clear_bit(start + j, pe_alloc); - } - } + pe_no = (r->start - phb->ioda.m64_base) / segsz; + limit = ALIGN(r->end - phb->ioda.m64_base, segsz) / + segsz; + for (; pe_no < limit; pe_no++) + set_bit(pe_no, pe_bitmap); + } + } - /* - * the current bus might not own M64 window and that's all - * contributed by its child buses. For the case, we needn't - * pick M64 dependent PE#. - */ - if (bitmap_empty(pe_alloc, phb->ioda.total_pe)) { - kfree(pe_alloc); + /* No M64 window found ? */ + if (bitmap_empty(pe_bitmap, phb->ioda.total_pe)) { + kfree(pe_bitmap); return IODA_INVALID_PE; } - /* - * Figure out the master PE and put all slave PEs to master - * PE's list to form compound PE. + /* Figure out the master PE and put all slave PEs + * to master PE's list to form compound PE. */ -done: master_pe = NULL; i = -1; - while ((i = find_next_bit(pe_alloc, phb->ioda.total_pe, i + 1)) < + while ((i = find_next_bit(pe_bitmap, phb->ioda.total_pe, i + 1)) < phb->ioda.total_pe) { pe = &phb->ioda.pe_array[i]; @@ -419,6 +447,13 @@ done: list_add_tail(&pe->list, &master_pe->slaves); } + /* Reserve the M64 segment, which should be available. Also, + * those M64 segments consumed by slave PEs are contributed + * to the master PE. + */ + BUG_ON(test_and_set_bit(pe->pe_number, phb->ioda.m64_segmap)); + BUG_ON(test_and_set_bit(pe->pe_number, master_pe->m64_segmap)); + /* P7IOC supports M64DT, which helps mapping M64 segment * to one particular PE#. However, PHB3 has fixed mapping * between M64 segment and PE#. In order to have same logic @@ -440,7 +475,7 @@ done: } } - kfree(pe_alloc); + kfree(pe_bitmap); return master_pe->pe_number; } @@ -1233,7 +1268,7 @@ static void pnv_pci_ioda_setup_PEs(void) /* M64 layout might affect PE allocation */ if (phb->reserve_m64_pe) - phb->reserve_m64_pe(phb); + phb->reserve_m64_pe(phb, phb->hose->bus); pnv_ioda_setup_PEs(hose->bus); } diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h index fc6be02..54657f4 100644 --- a/arch/powerpc/platforms/powernv/pci.h +++ b/arch/powerpc/platforms/powernv/pci.h @@ -49,6 +49,13 @@ struct pnv_ioda_pe { /* PE number */ unsigned int pe_number; + /* IO/M32/M64 segments consumed by the PE. Each PE can + * have one M64 segment at most, but M64 segments consumed + * by slave PEs will be contributed to the master PE. One + * PE can own multiple IO and M32 segments. + */ + unsigned long m64_segmap[8]; + /* "Weight" assigned to the PE for the sake of DMA resource * allocations */ @@ -113,7 +120,7 @@ struct pnv_phb { u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn); void (*shutdown)(struct pnv_phb *phb); int (*init_m64)(struct pnv_phb *phb); - void (*reserve_m64_pe)(struct pnv_phb *phb); + void (*reserve_m64_pe)(struct pnv_phb *phb, struct pci_bus *bus); int (*pick_m64_pe)(struct pnv_phb *phb, struct pci_bus *bus, int all); int (*get_pe_state)(struct pnv_phb *phb, int pe_no); void (*freeze_pe)(struct pnv_phb *phb, int pe_no); @@ -153,6 +160,7 @@ struct pnv_phb { struct mutex pe_alloc_mutex; /* M32 & IO segment maps */ + unsigned long m64_segmap[8]; unsigned int *m32_segmap; unsigned int *io_segmap; struct pnv_ioda_pe *pe_array;