Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ciprian Costea <ciprianmarian.costea@oss.nxp.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>,
	Vincent Mailhol <mailhol@kernel.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Haibo Chen <haibo.chen@nxp.com>
Cc: linux-can@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, NXP S32 Linux Team <s32@nxp.com>,
	imx@lists.linux.dev, Enric Balletbo <eballetb@redhat.com>,
	Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
Subject: [PATCH v7 2/4] can: rx-offload: move skb_queue and napi into struct can_rx_offload_queue
Date: Fri,  2 Oct 2026 09:12:01 +0200	[thread overview]
Message-ID: <20261002071203.1287650-3-ciprianmarian.costea@oss.nxp.com> (raw)
In-Reply-To: <20261002071203.1287650-1-ciprianmarian.costea@oss.nxp.com>

From: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>

Currently, struct can_rx_offload holds both the state filled by the
driver's IRQ handler (skb_irq_queue, mailbox range) and the state it
feeds (skb_queue, napi). To let more than one source of skbs feed the
same skb_queue and NAPI, the latter has to be separate from the
former.

Move skb_queue and napi into a new struct can_rx_offload_queue. For now
every struct can_rx_offload uses its own embedded instance, reached
through the queue pointer.

The NAPI poll function gets the netdev from napi->dev.

No functional change. The rx-offload API and its users are unchanged.

Suggested-by: Haibo Chen <haibo.chen@nxp.com>
Assisted-by: LLM
Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
---
 drivers/net/can/dev/rx-offload.c | 58 +++++++++++++++++---------------
 include/linux/can/rx-offload.h   | 14 +++++---
 2 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/drivers/net/can/dev/rx-offload.c b/drivers/net/can/dev/rx-offload.c
index 46e7b6db4a1e..92309ed47bac 100644
--- a/drivers/net/can/dev/rx-offload.c
+++ b/drivers/net/can/dev/rx-offload.c
@@ -41,16 +41,15 @@ can_rx_offload_inc(struct can_rx_offload *offload, unsigned int *val)
 
 static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota)
 {
-	struct can_rx_offload *offload = container_of(napi,
-						      struct can_rx_offload,
-						      napi);
-	struct net_device *dev = offload->dev;
-	struct net_device_stats *stats = &dev->stats;
+	struct can_rx_offload_queue *queue = container_of(napi,
+							  struct can_rx_offload_queue,
+							  napi);
+	struct net_device_stats *stats = &napi->dev->stats;
 	struct sk_buff *skb;
 	int work_done = 0;
 
 	while ((work_done < quota) &&
-	       (skb = skb_dequeue(&offload->skb_queue))) {
+	       (skb = skb_dequeue(&queue->skb_queue))) {
 		struct can_frame *cf = (struct can_frame *)skb->data;
 
 		work_done++;
@@ -66,8 +65,8 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota)
 		napi_complete_done(napi, work_done);
 
 		/* Check if there was another interrupt */
-		if (!skb_queue_empty(&offload->skb_queue))
-			napi_schedule(&offload->napi);
+		if (!skb_queue_empty(&queue->skb_queue))
+			napi_schedule(&queue->napi);
 	}
 
 	return work_done;
@@ -125,7 +124,7 @@ static int can_rx_offload_compare(struct sk_buff *a, struct sk_buff *b)
  * from the device and return the mailbox's content as a struct
  * sk_buff.
  *
- * If the struct can_rx_offload::skb_queue exceeds the maximal queue
+ * If the struct can_rx_offload_queue::skb_queue exceeds the maximal queue
  * length (struct can_rx_offload::skb_queue_len_max) or no skb can be
  * allocated, the mailbox contents is discarded by reading it into an
  * overflow buffer. This way the mailbox is marked as free by the
@@ -146,7 +145,7 @@ can_rx_offload_offload_one(struct can_rx_offload *offload, unsigned int n)
 	u32 timestamp;
 
 	/* If queue is full drop frame */
-	if (unlikely(skb_queue_len(&offload->skb_queue) >
+	if (unlikely(skb_queue_len(&offload->queue->skb_queue) >
 		     offload->skb_queue_len_max))
 		drop = true;
 
@@ -224,7 +223,7 @@ int can_rx_offload_queue_timestamp(struct can_rx_offload *offload,
 {
 	struct can_rx_offload_cb *cb;
 
-	if (skb_queue_len(&offload->skb_queue) >
+	if (skb_queue_len(&offload->queue->skb_queue) >
 	    offload->skb_queue_len_max) {
 		dev_kfree_skb_any(skb);
 		return -ENOBUFS;
@@ -268,7 +267,7 @@ EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb_queue_timestamp);
 int can_rx_offload_queue_tail(struct can_rx_offload *offload,
 			      struct sk_buff *skb)
 {
-	if (skb_queue_len(&offload->skb_queue) >
+	if (skb_queue_len(&offload->queue->skb_queue) >
 	    offload->skb_queue_len_max) {
 		dev_kfree_skb_any(skb);
 		return -ENOBUFS;
@@ -307,44 +306,46 @@ EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb_queue_tail);
 
 void can_rx_offload_irq_finish(struct can_rx_offload *offload)
 {
+	struct can_rx_offload_queue *queue = offload->queue;
 	unsigned long flags;
 	int queue_len;
 
 	if (skb_queue_empty_lockless(&offload->skb_irq_queue))
 		return;
 
-	spin_lock_irqsave(&offload->skb_queue.lock, flags);
-	skb_queue_splice_tail_init(&offload->skb_irq_queue, &offload->skb_queue);
-	spin_unlock_irqrestore(&offload->skb_queue.lock, flags);
+	spin_lock_irqsave(&queue->skb_queue.lock, flags);
+	skb_queue_splice_tail_init(&offload->skb_irq_queue, &queue->skb_queue);
+	spin_unlock_irqrestore(&queue->skb_queue.lock, flags);
 
-	queue_len = skb_queue_len(&offload->skb_queue);
+	queue_len = skb_queue_len(&queue->skb_queue);
 	if (queue_len > offload->skb_queue_len_max / 8)
 		netdev_dbg(offload->dev, "%s: queue_len=%d\n",
 			   __func__, queue_len);
 
-	napi_schedule(&offload->napi);
+	napi_schedule(&queue->napi);
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_irq_finish);
 
 void can_rx_offload_threaded_irq_finish(struct can_rx_offload *offload)
 {
+	struct can_rx_offload_queue *queue = offload->queue;
 	unsigned long flags;
 	int queue_len;
 
 	if (skb_queue_empty_lockless(&offload->skb_irq_queue))
 		return;
 
-	spin_lock_irqsave(&offload->skb_queue.lock, flags);
-	skb_queue_splice_tail_init(&offload->skb_irq_queue, &offload->skb_queue);
-	spin_unlock_irqrestore(&offload->skb_queue.lock, flags);
+	spin_lock_irqsave(&queue->skb_queue.lock, flags);
+	skb_queue_splice_tail_init(&offload->skb_irq_queue, &queue->skb_queue);
+	spin_unlock_irqrestore(&queue->skb_queue.lock, flags);
 
-	queue_len = skb_queue_len(&offload->skb_queue);
+	queue_len = skb_queue_len(&queue->skb_queue);
 	if (queue_len > offload->skb_queue_len_max / 8)
 		netdev_dbg(offload->dev, "%s: queue_len=%d\n",
 			   __func__, queue_len);
 
 	local_bh_disable();
-	napi_schedule(&offload->napi);
+	napi_schedule(&queue->napi);
 	local_bh_enable();
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_threaded_irq_finish);
@@ -353,15 +354,18 @@ static int can_rx_offload_init_queue(struct net_device *dev,
 				     struct can_rx_offload *offload,
 				     unsigned int weight)
 {
+	struct can_rx_offload_queue *queue = &offload->own_queue;
+
 	offload->dev = dev;
+	offload->queue = queue;
 
 	/* Limit queue len to 4x the weight (rounded to next power of two) */
 	offload->skb_queue_len_max = 2 << fls(weight);
 	offload->skb_queue_len_max *= 4;
-	skb_queue_head_init(&offload->skb_queue);
+	skb_queue_head_init(&queue->skb_queue);
 	__skb_queue_head_init(&offload->skb_irq_queue);
 
-	netif_napi_add_weight(dev, &offload->napi, can_rx_offload_napi_poll,
+	netif_napi_add_weight(dev, &queue->napi, can_rx_offload_napi_poll,
 			      weight);
 
 	dev_dbg(dev->dev.parent, "%s: skb_queue_len_max=%d\n",
@@ -414,14 +418,14 @@ EXPORT_SYMBOL_GPL(can_rx_offload_add_manual);
 
 void can_rx_offload_enable(struct can_rx_offload *offload)
 {
-	napi_enable(&offload->napi);
+	napi_enable(&offload->queue->napi);
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_enable);
 
 void can_rx_offload_del(struct can_rx_offload *offload)
 {
-	netif_napi_del(&offload->napi);
-	skb_queue_purge(&offload->skb_queue);
+	netif_napi_del(&offload->queue->napi);
+	skb_queue_purge(&offload->queue->skb_queue);
 	__skb_queue_purge(&offload->skb_irq_queue);
 }
 EXPORT_SYMBOL_GPL(can_rx_offload_del);
diff --git a/include/linux/can/rx-offload.h b/include/linux/can/rx-offload.h
index d29bb4521947..fafc00fc3700 100644
--- a/include/linux/can/rx-offload.h
+++ b/include/linux/can/rx-offload.h
@@ -12,6 +12,11 @@
 #include <linux/netdevice.h>
 #include <linux/can.h>
 
+struct can_rx_offload_queue {
+	struct sk_buff_head skb_queue;
+	struct napi_struct napi;
+};
+
 struct can_rx_offload {
 	struct net_device *dev;
 
@@ -19,16 +24,17 @@ struct can_rx_offload {
 					unsigned int mb, u32 *timestamp,
 					bool drop);
 
-	struct sk_buff_head skb_queue;
 	struct sk_buff_head skb_irq_queue;
 	u32 skb_queue_len_max;
 
 	unsigned int mb_first;
 	unsigned int mb_last;
 
-	struct napi_struct napi;
-
 	bool inc;
+
+	/* Points to own_queue. */
+	struct can_rx_offload_queue *queue;
+	struct can_rx_offload_queue own_queue;
 };
 
 int can_rx_offload_add_timestamp(struct net_device *dev,
@@ -59,7 +65,7 @@ void can_rx_offload_enable(struct can_rx_offload *offload);
 
 static inline void can_rx_offload_disable(struct can_rx_offload *offload)
 {
-	napi_disable(&offload->napi);
+	napi_disable(&offload->queue->napi);
 }
 
 #endif /* !_CAN_RX_OFFLOAD_H */
-- 
2.43.0



  parent reply	other threads:[~2026-10-02  7:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02  7:11 [PATCH v7 0/4] can: rx-offload: allow more than one receive source Ciprian Costea
2026-10-02  7:12 ` [PATCH v7 1/4] can: at91_can: release the rx-offload on teardown Ciprian Costea
2026-10-02  7:12 ` Ciprian Costea [this message]
2026-10-02  7:12 ` [PATCH v7 3/4] can: rx-offload: allow more than one receive source Ciprian Costea
2026-10-03 21:36   ` netdev-bot+sashiko
2026-10-05  9:46     ` Ciprian Marian Costea
2026-10-05 10:48     ` Marc Kleine-Budde
2026-10-02  7:12 ` [PATCH v7 4/4] can: flexcan: use one rx-offload source per IRQ line Ciprian Costea
2026-10-03 21:36   ` netdev-bot+sashiko

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=20261002071203.1287650-3-ciprianmarian.costea@oss.nxp.com \
    --to=ciprianmarian.costea@oss.nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=eballetb@redhat.com \
    --cc=haibo.chen@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol@kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=nicolas.ferre@microchip.com \
    --cc=s32@nxp.com \
    /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