All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, linux-can@vger.kernel.org,
	kernel@pengutronix.de,
	Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>,
	Wolfgang Grandegger <wg@grandegger.com>,
	Joe Burmeister <joe.burmeister@devtank.co.uk>,
	linux-stable <stable@vger.kernel.org>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 09/33] can: c_can: c_can_poll(): only read status register after status IRQ
Date: Tue,  5 Nov 2019 17:31:51 +0100	[thread overview]
Message-ID: <20191105163215.30194-10-mkl@pengutronix.de> (raw)
In-Reply-To: <20191105163215.30194-1-mkl@pengutronix.de>

From: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>

When the status register is read without the status IRQ pending, the
chip may not raise the interrupt line for an upcoming status interrupt
and the driver may miss a status interrupt.

It is critical that the BUSOFF status interrupt is forwarded to the
higher layers, since no more interrupts will follow without
intervention.

Thanks to Wolfgang and Joe for bringing up the first idea.

Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Joe Burmeister <joe.burmeister@devtank.co.uk>
Fixes: fa39b54ccf28 ("can: c_can: Get rid of pointless interrupts")
Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/c_can/c_can.c | 25 ++++++++++++++++++++-----
 drivers/net/can/c_can/c_can.h |  1 +
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 606b7d8ffe13..9b61bfbea6cd 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -97,6 +97,9 @@
 #define BTR_TSEG2_SHIFT		12
 #define BTR_TSEG2_MASK		(0x7 << BTR_TSEG2_SHIFT)
 
+/* interrupt register */
+#define INT_STS_PENDING		0x8000
+
 /* brp extension register */
 #define BRP_EXT_BRPE_MASK	0x0f
 #define BRP_EXT_BRPE_SHIFT	0
@@ -1029,10 +1032,16 @@ static int c_can_poll(struct napi_struct *napi, int quota)
 	u16 curr, last = priv->last_status;
 	int work_done = 0;
 
-	priv->last_status = curr = priv->read_reg(priv, C_CAN_STS_REG);
-	/* Ack status on C_CAN. D_CAN is self clearing */
-	if (priv->type != BOSCH_D_CAN)
-		priv->write_reg(priv, C_CAN_STS_REG, LEC_UNUSED);
+	/* Only read the status register if a status interrupt was pending */
+	if (atomic_xchg(&priv->sie_pending, 0)) {
+		priv->last_status = curr = priv->read_reg(priv, C_CAN_STS_REG);
+		/* Ack status on C_CAN. D_CAN is self clearing */
+		if (priv->type != BOSCH_D_CAN)
+			priv->write_reg(priv, C_CAN_STS_REG, LEC_UNUSED);
+	} else {
+		/* no change detected ... */
+		curr = last;
+	}
 
 	/* handle state changes */
 	if ((curr & STATUS_EWARN) && (!(last & STATUS_EWARN))) {
@@ -1083,10 +1092,16 @@ static irqreturn_t c_can_isr(int irq, void *dev_id)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct c_can_priv *priv = netdev_priv(dev);
+	int reg_int;
 
-	if (!priv->read_reg(priv, C_CAN_INT_REG))
+	reg_int = priv->read_reg(priv, C_CAN_INT_REG);
+	if (!reg_int)
 		return IRQ_NONE;
 
+	/* save for later use */
+	if (reg_int & INT_STS_PENDING)
+		atomic_set(&priv->sie_pending, 1);
+
 	/* disable all interrupts and schedule the NAPI */
 	c_can_irq_control(priv, false);
 	napi_schedule(&priv->napi);
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 8acdc7fa4792..d5567a7c1c6d 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -198,6 +198,7 @@ struct c_can_priv {
 	struct net_device *dev;
 	struct device *device;
 	atomic_t tx_active;
+	atomic_t sie_pending;
 	unsigned long tx_dir;
 	int last_status;
 	u16 (*read_reg) (const struct c_can_priv *priv, enum reg index);
-- 
2.24.0.rc1

  parent reply	other threads:[~2019-11-05 16:31 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 16:31 pull-request: can 2019-11-05 Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 01/33] can: dev: add missing of_node_put() after calling of_get_child_by_name() Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 02/33] can: gs_usb: gs_can_open(): prevent memory leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 03/33] can: mcba_usb: fix use-after-free on disconnect Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 04/33] can: usb_8dev: " Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 05/33] can: flexcan: disable completely the ECC mechanism Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 06/33] can: peak_usb: fix a potential out-of-sync while decoding packets Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 07/33] can: peak_usb: fix slab info leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 08/33] can: peak_usb: report bus recovery as well Marc Kleine-Budde
2019-11-05 16:31 ` Marc Kleine-Budde [this message]
2019-11-05 16:31 ` [PATCH 10/33] can: c_can: D_CAN: c_can_chip_config(): perform a sofware reset on open Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 11/33] can: c_can: C_CAN: add bus recovery events Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 12/33] can: xilinx_can: Fix flags field initialization for axi can Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 13/33] can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 14/33] can: rx-offload: can_rx_offload_queue_tail(): " Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 15/33] can: rx-offload: can_rx_offload_offload_one(): do not increase the skb_queue beyond skb_queue_len_max Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 16/33] can: rx-offload: can_rx_offload_offload_one(): increment rx_fifo_errors on queue overflow or OOM Marc Kleine-Budde
2019-11-05 16:31 ` [PATCH 17/33] can: rx-offload: can_rx_offload_offload_one(): use ERR_PTR() to propagate error value in case of errors Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 18/33] can: rx-offload: can_rx_offload_irq_offload_timestamp(): continue on error Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 19/33] can: rx-offload: can_rx_offload_irq_offload_fifo(): " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 20/33] can: flexcan: increase error counters if skb enqueueing via can_rx_offload_queue_sorted() fails Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 21/33] can: ti_hecc: ti_hecc_error(): " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 22/33] can: ti_hecc: ti_hecc_stop(): stop the CPK on down Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 23/33] can: ti_hecc: keep MIM and MD set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 24/33] can: ti_hecc: release the mailbox a bit earlier Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 25/33] can: ti_hecc: add fifo overflow error reporting Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 26/33] can: ti_hecc: properly report state changes Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 27/33] can: ti_hecc: add missing " Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 28/33] can: j1939: fix resource leak of skb on error return paths Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 29/33] can: j1939: fix memory leak if filters was set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 30/33] can: j1939: transport: j1939_session_fresh_new(): make sure EOMA is send with the total message size set Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 31/33] can: j1939: transport: j1939_xtp_rx_eoma_one(): Add sanity check for correct total message size Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 32/33] can: mcp251x: mcp251x_restart_work_handler(): Fix potential force_quit race condition Marc Kleine-Budde
2019-11-05 16:32 ` [PATCH 33/33] can: don't use deprecated license identifiers Marc Kleine-Budde
2019-11-05 21:30 ` pull-request: can 2019-11-05 David Miller
2019-11-05 21:36   ` Marc Kleine-Budde
2019-11-07  8:45 ` request: merge net/master into net-next/master Marc Kleine-Budde
2019-11-09 20:28   ` request: merge net/master into net-next/master,request: " David Miller

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=20191105163215.30194-10-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=dev.kurt@vandijck-laurijssen.be \
    --cc=joe.burmeister@devtank.co.uk \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.