From nobody Sat Oct 4 11:10:14 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 190062FF676; Mon, 18 Aug 2025 08:50:44 +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=1755507046; cv=none; b=GvskhLSZ54Lhfb18Vtr19vJnfcJCnv6LWAuc/sRBiZ6ci9M5+N8Rzle3HWMOJulxtf3WY8OQ4dSYWZdI01bxHFSkb7BBc2gKjS7G9IJi9461gK3js0NKdPCSOihAxFto7PveizA3n3rq05IYR7rccxPUJREU0tuHE3dYkcJn8jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755507046; c=relaxed/simple; bh=kh9PQCdvsuxt4RhIWm9+RprrvTqMluzmq/Q0sECbAY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSAbvyMWgva9uk1YRg7SHh0koEGbpp9XaulfWoJXaaM6h5fYJoVPWAVe2tOj42Dp8Dm6vooGXFOyOvGUyRbe6gWWQYmfceKTa3ynlEmqsx2z//DbxyHEZfi72r/NoN608RgDpXwviVitAjQ4ep23nR+tLGY9RoLg0cNoH/MR0ys= 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 4c55HT1D2Wz9sWC; Mon, 18 Aug 2025 10:20:05 +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 zqfx_29jJklv; Mon, 18 Aug 2025 10:20:05 +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 4c55HS3MbQz9sW4; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5975F8B766; Mon, 18 Aug 2025 10:20:04 +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 5uGw3xFPn1L2; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [10.25.207.160]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 22E3A8B764; Mon, 18 Aug 2025 10:20:04 +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 v3 1/4] soc: fsl: qmc: Only set completion interrupt when needed Date: Mon, 18 Aug 2025 10:20:00 +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=1755505199; l=3298; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=kh9PQCdvsuxt4RhIWm9+RprrvTqMluzmq/Q0sECbAY0=; b=V4R9Apsqr1Vcvnj5Mk1Fb0ZSXT/AZXjv+rBkjj0zzoV7QIS8SqFTd2svAgAzMFPgZ4oW28/1z u4S4lxsGkmvDAZQkafc5mGgwTaA/zVeXuYjFgW5tankXhrLdquZsA5V 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 Acked-by: Herve Codina --- 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 36c0ccc06151..da5ea6d35618 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_R | 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_E | 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 11:10:14 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93EDF3019A5; Mon, 18 Aug 2025 08:50:49 +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=1755507051; cv=none; b=MNfDO5clK65uNhkV1KhyftF1vPwk5RtTj57vuIo/ZRgwybP9/KUxajOCccGAtT/h4+4G51cCM6qd0wOdZ9EmkcBI41WoPO7rSV4MPRvf8RIoSFkPr7zcjNXfYXq5jdn4ZHriRbOVWHKr7mmHUmoXqJxFyWYdeBZqhZ6rk1NY+r0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755507051; c=relaxed/simple; bh=SYbloYwYI2o2l9qWMT+5H0KmD0kacEnPhYcSkHfzxEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dw13gkIVGdH/GLAnApwY9tMjk2/K2gwQwc0xF3lTQMsg7mEkt3Tn19Zd2QSd5DZPfJjgfiNeoUeAm3FTCIjDhNC0lnO1/ItXTk3dL7oj77cIXyPazRlGEqhm1doSJO+o4Dq888maFbsMm0+apsWEpUeQfyHWht9Xkx+b4j5Xm7Y= 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 4c55HV5XV9z9sW5; Mon, 18 Aug 2025 10:20:06 +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 wIe-lmP6pu4s; Mon, 18 Aug 2025 10:20:06 +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 4c55HS48Cfz9sW8; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 71F4D8B765; Mon, 18 Aug 2025 10:20:04 +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 3kaTHZm5b9PS; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [10.25.207.160]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 42BA08B763; Mon, 18 Aug 2025 10:20:04 +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 v3 2/4] ASoc: fsl: fsl_qmc_audio: Ensure audio channels are ordered in TDM bus Date: Mon, 18 Aug 2025 10:20:01 +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=1755505199; l=2217; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=SYbloYwYI2o2l9qWMT+5H0KmD0kacEnPhYcSkHfzxEw=; b=Uxas0iEZgPlcZBwnlSGDU/8/4rVUd4yigb4hH9u5SU6DZtVUdmKN2OuUc/rWZsAM4mXzkEijO vZrBAoq0e9MCqQjF+Z9g969K/eSnN68GhcOh89/95IwmbvmsH+WnOxS 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 Acked-by: Herve Codina --- 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 5614a8b909ed..c0c7ef0a1511 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->chans[i].qmc_chan, &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.tx_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 %d before %d)\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 %d before %d)\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 11:10:14 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 143DD1E570D; Mon, 18 Aug 2025 08:50: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=1755507037; cv=none; b=ElfyoYadr8VDaEPE9XYJ3VKECGyb6TZU2G00ba3/7jQbCTt5PhVwV7UkcO66BKfWfRnzjntfO0wDFua59QgmhsausztC0RgzN7blI+02wfXodh3PtUL+ZIBdPvjXOiqDfQDuB1kBWNh2e/3URrPdhwGEJpDDKMkhryM0WR6mhHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755507037; c=relaxed/simple; bh=LtGMMyc9XKRicdulQjD8tGFVx/BvLiQjDfeh4aHdKJc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fN56aU4Nw+kfqtcC1RvW4WcevEOLaeh9w9jGkUIA963BJMnxHD1uWsceTjJheahihiutYznbkuJtmVXKiPBLkSRbYsX44BJu4/leD+eQojunSf2vZQRqLaF0Nn4YVEl0GR0PtxLEh5Zo5sK1/6l3vFrmINW+2nzHHkkQrRq/bTw= 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 4c55HW2lrvz9sWD; Mon, 18 Aug 2025 10:20:07 +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 Lm2-x3VqRKpO; Mon, 18 Aug 2025 10:20:07 +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 4c55HS5GJqz9sWB; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9D7048B765; Mon, 18 Aug 2025 10:20:04 +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 sXvKLLQEmvwu; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [10.25.207.160]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6713D8B764; Mon, 18 Aug 2025 10:20:04 +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 v3 3/4] ASoC: fsl: fsl_qmc_audio: Only request completion on last channel Date: Mon, 18 Aug 2025 10:20:02 +0200 Message-ID: <2684693bdea6a31a0e8d1ef2af6d534b7fa97044.1755504428.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=1755505199; l=4994; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=LtGMMyc9XKRicdulQjD8tGFVx/BvLiQjDfeh4aHdKJc=; b=/aq0V28neDnaGuCyCxuNMZqphvYCXrD2+CswoU8Wzj27y2FboMgQ8+CZlMDfxKyr4gJTTLJ0y 3aQNnJHYyAZBAgrvrvpA39O/09PRPDvhGpy1rQd9r6qi4LTXxrGdbnN 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 c0c7ef0a1511..2790953543c5 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 11:10:14 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A09323A562; Mon, 18 Aug 2025 08:51:16 +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=1755507078; cv=none; b=KFxJFbGDlOZu+x7xXGOvJaOOuXOctxwoW3CZD8vjgyCGpZvPpaAsjYGLGIJLZlTzPegNhZ4JAn+JFSAOp5ezGMGJspCtHOBL/GNiz0B507dCmZVLKTWF9gupuYTuXrucXJLBzxRQwHiqylgjdSKEMckHxdm3qjX328wLIKfUiTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755507078; c=relaxed/simple; bh=kTwze63IXhfJKmOMOziMBpN3ze0bvx7Dv9G4bd5j9oQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QDlKAtAKkTNuD3mzpjd7+yhsIvknGoyRKLOnxh3P8rYXuK/y0SHDHGVO6vQdZOez/lK6da3JxLpWvvNA0SXbYzo/cEwyW2VMrLHkIH/4jPofP4KAsM37RLuFRipwq/vV4omEbj4pi20mwYeKDYVIIxQFaskjAGZmex61ICkVoSc= 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 4c55HX0qZFz9sWF; Mon, 18 Aug 2025 10:20:08 +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 9syMfqubNB4p; Mon, 18 Aug 2025 10:20:08 +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 4c55HS62zqz9sW7; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B866F8B764; Mon, 18 Aug 2025 10:20:04 +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 u3ByOgEZDKj3; Mon, 18 Aug 2025 10:20:04 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (unknown [10.25.207.160]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8B40F8B763; Mon, 18 Aug 2025 10:20:04 +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 v3 4/4] ASoc: fsl: fsl_qmc_audio: Drop struct qmc_dai_chan Date: Mon, 18 Aug 2025 10:20:03 +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=1755505200; l=7036; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=kTwze63IXhfJKmOMOziMBpN3ze0bvx7Dv9G4bd5j9oQ=; b=QhTyCGzMVd3HyrWxivP5SIyCJ3I9n7Zr9fLTH9jDUm9mguYkYHOz9yd/6ke7TQRUZGKs40xhm 34BRdv5LrO5BoLyge7Qs/ePpGM3uzM7E+ohnmIcWgnim6inJ7+Ag2Na 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 --- sound/soc/fsl/fsl_qmc_audio.c | 52 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/sound/soc/fsl/fsl_qmc_audio.c b/sound/soc/fsl/fsl_qmc_audio.c index 2790953543c5..3de448ef724c 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); @@ -851,7 +839,7 @@ static int qmc_audio_dai_parse(struct qmc_audio *qmc_au= dio, struct device_node * } } =20 - ret =3D qmc_chan_get_ts_info(qmc_dai->chans[i].qmc_chan, &ts_info); + 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); --=20 2.49.0