From nobody Thu Sep 18 20:30:53 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BDECC47088 for ; Fri, 2 Dec 2022 16:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233635AbiLBQVx (ORCPT ); Fri, 2 Dec 2022 11:21:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233987AbiLBQVc (ORCPT ); Fri, 2 Dec 2022 11:21:32 -0500 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F9CE3451 for ; Fri, 2 Dec 2022 08:18:51 -0800 (PST) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B28j12l022681; Fri, 2 Dec 2022 10:18:15 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=BE++jpEueF2GegZwNGVzOdbbuVP+vf8cC+Lif4Aj6fo=; b=HYCxCbLPyppYyzeG8rj1vuGq/Oi8jz0GcR93F3L0tdyquAMShqFb+KcSp5yG8SaFoY0S +d1XJMoj0QYbp22CPSSuvFySXrYIGBz2+4q1UWVJgtbCZHmNxJ15IUvZ0ocTFrJnRmpU lEnA34wnsMRUcE11odnTp+LYMZFFt7FZz8DlvxhGgVdaWe46sgxFxw2bCeJu9tGiY6r8 d+Flpv/KrX2Xy70TkqIkn70zop9bvP5g4twd8iQ0n/Bj03FTKqOsOhrEuklF75b1CRDV vnm7QaUsrjkNmMT8cSY1jQvWYeYc1gv0DlEeqlBJEJpa+AoBrgTSsSBrstgH4pkADJsc bg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3m6k2vt0n6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Dec 2022 10:18:14 -0600 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 2 Dec 2022 10:18:12 -0600 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.20 via Frontend Transport; Fri, 2 Dec 2022 10:18:12 -0600 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.111]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 9C556B2F; Fri, 2 Dec 2022 16:18:12 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , , Richard Fitzgerald Subject: [PATCH v2 3/3] soundwire: cadence: Drain the RX FIFO after an IO timeout Date: Fri, 2 Dec 2022 16:18:12 +0000 Message-ID: <20221202161812.4186897-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221202161812.4186897-1-rf@opensource.cirrus.com> References: <20221202161812.4186897-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: JbfrKx6hsDlg3qbXh0BsCbr3l__qe-bI X-Proofpoint-ORIG-GUID: JbfrKx6hsDlg3qbXh0BsCbr3l__qe-bI X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If wait_for_completion_timeout() times-out in _cdns_xfer_msg() it is possible that something could have been written to the RX FIFO. In this case, we should drain the RX FIFO so that anything in it doesn't carry over and mess up the next transfer. Obviously, if we got to this state something went wrong, and we don't really know the state of everything. The cleanup in this situation cannot be bullet-proof but we should attempt to avoid breaking future transaction, if only to reduce the amount of error noise when debugging the failure from a kernel log. Note that this patch only implements the draining for blocking (non-deferred) transfers. The deferred API doesn't have any proper handling of error conditions and would need some re-design before implementing cleanup. That is a task for a separate patch... Signed-off-by: Richard Fitzgerald --- Changes since v1: The change is "the same" but the function that is moved up the file has different content because of changes in patch #2 --- drivers/soundwire/cadence_master.c | 50 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence= _master.c index a6635f7f350e..521387322145 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -555,6 +555,29 @@ cdns_fill_msg_resp(struct sdw_cdns *cdns, return SDW_CMD_OK; } =20 +static void cdns_read_response(struct sdw_cdns *cdns) +{ + u32 num_resp, cmd_base; + int i; + + /* RX_FIFO_AVAIL can be 2 entries more than the FIFO size */ + BUILD_BUG_ON(ARRAY_SIZE(cdns->response_buf) < CDNS_MCP_CMD_LEN + 2); + + num_resp =3D cdns_readl(cdns, CDNS_MCP_FIFOSTAT); + num_resp &=3D CDNS_MCP_RX_FIFO_AVAIL; + if (num_resp > ARRAY_SIZE(cdns->response_buf)) { + dev_warn(cdns->dev, "RX AVAIL %d too long\n", num_resp); + num_resp =3D ARRAY_SIZE(cdns->response_buf); + } + + cmd_base =3D CDNS_MCP_CMD_BASE; + + for (i =3D 0; i < num_resp; i++) { + cdns->response_buf[i] =3D cdns_readl(cdns, cmd_base); + cmd_base +=3D CDNS_MCP_CMD_WORD_LEN; + } +} + static enum sdw_command_response _cdns_xfer_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int cmd, int offset, int count, bool defer) @@ -596,6 +619,10 @@ _cdns_xfer_msg(struct sdw_cdns *cdns, struct sdw_msg *= msg, int cmd, dev_err(cdns->dev, "IO transfer timed out, cmd %d device %d addr %x len = %d\n", cmd, msg->dev_num, msg->addr, msg->len); msg->len =3D 0; + + /* Drain anything in the RX_FIFO */ + cdns_read_response(cdns); + return SDW_CMD_TIMEOUT; } =20 @@ -769,29 +796,6 @@ EXPORT_SYMBOL(cdns_read_ping_status); * IRQ handling */ =20 -static void cdns_read_response(struct sdw_cdns *cdns) -{ - u32 num_resp, cmd_base; - int i; - - /* RX_FIFO_AVAIL can be 2 entries more than the FIFO size */ - BUILD_BUG_ON(ARRAY_SIZE(cdns->response_buf) < CDNS_MCP_CMD_LEN + 2); - - num_resp =3D cdns_readl(cdns, CDNS_MCP_FIFOSTAT); - num_resp &=3D CDNS_MCP_RX_FIFO_AVAIL; - if (num_resp > ARRAY_SIZE(cdns->response_buf)) { - dev_warn(cdns->dev, "RX AVAIL %d too long\n", num_resp); - num_resp =3D ARRAY_SIZE(cdns->response_buf); - } - - cmd_base =3D CDNS_MCP_CMD_BASE; - - for (i =3D 0; i < num_resp; i++) { - cdns->response_buf[i] =3D cdns_readl(cdns, cmd_base); - cmd_base +=3D CDNS_MCP_CMD_WORD_LEN; - } -} - static int cdns_update_slave_status(struct sdw_cdns *cdns, u64 slave_intstat) { --=20 2.30.2