From nobody Tue Apr 7 18:13:26 2026 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 496A5C04AA5 for ; Thu, 25 Aug 2022 12:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241637AbiHYMXH (ORCPT ); Thu, 25 Aug 2022 08:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241575AbiHYMW7 (ORCPT ); Thu, 25 Aug 2022 08:22:59 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C24FB14CC for ; Thu, 25 Aug 2022 05:22:58 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27P5j0L7027893; Thu, 25 Aug 2022 07:22:44 -0500 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=qM/4I4xQgYXa3nyrRPcPpQ8yR5SdWsQYKAd17M1tkEg=; b=piPYpx05qSWjLqY5CZUkX5Tp6LkOqZU0nNQgUBiYKYysU9R2QF2e5lyoqZt8uvzjp8/f BY3ujyAqY1ksRfVH3sNRsdxTRSnMNULoHJRkA3dGzv7ExWMf1/ZSlv2AQLcSxAEOS2KG QPf2/VLKjTeW5rPCWeIDxg40JlyS4oQtogI4/97rxnwCqvcvKb02olNv5YphmuOV/9v8 SrSBvzZRb2DCgV5y6n3v6ulC0jz+I6m2Zr3jkNgUP24GYzzI75Pnhr8dTWItDXMRKVgk LXelENXRgpesPKDChwrb24+Bd2+v+mFsV3X/YrMeb044kAchiQniGQ2uIqJUOrRh9lC5 sg== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3j4dgmbu3q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 07:22:44 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Thu, 25 Aug 2022 07:22:41 -0500 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.9 via Frontend Transport; Thu, 25 Aug 2022 07:22:41 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.95]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 97D7BB10; Thu, 25 Aug 2022 12:22:41 +0000 (UTC) From: Richard Fitzgerald To: , , , CC: , , , Simon Trimmer , Richard Fitzgerald Subject: [PATCH 1/3] soundwire: cadence: fix updating slave status when a bus has multiple peripherals Date: Thu, 25 Aug 2022 13:22:39 +0100 Message-ID: <20220825122241.273090-2-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825122241.273090-1-rf@opensource.cirrus.com> References: <20220825122241.273090-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: qQlJqhbI9BKDInlrStq1RBsORrO6ZASc X-Proofpoint-GUID: qQlJqhbI9BKDInlrStq1RBsORrO6ZASc X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Simon Trimmer The cadence IP explicitly reports slave status changes with bits for each possible change. The function cdns_update_slave_status() attempts to translate this into the current status of each of the slaves. However when there are multiple peripherals on a bus any slave that did not have a status change when the work function ran would not have it's status updated - the array is initialised to a value that equates to UNATTACHED and this can cause spurious reports that slaves had dropped off the bus. In the case where a slave has no status change or has multiple status changes the value from the last PING command is used. Signed-off-by: Simon Trimmer Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/cadence_master.c | 63 +++++++++++++----------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence= _master.c index 4fbb19557f5e..245191d22ccd 100644 --- a/drivers/soundwire/cadence_master.c +++ b/drivers/soundwire/cadence_master.c @@ -782,6 +782,7 @@ static int cdns_update_slave_status(struct sdw_cdns *cd= ns, enum sdw_slave_status status[SDW_MAX_DEVICES + 1]; bool is_slave =3D false; u32 mask; + u32 val; int i, set_status; =20 memset(status, 0, sizeof(status)); @@ -789,41 +790,38 @@ static int cdns_update_slave_status(struct sdw_cdns *= cdns, for (i =3D 0; i <=3D SDW_MAX_DEVICES; i++) { mask =3D (slave_intstat >> (i * CDNS_MCP_SLAVE_STATUS_NUM)) & CDNS_MCP_SLAVE_STATUS_BITS; - if (!mask) - continue; =20 - is_slave =3D true; set_status =3D 0; =20 - if (mask & CDNS_MCP_SLAVE_INTSTAT_RESERVED) { - status[i] =3D SDW_SLAVE_RESERVED; - set_status++; + if (mask) { + is_slave =3D true; + + if (mask & CDNS_MCP_SLAVE_INTSTAT_RESERVED) { + status[i] =3D SDW_SLAVE_RESERVED; + set_status++; + } + + if (mask & CDNS_MCP_SLAVE_INTSTAT_ATTACHED) { + status[i] =3D SDW_SLAVE_ATTACHED; + set_status++; + } + + if (mask & CDNS_MCP_SLAVE_INTSTAT_ALERT) { + status[i] =3D SDW_SLAVE_ALERT; + set_status++; + } + + if (mask & CDNS_MCP_SLAVE_INTSTAT_NPRESENT) { + status[i] =3D SDW_SLAVE_UNATTACHED; + set_status++; + } } =20 - if (mask & CDNS_MCP_SLAVE_INTSTAT_ATTACHED) { - status[i] =3D SDW_SLAVE_ATTACHED; - set_status++; - } - - if (mask & CDNS_MCP_SLAVE_INTSTAT_ALERT) { - status[i] =3D SDW_SLAVE_ALERT; - set_status++; - } - - if (mask & CDNS_MCP_SLAVE_INTSTAT_NPRESENT) { - status[i] =3D SDW_SLAVE_UNATTACHED; - set_status++; - } - - /* first check if Slave reported multiple status */ - if (set_status > 1) { - u32 val; - - dev_warn_ratelimited(cdns->dev, - "Slave %d reported multiple Status: %d\n", - i, mask); - - /* check latest status extracted from PING commands */ + /* + * check that there was a single reported Slave status and when + * there is not use the latest status extracted from PING commands + */ + if (set_status !=3D 1) { val =3D cdns_readl(cdns, CDNS_MCP_SLAVE_STAT); val >>=3D (i * 2); =20 @@ -842,11 +840,6 @@ static int cdns_update_slave_status(struct sdw_cdns *c= dns, status[i] =3D SDW_SLAVE_RESERVED; break; } - - dev_warn_ratelimited(cdns->dev, - "Slave %d status updated to %d\n", - i, status[i]); - } } =20 --=20 2.30.2 From nobody Tue Apr 7 18:13:26 2026 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 0DBA8C04AA5 for ; Thu, 25 Aug 2022 12:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241635AbiHYMXE (ORCPT ); Thu, 25 Aug 2022 08:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241454AbiHYMW7 (ORCPT ); Thu, 25 Aug 2022 08:22:59 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9ACE0AE9ED for ; Thu, 25 Aug 2022 05:22:58 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27P5nj9d003635; Thu, 25 Aug 2022 07:22:45 -0500 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=F89FFReRi1zqDj//baBjB5HIEbobACoV3vAIIeNB3ec=; b=hZdnWo58dExaHs8WhdAWFx8hNyyvGy8ZRmqBNWX6Ja6iGhDzHPZimIZuHoAjfcG56gZo 5QzsBl2t8x13BruiFYft9FQHXkkba1PuA4HRJ2Q6qKKj64OiU9TVz0WoYWkQctBOLsrn f3S/2mLBMGltzUVcXxRTDZ/B6pHQe333GCg+lrXPLxdLOI1t3xOm/txUHEm1zeb+MEs2 NGc7D8dCMNhEEZfqBGo1AigbJKKG+qPu+ywB+GdvzHV8WTiHgPJM+xXSewNMzOhOUurB P5LxKySA55kvgH31fvT6qsgE4UGL6wTYc6phZMdXN+Fok0OkXcnNp1dx+maB6RNtHgAV gw== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3j4dgmbu3r-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 07:22:44 -0500 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.9; Thu, 25 Aug 2022 07:22:41 -0500 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.9 via Frontend Transport; Thu, 25 Aug 2022 07:22:41 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.95]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id AAA18B16; Thu, 25 Aug 2022 12:22:41 +0000 (UTC) From: Richard Fitzgerald To: , , , CC: , , , Richard Fitzgerald Subject: [PATCH 2/3] soundwire: bus: Don't lose unattach notifications Date: Thu, 25 Aug 2022 13:22:40 +0100 Message-ID: <20220825122241.273090-3-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825122241.273090-1-rf@opensource.cirrus.com> References: <20220825122241.273090-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: R4M0MCMXsa_dW2vMEZQ1Wk1YwQqcZd6P X-Proofpoint-GUID: R4M0MCMXsa_dW2vMEZQ1Wk1YwQqcZd6P X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Ensure that if sdw_handle_slave_status() sees a peripheral has dropped off the bus it reports it to the client driver. If there are any devices reporting on address 0 it bails out after programming the device IDs. So it never reaches the second loop that calls sdw_update_slave_status(). If the missing device is one that is now showing as unenumerated it has been given a device ID so will report as attached next time sdw_handle_slave_status() runs. With the previous code the client driver would only see another ATTACHED notification because the UNATTACHED state was lost when sdw_handle_slave_status() bailed out after programming the device ID. This shows up most when the peripheral has to be reset after downloading updated firmware and there are multiple of these peripherals on the bus. They will all return to unenumerated state after the reset, and then there is a mix of unattached, attached and unenumerated PING states from the peripherals, as each is reset and they reboot. Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 704f75c0bae2..bb8ce26c68b3 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -1756,6 +1756,11 @@ int sdw_handle_slave_status(struct sdw_bus *bus, dev_warn(&slave->dev, "Slave %d state check1: UNATTACHED, status was %d= \n", i, slave->status); sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED); + + /* Ensure driver knows that peripheral unattached */ + ret =3D sdw_update_slave_status(slave, status[i]); + if (ret < 0) + dev_warn(&slave->dev, "Update Slave status failed:%d\n", ret); } } =20 --=20 2.30.2 From nobody Tue Apr 7 18:13:26 2026 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 5D726C04AA5 for ; Thu, 25 Aug 2022 12:23:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241665AbiHYMXK (ORCPT ); Thu, 25 Aug 2022 08:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241553AbiHYMW7 (ORCPT ); Thu, 25 Aug 2022 08:22:59 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 285F6B14CE for ; Thu, 25 Aug 2022 05:22:58 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27P5nj9c003635; Thu, 25 Aug 2022 07:22:44 -0500 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=lrFfeaNaq0qk25xBy3PLt6CJ1MTiZDp2a4Mc7/DICTo=; b=ibFyVbbt2GhRhghLUIN3juqWwBmei8RzYMsW06jOJnwJPMWdNYZi68rCYWI/gOiW0akn RTuuebA+Jfiy+p7LZeV2bMrhxQchdQ6cWzFbyiF6cD/hF2tlY4BWy2qXEO0Q3DH+80fL s8OfXDJNtuPwPz/jk85jv7w07taOcBiKGZwBgO3vXpnlY92SWOgwzieT0fvf1G914rLA V4J5cwAUfDW+WPf521p36rtN+p9DMJik8Z8vjHsmEBzknIc7JjLQRpvUsiGBn80ONQlh VH7gFwxxTe1wneJUCss0CD99g6dHYBZjpw+zQqOb636JpZ7UxpGWB9dCtN79lI4rOBu+ +w== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3j4dgmbu3r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Aug 2022 07:22:43 -0500 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.9; Thu, 25 Aug 2022 07:22:41 -0500 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.9 via Frontend Transport; Thu, 25 Aug 2022 07:22:41 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.95]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id BCCC0B0E; Thu, 25 Aug 2022 12:22:41 +0000 (UTC) From: Richard Fitzgerald To: , , , CC: , , , Richard Fitzgerald Subject: [PATCH 3/3] soundwire: bus: Fix lost UNATTACH when re-enumerating Date: Thu, 25 Aug 2022 13:22:41 +0100 Message-ID: <20220825122241.273090-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825122241.273090-1-rf@opensource.cirrus.com> References: <20220825122241.273090-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: vVYFBcLd_1lRC5qoVfwSSvPy0OCEKWAe X-Proofpoint-GUID: vVYFBcLd_1lRC5qoVfwSSvPy0OCEKWAe X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rearrange sdw_handle_slave_status() so that any peripherals on device #0 that are given a device ID are reported as unattached. The ensures that UNATTACH status is not lost. Handle unenumerated devices first and update the sdw_slave_status array to indicate IDs that must have become UNATTACHED. Look for UNATTACHED devices after this so we can pick up peripherals that were UNATTACHED in the original PING status and those that were still ATTACHED at the time of the PING but then reverted to unenumerated and were found by sdw_program_device_num(). As sdw_update_slave_status() is always processing a snapshot of a PING from some time in the past, it is possible that the status is changing while sdw_update_slave_status() is running. A peripheral could report attached in the PING, but detach and revert to device #0 and then be found in the loop in sdw_program_device_num(). Previously the code would not have updated slave->status to UNATTACHED because there was never a PING with that status. If the slave->status is not updated to UNATTACHED the next PING will report it as ATTACHED, but its slave->status is already ATTACHED so the re-attach will not be properly handled. This situations happens fairly frequently with multiple peripherals on a bus that are intentionally reset (for example after downloading firmware). Signed-off-by: Richard Fitzgerald Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index bb8ce26c68b3..1212148ac251 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -718,7 +718,8 @@ void sdw_extract_slave_id(struct sdw_bus *bus, } EXPORT_SYMBOL(sdw_extract_slave_id); =20 -static int sdw_program_device_num(struct sdw_bus *bus) +static int sdw_program_device_num(struct sdw_bus *bus, + enum sdw_slave_status status[]) { u8 buf[SDW_NUM_DEV_ID_REGISTERS] =3D {0}; struct sdw_slave *slave, *_s; @@ -776,6 +777,12 @@ static int sdw_program_device_num(struct sdw_bus *bus) return ret; } =20 + /* + * It could have dropped off the bus since the + * PING response so update the status array. + */ + status[slave->dev_num] =3D SDW_SLAVE_UNATTACHED; + break; } } @@ -1735,10 +1742,21 @@ int sdw_handle_slave_status(struct sdw_bus *bus, { enum sdw_slave_status prev_status; struct sdw_slave *slave; + bool programmed_dev_num =3D false; bool attached_initializing; int i, ret =3D 0; =20 - /* first check if any Slaves fell off the bus */ + /* Handle any unenumerated peripherals */ + if (status[0] =3D=3D SDW_SLAVE_ATTACHED) { + dev_dbg(bus->dev, "Slave attached, programming device number\n"); + ret =3D sdw_program_device_num(bus, status); + if (ret < 0) + dev_warn(bus->dev, "Slave attach failed: %d\n", ret); + + programmed_dev_num =3D true; + } + + /* Check if any fell off the bus */ for (i =3D 1; i <=3D SDW_MAX_DEVICES; i++) { mutex_lock(&bus->bus_lock); if (test_bit(i, bus->assigned) =3D=3D false) { @@ -1764,17 +1782,12 @@ int sdw_handle_slave_status(struct sdw_bus *bus, } } =20 - if (status[0] =3D=3D SDW_SLAVE_ATTACHED) { - dev_dbg(bus->dev, "Slave attached, programming device number\n"); - ret =3D sdw_program_device_num(bus); - if (ret < 0) - dev_err(bus->dev, "Slave attach failed: %d\n", ret); - /* - * programming a device number will have side effects, - * so we deal with other devices at a later time - */ - return ret; - } + /* + * programming a device number will have side effects, + * so we deal with other devices at a later time + */ + if (programmed_dev_num) + return 0; =20 /* Continue to check other slave statuses */ for (i =3D 1; i <=3D SDW_MAX_DEVICES; i++) { --=20 2.30.2