Linux CAN drivers development
 help / color / mirror / Atom feed
From: dariobin@libero.it
To: Jacob Kroon <jacob.kroon@gmail.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
	linux-can@vger.kernel.org, wg@grandegger.com
Subject: Re: CM-ITC, pch_can/c_can_pci, sendto() returning ENOBUFS
Date: Fri, 23 Sep 2022 21:45:04 +0200 (CEST)	[thread overview]
Message-ID: <1885528784.804387.1663962304792@mail1.libero.it> (raw)
In-Reply-To: <8665ef57-17fb-dfd7-afa2-8e5bebceb617@gmail.com>

Hi Jacob,

> Il 23/09/2022 21:21 Jacob Kroon <jacob.kroon@gmail.com> ha scritto:
> 
>  
> On 9/23/22 21:03, Jacob Kroon wrote:
> > Hi Dario,
> > 
> > On 9/23/22 19:55, dariobin@libero.it wrote:
> >> Hi Michael,
> >>
> >>> Il 23/09/2022 13:36 Marc Kleine-Budde <mkl@pengutronix.de> ha scritto:
> >>>
> >>> On 16.09.2022 06:14:58, Jacob Kroon wrote:
> >>>> What I do know is that if I revert commit:
> >>>>
> >>>> "can: c_can: cache frames to operate as a true FIFO"
> >>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=387da6bc7a826cc6d532b1c0002b7c7513238d5f
> >>>>
> >>>> then everything looks good. I don't get any BUG messages, and the host
> >>>> has been running overnight without problems, so it seems to have fixed
> >>>> the network interface lockup as well.
> >>>
> >>> Jacob, after this mail, I'll send 2 patches. One tries to disable the
> >>> cache feature for C_CAN cores, the other shuts a potential race window.
> >>
> >> About the "can: c_can: don't cache TX messages for C_CAN cores" patch:
> >> Could it make sense to change the c_can_start_xmit in this way
> >>
> >> -       if (idx < c_can_get_tx_tail(tx_ring))
> >> -               cmd &= ~IF_COMM_TXRQST; /* Cache the message */
> >> +       if (idx < c_can_get_tx_tail(tx_ring)) {
> >> +               if (priv->type == BOSCH_D_CAN) {
> >> +                       cmd &= ~IF_COMM_TXRQST; /* Cache the message */
> >> +               } else {
> >> +                       netif_stop_queue(priv->dev);
> >> +                       return NETDEV_TX_BUSY;
> >> +               }
> >> +       }
> >>
> >> without changing the c_can_get_tx_{free,busy} routines ?
> >>
> > 
> > I can test, so you suggest only doing the above patch, or were there 
> > other parts from Marc's patch you wanted in ?
> >
> 
> Well I tried only the above, and the patch below
> 
> diff --git a/drivers/net/can/c_can/c_can_main.c 
> b/drivers/net/can/c_can/c_can_main.c
> index a7362af0babb..21d0a55ebbb3 100644
> --- a/drivers/net/can/c_can/c_can_main.c
> +++ b/drivers/net/can/c_can/c_can_main.c
> @@ -468,8 +468,14 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff 
> *skb,
>   	if (c_can_get_tx_free(tx_ring) == 0)
>   		netif_stop_queue(dev);
> 
> -	if (idx < c_can_get_tx_tail(tx_ring))
> -		cmd &= ~IF_COMM_TXRQST; /* Cache the message */
> +	if (idx < c_can_get_tx_tail(tx_ring)) {
> +		if (priv->type == BOSCH_D_CAN) {
> +			cmd &= ~IF_COMM_TXRQST; /* Cache the message */
> +		} else {
> +			netif_stop_queue(priv->dev);
> +			return NETDEV_TX_BUSY;
> +		}
> +	}
> 
>   	/* Store the message in the interface so we can call
>   	 * can_put_echo_skb(). We must do this before we enable
> @@ -761,7 +767,7 @@ static void c_can_do_tx(struct net_device *dev)
> 
>   	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 */
> 
> 
> but they both seem to lockup the network.
> 

I didn't understand if you applied two patches separately or not.
This was the only patch I had thought of. Which was similar to Marc's 
for the interrupt part but differed in the c_can_start_xmit part.

--- a/drivers/net/can/c_can/c_can_main.c
+++ b/drivers/net/can/c_can/c_can_main.c
@@ -464,13 +464,19 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb,
                return NETDEV_TX_BUSY;
 
        idx = c_can_get_tx_head(tx_ring);
+       if (idx < c_can_get_tx_tail(tx_ring)) {
+               if (priv->type == BOSCH_D_CAN) {
+                       cmd &= ~IF_COMM_TXRQST; /* Cache the message */
+               } else {
+                       netif_stop_queue(priv->dev);
+                       return NETDEV_TX_BUSY;
+               }
+       }
+
        tx_ring->head++;
        if (c_can_get_tx_free(tx_ring) == 0)
                netif_stop_queue(dev);
 
-       if (idx < c_can_get_tx_tail(tx_ring))
-               cmd &= ~IF_COMM_TXRQST; /* Cache the message */
-
        /* Store the message in the interface so we can call
         * can_put_echo_skb(). We must do this before we enable
         * transmit as we might race against do_tx().
@@ -723,7 +729,6 @@ static void c_can_do_tx(struct net_device *dev)
        struct c_can_tx_ring *tx_ring = &priv->tx;
        struct net_device_stats *stats = &dev->stats;
        u32 idx, obj, pkts = 0, bytes = 0, pend;
-       u8 tail;
 
        if (priv->msg_obj_tx_last > 32)
                pend = priv->read_reg32(priv, C_CAN_INTPND3_REG);
@@ -759,15 +764,20 @@ static void c_can_do_tx(struct net_device *dev)
        stats->tx_bytes += bytes;
        stats->tx_packets += pkts;
 
-       tail = c_can_get_tx_tail(tx_ring);
+       if (priv->type == BOSCH_D_CAN) {
+               u8 tail;
+
+               tail = c_can_get_tx_tail(tx_ring);
 
-       if (tail == 0) {
-               u8 head = c_can_get_tx_head(tx_ring);
+               if (tail == 0) {
+                       u8 head = c_can_get_tx_head(tx_ring);
 
-               /* Start transmission for all cached messages */
-               for (idx = tail; idx < head; idx++) {
-                       obj = idx + priv->msg_obj_tx_first;
-                       c_can_object_put(dev, IF_NAPI, obj, IF_COMM_TXRQST);
+                       /* Start transmission for all cached messages */
+                       for (idx = tail; idx < head; idx++) {
+                               obj = idx + priv->msg_obj_tx_first;
+                               c_can_object_put(dev, IF_NAPI, obj,
+                                                IF_COMM_TXRQST);
+                       }
                }
        }
 }

I changed it a little from the previous email because I noticed a problem.

Thanks and regards,
Dario

> Jacob

  reply	other threads:[~2022-09-23 19:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25 13:25 CM-ITC, pch_can/c_can_pci, sendto() returning ENOBUFS Jacob Kroon
2022-08-26 11:24 ` Jacob Kroon
2022-08-29  9:14   ` Jacob Kroon
2022-08-29 13:20     ` Jacob Kroon
2022-08-29 13:53       ` Oliver Hartkopp
2022-08-30 12:59         ` Jacob Kroon
2022-08-30 19:15           ` Oliver Hartkopp
2022-09-01  9:38             ` Jacob Kroon
2022-09-01 16:35               ` Oliver Hartkopp
2022-09-02 15:13                 ` Jacob Kroon
2022-09-02 16:39                   ` Jacob Kroon
2022-09-05 14:17                   ` Marc Kleine-Budde
2022-09-05 15:54               ` Marc Kleine-Budde
2022-09-16  4:14                 ` Jacob Kroon
2022-09-19 23:24                   ` Jacob Kroon
2022-09-20  1:23                     ` Vincent Mailhol
2022-09-20  5:08                       ` Jacob Kroon
2022-09-21  7:25                     ` dariobin
2022-09-21  7:47                       ` Marc Kleine-Budde
2022-09-21  8:26                         ` Jacob Kroon
2022-09-21  9:55                         ` Oliver Hartkopp
2022-09-21 10:32                           ` Marc Kleine-Budde
2022-09-21 10:39                             ` Oliver Hartkopp
2022-09-21 10:53                               ` Marc Kleine-Budde
2022-09-21 11:00                                 ` Oliver Hartkopp
2022-09-22  7:20                         ` dariobin
2022-09-23 11:36                   ` Marc Kleine-Budde
2022-09-23 17:55                     ` dariobin
2022-09-23 19:03                       ` Jacob Kroon
2022-09-23 19:21                         ` Jacob Kroon
2022-09-23 19:45                           ` dariobin [this message]
2022-09-23 20:27                             ` Jacob Kroon
2022-09-24  5:17                               ` Jacob Kroon
2022-09-28  8:25                                 ` Marc Kleine-Budde
2022-09-28  8:28                                   ` Jacob Kroon
2022-09-28  8:02                             ` Marc Kleine-Budde

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=1885528784.804387.1663962304792@mail1.libero.it \
    --to=dariobin@libero.it \
    --cc=jacob.kroon@gmail.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --cc=wg@grandegger.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