mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vishnu Santhosh <vishnu.santhosh@oss.qualcomm.com>
To: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Stephan Gerhold <stephan@gerhold.net>,
	Loic Poulain <loic.poulain@oss.qualcomm.com>,
	Sergey Ryazanov <ryazanov.s.a@gmail.com>,
	Johannes Berg <johannes@sipsolutions.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vishnu Santhosh <vishnu.santhosh@oss.qualcomm.com>,
	Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
Subject: [PATCH net-next 2/3] net: wwan: qcom_bam_dmux: use DMA transfer size for RX packets
Date: Thu, 03 Dec 2026 21:40:53 +0530	[thread overview]
Message-ID: <20261203-qcom-bam-dmux-qmap-v1-2-abc2e80a03af@oss.qualcomm.com> (raw)
In-Reply-To: <20261203-qcom-bam-dmux-qmap-v1-0-abc2e80a03af@oss.qualcomm.com>

With QMAP, the multiplexing protocol handled by the rmnet driver, the
modem sets the length in the header of DATA packets to 0xffff. This
means that the payload fills the rest of the DMA transfer, which can
hold several QMAP packets. The driver treats 0xffff as a real length
and drops every such packet:

  Data larger than buffer? (65535 > 2040)

Get the number of received bytes from the DMA result, and:

 - drop the buffer if the transfer failed or is shorter than a header
 - take the payload length from the received size if the header says
   0xffff
 - drop packets that claim more data than was received, replacing the
   check against the buffer size, since a transfer cannot be larger
   than the buffer

Co-developed-by: Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
Signed-off-by: Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>
Signed-off-by: Vishnu Santhosh <vishnu.santhosh@oss.qualcomm.com>
---
 drivers/net/wwan/qcom_bam_dmux.c | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wwan/qcom_bam_dmux.c b/drivers/net/wwan/qcom_bam_dmux.c
index e1cc3038a724ee2a3eba4a9d97715f1f5966452d..a7d05b1b8b1230d1d54e9a7abcbc16a16681797e 100644
--- a/drivers/net/wwan/qcom_bam_dmux.c
+++ b/drivers/net/wwan/qcom_bam_dmux.c
@@ -30,6 +30,7 @@
 #define BAM_DMUX_NUM_SKB		32
 
 #define BAM_DMUX_HDR_MAGIC		0x33fc
+#define BAM_DMUX_LEN_FROM_DMA		0xffff
 
 #define BAM_DMUX_AUTOSUSPEND_DELAY	1000
 #define BAM_DMUX_REMOTE_TIMEOUT		msecs_to_jiffies(2000)
@@ -467,7 +468,8 @@ static void bam_dmux_register_netdev_work(struct work_struct *work)
 	}
 }
 
-static void bam_dmux_rx_callback(void *data);
+static void bam_dmux_rx_callback(void *data,
+				 const struct dmaengine_result *result);
 
 static bool bam_dmux_skb_dma_submit_rx(struct bam_dmux_skb_dma *skb_dma)
 {
@@ -482,7 +484,7 @@ static bool bam_dmux_skb_dma_submit_rx(struct bam_dmux_skb_dma *skb_dma)
 		return false;
 	}
 
-	dmaengine_desc_set_callback(desc, bam_dmux_rx_callback, NULL, skb_dma);
+	dmaengine_desc_set_callback(desc, NULL, bam_dmux_rx_callback, skb_dma);
 	dmaengine_submit(desc);
 	return true;
 }
@@ -500,21 +502,23 @@ static bool bam_dmux_skb_dma_queue_rx(struct bam_dmux_skb_dma *skb_dma, gfp_t gf
 	       bam_dmux_skb_dma_submit_rx(skb_dma);
 }
 
-static void bam_dmux_cmd_data(struct bam_dmux_skb_dma *skb_dma)
+static void bam_dmux_cmd_data(struct bam_dmux_skb_dma *skb_dma,
+			      unsigned int rx_len)
 {
 	struct bam_dmux *dmux = skb_dma->dmux;
 	struct sk_buff *skb = skb_dma->skb;
 	struct bam_dmux_hdr *hdr = (struct bam_dmux_hdr *)skb->data;
 	struct net_device *netdev = dmux->netdevs[hdr->ch];
+	unsigned int avail = rx_len - sizeof(*hdr);
 
 	if (!netdev || !netif_running(netdev)) {
 		dev_warn(dmux->dev, "Data for inactive channel %u\n", hdr->ch);
 		return;
 	}
 
-	if (hdr->len > BAM_DMUX_MAX_DATA_SIZE) {
-		dev_err(dmux->dev, "Data larger than buffer? (%u > %u)\n",
-			hdr->len, (u16)BAM_DMUX_MAX_DATA_SIZE);
+	if (hdr->len > avail) {
+		dev_err(dmux->dev, "Data larger than received? (%u > %u)\n",
+			hdr->len, avail);
 		return;
 	}
 
@@ -574,15 +578,29 @@ static void bam_dmux_cmd_close(struct bam_dmux *dmux, struct bam_dmux_hdr *hdr)
 		netif_device_detach(netdev);
 }
 
-static void bam_dmux_rx_callback(void *data)
+static void bam_dmux_rx_callback(void *data,
+				 const struct dmaengine_result *result)
 {
 	struct bam_dmux_skb_dma *skb_dma = data;
 	struct bam_dmux *dmux = skb_dma->dmux;
 	struct sk_buff *skb = skb_dma->skb;
 	struct bam_dmux_hdr *hdr = (struct bam_dmux_hdr *)skb->data;
+	unsigned int rx_len;
 
 	bam_dmux_skb_dma_unmap(skb_dma, DMA_FROM_DEVICE);
 
+	if (result->result != DMA_TRANS_NOERROR || result->residue > skb->len) {
+		dev_err(dmux->dev, "RX DMA failed: %d (residue %u)\n",
+			result->result, result->residue);
+		goto out;
+	}
+
+	rx_len = skb->len - result->residue;
+	if (rx_len < sizeof(*hdr)) {
+		dev_err(dmux->dev, "RX shorter than header: %u\n", rx_len);
+		goto out;
+	}
+
 	if (hdr->magic != BAM_DMUX_HDR_MAGIC) {
 		dev_err(dmux->dev, "Invalid magic in header: %#x\n", hdr->magic);
 		goto out;
@@ -593,9 +611,13 @@ static void bam_dmux_rx_callback(void *data)
 		goto out;
 	}
 
+	/* The remote side may leave it to us to use the DMA transfer size */
+	if (hdr->cmd == BAM_DMUX_CMD_DATA && hdr->len == BAM_DMUX_LEN_FROM_DMA)
+		hdr->len = rx_len - sizeof(*hdr);
+
 	switch (hdr->cmd) {
 	case BAM_DMUX_CMD_DATA:
-		bam_dmux_cmd_data(skb_dma);
+		bam_dmux_cmd_data(skb_dma, rx_len);
 		break;
 	case BAM_DMUX_CMD_OPEN:
 		bam_dmux_cmd_open(dmux, hdr);

-- 
2.34.1


  parent reply	other threads:[~2026-12-03 16:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:10 [PATCH net-next 0/3] net: wwan: qcom_bam_dmux: Add QMAP support Vishnu Santhosh
2026-12-03 16:10 ` [PATCH net-next 1/3] dmaengine: qcom: bam_dma: report residue for completed RX transfers Vishnu Santhosh
2026-12-03 16:19   ` Frank Li
2026-12-03 16:10 ` Vishnu Santhosh [this message]
2026-12-03 16:10 ` [PATCH net-next 3/3] net: wwan: qcom_bam_dmux: enable QMAP if supported by the modem Vishnu Santhosh
2026-12-03 19:22   ` Loic Poulain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203-qcom-bam-dmux-qmap-v1-2-abc2e80a03af@oss.qualcomm.com \
    --to=vishnu.santhosh@oss.qualcomm.com \
    --cc=Frank.Li@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=deepak.singh@oss.qualcomm.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=stephan@gerhold.net \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®