From patchwork Mon Jan 7 13:45:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koen Vandeputte X-Patchwork-Id: 10750589 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-2.web.codeaurora.org (Postfix) with ESMTP id 9EAE01515 for ; Mon, 7 Jan 2019 13:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D2BB28A7A for ; Mon, 7 Jan 2019 13:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81BE828A77; Mon, 7 Jan 2019 13:45:59 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 2825028A77 for ; Mon, 7 Jan 2019 13:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728368AbfAGNp4 (ORCPT ); Mon, 7 Jan 2019 08:45:56 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40067 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728355AbfAGNp4 (ORCPT ); Mon, 7 Jan 2019 08:45:56 -0500 Received: by mail-ed1-f68.google.com with SMTP id g22so911291edr.7 for ; Mon, 07 Jan 2019 05:45:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncentric-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=H/7doH88Idi5Mj1ZDeX/jUMyy4ALq/yqhRpTL/yV0ko=; b=X3zuFDeWy+8epsUMtjXM9hyLwipEBvOZq9Yv7HdvSQ8JaFkuqWw0XtMMk/sqscOvc8 fUdl8WnNSeC74T+J1wGDth2G7WEBglanCYsJCly2uKJyctNTuJQpyQwS2XituqayDEX8 XFfQJv+HqdUBXfI4wO7YZjaAwYjlh+owvmMa/nRgD+0L754LBIg+2AzjY4UfB+JJg06k QvvgZ42stTXp3hl7t0OWUfYUWDDYxHmzn8dyyva5wl1SOG2bhLaEwU1QHDiEJ8dBc05m LpgvFk+SH+20RpSoWtjz4iYPnOV7/b3BqcCVghJKrtPM4hme+KHrF1OP+dRVyoCn36ef jv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H/7doH88Idi5Mj1ZDeX/jUMyy4ALq/yqhRpTL/yV0ko=; b=XZjst6h11I+eILx6UmNOEycZpg4GKrtRAwe6ME50XZS5mNPcDfMVifVA0GdomjVoQ2 6sftZwbPbPEq0eWoZKRQ1O7OS3JdVMzC+K2XAg9kMeGzuVIMGYtfYDINS+V6oCBTk1UJ +TIOhn9pCCq6FAkmM/UgyF/LpjFg8Y4xaE/2CFTaEy2LIyDNdmLMc7vHKvoR3+nPWIYB tPYdj6jM/IDsIv2zPFLLM2fFiEV88126dwbkCYZGRs9p+r3xm+c5rsSoGPvZEGAMDGga q5PmWmJWJnU/8EvU1qYeyXMGb6QIBRW5VMnGqGPD0CNpPu+LpyStyHHOkdtD+Nx2+EIW eELQ== X-Gm-Message-State: AA+aEWb9CZ8BlwjczbtNPxcZvmKfq2BTKLwREM2ewWjuhDQVP1d/FELX k5iAubeZ6gmQHwTjac4Qnzf7aw== X-Google-Smtp-Source: AFSGD/W6sdmsvnX/mA+E2rLxIhpNqS/0Tjf68WiZjIhzptzxG32xwbWNXXyNmcZu6bR4as/hM2KB4A== X-Received: by 2002:aa7:dc51:: with SMTP id g17mr54978919edu.115.1546868754215; Mon, 07 Jan 2019 05:45:54 -0800 (PST) Received: from kvdp-BRIX.cmb.citymesh.com ([91.179.126.85]) by smtp.gmail.com with ESMTPSA id n18-v6sm14017427ejy.17.2019.01.07.05.45.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 05:45:53 -0800 (PST) From: Koen Vandeputte To: linux-arm-kernel@lists.infradead.org Cc: linux-pci@vger.kernel.org, Koen Vandeputte , Arnd Bergmann , Bjorn Helgaas , Olof Johansson , Robin Leblon , Rob Herring , Russell King , stable@vger.kernel.org Subject: [PATCH v2 1/2] arm: cns3xxx: fix writing to wrong PCI registers after alignment Date: Mon, 7 Jan 2019 14:45:09 +0100 Message-Id: <20190107134510.32494-1-koen.vandeputte@ncentric.com> X-Mailer: git-send-email 2.17.1 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 Originally, cns3xxx used it's own functions for mapping, reading and writing registers. Commit 802b7c06adc7 ("ARM: cns3xxx: Convert PCI to use generic config accessors") removed the internal PCI config write function in favor of the generic one: cns3xxx_pci_write_config() --> pci_generic_config_write() cns3xxx_pci_write_config() expected aligned addresses, being produced by cns3xxx_pci_map_bus() while the generic one pci_generic_config_write() actually expects the real address as both the function and hardware are capable of byte-aligned writes. This currently leads to pci_generic_config_write() writing to the wrong registers on some ocasions. First issue seen due to this: - driver ath9k gets loaded - The driver wants to write value 0xA8 to register PCI_LATENCY_TIMER, located at 0x0D - cns3xxx_pci_map_bus() aligns the address to 0x0C - pci_generic_config_write() effectively writes 0xA8 into register 0x0C (CACHE_LINE_SIZE) This seems to cause some slight instability when certain PCI devices are used. Another issue example caused by this this is the PCI bus numbering, where the primary bus is higher than the secondary, which is impossible. Before: 00:00.0 PCI bridge: Cavium, Inc. Device 3400 (rev 01) (prog-if 00 [Normal decode]) Flags: bus master, fast devsel, latency 0, IRQ 255 Bus: primary=02, secondary=01, subordinate=ff, sec-latency=0 After fix: 00:00.0 PCI bridge: Cavium, Inc. Device 3400 (rev 01) (prog-if 00 [Normal decode]) Flags: bus master, fast devsel, latency 0, IRQ 255 Bus: primary=00, secondary=01, subordinate=02, sec-latency=0 And very likely some more .. Fix all by omitting the alignment being done in the mapping function. Fixes: 802b7c06adc7 ("ARM: cns3xxx: Convert PCI to use generic config accessors") Acked-by: Krzysztof Halasa Acked-by: Tim Harvey Signed-off-by: Koen Vandeputte CC: Arnd Bergmann CC: Bjorn Helgaas CC: Olof Johansson CC: Robin Leblon CC: Rob Herring CC: Russell King CC: stable@vger.kernel.org # v4.0+ Acked-by: Arnd Bergmann --- arch/arm/mach-cns3xxx/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) V2: --> resend to be in sync with new second patch --> added acked-by's based on patch comments diff --git a/arch/arm/mach-cns3xxx/pcie.c b/arch/arm/mach-cns3xxx/pcie.c index 318394ed5c7a..5e11ad3164e0 100644 --- a/arch/arm/mach-cns3xxx/pcie.c +++ b/arch/arm/mach-cns3xxx/pcie.c @@ -83,7 +83,7 @@ static void __iomem *cns3xxx_pci_map_bus(struct pci_bus *bus, } else /* remote PCI bus */ base = cnspci->cfg1_regs + ((busno & 0xf) << 20); - return base + (where & 0xffc) + (devfn << 12); + return base + where + (devfn << 12); } static int cns3xxx_pci_read_config(struct pci_bus *bus, unsigned int devfn, From patchwork Mon Jan 7 13:45:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koen Vandeputte X-Patchwork-Id: 10750587 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-2.web.codeaurora.org (Postfix) with ESMTP id D377513B4 for ; Mon, 7 Jan 2019 13:45:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0EF428A7A for ; Mon, 7 Jan 2019 13:45:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B344728A7E; Mon, 7 Jan 2019 13:45:58 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 F031928A7A for ; Mon, 7 Jan 2019 13:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728378AbfAGNp5 (ORCPT ); Mon, 7 Jan 2019 08:45:57 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36058 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728364AbfAGNp5 (ORCPT ); Mon, 7 Jan 2019 08:45:57 -0500 Received: by mail-ed1-f67.google.com with SMTP id f23so930850edb.3 for ; Mon, 07 Jan 2019 05:45:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncentric-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b2DAOrsaqCpd7/c8SqsFrjOiq3UmHX0O+L9w4u3BsTM=; b=jenRUwhyHvUWELIvIH+8BYorQ0IClHpOHqijBtjNPwjd5zYHPLoxKBuyGMbWIXUuA+ YDH+9xih6RaHmuPbHGYPQDqXvJLbCyo+Jruc8QGAW11FfjEcwfPeC28bhCgKDuQZtDuD lAnQwB1DcB4fs5ts/UB9RXYYQnb3liquKTJj4NTQOXVJChg8T4Cgk5GdUzKxwZmSRz4G 8UzjOQ4exCXjo/bcCvK4rNAetCfLx/xDE1e5ldO69DqU0iJDCm3oj5LQT0DXkeGRcnvB Cc+SVqXwcLgkPq5gJKq2pbF1gcPb5eOwS+TyQScfS12yOuhzgMNSwXRawygQO/Ktq45w o4VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b2DAOrsaqCpd7/c8SqsFrjOiq3UmHX0O+L9w4u3BsTM=; b=fz7CFt2k1pao2z9OvCvSYDx2Tfp+T1amXrTgqEh9+WBl7UT5R9Njs0XKgRMbLamCee ZEZmT28kADQtdkeXnShARPp4R4ZJO7CQXSFP2bRN8oQergMfxfHSIEccJeChUhCbBYnK JsbPqUV/REQj7MhDixpq3MeldX2psAHpCAwWKeENBCvCIevuyRbBgjZ3yyc/a3k12E0W QjC55xQbKhWpp2xTOCgj2a8kfP1GGQTraDrIAvW9Zccoh40KlXVOsAJtdJn0ERK5/K2r l1ibzOD8t81NuGMDarQovM4tUAHQ8zW5fshsVj5GrAgBI97kKm3+RstZMJM6GFpo/INy TtAQ== X-Gm-Message-State: AJcUuke8L4L68cxvBybm9YKnYK1fphUswEVGXXUtsn20RkuLnaGozfKQ bT/7VKfkklKsZkptYTkvMOAlduhaYpU= X-Google-Smtp-Source: ALg8bN6G5eKBh+PZUJ6qp7Q7aqCNOoPkrOuvt4eUW7pAr0qgzvCo5/nNidyT0WQ/OjRF1KxI+fq2fg== X-Received: by 2002:a17:906:938e:: with SMTP id l14-v6mr11121227ejx.246.1546868755214; Mon, 07 Jan 2019 05:45:55 -0800 (PST) Received: from kvdp-BRIX.cmb.citymesh.com ([91.179.126.85]) by smtp.gmail.com with ESMTPSA id n18-v6sm14017427ejy.17.2019.01.07.05.45.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 05:45:54 -0800 (PST) From: Koen Vandeputte To: linux-arm-kernel@lists.infradead.org Cc: linux-pci@vger.kernel.org, Koen Vandeputte , Arnd Bergmann , Krzysztof Halasa , Olof Johansson , Robin Leblon , Rob Herring , Russell King , Tim Harvey , stable@vger.kernel.org Subject: [PATCH v2 2/2] arm: cns3xxx: use actual size reads for PCIe Date: Mon, 7 Jan 2019 14:45:10 +0100 Message-Id: <20190107134510.32494-2-koen.vandeputte@ncentric.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190107134510.32494-1-koen.vandeputte@ncentric.com> References: <20190107134510.32494-1-koen.vandeputte@ncentric.com> 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 commit 802b7c06adc7 ("ARM: cns3xxx: Convert PCI to use generic config accessors") reimplemented cns3xxx_pci_read_config() using pci_generic_config_read32(), which preserved the property of only doing 32-bit reads. It also replaced cns3xxx_pci_write_config() with pci_generic_config_write(), so it changed writes from always being 32 bits to being the actual size, which works just fine. Due to: - The documentation does not mention that only 32 bit access is allowed. - Writes are already executed using the actual size - Extensive testing shows that 8b, 16b and 32b reads work as intended It makes perfectly sense to also swap 32 bit reading in favor of actual size. Fixes: 802b7c06adc7 ("ARM: cns3xxx: Convert PCI to use generic config accessors") Suggested-by: Bjorn Helgaas Signed-off-by: Koen Vandeputte CC: Arnd Bergmann CC: Krzysztof Halasa CC: Olof Johansson CC: Robin Leblon CC: Rob Herring CC: Russell King CC: Tim Harvey CC: stable@vger.kernel.org # v4.0+ Acked-by: Krzysztof Halasa Acked-by: Krzysztof Halasa --- arch/arm/mach-cns3xxx/pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-cns3xxx/pcie.c b/arch/arm/mach-cns3xxx/pcie.c index 5e11ad3164e0..95a11d5b3587 100644 --- a/arch/arm/mach-cns3xxx/pcie.c +++ b/arch/arm/mach-cns3xxx/pcie.c @@ -93,7 +93,7 @@ static int cns3xxx_pci_read_config(struct pci_bus *bus, unsigned int devfn, u32 mask = (0x1ull << (size * 8)) - 1; int shift = (where % 4) * 8; - ret = pci_generic_config_read32(bus, devfn, where, size, val); + ret = pci_generic_config_read(bus, devfn, where, size, val); if (ret == PCIBIOS_SUCCESSFUL && !bus->number && !devfn && (where & 0xffc) == PCI_CLASS_REVISION)