mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Markus Schneider-Pargmann" <msp@baylibre.com>
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Chandrasekar Ramakrishnan" <rcsekar@samsung.com>,
	"Vincent Mailhol" <mailhol.vincent@wanadoo.fr>,
	"Patrik Flykt" <patrik.flykt@linux.intel.com>,
	"Dong Aisheng" <b29396@freescale.com>,
	"Varka Bhadram" <varkabhadram@gmail.com>,
	"Wu Bo" <wubo.oduw@gmail.com>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	<linux-can@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<kernel@pengutronix.de>
Subject: Re: [PATCH v2 2/7] can: m_can: only handle active interrupts
Date: Wed, 10 Sep 2025 18:04:38 +0200	[thread overview]
Message-ID: <DCP8XXYDW0EI.2QLN0NYPOWXVJ@baylibre.com> (raw)
In-Reply-To: <20250910-strange-hopeful-chamois-6c4b6f-mkl@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 3952 bytes --]

On Wed Sep 10, 2025 at 5:06 PM CEST, Marc Kleine-Budde wrote:
> On 10.09.2025 16:28:54, Marc Kleine-Budde wrote:
>> On 10.09.2025 10:41:28, Markus Schneider-Pargmann wrote:
>> > > diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
>> > > index fe74dbd2c966..16b38e6c3985 100644
>> > > --- a/drivers/net/can/m_can/m_can.c
>> > > +++ b/drivers/net/can/m_can/m_can.c
>> > > @@ -1057,6 +1057,7 @@ static int m_can_poll(struct napi_struct *napi, int quota)
>> > >  	u32 irqstatus;
>> > >  
>> > >  	irqstatus = cdev->irqstatus | m_can_read(cdev, M_CAN_IR);
>> > > +	irqstatus &= cdev->active_interrupts;
>> > >  
>> > >  	work_done = m_can_rx_handler(dev, quota, irqstatus);
>> > >  
>> > > @@ -1243,6 +1244,8 @@ static int m_can_interrupt_handler(struct m_can_classdev *cdev)
>> > >  	}
>> > >  
>> > >  	m_can_coalescing_update(cdev, ir);
>> > > +
>> > > +	ir &= cdev->active_interrupts;
>> > 
>> > m_can_coalescing_update() can change active_interrupts, meaning the
>> > interrupt that caused the interrupt handler to run may be disabled in
>> > active_interrupts above and then masked in this added line. Would that
>> > still work or does it confuse the hardware?
>> 
>> I think m_can_coalescing_update() expects the RX/TX will be cleared. Are
>> the following comments OK...
>> 
>> | diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
>> | index 16b38e6c3985..8cb9cc1cddbf 100644
>> | --- a/drivers/net/can/m_can/m_can.c
>> | +++ b/drivers/net/can/m_can/m_can.c
>> | @@ -1188,28 +1188,39 @@ static int m_can_echo_tx_event(struct net_device *dev)
>> |  
>> |  static void m_can_coalescing_update(struct m_can_classdev *cdev, u32 ir)
>> |  {
>> |          u32 new_interrupts = cdev->active_interrupts;
>> |          bool enable_rx_timer = false;
>> |          bool enable_tx_timer = false;
>> |  
>> |          if (!cdev->net->irq)
>> |                  return;
>> |  
>> | +        /* If there is a packet in the FIFO then:
>> | +         * - start timer
>> | +         * - disable not empty IRQ
>> | +         * - handle FIFO
>>                 ^^^^^^^^^^^
>> 
>> ...especially this one?
>> 
>> | +         */
>> |          if (cdev->rx_coalesce_usecs_irq > 0 && (ir & (IR_RF0N | IR_RF0W))) {
>> |                  enable_rx_timer = true;
>> |                  new_interrupts &= ~IR_RF0N;
>> |          }
>> |          if (cdev->tx_coalesce_usecs_irq > 0 && (ir & (IR_TEFN | IR_TEFW))) {
>> |                  enable_tx_timer = true;
>> |                  new_interrupts &= ~IR_TEFN;
>> |          }
>> | +
>> | +        /* If:
>> | +         * - timer is not going to be start
>> | +         * - and timer is not active
>> | +         * -> then enable FIFO empty IRQ
>> | +         */
>> |          if (!enable_rx_timer && !hrtimer_active(&cdev->hrtimer))
>> |                  new_interrupts |= IR_RF0N;
>> |          if (!enable_tx_timer && !hrtimer_active(&cdev->hrtimer))
>> |                  new_interrupts |= IR_TEFN;
>> |  
>> |          m_can_interrupt_enable(cdev, new_interrupts);
>> |          if (enable_rx_timer | enable_tx_timer)
>> |                  hrtimer_start(&cdev->hrtimer, cdev->irq_timer_wait,
>> |                                HRTIMER_MODE_REL);
>> |  }
>
> I can't reproduce the problem I had before. I will drop this patch for
> now.
>
> In an upcoming series, however, I would still like to move
> can_coalescing_update() to the end of the IRQ handler.

The interrupts are acked just before calling m_can_coalescing_update().
I think ideally the unwanted interrupts should be disabled quick,
especially if there are SPI transfers for handling packets which take
some time.

Another point is to refresh the timer consistently so it doesn't trigger
because we are late refreshing it. The runtime of the interrupt handler
depends on the amount of work in the fifo.

Best
Markus

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 289 bytes --]

  reply	other threads:[~2025-09-10 16:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 17:53 [PATCH v2 0/7] can: m_can: fix pm_runtime and CAN state handling Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 1/7] can: m_can: m_can_plat_remove(): add missing pm_runtime_disable() Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 2/7] can: m_can: only handle active interrupts Marc Kleine-Budde
2025-09-10  8:41   ` Markus Schneider-Pargmann
2025-09-10 14:28     ` Marc Kleine-Budde
2025-09-10 15:06       ` Marc Kleine-Budde
2025-09-10 16:04         ` Markus Schneider-Pargmann [this message]
2025-09-09 17:53 ` [PATCH v2 3/7] can: m_can: m_can_handle_state_errors(): fix CAN state transition to Error Active Marc Kleine-Budde
2025-09-10  8:47   ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 4/7] can: m_can: m_can_chip_config(): bring up interface in correct state Marc Kleine-Budde
2025-09-10  8:57   ` Markus Schneider-Pargmann
2025-09-09 17:53 ` [PATCH v2 5/7] can: m_can: fix CAN state in system PM Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 6/7] can: m_can: m_can_get_berr_counter(): don't wake up controller if interface is down Marc Kleine-Budde
2025-09-09 17:53 ` [PATCH v2 7/7] can: m_can: add optional support for reset Marc Kleine-Budde
2025-09-10  9:32   ` Markus Schneider-Pargmann
2025-09-10 14:35     ` 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=DCP8XXYDW0EI.2QLN0NYPOWXVJ@baylibre.com \
    --to=msp@baylibre.com \
    --cc=b29396@freescale.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=p.zabel@pengutronix.de \
    --cc=patrik.flykt@linux.intel.com \
    --cc=rcsekar@samsung.com \
    --cc=varkabhadram@gmail.com \
    --cc=wubo.oduw@gmail.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

all inboxes | Powered by JetHome®