From nobody Sat Oct 4 22:33:08 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D0272ED86F; Tue, 12 Aug 2025 11:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997668; cv=none; b=VDvXX/1bA3uJHkkvU7kd1CNq61trYiw/xke+SW+ythOSMMlRNftcs5LGY5rK4RXwuFIJzTZZsNVi/ztWHzBY0PlmfS3IvQuWbZZu4YnzvcylzDrMQ7CL7TrsSugBvAfqbveMTKcw/YbEdMy+kTRggZNIwxF3fyVZw2Ic58YjOsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997668; c=relaxed/simple; bh=btE/H/h8In+zFZ3coyNkPGTFp2sXECgeWwsH+bApf+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eE0ZWoHef8HQVPbTEiRYyHld029oDq1fMs8F1CYtsDYjmgMmjB2v+vqZINEjDtGnMWUHMlJoYmSiYvgphE17bPQgxlQuDS+EgQDeDlXnJtXG6TwSHnoWUCILVCntg4OC7Rp6Rt3cA9lqm7yuih0TSz4dqpQMmJOu+G3dD2YjsOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4c1SwZ1yR4z9sSL; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TZTC41d0Ji7b; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4c1SwZ10sYz9sSK; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 090E48B764; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id oYqVmKfN6oVn; Tue, 12 Aug 2025 12:51:09 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4C2A18B765; Tue, 12 Aug 2025 12:51:09 +0200 (CEST) From: Christophe Leroy To: Herve Codina , Qiang Zhao , Shengjiu Wang , Xiubo Li , Fabio Estevam , Nicolin Chen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Christophe Leroy , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH v2 1/4] soc: fsl: qmc: Only set completion interrupt when needed Date: Tue, 12 Aug 2025 12:50:55 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1754995860; l=3383; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=btE/H/h8In+zFZ3coyNkPGTFp2sXECgeWwsH+bApf+k=; b=zVwDmHckJ9mDmT1RDuIFBLmmtGpvCrpdaM679R61Csv/878/XJddDu6BCqmg5MWdRPutlVzV8 Tx9V7OFk3U+Cl67z/fTXBHb4yPB9HbRBYFB3c7X4RnCAC8pKGvZDWFv X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When no post-completion processing is expected, don't waste time handling useless interrupts. Only set QMC_BD_[R/T]X_I when a completion function is passed in, and perform seamless completion on submit for interruptless buffers. Signed-off-by: Christophe Leroy --- v2: Keep the UB flag to mark not completed buffers and seamlessly flag them= as completed during next submit. --- drivers/soc/fsl/qe/qmc.c | 44 ++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/drivers/soc/fsl/qe/qmc.c b/drivers/soc/fsl/qe/qmc.c index 36c0ccc06151f..8f76b9a5e385d 100644 --- a/drivers/soc/fsl/qe/qmc.c +++ b/drivers/soc/fsl/qe/qmc.c @@ -461,9 +461,16 @@ int qmc_chan_write_submit(struct qmc_chan *chan, dma_a= ddr_t addr, size_t length, =20 ctrl =3D qmc_read16(&bd->cbd_sc); if (ctrl & (QMC_BD_TX_R | QMC_BD_TX_UB)) { - /* We are full ... */ - ret =3D -EBUSY; - goto end; + if (!(ctrl & QMC_BD_TX_I) && bd =3D=3D chan->txbd_done) { + if (ctrl & QMC_BD_TX_W) + chan->txbd_done =3D chan->txbds; + else + chan->txbd_done++; + } else { + /* We are full ... */ + ret =3D -EBUSY; + goto end; + } } =20 qmc_write16(&bd->cbd_datlen, length); @@ -475,6 +482,10 @@ int qmc_chan_write_submit(struct qmc_chan *chan, dma_a= ddr_t addr, size_t length, =20 /* Activate the descriptor */ ctrl |=3D (QMC_BD_TX_R | QMC_BD_TX_UB); + if (complete) + ctrl |=3D QMC_BD_TX_I; + else + ctrl &=3D ~QMC_BD_TX_I; wmb(); /* Be sure to flush the descriptor before control update */ qmc_write16(&bd->cbd_sc, ctrl); =20 @@ -569,9 +580,16 @@ int qmc_chan_read_submit(struct qmc_chan *chan, dma_ad= dr_t addr, size_t length, =20 ctrl =3D qmc_read16(&bd->cbd_sc); if (ctrl & (QMC_BD_RX_E | QMC_BD_RX_UB)) { - /* We are full ... */ - ret =3D -EBUSY; - goto end; + if (!(ctrl & QMC_BD_RX_I) && bd =3D=3D chan->rxbd_done) { + if (ctrl & QMC_BD_RX_W) + chan->rxbd_done =3D chan->rxbds; + else + chan->rxbd_done++; + } else { + /* We are full ... */ + ret =3D -EBUSY; + goto end; + } } =20 qmc_write16(&bd->cbd_datlen, 0); /* data length is updated by the QMC */ @@ -587,6 +605,10 @@ int qmc_chan_read_submit(struct qmc_chan *chan, dma_ad= dr_t addr, size_t length, =20 /* Activate the descriptor */ ctrl |=3D (QMC_BD_RX_E | QMC_BD_RX_UB); + if (complete) + ctrl |=3D QMC_BD_RX_I; + else + ctrl &=3D ~QMC_BD_RX_I; wmb(); /* Be sure to flush data before descriptor activation */ qmc_write16(&bd->cbd_sc, ctrl); =20 @@ -1482,19 +1504,19 @@ static int qmc_setup_chan(struct qmc *qmc, struct q= mc_chan *chan) =20 /* Init Rx BDs and set Wrap bit on last descriptor */ BUILD_BUG_ON(QMC_NB_RXBDS =3D=3D 0); - val =3D QMC_BD_RX_I; for (i =3D 0; i < QMC_NB_RXBDS; i++) { bd =3D chan->rxbds + i; - qmc_write16(&bd->cbd_sc, val); + qmc_write16(&bd->cbd_sc, 0); } bd =3D chan->rxbds + QMC_NB_RXBDS - 1; - qmc_write16(&bd->cbd_sc, val | QMC_BD_RX_W); + qmc_write16(&bd->cbd_sc, QMC_BD_RX_W); =20 /* Init Tx BDs and set Wrap bit on last descriptor */ BUILD_BUG_ON(QMC_NB_TXBDS =3D=3D 0); - val =3D QMC_BD_TX_I; if (chan->mode =3D=3D QMC_HDLC) - val |=3D QMC_BD_TX_L | QMC_BD_TX_TC; + val =3D QMC_BD_TX_L | QMC_BD_TX_TC; + else + val =3D 0; for (i =3D 0; i < QMC_NB_TXBDS; i++) { bd =3D chan->txbds + i; qmc_write16(&bd->cbd_sc, val); --=20 2.49.0 From nobody Sat Oct 4 22:33:08 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 927881A9F8C; Tue, 12 Aug 2025 11:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997637; cv=none; b=AsgOpJWzEjf7VHFURsROBO+CbwrJa6+/GsbMMzTQ+sb/aOIQyq4qVJPnpDvEA2OCkrb8sr+fOd9MEt6qNyZwQCK7+GBWnnnU75+jmi1q+ytoku8MTe8QtzK9EfGoRMHb1h2U4rwWXGxcbmn5lBHOw6Bt+vhKAXof+R+N3JYc/Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997637; c=relaxed/simple; bh=XfURbicrtINn/6zsJVAuuKOWunGZaLPhKuyOsIyIZX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uN1WcoNB0YIJxIJLeQqJlWEQoSzIsvraZ+nLJb37Gb/ENg2VeyGXTOz3g4u9W7wg8H0GD3HWLclB2n2J09fe/TD1e+SDX8M6xoDIvIfsw7B01s7wLGBRb1Q9XvkxyJ66CBMRPCv+dpknZ10cUySeRVZpitwS0xAb0UIji6nRfBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4c1Swb2MHyz9sSN; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kerTTt7NRZVH; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4c1SwZ5d91z9sSK; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AA7BA8B764; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ClAnCfTxCmbT; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 03CA08B763; Tue, 12 Aug 2025 12:51:09 +0200 (CEST) From: Christophe Leroy To: Herve Codina , Qiang Zhao , Shengjiu Wang , Xiubo Li , Fabio Estevam , Nicolin Chen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Christophe Leroy , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH v2 2/4] ASoc: fsl: fsl_qmc_audio: Ensure audio channels are ordered in TDM bus Date: Tue, 12 Aug 2025 12:50:56 +0200 Message-ID: <8d01cf4599664188c92a515922d68c9834263384.1754993232.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1754995860; l=2232; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=XfURbicrtINn/6zsJVAuuKOWunGZaLPhKuyOsIyIZX0=; b=YBxguf9SJ+Iqmj02qL4fBifNH7KDTCcS7hy6Imu81/zBTIa3kKCjuwcO9Knmd63YnJxJKvq/X Q/IvZFe9FcrCZqrymZp7kNatPLd0/qa1D0OzNY8vUMKpguQFswGlVuH X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To reduce complexity of interrupt handling in following patch, ensure audio channels are configured in the same order as timeslots on the TDM bus. If we need a given ordering of audio sources in the audio frame, it is possible to re-order codecs on the TDM bus, no need to mix up timeslots in channels. Signed-off-by: Christophe Leroy --- v2: New --- sound/soc/fsl/fsl_qmc_audio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c index 5614a8b909edf..0be29ccc1ff7b 100644 --- a/sound/soc/fsl/fsl_qmc_audio.c +++ b/sound/soc/fsl/fsl_qmc_audio.c @@ -791,12 +791,17 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_= audio, struct device_node * struct qmc_dai *qmc_dai, struct snd_soc_dai_driver *qmc_soc_dai_driver) { + struct qmc_chan_ts_info ts_info; struct qmc_chan_info info; unsigned long rx_fs_rate; unsigned long tx_fs_rate; + int prev_last_rx_ts =3D 0; + int prev_last_tx_ts =3D 0; unsigned int nb_tx_ts; unsigned int nb_rx_ts; unsigned int i; + int last_rx_ts; + int last_tx_ts; int count; u32 val; int ret; @@ -879,6 +884,30 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_a= udio, struct device_node * return -EINVAL; } } + + ret =3D qmc_chan_get_ts_info(qmc_dai->qmc_chans[i], &ts_info); + if (ret) { + dev_err(qmc_audio->dev, "dai %d get QMC %d channel TS info failed %d\n", + qmc_dai->id, i, ret); + return ret; + } + + last_rx_ts =3D fls64(ts_info.rx_ts_mask); + last_tx_ts =3D fls64(ts_info.rx_ts_mask); + + if (prev_last_rx_ts > last_rx_ts) { + dev_err(qmc_audio->dev, "dai %d QMC chan %d unordered channels (RX time= slot %lu before %lu)\n", + qmc_dai->id, i, prev_last_rx_ts, last_rx_ts); + return -EINVAL; + } + if (prev_last_tx_ts > last_tx_ts) { + dev_err(qmc_audio->dev, "dai %d QMC chan %d unordered channels (TX time= slot %lu before %lu)\n", + qmc_dai->id, i, prev_last_tx_ts, last_tx_ts); + return -EINVAL; + } + + prev_last_rx_ts =3D last_rx_ts; + prev_last_tx_ts =3D last_tx_ts; } =20 qmc_dai->nb_chans_avail =3D count; --=20 2.49.0 From nobody Sat Oct 4 22:33:09 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AC242EB5D2; Tue, 12 Aug 2025 11:20:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997655; cv=none; b=oW16zGVnVURuGn/W+gDm7I17aEWi194q5MTFdPo9y1Ubeuch4sNiSkQaQRvNqvoVExnXDgKF4ncIJVV0j5CBv5n9DbH+uQc3teTnUQNIVxaY76fDXzdyuon3D9HxfbiPkEv0VoIk62ApGS7Kv4zCPybV0xKK0xn0i3T4amL264U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997655; c=relaxed/simple; bh=4WvVIASI4alTwJrylXkbVq3Sqy6GlVQKoVrURW7O4pc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QOODfM7AmxFxrwmo2xdthqY7mMMP4TUaF4wx5vHFJtjrnnsPldno41uZibkfW/iT5s5jytzepAXZC89G7Zx1fApG2ZbWF1jI3qiEMf+uNgDl363VBytXep9noNEs4BwTLVn7y2F3N8ZFH7eQOLyDjOnVWnVIX4GH/XW/R4olcnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4c1Swc0sHyz9sSR; Tue, 12 Aug 2025 12:51:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UZfLVWQ7jLtD; Tue, 12 Aug 2025 12:51:12 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4c1Swb3wGkz9sSK; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6C8CB8B764; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 4GfoNMbtMS8g; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id AB8FE8B765; Tue, 12 Aug 2025 12:51:10 +0200 (CEST) From: Christophe Leroy To: Herve Codina , Qiang Zhao , Shengjiu Wang , Xiubo Li , Fabio Estevam , Nicolin Chen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Christophe Leroy , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH v2 3/4] ASoC: fsl: fsl_qmc_audio: Only request completion on last channel Date: Tue, 12 Aug 2025 12:50:57 +0200 Message-ID: <21eb89cc03a1c2135bdaba6a4dd1d0c2e624ce29.1754993232.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1754995860; l=4945; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=4WvVIASI4alTwJrylXkbVq3Sqy6GlVQKoVrURW7O4pc=; b=kK0HMFbQjUGoU9gCyvZ9al1SVU7DiGHBkSIKbM6b3PMB48xoPCApvkWX7TBmhMOhpYNbI3W0n YdaUjFo/BHbD6r+nRb+tGtUznllA2+KDoXIpFTPGrpkXMYtBHP9XA7H X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In non-interleaved mode, several QMC channels are used in sync. More details can be found in commit 188d9cae5438 ("ASoC: fsl: fsl_qmc_audio: Add support for non-interleaved mode.") At the time being, an interrupt is requested on each channel to perform capture/playback completion, allthough the completion is really performed only once all channels have completed their work. This leads to a lot more interrupts than really needed. Looking at /proc/interrupts shows ~3800 interrupts per second when using 4 capture and 4 playback devices with 5ms periods while only 1600 (200 x 4 + 200 x 4) periods are processed during one second. The QMC channels work in sync, the one started first is the one finishing first and the one started last is the one finishing last, so when the last one finishes it is guaranteed that the other ones are finished as well. Therefore only request completion processing on the last QMC channel. On my board with the above exemple, on a kernel started with 'threadirqs' option, the QMC irq thread uses 16% CPU time with this patch while it uses 26% CPU time without this patch. Signed-off-by: Christophe Leroy Acked-by: Herve Codina --- sound/soc/fsl/fsl_qmc_audio.c | 46 +++++------------------------------ 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c index 0be29ccc1ff7b..92aa813aa3bee 100644 --- a/sound/soc/fsl/fsl_qmc_audio.c +++ b/sound/soc/fsl/fsl_qmc_audio.c @@ -57,7 +57,6 @@ struct qmc_dai_prtd { size_t ch_dma_offset; =20 unsigned int channels; - DECLARE_BITMAP(chans_pending, 64); struct snd_pcm_substream *substream; }; =20 @@ -126,17 +125,14 @@ static int qmc_audio_pcm_write_submit(struct qmc_dai_= prtd *prtd) int ret; =20 for (i =3D 0; i < prtd->channels; i++) { - bitmap_set(prtd->chans_pending, i, 1); - ret =3D qmc_chan_write_submit(prtd->qmc_dai->chans[i].qmc_chan, prtd->ch_dma_addr_current + i * prtd->ch_dma_offset, prtd->ch_dma_size, - qmc_audio_pcm_write_complete, - &prtd->qmc_dai->chans[i]); + i =3D=3D prtd->channels - 1 ? qmc_audio_pcm_write_complete : + NULL, prtd); if (ret) { dev_err(prtd->qmc_dai->dev, "write_submit %u failed %d\n", i, ret); - bitmap_clear(prtd->chans_pending, i, 1); return ret; } } @@ -146,20 +142,7 @@ static int qmc_audio_pcm_write_submit(struct qmc_dai_p= rtd *prtd) =20 static void qmc_audio_pcm_write_complete(void *context) { - struct qmc_dai_chan *chan =3D context; - struct qmc_dai_prtd *prtd; - - prtd =3D chan->prtd_tx; - - /* Mark the current channel as completed */ - bitmap_clear(prtd->chans_pending, chan - prtd->qmc_dai->chans, 1); - - /* - * All QMC channels involved must have completed their transfer before - * submitting a new one. - */ - if (!bitmap_empty(prtd->chans_pending, 64)) - return; + struct qmc_dai_prtd *prtd =3D context; =20 prtd->buffer_ended +=3D prtd->period_size; if (prtd->buffer_ended >=3D prtd->buffer_size) @@ -182,17 +165,14 @@ static int qmc_audio_pcm_read_submit(struct qmc_dai_p= rtd *prtd) int ret; =20 for (i =3D 0; i < prtd->channels; i++) { - bitmap_set(prtd->chans_pending, i, 1); - ret =3D qmc_chan_read_submit(prtd->qmc_dai->chans[i].qmc_chan, prtd->ch_dma_addr_current + i * prtd->ch_dma_offset, prtd->ch_dma_size, - qmc_audio_pcm_read_complete, - &prtd->qmc_dai->chans[i]); + i =3D=3D prtd->channels - 1 ? qmc_audio_pcm_read_complete : + NULL, prtd); if (ret) { dev_err(prtd->qmc_dai->dev, "read_submit %u failed %d\n", i, ret); - bitmap_clear(prtd->chans_pending, i, 1); return ret; } } @@ -202,26 +182,13 @@ static int qmc_audio_pcm_read_submit(struct qmc_dai_p= rtd *prtd) =20 static void qmc_audio_pcm_read_complete(void *context, size_t length, unsi= gned int flags) { - struct qmc_dai_chan *chan =3D context; - struct qmc_dai_prtd *prtd; - - prtd =3D chan->prtd_rx; - - /* Mark the current channel as completed */ - bitmap_clear(prtd->chans_pending, chan - prtd->qmc_dai->chans, 1); + struct qmc_dai_prtd *prtd =3D context; =20 if (length !=3D prtd->ch_dma_size) { dev_err(prtd->qmc_dai->dev, "read complete length =3D %zu, exp %zu\n", length, prtd->ch_dma_size); } =20 - /* - * All QMC channels involved must have completed their transfer before - * submitting a new one. - */ - if (!bitmap_empty(prtd->chans_pending, 64)) - return; - prtd->buffer_ended +=3D prtd->period_size; if (prtd->buffer_ended >=3D prtd->buffer_size) prtd->buffer_ended =3D 0; @@ -249,7 +216,6 @@ static int qmc_audio_pcm_trigger(struct snd_soc_compone= nt *component, =20 switch (cmd) { case SNDRV_PCM_TRIGGER_START: - bitmap_zero(prtd->chans_pending, 64); prtd->buffer_ended =3D 0; prtd->ch_dma_addr_current =3D prtd->ch_dma_addr_start; =20 --=20 2.49.0 From nobody Sat Oct 4 22:33:09 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 928092D5A07; Tue, 12 Aug 2025 11:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997637; cv=none; b=XGnpzh9wfbyyzXFldhfMezQZTYR3gOs95DMSl2qwuMtg1q8RNKwWmbleNnSMs6y/IXBiW1rz1i83tWp3xpWoXeNkAYsfvGBxsGmyBCUsY/QniOazUkBQkBnEk/jiIl6U+CZrEMRVoMmKn8pH2iQaKILDa9VYPdEyoPC5QE8lQWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754997637; c=relaxed/simple; bh=D8aJWskat7D7j+YQUUJGr8krPsanE8nzMLSq+13eJYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ocuVnloDsHuhf6isv2d4s7QdIhHEEow94DQZu9tBd94PCtZLkpPRRerw1Uy5BOYAkKy5PiuPMz8+u/A3MTz36oCBNuGir5giDKHsHRWbE1CUzH1AldbsQ1gS+6fSHr5ff/0G11i/ulmtWw46V1CpaI14Xvxk0v56lqzgbUkCBLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4c1Swd6CHXz9sSX; Tue, 12 Aug 2025 12:51:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iI9dJ_a7pdSu; Tue, 12 Aug 2025 12:51:13 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4c1Swc1tNfz9sSS; Tue, 12 Aug 2025 12:51:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2D1808B764; Tue, 12 Aug 2025 12:51:12 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 4jorW_lag49m; Tue, 12 Aug 2025 12:51:12 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 685288B763; Tue, 12 Aug 2025 12:51:11 +0200 (CEST) From: Christophe Leroy To: Herve Codina , Qiang Zhao , Shengjiu Wang , Xiubo Li , Fabio Estevam , Nicolin Chen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: Christophe Leroy , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org Subject: [PATCH v2 4/4] ASoc: fsl: fsl_qmc_audio: Drop struct qmc_dai_chan Date: Tue, 12 Aug 2025 12:50:58 +0200 Message-ID: <0e73d47d15cf38ad5c4c35fbab545153829dde75.1754993232.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1754995860; l=6627; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=D8aJWskat7D7j+YQUUJGr8krPsanE8nzMLSq+13eJYM=; b=sdXjy3Q5FBCRj+brdHzpE1YVcgqKY2OAvclAR2RvhgKoAGHu+CrM+KqAy40KOfN+VjEtaaeSL 1sImg+Jndj+Cd1xOlWkzqNaSAy1uJ/L/0iilFFGpdP8y8+O2C3bP6l6 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" prtd_tx and prtd_rx members are not used anymore and only qmc_chan member remains so struct qmc_dai_chan has become pointless. Use qmc_chan directly and drop struct qmc_dai_chan. Signed-off-by: Christophe Leroy Acked-by: Herve Codina --- v2: New --- sound/soc/fsl/fsl_qmc_audio.c | 50 +++++++++++++---------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c index 92aa813aa3bee..6719da1c81f1d 100644 --- a/sound/soc/fsl/fsl_qmc_audio.c +++ b/sound/soc/fsl/fsl_qmc_audio.c @@ -17,12 +17,6 @@ #include #include =20 -struct qmc_dai_chan { - struct qmc_dai_prtd *prtd_tx; - struct qmc_dai_prtd *prtd_rx; - struct qmc_chan *qmc_chan; -}; - struct qmc_dai { char *name; int id; @@ -33,7 +27,7 @@ struct qmc_dai { unsigned int nb_chans_avail; unsigned int nb_chans_used_tx; unsigned int nb_chans_used_rx; - struct qmc_dai_chan *chans; + struct qmc_chan **qmc_chans; }; =20 struct qmc_audio { @@ -125,7 +119,7 @@ static int qmc_audio_pcm_write_submit(struct qmc_dai_pr= td *prtd) int ret; =20 for (i =3D 0; i < prtd->channels; i++) { - ret =3D qmc_chan_write_submit(prtd->qmc_dai->chans[i].qmc_chan, + ret =3D qmc_chan_write_submit(prtd->qmc_dai->qmc_chans[i], prtd->ch_dma_addr_current + i * prtd->ch_dma_offset, prtd->ch_dma_size, i =3D=3D prtd->channels - 1 ? qmc_audio_pcm_write_complete : @@ -165,7 +159,7 @@ static int qmc_audio_pcm_read_submit(struct qmc_dai_prt= d *prtd) int ret; =20 for (i =3D 0; i < prtd->channels; i++) { - ret =3D qmc_chan_read_submit(prtd->qmc_dai->chans[i].qmc_chan, + ret =3D qmc_chan_read_submit(prtd->qmc_dai->qmc_chans[i], prtd->ch_dma_addr_current + i * prtd->ch_dma_offset, prtd->ch_dma_size, i =3D=3D prtd->channels - 1 ? qmc_audio_pcm_read_complete : @@ -206,7 +200,6 @@ static int qmc_audio_pcm_trigger(struct snd_soc_compone= nt *component, struct snd_pcm_substream *substream, int cmd) { struct qmc_dai_prtd *prtd =3D substream->runtime->private_data; - unsigned int i; int ret; =20 if (!prtd->qmc_dai) { @@ -220,9 +213,6 @@ static int qmc_audio_pcm_trigger(struct snd_soc_compone= nt *component, prtd->ch_dma_addr_current =3D prtd->ch_dma_addr_start; =20 if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) { - for (i =3D 0; i < prtd->channels; i++) - prtd->qmc_dai->chans[i].prtd_tx =3D prtd; - /* Submit first chunk ... */ ret =3D qmc_audio_pcm_write_submit(prtd); if (ret) @@ -238,9 +228,6 @@ static int qmc_audio_pcm_trigger(struct snd_soc_compone= nt *component, if (ret) return ret; } else { - for (i =3D 0; i < prtd->channels; i++) - prtd->qmc_dai->chans[i].prtd_rx =3D prtd; - /* Submit first chunk ... */ ret =3D qmc_audio_pcm_read_submit(prtd); if (ret) @@ -610,9 +597,9 @@ static int qmc_dai_hw_params(struct snd_pcm_substream *= substream, chan_param.mode =3D QMC_TRANSPARENT; chan_param.transp.max_rx_buf_size =3D params_period_bytes(params) / nb_c= hans_used; for (i =3D 0; i < nb_chans_used; i++) { - ret =3D qmc_chan_set_param(qmc_dai->chans[i].qmc_chan, &chan_param); + ret =3D qmc_chan_set_param(qmc_dai->qmc_chans[i], &chan_param); if (ret) { - dev_err(dai->dev, "chans[%u], set param failed %d\n", + dev_err(dai->dev, "qmc_chans[%u], set param failed %d\n", i, ret); return ret; } @@ -654,7 +641,7 @@ static int qmc_dai_trigger(struct snd_pcm_substream *su= bstream, int cmd, case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: for (i =3D 0; i < nb_chans_used; i++) { - ret =3D qmc_chan_start(qmc_dai->chans[i].qmc_chan, direction); + ret =3D qmc_chan_start(qmc_dai->qmc_chans[i], direction); if (ret) goto err_stop; } @@ -663,13 +650,13 @@ static int qmc_dai_trigger(struct snd_pcm_substream *= substream, int cmd, case SNDRV_PCM_TRIGGER_STOP: /* Stop and reset all QMC channels and return the first error encountere= d */ for (i =3D 0; i < nb_chans_used; i++) { - ret_tmp =3D qmc_chan_stop(qmc_dai->chans[i].qmc_chan, direction); + ret_tmp =3D qmc_chan_stop(qmc_dai->qmc_chans[i], direction); if (!ret) ret =3D ret_tmp; if (ret_tmp) continue; =20 - ret_tmp =3D qmc_chan_reset(qmc_dai->chans[i].qmc_chan, direction); + ret_tmp =3D qmc_chan_reset(qmc_dai->qmc_chans[i], direction); if (!ret) ret =3D ret_tmp; } @@ -681,7 +668,7 @@ static int qmc_dai_trigger(struct snd_pcm_substream *su= bstream, int cmd, case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* Stop all QMC channels and return the first error encountered */ for (i =3D 0; i < nb_chans_used; i++) { - ret_tmp =3D qmc_chan_stop(qmc_dai->chans[i].qmc_chan, direction); + ret_tmp =3D qmc_chan_stop(qmc_dai->qmc_chans[i], direction); if (!ret) ret =3D ret_tmp; } @@ -697,8 +684,8 @@ static int qmc_dai_trigger(struct snd_pcm_substream *su= bstream, int cmd, =20 err_stop: while (i--) { - qmc_chan_stop(qmc_dai->chans[i].qmc_chan, direction); - qmc_chan_reset(qmc_dai->chans[i].qmc_chan, direction); + qmc_chan_stop(qmc_dai->qmc_chans[i], direction); + qmc_chan_reset(qmc_dai->qmc_chans[i], direction); } return ret; } @@ -794,19 +781,20 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_= audio, struct device_node * return dev_err_probe(qmc_audio->dev, -EINVAL, "dai %d no QMC channel defined\n", qmc_dai->id); =20 - qmc_dai->chans =3D devm_kcalloc(qmc_audio->dev, count, sizeof(*qmc_dai->c= hans), GFP_KERNEL); - if (!qmc_dai->chans) + qmc_dai->qmc_chans =3D devm_kcalloc(qmc_audio->dev, count, sizeof(*qmc_da= i->qmc_chans), + GFP_KERNEL); + if (!qmc_dai->qmc_chans) return -ENOMEM; =20 for (i =3D 0; i < count; i++) { - qmc_dai->chans[i].qmc_chan =3D devm_qmc_chan_get_byphandles_index(qmc_au= dio->dev, np, - "fsl,qmc-chan", i); - if (IS_ERR(qmc_dai->chans[i].qmc_chan)) { - return dev_err_probe(qmc_audio->dev, PTR_ERR(qmc_dai->chans[i].qmc_chan= ), + qmc_dai->qmc_chans[i] =3D devm_qmc_chan_get_byphandles_index(qmc_audio->= dev, np, + "fsl,qmc-chan", i); + if (IS_ERR(qmc_dai->qmc_chans[i])) { + return dev_err_probe(qmc_audio->dev, PTR_ERR(qmc_dai->qmc_chans[i]), "dai %d get QMC channel %d failed\n", qmc_dai->id, i); } =20 - ret =3D qmc_chan_get_info(qmc_dai->chans[i].qmc_chan, &info); + ret =3D qmc_chan_get_info(qmc_dai->qmc_chans[i], &info); if (ret) { dev_err(qmc_audio->dev, "dai %d get QMC %d channel info failed %d\n", qmc_dai->id, i, ret); --=20 2.49.0