From patchwork Tue Apr 8 17:14:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 3950081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 699B49F499 for ; Tue, 8 Apr 2014 17:15:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94D642040F for ; Tue, 8 Apr 2014 17:15:52 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62730203B7 for ; Tue, 8 Apr 2014 17:15:51 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXZc1-0007nW-Pn; Tue, 08 Apr 2014 17:15:06 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXZbj-000226-KM; Tue, 08 Apr 2014 17:14:53 +0000 Received: from quartz.orcorp.ca ([184.70.90.242]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXZbf-00020z-Lk for linux-arm-kernel@lists.infradead.org; Tue, 08 Apr 2014 17:14:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=yXlOH7kgfwQE/e2ifuy5yb3yGUhN+KmcH+/NEHeWV2g=; b=PMQ0JXQlV+A0Nc/6UPRTkYsAWxoWhKvgapIsgwfVyxI3VS6SwCE2qQC5lDOcd5eZIZ9DWF/UGtITFPT7prVyC2ji48cVQ8mNgUgIkklEUANy12faRE4i5lU9BvgR0z/CF+H9E7H2hJRPEOOv23/7gTr66yYjxMHuBEH3+PDBqP8=; Received: from [10.0.0.161] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1WXZbF-0004Yl-Fc; Tue, 08 Apr 2014 11:14:17 -0600 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.80) (envelope-from ) id 1WXZbF-0008Ha-3B; Tue, 08 Apr 2014 11:14:17 -0600 Date: Tue, 8 Apr 2014 11:14:17 -0600 From: Jason Gunthorpe To: Thomas Petazzoni Subject: Re: Intel I350 mini-PCIe card (igb) on Mirabox (mvebu / Armada 370) Message-ID: <20140408171417.GB27776@obsidianresearch.com> References: <20140327044054.GA22681@obsidianresearch.com> <20140405193435.50d8dd81@skate> <54BB31A2B04145E8908E0183FAB6B61B@fatboyfat.co.uk> <20140408171309.09bbf968@skate> <20140408174034.79df403e@skate> <20140408175545.1b4d55a5@skate> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140408175545.1b4d55a5@skate> User-Agent: Mutt/1.5.21 (2010-09-15) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.161 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140408_131443_860376_768F8023 X-CRM114-Status: GOOD ( 17.22 ) X-Spam-Score: -2.0 (--) Cc: Neil Greatorex , Matthew Minter , Willy Tarreau , linux-arm-kernel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 On Tue, Apr 08, 2014 at 05:55:45PM +0200, Thomas Petazzoni wrote: > mvebu-mbus/devices output: > > # cat /sys/kernel/debug/mvebu-mbus/devices > [10] 00000000e0000000 - 00000000e0900000 : 0004:00e8 > I'm not sure why I don't have the non-power-of-two problem for the MBus > windows. Well, you do, 0x900000 is not aligned. It converts to size=0b10001111, which is undefined behavior for mbus. It looks like you are lucky, for your system the undefined behavior creates a window that hits all the BARs, but the others were not so lucky. What do you think about this: From 235b0bf637242a50ec45c8766d18a942bff601cf Mon Sep 17 00:00:00 2001 From: Jason Gunthorpe Date: Tue, 8 Apr 2014 11:12:41 -0600 Subject: [PATCH] bus: mvebu-mbus: Avoid setting an undefined window size The mbus hardware requires a power of two size, if a non-power of two is passed in to the low level routines they configure the register in a way that results in undefined behaviour. - WARN_ON to make this invalid usage really obvious - Round down to the nearest power of two so we only stuff a valid size into the HW - When reading interpret undefined values in a conservative way, the value is assumed to be the lowest power of two. This avoids the debugfs output showing a value that looks 'correct' All together this makes the recent problems with silent failure of PCI very obvious, noisy and debuggable. Signed-off-by: Jason Gunthorpe --- drivers/bus/mvebu-mbus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c index 2ac754e..d26f63c 100644 --- a/drivers/bus/mvebu-mbus.c +++ b/drivers/bus/mvebu-mbus.c @@ -56,6 +56,7 @@ #include #include #include +#include /* * DDR target is the same on all platforms. @@ -147,7 +148,7 @@ static void mvebu_mbus_read_window(struct mvebu_mbus_state *mbus, *enabled = 1; *base = ((u64)basereg & WIN_BASE_HIGH) << 32; *base |= (basereg & WIN_BASE_LOW); - *size = (ctrlreg | ~WIN_CTRL_SIZE_MASK) + 1; + *size = 1 << (ffs(~(ctrlreg | ~WIN_CTRL_SIZE_MASK)) - 1); if (target) *target = (ctrlreg & WIN_CTRL_TGT_MASK) >> WIN_CTRL_TGT_SHIFT; @@ -266,6 +267,9 @@ static int mvebu_mbus_setup_window(struct mvebu_mbus_state *mbus, mbus->soc->win_cfg_offset(win); u32 ctrl, remap_addr; + WARN_ON(!is_power_of_2(size)); + size = rounddown_pow_of_two(size); + ctrl = ((size - 1) & WIN_CTRL_SIZE_MASK) | (attr << WIN_CTRL_ATTR_SHIFT) | (target << WIN_CTRL_TGT_SHIFT) |