Skip to contentSkip to conversation

pull-request: can 2022-09-28

PATCH New Marc Kleine-Budde 2 participants 3 messages Sep 28, 2022

Subsystems (4)
lore
Share & tools
lore

Marc Kleine-Budde

author maintainer
#0 lore raw

cover pull-request: can 2022-09-28

Hello Jakub, hello David,

this is a pull request of 1 patch for net/main.

The patch is by me and targets the c_can driver. It disables an optimization in the TX path of C_CAN cores which causes problems.

regards,
Marc

---

The following changes since commit 44d70bb561dac9363f45787aa93dfca36877ee01:

Merge tag 'wireless-2022-09-27' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless (2022-09-27 16:52:45 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-6.0-20220928

for you to fetch changes up to 81d192c2ce74157e717e1fc4b68791f82f7499d4:

can: c_can: don't cache TX messages for C_CAN cores (2022-09-28 10:34:04 +0200)

----------------------------------------------------------------
linux-can-fixes-for-6.0-20220928

----------------------------------------------------------------
Marc Kleine-Budde (1):
can: c_can: don't cache TX messages for C_CAN cores

 drivers/net/can/c_can/c_can.h      | 17 +++++++++++++++--
 drivers/net/can/c_can/c_can_main.c | 11 +++++------
 2 files changed, 20 insertions(+), 8 deletions(-)
author maintainer
#1 lore raw

PATCH 1/1 can: c_can: don't cache TX messages for C_CAN cores

As Jacob noticed, the optimization introduced in 387da6bc7a82 ("can:
c_can: cache frames to operate as a true FIFO") doesn't properly work on C_CAN, but on D_CAN IP cores. The exact reasons are still unknown.

For now disable caching if CAN frames in the TX path for C_CAN cores.

---
 drivers/net/can/c_can/c_can.h      | 17 +++++++++++++++--
 drivers/net/can/c_can/c_can_main.c | 11 +++++------
 2 files changed, 20 insertions(+), 8 deletions(-)
drivers/net/can/c_can/c_can.h +15 -2
index f23a03300a81..029cd8194ed5 100644
@@ -235,9 +235,22 @@ static inline u8 c_can_get_tx_tail(const struct c_can_tx_ring *ring)
 	return ring->tail & (ring->obj_num - 1);
 }
 
-static inline u8 c_can_get_tx_free(const struct c_can_tx_ring *ring)
+static inline u8 c_can_get_tx_free(const struct c_can_priv *priv,
+				   const struct c_can_tx_ring *ring)
 {
-	return ring->obj_num - (ring->head - ring->tail);
+	u8 head = c_can_get_tx_head(ring);
+	u8 tail = c_can_get_tx_tail(ring);
+
+	if (priv->type == BOSCH_D_CAN)
+		return ring->obj_num - (ring->head - ring->tail);
+
+	/* This is not a FIFO. C/D_CAN sends out the buffers
+	 * prioritized. The lowest buffer number wins.
+	 */
+	if (head < tail)
+		return 0;
+
+	return ring->obj_num - head;
 }
 
 #endif /* C_CAN_H */
drivers/net/can/c_can/c_can_main.c +5 -6
index dc8132862f33..d6605dbb7737 100644
@@ -429,7 +429,7 @@ static void c_can_setup_receive_object(struct net_device *dev, int iface,
 static bool c_can_tx_busy(const struct c_can_priv *priv,
 			  const struct c_can_tx_ring *tx_ring)
 {
-	if (c_can_get_tx_free(tx_ring) > 0)
+	if (c_can_get_tx_free(priv, tx_ring) > 0)
 		return false;
 
 	netif_stop_queue(priv->dev);
@@ -437,7 +437,7 @@ static bool c_can_tx_busy(const struct c_can_priv *priv,
 	/* Memory barrier before checking tx_free (head and tail) */
 	smp_mb();
 
-	if (c_can_get_tx_free(tx_ring) == 0) {
+	if (c_can_get_tx_free(priv, tx_ring) == 0) {
 		netdev_dbg(priv->dev,
 			   "Stopping tx-queue (tx_head=0x%08x, tx_tail=0x%08x, len=%d).\n",
 			   tx_ring->head, tx_ring->tail,
@@ -465,7 +465,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
 
 	idx = c_can_get_tx_head(tx_ring);
 	tx_ring->head++;
-	if (c_can_get_tx_free(tx_ring) == 0)
+	if (c_can_get_tx_free(priv, tx_ring) == 0)
 		netif_stop_queue(dev);
 
 	if (idx < c_can_get_tx_tail(tx_ring))
@@ -748,7 +748,7 @@ static void c_can_do_tx(struct net_device *dev)
 		return;
 
 	tx_ring->tail += pkts;
-	if (c_can_get_tx_free(tx_ring)) {
+	if (c_can_get_tx_free(priv, tx_ring)) {
 		/* Make sure that anybody stopping the queue after
 		 * this sees the new tx_ring->tail.
 		 */
@@ -760,8 +760,7 @@ static void c_can_do_tx(struct net_device *dev)
 	stats->tx_packets += pkts;
 
 	tail = c_can_get_tx_tail(tx_ring);
-
-	if (tail == 0) {
+	if (priv->type == BOSCH_D_CAN && tail == 0) {
 		u8 head = c_can_get_tx_head(tx_ring);
 
 		/* Start transmission for all cached messages */

base-commit: 44d70bb561dac9363f45787aa93dfca36877ee01

Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH net] can: c_can: don't cache TX messages for C_CAN cores

This patch was applied to netdev/net.git (master) by Marc Kleine-Budde <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Marc Kleine-Budde <[email protected]>:

Quoted 14 lines · On Wed, 28 Sep 2022 11:06:29 +0200 you wrote:

As Jacob noticed, the optimization introduced in 387da6bc7a82 ("can:
c_can: cache frames to operate as a true FIFO") doesn't properly work on C_CAN, but on D_CAN IP cores. The exact reasons are still unknown.

For now disable caching if CAN frames in the TX path for C_CAN cores.

Quoted 1 line

[...]

Here is the summary with links:
- [net] can: c_can: don't cache TX messages for C_CAN cores

    https://git.kernel.org/netdev/net/c/81d192c2ce74

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html