From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.49 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796314756; b=3/92qAJL6Gp0EKKU466YFdnPHmL1QQ5tp0dy/UdFirfqVQLC7VaucYAxMV+oAgXprKX4 OlszM5Pp8C6Z8zUV6qNu+YcZ3EuJP8V6dOWr/c2Nu9b9eEvZ8R4LzdpFrZ46+owXw/8Ni d0WttbDdPEuMG6Esg154yoHk9Qi4TGBjPEaKQ0AvSwrJUjoZ44QuXdEJNHQYIOG2fWyFn FMh1n9UabW2gaqdJ/XtfUVUhGsY2tiuT2DVPUSoxBmEbcz22JVYlvfSHEGxmbTOArBngU e+55m1pnujTbbS2HO1UPzOwBsirZYhQwixEJTReAiKIdUwviBnjicKrkWBSKll8dzcw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796314756; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=jYJw3O9FIMrJ6bEdlbZmHzEiLf3ZMSYoLH5BbL+MVqU=; b=V2FMkULo0M4EmoFPgELiqTQxU1+/eMkHlbILOrgbLII6+xFUnhwTJkg4aCpkfPn7X4+E PMwf1AK4wzGd7VpgUqpFrLcw1TEdBR2nRG21RsCBI1wZjzjTqB9//0+65GG0bLosuzAmg EtFCYg79Jvaw4X3GF+2XTNPR05PwYh0mFYjf9KihQceBV4unJ7PNpHbgpSVC4lufR+l9R gG7n5ma4v8GU9mfumroTWd3hkq/i2E3nEpIhtBCV64yrEyLJodEQ+2aGWFfaQcrCyiS3b vjiY6v5zB1FW3Ce8YS8Wr8ST2bARq5cW5Pfynx+hpaSfZT65v3iqsCcE+t4Q/cFGyTA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=ryhnJMNN; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.49 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013049.outbound.protection.outlook.com [52.101.72.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A16D606A330; Thu, 3 Dec 2026 16:19:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A16D606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=ryhnJMNN ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QvKFv0XlpW4JKxyjkT/2/Q75iCw/fX2wED2Tc7exLKRucaqpdoKAFCtapHtgrxgfmfGuXVwwTdK4EEPgrGibgC1Y5pIQxux9O+g/vwOwvR+PetPK95PTFkQvKsrbtQBBueSjs2tSLd9nFMEqzJVvLIafKKGbLEeLnB/Yg5Elu7/l0FCkVqb9j/Uc015+nTYeZ/zIy+wSrJI7NvyPbiOM3YelVwIkTu7IIfOXHr433SlChLh8DDVXOQpTKabsH03b/CM6dgKy74wWt7ITHCkl+cUME/N6T7rv/ab3KwtuuSMz7jdtsKkB1yLNhtKw8wEBY10vU2niqKdi7mW7F5NG7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jYJw3O9FIMrJ6bEdlbZmHzEiLf3ZMSYoLH5BbL+MVqU=; b=Ve1OwBnxkIyuR4U3+NhswKKtmGqA1u3v6iYh27Jy6RIjL390DtGO2oiZLjp8ZZn/Su7BD7OaPeZMk1KgjnDYgqntnRSh89rkE5Oy0XJhl8516yqHTH2gF2q6hzP3kVomTISZWZe6IpzEyUrjMW3Camc1GckTJhox4t6aeY44ZOSk9H9vOrjCRNI3YvK9O67QRIbKWVrhe/nQ7oLD5dZF3W5bLgoJk5Dsb4BjQIuxiP/yJsbah+o+iIX5Fr0CUCBDAdrJaHhVbX1Cv7gDx0ONHSvN8if5lYPpHDnjyslhyWkEvGlY8x1Fcj9kN/7RxtcctkpvameGfQ7KyLwc6J1FKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jYJw3O9FIMrJ6bEdlbZmHzEiLf3ZMSYoLH5BbL+MVqU=; b=ryhnJMNN8egI8WPtWdvwHaz8VjQhwr4zECQtrkLgmrULFweL20oqP4txz4OP88mVR9KM3jQ678ivqfqlurO7dTF0x3UjNccFQfuuMePx2J8ew/gN9+PYMsmSsEKxohQiLDEBD1R9Td3fp2Sj25PMXmC92RVAJ/ibx2EtHVzT6GFfV7oOxcu+h7T7lsOu6kPFERSYejQ3xSiIgRPtEoLmLIFXAYAfEQH8BKTpLmK7I5XQThwlDIy19wMnLsr0IvDFtiHQ1NJVf5ujwUfwD9A870gkCvoxWGG/qTYPmc4V3JlJzf8B/WVw2IkGNaRIGp3+cqJwlUG2N2TajWA10FeOZQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) by PA1PR04MB10441.eurprd04.prod.outlook.com (2603:10a6:102:447::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 16:19:11 +0000 Received: from MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b]) by MI3PR04MB12438.eurprd04.prod.outlook.com ([fe80::c715:c32:8bb1:b70b%4]) with mapi id 15.21.0688.009; Thu, 3 Dec 2026 16:19:11 +0000 Date: Thu, 3 Dec 2026 10:19:00 -0600 From: Frank Li To: Vishnu Santhosh Cc: Vinod Koul , Frank Li , Stephan Gerhold , Loic Poulain , Sergey Ryazanov , Johannes Berg , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Deepak Kumar Singh Subject: Re: [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers Message-ID: References: <20261203-qcom-bam-dmux-qmap-v1-0-abc2e80a03af@oss.qualcomm.com> <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-1-abc2e80a03af@oss.qualcomm.com> X-ClientProxiedBy: PH0PR13CA0024.namprd13.prod.outlook.com (2603:10b6:510:343::16) To MI3PR04MB12438.eurprd04.prod.outlook.com (2603:10a6:290:76::14) X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MI3PR04MB12438:EE_|PA1PR04MB10441:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a47d818-f184-4813-d048-08df51592a37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|19092799006|23010399003|1800799024|7416014|376014|366016|4143699003|22082099003|18002099003|56012099006|261022075727099003|10067099003|11063799006|261026121527099003|261026140227099003|261028144727099003|261021121427099003|261009223027099003|261102123227099003|261022105027099003; X-Microsoft-Antispam-Message-Info: /sFqWnRXucObYvO7q32VD/pbIR4PVIZOdEvOm+BiZwg1Nb2jPKQ0ZMBRIKzFQ08qqhSaISalm56303+7FJCuhrz8FwmBm9fShroD0TECOVHgpbeuaR1fxu+81cijME68hEQXE2059yA8fB5Zt7rdKm7/QIP23sWfyjn8IAK27xYruLMXb5ttJuA7AeHEMkRSrD3nSCLo3+oR7noAijzOmtRisNFh7Mbc5hDgMi9QpRebzro3qyerC+bic3rroMYsPNiAo2dsPXQAs8tmfTM0FvbgUPdJ4nEB93WODkNo4vRF69emnVj+x4PnsvdaU6cK+aLFotVTrDPVRfHg+CsLc4RUvguanmir/KGe1qt7/2oOyoAOKVKQyq1JoRXtlyQQZZxNw8ETqptFCnWPCiKvfm01RmWYLwaC4pHsDDTckKnwzzgqAWnRL5S2aFUzlDDYbjhiT6oBGZ/IutBCyeP/g8KpiE16hES8Wu8eq8T/CE+30pl02CCmdQv3bQsrGT9p5QnUJOhN9PFBHUAvzqvMQH0lWnWiLpybTOw10/MrYmAR75x3Izk8tNeGDTUOIbM6QptFXAYSnKd3Jw3aVDIcjZYRDvw4EdhcpChiNQC10gjl8f+8v7TBWazEZAdPfWeZ/cFTbZtKHsiCPefdC3gqRxyXTUxfGAKBBeLudsGdbO4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MI3PR04MB12438.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(19092799006)(23010399003)(1800799024)(7416014)(376014)(366016)(4143699003)(22082099003)(18002099003)(56012099006)(261022075727099003)(10067099003)(11063799006)(261026121527099003)(261026140227099003)(261028144727099003)(261021121427099003)(261009223027099003)(261102123227099003)(261022105027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tlVf2B9jPP1PKtfwuT3UVSapihgw6gCKG9AT0cDwk1c1xcxGcgmkFm+1kQh+?= =?us-ascii?Q?q42ph6QsG9wmmYiiQEP6lvb6cKFu8VD6ai4C1XOcB+/sIzs4bxVaPbenieSa?= =?us-ascii?Q?CyVJRSGs9T9btKPqyn6y+xkba4qODBfq1TSVodoQDCj+eOb2YtD8oNuQenv6?= =?us-ascii?Q?0ZH26NKIR1jUrdg5AOPv1c7ErY0biMC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ascii?Q?BFx1UUhOFiRfLMhe0JmMJjBtruLIUUPRvehHSYygH9gnizTAVNvxAXZ10ebY?= =?us-ascii?Q?cDtVa3RqrKIa1mgwz5Fq90vwXuFF6zz0rd3hkdbvx6koeG+Q90SQjq55w4tN?= =?us-ascii?Q?LbA9ayyrcF5I/nG4TKWRWAXdc6xQ9cBLPMm4U24SMuQ7WVUMMhkGJqC9roty?= =?us-ascii?Q?GHv7/mVetb/p4VCFc2zh9deVpTEOc/mMrcc2NMLrun3Rn5seWKTocQ8W0EeZ?= =?us-ascii?Q?Y6JHwfhGIW96xSfJKc6LypVG6WG/2ePbK0gXIoeX1B3wKX/kDSfOgw5QbIQK?= =?us-ascii?Q?xFa2n83CJ0lKNhTKcjPPvKr8bqB7X8LjGLPNNZZlOugPjwHbG0rQXMLUQstV?= =?us-ascii?Q?STwBJ9pWpCTRcqxcsxRQbFzK8vcWfJBex51MdNufBxTqfJl7q8ATqCEDkDev?= =?us-ascii?Q?wKVnJ9Sbc3vtMlEJihN+SFPSZc3SqiuyJt+NTNej+ZyDnmQVyelrkE0+JGqN?= =?us-ascii?Q?7n8/QmJG6ugP6IqeGF7FR12qu1BMnXentlJXz9CubWCTOeZlP0waML9G9onf?= =?us-ascii?Q?sSe5uNnBC0mxjTjMnw/U0J/i2hcOl37JRQ8ds7vrk/jIr2C/RpsAOAp07u+6?= =?us-ascii?Q?ejDq7uX7VHk0KRjt6zAXy8YTdy+wJOXQs/lBJ649VT4wISbBHJTJTRrsXwmg?= =?us-ascii?Q?B+jmgML2wDvi4x5Y2cXC29ZfqAazl0UB0yjv7KfaXrd/KCMEldIL?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a47d818-f184-4813-d048-08df51592a37 X-MS-Exchange-CrossTenant-AuthSource: MI3PR04MB12438.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 16:19:11.4488 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fVe/MN1wkiEWb+VKApfifn3ujs/Cx29g7fROZYReI5eN/EuK4CedVqV3YS5ReppQgUIn7ln3J5x4Gn8r8Ay9ovxgwdbrXwdokKIpeLh1k1XogKwD7F+P1zIbwXLil051 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10441 On Thu, Dec 03, 2026 at 09:40:52PM +0530, Vishnu Santhosh wrote: > For device-to-memory transfers, the BAM writes the number of bytes it > transferred back into the size field of each completed descriptor in the > FIFO. The driver ignores this and always reports a residue of zero, so > clients cannot tell how much data was received. > > BAM-DMUX needs this, because the modem can send packets whose length is > only given by the size of the transfer. > > Read the written-back sizes when a transfer completes, and report the > unused part of the buffers as residue through callback_result. If the > BAM reports more bytes than were queued, mark the transfer as > DMA_TRANS_WRITE_FAILED. If a descriptor other than the last one is > short, the received data is not contiguous and cannot be described by a > residue, so mark the transfer as DMA_TRANS_ABORTED. > > All existing users set the plain callback, which does not receive the > result, so they are not affected. > > Co-developed-by: Deepak Kumar Singh > Signed-off-by: Deepak Kumar Singh > Signed-off-by: Vishnu Santhosh > --- > drivers/dma/qcom/bam_dma.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 53 insertions(+) > > diff --git a/drivers/dma/qcom/bam_dma.c b/drivers/dma/qcom/bam_dma.c > index e62e411dc8f8b24ecb9443b0c7eafb73ecfe8f01..b5d661b9af3df05ebd1ef909dea66a98ba938915 100644 > --- a/drivers/dma/qcom/bam_dma.c > +++ b/drivers/dma/qcom/bam_dma.c > @@ -834,6 +834,57 @@ static int bam_resume(struct dma_chan *chan) > return 0; > } > > +/** > + * bam_update_rx_result - account for bytes received by completed descriptors > + * @bchan: bam channel > + * @async_desc: descriptor whose hardware descriptors have completed > + * > + * On a producer pipe the BAM writes the number of bytes it transferred back > + * into the size field of each completed descriptor in the FIFO. Report the > + * unused part of the buffers as residue, so that clients using > + * callback_result know how much data was received. Only the last descriptor > + * of a transfer may be short, otherwise the transfer is marked as aborted. > + * Clients that rely on the residue should therefore use a single buffer of > + * at most BAM_FIFO_SIZE bytes per transfer. The residue is undefined if the > + * result is not DMA_TRANS_NOERROR. > + */ > +static void bam_update_rx_result(struct bam_chan *bchan, > + struct bam_async_desc *async_desc) > +{ > + struct bam_desc_hw *fifo = PTR_ALIGN(bchan->fifo_virt, > + sizeof(struct bam_desc_hw)); > + u32 i; > + > + if (async_desc->dir != DMA_DEV_TO_MEM) > + return; > + > + /* Read the written back sizes only after reading BAM_P_SW_OFSTS */ > + dma_rmb(); > + > + for (i = 0; i < async_desc->xfer_len; i++) { > + u16 expected = le16_to_cpu(async_desc->curr_desc[i].size); > + u16 received = le16_to_cpu(fifo[(bchan->head + i) % > + MAX_DESCRIPTORS].size); > + > + if (received > expected) { > + async_desc->vd.tx_result.result = DMA_TRANS_WRITE_FAILED; > + async_desc->vd.tx_result.residue += expected; > + continue; > + } > + > + /* > + * The next descriptor writes from its own address, so a short > + * write before the last one leaves a hole in the buffer that > + * cannot be described by the residue. > + */ > + if (received < expected && i != async_desc->num_desc - 1 && > + async_desc->vd.tx_result.result == DMA_TRANS_NOERROR) > + async_desc->vd.tx_result.result = DMA_TRANS_ABORTED; Suppose need break loop here. Need check following desc. Frank > + > + async_desc->vd.tx_result.residue += expected - received; > + } > +} > + > /** > * process_channel_irqs - processes the channel interrupts > * @bdev: bam controller > @@ -881,6 +932,8 @@ static u32 process_channel_irqs(struct bam_device *bdev) > if (avail < async_desc->xfer_len) > break; > > + bam_update_rx_result(bchan, async_desc); > + > /* manage FIFO */ > bchan->head += async_desc->xfer_len; > bchan->head %= MAX_DESCRIPTORS; > > -- > 2.34.1 >