Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp970471rdb; Fri, 1 Dec 2023 03:50:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6l/8KKlPTwgoHgT7RUJ3S0ApBX9453vMUwnkO2O8+ycsb1dpzLbRAkUNw1FzEbPDCh2WS X-Received: by 2002:a17:90b:3882:b0:285:9d3f:cca8 with SMTP id mu2-20020a17090b388200b002859d3fcca8mr26773437pjb.26.1701431456765; Fri, 01 Dec 2023 03:50:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701431456; cv=none; d=google.com; s=arc-20160816; b=YrJmfz6MaAEvMPmHa+dyH58efbGM9lNeTECecm6WAAf7x80LO/EMFAiJJEUFyxSQUO tqqIxL9EXasjVPH2bfST3BQCIq+PbtdTjyMfezeK8gsox80QwrpAeQ8tl9KYgVGyN8ty g+unwB3WmgAFUIg+uMtfLIRb+rxIso4EudnqhlK1yB4oBwbJ51PlIuyIIBercTUPGWBF ATPWzBGl/z8GWEuKGIg/0s8ZRNHnK27ovl+VJcrow8iy0H9AfsYbOuha5/R+vT5b+8LI tSH+/lBgGLvobQ3ZJQ96/v2oueatBXZdHS2vOh8nDBGkL/Dpkj/t0d/Qy6bxT0lU/tJo abaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=jXjXrL2mgtAhGYKgcBP0Wx2CKz797XazsgwROZ/jzWY=; fh=ty5JuqHk0Qk00XZ6GNb8HL58/5b15pyqC9qpwOjFr1E=; b=fSRC3dvzXJ1qavvRxc2nNhUsMZylmp7KQ5/bd3WjCCn+QwMTv1KU424Wzs4Booe0Xv FDaSr0QbcSmY0PrBGTrr1EiI+PIPoT9VdPS1YlqJOZHq1+n859TUr+VsbfBS91+xfkLe SgVPg+bFPyxwHgc8vvsblsJkfM0mnt/OUpH2oEWLKrWQ7SyuK/a4d4zzcYemvhS3FPF3 CyxBtn+TJ0hn9MwzLsXHIVS/0yQ93MgWB0qBFoyDxKHv34LZN+yCqgcGHOBpRl5R8k5m s7AM3Hmb3zyYarO1RAZA8kvpOMiTDCyVd158rcZ2ZuVFwXFd77E2/MtG7YEGNwoBbN72 kBNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm2 header.b=e8G17xEo; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=jgqH76Jo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c24-20020a17090abf1800b00285ab9d7408si5354583pjs.29.2023.12.01.03.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 03:50:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm2 header.b=e8G17xEo; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=jgqH76Jo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9368480F7E73; Fri, 1 Dec 2023 03:50:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378614AbjLALuf (ORCPT + 99 others); Fri, 1 Dec 2023 06:50:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378585AbjLALue (ORCPT ); Fri, 1 Dec 2023 06:50:34 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E3D1704; Fri, 1 Dec 2023 03:50:40 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.west.internal (Postfix) with ESMTP id 9013F3200AAB; Fri, 1 Dec 2023 06:50:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 01 Dec 2023 06:50:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to; s=fm2; t=1701431437; x=1701517837; bh=jXjXrL2mgt AhGYKgcBP0Wx2CKz797XazsgwROZ/jzWY=; b=e8G17xEobyMa27KHIIvZPT+i3q ooQo9Ob5ml8IvuHuMaiOjmdZJWtDpLoObh/z4XeAUuX4QpekUR4PdEhdzOH1lgA+ d7rv5c12frW4M4qC4C9Xae2n70cwYrOhWJ/ISev2px5xINy6nxJxzxqVE1kU5H0s RN+FB4CmaubnOxE4NGUiY1ZgliXRhdYC8C8aVGD6jBMZ3Tmpdjr9pQsbtbKt1jsn +6G9LHN1E4MPCFIo7pfqtnAQktEsue+vn3DGKaLU1r0tVZYtoNPIk3Gp/jAMD3+V i9FpFAgsfkcm33Mu89tOfcf1LtoBl6rYQ2lhzr7bedzT9+wF7mO0+ss5hloA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1701431437; x=1701517837; bh=jXjXrL2mgtAhG YKgcBP0Wx2CKz797XazsgwROZ/jzWY=; b=jgqH76Jo0tfYlS3yw0FTrrlf+LqiO wvQVWEUDB6YAP2RA+PrxAyxt7rTB4jjEzERSkAeJdeuWjDviPwB+BpTxjjKYJyOV efjfNmqT4Fudi9n/dyBNE5W+7ADEUFHWxpIgG8xHhyppGjItCdwLw16m1NXshg6H QEzDjoMetGdzdTtn7wYNdPIRQp85q9AZTaDRqE2Zk8xws4Hxv8NcfbYOwvywY+7g OGBQ8kaytY7dOj64y1WJ5au/2D4KdkrFpPt5vHNCLjd/h4UxtQWgDlR64tMhZSPi 5hAlpuDL0z20lSNA7x4wiw5nBSyTD75ZziW/X9ohbw7E/EvIxc7BhjPBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeiledgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghes fhhlhihgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdeuteekleeuudfgueethe dtuddthfdtleffgefhieehfeeigedvtdeuveetiedunecuffhomhgrihhnpehkvghrnhgv lhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjihgrgihunhdrhigrnhhgsehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Dec 2023 06:50:35 -0500 (EST) From: Jiaxun Yang To: linux-pci@vger.kernel.org Cc: lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, linux-kernel@vger.kernel.org, chenhuacai@kernel.org, Jiaxun Yang , stable@vger.kernel.org Subject: [PATCH v6] pci: loongson: Workaround MIPS firmware MRRS settings Date: Fri, 1 Dec 2023 11:50:28 +0000 Message-Id: <20231201115028.84351-1-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 01 Dec 2023 03:50:49 -0800 (PST) This is a partial revert of commit 8b3517f88ff2 ("PCI: loongson: Prevent LS7A MRRS increases") for MIPS based Loongson. There are many MIPS based Loongson systems in wild that shipped with firmware which does not set maximum MRRS properly. Limiting MRRS to 256 for all as MIPS Loongson comes with higher MRRS support is considered rare. It must be done at device enablement stage because MRRS setting may get lost if the parent bridge lost PCI_COMMAND_MASTER, and we are only sure parent bridge is enabled at this point. Cc: stable@vger.kernel.org Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217680 Fixes: 8b3517f88ff2 ("PCI: loongson: Prevent LS7A MRRS increases") Signed-off-by: Jiaxun Yang --- v4: Improve commit message v5: - Improve commit message and comments. - Style fix from Huacai's off-list input. v6: Fix a typo --- drivers/pci/controller/pci-loongson.c | 47 ++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/pci/controller/pci-loongson.c b/drivers/pci/controller/pci-loongson.c index d45e7b8dc530..e181d99decf1 100644 --- a/drivers/pci/controller/pci-loongson.c +++ b/drivers/pci/controller/pci-loongson.c @@ -80,13 +80,50 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LOONGSON, DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LOONGSON, DEV_LS7A_LPC, system_bus_quirk); +/* + * Some Loongson PCIe ports have h/w limitations of maximum read + * request size. They can't handle anything larger than this. + * Sane firmware will set proper MRRS at boot, so we only need + * no_inc_mrrs for bridges. However, some MIPS Loongson firmware + * won't set MRRS properly, and we have to enforce maximum safe + * MRRS, which is 256 bytes. + */ +#ifdef CONFIG_MIPS +static void loongson_set_min_mrrs_quirk(struct pci_dev *pdev) +{ + struct pci_bus *bus = pdev->bus; + struct pci_dev *bridge; + static const struct pci_device_id bridge_devids[] = { + { PCI_VDEVICE(LOONGSON, DEV_LS2K_PCIE_PORT0) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT0) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT1) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT2) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT3) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT4) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT5) }, + { PCI_VDEVICE(LOONGSON, DEV_LS7A_PCIE_PORT6) }, + { 0, }, + }; + + /* look for the matching bridge */ + while (!pci_is_root_bus(bus)) { + bridge = bus->self; + bus = bus->parent; + + if (pci_match_id(bridge_devids, bridge)) { + if (pcie_get_readrq(pdev) > 256) { + pci_info(pdev, "limiting MRRS to 256\n"); + pcie_set_readrq(pdev, 256); + } + break; + } + } +} +DECLARE_PCI_FIXUP_ENABLE(PCI_ANY_ID, PCI_ANY_ID, loongson_set_min_mrrs_quirk); +#endif + static void loongson_mrrs_quirk(struct pci_dev *pdev) { - /* - * Some Loongson PCIe ports have h/w limitations of maximum read - * request size. They can't handle anything larger than this. So - * force this limit on any devices attached under these ports. - */ struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); bridge->no_inc_mrrs = 1; -- 2.34.1