Skip to contentSkip to conversation

can: sun4i: fix overrun

PATCH Superseded GBert 2 participants 6 messages Oct 27, 2017 – Nov 7, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 5511583c-37ac-c6b7-f88d-1fd740fae3f5 () pengutronix ! de

GBert

author
#1 lore raw

PATCH v2 1/1 can: sun4i: fix overrun

From: Gerhard Bertelsmann <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

V2: no duplicate error reporting

---
 drivers/net/can/sun4i_can.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/sun4i_can.c +8 -2
index 68ef0a4..bcec511 100644
@@ -539,6 +539,11 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		}
 		stats->rx_over_errors++;
 		stats->rx_errors++;
+
+		/* reset the CAN IP by entering reset mode */
+		err = set_reset_mode(dev);
+		err = set_normal_mode(dev);
+
 		/* clear bit */
 		sun4i_can_write_cmdreg(priv, SUN4I_CMD_CLEAR_OR_FLAG);
 	}
@@ -653,8 +658,9 @@ static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)
 			netif_wake_queue(dev);
 			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
-		if (isrc & SUN4I_INT_RBUF_VLD) {
-			/* receive interrupt */
+		if ((isrc & SUN4I_INT_RBUF_VLD) &&
+		    !(isrc & SUN4I_INT_DATA_OR)) {
+			/* receive interrupt - don't read if overrun occurred */
 			while (status & SUN4I_STA_RBUF_RDY) {
 				/* RX buffer is not empty */
 				sun4i_can_rx(dev);
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 7 lines · GBert

From: Gerhard Bertelsmann <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

V2: no duplicate error reporting

Please don't forget your S-o-b.

Quoted 9 lines
---
 drivers/net/can/sun4i_can.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/sun4i_can.c +0 -0
index 68ef0a4..bcec511 100644

drivers/net/can/sun4i_can.c static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) · line 545

Quoted 7 lines
drivers/net/can/sun4i_can.c +4 -0
@@ -539,6 +539,11 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		}
 		stats->rx_over_errors++;
 		stats->rx_errors++;
+
+		/* reset the CAN IP by entering reset mode */
+		err = set_reset_mode(dev);
+		err = set_normal_mode(dev);

Please add the missing error handling here.

Marc

Signature · 4 lines
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   |
author
#3 lore raw

PATCH v4 1/1 can: sun4i: fix overrun

From: cb2begq <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

V4: add error handling
V3: fix compilation
V2: no duplicate error reporting

---
 drivers/net/can/sun4i_can.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/can/sun4i_can.c +12 -2
index b0c8085..1d2d12e 100644
@@ -539,6 +539,15 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		}
 		stats->rx_over_errors++;
 		stats->rx_errors++;
+
+		/* reset the CAN IP by entering reset mode */
+		err = set_reset_mode(dev);
+		if (err < 0)
+			return err;
+		err = set_normal_mode(dev);
+		if (err < 0)
+			return err;
+
 		/* clear bit */
 		sun4i_can_write_cmdreg(priv, SUN4I_CMD_CLEAR_OR_FLAG);
 	}
@@ -653,8 +663,9 @@ static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)
 			netif_wake_queue(dev);
 			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
-		if (isrc & SUN4I_INT_RBUF_VLD) {
-			/* receive interrupt */
+		if ((isrc & SUN4I_INT_RBUF_VLD) &&
+		    !(isrc & SUN4I_INT_DATA_OR)) {
+			/* receive interrupt - don't read if overrun occurred */
 			while (status & SUN4I_STA_RBUF_RDY) {
 				/* RX buffer is not empty */
 				sun4i_can_rx(dev);
Signature · 1 line
1.7.9.5
#4 lore raw
Quoted 23 lines · GBert

From: cb2begq <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

V4: add error handling
V3: fix compilation
V2: no duplicate error reporting

---
 drivers/net/can/sun4i_can.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/can/sun4i_can.c +0 -0
index b0c8085..1d2d12e 100644
@@ -539,6 +539,15 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		}

drivers/net/can/sun4i_can.c static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) · line 549

Quoted 10 lines
drivers/net/can/sun4i_can.c +8 -0
 		stats->rx_over_errors++;
 		stats->rx_errors++;
+
+		/* reset the CAN IP by entering reset mode */
+		err = set_reset_mode(dev);
+		if (err < 0)
+			return err;
+		err = set_normal_mode(dev);
+		if (err < 0)
+			return err;

If an skb has been allocated it's lost here.

However, in which state is the controller if the set_reset or set_normal doesn't work? Maybe ignore the error altogether and just carry on? If so, add ad comment stating that the only error can be a timeout and we ignore the errors in that case.

See the caller of sun4i_can_err() which assumes the only error will be a ENOMEM due to no skb.

Quoted 7 lines
drivers/net/can/sun4i_can.c +1 -0
+
 		/* clear bit */
 		sun4i_can_write_cmdreg(priv, SUN4I_CMD_CLEAR_OR_FLAG);
 	}
@@ -653,8 +663,9 @@ static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)
 			netif_wake_queue(dev);

drivers/net/can/sun4i_can.c static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id) · line 671

Quoted 10 lines
drivers/net/can/sun4i_can.c +3 -2
 			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
-		if (isrc & SUN4I_INT_RBUF_VLD) {
-			/* receive interrupt */
+		if ((isrc & SUN4I_INT_RBUF_VLD) &&
+		    !(isrc & SUN4I_INT_DATA_OR)) {
+			/* receive interrupt - don't read if overrun occurred */
 			while (status & SUN4I_STA_RBUF_RDY) {
 				/* RX buffer is not empty */
 				sun4i_can_rx(dev);

Marc

Signature · 4 lines
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   |
author
#5 lore raw

PATCH v5 1/1 can: sun4i: fix overrun

In reply to GBert

From: cb2begq <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

V5: ignore timeout error and add a comment
V4: add error handling
V3: fix compilation
V2: no duplicate error reporting

---
 drivers/net/can/sun4i_can.c |   12 ++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/can/sun4i_can.c +10 -2
index b0c8085..1d2d12e 100644
@@ -539,6 +539,13 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)
 		}
 		stats->rx_over_errors++;
 		stats->rx_errors++;
+
+		/* reset the CAN IP by entering reset mode
+		 * ignoring timeout error
+		 */
+		set_reset_mode(dev);
+		set_normal_mode(dev);
+
 		/* clear bit */
 		sun4i_can_write_cmdreg(priv, SUN4I_CMD_CLEAR_OR_FLAG);
 	}
@@ -653,8 +663,9 @@ static irqreturn_t sun4i_can_interrupt(int irq, void *dev_id)
 			netif_wake_queue(dev);
 			can_led_event(dev, CAN_LED_EVENT_TX);
 		}
-		if (isrc & SUN4I_INT_RBUF_VLD) {
-			/* receive interrupt */
+		if ((isrc & SUN4I_INT_RBUF_VLD) &&
+		    !(isrc & SUN4I_INT_DATA_OR)) {
+			/* receive interrupt - don't read if overrun occurred */
 			while (status & SUN4I_STA_RBUF_RDY) {
 				/* RX buffer is not empty */
 				sun4i_can_rx(dev);
Signature · 1 line
1.7.9.5
maintainer Applied
#6 lore raw
Quoted 6 lines · GBert

From: cb2begq <[email protected]>

SUN4Is CAN IP has a 64 byte deep FIFO buffer. If the buffer is not drained fast enough (overrun) it's getting mangled. Already received frames are dropped - the data can't be restored.

Quoted 7 lines

V5: ignore timeout error and add a comment
V4: add error handling
V3: fix compilation
V2: no duplicate error reporting

Applied to can.

tnx,
Marc

Signature · 4 lines
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   |