From patchwork Wed Dec 20 02:58:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 181432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2383290dyi; Tue, 19 Dec 2023 19:00:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhfNeQN97Ffj6X+vjnoM4IaxoU/nCi030ulVwc3pHA6zeFYQGu4gd1CPGOy5U70gzNN72k X-Received: by 2002:a2e:b888:0:b0:2cc:1c1c:c71c with SMTP id r8-20020a2eb888000000b002cc1c1cc71cmr8585450ljp.38.1703041205353; Tue, 19 Dec 2023 19:00:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703041205; cv=none; d=google.com; s=arc-20160816; b=HaO8JR6F12qJpfLBZBqss/tRoU8ARI12Nm/XE+i2X6Wi43mOUQyqfSjIGH6JnGrfQQ SI/UefF8WkykWoHrAkFC3kQ/SNh8YFaF7y/0mf1AMtzNlfPrlFjFo8yiDKX0btdlHC53 E53h+2mHqXh0EWyxb01Q5rSyKz8JtooD4SQeU5Enf+rJAVKtnUt0bTkSGvSmKj2ewM7x pPLf+MOKJO9HijJKtUdl004yd3gfxZKJngeIu7lhWrKS4pVEy+9UvJniRgfrrVt5LgG5 ZGgSyXOUAGWmIEzmzkwpJpQqXh3Pjs+aZvqe1UaWPNjCOnh/Ivjizfx9Ayvw3pMQ59H7 jLzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UuaEiQrOZqEYIrIdQpFz4PXcES/VN7uGDo+/eQ9bITI=; fh=N1RoyDnfCjDcHZogd/weDTGIEHhYAEffB1Vxjm06lzc=; b=TSv43iX/cb15f9fhiev3MR4CQJ3nImobmJss9G4XkQ9h+GbAjcIg+pRKzPaRQeqRDL TlA5Z38I/NtiWq2yYyLtegdvXEJ7TbR1hS4SthNkpClB39SwCgNDZdbl5hozmIb8F1po pdil4wP1TP4qpfpzCzCJFFKrPlW0+P9axKGK31MlJXQ6GhGCk6vd6xlKqRo+3shqyzhz xSheQepPOFZOvoUwn4VfWLQRwP/3K0IcHELywFBbVd9seKfpFWxDh4Hj5JrBRXyke0u1 +X2b0jxUGz/9ap2XBPnA990PwoAK1mx12CTLGO1Hx4aiSEKJeT6f+BY+EV2GffW2G9+c C79g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=JdzZO7mg; spf=pass (google.com: domain of linux-kernel+bounces-6306-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6306-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z4-20020a056402274400b0055293148185si1281858edd.369.2023.12.19.19.00.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 19:00:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6306-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=JdzZO7mg; spf=pass (google.com: domain of linux-kernel+bounces-6306-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6306-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C78881F261F1 for ; Wed, 20 Dec 2023 03:00:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7760714A9E; Wed, 20 Dec 2023 02:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="JdzZO7mg" X-Original-To: linux-kernel@vger.kernel.org Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB0B4881F; Wed, 20 Dec 2023 02:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: b13f2bc69ee311eea5db2bebc7c28f94-20231220 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=UuaEiQrOZqEYIrIdQpFz4PXcES/VN7uGDo+/eQ9bITI=; b=JdzZO7mgthSOjs0OjUjjqz9BmaubqRqUqGXQ1ERmRAHSD0Rhv3vsIJnM45yOmbzmHvtmNB41nh5jL8SJUemFZbADju8Hboma6dYniO+LZuD7JrxNEufCZua3v2TL/x7v8iB2bUfOhArcc8rBLRiYd1LGTTB+Mx7lxcvagbJY0QE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:660320a7-6806-4be6-8c86-927c5e66b55b,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:5d391d7,CLOUDID:5f5be117-1474-414b-9c9f-6d23a122e796,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: b13f2bc69ee311eea5db2bebc7c28f94-20231220 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1610279839; Wed, 20 Dec 2023 10:58:46 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 20 Dec 2023 10:58:45 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 20 Dec 2023 10:58:44 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , AngeloGioacchino Del Regno CC: Chunfeng Yun , Conor Dooley , Matthias Brugger , Mathias Nyman , , , , , , Eddie Hung , Macpaul Lin , Subject: [PATCH v3 2/3] usb: xhci-mtk: fix a short packet issue of gen1 isoc-in transfer Date: Wed, 20 Dec 2023 10:58:41 +0800 Message-ID: <20231220025842.7082-2-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231220025842.7082-1-chunfeng.yun@mediatek.com> References: <20231220025842.7082-1-chunfeng.yun@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785768134895724220 X-GMAIL-MSGID: 1785768134895724220 For Gen1 isoc-in transfer, host still send out unexpected ACK after device finish the burst with a short packet, this will cause an exception on the connected device, such as, a usb 4k camera. It can be fixed by setting rxfifo depth less than 4k bytes, prefer to use 3k here, the side-effect is that may cause performance drop about 10%, including bulk transfer. Fixes: 926d60ae64a6 ("usb: xhci-mtk: modify the SOF/ITP interval for mt8195") Cc: stable@vger.kernel.org Signed-off-by: Chunfeng Yun Reviewed-by: AngeloGioacchino Del Regno --- v3: add Cc stable change @rxfifo_depth from int to u32, due to property's value range is changed v2: use 'rx-fifo-depth' property; add header file 'linux/bitfield.h' to avoid building error on some ARCH; --- drivers/usb/host/xhci-mtk.c | 37 +++++++++++++++++++++++++++++++++++-- drivers/usb/host/xhci-mtk.h | 2 ++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c index bbdf1b0b7be1..868793b82348 100644 --- a/drivers/usb/host/xhci-mtk.c +++ b/drivers/usb/host/xhci-mtk.c @@ -7,6 +7,7 @@ * Chunfeng Yun */ +#include #include #include #include @@ -73,6 +74,9 @@ #define FRMCNT_LEV1_RANG (0x12b << 8) #define FRMCNT_LEV1_RANG_MASK GENMASK(19, 8) +#define HSCH_CFG1 0x960 +#define SCH3_RXFIFO_DEPTH_MASK GENMASK(21, 20) + #define SS_GEN2_EOF_CFG 0x990 #define SSG2EOF_OFFSET 0x3c @@ -165,6 +169,34 @@ static void xhci_mtk_set_frame_interval(struct xhci_hcd_mtk *mtk) writel(value, hcd->regs + SS_GEN2_EOF_CFG); } +/* + * workaround: usb3.2 gen1 isoc rx hw issue + * host send out unexpected ACK afer device fininsh a burst transfer with + * a short packet. + */ +static void xhci_mtk_rxfifo_depth_set(struct xhci_hcd_mtk *mtk) +{ + struct usb_hcd *hcd = mtk->hcd; + u32 value; + + if (!mtk->rxfifo_depth) + return; + + value = readl(hcd->regs + HSCH_CFG1); + value &= ~SCH3_RXFIFO_DEPTH_MASK; + value |= FIELD_PREP(SCH3_RXFIFO_DEPTH_MASK, mtk->rxfifo_depth - 1); + writel(value, hcd->regs + HSCH_CFG1); +} + +static void xhci_mtk_init_quirk(struct xhci_hcd_mtk *mtk) +{ + /* workaround only for mt8195 */ + xhci_mtk_set_frame_interval(mtk); + + /* workaround for SoCs using SSUSB about before IPM v1.6.0 */ + xhci_mtk_rxfifo_depth_set(mtk); +} + static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk) { struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; @@ -448,8 +480,7 @@ static int xhci_mtk_setup(struct usb_hcd *hcd) if (ret) return ret; - /* workaround only for mt8195 */ - xhci_mtk_set_frame_interval(mtk); + xhci_mtk_init_quirk(mtk); } ret = xhci_gen_setup(hcd, xhci_mtk_quirks); @@ -527,6 +558,8 @@ static int xhci_mtk_probe(struct platform_device *pdev) of_property_read_u32(node, "mediatek,u2p-dis-msk", &mtk->u2p_dis_msk); + of_property_read_u32(node, "rx-fifo-depth", &mtk->rxfifo_depth); + ret = usb_wakeup_of_property_parse(mtk, node); if (ret) { dev_err(dev, "failed to parse uwk property\n"); diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h index 39f7ae7d3087..f5e2bd66bb1b 100644 --- a/drivers/usb/host/xhci-mtk.h +++ b/drivers/usb/host/xhci-mtk.h @@ -171,6 +171,8 @@ struct xhci_hcd_mtk { struct regmap *uwk; u32 uwk_reg_base; u32 uwk_vers; + /* quirk */ + u32 rxfifo_depth; }; static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)