linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Klein <matthias.klein@optimeas.de>
To: wg@grandegger.com, mkl@pengutronix.de, linux-can@vger.kernel.org,
	support@karo-electronics.de
Cc: bigeasy@linutronix.de
Subject: [PATCH V2 5/5] net: can: flexcan: fix for wrong TX error count behaviour on i.MX53
Date: Mon, 28 Jul 2014 08:34:28 +0200	[thread overview]
Message-ID: <1406529268-20126-5-git-send-email-matthias.klein@optimeas.de> (raw)
In-Reply-To: <1406529268-20126-1-git-send-email-matthias.klein@optimeas.de>

Once the CAN-bus is open and a packet is sent, the controller switches
into the PASSIVE state and the TX error count goes to 0x80. When the
bus is closed and the packet gets acknowledged the controller switches
to ERROR-WARNING state and the TX error counter is decremented to 0x7f.
Everything OK so far.

When now the bus is open again and a packet is sent, the controller
switches into PASSIVE state and sets the TX error count to 0x86.
When now the bus is closed the TX error is decremented to 0x85, but
the state does not change to ERROR-WARNING. Now with each successfully
transfered packet (in PASSIVE state!) the TX error counter is
decremented, and when the TX error counter reaches 0x7f the controller
switched back into ERROR-WARNING state.

This fix sets the TX error count back to zero when entering the
ERROR-WARNING state (after the first retransfered packet is acknowledged).

Signed-off-by: Matthias Klein <matthias.klein@optimeas.de>
---
 drivers/net/can/flexcan.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index b77f1da..f9fefcb 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -479,6 +479,34 @@ static int flexcan_poll_bus_err(struct net_device *dev, u32 reg_esr)
 	return 1;
 }
 
+static void flexcan_reset_err_reg(struct flexcan_priv *priv)
+{
+	struct flexcan_regs __iomem *regs = priv->base;
+
+	/*
+	 * The reset of the error counter is ugly but I don't see any other way.
+	 * Open the CAN bus, send packet => HW goes to ERR-pasive, TX-err
+	 * counter is around 128 (maybe 129). Close the CAN-Bus, the TX-err
+	 * counter drops down to somewhere between 126 … 127, HW goes to
+	 * ERR-Warning, everything is fine.
+	 *
+	 * Now: Repeat the above procedure. What happens is that on send the
+	 * TX-err increases to around 134…136 and on connect it drops to
+	 * around 130. Occording to ESR the HW is still in passive mode _but_ it
+	 * is possible send packets - that means can send packets but has no
+	 * clue about it.
+	 * To get a consistent behavior here, the error counter are reset so we
+	 * fall back to Err-Active mode and the second "can send on open bus"
+	 * behaves just like the first one.
+	 */
+
+	flexcan_chip_freeze(priv);
+
+	flexcan_write(0, &regs->ecr);
+
+	flexcan_chip_unfreeze(priv);
+}
+
 static void do_state(struct net_device *dev,
 		     struct can_frame *cf, enum can_state new_state)
 {
@@ -537,6 +565,8 @@ static void do_state(struct net_device *dev,
 		cf->data[1] = (bec.txerr > bec.rxerr) ?
 			CAN_ERR_CRTL_TX_WARNING :
 			CAN_ERR_CRTL_RX_WARNING;
+
+		flexcan_reset_err_reg(priv);
 		break;
 	case CAN_STATE_ERROR_ACTIVE:
 		netdev_dbg(dev, "Error Active\n");
-- 
2.0.1


  parent reply	other threads:[~2014-07-28  6:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-28  6:34 [PATCH V2 1/5] net: can: flexcan: provide propper return code in ISR Matthias Klein
2014-07-28  6:34 ` [PATCH V2 2/5] net: can: flexcan: disable error interrupts in non ERR-Active state Matthias Klein
2014-07-28  6:40   ` Varka Bhadram
2014-07-28  6:34 ` [PATCH V2 3/5] net: can: flexcan: handle state passive -> warning transition Matthias Klein
2014-07-28  6:34 ` [PATCH V2 4/5] can: flexcan: fix transition from and to freeze mode in chip_{,un}freeze Matthias Klein
2014-07-28  6:38   ` Marc Kleine-Budde
2014-07-28  6:34 ` Matthias Klein [this message]
2014-07-28  6:39   ` [PATCH V2 5/5] net: can: flexcan: fix for wrong TX error count behaviour on i.MX53 Varka Bhadram
2014-07-28  7:05   ` Marc Kleine-Budde
2014-07-28  7:08     ` Sebastian Andrzej Siewior
2014-07-28  6:36 ` [PATCH V2 1/5] net: can: flexcan: provide propper return code in ISR Varka Bhadram

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=1406529268-20126-5-git-send-email-matthias.klein@optimeas.de \
    --to=matthias.klein@optimeas.de \
    --cc=bigeasy@linutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=support@karo-electronics.de \
    --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;
as well as URLs for NNTP newsgroup(s).