All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] can: mp251x: fix mcp2515 stops receiving problem
@ 2014-05-12 17:06 Marc Kleine-Budde
  2014-05-12 17:07 ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2014-05-12 17:06 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Rost, Martin, Alexander Shiyan, Marc Kleine-Budde

From: "Rost, Martin" <Martin.Rost@tonfunk.de>

The mcp2515 sometimes seems to trigger an interrupt with the corresponding
register not being set yet. This makes the driver exit the interrupt because
there is obviously nothing to do, but the interrupt line is kept low.
Therefore the driver does not see any more interrupts until the chip is reset
(via interface down/up).

This patch changes the IST to first check the IRQ registers, and wait up to 10
ms if an event really occurrs. If the IRQ register is still empty after 10ms,
a kernel message gets issued. The IST loop is rearranged to evaluate the IRQ
register at the last moment before exiting, to not miss a late irq event.

Not-Signed-off-by: Martin Rost <Martin.Rost@tonfunk.de>
Cc: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/spi/mcp251x.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index 5df239e..9b7f3cb 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -804,16 +804,25 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
 	struct mcp251x_priv *priv = dev_id;
 	struct spi_device *spi = priv->spi;
 	struct net_device *net = priv->net;
+	int retry = 10;
+	u8 intf, eflag;
 
 	mutex_lock(&priv->mcp_lock);
-	while (!priv->force_quit) {
+
+	do {
+		mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
+		if (!intf)
+			mdelay(1);
+	} while (!intf && (retry--));
+
+	if (!intf)
+		dev_err(&spi->dev, "IRQ without a cause.\n");
+
+	while ((!priv->force_quit) && intf) {
 		enum can_state new_state;
-		u8 intf, eflag;
 		u8 clear_intf = 0;
 		int can_id = 0, data1 = 0;
 
-		mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
-
 		/* mask out flags we don't care about */
 		intf &= CANINTF_RX | CANINTF_TX | CANINTF_ERR;
 
@@ -911,9 +920,6 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
 			}
 		}
 
-		if (intf == 0)
-			break;
-
 		if (intf & CANINTF_TX) {
 			net->stats.tx_packets++;
 			net->stats.tx_bytes += priv->tx_len - 1;
@@ -925,6 +931,7 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
 			netif_wake_queue(net);
 		}
 
+		mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
 	}
 	mutex_unlock(&priv->mcp_lock);
 	return IRQ_HANDLED;
-- 
2.0.0.rc0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: mp251x: fix mcp2515 stops receiving problem
  2014-05-12 17:06 [PATCH] can: mp251x: fix mcp2515 stops receiving problem Marc Kleine-Budde
@ 2014-05-12 17:07 ` Marc Kleine-Budde
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2014-05-12 17:07 UTC (permalink / raw)
  To: linux-can; +Cc: kernel, Rost, Martin, Alexander Shiyan

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

On 05/12/2014 07:06 PM, Marc Kleine-Budde wrote:
> From: "Rost, Martin" <Martin.Rost@tonfunk.de>
> 
> The mcp2515 sometimes seems to trigger an interrupt with the corresponding
> register not being set yet. This makes the driver exit the interrupt because
> there is obviously nothing to do, but the interrupt line is kept low.
> Therefore the driver does not see any more interrupts until the chip is reset
> (via interface down/up).
> 
> This patch changes the IST to first check the IRQ registers, and wait up to 10
> ms if an event really occurrs. If the IRQ register is still empty after 10ms,
> a kernel message gets issued. The IST loop is rearranged to evaluate the IRQ
> register at the last moment before exiting, to not miss a late irq event.
> 
> Not-Signed-off-by: Martin Rost <Martin.Rost@tonfunk.de>

Martin, can I add your S-o-b [1]?

> Cc: Alexander Shiyan <shc_work@mail.ru>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

[1]
http://lxr.free-electrons.com/source/Documentation/SubmittingPatches#L307

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] can: mp251x: fix mcp2515 stops receiving problem
@ 2014-05-12 17:17 Rost, Martin
  0 siblings, 0 replies; 3+ messages in thread
From: Rost, Martin @ 2014-05-12 17:17 UTC (permalink / raw)
  To: linux-can@vger.kernel.org

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

>> Not-Signed-off-by: Martin Rost <Martin.Rost@tonfunk.de>
> Martin, can I add your S-o-b [1]?

Please do so. Sorry, I was not aware when an S-o-b is due.

Regards,
Martin

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 2015 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-12 17:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-12 17:06 [PATCH] can: mp251x: fix mcp2515 stops receiving problem Marc Kleine-Budde
2014-05-12 17:07 ` Marc Kleine-Budde
  -- strict thread matches above, loose matches on Subject: below --
2014-05-12 17:17 Rost, Martin

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.